]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: dac: ad5758: Add support for hard reset
authorStefan Popa <stefan.popa@analog.com>
Wed, 29 Aug 2018 14:58:42 +0000 (17:58 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 2 Sep 2018 18:01:30 +0000 (19:01 +0100)
The ad5758 has a hardware reset active low input pin. This patch adds a
devicetree entry for a reset GPIO and a new ad5758_reset() function.
During
initialization, it is checked if the reset property is specified and the
the GPIO is being asserted, therefore the device will become active.

When the reset function is called, if the gpio_reset var is set, then
the
GPIO will be toggled, otherwise a software reset is performed.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Documentation/devicetree/bindings/iio/dac/ad5758.txt
drivers/iio/dac/ad5758.c

index bba01a5cab1bad1a4ce5ca43f8fbe9ddd8fe3bf6..2f607f41f9d3139c1cebd4ef7a8c80a1abf4ea74 100644 (file)
@@ -50,6 +50,9 @@ Required properties:
 
 Optional properties:
 
+ - reset-gpios : GPIO spec for the RESET pin. If specified, it will be
+                asserted during driver probe.
+
  - adi,dc-dc-ilim-microamp: The dc-to-dc converter current limit
                   The following values are currently supported [uA]:
                        * 150000
@@ -71,6 +74,8 @@ AD5758 Example:
                spi-max-frequency = <1000000>;
                spi-cpha;
 
+               reset-gpios = <&gpio 22 0>;
+
                adi,dc-dc-mode = <2>;
                adi,range-microvolt = <0 10000000>;
                adi,dc-dc-ilim-microamp = <200000>;
index bd36333257af8bf334bedbda9012bb4f8c9a6dfb..ef41f12bf2620c7e9e163d4c272e62dfa4d90b78 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/property.h>
 #include <linux/spi/spi.h>
+#include <linux/gpio/consumer.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -108,6 +109,7 @@ struct ad5758_range {
 struct ad5758_state {
        struct spi_device *spi;
        struct mutex lock;
+       struct gpio_desc *gpio_reset;
        struct ad5758_range out_range;
        unsigned int dc_dc_mode;
        unsigned int dc_dc_ilim;
@@ -474,6 +476,21 @@ static int ad5758_internal_buffers_en(struct ad5758_state *st, bool enable)
                                             AD5758_CAL_MEM_UNREFRESHED_MSK);
 }
 
+static int ad5758_reset(struct ad5758_state *st)
+{
+       if (st->gpio_reset) {
+               gpiod_set_value(st->gpio_reset, 0);
+               usleep_range(100, 1000);
+               gpiod_set_value(st->gpio_reset, 1);
+               usleep_range(100, 1000);
+
+               return 0;
+       } else {
+               /* Perform a software reset */
+               return ad5758_soft_reset(st);
+       }
+}
+
 static int ad5758_reg_access(struct iio_dev *indio_dev,
                             unsigned int reg,
                             unsigned int writeval,
@@ -768,13 +785,18 @@ static int ad5758_init(struct ad5758_state *st)
 {
        int regval, ret;
 
+       st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset",
+                                                GPIOD_OUT_HIGH);
+       if (IS_ERR(st->gpio_reset))
+               return PTR_ERR(st->gpio_reset);
+
        /* Disable CRC checks */
        ret = ad5758_crc_disable(st);
        if (ret < 0)
                return ret;
 
-       /* Perform a software reset */
-       ret = ad5758_soft_reset(st);
+       /* Perform a reset */
+       ret = ad5758_reset(st);
        if (ret < 0)
                return ret;