From: Jonathan Cameron <jic23@kernel.org>
To: Shrikant Raskar <raskar.shree97@gmail.com>
Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
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
Subject: Re: [PATCH v2 4/4] iio: proximity: rfd77402: Add interrupt handling support
Date: Sun, 7 Dec 2025 15:58:38 +0000 [thread overview]
Message-ID: <20251207155838.5b41324e@jic23-huawei> (raw)
In-Reply-To: <20251130153712.6792-5-raskar.shree97@gmail.com>
Hi Shrikant,
I'll try not to replicate too much stuff from Andy's review.
> +static irqreturn_t rfd77402_interrupt_handler(int irq, void *dev_id)
Why dev_id? Seems unrelated to what it is which is data about the device.
> +{
> + struct rfd77402_data *data = dev_id;
> + int ret;
> +
> + 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_measure(struct i2c_client *client)
> +static int rfd77402_measure(struct rfd77402_data *data)
> {
> + struct i2c_client *client = data->client;
> int ret;
> +
Blank line should have been in patch 3. I just replied to that
having missed it whilst reading that one.
> ret = rfd77402_set_state(client, RFD77402_CMD_MCPU_ON,
> RFD77402_STATUS_MCPU_ON);
> @@ -195,8 +247,25 @@ 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 < 0)
I would use
if (ret)
here to make the next change more consistent looking.
> + return ret;
> +
> + ret = i2c_smbus_write_byte_data(client, RFD77402_IER, ier);
> + if (ret < 0)
> + return ret;
> +
> + return 0;
return i2c_smbus_write_byte_data();
is fine as it is documented as never returning anything other than negative
or 0.
> +}
> +
> 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,
> @@ -204,9 +273,25 @@ 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 (data->irq_en) {
> + /*
> + * Enable interrupt mode:
> + * - Configure ICSR for auto-clear on read, push-pull output and falling edge
> + * - Enable "result ready" interrupt in IER
> + */
Indent should match code. Will require a bit more wrapping.
> + 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 interrupt in IER
> + */
As above.
> + ret = rfd77402_config_irq(client, 0, 0);
> + }
> +
> if (ret < 0)
> return ret;
>
> @@ -283,6 +368,31 @@ static int rfd77402_probe(struct i2c_client *client)
> data = iio_priv(indio_dev);
> data->client = client;
> mutex_init(&data->lock);
> + init_completion(&data->completion);
> +
> + i2c_set_clientdata(client, indio_dev);
> +
> + data->irq_en = false;
> + if (client->irq > 0) {
> + /* interrupt mode */
Kind of obvious comment. I'd drop it.
> + ret = devm_request_threaded_irq(&client->dev, client->irq,
> + NULL, rfd77402_interrupt_handler,
> + IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
Repeating Andy here the direction is a firmware problem.
We have some historical drivers doing this which we now can't
fix as we don't know if boards need it. But no new cases should
be added.
> + "rfd77402", data);
> + if (ret < 0) {
> + dev_err(&client->dev,
> + "Failed to request IRQ %d: %d\n",
> + client->irq, ret);
> + return ret;
> + }
> +
> + data->irq_en = true;
> + dev_info(&client->dev, "Using interrupt mode\n");
dev_dbg()
> +
> + } else {
> + /* polling mode */
> + dev_info(&client->dev, "No interrupt specified, using polling mode\n");
Easy to tell from userspace with cat /proc/interrupts so no need for such a noisy print.
dev_dbg()
> + }
>
> indio_dev->info = &rfd77402_info;
> indio_dev->channels = rfd77402_channels;
prev parent reply other threads:[~2025-12-07 15:58 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 ` [PATCH v2 3/4] iio: proximity: rfd77402: Move polling logic into helper Shrikant Raskar
2025-11-30 16:52 ` 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 [this message]
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=20251207155838.5b41324e@jic23-huawei \
--to=jic23@kernel.org \
--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=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=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