linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers.
@ 2023-08-22 13:12 Li Zetao
  2023-08-22 13:12 ` [PATCH -next 01/25] spi: ar934x: Use helper function devm_clk_get_enabled() Li Zetao
                   ` (26 more replies)
  0 siblings, 27 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

Commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
and enabled clocks") provides a 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 clocks explicitly when remove drivers or in the
error handling path.

Li Zetao (25):
  spi: ar934x: Use helper function devm_clk_get_enabled()
  spi: armada-3700: Use helper function devm_clk_get_prepared()
  spi: aspeed: Use helper function devm_clk_get_enabled()
  spi: ath79: Use helper function devm_clk_get_enabled()
  spi: spi-axi-spi-engine: Use helper function devm_clk_get_enabled()
  spi: bcm2835: Use helper function devm_clk_get_enabled()
  spi: bcm2835aux: Use helper function devm_clk_get_enabled()
  spi: spi-cadence: Use helper function devm_clk_get_enabled()
  spi: spi-cavium-thunderx: Use helper function devm_clk_get_enabled()
  spi: davinci: Use helper function devm_clk_get_enabled()
  spi: dw-bt1: Use helper function devm_clk_get_enabled()
  spi: dw-mmio: Use helper function devm_clk_get_*()
  spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled()
  spi: lantiq-ssc: Use helper function devm_clk_get_enabled()
  spi: meson-spicc: Use helper function devm_clk_get_enabled()
  spi: spi-meson-spifc: Use helper function devm_clk_get_enabled()
  spi: microchip-core-qspi: Use helper function devm_clk_get_enabled()
  spi: microchip-core: Use helper function devm_clk_get_enabled()
  spi: mtk-snfi: Use helper function devm_clk_get_enabled()
  spi: npcm-fiu: Use helper function devm_clk_get_enabled()
  spi: orion: Use helper function devm_clk_get_enabled()
  spi: pic32-sqi: Use helper function devm_clk_get_enabled()
  spi: pic32: Use helper function devm_clk_get_enabled()
  spi: spl022: Use helper function devm_clk_get_enabled()
  spi: rockchip: Use helper function devm_clk_get_enabled()

 drivers/spi/spi-ar934x.c              | 22 ++--------
 drivers/spi/spi-armada-3700.c         | 18 ++------
 drivers/spi/spi-aspeed-smc.c          | 16 +------
 drivers/spi/spi-ath79.c               | 11 +----
 drivers/spi/spi-axi-spi-engine.c      | 25 +++--------
 drivers/spi/spi-bcm2835.c             | 11 +----
 drivers/spi/spi-bcm2835aux.c          | 23 ++--------
 drivers/spi/spi-cadence.c             | 23 ++--------
 drivers/spi/spi-cavium-thunderx.c     |  8 +---
 drivers/spi/spi-davinci.c             | 11 +----
 drivers/spi/spi-dw-bt1.c              | 23 +++-------
 drivers/spi/spi-dw-mmio.c             | 20 +++------
 drivers/spi/spi-fsl-dspi.c            | 12 ++----
 drivers/spi/spi-lantiq-ssc.c          | 10 +----
 drivers/spi/spi-meson-spicc.c         | 33 +++------------
 drivers/spi/spi-meson-spifc.c         | 17 ++------
 drivers/spi/spi-microchip-core-qspi.c | 29 +++----------
 drivers/spi/spi-microchip-core.c      |  9 +---
 drivers/spi/spi-mtk-snfi.c            | 61 ++++-----------------------
 drivers/spi/spi-npcm-fiu.c            | 14 ++----
 drivers/spi/spi-orion.c               | 11 +----
 drivers/spi/spi-pic32-sqi.c           | 27 ++----------
 drivers/spi/spi-pic32.c               |  8 +---
 drivers/spi/spi-pl022.c               | 21 +++------
 drivers/spi/spi-rockchip.c            | 30 +++----------
 25 files changed, 88 insertions(+), 405 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 71+ messages in thread

* [PATCH -next 01/25] spi: ar934x: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared() Li Zetao
                   ` (25 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-ar934x.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/drivers/spi/spi-ar934x.c b/drivers/spi/spi-ar934x.c
index 58b98cea31d9..5ba988720851 100644
--- a/drivers/spi/spi-ar934x.c
+++ b/drivers/spi/spi-ar934x.c
@@ -168,27 +168,21 @@ static int ar934x_spi_probe(struct platform_device *pdev)
 	struct ar934x_spi *sp;
 	void __iomem *base;
 	struct clk *clk;
-	int ret;
 
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
 		return PTR_ERR(base);
 
-	clk = devm_clk_get(&pdev->dev, NULL);
+	clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "failed to get clock\n");
 		return PTR_ERR(clk);
 	}
 
-	ret = clk_prepare_enable(clk);
-	if (ret)
-		return ret;
-
 	ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*sp));
 	if (!ctlr) {
 		dev_info(&pdev->dev, "failed to allocate spi controller\n");
-		ret = -ENOMEM;
-		goto err_clk_disable;
+		return -ENOMEM;
 	}
 
 	/* disable flash mapping and expose spi controller registers */
@@ -212,25 +206,15 @@ static int ar934x_spi_probe(struct platform_device *pdev)
 	sp->clk_freq = clk_get_rate(clk);
 	sp->ctlr = ctlr;
 
-	ret = spi_register_controller(ctlr);
-	if (!ret)
-		return 0;
-
-err_clk_disable:
-	clk_disable_unprepare(clk);
-	return ret;
+	return spi_register_controller(ctlr);
 }
 
 static void ar934x_spi_remove(struct platform_device *pdev)
 {
 	struct spi_controller *ctlr;
-	struct ar934x_spi *sp;
 
 	ctlr = dev_get_drvdata(&pdev->dev);
-	sp = spi_controller_get_devdata(ctlr);
-
 	spi_unregister_controller(ctlr);
-	clk_disable_unprepare(sp->clk);
 }
 
 static struct platform_driver ar934x_spi_driver = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
  2023-08-22 13:12 ` [PATCH -next 01/25] spi: ar934x: Use helper function devm_clk_get_enabled() Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 15:55   ` Jonathan Cameron
  2023-08-22 13:12 ` [PATCH -next 03/25] spi: aspeed: Use helper function devm_clk_get_enabled() Li Zetao
                   ` (24 subsequent siblings)
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
and enabled clocks"), devm_clk_get() and clk_prepare() can now be replaced
by devm_clk_get_prepared() when driver prepares the clocks for the whole
lifetime of the device. Moreover, it is no longer necessary to unprepare
the clocks explicitly.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/spi/spi-armada-3700.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi-armada-3700.c b/drivers/spi/spi-armada-3700.c
index 0103ac0158c0..70113b9dab35 100644
--- a/drivers/spi/spi-armada-3700.c
+++ b/drivers/spi/spi-armada-3700.c
@@ -865,18 +865,12 @@ static int a3700_spi_probe(struct platform_device *pdev)
 
 	init_completion(&spi->done);
 
-	spi->clk = devm_clk_get(dev, NULL);
+	spi->clk = devm_clk_get_prepared(dev, NULL);
 	if (IS_ERR(spi->clk)) {
 		dev_err(dev, "could not find clk: %ld\n", PTR_ERR(spi->clk));
 		goto error;
 	}
 
-	ret = clk_prepare(spi->clk);
-	if (ret) {
-		dev_err(dev, "could not prepare clk: %d\n", ret);
-		goto error;
-	}
-
 	host->max_speed_hz = min_t(unsigned long, A3700_SPI_MAX_SPEED_HZ,
 					clk_get_rate(spi->clk));
 	host->min_speed_hz = DIV_ROUND_UP(clk_get_rate(spi->clk),
@@ -888,19 +882,17 @@ static int a3700_spi_probe(struct platform_device *pdev)
 			       dev_name(dev), host);
 	if (ret) {
 		dev_err(dev, "could not request IRQ: %d\n", ret);
-		goto error_clk;
+		goto error;
 	}
 
 	ret = devm_spi_register_controller(dev, host);
 	if (ret) {
 		dev_err(dev, "Failed to register host\n");
-		goto error_clk;
+		goto error;
 	}
 
 	return 0;
 
-error_clk:
-	clk_unprepare(spi->clk);
 error:
 	spi_controller_put(host);
 out:
@@ -909,10 +901,6 @@ static int a3700_spi_probe(struct platform_device *pdev)
 
 static void a3700_spi_remove(struct platform_device *pdev)
 {
-	struct spi_controller *host = platform_get_drvdata(pdev);
-	struct a3700_spi *spi = spi_controller_get_devdata(host);
-
-	clk_unprepare(spi->clk);
 }
 
 static struct platform_driver a3700_spi_driver = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 03/25] spi: aspeed: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
  2023-08-22 13:12 ` [PATCH -next 01/25] spi: ar934x: Use helper function devm_clk_get_enabled() Li Zetao
  2023-08-22 13:12 ` [PATCH -next 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared() Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-23  7:11   ` Chin-Ting Kuo
  2023-08-24  8:55   ` Cédric Le Goater
  2023-08-22 13:12 ` [PATCH -next 04/25] spi: ath79: " Li Zetao
                   ` (23 subsequent siblings)
  26 siblings, 2 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-aspeed-smc.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c
index 21b0fa646c7d..bbd417c55e7f 100644
--- a/drivers/spi/spi-aspeed-smc.c
+++ b/drivers/spi/spi-aspeed-smc.c
@@ -748,7 +748,7 @@ static int aspeed_spi_probe(struct platform_device *pdev)
 	aspi->ahb_window_size = resource_size(res);
 	aspi->ahb_base_phy = res->start;
 
-	aspi->clk = devm_clk_get(&pdev->dev, NULL);
+	aspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(aspi->clk)) {
 		dev_err(dev, "missing clock\n");
 		return PTR_ERR(aspi->clk);
@@ -760,12 +760,6 @@ static int aspeed_spi_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	ret = clk_prepare_enable(aspi->clk);
-	if (ret) {
-		dev_err(dev, "can not enable the clock\n");
-		return ret;
-	}
-
 	/* IRQ is for DMA, which the driver doesn't support yet */
 
 	ctlr->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | data->mode_bits;
@@ -777,14 +771,9 @@ static int aspeed_spi_probe(struct platform_device *pdev)
 	ctlr->dev.of_node = dev->of_node;
 
 	ret = devm_spi_register_controller(dev, ctlr);
-	if (ret) {
+	if (ret)
 		dev_err(&pdev->dev, "spi_register_controller failed\n");
-		goto disable_clk;
-	}
-	return 0;
 
-disable_clk:
-	clk_disable_unprepare(aspi->clk);
 	return ret;
 }
 
@@ -793,7 +782,6 @@ static void aspeed_spi_remove(struct platform_device *pdev)
 	struct aspeed_spi *aspi = platform_get_drvdata(pdev);
 
 	aspeed_spi_enable(aspi, false);
-	clk_disable_unprepare(aspi->clk);
 }
 
 /*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 04/25] spi: ath79: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (2 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 03/25] spi: aspeed: Use helper function devm_clk_get_enabled() Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 05/25] spi: spi-axi-spi-engine: " Li Zetao
                   ` (22 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-ath79.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c
index 1b6d977d111c..c9f1d1e1dcf7 100644
--- a/drivers/spi/spi-ath79.c
+++ b/drivers/spi/spi-ath79.c
@@ -200,20 +200,16 @@ static int ath79_spi_probe(struct platform_device *pdev)
 		goto err_put_host;
 	}
 
-	sp->clk = devm_clk_get(&pdev->dev, "ahb");
+	sp->clk = devm_clk_get_enabled(&pdev->dev, "ahb");
 	if (IS_ERR(sp->clk)) {
 		ret = PTR_ERR(sp->clk);
 		goto err_put_host;
 	}
 
-	ret = clk_prepare_enable(sp->clk);
-	if (ret)
-		goto err_put_host;
-
 	rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ);
 	if (!rate) {
 		ret = -EINVAL;
-		goto err_clk_disable;
+		goto err_put_host;
 	}
 
 	sp->rrw_delay = ATH79_SPI_RRW_DELAY_FACTOR / rate;
@@ -229,8 +225,6 @@ static int ath79_spi_probe(struct platform_device *pdev)
 
 err_disable:
 	ath79_spi_disable(sp);
-err_clk_disable:
-	clk_disable_unprepare(sp->clk);
 err_put_host:
 	spi_controller_put(host);
 
@@ -243,7 +237,6 @@ static void ath79_spi_remove(struct platform_device *pdev)
 
 	spi_bitbang_stop(&sp->bitbang);
 	ath79_spi_disable(sp);
-	clk_disable_unprepare(sp->clk);
 	spi_controller_put(sp->bitbang.master);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 05/25] spi: spi-axi-spi-engine: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (3 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 04/25] spi: ath79: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 06/25] spi: bcm2835: " Li Zetao
                   ` (21 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-axi-spi-engine.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c
index 0258c9a72fdc..b96e55f59d1a 100644
--- a/drivers/spi/spi-axi-spi-engine.c
+++ b/drivers/spi/spi-axi-spi-engine.c
@@ -485,30 +485,22 @@ static int spi_engine_probe(struct platform_device *pdev)
 
 	spin_lock_init(&spi_engine->lock);
 
-	spi_engine->clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
+	spi_engine->clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk");
 	if (IS_ERR(spi_engine->clk)) {
 		ret = PTR_ERR(spi_engine->clk);
 		goto err_put_host;
 	}
 
-	spi_engine->ref_clk = devm_clk_get(&pdev->dev, "spi_clk");
+	spi_engine->ref_clk = devm_clk_get_enabled(&pdev->dev, "spi_clk");
 	if (IS_ERR(spi_engine->ref_clk)) {
 		ret = PTR_ERR(spi_engine->ref_clk);
 		goto err_put_host;
 	}
 
-	ret = clk_prepare_enable(spi_engine->clk);
-	if (ret)
-		goto err_put_host;
-
-	ret = clk_prepare_enable(spi_engine->ref_clk);
-	if (ret)
-		goto err_clk_disable;
-
 	spi_engine->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(spi_engine->base)) {
 		ret = PTR_ERR(spi_engine->base);
-		goto err_ref_clk_disable;
+		goto err_put_host;
 	}
 
 	version = readl(spi_engine->base + SPI_ENGINE_REG_VERSION);
@@ -518,7 +510,7 @@ static int spi_engine_probe(struct platform_device *pdev)
 			SPI_ENGINE_VERSION_MINOR(version),
 			SPI_ENGINE_VERSION_PATCH(version));
 		ret = -ENODEV;
-		goto err_ref_clk_disable;
+		goto err_put_host;
 	}
 
 	writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET);
@@ -527,7 +519,7 @@ static int spi_engine_probe(struct platform_device *pdev)
 
 	ret = request_irq(irq, spi_engine_irq, 0, pdev->name, host);
 	if (ret)
-		goto err_ref_clk_disable;
+		goto err_put_host;
 
 	host->dev.of_node = pdev->dev.of_node;
 	host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE;
@@ -545,10 +537,6 @@ static int spi_engine_probe(struct platform_device *pdev)
 	return 0;
 err_free_irq:
 	free_irq(irq, host);
-err_ref_clk_disable:
-	clk_disable_unprepare(spi_engine->ref_clk);
-err_clk_disable:
-	clk_disable_unprepare(spi_engine->clk);
 err_put_host:
 	spi_controller_put(host);
 	return ret;
@@ -569,9 +557,6 @@ static void spi_engine_remove(struct platform_device *pdev)
 	writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
 	writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE);
 	writel_relaxed(0x01, spi_engine->base + SPI_ENGINE_REG_RESET);
-
-	clk_disable_unprepare(spi_engine->ref_clk);
-	clk_disable_unprepare(spi_engine->clk);
 }
 
 static const struct of_device_id spi_engine_match_table[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 06/25] spi: bcm2835: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (4 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 05/25] spi: spi-axi-spi-engine: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 07/25] spi: bcm2835aux: " Li Zetao
                   ` (20 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-bcm2835.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index e7bb2714678a..a457ad2f7db1 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -1352,7 +1352,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
 	if (IS_ERR(bs->regs))
 		return PTR_ERR(bs->regs);
 
-	bs->clk = devm_clk_get(&pdev->dev, NULL);
+	bs->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(bs->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(bs->clk),
 				     "could not get clk\n");
@@ -1363,14 +1363,11 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
 	if (bs->irq < 0)
 		return bs->irq;
 
-	err = clk_prepare_enable(bs->clk);
-	if (err)
-		return err;
 	bs->clk_hz = clk_get_rate(bs->clk);
 
 	err = bcm2835_dma_init(ctlr, &pdev->dev, bs);
 	if (err)
-		goto out_clk_disable;
+		return err;
 
 	/* initialise the hardware with the default polarities */
 	bcm2835_wr(bs, BCM2835_SPI_CS,
@@ -1396,8 +1393,6 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
 
 out_dma_release:
 	bcm2835_dma_release(ctlr, bs);
-out_clk_disable:
-	clk_disable_unprepare(bs->clk);
 	return err;
 }
 
@@ -1415,8 +1410,6 @@ static void bcm2835_spi_remove(struct platform_device *pdev)
 	/* Clear FIFOs, and disable the HW block */
 	bcm2835_wr(bs, BCM2835_SPI_CS,
 		   BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX);
-
-	clk_disable_unprepare(bs->clk);
 }
 
 static const struct of_device_id bcm2835_spi_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 07/25] spi: bcm2835aux: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (5 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 06/25] spi: bcm2835: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 08/25] spi: spi-cadence: " Li Zetao
                   ` (19 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-bcm2835aux.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/drivers/spi/spi-bcm2835aux.c b/drivers/spi/spi-bcm2835aux.c
index 6d2a5d9f2498..06fe155a70c9 100644
--- a/drivers/spi/spi-bcm2835aux.c
+++ b/drivers/spi/spi-bcm2835aux.c
@@ -512,7 +512,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
 	if (IS_ERR(bs->regs))
 		return PTR_ERR(bs->regs);
 
-	bs->clk = devm_clk_get(&pdev->dev, NULL);
+	bs->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(bs->clk)) {
 		err = PTR_ERR(bs->clk);
 		dev_err(&pdev->dev, "could not get clk: %d\n", err);
@@ -523,19 +523,11 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
 	if (bs->irq < 0)
 		return bs->irq;
 
-	/* this also enables the HW block */
-	err = clk_prepare_enable(bs->clk);
-	if (err) {
-		dev_err(&pdev->dev, "could not prepare clock: %d\n", err);
-		return err;
-	}
-
 	/* just checking if the clock returns a sane value */
 	clk_hz = clk_get_rate(bs->clk);
 	if (!clk_hz) {
 		dev_err(&pdev->dev, "clock returns 0 Hz\n");
-		err = -ENODEV;
-		goto out_clk_disable;
+		return -ENODEV;
 	}
 
 	/* reset SPI-HW block */
@@ -547,22 +539,18 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
 			       dev_name(&pdev->dev), host);
 	if (err) {
 		dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
-		goto out_clk_disable;
+		return err;
 	}
 
 	err = spi_register_controller(host);
 	if (err) {
 		dev_err(&pdev->dev, "could not register SPI host: %d\n", err);
-		goto out_clk_disable;
+		return err;
 	}
 
 	bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev));
 
 	return 0;
-
-out_clk_disable:
-	clk_disable_unprepare(bs->clk);
-	return err;
 }
 
 static void bcm2835aux_spi_remove(struct platform_device *pdev)
@@ -575,9 +563,6 @@ static void bcm2835aux_spi_remove(struct platform_device *pdev)
 	spi_unregister_controller(host);
 
 	bcm2835aux_spi_reset_hw(bs);
-
-	/* disable the HW block by releasing the clock */
-	clk_disable_unprepare(bs->clk);
 }
 
 static const struct of_device_id bcm2835aux_spi_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 08/25] spi: spi-cadence: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (6 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 07/25] spi: bcm2835aux: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 09/25] spi: spi-cavium-thunderx: " Li Zetao
                   ` (18 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-cadence.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
index 3c9813ad064b..174476bbdf54 100644
--- a/drivers/spi/spi-cadence.c
+++ b/drivers/spi/spi-cadence.c
@@ -576,31 +576,19 @@ static int cdns_spi_probe(struct platform_device *pdev)
 		goto remove_ctlr;
 	}
 
-	xspi->pclk = devm_clk_get(&pdev->dev, "pclk");
+	xspi->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
 	if (IS_ERR(xspi->pclk)) {
 		dev_err(&pdev->dev, "pclk clock not found.\n");
 		ret = PTR_ERR(xspi->pclk);
 		goto remove_ctlr;
 	}
 
-	ret = clk_prepare_enable(xspi->pclk);
-	if (ret) {
-		dev_err(&pdev->dev, "Unable to enable APB clock.\n");
-		goto remove_ctlr;
-	}
-
 	if (!spi_controller_is_target(ctlr)) {
-		xspi->ref_clk = devm_clk_get(&pdev->dev, "ref_clk");
+		xspi->ref_clk = devm_clk_get_enabled(&pdev->dev, "ref_clk");
 		if (IS_ERR(xspi->ref_clk)) {
 			dev_err(&pdev->dev, "ref_clk clock not found.\n");
 			ret = PTR_ERR(xspi->ref_clk);
-			goto clk_dis_apb;
-		}
-
-		ret = clk_prepare_enable(xspi->ref_clk);
-		if (ret) {
-			dev_err(&pdev->dev, "Unable to enable device clock.\n");
-			goto clk_dis_apb;
+			goto remove_ctlr;
 		}
 
 		pm_runtime_use_autosuspend(&pdev->dev);
@@ -674,10 +662,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
 	if (!spi_controller_is_target(ctlr)) {
 		pm_runtime_set_suspended(&pdev->dev);
 		pm_runtime_disable(&pdev->dev);
-		clk_disable_unprepare(xspi->ref_clk);
 	}
-clk_dis_apb:
-	clk_disable_unprepare(xspi->pclk);
 remove_ctlr:
 	spi_controller_put(ctlr);
 	return ret;
@@ -698,8 +683,6 @@ static void cdns_spi_remove(struct platform_device *pdev)
 
 	cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
 
-	clk_disable_unprepare(xspi->ref_clk);
-	clk_disable_unprepare(xspi->pclk);
 	pm_runtime_set_suspended(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 09/25] spi: spi-cavium-thunderx: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (7 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 08/25] spi: spi-cadence: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 10/25] spi: davinci: " Li Zetao
                   ` (17 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-cavium-thunderx.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/spi/spi-cavium-thunderx.c b/drivers/spi/spi-cavium-thunderx.c
index f7c378a5f1bc..337aef12abcc 100644
--- a/drivers/spi/spi-cavium-thunderx.c
+++ b/drivers/spi/spi-cavium-thunderx.c
@@ -49,16 +49,12 @@ static int thunderx_spi_probe(struct pci_dev *pdev,
 	p->regs.tx = 0x1010;
 	p->regs.data = 0x1080;
 
-	p->clk = devm_clk_get(dev, NULL);
+	p->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(p->clk)) {
 		ret = PTR_ERR(p->clk);
 		goto error;
 	}
 
-	ret = clk_prepare_enable(p->clk);
-	if (ret)
-		goto error;
-
 	p->sys_freq = clk_get_rate(p->clk);
 	if (!p->sys_freq)
 		p->sys_freq = SYS_FREQ_DEFAULT;
@@ -82,7 +78,6 @@ static int thunderx_spi_probe(struct pci_dev *pdev,
 	return 0;
 
 error:
-	clk_disable_unprepare(p->clk);
 	pci_release_regions(pdev);
 	spi_controller_put(host);
 	return ret;
@@ -97,7 +92,6 @@ static void thunderx_spi_remove(struct pci_dev *pdev)
 	if (!p)
 		return;
 
-	clk_disable_unprepare(p->clk);
 	pci_release_regions(pdev);
 	/* Put everything in a known state. */
 	writeq(0, p->register_base + OCTEON_SPI_CFG(p));
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 10/25] spi: davinci: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (8 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 09/25] spi: spi-cavium-thunderx: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 11/25] spi: dw-bt1: " Li Zetao
                   ` (16 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-davinci.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index c457b550d3ad..5688be245c68 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -915,14 +915,11 @@ static int davinci_spi_probe(struct platform_device *pdev)
 
 	dspi->bitbang.master = host;
 
-	dspi->clk = devm_clk_get(&pdev->dev, NULL);
+	dspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(dspi->clk)) {
 		ret = -ENODEV;
 		goto free_host;
 	}
