From patchwork Thu Jul 25 14:42:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 11059019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5E44138D for ; Thu, 25 Jul 2019 14:44:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5284287E0 for ; Thu, 25 Jul 2019 14:44:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C99322882C; Thu, 25 Jul 2019 14:44:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 17C8628895 for ; Thu, 25 Jul 2019 14:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:References:MIME-Version:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CJPq5s1Z7SG1NdSK5f9jWzmaanX2U6pErUOBECOD8BM=; b=HtcOsxklHEJyJQ pT0ZKXq44qhwA5TE0yU+lkg9L5o8MAsR/JGo2nKhEDPGmYZwem01C227Tbs7W4HdaHKtqXhV61QdV 0IAj8X/soiTJY9UPVTKI1q2k+pFytOHbU8yc5BR/5Y6FrW92+QTEEDUlI4SMngW/8HR6F0/jPoaeL qBiMt/lUMXOihSQ8fOnrvUL/cswaz+hbDvXGgbwsHi/BJVkTZRz/RW4c3wbItYF5ZL9JV3998yku5 kokaMHxp5xuHtarYfUfMOHjqWP7Z12jFyzi8nvl5mmqY+2WZKud6NPuX34PncY9kthwhoeDWZv7K5 IxkLrTmaChHoloXz5AIA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hqeys-0004SN-Al; Thu, 25 Jul 2019 14:44:30 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hqexu-0003hn-NJ for linux-arm-kernel@lists.infradead.org; Thu, 25 Jul 2019 14:43:33 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20190725144327euoutp0206a6313b8415f4d5bb30f697ce9e8678~0rZClpG2g1162511625euoutp02e for ; Thu, 25 Jul 2019 14:43:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20190725144327euoutp0206a6313b8415f4d5bb30f697ce9e8678~0rZClpG2g1162511625euoutp02e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1564065807; bh=UyI1wQ20jgXxJKqp5TkkQjurNLXPwK0/yJfHRL2NaWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c6+O3NQBC4Ns3Zzy/47I6P2MW2aTdQS+pNiWQitTU42czt/ljOhTnybL+iMahx3Lw vEuKMsZxj/15H0fOX74Euk8xo7HU+4gnvyOLMuXkDbRVcGB5hcMOVVl7uBXVABoeOs NM3x23fj6CdbocUu9/KUxU78DHb07Zm220D3eXdQ= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20190725144326eucas1p14f80b2ad8cd63ad739d5171090ac0896~0rZCCDwNT1363913639eucas1p1j; Thu, 25 Jul 2019 14:43:26 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id CF.38.04298.E00C93D5; Thu, 25 Jul 2019 15:43:26 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20190725144325eucas1p204f9ffe8988a3604fdf21f77d242c7b8~0rZBLUxw71530115301eucas1p2o; Thu, 25 Jul 2019 14:43:25 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20190725144325eusmtrp11e79d58e292db99dbf0c8c1eed063582~0rZA9ETcK0724307243eusmtrp1A; Thu, 25 Jul 2019 14:43:25 +0000 (GMT) X-AuditID: cbfec7f2-f13ff700000010ca-d6-5d39c00efc85 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 2E.2E.04146.D00C93D5; Thu, 25 Jul 2019 15:43:25 +0100 (BST) Received: from AMDC3218.DIGITAL.local (unknown [106.120.51.18]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20190725144324eusmtip12c99b1a847eb7d9406e4cc76ba4d2538~0rZAOPIad3128231282eusmtip1j; Thu, 25 Jul 2019 14:43:24 +0000 (GMT) From: k.konieczny@partner.samsung.com To: k.konieczny@partner.samsung.com Subject: [PATCH v4 2/5] devfreq: exynos-bus: convert to use dev_pm_opp_set_rate() Date: Thu, 25 Jul 2019 16:42:57 +0200 Message-Id: <20190725144300.25014-3-k.konieczny@partner.samsung.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190725144300.25014-1-k.konieczny@partner.samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa0hTYRjHe3fOzjmKk9M0fHBStCgy8BYGrxSWdFtFIBVFWdTSg5Y6ZVNr RaVl2axm5QcvybqaIt62pqmpNRtJmS4vaRHlQEuraTUXFaW27djl2+/8L/zfBw5DiAeF/swB RRqnVMiTpJQnWf/ohyXI+0HEntCxagnWF9YI8YBjRIivmruEWNs6jXDe0EcCWyy1NO48aaOx YahfiHubSig8ccGMcKGlVYCrzK9pXDrQLcCvssopbPveKcCnW8w0nurXk/iO9RG1Siyr1FUi maFCQ8nu3DohM403C2RaYwWStb+4K5BNGOZG07s8V8RxSQcyOGVI5D7PhC7DfSq1Y+nh531n iEzkWJyLPBhgw+GGXSdwsZgtR3C1LTAXeTrZgeCiRUfxHxMIPo1kk38aXd9PkrxRhsAypBf8 rTSNNhGuFMUuBGPhe9rFvuwCyH9TQLhCBPuDhNpevdvwYbfCkPYncjHpLJjybrtZxK4Be0cm xc/NA03DPfe0B7sWJrOqZjKz4XHRsFsnnJlTdVfcA8CO0dD4qRHx5TVQlPeS4NkHPrQbaZ4D oCP//Mw9h+DtdS3Nl7MRWHO+zBjL4WF7tzAXMc6FQKhpCuHlKLAP2mmXDKw3vBibzb/BGy7X u450ySI4e0bMp4NAN/1UyLMEcqerZ1gGk7YW+iKaX/zfNcX/XVP8b/caIiqQH5euSo7nVGEK 7lCwSp6sSlfEB8emJBuQ87frmGq3N6CvPfvbEMsgqZfoWVnEHrFQnqFSJ7chYAipr6iuwSmJ 4uTqI5wyZa8yPYlTtSEJQ0r9REdnWWPEbLw8jUvkuFRO+ccVMB7+mSjRq2SLfnvZZ5t0SwLs WDmorzYF9cc2nm9UaNTLc578MpWULuphW4cnYozb1I4ofW3BVGdf7KlNo+ObHWniLhuySy71 WpsPhn9713wscfU6y+nxtEj725vm+Zq+7mzbBuv6c7dXTkZ9fT9YuiI6o2W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generator: CA X-RootMTR: 20190725144325eucas1p204f9ffe8988a3604fdf21f77d242c7b8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190725144325eucas1p204f9ffe8988a3604fdf21f77d242c7b8 References: <20190725144300.25014-1-k.konieczny@partner.samsung.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190725_074330_904860_5D2F2608 X-CRM114-Status: GOOD ( 24.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Nishanth Menon , linux-samsung-soc@vger.kernel.org, Rob Herring , linux-arm-kernel@lists.infradead.org, Bartlomiej Zolnierkiewicz , Stephen Boyd , Viresh Kumar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski , Chanwoo Choi , Kyungmin Park , Kukjin Kim , MyungJoo Ham , devicetree@vger.kernel.org, Marek Szyprowski Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Reuse opp core code for setting bus clock and voltage. As a side effect this allow usage of coupled regulators feature (required for boards using Exynos5422/5800 SoCs) because dev_pm_opp_set_rate() uses regulator_set_voltage_triplet() for setting regulator voltage while the old code used regulator_set_voltage_tol() with fixed tolerance. This patch also removes no longer needed parsing of DT property "exynos,voltage-tolerance" (no Exynos devfreq DT node uses it). Signed-off-by: Kamil Konieczny --- Changes: v4: - remove unrelated changes, add newline before comment --- drivers/devfreq/exynos-bus.c | 108 +++++++++-------------------------- 1 file changed, 28 insertions(+), 80 deletions(-) diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c index f34fa26f00d0..ebb8f46312b6 100644 --- a/drivers/devfreq/exynos-bus.c +++ b/drivers/devfreq/exynos-bus.c @@ -25,7 +25,6 @@ #include #define DEFAULT_SATURATION_RATIO 40 -#define DEFAULT_VOLTAGE_TOLERANCE 2 struct exynos_bus { struct device *dev; @@ -37,9 +36,8 @@ struct exynos_bus { unsigned long curr_freq; - struct regulator *regulator; + struct opp_table *opp_table; struct clk *clk; - unsigned int voltage_tolerance; unsigned int ratio; }; @@ -99,56 +97,23 @@ static int exynos_bus_target(struct device *dev, unsigned long *freq, u32 flags) { struct exynos_bus *bus = dev_get_drvdata(dev); struct dev_pm_opp *new_opp; - unsigned long old_freq, new_freq, new_volt, tol; int ret = 0; - /* Get new opp-bus instance according to new bus clock */ + /* Get correct frequency for bus. */ new_opp = devfreq_recommended_opp(dev, freq, flags); if (IS_ERR(new_opp)) { dev_err(dev, "failed to get recommended opp instance\n"); return PTR_ERR(new_opp); } - new_freq = dev_pm_opp_get_freq(new_opp); - new_volt = dev_pm_opp_get_voltage(new_opp); dev_pm_opp_put(new_opp); - old_freq = bus->curr_freq; - - if (old_freq == new_freq) - return 0; - tol = new_volt * bus->voltage_tolerance / 100; - /* Change voltage and frequency according to new OPP level */ mutex_lock(&bus->lock); + ret = dev_pm_opp_set_rate(dev, *freq); + if (!ret) + bus->curr_freq = *freq; - if (old_freq < new_freq) { - ret = regulator_set_voltage_tol(bus->regulator, new_volt, tol); - if (ret < 0) { - dev_err(bus->dev, "failed to set voltage\n"); - goto out; - } - } - - ret = clk_set_rate(bus->clk, new_freq); - if (ret < 0) { - dev_err(dev, "failed to change clock of bus\n"); - clk_set_rate(bus->clk, old_freq); - goto out; - } - - if (old_freq > new_freq) { - ret = regulator_set_voltage_tol(bus->regulator, new_volt, tol); - if (ret < 0) { - dev_err(bus->dev, "failed to set voltage\n"); - goto out; - } - } - bus->curr_freq = new_freq; - - dev_dbg(dev, "Set the frequency of bus (%luHz -> %luHz, %luHz)\n", - old_freq, new_freq, clk_get_rate(bus->clk)); -out: mutex_unlock(&bus->lock); return ret; @@ -196,8 +161,10 @@ static void exynos_bus_exit(struct device *dev) dev_pm_opp_of_remove_table(dev); clk_disable_unprepare(bus->clk); - if (bus->regulator) - regulator_disable(bus->regulator); + if (bus->opp_table) { + dev_pm_opp_put_regulators(bus->opp_table); + bus->opp_table = NULL; + } } /* @@ -208,39 +175,23 @@ static int exynos_bus_passive_target(struct device *dev, unsigned long *freq, { struct exynos_bus *bus = dev_get_drvdata(dev); struct dev_pm_opp *new_opp; - unsigned long old_freq, new_freq; - int ret = 0; + int ret; - /* Get new opp-bus instance according to new bus clock */ + /* Get correct frequency for bus. */ new_opp = devfreq_recommended_opp(dev, freq, flags); if (IS_ERR(new_opp)) { dev_err(dev, "failed to get recommended opp instance\n"); return PTR_ERR(new_opp); } - new_freq = dev_pm_opp_get_freq(new_opp); dev_pm_opp_put(new_opp); - old_freq = bus->curr_freq; - - if (old_freq == new_freq) - return 0; - /* Change the frequency according to new OPP level */ mutex_lock(&bus->lock); + ret = dev_pm_opp_set_rate(dev, *freq); + if (!ret) + bus->curr_freq = *freq; - ret = clk_set_rate(bus->clk, new_freq); - if (ret < 0) { - dev_err(dev, "failed to set the clock of bus\n"); - goto out; - } - - *freq = new_freq; - bus->curr_freq = new_freq; - - dev_dbg(dev, "Set the frequency of bus (%luHz -> %luHz, %luHz)\n", - old_freq, new_freq, clk_get_rate(bus->clk)); -out: mutex_unlock(&bus->lock); return ret; @@ -258,21 +209,19 @@ static int exynos_bus_parent_parse_of(struct device_node *np, struct exynos_bus *bus) { struct device *dev = bus->dev; + struct opp_table *opp_table; + const char *vdd = "vdd"; 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"); - return PTR_ERR(bus->regulator); - } - - ret = regulator_enable(bus->regulator); - if (ret < 0) { - dev_err(dev, "failed to enable VDD regulator\n"); + opp_table = dev_pm_opp_set_regulators(dev, &vdd, 1); + if (IS_ERR(opp_table)) { + ret = PTR_ERR(opp_table); + dev_err(dev, "failed to set regulators %d\n", ret); return ret; } + bus->opp_table = opp_table; + /* * Get the devfreq-event devices to get the current utilization of * buses. This raw data will be used in devfreq ondemand governor. @@ -313,14 +262,11 @@ static int exynos_bus_parent_parse_of(struct device_node *np, if (of_property_read_u32(np, "exynos,saturation-ratio", &bus->ratio)) bus->ratio = DEFAULT_SATURATION_RATIO; - if (of_property_read_u32(np, "exynos,voltage-tolerance", - &bus->voltage_tolerance)) - bus->voltage_tolerance = DEFAULT_VOLTAGE_TOLERANCE; - return 0; err_regulator: - regulator_disable(bus->regulator); + dev_pm_opp_put_regulators(bus->opp_table); + bus->opp_table = NULL; return ret; } @@ -511,8 +457,10 @@ static int exynos_bus_probe(struct platform_device *pdev) dev_pm_opp_of_remove_table(dev); clk_disable_unprepare(bus->clk); err_reg: - if (!passive) - regulator_disable(bus->regulator); + if (!passive) { + dev_pm_opp_put_regulators(bus->opp_table); + bus->opp_table = NULL; + } return ret; }