Skip to contentSkip to conversation

gpio: pca953x: Clear irq trigger type on irq shutdown

PATCH In review Grigoryev Denis 3 participants 4 messages May 4, 2018 – May 23, 2018 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: pca953x: Clear irq trigger type on irq shutdown

The driver stores the result of irq_set_type() in the internal variables irq_trig_raise and irq_trig_fall, which later are used to determine the GPIOs that must be re-configured as input. These variables retain their value between gpiolib's export / unexport, resulting in an incorrect state in some cases. The corresponding bits in the variables irq_trig_raise and irq_trig_fall should be cleared in irq_shutdown().

---
 drivers/gpio/gpio-pca953x.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpio/gpio-pca953x.c +10 -0
index d2ead4b..b41be8c 100644
@@ -522,6 +522,15 @@ static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
 	return 0;
 }
 
+static void pca953x_irq_shutdown(struct irq_data *d)
+{
+	struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
+	u8 mask = 1 << (d->hwirq % BANK_SZ);
+
+	chip->irq_trig_raise[d->hwirq / BANK_SZ] &= ~mask;
+	chip->irq_trig_fall[d->hwirq / BANK_SZ] &= ~mask;
+}
+
 static struct irq_chip pca953x_irq_chip = {
 	.name			= "pca953x",
 	.irq_mask		= pca953x_irq_mask,
@@ -529,6 +538,7 @@ static struct irq_chip pca953x_irq_chip = {
 	.irq_bus_lock		= pca953x_irq_bus_lock,
 	.irq_bus_sync_unlock	= pca953x_irq_bus_sync_unlock,
 	.irq_set_type		= pca953x_irq_set_type,
+	.irq_shutdown		= pca953x_irq_shutdown,
 };
 
 static bool pca953x_irq_pending(struct pca953x_chip *chip, u8 *pending)
Signature · 1 line
2.7.4
#1 lore raw
Quoted 33 lines · Grigoryev Denis

The driver stores the result of irq_set_type() in the internal variables irq_trig_raise and irq_trig_fall, which later are used to determine the GPIOs that must be re-configured as input. These variables retain their value between gpiolib's export / unexport, resulting in an incorrect state in some cases. The corresponding bits in the variables irq_trig_raise and irq_trig_fall should be cleared in irq_shutdown().

---
 drivers/gpio/gpio-pca953x.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpio/gpio-pca953x.c +9 -0
index d2ead4b..b41be8c 100644
@@ -522,6 +522,15 @@ static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
        return 0;
 }
 
+static void pca953x_irq_shutdown(struct irq_data *d)
+{
+       struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
+       u8 mask = 1 << (d->hwirq % BANK_SZ);
+
+       chip->irq_trig_raise[d->hwirq / BANK_SZ] &= ~mask;
+       chip->irq_trig_fall[d->hwirq / BANK_SZ] &= ~mask;
+}
+
 static struct irq_chip pca953x_irq_chip = {
        .name                   = "pca953x",
        .irq_mask               = pca953x_irq_mask,

drivers/gpio/gpio-pca953x.c static struct irq_chip pca953x_irq_chip = { · line 542

Quoted 5 lines
drivers/gpio/gpio-pca953x.c +1 -0
@@ -529,6 +538,7 @@ static struct irq_chip pca953x_irq_chip = {
        .irq_bus_lock           = pca953x_irq_bus_lock,
        .irq_bus_sync_unlock    = pca953x_irq_bus_sync_unlock,
        .irq_set_type           = pca953x_irq_set_type,
+       .irq_shutdown           = pca953x_irq_shutdown,
 };

This driver has a big set of users, so putting some maintainers in the loop so we can get some patch review.

Yours,
Linus Walleij

#2 lore raw
Quoted 3 lines · Linus Walleij

On Fri, May 4, 2018 at 6:53 PM, Grigoryev Denis <[email protected]> wrote:

If it's full context below, the patch looks good enough to me (assuming it works and doesn't break things on other chips like PCAL variants).

Though, I didn't read the code carefully (not enough time this week). Thus, FWIW,

with above caveats in mind.

Quoted 50 lines
Quoted 39 lines

The driver stores the result of irq_set_type() in the internal variables
irq_trig_raise and irq_trig_fall, which later are used to determine the GPIOs that must be re-configured as input. These variables retain their
value between gpiolib's export / unexport, resulting in an incorrect
state in some cases. The corresponding bits in the variables irq_trig_raise and irq_trig_fall should be cleared in irq_shutdown().

---
 drivers/gpio/gpio-pca953x.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpio/gpio- renamed from drivers/gpio/gpio-pca953x.c +0 -0

pca953x.c
index d2ead4b..b41be8c 100644

drivers/gpio/gpio-pca953x.c +9 -0
@@ -522,6 +522,15 @@ static int pca953x_irq_set_type(struct irq_data
 *d, unsigned int type)
        return 0;
 }
 
+static void pca953x_irq_shutdown(struct irq_data *d)
+{
+       struct pca953x_chip *chip = irq_data_get_irq_chip_data(d);
+       u8 mask = 1 << (d->hwirq % BANK_SZ);
+
+       chip->irq_trig_raise[d->hwirq / BANK_SZ] &= ~mask;
+       chip->irq_trig_fall[d->hwirq / BANK_SZ] &= ~mask;
+}
+
 static struct irq_chip pca953x_irq_chip = {
        .name                   = "pca953x",

.irq_mask = pca953x_irq_mask,

drivers/gpio/gpio-pca953x.c static struct irq_chip pca953x_irq_chip = { · line 542

Quoted 5 lines
drivers/gpio/gpio-pca953x.c +1 -0
@@ -529,6 +538,7 @@ static struct irq_chip pca953x_irq_chip = {
        .irq_bus_lock           = pca953x_irq_bus_lock,
        .irq_bus_sync_unlock    = pca953x_irq_bus_sync_unlock,
        .irq_set_type           = pca953x_irq_set_type,
+       .irq_shutdown           = pca953x_irq_shutdown,
 };

This driver has a big set of users, so putting some maintainers in the loop so we can get some patch review.

Yours,
Linus Walleij

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#3 lore raw
In reply to Grigoryev Denis
Quoted 8 lines · Grigoryev Denis

The driver stores the result of irq_set_type() in the internal variables irq_trig_raise and irq_trig_fall, which later are used to determine the GPIOs that must be re-configured as input. These variables retain their value between gpiolib's export / unexport, resulting in an incorrect state in some cases. The corresponding bits in the variables irq_trig_raise and irq_trig_fall should be cleared in irq_shutdown().

Patch applied with Andy's ACK.

If there are issues we can just revert it.

Yours,
Linus Walleij