Skip to contentSkip to conversation

ASoC: atmel-classd: Improve clock and probe handling

PATCH Superseded [email protected] 1 participant 3 messages Nov 13

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

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 | 42 ++++++++++------------------------
 1 file changed, 12 insertions(+), 30 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

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

From: bui duc phuc <[email protected]>

Use dev_err_probe() for clock acquisition to suppress probe deferral logs and remove the unnecessary cleanup label, as all resources are managed by devm.

---
 sound/soc/atmel/atmel-classd.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)
sound/soc/atmel/atmel-classd.c +10 -19
index 6693bdcbb8f5..117c8e400184 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))
@@ -593,29 +589,24 @@ static int atmel_classd_probe(struct platform_device *pdev)
 
 	/* register sound card */
 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
-	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 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 117c8e400184..b6d815804e33 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