diff mbox series

[PATCHv2,4/6] gpiolib: override irq_enable/disable

Message ID 20180908092319.43900-5-hverkuil@xs4all.nl
State New
Headers show
Series gpiolib: track irq enabled/disabled state | expand

Commit Message

Hans Verkuil Sept. 8, 2018, 9:23 a.m. UTC
From: Hans Verkuil <hans.verkuil@cisco.com>

When using the gpiolib irqchip helpers install irq_enable/disable
hooks for the irqchip to ensure that gpiolib knows when the irq
is enabled or disabled, allowing drivers to disable the irq and then
use it as an output pin, and later switch the direction to input and
re-enable the irq.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/gpio/gpiolib.c      | 43 +++++++++++++++++++++++++++++++++----
 include/linux/gpio/driver.h | 14 ++++++++++++
 2 files changed, 53 insertions(+), 4 deletions(-)

Comments

Guenter Roeck Sept. 14, 2018, 7:41 p.m. UTC | #1
Hi,

On Sat, Sep 08, 2018 at 11:23:17AM +0200, Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> When using the gpiolib irqchip helpers install irq_enable/disable
> hooks for the irqchip to ensure that gpiolib knows when the irq
> is enabled or disabled, allowing drivers to disable the irq and then
> use it as an output pin, and later switch the direction to input and
> re-enable the irq.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

This patch is causing a number of boot failures with qemu tests in
-next. A non-exhaustive list is:

arm:realview-pb-a8:realview_defconfig:arm-realview-pba8
arm:realview-pbx-a9:realview_defconfig:arm-realview-pbx-a9
arm:realview-eb:realview_defconfig:arm-realview-eb

"non-exhaustive" because most of my tests crash due to the recent
filesystem changes, and it is difficult to dig through 200+ boot
failures to identify other crash reasons.

Reverting the patch fixes the problem.

Guenter

---
# bad: [f8dcd02792146c5047419ff4c856651acd04f7c6] Add linux-next specific files for 20180913
# good: [11da3a7f84f19c26da6f86af878298694ede0804] Linux 4.19-rc3
git bisect start 'next-20180913' 'v4.19-rc3'
# good: [55628d01c950e01d5623a0d18a55ef85ac44a1f0] Merge remote-tracking branch 'crypto/master'
git bisect good 55628d01c950e01d5623a0d18a55ef85ac44a1f0
# good: [6cbddf4086a81886d25a0802a66632a6ca171273] Merge remote-tracking branch 'tip/auto-latest'
git bisect good 6cbddf4086a81886d25a0802a66632a6ca171273
# good: [5459d49aee6159b83ef4d4a985fd01893b75443b] Merge remote-tracking branch 'staging/staging-next'
git bisect good 5459d49aee6159b83ef4d4a985fd01893b75443b
# bad: [c80105cfc90216d6e5bbfc07ab64e732507142c3] Merge remote-tracking branch 'kselftest/next'
git bisect bad c80105cfc90216d6e5bbfc07ab64e732507142c3
# good: [84d3a3806fdb0ac6154a5fa5681b9ea67bf37581] Merge remote-tracking branch 'scsi/for-next'
git bisect good 84d3a3806fdb0ac6154a5fa5681b9ea67bf37581
# bad: [461c1a7d4733d1dfd5c47b040cf32a5e7eefbc6c] gpiolib: override irq_enable/disable
git bisect bad 461c1a7d4733d1dfd5c47b040cf32a5e7eefbc6c
# good: [888263947cd9f14e3f83be5b3e73ccabb71834d1] Merge branch 'ib-ingenic' of ../linux-pinctrl into devel
git bisect good 888263947cd9f14e3f83be5b3e73ccabb71834d1
# good: [ba21d55f6ad19cbb466b2429829900de5efac513] gpio: twl4030: Include the right header
git bisect good ba21d55f6ad19cbb466b2429829900de5efac513
# good: [ba74bd5d5b5b063d50891af16d5c14c29bcc52a6] gpio: twl6040: Implement .get_direction()
git bisect good ba74bd5d5b5b063d50891af16d5c14c29bcc52a6
# good: [f6d9af4770995d1f58be57139bce7974868231e8] gpio: ep93xx: fix test for end of loop
git bisect good f6d9af4770995d1f58be57139bce7974868231e8
# good: [ca620f2de153d690d6d6f50f32b8a14dd46107f4] gliolib: set hooks in gpiochip_set_irq_hooks()
git bisect good ca620f2de153d690d6d6f50f32b8a14dd46107f4
# good: [4e9439ddacea06f35acce4d374bf6bd0acf99bc8] gpiolib: add flag to indicate if the irq is disabled
git bisect good 4e9439ddacea06f35acce4d374bf6bd0acf99bc8
# first bad commit: [461c1a7d4733d1dfd5c47b040cf32a5e7eefbc6c] gpiolib: override irq_enable/disable
Hans Verkuil Sept. 14, 2018, 9:05 p.m. UTC | #2
On 09/14/2018 09:41 PM, Guenter Roeck wrote:
> Hi,
> 
> On Sat, Sep 08, 2018 at 11:23:17AM +0200, Hans Verkuil wrote:
>> From: Hans Verkuil <hans.verkuil@cisco.com>
>>
>> When using the gpiolib irqchip helpers install irq_enable/disable
>> hooks for the irqchip to ensure that gpiolib knows when the irq
>> is enabled or disabled, allowing drivers to disable the irq and then
>> use it as an output pin, and later switch the direction to input and
>> re-enable the irq.
>>
>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> This patch is causing a number of boot failures with qemu tests in
> -next. A non-exhaustive list is:

