From: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Francesco Dolcini <francesco.dolcini@toradex.com>,
linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
Subject: [PATCH 5/5] gpio: fxl6408: Add interrupt controller support
Date: Thu, 26 Nov 2026 19:03:15 +0100 [thread overview]
Message-ID: <20261126180315.98034-6-gianfranco.mariotti94@gmail.com> (raw)
In-Reply-To: <20261126180315.98034-1-gianfranco.mariotti94@gmail.com>
The FXL6408 and PI4IOE5V6408 GPIO expanders feature an open-drain
active-low interrupt output asserted when an unmasked input transitions
away from the state programmed in INPUT_DEFAULT_STATE (register 0x09).
Reading INT_STS (register 0x13) clears all latched interrupt status bits
and releases the INT line, requiring the input to return to its default
state before another interrupt is generated.
Wire up interrupt controller support via regmap-irq and gpio-regmap for
rising and falling edge triggers, mark the clear-on-read registers
(DEVICE_ID and INT_STS) as precious, and clear RST_INT on system resume
in case power was lost during suspend.
Signed-off-by: Gianfranco Mariotti <gianfranco.mariotti94@gmail.com>
---
drivers/gpio/Kconfig | 2 +
drivers/gpio/gpio-fxl6408.c | 101 ++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 0e197fd2bd6d2..a622cee9df1bd 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1204,8 +1204,10 @@ config GPIO_ADNP
config GPIO_FXL6408
tristate "FXL6408 I2C GPIO expander"
+ select GPIOLIB_IRQCHIP
select GPIO_REGMAP
select REGMAP_I2C
+ select REGMAP_IRQ
help
GPIO driver for Fairchild Semiconductor FXL6408 GPIO expander.
diff --git a/drivers/gpio/gpio-fxl6408.c b/drivers/gpio/gpio-fxl6408.c
index ae9003fc513a1..d503383fb119b 100644
--- a/drivers/gpio/gpio-fxl6408.c
+++ b/drivers/gpio/gpio-fxl6408.c
@@ -13,11 +13,14 @@
#include <linux/gpio/consumer.h>
#include <linux/gpio/regmap.h>
#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pinctrl/pinconf-generic.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
#define FXL6408_REG_DEVICE_ID 0x01
#define FXL6408_MF_FAIRCHILD 0b101
@@ -35,6 +38,12 @@
/* Bits here make the output High-Z, instead of the OUTPUT value. */
#define FXL6408_REG_OUTPUT_HIGH_Z 0x07
+/*
+ * Bits here define the expected input state of the GPIO.
+ * INT_STS bits are set when the input transitions away from this value.
+ */
+#define FXL6408_REG_INPUT_DEFAULT_STATE 0x09
+
/* Bits here enable either pull-up or pull-down according to FXL6408_REG_PULL_UP. */
#define FXL6408_REG_PULL_ENABLE 0x0b
@@ -44,6 +53,9 @@
/* Returns the current status (1 = HIGH) of the input pins. */
#define FXL6408_REG_INPUT_STATUS 0x0f
+/* Bits set here mask (disable) interrupts from the corresponding input pins. */
+#define FXL6408_REG_INT_MASK 0x11
+
/*
* Return the current interrupt status
* This bit is HIGH if input GPIO != default state (register 09h).
@@ -59,9 +71,12 @@ static const struct regmap_range rd_range[] = {
{ FXL6408_REG_IO_DIR, FXL6408_REG_IO_DIR },
{ FXL6408_REG_OUTPUT, FXL6408_REG_OUTPUT },
{ FXL6408_REG_OUTPUT_HIGH_Z, FXL6408_REG_OUTPUT_HIGH_Z },
+ { FXL6408_REG_INPUT_DEFAULT_STATE, FXL6408_REG_INPUT_DEFAULT_STATE },
{ FXL6408_REG_PULL_ENABLE, FXL6408_REG_PULL_ENABLE },
{ FXL6408_REG_PULL_UP, FXL6408_REG_PULL_UP },
{ FXL6408_REG_INPUT_STATUS, FXL6408_REG_INPUT_STATUS },
+ { FXL6408_REG_INT_MASK, FXL6408_REG_INT_MASK },
+ { FXL6408_REG_INT_STS, FXL6408_REG_INT_STS },
};
static const struct regmap_range wr_range[] = {
@@ -69,13 +84,21 @@ static const struct regmap_range wr_range[] = {
{ FXL6408_REG_IO_DIR, FXL6408_REG_IO_DIR },
{ FXL6408_REG_OUTPUT, FXL6408_REG_OUTPUT },
{ FXL6408_REG_OUTPUT_HIGH_Z, FXL6408_REG_OUTPUT_HIGH_Z },
+ { FXL6408_REG_INPUT_DEFAULT_STATE, FXL6408_REG_INPUT_DEFAULT_STATE },
{ FXL6408_REG_PULL_ENABLE, FXL6408_REG_PULL_ENABLE },
{ FXL6408_REG_PULL_UP, FXL6408_REG_PULL_UP },
+ { FXL6408_REG_INT_MASK, FXL6408_REG_INT_MASK },
};
static const struct regmap_range volatile_range[] = {
{ FXL6408_REG_DEVICE_ID, FXL6408_REG_DEVICE_ID },
{ FXL6408_REG_INPUT_STATUS, FXL6408_REG_INPUT_STATUS },
+ { FXL6408_REG_INT_STS, FXL6408_REG_INT_STS },
+};
+
+static const struct regmap_range precious_range[] = {
+ { FXL6408_REG_DEVICE_ID, FXL6408_REG_DEVICE_ID },
+ { FXL6408_REG_INT_STS, FXL6408_REG_INT_STS },
};
static const struct regmap_access_table rd_table = {
@@ -93,6 +116,11 @@ static const struct regmap_access_table volatile_table = {
.n_yes_ranges = ARRAY_SIZE(volatile_range),
};
+static const struct regmap_access_table precious_table = {
+ .yes_ranges = precious_range,
+ .n_yes_ranges = ARRAY_SIZE(precious_range),
+};
+
static const struct regmap_config regmap = {
.reg_bits = 8,
.val_bits = 8,
@@ -103,11 +131,53 @@ static const struct regmap_config regmap = {
.wr_table = &wr_table,
.rd_table = &rd_table,
.volatile_table = &volatile_table,
+ .precious_table = &precious_table,
.cache_type = REGCACHE_MAPLE,
.num_reg_defaults_raw = FXL6408_REG_INT_STS + 1,
};
+static const unsigned int fxl6408_irq_config_base[] = {
+ FXL6408_REG_INPUT_DEFAULT_STATE,
+};
+
+#define FXL6408_REGMAP_IRQ(_n) \
+ [_n] = { \
+ .mask = BIT(_n), \
+ .type = { \
+ .types_supported = IRQ_TYPE_SENSE_MASK, \
+ }, \
+ }
+
+static const struct regmap_irq fxl6408_regmap_irqs[FXL6408_NGPIO] = {
+ FXL6408_REGMAP_IRQ(0),
+ FXL6408_REGMAP_IRQ(1),
+ FXL6408_REGMAP_IRQ(2),
+ FXL6408_REGMAP_IRQ(3),
+ FXL6408_REGMAP_IRQ(4),
+ FXL6408_REGMAP_IRQ(5),
+ FXL6408_REGMAP_IRQ(6),
+ FXL6408_REGMAP_IRQ(7),
+};
+
+static int fxl6408_irq_set_type_config(unsigned int **buf, unsigned int type,
+ const struct regmap_irq *irq_data,
+ int idx, void *irq_drv_data)
+{
+ switch (type) {
+ case IRQ_TYPE_EDGE_FALLING:
+ buf[0][idx] |= irq_data->mask;
+ break;
+ case IRQ_TYPE_EDGE_RISING:
+ buf[0][idx] &= ~irq_data->mask;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int fxl6408_gpio_set_config(struct gpio_regmap *gpio,
struct gpio_chip *chip,
unsigned int offset, unsigned long config)
@@ -206,12 +276,43 @@ static int fxl6408_probe(struct i2c_client *client)
if (ret)
return dev_err_probe(dev, ret, "failed to write 'output high Z' register\n");
+ if (client->irq > 0) {
+ struct regmap_irq_chip *irq_chip;
+
+ irq_chip = devm_kzalloc_obj(dev, *irq_chip);
+ if (!irq_chip)
+ return -ENOMEM;
+
+ irq_chip->name = dev_name(dev);
+ irq_chip->status_base = FXL6408_REG_INT_STS;
+ irq_chip->mask_base = FXL6408_REG_INT_MASK;
+ irq_chip->config_base = fxl6408_irq_config_base;
+ irq_chip->num_config_bases = ARRAY_SIZE(fxl6408_irq_config_base);
+ irq_chip->num_config_regs = 1;
+ irq_chip->num_regs = 1;
+ irq_chip->irqs = fxl6408_regmap_irqs;
+ irq_chip->num_irqs = ARRAY_SIZE(fxl6408_regmap_irqs);
+ irq_chip->init_ack_masked = true;
+ irq_chip->clear_on_unmask = true;
+ irq_chip->set_type_config = fxl6408_irq_set_type_config;
+
+ gpio_config.regmap_irq_chip = irq_chip;
+ gpio_config.regmap_irq_line = client->irq;
+ gpio_config.regmap_irq_flags = IRQF_ONESHOT | IRQF_SHARED;
+ }
+
return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config));
}
static int fxl6408_resume(struct device *dev)
{
struct regmap *regmap = dev_get_drvdata(dev);
+ int val, ret;
+
+ /* Clear RST_INT in case power was lost during suspend. */
+ ret = regmap_read(regmap, FXL6408_REG_DEVICE_ID, &val);
+ if (ret)
+ return ret;
regcache_mark_dirty(regmap);
return regcache_sync(regmap);
--
2.25.1
prev parent reply other threads:[~2026-11-26 18:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 18:03 [PATCH 0/5] gpio: fxl6408: Fix regmap ranges/bursts and add PI4IOE5V6408, reset, bias, and IRQ support Gianfranco Mariotti
2026-11-26 18:03 ` [PATCH 1/5] gpio: fxl6408: Fix reserved register access and disable burst transfers Gianfranco Mariotti
2026-11-26 18:03 ` [PATCH 2/5] dt-bindings: gpio: Split fcs,fxl6408 from trivial-gpio and add diodes,pi4ioe5v6408 Gianfranco Mariotti
2026-11-26 18:03 ` [PATCH 3/5] gpio: fxl6408: Support optional power supplies and reset GPIO Gianfranco Mariotti
2026-11-26 18:03 ` [PATCH 4/5] gpio: fxl6408: Add pull-up and pull-down bias configuration Gianfranco Mariotti
2026-11-26 18:03 ` Gianfranco Mariotti [this message]
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=20261126180315.98034-6-gianfranco.mariotti94@gmail.com \
--to=gianfranco.mariotti94@gmail.com \
--cc=andy.shevchenko@gmail.com \
--cc=brgl@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=emanuele.ghidoli@toradex.com \
--cc=francesco.dolcini@toradex.com \
--cc=krzk+dt@kernel.org \
--cc=linusw@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®