[PATCH] pinctrl: ocelot: support GPIO interrupts behind a sleeping bus

From: Jens Emil Schulz Østergaard

Date: Fri Nov 27 2026 - 05:41:56 EST


When the regmap sits on a bus that can sleep, as for VSC7512 or lan9645x
attached over SPI, the driver registers no irqchip, so consumers such as
sfp have to poll their GPIOs.

Register a regmap-irq chip for that case and add its domain to the
gpiochip. GPIO_INTR_IDENT is the status register, GPIO_INTR_ENA enables
a pin, and the reported bits in GPIO_INTR are cleared before the nested
handlers run. GPIO_INTR also records changes of a disabled pin, so a
change while the interrupt is disabled is handled when it is enabled
again. GPIO_INTR is cleared once at probe. The resource request and
release callbacks lock the line as an interrupt in gpiolib. The
regmap-irq chip is deleted after the gpiochip is removed, so the
interrupts gpiolib frees on removal still have their mappings.

GPIO_INTR records any change of an input, so only the both edges trigger
is supported and the other types are rejected.

When the regmap can sleep, the probe returns -EPROBE_DEFER while the
interrupt parent is not there yet. SoCs with memory mapped registers
still register the gpiochip without an irqchip in that case.

Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@xxxxxxxxxxxxx>
---
Tested on a lan9668 host board (pcb8385) with a lan9645x attached over
SPI.

Dependencies:

