[PATCH 3/3] iio: adc: mcp3911: add reset management

Marcus Folkesson posted 3 patches 7 months, 4 weeks ago
There is a newer version of this series
[PATCH 3/3] iio: adc: mcp3911: add reset management
Posted by Marcus Folkesson 7 months, 4 weeks ago
Add support for optional HW reset.
If specified, a reset will be asserted during driver probe.

Co-developed-by: Lukas Rauber <lukas.rauber@janitza.de>
Signed-off-by: Lukas Rauber <lukas.rauber@janitza.de>
Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
---
 drivers/iio/adc/mcp3911.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c
index b72ed4928da88664a00dc143ebf218cb4a7be421..4c04ce1b3982d84286355ee427a92aa55ff2fc51 100644
--- a/drivers/iio/adc/mcp3911.c
+++ b/drivers/iio/adc/mcp3911.c
@@ -11,6 +11,7 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/err.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/mod_devicetable.h>
 #include <linux/property.h>
@@ -706,6 +707,7 @@ static const struct iio_trigger_ops mcp3911_trigger_ops = {
 static int mcp3911_probe(struct spi_device *spi)
 {
 	struct device *dev = &spi->dev;
+	struct gpio_desc *gpio_reset;
 	struct iio_dev *indio_dev;
 	struct mcp3911 *adc;
 	bool external_vref;
@@ -750,6 +752,21 @@ static int mcp3911_probe(struct spi_device *spi)
 	}
 	dev_dbg(dev, "use device address %i\n", adc->dev_addr);
 
+	gpio_reset = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpio_reset))
+		return dev_err_probe(dev, PTR_ERR(gpio_reset),
+				     "Cannot get reset GPIO\n");
+
+	if (gpio_reset) {
+		gpiod_set_value_cansleep(gpio_reset, 0);
+		dev_dbg(dev, "gpio reset de-asserted.\n");
+
+		/* Settling time after Hard Reset Mode (determined experimentally):
+		 *  330 micro-seconds are too few; 470 micro-seconds are sufficient.
+		 * Just in case, we add some safety factor... */
+		fsleep(680);
+	}
+
 	ret = adc->chip->config(adc, external_vref);
 	if (ret)
 		return ret;

-- 
2.49.0
Re: [PATCH 3/3] iio: adc: mcp3911: add reset management
Posted by Andy Shevchenko 7 months, 4 weeks ago
On Wed, Apr 23, 2025 at 04:46:51PM +0200, Marcus Folkesson wrote:
> Add support for optional HW reset.
> If specified, a reset will be asserted during driver probe.

...

> +		return dev_err_probe(dev, PTR_ERR(gpio_reset),
> +				     "Cannot get reset GPIO\n");

+ dev_printk.h

...

> +		dev_dbg(dev, "gpio reset de-asserted.\n");

How useful is this?

...

> +		/* Settling time after Hard Reset Mode (determined experimentally):
> +		 *  330 micro-seconds are too few; 470 micro-seconds are sufficient.
> +		 * Just in case, we add some safety factor... */

/*
 * Please, fix the nulti-line comment
 * style. This one can serve you as an
 * example.
 */

> +		fsleep(680);

Why not simply 500? or 600?


-- 
With Best Regards,
Andy Shevchenko