-	ret = clk_prepare_enable(dspi->clk);
-	if (ret)
-		goto free_host;
 
 	host->use_gpio_descriptors = true;
 	host->dev.of_node = pdev->dev.of_node;
@@ -947,7 +944,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
 
 	ret = davinci_spi_request_dma(dspi);
 	if (ret == -EPROBE_DEFER) {
-		goto free_clk;
+		goto free_host;
 	} else if (ret) {
 		dev_info(&pdev->dev, "DMA is not supported (%d)\n", ret);
 		dspi->dma_rx = NULL;
@@ -991,8 +988,6 @@ static int davinci_spi_probe(struct platform_device *pdev)
 		dma_release_channel(dspi->dma_rx);
 		dma_release_channel(dspi->dma_tx);
 	}
-free_clk:
-	clk_disable_unprepare(dspi->clk);
 free_host:
 	spi_controller_put(host);
 err:
@@ -1018,8 +1013,6 @@ static void davinci_spi_remove(struct platform_device *pdev)
 
 	spi_bitbang_stop(&dspi->bitbang);
 
-	clk_disable_unprepare(dspi->clk);
-
 	if (dspi->dma_rx) {
 		dma_release_channel(dspi->dma_rx);
 		dma_release_channel(dspi->dma_tx);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 11/25] spi: dw-bt1: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (9 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 10/25] spi: davinci: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:48   ` Serge Semin
  2023-08-22 13:12 ` [PATCH -next 12/25] spi: dw-mmio: Use helper function devm_clk_get_*() Li Zetao
                   ` (15 subsequent siblings)
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-dw-bt1.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c
index 5e1c01822967..5391bcac305c 100644
--- a/drivers/spi/spi-dw-bt1.c
+++ b/drivers/spi/spi-dw-bt1.c
@@ -269,43 +269,32 @@ static int dw_spi_bt1_probe(struct platform_device *pdev)
 
 	dws->paddr = mem->start;
 
-	dwsbt1->clk = devm_clk_get(&pdev->dev, NULL);
+	dwsbt1->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(dwsbt1->clk))
 		return PTR_ERR(dwsbt1->clk);
 
-	ret = clk_prepare_enable(dwsbt1->clk);
-	if (ret)
-		return ret;
-
 	dws->bus_num = pdev->id;
 	dws->reg_io_width = 4;
 	dws->max_freq = clk_get_rate(dwsbt1->clk);
-	if (!dws->max_freq) {
-		ret = -EINVAL;
-		goto err_disable_clk;
-	}
+	if (!dws->max_freq)
+		return -EINVAL;
 
 	init_func = device_get_match_data(&pdev->dev);
 	ret = init_func(pdev, dwsbt1);
 	if (ret)
-		goto err_disable_clk;
+		return ret;
 
 	pm_runtime_enable(&pdev->dev);
 
 	ret = dw_spi_add_host(&pdev->dev, dws);
 	if (ret) {
 		pm_runtime_disable(&pdev->dev);
-		goto err_disable_clk;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, dwsbt1);
 
 	return 0;
-
-err_disable_clk:
-	clk_disable_unprepare(dwsbt1->clk);
-
-	return ret;
 }
 
 static void dw_spi_bt1_remove(struct platform_device *pdev)
@@ -315,8 +304,6 @@ static void dw_spi_bt1_remove(struct platform_device *pdev)
 	dw_spi_remove_host(&dwsbt1->dws);
 
 	pm_runtime_disable(&pdev->dev);
-
-	clk_disable_unprepare(dwsbt1->clk);
 }
 
 static const struct of_device_id dw_spi_bt1_of_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 12/25] spi: dw-mmio: Use helper function devm_clk_get_*()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (10 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 11/25] spi: dw-bt1: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:46   ` Serge Semin
  2023-08-22 13:12 ` [PATCH -next 13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled() Li Zetao
                   ` (14 subsequent siblings)
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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. Also,
devm_clk_get_optional() and clk_prepare_enable() can now be replaced by
devm_clk_get_optional_enabled(). Moreover, the lable "out_clk" no longer
makes sense, rename it to "out_reset".

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/spi/spi-dw-mmio.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index 805264c9c65c..6d9f64ecbfd6 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -340,28 +340,22 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
 	if (dws->irq < 0)
 		return dws->irq; /* -ENXIO */
 
-	dwsmmio->clk = devm_clk_get(&pdev->dev, NULL);
+	dwsmmio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(dwsmmio->clk))
 		return PTR_ERR(dwsmmio->clk);
-	ret = clk_prepare_enable(dwsmmio->clk);
-	if (ret)
-		return ret;
 
 	/* Optional clock needed to access the registers */
-	dwsmmio->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
+	dwsmmio->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
 	if (IS_ERR(dwsmmio->pclk)) {
 		ret = PTR_ERR(dwsmmio->pclk);
-		goto out_clk;
+		goto out_reset;
 	}
-	ret = clk_prepare_enable(dwsmmio->pclk);
-	if (ret)
-		goto out_clk;
 
 	/* find an optional reset controller */
 	dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi");
 	if (IS_ERR(dwsmmio->rstc)) {
 		ret = PTR_ERR(dwsmmio->rstc);
-		goto out_clk;
+		goto out_reset;
 	}
 	reset_control_deassert(dwsmmio->rstc);
 
@@ -397,9 +391,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
 
 out:
 	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(dwsmmio->pclk);
-out_clk:
-	clk_disable_unprepare(dwsmmio->clk);
+out_reset:
 	reset_control_assert(dwsmmio->rstc);
 
 	return ret;
@@ -411,8 +403,6 @@ static void dw_spi_mmio_remove(struct platform_device *pdev)
 
 	dw_spi_remove_host(&dwsmmio->dws);
 	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(dwsmmio->pclk);
-	clk_disable_unprepare(dwsmmio->clk);
 	reset_control_assert(dwsmmio->rstc);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (11 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 12/25] spi: dw-mmio: Use helper function devm_clk_get_*() Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 14/25] spi: lantiq-ssc: " Li Zetao
                   ` (13 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-fsl-dspi.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 8318249f8a1f..c9eae046f66c 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -1372,19 +1372,16 @@ static int dspi_probe(struct platform_device *pdev)
 		}
 	}
 
-	dspi->clk = devm_clk_get(&pdev->dev, "dspi");
+	dspi->clk = devm_clk_get_enabled(&pdev->dev, "dspi");
 	if (IS_ERR(dspi->clk)) {
 		ret = PTR_ERR(dspi->clk);
 		dev_err(&pdev->dev, "unable to get clock\n");
 		goto out_ctlr_put;
 	}
-	ret = clk_prepare_enable(dspi->clk);
-	if (ret)
-		goto out_ctlr_put;
 
 	ret = dspi_init(dspi);
 	if (ret)
-		goto out_clk_put;
+		goto out_ctlr_put;
 
 	dspi->irq = platform_get_irq(pdev, 0);
 	if (dspi->irq <= 0) {
@@ -1400,7 +1397,7 @@ static int dspi_probe(struct platform_device *pdev)
 				   IRQF_SHARED, pdev->name, dspi);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to attach DSPI interrupt\n");
-		goto out_clk_put;
+		goto out_ctlr_put;
 	}
 
 poll_mode:
@@ -1432,8 +1429,6 @@ static int dspi_probe(struct platform_device *pdev)
 out_free_irq:
 	if (dspi->irq)
 		free_irq(dspi->irq, dspi);
-out_clk_put:
-	clk_disable_unprepare(dspi->clk);
 out_ctlr_put:
 	spi_controller_put(ctlr);
 
@@ -1458,7 +1453,6 @@ static void dspi_remove(struct platform_device *pdev)
 	dspi_release_dma(dspi);
 	if (dspi->irq)
 		free_irq(dspi->irq, dspi);
-	clk_disable_unprepare(dspi->clk);
 }
 
 static void dspi_shutdown(struct platform_device *pdev)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 14/25] spi: lantiq-ssc: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (12 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled() Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 15/25] spi: meson-spicc: " Li Zetao
                   ` (12 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-lantiq-ssc.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-lantiq-ssc.c b/drivers/spi/spi-lantiq-ssc.c
index 938e9e577e4f..18a46569ba46 100644
--- a/drivers/spi/spi-lantiq-ssc.c
+++ b/drivers/spi/spi-lantiq-ssc.c
@@ -932,14 +932,11 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
 	if (err)
 		goto err_host_put;
 
-	spi->spi_clk = devm_clk_get(dev, "gate");
+	spi->spi_clk = devm_clk_get_enabled(dev, "gate");
 	if (IS_ERR(spi->spi_clk)) {
 		err = PTR_ERR(spi->spi_clk);
 		goto err_host_put;
 	}
-	err = clk_prepare_enable(spi->spi_clk);
-	if (err)
-		goto err_host_put;
 
 	/*
 	 * Use the old clk_get_fpi() function on Lantiq platform, till it
@@ -952,7 +949,7 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
 #endif
 	if (IS_ERR(spi->fpi_clk)) {
 		err = PTR_ERR(spi->fpi_clk);
-		goto err_clk_disable;
+		goto err_host_put;
 	}
 
 	num_cs = 8;
@@ -1010,8 +1007,6 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
 	destroy_workqueue(spi->wq);
 err_clk_put:
 	clk_put(spi->fpi_clk);
-err_clk_disable:
-	clk_disable_unprepare(spi->spi_clk);
 err_host_put:
 	spi_controller_put(host);
 
@@ -1029,7 +1024,6 @@ static void lantiq_ssc_remove(struct platform_device *pdev)
 	hw_enter_config_mode(spi);
 
 	destroy_workqueue(spi->wq);
-	clk_disable_unprepare(spi->spi_clk);
 	clk_put(spi->fpi_clk);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 15/25] spi: meson-spicc: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (13 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 14/25] spi: lantiq-ssc: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 16/25] spi: spi-meson-spifc: " Li Zetao
                   ` (11 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-meson-spicc.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

diff --git a/drivers/spi/spi-meson-spicc.c b/drivers/spi/spi-meson-spicc.c
index 43d134f4b42b..1f2d26254e03 100644
--- a/drivers/spi/spi-meson-spicc.c
+++ b/drivers/spi/spi-meson-spicc.c
@@ -820,7 +820,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
 		goto out_master;
 	}
 
-	spicc->core = devm_clk_get(&pdev->dev, "core");
+	spicc->core = devm_clk_get_enabled(&pdev->dev, "core");
 	if (IS_ERR(spicc->core)) {
 		dev_err(&pdev->dev, "core clock request failed\n");
 		ret = PTR_ERR(spicc->core);
@@ -828,7 +828,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
 	}
 
 	if (spicc->data->has_pclk) {
-		spicc->pclk = devm_clk_get(&pdev->dev, "pclk");
+		spicc->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
 		if (IS_ERR(spicc->pclk)) {
 			dev_err(&pdev->dev, "pclk clock request failed\n");
 			ret = PTR_ERR(spicc->pclk);
@@ -836,22 +836,10 @@ static int meson_spicc_probe(struct platform_device *pdev)
 		}
 	}
 
-	ret = clk_prepare_enable(spicc->core);
-	if (ret) {
-		dev_err(&pdev->dev, "core clock enable failed\n");
-		goto out_master;
-	}
-
-	ret = clk_prepare_enable(spicc->pclk);
-	if (ret) {
-		dev_err(&pdev->dev, "pclk clock enable failed\n");
-		goto out_core_clk;
-	}
-
 	spicc->pinctrl = devm_pinctrl_get(&pdev->dev);
 	if (IS_ERR(spicc->pinctrl)) {
 		ret = PTR_ERR(spicc->pinctrl);
-		goto out_clk;
+		goto out_master;
 	}
 
 	device_reset_optional(&pdev->dev);
@@ -878,31 +866,25 @@ static int meson_spicc_probe(struct platform_device *pdev)
 	ret = meson_spicc_pow2_clk_init(spicc);
 	if (ret) {
 		dev_err(&pdev->dev, "pow2 clock registration failed\n");
-		goto out_clk;
+		goto out_master;
 	}
 
 	if (spicc->data->has_enhance_clk_div) {
 		ret = meson_spicc_enh_clk_init(spicc);
 		if (ret) {
 			dev_err(&pdev->dev, "clock registration failed\n");
-			goto out_clk;
+			goto out_master;
 		}
 	}
 
 	ret = devm_spi_register_master(&pdev->dev, master);
 	if (ret) {
 		dev_err(&pdev->dev, "spi master registration failed\n");
-		goto out_clk;
+		goto out_master;
 	}
 
 	return 0;
 
-out_clk:
-	clk_disable_unprepare(spicc->pclk);
-
-out_core_clk:
-	clk_disable_unprepare(spicc->core);
-
 out_master:
 	spi_master_put(master);
 
@@ -916,9 +898,6 @@ static void meson_spicc_remove(struct platform_device *pdev)
 	/* Disable SPI */
 	writel(0, spicc->base + SPICC_CONREG);
 
-	clk_disable_unprepare(spicc->core);
-	clk_disable_unprepare(spicc->pclk);
-
 	spi_master_put(spicc->master);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 16/25] spi: spi-meson-spifc: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (14 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 15/25] spi: meson-spicc: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 17/25] spi: microchip-core-qspi: " Li Zetao
                   ` (10 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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.
Moreover, the lable "out_clk" no longer makes sense, rename it to "out_pm".

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/spi/spi-meson-spifc.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/spi-meson-spifc.c b/drivers/spi/spi-meson-spifc.c
index 06626f406f68..d70a18885b49 100644
--- a/drivers/spi/spi-meson-spifc.c
+++ b/drivers/spi/spi-meson-spifc.c
@@ -312,19 +312,13 @@ static int meson_spifc_probe(struct platform_device *pdev)
 		goto out_err;
 	}
 
-	spifc->clk = devm_clk_get(spifc->dev, NULL);
+	spifc->clk = devm_clk_get_enabled(spifc->dev, NULL);
 	if (IS_ERR(spifc->clk)) {
 		dev_err(spifc->dev, "missing clock\n");
 		ret = PTR_ERR(spifc->clk);
 		goto out_err;
 	}
 
-	ret = clk_prepare_enable(spifc->clk);
-	if (ret) {
-		dev_err(spifc->dev, "can't prepare clock\n");
-		goto out_err;
-	}
-
 	rate = clk_get_rate(spifc->clk);
 
 	master->num_chipselect = 1;
@@ -343,12 +337,11 @@ static int meson_spifc_probe(struct platform_device *pdev)
 	ret = devm_spi_register_master(spifc->dev, master);
 	if (ret) {
 		dev_err(spifc->dev, "failed to register spi master\n");
-		goto out_clk;
+		goto out_pm;
 	}
 
 	return 0;
-out_clk:
-	clk_disable_unprepare(spifc->clk);
+out_pm:
 	pm_runtime_disable(spifc->dev);
 out_err:
 	spi_master_put(master);
@@ -357,11 +350,7 @@ static int meson_spifc_probe(struct platform_device *pdev)
 
 static void meson_spifc_remove(struct platform_device *pdev)
 {
-	struct spi_master *master = platform_get_drvdata(pdev);
-	struct meson_spifc *spifc = spi_master_get_devdata(master);
-
 	pm_runtime_get_sync(&pdev->dev);
-	clk_disable_unprepare(spifc->clk);
 	pm_runtime_disable(&pdev->dev);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 17/25] spi: microchip-core-qspi: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (15 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 16/25] spi: spi-meson-spifc: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 18/25] spi: microchip-core: " Li Zetao
                   ` (9 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-microchip-core-qspi.c | 29 +++++++--------------------
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/drivers/spi/spi-microchip-core-qspi.c b/drivers/spi/spi-microchip-core-qspi.c
index 4f76ddf97b10..396dfc0fa278 100644
--- a/drivers/spi/spi-microchip-core-qspi.c
+++ b/drivers/spi/spi-microchip-core-qspi.c
@@ -518,30 +518,23 @@ static int mchp_coreqspi_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, PTR_ERR(qspi->regs),
 				     "failed to map registers\n");
 
-	qspi->clk = devm_clk_get(&pdev->dev, NULL);
+	qspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(qspi->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(qspi->clk),
 				     "could not get clock\n");
 
-	ret = clk_prepare_enable(qspi->clk);
-	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
-				     "failed to enable clock\n");
-
 	init_completion(&qspi->data_completion);
 	mutex_init(&qspi->op_lock);
 
 	qspi->irq = platform_get_irq(pdev, 0);
-	if (qspi->irq < 0) {
-		ret = qspi->irq;
-		goto out;
-	}
+	if (qspi->irq < 0)
+		return qspi->irq;
 
 	ret = devm_request_irq(&pdev->dev, qspi->irq, mchp_coreqspi_isr,
 			       IRQF_SHARED, pdev->name, qspi);
 	if (ret) {
 		dev_err(&pdev->dev, "request_irq failed %d\n", ret);
-		goto out;
+		return ret;
 	}
 
 	ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
@@ -552,18 +545,11 @@ static int mchp_coreqspi_probe(struct platform_device *pdev)
 	ctlr->dev.of_node = np;
 
 	ret = devm_spi_register_controller(&pdev->dev, ctlr);
-	if (ret) {
-		dev_err_probe(&pdev->dev, ret,
-			      "spi_register_controller failed\n");
-		goto out;
-	}
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "spi_register_controller failed\n");
 
 	return 0;
-
-out:
-	clk_disable_unprepare(qspi->clk);
-
-	return ret;
 }
 
 static void mchp_coreqspi_remove(struct platform_device *pdev)
@@ -574,7 +560,6 @@ static void mchp_coreqspi_remove(struct platform_device *pdev)
 	mchp_coreqspi_disable_ints(qspi);
 	control &= ~CONTROL_ENABLE;
 	writel_relaxed(control, qspi->regs + REG_CONTROL);
-	clk_disable_unprepare(qspi->clk);
 }
 
 static const struct of_device_id mchp_coreqspi_of_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 18/25] spi: microchip-core: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (16 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 17/25] spi: microchip-core-qspi: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 19/25] spi: mtk-snfi: " Li Zetao
                   ` (8 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-microchip-core.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/spi/spi-microchip-core.c b/drivers/spi/spi-microchip-core.c
index b451cd4860ec..becdcdc9e6d1 100644
--- a/drivers/spi/spi-microchip-core.c
+++ b/drivers/spi/spi-microchip-core.c
@@ -539,22 +539,16 @@ static int mchp_corespi_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, ret,
 				     "could not request irq\n");
 
-	spi->clk = devm_clk_get(&pdev->dev, NULL);
+	spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(spi->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk),
 				     "could not get clk\n");
 
-	ret = clk_prepare_enable(spi->clk);
-	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
-				     "failed to enable clock\n");
-
 	mchp_corespi_init(master, spi);
 
 	ret = devm_spi_register_master(&pdev->dev, master);
 	if (ret) {
 		mchp_corespi_disable(spi);
-		clk_disable_unprepare(spi->clk);
 		return dev_err_probe(&pdev->dev, ret,
 				     "unable to register master for SPI controller\n");
 	}
@@ -570,7 +564,6 @@ static void mchp_corespi_remove(struct platform_device *pdev)
 	struct mchp_corespi *spi = spi_master_get_devdata(master);
 
 	mchp_corespi_disable_ints(spi);
-	clk_disable_unprepare(spi->clk);
 	mchp_corespi_disable(spi);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 19/25] spi: mtk-snfi: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (17 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 18/25] spi: microchip-core: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 20/25] spi: npcm-fiu: " Li Zetao
                   ` (7 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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.
Also, devm_clk_get_optional() and clk_prepare_enable() can now be
replaced by devm_clk_get_optional_enabled().Moreover, the two functions
mtk_snand_enable_clk() and mtk_snand_disable_clk() no longer are used,
drop them for clean code.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/spi/spi-mtk-snfi.c | 61 ++++++--------------------------------
 1 file changed, 9 insertions(+), 52 deletions(-)

diff --git a/drivers/spi/spi-mtk-snfi.c b/drivers/spi/spi-mtk-snfi.c
index 4433a8a9299f..8ad5a4764855 100644
--- a/drivers/spi/spi-mtk-snfi.c
+++ b/drivers/spi/spi-mtk-snfi.c
@@ -1332,42 +1332,6 @@ static const struct of_device_id mtk_snand_ids[] = {
 
 MODULE_DEVICE_TABLE(of, mtk_snand_ids);
 
-static int mtk_snand_enable_clk(struct mtk_snand *ms)
-{
-	int ret;
-
-	ret = clk_prepare_enable(ms->nfi_clk);
-	if (ret) {
-		dev_err(ms->dev, "unable to enable nfi clk\n");
-		return ret;
-	}
-	ret = clk_prepare_enable(ms->pad_clk);
-	if (ret) {
-		dev_err(ms->dev, "unable to enable pad clk\n");
-		goto err1;
-	}
-	ret = clk_prepare_enable(ms->nfi_hclk);
-	if (ret) {
-		dev_err(ms->dev, "unable to enable nfi hclk\n");
-		goto err2;
-	}
-
-	return 0;
-
-err2:
-	clk_disable_unprepare(ms->pad_clk);
-err1:
-	clk_disable_unprepare(ms->nfi_clk);
-	return ret;
-}
-
-static void mtk_snand_disable_clk(struct mtk_snand *ms)
-{
-	clk_disable_unprepare(ms->nfi_hclk);
-	clk_disable_unprepare(ms->pad_clk);
-	clk_disable_unprepare(ms->nfi_clk);
-}
-
 static int mtk_snand_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1406,49 +1370,45 @@ static int mtk_snand_probe(struct platform_device *pdev)
 
 	ms->dev = &pdev->dev;
 
-	ms->nfi_clk = devm_clk_get(&pdev->dev, "nfi_clk");
+	ms->nfi_clk = devm_clk_get_enabled(&pdev->dev, "nfi_clk");
 	if (IS_ERR(ms->nfi_clk)) {
 		ret = PTR_ERR(ms->nfi_clk);
 		dev_err(&pdev->dev, "unable to get nfi_clk, err = %d\n", ret);
 		goto release_ecc;
 	}
 
-	ms->pad_clk = devm_clk_get(&pdev->dev, "pad_clk");
+	ms->pad_clk = devm_clk_get_enabled(&pdev->dev, "pad_clk");
 	if (IS_ERR(ms->pad_clk)) {
 		ret = PTR_ERR(ms->pad_clk);
 		dev_err(&pdev->dev, "unable to get pad_clk, err = %d\n", ret);
 		goto release_ecc;
 	}
 
-	ms->nfi_hclk = devm_clk_get_optional(&pdev->dev, "nfi_hclk");
+	ms->nfi_hclk = devm_clk_get_optional_enabled(&pdev->dev, "nfi_hclk");
 	if (IS_ERR(ms->nfi_hclk)) {
 		ret = PTR_ERR(ms->nfi_hclk);
 		dev_err(&pdev->dev, "unable to get nfi_hclk, err = %d\n", ret);
 		goto release_ecc;
 	}
 
-	ret = mtk_snand_enable_clk(ms);
-	if (ret)
-		goto release_ecc;
-
 	init_completion(&ms->op_done);
 
 	ms->irq = platform_get_irq(pdev, 0);
 	if (ms->irq < 0) {
 		ret = ms->irq;
-		goto disable_clk;
+		goto release_ecc;
 	}
 	ret = devm_request_irq(ms->dev, ms->irq, mtk_snand_irq, 0x0,
 			       "mtk-snand", ms);
 	if (ret) {
 		dev_err(ms->dev, "failed to request snfi irq\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	ret = dma_set_mask(ms->dev, DMA_BIT_MASK(32));
 	if (ret) {
 		dev_err(ms->dev, "failed to set dma mask\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	// switch to SNFI mode
@@ -1472,7 +1432,7 @@ static int mtk_snand_probe(struct platform_device *pdev)
 	ret = mtk_snand_setup_pagefmt(ms, SZ_2K, SZ_64);
 	if (ret) {
 		dev_err(ms->dev, "failed to set initial page format\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	// setup ECC engine
@@ -1484,7 +1444,7 @@ static int mtk_snand_probe(struct platform_device *pdev)
 	ret = nand_ecc_register_on_host_hw_engine(&ms->ecc_eng);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register ecc engine.\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	ctlr->num_chipselect = 1;
@@ -1496,12 +1456,10 @@ static int mtk_snand_probe(struct platform_device *pdev)
 	ret = spi_register_controller(ctlr);
 	if (ret) {
 		dev_err(&pdev->dev, "spi_register_controller failed.\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	return 0;
-disable_clk:
-	mtk_snand_disable_clk(ms);
 release_ecc:
 	mtk_ecc_release(ms->ecc);
 	return ret;
@@ -1513,7 +1471,6 @@ static void mtk_snand_remove(struct platform_device *pdev)
 	struct mtk_snand *ms = spi_controller_get_devdata(ctlr);
 
 	spi_unregister_controller(ctlr);
-	mtk_snand_disable_clk(ms);
 	mtk_ecc_release(ms->ecc);
 	kfree(ms->buf);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 20/25] spi: npcm-fiu: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (18 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 19/25] spi: mtk-snfi: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 21/25] spi: orion: " Li Zetao
                   ` (6 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-npcm-fiu.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi-npcm-fiu.c b/drivers/spi/spi-npcm-fiu.c
index 0ca21ff0e9cc..1a5277ff349f 100644
--- a/drivers/spi/spi-npcm-fiu.c
+++ b/drivers/spi/spi-npcm-fiu.c
@@ -699,7 +699,7 @@ static int npcm_fiu_probe(struct platform_device *pdev)
 	struct spi_controller *ctrl;
 	struct npcm_fiu_spi *fiu;
 	void __iomem *regbase;
-	int id, ret;
+	int id;
 
 	ctrl = devm_spi_alloc_host(dev, sizeof(*fiu));
 	if (!ctrl)
@@ -737,7 +737,7 @@ static int npcm_fiu_probe(struct platform_device *pdev)
 
 	fiu->res_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
 						    "memory");
-	fiu->clk = devm_clk_get(dev, NULL);
+	fiu->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(fiu->clk))
 		return PTR_ERR(fiu->clk);
 
@@ -745,7 +745,6 @@ static int npcm_fiu_probe(struct platform_device *pdev)
 					       "nuvoton,spix-mode");
 
 	platform_set_drvdata(pdev, fiu);
-	clk_prepare_enable(fiu->clk);
 
 	ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD
 		| SPI_TX_DUAL | SPI_TX_QUAD;
@@ -755,18 +754,11 @@ static int npcm_fiu_probe(struct platform_device *pdev)
 	ctrl->num_chipselect = fiu->info->max_cs;
 	ctrl->dev.of_node = dev->of_node;
 
-	ret = devm_spi_register_controller(dev, ctrl);
-	if (ret)
-		clk_disable_unprepare(fiu->clk);
-
-	return ret;
+	return devm_spi_register_controller(dev, ctrl);
 }
 
 static void npcm_fiu_remove(struct platform_device *pdev)
 {
-	struct npcm_fiu_spi *fiu = platform_get_drvdata(pdev);
-
-	clk_disable_unprepare(fiu->clk);
 }
 
 MODULE_DEVICE_TABLE(of, npcm_fiu_dt_ids);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 21/25] spi: orion: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (19 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 20/25] spi: npcm-fiu: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 22/25] spi: pic32-sqi: " Li Zetao
                   ` (5 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-orion.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index faf2764b91a8..d22bb67fee00 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -688,21 +688,17 @@ static int orion_spi_probe(struct platform_device *pdev)
 	devdata = devdata ? devdata : &orion_spi_dev_data;
 	spi->devdata = devdata;
 
-	spi->clk = devm_clk_get(&pdev->dev, NULL);
+	spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(spi->clk)) {
 		status = PTR_ERR(spi->clk);
 		goto out;
 	}
 
-	status = clk_prepare_enable(spi->clk);
-	if (status)
-		goto out;
-
 	/* The following clock is only used by some SoCs */
 	spi->axi_clk = devm_clk_get(&pdev->dev, "axi");
 	if (PTR_ERR(spi->axi_clk) == -EPROBE_DEFER) {
 		status = -EPROBE_DEFER;
-		goto out_rel_clk;
+		goto out;
 	}
 	if (!IS_ERR(spi->axi_clk))
 		clk_prepare_enable(spi->axi_clk);
@@ -795,8 +791,6 @@ static int orion_spi_probe(struct platform_device *pdev)
 	pm_runtime_disable(&pdev->dev);
 out_rel_axi_clk:
 	clk_disable_unprepare(spi->axi_clk);
-out_rel_clk:
-	clk_disable_unprepare(spi->clk);
 out:
 	spi_master_put(master);
 	return status;
@@ -810,7 +804,6 @@ static void orion_spi_remove(struct platform_device *pdev)
 
 	pm_runtime_get_sync(&pdev->dev);
 	clk_disable_unprepare(spi->axi_clk);
-	clk_disable_unprepare(spi->clk);
 
 	spi_unregister_master(master);
 	pm_runtime_disable(&pdev->dev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 22/25] spi: pic32-sqi: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (20 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 21/25] spi: orion: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 23/25] spi: pic32: " Li Zetao
                   ` (4 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-pic32-sqi.c | 27 +++------------------------
 1 file changed, 3 insertions(+), 24 deletions(-)

diff --git a/drivers/spi/spi-pic32-sqi.c b/drivers/spi/spi-pic32-sqi.c
index 5cbebcf26a2a..d894b99e4104 100644
--- a/drivers/spi/spi-pic32-sqi.c
+++ b/drivers/spi/spi-pic32-sqi.c
@@ -593,33 +593,20 @@ static int pic32_sqi_probe(struct platform_device *pdev)
 	}
 
 	/* clocks */
-	sqi->sys_clk = devm_clk_get(&pdev->dev, "reg_ck");
+	sqi->sys_clk = devm_clk_get_enabled(&pdev->dev, "reg_ck");
 	if (IS_ERR(sqi->sys_clk)) {
 		ret = PTR_ERR(sqi->sys_clk);
 		dev_err(&pdev->dev, "no sys_clk ?\n");
 		goto err_free_master;
 	}
 
-	sqi->base_clk = devm_clk_get(&pdev->dev, "spi_ck");
+	sqi->base_clk = devm_clk_get_enabled(&pdev->dev, "spi_ck");
 	if (IS_ERR(sqi->base_clk)) {
 		ret = PTR_ERR(sqi->base_clk);
 		dev_err(&pdev->dev, "no base clk ?\n");
 		goto err_free_master;
 	}
 
-	ret = clk_prepare_enable(sqi->sys_clk);
-	if (ret) {
-		dev_err(&pdev->dev, "sys clk enable failed\n");
-		goto err_free_master;
-	}
-
-	ret = clk_prepare_enable(sqi->base_clk);
-	if (ret) {
-		dev_err(&pdev->dev, "base clk enable failed\n");
-		clk_disable_unprepare(sqi->sys_clk);
-		goto err_free_master;
-	}
-
 	init_completion(&sqi->xfer_done);
 
 	/* initialize hardware */
@@ -629,7 +616,7 @@ static int pic32_sqi_probe(struct platform_device *pdev)
 	ret = ring_desc_ring_alloc(sqi);
 	if (ret) {
 		dev_err(&pdev->dev, "ring alloc failed\n");
-		goto err_disable_clk;
+		goto err_free_master;
 	}
 
 	/* install irq handlers */
@@ -669,10 +656,6 @@ static int pic32_sqi_probe(struct platform_device *pdev)
 err_free_ring:
 	ring_desc_ring_free(sqi);
 
-err_disable_clk:
-	clk_disable_unprepare(sqi->base_clk);
-	clk_disable_unprepare(sqi->sys_clk);
-
 err_free_master:
 	spi_master_put(master);
 	return ret;
@@ -685,10 +668,6 @@ static void pic32_sqi_remove(struct platform_device *pdev)
 	/* release resources */
 	free_irq(sqi->irq, sqi);
 	ring_desc_ring_free(sqi);
-
-	/* disable clk */
-	clk_disable_unprepare(sqi->base_clk);
-	clk_disable_unprepare(sqi->sys_clk);
 }
 
 static const struct of_device_id pic32_sqi_of_ids[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 23/25] spi: pic32: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (21 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 22/25] spi: pic32-sqi: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 13:12 ` [PATCH -next 24/25] spi: spl022: " Li Zetao
                   ` (3 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-pic32.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/spi/spi-pic32.c b/drivers/spi/spi-pic32.c
index e9b4c9cb97fb..2b0680974cba 100644
--- a/drivers/spi/spi-pic32.c
+++ b/drivers/spi/spi-pic32.c
@@ -730,17 +730,13 @@ static int pic32_spi_hw_probe(struct platform_device *pdev,
 		return pic32s->tx_irq;
 
 	/* get clock */
-	pic32s->clk = devm_clk_get(&pdev->dev, "mck0");
+	pic32s->clk = devm_clk_get_enabled(&pdev->dev, "mck0");
 	if (IS_ERR(pic32s->clk)) {
 		dev_err(&pdev->dev, "clk not found\n");
 		ret = PTR_ERR(pic32s->clk);
 		goto err_unmap_mem;
 	}
 
-	ret = clk_prepare_enable(pic32s->clk);
-	if (ret)
-		goto err_unmap_mem;
-
 	pic32_spi_hw_init(pic32s);
 
 	return 0;
@@ -837,7 +833,6 @@ static int pic32_spi_probe(struct platform_device *pdev)
 
 err_bailout:
 	pic32_spi_dma_unprep(pic32s);
-	clk_disable_unprepare(pic32s->clk);
 err_master:
 	spi_master_put(master);
 	return ret;
@@ -849,7 +844,6 @@ static void pic32_spi_remove(struct platform_device *pdev)
 
 	pic32s = platform_get_drvdata(pdev);
 	pic32_spi_disable(pic32s);
-	clk_disable_unprepare(pic32s->clk);
 	pic32_spi_dma_unprep(pic32s);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 24/25] spi: spl022: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (22 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 23/25] spi: pic32: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-08-22 16:14   ` Jonathan Cameron
  2023-08-23  6:55   ` Linus Walleij
  2023-08-22 13:12 ` [PATCH -next 25/25] spi: rockchip: " Li Zetao
                   ` (2 subsequent siblings)
  26 siblings, 2 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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.
Moreover, the label "err_no_clk_en" is no used, drop it for clean code.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/spi/spi-pl022.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 1af75eff26b6..468a7fea9091 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -2168,19 +2168,13 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
 	dev_info(&adev->dev, "mapped registers from %pa to %p\n",
 		&adev->res.start, pl022->virtbase);
 
-	pl022->clk = devm_clk_get(&adev->dev, NULL);
+	pl022->clk = devm_clk_get_enabled(&adev->dev, NULL);
 	if (IS_ERR(pl022->clk)) {
 		status = PTR_ERR(pl022->clk);
 		dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
 		goto err_no_clk;
 	}
 
-	status = clk_prepare_enable(pl022->clk);
-	if (status) {
-		dev_err(&adev->dev, "could not enable SSP/SPI bus clock\n");
-		goto err_no_clk_en;
-	}
-
 	/* Initialize transfer pump */
 	tasklet_init(&pl022->pump_transfers, pump_transfers,
 		     (unsigned long)pl022);
@@ -2236,16 +2230,14 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
 
 	return 0;
 
- err_spi_register:
+err_spi_register:
 	if (platform_info->enable_dma)
 		pl022_dma_remove(pl022);
- err_no_irq:
-	clk_disable_unprepare(pl022->clk);
- err_no_clk_en:
- err_no_clk:
- err_no_ioremap:
+err_no_irq:
+err_no_clk:
+err_no_ioremap:
 	amba_release_regions(adev);
- err_no_ioregion:
+err_no_ioregion:
 	spi_master_put(master);
 	return status;
 }
@@ -2268,7 +2260,6 @@ pl022_remove(struct amba_device *adev)
 	if (pl022->master_info->enable_dma)
 		pl022_dma_remove(pl022);
 
-	clk_disable_unprepare(pl022->clk);
 	amba_release_regions(adev);
 	tasklet_disable(&pl022->pump_transfers);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next 25/25] spi: rockchip: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (23 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 24/25] spi: spl022: " Li Zetao
@ 2023-08-22 13:12 ` Li Zetao
  2023-10-04 21:18   ` Heiko Stübner
  2023-08-22 16:16 ` [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Jonathan Cameron
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-22 13:12 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

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 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/spi/spi-rockchip.c | 30 +++++-------------------------
 1 file changed, 5 insertions(+), 25 deletions(-)

diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index a37943847e81..cdbb86049d59 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -782,42 +782,30 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 		goto err_put_ctlr;
 	}
 
-	rs->apb_pclk = devm_clk_get(&pdev->dev, "apb_pclk");
+	rs->apb_pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk");
 	if (IS_ERR(rs->apb_pclk)) {
 		dev_err(&pdev->dev, "Failed to get apb_pclk\n");
 		ret = PTR_ERR(rs->apb_pclk);
 		goto err_put_ctlr;
 	}
 
-	rs->spiclk = devm_clk_get(&pdev->dev, "spiclk");
+	rs->spiclk = devm_clk_get_enabled(&pdev->dev, "spiclk");
 	if (IS_ERR(rs->spiclk)) {
 		dev_err(&pdev->dev, "Failed to get spi_pclk\n");
 		ret = PTR_ERR(rs->spiclk);
 		goto err_put_ctlr;
 	}
 
-	ret = clk_prepare_enable(rs->apb_pclk);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to enable apb_pclk\n");
-		goto err_put_ctlr;
-	}
-
-	ret = clk_prepare_enable(rs->spiclk);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to enable spi_clk\n");
-		goto err_disable_apbclk;
-	}
-
 	spi_enable_chip(rs, false);
 
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0)
-		goto err_disable_spiclk;
+		goto err_put_ctlr;
 
 	ret = devm_request_threaded_irq(&pdev->dev, ret, rockchip_spi_isr, NULL,
 			IRQF_ONESHOT, dev_name(&pdev->dev), ctlr);
 	if (ret)
-		goto err_disable_spiclk;
+		goto err_put_ctlr;
 
 	rs->dev = &pdev->dev;
 	rs->freq = clk_get_rate(rs->spiclk);
@@ -843,7 +831,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 	if (!rs->fifo_len) {
 		dev_err(&pdev->dev, "Failed to get fifo length\n");
 		ret = -EINVAL;
-		goto err_disable_spiclk;
+		goto err_put_ctlr;
 	}
 
 	pm_runtime_set_autosuspend_delay(&pdev->dev, ROCKCHIP_AUTOSUSPEND_TIMEOUT);
@@ -937,10 +925,6 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 		dma_release_channel(ctlr->dma_tx);
 err_disable_pm_runtime:
 	pm_runtime_disable(&pdev->dev);
-err_disable_spiclk:
-	clk_disable_unprepare(rs->spiclk);
-err_disable_apbclk:
-	clk_disable_unprepare(rs->apb_pclk);
 err_put_ctlr:
 	spi_controller_put(ctlr);
 
@@ -950,13 +934,9 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 static void rockchip_spi_remove(struct platform_device *pdev)
 {
 	struct spi_controller *ctlr = spi_controller_get(platform_get_drvdata(pdev));
-	struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
 
 	pm_runtime_get_sync(&pdev->dev);
 
-	clk_disable_unprepare(rs->spiclk);
-	clk_disable_unprepare(rs->apb_pclk);
-
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_set_suspended(&pdev->dev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* Re: [PATCH -next 12/25] spi: dw-mmio: Use helper function devm_clk_get_*()
  2023-08-22 13:12 ` [PATCH -next 12/25] spi: dw-mmio: Use helper function devm_clk_get_*() Li Zetao
@ 2023-08-22 13:46   ` Serge Semin
  0 siblings, 0 replies; 71+ messages in thread
From: Serge Semin @ 2023-08-22 13:46 UTC (permalink / raw)
  To: Li Zetao
  Cc: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko, linux-spi,
	linux-aspeed, openbmc, linux-arm-kernel, linux-rpi-kernel,
	linux-amlogic, linux-riscv, linux-mediatek, linux-rockchip

Hi Li

On Tue, Aug 22, 2023 at 09:12:24PM +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 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. Also,
> devm_clk_get_optional() and clk_prepare_enable() can now be replaced by
> devm_clk_get_optional_enabled(). Moreover, the lable "out_clk" no longer
> makes sense, rename it to "out_reset".
> 
> Signed-off-by: Li Zetao <lizetao1@huawei.com>

Several nitpicks below please since you are touching the code anyway.

> ---
>  drivers/spi/spi-dw-mmio.c | 20 +++++---------------
>  1 file changed, 5 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
> index 805264c9c65c..6d9f64ecbfd6 100644
> --- a/drivers/spi/spi-dw-mmio.c
> +++ b/drivers/spi/spi-dw-mmio.c
> @@ -340,28 +340,22 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
>  	if (dws->irq < 0)
>  		return dws->irq; /* -ENXIO */
>  
> -	dwsmmio->clk = devm_clk_get(&pdev->dev, NULL);
> +	dwsmmio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  	if (IS_ERR(dwsmmio->clk))
>  		return PTR_ERR(dwsmmio->clk);
> -	ret = clk_prepare_enable(dwsmmio->clk);
> -	if (ret)
> -		return ret;
>  
>  	/* Optional clock needed to access the registers */
> -	dwsmmio->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> +	dwsmmio->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");

>  	if (IS_ERR(dwsmmio->pclk)) {
>  		ret = PTR_ERR(dwsmmio->pclk);
> -		goto out_clk;
> +		goto out_reset;
>  	}

Just return from here please. There is no point in calling
reset_control_deassert() on error because the reset control handler
hasn't been requested yet. So the argument will be NULL and considered
as optional reset-control.

> -	ret = clk_prepare_enable(dwsmmio->pclk);
> -	if (ret)
> -		goto out_clk;
>  
>  	/* find an optional reset controller */
>  	dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi");

>  	if (IS_ERR(dwsmmio->rstc)) {
>  		ret = PTR_ERR(dwsmmio->rstc);
> -		goto out_clk;
> +		goto out_reset;
>  	}

ditto


Please use the "out_reset" label in the next part of the code:
	init_func = device_get_match_data(&pdev->dev);
	if (init_func) {
		ret = init_func(pdev, dwsmmio);
		if (ret)
-			goto out;
+			goto out_reset;
	}

I know this changes the cleanup-on-error path logic. But since you are
touching exactly that code anyway it would be good to have it properly
fixed.

>  	reset_control_deassert(dwsmmio->rstc);
>  
> @@ -397,9 +391,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
>  
>  out:
>  	pm_runtime_disable(&pdev->dev);
> -	clk_disable_unprepare(dwsmmio->pclk);
> -out_clk:
> -	clk_disable_unprepare(dwsmmio->clk);
> +out_reset:
>  	reset_control_assert(dwsmmio->rstc);
>  
>  	return ret;
> @@ -411,8 +403,6 @@ static void dw_spi_mmio_remove(struct platform_device *pdev)
>  

>  	dw_spi_remove_host(&dwsmmio->dws);
>  	pm_runtime_disable(&pdev->dev);
> -	clk_disable_unprepare(dwsmmio->pclk);
> -	clk_disable_unprepare(dwsmmio->clk);
>  	reset_control_assert(dwsmmio->rstc);

The order here isn't correct too. But I guess we can live with it.
It isn't that important.

-Serge(y)

>  }
>  
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next 11/25] spi: dw-bt1: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 ` [PATCH -next 11/25] spi: dw-bt1: " Li Zetao
@ 2023-08-22 13:48   ` Serge Semin
  0 siblings, 0 replies; 71+ messages in thread
From: Serge Semin @ 2023-08-22 13:48 UTC (permalink / raw)
  To: Li Zetao
  Cc: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko, linux-spi,
	linux-aspeed, openbmc, linux-arm-kernel, linux-rpi-kernel,
	linux-amlogic, linux-riscv, linux-mediatek, linux-rockchip

On Tue, Aug 22, 2023 at 09:12:23PM +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 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>

LGTM. Thanks!
Acked-by: Serge Semin <fancer.lancer@gmail.com>

-Serge(y)

> ---
>  drivers/spi/spi-dw-bt1.c | 23 +++++------------------
>  1 file changed, 5 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c
> index 5e1c01822967..5391bcac305c 100644
> --- a/drivers/spi/spi-dw-bt1.c
> +++ b/drivers/spi/spi-dw-bt1.c
> @@ -269,43 +269,32 @@ static int dw_spi_bt1_probe(struct platform_device *pdev)
>  
>  	dws->paddr = mem->start;
>  
> -	dwsbt1->clk = devm_clk_get(&pdev->dev, NULL);
> +	dwsbt1->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  	if (IS_ERR(dwsbt1->clk))
>  		return PTR_ERR(dwsbt1->clk);
>  
> -	ret = clk_prepare_enable(dwsbt1->clk);
> -	if (ret)
> -		return ret;
> -
>  	dws->bus_num = pdev->id;
>  	dws->reg_io_width = 4;
>  	dws->max_freq = clk_get_rate(dwsbt1->clk);
> -	if (!dws->max_freq) {
> -		ret = -EINVAL;
> -		goto err_disable_clk;
> -	}
> +	if (!dws->max_freq)
> +		return -EINVAL;
>  
>  	init_func = device_get_match_data(&pdev->dev);
>  	ret = init_func(pdev, dwsbt1);
>  	if (ret)
> -		goto err_disable_clk;
> +		return ret;
>  
>  	pm_runtime_enable(&pdev->dev);
>  
>  	ret = dw_spi_add_host(&pdev->dev, dws);
>  	if (ret) {
>  		pm_runtime_disable(&pdev->dev);
> -		goto err_disable_clk;
> +		return ret;
>  	}
>  
>  	platform_set_drvdata(pdev, dwsbt1);
>  
>  	return 0;
> -
> -err_disable_clk:
> -	clk_disable_unprepare(dwsbt1->clk);
> -
> -	return ret;
>  }
>  
>  static void dw_spi_bt1_remove(struct platform_device *pdev)
> @@ -315,8 +304,6 @@ static void dw_spi_bt1_remove(struct platform_device *pdev)
>  	dw_spi_remove_host(&dwsbt1->dws);
>  
>  	pm_runtime_disable(&pdev->dev);
> -
> -	clk_disable_unprepare(dwsbt1->clk);
>  }
>  
>  static const struct of_device_id dw_spi_bt1_of_match[] = {
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared()
  2023-08-22 13:12 ` [PATCH -next 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared() Li Zetao
@ 2023-08-22 15:55   ` Jonathan Cameron
  0 siblings, 0 replies; 71+ messages in thread
From: Jonathan Cameron @ 2023-08-22 15:55 UTC (permalink / raw)
  To: Li Zetao
  Cc: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko, linux-spi,
	linux-aspeed, openbmc, linux-arm-kernel, linux-rpi-kernel,
	linux-amlogic, linux-riscv, linux-mediatek, linux-rockchip


> @@ -909,10 +901,6 @@ static int a3700_spi_probe(struct platform_device *pdev)
>  
>  static void a3700_spi_remove(struct platform_device *pdev)
>  {
> -	struct spi_controller *host = platform_get_drvdata(pdev);
> -	struct a3700_spi *spi = spi_controller_get_devdata(host);
> -
> -	clk_unprepare(spi->clk);
Hi.

No point in keeping an empty remove function.  Drop the whole thing now
there is nothing to do.

Jonathan

>  }
>  
>  static struct platform_driver a3700_spi_driver = {


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next 24/25] spi: spl022: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 ` [PATCH -next 24/25] spi: spl022: " Li Zetao
@ 2023-08-22 16:14   ` Jonathan Cameron
  2023-08-23  6:55   ` Linus Walleij
  1 sibling, 0 replies; 71+ messages in thread
From: Jonathan Cameron @ 2023-08-22 16:14 UTC (permalink / raw)
  To: Li Zetao
  Cc: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko, linux-spi,
	linux-aspeed, openbmc, linux-arm-kernel, linux-rpi-kernel,
	linux-amlogic, linux-riscv, linux-mediatek, linux-rockchip

On Tue, 22 Aug 2023 21:12:36 +0800
Li Zetao <lizetao1@huawei.com> 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 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.
> Moreover, the label "err_no_clk_en" is no used, drop it for clean code.
> 
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
Hi.

There is some odd formatting in the existing file, but cleaning that up
should probably be a separate patch.

Thanks,

Jonathan

> ---
>  drivers/spi/spi-pl022.c | 21 ++++++---------------
>  1 file changed, 6 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
> index 1af75eff26b6..468a7fea9091 100644
> --- a/drivers/spi/spi-pl022.c
> +++ b/drivers/spi/spi-pl022.c
> @@ -2168,19 +2168,13 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
>  	dev_info(&adev->dev, "mapped registers from %pa to %p\n",
>  		&adev->res.start, pl022->virtbase);
>  
> -	pl022->clk = devm_clk_get(&adev->dev, NULL);
> +	pl022->clk = devm_clk_get_enabled(&adev->dev, NULL);
>  	if (IS_ERR(pl022->clk)) {
>  		status = PTR_ERR(pl022->clk);
>  		dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
>  		goto err_no_clk;
>  	}
>  
> -	status = clk_prepare_enable(pl022->clk);
> -	if (status) {
> -		dev_err(&adev->dev, "could not enable SSP/SPI bus clock\n");
> -		goto err_no_clk_en;
> -	}
> -
>  	/* Initialize transfer pump */
>  	tasklet_init(&pl022->pump_transfers, pump_transfers,
>  		     (unsigned long)pl022);
> @@ -2236,16 +2230,14 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
>  
>  	return 0;
>  
> - err_spi_register:
> +err_spi_register:
>  	if (platform_info->enable_dma)
>  		pl022_dma_remove(pl022);
> - err_no_irq:
> -	clk_disable_unprepare(pl022->clk);
> - err_no_clk_en:
> - err_no_clk:
> - err_no_ioremap:
> +err_no_irq:
> +err_no_clk:
> +err_no_ioremap:
>  	amba_release_regions(adev);
> - err_no_ioregion:
> +err_no_ioregion:
>  	spi_master_put(master);
>  	return status;
>  }
> @@ -2268,7 +2260,6 @@ pl022_remove(struct amba_device *adev)
>  	if (pl022->master_info->enable_dma)
>  		pl022_dma_remove(pl022);
>  
> -	clk_disable_unprepare(pl022->clk);
>  	amba_release_regions(adev);
>  	tasklet_disable(&pl022->pump_transfers);
>  }


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers.
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (24 preceding siblings ...)
  2023-08-22 13:12 ` [PATCH -next 25/25] spi: rockchip: " Li Zetao
@ 2023-08-22 16:16 ` Jonathan Cameron
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
  26 siblings, 0 replies; 71+ messages in thread
From: Jonathan Cameron @ 2023-08-22 16:16 UTC (permalink / raw)
  To: Li Zetao
  Cc: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko, linux-spi,
	linux-aspeed, openbmc, linux-arm-kernel, linux-rpi-kernel,
	linux-amlogic, linux-riscv, linux-mediatek, linux-rockchip

On Tue, 22 Aug 2023 21:12:12 +0800
Li Zetao <lizetao1@huawei.com> wrote:

> Commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
> and enabled clocks") provides a 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 clocks explicitly when remove drivers or in the
> error handling path.

For all except 2, 12 and 24
they look good to me and I don't think there are any other ordering issues
of the sort we tend to see in devm conversions where things get turned off
later than in pre devm version.

So for those..
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>



> 
> Li Zetao (25):
>   spi: ar934x: Use helper function devm_clk_get_enabled()
>   spi: armada-3700: Use helper function devm_clk_get_prepared()
>   spi: aspeed: Use helper function devm_clk_get_enabled()
>   spi: ath79: Use helper function devm_clk_get_enabled()
>   spi: spi-axi-spi-engine: Use helper function devm_clk_get_enabled()
>   spi: bcm2835: Use helper function devm_clk_get_enabled()
>   spi: bcm2835aux: Use helper function devm_clk_get_enabled()
>   spi: spi-cadence: Use helper function devm_clk_get_enabled()
>   spi: spi-cavium-thunderx: Use helper function devm_clk_get_enabled()
>   spi: davinci: Use helper function devm_clk_get_enabled()
>   spi: dw-bt1: Use helper function devm_clk_get_enabled()
>   spi: dw-mmio: Use helper function devm_clk_get_*()
>   spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled()
>   spi: lantiq-ssc: Use helper function devm_clk_get_enabled()
>   spi: meson-spicc: Use helper function devm_clk_get_enabled()
>   spi: spi-meson-spifc: Use helper function devm_clk_get_enabled()
>   spi: microchip-core-qspi: Use helper function devm_clk_get_enabled()
>   spi: microchip-core: Use helper function devm_clk_get_enabled()
>   spi: mtk-snfi: Use helper function devm_clk_get_enabled()
>   spi: npcm-fiu: Use helper function devm_clk_get_enabled()
>   spi: orion: Use helper function devm_clk_get_enabled()
>   spi: pic32-sqi: Use helper function devm_clk_get_enabled()
>   spi: pic32: Use helper function devm_clk_get_enabled()
>   spi: spl022: Use helper function devm_clk_get_enabled()
>   spi: rockchip: Use helper function devm_clk_get_enabled()
> 
>  drivers/spi/spi-ar934x.c              | 22 ++--------
>  drivers/spi/spi-armada-3700.c         | 18 ++------
>  drivers/spi/spi-aspeed-smc.c          | 16 +------
>  drivers/spi/spi-ath79.c               | 11 +----
>  drivers/spi/spi-axi-spi-engine.c      | 25 +++--------
>  drivers/spi/spi-bcm2835.c             | 11 +----
>  drivers/spi/spi-bcm2835aux.c          | 23 ++--------
>  drivers/spi/spi-cadence.c             | 23 ++--------
>  drivers/spi/spi-cavium-thunderx.c     |  8 +---
>  drivers/spi/spi-davinci.c             | 11 +----
>  drivers/spi/spi-dw-bt1.c              | 23 +++-------
>  drivers/spi/spi-dw-mmio.c             | 20 +++------
>  drivers/spi/spi-fsl-dspi.c            | 12 ++----
>  drivers/spi/spi-lantiq-ssc.c          | 10 +----
>  drivers/spi/spi-meson-spicc.c         | 33 +++------------
>  drivers/spi/spi-meson-spifc.c         | 17 ++------
>  drivers/spi/spi-microchip-core-qspi.c | 29 +++----------
>  drivers/spi/spi-microchip-core.c      |  9 +---
>  drivers/spi/spi-mtk-snfi.c            | 61 ++++-----------------------
>  drivers/spi/spi-npcm-fiu.c            | 14 ++----
>  drivers/spi/spi-orion.c               | 11 +----
>  drivers/spi/spi-pic32-sqi.c           | 27 ++----------
>  drivers/spi/spi-pic32.c               |  8 +---
>  drivers/spi/spi-pl022.c               | 21 +++------
>  drivers/spi/spi-rockchip.c            | 30 +++----------
>  25 files changed, 88 insertions(+), 405 deletions(-)
> 


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next 24/25] spi: spl022: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 ` [PATCH -next 24/25] spi: spl022: " Li Zetao
  2023-08-22 16:14   ` Jonathan Cameron
@ 2023-08-23  6:55   ` Linus Walleij
  1 sibling, 0 replies; 71+ messages in thread
From: Linus Walleij @ 2023-08-23  6:55 UTC (permalink / raw)
  To: Li Zetao
  Cc: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, heiko, linux-spi, linux-aspeed,
	openbmc, linux-arm-kernel, linux-rpi-kernel, linux-amlogic,
	linux-riscv, linux-mediatek, linux-rockchip

On Tue, Aug 22, 2023 at 3:13 PM Li Zetao <lizetao1@huawei.com> 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 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.
> Moreover, the label "err_no_clk_en" is no used, drop it for clean code.
>
> Signed-off-by: Li Zetao <lizetao1@huawei.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 71+ messages in thread

* RE: [PATCH -next 03/25] spi: aspeed: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 ` [PATCH -next 03/25] spi: aspeed: Use helper function devm_clk_get_enabled() Li Zetao
@ 2023-08-23  7:11   ` Chin-Ting Kuo
  2023-08-24  8:55   ` Cédric Le Goater
  1 sibling, 0 replies; 71+ messages in thread
From: Chin-Ting Kuo @ 2023-08-23  7:11 UTC (permalink / raw)
  To: Li Zetao, broonie, clg, joel, andrew, florian.fainelli, rjui,
	sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip


> -----Original Message-----
> From: Li Zetao <lizetao1@huawei.com>
> Sent: Tuesday, August 22, 2023 9:12 PM
> Subject: [PATCH -next 03/25] spi: aspeed: Use helper function
> devm_clk_get_enabled()
> 
> 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 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/spi/spi-aspeed-smc.c | 16 ++--------------
>  1 file changed, 2 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c index
> 21b0fa646c7d..bbd417c55e7f 100644
> --- a/drivers/spi/spi-aspeed-smc.c
> +++ b/drivers/spi/spi-aspeed-smc.c
> @@ -748,7 +748,7 @@ static int aspeed_spi_probe(struct platform_device
> *pdev)
>  	aspi->ahb_window_size = resource_size(res);
>  	aspi->ahb_base_phy = res->start;
> 
> -	aspi->clk = devm_clk_get(&pdev->dev, NULL);
> +	aspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  	if (IS_ERR(aspi->clk)) {
>  		dev_err(dev, "missing clock\n");
>  		return PTR_ERR(aspi->clk);
> @@ -760,12 +760,6 @@ static int aspeed_spi_probe(struct platform_device
> *pdev)
>  		return -EINVAL;
>  	}
> 
> -	ret = clk_prepare_enable(aspi->clk);
> -	if (ret) {
> -		dev_err(dev, "can not enable the clock\n");
> -		return ret;
> -	}
> -
>  	/* IRQ is for DMA, which the driver doesn't support yet */
> 
>  	ctlr->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | data->mode_bits; @@
> -777,14 +771,9 @@ static int aspeed_spi_probe(struct platform_device *pdev)
>  	ctlr->dev.of_node = dev->of_node;
> 
>  	ret = devm_spi_register_controller(dev, ctlr);
> -	if (ret) {
> +	if (ret)
>  		dev_err(&pdev->dev, "spi_register_controller failed\n");
> -		goto disable_clk;
> -	}
> -	return 0;
> 
> -disable_clk:
> -	clk_disable_unprepare(aspi->clk);
>  	return ret;
>  }
> 
> @@ -793,7 +782,6 @@ static void aspeed_spi_remove(struct platform_device
> *pdev)
>  	struct aspeed_spi *aspi = platform_get_drvdata(pdev);
> 
>  	aspeed_spi_enable(aspi, false);
> -	clk_disable_unprepare(aspi->clk);
>  }
> 
>  /*
> --
> 2.34.1

Reviewed-by: Chin-Ting Kuo <chin-ting_kuo@aspeedtech.com>


^ permalink raw reply	[flat|nested] 71+ messages in thread

* [PATCH -next v2 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers.
  2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
                   ` (25 preceding siblings ...)
  2023-08-22 16:16 ` [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Jonathan Cameron
@ 2023-08-23 13:39 ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 01/25] spi: ar934x: Use helper function devm_clk_get_enabled() Li Zetao
                     ` (26 more replies)
  26 siblings, 27 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn

Commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
and enabled clocks") provides a 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 clocks explicitly when remove drivers or in the
error handling path.

Change log:

v2:
 - Remove empty function a3700_spi_remove(), while is nothing to do.
 - Return directly instead of calling reset_control_deassert(), because
   the reset control handler hasn't been requested yet in
   dw_spi_mmio_probe(). And use the "out_reset" label instead of "out"
   before calling pm_runtime_enable().
 - Delete the modification of odd formatting, it should probably be a
   separate patch.

v1: https://lore.kernel.org/all/20230822131237.1022815-1-lizetao1@huawei.com/

Li Zetao (25):
  spi: ar934x: Use helper function devm_clk_get_enabled()
  spi: armada-3700: Use helper function devm_clk_get_prepared()
  spi: aspeed: Use helper function devm_clk_get_enabled()
  spi: ath79: Use helper function devm_clk_get_enabled()
  spi: spi-axi-spi-engine: Use helper function devm_clk_get_enabled()
  spi: bcm2835: Use helper function devm_clk_get_enabled()
  spi: bcm2835aux: Use helper function devm_clk_get_enabled()
  spi: spi-cadence: Use helper function devm_clk_get_enabled()
  spi: spi-cavium-thunderx: Use helper function devm_clk_get_enabled()
  spi: davinci: Use helper function devm_clk_get_enabled()
  spi: dw-bt1: Use helper function devm_clk_get_enabled()
  spi: dw-mmio: Use helper function devm_clk_get_*()
  spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled()
  spi: lantiq-ssc: Use helper function devm_clk_get_enabled()
  spi: meson-spicc: Use helper function devm_clk_get_enabled()
  spi: spi-meson-spifc: Use helper function devm_clk_get_enabled()
  spi: microchip-core-qspi: Use helper function devm_clk_get_enabled()
  spi: microchip-core: Use helper function devm_clk_get_enabled()
  spi: mtk-snfi: Use helper function devm_clk_get_enabled()
  spi: npcm-fiu: Use helper function devm_clk_get_enabled()
  spi: orion: Use helper function devm_clk_get_enabled()
  spi: pic32-sqi: Use helper function devm_clk_get_enabled()
  spi: pic32: Use helper function devm_clk_get_enabled()
  spi: spl022: Use helper function devm_clk_get_enabled()
  spi: rockchip: Use helper function devm_clk_get_enabled()

 drivers/spi/spi-ar934x.c              | 22 ++--------
 drivers/spi/spi-armada-3700.c         | 23 ++--------
 drivers/spi/spi-aspeed-smc.c          | 16 +------
 drivers/spi/spi-ath79.c               | 11 +----
 drivers/spi/spi-axi-spi-engine.c      | 25 +++--------
 drivers/spi/spi-bcm2835.c             | 11 +----
 drivers/spi/spi-bcm2835aux.c          | 23 ++--------
 drivers/spi/spi-cadence.c             | 23 ++--------
 drivers/spi/spi-cavium-thunderx.c     |  8 +---
 drivers/spi/spi-davinci.c             | 11 +----
 drivers/spi/spi-dw-bt1.c              | 23 +++-------
 drivers/spi/spi-dw-mmio.c             | 31 ++++----------
 drivers/spi/spi-fsl-dspi.c            | 12 ++----
 drivers/spi/spi-lantiq-ssc.c          | 10 +----
 drivers/spi/spi-meson-spicc.c         | 33 +++------------
 drivers/spi/spi-meson-spifc.c         | 17 ++------
 drivers/spi/spi-microchip-core-qspi.c | 29 +++----------
 drivers/spi/spi-microchip-core.c      |  9 +---
 drivers/spi/spi-mtk-snfi.c            | 61 ++++-----------------------
 drivers/spi/spi-npcm-fiu.c            | 14 ++----
 drivers/spi/spi-orion.c               | 11 +----
 drivers/spi/spi-pic32-sqi.c           | 27 ++----------
 drivers/spi/spi-pic32.c               |  8 +---
 drivers/spi/spi-pl022.c               | 11 +----
 drivers/spi/spi-rockchip.c            | 30 +++----------
 25 files changed, 87 insertions(+), 412 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 71+ messages in thread

* [PATCH -next v2 01/25] spi: ar934x: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared() Li Zetao
                     ` (25 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-ar934x.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/drivers/spi/spi-ar934x.c b/drivers/spi/spi-ar934x.c
index 58b98cea31d9..5ba988720851 100644
--- a/drivers/spi/spi-ar934x.c
+++ b/drivers/spi/spi-ar934x.c
@@ -168,27 +168,21 @@ static int ar934x_spi_probe(struct platform_device *pdev)
 	struct ar934x_spi *sp;
 	void __iomem *base;
 	struct clk *clk;
-	int ret;
 
 	base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(base))
 		return PTR_ERR(base);
 
-	clk = devm_clk_get(&pdev->dev, NULL);
+	clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "failed to get clock\n");
 		return PTR_ERR(clk);
 	}
 
-	ret = clk_prepare_enable(clk);
-	if (ret)
-		return ret;
-
 	ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*sp));
 	if (!ctlr) {
 		dev_info(&pdev->dev, "failed to allocate spi controller\n");
-		ret = -ENOMEM;
-		goto err_clk_disable;
+		return -ENOMEM;
 	}
 
 	/* disable flash mapping and expose spi controller registers */
@@ -212,25 +206,15 @@ static int ar934x_spi_probe(struct platform_device *pdev)
 	sp->clk_freq = clk_get_rate(clk);
 	sp->ctlr = ctlr;
 
-	ret = spi_register_controller(ctlr);
-	if (!ret)
-		return 0;
-
-err_clk_disable:
-	clk_disable_unprepare(clk);
-	return ret;
+	return spi_register_controller(ctlr);
 }
 
 static void ar934x_spi_remove(struct platform_device *pdev)
 {
 	struct spi_controller *ctlr;
-	struct ar934x_spi *sp;
 
 	ctlr = dev_get_drvdata(&pdev->dev);
-	sp = spi_controller_get_devdata(ctlr);
-
 	spi_unregister_controller(ctlr);
-	clk_disable_unprepare(sp->clk);
 }
 
 static struct platform_driver ar934x_spi_driver = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 01/25] spi: ar934x: Use helper function devm_clk_get_enabled() Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 17:10     ` Jonathan Cameron
  2023-08-23 13:39   ` [PATCH -next v2 03/25] spi: aspeed: Use helper function devm_clk_get_enabled() Li Zetao
                     ` (24 subsequent siblings)
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn

Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
and enabled clocks"), devm_clk_get() and clk_prepare() can now be replaced
by devm_clk_get_prepared() when driver prepares the clocks for the whole
lifetime of the device. Moreover, it is no longer necessary to unprepare
the clocks explicitly.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: Drop the empty remove function a3700_spi_remove().

 drivers/spi/spi-armada-3700.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/spi/spi-armada-3700.c b/drivers/spi/spi-armada-3700.c
index 0103ac0158c0..3c9ed412932f 100644
--- a/drivers/spi/spi-armada-3700.c
+++ b/drivers/spi/spi-armada-3700.c
@@ -865,18 +865,12 @@ static int a3700_spi_probe(struct platform_device *pdev)
 
 	init_completion(&spi->done);
 
-	spi->clk = devm_clk_get(dev, NULL);
+	spi->clk = devm_clk_get_prepared(dev, NULL);
 	if (IS_ERR(spi->clk)) {
 		dev_err(dev, "could not find clk: %ld\n", PTR_ERR(spi->clk));
 		goto error;
 	}
 
-	ret = clk_prepare(spi->clk);
-	if (ret) {
-		dev_err(dev, "could not prepare clk: %d\n", ret);
-		goto error;
-	}
-
 	host->max_speed_hz = min_t(unsigned long, A3700_SPI_MAX_SPEED_HZ,
 					clk_get_rate(spi->clk));
 	host->min_speed_hz = DIV_ROUND_UP(clk_get_rate(spi->clk),
@@ -888,40 +882,29 @@ static int a3700_spi_probe(struct platform_device *pdev)
 			       dev_name(dev), host);
 	if (ret) {
 		dev_err(dev, "could not request IRQ: %d\n", ret);
-		goto error_clk;
+		goto error;
 	}
 
 	ret = devm_spi_register_controller(dev, host);
 	if (ret) {
 		dev_err(dev, "Failed to register host\n");
-		goto error_clk;
+		goto error;
 	}
 
 	return 0;
 
-error_clk:
-	clk_unprepare(spi->clk);
 error:
 	spi_controller_put(host);
 out:
 	return ret;
 }
 
-static void a3700_spi_remove(struct platform_device *pdev)
-{
-	struct spi_controller *host = platform_get_drvdata(pdev);
-	struct a3700_spi *spi = spi_controller_get_devdata(host);
-
-	clk_unprepare(spi->clk);
-}
-
 static struct platform_driver a3700_spi_driver = {
 	.driver = {
 		.name	= DRIVER_NAME,
 		.of_match_table = of_match_ptr(a3700_spi_dt_ids),
 	},
 	.probe		= a3700_spi_probe,
-	.remove_new	= a3700_spi_remove,
 };
 
 module_platform_driver(a3700_spi_driver);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 03/25] spi: aspeed: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 01/25] spi: ar934x: Use helper function devm_clk_get_enabled() Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared() Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 04/25] spi: ath79: " Li Zetao
                     ` (23 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Chin-Ting Kuo <chin-ting_kuo@aspeedtech.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-aspeed-smc.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c
index 21b0fa646c7d..bbd417c55e7f 100644
--- a/drivers/spi/spi-aspeed-smc.c
+++ b/drivers/spi/spi-aspeed-smc.c
@@ -748,7 +748,7 @@ static int aspeed_spi_probe(struct platform_device *pdev)
 	aspi->ahb_window_size = resource_size(res);
 	aspi->ahb_base_phy = res->start;
 
-	aspi->clk = devm_clk_get(&pdev->dev, NULL);
+	aspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(aspi->clk)) {
 		dev_err(dev, "missing clock\n");
 		return PTR_ERR(aspi->clk);
@@ -760,12 +760,6 @@ static int aspeed_spi_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	ret = clk_prepare_enable(aspi->clk);
-	if (ret) {
-		dev_err(dev, "can not enable the clock\n");
-		return ret;
-	}
-
 	/* IRQ is for DMA, which the driver doesn't support yet */
 
 	ctlr->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | data->mode_bits;
@@ -777,14 +771,9 @@ static int aspeed_spi_probe(struct platform_device *pdev)
 	ctlr->dev.of_node = dev->of_node;
 
 	ret = devm_spi_register_controller(dev, ctlr);
-	if (ret) {
+	if (ret)
 		dev_err(&pdev->dev, "spi_register_controller failed\n");
-		goto disable_clk;
-	}
-	return 0;
 
-disable_clk:
-	clk_disable_unprepare(aspi->clk);
 	return ret;
 }
 
@@ -793,7 +782,6 @@ static void aspeed_spi_remove(struct platform_device *pdev)
 	struct aspeed_spi *aspi = platform_get_drvdata(pdev);
 
 	aspeed_spi_enable(aspi, false);
-	clk_disable_unprepare(aspi->clk);
 }
 
 /*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 04/25] spi: ath79: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (2 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 03/25] spi: aspeed: Use helper function devm_clk_get_enabled() Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 05/25] spi: spi-axi-spi-engine: " Li Zetao
                     ` (22 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-ath79.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c
index 1b6d977d111c..c9f1d1e1dcf7 100644
--- a/drivers/spi/spi-ath79.c
+++ b/drivers/spi/spi-ath79.c
@@ -200,20 +200,16 @@ static int ath79_spi_probe(struct platform_device *pdev)
 		goto err_put_host;
 	}
 