This should be fixed with this patch:

https://patchwork.ozlabs.org/patch/969684/

I gather it has already been applied.

Regards,

	Hans

> 
> arm:realview-pb-a8:realview_defconfig:arm-realview-pba8
> arm:realview-pbx-a9:realview_defconfig:arm-realview-pbx-a9
> arm:realview-eb:realview_defconfig:arm-realview-eb
> 
> "non-exhaustive" because most of my tests crash due to the recent
> filesystem changes, and it is difficult to dig through 200+ boot
> failures to identify other crash reasons.
> 
> Reverting the patch fixes the problem.
> 
> Guenter
> 
> ---
> # bad: [f8dcd02792146c5047419ff4c856651acd04f7c6] Add linux-next specific files for 20180913
> # good: [11da3a7f84f19c26da6f86af878298694ede0804] Linux 4.19-rc3
> git bisect start 'next-20180913' 'v4.19-rc3'
> # good: [55628d01c950e01d5623a0d18a55ef85ac44a1f0] Merge remote-tracking branch 'crypto/master'
> git bisect good 55628d01c950e01d5623a0d18a55ef85ac44a1f0
> # good: [6cbddf4086a81886d25a0802a66632a6ca171273] Merge remote-tracking branch 'tip/auto-latest'
> git bisect good 6cbddf4086a81886d25a0802a66632a6ca171273
> # good: [5459d49aee6159b83ef4d4a985fd01893b75443b] Merge remote-tracking branch 'staging/staging-next'
> git bisect good 5459d49aee6159b83ef4d4a985fd01893b75443b
> # bad: [c80105cfc90216d6e5bbfc07ab64e732507142c3] Merge remote-tracking branch 'kselftest/next'
> git bisect bad c80105cfc90216d6e5bbfc07ab64e732507142c3
> # good: [84d3a3806fdb0ac6154a5fa5681b9ea67bf37581] Merge remote-tracking branch 'scsi/for-next'
> git bisect good 84d3a3806fdb0ac6154a5fa5681b9ea67bf37581
> # bad: [461c1a7d4733d1dfd5c47b040cf32a5e7eefbc6c] gpiolib: override irq_enable/disable
> git bisect bad 461c1a7d4733d1dfd5c47b040cf32a5e7eefbc6c
> # good: [888263947cd9f14e3f83be5b3e73ccabb71834d1] Merge branch 'ib-ingenic' of ../linux-pinctrl into devel
> git bisect good 888263947cd9f14e3f83be5b3e73ccabb71834d1
> # good: [ba21d55f6ad19cbb466b2429829900de5efac513] gpio: twl4030: Include the right header
> git bisect good ba21d55f6ad19cbb466b2429829900de5efac513
> # good: [ba74bd5d5b5b063d50891af16d5c14c29bcc52a6] gpio: twl6040: Implement .get_direction()
> git bisect good ba74bd5d5b5b063d50891af16d5c14c29bcc52a6
> # good: [f6d9af4770995d1f58be57139bce7974868231e8] gpio: ep93xx: fix test for end of loop
> git bisect good f6d9af4770995d1f58be57139bce7974868231e8
> # good: [ca620f2de153d690d6d6f50f32b8a14dd46107f4] gliolib: set hooks in gpiochip_set_irq_hooks()
> git bisect good ca620f2de153d690d6d6f50f32b8a14dd46107f4
> # good: [4e9439ddacea06f35acce4d374bf6bd0acf99bc8] gpiolib: add flag to indicate if the irq is disabled
> git bisect good 4e9439ddacea06f35acce4d374bf6bd0acf99bc8
> # first bad commit: [461c1a7d4733d1dfd5c47b040cf32a5e7eefbc6c] gpiolib: override irq_enable/disable
>
Guenter Roeck Sept. 14, 2018, 9:21 p.m. UTC | #3
On Fri, Sep 14, 2018 at 11:05:19PM +0200, Hans Verkuil wrote:
> On 09/14/2018 09:41 PM, Guenter Roeck wrote:
> > Hi,
> > 
> > On Sat, Sep 08, 2018 at 11:23:17AM +0200, Hans Verkuil wrote:
> >> From: Hans Verkuil <hans.verkuil@cisco.com>
> >>
> >> When using the gpiolib irqchip helpers install irq_enable/disable
> >> hooks for the irqchip to ensure that gpiolib knows when the irq
> >> is enabled or disabled, allowing drivers to disable the irq and then
> >> use it as an output pin, and later switch the direction to input and
> >> re-enable the irq.
> >>
> >> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > This patch is causing a number of boot failures with qemu tests in
> > -next. A non-exhaustive list is:
> 
> This should be fixed with this patch:
> 
> https://patchwork.ozlabs.org/patch/969684/
> 
Confirmed.

