From 3d084c214404f8f3acbaadad9eb8eac25c12e9f3 Mon Sep 17 00:00:00 2001 From: Sugar Zhang Date: Tue, 28 Feb 2023 23:29:52 +0800 Subject: [PATCH] ASoC: rockchip: i2s: Simplify FIFO clear routine Signed-off-by: Sugar Zhang Change-Id: I4ecfe4978d7646a99b205772515ae1c4f2d4607f --- sound/soc/rockchip/rockchip_i2s.c | 54 +++++++++++-------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c index 0a7304807f30..bd4c41f081a6 100644 --- a/sound/soc/rockchip/rockchip_i2s.c +++ b/sound/soc/rockchip/rockchip_i2s.c @@ -93,11 +93,24 @@ static inline struct rk_i2s_dev *to_info(struct snd_soc_dai *dai) return snd_soc_dai_get_drvdata(dai); } +static int rockchip_i2s_clear(struct rk_i2s_dev *i2s) +{ + unsigned int clr = I2S_CLR_TXC | I2S_CLR_RXC; + unsigned int val = 0; + int ret; + + regmap_update_bits(i2s->regmap, I2S_CLR, clr, clr); + + ret = regmap_read_poll_timeout_atomic(i2s->regmap, I2S_CLR, val, + !(val & clr), 10, 100); + if (ret < 0) + dev_warn(i2s->dev, "fail to clear\n"); + + return ret; +} + static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) { - unsigned int val = 0; - int retry = 10; - spin_lock(&i2s->lock); if (on) { regmap_update_bits(i2s->regmap, I2S_DMACR, @@ -122,21 +135,7 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) I2S_XFER_RXS_STOP); udelay(150); - regmap_update_bits(i2s->regmap, I2S_CLR, - I2S_CLR_TXC | I2S_CLR_RXC, - I2S_CLR_TXC | I2S_CLR_RXC); - - regmap_read(i2s->regmap, I2S_CLR, &val); - - /* Should wait for clear operation to finish */ - while (val) { - regmap_read(i2s->regmap, I2S_CLR, &val); - retry--; - if (!retry) { - dev_warn(i2s->dev, "fail to clear\n"); - break; - } - } + rockchip_i2s_clear(i2s); } } spin_unlock(&i2s->lock); @@ -144,9 +143,6 @@ static void rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on) static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) { - unsigned int val = 0; - int retry = 10; - spin_lock(&i2s->lock); if (on) { regmap_update_bits(i2s->regmap, I2S_DMACR, @@ -171,21 +167,7 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on) I2S_XFER_RXS_STOP); udelay(150); - regmap_update_bits(i2s->regmap, I2S_CLR, - I2S_CLR_TXC | I2S_CLR_RXC, - I2S_CLR_TXC | I2S_CLR_RXC); - - regmap_read(i2s->regmap, I2S_CLR, &val); - - /* Should wait for clear operation to finish */ - while (val) { - regmap_read(i2s->regmap, I2S_CLR, &val); - retry--; - if (!retry) { - dev_warn(i2s->dev, "fail to clear\n"); - break; - } - } + rockchip_i2s_clear(i2s); } } spin_unlock(&i2s->lock);