From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: raskar.shree97@gmail.com
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
skhan@linuxfoundation.org, david.hunter.linux@gmail.com,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 4/4] iio: proximity: rfd77402: Add interrupt handling support
Date: Fri, 2 Jan 2026 14:34:16 +0200 [thread overview]
Message-ID: <aVe7SP914oI-jAam@smile.fi.intel.com> (raw)
In-Reply-To: <20260101-b4-rfd77402_irq-v4-4-42cd54359e9f@gmail.com>
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
next prev parent reply other threads:[~2026-01-02 12:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-01-06 0:09 ` Shrikant
2026-01-06 20:47 ` Andy Shevchenko
2026-01-02 12:26 ` [PATCH v4 0/4] iio: proximity: Add interrupt support for RFD77402 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=aVe7SP914oI-jAam@smile.fi.intel.com \
--to=andriy.shevchenko@intel.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=jic23@kernel.org \
--cc=krzk+dt@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=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;
as well as URLs for NNTP newsgroup(s).