* [PATCH 0/5] ASoC: samsung: Use guard() for spin locks
@ 2026-04-23 12:56 phucduc.bui
2026-04-23 12:56 ` [PATCH 1/5] ASoC: samsung: i2s: " phucduc.bui
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: phucduc.bui @ 2026-04-23 12:56 UTC (permalink / raw)
To: Mark Brown
Cc: Martin Povišer, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
asahi, linux-sound, linux-kernel, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Hi all,
This series simplifies spinlock management across several Samsung ASoC
drivers by adopting the guard() macro.
All patches are strictly code refactoring with no functional changes
intended.
Best regards,
Phuc
bui duc phuc (5):
ASoC: samsung: i2s: Use guard() for spin locks
ASoC: samsung: idma: Use guard() for spin locks
ASoC: samsung: odroid: Use guard() for spin locks
ASoC: samsung: pcm: Use guard() for spin locks
ASoC: samsung: spdif: Use guard() for spin locks
sound/soc/samsung/i2s.c | 118 ++++++++++++++++---------------------
sound/soc/samsung/idma.c | 26 +++-----
sound/soc/samsung/odroid.c | 21 ++-----
sound/soc/samsung/pcm.c | 99 +++++++++++++------------------
sound/soc/samsung/spdif.c | 25 +++-----
5 files changed, 113 insertions(+), 176 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] ASoC: samsung: i2s: Use guard() for spin locks
2026-04-23 12:56 [PATCH 0/5] ASoC: samsung: Use guard() for spin locks phucduc.bui
@ 2026-04-23 12:56 ` phucduc.bui
2026-04-23 12:56 ` [PATCH 2/5] ASoC: samsung: idma: " phucduc.bui
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: phucduc.bui @ 2026-04-23 12:56 UTC (permalink / raw)
To: Mark Brown
Cc: Martin Povišer, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
asahi, linux-sound, 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>
---
sound/soc/samsung/i2s.c | 118 +++++++++++++++++-----------------------
1 file changed, 50 insertions(+), 68 deletions(-)
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index 140907a41a70..f80f697a5d55 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -510,14 +510,13 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int rfs,
unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off;
unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off;
u32 mod, mask, val = 0;
- unsigned long flags;
int ret = 0;
pm_runtime_get_sync(dai->dev);
- spin_lock_irqsave(&priv->lock, flags);
- mod = readl(priv->addr + I2SMOD);
- spin_unlock_irqrestore(&priv->lock, flags);
+ scoped_guard(spinlock_irqsave, &priv->lock)
+ mod = readl(priv->addr + I2SMOD);
+
switch (clk_id) {
case SAMSUNG_I2S_OPCLK:
@@ -612,11 +611,11 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int rfs,
goto err;
}
- spin_lock_irqsave(&priv->lock, flags);
- mod = readl(priv->addr + I2SMOD);
- mod = (mod & ~mask) | val;
- writel(mod, priv->addr + I2SMOD);
- spin_unlock_irqrestore(&priv->lock, flags);
+ scoped_guard(spinlock_irqsave, &priv->lock) {
+ mod = readl(priv->addr + I2SMOD);
+ mod = (mod & ~mask) | val;
+ writel(mod, priv->addr + I2SMOD);
+ }
done:
pm_runtime_put(dai->dev);
@@ -729,7 +728,6 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
struct i2s_dai *i2s = to_info(dai);
u32 mod, mask = 0, val = 0;
struct clk *rclksrc;
- unsigned long flags;
WARN_ON(!pm_runtime_active(dai->dev));
@@ -801,11 +799,11 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}
- spin_lock_irqsave(&priv->lock, flags);
- mod = readl(priv->addr + I2SMOD);
- mod = (mod & ~mask) | val;
- writel(mod, priv->addr + I2SMOD);
- spin_unlock_irqrestore(&priv->lock, flags);
+ scoped_guard(spinlock_irqsave, &priv->lock) {
+ mod = readl(priv->addr + I2SMOD);
+ mod = (mod & ~mask) | val;
+ writel(mod, priv->addr + I2SMOD);
+ }
snd_soc_dai_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
@@ -825,11 +823,10 @@ static int i2s_startup(struct snd_pcm_substream *substream,
struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai);
struct i2s_dai *i2s = to_info(dai);
struct i2s_dai *other = get_other_dai(i2s);
- unsigned long flags;
pm_runtime_get_sync(dai->dev);
- spin_lock_irqsave(&priv->pcm_lock, flags);
+ guard(spinlock_irqsave)(&priv->pcm_lock);
i2s->mode |= DAI_OPENED;
@@ -841,8 +838,6 @@ static int i2s_startup(struct snd_pcm_substream *substream,
if (!any_active(i2s) && (priv->quirks & QUIRK_NEED_RSTCLR))
writel(CON_RSTCLR, i2s->priv->addr + I2SCON);
- spin_unlock_irqrestore(&priv->pcm_lock, flags);
-
return 0;
}
@@ -852,21 +847,18 @@ static void i2s_shutdown(struct snd_pcm_substream *substream,
struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai);
struct i2s_dai *i2s = to_info(dai);
struct i2s_dai *other = get_other_dai(i2s);
- unsigned long flags;
-
- spin_lock_irqsave(&priv->pcm_lock, flags);
- i2s->mode &= ~DAI_OPENED;
- i2s->mode &= ~DAI_MANAGER;
+ scoped_guard(spinlock_irqsave, &priv->pcm_lock) {
+ i2s->mode &= ~DAI_OPENED;
+ i2s->mode &= ~DAI_MANAGER;
- if (is_opened(other))
- other->mode |= DAI_MANAGER;
+ if (is_opened(other))
+ other->mode |= DAI_MANAGER;
- /* Reset any constraint on RFS and BFS */
- i2s->rfs = 0;
- i2s->bfs = 0;
-
- spin_unlock_irqrestore(&priv->pcm_lock, flags);
+ /* Reset any constraint on RFS and BFS */
+ i2s->rfs = 0;
+ i2s->bfs = 0;
+ }
pm_runtime_put(dai->dev);
}
@@ -939,7 +931,6 @@ static int i2s_trigger(struct snd_pcm_substream *substream,
int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct i2s_dai *i2s = to_info(snd_soc_rtd_to_cpu(rtd, 0));
- unsigned long flags;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
@@ -950,37 +941,31 @@ static int i2s_trigger(struct snd_pcm_substream *substream,
if (priv->fixup_early)
priv->fixup_early(substream, dai);
- spin_lock_irqsave(&priv->lock, flags);
+ scoped_guard(spinlock_irqsave, &priv->lock) {
+ if (config_setup(i2s))
+ return -EINVAL;
- if (config_setup(i2s)) {
- spin_unlock_irqrestore(&priv->lock, flags);
- return -EINVAL;
- }
+ if (priv->fixup_late)
+ priv->fixup_late(substream, dai);
- if (priv->fixup_late)
- priv->fixup_late(substream, dai);
-
- if (capture)
- i2s_rxctrl(i2s, 1);
- else
- i2s_txctrl(i2s, 1);
-
- spin_unlock_irqrestore(&priv->lock, flags);
+ if (capture)
+ i2s_rxctrl(i2s, 1);
+ else
+ i2s_txctrl(i2s, 1);
+ }
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- spin_lock_irqsave(&priv->lock, flags);
-
- if (capture) {
- i2s_rxctrl(i2s, 0);
- i2s_fifo(i2s, FIC_RXFLUSH);
- } else {
- i2s_txctrl(i2s, 0);
- i2s_fifo(i2s, FIC_TXFLUSH);
+ scoped_guard(spinlock_irqsave, &priv->lock) {
+ if (capture) {
+ i2s_rxctrl(i2s, 0);
+ i2s_fifo(i2s, FIC_RXFLUSH);
+ } else {
+ i2s_txctrl(i2s, 0);
+ i2s_fifo(i2s, FIC_TXFLUSH);
+ }
}
-
- spin_unlock_irqrestore(&priv->lock, flags);
pm_runtime_put(dai->dev);
break;
}
@@ -1056,7 +1041,6 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai);
struct i2s_dai *i2s = to_info(dai);
struct i2s_dai *other = get_other_dai(i2s);
- unsigned long flags;
pm_runtime_get_sync(dai->dev);
@@ -1079,13 +1063,13 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
i2s->rfs = 0;
i2s->bfs = 0;
- spin_lock_irqsave(&priv->lock, flags);
- i2s_txctrl(i2s, 0);
- i2s_rxctrl(i2s, 0);
- i2s_fifo(i2s, FIC_TXFLUSH);
- i2s_fifo(other, FIC_TXFLUSH);
- i2s_fifo(i2s, FIC_RXFLUSH);
- spin_unlock_irqrestore(&priv->lock, flags);
+ scoped_guard(spinlock_irqsave, &priv->lock) {
+ i2s_txctrl(i2s, 0);
+ i2s_rxctrl(i2s, 0);
+ i2s_fifo(i2s, FIC_TXFLUSH);
+ i2s_fifo(other, FIC_TXFLUSH);
+ i2s_fifo(i2s, FIC_RXFLUSH);
+ }
/* Gate CDCLK by default */
if (!is_opened(other))
@@ -1100,15 +1084,13 @@ static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
{
struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai);
struct i2s_dai *i2s = to_info(dai);
- unsigned long flags;
pm_runtime_get_sync(dai->dev);
if (!is_secondary(i2s)) {
if (priv->quirks & QUIRK_NEED_RSTCLR) {
- spin_lock_irqsave(&priv->lock, flags);
- writel(0, priv->addr + I2SCON);
- spin_unlock_irqrestore(&priv->lock, flags);
+ scoped_guard(spinlock_irqsave, &priv->lock)
+ writel(0, priv->addr + I2SCON);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/5] ASoC: samsung: idma: Use guard() for spin locks
2026-04-23 12:56 [PATCH 0/5] ASoC: samsung: Use guard() for spin locks phucduc.bui
2026-04-23 12:56 ` [PATCH 1/5] ASoC: samsung: i2s: " phucduc.bui
@ 2026-04-23 12:56 ` phucduc.bui
2026-04-23 12:56 ` [PATCH 3/5] ASoC: samsung: odroid: " phucduc.bui
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: phucduc.bui @ 2026-04-23 12:56 UTC (permalink / raw)
To: Mark Brown
Cc: Martin Povišer, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
asahi, linux-sound, 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>
---
sound/soc/samsung/idma.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/sound/soc/samsung/idma.c b/sound/soc/samsung/idma.c
index cb455ddce253..d362136e1069 100644
--- a/sound/soc/samsung/idma.c
+++ b/sound/soc/samsung/idma.c
@@ -67,9 +67,8 @@ static int idma_enqueue(struct snd_pcm_substream *substream)
struct idma_ctrl *prtd = substream->runtime->private_data;
u32 val;
- spin_lock(&prtd->lock);
- prtd->token = (void *) substream;
- spin_unlock(&prtd->lock);
+ scoped_guard(spinlock, &prtd->lock)
+ prtd->token = (void *) substream;
/* Internal DMA Level0 Interrupt Address */
val = idma.lp_tx_addr + prtd->periodsz;
@@ -101,16 +100,15 @@ static void idma_setcallbk(struct snd_pcm_substream *substream,
{
struct idma_ctrl *prtd = substream->runtime->private_data;
- spin_lock(&prtd->lock);
+ guard(spinlock)(&prtd->lock);
prtd->cb = cb;
- spin_unlock(&prtd->lock);
}
static void idma_control(int op)
{
u32 val = readl(idma.regs + I2SAHB);
- spin_lock(&idma.lock);
+ guard(spinlock)(&idma.lock);
switch (op) {
case LPAM_DMA_START:
@@ -120,12 +118,10 @@ static void idma_control(int op)
val &= ~(AHB_INTENLVL0 | AHB_DMAEN);
break;
default:
- spin_unlock(&idma.lock);
return;
}
writel(val, idma.regs + I2SAHB);
- spin_unlock(&idma.lock);
}
static void idma_done(void *id, int bytes_xfer)
@@ -192,7 +188,7 @@ static int idma_trigger(struct snd_soc_component *component,
struct idma_ctrl *prtd = substream->runtime->private_data;
int ret = 0;
- spin_lock(&prtd->lock);
+ guard(spinlock)(&prtd->lock);
switch (cmd) {
case SNDRV_PCM_TRIGGER_RESUME:
@@ -214,8 +210,6 @@ static int idma_trigger(struct snd_soc_component *component,
break;
}
- spin_unlock(&prtd->lock);
-
return ret;
}
@@ -228,12 +222,10 @@ idma_pointer(struct snd_soc_component *component,
dma_addr_t src;
unsigned long res;
- spin_lock(&prtd->lock);
-
- idma_getpos(&src);
- res = src - prtd->start;
-
- spin_unlock(&prtd->lock);
+ scoped_guard(spinlock, &prtd->lock) {
+ idma_getpos(&src);
+ res = src - prtd->start;
+ }
return bytes_to_frames(substream->runtime, res);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/5] ASoC: samsung: odroid: Use guard() for spin locks
2026-04-23 12:56 [PATCH 0/5] ASoC: samsung: Use guard() for spin locks phucduc.bui
2026-04-23 12:56 ` [PATCH 1/5] ASoC: samsung: i2s: " phucduc.bui
2026-04-23 12:56 ` [PATCH 2/5] ASoC: samsung: idma: " phucduc.bui
@ 2026-04-23 12:56 ` phucduc.bui
2026-04-23 12:56 ` [PATCH 4/5] ASoC: samsung: pcm: " phucduc.bui
2026-04-23 12:56 ` [PATCH 5/5] ASoC: samsung: spdif: " phucduc.bui
4 siblings, 0 replies; 6+ messages in thread
From: phucduc.bui @ 2026-04-23 12:56 UTC (permalink / raw)
To: Mark Brown
Cc: Martin Povišer, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
asahi, linux-sound, 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>
---
sound/soc/samsung/odroid.c | 21 ++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)
diff --git a/sound/soc/samsung/odroid.c b/sound/soc/samsung/odroid.c
index ab3398f39f4a..5c5ecbea5331 100644
--- a/sound/soc/samsung/odroid.c
+++ b/sound/soc/samsung/odroid.c
@@ -36,15 +36,12 @@ static int odroid_card_fe_hw_params(struct snd_pcm_substream *substream,
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct odroid_priv *priv = snd_soc_card_get_drvdata(rtd->card);
- unsigned long flags;
- int ret = 0;
- spin_lock_irqsave(&priv->lock, flags);
+ guard(spinlock_irqsave)(&priv->lock);
if (priv->be_active && priv->be_sample_rate != params_rate(params))
- ret = -EINVAL;
- spin_unlock_irqrestore(&priv->lock, flags);
+ return -EINVAL;
- return ret;
+ return 0;
}
static const struct snd_soc_ops odroid_card_fe_ops = {
@@ -58,7 +55,6 @@ static int odroid_card_be_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct odroid_priv *priv = snd_soc_card_get_drvdata(rtd->card);
unsigned int pll_freq, rclk_freq, rfs;
- unsigned long flags;
int ret;
switch (params_rate(params)) {
@@ -105,10 +101,8 @@ static int odroid_card_be_hw_params(struct snd_pcm_substream *substream,
return ret;
}
- spin_lock_irqsave(&priv->lock, flags);
- priv->be_sample_rate = params_rate(params);
- spin_unlock_irqrestore(&priv->lock, flags);
-
+ scoped_guard(spinlock_irqsave, &priv->lock)
+ priv->be_sample_rate = params_rate(params);
return 0;
}
@@ -116,9 +110,8 @@ static int odroid_card_be_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct odroid_priv *priv = snd_soc_card_get_drvdata(rtd->card);
- unsigned long flags;
- spin_lock_irqsave(&priv->lock, flags);
+ guard(spinlock_irqsave)(&priv->lock);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
@@ -134,8 +127,6 @@ static int odroid_card_be_trigger(struct snd_pcm_substream *substream, int cmd)
break;
}
- spin_unlock_irqrestore(&priv->lock, flags);
-
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/5] ASoC: samsung: pcm: Use guard() for spin locks
2026-04-23 12:56 [PATCH 0/5] ASoC: samsung: Use guard() for spin locks phucduc.bui
` (2 preceding siblings ...)
2026-04-23 12:56 ` [PATCH 3/5] ASoC: samsung: odroid: " phucduc.bui
@ 2026-04-23 12:56 ` phucduc.bui
2026-04-23 12:56 ` [PATCH 5/5] ASoC: samsung: spdif: " phucduc.bui
4 siblings, 0 replies; 6+ messages in thread
From: phucduc.bui @ 2026-04-23 12:56 UTC (permalink / raw)
To: Mark Brown
Cc: Martin Povišer, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
asahi, linux-sound, 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>
---
sound/soc/samsung/pcm.c | 99 +++++++++++++++++------------------------
1 file changed, 40 insertions(+), 59 deletions(-)
diff --git a/sound/soc/samsung/pcm.c b/sound/soc/samsung/pcm.c
index a03ba9374c2e..309f024bf2a4 100644
--- a/sound/soc/samsung/pcm.c
+++ b/sound/soc/samsung/pcm.c
@@ -218,7 +218,6 @@ static int s3c_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct s3c_pcm_info *pcm = snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0));
- unsigned long flags;
dev_dbg(pcm->dev, "Entered %s\n", __func__);
@@ -226,27 +225,23 @@ static int s3c_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- spin_lock_irqsave(&pcm->lock, flags);
-
- if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
- s3c_pcm_snd_rxctrl(pcm, 1);
- else
- s3c_pcm_snd_txctrl(pcm, 1);
-
- spin_unlock_irqrestore(&pcm->lock, flags);
+ scoped_guard(spinlock_irqsave, &pcm->lock) {
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ s3c_pcm_snd_rxctrl(pcm, 1);
+ else
+ s3c_pcm_snd_txctrl(pcm, 1);
+ }
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- spin_lock_irqsave(&pcm->lock, flags);
-
- if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
- s3c_pcm_snd_rxctrl(pcm, 0);
- else
- s3c_pcm_snd_txctrl(pcm, 0);
-
- spin_unlock_irqrestore(&pcm->lock, flags);
+ scoped_guard(spinlock_irqsave, &pcm->lock) {
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ s3c_pcm_snd_rxctrl(pcm, 0);
+ else
+ s3c_pcm_snd_txctrl(pcm, 0);
+ }
break;
default:
@@ -265,7 +260,6 @@ static int s3c_pcm_hw_params(struct snd_pcm_substream *substream,
void __iomem *regs = pcm->regs;
struct clk *clk;
int sclk_div, sync_div;
- unsigned long flags;
u32 clkctl;
dev_dbg(pcm->dev, "Entered %s\n", __func__);
@@ -278,36 +272,33 @@ static int s3c_pcm_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}
- spin_lock_irqsave(&pcm->lock, flags);
-
- /* Get hold of the PCMSOURCE_CLK */
- clkctl = readl(regs + S3C_PCM_CLKCTL);
- if (clkctl & S3C_PCM_CLKCTL_SERCLKSEL_PCLK)
- clk = pcm->pclk;
- else
- clk = pcm->cclk;
-
- /* Set the SCLK divider */
- sclk_div = clk_get_rate(clk) / pcm->sclk_per_fs /
- params_rate(params) / 2 - 1;
-
- clkctl &= ~(S3C_PCM_CLKCTL_SCLKDIV_MASK
- << S3C_PCM_CLKCTL_SCLKDIV_SHIFT);
- clkctl |= ((sclk_div & S3C_PCM_CLKCTL_SCLKDIV_MASK)
- << S3C_PCM_CLKCTL_SCLKDIV_SHIFT);
+ scoped_guard(spinlock_irqsave, &pcm->lock) {
+ /* Get hold of the PCMSOURCE_CLK */
+ clkctl = readl(regs + S3C_PCM_CLKCTL);
+ if (clkctl & S3C_PCM_CLKCTL_SERCLKSEL_PCLK)
+ clk = pcm->pclk;
+ else
+ clk = pcm->cclk;
- /* Set the SYNC divider */
- sync_div = pcm->sclk_per_fs - 1;
+ /* Set the SCLK divider */
+ sclk_div = clk_get_rate(clk) / pcm->sclk_per_fs /
+ params_rate(params) / 2 - 1;
- clkctl &= ~(S3C_PCM_CLKCTL_SYNCDIV_MASK
- << S3C_PCM_CLKCTL_SYNCDIV_SHIFT);
- clkctl |= ((sync_div & S3C_PCM_CLKCTL_SYNCDIV_MASK)
- << S3C_PCM_CLKCTL_SYNCDIV_SHIFT);
+ clkctl &= ~(S3C_PCM_CLKCTL_SCLKDIV_MASK
+ << S3C_PCM_CLKCTL_SCLKDIV_SHIFT);
+ clkctl |= ((sclk_div & S3C_PCM_CLKCTL_SCLKDIV_MASK)
+ << S3C_PCM_CLKCTL_SCLKDIV_SHIFT);
- writel(clkctl, regs + S3C_PCM_CLKCTL);
+ /* Set the SYNC divider */
+ sync_div = pcm->sclk_per_fs - 1;
- spin_unlock_irqrestore(&pcm->lock, flags);
+ clkctl &= ~(S3C_PCM_CLKCTL_SYNCDIV_MASK
+ << S3C_PCM_CLKCTL_SYNCDIV_SHIFT);
+ clkctl |= ((sync_div & S3C_PCM_CLKCTL_SYNCDIV_MASK)
+ << S3C_PCM_CLKCTL_SYNCDIV_SHIFT);
+ writel(clkctl, regs + S3C_PCM_CLKCTL);
+ }
dev_dbg(pcm->dev, "PCMSOURCE_CLK-%lu SCLK=%ufs SCLK_DIV=%d SYNC_DIV=%d\n",
clk_get_rate(clk), pcm->sclk_per_fs,
sclk_div, sync_div);
@@ -320,13 +311,11 @@ static int s3c_pcm_set_fmt(struct snd_soc_dai *cpu_dai,
{
struct s3c_pcm_info *pcm = snd_soc_dai_get_drvdata(cpu_dai);
void __iomem *regs = pcm->regs;
- unsigned long flags;
- int ret = 0;
u32 ctl;
dev_dbg(pcm->dev, "Entered %s\n", __func__);
- spin_lock_irqsave(&pcm->lock, flags);
+ guard(spinlock_irqsave)(&pcm->lock);
ctl = readl(regs + S3C_PCM_CTL);
@@ -336,8 +325,7 @@ static int s3c_pcm_set_fmt(struct snd_soc_dai *cpu_dai,
break;
default:
dev_err(pcm->dev, "Unsupported clock inversion!\n");
- ret = -EINVAL;
- goto exit;
+ return -EINVAL;
}
switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
@@ -346,8 +334,7 @@ static int s3c_pcm_set_fmt(struct snd_soc_dai *cpu_dai,
break;
default:
dev_err(pcm->dev, "Unsupported master/slave format!\n");
- ret = -EINVAL;
- goto exit;
+ return -EINVAL;
}
switch (fmt & SND_SOC_DAIFMT_CLOCK_MASK) {
@@ -359,8 +346,7 @@ static int s3c_pcm_set_fmt(struct snd_soc_dai *cpu_dai,
break;
default:
dev_err(pcm->dev, "Invalid Clock gating request!\n");
- ret = -EINVAL;
- goto exit;
+ return -EINVAL;
}
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
@@ -374,16 +360,11 @@ static int s3c_pcm_set_fmt(struct snd_soc_dai *cpu_dai,
break;
default:
dev_err(pcm->dev, "Unsupported data format!\n");
- ret = -EINVAL;
- goto exit;
+ return -EINVAL;
}
writel(ctl, regs + S3C_PCM_CTL);
-
-exit:
- spin_unlock_irqrestore(&pcm->lock, flags);
-
- return ret;
+ return 0;
}
static int s3c_pcm_set_clkdiv(struct snd_soc_dai *cpu_dai,
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/5] ASoC: samsung: spdif: Use guard() for spin locks
2026-04-23 12:56 [PATCH 0/5] ASoC: samsung: Use guard() for spin locks phucduc.bui
` (3 preceding siblings ...)
2026-04-23 12:56 ` [PATCH 4/5] ASoC: samsung: pcm: " phucduc.bui
@ 2026-04-23 12:56 ` phucduc.bui
4 siblings, 0 replies; 6+ messages in thread
From: phucduc.bui @ 2026-04-23 12:56 UTC (permalink / raw)
To: Mark Brown
Cc: Martin Povišer, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
asahi, linux-sound, 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>
---
sound/soc/samsung/spdif.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/sound/soc/samsung/spdif.c b/sound/soc/samsung/spdif.c
index fb30f6b637a0..7fc46d55c522 100644
--- a/sound/soc/samsung/spdif.c
+++ b/sound/soc/samsung/spdif.c
@@ -143,7 +143,6 @@ static int spdif_trigger(struct snd_pcm_substream *substream, int cmd,
{
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
struct samsung_spdif_info *spdif = to_info(snd_soc_rtd_to_cpu(rtd, 0));
- unsigned long flags;
dev_dbg(spdif->dev, "Entered %s\n", __func__);
@@ -151,16 +150,14 @@ static int spdif_trigger(struct snd_pcm_substream *substream, int cmd,
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- spin_lock_irqsave(&spdif->lock, flags);
- spdif_snd_txctrl(spdif, 1);
- spin_unlock_irqrestore(&spdif->lock, flags);
+ scoped_guard(spinlock_irqsave, &spdif->lock)
+ spdif_snd_txctrl(spdif, 1);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- spin_lock_irqsave(&spdif->lock, flags);
- spdif_snd_txctrl(spdif, 0);
- spin_unlock_irqrestore(&spdif->lock, flags);
+ scoped_guard(spinlock_irqsave, &spdif->lock)
+ spdif_snd_txctrl(spdif, 0);
break;
default:
return -EINVAL;
@@ -182,7 +179,6 @@ static int spdif_hw_params(struct snd_pcm_substream *substream,
void __iomem *regs = spdif->regs;
struct snd_dmaengine_dai_dma_data *dma_data;
u32 con, clkcon, cstas;
- unsigned long flags;
int i, ratio;
dev_dbg(spdif->dev, "Entered %s\n", __func__);
@@ -196,7 +192,7 @@ static int spdif_hw_params(struct snd_pcm_substream *substream,
snd_soc_dai_set_dma_data(snd_soc_rtd_to_cpu(rtd, 0), substream, dma_data);
- spin_lock_irqsave(&spdif->lock, flags);
+ guard(spinlock_irqsave)(&spdif->lock);
con = readl(regs + CON) & CON_MASK;
cstas = readl(regs + CSTAS) & CSTAS_MASK;
@@ -214,7 +210,7 @@ static int spdif_hw_params(struct snd_pcm_substream *substream,
break;
default:
dev_err(spdif->dev, "Unsupported data size.\n");
- goto err;
+ return -EINVAL;
}
ratio = spdif->clk_rate / params_rate(params);
@@ -224,7 +220,7 @@ static int spdif_hw_params(struct snd_pcm_substream *substream,
if (i == ARRAY_SIZE(spdif_sysclk_ratios)) {
dev_err(spdif->dev, "Invalid clock ratio %ld/%d\n",
spdif->clk_rate, params_rate(params));
- goto err;
+ return -EINVAL;
}
con &= ~CON_MCLKDIV_MASK;
@@ -257,7 +253,7 @@ static int spdif_hw_params(struct snd_pcm_substream *substream,
default:
dev_err(spdif->dev, "Invalid sampling rate %d\n",
params_rate(params));
- goto err;
+ return -EINVAL;
}
cstas &= ~CSTAS_CATEGORY_MASK;
@@ -268,12 +264,7 @@ static int spdif_hw_params(struct snd_pcm_substream *substream,
writel(cstas, regs + CSTAS);
writel(clkcon, regs + CLKCON);
- spin_unlock_irqrestore(&spdif->lock, flags);
-
return 0;
-err:
- spin_unlock_irqrestore(&spdif->lock, flags);
- return -EINVAL;
}
static void spdif_shutdown(struct snd_pcm_substream *substream,
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-23 12:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23 12:56 [PATCH 0/5] ASoC: samsung: Use guard() for spin locks phucduc.bui
2026-04-23 12:56 ` [PATCH 1/5] ASoC: samsung: i2s: " phucduc.bui
2026-04-23 12:56 ` [PATCH 2/5] ASoC: samsung: idma: " phucduc.bui
2026-04-23 12:56 ` [PATCH 3/5] ASoC: samsung: odroid: " phucduc.bui
2026-04-23 12:56 ` [PATCH 4/5] ASoC: samsung: pcm: " phucduc.bui
2026-04-23 12:56 ` [PATCH 5/5] ASoC: samsung: spdif: " phucduc.bui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox