Skip to contentSkip to conversation

ASoC: atmel-classd: Improve clock and probe handling

PATCH In review [email protected] 2 participants 5 messages Nov 16

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover ASoC: atmel-classd: Improve clock and probe handling

From: bui duc phuc <[email protected]>

Hi all,

This series simplifies probe error handling and fixes the peripheral clock lifecycle management in the Atmel CLASSD driver.

Link v1 :
https://lore.kernel.org/all/[email protected]/

Change in v2:

- Rebase the patches on the latest for-next branch after checking the Sashiko review page and discovering that the patches could not be applied cleanly.
- Use dev_err_probe() for devm_regmap_init_mmio() error handling.

Compile-tested only.

Best regards,
Phuc

bui duc phuc (2):
ASoC: atmel-classd: Simplify probe error handling
ASoC: atmel-classd: Enable pclk during probe

 sound/soc/atmel/atmel-classd.c | 50 ++++++++++------------------------
 1 file changed, 15 insertions(+), 35 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 ASoC: atmel-classd: Simplify probe error handling

From: bui duc phuc <[email protected]>

Use dev_err_probe() for clock acquisition and regmap initialization to suppress probe deferral logs and simplify error handling.

Also remove the unnecessary cleanup label, as all resources are managed by devm.

---

Change in v2:
- Use dev_err_probe() for devm_regmap_init_mmio() error handling.

 sound/soc/atmel/atmel-classd.c | 37 ++++++++++++----------------------
 1 file changed, 13 insertions(+), 24 deletions(-)
sound/soc/atmel/atmel-classd.c +13 -24
index 746e6bbbf423..59490e9effab 100644
@@ -547,18 +547,14 @@ static int atmel_classd_probe(struct platform_device *pdev)
 		return dd->irq;
 
 	dd->pclk = devm_clk_get(dev, "pclk");
-	if (IS_ERR(dd->pclk)) {
-		ret = PTR_ERR(dd->pclk);
-		dev_err(dev, "failed to get peripheral clock: %d\n", ret);
-		return ret;
-	}
+	if (IS_ERR(dd->pclk))
+		return dev_err_probe(dev, PTR_ERR(dd->pclk),
+				     "failed to get peripheral clock\n");
 
 	dd->gclk = devm_clk_get(dev, "gclk");
-	if (IS_ERR(dd->gclk)) {
-		ret = PTR_ERR(dd->gclk);
-		dev_err(dev, "failed to get GCK clock: %d\n", ret);
-		return ret;
-	}
+	if (IS_ERR(dd->gclk))
+		return dev_err_probe(dev, PTR_ERR(dd->gclk),
+				     "failed to get GCK clock\n");
 
 	io_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 	if (IS_ERR(io_base))
@@ -569,11 +565,9 @@ static int atmel_classd_probe(struct platform_device *pdev)
 
 	dd->regmap = devm_regmap_init_mmio(dev, io_base,
 					&atmel_classd_regmap_config);