-	sp->clk = devm_clk_get(&pdev->dev, "ahb");
+	sp->clk = devm_clk_get_enabled(&pdev->dev, "ahb");
 	if (IS_ERR(sp->clk)) {
 		ret = PTR_ERR(sp->clk);
 		goto err_put_host;
 	}
 
-	ret = clk_prepare_enable(sp->clk);
-	if (ret)
-		goto err_put_host;
-
 	rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ);
 	if (!rate) {
 		ret = -EINVAL;
-		goto err_clk_disable;
+		goto err_put_host;
 	}
 
 	sp->rrw_delay = ATH79_SPI_RRW_DELAY_FACTOR / rate;
@@ -229,8 +225,6 @@ static int ath79_spi_probe(struct platform_device *pdev)
 
 err_disable:
 	ath79_spi_disable(sp);
-err_clk_disable:
-	clk_disable_unprepare(sp->clk);
 err_put_host:
 	spi_controller_put(host);
 
@@ -243,7 +237,6 @@ static void ath79_spi_remove(struct platform_device *pdev)
 
 	spi_bitbang_stop(&sp->bitbang);
 	ath79_spi_disable(sp);
-	clk_disable_unprepare(sp->clk);
 	spi_controller_put(sp->bitbang.master);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 05/25] spi: spi-axi-spi-engine: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (3 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 04/25] spi: ath79: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 06/25] spi: bcm2835: " Li Zetao
                     ` (21 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-axi-spi-engine.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c
index 0258c9a72fdc..b96e55f59d1a 100644
--- a/drivers/spi/spi-axi-spi-engine.c
+++ b/drivers/spi/spi-axi-spi-engine.c
@@ -485,30 +485,22 @@ static int spi_engine_probe(struct platform_device *pdev)
 
 	spin_lock_init(&spi_engine->lock);
 
-	spi_engine->clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
+	spi_engine->clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk");
 	if (IS_ERR(spi_engine->clk)) {
 		ret = PTR_ERR(spi_engine->clk);
 		goto err_put_host;
 	}
 
-	spi_engine->ref_clk = devm_clk_get(&pdev->dev, "spi_clk");
+	spi_engine->ref_clk = devm_clk_get_enabled(&pdev->dev, "spi_clk");
 	if (IS_ERR(spi_engine->ref_clk)) {
 		ret = PTR_ERR(spi_engine->ref_clk);
 		goto err_put_host;
 	}
 
-	ret = clk_prepare_enable(spi_engine->clk);
-	if (ret)
-		goto err_put_host;
-
-	ret = clk_prepare_enable(spi_engine->ref_clk);
-	if (ret)
-		goto err_clk_disable;
-
 	spi_engine->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(spi_engine->base)) {
 		ret = PTR_ERR(spi_engine->base);
-		goto err_ref_clk_disable;
+		goto err_put_host;
 	}
 
 	version = readl(spi_engine->base + SPI_ENGINE_REG_VERSION);
@@ -518,7 +510,7 @@ static int spi_engine_probe(struct platform_device *pdev)
 			SPI_ENGINE_VERSION_MINOR(version),
 			SPI_ENGINE_VERSION_PATCH(version));
 		ret = -ENODEV;
-		goto err_ref_clk_disable;
+		goto err_put_host;
 	}
 
 	writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET);
@@ -527,7 +519,7 @@ static int spi_engine_probe(struct platform_device *pdev)
 
 	ret = request_irq(irq, spi_engine_irq, 0, pdev->name, host);
 	if (ret)
-		goto err_ref_clk_disable;
+		goto err_put_host;
 
 	host->dev.of_node = pdev->dev.of_node;
 	host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE;
@@ -545,10 +537,6 @@ static int spi_engine_probe(struct platform_device *pdev)
 	return 0;
 err_free_irq:
 	free_irq(irq, host);
-err_ref_clk_disable:
-	clk_disable_unprepare(spi_engine->ref_clk);
-err_clk_disable:
-	clk_disable_unprepare(spi_engine->clk);
 err_put_host:
 	spi_controller_put(host);
 	return ret;
@@ -569,9 +557,6 @@ static void spi_engine_remove(struct platform_device *pdev)
 	writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
 	writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE);
 	writel_relaxed(0x01, spi_engine->base + SPI_ENGINE_REG_RESET);
-
-	clk_disable_unprepare(spi_engine->ref_clk);
-	clk_disable_unprepare(spi_engine->clk);
 }
 
 static const struct of_device_id spi_engine_match_table[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 06/25] spi: bcm2835: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (4 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 05/25] spi: spi-axi-spi-engine: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 07/25] spi: bcm2835aux: " Li Zetao
                     ` (20 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-bcm2835.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index e7bb2714678a..a457ad2f7db1 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -1352,7 +1352,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
 	if (IS_ERR(bs->regs))
 		return PTR_ERR(bs->regs);
 
-	bs->clk = devm_clk_get(&pdev->dev, NULL);
+	bs->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(bs->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(bs->clk),
 				     "could not get clk\n");
@@ -1363,14 +1363,11 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
 	if (bs->irq < 0)
 		return bs->irq;
 
-	err = clk_prepare_enable(bs->clk);
-	if (err)
-		return err;
 	bs->clk_hz = clk_get_rate(bs->clk);
 
 	err = bcm2835_dma_init(ctlr, &pdev->dev, bs);
 	if (err)
-		goto out_clk_disable;
+		return err;
 
 	/* initialise the hardware with the default polarities */
 	bcm2835_wr(bs, BCM2835_SPI_CS,
@@ -1396,8 +1393,6 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
 
 out_dma_release:
 	bcm2835_dma_release(ctlr, bs);
-out_clk_disable:
-	clk_disable_unprepare(bs->clk);
 	return err;
 }
 
@@ -1415,8 +1410,6 @@ static void bcm2835_spi_remove(struct platform_device *pdev)
 	/* Clear FIFOs, and disable the HW block */
 	bcm2835_wr(bs, BCM2835_SPI_CS,
 		   BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX);
-
-	clk_disable_unprepare(bs->clk);
 }
 
 static const struct of_device_id bcm2835_spi_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 07/25] spi: bcm2835aux: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (5 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 06/25] spi: bcm2835: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 08/25] spi: spi-cadence: " Li Zetao
                     ` (19 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-bcm2835aux.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/drivers/spi/spi-bcm2835aux.c b/drivers/spi/spi-bcm2835aux.c
index 6d2a5d9f2498..06fe155a70c9 100644
--- a/drivers/spi/spi-bcm2835aux.c
+++ b/drivers/spi/spi-bcm2835aux.c
@@ -512,7 +512,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
 	if (IS_ERR(bs->regs))
 		return PTR_ERR(bs->regs);
 
-	bs->clk = devm_clk_get(&pdev->dev, NULL);
+	bs->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(bs->clk)) {
 		err = PTR_ERR(bs->clk);
 		dev_err(&pdev->dev, "could not get clk: %d\n", err);
@@ -523,19 +523,11 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
 	if (bs->irq < 0)
 		return bs->irq;
 
-	/* this also enables the HW block */
-	err = clk_prepare_enable(bs->clk);
-	if (err) {
-		dev_err(&pdev->dev, "could not prepare clock: %d\n", err);
-		return err;
-	}
-
 	/* just checking if the clock returns a sane value */
 	clk_hz = clk_get_rate(bs->clk);
 	if (!clk_hz) {
 		dev_err(&pdev->dev, "clock returns 0 Hz\n");
-		err = -ENODEV;
-		goto out_clk_disable;
+		return -ENODEV;
 	}
 
 	/* reset SPI-HW block */
@@ -547,22 +539,18 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
 			       dev_name(&pdev->dev), host);
 	if (err) {
 		dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
-		goto out_clk_disable;
+		return err;
 	}
 
 	err = spi_register_controller(host);
 	if (err) {
 		dev_err(&pdev->dev, "could not register SPI host: %d\n", err);
-		goto out_clk_disable;
+		return err;
 	}
 
 	bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev));
 
 	return 0;
-
-out_clk_disable:
-	clk_disable_unprepare(bs->clk);
-	return err;
 }
 
 static void bcm2835aux_spi_remove(struct platform_device *pdev)
@@ -575,9 +563,6 @@ static void bcm2835aux_spi_remove(struct platform_device *pdev)
 	spi_unregister_controller(host);
 
 	bcm2835aux_spi_reset_hw(bs);
-
-	/* disable the HW block by releasing the clock */
-	clk_disable_unprepare(bs->clk);
 }
 
 static const struct of_device_id bcm2835aux_spi_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 08/25] spi: spi-cadence: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (6 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 07/25] spi: bcm2835aux: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 09/25] spi: spi-cavium-thunderx: " Li Zetao
                     ` (18 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-cadence.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
index 12c940ba074a..1f2f8c717df6 100644
--- a/drivers/spi/spi-cadence.c
+++ b/drivers/spi/spi-cadence.c
@@ -581,31 +581,19 @@ static int cdns_spi_probe(struct platform_device *pdev)
 		goto remove_ctlr;
 	}
 
-	xspi->pclk = devm_clk_get(&pdev->dev, "pclk");
+	xspi->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
 	if (IS_ERR(xspi->pclk)) {
 		dev_err(&pdev->dev, "pclk clock not found.\n");
 		ret = PTR_ERR(xspi->pclk);
 		goto remove_ctlr;
 	}
 
-	ret = clk_prepare_enable(xspi->pclk);
-	if (ret) {
-		dev_err(&pdev->dev, "Unable to enable APB clock.\n");
-		goto remove_ctlr;
-	}
-
 	if (!spi_controller_is_target(ctlr)) {
-		xspi->ref_clk = devm_clk_get(&pdev->dev, "ref_clk");
+		xspi->ref_clk = devm_clk_get_enabled(&pdev->dev, "ref_clk");
 		if (IS_ERR(xspi->ref_clk)) {
 			dev_err(&pdev->dev, "ref_clk clock not found.\n");
 			ret = PTR_ERR(xspi->ref_clk);
-			goto clk_dis_apb;
-		}
-
-		ret = clk_prepare_enable(xspi->ref_clk);
-		if (ret) {
-			dev_err(&pdev->dev, "Unable to enable device clock.\n");
-			goto clk_dis_apb;
+			goto remove_ctlr;
 		}
 
 		pm_runtime_use_autosuspend(&pdev->dev);
@@ -679,10 +667,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
 	if (!spi_controller_is_target(ctlr)) {
 		pm_runtime_set_suspended(&pdev->dev);
 		pm_runtime_disable(&pdev->dev);
-		clk_disable_unprepare(xspi->ref_clk);
 	}
-clk_dis_apb:
-	clk_disable_unprepare(xspi->pclk);
 remove_ctlr:
 	spi_controller_put(ctlr);
 	return ret;
@@ -703,8 +688,6 @@ static void cdns_spi_remove(struct platform_device *pdev)
 
 	cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
 
-	clk_disable_unprepare(xspi->ref_clk);
-	clk_disable_unprepare(xspi->pclk);
 	pm_runtime_set_suspended(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 09/25] spi: spi-cavium-thunderx: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (7 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 08/25] spi: spi-cadence: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 10/25] spi: davinci: " Li Zetao
                     ` (17 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-cavium-thunderx.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/spi/spi-cavium-thunderx.c b/drivers/spi/spi-cavium-thunderx.c
index f7c378a5f1bc..337aef12abcc 100644
--- a/drivers/spi/spi-cavium-thunderx.c
+++ b/drivers/spi/spi-cavium-thunderx.c
@@ -49,16 +49,12 @@ static int thunderx_spi_probe(struct pci_dev *pdev,
 	p->regs.tx = 0x1010;
 	p->regs.data = 0x1080;
 
-	p->clk = devm_clk_get(dev, NULL);
+	p->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(p->clk)) {
 		ret = PTR_ERR(p->clk);
 		goto error;
 	}
 
-	ret = clk_prepare_enable(p->clk);
-	if (ret)
-		goto error;
-
 	p->sys_freq = clk_get_rate(p->clk);
 	if (!p->sys_freq)
 		p->sys_freq = SYS_FREQ_DEFAULT;
@@ -82,7 +78,6 @@ static int thunderx_spi_probe(struct pci_dev *pdev,
 	return 0;
 
 error:
-	clk_disable_unprepare(p->clk);
 	pci_release_regions(pdev);
 	spi_controller_put(host);
 	return ret;
@@ -97,7 +92,6 @@ static void thunderx_spi_remove(struct pci_dev *pdev)
 	if (!p)
 		return;
 
-	clk_disable_unprepare(p->clk);
 	pci_release_regions(pdev);
 	/* Put everything in a known state. */
 	writeq(0, p->register_base + OCTEON_SPI_CFG(p));
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 10/25] spi: davinci: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (8 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 09/25] spi: spi-cavium-thunderx: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 11/25] spi: dw-bt1: " Li Zetao
                     ` (16 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-davinci.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index c457b550d3ad..5688be245c68 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -915,14 +915,11 @@ static int davinci_spi_probe(struct platform_device *pdev)
 
 	dspi->bitbang.master = host;
 
-	dspi->clk = devm_clk_get(&pdev->dev, NULL);
+	dspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(dspi->clk)) {
 		ret = -ENODEV;
 		goto free_host;
 	}
-	ret = clk_prepare_enable(dspi->clk);
-	if (ret)
-		goto free_host;
 
 	host->use_gpio_descriptors = true;
 	host->dev.of_node = pdev->dev.of_node;
@@ -947,7 +944,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
 
 	ret = davinci_spi_request_dma(dspi);
 	if (ret == -EPROBE_DEFER) {
-		goto free_clk;
+		goto free_host;
 	} else if (ret) {
 		dev_info(&pdev->dev, "DMA is not supported (%d)\n", ret);
 		dspi->dma_rx = NULL;
@@ -991,8 +988,6 @@ static int davinci_spi_probe(struct platform_device *pdev)
 		dma_release_channel(dspi->dma_rx);
 		dma_release_channel(dspi->dma_tx);
 	}
-free_clk:
-	clk_disable_unprepare(dspi->clk);
 free_host:
 	spi_controller_put(host);
 err:
@@ -1018,8 +1013,6 @@ static void davinci_spi_remove(struct platform_device *pdev)
 
 	spi_bitbang_stop(&dspi->bitbang);
 
-	clk_disable_unprepare(dspi->clk);
-
 	if (dspi->dma_rx) {
 		dma_release_channel(dspi->dma_rx);
 		dma_release_channel(dspi->dma_tx);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 11/25] spi: dw-bt1: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (9 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 10/25] spi: davinci: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 14:35     ` Serge Semin
  2023-08-23 13:39   ` [PATCH -next v2 12/25] spi: dw-mmio: Use helper function devm_clk_get_*() Li Zetao
                     ` (15 subsequent siblings)
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-dw-bt1.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c
index 5e1c01822967..5391bcac305c 100644
--- a/drivers/spi/spi-dw-bt1.c
+++ b/drivers/spi/spi-dw-bt1.c
@@ -269,43 +269,32 @@ static int dw_spi_bt1_probe(struct platform_device *pdev)
 
 	dws->paddr = mem->start;
 
-	dwsbt1->clk = devm_clk_get(&pdev->dev, NULL);
+	dwsbt1->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(dwsbt1->clk))
 		return PTR_ERR(dwsbt1->clk);
 
-	ret = clk_prepare_enable(dwsbt1->clk);
-	if (ret)
-		return ret;
-
 	dws->bus_num = pdev->id;
 	dws->reg_io_width = 4;
 	dws->max_freq = clk_get_rate(dwsbt1->clk);
-	if (!dws->max_freq) {
-		ret = -EINVAL;
-		goto err_disable_clk;
-	}
+	if (!dws->max_freq)
+		return -EINVAL;
 
 	init_func = device_get_match_data(&pdev->dev);
 	ret = init_func(pdev, dwsbt1);
 	if (ret)
-		goto err_disable_clk;
+		return ret;
 
 	pm_runtime_enable(&pdev->dev);
 
 	ret = dw_spi_add_host(&pdev->dev, dws);
 	if (ret) {
 		pm_runtime_disable(&pdev->dev);
-		goto err_disable_clk;
+		return ret;
 	}
 
 	platform_set_drvdata(pdev, dwsbt1);
 
 	return 0;
-
-err_disable_clk:
-	clk_disable_unprepare(dwsbt1->clk);
-
-	return ret;
 }
 
 static void dw_spi_bt1_remove(struct platform_device *pdev)
@@ -315,8 +304,6 @@ static void dw_spi_bt1_remove(struct platform_device *pdev)
 	dw_spi_remove_host(&dwsbt1->dws);
 
 	pm_runtime_disable(&pdev->dev);
-
-	clk_disable_unprepare(dwsbt1->clk);
 }
 
 static const struct of_device_id dw_spi_bt1_of_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 12/25] spi: dw-mmio: Use helper function devm_clk_get_*()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (10 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 11/25] spi: dw-bt1: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 14:20     ` Serge Semin
  2023-08-23 13:39   ` [PATCH -next v2 13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled() Li Zetao
                     ` (14 subsequent siblings)
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn

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 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. Also,
devm_clk_get_optional() and clk_prepare_enable() can now be replaced by
devm_clk_get_optional_enabled(). Moreover, the lable "out_clk" no longer
makes sense, rename it to "out_reset".

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: Return directly instead of calling reset_control_deassert()
before the reset control handler has been requested. And use the
"out_reset" label instead of "out" before calling pm_runtime_enable().

 drivers/spi/spi-dw-mmio.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index 805264c9c65c..46801189a651 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -340,29 +340,20 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
 	if (dws->irq < 0)
 		return dws->irq; /* -ENXIO */
 
-	dwsmmio->clk = devm_clk_get(&pdev->dev, NULL);
+	dwsmmio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(dwsmmio->clk))
 		return PTR_ERR(dwsmmio->clk);
-	ret = clk_prepare_enable(dwsmmio->clk);
-	if (ret)
-		return ret;
 
 	/* Optional clock needed to access the registers */
-	dwsmmio->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
-	if (IS_ERR(dwsmmio->pclk)) {
-		ret = PTR_ERR(dwsmmio->pclk);
-		goto out_clk;
-	}
-	ret = clk_prepare_enable(dwsmmio->pclk);
-	if (ret)
-		goto out_clk;
+	dwsmmio->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
+	if (IS_ERR(dwsmmio->pclk))
+		return PTR_ERR(dwsmmio->pclk);
 
 	/* find an optional reset controller */
 	dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi");
-	if (IS_ERR(dwsmmio->rstc)) {
-		ret = PTR_ERR(dwsmmio->rstc);
-		goto out_clk;
-	}
+	if (IS_ERR(dwsmmio->rstc))
+		return PTR_ERR(dwsmmio->rstc);
+
 	reset_control_deassert(dwsmmio->rstc);
 
 	dws->bus_num = pdev->id;
@@ -383,7 +374,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
 	if (init_func) {
 		ret = init_func(pdev, dwsmmio);
 		if (ret)
-			goto out;
+			goto out_reset;
 	}
 
 	pm_runtime_enable(&pdev->dev);
@@ -397,9 +388,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
 
 out:
 	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(dwsmmio->pclk);
-out_clk:
-	clk_disable_unprepare(dwsmmio->clk);
+out_reset:
 	reset_control_assert(dwsmmio->rstc);
 
 	return ret;
@@ -411,8 +400,6 @@ static void dw_spi_mmio_remove(struct platform_device *pdev)
 
 	dw_spi_remove_host(&dwsmmio->dws);
 	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(dwsmmio->pclk);
-	clk_disable_unprepare(dwsmmio->clk);
 	reset_control_assert(dwsmmio->rstc);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (11 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 12/25] spi: dw-mmio: Use helper function devm_clk_get_*() Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 14/25] spi: lantiq-ssc: " Li Zetao
                     ` (13 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-fsl-dspi.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 8318249f8a1f..c9eae046f66c 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -1372,19 +1372,16 @@ static int dspi_probe(struct platform_device *pdev)
 		}
 	}
 
-	dspi->clk = devm_clk_get(&pdev->dev, "dspi");
+	dspi->clk = devm_clk_get_enabled(&pdev->dev, "dspi");
 	if (IS_ERR(dspi->clk)) {
 		ret = PTR_ERR(dspi->clk);
 		dev_err(&pdev->dev, "unable to get clock\n");
 		goto out_ctlr_put;
 	}
-	ret = clk_prepare_enable(dspi->clk);
-	if (ret)
-		goto out_ctlr_put;
 
 	ret = dspi_init(dspi);
 	if (ret)
-		goto out_clk_put;
+		goto out_ctlr_put;
 
 	dspi->irq = platform_get_irq(pdev, 0);
 	if (dspi->irq <= 0) {
@@ -1400,7 +1397,7 @@ static int dspi_probe(struct platform_device *pdev)
 				   IRQF_SHARED, pdev->name, dspi);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to attach DSPI interrupt\n");
-		goto out_clk_put;
+		goto out_ctlr_put;
 	}
 
 poll_mode:
@@ -1432,8 +1429,6 @@ static int dspi_probe(struct platform_device *pdev)
 out_free_irq:
 	if (dspi->irq)
 		free_irq(dspi->irq, dspi);
-out_clk_put:
-	clk_disable_unprepare(dspi->clk);
 out_ctlr_put:
 	spi_controller_put(ctlr);
 
@@ -1458,7 +1453,6 @@ static void dspi_remove(struct platform_device *pdev)
 	dspi_release_dma(dspi);
 	if (dspi->irq)
 		free_irq(dspi->irq, dspi);
-	clk_disable_unprepare(dspi->clk);
 }
 
 static void dspi_shutdown(struct platform_device *pdev)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 14/25] spi: lantiq-ssc: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (12 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled() Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 15/25] spi: meson-spicc: " Li Zetao
                     ` (12 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-lantiq-ssc.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-lantiq-ssc.c b/drivers/spi/spi-lantiq-ssc.c
index 938e9e577e4f..18a46569ba46 100644
--- a/drivers/spi/spi-lantiq-ssc.c
+++ b/drivers/spi/spi-lantiq-ssc.c
@@ -932,14 +932,11 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
 	if (err)
 		goto err_host_put;
 
-	spi->spi_clk = devm_clk_get(dev, "gate");
+	spi->spi_clk = devm_clk_get_enabled(dev, "gate");
 	if (IS_ERR(spi->spi_clk)) {
 		err = PTR_ERR(spi->spi_clk);
 		goto err_host_put;
 	}
-	err = clk_prepare_enable(spi->spi_clk);
-	if (err)
-		goto err_host_put;
 
 	/*
 	 * Use the old clk_get_fpi() function on Lantiq platform, till it
@@ -952,7 +949,7 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
 #endif
 	if (IS_ERR(spi->fpi_clk)) {
 		err = PTR_ERR(spi->fpi_clk);
-		goto err_clk_disable;
+		goto err_host_put;
 	}
 
 	num_cs = 8;
@@ -1010,8 +1007,6 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
 	destroy_workqueue(spi->wq);
 err_clk_put:
 	clk_put(spi->fpi_clk);
-err_clk_disable:
-	clk_disable_unprepare(spi->spi_clk);
 err_host_put:
 	spi_controller_put(host);
 
@@ -1029,7 +1024,6 @@ static void lantiq_ssc_remove(struct platform_device *pdev)
 	hw_enter_config_mode(spi);
 
 	destroy_workqueue(spi->wq);
-	clk_disable_unprepare(spi->spi_clk);
 	clk_put(spi->fpi_clk);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 15/25] spi: meson-spicc: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (13 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 14/25] spi: lantiq-ssc: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 16/25] spi: spi-meson-spifc: " Li Zetao
                     ` (11 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-meson-spicc.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

diff --git a/drivers/spi/spi-meson-spicc.c b/drivers/spi/spi-meson-spicc.c
index 43d134f4b42b..1f2d26254e03 100644
--- a/drivers/spi/spi-meson-spicc.c
+++ b/drivers/spi/spi-meson-spicc.c
@@ -820,7 +820,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
 		goto out_master;
 	}
 
-	spicc->core = devm_clk_get(&pdev->dev, "core");
+	spicc->core = devm_clk_get_enabled(&pdev->dev, "core");
 	if (IS_ERR(spicc->core)) {
 		dev_err(&pdev->dev, "core clock request failed\n");
 		ret = PTR_ERR(spicc->core);
@@ -828,7 +828,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
 	}
 
 	if (spicc->data->has_pclk) {
-		spicc->pclk = devm_clk_get(&pdev->dev, "pclk");
+		spicc->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
 		if (IS_ERR(spicc->pclk)) {
 			dev_err(&pdev->dev, "pclk clock request failed\n");
 			ret = PTR_ERR(spicc->pclk);
@@ -836,22 +836,10 @@ static int meson_spicc_probe(struct platform_device *pdev)
 		}
 	}
 
-	ret = clk_prepare_enable(spicc->core);
-	if (ret) {
-		dev_err(&pdev->dev, "core clock enable failed\n");
-		goto out_master;
-	}
-
-	ret = clk_prepare_enable(spicc->pclk);
-	if (ret) {
-		dev_err(&pdev->dev, "pclk clock enable failed\n");
-		goto out_core_clk;
-	}
-
 	spicc->pinctrl = devm_pinctrl_get(&pdev->dev);
 	if (IS_ERR(spicc->pinctrl)) {
 		ret = PTR_ERR(spicc->pinctrl);
-		goto out_clk;
+		goto out_master;
 	}
 
 	device_reset_optional(&pdev->dev);
@@ -878,31 +866,25 @@ static int meson_spicc_probe(struct platform_device *pdev)
 	ret = meson_spicc_pow2_clk_init(spicc);
 	if (ret) {
 		dev_err(&pdev->dev, "pow2 clock registration failed\n");
-		goto out_clk;
+		goto out_master;
 	}
 
 	if (spicc->data->has_enhance_clk_div) {
 		ret = meson_spicc_enh_clk_init(spicc);
 		if (ret) {
 			dev_err(&pdev->dev, "clock registration failed\n");
-			goto out_clk;
+			goto out_master;
 		}
 	}
 
 	ret = devm_spi_register_master(&pdev->dev, master);
 	if (ret) {
 		dev_err(&pdev->dev, "spi master registration failed\n");
-		goto out_clk;
+		goto out_master;
 	}
 
 	return 0;
 
-out_clk:
-	clk_disable_unprepare(spicc->pclk);
-
-out_core_clk:
-	clk_disable_unprepare(spicc->core);
-
 out_master:
 	spi_master_put(master);
 
@@ -916,9 +898,6 @@ static void meson_spicc_remove(struct platform_device *pdev)
 	/* Disable SPI */
 	writel(0, spicc->base + SPICC_CONREG);
 
-	clk_disable_unprepare(spicc->core);
-	clk_disable_unprepare(spicc->pclk);
-
 	spi_master_put(spicc->master);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 16/25] spi: spi-meson-spifc: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (14 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 15/25] spi: meson-spicc: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 17/25] spi: microchip-core-qspi: " Li Zetao
                     ` (10 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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.
Moreover, the lable "out_clk" no longer makes sense, rename it to "out_pm".

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-meson-spifc.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/spi-meson-spifc.c b/drivers/spi/spi-meson-spifc.c
index 06626f406f68..d70a18885b49 100644
--- a/drivers/spi/spi-meson-spifc.c
+++ b/drivers/spi/spi-meson-spifc.c
@@ -312,19 +312,13 @@ static int meson_spifc_probe(struct platform_device *pdev)
 		goto out_err;
 	}
 
-	spifc->clk = devm_clk_get(spifc->dev, NULL);
+	spifc->clk = devm_clk_get_enabled(spifc->dev, NULL);
 	if (IS_ERR(spifc->clk)) {
 		dev_err(spifc->dev, "missing clock\n");
 		ret = PTR_ERR(spifc->clk);
 		goto out_err;
 	}
 
-	ret = clk_prepare_enable(spifc->clk);
-	if (ret) {
-		dev_err(spifc->dev, "can't prepare clock\n");
-		goto out_err;
-	}
-
 	rate = clk_get_rate(spifc->clk);
 
 	master->num_chipselect = 1;
@@ -343,12 +337,11 @@ static int meson_spifc_probe(struct platform_device *pdev)
 	ret = devm_spi_register_master(spifc->dev, master);
 	if (ret) {
 		dev_err(spifc->dev, "failed to register spi master\n");
-		goto out_clk;
+		goto out_pm;
 	}
 
 	return 0;
-out_clk:
-	clk_disable_unprepare(spifc->clk);
+out_pm:
 	pm_runtime_disable(spifc->dev);
 out_err:
 	spi_master_put(master);
@@ -357,11 +350,7 @@ static int meson_spifc_probe(struct platform_device *pdev)
 
 static void meson_spifc_remove(struct platform_device *pdev)
 {
-	struct spi_master *master = platform_get_drvdata(pdev);
-	struct meson_spifc *spifc = spi_master_get_devdata(master);
-
 	pm_runtime_get_sync(&pdev->dev);
-	clk_disable_unprepare(spifc->clk);
 	pm_runtime_disable(&pdev->dev);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 17/25] spi: microchip-core-qspi: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (15 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 16/25] spi: spi-meson-spifc: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 18/25] spi: microchip-core: " Li Zetao
                     ` (9 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-microchip-core-qspi.c | 29 +++++++--------------------
 1 file changed, 7 insertions(+), 22 deletions(-)

diff --git a/drivers/spi/spi-microchip-core-qspi.c b/drivers/spi/spi-microchip-core-qspi.c
index 4f76ddf97b10..396dfc0fa278 100644
--- a/drivers/spi/spi-microchip-core-qspi.c
+++ b/drivers/spi/spi-microchip-core-qspi.c
@@ -518,30 +518,23 @@ static int mchp_coreqspi_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, PTR_ERR(qspi->regs),
 				     "failed to map registers\n");
 
