diff mbox series

[08/15] iio: sx9310: Use regmap_read_poll_timeout() for compensation

Message ID 20200728091057.8.I34c7a1bfca7fe3d607f8876ef9f10c22153556d2@changeid (mailing list archive)
State New, archived
Headers show
Series sx9310 iio driver updates | expand

Commit Message

Daniel Campello July 28, 2020, 3:12 p.m. UTC
Simplify compensation stage by using regmap_read_poll_timeout().

Signed-off-by: Daniel Campello <campello@chromium.org>
---

 drivers/iio/proximity/sx9310.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

Comments

Andy Shevchenko July 28, 2020, 6:14 p.m. UTC | #1
On Tue, Jul 28, 2020 at 6:15 PM Daniel Campello <campello@chromium.org> wrote:
>
> Simplify compensation stage by using regmap_read_poll_timeout().

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Daniel Campello <campello@chromium.org>
> ---
>
>  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 2465064971d0a7..3956fd679c6db9 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -796,7 +796,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;
>
> @@ -810,22 +810,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,
> +                               "0x02 << 3l compensation timed out: 0x%02x",
> +                               val);
> +               return ret;
>         }
>
> -out:
>         regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0);
>         return ret;
>  }
> --
> 2.28.0.rc0.142.g3c755180ce-goog
>
Stephen Boyd July 28, 2020, 7:37 p.m. UTC | #2
Quoting Daniel Campello (2020-07-28 08:12:51)
> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index 2465064971d0a7..3956fd679c6db9 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -810,22 +810,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,
> +                               "0x02 << 3l compensation timed out: 0x%02x",

What does 0x02 << 3l mean?

> +                               val);
> +               return ret;
>         }
>
diff mbox series

Patch

diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 2465064971d0a7..3956fd679c6db9 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -796,7 +796,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;
 
@@ -810,22 +810,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,
+				"0x02 << 3l compensation timed out: 0x%02x",
+				val);
+		return ret;
 	}
 
-out:
 	regmap_write(data->regmap, SX9310_REG_PROX_CTRL0, ctrl0);
 	return ret;
 }