-	if (IS_ERR(dd->regmap)) {
-		ret = PTR_ERR(dd->regmap);
-		dev_err(dev, "failed to init register map: %d\n", ret);
-		return ret;
-	}
+	if (IS_ERR(dd->regmap))
+		return dev_err_probe(dev, PTR_ERR(dd->regmap),
+				     "failed to init register map\n");
 
 	ret = devm_snd_soc_register_component(dev,
 					&atmel_classd_cpu_dai_component,
@@ -593,29 +587,24 @@ static int atmel_classd_probe(struct platform_device *pdev)
 
 	/* register sound card */
 	card = devm_kzalloc_obj(dev, *card);
-	if (!card) {
-		ret = -ENOMEM;
-		goto unregister_codec;
-	}
+	if (!card)
+		return -ENOMEM;
 
 	snd_soc_card_set_drvdata(card, dd);
 
 	ret = atmel_classd_asoc_card_init(dev, card);
 	if (ret) {
 		dev_err(dev, "failed to init sound card\n");
-		goto unregister_codec;
+		return ret;
 	}
 
 	ret = devm_snd_soc_register_card(dev, card);
 	if (ret) {
 		dev_err(dev, "failed to register sound card: %d\n", ret);
-		goto unregister_codec;
+		return ret;
 	}
 
 	return 0;
-
-unregister_codec:
-	return ret;
 }
 
 static struct platform_driver atmel_classd_driver = {
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/2 ASoC: atmel-classd: Enable pclk during probe

In reply to [email protected]

From: bui duc phuc <[email protected]>

The peripheral clock is enabled in the startup callback but never disabled, causing its enable reference count to increase on each startup and preventing the clock from being gated.

Use devm_clk_get_enabled() to enable pclk once during probe and automatically disable it on device removal.

---
 sound/soc/atmel/atmel-classd.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
sound/soc/atmel/atmel-classd.c +3 -12
index 59490e9effab..4216a28d3371 100644
@@ -122,19 +122,10 @@ static int atmel_classd_cpu_dai_startup(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
 	struct atmel_classd *dd = snd_soc_card_get_drvdata(rtd->card);
-	int err;
 
 	regmap_write(dd->regmap, CLASSD_THR, 0x0);
 
-	err = clk_prepare_enable(dd->pclk);
-	if (err)
-		return err;
-	err = clk_prepare_enable(dd->gclk);
-	if (err) {
-		clk_disable_unprepare(dd->pclk);
-		return err;
-	}
-	return 0;
+	return clk_prepare_enable(dd->gclk);
 }
 
 /* platform */
@@ -546,10 +537,10 @@ static int atmel_classd_probe(struct platform_device *pdev)
 	if (dd->irq < 0)
 		return dd->irq;
 
-	dd->pclk = devm_clk_get(dev, "pclk");
+	dd->pclk = devm_clk_get_enabled(dev, "pclk");
 	if (IS_ERR(dd->pclk))
 		return dev_err_probe(dev, PTR_ERR(dd->pclk),
-				     "failed to get peripheral clock\n");
+				     "failed to get/enable peripheral clock\n");
 
 	dd->gclk = devm_clk_get(dev, "gclk");
 	if (IS_ERR(dd->gclk))
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v2 2/2] ASoC: atmel-classd: Enable pclk during probe

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] ASoC: atmel-classd: missing Fixes trailer for pclk leak in atmel_classd_cpu_dai_startup() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] ASoC: atmel-classd: missing Fixes trailer for pclk leak in atmel_classd_cpu_dai_startup()
--

commit 649a4204c070ced412b97a23b481af5d990b2be5
Author: bui duc phuc <[email protected]>

Quoted 10 lines

ASoC: atmel-classd: Enable pclk during probe

The peripheral clock is enabled in the startup callback but never disabled, causing its enable reference count to increase on each startup and preventing the clock from being gated.

Use devm_clk_get_enabled() to enable pclk once during probe and automatically disable it on device removal.

[Severity: Low]
Commit 1dfdbe73ccf9 ("ASoC: atmel-classd: remove codec component") merged the codec and CPU DAI callbacks, dropping clk_disable_unprepare(dd->pclk) from atmel_classd_cpu_dai_shutdown() while leaving clk_prepare_enable(dd->pclk) in atmel_classd_cpu_dai_startup(). Should this include a Fixes tag?

Fixes 1dfdbe73ccf9 ("ASoC: atmel-classd: remove codec component")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH v2 2/2] ASoC: atmel-classd: Enable pclk during probe

Quoted 8 lines

[Severity: Low]
Commit 1dfdbe73ccf9 ("ASoC: atmel-classd: remove codec component") merged the codec and CPU DAI callbacks, dropping clk_disable_unprepare(dd->pclk) from atmel_classd_cpu_dai_shutdown() while leaving clk_prepare_enable(dd->pclk) in atmel_classd_cpu_dai_startup(). Should this include a Fixes tag?

Fixes 1dfdbe73ccf9 ("ASoC: atmel-classd: remove codec component")

I agree that a Fixes tag would be appropriate here.
However, I'll leave it to the maintainer to decide whether to include it, as I'd prefer to avoid another revision just for this.