-	qspi->clk = devm_clk_get(&pdev->dev, NULL);
+	qspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(qspi->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(qspi->clk),
 				     "could not get clock\n");
 
-	ret = clk_prepare_enable(qspi->clk);
-	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
-				     "failed to enable clock\n");
-
 	init_completion(&qspi->data_completion);
 	mutex_init(&qspi->op_lock);
 
 	qspi->irq = platform_get_irq(pdev, 0);
-	if (qspi->irq < 0) {
-		ret = qspi->irq;
-		goto out;
-	}
+	if (qspi->irq < 0)
+		return qspi->irq;
 
 	ret = devm_request_irq(&pdev->dev, qspi->irq, mchp_coreqspi_isr,
 			       IRQF_SHARED, pdev->name, qspi);
 	if (ret) {
 		dev_err(&pdev->dev, "request_irq failed %d\n", ret);
-		goto out;
+		return ret;
 	}
 
 	ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
@@ -552,18 +545,11 @@ static int mchp_coreqspi_probe(struct platform_device *pdev)
 	ctlr->dev.of_node = np;
 
 	ret = devm_spi_register_controller(&pdev->dev, ctlr);
-	if (ret) {
-		dev_err_probe(&pdev->dev, ret,
-			      "spi_register_controller failed\n");
-		goto out;
-	}
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "spi_register_controller failed\n");
 
 	return 0;
-
-out:
-	clk_disable_unprepare(qspi->clk);
-
-	return ret;
 }
 
 static void mchp_coreqspi_remove(struct platform_device *pdev)
@@ -574,7 +560,6 @@ static void mchp_coreqspi_remove(struct platform_device *pdev)
 	mchp_coreqspi_disable_ints(qspi);
 	control &= ~CONTROL_ENABLE;
 	writel_relaxed(control, qspi->regs + REG_CONTROL);
-	clk_disable_unprepare(qspi->clk);
 }
 
 static const struct of_device_id mchp_coreqspi_of_match[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 18/25] spi: microchip-core: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (16 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 17/25] spi: microchip-core-qspi: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 19/25] spi: mtk-snfi: " Li Zetao
                     ` (8 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-microchip-core.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/spi/spi-microchip-core.c b/drivers/spi/spi-microchip-core.c
index b451cd4860ec..becdcdc9e6d1 100644
--- a/drivers/spi/spi-microchip-core.c
+++ b/drivers/spi/spi-microchip-core.c
@@ -539,22 +539,16 @@ static int mchp_corespi_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, ret,
 				     "could not request irq\n");
 
-	spi->clk = devm_clk_get(&pdev->dev, NULL);
+	spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(spi->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk),
 				     "could not get clk\n");
 
-	ret = clk_prepare_enable(spi->clk);
-	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
-				     "failed to enable clock\n");
-
 	mchp_corespi_init(master, spi);
 
 	ret = devm_spi_register_master(&pdev->dev, master);
 	if (ret) {
 		mchp_corespi_disable(spi);
-		clk_disable_unprepare(spi->clk);
 		return dev_err_probe(&pdev->dev, ret,
 				     "unable to register master for SPI controller\n");
 	}
@@ -570,7 +564,6 @@ static void mchp_corespi_remove(struct platform_device *pdev)
 	struct mchp_corespi *spi = spi_master_get_devdata(master);
 
 	mchp_corespi_disable_ints(spi);
-	clk_disable_unprepare(spi->clk);
 	mchp_corespi_disable(spi);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 19/25] spi: mtk-snfi: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (17 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 18/25] spi: microchip-core: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-09-13  9:15     ` AngeloGioacchino Del Regno
  2023-08-23 13:39   ` [PATCH -next v2 20/25] spi: npcm-fiu: " Li Zetao
                     ` (7 subsequent siblings)
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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.
Also, devm_clk_get_optional() and clk_prepare_enable() can now be
replaced by devm_clk_get_optional_enabled().Moreover, the two functions
mtk_snand_enable_clk() and mtk_snand_disable_clk() no longer are used,
drop them for clean code.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-mtk-snfi.c | 61 ++++++--------------------------------
 1 file changed, 9 insertions(+), 52 deletions(-)

