[PATCH v3 10/14] iio: adc: ad7768: Register GPIO auxiliary device

From: Janani Sunil

Date: Thu Aug 13 2026 - 10:04:21 EST


Register an auxiliary device when the AD7768 is described as a GPIO
controller. This allows the GPIO driver to share the parent regmap and
runtime power-management state.

Signed-off-by: Janani Sunil <janani.sunil@xxxxxxxxxx>
---
drivers/iio/adc/ad7768.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/drivers/iio/adc/ad7768.c b/drivers/iio/adc/ad7768.c
index d7151b1fa863..6df219610b65 100644
--- a/drivers/iio/adc/ad7768.c
+++ b/drivers/iio/adc/ad7768.c
@@ -6,6 +6,7 @@
*/

#include <linux/array_size.h>
+#include <linux/auxiliary_bus.h>
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/cleanup.h>
@@ -1209,6 +1210,27 @@ static void ad7768_set_available_sampl_freq(struct ad7768_state *st)
}
}

+static int ad7768_gpio_adev_init(struct ad7768_state *st)
+{
+ struct device *dev = regmap_get_device(st->regmap);
+ struct spi_device *spi = to_spi_device(dev);
+ struct auxiliary_device *adev;
+ int id;
+
+ if (!device_property_read_bool(dev, "gpio-controller"))
+ return 0;
+
+ /* Use the SPI bus number and chip select to derive a stable per-device ID. */
+ id = (spi->controller->bus_num << 8) | spi_get_chipselect(spi, 0);
+ adev = __devm_auxiliary_device_create(dev, KBUILD_MODNAME, "gpio",
+ NULL, id);
+ if (!adev)
+ return dev_err_probe(dev, -ENODEV,
+ "Failed to create GPIO auxiliary device\n");
+
+ return 0;
+}
+
static int ad7768_set_filter_mode(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan,
unsigned int mode)
@@ -1585,6 +1607,10 @@ static int ad7768_probe(struct spi_device *spi)

indio_dev->setup_ops = &ad7768_buffer_ops;

+ ret = ad7768_gpio_adev_init(st);
+ if (ret)
+ return ret;
+
ret = devm_iio_device_register(dev, indio_dev);
if (ret)
return ret;

--
2.43.0