[PATCH v2 2/3] ASoC: sunxi: sun4i-spdif: Resume device before kcontrol register access

From: phucduc . bui

Date: Fri May 22 2026 - 05:56:18 EST


From: bui duc phuc <phucduc.bui@xxxxxxxxx>

Accessing registers while the device is runtime-suspended
may lead to invalid hardware accesses on systems where the
APB bus clock is gated during runtime suspend.

Ensure the device is resumed before accessing registers.

Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/sunxi/sun4i-spdif.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/sound/soc/sunxi/sun4i-spdif.c b/sound/soc/sunxi/sun4i-spdif.c
index 89eccc83a130..f54eb14c9ed8 100644
--- a/sound/soc/sunxi/sun4i-spdif.c
+++ b/sound/soc/sunxi/sun4i-spdif.c
@@ -428,6 +428,11 @@ static int sun4i_spdif_get_status(struct snd_kcontrol *kcontrol,
struct sun4i_spdif_dev *host = snd_soc_dai_get_drvdata(cpu_dai);
u8 *status = ucontrol->value.iec958.status;
unsigned int reg;
+ int ret;
+
+ ret = pm_runtime_resume_and_get(cpu_dai->dev);
+ if (ret)
+ return ret;

scoped_guard(spinlock_irqsave, &host->lock) {
regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA0, &reg);
@@ -443,6 +448,8 @@ static int sun4i_spdif_get_status(struct snd_kcontrol *kcontrol,
status[5] = (reg >> 8) & 0x3;
}

+ pm_runtime_put(cpu_dai->dev);
+
return 0;
}

@@ -453,8 +460,13 @@ static int sun4i_spdif_set_status(struct snd_kcontrol *kcontrol,
struct sun4i_spdif_dev *host = snd_soc_dai_get_drvdata(cpu_dai);
u8 *status = ucontrol->value.iec958.status;
unsigned int reg;
+ int ret;
bool chg0, chg1;

+ ret = pm_runtime_resume_and_get(cpu_dai->dev);
+ if (ret)
+ return ret;
+
scoped_guard(spinlock_irqsave, &host->lock) {
reg = (u32)status[3] << 24;
reg |= (u32)status[2] << 16;
@@ -479,6 +491,8 @@ static int sun4i_spdif_set_status(struct snd_kcontrol *kcontrol,
SUN4I_SPDIF_TXCFG_NONAUDIO, reg);
}

+ pm_runtime_put(cpu_dai->dev);
+
return chg0 || chg1;
}

--
2.43.0