From patchwork Mon Aug 8 06:06:40 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: 12938495 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CE23C00140 for ; Mon, 8 Aug 2022 06:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233845AbiHHGHh (ORCPT ); Mon, 8 Aug 2022 02:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbiHHGHg (ORCPT ); Mon, 8 Aug 2022 02:07:36 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C616010B8 for ; Sun, 7 Aug 2022 23:07:34 -0700 (PDT) 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 1oKvv3-0002xh-JN; Mon, 08 Aug 2022 08:07:17 +0200 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 1oKvuu-002RHx-0Q; Mon, 08 Aug 2022 08:07:10 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1oKvuv-00AIXg-Cj; Mon, 08 Aug 2022 08:07:09 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Jean Delvare , Guenter Roeck Cc: =?utf-8?q?Nuno_S=C3=A1?= , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, linux-hwmon@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de, Jonathan Cameron Subject: [PATCH] hwmon: Make use of devm_clk_get_enabled() Date: Mon, 8 Aug 2022 08:06:40 +0200 Message-Id: <20220808060640.272549-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6257; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=WlGqjQhx5x/Cm8pqN8Iwq453zaD79vCbsN7288gPPz8=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBi8KfqAr+J5U0wLptBSNQthZTfliYA9uNIEs6yKErb l95oIo+JATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCYvCn6gAKCRDB/BR4rcrsCbcJCA CeT+eofVlVaH9hih7k97PYnK20Hk0ueHCIfmNWXsjA3YvN2GAidQsNRd2DPZ89WvPFUztz9XLdlDlC hLp+3j+7VnK9FWZD9q+6RoRXBXDxcc7jGBAENMb8sEURkHxwZvh+Td/xYhu0IlVRXvSAlEOgh7BQpm R9/dwA4btIlxc8xm1kASfDpSJXCM6FlsnaVDqRbOUPnBBj8AWYnriaFy5FF16jultC8ucq0Ta39TVa +HFuv9ZU2hhjjBoB8/i9rTEWVu1/Rvoy3GAmBEc15zMRRXPS9ChTsb8JATo9WAj8j9EZqGwolDA2cV CEM1SMNGGBpIm4BLCr0x/jNK1tU74n X-Developer-Key: i=u.kleine-koenig@pengutronix.de; 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-hwmon@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Several drivers manually register a devm handler to disable their clk. Convert them to devm_clk_get_enabled(). Acked-by: Guenter Roeck Reviewed-by: Nuno Sá Acked-by: Jonathan Cameron Signed-off-by: Uwe Kleine-König Reviewed-by: Jonathan Cameron --- Hello, previously this patch was an example to show the benefits of adding devm_clk_get_enabled() and its variants. Last submission was on 14 Mar 2022 (https://lore.kernel.org/all/20220314141643.22184-5-u.kleine-koenig@pengutronix.de). This patch obviously depends on 7ef9651e9792 clk: Provide new devm_clk helpers for prepared and enabled clocks and to actually work needs 8b3d743fc9e2 clk: Fix pointer casting to prevent oops in devm_clk_release() which are both in Linus' tree now. Best regards Uwe 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(-) base-commit: 8b3d743fc9e2542822826890b482afabf0e7522a diff --git a/drivers/hwmon/axi-fan-control.c b/drivers/hwmon/axi-fan-control.c index 96c4a5c45291..6724e0dd3088 100644 --- a/drivers/hwmon/axi-fan-control.c +++ b/drivers/hwmon/axi-fan-control.c @@ -394,11 +394,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), @@ -478,20 +473,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 26278b0f17a9..cf9467d03531 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -451,24 +451,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; @@ -505,16 +487,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,