[RFC PATCH 2/2] ASoC: loongson: Handle clock enable errors in set_fmt
From: phucduc . bui
Date: Thu Oct 22 2026 - 04:41:45 EST
From: bui duc phuc <phucduc.bui@xxxxxxxxx>
loongson_i2s_set_fmt() treats all clock enable errors as timeouts,
warns, and returns success. This hides errors other than -ETIMEDOUT.
Preserve the existing behaviour for -ETIMEDOUT, but propagate other
errors. Also clear MASTER, MCLK_EN and MSB on the error path to
clean up the controller state, including when the clock provider
format is invalid.
Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/loongson/loongson_i2s.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/sound/soc/loongson/loongson_i2s.c b/sound/soc/loongson/loongson_i2s.c
index 109cb61c6ddf..4823b89cab8a 100644
--- a/sound/soc/loongson/loongson_i2s.c
+++ b/sound/soc/loongson/loongson_i2s.c
@@ -185,34 +185,50 @@ static int loongson_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
regmap_update_bits(i2s->regmap, LS_I2S_CTRL, I2S_CTRL_MASTER,
I2S_CTRL_MASTER);
ret = loongson_i2s_enable_bclk(i2s);
- if (ret < 0)
+ if (ret == -ETIMEDOUT)
dev_warn(dai->dev, "wait BCLK ready timeout\n");
+ else if (ret)
+ goto err;
break;
case SND_SOC_DAIFMT_BC_FP:
/* Enable MCLK */
ret = loongson_i2s_enable_mclk(i2s);
- if (ret < 0)
+ if (ret == -ETIMEDOUT)
dev_warn(dai->dev, "wait MCLK ready timeout\n");
+ else if (ret)
+ goto err;
break;
case SND_SOC_DAIFMT_BP_FP:
/* Enable MCLK */
ret = loongson_i2s_enable_mclk(i2s);
- if (ret < 0)
+ if (ret == -ETIMEDOUT)
dev_warn(dai->dev, "wait MCLK ready timeout\n");
+ else if (ret)
+ goto err;
/* Enable master mode */
regmap_update_bits(i2s->regmap, LS_I2S_CTRL, I2S_CTRL_MASTER,
I2S_CTRL_MASTER);
ret = loongson_i2s_enable_bclk(i2s);
- if (ret < 0)
+ if (ret == -ETIMEDOUT)
dev_warn(dai->dev, "wait BCLK ready timeout\n");
+ else if (ret)
+ goto err;
break;
default:
- return -EINVAL;
+ ret = -EINVAL;
+ goto err;
}
return 0;
+
+err:
+ regmap_update_bits(i2s->regmap, LS_I2S_CTRL, I2S_CTRL_MASTER, 0);
+ regmap_update_bits(i2s->regmap, LS_I2S_CTRL, I2S_CTRL_MCLK_EN, 0);
+ regmap_update_bits(i2s->regmap, LS_I2S_CTRL, I2S_CTRL_MSB, 0);
+
+ return ret;
}
static int loongson_i2s_dai_probe(struct snd_soc_dai *cpu_dai)
--
2.43.0