From: Kim Seer Paller <kimseer.paller@analog.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: <linux-gpio@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Kim Seer Paller <kimseer.paller@analog.com>
Subject: [PATCH v2 2/2] gpio: gpio-adg1414: New driver
Date: Thu, 13 Feb 2025 21:15:10 +0800 [thread overview]
Message-ID: <20250213-for_upstream-v2-2-ec4eff3b3cd5@analog.com> (raw)
In-Reply-To: <20250213-for_upstream-v2-0-ec4eff3b3cd5@analog.com>
The ADG1414 is a 9.5 Ω RON ±15 V/+12 V/±5 V iCMOS Serially-Controlled
Octal SPST Switches
Signed-off-by: Kim Seer Paller <kimseer.paller@analog.com>
---
MAINTAINERS | 1 +
drivers/gpio/Kconfig | 10 +++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-adg1414.c | 162 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 174 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 66d92be0f57daa9eabb48d7e53b6b2bea0c40863..65877ca70b7e929353798c5639bf38593241d83e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -503,6 +503,7 @@ M: Kim Seer Paller <kimseer.paller@analog.com>
S: Supported
W: https://ez.analog.com/linux-software-drivers
F: Documentation/devicetree/bindings/gpio/gpio-adg1414.yaml
+F: drivers/gpio/gpio-adg1414.c
ADM1025 HARDWARE MONITOR DRIVER
M: Jean Delvare <jdelvare@suse.com>
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 98b4d1633b258b93d05ba66d53f647e7ec6ac364..4b797ddebd21bc879524f8504b343add2730c793 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1797,6 +1797,16 @@ config GPIO_74X164
shift registers. This driver can be used to provide access
to more GPIO outputs.
+config GPIO_ADG1414
+ tristate "ADG1414 Serially-Controlled Octal SPST Switches"
+ depends on SPI
+ help
+ Say yes here to build support for Analog Devices ADG1414
+ Serially-Controlled Octal SPST Switches
+
+ To compile this driver as a module, choose M here: the
+ module will be called gpio-adg1414.
+
config GPIO_MAX3191X
tristate "Maxim MAX3191x industrial serializer"
select CRC8
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index af3ba4d81b583842893ea69e677fbe2abf31bc7b..58d723cb32feebd35db13ae9cae5d232feba3f5b 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -24,6 +24,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_ADG1414) += gpio-adg1414.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-adg1414.c b/drivers/gpio/gpio-adg1414.c
new file mode 100644
index 0000000000000000000000000000000000000000..91e07c38fb1c86162afd9cfcdf1d7cfcccb03234
--- /dev/null
+++ b/drivers/gpio/gpio-adg1414.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ADG1414 Serially-Controlled Octal SPST Switches
+ *
+ * Copyright 2025 Analog Devices Inc.
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
+#include <linux/module.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#define ADG1414_MAX_DEVICES 4
+
+struct adg1414_state {
+ struct spi_device *spi;
+ struct gpio_chip chip;
+ struct regmap *regmap;
+ struct mutex lock; /* protect sensor state */
+ u32 buf;
+
+ __be32 tx __aligned(ARCH_DMA_MINALIGN);
+};
+
+static int adg1414_spi_write(void *context, const void *data, size_t count)
+{
+ struct adg1414_state *st = context;
+
+ struct spi_transfer xfer = {
+ .tx_buf = &st->tx,
+ .len = count,
+ };
+
+ return spi_sync_transfer(st->spi, &xfer, 1);
+}
+
+static int adg1414_spi_read(void *context, const void *reg, size_t reg_size,
+ void *val, size_t val_size)
+{
+ return 0;
+}
+
+static int adg1414_get(struct gpio_chip *chip, unsigned int offset)
+{
+ struct adg1414_state *st = gpiochip_get_data(chip);
+
+ guard(mutex)(&st->lock);
+
+ return st->buf & BIT(offset);
+}
+
+static void adg1414_set(struct gpio_chip *chip, unsigned int offset, int value)
+{
+ struct adg1414_state *st = gpiochip_get_data(chip);
+
+ guard(mutex)(&st->lock);
+
+ if (value)
+ st->buf |= BIT(offset);
+ else
+ st->buf &= ~BIT(offset);
+
+ st->tx = cpu_to_be32(st->buf << (32 - st->chip.ngpio));
+
+ adg1414_spi_write(st, 0, st->chip.ngpio / 8);
+}
+
+static const struct regmap_bus adg1414_regmap_bus = {
+ .write = adg1414_spi_write,
+ .read = adg1414_spi_read,
+ .reg_format_endian_default = REGMAP_ENDIAN_BIG,
+ .val_format_endian_default = REGMAP_ENDIAN_BIG,
+};
+
+static const struct regmap_config adg1414_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+};
+
+static int adg1414_get_direction(struct gpio_chip *chip,
+ unsigned int offset)
+{
+ return GPIO_LINE_DIRECTION_OUT;
+}
+
+static int adg1414_probe(struct spi_device *spi)
+{
+ struct device *dev = &spi->dev;
+ struct adg1414_state *st;
+ struct gpio_desc *reset;
+ u32 num_devices;
+ int ret;
+
+ st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL);
+ if (!st)
+ return -ENOMEM;
+
+ st->spi = spi;
+
+ st->regmap = devm_regmap_init(dev, &adg1414_regmap_bus, st,
+ &adg1414_regmap_config);
+ if (IS_ERR(st->regmap))
+ return dev_err_probe(dev, PTR_ERR(st->regmap),
+ "Failed to initialize regmap");
+
+ /* Use reset pin to reset the device */
+ reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(reset))
+ return dev_err_probe(dev, PTR_ERR(reset),
+ "Failed to get reset gpio");
+
+ if (reset) {
+ fsleep(1);
+ gpiod_set_value_cansleep(reset, 0);
+ }
+
+ num_devices = 1;
+ ret = device_property_read_u32(dev, "#daisy-chained-devices",
+ &num_devices);
+ if (!ret) {
+ if (!num_devices || num_devices > ADG1414_MAX_DEVICES)
+ return dev_err_probe(dev, ret,
+ "Failed to get daisy-chained-devices property\n");
+ }
+
+ st->chip.label = "adg1414";
+ st->chip.parent = dev;
+ st->chip.get_direction = adg1414_get_direction;
+ st->chip.set = adg1414_set;
+ st->chip.get = adg1414_get;
+ st->chip.base = -1;
+ st->chip.ngpio = num_devices * 8;
+ st->chip.can_sleep = true;
+
+ ret = devm_mutex_init(dev, &st->lock);
+ if (ret)
+ return ret;
+
+ return devm_gpiochip_add_data(dev, &st->chip, st);
+}
+
+static const struct of_device_id adg1414_of_match[] = {
+ { .compatible = "adi,adg1414-gpio" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, adg1414_of_match);
+
+static struct spi_driver adg1414_driver = {
+ .driver = {
+ .name = "adg1414-gpio",
+ .of_match_table = adg1414_of_match,
+ },
+ .probe = adg1414_probe,
+};
+module_spi_driver(adg1414_driver);
+
+MODULE_AUTHOR("Kim Seer Paller <kimseer.paller@analog.com>");
+MODULE_DESCRIPTION("ADG1414 Serially-Controlled Octal SPST Switches");
+MODULE_LICENSE("GPL");
--
2.34.1
next prev parent reply other threads:[~2025-02-13 13:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 13:15 [PATCH v2 0/2] Add support for ADG1414 Serially-Controlled Octal SPST Switches Kim Seer Paller
2025-02-13 13:15 ` [PATCH v2 1/2] dt-bindings: gpio: add adg1414 Kim Seer Paller
2025-02-13 16:11 ` kernel test robot
2025-02-13 18:16 ` Krzysztof Kozlowski
2025-02-14 10:42 ` Linus Walleij
2025-02-13 13:15 ` Kim Seer Paller [this message]
2025-02-13 23:25 ` [PATCH v2 2/2] gpio: gpio-adg1414: New driver Linus Walleij
2025-02-14 13:17 ` Nuno Sá
2025-02-14 23:22 ` Linus Walleij
2025-02-16 14:30 ` Jonathan Cameron
2025-02-17 7:02 ` Paller, Kim Seer
2025-02-17 9:32 ` Nuno Sá
2025-02-27 0:33 ` Linus Walleij
2025-02-15 1:12 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250213-for_upstream-v2-2-ec4eff3b3cd5@analog.com \
--to=kimseer.paller@analog.com \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.