From: Shrikant Raskar via B4 Relay <devnull+raskar.shree97.gmail.com@kernel.org>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Cc: skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
raskar.shree97@gmail.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@intel.com>
Subject: [PATCH v8 3/6] iio: proximity: rfd77402: Use kernel helper for result polling
Date: Wed, 28 Jan 2026 23:21:50 +0530 [thread overview]
Message-ID: <20260128-b4-rfd77402_v5-v8-3-36388fe7b95e@gmail.com> (raw)
In-Reply-To: <20260128-b4-rfd77402_v5-v8-0-36388fe7b95e@gmail.com>
From: Shrikant Raskar <raskar.shree97@gmail.com>
Replace the manually written polling loop with read_poll_timeout(),
the kernel's standard helper for waiting on hardware status.This
makes the code easier to read.
Move the polling logic into a dedicated helper function, as it will
be reused by future updates.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
---
drivers/iio/proximity/rfd77402.c | 42 ++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77402.c
index 8f7debf0e61f..6b23fb3bfe1d 100644
--- a/drivers/iio/proximity/rfd77402.c
+++ b/drivers/iio/proximity/rfd77402.c
@@ -12,6 +12,7 @@
#include <linux/delay.h>
#include <linux/i2c.h>
+#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
@@ -110,10 +111,27 @@ static int rfd77402_set_state(struct i2c_client *client, u8 state, u16 check)
return 0;
}
-static int rfd77402_measure(struct i2c_client *client)
+static int rfd77402_wait_for_result(struct rfd77402_data *data)
{
+ struct i2c_client *client = data->client;
+ int val, ret;
+
+ ret = read_poll_timeout(i2c_smbus_read_byte_data, val,
+ (val < 0) || (val & RFD77402_ICSR_RESULT),
+ 10 * USEC_PER_MSEC,
+ 10 * 10 * USEC_PER_MSEC,
+ false,
+ client, RFD77402_ICSR);
+ if (val < 0)
+ return val;
+
+ return ret;
+}
+
+static int rfd77402_measure(struct rfd77402_data *data)
+{
+ struct i2c_client *client = data->client;
int ret;
- int tries = 10;
ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON,
RFD77402_STATUS_MCPU_ON);
@@ -126,23 +144,9 @@ static int rfd77402_measure(struct i2c_client *client)
if (ret < 0)
goto err;
- while (tries-- > 0) {
- ret = i2c_smbus_read_byte_data(client, RFD77402_ICSR);
- if (ret < 0)
- goto err;
- if (ret & RFD77402_ICSR_RESULT)
- break;
- /*
- * As per RFD77402 datasheet section '3.1.1 Single Measure',
- * the suggested timeout value for single measure is 100ms.
- */
- msleep(10);
- }
-
- if (tries < 0) {
- ret = -ETIMEDOUT;
+ ret = rfd77402_wait_for_result(data);
+ if (ret < 0)
goto err;
- }
ret = i2c_smbus_read_word_data(client, RFD77402_RESULT_R);
if (ret < 0)
@@ -172,7 +176,7 @@ static int rfd77402_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
mutex_lock(&data->lock);
- ret = rfd77402_measure(data->client);
+ ret = rfd77402_measure(data);
mutex_unlock(&data->lock);
if (ret < 0)
return ret;
--
2.43.0
next prev parent reply other threads:[~2026-01-28 17:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 17:51 [PATCH v8 0/6] iio: proximity: Add interrupt support for RFD77402 Shrikant Raskar via B4 Relay
2026-01-28 17:51 ` [PATCH v8 1/6] iio: proximity: rfd77402: Reorder header includes Shrikant Raskar via B4 Relay
2026-01-29 17:52 ` Jonathan Cameron
2026-01-28 17:51 ` [PATCH v8 2/6] iio: proximity: rfd77402: Align polling timeout with datasheet Shrikant Raskar via B4 Relay
2026-01-28 22:21 ` Andy Shevchenko
2026-01-28 17:51 ` Shrikant Raskar via B4 Relay [this message]
2026-01-28 22:23 ` [PATCH v8 3/6] iio: proximity: rfd77402: Use kernel helper for result polling Andy Shevchenko
2026-01-29 17:48 ` Jonathan Cameron
2026-01-28 17:51 ` [PATCH v8 4/6] iio: proximity: rfd77402: Use devm-managed mutex initialization Shrikant Raskar via B4 Relay
2026-01-28 17:51 ` [PATCH v8 5/6] iio: proximity: rfd77402: Document device private data structure Shrikant Raskar via B4 Relay
2026-01-28 17:51 ` [PATCH v8 6/6] iio: proximity: rfd77402: Add interrupt handling support Shrikant Raskar via B4 Relay
2026-01-28 22:25 ` [PATCH v8 0/6] iio: proximity: Add interrupt support for RFD77402 Andy Shevchenko
2026-01-29 17:51 ` Jonathan Cameron
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=20260128-b4-rfd77402_v5-v8-3-36388fe7b95e@gmail.com \
--to=devnull+raskar.shree97.gmail.com@kernel.org \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=david.hunter.linux@gmail.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=raskar.shree97@gmail.com \
--cc=skhan@linuxfoundation.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
all inboxes | Powered by JetHome®