Skip to content

Commit fcb958e

Browse files
Sugar Zhangbroonie
authored andcommitted
ASoC: rockchip: i2s: Fix concurrency between tx/rx
This patch adds lock to fix comcurrency between tx/rx to fix 'rockchip-i2s ff070000.i2s; fail to clear' Considering the situation; tx stream rx stream | | | disable enable | | reset After this patch: lock | tx stream | enable | unlock -------- --------- lock | rx stream | disable | reset | unlock Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com> Link: https://lore.kernel.org/r/1630674434-650-1-git-send-email-sugar.zhang@rock-chips.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 7eac1e2 commit fcb958e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sound/soc/rockchip/rockchip_i2s.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/clk.h>
1616
#include <linux/pm_runtime.h>
1717
#include <linux/regmap.h>
18+
#include <linux/spinlock.h>
1819
#include <sound/pcm_params.h>
1920
#include <sound/dmaengine_pcm.h>
2021

@@ -53,6 +54,7 @@ struct rk_i2s_dev {
5354
bool is_master_mode;
5455
const struct rk_i2s_pins *pins;
5556
unsigned int bclk_ratio;
57+
spinlock_t lock; /* tx/rx lock */
5658
};
5759

5860
static int i2s_runtime_suspend(struct device *dev)
@@ -96,6 +98,7 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on)
9698
unsigned int val = 0;
9799
int retry = 10;
98100

101+
spin_lock(&i2s->lock);
99102
if (on) {
100103
regmap_update_bits(i2s->regmap, I2S_DMACR,
101104
I2S_DMACR_TDE_ENABLE, I2S_DMACR_TDE_ENABLE);
@@ -136,13 +139,15 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on)
136139
}
137140
}
138141
}
142+
spin_unlock(&i2s->lock);
139143
}
140144

141145
static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on)
142146
{
143147
unsigned int val = 0;
144148
int retry = 10;
145149

150+
spin_lock(&i2s->lock);
146151
if (on) {
147152
regmap_update_bits(i2s->regmap, I2S_DMACR,
148153
I2S_DMACR_RDE_ENABLE, I2S_DMACR_RDE_ENABLE);
@@ -183,6 +188,7 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on)
183188
}
184189
}
185190
}
191+
spin_unlock(&i2s->lock);
186192
}
187193

188194
static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
@@ -684,6 +690,7 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
684690
if (!i2s)
685691
return -ENOMEM;
686692

693+
spin_lock_init(&i2s->lock);
687694
i2s->dev = &pdev->dev;
688695

689696
i2s->grf = syscon_regmap_lookup_by_phandle(node, "rockchip,grf");

0 commit comments

Comments
 (0)