Skip to contentSkip to conversation

ASoC: fsl_sai: Address several issues in the driver

PATCH Superseded [email protected] 1 participant 6 messages Oct 30

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: fsl_sai: Address several issues in the driver

From: bui duc phuc <[email protected]>

Hi all,

I've been reviewing the FSL SAI driver and found a few issues related to error handling and clock management.

This series addresses those issues with several small fixes and cleanups.

There may be more to look at, but I wanted to send these changes first.

Compile-tested only.

Best regards,
Phuc

bui duc phuc (5):
ASoC: fsl_sai: Fix PM QoS cleanup on resume failure
ASoC: fsl_sai: Use optional clock getter for MCLKs
ASoC: fsl_sai: Remove redundant error messages
ASoC: fsl_sai: Propagate device tree property read errors
ASoC: fsl_sai: Drop redundant dataline mask AND

 sound/soc/fsl/fsl_sai.c | 40 +++++++++++++++++-----------------------
 1 file changed, 17 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/5 ASoC: fsl_sai: Fix PM QoS cleanup on resume failure

From: bui duc phuc <[email protected]>

If regcache_sync() fails during runtime resume, the CPU latency QoS request remains active even though the resume operation failed.

Switch the regmap back to cache-only mode and remove the PM QoS request before disabling the clocks, ensuring that the resources enabled earlier in the resume path are properly cleaned up.

Fixes 907e0cdebc1f ("ASoC: fsl_sai: Add pm qos cpu latency support")
---
 sound/soc/fsl/fsl_sai.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
sound/soc/fsl/fsl_sai.c +7 -2
index d232c8f53061..042885ba415e 100644
@@ -1981,7 +1981,7 @@ static int fsl_sai_runtime_resume(struct device *dev)
 
 	ret = regcache_sync(sai->regmap);
 	if (ret)
-		goto disable_rx_clk;
+		goto remove_qos;
 
 	if (sai->soc_data->mclk_with_tere && sai->mclk_direction_output)
 		regmap_update_bits(sai->regmap, FSL_SAI_TCSR(ofs),
@@ -1989,7 +1989,12 @@ static int fsl_sai_runtime_resume(struct device *dev)
 
 	return 0;
 
-disable_rx_clk:
+remove_qos:
+	regcache_cache_only(sai->regmap, true);
+
+	if (sai->soc_data->flags & PMQOS_CPU_LATENCY)
+		cpu_latency_qos_remove_request(&sai->pm_qos_req);
+
 	if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE))
 		clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[0]]);
 disable_tx_clk:
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/5 ASoC: fsl_sai: Use optional clock getter for MCLKs

In reply to [email protected]

From: bui duc phuc <[email protected]>

The current code uses devm_clk_get() and sets the clock pointer to NULL when it returns an error. However, this silently ignores errors such as -EPROBE_DEFER, allowing the driver to continue probing without the requested clock.

Use devm_clk_get_optional() to handle missing optional clocks automatically, and dev_err_probe() to properly propagate other errors, including -EPROBE_DEFER.

---
 sound/soc/fsl/fsl_sai.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
sound/soc/fsl/fsl_sai.c +4 -6
index 042885ba415e..44a34f48a0cf 100644
@@ -1589,12 +1589,10 @@ static int fsl_sai_probe(struct platform_device *pdev)
 
 	for (i = 1; i < FSL_SAI_MCLK_MAX; i++) {
 		sprintf(tmp, "mclk%d", i);
-		sai->mclk_clk[i] = devm_clk_get(dev, tmp);
-		if (IS_ERR(sai->mclk_clk[i])) {
-			dev_err(dev, "failed to get mclk%d clock: %ld\n",
-					i, PTR_ERR(sai->mclk_clk[i]));
-			sai->mclk_clk[i] = NULL;
-		}
+		sai->mclk_clk[i] = devm_clk_get_optional(dev, tmp);
+		if (IS_ERR(sai->mclk_clk[i]))
+			return dev_err_probe(dev, PTR_ERR(sai->mclk_clk[i]),
+					     "failed to get mclk%d clock\n", i);
 	}
 
 	if (sai->soc_data->mclk0_is_mclk1)
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/5 ASoC: fsl_sai: Remove redundant error messages

In reply to [email protected]

From: bui duc phuc <[email protected]>

The errors are either reported directly by these functions or already reported deeper in the call chain, so additional dev_err() and dev_warn() calls are unnecessary.

---
 sound/soc/fsl/fsl_sai.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
sound/soc/fsl/fsl_sai.c +3 -9
index 44a34f48a0cf..5532fab80be0 100644
@@ -1615,10 +1615,8 @@ static int fsl_sai_probe(struct platform_device *pdev)
 
 	/* read dataline mask for rx and tx*/
 	ret = fsl_sai_read_dlcfg(sai);
-	if (ret < 0) {
-		dev_err(dev, "failed to read dlcfg %d\n", ret);
+	if (ret < 0)
 		return ret;
-	}
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
@@ -1698,9 +1696,7 @@ static int fsl_sai_probe(struct platform_device *pdev)
 	if (ret < 0)
 		dev_warn(dev, "Error reading SAI version: %d\n", ret);
 
-	ret = fsl_sai_reset_hw(dev);
-	if (ret < 0)
-		dev_warn(dev, "Failed to reset hardware: %d\n", ret);
+	fsl_sai_reset_hw(dev);
 
 	/* Select MCLK direction */
 	if (sai->mclk_direction_output &&
@@ -1715,10 +1711,8 @@ static int fsl_sai_probe(struct platform_device *pdev)
 
 	ret = devm_request_irq(dev, irq, fsl_sai_isr, IRQF_SHARED,
 			       np->name, sai);
-	if (ret) {
-		dev_err(dev, "failed to claim irq %u\n", irq);
+	if (ret)
 		goto err_pm_get_sync;
-	}
 
 	if (of_device_is_compatible(np, "fsl,imx952-sai") &&
 	    !of_property_read_string(np, "fsl,sai-amix-mode", &str)) {
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/5 ASoC: fsl_sai: Propagate device tree property read errors

In reply to [email protected]

From: bui duc phuc <[email protected]>

Return the original error codes from of_property_read_u32_index() instead of replacing them with -EINVAL.

---
 sound/soc/fsl/fsl_sai.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/fsl/fsl_sai.c +3 -3
index 5532fab80be0..cb07e7d13132 100644
@@ -1495,15 +1495,15 @@ static int fsl_sai_read_dlcfg(struct fsl_sai *sai)
 		 */
 		ret = of_property_read_u32_index(np, propname, index++, &type);
 		if (ret)
-			return -EINVAL;
+			return ret;
 
 		ret = of_property_read_u32_index(np, propname, index++, &rx);
 		if (ret)
-			return -EINVAL;
+			return ret;
 
 		ret = of_property_read_u32_index(np, propname, index++, &tx);
 		if (ret)
-			return -EINVAL;
+			return ret;
 
 		if ((rx & ~soc_dl) || (tx & ~soc_dl)) {
 			dev_err(dev, "dataline cfg[%d] setting error, mask is 0x%x\n", i, soc_dl);
Signature · 1 line
2.43.0
#5 lore raw

PATCH 5/5 ASoC: fsl_sai: Drop redundant dataline mask AND

In reply to [email protected]

From: bui duc phuc <[email protected]>

The rx/tx masks with bits outside soc_dl are already rejected just above, so masking them with soc_dl again is no-op. Remove it.

---
 sound/soc/fsl/fsl_sai.c | 3 ---
 1 file changed, 3 deletions(-)
sound/soc/fsl/fsl_sai.c +0 -3
index cb07e7d13132..8315a0d8893b 100644
@@ -1510,9 +1510,6 @@ static int fsl_sai_read_dlcfg(struct fsl_sai *sai)
 			return -EINVAL;
 		}
 
-		rx = rx & soc_dl;
-		tx = tx & soc_dl;
-
 		cfg[i].type = type;
 		cfg[i].pins[0] = hweight8(rx);
 		cfg[i].mask[0] = rx;
Signature · 1 line
2.43.0