Based on v7.4-rc4, which contains the dependency 5cf0969621bc
("pinctrl: ocelot: do not use the chained irqchip behind a sleeping
bus"). It does not apply to pinctrl devel without it.

If merging v7.4-rc4 into devel is not wanted, I will resend on top of
v7.5-rc1. Review is welcome in the meantime.
---
drivers/pinctrl/Kconfig | 1 +
drivers/pinctrl/pinctrl-ocelot.c | 110 +++++++++++++++++++++++++++++++++++++--
2 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index dc7138302c55..fc10914e2e1a 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -467,6 +467,7 @@ config PINCTRL_OCELOT
select GENERIC_PINCONF
select GENERIC_PINCTRL_GROUPS
select GENERIC_PINMUX_FUNCTIONS
+ select REGMAP_IRQ
select REGMAP_MMIO
help
Support for the internal GPIO interfaces on Microsemi Ocelot and
diff --git a/drivers/pinctrl/pinctrl-ocelot.c b/drivers/pinctrl/pinctrl-ocelot.c
index c71ddcb24dbd..e593af9f1179 100644
--- a/drivers/pinctrl/pinctrl-ocelot.c
+++ b/drivers/pinctrl/pinctrl-ocelot.c
@@ -376,6 +376,9 @@ struct ocelot_pinctrl {
u8 stride;
u8 altm_stride;
struct workqueue_struct *wq;
+ struct regmap_irq_chip irq_chip;
+ struct regmap_irq_chip_data *irq_data;
+ int irq;
};

struct ocelot_match_data {
@@ -2327,6 +2330,91 @@ static int ocelot_irq_set_type(struct irq_data *data, unsigned int type)
return 0;
}

+static int ocelot_sleep_irq_set_type_config(unsigned int **buf,
+ unsigned int type,
+ const struct regmap_irq *irq_data,
+ int idx, void *irq_drv_data)
+{
+ return type == IRQ_TYPE_EDGE_BOTH ? 0 : -EINVAL;
+}
+
+static int ocelot_sleep_irq_reqres(void *irq_drv_data, irq_hw_number_t hwirq)
+{
+ struct ocelot_pinctrl *info = irq_drv_data;
+
+ return gpiochip_reqres_irq(&info->gpio_chip, hwirq);
+}
+
+static void ocelot_sleep_irq_relres(void *irq_drv_data, irq_hw_number_t hwirq)
+{
+ struct ocelot_pinctrl *info = irq_drv_data;
+
+ gpiochip_relres_irq(&info->gpio_chip, hwirq);
+}
+
+static void ocelot_sleep_irq_remove(void *data)
+{
+ struct ocelot_pinctrl *info = data;
+
+ regmap_del_irq_chip(info->irq, info->irq_data);
+}
+
+static int ocelot_sleep_irq_init(struct platform_device *pdev,
+ struct ocelot_pinctrl *info)
+{
+ struct regmap_irq_chip *chip = &info->irq_chip;
+ struct regmap_irq *irqs;
+ unsigned int i;
+
+ irqs = devm_kcalloc(&pdev->dev, info->desc->npins, sizeof(*irqs),
+ GFP_KERNEL);
+ if (!irqs)
+ return -ENOMEM;
+
+ for (i = 0; i < info->desc->npins; i++) {
+ irqs[i].reg_offset = REG(0, info, i);
+ irqs[i].mask = BIT(i % 32);
+ irqs[i].type.types_supported = IRQ_TYPE_SENSE_MASK;
+ }
+
+ chip->name = dev_name(&pdev->dev);
+ chip->status_base = REG(OCELOT_GPIO_INTR_IDENT, info, 0);
+ chip->unmask_base = REG(OCELOT_GPIO_INTR_ENA, info, 0);
+ chip->ack_base = REG(OCELOT_GPIO_INTR, info, 0);
+ chip->num_regs = info->stride;
+ chip->irqs = irqs;
+ chip->num_irqs = info->desc->npins;
+ chip->set_type_config = ocelot_sleep_irq_set_type_config;
+ chip->irq_reqres = ocelot_sleep_irq_reqres;
+ chip->irq_relres = ocelot_sleep_irq_relres;
+ chip->irq_drv_data = info;
+
+ return devm_add_action(&pdev->dev, ocelot_sleep_irq_remove, info);
+}
+
+static int ocelot_sleep_irq_register(struct platform_device *pdev,
+ struct ocelot_pinctrl *info)
+{
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < info->stride; i++) {
+ ret = regmap_write(info->map,
+ REG(OCELOT_GPIO_INTR, info, 32 * i), ~0);
+ if (ret)
+ return ret;
+ }
+
+ ret = regmap_add_irq_chip_fwnode(dev_fwnode(&pdev->dev), info->map,
+ info->irq, 0, 0, &info->irq_chip,
+ &info->irq_data);
+ if (ret)
+ return ret;
+
+ return gpiochip_irqchip_add_domain(&info->gpio_chip,
+ regmap_irq_get_domain(info->irq_data));
+}
+
static void ocelot_irq_handler(struct irq_desc *desc)
{
struct irq_chip *parent_chip = irq_desc_get_chip(desc);
@@ -2358,7 +2446,8 @@ static int ocelot_gpiochip_register(struct platform_device *pdev,
{
struct gpio_chip *gc;
struct gpio_irq_chip *girq;
- int irq;
+ int irq = info->irq;
+ int ret;

info->gpio_chip = ocelot_gpiolib_chip;

@@ -2369,8 +2458,7 @@ static int ocelot_gpiochip_register(struct platform_device *pdev,
gc->label = "ocelot-gpio";
gc->can_sleep = regmap_might_sleep(info->map);

- irq = gc->can_sleep ? 0 : platform_get_irq_optional(pdev, 0);
- if (irq > 0) {
+ if (irq > 0 && !gc->can_sleep) {
girq = &gc->irq;
gpio_irq_chip_set_chip(girq, &ocelot_irqchip);
girq->parent_handler = ocelot_irq_handler;
@@ -2383,7 +2471,17 @@ static int ocelot_gpiochip_register(struct platform_device *pdev,
girq->handler = handle_edge_irq;
}

- return devm_gpiochip_add_data(&pdev->dev, gc, info);
+ if (irq > 0 && gc->can_sleep) {
+ ret = ocelot_sleep_irq_init(pdev, info);
+ if (ret)
+ return ret;
+ }
+
+ ret = devm_gpiochip_add_data(&pdev->dev, gc, info);
+ if (ret || irq <= 0 || !gc->can_sleep)
+ return ret;
+
+ return ocelot_sleep_irq_register(pdev, info);
}

static const struct of_device_id ocelot_pinctrl_of_match[] = {
@@ -2486,6 +2584,10 @@ static int ocelot_pinctrl_probe(struct platform_device *pdev)
dev_set_drvdata(dev, info);
info->dev = dev;

+ info->irq = platform_get_irq_optional(pdev, 0);
+ if (info->irq == -EPROBE_DEFER && regmap_might_sleep(info->map))
+ return info->irq;
+
/* Pinconf registers */
if (info->desc->confops) {
pincfg = ocelot_pinctrl_create_pincfg(pdev, info);

---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261119-ocelot-pinctrl-irq-behind-sleeping-bus-7bc7e2d23d12

Best regards,
--
Jens Emil Schulz Østergaard <jensemil.schulzostergaard@xxxxxxxxxxxxx>