mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shrikant Raskar <raskar.shree97@gmail.com>
To: jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org
Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	heiko@sntech.de, neil.armstrong@linaro.org,
	skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Shrikant Raskar <raskar.shree97@gmail.com>
Subject: [PATCH v2 3/4] iio: proximity: rfd77402: Move polling logic into helper
Date: Sun, 30 Nov 2025 21:07:11 +0530	[thread overview]
Message-ID: <20251130153712.6792-4-raskar.shree97@gmail.com> (raw)
In-Reply-To: <20251130153712.6792-1-raskar.shree97@gmail.com>

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@gmail.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


  parent reply	other threads:[~2025-11-30 15:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-30 15:37 [PATCH v2 0/4] iio: proximity: Add DT and interrupt support for RFD77402 Shrikant Raskar
2025-11-30 15:37 ` [PATCH v2 1/4] dt-bindings: iio: proximity: Add RF Digital RFD77402 ToF sensor Shrikant Raskar
2025-11-30 16:16   ` Rob Herring (Arm)
2025-12-01  8:06   ` Krzysztof Kozlowski
2025-12-02  3:15     ` Shrikant
2025-11-30 15:37 ` [PATCH v2 2/4] iio: proximity: rfd77402: Add Device Tree support Shrikant Raskar
2025-11-30 16:48   ` Andy Shevchenko
2025-11-30 15:37 ` Shrikant Raskar [this message]
2025-11-30 16:52   ` [PATCH v2 3/4] iio: proximity: rfd77402: Move polling logic into helper Andy Shevchenko
2025-12-07 15:53   ` Jonathan Cameron
2025-11-30 15:37 ` [PATCH v2 4/4] iio: proximity: rfd77402: Add interrupt handling support Shrikant Raskar
2025-11-30 17:01   ` Andy Shevchenko
2025-12-07 15:58   ` 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=20251130153712.6792-4-raskar.shree97@gmail.com \
    --to=raskar.shree97@gmail.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=david.hunter.linux@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=heiko@sntech.de \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    --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®