]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
iio: sx9310: Use regmap_read_poll_timeout() for compensation
authorDaniel Campello <campello@chromium.org>
Mon, 3 Aug 2020 23:58:08 +0000 (17:58 -0600)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 3 Sep 2020 18:40:42 +0000 (19:40 +0100)
Simplify compensation stage by using regmap_read_poll_timeout().

Signed-off-by: Daniel Campello <campello@chromium.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/proximity/sx9310.c

index a9deed262dbd57b1dcb3d46f2017d1d5c7d89bff..dd04aaf66d31ca3e4d6e8156b6d366c54f1766fc 100644 (file)
@@ -797,7 +797,7 @@ static const struct sx9310_reg_default sx9310_default_regs[] = {
 static int sx9310_init_compensation(struct iio_dev *indio_dev)
 {
        struct sx9310_data *data = iio_priv(indio_dev);
-       int i, ret;
+       int ret;
        unsigned int val;
        unsigned int ctrl0;
 
@@ -811,22 +811,17 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev)
        if (ret < 0)
                return ret;
 
-       for (i = 100; i >= 0; i--) {
-               msleep(20);
-               ret = regmap_read(data->regmap, SX9310_REG_STAT1, &val);
-               if (ret < 0)
-                       goto out;
-               if (!(val & SX9310_REG_STAT1_COMPSTAT_MASK))
-                       break;
-       }
-
-       if (i < 0) {
-               dev_err(&data->client->dev,
-                       "initial compensation timed out: 0x%02x", val);
-               ret = -ETIMEDOUT;
+       ret = regmap_read_poll_timeout(data->regmap, SX9310_REG_STAT1, val,
+                                      !(val & SX9310_REG_STAT1_COMPSTAT_MASK),
+                                      20000, 2000000);
+       if (ret) {
+               if (ret == -ETIMEDOUT)
+                       dev_err(&data->client->dev,
+                               "initial compensation timed out: 0x%02x\n",
+                               val);
+               return ret;
        }
 
-out:
        regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0);
        return ret;
 }