* [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling
@ 2026-08-28 9:15 phucduc.bui
2026-08-28 9:15 ` [PATCH v3 1/8] ASoC: mediatek: mt8186: Fix APLL mux setting " phucduc.bui
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Hi all,
This series fixes several error handling issues in the mt8186 ASoC driver.
The patches mainly address failures during APLL/mux, clock, MCK, GPIO,
and regcache operations. In particular, they make sure that partial
failures are handled correctly and that resources are left in a
consistent state.
The series also removes redundant probe error messages where the errors
are already reported by the called functions.
The changes were found by manual code inspection and compile-tested only.
Link v1 :
https://lore.kernel.org/all/20260820111253.97866-1-phucduc.bui@gmail.com/
link v2:
https://lore.kernel.org/all/20260821123021.41390-1-phucduc.bui@gmail.com/
Changes in v2:
- Update the cover letter.
- Drop patch 5 from v1.
- Add Fixes tags.
Changes in v3:
- Add a patch to fix clock handling in the mux disable path
- Return directly from apllx_mux_setting() instead of using a goto label
- Add GPIO rollback handling for partial failures in ADDA DL/UL.
- Add Handle failures from regcache_sync().
- Add a patch to remove redundant error messages from the probe path.
- Update the cover letter.
Best regards,
Phuc
bui duc phuc (8):
ASoC: mediatek: mt8186: Fix APLL mux setting error handling
ASoC: mediatek: mt8186: Fix clock handling in mux disable path
ASoC: mediatek: mt8186: Fix AFE clock error handling
ASoC: mediatek: mt8186: Fix APLL enable error handling
ASoC: mediatek: mt8186: Fix MCK error handling
ASoC: mediatek: mt8186: Fix gpio rollback on adda dl/ul partial
failure
ASoC: mediatek: mt8186: Handle regcache sync failure
ASoC: mediatek: mt8186: Drop redundant probe error messages
sound/soc/mediatek/mt8186/mt8186-afe-clk.c | 163 ++++++++++++--------
sound/soc/mediatek/mt8186/mt8186-afe-gpio.c | 6 +-
sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 21 ++-
3 files changed, 116 insertions(+), 74 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 1/8] ASoC: mediatek: mt8186: Fix APLL mux setting error handling
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
@ 2026-08-28 9:15 ` phucduc.bui
2026-08-28 9:15 ` [PATCH v3 2/8] ASoC: mediatek: mt8186: Fix clock handling in mux disable path phucduc.bui
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
The APLL mux setup functions return immediately when a clock operation
fails, without undoing the clock changes already made. This can leave
clocks enabled or muxes configured to an unexpected parent.
Restore the affected muxes to CLK26M and disable previously enabled
clocks on error before propagating the original error.
Fixes: 55b423d5623c ("ASoC: mediatek: mt8186: support audio clock control in platform driver")
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/mediatek/mt8186/mt8186-afe-clk.c | 50 ++++++++++++++++------
1 file changed, 38 insertions(+), 12 deletions(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
index daaca36a2d08..aa8b2eaf7b95 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
@@ -98,7 +98,7 @@ static int apll1_mux_setting(struct mtk_base_afe *afe, bool enable)
if (ret) {
dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_1], ret);
- return ret;
+ goto ERR_ENABLE_CLK_TOP_MUX_AUD_1;
}
ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1],
afe_priv->clk[CLK_TOP_APLL1_CK]);
@@ -106,7 +106,7 @@ static int apll1_mux_setting(struct mtk_base_afe *afe, bool enable)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_1],
aud_clks[CLK_TOP_APLL1_CK], ret);
- return ret;
+ goto ERR_SELECT_CLK_TOP_MUX_AUD_1;
}
/* 180.6336 / 8 = 22.5792MHz */
@@ -114,7 +114,7 @@ static int apll1_mux_setting(struct mtk_base_afe *afe, bool enable)
if (ret) {
dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_ENG1], ret);
- return ret;
+ goto ERR_ENABLE_CLK_TOP_MUX_AUD_ENG1;
}
ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1],
afe_priv->clk[CLK_TOP_APLL1_D8]);
@@ -122,7 +122,7 @@ static int apll1_mux_setting(struct mtk_base_afe *afe, bool enable)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_ENG1],
aud_clks[CLK_TOP_APLL1_D8], ret);
- return ret;
+ goto ERR_SELECT_CLK_TOP_MUX_AUD_ENG1;
}
} else {
ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1],
@@ -131,7 +131,7 @@ static int apll1_mux_setting(struct mtk_base_afe *afe, bool enable)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_ENG1],
aud_clks[CLK_CLK26M], ret);
- return ret;
+ goto EXIT;
}
clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1]);
@@ -141,12 +141,25 @@ static int apll1_mux_setting(struct mtk_base_afe *afe, bool enable)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_1],
aud_clks[CLK_CLK26M], ret);
- return ret;
+ goto EXIT;
}
clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_1]);
}
return 0;
+
+ERR_SELECT_CLK_TOP_MUX_AUD_ENG1:
+ clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1],
+ afe_priv->clk[CLK_CLK26M]);
+ clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1]);
+ERR_ENABLE_CLK_TOP_MUX_AUD_ENG1:
+ERR_SELECT_CLK_TOP_MUX_AUD_1:
+ clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1],
+ afe_priv->clk[CLK_CLK26M]);
+ clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_1]);
+ERR_ENABLE_CLK_TOP_MUX_AUD_1:
+EXIT:
+ return ret;
}
static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
@@ -159,7 +172,7 @@ static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
if (ret) {
dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_2], ret);
- return ret;
+ goto ERR_ENABLE_CLK_TOP_MUX_AUD_2;
}
ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2],
afe_priv->clk[CLK_TOP_APLL2_CK]);
@@ -167,7 +180,7 @@ static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_2],
aud_clks[CLK_TOP_APLL2_CK], ret);
- return ret;
+ goto ERR_SELECT_CLK_TOP_MUX_AUD_2;
}
/* 196.608 / 8 = 24.576MHz */
@@ -175,7 +188,7 @@ static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
if (ret) {
dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_ENG2], ret);
- return ret;
+ goto ERR_ENABLE_CLK_TOP_MUX_AUD_ENG2;
}
ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2],
afe_priv->clk[CLK_TOP_APLL2_D8]);
@@ -183,7 +196,7 @@ static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_ENG2],
aud_clks[CLK_TOP_APLL2_D8], ret);
- return ret;
+ goto ERR_SELECT_CLK_TOP_MUX_AUD_ENG2;
}
} else {
ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2],
@@ -192,7 +205,7 @@ static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_ENG2],
aud_clks[CLK_CLK26M], ret);
- return ret;
+ goto EXIT;
}
clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2]);
@@ -202,12 +215,25 @@ static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_TOP_MUX_AUD_2],
aud_clks[CLK_CLK26M], ret);
- return ret;
+ goto EXIT;
}
clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_2]);
}
return 0;
+
+ERR_SELECT_CLK_TOP_MUX_AUD_ENG2:
+ clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2],
+ afe_priv->clk[CLK_CLK26M]);
+ clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2]);
+ERR_ENABLE_CLK_TOP_MUX_AUD_ENG2:
+ERR_SELECT_CLK_TOP_MUX_AUD_2:
+ clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2],
+ afe_priv->clk[CLK_CLK26M]);
+ clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_2]);
+ERR_ENABLE_CLK_TOP_MUX_AUD_2:
+EXIT:
+ return ret;
}
int mt8186_afe_enable_cgs(struct mtk_base_afe *afe)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 2/8] ASoC: mediatek: mt8186: Fix clock handling in mux disable path
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
2026-08-28 9:15 ` [PATCH v3 1/8] ASoC: mediatek: mt8186: Fix APLL mux setting " phucduc.bui
@ 2026-08-28 9:15 ` phucduc.bui
2026-08-28 9:15 ` [PATCH v3 3/8] ASoC: mediatek: mt8186: Fix AFE clock error handling phucduc.bui
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
In the disable path of the appl*_mux_setting() functions,
clk_disable_unprepare() is called after clk_set_parent().
If clk_set_parent() fails, clk_disable_unprepare() is skipped,
potentially leaving one of the clocks enabled.
Move the clk_disable_unprepare() calls before clk_set_parent()
so that the clocks are always disabled and unprepared in the
disable path.
Fixes: 55b423d5623c ("ASoC: mediatek: mt8186: support audio clock control in platform driver")
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/mediatek/mt8186/mt8186-afe-clk.c | 70 +++++++++++-----------
1 file changed, 36 insertions(+), 34 deletions(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
index aa8b2eaf7b95..a517aa67abf6 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
@@ -125,25 +125,26 @@ static int apll1_mux_setting(struct mtk_base_afe *afe, bool enable)
goto ERR_SELECT_CLK_TOP_MUX_AUD_ENG1;
}
} else {
- ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1],
- afe_priv->clk[CLK_CLK26M]);
- if (ret) {
- dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
- __func__, aud_clks[CLK_TOP_MUX_AUD_ENG1],
- aud_clks[CLK_CLK26M], ret);
- goto EXIT;
- }
clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1]);
-
- ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1],
- afe_priv->clk[CLK_CLK26M]);
- if (ret) {
- dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
- __func__, aud_clks[CLK_TOP_MUX_AUD_1],
- aud_clks[CLK_CLK26M], ret);
- goto EXIT;
- }
clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_1]);
+
+ ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG1],
+ afe_priv->clk[CLK_CLK26M]);
+ if (ret) {
+ dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
+ __func__, aud_clks[CLK_TOP_MUX_AUD_ENG1],
+ aud_clks[CLK_CLK26M], ret);
+ goto EXIT;
+ }
+
+ ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_1],
+ afe_priv->clk[CLK_CLK26M]);
+ if (ret) {
+ dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
+ __func__, aud_clks[CLK_TOP_MUX_AUD_1],
+ aud_clks[CLK_CLK26M], ret);
+ goto EXIT;
+ }
}
return 0;
@@ -199,25 +200,26 @@ static int apll2_mux_setting(struct mtk_base_afe *afe, bool enable)
goto ERR_SELECT_CLK_TOP_MUX_AUD_ENG2;
}
} else {
- ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2],
- afe_priv->clk[CLK_CLK26M]);
- if (ret) {
- dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
- __func__, aud_clks[CLK_TOP_MUX_AUD_ENG2],
- aud_clks[CLK_CLK26M], ret);
- goto EXIT;
- }
clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2]);
-
- ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2],
- afe_priv->clk[CLK_CLK26M]);
- if (ret) {
- dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
- __func__, aud_clks[CLK_TOP_MUX_AUD_2],
- aud_clks[CLK_CLK26M], ret);
- goto EXIT;
- }
clk_disable_unprepare(afe_priv->clk[CLK_TOP_MUX_AUD_2]);
+
+ ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_ENG2],
+ afe_priv->clk[CLK_CLK26M]);
+ if (ret) {
+ dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
+ __func__, aud_clks[CLK_TOP_MUX_AUD_ENG2],
+ aud_clks[CLK_CLK26M], ret);
+ goto EXIT;
+ }
+
+ ret = clk_set_parent(afe_priv->clk[CLK_TOP_MUX_AUD_2],
+ afe_priv->clk[CLK_CLK26M]);
+ if (ret) {
+ dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
+ __func__, aud_clks[CLK_TOP_MUX_AUD_2],
+ aud_clks[CLK_CLK26M], ret);
+ goto EXIT;
+ }
}
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 3/8] ASoC: mediatek: mt8186: Fix AFE clock error handling
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
2026-08-28 9:15 ` [PATCH v3 1/8] ASoC: mediatek: mt8186: Fix APLL mux setting " phucduc.bui
2026-08-28 9:15 ` [PATCH v3 2/8] ASoC: mediatek: mt8186: Fix clock handling in mux disable path phucduc.bui
@ 2026-08-28 9:15 ` phucduc.bui
2026-08-28 9:15 ` [PATCH v3 4/8] ASoC: mediatek: mt8186: Fix APLL enable " phucduc.bui
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
The error paths in mt8186_afe_enable_clock() do not consistently
undo the clock operations performed before an error.
Fix the goto targets and cleanup order so that the audio internal
bus parent is restored to CLK26M and all previously enabled clocks
are disabled before returning the error.
Fixes: 55b423d5623c ("ASoC: mediatek: mt8186: support audio clock control in platform driver")
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/mediatek/mt8186/mt8186-afe-clk.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
index a517aa67abf6..b3e938088a7b 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
@@ -296,7 +296,7 @@ int mt8186_afe_enable_clock(struct mtk_base_afe *afe)
dev_err(afe->dev, "%s clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[CLK_MUX_AUDIO],
aud_clks[CLK_CLK26M], ret);
- goto clk_mux_audio_err;
+ goto clk_mux_audio_intbus_err;
}
ret = clk_prepare_enable(afe_priv->clk[CLK_MUX_AUDIOINTBUS]);
@@ -323,24 +323,22 @@ int mt8186_afe_enable_clock(struct mtk_base_afe *afe)
if (ret) {
dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
__func__, aud_clks[CLK_AFE], ret);
- goto clk_afe_err;
+ goto clk_mux_audio_h_parent_err;
}
return 0;
-clk_afe_err:
- clk_disable_unprepare(afe_priv->clk[CLK_AFE]);
clk_mux_audio_h_parent_err:
+ mt8186_set_audio_int_bus_parent(afe, CLK_CLK26M);
clk_mux_audio_intbus_parent_err:
- mt8186_set_audio_int_bus_parent(afe, CLK_CLK26M);
+ clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIOINTBUS]);
clk_mux_audio_intbus_err:
- clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIOINTBUS]);
+ clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIO]);
clk_mux_audio_err:
- clk_disable_unprepare(afe_priv->clk[CLK_MUX_AUDIO]);
-clk_infra_sys_audio_err:
- clk_disable_unprepare(afe_priv->clk[CLK_INFRA_SYS_AUDIO]);
+ clk_disable_unprepare(afe_priv->clk[CLK_INFRA_AUDIO_26M]);
clk_infra_audio_26m_err:
- clk_disable_unprepare(afe_priv->clk[CLK_INFRA_AUDIO_26M]);
+ clk_disable_unprepare(afe_priv->clk[CLK_INFRA_SYS_AUDIO]);
+clk_infra_sys_audio_err:
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 4/8] ASoC: mediatek: mt8186: Fix APLL enable error handling
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
` (2 preceding siblings ...)
2026-08-28 9:15 ` [PATCH v3 3/8] ASoC: mediatek: mt8186: Fix AFE clock error handling phucduc.bui
@ 2026-08-28 9:15 ` phucduc.bui
2026-08-28 9:15 ` [PATCH v3 5/8] ASoC: mediatek: mt8186: Fix MCK " phucduc.bui
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Currently, the mt8186_apll*_enable() functions call mux_setting(afe, true)
but do not check its return value to handle failures.
In addition, the cleanup paths of mt8186_apll*_enable() do not call
mux_setting(afe, false) when the enable operation fails, while the
mt8186_apll*_disable() functions do.
Add error handling for apll*_mux_setting() and call mux_setting(afe, false)
in the cleanup paths when mt8186_apll*_enable() fails.
Fixes: 55b423d5623c ("ASoC: mediatek: mt8186: support audio clock control in platform driver")
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
Changes in v3:
- Return directly from apllx_mux_setting() instead of using a goto label
sound/soc/mediatek/mt8186/mt8186-afe-clk.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
index b3e938088a7b..85fe828ca5ae 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
@@ -361,7 +361,9 @@ int mt8186_apll1_enable(struct mtk_base_afe *afe)
int ret;
/* setting for APLL */
- apll1_mux_setting(afe, true);
+ ret = apll1_mux_setting(afe, true);
+ if (ret)
+ return ret;
ret = clk_prepare_enable(afe_priv->clk[CLK_APLL22M]);
if (ret) {
@@ -386,9 +388,9 @@ int mt8186_apll1_enable(struct mtk_base_afe *afe)
return 0;
err_clk_apll1_tuner:
- clk_disable_unprepare(afe_priv->clk[CLK_APLL1_TUNER]);
+ clk_disable_unprepare(afe_priv->clk[CLK_APLL22M]);
err_clk_apll22m:
- clk_disable_unprepare(afe_priv->clk[CLK_APLL22M]);
+ apll1_mux_setting(afe, false);
return ret;
}
@@ -414,7 +416,9 @@ int mt8186_apll2_enable(struct mtk_base_afe *afe)
int ret;
/* setting for APLL */
- apll2_mux_setting(afe, true);
+ ret = apll2_mux_setting(afe, true);
+ if (ret)
+ return ret;
ret = clk_prepare_enable(afe_priv->clk[CLK_APLL24M]);
if (ret) {
@@ -439,9 +443,9 @@ int mt8186_apll2_enable(struct mtk_base_afe *afe)
return 0;
err_clk_apll2_tuner:
- clk_disable_unprepare(afe_priv->clk[CLK_APLL2_TUNER]);
+ clk_disable_unprepare(afe_priv->clk[CLK_APLL24M]);
err_clk_apll24m:
- clk_disable_unprepare(afe_priv->clk[CLK_APLL24M]);
+ apll2_mux_setting(afe, false);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 5/8] ASoC: mediatek: mt8186: Fix MCK error handling
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
` (3 preceding siblings ...)
2026-08-28 9:15 ` [PATCH v3 4/8] ASoC: mediatek: mt8186: Fix APLL enable " phucduc.bui
@ 2026-08-28 9:15 ` phucduc.bui
2026-08-28 9:15 ` [PATCH v3 6/8] ASoC: mediatek: mt8186: Fix gpio rollback on adda dl/ul partial failure phucduc.bui
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
The mt8186_mck_enable() function returns immediately when a clock
operation fails, leaving previously enabled clocks active.
Add error paths to disable previously enabled clocks before returning
the error.
Fixes: 55b423d5623c ("ASoC: mediatek: mt8186: support audio clock control in platform driver")
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/mediatek/mt8186/mt8186-afe-clk.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
index 85fe828ca5ae..6d2871254e32 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
@@ -528,7 +528,7 @@ int mt8186_mck_enable(struct mtk_base_afe *afe, int mck_id, int rate)
if (ret) {
dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n",
__func__, aud_clks[m_sel_id], ret);
- return ret;
+ goto ERR_ENABLE_MCLK;
}
ret = clk_set_parent(afe_priv->clk[m_sel_id],
afe_priv->clk[apll_clk_id]);
@@ -536,7 +536,7 @@ int mt8186_mck_enable(struct mtk_base_afe *afe, int mck_id, int rate)
dev_err(afe->dev, "%s(), clk_set_parent %s-%s fail %d\n",
__func__, aud_clks[m_sel_id],
aud_clks[apll_clk_id], ret);
- return ret;
+ goto ERR_SELECT_MCLK;
}
}
@@ -545,16 +545,25 @@ int mt8186_mck_enable(struct mtk_base_afe *afe, int mck_id, int rate)
if (ret) {
dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n",
__func__, aud_clks[div_clk_id], ret);
- return ret;
+ goto ERR_ENABLE_MCLK_DIV;
}
ret = clk_set_rate(afe_priv->clk[div_clk_id], rate);
if (ret) {
dev_err(afe->dev, "%s(), clk_set_rate %s, rate %d, fail %d\n",
__func__, aud_clks[div_clk_id], rate, ret);
- return ret;
+ goto ERR_SET_MCLK_RATE;
}
return 0;
+
+ERR_SET_MCLK_RATE:
+ clk_disable_unprepare(afe_priv->clk[div_clk_id]);
+ERR_ENABLE_MCLK_DIV:
+ERR_SELECT_MCLK:
+ if (m_sel_id >= 0)
+ clk_disable_unprepare(afe_priv->clk[m_sel_id]);
+ERR_ENABLE_MCLK:
+ return ret;
}
void mt8186_mck_disable(struct mtk_base_afe *afe, int mck_id)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 6/8] ASoC: mediatek: mt8186: Fix gpio rollback on adda dl/ul partial failure
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
` (4 preceding siblings ...)
2026-08-28 9:15 ` [PATCH v3 5/8] ASoC: mediatek: mt8186: Fix MCK " phucduc.bui
@ 2026-08-28 9:15 ` phucduc.bui
2026-08-28 9:15 ` [PATCH v3 7/8] ASoC: mediatek: mt8186: Handle regcache sync failure phucduc.bui
2026-08-28 9:15 ` [PATCH v3 8/8] ASoC: mediatek: mt8186: Drop redundant probe error messages phucduc.bui
7 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
If the second mt8186_afe_gpio_select() call in adda_dl()/adda_ul() fails,
the first one's state is left applied, leaving CLK/DAT in an inconsistent
state. Roll back the first select on failure.
Also fix a copy-pasted "CLK ON" debug message that should say "CLK OFF"
in the _dl disable path.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/mediatek/mt8186/mt8186-afe-gpio.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-gpio.c b/sound/soc/mediatek/mt8186/mt8186-afe-gpio.c
index aced8e7e920c..1cff2a63ef37 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-gpio.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-gpio.c
@@ -143,6 +143,7 @@ static int mt8186_afe_gpio_adda_dl(struct device *dev, bool enable)
ret = mt8186_afe_gpio_select(dev, MT8186_AFE_GPIO_DAT_MOSI_ON);
if (ret) {
dev_dbg(dev, "%s(), MOSI DAT ON select fail!\n", __func__);
+ mt8186_afe_gpio_select(dev, MT8186_AFE_GPIO_CLK_MOSI_OFF);
return ret;
}
} else {
@@ -154,7 +155,8 @@ static int mt8186_afe_gpio_adda_dl(struct device *dev, bool enable)
ret = mt8186_afe_gpio_select(dev, MT8186_AFE_GPIO_CLK_MOSI_OFF);
if (ret) {
- dev_dbg(dev, "%s(), MOSI CLK ON select fail!\n", __func__);
+ dev_dbg(dev, "%s(), MOSI CLK OFF select fail!\n", __func__);
+ mt8186_afe_gpio_select(dev, MT8186_AFE_GPIO_DAT_MOSI_ON);
return ret;
}
}
@@ -176,6 +178,7 @@ static int mt8186_afe_gpio_adda_ul(struct device *dev, bool enable)
ret = mt8186_afe_gpio_select(dev, MT8186_AFE_GPIO_DAT_MISO_ON);
if (ret) {
dev_dbg(dev, "%s(), MISO DAT ON select fail!\n", __func__);
+ mt8186_afe_gpio_select(dev, MT8186_AFE_GPIO_CLK_MISO_OFF);
return ret;
}
} else {
@@ -188,6 +191,7 @@ static int mt8186_afe_gpio_adda_ul(struct device *dev, bool enable)
ret = mt8186_afe_gpio_select(dev, MT8186_AFE_GPIO_CLK_MISO_OFF);
if (ret) {
dev_dbg(dev, "%s(), MISO CLK OFF select fail!\n", __func__);
+ mt8186_afe_gpio_select(dev, MT8186_AFE_GPIO_DAT_MISO_ON);
return ret;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 7/8] ASoC: mediatek: mt8186: Handle regcache sync failure
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
` (5 preceding siblings ...)
2026-08-28 9:15 ` [PATCH v3 6/8] ASoC: mediatek: mt8186: Fix gpio rollback on adda dl/ul partial failure phucduc.bui
@ 2026-08-28 9:15 ` phucduc.bui
2026-08-28 9:15 ` [PATCH v3 8/8] ASoC: mediatek: mt8186: Drop redundant probe error messages phucduc.bui
7 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Check the return value of regcache_sync() and restore cache-only mode
if synchronization fails.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
index 44a521c3a610..143386c54dd7 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
@@ -2743,7 +2743,11 @@ static int mt8186_afe_runtime_resume(struct device *dev)
goto skip_regmap;
regcache_cache_only(afe->regmap, false);
- regcache_sync(afe->regmap);
+ ret = regcache_sync(afe->regmap);
+ if (ret) {
+ regcache_cache_only(afe->regmap, true);
+ return ret;
+ }
/* enable audio sys DCM for power saving */
regmap_update_bits(afe_priv->infracfg, PERI_BUS_DCM_CTRL, BIT(29), BIT(29));
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 8/8] ASoC: mediatek: mt8186: Drop redundant probe error messages
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
` (6 preceding siblings ...)
2026-08-28 9:15 ` [PATCH v3 7/8] ASoC: mediatek: mt8186: Handle regcache sync failure phucduc.bui
@ 2026-08-28 9:15 ` phucduc.bui
7 siblings, 0 replies; 9+ messages in thread
From: phucduc.bui @ 2026-08-28 9:15 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Liam Girdwood, AngeloGioacchino Del Regno, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, linux-sound, linux-arm-kernel,
linux-mediatek, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
The errors handled here are already reported by the called functions,
either directly or deeper in the call chain. Therefore, the additional
dev_err() calls are redundant and can be removed.
platform_get_irq() returns a negative value on error and does not
return zero. Therefore, only check for a negative error code and
return it directly.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
index 143386c54dd7..4bf098657fb4 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
@@ -2852,10 +2852,8 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
/* init audio related clock */
ret = mt8186_init_clock(afe);
- if (ret) {
- dev_err(dev, "init clock error, ret %d\n", ret);
+ if (ret)
return ret;
- }
/* init memif */
afe->memif_32bit_supported = 0;
@@ -2885,15 +2883,14 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
/* request irq */
irq_id = platform_get_irq(pdev, 0);
- if (irq_id <= 0)
- return dev_err_probe(dev, irq_id < 0 ? irq_id : -ENXIO,
- "no irq found");
+ if (irq_id < 0)
+ return irq_id;
ret = devm_request_irq(dev, irq_id, mt8186_afe_irq_handler,
IRQF_TRIGGER_NONE,
"Afe_ISR_Handle", (void *)afe);
if (ret)
- return dev_err_probe(dev, ret, "could not request_irq for Afe_ISR_Handle\n");
+ return ret;
ret = enable_irq_wake(irq_id);
if (ret < 0)
@@ -2957,10 +2954,8 @@ static int mt8186_afe_pcm_dev_probe(struct platform_device *pdev)
&mt8186_afe_component,
afe->dai_drivers,
afe->num_dai_drivers);
- if (ret) {
- dev_err(dev, "err_dai_component\n");
+ if (ret)
goto err_pm_disable;
- }
ret = pm_runtime_put_sync(dev);
if (ret) {
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-08-28 9:17 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28 9:15 [PATCH v3 0/8] ASoC: mediatek: mt8186: Fix clock error handling phucduc.bui
2026-08-28 9:15 ` [PATCH v3 1/8] ASoC: mediatek: mt8186: Fix APLL mux setting " phucduc.bui
2026-08-28 9:15 ` [PATCH v3 2/8] ASoC: mediatek: mt8186: Fix clock handling in mux disable path phucduc.bui
2026-08-28 9:15 ` [PATCH v3 3/8] ASoC: mediatek: mt8186: Fix AFE clock error handling phucduc.bui
2026-08-28 9:15 ` [PATCH v3 4/8] ASoC: mediatek: mt8186: Fix APLL enable " phucduc.bui
2026-08-28 9:15 ` [PATCH v3 5/8] ASoC: mediatek: mt8186: Fix MCK " phucduc.bui
2026-08-28 9:15 ` [PATCH v3 6/8] ASoC: mediatek: mt8186: Fix gpio rollback on adda dl/ul partial failure phucduc.bui
2026-08-28 9:15 ` [PATCH v3 7/8] ASoC: mediatek: mt8186: Handle regcache sync failure phucduc.bui
2026-08-28 9:15 ` [PATCH v3 8/8] ASoC: mediatek: mt8186: Drop redundant probe error messages phucduc.bui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox