diff mbox series

[-next,07/11] gpio: mxc: Use helper function devm_clk_get_optional_enabled()

Message ID 20230818093018.1051434-8-lizetao1@huawei.com (mailing list archive)
State New, archived
Headers show
Series gpio: Use devm_clk_get_*() helper function to simplify the drivers. | expand

Commit Message

Li Zetao Aug. 18, 2023, 9:30 a.m. UTC
Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
prepared and enabled clocks"), devm_clk_get_optional() and
clk_prepare_enable() can now be replaced by
devm_clk_get_optional_enabled() when the driver enables (and possibly
prepares) the clocks for the whole lifetime of the device. Moreover,
it is no longer necessary to unprepare and disable the clocks explicitly.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/gpio/gpio-mxc.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

Comments

Andy Shevchenko Aug. 18, 2023, 1:59 p.m. UTC | #1
On Fri, Aug 18, 2023 at 05:30:14PM +0800, Li Zetao wrote:
> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
> prepared and enabled clocks"), devm_clk_get_optional() and
> clk_prepare_enable() can now be replaced by
> devm_clk_get_optional_enabled() when the driver enables (and possibly
> prepares) the clocks for the whole lifetime of the device. Moreover,
> it is no longer necessary to unprepare and disable the clocks explicitly.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Bartosz Golaszewski Aug. 21, 2023, 12:12 p.m. UTC | #2
On Fri, Aug 18, 2023 at 11:30 AM Li Zetao <lizetao1@huawei.com> wrote:
>
> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
> prepared and enabled clocks"), devm_clk_get_optional() and
> clk_prepare_enable() can now be replaced by
> devm_clk_get_optional_enabled() when the driver enables (and possibly
> prepares) the clocks for the whole lifetime of the device. Moreover,
> it is no longer necessary to unprepare and disable the clocks explicitly.
>
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
>  drivers/gpio/gpio-mxc.c | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
> index 004c6ad7ce52..4cb455b2bdee 100644
> --- a/drivers/gpio/gpio-mxc.c
> +++ b/drivers/gpio/gpio-mxc.c
> @@ -452,16 +452,10 @@ static int mxc_gpio_probe(struct platform_device *pdev)
>                 return port->irq;
>
>         /* the controller clock is optional */
> -       port->clk = devm_clk_get_optional(&pdev->dev, NULL);
> +       port->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
>         if (IS_ERR(port->clk))
>                 return PTR_ERR(port->clk);
>
> -       err = clk_prepare_enable(port->clk);
> -       if (err) {
> -               dev_err(&pdev->dev, "Unable to enable clock.\n");
> -               return err;
> -       }
> -
>         if (of_device_is_compatible(np, "fsl,imx7d-gpio"))
>                 port->power_off = true;
>
> @@ -535,7 +529,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)
>  out_bgio:
>         pm_runtime_disable(&pdev->dev);
>         pm_runtime_put_noidle(&pdev->dev);
> -       clk_disable_unprepare(port->clk);
>         dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err);
>         return err;
>  }
> --
> 2.34.1
>

Applied, thanks!

Bart
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 004c6ad7ce52..4cb455b2bdee 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -452,16 +452,10 @@  static int mxc_gpio_probe(struct platform_device *pdev)
 		return port->irq;
 
 	/* the controller clock is optional */
-	port->clk = devm_clk_get_optional(&pdev->dev, NULL);
+	port->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
 	if (IS_ERR(port->clk))
 		return PTR_ERR(port->clk);
 
-	err = clk_prepare_enable(port->clk);
-	if (err) {
-		dev_err(&pdev->dev, "Unable to enable clock.\n");
-		return err;
-	}
-
 	if (of_device_is_compatible(np, "fsl,imx7d-gpio"))
 		port->power_off = true;
 
@@ -535,7 +529,6 @@  static int mxc_gpio_probe(struct platform_device *pdev)
 out_bgio:
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_put_noidle(&pdev->dev);
-	clk_disable_unprepare(port->clk);
 	dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err);
 	return err;
 }