diff --git a/drivers/spi/spi-mtk-snfi.c b/drivers/spi/spi-mtk-snfi.c
index 4433a8a9299f..8ad5a4764855 100644
--- a/drivers/spi/spi-mtk-snfi.c
+++ b/drivers/spi/spi-mtk-snfi.c
@@ -1332,42 +1332,6 @@ static const struct of_device_id mtk_snand_ids[] = {
 
 MODULE_DEVICE_TABLE(of, mtk_snand_ids);
 
-static int mtk_snand_enable_clk(struct mtk_snand *ms)
-{
-	int ret;
-
-	ret = clk_prepare_enable(ms->nfi_clk);
-	if (ret) {
-		dev_err(ms->dev, "unable to enable nfi clk\n");
-		return ret;
-	}
-	ret = clk_prepare_enable(ms->pad_clk);
-	if (ret) {
-		dev_err(ms->dev, "unable to enable pad clk\n");
-		goto err1;
-	}
-	ret = clk_prepare_enable(ms->nfi_hclk);
-	if (ret) {
-		dev_err(ms->dev, "unable to enable nfi hclk\n");
-		goto err2;
-	}
-
-	return 0;
-
-err2:
-	clk_disable_unprepare(ms->pad_clk);
-err1:
-	clk_disable_unprepare(ms->nfi_clk);
-	return ret;
-}
-
-static void mtk_snand_disable_clk(struct mtk_snand *ms)
-{
-	clk_disable_unprepare(ms->nfi_hclk);
-	clk_disable_unprepare(ms->pad_clk);
-	clk_disable_unprepare(ms->nfi_clk);
-}
-
 static int mtk_snand_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1406,49 +1370,45 @@ static int mtk_snand_probe(struct platform_device *pdev)
 
 	ms->dev = &pdev->dev;
 
-	ms->nfi_clk = devm_clk_get(&pdev->dev, "nfi_clk");
+	ms->nfi_clk = devm_clk_get_enabled(&pdev->dev, "nfi_clk");
 	if (IS_ERR(ms->nfi_clk)) {
 		ret = PTR_ERR(ms->nfi_clk);
 		dev_err(&pdev->dev, "unable to get nfi_clk, err = %d\n", ret);
 		goto release_ecc;
 	}
 
-	ms->pad_clk = devm_clk_get(&pdev->dev, "pad_clk");
+	ms->pad_clk = devm_clk_get_enabled(&pdev->dev, "pad_clk");
 	if (IS_ERR(ms->pad_clk)) {
 		ret = PTR_ERR(ms->pad_clk);
 		dev_err(&pdev->dev, "unable to get pad_clk, err = %d\n", ret);
 		goto release_ecc;
 	}
 
-	ms->nfi_hclk = devm_clk_get_optional(&pdev->dev, "nfi_hclk");
+	ms->nfi_hclk = devm_clk_get_optional_enabled(&pdev->dev, "nfi_hclk");
 	if (IS_ERR(ms->nfi_hclk)) {
 		ret = PTR_ERR(ms->nfi_hclk);
 		dev_err(&pdev->dev, "unable to get nfi_hclk, err = %d\n", ret);
 		goto release_ecc;
 	}
 
-	ret = mtk_snand_enable_clk(ms);
-	if (ret)
-		goto release_ecc;
-
 	init_completion(&ms->op_done);
 
 	ms->irq = platform_get_irq(pdev, 0);
 	if (ms->irq < 0) {
 		ret = ms->irq;
-		goto disable_clk;
+		goto release_ecc;
 	}
 	ret = devm_request_irq(ms->dev, ms->irq, mtk_snand_irq, 0x0,
 			       "mtk-snand", ms);
 	if (ret) {
 		dev_err(ms->dev, "failed to request snfi irq\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	ret = dma_set_mask(ms->dev, DMA_BIT_MASK(32));
 	if (ret) {
 		dev_err(ms->dev, "failed to set dma mask\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	// switch to SNFI mode
@@ -1472,7 +1432,7 @@ static int mtk_snand_probe(struct platform_device *pdev)
 	ret = mtk_snand_setup_pagefmt(ms, SZ_2K, SZ_64);
 	if (ret) {
 		dev_err(ms->dev, "failed to set initial page format\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	// setup ECC engine
@@ -1484,7 +1444,7 @@ static int mtk_snand_probe(struct platform_device *pdev)
 	ret = nand_ecc_register_on_host_hw_engine(&ms->ecc_eng);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register ecc engine.\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	ctlr->num_chipselect = 1;
@@ -1496,12 +1456,10 @@ static int mtk_snand_probe(struct platform_device *pdev)
 	ret = spi_register_controller(ctlr);
 	if (ret) {
 		dev_err(&pdev->dev, "spi_register_controller failed.\n");
-		goto disable_clk;
+		goto release_ecc;
 	}
 
 	return 0;
-disable_clk:
-	mtk_snand_disable_clk(ms);
 release_ecc:
 	mtk_ecc_release(ms->ecc);
 	return ret;
@@ -1513,7 +1471,6 @@ static void mtk_snand_remove(struct platform_device *pdev)
 	struct mtk_snand *ms = spi_controller_get_devdata(ctlr);
 
 	spi_unregister_controller(ctlr);
-	mtk_snand_disable_clk(ms);
 	mtk_ecc_release(ms->ecc);
 	kfree(ms->buf);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 20/25] spi: npcm-fiu: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (18 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 19/25] spi: mtk-snfi: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 21/25] spi: orion: " Li Zetao
                     ` (6 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-npcm-fiu.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi-npcm-fiu.c b/drivers/spi/spi-npcm-fiu.c
index 0ca21ff0e9cc..1a5277ff349f 100644
--- a/drivers/spi/spi-npcm-fiu.c
+++ b/drivers/spi/spi-npcm-fiu.c
@@ -699,7 +699,7 @@ static int npcm_fiu_probe(struct platform_device *pdev)
 	struct spi_controller *ctrl;
 	struct npcm_fiu_spi *fiu;
 	void __iomem *regbase;
-	int id, ret;
+	int id;
 
 	ctrl = devm_spi_alloc_host(dev, sizeof(*fiu));
 	if (!ctrl)
@@ -737,7 +737,7 @@ static int npcm_fiu_probe(struct platform_device *pdev)
 
 	fiu->res_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
 						    "memory");
-	fiu->clk = devm_clk_get(dev, NULL);
+	fiu->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(fiu->clk))
 		return PTR_ERR(fiu->clk);
 
@@ -745,7 +745,6 @@ static int npcm_fiu_probe(struct platform_device *pdev)
 					       "nuvoton,spix-mode");
 
 	platform_set_drvdata(pdev, fiu);
-	clk_prepare_enable(fiu->clk);
 
 	ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD
 		| SPI_TX_DUAL | SPI_TX_QUAD;
@@ -755,18 +754,11 @@ static int npcm_fiu_probe(struct platform_device *pdev)
 	ctrl->num_chipselect = fiu->info->max_cs;
 	ctrl->dev.of_node = dev->of_node;
 
-	ret = devm_spi_register_controller(dev, ctrl);
-	if (ret)
-		clk_disable_unprepare(fiu->clk);
-
-	return ret;
+	return devm_spi_register_controller(dev, ctrl);
 }
 
 static void npcm_fiu_remove(struct platform_device *pdev)
 {
-	struct npcm_fiu_spi *fiu = platform_get_drvdata(pdev);
-
-	clk_disable_unprepare(fiu->clk);
 }
 
 MODULE_DEVICE_TABLE(of, npcm_fiu_dt_ids);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 21/25] spi: orion: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (19 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 20/25] spi: npcm-fiu: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 22/25] spi: pic32-sqi: " Li Zetao
                     ` (5 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-orion.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index 1f10f5c8e34d..eee9ff4bfa5b 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -688,21 +688,17 @@ static int orion_spi_probe(struct platform_device *pdev)
 	devdata = devdata ? devdata : &orion_spi_dev_data;
 	spi->devdata = devdata;
 
-	spi->clk = devm_clk_get(&pdev->dev, NULL);
+	spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(spi->clk)) {
 		status = PTR_ERR(spi->clk);
 		goto out;
 	}
 
-	status = clk_prepare_enable(spi->clk);
-	if (status)
-		goto out;
-
 	/* The following clock is only used by some SoCs */
 	spi->axi_clk = devm_clk_get(&pdev->dev, "axi");
 	if (PTR_ERR(spi->axi_clk) == -EPROBE_DEFER) {
 		status = -EPROBE_DEFER;
-		goto out_rel_clk;
+		goto out;
 	}
 	if (!IS_ERR(spi->axi_clk))
 		clk_prepare_enable(spi->axi_clk);
@@ -795,8 +791,6 @@ static int orion_spi_probe(struct platform_device *pdev)
 	pm_runtime_disable(&pdev->dev);
 out_rel_axi_clk:
 	clk_disable_unprepare(spi->axi_clk);
-out_rel_clk:
-	clk_disable_unprepare(spi->clk);
 out:
 	spi_controller_put(host);
 	return status;
@@ -810,7 +804,6 @@ static void orion_spi_remove(struct platform_device *pdev)
 
 	pm_runtime_get_sync(&pdev->dev);
 	clk_disable_unprepare(spi->axi_clk);
-	clk_disable_unprepare(spi->clk);
 
 	spi_unregister_controller(host);
 	pm_runtime_disable(&pdev->dev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 22/25] spi: pic32-sqi: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (20 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 21/25] spi: orion: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 23/25] spi: pic32: " Li Zetao
                     ` (4 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-pic32-sqi.c | 27 +++------------------------
 1 file changed, 3 insertions(+), 24 deletions(-)

diff --git a/drivers/spi/spi-pic32-sqi.c b/drivers/spi/spi-pic32-sqi.c
index 883354d0ff52..3f1e5b27776b 100644
--- a/drivers/spi/spi-pic32-sqi.c
+++ b/drivers/spi/spi-pic32-sqi.c
@@ -593,33 +593,20 @@ static int pic32_sqi_probe(struct platform_device *pdev)
 	}
 
 	/* clocks */
-	sqi->sys_clk = devm_clk_get(&pdev->dev, "reg_ck");
+	sqi->sys_clk = devm_clk_get_enabled(&pdev->dev, "reg_ck");
 	if (IS_ERR(sqi->sys_clk)) {
 		ret = PTR_ERR(sqi->sys_clk);
 		dev_err(&pdev->dev, "no sys_clk ?\n");
 		goto err_free_host;
 	}
 
-	sqi->base_clk = devm_clk_get(&pdev->dev, "spi_ck");
+	sqi->base_clk = devm_clk_get_enabled(&pdev->dev, "spi_ck");
 	if (IS_ERR(sqi->base_clk)) {
 		ret = PTR_ERR(sqi->base_clk);
 		dev_err(&pdev->dev, "no base clk ?\n");
 		goto err_free_host;
 	}
 
-	ret = clk_prepare_enable(sqi->sys_clk);
-	if (ret) {
-		dev_err(&pdev->dev, "sys clk enable failed\n");
-		goto err_free_host;
-	}
-
-	ret = clk_prepare_enable(sqi->base_clk);
-	if (ret) {
-		dev_err(&pdev->dev, "base clk enable failed\n");
-		clk_disable_unprepare(sqi->sys_clk);
-		goto err_free_host;
-	}
-
 	init_completion(&sqi->xfer_done);
 
 	/* initialize hardware */
@@ -629,7 +616,7 @@ static int pic32_sqi_probe(struct platform_device *pdev)
 	ret = ring_desc_ring_alloc(sqi);
 	if (ret) {
 		dev_err(&pdev->dev, "ring alloc failed\n");
-		goto err_disable_clk;
+		goto err_free_host;
 	}
 
 	/* install irq handlers */
@@ -669,10 +656,6 @@ static int pic32_sqi_probe(struct platform_device *pdev)
 err_free_ring:
 	ring_desc_ring_free(sqi);
 
-err_disable_clk:
-	clk_disable_unprepare(sqi->base_clk);
-	clk_disable_unprepare(sqi->sys_clk);
-
 err_free_host:
 	spi_controller_put(host);
 	return ret;
@@ -685,10 +668,6 @@ static void pic32_sqi_remove(struct platform_device *pdev)
 	/* release resources */
 	free_irq(sqi->irq, sqi);
 	ring_desc_ring_free(sqi);
-
-	/* disable clk */
-	clk_disable_unprepare(sqi->base_clk);
-	clk_disable_unprepare(sqi->sys_clk);
 }
 
 static const struct of_device_id pic32_sqi_of_ids[] = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 23/25] spi: pic32: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (21 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 22/25] spi: pic32-sqi: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 13:39   ` [PATCH -next v2 24/25] spi: spl022: " Li Zetao
                     ` (3 subsequent siblings)
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-pic32.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/spi/spi-pic32.c b/drivers/spi/spi-pic32.c
index 52b788dac10a..f55b38c577e4 100644
--- a/drivers/spi/spi-pic32.c
+++ b/drivers/spi/spi-pic32.c
@@ -730,17 +730,13 @@ static int pic32_spi_hw_probe(struct platform_device *pdev,
 		return pic32s->tx_irq;
 
 	/* get clock */
-	pic32s->clk = devm_clk_get(&pdev->dev, "mck0");
+	pic32s->clk = devm_clk_get_enabled(&pdev->dev, "mck0");
 	if (IS_ERR(pic32s->clk)) {
 		dev_err(&pdev->dev, "clk not found\n");
 		ret = PTR_ERR(pic32s->clk);
 		goto err_unmap_mem;
 	}
 
-	ret = clk_prepare_enable(pic32s->clk);
-	if (ret)
-		goto err_unmap_mem;
-
 	pic32_spi_hw_init(pic32s);
 
 	return 0;
@@ -837,7 +833,6 @@ static int pic32_spi_probe(struct platform_device *pdev)
 
 err_bailout:
 	pic32_spi_dma_unprep(pic32s);
-	clk_disable_unprepare(pic32s->clk);
 err_host:
 	spi_controller_put(host);
 	return ret;
@@ -849,7 +844,6 @@ static void pic32_spi_remove(struct platform_device *pdev)
 
 	pic32s = platform_get_drvdata(pdev);
 	pic32_spi_disable(pic32s);
-	clk_disable_unprepare(pic32s->clk);
 	pic32_spi_dma_unprep(pic32s);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 24/25] spi: spl022: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (22 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 23/25] spi: pic32: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 17:16     ` Jonathan Cameron
  2023-08-23 13:39   ` [PATCH -next v2 25/25] spi: rockchip: " Li Zetao
                     ` (2 subsequent siblings)
  26 siblings, 1 reply; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn

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 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.
Moreover, the label "err_no_clk_en" is no used, drop it for clean code.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: Delete the modification of odd formatting.

 drivers/spi/spi-pl022.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index bb347b6bb6f3..d1b6110b38fc 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -2168,19 +2168,13 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
 	dev_info(&adev->dev, "mapped registers from %pa to %p\n",
 		&adev->res.start, pl022->virtbase);
 
-	pl022->clk = devm_clk_get(&adev->dev, NULL);
+	pl022->clk = devm_clk_get_enabled(&adev->dev, NULL);
 	if (IS_ERR(pl022->clk)) {
 		status = PTR_ERR(pl022->clk);
 		dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
 		goto err_no_clk;
 	}
 
-	status = clk_prepare_enable(pl022->clk);
-	if (status) {
-		dev_err(&adev->dev, "could not enable SSP/SPI bus clock\n");
-		goto err_no_clk_en;
-	}
-
 	/* Initialize transfer pump */
 	tasklet_init(&pl022->pump_transfers, pump_transfers,
 		     (unsigned long)pl022);
@@ -2240,8 +2234,6 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
 	if (platform_info->enable_dma)
 		pl022_dma_remove(pl022);
  err_no_irq:
-	clk_disable_unprepare(pl022->clk);
- err_no_clk_en:
  err_no_clk:
  err_no_ioremap:
 	amba_release_regions(adev);
@@ -2268,7 +2260,6 @@ pl022_remove(struct amba_device *adev)
 	if (pl022->host_info->enable_dma)
 		pl022_dma_remove(pl022);
 
-	clk_disable_unprepare(pl022->clk);
 	amba_release_regions(adev);
 	tasklet_disable(&pl022->pump_transfers);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* [PATCH -next v2 25/25] spi: rockchip: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (23 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 24/25] spi: spl022: " Li Zetao
@ 2023-08-23 13:39   ` Li Zetao
  2023-08-23 14:33   ` [PATCH -next v2 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Mark Brown
  2023-09-12 11:37   ` Mark Brown
  26 siblings, 0 replies; 71+ messages in thread
From: Li Zetao @ 2023-08-23 13:39 UTC (permalink / raw)
  To: lizetao1
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn,
	Jonathan Cameron

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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
v1 -> v2: None

 drivers/spi/spi-rockchip.c | 30 +++++-------------------------
 1 file changed, 5 insertions(+), 25 deletions(-)

diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index 5b010094dace..4b9669da2cf3 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -782,42 +782,30 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 		goto err_put_ctlr;
 	}
 
-	rs->apb_pclk = devm_clk_get(&pdev->dev, "apb_pclk");
+	rs->apb_pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk");
 	if (IS_ERR(rs->apb_pclk)) {
 		dev_err(&pdev->dev, "Failed to get apb_pclk\n");
 		ret = PTR_ERR(rs->apb_pclk);
 		goto err_put_ctlr;
 	}
 
-	rs->spiclk = devm_clk_get(&pdev->dev, "spiclk");
+	rs->spiclk = devm_clk_get_enabled(&pdev->dev, "spiclk");
 	if (IS_ERR(rs->spiclk)) {
 		dev_err(&pdev->dev, "Failed to get spi_pclk\n");
 		ret = PTR_ERR(rs->spiclk);
 		goto err_put_ctlr;
 	}
 
-	ret = clk_prepare_enable(rs->apb_pclk);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to enable apb_pclk\n");
-		goto err_put_ctlr;
-	}
-
-	ret = clk_prepare_enable(rs->spiclk);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to enable spi_clk\n");
-		goto err_disable_apbclk;
-	}
-
 	spi_enable_chip(rs, false);
 
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0)
-		goto err_disable_spiclk;
+		goto err_put_ctlr;
 
 	ret = devm_request_threaded_irq(&pdev->dev, ret, rockchip_spi_isr, NULL,
 			IRQF_ONESHOT, dev_name(&pdev->dev), ctlr);
 	if (ret)
-		goto err_disable_spiclk;
+		goto err_put_ctlr;
 
 	rs->dev = &pdev->dev;
 	rs->freq = clk_get_rate(rs->spiclk);
@@ -843,7 +831,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 	if (!rs->fifo_len) {
 		dev_err(&pdev->dev, "Failed to get fifo length\n");
 		ret = -EINVAL;
-		goto err_disable_spiclk;
+		goto err_put_ctlr;
 	}
 
 	pm_runtime_set_autosuspend_delay(&pdev->dev, ROCKCHIP_AUTOSUSPEND_TIMEOUT);
@@ -937,10 +925,6 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 		dma_release_channel(ctlr->dma_tx);
 err_disable_pm_runtime:
 	pm_runtime_disable(&pdev->dev);
-err_disable_spiclk:
-	clk_disable_unprepare(rs->spiclk);
-err_disable_apbclk:
-	clk_disable_unprepare(rs->apb_pclk);
 err_put_ctlr:
 	spi_controller_put(ctlr);
 
@@ -950,13 +934,9 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 static void rockchip_spi_remove(struct platform_device *pdev)
 {
 	struct spi_controller *ctlr = spi_controller_get(platform_get_drvdata(pdev));
-	struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
 
 	pm_runtime_get_sync(&pdev->dev);
 
-	clk_disable_unprepare(rs->spiclk);
-	clk_disable_unprepare(rs->apb_pclk);
-
 	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_set_suspended(&pdev->dev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 12/25] spi: dw-mmio: Use helper function devm_clk_get_*()
  2023-08-23 13:39   ` [PATCH -next v2 12/25] spi: dw-mmio: Use helper function devm_clk_get_*() Li Zetao
@ 2023-08-23 14:20     ` Serge Semin
  2023-08-23 17:15       ` Jonathan Cameron
  0 siblings, 1 reply; 71+ messages in thread
From: Serge Semin @ 2023-08-23 14:20 UTC (permalink / raw)
  To: Li Zetao
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, florian.fainelli, heiko,
	jbrunet, joel, khilman, linus.walleij, linux-amlogic,
	linux-arm-kernel, linux-aspeed, linux-mediatek, linux-riscv,
	linux-rockchip, linux-rpi-kernel, linux-spi, martin.blumenstingl,
	matthias.bgg, neil.armstrong, olteanv, openbmc, rjui, sbranden,
	tali.perry1, tmaimon77, venture, yuenn

On Wed, Aug 23, 2023 at 09:39:25PM +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 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. Also,
> devm_clk_get_optional() and clk_prepare_enable() can now be replaced by
> devm_clk_get_optional_enabled(). Moreover, the lable "out_clk" no longer
> makes sense, rename it to "out_reset".
> 
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
> v1 -> v2: Return directly instead of calling reset_control_deassert()
> before the reset control handler has been requested. And use the
> "out_reset" label instead of "out" before calling pm_runtime_enable().

LGTM. Thanks!
Acked-by: Serge Semin <fancer.lancer@gmail.com>

-Serge(y)

> 
>  drivers/spi/spi-dw-mmio.c | 31 +++++++++----------------------
>  1 file changed, 9 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
> index 805264c9c65c..46801189a651 100644
> --- a/drivers/spi/spi-dw-mmio.c
> +++ b/drivers/spi/spi-dw-mmio.c
> @@ -340,29 +340,20 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
>  	if (dws->irq < 0)
>  		return dws->irq; /* -ENXIO */
>  
> -	dwsmmio->clk = devm_clk_get(&pdev->dev, NULL);
> +	dwsmmio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  	if (IS_ERR(dwsmmio->clk))
>  		return PTR_ERR(dwsmmio->clk);
> -	ret = clk_prepare_enable(dwsmmio->clk);
> -	if (ret)
> -		return ret;
>  
>  	/* Optional clock needed to access the registers */
> -	dwsmmio->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> -	if (IS_ERR(dwsmmio->pclk)) {
> -		ret = PTR_ERR(dwsmmio->pclk);
> -		goto out_clk;
> -	}
> -	ret = clk_prepare_enable(dwsmmio->pclk);
> -	if (ret)
> -		goto out_clk;
> +	dwsmmio->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
> +	if (IS_ERR(dwsmmio->pclk))
> +		return PTR_ERR(dwsmmio->pclk);
>  
>  	/* find an optional reset controller */
>  	dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi");
> -	if (IS_ERR(dwsmmio->rstc)) {
> -		ret = PTR_ERR(dwsmmio->rstc);
> -		goto out_clk;
> -	}
> +	if (IS_ERR(dwsmmio->rstc))
> +		return PTR_ERR(dwsmmio->rstc);
> +
>  	reset_control_deassert(dwsmmio->rstc);
>  
>  	dws->bus_num = pdev->id;
> @@ -383,7 +374,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
>  	if (init_func) {
>  		ret = init_func(pdev, dwsmmio);
>  		if (ret)
> -			goto out;
> +			goto out_reset;
>  	}
>  
>  	pm_runtime_enable(&pdev->dev);
> @@ -397,9 +388,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
>  
>  out:
>  	pm_runtime_disable(&pdev->dev);
> -	clk_disable_unprepare(dwsmmio->pclk);
> -out_clk:
> -	clk_disable_unprepare(dwsmmio->clk);
> +out_reset:
>  	reset_control_assert(dwsmmio->rstc);
>  
>  	return ret;
> @@ -411,8 +400,6 @@ static void dw_spi_mmio_remove(struct platform_device *pdev)
>  
>  	dw_spi_remove_host(&dwsmmio->dws);
>  	pm_runtime_disable(&pdev->dev);
> -	clk_disable_unprepare(dwsmmio->pclk);
> -	clk_disable_unprepare(dwsmmio->clk);
>  	reset_control_assert(dwsmmio->rstc);
>  }
>  
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers.
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (24 preceding siblings ...)
  2023-08-23 13:39   ` [PATCH -next v2 25/25] spi: rockchip: " Li Zetao
@ 2023-08-23 14:33   ` Mark Brown
  2023-09-12 11:37   ` Mark Brown
  26 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2023-08-23 14:33 UTC (permalink / raw)
  To: Li Zetao
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, chin-ting_kuo, clg,
	conor.dooley, daire.mcnamara, fancer.lancer, florian.fainelli,
	heiko, jbrunet, joel, khilman, linus.walleij, linux-amlogic,
	linux-arm-kernel, linux-aspeed, linux-mediatek, linux-riscv,
	linux-rockchip, linux-rpi-kernel, linux-spi, martin.blumenstingl,
	matthias.bgg, neil.armstrong, olteanv, openbmc, rjui, sbranden,
	tali.perry1, tmaimon77, venture, yuenn

[-- Attachment #1: Type: text/plain, Size: 699 bytes --]

On Wed, Aug 23, 2023 at 09:39:13PM +0800, Li Zetao wrote:
> Commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
> and enabled clocks") provides a 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

Please don't send new patches in reply to old patches or serieses, this
makes it harder for both people and tools to understand what is going
on - it can bury things in mailboxes and make it difficult to keep track
of what current patches are, both for the new patches and the old ones.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 11/25] spi: dw-bt1: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39   ` [PATCH -next v2 11/25] spi: dw-bt1: " Li Zetao
@ 2023-08-23 14:35     ` Serge Semin
  2023-08-23 17:13       ` Jonathan Cameron
  0 siblings, 1 reply; 71+ messages in thread
From: Serge Semin @ 2023-08-23 14:35 UTC (permalink / raw)
  To: Li Zetao
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, florian.fainelli, heiko,
	jbrunet, joel, khilman, linus.walleij, linux-amlogic,
	linux-arm-kernel, linux-aspeed, linux-mediatek, linux-riscv,
	linux-rockchip, linux-rpi-kernel, linux-spi, martin.blumenstingl,
	matthias.bgg, neil.armstrong, olteanv, openbmc, rjui, sbranden,
	tali.perry1, tmaimon77, venture, yuenn, Jonathan Cameron

On Wed, Aug 23, 2023 at 09:39:24PM +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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Acked-by: Serge Semin <fancer.lancer@gmail.com>
> Signed-off-by: Li Zetao <lizetao1@huawei.com>

Just for the record, the tags order is normally supposed to reflect a
patch route. Even though AFAICS it's explicitly defined for the Sob
tags only (see Documentation/process/submitting-patches.rst), but
almost all kernel developers apply that rule to all the tags. See the
kernel git log as the brightest example. So your Sob tag should have
been kept first, then either my Ab or Jonathan' Rb tags.

-Serge(y)

> ---
> v1 -> v2: None
> 
>  drivers/spi/spi-dw-bt1.c | 23 +++++------------------
>  1 file changed, 5 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c
> index 5e1c01822967..5391bcac305c 100644
> --- a/drivers/spi/spi-dw-bt1.c
> +++ b/drivers/spi/spi-dw-bt1.c
> @@ -269,43 +269,32 @@ static int dw_spi_bt1_probe(struct platform_device *pdev)
>  
>  	dws->paddr = mem->start;
>  
> -	dwsbt1->clk = devm_clk_get(&pdev->dev, NULL);
> +	dwsbt1->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>  	if (IS_ERR(dwsbt1->clk))
>  		return PTR_ERR(dwsbt1->clk);
>  
> -	ret = clk_prepare_enable(dwsbt1->clk);
> -	if (ret)
> -		return ret;
> -
>  	dws->bus_num = pdev->id;
>  	dws->reg_io_width = 4;
>  	dws->max_freq = clk_get_rate(dwsbt1->clk);
> -	if (!dws->max_freq) {
> -		ret = -EINVAL;
> -		goto err_disable_clk;
> -	}
> +	if (!dws->max_freq)
> +		return -EINVAL;
>  
>  	init_func = device_get_match_data(&pdev->dev);
>  	ret = init_func(pdev, dwsbt1);
>  	if (ret)
> -		goto err_disable_clk;
> +		return ret;
>  
>  	pm_runtime_enable(&pdev->dev);
>  
>  	ret = dw_spi_add_host(&pdev->dev, dws);
>  	if (ret) {
>  		pm_runtime_disable(&pdev->dev);
> -		goto err_disable_clk;
> +		return ret;
>  	}
>  
>  	platform_set_drvdata(pdev, dwsbt1);
>  
>  	return 0;
> -
> -err_disable_clk:
> -	clk_disable_unprepare(dwsbt1->clk);
> -
> -	return ret;
>  }
>  
>  static void dw_spi_bt1_remove(struct platform_device *pdev)
> @@ -315,8 +304,6 @@ static void dw_spi_bt1_remove(struct platform_device *pdev)
>  	dw_spi_remove_host(&dwsbt1->dws);
>  
>  	pm_runtime_disable(&pdev->dev);
> -
> -	clk_disable_unprepare(dwsbt1->clk);
>  }
>  
>  static const struct of_device_id dw_spi_bt1_of_match[] = {
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared()
  2023-08-23 13:39   ` [PATCH -next v2 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared() Li Zetao
@ 2023-08-23 17:10     ` Jonathan Cameron
  0 siblings, 0 replies; 71+ messages in thread
From: Jonathan Cameron @ 2023-08-23 17:10 UTC (permalink / raw)
  To: Li Zetao
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-amlogic, linux-arm-kernel, linux-aspeed, linux-mediatek,
	linux-riscv, linux-rockchip, linux-rpi-kernel, linux-spi,
	martin.blumenstingl, matthias.bgg, neil.armstrong, olteanv,
	openbmc, rjui, sbranden, tali.perry1, tmaimon77, venture, yuenn

On Wed, 23 Aug 2023 21:39:15 +0800
Li Zetao <lizetao1@huawei.com> wrote:

> Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
> and enabled clocks"), devm_clk_get() and clk_prepare() can now be replaced
> by devm_clk_get_prepared() when driver prepares the clocks for the whole
> lifetime of the device. Moreover, it is no longer necessary to unprepare
> the clocks explicitly.
> 
> Signed-off-by: Li Zetao <lizetao1@huawei.com>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
> v1 -> v2: Drop the empty remove function a3700_spi_remove().
> 
>  drivers/spi/spi-armada-3700.c | 23 +++--------------------
>  1 file changed, 3 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/spi/spi-armada-3700.c b/drivers/spi/spi-armada-3700.c
> index 0103ac0158c0..3c9ed412932f 100644
> --- a/drivers/spi/spi-armada-3700.c
> +++ b/drivers/spi/spi-armada-3700.c
> @@ -865,18 +865,12 @@ static int a3700_spi_probe(struct platform_device *pdev)
>  
>  	init_completion(&spi->done);
>  
> -	spi->clk = devm_clk_get(dev, NULL);
> +	spi->clk = devm_clk_get_prepared(dev, NULL);
>  	if (IS_ERR(spi->clk)) {
>  		dev_err(dev, "could not find clk: %ld\n", PTR_ERR(spi->clk));
>  		goto error;
>  	}
>  
> -	ret = clk_prepare(spi->clk);
> -	if (ret) {
> -		dev_err(dev, "could not prepare clk: %d\n", ret);
> -		goto error;
> -	}
> -
>  	host->max_speed_hz = min_t(unsigned long, A3700_SPI_MAX_SPEED_HZ,
>  					clk_get_rate(spi->clk));
>  	host->min_speed_hz = DIV_ROUND_UP(clk_get_rate(spi->clk),
> @@ -888,40 +882,29 @@ static int a3700_spi_probe(struct platform_device *pdev)
>  			       dev_name(dev), host);
>  	if (ret) {
>  		dev_err(dev, "could not request IRQ: %d\n", ret);
> -		goto error_clk;
> +		goto error;
>  	}
>  
>  	ret = devm_spi_register_controller(dev, host);
>  	if (ret) {
>  		dev_err(dev, "Failed to register host\n");
> -		goto error_clk;
> +		goto error;
>  	}
>  
>  	return 0;
>  
> -error_clk:
> -	clk_unprepare(spi->clk);
>  error:
>  	spi_controller_put(host);
>  out:
>  	return ret;
>  }
>  
> -static void a3700_spi_remove(struct platform_device *pdev)
> -{
> -	struct spi_controller *host = platform_get_drvdata(pdev);
> -	struct a3700_spi *spi = spi_controller_get_devdata(host);
> -
> -	clk_unprepare(spi->clk);
> -}
> -
>  static struct platform_driver a3700_spi_driver = {
>  	.driver = {
>  		.name	= DRIVER_NAME,
>  		.of_match_table = of_match_ptr(a3700_spi_dt_ids),
>  	},
>  	.probe		= a3700_spi_probe,
> -	.remove_new	= a3700_spi_remove,
>  };
>  
>  module_platform_driver(a3700_spi_driver);


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 11/25] spi: dw-bt1: Use helper function devm_clk_get_enabled()
  2023-08-23 14:35     ` Serge Semin
@ 2023-08-23 17:13       ` Jonathan Cameron
  2023-08-25 18:01         ` Serge Semin
  0 siblings, 1 reply; 71+ messages in thread
From: Jonathan Cameron @ 2023-08-23 17:13 UTC (permalink / raw)
  To: Serge Semin
  Cc: Li Zetao, andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, florian.fainelli, heiko,
	jbrunet, joel, khilman, linus.walleij, linux-amlogic,
	linux-arm-kernel, linux-aspeed, linux-mediatek, linux-riscv,
	linux-rockchip, linux-rpi-kernel, linux-spi, martin.blumenstingl,
	matthias.bgg, neil.armstrong, olteanv, openbmc, rjui, sbranden,
	tali.perry1, tmaimon77, venture, yuenn

On Wed, 23 Aug 2023 17:35:35 +0300
Serge Semin <fancer.lancer@gmail.com> wrote:

> On Wed, Aug 23, 2023 at 09:39:24PM +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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Acked-by: Serge Semin <fancer.lancer@gmail.com>
> > Signed-off-by: Li Zetao <lizetao1@huawei.com>  
> 
> Just for the record, the tags order is normally supposed to reflect a
> patch route. Even though AFAICS it's explicitly defined for the Sob
> tags only (see Documentation/process/submitting-patches.rst), but
> almost all kernel developers apply that rule to all the tags. See the
> kernel git log as the brightest example. So your Sob tag should have
> been kept first, then either my Ab or Jonathan' Rb tags.

There have been far too many discussions about this over the years.
There is an argument (I'm not saying I agree with it) that tags given
on an earlier version than the one posted should be before the SoB of
the author on basis that the SoB is occurring later (as it's on the new
version).  That is a slightly stronger argument if there are changes
to the patch, but then things get inconsistent between patches with minor
changes and those without. *sigh*

So this pattern is fairly common if a bit weird in my view :)

Jonathan

> 
> -Serge(y)
> 
> > ---
> > v1 -> v2: None
> > 
> >  drivers/spi/spi-dw-bt1.c | 23 +++++------------------
> >  1 file changed, 5 insertions(+), 18 deletions(-)
> > 
> > diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c
> > index 5e1c01822967..5391bcac305c 100644
> > --- a/drivers/spi/spi-dw-bt1.c
> > +++ b/drivers/spi/spi-dw-bt1.c
> > @@ -269,43 +269,32 @@ static int dw_spi_bt1_probe(struct platform_device *pdev)
> >  
> >  	dws->paddr = mem->start;
> >  
> > -	dwsbt1->clk = devm_clk_get(&pdev->dev, NULL);
> > +	dwsbt1->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> >  	if (IS_ERR(dwsbt1->clk))
> >  		return PTR_ERR(dwsbt1->clk);
> >  
> > -	ret = clk_prepare_enable(dwsbt1->clk);
> > -	if (ret)
> > -		return ret;
> > -
> >  	dws->bus_num = pdev->id;
> >  	dws->reg_io_width = 4;
> >  	dws->max_freq = clk_get_rate(dwsbt1->clk);
> > -	if (!dws->max_freq) {
> > -		ret = -EINVAL;
> > -		goto err_disable_clk;
> > -	}
> > +	if (!dws->max_freq)
> > +		return -EINVAL;
> >  
> >  	init_func = device_get_match_data(&pdev->dev);
> >  	ret = init_func(pdev, dwsbt1);
> >  	if (ret)
> > -		goto err_disable_clk;
> > +		return ret;
> >  
> >  	pm_runtime_enable(&pdev->dev);
> >  
> >  	ret = dw_spi_add_host(&pdev->dev, dws);
> >  	if (ret) {
> >  		pm_runtime_disable(&pdev->dev);
> > -		goto err_disable_clk;
> > +		return ret;
> >  	}
> >  
> >  	platform_set_drvdata(pdev, dwsbt1);
> >  
> >  	return 0;
> > -
> > -err_disable_clk:
> > -	clk_disable_unprepare(dwsbt1->clk);
> > -
> > -	return ret;
> >  }
> >  
> >  static void dw_spi_bt1_remove(struct platform_device *pdev)
> > @@ -315,8 +304,6 @@ static void dw_spi_bt1_remove(struct platform_device *pdev)
> >  	dw_spi_remove_host(&dwsbt1->dws);
> >  
> >  	pm_runtime_disable(&pdev->dev);
> > -
> > -	clk_disable_unprepare(dwsbt1->clk);
> >  }
> >  
> >  static const struct of_device_id dw_spi_bt1_of_match[] = {
> > -- 
> > 2.34.1
> >   


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 12/25] spi: dw-mmio: Use helper function devm_clk_get_*()
  2023-08-23 14:20     ` Serge Semin
@ 2023-08-23 17:15       ` Jonathan Cameron
  0 siblings, 0 replies; 71+ messages in thread
From: Jonathan Cameron @ 2023-08-23 17:15 UTC (permalink / raw)
  To: Serge Semin
  Cc: Li Zetao, andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, florian.fainelli, heiko,
	jbrunet, joel, khilman, linus.walleij, linux-amlogic,
	linux-arm-kernel, linux-aspeed, linux-mediatek, linux-riscv,
	linux-rockchip, linux-rpi-kernel, linux-spi, martin.blumenstingl,
	matthias.bgg, neil.armstrong, olteanv, openbmc, rjui, sbranden,
	tali.perry1, tmaimon77, venture, yuenn

On Wed, 23 Aug 2023 17:20:12 +0300
Serge Semin <fancer.lancer@gmail.com> wrote:

> On Wed, Aug 23, 2023 at 09:39:25PM +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 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. Also,
> > devm_clk_get_optional() and clk_prepare_enable() can now be replaced by
> > devm_clk_get_optional_enabled(). Moreover, the lable "out_clk" no longer
> > makes sense, rename it to "out_reset".
> > 
> > Signed-off-by: Li Zetao <lizetao1@huawei.com>
> > ---
> > v1 -> v2: Return directly instead of calling reset_control_deassert()
> > before the reset control handler has been requested. And use the
> > "out_reset" label instead of "out" before calling pm_runtime_enable().  
> 
> LGTM. Thanks!
> Acked-by: Serge Semin <fancer.lancer@gmail.com>
Agreed - looks much better now.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> 
> -Serge(y)
> 
> > 
> >  drivers/spi/spi-dw-mmio.c | 31 +++++++++----------------------
> >  1 file changed, 9 insertions(+), 22 deletions(-)
> > 
> > diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
> > index 805264c9c65c..46801189a651 100644
> > --- a/drivers/spi/spi-dw-mmio.c
> > +++ b/drivers/spi/spi-dw-mmio.c
> > @@ -340,29 +340,20 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
> >  	if (dws->irq < 0)
> >  		return dws->irq; /* -ENXIO */
> >  
> > -	dwsmmio->clk = devm_clk_get(&pdev->dev, NULL);
> > +	dwsmmio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> >  	if (IS_ERR(dwsmmio->clk))
> >  		return PTR_ERR(dwsmmio->clk);
> > -	ret = clk_prepare_enable(dwsmmio->clk);
> > -	if (ret)
> > -		return ret;
> >  
> >  	/* Optional clock needed to access the registers */
> > -	dwsmmio->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> > -	if (IS_ERR(dwsmmio->pclk)) {
> > -		ret = PTR_ERR(dwsmmio->pclk);
> > -		goto out_clk;
> > -	}
> > -	ret = clk_prepare_enable(dwsmmio->pclk);
> > -	if (ret)
> > -		goto out_clk;
> > +	dwsmmio->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
> > +	if (IS_ERR(dwsmmio->pclk))
> > +		return PTR_ERR(dwsmmio->pclk);
> >  
> >  	/* find an optional reset controller */
> >  	dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi");
> > -	if (IS_ERR(dwsmmio->rstc)) {
> > -		ret = PTR_ERR(dwsmmio->rstc);
> > -		goto out_clk;
> > -	}
> > +	if (IS_ERR(dwsmmio->rstc))
> > +		return PTR_ERR(dwsmmio->rstc);
> > +
> >  	reset_control_deassert(dwsmmio->rstc);
> >  
> >  	dws->bus_num = pdev->id;
> > @@ -383,7 +374,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
> >  	if (init_func) {
> >  		ret = init_func(pdev, dwsmmio);
> >  		if (ret)
> > -			goto out;
> > +			goto out_reset;
> >  	}
> >  
> >  	pm_runtime_enable(&pdev->dev);
> > @@ -397,9 +388,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
> >  
> >  out:
> >  	pm_runtime_disable(&pdev->dev);
> > -	clk_disable_unprepare(dwsmmio->pclk);
> > -out_clk:
> > -	clk_disable_unprepare(dwsmmio->clk);
> > +out_reset:
> >  	reset_control_assert(dwsmmio->rstc);
> >  
> >  	return ret;
> > @@ -411,8 +400,6 @@ static void dw_spi_mmio_remove(struct platform_device *pdev)
> >  
> >  	dw_spi_remove_host(&dwsmmio->dws);
> >  	pm_runtime_disable(&pdev->dev);
> > -	clk_disable_unprepare(dwsmmio->pclk);
> > -	clk_disable_unprepare(dwsmmio->clk);
> >  	reset_control_assert(dwsmmio->rstc);
> >  }
> >  
> > -- 
> > 2.34.1
> >   
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 24/25] spi: spl022: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39   ` [PATCH -next v2 24/25] spi: spl022: " Li Zetao
@ 2023-08-23 17:16     ` Jonathan Cameron
  0 siblings, 0 replies; 71+ messages in thread
From: Jonathan Cameron @ 2023-08-23 17:16 UTC (permalink / raw)
  To: Li Zetao, linux-amlogic, linux-arm-kernel, linux-rpi-kernel
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, fancer.lancer,
	florian.fainelli, heiko, jbrunet, joel, khilman, linus.walleij,
	linux-aspeed, linux-mediatek, linux-riscv, linux-rockchip,
	linux-spi, martin.blumenstingl, matthias.bgg, neil.armstrong,
	olteanv, openbmc, rjui, sbranden, tali.perry1, tmaimon77,
	venture, yuenn

On Wed, 23 Aug 2023 21:39:37 +0800
Li Zetao <lizetao1@huawei.com> 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 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.
> Moreover, the label "err_no_clk_en" is no used, drop it for clean code.
> 
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
FWIW
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

If you want to follow up with a patch fixing that odd formatting (on it's own)
then that would be great.

Jonathan

> ---
> v1 -> v2: Delete the modification of odd formatting.
> 
>  drivers/spi/spi-pl022.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)
> 
> diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
> index bb347b6bb6f3..d1b6110b38fc 100644
> --- a/drivers/spi/spi-pl022.c
> +++ b/drivers/spi/spi-pl022.c
> @@ -2168,19 +2168,13 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
>  	dev_info(&adev->dev, "mapped registers from %pa to %p\n",
>  		&adev->res.start, pl022->virtbase);
>  
> -	pl022->clk = devm_clk_get(&adev->dev, NULL);
> +	pl022->clk = devm_clk_get_enabled(&adev->dev, NULL);
>  	if (IS_ERR(pl022->clk)) {
>  		status = PTR_ERR(pl022->clk);
>  		dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
>  		goto err_no_clk;
>  	}
>  
> -	status = clk_prepare_enable(pl022->clk);
> -	if (status) {
> -		dev_err(&adev->dev, "could not enable SSP/SPI bus clock\n");
> -		goto err_no_clk_en;
> -	}
> -
>  	/* Initialize transfer pump */
>  	tasklet_init(&pl022->pump_transfers, pump_transfers,
>  		     (unsigned long)pl022);
> @@ -2240,8 +2234,6 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
>  	if (platform_info->enable_dma)
>  		pl022_dma_remove(pl022);
>   err_no_irq:
> -	clk_disable_unprepare(pl022->clk);
> - err_no_clk_en:
>   err_no_clk:
>   err_no_ioremap:
>  	amba_release_regions(adev);
> @@ -2268,7 +2260,6 @@ pl022_remove(struct amba_device *adev)
>  	if (pl022->host_info->enable_dma)
>  		pl022_dma_remove(pl022);
>  
> -	clk_disable_unprepare(pl022->clk);
>  	amba_release_regions(adev);
>  	tasklet_disable(&pl022->pump_transfers);
>  }


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next 03/25] spi: aspeed: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 ` [PATCH -next 03/25] spi: aspeed: Use helper function devm_clk_get_enabled() Li Zetao
  2023-08-23  7:11   ` Chin-Ting Kuo
@ 2023-08-24  8:55   ` Cédric Le Goater
  1 sibling, 0 replies; 71+ messages in thread
From: Cédric Le Goater @ 2023-08-24  8:55 UTC (permalink / raw)
  To: Li Zetao, broonie, chin-ting_kuo, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, heiko
  Cc: linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

On 8/22/23 15:12, 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 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>


Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 11/25] spi: dw-bt1: Use helper function devm_clk_get_enabled()
  2023-08-23 17:13       ` Jonathan Cameron
@ 2023-08-25 18:01         ` Serge Semin
  0 siblings, 0 replies; 71+ messages in thread
