Skip to contentSkip to conversation

Add GPIO level-sensitive interrupt support

PATCH Superseded Alexandre Torgue 3 participants 20 messages Feb 18, 2020 – Feb 21, 2020

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add GPIO level-sensitive interrupt support

This series adds the possibility to handle gpio interrupts on level.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip) is retriggered following interrupt type and gpio line value.

In exti irq chip, retrigger ops function is added.

Changes since v1:
- Fix issue reported by Marek: return statment in "stm32_gpio_set_type" function.

Regards
Alex

Alexandre Torgue (2):
irqchip/stm32: Add irq retrigger support
pinctrl: stm32: Add level interrupt support to gpio irq chip

 drivers/irqchip/irq-stm32-exti.c      | 14 ++++++++-
 drivers/pinctrl/stm32/pinctrl-stm32.c | 45 +++++++++++++++++++++++++--
 2 files changed, 56 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/2 irqchip/stm32: Add irq retrigger support

This commit introduces retrigger support for stm32_ext_h chip. It consists to rise the GIC interrupt mapped to an EXTI line.

drivers/irqchip/irq-stm32-exti.c +13 -1
index e00f2fa27f00..c971d115edb4 100644
@@ -604,12 +604,24 @@ static void stm32_exti_h_syscore_deinit(void)
 	unregister_syscore_ops(&stm32_exti_h_syscore_ops);
 }
 
+static int stm32_exti_h_retrigger(struct irq_data *d)
+{
+	struct stm32_exti_chip_data *chip_data = irq_data_get_irq_chip_data(d);
+	const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank;
+	void __iomem *base = chip_data->host_data->base;
+	u32 mask = BIT(d->hwirq % IRQS_PER_BANK);
+
+	writel_relaxed(mask, base + stm32_bank->swier_ofst);
+
+	return irq_chip_retrigger_hierarchy(d);
+}
+
 static struct irq_chip stm32_exti_h_chip = {
 	.name			= "stm32-exti-h",
 	.irq_eoi		= stm32_exti_h_eoi,
 	.irq_mask		= stm32_exti_h_mask,
 	.irq_unmask		= stm32_exti_h_unmask,
-	.irq_retrigger		= irq_chip_retrigger_hierarchy,
+	.irq_retrigger		= stm32_exti_h_retrigger,
 	.irq_set_type		= stm32_exti_h_set_type,
 	.irq_set_wake		= stm32_exti_h_set_wake,
 	.flags			= IRQCHIP_MASK_ON_SUSPEND,
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH v2 1/2] irqchip/stm32: Add irq retrigger support

In reply to Alexandre Torgue

Fix Marc email address

Quoted 36 lines · Alexandre Torgue

This commit introduces retrigger support for stm32_ext_h chip. It consists to rise the GIC interrupt mapped to an EXTI line.

drivers/irqchip/irq-stm32-exti.c +13 -1
index e00f2fa27f00..c971d115edb4 100644
@@ -604,12 +604,24 @@ static void stm32_exti_h_syscore_deinit(void)
  	unregister_syscore_ops(&stm32_exti_h_syscore_ops);
  }
 
+static int stm32_exti_h_retrigger(struct irq_data *d)
+{
+	struct stm32_exti_chip_data *chip_data = irq_data_get_irq_chip_data(d);
+	const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank;
+	void __iomem *base = chip_data->host_data->base;
+	u32 mask = BIT(d->hwirq % IRQS_PER_BANK);
+
+	writel_relaxed(mask, base + stm32_bank->swier_ofst);
+
+	return irq_chip_retrigger_hierarchy(d);
+}
+
  static struct irq_chip stm32_exti_h_chip = {
  	.name			= "stm32-exti-h",
  	.irq_eoi		= stm32_exti_h_eoi,
  	.irq_mask		= stm32_exti_h_mask,
  	.irq_unmask		= stm32_exti_h_unmask,
-	.irq_retrigger		= irq_chip_retrigger_hierarchy,
+	.irq_retrigger		= stm32_exti_h_retrigger,
  	.irq_set_type		= stm32_exti_h_set_type,
  	.irq_set_wake		= stm32_exti_h_set_wake,
  	.flags			= IRQCHIP_MASK_ON_SUSPEND,
#4 lore raw

Re: [PATCH v2 1/2] irqchip/stm32: Add irq retrigger support

Quoted 18 lines · Alexandre Torgue

Fix Marc email address

Quoted 15 lines · Alexandre Torgue

This commit introduces retrigger support for stm32_ext_h chip. It consists to rise the GIC interrupt mapped to an EXTI line.

drivers/irqchip/irq-stm32-exti.c +2 -0
index e00f2fa27f00..c971d115edb4 100644
@@ -604,12 +604,24 @@ static void stm32_exti_h_syscore_deinit(void)
  	unregister_syscore_ops(&stm32_exti_h_syscore_ops);
  }
  +static int stm32_exti_h_retrigger(struct irq_data *d)
