All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] iio: ltc2983: add support for optional reset gpio
@ 2021-08-25  8:41 Nuno Sá
  2021-08-25  8:41 ` [PATCH v2 2/2] iio: ltc2983: fail probe if no channels are given Nuno Sá
  0 siblings, 1 reply; 3+ messages in thread
From: Nuno Sá @ 2021-08-25  8:41 UTC (permalink / raw)
  To: linux-iio; +Cc: Jonathan Cameron, Lars-Peter Clausen, Drew Fustini

Check if an optional reset gpio is present and if so, make sure to reset
the device.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
Changes in v2:

* Increased the 'usleep_range()' upper limit so that we get better
chances for not having an IRQ triggered by the hrtimers.

 drivers/iio/temperature/ltc2983.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
index 3b4a0e60e605..22e6a26ce6b1 100644
--- a/drivers/iio/temperature/ltc2983.c
+++ b/drivers/iio/temperature/ltc2983.c
@@ -1470,6 +1470,7 @@ static int ltc2983_probe(struct spi_device *spi)
 {
 	struct ltc2983_data *st;
 	struct iio_dev *indio_dev;
+	struct gpio_desc *gpio;
 	const char *name = spi_get_device_id(spi)->name;
 	int ret;
 
@@ -1494,6 +1495,16 @@ static int ltc2983_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
+	gpio = devm_gpiod_get_optional(&st->spi->dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpio))
+		return PTR_ERR(gpio);
+
+	if (gpio) {
+		/* bring the device out of reset */
+		usleep_range(1000, 1200);
+		gpiod_set_value_cansleep(gpio, 0);
+	}
+
 	ret = ltc2983_setup(st, true);
 	if (ret)
 		return ret;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] iio: ltc2983: fail probe if no channels are given
  2021-08-25  8:41 [PATCH v2 1/2] iio: ltc2983: add support for optional reset gpio Nuno Sá
@ 2021-08-25  8:41 ` Nuno Sá
  2021-08-30 11:05   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Nuno Sá @ 2021-08-25  8:41 UTC (permalink / raw)
  To: linux-iio
  Cc: Jonathan Cameron, Lars-Peter Clausen, Drew Fustini, Alexandru Ardelean

If there are no channels defined in the devicetree, there's no point in
probing the device. We were actually requesting a zero sized 'kmalloc'
array but since we were not touching the ZERO_SIZE_PTR afterwards,
nothing bad was actually happening. Hence this is not really a fix but
rather an improvement.

Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
Nothing changed in v2.

 drivers/iio/temperature/ltc2983.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
index 22e6a26ce6b1..301c3f13fb26 100644
--- a/drivers/iio/temperature/ltc2983.c
+++ b/drivers/iio/temperature/ltc2983.c
@@ -1275,6 +1275,11 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
 			     &st->filter_notch_freq);
 
 	st->num_channels = of_get_available_child_count(dev->of_node);
+	if (!st->num_channels) {
+		dev_err(&st->spi->dev, "At least one channel must be given!");
+		return -EINVAL;
+	}
+
 	st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors),
 				   GFP_KERNEL);
 	if (!st->sensors)
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 2/2] iio: ltc2983: fail probe if no channels are given
  2021-08-25  8:41 ` [PATCH v2 2/2] iio: ltc2983: fail probe if no channels are given Nuno Sá
@ 2021-08-30 11:05   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2021-08-30 11:05 UTC (permalink / raw)
  To: Nuno Sá
  Cc: linux-iio, Lars-Peter Clausen, Drew Fustini, Alexandru Ardelean

On Wed, 25 Aug 2021 10:41:49 +0200
Nuno Sá <nuno.sa@analog.com> wrote:

> If there are no channels defined in the devicetree, there's no point in
> probing the device. We were actually requesting a zero sized 'kmalloc'
> array but since we were not touching the ZERO_SIZE_PTR afterwards,
> nothing bad was actually happening. Hence this is not really a fix but
> rather an improvement.
> 
> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Both applied.

Thanks,

J
> ---
> Nothing changed in v2.
> 
>  drivers/iio/temperature/ltc2983.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
> index 22e6a26ce6b1..301c3f13fb26 100644
> --- a/drivers/iio/temperature/ltc2983.c
> +++ b/drivers/iio/temperature/ltc2983.c
> @@ -1275,6 +1275,11 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
>  			     &st->filter_notch_freq);
>  
>  	st->num_channels = of_get_available_child_count(dev->of_node);
> +	if (!st->num_channels) {
> +		dev_err(&st->spi->dev, "At least one channel must be given!");
> +		return -EINVAL;
> +	}
> +
>  	st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors),
>  				   GFP_KERNEL);
>  	if (!st->sensors)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-30 11:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25  8:41 [PATCH v2 1/2] iio: ltc2983: add support for optional reset gpio Nuno Sá
2021-08-25  8:41 ` [PATCH v2 2/2] iio: ltc2983: fail probe if no channels are given Nuno Sá
2021-08-30 11:05   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.