* [PATCH v3 0/3] ASoC: sunxi: sun4i-spdif: Cleanup and runtime PM improvements
@ 2026-06-02 11:44 phucduc.bui
2026-06-02 11:44 ` [PATCH v3 1/3] ASoC: sunxi: sun4i-spdif: Use guard() for spin locks phucduc.bui
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: phucduc.bui @ 2026-06-02 11:44 UTC (permalink / raw)
To: Chen-Yu Tsai, Liam Girdwood, Mark Brown
Cc: Jaroslav Kysela, Takashi Iwai, Jernej Skrabec, Samuel Holland,
linux-sound, linux-arm-kernel, linux-sunxi, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Hi,
This series contains a few improvements for the sun4i-spdif driver,
including guard() conversions and ensuring the device is resumed
via runtime PM before kcontrol register accesses.
Link v1:
https://lore.kernel.org/all/20260513105003.81880-1-phucduc.bui@gmail.com/
Link v2:
https://lore.kernel.org/all/20260522095401.72915-1-phucduc.bui@gmail.com/
Change in v2:
- Switched from using guard() to scoped_guard()
- Added runtime PM handling for kcontrol register accesses.
Change in v3:
- Clarify in the commit message that the resume sequence becomes the
reverse of the suspend sequence.
- Add Reported-by tag from Sashiko AI review.
Best Regards,
Phuc
bui duc phuc (3):
ASoC: sunxi: sun4i-spdif: Use guard() for spin locks
ASoC: sunxi: sun4i-spdif: Resume device before kcontrol register
access
ASoC: sunxi: sun4i-spdif: Reorder clock enable sequence
sound/soc/sunxi/sun4i-spdif.c | 76 +++++++++++++++++++----------------
1 file changed, 42 insertions(+), 34 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 1/3] ASoC: sunxi: sun4i-spdif: Use guard() for spin locks
2026-06-02 11:44 [PATCH v3 0/3] ASoC: sunxi: sun4i-spdif: Cleanup and runtime PM improvements phucduc.bui
@ 2026-06-02 11:44 ` phucduc.bui
2026-06-02 11:44 ` [PATCH v3 2/3] ASoC: sunxi: sun4i-spdif: Resume device before kcontrol register access phucduc.bui
2026-06-02 11:44 ` [PATCH v3 3/3] ASoC: sunxi: sun4i-spdif: Reorder clock enable sequence phucduc.bui
2 siblings, 0 replies; 4+ messages in thread
From: phucduc.bui @ 2026-06-02 11:44 UTC (permalink / raw)
To: Chen-Yu Tsai, Liam Girdwood, Mark Brown
Cc: Jaroslav Kysela, Takashi Iwai, Jernej Skrabec, Samuel Holland,
linux-sound, linux-arm-kernel, linux-sunxi, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
NOTE: This patch is compile-tested only.
sound/soc/sunxi/sun4i-spdif.c | 62 ++++++++++++++++-------------------
1 file changed, 28 insertions(+), 34 deletions(-)
diff --git a/sound/soc/sunxi/sun4i-spdif.c b/sound/soc/sunxi/sun4i-spdif.c
index c2ec19437cd7..89eccc83a130 100644
--- a/sound/soc/sunxi/sun4i-spdif.c
+++ b/sound/soc/sunxi/sun4i-spdif.c
@@ -427,24 +427,21 @@ static int sun4i_spdif_get_status(struct snd_kcontrol *kcontrol,
struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
struct sun4i_spdif_dev *host = snd_soc_dai_get_drvdata(cpu_dai);
u8 *status = ucontrol->value.iec958.status;
- unsigned long flags;
unsigned int reg;
- spin_lock_irqsave(&host->lock, flags);
+ scoped_guard(spinlock_irqsave, &host->lock) {
+ regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA0, ®);
- regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA0, ®);
+ status[0] = reg & 0xff;
+ status[1] = (reg >> 8) & 0xff;
+ status[2] = (reg >> 16) & 0xff;
+ status[3] = (reg >> 24) & 0xff;
- status[0] = reg & 0xff;
- status[1] = (reg >> 8) & 0xff;
- status[2] = (reg >> 16) & 0xff;
- status[3] = (reg >> 24) & 0xff;
+ regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA1, ®);
- regmap_read(host->regmap, SUN4I_SPDIF_TXCHSTA1, ®);
-
- status[4] = reg & 0xff;
- status[5] = (reg >> 8) & 0x3;
-
- spin_unlock_irqrestore(&host->lock, flags);
+ status[4] = reg & 0xff;
+ status[5] = (reg >> 8) & 0x3;
+ }
return 0;
}
@@ -455,35 +452,32 @@ static int sun4i_spdif_set_status(struct snd_kcontrol *kcontrol,
struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
struct sun4i_spdif_dev *host = snd_soc_dai_get_drvdata(cpu_dai);
u8 *status = ucontrol->value.iec958.status;
- unsigned long flags;
unsigned int reg;
bool chg0, chg1;
- spin_lock_irqsave(&host->lock, flags);
-
- reg = (u32)status[3] << 24;
- reg |= (u32)status[2] << 16;
- reg |= (u32)status[1] << 8;
- reg |= (u32)status[0];
+ scoped_guard(spinlock_irqsave, &host->lock) {
+ reg = (u32)status[3] << 24;
+ reg |= (u32)status[2] << 16;
+ reg |= (u32)status[1] << 8;
+ reg |= (u32)status[0];
- regmap_update_bits_check(host->regmap, SUN4I_SPDIF_TXCHSTA0,
- GENMASK(31,0), reg, &chg0);
+ regmap_update_bits_check(host->regmap, SUN4I_SPDIF_TXCHSTA0,
+ GENMASK(31, 0), reg, &chg0);
- reg = (u32)status[5] << 8;
- reg |= (u32)status[4];
+ reg = (u32)status[5] << 8;
+ reg |= (u32)status[4];
- regmap_update_bits_check(host->regmap, SUN4I_SPDIF_TXCHSTA1,
- GENMASK(9,0), reg, &chg1);
+ regmap_update_bits_check(host->regmap, SUN4I_SPDIF_TXCHSTA1,
+ GENMASK(9, 0), reg, &chg1);
- reg = SUN4I_SPDIF_TXCFG_CHSTMODE;
- if (status[0] & IEC958_AES0_NONAUDIO)
- reg |= SUN4I_SPDIF_TXCFG_NONAUDIO;
+ reg = SUN4I_SPDIF_TXCFG_CHSTMODE;
+ if (status[0] & IEC958_AES0_NONAUDIO)
+ reg |= SUN4I_SPDIF_TXCFG_NONAUDIO;
- regmap_update_bits(host->regmap, SUN4I_SPDIF_TXCFG,
- SUN4I_SPDIF_TXCFG_CHSTMODE |
- SUN4I_SPDIF_TXCFG_NONAUDIO, reg);
-
- spin_unlock_irqrestore(&host->lock, flags);
+ regmap_update_bits(host->regmap, SUN4I_SPDIF_TXCFG,
+ SUN4I_SPDIF_TXCFG_CHSTMODE |
+ SUN4I_SPDIF_TXCFG_NONAUDIO, reg);
+ }
return chg0 || chg1;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 2/3] ASoC: sunxi: sun4i-spdif: Resume device before kcontrol register access
2026-06-02 11:44 [PATCH v3 0/3] ASoC: sunxi: sun4i-spdif: Cleanup and runtime PM improvements phucduc.bui
2026-06-02 11:44 ` [PATCH v3 1/3] ASoC: sunxi: sun4i-spdif: Use guard() for spin locks phucduc.bui
@ 2026-06-02 11:44 ` phucduc.bui
2026-06-02 11:44 ` [PATCH v3 3/3] ASoC: sunxi: sun4i-spdif: Reorder clock enable sequence phucduc.bui
2 siblings, 0 replies; 4+ messages in thread
From: phucduc.bui @ 2026-06-02 11:44 UTC (permalink / raw)
To: Chen-Yu Tsai, Liam Girdwood, Mark Brown
Cc: Jaroslav Kysela, Takashi Iwai, Jernej Skrabec, Samuel Holland,
linux-sound, linux-arm-kernel, linux-sunxi, linux-kernel,
bui duc phuc, Sashiko AI Review
From: bui duc phuc <phucduc.bui@gmail.com>
The IEC958 status kcontrols access hardware registers directly.
Take a runtime PM reference while accessing the registers so that the
device remains active for the duration of the operation.
Reported-by: Sashiko AI Review <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260514043314.62222C2BCB7@smtp.kernel.org/
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
NOTE: This patch is compile-tested only.
Changes in v3:
- Add Reported-by tag from Sashiko AI review.
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, ®);
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v3 3/3] ASoC: sunxi: sun4i-spdif: Reorder clock enable sequence
2026-06-02 11:44 [PATCH v3 0/3] ASoC: sunxi: sun4i-spdif: Cleanup and runtime PM improvements phucduc.bui
2026-06-02 11:44 ` [PATCH v3 1/3] ASoC: sunxi: sun4i-spdif: Use guard() for spin locks phucduc.bui
2026-06-02 11:44 ` [PATCH v3 2/3] ASoC: sunxi: sun4i-spdif: Resume device before kcontrol register access phucduc.bui
@ 2026-06-02 11:44 ` phucduc.bui
2 siblings, 0 replies; 4+ messages in thread
From: phucduc.bui @ 2026-06-02 11:44 UTC (permalink / raw)
To: Chen-Yu Tsai, Liam Girdwood, Mark Brown
Cc: Jaroslav Kysela, Takashi Iwai, Jernej Skrabec, Samuel Holland,
linux-sound, linux-arm-kernel, linux-sunxi, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Reorder the runtime resume clock enable sequence to match the hardware
dependency and ensure symmetry with the suspend path.
The APB bus clock drives the register interface and must be enabled before
the functional module clock. This aligns the resume sequence to be the
exact reverse of the suspend sequence.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
NOTE: This patch is compile-tested only.
Changes in v3:
- Clarify in the commit message that the resume sequence becomes the
reverse of the suspend sequence.
sound/soc/sunxi/sun4i-spdif.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sound/soc/sunxi/sun4i-spdif.c b/sound/soc/sunxi/sun4i-spdif.c
index f54eb14c9ed8..102db1a2afbb 100644
--- a/sound/soc/sunxi/sun4i-spdif.c
+++ b/sound/soc/sunxi/sun4i-spdif.c
@@ -643,15 +643,15 @@ static int sun4i_spdif_runtime_suspend(struct device *dev)
static int sun4i_spdif_runtime_resume(struct device *dev)
{
- struct sun4i_spdif_dev *host = dev_get_drvdata(dev);
+ struct sun4i_spdif_dev *host = dev_get_drvdata(dev);
int ret;
- ret = clk_prepare_enable(host->spdif_clk);
+ ret = clk_prepare_enable(host->apb_clk);
if (ret)
return ret;
- ret = clk_prepare_enable(host->apb_clk);
+ ret = clk_prepare_enable(host->spdif_clk);
if (ret)
- clk_disable_unprepare(host->spdif_clk);
+ clk_disable_unprepare(host->apb_clk);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-02 11:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02 11:44 [PATCH v3 0/3] ASoC: sunxi: sun4i-spdif: Cleanup and runtime PM improvements phucduc.bui
2026-06-02 11:44 ` [PATCH v3 1/3] ASoC: sunxi: sun4i-spdif: Use guard() for spin locks phucduc.bui
2026-06-02 11:44 ` [PATCH v3 2/3] ASoC: sunxi: sun4i-spdif: Resume device before kcontrol register access phucduc.bui
2026-06-02 11:44 ` [PATCH v3 3/3] ASoC: sunxi: sun4i-spdif: Reorder clock enable sequence phucduc.bui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox