Commit dc46198f authored by Daniel Campello's avatar Daniel Campello Committed by Jonathan Cameron

iio: sx9310: Use regmap_read_poll_timeout() for compensation

Simplify compensation stage by using regmap_read_poll_timeout().
Signed-off-by: default avatarDaniel Campello <campello@chromium.org>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: default avatarStephen Boyd <swboyd@chromium.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 68aa360a
...@@ -797,7 +797,7 @@ static const struct sx9310_reg_default sx9310_default_regs[] = { ...@@ -797,7 +797,7 @@ static const struct sx9310_reg_default sx9310_default_regs[] = {
static int sx9310_init_compensation(struct iio_dev *indio_dev) static int sx9310_init_compensation(struct iio_dev *indio_dev)
{ {
struct sx9310_data *data = iio_priv(indio_dev); struct sx9310_data *data = iio_priv(indio_dev);
int i, ret; int ret;
unsigned int val; unsigned int val;
unsigned int ctrl0; unsigned int ctrl0;
...@@ -811,22 +811,17 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev) ...@@ -811,22 +811,17 @@ static int sx9310_init_compensation(struct iio_dev *indio_dev)
if (ret < 0) if (ret < 0)
return ret; return ret;
for (i = 100; i >= 0; i--) { ret = regmap_read_poll_timeout(data->regmap, SX9310_REG_STAT1, val,
msleep(20); !(val & SX9310_REG_STAT1_COMPSTAT_MASK),
ret = regmap_read(data->regmap, SX9310_REG_STAT1, &val); 20000, 2000000);
if (ret < 0) if (ret) {
goto out; if (ret == -ETIMEDOUT)
if (!(val & SX9310_REG_STAT1_COMPSTAT_MASK))
break;
}
if (i < 0) {
dev_err(&data->client->dev, dev_err(&data->client->dev,
"initial compensation timed out: 0x%02x", val); "initial compensation timed out: 0x%02x\n",
ret = -ETIMEDOUT; val);
return ret;
} }
out:
regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0); regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment