* [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402
@ 2026-01-01 16:17 Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 1/4] dt-bindings: iio: proximity: Add RF Digital RFD77402 ToF sensor Shrikant Raskar via B4 Relay
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Shrikant Raskar via B4 Relay @ 2026-01-01 16:17 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: raskar.shree97, skhan, david.hunter.linux, linux-iio, devicetree,
linux-kernel, Krzysztof Kozlowski
This patch series adds:
- Add RF Digital vendor prefix
- YAML binding for RFD77402
- Add OF device ID for enumeration via DT
- Use kernel helper for result polling
- Interrupt handling support
These changes enable DT-based configuration and event-driven
operation for the RFD77402 Time-of-Flight sensor.
Changelog:
- Resend the patch series as v4 since not all patches were delivered
in v3 due to SMTP daily sending limits.
- Add 'Reviewed-by' tag to dt-binding patch.
- Update commit message in OF device ID patch.
- Update commit message in the third patch.
- Replace rfd77402_result_polling() with read_poll_timeout().
- Add 'struct rfd77402_data' details in kernel-doc format.
- Arrange includes in order.
- Add comment for completion timeout value.
- Remove blank lines.
- Indent the comments to code.
- Convert mutex_init() to devm_mutex_init().
- Remove 'IRQF_TRIGGER_FALLING' flag from devm_request_threaded_irq().
- Drop the duplicate message.
- Replace 'dev_info' with 'dev_dbg()'.
- Update 'dev_id' to 'pdata' in rfd77402_interrupt_handler().
- Drop 'interrupt mode' comment
- Use 'if(ret)' instead of 'if(ret < 0) for consistency.
- Use 'return i2c_smbus_write_byte_data()' in 'rfd77402_config_irq'.
Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
---
Shrikant Raskar (4):
dt-bindings: iio: proximity: Add RF Digital RFD77402 ToF sensor
iio: proximity: rfd77402: Add OF device ID for enumeration via DT
iio: proximity: rfd77402: Use kernel helper for result polling
iio: proximity: rfd77402: Add interrupt handling support
.../bindings/iio/proximity/rfdigital,rfd77402.yaml | 53 ++++++++
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
drivers/iio/proximity/rfd77402.c | 149 ++++++++++++++++++---
3 files changed, 183 insertions(+), 21 deletions(-)
---
base-commit: d8ba32c5a460837a5f0b9619dac99fafb6faef07
change-id: 20260101-b4-rfd77402_irq-3dda6baf2370
Best regards,
--
Shrikant Raskar <raskar.shree97@gmail.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 1/4] dt-bindings: iio: proximity: Add RF Digital RFD77402 ToF sensor
2026-01-01 16:17 [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Shrikant Raskar via B4 Relay
@ 2026-01-01 16:17 ` Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 2/4] iio: proximity: rfd77402: Add OF device ID for enumeration via DT Shrikant Raskar via B4 Relay
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Shrikant Raskar via B4 Relay @ 2026-01-01 16:17 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: raskar.shree97, skhan, david.hunter.linux, linux-iio, devicetree,
linux-kernel, Krzysztof Kozlowski
From: Shrikant Raskar <raskar.shree97@gmail.com>
The RF Digital RFD77402 is a Time-of-Flight (ToF) proximity and distance
sensor that provides absolute and highly accurate distance measurements
from 100 mm up to 2000 mm over an I2C interface. It includes an optional
interrupt pin that signals when new measurement data is ready.
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
---
.../bindings/iio/proximity/rfdigital,rfd77402.yaml | 53 ++++++++++++++++++++++
.../devicetree/bindings/vendor-prefixes.yaml | 2 +
2 files changed, 55 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/proximity/rfdigital,rfd77402.yaml b/Documentation/devicetree/bindings/iio/proximity/rfdigital,rfd77402.yaml
new file mode 100644
index 000000000000..1ef6326b209e
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/rfdigital,rfd77402.yaml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/proximity/rfdigital,rfd77402.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RF Digital RFD77402 ToF sensor
+
+maintainers:
+ - Shrikant Raskar <raskar.shree97@gmail.com>
+
+description:
+ The RF Digital RFD77402 is a Time-of-Flight (ToF) proximity and distance
+ sensor providing up to 200 mm range measurement over an I2C interface.
+
+properties:
+ compatible:
+ const: rfdigital,rfd77402
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+ description:
+ Interrupt asserted when a new distance measurement is available.
+
+ vdd-supply:
+ description: Regulator that provides power to the sensor.
+
+required:
+ - compatible
+ - reg
+ - vdd-supply
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ proximity@4c {
+ compatible = "rfdigital,rfd77402";
+ reg = <0x4c>;
+ vdd-supply = <&vdd_3v3>;
+ interrupt-parent = <&gpio>;
+ interrupts = <4 IRQ_TYPE_EDGE_FALLING>;
+ };
+ };
+...
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index c7591b2aec2a..59ac4f0756d9 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -1361,6 +1361,8 @@ patternProperties:
description: Revolution Robotics, Inc. (Revotics)
"^rex,.*":
description: iMX6 Rex Project
+ "^rfdigital,.*":
+ description: RF Digital Corporation
"^richtek,.*":
description: Richtek Technology Corporation
"^ricoh,.*":
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v4 2/4] iio: proximity: rfd77402: Add OF device ID for enumeration via DT
2026-01-01 16:17 [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 1/4] dt-bindings: iio: proximity: Add RF Digital RFD77402 ToF sensor Shrikant Raskar via B4 Relay
@ 2026-01-01 16:17 ` Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 3/4] iio: proximity: rfd77402: Use kernel helper for result polling Shrikant Raskar via B4 Relay
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Shrikant Raskar via B4 Relay @ 2026-01-01 16:17 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: raskar.shree97, skhan, david.hunter.linux, linux-iio, devicetree,
linux-kernel
From: Shrikant Raskar <raskar.shree97@gmail.com>
Add an OF device ID table so the driver can bind automatically when
the RFD77402 sensor is described in Device Tree. This enables proper
enumeration via its compatible string and allows instantiation on
DT-based platforms.
Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
---
drivers/iio/proximity/rfd77402.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77402.c
index aff60a3c1a6f..3262af6f6882 100644
--- a/drivers/iio/proximity/rfd77402.c
+++ b/drivers/iio/proximity/rfd77402.c
@@ -313,10 +313,17 @@ static const struct i2c_device_id rfd77402_id[] = {
};
MODULE_DEVICE_TABLE(i2c, rfd77402_id);
+static const struct of_device_id rfd77402_of_match[] = {
+ { .compatible = "rfdigital,rfd77402" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, rfd77402_of_match);
+
static struct i2c_driver rfd77402_driver = {
.driver = {
.name = RFD77402_DRV_NAME,
.pm = pm_sleep_ptr(&rfd77402_pm_ops),
+ .of_match_table = rfd77402_of_match,
},
.probe = rfd77402_probe,
.id_table = rfd77402_id,
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v4 3/4] iio: proximity: rfd77402: Use kernel helper for result polling
2026-01-01 16:17 [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 1/4] dt-bindings: iio: proximity: Add RF Digital RFD77402 ToF sensor Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 2/4] iio: proximity: rfd77402: Add OF device ID for enumeration via DT Shrikant Raskar via B4 Relay
@ 2026-01-01 16:17 ` Shrikant Raskar via B4 Relay
2026-01-02 12:24 ` Andy Shevchenko
2026-01-01 16:17 ` [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support Shrikant Raskar via B4 Relay
2026-01-02 12:26 ` [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Andy Shevchenko
4 siblings, 1 reply; 9+ messages in thread
From: Shrikant Raskar via B4 Relay @ 2026-01-01 16:17 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: raskar.shree97, skhan, david.hunter.linux, linux-iio, devicetree,
linux-kernel
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 and avoids repeating the same
polling code in the driver.
Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
---
drivers/iio/proximity/rfd77402.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77402.c
index 3262af6f6882..496c1412ebf8 100644
--- a/drivers/iio/proximity/rfd77402.c
+++ b/drivers/iio/proximity/rfd77402.c
@@ -13,6 +13,7 @@
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/delay.h>
+#include <linux/iopoll.h>
#include <linux/iio/iio.h>
@@ -113,7 +114,6 @@ static int rfd77402_set_state(struct i2c_client *client, u8 state, u16 check)
static int rfd77402_measure(struct i2c_client *client)
{
int ret;
- int tries = 10;
ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON,
RFD77402_STATUS_MCPU_ON);
@@ -126,19 +126,15 @@ 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;
- msleep(20);
- }
-
- if (tries < 0) {
- ret = -ETIMEDOUT;
+ /* Poll ICSR until RESULT bit is set */
+ ret = read_poll_timeout(i2c_smbus_read_byte_data, ret,
+ ret & RFD77402_ICSR_RESULT,
+ 10000, /* sleep: 10ms */
+ 100000, /* timeout: 100ms */
+ false,
+ client, RFD77402_ICSR);
+ if (ret < 0)
goto err;
- }
ret = i2c_smbus_read_word_data(client, RFD77402_RESULT_R);
if (ret < 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support
2026-01-01 16:17 [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Shrikant Raskar via B4 Relay
` (2 preceding siblings ...)
2026-01-01 16:17 ` [PATCH v4 3/4] iio: proximity: rfd77402: Use kernel helper for result polling Shrikant Raskar via B4 Relay
@ 2026-01-01 16:17 ` Shrikant Raskar via B4 Relay
2026-01-02 12:34 ` Andy Shevchenko
2026-01-02 12:26 ` [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Andy Shevchenko
4 siblings, 1 reply; 9+ messages in thread
From: Shrikant Raskar via B4 Relay @ 2026-01-01 16:17 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: raskar.shree97, skhan, david.hunter.linux, linux-iio, devicetree,
linux-kernel
From: Shrikant Raskar <raskar.shree97@gmail.com>
Add interrupt handling support to enable event-driven data acquisition
instead of continuous polling. This improves responsiveness, reduces
CPU overhead, and supports low-power operation by allowing the system
to remain idle until an interrupt occurs.
Signed-off-by: Shrikant Raskar <raskar.shree97@gmail.com>
---
drivers/iio/proximity/rfd77402.c | 136 ++++++++++++++++++++++++++++++++++-----
1 file changed, 120 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/proximity/rfd77402.c b/drivers/iio/proximity/rfd77402.c
index 496c1412ebf8..8cddf509f9c6 100644
--- a/drivers/iio/proximity/rfd77402.c
+++ b/drivers/iio/proximity/rfd77402.c
@@ -6,13 +6,14 @@
*
* 7-bit I2C slave address 0x4c
*
- * TODO: interrupt
* https://media.digikey.com/pdf/Data%20Sheets/RF%20Digital%20PDFs/RFD77402.pdf
*/
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/completion.h>
#include <linux/iopoll.h>
#include <linux/iio/iio.h>
@@ -20,6 +21,8 @@
#define RFD77402_DRV_NAME "rfd77402"
#define RFD77402_ICSR 0x00 /* Interrupt Control Status Register */
+#define RFD77402_ICSR_CLR_CFG BIT(0)
+#define RFD77402_ICSR_CLR_TYPE BIT(1)
#define RFD77402_ICSR_INT_MODE BIT(2)
#define RFD77402_ICSR_INT_POL BIT(3)
#define RFD77402_ICSR_RESULT BIT(4)
@@ -27,6 +30,12 @@
#define RFD77402_ICSR_H2M_MSG BIT(6)
#define RFD77402_ICSR_RESET BIT(7)
+#define RFD77402_IER 0x02
+#define RFD77402_IER_RESULT BIT(0)
+#define RFD77402_IER_M2H_MSG BIT(1)
+#define RFD77402_IER_H2M_MSG BIT(2)
+#define RFD77402_IER_RESET BIT(3)
+
#define RFD77402_CMD_R 0x04
#define RFD77402_CMD_SINGLE 0x01
#define RFD77402_CMD_STANDBY 0x10
@@ -77,10 +86,18 @@ static const struct {
{RFD77402_HFCFG_3, 0x45d4},
};
+/**
+ * struct rfd77402_data - device-specific data for the RFD77402 sensor
+ * @client: I2C client handle
+ * @lock: mutex to serialize sensor reads
+ * @completion: completion used for interrupt-driven measurements
+ * @irq_en: indicates whether interrupt mode is enabled
+ */
struct rfd77402_data {
struct i2c_client *client;
- /* Serialize reads from the sensor */
struct mutex lock;
+ struct completion completion;
+ bool irq_en;
};
static const struct iio_chan_spec rfd77402_channels[] = {
@@ -91,6 +108,39 @@ static const struct iio_chan_spec rfd77402_channels[] = {
},
};
+static irqreturn_t rfd77402_interrupt_handler(int irq, void *pdata)
+{
+ struct rfd77402_data *data = pdata;
+ int ret;
+
+ if (!data || !data->client)
+ return IRQ_NONE;
+
+ ret = i2c_smbus_read_byte_data(data->client, RFD77402_ICSR);
+ if (ret < 0)
+ return IRQ_NONE;
+
+ /* Check if the interrupt is from our device */
+ if (!(ret & RFD77402_ICSR_RESULT))
+ return IRQ_NONE;
+
+ /* Signal completion of measurement */
+ complete(&data->completion);
+ return IRQ_HANDLED;
+}
+
+static int rfd77402_wait_for_irq(struct rfd77402_data *data)
+{
+ int ret;
+ /* As per datasheet, single measurement flow takes 100ms */
+ ret = wait_for_completion_timeout(&data->completion,
+ msecs_to_jiffies(100));
+ if (ret == 0)
+ return -ETIMEDOUT;
+
+ return 0;
+}
+
static int rfd77402_set_state(struct i2c_client *client, u8 state, u16 check)
{
int ret;
@@ -111,8 +161,9 @@ 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_measure(struct rfd77402_data *data)
{
+ struct i2c_client *client = data->client;
int ret;
ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON,
@@ -126,13 +177,19 @@ static int rfd77402_measure(struct i2c_client *client)
if (ret < 0)
goto err;
- /* Poll ICSR until RESULT bit is set */
- ret = read_poll_timeout(i2c_smbus_read_byte_data, ret,
- ret & RFD77402_ICSR_RESULT,
- 10000, /* sleep: 10ms */
- 100000, /* timeout: 100ms */
- false,
- client, RFD77402_ICSR);
+ if (data->irq_en) {
+ /* Re-initialize completion and wait for interrupt */
+ reinit_completion(&data->completion);
+ ret = rfd77402_wait_for_irq(data);
+ } else {
+ /* Poll ICSR until RESULT bit is set */
+ ret = read_poll_timeout(i2c_smbus_read_byte_data, ret,
+ ret & RFD77402_ICSR_RESULT,
+ 10000, /* sleep 10ms */
+ 100000, /* timeout 100ms */
+ false,
+ client, RFD77402_ICSR);
+ }
if (ret < 0)
goto err;
@@ -164,7 +221,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;
@@ -184,8 +241,21 @@ static const struct iio_info rfd77402_info = {
.read_raw = rfd77402_read_raw,
};
+static int rfd77402_config_irq(struct i2c_client *client, u8 csr, u8 ier)
+{
+ int ret;
+
+ ret = i2c_smbus_write_byte_data(client, RFD77402_ICSR, csr);
+ if (ret)
+ return ret;
+
+ return i2c_smbus_write_byte_data(client, RFD77402_IER, ier);
+}
+
static int rfd77402_init(struct i2c_client *client)
{
+ struct iio_dev *indio_dev = i2c_get_clientdata(client);
+ struct rfd77402_data *data = iio_priv(indio_dev);
int ret, i;
ret = rfd77402_set_state(client, RFD77402_CMD_STANDBY,
@@ -193,10 +263,24 @@ static int rfd77402_init(struct i2c_client *client)
if (ret < 0)
return ret;
- /* configure INT pad as push-pull, active low */
- ret = i2c_smbus_write_byte_data(client, RFD77402_ICSR,
- RFD77402_ICSR_INT_MODE);
- if (ret < 0)
+ if (data->irq_en) {
+ /* Enable interrupt mode:
+ * - Configure ICSR for auto-clear on read and
+ * push-pull output
+ * - Enable "result ready" interrupt in IER
+ */
+ ret = rfd77402_config_irq(client,
+ RFD77402_ICSR_CLR_CFG |
+ RFD77402_ICSR_INT_MODE,
+ RFD77402_IER_RESULT);
+ } else {
+ /* Disable all interrupts:
+ * - Clear ICSR configuration
+ * - Disable all interrupts in IER
+ */
+ ret = rfd77402_config_irq(client, 0, 0);
+ }
+ if (ret)
return ret;
/* I2C configuration */
@@ -271,7 +355,27 @@ static int rfd77402_probe(struct i2c_client *client)
data = iio_priv(indio_dev);
data->client = client;
- mutex_init(&data->lock);
+ ret = devm_mutex_init(&client->dev, &data->lock);
+ if (ret)
+ return ret;
+
+ init_completion(&data->completion);
+ i2c_set_clientdata(client, indio_dev);
+
+ data->irq_en = false;
+ if (client->irq > 0) {
+ ret = devm_request_threaded_irq(&client->dev, client->irq,
+ NULL, rfd77402_interrupt_handler,
+ IRQF_ONESHOT,
+ "rfd77402", data);
+ if (ret)
+ return ret;
+
+ data->irq_en = true;
+ dev_dbg(&client->dev, "Using interrupt mode\n");
+ } else {
+ dev_dbg(&client->dev, "Using polling mode\n");
+ }
indio_dev->info = &rfd77402_info;
indio_dev->channels = rfd77402_channels;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v4 3/4] iio: proximity: rfd77402: Use kernel helper for result polling
2026-01-01 16:17 ` [PATCH v4 3/4] iio: proximity: rfd77402: Use kernel helper for result polling Shrikant Raskar via B4 Relay
@ 2026-01-02 12:24 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-02 12:24 UTC (permalink / raw)
To: raskar.shree97
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, skhan,
david.hunter.linux, linux-iio, devicetree, linux-kernel
On Thu, Jan 01, 2026 at 09:47:40PM +0530, Shrikant Raskar via B4 Relay wrote:
> 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 and avoids repeating the same
> polling code in the driver.
...
> index 3262af6f6882..496c1412ebf8 100644
> --- a/drivers/iio/proximity/rfd77402.c
> +++ b/drivers/iio/proximity/rfd77402.c
> @@ -13,6 +13,7 @@
> #include <linux/module.h>
> #include <linux/i2c.h>
> #include <linux/delay.h>
> +#include <linux/iopoll.h>
Even if the original is unsorted, try to place the new inclusion into the
longest sorted (but maybe be sparse) chain. From the given context it might
be somewhere before module.h or less likely after i2c.h.
> #include <linux/iio/iio.h>
...
> + /* Poll ICSR until RESULT bit is set */
> + ret = read_poll_timeout(i2c_smbus_read_byte_data, ret,
> + ret & RFD77402_ICSR_RESULT,
> + 10000, /* sleep: 10ms */
> + 100000, /* timeout: 100ms */
Instead of the noisy comments use proper multipliers
10 * USEC_PER_MSEC
10 * 10 * USEC_PER_MSEC
(yes, 10 * 10 is to distinguish between one iteration delay and the whole op
timeout.)
> + false,
> + client, RFD77402_ICSR);
> + if (ret < 0)
> goto err;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402
2026-01-01 16:17 [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Shrikant Raskar via B4 Relay
` (3 preceding siblings ...)
2026-01-01 16:17 ` [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support Shrikant Raskar via B4 Relay
@ 2026-01-02 12:26 ` Andy Shevchenko
4 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-02 12:26 UTC (permalink / raw)
To: raskar.shree97
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, skhan,
david.hunter.linux, linux-iio, devicetree, linux-kernel,
Krzysztof Kozlowski
On Thu, Jan 01, 2026 at 09:47:37PM +0530, Shrikant Raskar via B4 Relay wrote:
> This patch series adds:
> - Add RF Digital vendor prefix
> - YAML binding for RFD77402
> - Add OF device ID for enumeration via DT
> - Use kernel helper for result polling
> - Interrupt handling support
>
> These changes enable DT-based configuration and event-driven
> operation for the RFD77402 Time-of-Flight sensor.
>
> Changelog:
> - Resend the patch series as v4 since not all patches were delivered
> in v3 due to SMTP daily sending limits.
Is this a Changelog between v1 and v3/v4 or between v2 and v3/v4?
For the former, please split, for the latter please add v1 to v2.
> - Add 'Reviewed-by' tag to dt-binding patch.
> - Update commit message in OF device ID patch.
> - Update commit message in the third patch.
> - Replace rfd77402_result_polling() with read_poll_timeout().
> - Add 'struct rfd77402_data' details in kernel-doc format.
> - Arrange includes in order.
> - Add comment for completion timeout value.
> - Remove blank lines.
> - Indent the comments to code.
> - Convert mutex_init() to devm_mutex_init().
> - Remove 'IRQF_TRIGGER_FALLING' flag from devm_request_threaded_irq().
> - Drop the duplicate message.
> - Replace 'dev_info' with 'dev_dbg()'.
> - Update 'dev_id' to 'pdata' in rfd77402_interrupt_handler().
> - Drop 'interrupt mode' comment
> - Use 'if(ret)' instead of 'if(ret < 0) for consistency.
> - Use 'return i2c_smbus_write_byte_data()' in 'rfd77402_config_irq'.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support
2026-01-01 16:17 ` [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support Shrikant Raskar via B4 Relay
@ 2026-01-02 12:34 ` Andy Shevchenko
2026-01-06 0:09 ` Shrikant
0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-02 12:34 UTC (permalink / raw)
To: raskar.shree97
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, skhan,
david.hunter.linux, linux-iio, devicetree, linux-kernel
On Thu, Jan 01, 2026 at 09:47:41PM +0530, Shrikant Raskar via B4 Relay wrote:
> Add interrupt handling support to enable event-driven data acquisition
> instead of continuous polling. This improves responsiveness, reduces
> CPU overhead, and supports low-power operation by allowing the system
> to remain idle until an interrupt occurs.
...
> #include <linux/module.h>
> #include <linux/i2c.h>
> #include <linux/delay.h>
> +#include <linux/interrupt.h>
> +#include <linux/completion.h>
> #include <linux/iopoll.h>
Same comment as per previous patch. Do not add even more misordering, please.
...
> +/**
> + * struct rfd77402_data - device-specific data for the RFD77402 sensor
> + * @client: I2C client handle
> + * @lock: mutex to serialize sensor reads
> + * @completion: completion used for interrupt-driven measurements
> + * @irq_en: indicates whether interrupt mode is enabled
> + */
> struct rfd77402_data {
> struct i2c_client *client;
> - /* Serialize reads from the sensor */
> struct mutex lock;
> + struct completion completion;
> + bool irq_en;
> };
The kernel-doc conversion can be a separate patch, but I'm not insisting.
...
> +static irqreturn_t rfd77402_interrupt_handler(int irq, void *pdata)
> +{
> + struct rfd77402_data *data = pdata;
> + int ret;
> + if (!data || !data->client)
> + return IRQ_NONE;
How is this possible to be non-dead code?
> + ret = i2c_smbus_read_byte_data(data->client, RFD77402_ICSR);
> + if (ret < 0)
> + return IRQ_NONE;
> +
> + /* Check if the interrupt is from our device */
> + if (!(ret & RFD77402_ICSR_RESULT))
> + return IRQ_NONE;
> +
> + /* Signal completion of measurement */
> + complete(&data->completion);
> + return IRQ_HANDLED;
> +}
...
> +static int rfd77402_wait_for_irq(struct rfd77402_data *data)
> +{
> + int ret;
Missed blank line. Doesn't checkpatch complain?
> + /* As per datasheet, single measurement flow takes 100ms */
Please, be more specific about datasheet, i.e. which Chapter/Section (with its
number and possible name) or Table specifies this.
> + ret = wait_for_completion_timeout(&data->completion,
> + msecs_to_jiffies(100));
> + if (ret == 0)
> + return -ETIMEDOUT;
> +
> + return 0;
> +}
...
> +static int rfd77402_measure(struct rfd77402_data *data)
> {
> + struct i2c_client *client = data->client;
This (conversion to data instead of client) can be split into a separate
precursor change.a but it seems not a big deal. Up to maintainers.
...
> - /* Poll ICSR until RESULT bit is set */
> - ret = read_poll_timeout(i2c_smbus_read_byte_data, ret,
> - ret & RFD77402_ICSR_RESULT,
> - 10000, /* sleep: 10ms */
> - 100000, /* timeout: 100ms */
> - false,
> - client, RFD77402_ICSR);
> + if (data->irq_en) {
> + /* Re-initialize completion and wait for interrupt */
> + reinit_completion(&data->completion);
> + ret = rfd77402_wait_for_irq(data);
> + } else {
> + /* Poll ICSR until RESULT bit is set */
> + ret = read_poll_timeout(i2c_smbus_read_byte_data, ret,
> + ret & RFD77402_ICSR_RESULT,
> + 10000, /* sleep 10ms */
> + 100000, /* timeout 100ms */
> + false,
> + client, RFD77402_ICSR);
> + }
This is ping-pong type of change. You just introduced it a patch ago. Make sure
you don't remove/modify (too much at least) the lines that were just added.
One of the possible technique to achieve this is to use a helper function.
...
> static int rfd77402_init(struct i2c_client *client)
> {
> + struct iio_dev *indio_dev = i2c_get_clientdata(client);
> + struct rfd77402_data *data = iio_priv(indio_dev);
Can't this now take the data as above modified functon?
...
> - mutex_init(&data->lock);
> + ret = devm_mutex_init(&client->dev, &data->lock);
> + if (ret)
> + return ret;
In my opinion this deserves a separate change.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support
2026-01-02 12:34 ` Andy Shevchenko
@ 2026-01-06 0:09 ` Shrikant
0 siblings, 0 replies; 9+ messages in thread
From: Shrikant @ 2026-01-06 0:09 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, skhan,
david.hunter.linux, linux-iio, devicetree, linux-kernel
> > #include <linux/module.h>
> > #include <linux/i2c.h>
> > #include <linux/delay.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/completion.h>
> > #include <linux/iopoll.h>
>
> Same comment as per previous patch. Do not add even more misordering, please.
Will it be okay if I re-order the includes as below ?
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
> > +/**
> > + * struct rfd77402_data - device-specific data for the RFD77402 sensor
> > + * @client: I2C client handle
> > + * @lock: mutex to serialize sensor reads
> > + * @completion: completion used for interrupt-driven measurements
> > + * @irq_en: indicates whether interrupt mode is enabled
> > + */
> > struct rfd77402_data {
> > struct i2c_client *client;
> > - /* Serialize reads from the sensor */
> > struct mutex lock;
> > + struct completion completion;
> > + bool irq_en;
> > };
>
> The kernel-doc conversion can be a separate patch, but I'm not insisting.
I can split this into a separate patch within the same series.
Please let me know if you would prefer it to be handled differently.
> > +static int rfd77402_wait_for_irq(struct rfd77402_data *data)
> > +{
> > + int ret;
>
> Missed blank line. Doesn't checkpatch complain?
Checkpatch did not complain but I will add a blank line.
> > - mutex_init(&data->lock);
> > + ret = devm_mutex_init(&client->dev, &data->lock);
> > + if (ret)
> > + return ret;
>
> In my opinion this deserves a separate change.
I will add a separate patch for this within the same series.
Please let me know if you would prefer it to be handled differently
Regards,
Shrikant
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-01-06 0:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-01 16:17 [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 1/4] dt-bindings: iio: proximity: Add RF Digital RFD77402 ToF sensor Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 2/4] iio: proximity: rfd77402: Add OF device ID for enumeration via DT Shrikant Raskar via B4 Relay
2026-01-01 16:17 ` [PATCH v4 3/4] iio: proximity: rfd77402: Use kernel helper for result polling Shrikant Raskar via B4 Relay
2026-01-02 12:24 ` Andy Shevchenko
2026-01-01 16:17 ` [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support Shrikant Raskar via B4 Relay
2026-01-02 12:34 ` Andy Shevchenko
2026-01-06 0:09 ` Shrikant
2026-01-02 12:26 ` [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 Andy Shevchenko
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).