From patchwork Thu Mar 24 04:25:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chanwoo Choi X-Patchwork-Id: 8657441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B500BC0553 for ; Thu, 24 Mar 2016 04:30:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 661FF20340 for ; Thu, 24 Mar 2016 04:30:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 128D320374 for ; Thu, 24 Mar 2016 04:30:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aiwsV-0006OT-Ha; Thu, 24 Mar 2016 04:28:11 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aiwqN-00051a-Un for linux-arm-kernel@lists.infradead.org; Thu, 24 Mar 2016 04:26:04 +0000 Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O4J02QCT0ALHMD0@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 24 Mar 2016 13:25:33 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.115]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id 1F.C7.04972.D3C63F65; Thu, 24 Mar 2016 13:25:33 +0900 (KST) X-AuditID: cbfee68e-f793c6d00000136c-5b-56f36c3db1e7 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id D6.17.09068.D3C63F65; Thu, 24 Mar 2016 13:25:33 +0900 (KST) Received: from chan.10.32.193.11 ([10.113.62.212]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O4J007XC0AJOI80@mmp1.samsung.com>; Thu, 24 Mar 2016 13:25:32 +0900 (KST) From: Chanwoo Choi To: myungjoo.ham@samsung.com, kyungmin.park@samsung.com, k.kozlowski@samsung.com, kgene@kernel.org Subject: [PATCH v5 07/21] PM / devfreq: exynos: Add support of bus frequency of sub-blocks using passive governor Date: Thu, 24 Mar 2016 13:25:16 +0900 Message-id: <1458793530-31897-8-git-send-email-cw00.choi@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1458793530-31897-1-git-send-email-cw00.choi@samsung.com> References: <1458793530-31897-1-git-send-email-cw00.choi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsWyRsSkWNc253OYwbUNWhbXvzxntZh/5Byr Rf+bhawW516tZLR4/cLQov/xa2aLs01v2C02Pb7GanF51xw2i8+9RxgtZpzfx2SxbuMtdovb l3ktll6/yGRxu3EFm8WE6WtZLM6cvsRq0br3CLtF2+oPrA7CHmvmrWH0aGnuYfO43NfL5LFz 1l12j5XLv7B5bFrVyeaxeUm9x79j7B5brrazePRtWcXo8XmTXAB3FJdNSmpOZllqkb5dAlfG tIkfmAruRFZc/3aKpYHxunsXIyeHhICJxKrTU9ggbDGJC/fWg9lCAisYJXrPCsLUTN90mrWL kQsovpRRYvufo8wQRV8YJVY/rgex2QS0JPa/uAHWLCKQIvH44Uk2kAZmgSnMEsunN7N0MXJw CAsUSzROkAOpYRFQlbj89ilYPa+Aq8SkrxehjpCT+LDnETuIzSngJjG1oYkFYperxNPHm8CO kBBYyCF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 7ocYBTgYlXh4b3B9DhNiTSwrrsw9xCjBwawkwrs+HCjEm5JYWZValB9fVJqTWnyI0RTosInM UqLJ+cCUlFcSb2hsYmZkaWRuaGFkbK4kzvv4/7owIYH0xJLU7NTUgtQimD4mDk6pBkat1758 k8rX2rocUjyfc2W2pv0KBfeF2lpPIwXXK1cf+5s5VXmB0YwpPxwe+u6a8vT8FcGWd5P29u9J 8OCSbJLWumW3vaAtJWLxPY9trv8tnh99ejLxnVXg0t35lg81/OUn77zYub/bVYb7Nf+sutvb J3DcDYx7miJa7vlPQv13Vb9MyT4exY1KLMUZiYZazEXFiQBe1OebEQMAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160323_212600_421942_6532D15C X-CRM114-Status: GOOD ( 27.06 ) X-Spam-Score: -6.9 (------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux@arm.linux.org.uk, cw00.choi@samsung.com, pawel.moll@arm.com, ijc+devicetree@hellion.org.uk, linux.amoon@gmail.com, linux-pm@vger.kernel.org, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, tjakobi@math.uni-bielefeld.de, robh+dt@kernel.org, galak@codeaurora.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the support of bus frequency feature for sub-blocks which share the one power line. If each bus depends on the power line, each bus is not able to change the voltage by oneself. To optimize the power-consumption on runtime, some buses using the same power line should change the source clock and regulator at the same time. So, this patch uses the passive governor to support the bus frequency for all buses which sharing the one power line. For example, Exynos3250 include the two power line for AXI buses as following: : VDD_MIF : MIF (Memory Interface) provide the DMC (Dynamic Memory Controller) with the power (regulator). : VDD_INT : INT (Internal) provide the various sub-blocks with the power (regulator). Each bus is included in as follwoing block. In the case of VDD_MIF, only DMC bus use the power line. So, there is no any depencency between buese. But, in the case of VDD_INT, various buses share the one power line of VDD_INT. We need to make the depenency between buses. When using passive governor, there is no problem to support the bus frequency as DVFS for all buses. One bus should be operated as the parent bus device which gathering the current load of INT block and then decides the new frequency with some governors except of passive governor. After deciding the new frequency by the parent bus device, the rest bus devices will change the each source clock according to new frequency of the parent bus device. - MIF (Memory Interface) block : VDD_MIF |--- DMC - INT (Internal) block : VDD_INT |--- LEFTBUS (parent) |--- PERIL |--- MFC |--- G3D |--- RIGHTBUS |--- FSYS |--- LCD0 |--- PERIR |--- ISP |--- CAM [tjakobi: Reported debugfs error during booting and cw00.choi fix it.] Reported-by: Tobias Jakobi Signed-off-by: Chanwoo Choi --- drivers/devfreq/Kconfig | 1 + drivers/devfreq/exynos-bus.c | 210 +++++++++++++++++++++++++++++++++---------- 2 files changed, 165 insertions(+), 46 deletions(-) diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig index ae689ad375fa..357b548851a3 100644 --- a/drivers/devfreq/Kconfig +++ b/drivers/devfreq/Kconfig @@ -77,6 +77,7 @@ config ARM_EXYNOS_BUS_DEVFREQ bool "ARM EXYNOS Generic Memory Bus DEVFREQ Driver" depends on ARCH_EXYNOS select DEVFREQ_GOV_SIMPLE_ONDEMAND + select DEVFREQ_GOV_PASSIVE select DEVFREQ_EVENT_EXYNOS_PPMU select PM_DEVFREQ_EVENT select PM_OPP diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c index f79963187fa1..c4249efaf0e1 100644 --- a/drivers/devfreq/exynos-bus.c +++ b/drivers/devfreq/exynos-bus.c @@ -1,7 +1,7 @@ /* * Generic Exynos Bus frequency driver with DEVFREQ Framework * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * Author : Chanwoo Choi * * This driver support Exynos Bus frequency feature by using @@ -93,7 +93,7 @@ static int exynos_bus_get_event(struct exynos_bus *bus, } /* - * Must necessary function for devfreq governor + * Must necessary function for devfreq simple-ondemand governor */ static int exynos_bus_target(struct device *dev, unsigned long *freq, u32 flags) { @@ -202,59 +202,80 @@ static void exynos_bus_exit(struct device *dev) regulator_disable(bus->regulator); dev_pm_opp_of_remove_table(dev); + clk_disable_unprepare(bus->clk); } -static int exynos_bus_parse_of(struct device_node *np, - struct exynos_bus *bus) +/* + * Must necessary function for devfreq passive governor + */ +static int exynos_bus_passive_target(struct device *dev, unsigned long *freq, + u32 flags) { - struct device *dev = bus->dev; - unsigned long rate; - int i, ret, count, size; + struct exynos_bus *bus = dev_get_drvdata(dev); + struct dev_pm_opp *new_opp; + unsigned long old_freq, new_freq; + int ret = 0; - /* Get the clock to provide each bus with source clock */ - bus->clk = devm_clk_get(dev, "bus"); - if (IS_ERR(bus->clk)) { - dev_err(dev, "failed to get bus clock\n"); - return PTR_ERR(bus->clk); + /* Get new opp-bus instance according to new bus clock */ + rcu_read_lock(); + new_opp = devfreq_recommended_opp(dev, freq, flags); + if (IS_ERR_OR_NULL(new_opp)) { + dev_err(dev, "failed to get recommed opp instance\n"); + rcu_read_unlock(); + return PTR_ERR(new_opp); } - ret = clk_prepare_enable(bus->clk); - if (ret < 0) { - dev_err(dev, "failed to get enable clock\n"); - return ret; - } + new_freq = dev_pm_opp_get_freq(new_opp); + old_freq = dev_pm_opp_get_freq(bus->curr_opp); + rcu_read_unlock(); - /* Get the freq/voltage OPP table to scale the bus frequency */ - rcu_read_lock(); - ret = dev_pm_opp_of_add_table(dev); + if (old_freq == new_freq) + return 0; + + /* Change the frequency according to new OPP level */ + mutex_lock(&bus->lock); + + ret = clk_set_rate(bus->clk, new_freq); if (ret < 0) { - dev_err(dev, "failed to get OPP table\n"); - rcu_read_unlock(); - goto err_clk; + dev_err(dev, "failed to set the clock of bus\n"); + goto out; } - rate = clk_get_rate(bus->clk); - bus->curr_opp = dev_pm_opp_find_freq_ceil(dev, &rate); - if (IS_ERR(bus->curr_opp)) { - dev_err(dev, "failed to find dev_pm_opp\n"); - rcu_read_unlock(); - ret = PTR_ERR(bus->curr_opp); - goto err_opp; - } - rcu_read_unlock(); + bus->curr_opp = new_opp; + + dev_dbg(dev, "Set the frequency of bus (%lukHz -> %lukHz)\n", + old_freq/1000, new_freq/1000); +out: + mutex_unlock(&bus->lock); + + return ret; +} + +static void exynos_bus_passive_exit(struct device *dev) +{ + struct exynos_bus *bus = dev_get_drvdata(dev); + + dev_pm_opp_of_remove_table(dev); + clk_disable_unprepare(bus->clk); +} + +static int exynos_bus_parent_parse_of(struct device_node *np, + struct exynos_bus *bus) +{ + struct device *dev = bus->dev; + int i, ret, count, size; /* Get the regulator to provide each bus with the power */ bus->regulator = devm_regulator_get(dev, "vdd"); if (IS_ERR(bus->regulator)) { dev_err(dev, "failed to get VDD regulator\n"); - ret = PTR_ERR(bus->regulator); - goto err_opp; + return PTR_ERR(bus->regulator); } ret = regulator_enable(bus->regulator); if (ret < 0) { dev_err(dev, "failed to enable VDD regulator\n"); - goto err_opp; + return ret; } /* @@ -305,6 +326,51 @@ static int exynos_bus_parse_of(struct device_node *np, err_regulator: regulator_disable(bus->regulator); + + return ret; +} + +static int exynos_bus_parse_of(struct device_node *np, + struct exynos_bus *bus) +{ + struct device *dev = bus->dev; + unsigned long rate; + int ret; + + /* Get the clock to provide each bus with source clock */ + bus->clk = devm_clk_get(dev, "bus"); + if (IS_ERR(bus->clk)) { + dev_err(dev, "failed to get bus clock\n"); + return PTR_ERR(bus->clk); + } + + ret = clk_prepare_enable(bus->clk); + if (ret < 0) { + dev_err(dev, "failed to get enable clock\n"); + return ret; + } + + /* Get the freq and voltage from OPP table to scale the bus freq */ + rcu_read_lock(); + ret = dev_pm_opp_of_add_table(dev); + if (ret < 0) { + dev_err(dev, "failed to get OPP table\n"); + rcu_read_unlock(); + goto err_clk; + } + + rate = clk_get_rate(bus->clk); + bus->curr_opp = dev_pm_opp_find_freq_ceil(dev, &rate); + if (IS_ERR(bus->curr_opp)) { + dev_err(dev, "failed to find dev_pm_opp\n"); + rcu_read_unlock(); + ret = PTR_ERR(bus->curr_opp); + goto err_opp; + } + rcu_read_unlock(); + + return 0; + err_opp: dev_pm_opp_of_remove_table(dev); err_clk: @@ -319,8 +385,10 @@ static int exynos_bus_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; struct devfreq_dev_profile *profile; struct devfreq_simple_ondemand_data *ondemand_data; + struct devfreq *parent_devfreq; struct exynos_bus *bus; - int ret; + int ret, max_state; + unsigned long min_freq, max_freq; if (!np) { dev_err(dev, "failed to find devicetree node\n"); @@ -337,20 +405,33 @@ static int exynos_bus_probe(struct platform_device *pdev) /* Parse the device-tree to get the resource information */ ret = exynos_bus_parse_of(np, bus); if (ret < 0) - return ret; + goto err; - /* Initalize the struct profile and governor data */ profile = devm_kzalloc(dev, sizeof(*profile), GFP_KERNEL); - if (!profile) - return -ENOMEM; + if (!profile) { + ret = -ENOMEM; + goto err; + } + + if (of_parse_phandle(dev->of_node, "devfreq", 0)) + goto passive; + else + ret = exynos_bus_parent_parse_of(np, bus); + + if (ret < 0) + goto err; + + /* Initalize the struct profile and governor data for parent device */ profile->polling_ms = 50; profile->target = exynos_bus_target; profile->get_dev_status = exynos_bus_get_dev_status; profile->exit = exynos_bus_exit; ondemand_data = devm_kzalloc(dev, sizeof(*ondemand_data), GFP_KERNEL); - if (!ondemand_data) - return -ENOMEM; + if (!ondemand_data) { + ret = -ENOMEM; + goto err; + } ondemand_data->upthreshold = 40; ondemand_data->downdifferential = 5; @@ -359,14 +440,15 @@ static int exynos_bus_probe(struct platform_device *pdev) ondemand_data); if (IS_ERR_OR_NULL(bus->devfreq)) { dev_err(dev, "failed to add devfreq device\n"); - return PTR_ERR(bus->devfreq); + ret = PTR_ERR(bus->devfreq); + goto err; } /* Register opp_notifier to catch the change of OPP */ ret = devm_devfreq_register_opp_notifier(dev, bus->devfreq); if (ret < 0) { dev_err(dev, "failed to register opp notifier\n"); - return ret; + goto err; } /* @@ -376,16 +458,52 @@ static int exynos_bus_probe(struct platform_device *pdev) ret = exynos_bus_enable_edev(bus); if (ret < 0) { dev_err(dev, "failed to enable devfreq-event devices\n"); - return ret; + goto err; } ret = exynos_bus_set_event(bus); if (ret < 0) { dev_err(dev, "failed to set event to devfreq-event devices\n"); - return ret; + goto err; + } + + goto out; +passive: + /* Initalize the struct profile and governor data for passive device */ + profile->target = exynos_bus_passive_target; + profile->exit = exynos_bus_passive_exit; + + /* Get the instance of parent devfreq device */ + parent_devfreq = devfreq_get_devfreq_by_phandle(dev, 0); + if (IS_ERR(parent_devfreq)) { + ret = -EPROBE_DEFER; + goto err; } + /* Add devfreq device for exynos bus with passive governor */ + bus->devfreq = devm_devfreq_add_device(dev, profile, "passive", + parent_devfreq); + if (IS_ERR_OR_NULL(bus->devfreq)) { + dev_err(dev, + "failed to add devfreq dev with passive governor\n"); + ret = -EPROBE_DEFER; + goto err; + } + +out: + max_state = bus->devfreq->profile->max_state; + min_freq = (bus->devfreq->profile->freq_table[0] / 1000); + max_freq = (bus->devfreq->profile->freq_table[max_state - 1] / 1000); + pr_info("exynos-bus: new bus device registered: %s (%6ld KHz ~ %6ld KHz)\n", + dev_name(dev), min_freq, max_freq); + return 0; + +err: + dev_pm_opp_of_remove_table(dev); + clk_disable_unprepare(bus->clk); + + return ret; } #ifdef CONFIG_PM_SLEEP