From: Serge Semin @ 2023-08-25 18:01 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Li Zetao, andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, broonie, chin-ting_kuo,
	clg, conor.dooley, daire.mcnamara, florian.fainelli, heiko,
	jbrunet, joel, khilman, linus.walleij, linux-amlogic,
	linux-arm-kernel, linux-aspeed, linux-mediatek, linux-riscv,
	linux-rockchip, linux-rpi-kernel, linux-spi, martin.blumenstingl,
	matthias.bgg, neil.armstrong, olteanv, openbmc, rjui, sbranden,
	tali.perry1, tmaimon77, venture, yuenn

On Wed, Aug 23, 2023 at 06:13:44PM +0100, Jonathan Cameron wrote:
> On Wed, 23 Aug 2023 17:35:35 +0300
> Serge Semin <fancer.lancer@gmail.com> wrote:
> 
> > On Wed, Aug 23, 2023 at 09:39:24PM +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 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > Acked-by: Serge Semin <fancer.lancer@gmail.com>
> > > Signed-off-by: Li Zetao <lizetao1@huawei.com>  
> > 
> > Just for the record, the tags order is normally supposed to reflect a
> > patch route. Even though AFAICS it's explicitly defined for the Sob
> > tags only (see Documentation/process/submitting-patches.rst), but
> > almost all kernel developers apply that rule to all the tags. See the
> > kernel git log as the brightest example. So your Sob tag should have
> > been kept first, then either my Ab or Jonathan' Rb tags.
> 

> There have been far too many discussions about this over the years.
> There is an argument (I'm not saying I agree with it) that tags given
> on an earlier version than the one posted should be before the SoB of
> the author on basis that the SoB is occurring later (as it's on the new
> version).  That is a slightly stronger argument if there are changes
> to the patch, but then things get inconsistent between patches with minor
> changes and those without. *sigh*
> 
> So this pattern is fairly common if a bit weird in my view :)

Ah, I didn't know it was a holy-warring topic.) My judgement was based
on the vast majority of commits in the kernel git log and on my
experience in the patches review. Anyway in order not to raise it
again let's consider my comment as a general note with no obligation
towards the patch author.)

-Serge(y)

> 
> Jonathan
> 
> > 
> > -Serge(y)
> > 
> > > ---
> > > v1 -> v2: None
> > > 
> > >  drivers/spi/spi-dw-bt1.c | 23 +++++------------------
> > >  1 file changed, 5 insertions(+), 18 deletions(-)
> > > 
> > > diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c
> > > index 5e1c01822967..5391bcac305c 100644
> > > --- a/drivers/spi/spi-dw-bt1.c
> > > +++ b/drivers/spi/spi-dw-bt1.c
> > > @@ -269,43 +269,32 @@ static int dw_spi_bt1_probe(struct platform_device *pdev)
> > >  
> > >  	dws->paddr = mem->start;
> > >  
> > > -	dwsbt1->clk = devm_clk_get(&pdev->dev, NULL);
> > > +	dwsbt1->clk = devm_clk_get_enabled(&pdev->dev, NULL);
> > >  	if (IS_ERR(dwsbt1->clk))
> > >  		return PTR_ERR(dwsbt1->clk);
> > >  
> > > -	ret = clk_prepare_enable(dwsbt1->clk);
> > > -	if (ret)
> > > -		return ret;
> > > -
> > >  	dws->bus_num = pdev->id;
> > >  	dws->reg_io_width = 4;
> > >  	dws->max_freq = clk_get_rate(dwsbt1->clk);
> > > -	if (!dws->max_freq) {
> > > -		ret = -EINVAL;
> > > -		goto err_disable_clk;
> > > -	}
> > > +	if (!dws->max_freq)
> > > +		return -EINVAL;
> > >  
> > >  	init_func = device_get_match_data(&pdev->dev);
> > >  	ret = init_func(pdev, dwsbt1);
> > >  	if (ret)
> > > -		goto err_disable_clk;
> > > +		return ret;
> > >  
> > >  	pm_runtime_enable(&pdev->dev);
> > >  
> > >  	ret = dw_spi_add_host(&pdev->dev, dws);
> > >  	if (ret) {
> > >  		pm_runtime_disable(&pdev->dev);
> > > -		goto err_disable_clk;
> > > +		return ret;
> > >  	}
> > >  
> > >  	platform_set_drvdata(pdev, dwsbt1);
> > >  
> > >  	return 0;
> > > -
> > > -err_disable_clk:
> > > -	clk_disable_unprepare(dwsbt1->clk);
> > > -
> > > -	return ret;
> > >  }
> > >  
> > >  static void dw_spi_bt1_remove(struct platform_device *pdev)
> > > @@ -315,8 +304,6 @@ static void dw_spi_bt1_remove(struct platform_device *pdev)
> > >  	dw_spi_remove_host(&dwsbt1->dws);
> > >  
> > >  	pm_runtime_disable(&pdev->dev);
> > > -
> > > -	clk_disable_unprepare(dwsbt1->clk);
> > >  }
> > >  
> > >  static const struct of_device_id dw_spi_bt1_of_match[] = {
> > > -- 
> > > 2.34.1
> > >   
> 

^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers.
  2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
                     ` (25 preceding siblings ...)
  2023-08-23 14:33   ` [PATCH -next v2 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Mark Brown
@ 2023-09-12 11:37   ` Mark Brown
  26 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2023-09-12 11:37 UTC (permalink / raw)
  To: Li Zetao
  Cc: andrew, angelogioacchino.delregno, avifishman70,
	bcm-kernel-feedback-list, benjaminfair, chin-ting_kuo, clg,
	conor.dooley, daire.mcnamara, fancer.lancer, florian.fainelli,
	heiko, jbrunet, joel, khilman, linus.walleij, linux-amlogic,
	linux-arm-kernel, linux-aspeed, linux-mediatek, linux-riscv,
	linux-rockchip, linux-rpi-kernel, linux-spi, martin.blumenstingl,
	matthias.bgg, neil.armstrong, olteanv, openbmc, rjui, sbranden,
	tali.perry1, tmaimon77, venture, yuenn

On Wed, 23 Aug 2023 21:39:13 +0800, Li Zetao wrote:
> Commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared
> and enabled clocks") provides a 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 clocks explicitly when remove drivers or in the
> error handling path.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[01/25] spi: ar934x: Use helper function devm_clk_get_enabled()
        commit: 1d3ea34b7b69b2cbdcc82f1d399705c06ea5f748
[02/25] spi: armada-3700: Use helper function devm_clk_get_prepared()
        commit: f918b3a67ccbcf326a80100c17e107eece5df868
[03/25] spi: aspeed: Use helper function devm_clk_get_enabled()
        commit: 9ee8fbc05ef0b69e8cb4295b2663e044dd3868a3
[04/25] spi: ath79: Use helper function devm_clk_get_enabled()
        commit: b3422ea3913e27fd43a7a1883f358cb20599289e
[05/25] spi: spi-axi-spi-engine: Use helper function devm_clk_get_enabled()
        commit: a08199b309f833fd4221ab5ee2391c791fe26385
[06/25] spi: bcm2835: Use helper function devm_clk_get_enabled()
        commit: ba85f5fad849821bfce0ee154a72df7e2376c5eb
[07/25] spi: bcm2835aux: Use helper function devm_clk_get_enabled()
        commit: 0135a38436111366bc2fe6d3cd82a9c2cc92ce7f
[08/25] spi: spi-cadence: Use helper function devm_clk_get_enabled()
        commit: f64b1600f92e786e502cc30d31d9e3c5f2f6d682
[09/25] spi: spi-cavium-thunderx: Use helper function devm_clk_get_enabled()
        commit: c32cb76e8d5e487698f8eceb5b53df95a33fe388
[10/25] spi: davinci: Use helper function devm_clk_get_enabled()
        commit: 9dc2aa96a3533215fbed9cf1297f7aa70dae840b
[11/25] spi: dw-bt1: Use helper function devm_clk_get_enabled()
        commit: 10c3937890be2c53bfa4aaf3b22a46749857f86a
[12/25] spi: dw-mmio: Use helper function devm_clk_get_*()
        commit: 349112b6769ec0018404f87dd4632f8ea393fcaf
[13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled()
        commit: 4812bc31af2b523d4da8386a524a2cd2f6f5919b
[14/25] spi: lantiq-ssc: Use helper function devm_clk_get_enabled()
        commit: e2b9622b2a3d058e7d06827b99487b27f777b9c2
[15/25] spi: meson-spicc: Use helper function devm_clk_get_enabled()
        commit: 7ef51102d32ddc4776b2cdd583fe84afb84c823f
[16/25] spi: spi-meson-spifc: Use helper function devm_clk_get_enabled()
        commit: c45fd1217b38048332c4f5bff8bfb7c1fe6ab6dd
[17/25] spi: microchip-core-qspi: Use helper function devm_clk_get_enabled()
        commit: e922f3fff21445117e9196bd8e940ad8e15ca8c7
[18/25] spi: microchip-core: Use helper function devm_clk_get_enabled()
        commit: 605204fcb9c49818a8a7e533147061a305ac39e3
[19/25] spi: mtk-snfi: Use helper function devm_clk_get_enabled()
        commit: a06b6935f10267a300be724dca11226d6d519156
[20/25] spi: npcm-fiu: Use helper function devm_clk_get_enabled()
        commit: 82c4fadb0b957c817b5a3fcc05dc774bf32a4d07
[21/25] spi: orion: Use helper function devm_clk_get_enabled()
        commit: bbd0a66b85fe860e8b6acfb1739d15b517a4f6fb
[22/25] spi: pic32-sqi: Use helper function devm_clk_get_enabled()
        commit: 909d4cd6bc316e6cd7958832f3efe9e2fd51dcbf
[23/25] spi: pic32: Use helper function devm_clk_get_enabled()
        commit: 6b6cc88c4e5b42d2ba6af43152af6d9d96872ee8
[24/25] spi: spl022: Use helper function devm_clk_get_enabled()
        commit: 9351339c1a99cca47e6fbeef88b1ef6438d36127
[25/25] spi: rockchip: Use helper function devm_clk_get_enabled()
        commit: d6c612a34740118855cd1c8acc4339adea686266

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next v2 19/25] spi: mtk-snfi: Use helper function devm_clk_get_enabled()
  2023-08-23 13:39   ` [PATCH -next v2 19/25] spi: mtk-snfi: " Li Zetao
@ 2023-09-13  9:15     ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 71+ messages in thread
From: AngeloGioacchino Del Regno @ 2023-09-13  9:15 UTC (permalink / raw)
  To: Li Zetao
  Cc: andrew, avifishman70, bcm-kernel-feedback-list, benjaminfair,
	broonie, chin-ting_kuo, clg, conor.dooley, daire.mcnamara,
	fancer.lancer, florian.fainelli, heiko, jbrunet, joel, khilman,
	linus.walleij, linux-amlogic, linux-arm-kernel, linux-aspeed,
	linux-mediatek, linux-riscv, linux-rockchip, linux-rpi-kernel,
	linux-spi, martin.blumenstingl, matthias.bgg, neil.armstrong,
	olteanv, openbmc, rjui, sbranden, tali.perry1, tmaimon77,
	venture, yuenn, Jonathan Cameron

Il 23/08/23 15:39, Li Zetao ha scritto:
> 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 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.
> Also, devm_clk_get_optional() and clk_prepare_enable() can now be
> replaced by devm_clk_get_optional_enabled().Moreover, the two functions
> mtk_snand_enable_clk() and mtk_snand_disable_clk() no longer are used,
> drop them for clean code.
> 
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Li Zetao <lizetao1@huawei.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



^ permalink raw reply	[flat|nested] 71+ messages in thread

* Re: [PATCH -next 25/25] spi: rockchip: Use helper function devm_clk_get_enabled()
  2023-08-22 13:12 ` [PATCH -next 25/25] spi: rockchip: " Li Zetao
@ 2023-10-04 21:18   ` Heiko Stübner
  0 siblings, 0 replies; 71+ messages in thread
From: Heiko Stübner @ 2023-10-04 21:18 UTC (permalink / raw)
  To: broonie, chin-ting_kuo, clg, joel, andrew, florian.fainelli,
	rjui, sbranden, bcm-kernel-feedback-list, fancer.lancer, olteanv,
	neil.armstrong, khilman, jbrunet, martin.blumenstingl,
	conor.dooley, daire.mcnamara, matthias.bgg,
	angelogioacchino.delregno, avifishman70, tmaimon77, tali.perry1,
	venture, yuenn, benjaminfair, linus.walleij, Li Zetao
  Cc: lizetao1, linux-spi, linux-aspeed, openbmc, linux-arm-kernel,
	linux-rpi-kernel, linux-amlogic, linux-riscv, linux-mediatek,
	linux-rockchip

Am Dienstag, 22. August 2023, 15:12:37 CEST schrieb Li Zetao:
> 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 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>

Reviewed-by: Heiko Stuebner <heiko@sntech.de>



^ permalink raw reply	[flat|nested] 71+ messages in thread

end of thread, other threads:[~2023-10-04 21:19 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-22 13:12 [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Li Zetao
2023-08-22 13:12 ` [PATCH -next 01/25] spi: ar934x: Use helper function devm_clk_get_enabled() Li Zetao
2023-08-22 13:12 ` [PATCH -next 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared() Li Zetao
2023-08-22 15:55   ` Jonathan Cameron
2023-08-22 13:12 ` [PATCH -next 03/25] spi: aspeed: Use helper function devm_clk_get_enabled() Li Zetao
2023-08-23  7:11   ` Chin-Ting Kuo
2023-08-24  8:55   ` Cédric Le Goater
2023-08-22 13:12 ` [PATCH -next 04/25] spi: ath79: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 05/25] spi: spi-axi-spi-engine: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 06/25] spi: bcm2835: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 07/25] spi: bcm2835aux: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 08/25] spi: spi-cadence: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 09/25] spi: spi-cavium-thunderx: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 10/25] spi: davinci: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 11/25] spi: dw-bt1: " Li Zetao
2023-08-22 13:48   ` Serge Semin
2023-08-22 13:12 ` [PATCH -next 12/25] spi: dw-mmio: Use helper function devm_clk_get_*() Li Zetao
2023-08-22 13:46   ` Serge Semin
2023-08-22 13:12 ` [PATCH -next 13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled() Li Zetao
2023-08-22 13:12 ` [PATCH -next 14/25] spi: lantiq-ssc: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 15/25] spi: meson-spicc: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 16/25] spi: spi-meson-spifc: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 17/25] spi: microchip-core-qspi: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 18/25] spi: microchip-core: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 19/25] spi: mtk-snfi: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 20/25] spi: npcm-fiu: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 21/25] spi: orion: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 22/25] spi: pic32-sqi: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 23/25] spi: pic32: " Li Zetao
2023-08-22 13:12 ` [PATCH -next 24/25] spi: spl022: " Li Zetao
2023-08-22 16:14   ` Jonathan Cameron
2023-08-23  6:55   ` Linus Walleij
2023-08-22 13:12 ` [PATCH -next 25/25] spi: rockchip: " Li Zetao
2023-10-04 21:18   ` Heiko Stübner
2023-08-22 16:16 ` [PATCH -next 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Jonathan Cameron
2023-08-23 13:39 ` [PATCH -next v2 " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 01/25] spi: ar934x: Use helper function devm_clk_get_enabled() Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 02/25] spi: armada-3700: Use helper function devm_clk_get_prepared() Li Zetao
2023-08-23 17:10     ` Jonathan Cameron
2023-08-23 13:39   ` [PATCH -next v2 03/25] spi: aspeed: Use helper function devm_clk_get_enabled() Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 04/25] spi: ath79: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 05/25] spi: spi-axi-spi-engine: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 06/25] spi: bcm2835: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 07/25] spi: bcm2835aux: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 08/25] spi: spi-cadence: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 09/25] spi: spi-cavium-thunderx: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 10/25] spi: davinci: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 11/25] spi: dw-bt1: " Li Zetao
2023-08-23 14:35     ` Serge Semin
2023-08-23 17:13       ` Jonathan Cameron
2023-08-25 18:01         ` Serge Semin
2023-08-23 13:39   ` [PATCH -next v2 12/25] spi: dw-mmio: Use helper function devm_clk_get_*() Li Zetao
2023-08-23 14:20     ` Serge Semin
2023-08-23 17:15       ` Jonathan Cameron
2023-08-23 13:39   ` [PATCH -next v2 13/25] spi: spi-fsl-dspi: Use helper function devm_clk_get_enabled() Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 14/25] spi: lantiq-ssc: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 15/25] spi: meson-spicc: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 16/25] spi: spi-meson-spifc: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 17/25] spi: microchip-core-qspi: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 18/25] spi: microchip-core: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 19/25] spi: mtk-snfi: " Li Zetao
2023-09-13  9:15     ` AngeloGioacchino Del Regno
2023-08-23 13:39   ` [PATCH -next v2 20/25] spi: npcm-fiu: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 21/25] spi: orion: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 22/25] spi: pic32-sqi: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 23/25] spi: pic32: " Li Zetao
2023-08-23 13:39   ` [PATCH -next v2 24/25] spi: spl022: " Li Zetao
2023-08-23 17:16     ` Jonathan Cameron
2023-08-23 13:39   ` [PATCH -next v2 25/25] spi: rockchip: " Li Zetao
2023-08-23 14:33   ` [PATCH -next v2 00/25] spi: Use devm_clk_get_*() helper function to simplify the drivers Mark Brown
2023-09-12 11:37   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).