ASoC: rockchip: i2s: use regmap_read_poll_timeout to poll I2S_CLR
authorJudy Hsiao <judyhsiao@chromium.org>
Wed, 14 Sep 2022 03:12:34 +0000 (03:12 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 14 Sep 2022 09:39:28 +0000 (10:39 +0100)
Use regmap_read_poll_timeout to poll I2S_CLR.
It also fixes the 'rockchip-i2s ff070000.i2s; fail to clear' when
the read of I2S_CLR exceeds the retry limit.

Fixes: 0ff9f8b9f592 ("ASoC: rockchip: i2s: Fix error code when fail to read I2S_CLR")
Signed-off-by: Judy Hsiao <judyhsiao@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Link: https://lore.kernel.org/r/20220914031234.2250298-1-judyhsiao@chromium.org
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/rockchip/rockchip_i2s.c

index f5f3540..28c86f5 100644 (file)
@@ -126,7 +126,6 @@ static inline struct rk_i2s_dev *to_info(struct snd_soc_dai *dai)
 static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on)
 {
        unsigned int val = 0;
-       int retry = 10;
        int ret = 0;
 
        spin_lock(&i2s->lock);
@@ -163,18 +162,14 @@ static int rockchip_snd_txctrl(struct rk_i2s_dev *i2s, int on)
                                                 I2S_CLR_TXC | I2S_CLR_RXC);
                        if (ret < 0)
                                goto end;
-                       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");
-                                       ret = -EBUSY;
-                                       break;
-                               }
-                       }
+                       ret = regmap_read_poll_timeout(i2s->regmap,
+                                                      I2S_CLR,
+                                                      val,
+                                                      val != 0,
+                                                      20,
+                                                      200);
+                       if (ret < 0)
+                               dev_warn(i2s->dev, "fail to clear: %d\n", ret);
                }
        }
 end:
@@ -188,7 +183,6 @@ end:
 static int rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on)
 {
        unsigned int val = 0;
-       int retry = 10;
        int ret = 0;
 
        spin_lock(&i2s->lock);
@@ -226,17 +220,14 @@ static int rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on)
                                                 I2S_CLR_TXC | I2S_CLR_RXC);
                        if (ret < 0)
                                goto end;
-                       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");
-                                       ret = -EBUSY;
-                                       break;
-                               }
-                       }
+                       ret = regmap_read_poll_timeout(i2s->regmap,
+                                                      I2S_CLR,
+                                                      val,
+                                                      val != 0,
+                                                      20,
+                                                      200);
+                       if (ret < 0)
+                               dev_warn(i2s->dev, "fail to clear: %d\n", ret);
                }
        }
 end: