public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Siratul Islam <email@sirat.me>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/2] iio: proximity: add driver for ST VL53L1X ToF sensor
Date: Sat, 21 Mar 2026 17:21:51 +0000	[thread overview]
Message-ID: <20260321172151.1f434680@jic23-huawei> (raw)
In-Reply-To: <20260319190738.151614-3-email@sirat.me>

On Fri, 20 Mar 2026 01:07:14 +0600
Siratul Islam <email@sirat.me> wrote:

> Add support for the STMicroelectronics VL53L1X Time-of-Flight
> ranging sensor with I2C interface.
> 
> Signed-off-by: Siratul Islam <email@sirat.me>
Hi Siratul

Just a few minor things seeing as you are going to v7 anyway.
If you weren't I'd have applied some or maybe all of these as tweaks
whilst picking the driver up.

thanks,

Jonathan

> diff --git a/drivers/iio/proximity/vl53l1x-i2c.c b/drivers/iio/proximity/vl53l1x-i2c.c
> new file mode 100644
> index 000000000000..771598b92e04
> --- /dev/null
> +++ b/drivers/iio/proximity/vl53l1x-i2c.c
> @@ -0,0 +1,820 @@


> +static irqreturn_t vl53l1x_trigger_handler(int irq, void *priv)
> +{
> +	struct iio_poll_func *pf = priv;
> +	struct iio_dev *indio_dev = pf->indio_dev;
> +	struct vl53l1x_data *data = iio_priv(indio_dev);
> +	struct {
> +		u16 distance;
> +		aligned_s64 timestamp;
> +	} scan = {};
> +	unsigned int range_status;
> +	int ret;
> +
> +	ret = regmap_read(data->regmap, VL53L1X_RESULT__RANGE_STATUS,
> +			  &range_status);
> +	if (ret)
> +		goto notify_and_clear_irq;
> +	if (FIELD_GET(VL53L1X_RANGE_STATUS_MASK, range_status) !=
> +		      VL53L1X_RANGE_STATUS_VALID)
> +		goto notify_and_clear_irq;
> +
> +	ret = vl53l1x_read_u16(data,
> +			       VL53L1X_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0,
> +			       &scan.distance);
> +	if (ret)
> +		goto notify_and_clear_irq;
> +
> +	iio_push_to_buffers_with_timestamp(indio_dev, &scan,
> +					   iio_get_time_ns(indio_dev));

Use iio_push_to_buffers_with_ts() that also takes the size of the buffer
as a parameter.  That defends against mismatch in channel spec and the
buffer provided.  Can help catch some types of bugs.

> +
> +notify_and_clear_irq:
> +	iio_trigger_notify_done(indio_dev->trig);
> +	vl53l1x_clear_irq(data);
> +
> +	return IRQ_HANDLED;
> +}


> +static int vl53l1x_configure_irq(struct device *dev, int irq,
> +				 struct iio_dev *indio_dev)
> +{
> +	struct vl53l1x_data *data = iio_priv(indio_dev);
> +	int ret;
> +
> +	ret = devm_request_irq(dev, irq, vl53l1x_irq_handler, IRQF_NO_THREAD,
> +			       indio_dev->name, indio_dev);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_write(data->regmap, VL53L1X_SYSTEM__INTERRUPT_CONFIG_GPIO,
> +			   VL53L1X_INT_NEW_SAMPLE_READY);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +				     "failed to configure IRQ\n");

Andy already pointed out that easily fits on oneline.


> +
> +	return 0;
> +}
> +
> +static int vl53l1x_probe(struct i2c_client *client)
> +{
> +	struct device *dev = &client->dev;
> +	struct vl53l1x_data *data;
> +	struct iio_dev *indio_dev;
> +	int ret;
> +
> +	if (!i2c_check_functionality(client->adapter,
> +				     I2C_FUNC_SMBUS_READ_I2C_BLOCK |
> +				     I2C_FUNC_SMBUS_BYTE_DATA))
> +		return -EOPNOTSUPP;
> +
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> +	if (!indio_dev)
> +		return -ENOMEM;
> +
> +	data = iio_priv(indio_dev);
> +	data->irq = client->irq;
> +
> +	data->regmap = devm_regmap_init_i2c(client, &vl53l1x_regmap_config);
> +	if (IS_ERR(data->regmap))
> +		return dev_err_probe(dev, PTR_ERR(data->regmap),
> +				     "regmap initialization failed\n");
> +
> +	/*
> +	 * vdd-supply is required in the DT binding but we
> +	 * continue if it is missing to support older DTs.

Given the driver does nothing different for an auto provided fake regulator
and one from DT, I'm not seeing the comment as particularly useful.

Drop it.

> +	 */
> +	data->vdd_supply = devm_regulator_get(dev, "vdd");
> +	if (IS_ERR(data->vdd_supply))
> +		return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
> +				     "Unable to get VDD regulator\n");


  parent reply	other threads:[~2026-03-21 17:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19 19:07 [PATCH v6 0/2] iio: proximity: add driver for ST VL53L1X ToF sensor Siratul Islam
2026-03-19 19:07 ` [PATCH v6 1/2] dt-bindings: iio: proximity: add " Siratul Islam
2026-03-20  9:05   ` Krzysztof Kozlowski
2026-03-20 12:10     ` Sirat
2026-03-20 12:44       ` Krzysztof Kozlowski
2026-03-20 12:52   ` Krzysztof Kozlowski
2026-03-20 13:28     ` Sirat
2026-03-21 10:00       ` Krzysztof Kozlowski
2026-03-19 19:07 ` [PATCH v6 2/2] iio: proximity: add driver for " Siratul Islam
2026-03-20  8:38   ` Andy Shevchenko
2026-03-21 17:09   ` David Lechner
2026-03-21 22:39     ` Sirat
2026-03-22  0:37       ` David Lechner
2026-03-22 11:03         ` Jonathan Cameron
2026-03-22 13:52           ` Sirat
2026-03-24 15:17             ` Sirat
2026-03-24 17:29               ` David Lechner
2026-03-24 18:04                 ` Sirat
2026-03-21 17:21   ` Jonathan Cameron [this message]
2026-03-21 23:40     ` Sirat
2026-03-22  0:39       ` David Lechner

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=20260321172151.1f434680@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=email@sirat.me \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.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