[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251130153712.6792-4-raskar.shree97@gmail.com>
Date: Sun, 30 Nov 2025 21:07:11 +0530
From: Shrikant Raskar <raskar.shree97@...il.com>
To: jic23@...nel.org,
robh@...nel.org,
krzk+dt@...nel.org,
conor+dt@...nel.org
Cc: dlechner@...libre.com,
nuno.sa@...log.com,
andy@...nel.org,
heiko@...ech.de,
neil.armstrong@...aro.org,
skhan@...uxfoundation.org,
david.hunter.linux@...il.com,
linux-iio@...r.kernel.org,
devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org,
Shrikant Raskar <raskar.shree97@...il.com>
Subject: [PATCH v2 3/4] iio: proximity: rfd77402: Move polling logic into helper
This change extracts the polling logic into a dedicated helper,
rfd77402_result_polling(), which improves readability and keeps
rfd77402_measure() focused on the high-level measurement flow.
This refactoring is also a necessary preparation step for adding
interrupt-based result handling in a follow-up patch.
Signed-off-by: Shrikant Raskar <raskar.shree97@...il.com>
---
drivers/iio/proximity/rfd77402.c | 35 +++++++++++++++++++-------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77402.c
index 3262af6f6882..2152509816ca 100644
--- a/drivers/iio/proximity/rfd77402.c
+++ b/drivers/iio/proximity/rfd77402.c
@@ -110,11 +110,28 @@ 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_result_polling(struct i2c_client *client)
{
int ret;
int tries = 10;
+ while (tries-- > 0) {
+ ret = i2c_smbus_read_byte_data(client, RFD77402_ICSR);
+ if (ret < 0)
+ return ret;
+
+ if (ret & RFD77402_ICSR_RESULT)
+ return 0;
+
+ msleep(20);
+ }
+
+ return -ETIMEDOUT;
+}
+
+static int rfd77402_measure(struct i2c_client *client)
+{
+ int ret;
ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON,
RFD77402_STATUS_MCPU_ON);
if (ret < 0)
@@ -125,20 +142,10 @@ static int rfd77402_measure(struct i2c_client *client)
RFD77402_CMD_VALID);
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;
- msleep(20);
- }
-
- if (tries < 0) {
- ret = -ETIMEDOUT;
+
+ ret = rfd77402_result_polling(client);
+ if (ret < 0)
goto err;
- }
ret = i2c_smbus_read_word_data(client, RFD77402_RESULT_R);
if (ret < 0)
--
2.43.0
Powered by blists - more mailing lists