[PATCH 02/13] ASoC: mediatek: mt8189: Propagate APLL enable errors
phucduc.bui at gmail.com
phucduc.bui at gmail.com
Thu Sep 10 05:57:31 PDT 2026
From: bui duc phuc <phucduc.bui at gmail.com>
mt8189_apll1_enable() and mt8189_apll2_enable() currently ignore
errors from regmap_update_bits() and do not clean up resources when
clock enable operations fail.
Propagate these errors and roll back the clocks and tuner state on
errors.
Fixes: dc637ffeed6c ("ASoC: mediatek: mt8189: support audio clock control")
Signed-off-by: bui duc phuc <phucduc.bui at gmail.com>
---
sound/soc/mediatek/mt8189/mt8189-afe-clk.c | 78 ++++++++++++++++------
1 file changed, 56 insertions(+), 22 deletions(-)
diff --git a/sound/soc/mediatek/mt8189/mt8189-afe-clk.c b/sound/soc/mediatek/mt8189/mt8189-afe-clk.c
index 63e03a40dbbe..a901be97e75f 100644
--- a/sound/soc/mediatek/mt8189/mt8189-afe-clk.c
+++ b/sound/soc/mediatek/mt8189/mt8189-afe-clk.c
@@ -454,30 +454,47 @@ int mt8189_apll1_enable(struct mtk_base_afe *afe)
ret = mt8189_afe_enable_top_cg(afe, MT8189_CG_APLL1_CK);
if (ret)
- return ret;
+ goto err_apll1_ck;
ret = mt8189_afe_enable_top_cg(afe, MT8189_PDN_APLL_TUNER1);
if (ret)
- return ret;
+ goto err_apll_tuner1;
/* sel 44.1kHz:1, apll_div:7, upper bound:3 */
- regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG,
- XTAL_EN_128FS_SEL_MASK_SFT | APLL_DIV_MASK_SFT |
- UPPER_BOUND_MASK_SFT,
- (0x1 << XTAL_EN_128FS_SEL_SFT) | (7 << APLL_DIV_SFT) |
- (3 << UPPER_BOUND_SFT));
+ ret = regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG,
+ XTAL_EN_128FS_SEL_MASK_SFT | APLL_DIV_MASK_SFT |
+ UPPER_BOUND_MASK_SFT,
+ (0x1 << XTAL_EN_128FS_SEL_SFT) | (7 << APLL_DIV_SFT) |
+ (3 << UPPER_BOUND_SFT));
+ if (ret)
+ goto err_tuner;
/* apll1 freq tuner enable */
- regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG,
- FREQ_TUNER_EN_MASK_SFT,
- 0x1 << FREQ_TUNER_EN_SFT);
+ ret = regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG,
+ FREQ_TUNER_EN_MASK_SFT,
+ 0x1 << FREQ_TUNER_EN_SFT);
+ if (ret)
+ goto err_tuner;
/* audio apll1 on */
ret = mt8189_afe_enable_top_cg(afe, MT8189_AUDIO_APLL1_EN_ON);
if (ret)
- return ret;
+ goto err_apll1_en_on;
return 0;
+
+err_apll1_en_on:
+ regmap_update_bits(afe->regmap, AFE_APLL1_TUNER_CFG,
+ FREQ_TUNER_EN_MASK_SFT,
+ 0x0);
+err_tuner:
+ mt8189_afe_disable_top_cg(afe, MT8189_PDN_APLL_TUNER1);
+err_apll_tuner1:
+ mt8189_afe_disable_top_cg(afe, MT8189_CG_APLL1_CK);
+err_apll1_ck:
+ apll1_mux_setting(afe, false);
+
+ return ret;
}
void mt8189_apll1_disable(struct mtk_base_afe *afe)
@@ -506,30 +523,47 @@ int mt8189_apll2_enable(struct mtk_base_afe *afe)
ret = mt8189_afe_enable_top_cg(afe, MT8189_CG_APLL2_CK);
if (ret)
- return ret;
+ goto err_apll2_ck;
ret = mt8189_afe_enable_top_cg(afe, MT8189_PDN_APLL_TUNER2);
if (ret)
- return ret;
+ goto err_apll_tuner2;
/* sel 48kHz: 2, apll_div: 7, upper bound: 3*/
- regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG,
- XTAL_EN_128FS_SEL_MASK_SFT | APLL_DIV_MASK_SFT |
- UPPER_BOUND_MASK_SFT,
- (0x2 << XTAL_EN_128FS_SEL_SFT) | (7 << APLL_DIV_SFT) |
- (3 << UPPER_BOUND_SFT));
+ ret = regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG,
+ XTAL_EN_128FS_SEL_MASK_SFT | APLL_DIV_MASK_SFT |
+ UPPER_BOUND_MASK_SFT,
+ (0x2 << XTAL_EN_128FS_SEL_SFT) | (7 << APLL_DIV_SFT) |
+ (3 << UPPER_BOUND_SFT));
+ if (ret)
+ goto err_tuner;
/* apll2 freq tuner enable */
- regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG,
- FREQ_TUNER_EN_MASK_SFT,
- 0x1 << FREQ_TUNER_EN_SFT);
+ ret = regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG,
+ FREQ_TUNER_EN_MASK_SFT,
+ 0x1 << FREQ_TUNER_EN_SFT);
+ if (ret)
+ goto err_tuner;
/* audio apll2 on */
ret = mt8189_afe_enable_top_cg(afe, MT8189_AUDIO_APLL2_EN_ON);
if (ret)
- return ret;
+ goto err_apll2_en_on;
return 0;
+
+err_apll2_en_on:
+ regmap_update_bits(afe->regmap, AFE_APLL2_TUNER_CFG,
+ FREQ_TUNER_EN_MASK_SFT,
+ 0x0);
+err_tuner:
+ mt8189_afe_disable_top_cg(afe, MT8189_PDN_APLL_TUNER2);
+err_apll_tuner2:
+ mt8189_afe_disable_top_cg(afe, MT8189_CG_APLL2_CK);
+err_apll2_ck:
+ apll2_mux_setting(afe, false);
+
+ return ret;
}
void mt8189_apll2_disable(struct mtk_base_afe *afe)
--
2.43.0
More information about the Linux-mediatek
mailing list