[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200731104555.v3.8.Ia205f0b0363bf663db7704026b5b7036b9748c56@changeid>
Date: Fri, 31 Jul 2020 10:48:45 -0600
From: Daniel Campello <campello@...omium.org>
To: LKML <devicetree@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>
Cc: Jonathan Cameron <jic23@...nel.org>,
Daniel Campello <campello@...omium.org>,
Andy Shevchenko <andy.shevchenko@...il.com>,
Douglas Anderson <dianders@...omium.org>,
Hartmut Knaack <knaack.h@....de>,
Lars-Peter Clausen <lars@...afoo.de>,
Peter Meerwald-Stadler <pmeerw@...erw.net>,
Stephen Boyd <swboyd@...omium.org>, linux-iio@...r.kernel.org
Subject: [PATCH v3 08/15] iio: sx9310: Use regmap_read_poll_timeout() for compensation
Simplify compensation stage by using regmap_read_poll_timeout().
Signed-off-by: Daniel Campello <campello@...omium.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@...il.com>
---
Changes in v3: None
Changes in v2:
- Fixed dev_err() message
drivers/iio/proximity/sx9310.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 8f80a4c20ac05e..9f6292cc86146d 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -802,7 +802,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;
@@ -816,22 +816,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_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;
}
--
2.28.0.163.g6104cc2f0b6-goog
Powered by blists - more mailing lists