From: Crt Mori <cmo@melexis.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Crt Mori <cmo@melexis.com>
Subject: [PATCH v4 4/4] iio:temperature:mlx90632: Convert polling while loops to do-while
Date: Sat, 8 Aug 2020 14:10:26 +0200 [thread overview]
Message-ID: <20200808121026.1300375-5-cmo@melexis.com> (raw)
In-Reply-To: <20200808121026.1300375-1-cmo@melexis.com>
Reduce number of lines and improve readability to convert polling while
loops to do-while. The iopoll.h interface was not used, because we
require more than 20ms timeout, because time for sensor to perform a
measurement is around 10ms and it needs to perform measurements for each
channel (which currently is 3).
Signed-off-by: Crt Mori <cmo@melexis.com>
---
drivers/iio/temperature/mlx90632.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/temperature/mlx90632.c b/drivers/iio/temperature/mlx90632.c
index 4e0131705c11..24ffcce9ad74 100644
--- a/drivers/iio/temperature/mlx90632.c
+++ b/drivers/iio/temperature/mlx90632.c
@@ -214,15 +214,13 @@ static int mlx90632_perform_measurement(struct mlx90632_data *data)
if (ret < 0)
return ret;
- while (tries-- > 0) {
+ do {
ret = regmap_read(data->regmap, MLX90632_REG_STATUS,
®_status);
if (ret < 0)
return ret;
- if (reg_status & MLX90632_STAT_DATA_RDY)
- break;
usleep_range(10000, 11000);
- }
+ } while (!(reg_status & MLX90632_STAT_DATA_RDY) && tries--);
if (tries < 0) {
dev_err(&data->client->dev, "data not ready");
@@ -419,7 +417,7 @@ static int mlx90632_read_object_raw_extended(struct regmap *regmap, s16 *object_
static int mlx90632_read_all_channel_extended(struct mlx90632_data *data, s16 *object_new_raw,
s16 *ambient_new_raw, s16 *ambient_old_raw)
{
- int tries = 4;
+ int tries = 5;
int ret;
mutex_lock(&data->lock);
@@ -427,14 +425,13 @@ static int mlx90632_read_all_channel_extended(struct mlx90632_data *data, s16 *o
if (ret < 0)
goto read_unlock;
- while (tries-- > 0) {
+ do {
ret = mlx90632_perform_measurement(data);
if (ret < 0)
goto read_unlock;
- if (ret == 19)
- break;
- }
+ } while ((ret != 19) && tries--);
+
if (tries < 0) {
ret = -ETIMEDOUT;
goto read_unlock;
--
2.25.1
next prev parent reply other threads:[~2020-08-08 12:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-08 12:10 [PATCH v4 0/4] iio: temperature: mlx90632: Add extended calibration calculations Crt Mori
2020-08-08 12:10 ` [PATCH v4 1/4] iio:temperature:mlx90632: Reduce number of equal calulcations Crt Mori
2020-08-08 19:58 ` Andy Shevchenko
2020-08-08 12:10 ` [PATCH v4 2/4] iio:temperature:mlx90632: Adding extended calibration option Crt Mori
2020-08-08 20:03 ` Andy Shevchenko
2020-08-08 21:57 ` Crt Mori
2020-08-09 13:32 ` Jonathan Cameron
2020-08-09 21:05 ` Crt Mori
2020-08-11 7:53 ` Crt Mori
2020-08-16 9:09 ` Jonathan Cameron
2020-08-08 12:10 ` [PATCH v4 3/4] iio:temperature:mlx90632: Add kerneldoc to the internal struct Crt Mori
2020-08-08 19:54 ` Andy Shevchenko
2020-08-08 12:10 ` Crt Mori [this message]
2020-08-08 19:56 ` [PATCH v4 0/4] iio: temperature: mlx90632: Add extended calibration calculations Andy Shevchenko
2020-08-08 20:04 ` Andy Shevchenko
2020-08-08 20:06 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200808121026.1300375-5-cmo@melexis.com \
--to=cmo@melexis.com \
--cc=andy.shevchenko@gmail.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).