+{
+	struct stm32_exti_chip_data *chip_data = 
Quoted 8 lines

drivers/irqchip/irq-stm32-exti.c static void stm32_exti_h_syscore_deinit(void) · line 616

Quoted 8 lines
drivers/irqchip/irq-stm32-exti.c +7 -0
 irq_data_get_irq_chip_data(d);
+	const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank;
+	void __iomem *base = chip_data->host_data->base;
+	u32 mask = BIT(d->hwirq % IRQS_PER_BANK);
+
+	writel_relaxed(mask, base + stm32_bank->swier_ofst);
+
+	return irq_chip_retrigger_hierarchy(d);

Calling irq_chip_retrigger_hierarchy here is really odd. If the write above has the effect of making the interrupt pending again, why do you need to force the retrigger any further?

            M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#5 lore raw

Re: [PATCH v2 1/2] irqchip/stm32: Add irq retrigger support

Quoted 23 lines · Marc Zyngier
Quoted 22 lines · Alexandre Torgue

Fix Marc email address

Quoted 19 lines · Alexandre Torgue

This commit introduces retrigger support for stm32_ext_h chip. It consists to rise the GIC interrupt mapped to an EXTI line.

drivers/irqchip/irq-stm32-exti.c +5 -0
index e00f2fa27f00..c971d115edb4 100644
@@ -604,12 +604,24 @@ static void stm32_exti_h_syscore_deinit(void)
       unregister_syscore_ops(&stm32_exti_h_syscore_ops);
   }
   +static int stm32_exti_h_retrigger(struct irq_data *d)
+{
+    struct stm32_exti_chip_data *chip_data = 
 irq_data_get_irq_chip_data(d);
+    const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank;
+    void __iomem *base = chip_data->host_data->base;
+    u32 mask = BIT(d->hwirq % IRQS_PER_BANK);
Quoted 8 lines
Quoted 4 lines

drivers/irqchip/irq-stm32-exti.c static void stm32_exti_h_syscore_deinit(void) · line 616

Quoted 4 lines
drivers/irqchip/irq-stm32-exti.c +4 -0
+
+    writel_relaxed(mask, base + stm32_bank->swier_ofst);
+
+    return irq_chip_retrigger_hierarchy(d);

Calling irq_chip_retrigger_hierarchy here is really odd. If the write above has the effect of making the interrupt pending again, why do you need to force the retrigger any further?

To be honest, as we use hierarchical irq_chip, I thought it was the way to follow (to retrigger parent irq_chip). It makes maybe no sens here. The most important to regenerate gic interrupt (associate to the exti line) is to write in SWIER register.

Alex

Quoted 2 lines

            M.

#6 lore raw

Re: [PATCH v2 1/2] irqchip/stm32: Add irq retrigger support

Quoted 33 lines · Alexandre Torgue
Quoted 23 lines · Marc Zyngier
Quoted 22 lines · Alexandre Torgue

Fix Marc email address

Quoted 19 lines · Alexandre Torgue

This commit introduces retrigger support for stm32_ext_h chip. It consists to rise the GIC interrupt mapped to an EXTI line.

drivers/irqchip/irq-stm32-exti.c +5 -0
index e00f2fa27f00..c971d115edb4 100644
@@ -604,12 +604,24 @@ static void stm32_exti_h_syscore_deinit(void)
       unregister_syscore_ops(&stm32_exti_h_syscore_ops);
   }
   +static int stm32_exti_h_retrigger(struct irq_data *d)
+{
+    struct stm32_exti_chip_data *chip_data = 
 irq_data_get_irq_chip_data(d);
+    const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank;
+    void __iomem *base = chip_data->host_data->base;
+    u32 mask = BIT(d->hwirq % IRQS_PER_BANK);
Quoted 8 lines
Quoted 4 lines

drivers/irqchip/irq-stm32-exti.c static void stm32_exti_h_syscore_deinit(void) · line 616

Quoted 4 lines
drivers/irqchip/irq-stm32-exti.c +4 -0
+
+    writel_relaxed(mask, base + stm32_bank->swier_ofst);
+
+    return irq_chip_retrigger_hierarchy(d);

Calling irq_chip_retrigger_hierarchy here is really odd. If the write above has the effect of making the interrupt pending again, why do you need to force the retrigger any further?

Quoted 3 lines

To be honest, as we use hierarchical irq_chip, I thought it was the way to follow (to retrigger parent irq_chip). It makes maybe no sens here.

Indeed, it looks perfectly pointless. What irq_chip_retrigger_hierarchy() does is to look for the first parent irqchip that is able to retrigger the interrupt. Guess what, you've just done that already. And once you've generated the interrupt, you don't need to ask the other irqchips in the chain to do the same thing.

Quoted 2 lines

The most important to regenerate gic interrupt (associate to the exti line) is to write in SWIER register.

Quite. Hence my question.

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#7 lore raw

Re: [PATCH v2 1/2] irqchip/stm32: Add irq retrigger support

Quoted 38 lines · Marc Zyngier
Quoted 33 lines · Alexandre Torgue
Quoted 23 lines · Marc Zyngier
Quoted 22 lines · Alexandre Torgue

Fix Marc email address

Quoted 19 lines · Alexandre Torgue

This commit introduces retrigger support for stm32_ext_h chip. It consists to rise the GIC interrupt mapped to an EXTI line.

drivers/irqchip/irq-stm32-exti.c +5 -0
index e00f2fa27f00..c971d115edb4 100644
@@ -604,12 +604,24 @@ static void stm32_exti_h_syscore_deinit(void)
       unregister_syscore_ops(&stm32_exti_h_syscore_ops);
   }
   +static int stm32_exti_h_retrigger(struct irq_data *d)
+{
+    struct stm32_exti_chip_data *chip_data = 
 irq_data_get_irq_chip_data(d);
+    const struct stm32_exti_bank *stm32_bank = chip_data->reg_bank;
+    void __iomem *base = chip_data->host_data->base;
+    u32 mask = BIT(d->hwirq % IRQS_PER_BANK);
Quoted 8 lines
Quoted 4 lines

drivers/irqchip/irq-stm32-exti.c static void stm32_exti_h_syscore_deinit(void) · line 616

Quoted 4 lines
drivers/irqchip/irq-stm32-exti.c +4 -0
+
+    writel_relaxed(mask, base + stm32_bank->swier_ofst);
+
+    return irq_chip_retrigger_hierarchy(d);

Calling irq_chip_retrigger_hierarchy here is really odd. If the write above has the effect of making the interrupt pending again, why do you need to force the retrigger any further?

Quoted 3 lines

To be honest, as we use hierarchical irq_chip, I thought it was the way to follow (to retrigger parent irq_chip). It makes maybe no sens here.

Quoted 5 lines

Indeed, it looks perfectly pointless. What irq_chip_retrigger_hierarchy() does is to look for the first parent irqchip that is able to retrigger the interrupt. Guess what, you've just done that already. And once you've generated the interrupt, you don't need to ask the other irqchips in the chain to do the same thing.

I agree. I gonna remove it v3.

Thanks for the feeback.
Alex

Quoted 6 lines
Quoted 2 lines

The most important to regenerate gic interrupt (associate to the exti line) is to write in SWIER register.

Quite. Hence my question.

        M.

#8 lore raw

PATCH v2 2/2 pinctrl: stm32: Add level interrupt support to gpio irq chip

In reply to Alexandre Torgue

This patch adds level interrupt support to gpio irq chip.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip) is retriggered following interrupt type and gpio line value.

drivers/pinctrl/stm32/pinctrl-stm32.c +43 -2
index 2d5e0435af0a..dae236562543 100644
@@ -92,6 +92,7 @@ struct stm32_gpio_bank {
 	u32 bank_nr;
 	u32 bank_ioport_nr;
 	u32 pin_backup[STM32_GPIO_PINS_PER_BANK];
+	u32 irq_type[STM32_GPIO_PINS_PER_BANK];
 };
 
 struct stm32_pinctrl {
@@ -303,6 +304,46 @@ static const struct gpio_chip stm32_gpio_template = {
 	.get_direction		= stm32_gpio_get_direction,
 };
 
+void stm32_gpio_irq_eoi(struct irq_data *d)
+{
+	struct stm32_gpio_bank *bank = d->domain->host_data;
+	int line;
+
+	irq_chip_eoi_parent(d);
+
+	/* If level interrupt type then retrig */
+	line = stm32_gpio_get(&bank->gpio_chip, d->hwirq);
+	if ((line == 0 && bank->irq_type[d->hwirq] == IRQ_TYPE_LEVEL_LOW) ||
+	    (line == 1 && bank->irq_type[d->hwirq] == IRQ_TYPE_LEVEL_HIGH))
+		irq_chip_retrigger_hierarchy(d);
+};
+
+static int stm32_gpio_set_type(struct irq_data *d, unsigned int type)
+{
+	struct stm32_gpio_bank *bank = d->domain->host_data;
+	u32 parent_type;
+
+	bank->irq_type[d->hwirq] = type;
+
+	switch (type) {
+	case IRQ_TYPE_EDGE_RISING:
+	case IRQ_TYPE_EDGE_FALLING:
+	case IRQ_TYPE_EDGE_BOTH:
+		parent_type = type;
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		parent_type = IRQ_TYPE_EDGE_RISING;
+		break;
+	case IRQ_TYPE_LEVEL_LOW:
+		parent_type = IRQ_TYPE_EDGE_FALLING;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return irq_chip_set_type_parent(d, parent_type);
+};
+
 static int stm32_gpio_irq_request_resources(struct irq_data *irq_data)
 {
 	struct stm32_gpio_bank *bank = irq_data->domain->host_data;
@@ -332,11 +373,11 @@ static void stm32_gpio_irq_release_resources(struct irq_data *irq_data)
 
 static struct irq_chip stm32_gpio_irq_chip = {
 	.name		= "stm32gpio",
-	.irq_eoi	= irq_chip_eoi_parent,
+	.irq_eoi	= stm32_gpio_irq_eoi,
 	.irq_ack	= irq_chip_ack_parent,
 	.irq_mask	= irq_chip_mask_parent,
 	.irq_unmask	= irq_chip_unmask_parent,
-	.irq_set_type	= irq_chip_set_type_parent,
+	.irq_set_type	= stm32_gpio_set_type,
 	.irq_set_wake	= irq_chip_set_wake_parent,
 	.irq_request_resources = stm32_gpio_irq_request_resources,
 	.irq_release_resources = stm32_gpio_irq_release_resources,
Signature · 1 line
2.17.1
Reviewed-by on v2 2/2
#9 lore raw

Re: [PATCH v2 2/2] pinctrl: stm32: Add level interrupt support to gpio irq chip

Quoted 9 lines · Alexandre Torgue

This patch adds level interrupt support to gpio irq chip.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip) is retriggered following interrupt type and gpio line value.

(and I tested the previous version on STM32MP1)

#10 lore raw

Re: [PATCH v2 2/2] pinctrl: stm32: Add level interrupt support to gpio irq chip

In reply to Alexandre Torgue

Fix Marc email address.

Quoted 84 lines · Alexandre Torgue

This patch adds level interrupt support to gpio irq chip.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip) is retriggered following interrupt type and gpio line value.

drivers/pinctrl/stm32/pinctrl-stm32.c +43 -2
index 2d5e0435af0a..dae236562543 100644
@@ -92,6 +92,7 @@ struct stm32_gpio_bank {
  	u32 bank_nr;
  	u32 bank_ioport_nr;
  	u32 pin_backup[STM32_GPIO_PINS_PER_BANK];
+	u32 irq_type[STM32_GPIO_PINS_PER_BANK];
  };
 
  struct stm32_pinctrl {
@@ -303,6 +304,46 @@ static const struct gpio_chip stm32_gpio_template = {
  	.get_direction		= stm32_gpio_get_direction,
  };
 
+void stm32_gpio_irq_eoi(struct irq_data *d)
+{
+	struct stm32_gpio_bank *bank = d->domain->host_data;
+	int line;
+
+	irq_chip_eoi_parent(d);
+
+	/* If level interrupt type then retrig */
+	line = stm32_gpio_get(&bank->gpio_chip, d->hwirq);
+	if ((line == 0 && bank->irq_type[d->hwirq] == IRQ_TYPE_LEVEL_LOW) ||
+	    (line == 1 && bank->irq_type[d->hwirq] == IRQ_TYPE_LEVEL_HIGH))
+		irq_chip_retrigger_hierarchy(d);
+};
+
+static int stm32_gpio_set_type(struct irq_data *d, unsigned int type)
+{
+	struct stm32_gpio_bank *bank = d->domain->host_data;
+	u32 parent_type;
+
+	bank->irq_type[d->hwirq] = type;
+
+	switch (type) {
+	case IRQ_TYPE_EDGE_RISING:
+	case IRQ_TYPE_EDGE_FALLING:
+	case IRQ_TYPE_EDGE_BOTH:
+		parent_type = type;
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		parent_type = IRQ_TYPE_EDGE_RISING;
+		break;
+	case IRQ_TYPE_LEVEL_LOW:
+		parent_type = IRQ_TYPE_EDGE_FALLING;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return irq_chip_set_type_parent(d, parent_type);
+};
+
  static int stm32_gpio_irq_request_resources(struct irq_data *irq_data)
  {
  	struct stm32_gpio_bank *bank = irq_data->domain->host_data;
@@ -332,11 +373,11 @@ static void stm32_gpio_irq_release_resources(struct irq_data *irq_data)
 
  static struct irq_chip stm32_gpio_irq_chip = {
  	.name		= "stm32gpio",
-	.irq_eoi	= irq_chip_eoi_parent,
+	.irq_eoi	= stm32_gpio_irq_eoi,
  	.irq_ack	= irq_chip_ack_parent,
  	.irq_mask	= irq_chip_mask_parent,
  	.irq_unmask	= irq_chip_unmask_parent,
-	.irq_set_type	= irq_chip_set_type_parent,
+	.irq_set_type	= stm32_gpio_set_type,
  	.irq_set_wake	= irq_chip_set_wake_parent,
  	.irq_request_resources = stm32_gpio_irq_request_resources,
  	.irq_release_resources = stm32_gpio_irq_release_resources,
#11 lore raw

Re: [PATCH v2 2/2] pinctrl: stm32: Add level interrupt support to gpio irq chip

Quoted 4 lines · Alexandre Torgue

Fix Marc email address.

Quoted 1 line · Alexandre Torgue

This patch adds level interrupt support to gpio irq chip.

A commit message should not contain "this patch".

Quoted 9 lines
Quoted 9 lines

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip) is retriggered following interrupt type and gpio line value.

Quoted 9 lines

drivers/pinctrl/stm32/pinctrl-stm32.c struct stm32_gpio_bank { · line 95

Quoted 9 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +1 -0
index 2d5e0435af0a..dae236562543 100644
@@ -92,6 +92,7 @@ struct stm32_gpio_bank {
  	u32 bank_nr;
  	u32 bank_ioport_nr;
  	u32 pin_backup[STM32_GPIO_PINS_PER_BANK];
+	u32 irq_type[STM32_GPIO_PINS_PER_BANK];

Do you really need a u32 here? an array of u8 seems enough. After all, you only need two bits of information per interrupts (level or not, low or high).

Quoted 10 lines
Quoted 10 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +3 -0
  };
    struct stm32_pinctrl {
@@ -303,6 +304,46 @@ static const struct gpio_chip stm32_gpio_template 
 = {
  	.get_direction		= stm32_gpio_get_direction,
  };
  +void stm32_gpio_irq_eoi(struct irq_data *d)
+{
+	struct stm32_gpio_bank *bank = d->domain->host_data;
+	int line;
Quoted 8 lines

drivers/pinctrl/stm32/pinctrl-stm32.c static const struct gpio_chip stm32_gpio_template = { · line 318

Quoted 8 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +8 -0
+
+	irq_chip_eoi_parent(d);
+
+	/* If level interrupt type then retrig */
+	line = stm32_gpio_get(&bank->gpio_chip, d->hwirq);
+	if ((line == 0 && bank->irq_type[d->hwirq] == IRQ_TYPE_LEVEL_LOW) ||
+	    (line == 1 && bank->irq_type[d->hwirq] == IRQ_TYPE_LEVEL_HIGH))
+		irq_chip_retrigger_hierarchy(d);

s/line/level/

Quoted 8 lines

drivers/pinctrl/stm32/pinctrl-stm32.c static const struct gpio_chip stm32_gpio_template = { · line 326

Quoted 8 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +8 -0
+};
+
+static int stm32_gpio_set_type(struct irq_data *d, unsigned int type)
+{
+	struct stm32_gpio_bank *bank = d->domain->host_data;
+	u32 parent_type;
+
+	bank->irq_type[d->hwirq] = type;

It would make more sense if this this assignment was done *after* sanitizing the type value.

Quoted 31 lines
Quoted 31 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +21 -1
+
+	switch (type) {
+	case IRQ_TYPE_EDGE_RISING:
+	case IRQ_TYPE_EDGE_FALLING:
+	case IRQ_TYPE_EDGE_BOTH:
+		parent_type = type;
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		parent_type = IRQ_TYPE_EDGE_RISING;
+		break;
+	case IRQ_TYPE_LEVEL_LOW:
+		parent_type = IRQ_TYPE_EDGE_FALLING;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return irq_chip_set_type_parent(d, parent_type);
+};
+
  static int stm32_gpio_irq_request_resources(struct irq_data 
 *irq_data)
  {
  	struct stm32_gpio_bank *bank = irq_data->domain->host_data;
@@ -332,11 +373,11 @@ static void 
 stm32_gpio_irq_release_resources(struct irq_data *irq_data)
    static struct irq_chip stm32_gpio_irq_chip = {
  	.name		= "stm32gpio",
-	.irq_eoi	= irq_chip_eoi_parent,
+	.irq_eoi	= stm32_gpio_irq_eoi,
  	.irq_ack	= irq_chip_ack_parent,
Quoted 8 lines

drivers/pinctrl/stm32/pinctrl-stm32.c static void stm32_gpio_irq_release_resources(struct irq_data *irq_data) · line 383

Quoted 8 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +1 -1
  	.irq_mask	= irq_chip_mask_parent,
  	.irq_unmask	= irq_chip_unmask_parent,
-	.irq_set_type	= irq_chip_set_type_parent,
+	.irq_set_type	= stm32_gpio_set_type,
  	.irq_set_wake	= irq_chip_set_wake_parent,
  	.irq_request_resources = stm32_gpio_irq_request_resources,
  	.irq_release_resources = stm32_gpio_irq_release_resources,

Thanks,

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#12 lore raw

Re: [PATCH v2 2/2] pinctrl: stm32: Add level interrupt support to gpio irq chip

Hi Marc

Quoted 7 lines · Marc Zyngier
Quoted 4 lines · Alexandre Torgue

Fix Marc email address.

Quoted 1 line · Alexandre Torgue

This patch adds level interrupt support to gpio irq chip.

A commit message should not contain "this patch".

Ok I'll change in v3

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip) is retriggered following interrupt type and gpio line value.

Quoted 13 lines
Quoted 9 lines

drivers/pinctrl/stm32/pinctrl-stm32.c struct stm32_gpio_bank { · line 95

Quoted 9 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +1 -0
index 2d5e0435af0a..dae236562543 100644
@@ -92,6 +92,7 @@ struct stm32_gpio_bank {
       u32 bank_nr;
       u32 bank_ioport_nr;
       u32 pin_backup[STM32_GPIO_PINS_PER_BANK];
+    u32 irq_type[STM32_GPIO_PINS_PER_BANK];

Do you really need a u32 here? an array of u8 seems enough. After all, you only need two bits of information per interrupts (level or not, low or high).

I agree. No need to have u32.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +6 -0
   };
     struct stm32_pinctrl {
@@ -303,6 +304,46 @@ static const struct gpio_chip 
 stm32_gpio_template = {
       .get_direction        = stm32_gpio_get_direction,
   };
   +void stm32_gpio_irq_eoi(struct irq_data *d)
+{
+    struct stm32_gpio_bank *bank = d->domain->host_data;
+    int line;
+
+    irq_chip_eoi_parent(d);
+
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +3 -0
+    /* If level interrupt type then retrig */
+    line = stm32_gpio_get(&bank->gpio_chip, d->hwirq);
+    if ((line == 0 && bank->irq_type[d->hwirq] == 

IRQ_TYPE_LEVEL_LOW) ||
+        (line == 1 && bank->irq_type[d->hwirq] == IRQ_TYPE_LEVEL_HIGH)) +        irq_chip_retrigger_hierarchy(d);

s/line/level/

correct

Quoted 11 lines
Quoted 8 lines

drivers/pinctrl/stm32/pinctrl-stm32.c static const struct gpio_chip stm32_gpio_template = { · line 326

Quoted 8 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +8 -0
+};
+
+static int stm32_gpio_set_type(struct irq_data *d, unsigned int type)
+{
+    struct stm32_gpio_bank *bank = d->domain->host_data;
+    u32 parent_type;
+
+    bank->irq_type[d->hwirq] = type;

It would make more sense if this this assignment was done *after* sanitizing the type value.

Ok.

Quoted 43 lines
Quoted 31 lines
Quoted 31 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +20 -0
+
+    switch (type) {
+    case IRQ_TYPE_EDGE_RISING:
+    case IRQ_TYPE_EDGE_FALLING:
+    case IRQ_TYPE_EDGE_BOTH:
+        parent_type = type;
+        break;
+    case IRQ_TYPE_LEVEL_HIGH:
+        parent_type = IRQ_TYPE_EDGE_RISING;
+        break;
+    case IRQ_TYPE_LEVEL_LOW:
+        parent_type = IRQ_TYPE_EDGE_FALLING;
+        break;
+    default:
+        return -EINVAL;
+    }
+
+    return irq_chip_set_type_parent(d, parent_type);
+};
+

  static int stm32_gpio_irq_request_resources(struct irq_data *irq_data) {
      struct stm32_gpio_bank *bank = irq_data->domain->host_data;

drivers/pinctrl/stm32/pinctrl-stm32.c +1 -1
@@ -332,11 +373,11 @@ static void 
 stm32_gpio_irq_release_resources(struct irq_data *irq_data)
     static struct irq_chip stm32_gpio_irq_chip = {
       .name        = "stm32gpio",
-    .irq_eoi    = irq_chip_eoi_parent,
+    .irq_eoi    = stm32_gpio_irq_eoi,
       .irq_ack    = irq_chip_ack_parent,
Quoted 8 lines

drivers/pinctrl/stm32/pinctrl-stm32.c static void stm32_gpio_irq_release_resources(struct irq_data *irq_data) · line 383

Quoted 8 lines
drivers/pinctrl/stm32/pinctrl-stm32.c +1 -1
       .irq_mask    = irq_chip_mask_parent,
       .irq_unmask    = irq_chip_unmask_parent,
-    .irq_set_type    = irq_chip_set_type_parent,
+    .irq_set_type    = stm32_gpio_set_type,
       .irq_set_wake    = irq_chip_set_wake_parent,
       .irq_request_resources = stm32_gpio_irq_request_resources,
       .irq_release_resources = stm32_gpio_irq_release_resources,

Thanks,

        M.

#13 lore raw
In reply to Alexandre Torgue
Quoted 8 lines · Alexandre Torgue

This series adds the possibility to handle gpio interrupts on level.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip) is retriggered following interrupt type and gpio line value.

In exti irq chip, retrigger ops function is added.

btw. this might be unrelated, but is it possible to have e.g. gpioC2 set as trigger-level-low and gpioD2 set as trigger-edge-falling ? It seems 8eb2dfee9fb1 ("pinctrl: stm32: add lock mechanism for irqmux selection") prevents that.

#14 lore raw

Hi Marek

Quoted 8 lines · Marek Vasut
Quoted 7 lines · Alexandre Torgue

This series adds the possibility to handle gpio interrupts on level.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip) is retriggered following interrupt type and gpio line value.

Quoted 7 lines
Quoted 1 line

In exti irq chip, retrigger ops function is added.

btw. this might be unrelated, but is it possible to have e.g. gpioC2 set as trigger-level-low and gpioD2 set as trigger-edge-falling ? It seems 8eb2dfee9fb1 ("pinctrl: stm32: add lock mechanism for irqmux selection") prevents that.

No it's not possible. Each gpio line doesn't have a dedicated Exti line Each Exti line is muxing between gpio banks.

Mapping is done as following:

EXTI0 = A0 or B0 or C0 .... or Z0 : selected by Mux EXTI1 = A1 or B1 or C1 ....or Z1 : selected by Mux EXTI2 = A2 or B2 or C2 ....or Z2 : selected by Mux
...

regards
Alexandre

#15 lore raw
Quoted 1 line · Alexandre Torgue

Hi Marek

Hi,

Quoted 12 lines · Marek Vasut
Quoted 11 lines · Alexandre Torgue
Quoted 9 lines

This series adds the possibility to handle gpio interrupts on level.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip)
is retriggered following interrupt type and gpio line value.

In exti irq chip, retrigger ops function is added.

Quoted 8 lines
Quoted 5 lines

btw. this might be unrelated, but is it possible to have e.g. gpioC2 set as trigger-level-low and gpioD2 set as trigger-edge-falling ? It seems 8eb2dfee9fb1 ("pinctrl: stm32: add lock mechanism for irqmux selection") prevents that.

No it's not possible. Each gpio line doesn't have a dedicated Exti line Each Exti line is muxing between gpio banks.

OK, that confirms my assumption.

Quoted 6 lines

Mapping is done as following:

EXTI0 = A0 or B0 or C0 .... or Z0 : selected by Mux EXTI1 = A1 or B1 or C1 ....or Z1 : selected by Mux EXTI2 = A2 or B2 or C2 ....or Z2 : selected by Mux
...

Is it at least possible to have IRQs of the same type on the same exti line? E.g. gpioA2 of trigger-edge-falling and gpioB2 trigger-edge-falling ?

#16 lore raw
Quoted 30 lines · Marek Vasut
Quoted 1 line · Alexandre Torgue

Hi Marek

Hi,

Quoted 12 lines · Marek Vasut
Quoted 11 lines · Alexandre Torgue
Quoted 9 lines

This series adds the possibility to handle gpio interrupts on level.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip)
is retriggered following interrupt type and gpio line value.

In exti irq chip, retrigger ops function is added.

Quoted 8 lines
Quoted 5 lines

btw. this might be unrelated, but is it possible to have e.g. gpioC2 set as trigger-level-low and gpioD2 set as trigger-edge-falling ? It seems 8eb2dfee9fb1 ("pinctrl: stm32: add lock mechanism for irqmux selection") prevents that.

No it's not possible. Each gpio line doesn't have a dedicated Exti line Each Exti line is muxing between gpio banks.

OK, that confirms my assumption.

Quoted 2 lines

Mapping is done as following:

Quoted 8 lines
Quoted 4 lines

EXTI0 = A0 or B0 or C0 .... or Z0 : selected by Mux EXTI1 = A1 or B1 or C1 ....or Z1 : selected by Mux EXTI2 = A2 or B2 or C2 ....or Z2 : selected by Mux
...

Is it at least possible to have IRQs of the same type on the same exti line? E.g. gpioA2 of trigger-edge-falling and gpioB2 trigger-edge-falling ?

Sorry I don't catch your point. If you already succeed to get gpioA2, then you will failed to get gpioB2 but looking at function call stack we could get an other issue.

Lets take example where you succeed to get gpioa2 as interrupt (using interrupt bindings) and now you try to do the same for gpiob2, you will have (roughly):

stm32_gpio_irq_request_resources (for gpiob2) --> succeed

stm32_gpio_set_type
|
|--> stm32_exti_set_type type -> change exti line 2 trigger registers
with gpiob2 binding.

stm32_gpio_domain_activate --> failed as exti line2 is already used
by gpioa2.

So as stm32_gpio_set_type is called before checking than exti line is available, type could be changed and behavior of gpioa2 interrupt broken.

Solution would be to move the exti line mux check from stm32_gpio_domain_activate to stm32_gpio_irq_request_resources callback.

Regards
Alex

#17 lore raw

On 2/19/20 10:20 AM, Alexandre Torgue wrote:
Hi,
[...]

Quoted 31 lines
Quoted 31 lines
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines

This series adds the possibility to handle gpio interrupts on level.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on
level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip)
is retriggered following interrupt type and gpio line value.

Quoted 9 lines
Quoted 1 line

In exti irq chip, retrigger ops function is added.

btw. this might be unrelated, but is it possible to have e.g. gpioC2 set
as trigger-level-low and gpioD2 set as trigger-edge-falling ? It seems 8eb2dfee9fb1 ("pinctrl: stm32: add lock mechanism for irqmux selection")
prevents that.

Quoted 2 lines

No it's not possible. Each gpio line doesn't have a dedicated Exti line Each Exti line is muxing between gpio banks.

OK, that confirms my assumption.

Quoted 6 lines

Mapping is done as following:

EXTI0 = A0 or B0 or C0 .... or Z0 : selected by Mux EXTI1 = A1 or B1 or C1 ....or Z1 : selected by Mux EXTI2 = A2 or B2 or C2 ....or Z2 : selected by Mux
...

Quoted 8 lines
Quoted 4 lines

Is it at least possible to have IRQs of the same type on the same exti line? E.g. gpioA2 of trigger-edge-falling and gpioB2 trigger-edge-falling ?

Sorry I don't catch your point. If you already succeed to get gpioA2, then you will failed to get gpioB2 but looking at function call stack we could get an other issue.

Considering the EXTI line limitations, I'd like to know what kind of IRQ input configuration is allowed/valid and what kind of configuration is not valid.

Quoted 11 lines

Lets take example where you succeed to get gpioa2 as interrupt (using interrupt bindings) and now you try to do the same for gpiob2, you will have (roughly):

stm32_gpio_irq_request_resources (for gpiob2) --> succeed

stm32_gpio_set_type
 |
 |--> stm32_exti_set_type type -> change exti line 2 trigger registers with gpiob2 binding.

Quoted 8 lines

stm32_gpio_domain_activate --> failed as exti line2 is already used by gpioa2.

So as stm32_gpio_set_type is called before checking than exti line is available, type could be changed and behavior of gpioa2 interrupt broken.

Solution would be to move the exti line mux check from stm32_gpio_domain_activate to  stm32_gpio_irq_request_resources callback.

So the hardware does support using both gpioA2 and gpioB2 as an interrupt source, for different drivers, if they are of the same interrupt type. Except the current implementation does not permit that.

If the interrupt types are different, that is not supported by the hardware.

Correct ?

#18 lore raw

Hi Marek

Quoted 39 lines · Marek Vasut

On 2/19/20 10:20 AM, Alexandre Torgue wrote:
Hi,
[...]

Quoted 36 lines
Quoted 35 lines
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines

This series adds the possibility to handle gpio interrupts on level.

GPIO hardware block is directly linked to EXTI block but EXTI handles external interrupts only on edge. To be able to handle GPIO interrupt on
level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip)
is retriggered following interrupt type and gpio line value.

Quoted 9 lines
Quoted 1 line

In exti irq chip, retrigger ops function is added.

btw. this might be unrelated, but is it possible to have e.g. gpioC2 set
as trigger-level-low and gpioD2 set as trigger-edge-falling ? It seems 8eb2dfee9fb1 ("pinctrl: stm32: add lock mechanism for irqmux selection")
prevents that.

Quoted 2 lines

No it's not possible. Each gpio line doesn't have a dedicated Exti line Each Exti line is muxing between gpio banks.

OK, that confirms my assumption.

Quoted 6 lines

Mapping is done as following:

EXTI0 = A0 or B0 or C0 .... or Z0 : selected by Mux EXTI1 = A1 or B1 or C1 ....or Z1 : selected by Mux EXTI2 = A2 or B2 or C2 ....or Z2 : selected by Mux
...

Is it at least possible to have IRQs of the same type on the same exti line? E.g. gpioA2 of trigger-edge-falling and gpioB2 trigger-edge-falling ?

Quoted 7 lines
Quoted 3 lines

Sorry I don't catch your point. If you already succeed to get gpioA2, then you will failed to get gpioB2 but looking at function call stack we could get an other issue.

Considering the EXTI line limitations, I'd like to know what kind of IRQ input configuration is allowed/valid and what kind of configuration is not valid.

As a mux is used to select which GPIO[A..Z]_X has to be mapped on exti_X line, only one GPIO can be used on the EXTI line.

For example, on EXTI2 you could map either gpioa2 or gpiob2 or ....gpioz2 but not gpioa2 and gpiob2 in the same time.

Quoted 18 lines
Quoted 18 lines

Lets take example where you succeed to get gpioa2 as interrupt (using interrupt bindings) and now you try to do the same for gpiob2, you will have (roughly):

stm32_gpio_irq_request_resources (for gpiob2) --> succeed

stm32_gpio_set_type
 |
 |--> stm32_exti_set_type type -> change exti line 2 trigger registers with gpiob2 binding.

stm32_gpio_domain_activate --> failed as exti line2 is already used
                   by gpioa2.

So as stm32_gpio_set_type is called before checking than exti line is available, type could be changed and behavior of gpioa2 interrupt broken.

Quoted 7 lines
Quoted 2 lines

Solution would be to move the exti line mux check from stm32_gpio_domain_activate to  stm32_gpio_irq_request_resources callback.

So the hardware does support using both gpioA2 and gpioB2 as an interrupt source, for different drivers, if they are of the same interrupt type. Except the current implementation does not permit that.

No hardware doesn't allow it for reason explain above.

Quoted 4 lines

If the interrupt types are different, that is not supported by the hardware.

Correct ?

#19 lore raw
Quoted 1 line · Alexandre Torgue

Hi Marek

Hi,

Quoted 51 lines · Marek Vasut
Quoted 42 lines · Alexandre Torgue

Hi,
[...]

Quoted 39 lines
Quoted 38 lines
Quoted 21 lines
Quoted 12 lines
Quoted 11 lines

This series adds the possibility to handle gpio interrupts on level.

GPIO hardware block is directly linked to EXTI block but EXTI handles
external interrupts only on edge. To be able to handle GPIO interrupt on
level a "hack" is done in gpio irq chip: parent interrupt (exti irq chip)
is retriggered following interrupt type and gpio line value.

In exti irq chip, retrigger ops function is added.

Quoted 8 lines

btw. this might be unrelated, but is it possible to have e.g. gpioC2 set
as trigger-level-low and gpioD2 set as trigger-edge-falling ? It seems
8eb2dfee9fb1 ("pinctrl: stm32: add lock mechanism for irqmux selection")
prevents that.

Quoted 3 lines

No it's not possible. Each gpio line doesn't have a dedicated Exti line
Each Exti line is muxing between gpio banks.

OK, that confirms my assumption.

Quoted 6 lines

Mapping is done as following:

EXTI0 = A0 or B0 or C0 .... or Z0 : selected by Mux EXTI1 = A1 or B1 or C1 ....or Z1 : selected by Mux EXTI2 = A2 or B2 or C2 ....or Z2 : selected by Mux
...

Is it at least possible to have IRQs of the same type on the same exti line? E.g. gpioA2 of trigger-edge-falling and gpioB2 trigger-edge-falling ?

Quoted 7 lines
Quoted 3 lines

Sorry I don't catch your point. If you already succeed to get gpioA2, then you will failed to get gpioB2 but looking at function call stack we could get an other issue.

Considering the EXTI line limitations, I'd like to know what kind of IRQ input configuration is allowed/valid and what kind of configuration is not valid.

Quoted 5 lines

As a mux is used to select which GPIO[A..Z]_X has to be mapped on exti_X line, only one GPIO can be used on the EXTI line.

For example, on EXTI2 you could map either gpioa2 or gpiob2 or ....gpioz2 but not gpioa2 and gpiob2 in the same time.

Got it, thank you for the clarification.

Maybe that could be something to improve for MP2 :-)