> I gather it has already been applied.
> 
Excellent. I sent a Tested-by: anyway; doesn't hurt.

Thanks a lot for the quick fix!

Guenter
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e52fa72f13d7..efce534a269b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1826,6 +1826,28 @@  static void gpiochip_irq_relres(struct irq_data *d)
 	gpiochip_relres_irq(chip, d->hwirq);
 }
 
+static void gpiochip_irq_enable(struct irq_data *d)
+{
+	struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
+
+	gpiochip_enable_irq(chip, d->hwirq);
+	if (chip->irq.irq_enable)
+		chip->irq.irq_enable(d);
+	else
+		chip->irq.chip->irq_unmask(d);
+}
+
+static void gpiochip_irq_disable(struct irq_data *d)
+{
+	struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
+
+	if (chip->irq.irq_disable)
+		chip->irq.irq_disable(d);
+	else
+		chip->irq.chip->irq_mask(d);
+	gpiochip_disable_irq(chip, d->hwirq);
+}
+
 static void gpiochip_set_irq_hooks(struct gpio_chip *gpiochip)
 {
 	struct irq_chip *irqchip = gpiochip->irq.chip;
@@ -1835,6 +1857,12 @@  static void gpiochip_set_irq_hooks(struct gpio_chip *gpiochip)
 		irqchip->irq_request_resources = gpiochip_irq_reqres;
 		irqchip->irq_release_resources = gpiochip_irq_relres;
 	}
+	if (WARN_ON(gpiochip->irq.irq_enable))
+		return;
+	gpiochip->irq.irq_enable = irqchip->irq_enable;
+	gpiochip->irq.irq_disable = irqchip->irq_disable;
+	irqchip->irq_enable = gpiochip_irq_enable;
+	irqchip->irq_disable = gpiochip_irq_disable;
 }
 
 /**
@@ -1954,11 +1982,18 @@  static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
 		irq_domain_remove(gpiochip->irq.domain);
 	}
 
-	if (irqchip &&
-	    irqchip->irq_request_resources == gpiochip_irq_reqres) {
-		irqchip->irq_request_resources = NULL;
-		irqchip->irq_release_resources = NULL;
+	if (irqchip) {
+		if (irqchip->irq_request_resources == gpiochip_irq_reqres) {
+			irqchip->irq_request_resources = NULL;
+			irqchip->irq_release_resources = NULL;
+		}
+		if (irqchip->irq_enable == gpiochip_irq_enable) {
+			irqchip->irq_enable = gpiochip->irq.irq_enable;
+			irqchip->irq_disable = gpiochip->irq.irq_disable;
+		}
 	}
+	gpiochip->irq.irq_enable = NULL;
+	gpiochip->irq.irq_disable = NULL;
 	gpiochip->irq.chip = NULL;
 
 	gpiochip_irqchip_free_valid_mask(gpiochip);
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index b3dcb7018714..c30ee6fa5d19 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -138,6 +138,20 @@  struct gpio_irq_chip {
 	 * will allocate and map all IRQs during initialization.
 	 */
 	unsigned int first;
+
+	/**
+	 * @irq_enable:
+	 *
+	 * Store old irq_chip irq_enable callback
+	 */
+	void		(*irq_enable)(struct irq_data *data);
+
+	/**
+	 * @irq_disable:
+	 *
+	 * Store old irq_chip irq_disable callback
+	 */
+	void		(*irq_disable)(struct irq_data *data);
 };
 
 static inline struct gpio_irq_chip *to_gpio_irq_chip(struct irq_chip *chip)