iio: resolver: ad2s1210: add reset gpio support
authorDavid Lechner <dlechner@baylibre.com>
Mon, 16 Oct 2023 15:43:09 +0000 (10:43 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 16 Nov 2023 19:10:25 +0000 (19:10 +0000)
This adds support for the optional reset gpio to the ad2s1210 resolver
driver. If the gpio is present in the device tree, it is toggled during
driver probe before the reset of the device initialization. As per the
devicetree bindings, it is expected for the gpio to configured as active
low.

Suggested-by: Michael Hennerich <Michael.Hennerich@analog.com>
Signed-off-by: David Lechner <dlechner@baylibre.com>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Link: https://lore.kernel.org/r/20231016154311.38547-1-dlechner@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/resolver/ad2s1210.c

index 8646389ec88de53b491c3513d63c0eff4852d797..a414eef12e5e317a25f856ece7f3f7326b94f1fe 100644 (file)
@@ -1426,6 +1426,7 @@ static int ad2s1210_setup_gpios(struct ad2s1210_state *st)
 {
        struct device *dev = &st->sdev->dev;
        struct gpio_descs *resolution_gpios;
+       struct gpio_desc *reset_gpio;
        DECLARE_BITMAP(bitmap, 2);
        int ret;
 
@@ -1481,6 +1482,17 @@ static int ad2s1210_setup_gpios(struct ad2s1210_state *st)
                                             "failed to set resolution gpios\n");
        }
 
+       /* If the optional reset GPIO is present, toggle it to do a hard reset. */
+       reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+       if (IS_ERR(reset_gpio))
+               return dev_err_probe(dev, PTR_ERR(reset_gpio),
+                                    "failed to request reset GPIO\n");
+
+       if (reset_gpio) {
+               udelay(10);
+               gpiod_set_value(reset_gpio, 0);
+       }
+
        return 0;
 }