From patchwork Mon Mar 14 14:16:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12780220 X-Patchwork-Delegate: neil.armstrong@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35A4BC433F5 for ; Mon, 14 Mar 2022 14:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xNkwgSH5aLwbsO+RWET7+uJxq1U89lF3sPlskKqo1qk=; b=o6CuyjIWGFzMpJ Rt+n/4DI2KeB3zzjIQYuOARsHESXO03vKDhv/QUbQyW9X/s4vstLe+9jOhJUi+xPNHs9mZBifu9aL Gch8IusYmYD4vo0TlWLeenORXsLnkUzaOiMZO8Xj7eTwmXOxOts3hiWbyfukxluXmhSdRfoWJhTXt WG8HYG+ZzFhZVv4ya4JY3Xspl5lSWZ30jsFS14HPkit0S+Ih799y1YkoVuzP649xnI+cjO0FlKedU K0wF6oTx6msL93h8PErSDhekhxqRhONsJt01YM67KPupq+t1QBtDnB8QuonTneeDlO19SOGlPkEFp AIs0kSBietDetEbemWpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlXg-005daM-HG; Mon, 14 Mar 2022 14:19:24 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlVx-005ch4-9C for linux-amlogic@lists.infradead.org; Mon, 14 Mar 2022 14:17:39 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nTlVS-0004zJ-Bp; Mon, 14 Mar 2022 15:17:06 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1nTlVI-000f2e-6F; Mon, 14 Mar 2022 15:16:54 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1nTlVG-0097aY-0z; Mon, 14 Mar 2022 15:16:54 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Michael Turquette , Stephen Boyd , Russell King , =?utf-8?q?Nuno_S=C3=A1?= , Jean Delvare , Guenter Roeck , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, linux-hwmon@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Matt Mackall , Herbert Xu , Greg Kroah-Hartman , Linus Walleij , Bartosz Golaszewski , Neil Armstrong , David Airlie , Daniel Vetter , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Paul Cercueil , Alessandro Zummo , Alexandre Belloni , Wim Van Sebroeck , Claudiu Beznea , Thierry Reding , Lee Jones , Nicolas Ferre , Oleksij Rempel , Shawn Guo , Fabio Estevam , NXP Linux Team , Mark Brown , Vinod Koul Cc: linux-clk@vger.kernel.org, kernel@pengutronix.de, Vladimir Zapolskiy , Heiko Stuebner , Tomislav Denis , Anand Ashok Dumbre , Michal Simek , =?utf-8?q?Andr=C3=A9_Gustavo_Nakago?= =?utf-8?q?mi_Lopez?= , Cai Huoqing , linux-iio@vger.kernel.org, linux-crypto@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mips@vger.kernel.org, linux-rtc@vger.kernel.org, Keguang Zhang , Andy Gross , Bjorn Andersson , Patrice Chotard , Maxime Coquelin , Alexandre Torgue , Nobuhiro Iwamatsu , linux-watchdog@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-pwm@vger.kernel.org, linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org, Amireddy Mallikarjuna reddy , dmaengine@vger.kernel.org, Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v8 01/16] clk: generalize devm_clk_get() a bit Date: Mon, 14 Mar 2022 15:16:28 +0100 Message-Id: <20220314141643.22184-2-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> References: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2782; i=uwe@kleine-koenig.org; h=from:subject; bh=R5i2zDoCQJSy1ZUerxZ75D9yH7vs0Yq+WK5mYZohDQQ=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBiL03r/FSSSMkN+/sPRSPRmnzWG7n80mxF6W/uPagY Wwq6G3KJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYi9N6wAKCRDB/BR4rcrsCV9PB/ 0Ta+XpJTQdCUjeWsaz8sXPQtyQK6APLzjZjbMmijfMg1ieaLo661ZXlQ8J00dDwFm86jaFSY4bMFT8 kCb+ukClQrRlqBmc6meykJlwPPOzYg7tGDzPrxmdQ7VGGvBFA5K/WpPlbvDdKXelOYAu2aZwBCWbq0 FzgMe0Sh1f0MgOHwnoUeIX/cHA/dbXzDLOwzwlbn5S0v9G9LM7gvadMBgB/z4hNNQfus9Vkl9FekTs bJwETa6zMgveA6AyNUTNmVeD+lAZj1BLCvTzQ2PgRzuzhYXSLbFBv7hMNf2L522++rcuXIAD0es4uA lpqZWzW5CukIzfkUhCS/a5WhswjluT X-Developer-Key: i=uwe@kleine-koenig.org; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220314_071737_372063_5EC3A0A5 X-CRM114-Status: GOOD ( 18.70 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Allow to add an exit hook to devm managed clocks. Also use clk_get_optional() in devm_clk_get_optional instead of open coding it. The generalisation will be used in the next commit to add some more devm_clk helpers. Reviewed-by: Jonathan Cameron Reviewed-by: Alexandru Ardelean Signed-off-by: Uwe Kleine-König Tested-by: Jon Hunter --- drivers/clk/clk-devres.c | 67 ++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index f9d5b7334341..fb7761888b30 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -4,39 +4,72 @@ #include #include +struct devm_clk_state { + struct clk *clk; + void (*exit)(struct clk *clk); +}; + static void devm_clk_release(struct device *dev, void *res) { - clk_put(*(struct clk **)res); + struct devm_clk_state *state = *(struct devm_clk_state **)res; + + if (state->exit) + state->exit(state->clk); + + clk_put(state->clk); } -struct clk *devm_clk_get(struct device *dev, const char *id) +static struct clk *__devm_clk_get(struct device *dev, const char *id, + struct clk *(*get)(struct device *dev, const char *id), + int (*init)(struct clk *clk), + void (*exit)(struct clk *clk)) { - struct clk **ptr, *clk; + struct devm_clk_state *state; + struct clk *clk; + int ret; - ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL); - if (!ptr) + state = devres_alloc(devm_clk_release, sizeof(*state), GFP_KERNEL); + if (!state) return ERR_PTR(-ENOMEM); - clk = clk_get(dev, id); - if (!IS_ERR(clk)) { - *ptr = clk; - devres_add(dev, ptr); - } else { - devres_free(ptr); + clk = get(dev, id); + if (IS_ERR(clk)) { + ret = PTR_ERR(clk); + goto err_clk_get; } + if (init) { + ret = init(clk); + if (ret) + goto err_clk_init; + } + + state->clk = clk; + state->exit = exit; + + devres_add(dev, state); + return clk; + +err_clk_init: + + clk_put(clk); +err_clk_get: + + devres_free(state); + return ERR_PTR(ret); } -EXPORT_SYMBOL(devm_clk_get); -struct clk *devm_clk_get_optional(struct device *dev, const char *id) +struct clk *devm_clk_get(struct device *dev, const char *id) { - struct clk *clk = devm_clk_get(dev, id); + return __devm_clk_get(dev, id, clk_get, NULL, NULL); - if (clk == ERR_PTR(-ENOENT)) - return NULL; +} +EXPORT_SYMBOL(devm_clk_get); - return clk; +struct clk *devm_clk_get_optional(struct device *dev, const char *id) +{ + return __devm_clk_get(dev, id, clk_get_optional, NULL, NULL); } EXPORT_SYMBOL(devm_clk_get_optional); From patchwork Mon Mar 14 14:16:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12780221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CFF04C433F5 for ; Mon, 14 Mar 2022 14:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xHx+UzbYgX4N2z/WL9ZhfqtlbknSPZkmlzt5Ii+GOJ8=; b=hTwefWpMofoj4Y uLQSRSAZc+IfWvNGa0sn3/JEydZNMTLL88/XNnd6EDqwBB8Q0rvHVr/8548GLbdp2h6pi9+4aStv/ vtqIS8LfmkLyN9IEhA9rbV56OZGuPKgyjH2t4l/dJbZJ87qbZ9iuXs3GGVqKTOEfOwZJMd35H9Xdt 76og/KzNBs2mgAVRcFeF4Z6NseQh8yZgHLVz8pVZu/LB6UvKXkcCmt2dajjVmLIWkgYFPgyXVGOYc YL7XW3kum+/SbwLJH3K/yW+zftmO6CxUK3veoD08hwtNwMuGbIXZwG8TOlAaDf17SbEnYvkZ2vjLy hxZ1K1n8UQbJjHitnPlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlXl-005ddI-V3; Mon, 14 Mar 2022 14:19:30 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlVy-005chf-Fs for linux-amlogic@lists.infradead.org; Mon, 14 Mar 2022 14:17:40 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nTlVS-0004zK-Bl; Mon, 14 Mar 2022 15:17:06 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1nTlVI-000f2h-Bp; Mon, 14 Mar 2022 15:16:55 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1nTlVG-0097ab-9N; Mon, 14 Mar 2022 15:16:54 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Michael Turquette , Stephen Boyd , Russell King , =?utf-8?q?Nuno_S=C3=A1?= , Jean Delvare , Guenter Roeck , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, linux-hwmon@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Matt Mackall , Herbert Xu , Greg Kroah-Hartman , Linus Walleij , Bartosz Golaszewski , Neil Armstrong , David Airlie , Daniel Vetter , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Paul Cercueil , Alessandro Zummo , Alexandre Belloni , Wim Van Sebroeck , Claudiu Beznea , Thierry Reding , Lee Jones , Nicolas Ferre , Oleksij Rempel , Shawn Guo , Fabio Estevam , NXP Linux Team , Mark Brown , Vinod Koul Cc: linux-clk@vger.kernel.org, kernel@pengutronix.de, Vladimir Zapolskiy , Heiko Stuebner , Tomislav Denis , Anand Ashok Dumbre , Michal Simek , =?utf-8?q?Andr=C3=A9_Gustavo_Nakago?= =?utf-8?q?mi_Lopez?= , Cai Huoqing , linux-iio@vger.kernel.org, linux-crypto@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-gpio@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mips@vger.kernel.org, linux-rtc@vger.kernel.org, Keguang Zhang , Andy Gross , Bjorn Andersson , Patrice Chotard , Maxime Coquelin , Alexandre Torgue , Nobuhiro Iwamatsu , linux-watchdog@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-pwm@vger.kernel.org, linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org, Amireddy Mallikarjuna reddy , dmaengine@vger.kernel.org, Jonathan Cameron , Alexandru Ardelean Subject: [PATCH v8 02/16] clk: Provide new devm_clk helpers for prepared and enabled clocks Date: Mon, 14 Mar 2022 15:16:29 +0100 Message-Id: <20220314141643.22184-3-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> References: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6580; i=uwe@kleine-koenig.org; h=from:subject; bh=jqwSnvDQbBb4RgD/N+2Gw8Lk4ZgGlEcniX5xP+ormpg=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBiL03vygZ14+FklBjEtfsr0n5Fj7pM3zCRBT9hjlOo D6x0wfOJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYi9N7wAKCRDB/BR4rcrsCW0OB/ 43XIdPZ3YEVyeJcVZVgIWqjU0WCMAkdNPd+cU39oxeA5WcvEM+r2wINAXO9SjYVP4eV60bVzYVmWWP /4qbeio/xVurdJ7Ut2JGUCHJFu6SPC4ClqX2SoQ/JgYpWKUthuRTck4jK/kt92O+Rx8MXx3VYb58Te WdLCTWqtr7pFF4DaX9T5+yuCky8m4NUbi3kaBeCxn5rVPZlXNv0IEn1k9Xkeb5VWYhGIzPb277tXWL 2BwknXn7RuNCQErT4IAfGPlnO1EMkKZxvhHJ3f5GuCKo9hh7+mqbcb2+7anljvY6nbic3kSBAgO8Kc UpsFmFTmEF329SWkaIlHjE4yXN1sYB X-Developer-Key: i=uwe@kleine-koenig.org; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220314_071738_724321_AEB16D1F X-CRM114-Status: GOOD ( 19.87 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org When a driver keeps a clock prepared (or enabled) during the whole lifetime of the driver, these helpers allow to simplify the drivers. Reviewed-by: Jonathan Cameron Reviewed-by: Alexandru Ardelean Signed-off-by: Uwe Kleine-König --- drivers/clk/clk-devres.c | 31 ++++++++++++++ include/linux/clk.h | 90 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c index fb7761888b30..4707fe718f0b 100644 --- a/drivers/clk/clk-devres.c +++ b/drivers/clk/clk-devres.c @@ -67,12 +67,43 @@ struct clk *devm_clk_get(struct device *dev, const char *id) } EXPORT_SYMBOL(devm_clk_get); +struct clk *devm_clk_get_prepared(struct device *dev, const char *id) +{ + return __devm_clk_get(dev, id, clk_get, clk_prepare, clk_unprepare); + +} +EXPORT_SYMBOL(devm_clk_get_prepared); + +struct clk *devm_clk_get_enabled(struct device *dev, const char *id) +{ + return __devm_clk_get(dev, id, clk_get, + clk_prepare_enable, clk_disable_unprepare); + +} +EXPORT_SYMBOL(devm_clk_get_enabled); + struct clk *devm_clk_get_optional(struct device *dev, const char *id) { return __devm_clk_get(dev, id, clk_get_optional, NULL, NULL); } EXPORT_SYMBOL(devm_clk_get_optional); +struct clk *devm_clk_get_optional_prepared(struct device *dev, const char *id) +{ + return __devm_clk_get(dev, id, clk_get_optional, + clk_prepare, clk_unprepare); + +} +EXPORT_SYMBOL(devm_clk_get_optional_prepared); + +struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id) +{ + return __devm_clk_get(dev, id, clk_get_optional, + clk_prepare_enable, clk_disable_unprepare); + +} +EXPORT_SYMBOL(devm_clk_get_optional_enabled); + struct clk_bulk_devres { struct clk_bulk_data *clks; int num_clks; diff --git a/include/linux/clk.h b/include/linux/clk.h index 266e8de3cb51..b011dbba7109 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -449,7 +449,7 @@ int __must_check devm_clk_bulk_get_all(struct device *dev, * the clock producer. (IOW, @id may be identical strings, but * clk_get may return different clock producers depending on @dev.) * - * Drivers must assume that the clock source is not enabled. + * Drivers must assume that the clock source is neither prepared nor enabled. * * devm_clk_get should not be called from within interrupt context. * @@ -458,6 +458,47 @@ int __must_check devm_clk_bulk_get_all(struct device *dev, */ struct clk *devm_clk_get(struct device *dev, const char *id); +/** + * devm_clk_get_prepared - devm_clk_get() + clk_prepare() + * @dev: device for clock "consumer" + * @id: clock consumer ID + * + * Returns a struct clk corresponding to the clock producer, or + * valid IS_ERR() condition containing errno. The implementation + * uses @dev and @id to determine the clock consumer, and thereby + * the clock producer. (IOW, @id may be identical strings, but + * clk_get may return different clock producers depending on @dev.) + * + * The returned clk (if valid) is prepared. Drivers must however assume that the + * clock is not enabled. + * + * devm_clk_get_prepared should not be called from within interrupt context. + * + * The clock will automatically be unprepared and freed when the + * device is unbound from the bus. + */ +struct clk *devm_clk_get_prepared(struct device *dev, const char *id); + +/** + * devm_clk_get_enabled - devm_clk_get() + clk_prepare_enable() + * @dev: device for clock "consumer" + * @id: clock consumer ID + * + * Returns a struct clk corresponding to the clock producer, or valid IS_ERR() + * condition containing errno. The implementation uses @dev and @id to + * determine the clock consumer, and thereby the clock producer. (IOW, @id may + * be identical strings, but clk_get may return different clock producers + * depending on @dev.) + * + * The returned clk (if valid) is prepared and enabled. + * + * devm_clk_get_prepared should not be called from within interrupt context. + * + * The clock will automatically be disabled, unprepared and freed when the + * device is unbound from the bus. + */ +struct clk *devm_clk_get_enabled(struct device *dev, const char *id); + /** * devm_clk_get_optional - lookup and obtain a managed reference to an optional * clock producer. @@ -469,6 +510,29 @@ struct clk *devm_clk_get(struct device *dev, const char *id); */ struct clk *devm_clk_get_optional(struct device *dev, const char *id); +/** + * devm_clk_get_optional_prepared - devm_clk_get_optional() + clk_prepare() + * @dev: device for clock "consumer" + * @id: clock consumer ID + * + * Behaves the same as devm_clk_get_prepared() except where there is no clock + * producer. In this case, instead of returning -ENOENT, the function returns + * NULL. + */ +struct clk *devm_clk_get_optional_prepared(struct device *dev, const char *id); + +/** + * devm_clk_get_optional_enabled - devm_clk_get_optional() + + * clk_prepare_enable() + * @dev: device for clock "consumer" + * @id: clock consumer ID + * + * Behaves the same as devm_clk_get_enabled() except where there is no clock + * producer. In this case, instead of returning -ENOENT, the function returns + * NULL. + */ +struct clk *devm_clk_get_optional_enabled(struct device *dev, const char *id); + /** * devm_get_clk_from_child - lookup and obtain a managed reference to a * clock producer from child node. @@ -813,12 +877,36 @@ static inline struct clk *devm_clk_get(struct device *dev, const char *id) return NULL; } +static inline struct clk *devm_clk_get_prepared(struct device *dev, + const char *id) +{ + return NULL; +} + +static inline struct clk *devm_clk_get_enabled(struct device *dev, + const char *id) +{ + return NULL; +} + static inline struct clk *devm_clk_get_optional(struct device *dev, const char *id) { return NULL; } +static inline struct clk *devm_clk_get_optional_prepared(struct device *dev, + const char *id) +{ + return NULL; +} + +static inline struct clk *devm_clk_get_optional_enabled(struct device *dev, + const char *id) +{ + return NULL; +} + static inline int __must_check devm_clk_bulk_get(struct device *dev, int num_clks, struct clk_bulk_data *clks) { From patchwork Mon Mar 14 14:16:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12780263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92FC0C433EF for ; Mon, 14 Mar 2022 14:21:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FQ+NUA5Vd957Mb8blkmNaUTwoZetQWk/bkgX+JEWGUE=; b=FVeQNeKCjxKhVq o7S36aOoXLMn/C/S2lvv6Kz7kbAba4Ly+9HISTCFR2o23T64pT22nqWrjr5FjE5L2tu07ZAhJGa77 1VJ46/NCgNnkBanyYM48wdy0QLHCeZgi9jSj2UpuScDZrOyNh6aDc2oyrJdz8sIhcrspig9Ir6roL Q2P5eXMtWYQWXsHHnYSZXFW9WBGTmQbSPuzzmqAOBlcjN3Ge3BXlOE/Fwg3K/9XGjPXC5dqUelyn4 tcMXcXGUGDAN+g6sLTIDgt6Zw6BlJa9JfXLRS+R+uk8GS5zbaazcvJj6i4855Wq4b9dg6pfhziR49 82JM+Vtz6xjcxpCumwtA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlZF-005eTb-LD; Mon, 14 Mar 2022 14:21:01 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlWi-005d1l-98 for linux-amlogic@lists.infradead.org; Mon, 14 Mar 2022 14:18:26 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nTlVQ-0004zL-Eh; Mon, 14 Mar 2022 15:17:04 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1nTlVI-000f2l-Q9; Mon, 14 Mar 2022 15:16:55 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1nTlVG-0097af-Ma; Mon, 14 Mar 2022 15:16:54 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Michael Turquette , Stephen Boyd , Russell King , =?utf-8?q?Nuno_S=C3=A1?= , Jean Delvare , Guenter Roeck , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, linux-hwmon@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Matt Mackall , Herbert Xu Cc: linux-clk@vger.kernel.org, kernel@pengutronix.de, Paul Cercueil , Vladimir Zapolskiy , Heiko Stuebner , Tomislav Denis , Anand Ashok Dumbre , Michal Simek , =?utf-8?q?Andr=C3=A9_Gustavo_Nakago?= =?utf-8?q?mi_Lopez?= , Cai Huoqing , linux-iio@vger.kernel.org, Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , linux-crypto@vger.kernel.org, linux-amlogic@lists.infradead.org Subject: [PATCH v8 03/16] hwmon: Make use of devm_clk_get_enabled() Date: Mon, 14 Mar 2022 15:16:30 +0100 Message-Id: <20220314141643.22184-4-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> References: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5520; i=uwe@kleine-koenig.org; h=from:subject; bh=yoWCqkNop/4c6OeHmiSUVdq/1kzaWm1CMWom+WTtANQ=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBiL03yCpTW66mjenPvolXbHi93VsM0yzx1/1i/xg38 JATIi6SJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYi9N8gAKCRDB/BR4rcrsCQkqB/ 9PjEPh2PyWfNPLXABv6MwOZQFQlkQEqb7Uekuh33gB2X0gHncSoOfkEhvSA3yU5f1JKsoWGktEOVRg n+3bvFwDe1hNoOS5coZgZV7FTfW8NcDdt1L55ROM501f7GHgh9/VyyqTbW9Jfg108IB6GXoVFmyiA3 zdrIOdlQb2gSicQGiLiTWR0+HZModM3RWjv+KN8b3Mz5fHJdX2rt20lVLbG6aC4fgbxgl/k2GNIq7F utAI4QGzo9+Vc41UCForfyIXi/JNyyOSfFvugrXq8ze/4V3IkxdO+/DOtDfkPum8ClhrVLXZeDmngJ RvozUy0kpU8RDShp4aDvanTK0USO9z X-Developer-Key: i=uwe@kleine-koenig.org; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220314_071824_517686_43AE463F X-CRM114-Status: GOOD ( 15.52 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Several drivers manually register a devm handler to disable their clk. Convert them to devm_clk_get_enabled(). Signed-off-by: Uwe Kleine-König Acked-by: Guenter Roeck --- drivers/hwmon/axi-fan-control.c | 15 +-------------- drivers/hwmon/ltc2947-core.c | 17 +---------------- drivers/hwmon/mr75203.c | 26 +------------------------- drivers/hwmon/sparx5-temp.c | 19 +------------------ 4 files changed, 4 insertions(+), 73 deletions(-) diff --git a/drivers/hwmon/axi-fan-control.c b/drivers/hwmon/axi-fan-control.c index d2092c17d993..ce404ed9c53e 100644 --- a/drivers/hwmon/axi-fan-control.c +++ b/drivers/hwmon/axi-fan-control.c @@ -393,11 +393,6 @@ static int axi_fan_control_init(struct axi_fan_control_data *ctl, return ret; } -static void axi_fan_control_clk_disable(void *clk) -{ - clk_disable_unprepare(clk); -} - static const struct hwmon_channel_info *axi_fan_control_info[] = { HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT), HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_LABEL), @@ -477,20 +472,12 @@ static int axi_fan_control_probe(struct platform_device *pdev) if (IS_ERR(ctl->base)) return PTR_ERR(ctl->base); - clk = devm_clk_get(&pdev->dev, NULL); + clk = devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(clk)) { dev_err(&pdev->dev, "clk_get failed with %ld\n", PTR_ERR(clk)); return PTR_ERR(clk); } - ret = clk_prepare_enable(clk); - if (ret) - return ret; - - ret = devm_add_action_or_reset(&pdev->dev, axi_fan_control_clk_disable, clk); - if (ret) - return ret; - ctl->clk_rate = clk_get_rate(clk); if (!ctl->clk_rate) return -EINVAL; diff --git a/drivers/hwmon/ltc2947-core.c b/drivers/hwmon/ltc2947-core.c index 5423466de697..626f5bf2c9c7 100644 --- a/drivers/hwmon/ltc2947-core.c +++ b/drivers/hwmon/ltc2947-core.c @@ -956,13 +956,6 @@ static struct attribute *ltc2947_attrs[] = { }; ATTRIBUTE_GROUPS(ltc2947); -static void ltc2947_clk_disable(void *data) -{ - struct clk *extclk = data; - - clk_disable_unprepare(extclk); -} - static int ltc2947_setup(struct ltc2947_data *st) { int ret; @@ -989,7 +982,7 @@ static int ltc2947_setup(struct ltc2947_data *st) return ret; /* check external clock presence */ - extclk = devm_clk_get_optional(st->dev, NULL); + extclk = devm_clk_get_optional_enabled(st->dev, NULL); if (IS_ERR(extclk)) return dev_err_probe(st->dev, PTR_ERR(extclk), "Failed to get external clock\n"); @@ -1007,14 +1000,6 @@ static int ltc2947_setup(struct ltc2947_data *st) return -EINVAL; } - ret = clk_prepare_enable(extclk); - if (ret) - return ret; - - ret = devm_add_action_or_reset(st->dev, ltc2947_clk_disable, - extclk); - if (ret) - return ret; /* as in table 1 of the datasheet */ if (rate_hz >= LTC2947_CLK_MIN && rate_hz <= 1000000) pre = 0; diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 1ba1e3145969..0c691f291a64 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -461,24 +461,6 @@ static int pvt_get_regmap(struct platform_device *pdev, char *reg_name, return 0; } -static void pvt_clk_disable(void *data) -{ - struct pvt_device *pvt = data; - - clk_disable_unprepare(pvt->clk); -} - -static int pvt_clk_enable(struct device *dev, struct pvt_device *pvt) -{ - int ret; - - ret = clk_prepare_enable(pvt->clk); - if (ret) - return ret; - - return devm_add_action_or_reset(dev, pvt_clk_disable, pvt); -} - static void pvt_reset_control_assert(void *data) { struct pvt_device *pvt = data; @@ -515,16 +497,10 @@ static int mr75203_probe(struct platform_device *pdev) if (ret) return ret; - pvt->clk = devm_clk_get(dev, NULL); + pvt->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(pvt->clk)) return dev_err_probe(dev, PTR_ERR(pvt->clk), "failed to get clock\n"); - ret = pvt_clk_enable(dev, pvt); - if (ret) { - dev_err(dev, "failed to enable clock\n"); - return ret; - } - pvt->rst = devm_reset_control_get_exclusive(dev, NULL); if (IS_ERR(pvt->rst)) return dev_err_probe(dev, PTR_ERR(pvt->rst), diff --git a/drivers/hwmon/sparx5-temp.c b/drivers/hwmon/sparx5-temp.c index 98be48e3a22a..04fd8505e5d6 100644 --- a/drivers/hwmon/sparx5-temp.c +++ b/drivers/hwmon/sparx5-temp.c @@ -26,13 +26,6 @@ struct s5_hwmon { struct clk *clk; }; -static void s5_temp_clk_disable(void *data) -{ - struct clk *clk = data; - - clk_disable_unprepare(clk); -} - static void s5_temp_enable(struct s5_hwmon *hwmon) { u32 val = readl(hwmon->base + TEMP_CFG); @@ -113,7 +106,6 @@ static int s5_temp_probe(struct platform_device *pdev) { struct device *hwmon_dev; struct s5_hwmon *hwmon; - int ret; hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); if (!hwmon) @@ -123,19 +115,10 @@ static int s5_temp_probe(struct platform_device *pdev) if (IS_ERR(hwmon->base)) return PTR_ERR(hwmon->base); - hwmon->clk = devm_clk_get(&pdev->dev, NULL); + hwmon->clk = devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(hwmon->clk)) return PTR_ERR(hwmon->clk); - ret = clk_prepare_enable(hwmon->clk); - if (ret) - return ret; - - ret = devm_add_action_or_reset(&pdev->dev, s5_temp_clk_disable, - hwmon->clk); - if (ret) - return ret; - s5_temp_enable(hwmon); hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, From patchwork Mon Mar 14 14:16:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12780218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D31C9C433FE for ; Mon, 14 Mar 2022 14:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OA31jcvbOgSYyxxooBdYn8RRA3bNG0RPed4Y5aC81gE=; b=Ce+QK4HViEpTgC RyKJTkKKjkvvgs8BB3nXU6oEMk5601wvF8yPWW0SrZNP1fQ29Ymbsh6F2whLY3eyofvrzmoTm2frm mBy/GpbF2523T1DkhilqMgq0Io8IhjEAw410VH2rxKGfKVMMTCHDmo3KaG1JAd02gbBKs0NFXXYF3 tl6Gtj0ZMUBBmL67VOmv0vib0MBguDPqClvuKshRf38trb5ZETuPnzGZD6ujfawpl5p0G/4k8sDw2 LAX6HzfhCG5fW34jn2uNyZKLg9SdrfzmRLAFvIWU5jj3W652V0qsvxXD5frmNU6Cebo+OEc45CkES t/2sh+Szq1xBtnALYEMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlXB-005dHA-16; Mon, 14 Mar 2022 14:18:53 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlVk-005cdN-HC for linux-amlogic@lists.infradead.org; Mon, 14 Mar 2022 14:17:26 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nTlVL-0004zT-8j; Mon, 14 Mar 2022 15:16:59 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1nTlVL-000f2z-Gx; Mon, 14 Mar 2022 15:16:58 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1nTlVJ-0097ao-2C; Mon, 14 Mar 2022 15:16:57 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Michael Turquette , Stephen Boyd , Russell King , Matt Mackall , Herbert Xu Cc: linux-clk@vger.kernel.org, kernel@pengutronix.de, Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org Subject: [PATCH v8 05/16] hwrng: meson - Don't open-code devm_clk_get_optional_enabled() Date: Mon, 14 Mar 2022 15:16:32 +0100 Message-Id: <20220314141643.22184-6-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> References: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1735; i=uwe@kleine-koenig.org; h=from:subject; bh=bfqnxylPnbbJXe+3GBtwLYLgZPhd+qJZuw2RI3jILYE=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBiL035AdG35VtGykFXO3us1e4Qyfe85laP1NXWH96B J/ooUYmJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYi9N+QAKCRDB/BR4rcrsCaXiCA CYQFfcviJ8XTZvDwlKW0nOhnqK5pTk5a0ilSqlNkH2f7pbLRUYz1rMgQTnxyx4mfi2x7jHSUvQ80ZT XrlFiSMUGotXPWPSjAUJtt/ZB9qpJIkDJquiChcWWfqfB93qxX7eOCzqjmM/C3k/uibRqKM6E2qaKK kEmkOLoBVbmGMXAlti6yjPpMx+ObbWu4w1cwFw1pLAaCuq8fgXcIjhi95Q/7JfLu+gadS6zU5a44LZ Eqie89qMyY4R8y4ZcWGjy+UHyrWlXdQ3RxglzdRGZHT3wAZb+gFSUfxq+FyiKjlwfM8XheHVut3VVz P3sPTI8D/NFV8C+7vxPxHB1zuDfQqZ X-Developer-Key: i=uwe@kleine-koenig.org; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220314_071724_603970_12ED9320 X-CRM114-Status: GOOD ( 12.53 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org devm_clk_get_enabled() returns a clock prepared and enabled and already registers a devm exit handler to disable (and unprepare) the clock. Signed-off-by: Uwe Kleine-König Acked-by: Neil Armstrong --- drivers/char/hw_random/meson-rng.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/drivers/char/hw_random/meson-rng.c b/drivers/char/hw_random/meson-rng.c index 8bb30282ca46..06db5a93e257 100644 --- a/drivers/char/hw_random/meson-rng.c +++ b/drivers/char/hw_random/meson-rng.c @@ -33,16 +33,10 @@ static int meson_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) return sizeof(u32); } -static void meson_rng_clk_disable(void *data) -{ - clk_disable_unprepare(data); -} - static int meson_rng_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct meson_rng_data *data; - int ret; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -54,20 +48,10 @@ static int meson_rng_probe(struct platform_device *pdev) if (IS_ERR(data->base)) return PTR_ERR(data->base); - data->core_clk = devm_clk_get_optional(dev, "core"); + data->core_clk = devm_clk_get_optional_enabled(dev, "core"); if (IS_ERR(data->core_clk)) return dev_err_probe(dev, PTR_ERR(data->core_clk), - "Failed to get core clock\n"); - - if (data->core_clk) { - ret = clk_prepare_enable(data->core_clk); - if (ret) - return ret; - ret = devm_add_action_or_reset(dev, meson_rng_clk_disable, - data->core_clk); - if (ret) - return ret; - } + "Failed to get enabled core clock\n"); data->rng.name = pdev->name; data->rng.read = meson_rng_read; From patchwork Mon Mar 14 14:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12780217 X-Patchwork-Delegate: neil.armstrong@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2575C4332F for ; Mon, 14 Mar 2022 14:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AXk3MeXAZ00+4DYPIP4IIr9Ca7SzroePrZotFYskb2I=; b=od8Y17DnWtswIO 8apHpgYa20xYEaHE15ZlGnmDriXIljkZfqz7wwleFwngf5wFWgCMHSG3FJj3ZkJTFprH24qI3I1yM KLXbVLkRbVMesc/Bqicpzt1vqODdo5p1lVDeLkoYJhdV886oJHTNDJOSDB0tgcUc14RnGVh6Wk4Mv XI2JWKbLxVA9lIvkoltMJTfSkgLmivJTL0HKFfPuZu77QX6Idulg+Orlu1Hon3hGtm1Mjvf4Kdreg twGijFq6uom1TZDVKdW7U3Bjp8c8bpKSz2erfAE+RCVlzz1DVzijdzkGEf7paa8MYl5hwx7uud1S/ +mH7NyXHziVgZ1iKXP8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlW1-005ciw-D3; Mon, 14 Mar 2022 14:17:41 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlVZ-005cZ5-3a for linux-amlogic@lists.infradead.org; Mon, 14 Mar 2022 14:17:14 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nTlVL-0004zV-JM; Mon, 14 Mar 2022 15:16:59 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1nTlVL-000f35-Nf; Mon, 14 Mar 2022 15:16:58 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1nTlVJ-0097ay-KN; Mon, 14 Mar 2022 15:16:57 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Michael Turquette , Stephen Boyd , Russell King , Neil Armstrong , David Airlie , Daniel Vetter , Kevin Hilman , Jerome Brunet , Martin Blumenstingl Cc: linux-clk@vger.kernel.org, kernel@pengutronix.de, dri-devel@lists.freedesktop.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 08/16] drm/meson: dw-hdmi: Don't open code devm_clk_get_enabled() Date: Mon, 14 Mar 2022 15:16:35 +0100 Message-Id: <20220314141643.22184-9-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> References: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2666; i=uwe@kleine-koenig.org; h=from:subject; bh=YhET4fR0Omj8gJ/JCkSwUJxwvBYawy9/DlBkkMAAnOI=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBiL04EyEHJOItayKHmew1fSM2xmrHq4+SWHnqUOQnS kKp0Dr2JATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYi9OBAAKCRDB/BR4rcrsCddkCA CAisftWSdUNCnYOFUA6r4wIsgWzLZYQ396YWYMZkQQBC6DXAThdrh1a/WIy8BEpr3wbFQNBL2loko5 kJ2p6cWyeNYDVeKT7iRuClSG8JnvWw55qDtphq6pz4SQXK2Un3STKZc26NxmIoln93Yg+qfevK5WnG ydjVSz0wApZ769rEmeP45xTHd7rRYDiXWw4GeEeTvBR/alJGPVrpp2K6QqWMdJpae2GsFFRpULtrJe fSHYK6Yo5jEbhgaIu47FXZkBYBWfygDwv/BVwA3xd5S5kHHm+RAjQ0dodEJ8I/Rr9LbHYit2s4f5Je H3fc37FLniTUu0zu464M9/qguAsgrO X-Developer-Key: i=uwe@kleine-koenig.org; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220314_071713_175935_8C2F3018 X-CRM114-Status: GOOD ( 15.04 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org devm_clk_get_enabled() returns a clock prepared and enabled and already registers a devm exit handler to disable (and unprepare) the clock. There is slight change in behavior as a failure to enable the clock now results in an error message, too. Also the actual error code is added to the message. Signed-off-by: Uwe Kleine-König Acked-by: Neil Armstrong --- drivers/gpu/drm/meson/meson_dw_hdmi.c | 48 +++++++++------------------ 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/meson/meson_dw_hdmi.c b/drivers/gpu/drm/meson/meson_dw_hdmi.c index 5cd2b2ebbbd3..6034e80c5b2e 100644 --- a/drivers/gpu/drm/meson/meson_dw_hdmi.c +++ b/drivers/gpu/drm/meson/meson_dw_hdmi.c @@ -670,29 +670,6 @@ static void meson_disable_regulator(void *data) regulator_disable(data); } -static void meson_disable_clk(void *data) -{ - clk_disable_unprepare(data); -} - -static int meson_enable_clk(struct device *dev, char *name) -{ - struct clk *clk; - int ret; - - clk = devm_clk_get(dev, name); - if (IS_ERR(clk)) { - dev_err(dev, "Unable to get %s pclk\n", name); - return PTR_ERR(clk); - } - - ret = clk_prepare_enable(clk); - if (!ret) - ret = devm_add_action_or_reset(dev, meson_disable_clk, clk); - - return ret; -} - static int meson_dw_hdmi_bind(struct device *dev, struct device *master, void *data) { @@ -702,6 +679,7 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master, struct drm_device *drm = data; struct meson_drm *priv = drm->dev_private; struct dw_hdmi_plat_data *dw_plat_data; + struct clk *clk; int irq; int ret; @@ -763,17 +741,23 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master, if (IS_ERR(meson_dw_hdmi->hdmitx)) return PTR_ERR(meson_dw_hdmi->hdmitx); - ret = meson_enable_clk(dev, "isfr"); - if (ret) - return ret; + clk = devm_clk_get_enabled(dev, "isfr"); + if (IS_ERR(clk)) { + dev_err(dev, "Failed to get enabled isfr pclk (%pe)\n", clk); + return PTR_ERR(clk); + } - ret = meson_enable_clk(dev, "iahb"); - if (ret) - return ret; + clk = devm_clk_get_enabled(dev, "iahb"); + if (IS_ERR(clk)) { + dev_err(dev, "Failed to get enabled iahb pclk (%pe)\n", clk); + return PTR_ERR(clk); + } - ret = meson_enable_clk(dev, "venci"); - if (ret) - return ret; + clk = devm_clk_get_enabled(dev, "venci"); + if (IS_ERR(clk)) { + dev_err(dev, "Failed to get enabled venci pclk (%pe)\n", clk); + return PTR_ERR(clk); + } dw_plat_data->regm = devm_regmap_init(dev, NULL, meson_dw_hdmi, &meson_dw_hdmi_regmap_config); From patchwork Mon Mar 14 14:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12780216 X-Patchwork-Delegate: neil.armstrong@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2549C433FE for ; Mon, 14 Mar 2022 14:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=W/1EIvlMmRX/zRFlpejZMxTz0OLOFuOcREjrFbb+MXA=; b=el4B2xuFNhxPjJ pweXy0ZjQk8bgHw9raY8+sxuSgGcpcj4G1vjZnXpjB3VVdop3zU4tiFfS0aAJULOHXJvuV/ZOWIEH sUYi7rJLCgq5LxT45oPs/fFeQj4wEo6EPi4fIrjaMu979ag8XiNZu8X8HHs/8igcnA4R/70cnLRKA ekBUu7EZ9Ui0EsTbhLiTdFwDUngSORNTt9TesYwduH64t90e/7c+YAu+3jJhoHcIWPYEcvcT4G5Wy Xwa31ZrDpJqX3Sx9kyib3daehYrF81dlsSHjvIYX9rWXzJSNejbbptPtedogHJZyCGbRNVH/hG7Go wzOe1K/Mqva7iFVYOJ+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlW0-005ciM-It; Mon, 14 Mar 2022 14:17:40 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlVX-005cYF-BU for linux-amlogic@lists.infradead.org; Mon, 14 Mar 2022 14:17:13 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nTlVM-00050A-2Z; Mon, 14 Mar 2022 15:17:00 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1nTlVM-000f3E-Kq; Mon, 14 Mar 2022 15:16:59 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1nTlVK-0097bA-H4; Mon, 14 Mar 2022 15:16:58 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Michael Turquette , Stephen Boyd , Russell King , Neil Armstrong , Jerome Brunet , Kevin Hilman , Martin Blumenstingl Cc: linux-clk@vger.kernel.org, kernel@pengutronix.de, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 10/16] clk: meson: axg-audio: Don't duplicate devm_clk_get_enabled() Date: Mon, 14 Mar 2022 15:16:37 +0100 Message-Id: <20220314141643.22184-11-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> References: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1899; i=uwe@kleine-koenig.org; h=from:subject; bh=ifDCWLNWOL0YsD190lDHgYWEgpILJPKuKKXrEJE9+6k=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBiL04L4e9IWDji46EkjNnzAhHVqLKQME2Cj5ZGNUdC xgjHkqmJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYi9OCwAKCRDB/BR4rcrsCaRsB/ 4lw+anORVBYqdBZWfiCRFFXRQ1s91OC7WxPcmn0FjB9HAVMFy2dbkDyj6f0nmTf+yUwEGrDTPZOFJN sm4dQ6knZvNGSweqsOAOLHFzuLkqcEE4Q25ruO0NF7Lvc6zA276x7VDCocmn7B8oKPg2+sITuo7qcW l6GpEHjwOvtN+FrW61a/R97V0S9wv6Ko0ZkN43U5h5uQsgt1hGo3JjZEf2wLOMIgq+MDqlMu8Fd7fC 88wZVw9dR6TsrgMSkJrdXY/2ykuniA9i3TmaWCIZ0qIc9Sa5tOp2sw1MqXJaX1blBcXqn4Kw5x5lZy U5SXida2sOuLdzEBzT18QLzS/ce2Dc X-Developer-Key: i=uwe@kleine-koenig.org; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220314_071711_416083_D12E4C95 X-CRM114-Status: GOOD ( 14.60 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org The clk API recently got a function with a slightly different name and the same functionality. Remove the duplication. Signed-off-by: Uwe Kleine-König --- drivers/clk/meson/axg-audio.c | 36 ++++------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/drivers/clk/meson/axg-audio.c b/drivers/clk/meson/axg-audio.c index bfe36bd41339..5016682e47c8 100644 --- a/drivers/clk/meson/axg-audio.c +++ b/drivers/clk/meson/axg-audio.c @@ -1657,35 +1657,6 @@ static struct clk_regmap *const sm1_clk_regmaps[] = { &sm1_sysclk_b_en, }; -static int devm_clk_get_enable(struct device *dev, char *id) -{ - struct clk *clk; - int ret; - - clk = devm_clk_get(dev, id); - if (IS_ERR(clk)) { - ret = PTR_ERR(clk); - dev_err_probe(dev, ret, "failed to get %s", id); - return ret; - } - - ret = clk_prepare_enable(clk); - if (ret) { - dev_err(dev, "failed to enable %s", id); - return ret; - } - - ret = devm_add_action_or_reset(dev, - (void(*)(void *))clk_disable_unprepare, - clk); - if (ret) { - dev_err(dev, "failed to add reset action on %s", id); - return ret; - } - - return 0; -} - struct axg_audio_reset_data { struct reset_controller_dev rstc; struct regmap *map; @@ -1787,6 +1758,7 @@ static int axg_audio_clkc_probe(struct platform_device *pdev) struct regmap *map; void __iomem *regs; struct clk_hw *hw; + struct clk *clk; int ret, i; data = of_device_get_match_data(dev); @@ -1804,9 +1776,9 @@ static int axg_audio_clkc_probe(struct platform_device *pdev) } /* Get the mandatory peripheral clock */ - ret = devm_clk_get_enable(dev, "pclk"); - if (ret) - return ret; + clk = devm_clk_get_enabled(dev, "pclk"); + if (IS_ERR(clk)) + return PTR_ERR(clk); ret = device_reset(dev); if (ret) { From patchwork Mon Mar 14 14:16:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 12780219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4825CC433EF for ; Mon, 14 Mar 2022 14:19:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SskEh6MetTWlpmIUG9THvC/uGxRQ20D4iE5/B4tjzlg=; b=wswbE2TNo1M9vQ hzAdzcBPhhfWlbgzJR2CQx1tb5RZ+t9lNKGOM/ihNT71IEpqSYWtr5qSbpyoDcQF/ZPcAyfn4AD6A +j+c/V9iTE+h0M2s28APym5T7RNr/isz09EgfPy4kXGxz7Jjq7G55MJfD9qh+q4npeJ3kpcTzC6p+ 5VgBHucBndYxqWdOsHABDswtZGPenYL0GTCH14gFcBCswErXAQ7WVEutma5CbotCR87dRUt41ah/X vQqKsO6ofceMhmc9qDyL9eL2sih+xEUikegGzbNxMb7Ds7YXF6zfcLdG2tvzHfnGa90dM1JVchDeZ VBhQVwAnErKUyo2gwS0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlXd-005dYr-SW; Mon, 14 Mar 2022 14:19:21 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nTlVr-005cfi-Lq for linux-amlogic@lists.infradead.org; Mon, 14 Mar 2022 14:17:35 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nTlVQ-00050t-Iu; Mon, 14 Mar 2022 15:17:04 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1nTlVN-000f3O-FH; Mon, 14 Mar 2022 15:17:00 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1nTlVL-0097bD-6i; Mon, 14 Mar 2022 15:16:59 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Michael Turquette , Stephen Boyd , Russell King , Wim Van Sebroeck , Guenter Roeck Cc: linux-clk@vger.kernel.org, kernel@pengutronix.de, Shawn Guo , Fabio Estevam , NXP Linux Team , Keguang Zhang , Vladimir Zapolskiy , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Michal Simek , Andy Gross , Bjorn Andersson , Patrice Chotard , Maxime Coquelin , Alexandre Torgue , Nobuhiro Iwamatsu , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH v8 11/16] watchdog: Make use of devm_clk_get_enabled() Date: Mon, 14 Mar 2022 15:16:38 +0100 Message-Id: <20220314141643.22184-12-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> References: <20220314141643.22184-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=23797; i=uwe@kleine-koenig.org; h=from:subject; bh=z57t7hxiRb0NTIAkiUMcqO0E2/a/jQQAqPgx8u7xqp0=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBiL04OjJ1FYttOI7EmFq+M+HzPZrVVsUCPl4DrTTRp LASeDoCJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYi9ODgAKCRDB/BR4rcrsCVb5B/ oCGFESVzd5j1J6vbnXf8xVUoGYb6wv7mg2MmYMQpOfZOBE+HC6QiVcPTE8UrrpQrMZ7Q3kyzwgKhFD VFr0JrkdljITIRjQbGiP1/nhZ9HxvZylfahRcUn3RkjI7UGpqY3numSTZD2K/+SOWXygT2r/v38aXW y4gtNsNOMki+77Z1AZ33n73l3r+4Ijwvh5Trbyaphb197zfnp43MUyQ2HxvBWtyeepS/2Qd6jfLwxP 64U0fzNNhCMfAihV+UWK1ORTzh1Zrp7WRDUiiOnd2p0XFjw+Q0QR2lk6iNtsPnE2XDvO24vkd5WwHe E6+1UtteAyud51zR+4hhlBhgDqHYVa X-Developer-Key: i=uwe@kleine-koenig.org; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220314_071732_139792_DFA914CC X-CRM114-Status: GOOD ( 14.99 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Several drivers manually register a devm handler to disable their clk. Convert them to devm_clk_get_enabled(). Signed-off-by: Uwe Kleine-König Acked-by: Guenter Roeck --- drivers/watchdog/cadence_wdt.c | 17 +---------------- drivers/watchdog/davinci_wdt.c | 18 +----------------- drivers/watchdog/imgpdc_wdt.c | 31 +++---------------------------- drivers/watchdog/imx2_wdt.c | 15 +-------------- drivers/watchdog/imx7ulp_wdt.c | 15 +-------------- drivers/watchdog/loongson1_wdt.c | 17 +---------------- drivers/watchdog/lpc18xx_wdt.c | 30 ++---------------------------- drivers/watchdog/meson_gxbb_wdt.c | 16 +--------------- drivers/watchdog/of_xilinx_wdt.c | 16 +--------------- drivers/watchdog/pic32-dmt.c | 15 +-------------- drivers/watchdog/pic32-wdt.c | 17 +---------------- drivers/watchdog/pnx4008_wdt.c | 15 +-------------- drivers/watchdog/qcom-wdt.c | 16 +--------------- drivers/watchdog/rtd119x_wdt.c | 16 +--------------- drivers/watchdog/st_lpc_wdt.c | 16 +--------------- drivers/watchdog/stm32_iwdg.c | 31 ++----------------------------- drivers/watchdog/visconti_wdt.c | 18 +----------------- 17 files changed, 21 insertions(+), 298 deletions(-) diff --git a/drivers/watchdog/cadence_wdt.c b/drivers/watchdog/cadence_wdt.c index bc99e9164930..23d41043863f 100644 --- a/drivers/watchdog/cadence_wdt.c +++ b/drivers/watchdog/cadence_wdt.c @@ -274,11 +274,6 @@ static const struct watchdog_ops cdns_wdt_ops = { .set_timeout = cdns_wdt_settimeout, }; -static void cdns_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - /************************Platform Operations*****************************/ /** * cdns_wdt_probe - Probe call for the device. @@ -333,21 +328,11 @@ static int cdns_wdt_probe(struct platform_device *pdev) watchdog_stop_on_reboot(cdns_wdt_device); watchdog_set_drvdata(cdns_wdt_device, wdt); - wdt->clk = devm_clk_get(dev, NULL); + wdt->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(wdt->clk)) return dev_err_probe(dev, PTR_ERR(wdt->clk), "input clock not found\n"); - ret = clk_prepare_enable(wdt->clk); - if (ret) { - dev_err(dev, "unable to enable clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, cdns_clk_disable_unprepare, - wdt->clk); - if (ret) - return ret; - clock_f = clk_get_rate(wdt->clk); if (clock_f <= CDNS_WDT_CLK_75MHZ) { wdt->prescaler = CDNS_WDT_PRESCALE_512; diff --git a/drivers/watchdog/davinci_wdt.c b/drivers/watchdog/davinci_wdt.c index 584a56893b81..5f2184bda7b2 100644 --- a/drivers/watchdog/davinci_wdt.c +++ b/drivers/watchdog/davinci_wdt.c @@ -189,14 +189,8 @@ static const struct watchdog_ops davinci_wdt_ops = { .restart = davinci_wdt_restart, }; -static void davinci_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int davinci_wdt_probe(struct platform_device *pdev) { - int ret = 0; struct device *dev = &pdev->dev; struct watchdog_device *wdd; struct davinci_wdt_device *davinci_wdt; @@ -205,21 +199,11 @@ static int davinci_wdt_probe(struct platform_device *pdev) if (!davinci_wdt) return -ENOMEM; - davinci_wdt->clk = devm_clk_get(dev, NULL); + davinci_wdt->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(davinci_wdt->clk)) return dev_err_probe(dev, PTR_ERR(davinci_wdt->clk), "failed to get clock node\n"); - ret = clk_prepare_enable(davinci_wdt->clk); - if (ret) { - dev_err(dev, "failed to prepare clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, davinci_clk_disable_unprepare, - davinci_wdt->clk); - if (ret) - return ret; - platform_set_drvdata(pdev, davinci_wdt); wdd = &davinci_wdt->wdd; diff --git a/drivers/watchdog/imgpdc_wdt.c b/drivers/watchdog/imgpdc_wdt.c index b57ff3787052..a55f801895d4 100644 --- a/drivers/watchdog/imgpdc_wdt.c +++ b/drivers/watchdog/imgpdc_wdt.c @@ -175,16 +175,11 @@ static const struct watchdog_ops pdc_wdt_ops = { .restart = pdc_wdt_restart, }; -static void pdc_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int pdc_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; u64 div; - int ret, val; + int val; unsigned long clk_rate; struct pdc_wdt_dev *pdc_wdt; @@ -196,38 +191,18 @@ static int pdc_wdt_probe(struct platform_device *pdev) if (IS_ERR(pdc_wdt->base)) return PTR_ERR(pdc_wdt->base); - pdc_wdt->sys_clk = devm_clk_get(dev, "sys"); + pdc_wdt->sys_clk = devm_clk_get_enabled(dev, "sys"); if (IS_ERR(pdc_wdt->sys_clk)) { dev_err(dev, "failed to get the sys clock\n"); return PTR_ERR(pdc_wdt->sys_clk); } - pdc_wdt->wdt_clk = devm_clk_get(dev, "wdt"); + pdc_wdt->wdt_clk = devm_clk_get_enabled(dev, "wdt"); if (IS_ERR(pdc_wdt->wdt_clk)) { dev_err(dev, "failed to get the wdt clock\n"); return PTR_ERR(pdc_wdt->wdt_clk); } - ret = clk_prepare_enable(pdc_wdt->sys_clk); - if (ret) { - dev_err(dev, "could not prepare or enable sys clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, pdc_clk_disable_unprepare, - pdc_wdt->sys_clk); - if (ret) - return ret; - - ret = clk_prepare_enable(pdc_wdt->wdt_clk); - if (ret) { - dev_err(dev, "could not prepare or enable wdt clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, pdc_clk_disable_unprepare, - pdc_wdt->wdt_clk); - if (ret) - return ret; - /* We use the clock rate to calculate the max timeout */ clk_rate = clk_get_rate(pdc_wdt->wdt_clk); if (clk_rate == 0) { diff --git a/drivers/watchdog/imx2_wdt.c b/drivers/watchdog/imx2_wdt.c index 51bfb796898b..273d720588bf 100644 --- a/drivers/watchdog/imx2_wdt.c +++ b/drivers/watchdog/imx2_wdt.c @@ -248,11 +248,6 @@ static const struct regmap_config imx2_wdt_regmap_config = { .max_register = 0x8, }; -static void imx2_wdt_action(void *data) -{ - clk_disable_unprepare(data); -} - static int __init imx2_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -277,7 +272,7 @@ static int __init imx2_wdt_probe(struct platform_device *pdev) return PTR_ERR(wdev->regmap); } - wdev->clk = devm_clk_get(dev, NULL); + wdev->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(wdev->clk)) { dev_err(dev, "can't get Watchdog clock\n"); return PTR_ERR(wdev->clk); @@ -297,14 +292,6 @@ static int __init imx2_wdt_probe(struct platform_device *pdev) dev_name(dev), wdog)) wdog->info = &imx2_wdt_pretimeout_info; - ret = clk_prepare_enable(wdev->clk); - if (ret) - return ret; - - ret = devm_add_action_or_reset(dev, imx2_wdt_action, wdev->clk); - if (ret) - return ret; - wdev->clk_is_on = true; regmap_read(wdev->regmap, IMX2_WDT_WRSR, &val); diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c index 922b60374295..61517abf2dba 100644 --- a/drivers/watchdog/imx7ulp_wdt.c +++ b/drivers/watchdog/imx7ulp_wdt.c @@ -200,11 +200,6 @@ static int imx7ulp_wdt_init(void __iomem *base, unsigned int timeout) return ret; } -static void imx7ulp_wdt_action(void *data) -{ - clk_disable_unprepare(data); -} - static int imx7ulp_wdt_probe(struct platform_device *pdev) { struct imx7ulp_wdt_device *imx7ulp_wdt; @@ -222,20 +217,12 @@ static int imx7ulp_wdt_probe(struct platform_device *pdev) if (IS_ERR(imx7ulp_wdt->base)) return PTR_ERR(imx7ulp_wdt->base); - imx7ulp_wdt->clk = devm_clk_get(dev, NULL); + imx7ulp_wdt->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(imx7ulp_wdt->clk)) { dev_err(dev, "Failed to get watchdog clock\n"); return PTR_ERR(imx7ulp_wdt->clk); } - ret = clk_prepare_enable(imx7ulp_wdt->clk); - if (ret) - return ret; - - ret = devm_add_action_or_reset(dev, imx7ulp_wdt_action, imx7ulp_wdt->clk); - if (ret) - return ret; - wdog = &imx7ulp_wdt->wdd; wdog->info = &imx7ulp_wdt_info; wdog->ops = &imx7ulp_wdt_ops; diff --git a/drivers/watchdog/loongson1_wdt.c b/drivers/watchdog/loongson1_wdt.c index bb3d075c0633..c55656cfb403 100644 --- a/drivers/watchdog/loongson1_wdt.c +++ b/drivers/watchdog/loongson1_wdt.c @@ -79,11 +79,6 @@ static const struct watchdog_ops ls1x_wdt_ops = { .set_timeout = ls1x_wdt_set_timeout, }; -static void ls1x_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int ls1x_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -100,20 +95,10 @@ static int ls1x_wdt_probe(struct platform_device *pdev) if (IS_ERR(drvdata->base)) return PTR_ERR(drvdata->base); - drvdata->clk = devm_clk_get(dev, pdev->name); + drvdata->clk = devm_clk_get_enabled(dev, pdev->name); if (IS_ERR(drvdata->clk)) return PTR_ERR(drvdata->clk); - err = clk_prepare_enable(drvdata->clk); - if (err) { - dev_err(dev, "clk enable failed\n"); - return err; - } - err = devm_add_action_or_reset(dev, ls1x_clk_disable_unprepare, - drvdata->clk); - if (err) - return err; - clk_rate = clk_get_rate(drvdata->clk); if (!clk_rate) return -EINVAL; diff --git a/drivers/watchdog/lpc18xx_wdt.c b/drivers/watchdog/lpc18xx_wdt.c index 60b6d74f267d..1b9b5f21a0df 100644 --- a/drivers/watchdog/lpc18xx_wdt.c +++ b/drivers/watchdog/lpc18xx_wdt.c @@ -197,16 +197,10 @@ static const struct watchdog_ops lpc18xx_wdt_ops = { .restart = lpc18xx_wdt_restart, }; -static void lpc18xx_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int lpc18xx_wdt_probe(struct platform_device *pdev) { struct lpc18xx_wdt_dev *lpc18xx_wdt; struct device *dev = &pdev->dev; - int ret; lpc18xx_wdt = devm_kzalloc(dev, sizeof(*lpc18xx_wdt), GFP_KERNEL); if (!lpc18xx_wdt) @@ -216,38 +210,18 @@ static int lpc18xx_wdt_probe(struct platform_device *pdev) if (IS_ERR(lpc18xx_wdt->base)) return PTR_ERR(lpc18xx_wdt->base); - lpc18xx_wdt->reg_clk = devm_clk_get(dev, "reg"); + lpc18xx_wdt->reg_clk = devm_clk_get_enabled(dev, "reg"); if (IS_ERR(lpc18xx_wdt->reg_clk)) { dev_err(dev, "failed to get the reg clock\n"); return PTR_ERR(lpc18xx_wdt->reg_clk); } - lpc18xx_wdt->wdt_clk = devm_clk_get(dev, "wdtclk"); + lpc18xx_wdt->wdt_clk = devm_clk_get_enabled(dev, "wdtclk"); if (IS_ERR(lpc18xx_wdt->wdt_clk)) { dev_err(dev, "failed to get the wdt clock\n"); return PTR_ERR(lpc18xx_wdt->wdt_clk); } - ret = clk_prepare_enable(lpc18xx_wdt->reg_clk); - if (ret) { - dev_err(dev, "could not prepare or enable sys clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, lpc18xx_clk_disable_unprepare, - lpc18xx_wdt->reg_clk); - if (ret) - return ret; - - ret = clk_prepare_enable(lpc18xx_wdt->wdt_clk); - if (ret) { - dev_err(dev, "could not prepare or enable wdt clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, lpc18xx_clk_disable_unprepare, - lpc18xx_wdt->wdt_clk); - if (ret) - return ret; - /* We use the clock rate to calculate timeouts */ lpc18xx_wdt->clk_rate = clk_get_rate(lpc18xx_wdt->wdt_clk); if (lpc18xx_wdt->clk_rate == 0) { diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c index d3c9e2f6e63b..cf65d096f3c0 100644 --- a/drivers/watchdog/meson_gxbb_wdt.c +++ b/drivers/watchdog/meson_gxbb_wdt.c @@ -146,16 +146,10 @@ static const struct of_device_id meson_gxbb_wdt_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, meson_gxbb_wdt_dt_ids); -static void meson_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int meson_gxbb_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct meson_gxbb_wdt *data; - int ret; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -165,18 +159,10 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev) if (IS_ERR(data->reg_base)) return PTR_ERR(data->reg_base); - data->clk = devm_clk_get(dev, NULL); + data->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(data->clk)) return PTR_ERR(data->clk); - ret = clk_prepare_enable(data->clk); - if (ret) - return ret; - ret = devm_add_action_or_reset(dev, meson_clk_disable_unprepare, - data->clk); - if (ret) - return ret; - platform_set_drvdata(pdev, data); data->wdt_dev.parent = dev; diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c index 3318544366b8..2a079ca04aa3 100644 --- a/drivers/watchdog/of_xilinx_wdt.c +++ b/drivers/watchdog/of_xilinx_wdt.c @@ -154,11 +154,6 @@ static u32 xwdt_selftest(struct xwdt_device *xdev) return XWT_TIMER_FAILED; } -static void xwdt_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int xwdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -193,7 +188,7 @@ static int xwdt_probe(struct platform_device *pdev) watchdog_set_nowayout(xilinx_wdt_wdd, enable_once); - xdev->clk = devm_clk_get(dev, NULL); + xdev->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(xdev->clk)) { if (PTR_ERR(xdev->clk) != -ENOENT) return PTR_ERR(xdev->clk); @@ -211,15 +206,6 @@ static int xwdt_probe(struct platform_device *pdev) "The watchdog clock freq cannot be obtained\n"); } else { pfreq = clk_get_rate(xdev->clk); - rc = clk_prepare_enable(xdev->clk); - if (rc) { - dev_err(dev, "unable to enable clock\n"); - return rc; - } - rc = devm_add_action_or_reset(dev, xwdt_clk_disable_unprepare, - xdev->clk); - if (rc) - return rc; } /* diff --git a/drivers/watchdog/pic32-dmt.c b/drivers/watchdog/pic32-dmt.c index f43062b3c4c8..bc4ccddc75a3 100644 --- a/drivers/watchdog/pic32-dmt.c +++ b/drivers/watchdog/pic32-dmt.c @@ -164,11 +164,6 @@ static struct watchdog_device pic32_dmt_wdd = { .ops = &pic32_dmt_fops, }; -static void pic32_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int pic32_dmt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -184,20 +179,12 @@ static int pic32_dmt_probe(struct platform_device *pdev) if (IS_ERR(dmt->regs)) return PTR_ERR(dmt->regs); - dmt->clk = devm_clk_get(dev, NULL); + dmt->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(dmt->clk)) { dev_err(dev, "clk not found\n"); return PTR_ERR(dmt->clk); } - ret = clk_prepare_enable(dmt->clk); - if (ret) - return ret; - ret = devm_add_action_or_reset(dev, pic32_clk_disable_unprepare, - dmt->clk); - if (ret) - return ret; - wdd->timeout = pic32_dmt_get_timeout_secs(dmt); if (!wdd->timeout) { dev_err(dev, "failed to read watchdog register timeout\n"); diff --git a/drivers/watchdog/pic32-wdt.c b/drivers/watchdog/pic32-wdt.c index 41715d68d9e9..6d1a00222991 100644 --- a/drivers/watchdog/pic32-wdt.c +++ b/drivers/watchdog/pic32-wdt.c @@ -162,11 +162,6 @@ static const struct of_device_id pic32_wdt_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, pic32_wdt_dt_ids); -static void pic32_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int pic32_wdt_drv_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -186,22 +181,12 @@ static int pic32_wdt_drv_probe(struct platform_device *pdev) if (!wdt->rst_base) return -ENOMEM; - wdt->clk = devm_clk_get(dev, NULL); + wdt->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(wdt->clk)) { dev_err(dev, "clk not found\n"); return PTR_ERR(wdt->clk); } - ret = clk_prepare_enable(wdt->clk); - if (ret) { - dev_err(dev, "clk enable failed\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, pic32_clk_disable_unprepare, - wdt->clk); - if (ret) - return ret; - if (pic32_wdt_is_win_enabled(wdt)) { dev_err(dev, "windowed-clear mode is not supported.\n"); return -ENODEV; diff --git a/drivers/watchdog/pnx4008_wdt.c b/drivers/watchdog/pnx4008_wdt.c index e0ea133c1690..87a44a5675a1 100644 --- a/drivers/watchdog/pnx4008_wdt.c +++ b/drivers/watchdog/pnx4008_wdt.c @@ -179,11 +179,6 @@ static struct watchdog_device pnx4008_wdd = { .max_timeout = MAX_HEARTBEAT, }; -static void pnx4008_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int pnx4008_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -195,18 +190,10 @@ static int pnx4008_wdt_probe(struct platform_device *pdev) if (IS_ERR(wdt_base)) return PTR_ERR(wdt_base); - wdt_clk = devm_clk_get(dev, NULL); + wdt_clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(wdt_clk)) return PTR_ERR(wdt_clk); - ret = clk_prepare_enable(wdt_clk); - if (ret) - return ret; - ret = devm_add_action_or_reset(dev, pnx4008_clk_disable_unprepare, - wdt_clk); - if (ret) - return ret; - pnx4008_wdd.bootstatus = (readl(WDTIM_RES(wdt_base)) & WDOG_RESET) ? WDIOF_CARDRESET : 0; pnx4008_wdd.parent = dev; diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c index 0d2209c5eaca..d776474dcdf3 100644 --- a/drivers/watchdog/qcom-wdt.c +++ b/drivers/watchdog/qcom-wdt.c @@ -175,11 +175,6 @@ static const struct watchdog_info qcom_wdt_pt_info = { .identity = KBUILD_MODNAME, }; -static void qcom_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static const struct qcom_wdt_match_data match_data_apcs_tmr = { .offset = reg_offset_data_apcs_tmr, .pretimeout = false, @@ -226,21 +221,12 @@ static int qcom_wdt_probe(struct platform_device *pdev) if (IS_ERR(wdt->base)) return PTR_ERR(wdt->base); - clk = devm_clk_get(dev, NULL); + clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(clk)) { dev_err(dev, "failed to get input clock\n"); return PTR_ERR(clk); } - ret = clk_prepare_enable(clk); - if (ret) { - dev_err(dev, "failed to setup clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, qcom_clk_disable_unprepare, clk); - if (ret) - return ret; - /* * We use the clock rate to calculate the max timeout, so ensure it's * not zero to avoid a divide-by-zero exception. diff --git a/drivers/watchdog/rtd119x_wdt.c b/drivers/watchdog/rtd119x_wdt.c index 834b94ff3f90..95c8d7abce42 100644 --- a/drivers/watchdog/rtd119x_wdt.c +++ b/drivers/watchdog/rtd119x_wdt.c @@ -94,16 +94,10 @@ static const struct of_device_id rtd119x_wdt_dt_ids[] = { { } }; -static void rtd119x_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int rtd119x_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct rtd119x_watchdog_device *data; - int ret; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -113,18 +107,10 @@ static int rtd119x_wdt_probe(struct platform_device *pdev) if (IS_ERR(data->base)) return PTR_ERR(data->base); - data->clk = devm_clk_get(dev, NULL); + data->clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(data->clk)) return PTR_ERR(data->clk); - ret = clk_prepare_enable(data->clk); - if (ret) - return ret; - ret = devm_add_action_or_reset(dev, rtd119x_clk_disable_unprepare, - data->clk); - if (ret) - return ret; - data->wdt_dev.info = &rtd119x_wdt_info; data->wdt_dev.ops = &rtd119x_wdt_ops; data->wdt_dev.timeout = 120; diff --git a/drivers/watchdog/st_lpc_wdt.c b/drivers/watchdog/st_lpc_wdt.c index 14ab6559c748..d79823e1b07e 100644 --- a/drivers/watchdog/st_lpc_wdt.c +++ b/drivers/watchdog/st_lpc_wdt.c @@ -142,11 +142,6 @@ static struct watchdog_device st_wdog_dev = { .ops = &st_wdog_ops, }; -static void st_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int st_wdog_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -190,7 +185,7 @@ static int st_wdog_probe(struct platform_device *pdev) return PTR_ERR(regmap); } - clk = devm_clk_get(dev, NULL); + clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(clk)) { dev_err(dev, "Unable to request clock\n"); return PTR_ERR(clk); @@ -210,15 +205,6 @@ static int st_wdog_probe(struct platform_device *pdev) st_wdog_dev.max_timeout = 0xFFFFFFFF / st_wdog->clkrate; st_wdog_dev.parent = dev; - ret = clk_prepare_enable(clk); - if (ret) { - dev_err(dev, "Unable to enable clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, st_clk_disable_unprepare, clk); - if (ret) - return ret; - watchdog_set_drvdata(&st_wdog_dev, st_wdog); watchdog_set_nowayout(&st_wdog_dev, WATCHDOG_NOWAYOUT); diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c index 570a71509d2a..01849720310d 100644 --- a/drivers/watchdog/stm32_iwdg.c +++ b/drivers/watchdog/stm32_iwdg.c @@ -150,50 +150,23 @@ static int stm32_iwdg_set_timeout(struct watchdog_device *wdd, return 0; } -static void stm32_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int stm32_iwdg_clk_init(struct platform_device *pdev, struct stm32_iwdg *wdt) { struct device *dev = &pdev->dev; - u32 ret; - wdt->clk_lsi = devm_clk_get(dev, "lsi"); + wdt->clk_lsi = devm_clk_get_enabled(dev, "lsi"); if (IS_ERR(wdt->clk_lsi)) return dev_err_probe(dev, PTR_ERR(wdt->clk_lsi), "Unable to get lsi clock\n"); /* optional peripheral clock */ if (wdt->data->has_pclk) { - wdt->clk_pclk = devm_clk_get(dev, "pclk"); + wdt->clk_pclk = devm_clk_get_enabled(dev, "pclk"); if (IS_ERR(wdt->clk_pclk)) return dev_err_probe(dev, PTR_ERR(wdt->clk_pclk), "Unable to get pclk clock\n"); - - ret = clk_prepare_enable(wdt->clk_pclk); - if (ret) { - dev_err(dev, "Unable to prepare pclk clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, - stm32_clk_disable_unprepare, - wdt->clk_pclk); - if (ret) - return ret; } - ret = clk_prepare_enable(wdt->clk_lsi); - if (ret) { - dev_err(dev, "Unable to prepare lsi clock\n"); - return ret; - } - ret = devm_add_action_or_reset(dev, stm32_clk_disable_unprepare, - wdt->clk_lsi); - if (ret) - return ret; - wdt->rate = clk_get_rate(wdt->clk_lsi); return 0; diff --git a/drivers/watchdog/visconti_wdt.c b/drivers/watchdog/visconti_wdt.c index 83ef55e66ca8..1127e42734f4 100644 --- a/drivers/watchdog/visconti_wdt.c +++ b/drivers/watchdog/visconti_wdt.c @@ -112,11 +112,6 @@ static const struct watchdog_ops visconti_wdt_ops = { .set_timeout = visconti_wdt_set_timeout, }; -static void visconti_clk_disable_unprepare(void *data) -{ - clk_disable_unprepare(data); -} - static int visconti_wdt_probe(struct platform_device *pdev) { struct watchdog_device *wdev; @@ -134,20 +129,9 @@ static int visconti_wdt_probe(struct platform_device *pdev) if (IS_ERR(priv->base)) return PTR_ERR(priv->base); - clk = devm_clk_get(dev, NULL); + clk = devm_clk_get_enabled(dev, NULL); if (IS_ERR(clk)) return dev_err_probe(dev, PTR_ERR(clk), "Could not get clock\n"); - - ret = clk_prepare_enable(clk); - if (ret) { - dev_err(dev, "Could not enable clock\n"); - return ret; - } - - ret = devm_add_action_or_reset(dev, visconti_clk_disable_unprepare, clk); - if (ret) - return ret; - clk_freq = clk_get_rate(clk); if (!clk_freq) return -EINVAL;