mbox series

[-next,00/11] gpio: Use devm_clk_get_*() helper function to simplify the drivers.

Message ID 20230818093018.1051434-1-lizetao1@huawei.com
Headers show
Series gpio: Use devm_clk_get_*() helper function to simplify the drivers. | expand

Message

Li Zetao Aug. 18, 2023, 9:30 a.m. UTC
Commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
and enabled clocks") provides a a series of new helper function for
prepared and enabled clocks when a driver keeps a clock prepared
(or enabled) during the whole lifetime of the driver. So where drivers
get clocks and enable them immediately, it can be combined into a single
function devm_clk_get_*(). Moreover, the unprepare and disable function
has been registered to devm_clk_state, and before devm_clk_state is
released, the clocks will be unprepareed and disable, so it is unnecessary
to unprepare and disable clock explicitly when remove drivers or in the
error handling path.

Li Zetao (11):
  gpio: cadence: Use helper function devm_clk_get_enabled()
  gpio: davinci: Use helper function devm_clk_get_enabled()
  gpio: ftgpio010: Use helper function devm_clk_get_enabled()
  gpio: lpc18xx: Use helper function devm_clk_get_enabled()
  gpio: mb86s7x: Use helper function devm_clk_get_optional_enabled()
  gpio: mvebu: Use helper function devm_clk_get_enabled()
  gpio: mxc: Use helper function devm_clk_get_optional_enabled()
  gpio: omap: Use helper function devm_clk_get_prepared()
  gpio: stp-xway: Use helper function devm_clk_get_enabled()
  gpio: xilinx: Use helper function devm_clk_get_optional_enabled()
  gpio: zynq: Use helper function devm_clk_get_enabled()

 drivers/gpio/gpio-cadence.c   | 20 +++++---------------
 drivers/gpio/gpio-davinci.c   | 13 ++-----------
 drivers/gpio/gpio-ftgpio010.c | 29 +++++++----------------------
 drivers/gpio/gpio-lpc18xx.c   | 14 +++-----------
 drivers/gpio/gpio-mb86s7x.c   |  8 +-------
 drivers/gpio/gpio-mvebu.c     |  4 +---
 drivers/gpio/gpio-mxc.c       |  9 +--------
 drivers/gpio/gpio-omap.c      |  8 +-------
 drivers/gpio/gpio-stp-xway.c  | 10 ++--------
 drivers/gpio/gpio-xilinx.c    | 14 +++-----------
 drivers/gpio/gpio-zynq.c      | 13 +++----------
 11 files changed, 29 insertions(+), 113 deletions(-)

Comments

Andy Shevchenko Aug. 18, 2023, 1:47 p.m. UTC | #1
On Fri, Aug 18, 2023 at 05:30:10PM +0800, Li Zetao wrote:
> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
> prepared and enabled clocks"), devm_clk_get() and clk_prepare_enable()
> can now be replaced by devm_clk_get_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.

...

> -	} else if (PTR_ERR(g->clk) == -EPROBE_DEFER) {
> +	g->clk = devm_clk_get_enabled(dev, NULL);
> +	if (PTR_ERR_OR_ZERO(g->clk) == -EPROBE_DEFER)
>  		/*
>  		 * Percolate deferrals, for anything else,
>  		 * just live without the clocking.
>  		 */
>  		return PTR_ERR(g->clk);
> -	}

It means you need to use _optional variant here and return whatever error you
get.

...

>  	platform_set_drvdata(pdev, g);

Do you now need this?
Andy Shevchenko Aug. 18, 2023, 1:55 p.m. UTC | #2
On Fri, Aug 18, 2023 at 05:30:13PM +0800, Li Zetao wrote:
> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
> prepared and enabled clocks"), devm_clk_get() and clk_prepare_enable()
> can now be replaced by devm_clk_get_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.

...

> -	mvchip->clk = devm_clk_get(&pdev->dev, NULL);
>  	/* Not all SoCs require a clock.*/
> -	if (!IS_ERR(mvchip->clk))
> -		clk_prepare_enable(mvchip->clk);
> +	mvchip->clk = devm_clk_get_enabled(&pdev->dev, NULL);

The clk is only used in the PWM part, move it there and remove clk member from
the private struct.
Andy Shevchenko Aug. 18, 2023, 2:03 p.m. UTC | #3
On Fri, Aug 18, 2023 at 05:30:09PM +0800, Li Zetao wrote:
> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for
> prepared and enabled clocks"), devm_clk_get() and clk_prepare_enable()
> can now be replaced by devm_clk_get_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.

It seems it fixes a bug that we try to remove the enabled clock on unbinding.
Maybe Tony can shed a light here. If this is the case, add a Fixes tag.
Otherwise it might be (undesired?) functional change and in any case has to
be mentioned in the commit message.