[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251108174055.3665-3-antoniu.miclaus@analog.com>
Date: Sat, 8 Nov 2025 17:40:29 +0000
From: Antoniu Miclaus <antoniu.miclaus@...log.com>
To: Linus Walleij <linus.walleij@...aro.org>,
Bartosz Golaszewski
<brgl@...ev.pl>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski
<krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, <linux-gpio@...r.kernel.org>,
<devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC: Antoniu Miclaus <antoniu.miclaus@...log.com>
Subject: [PATCH v2 2/2] gpio: adg1712: add driver support
Add driver support for the ADG1712, which contains four independent
single-pole/single-throw (SPST) switches and operates with a
low-voltage single supply range from +1.08V to +5.5V or a low-voltage
dual supply range from ±1.08V to ±2.75V.
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@...log.com>
---
Changes in v2:
- Replace individual GPIO descriptors array with gpio_descs structure
- Use devm_gpiod_get_array() instead of individual devm_gpiod_get() calls
- Use GPIOD_ASIS flag to preserve current GPIO states instead of GPIOD_OUT_LOW
- Remove unnecessary direction_input and direction_output callbacks for output-only device
- Remove unnecessary offset bounds checking (handled by GPIO core)
- Return result from gpiod_set_value_cansleep() instead of always returning 0
- Optimize set_multiple() to use gpiod_set_array_value_cansleep() for bulk operations
- Change dev_info() to dev_dbg() for registration message
- Simplify probe function by eliminating the GPIO setup loop
---
drivers/gpio/Kconfig | 9 +++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-adg1712.c | 119 ++++++++++++++++++++++++++++++++++++
3 files changed, 129 insertions(+)
create mode 100644 drivers/gpio/gpio-adg1712.c
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 7ee3afbc2b05..3fac05823eae 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -157,6 +157,15 @@ config GPIO_74XX_MMIO
8 bits: 74244 (Input), 74273 (Output)
16 bits: 741624 (Input), 7416374 (Output)
+config GPIO_ADG1712
+ tristate "Analog Devices ADG1712 quad SPST switch GPIO driver"
+ depends on GPIOLIB
+ help
+ GPIO driver for Analog Devices ADG1712 quad single-pole,
+ single-throw (SPST) switch. The driver provides a GPIO controller
+ interface where each GPIO line controls one of the four independent
+ analog switches on the ADG1712.
+
config GPIO_ALTERA
tristate "Altera GPIO"
select GPIOLIB_IRQCHIP
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index ec296fa14bfd..9043d2d07a15 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o
obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o
obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o
obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.o
+obj-$(CONFIG_GPIO_ADG1712) += gpio-adg1712.o
obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o
obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
obj-$(CONFIG_GPIO_ADP5585) += gpio-adp5585.o
diff --git a/drivers/gpio/gpio-adg1712.c b/drivers/gpio/gpio-adg1712.c
new file mode 100644
index 000000000000..092dc459c7e8
--- /dev/null
+++ b/drivers/gpio/gpio-adg1712.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices ADG1712 quad SPST switch GPIO driver
+ *
+ * Copyright 2025 Analog Devices Inc.
+ *
+ * Author: Antoniu Miclaus <antoniu.miclaus@...log.com>
+ */
+
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+
+#define ADG1712_NUM_GPIOS 4
+
+struct adg1712 {
+ struct gpio_chip chip;
+ struct gpio_descs *switch_gpios;
+};
+
+static int adg1712_get_direction(struct gpio_chip *chip, unsigned int offset)
+{
+ return GPIO_LINE_DIRECTION_OUT;
+}
+
+static int adg1712_set(struct gpio_chip *chip, unsigned int offset, int value)
+{
+ struct adg1712 *adg1712 = gpiochip_get_data(chip);
+
+ return gpiod_set_value_cansleep(adg1712->switch_gpios->desc[offset],
+ value);
+}
+
+static int adg1712_get(struct gpio_chip *chip, unsigned int offset)
+{
+ struct adg1712 *adg1712 = gpiochip_get_data(chip);
+
+ return gpiod_get_value_cansleep(adg1712->switch_gpios->desc[offset]);
+}
+
+static int adg1712_set_multiple(struct gpio_chip *chip, unsigned long *mask,
+ unsigned long *bits)
+{
+ struct adg1712 *adg1712 = gpiochip_get_data(chip);
+
+ return gpiod_set_array_value_cansleep(adg1712->switch_gpios->ndescs,
+ adg1712->switch_gpios->desc,
+ adg1712->switch_gpios->info,
+ bits);
+}
+
+static const struct gpio_chip adg1712_gpio_chip = {
+ .label = "adg1712",
+ .owner = THIS_MODULE,
+ .get_direction = adg1712_get_direction,
+ .get = adg1712_get,
+ .set = adg1712_set,
+ .set_multiple = adg1712_set_multiple,
+ .base = -1,
+ .ngpio = ADG1712_NUM_GPIOS,
+ .can_sleep = true,
+};
+
+static int adg1712_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct adg1712 *adg1712;
+ int ret;
+
+ adg1712 = devm_kzalloc(dev, sizeof(*adg1712), GFP_KERNEL);
+ if (!adg1712)
+ return -ENOMEM;
+
+ adg1712->chip = adg1712_gpio_chip;
+ adg1712->chip.parent = dev;
+
+ adg1712->switch_gpios = devm_gpiod_get_array(dev, "switch", GPIOD_ASIS);
+ if (IS_ERR(adg1712->switch_gpios))
+ return dev_err_probe(dev, PTR_ERR(adg1712->switch_gpios),
+ "failed to get switch gpios\n");
+
+ if (adg1712->switch_gpios->ndescs != ADG1712_NUM_GPIOS)
+ return dev_err_probe(dev, -EINVAL,
+ "expected %d gpios, got %d\n",
+ ADG1712_NUM_GPIOS,
+ adg1712->switch_gpios->ndescs);
+
+ ret = devm_gpiochip_add_data(dev, &adg1712->chip, adg1712);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to add gpio chip\n");
+
+ dev_dbg(dev, "ADG1712 %u-GPIO expander registered\n",
+ adg1712->chip.ngpio);
+
+ return 0;
+}
+
+static const struct of_device_id adg1712_dt_ids[] = {
+ { .compatible = "adi,adg1712", },
+ { }
+};
+MODULE_DEVICE_TABLE(of, adg1712_dt_ids);
+
+static struct platform_driver adg1712_driver = {
+ .driver = {
+ .name = "adg1712",
+ .of_match_table = adg1712_dt_ids,
+ },
+ .probe = adg1712_probe,
+};
+module_platform_driver(adg1712_driver);
+
+MODULE_DESCRIPTION("Analog Devices ADG1712 quad SPST switch GPIO driver");
+MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@...log.com>");
+MODULE_LICENSE("GPL");
--
2.43.0
Powered by blists - more mailing lists