]> www.infradead.org Git - users/willy/xarray.git/commitdiff
iio: addac: ad74413r: drop reset_gpio from struct ad74413r_state
authorNuno Sa <nuno.sa@analog.com>
Wed, 16 Oct 2024 14:21:59 +0000 (16:21 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 21 Oct 2024 18:19:25 +0000 (19:19 +0100)
We just need the reset gpio during probe so there's no need to keep it
in our state struct. Hence, move devm_gpiod_get_optional() into
ad74413r_reset() and use a local struct gpio_desc.

While at it, request the gpio in the asserted state (GPIOD_OUT_HIGH) so
that we already perform the reset while requesting the gpio saving us a
call to gpiod_set_value_cansleep().

Also, explicitly include <gpio/consumer.h> for
devm_gpiod_get_optional().

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20241016-dev-ad74413r-minor-improv-v1-1-13c9c769237d@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/addac/ad74413r.c

index e50c896a076683f2594443b8d67276fc0f9860ca..550e2460e29ca007ef608f7e6b43f8f4a4d56718 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/crc8.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
 #include <linux/iio/buffer.h>
 #include <linux/iio/iio.h>
@@ -72,7 +73,6 @@ struct ad74413r_state {
        struct regmap                   *regmap;
        struct device                   *dev;
        struct iio_trigger              *trig;
-       struct gpio_desc                *reset_gpio;
 
        size_t                  adc_active_channels;
        struct spi_message      adc_samples_msg;
@@ -407,12 +407,16 @@ static int ad74413r_gpio_set_comp_config(struct gpio_chip *chip,
 
 static int ad74413r_reset(struct ad74413r_state *st)
 {
+       struct gpio_desc *reset_gpio;
        int ret;
 
-       if (st->reset_gpio) {
-               gpiod_set_value_cansleep(st->reset_gpio, 1);
+       reset_gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_HIGH);
+       if (IS_ERR(reset_gpio))
+               return PTR_ERR(reset_gpio);
+
+       if (reset_gpio) {
                fsleep(50);
-               gpiod_set_value_cansleep(st->reset_gpio, 0);
+               gpiod_set_value_cansleep(reset_gpio, 0);
                return 0;
        }
 
@@ -1378,10 +1382,6 @@ static int ad74413r_probe(struct spi_device *spi)
        if (IS_ERR(st->regmap))
                return PTR_ERR(st->regmap);
 
-       st->reset_gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_LOW);
-       if (IS_ERR(st->reset_gpio))
-               return PTR_ERR(st->reset_gpio);
-
        st->refin_reg = devm_regulator_get(st->dev, "refin");
        if (IS_ERR(st->refin_reg))
                return dev_err_probe(st->dev, PTR_ERR(st->refin_reg),