gpio: Add driver for ACPI INT0002 Virtual GPIO device
v4 cover gpio: Add driver for ACPI INT0002 Virtual GPIO device
Hi All,
Here is v4 of my patch adding a driver for the ACPI INT0002 Virtual GPIO device. When I started working on this driver using 4.11 as kernel this fixed an irq-storm on irq 9, with some of the recent suspend-to-idle wakeup changes which have landed in 4.12-rc1 this "driver" is necessary to fix affected systems getting stuck in suspend when the user tries to wake them through a peripheral which signals PME to the PMC to wakeup the system, such as the xHCI controller.
As such ideally this driver should get added to a later 4.12-rc# as a bugfix. Also see this linux-acpi mailinglist-thread:
https://www.spinics.net/lists/linux-acpi/msg74614.html
Regards,
Hans
PATCH v4 1/1 gpio: Add driver for ACPI INT0002 Virtual GPIO device
Some peripherals on Bay Trail and Cherry Trail platforms signal PME to the PMC to wakeup the system. When this happens software needs to clear the PME_B0_STS bit in the GPE0a_STS register to avoid an IRQ storm on IRQ 9.
This is modeled in ACPI through the INT0002 ACPI Virtual GPIO device.
This commit adds a driver which registers the Virtual GPIOs expected by the DSDT on these devices, letting gpiolib-acpi claim the virtual GPIO and install a GPIO-interrupt handler which call the _L02 handler as it would for a real GPIO controller.
---
Changes in v2:
-Remove dev_err after malloc failure
-Remove unused empty runtime pm callbacks -s/GPE0A_PME_/GPE0A_PME_B0_/
-Fixed some checkpatch warnings (I forgot to run checkpatch on v1) Changes in v3:
-Rewrite as gpiochip driver letting gpiolib-acpi deal with claiming the pin
0x0002 and calling the _L02 event handler when the virtual gpio-irq triggers
-Rebase on 4.12-rc1
Changes in v4:
-Drop device_init_wakeup() from _probe(), use pm_system_wakeup() instead
of pm_wakeup_hard_event(chip->parent)
-Improve commit message
--- drivers/gpio/Kconfig | 14 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-int0002.c | 210 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 drivers/gpio/gpio-int0002.c
drivers/gpio/Kconfig +14 -0
@@ -608,6 +608,20 @@ config GPIO_GPIO_MM The base port addresses for the devices may be configured via the base array module parameter. +config GPIO_INT0002 + tristate "Intel ACPI INT0002 Virtual GPIO" + depends on ACPI + select GPIOLIB_IRQCHIP + ---help--- + Some peripherals on Baytrail and Cherrytrail platforms signal + PME to the PMC to wakeup the system. When this happens software + needs to explicitly clear the interrupt source to avoid an IRQ + storm on IRQ 9. This is modelled in ACPI through the INT0002 + Virtual GPIO ACPI device. + + To compile this driver as a module, choose M here: the module will + be called gpio_int0002. + config GPIO_IT87 tristate "IT87xx GPIO support" help
drivers/gpio/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_GPIO_GPIO_MM) += gpio-gpio-mm.o obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o obj-$(CONFIG_HTC_EGPIO) += gpio-htc-egpio.o obj-$(CONFIG_GPIO_ICH) += gpio-ich.o +obj-$(CONFIG_GPIO_INT0002) += gpio-int0002.o obj-$(CONFIG_GPIO_IOP) += gpio-iop.o obj-$(CONFIG_GPIO_IT87) += gpio-it87.o obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o
drivers/gpio/gpio-int0002.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.13.0
Quoted 7 lines · Hans de Goede
Some peripherals on Bay Trail and Cherry Trail platforms signal PME to the
PMC to wakeup the system. When this happens software needs to clear thePME_B0_STSbit in theGPE0a_STSregister to avoid an IRQ storm on IRQ 9.
Quoted 6 lines
This is modeled in ACPI through the INT0002 ACPI Virtual GPIO device.
This commit adds a driver which registers the Virtual GPIOs expected by the DSDT on these devices, letting gpiolib-acpi claim the virtual GPIO and install a GPIO-interrupt handler which call the
_L02handler as it would for a real GPIO controller.
Some issues below, after addressing them
drivers/gpio/Kconfig config GPIO_GPIO_MM · line 613
Quoted 3 lines
drivers/gpio/Kconfig +3
-0+config GPIO_INT0002 + tristate "Intel ACPI INT0002 Virtual GPIO" + depends on ACPI
&& X86 (see below why)
drivers/gpio/gpio-int0002.c line 31
Quoted 2 lines
drivers/gpio/gpio-int0002.c new file +2
-0+#include <asm/cpu_device_id.h> +#include <asm/intel-family.h>
Please, move this after <linux/*> headers with empty line in between.
Because you are using specific x86 headers you must depend on X86.
Quoted 13 lines
drivers/gpio/gpio-int0002.c new file +11
-0+#include <linux/acpi.h> +#include <linux/gpio.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/suspend.h> + +/* For some reason the virtual GPIO pin tied to the GPE is numbered pin 2 */
drivers/gpio/gpio-int0002.c line 48
Quoted 5 lines
drivers/gpio/gpio-int0002.c new file +4
-0+#define GPE0A_PME_B0_VIRT_GPIO_PIN 2 + +#define GPE0A_PME_B0_STS_BIT 0x2000 +#define GPE0A_PME_B0_EN_BIT 0x2000
BIT() ?
drivers/gpio/gpio-int0002.c line 134
Quoted 13 lines
drivers/gpio/gpio-int0002.c new file +11
-0+#define GPE0A_STS_PORT 0x420 +#define GPE0A_EN_PORT 0x428 + +static int int0002_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +const struct x86_cpu_id *cpu_id; +struct gpio_chip *chip; +int i, irq, ret; + +/* Menlow has a different INT0002 device? <sigh> */
Perhaps we can remove that all code. I will look at it when I have spare time.
For now we may go with your code as is.
Quoted 39 lines
drivers/gpio/gpio-int0002.c new file +36
-0+ cpu_id =x86_match_cpu (int0002_cpu_ids); +if (!cpu_id) +return -ENODEV ; + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) { +dev_err (dev,"Error getting IRQ: %d\n" , irq); +return irq; + } + + chip =devm_kzalloc (dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->label =DRV_NAME ; + chip->parent = dev; + chip->owner =THIS_MODULE ; + chip->get = int0002_gpio_get; + chip->set = int0002_gpio_set; + chip->direction_input = int0002_gpio_get; + chip->direction_output = int0002_gpio_direction_output; + chip->base =-1 ; + chip->ngpio =GPE0A_PME_B0_VIRT_GPIO_PIN +1 ; + chip->irq_need_valid_mask = true; + + ret =devm_gpiochip_add_data (&pdev->dev, chip,NULL ); +if (ret) { +dev_err (dev,"Error adding gpio chip: %d\n" , ret); +return ret; + } + +for (i =0 ; i <GPE0A_PME_B0_VIRT_GPIO_PIN ; i++) +clear_bit (i, chip->irq_valid_mask); + +/* +* We manually request the irq here instead of passing a flow-handler
(quoted diff) +1
-0+ * to gpiochip_set_chained_irqchip, because the irq isshared.
Review
Quoted 1 line
(quoted diff) +1
-0+ */
Linus, I'm just wondering if we can provide generic solution for such cases (AFAIU this is copied from some of Intel pin control driver, so, we have two or more users already).
For now let's go with current proposal.
Quoted 23 lines
(quoted diff) +2
-0+ ret = devm_request_irq(dev, irq, int0002_irq, + IRQF_SHARED | IRQF_NO_THREAD,"INT0002", chip);
(quoted diff) +2
-0+ if (ret) { + dev_err(dev, "Error requesting IRQ %d: %d\n", irq,ret);
drivers/gpio/gpio-int0002.c new file +14
-0+return ret; + } + + +static const struct acpi_device_id int0002_acpi_ids[] = { + {"INT0002" ,0 }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, int0002_acpi_ids); + +static struct platform_driver int0002_driver = { + .driver = { + .name =DRV_NAME , + .acpi_match_table =
Quoted 1 line
ACPI_PTR(int0002_acpi_ids),
No #ifdef, so ACPI_PTR can be dropped.
Quoted 3 lines
drivers/gpio/gpio-int0002.c new file +3
-0+ }, + .probe = int0002_probe, +};
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Hi,
Quoted 15 lines · Andy Shevchenko
Quoted 7 lines · Hans de Goede
Some peripherals on Bay Trail and Cherry Trail platforms signal PME to the
PMC to wakeup the system. When this happens software needs to clear thePME_B0_STSbit in theGPE0a_STSregister to avoid an IRQ storm on IRQ 9.Quoted 6 lines
This is modeled in ACPI through the INT0002 ACPI Virtual GPIO device.
This commit adds a driver which registers the Virtual GPIOs expected by the DSDT on these devices, letting gpiolib-acpi claim the virtual GPIO and install a GPIO-interrupt handler which call the
_L02handler as it would for a real GPIO controller.
Quoted 8 lines
Some issues below, after addressing them
Reviewed-by Andy Shevchenko <[email protected]>drivers/gpio/Kconfig config GPIO_GPIO_MM · line 613
Quoted 3 lines
drivers/gpio/Kconfig +3
-0+config GPIO_INT0002 + tristate "Intel ACPI INT0002 Virtual GPIO" + depends on ACPI&& X86 (see below why)
This is part of:
menu "Port-mapped I/O GPIO drivers"
depends on X86 # Unconditional I/O space access
So that is already required, which is why I dropped it (previous versions did have it).
Quoted 5 lines
drivers/gpio/gpio-int0002.c line 31
Quoted 3 lines
drivers/gpio/gpio-int0002.c new file +2
-0+#include <asm/cpu_device_id.h> +#include <asm/intel-family.h> Please, move this after <linux/*> headers with empty line in between.
I'm using alphabetic sort for #includes, I don't see how these are special its not like they are "local" headers, e.g. drivers/gpio/gpio-aspeed.c does the same. What if this driver were to also need acpi/ headers should those go in their block too, etc. ?
Quoted 19 lines
Because you are using specific x86 headers you must depend on X86.
Quoted 15 lines
drivers/gpio/gpio-int0002.c new file +11
-0+#include <linux/acpi.h> +#include <linux/gpio.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/suspend.h> + +/* For some reason the virtual GPIO pin tied to the GPE is numbered pin 2 */
(quoted diff) +2
-0+#define GPE0A_PME_B0_VIRT_GPIO_PIN 2 +
Quoted 4 lines
drivers/gpio/gpio-int0002.c line 48
Quoted 2 lines
drivers/gpio/gpio-int0002.c new file +2
-0+#define GPE0A_PME_B0_STS_BIT 0x2000 +#define GPE0A_PME_B0_EN_BIT 0x2000
BIT()?
Ack.
Quoted 13 lines
Quoted 12 lines
drivers/gpio/gpio-int0002.c new file +10
-0+#define GPE0A_STS_PORT 0x420 +#define GPE0A_EN_PORT 0x428 + +static int int0002_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +const struct x86_cpu_id *cpu_id; +struct gpio_chip *chip; +int i, irq, ret; +
Quoted 4 lines
drivers/gpio/gpio-int0002.c line 134
Quoted 1 line
drivers/gpio/gpio-int0002.c new file +1
-0+/* Menlow has a different INT0002 device? <sigh> */ Perhaps we can remove that all code. I will look at it when I have spare time.
Even if we remove the code for the INT0002 Menlow device we still don't want to bind to it, or are you talking about dropping Menlow support in such a way that newer kernels will not boot on Menlow at all anymore ?
Quoted 72 lines
For now we may go with your code as is.
Quoted 39 lines
drivers/gpio/gpio-int0002.c new file +36
-0+ cpu_id =x86_match_cpu (int0002_cpu_ids); +if (!cpu_id) +return -ENODEV ; + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) { +dev_err (dev,"Error getting IRQ: %d\n" , irq); +return irq; + } + + chip =devm_kzalloc (dev,sizeof (*chip),GFP_KERNEL ); +if (!chip) +return -ENOMEM ; + + chip->label =DRV_NAME ; + chip->parent = dev; + chip->owner =THIS_MODULE ; + chip->get = int0002_gpio_get; + chip->set = int0002_gpio_set; + chip->direction_input = int0002_gpio_get; + chip->direction_output = int0002_gpio_direction_output; + chip->base =-1 ; + chip->ngpio =GPE0A_PME_B0_VIRT_GPIO_PIN +1 ; + chip->irq_need_valid_mask = true; + + ret =devm_gpiochip_add_data (&pdev->dev, chip,NULL ); +if (ret) { +dev_err (dev,"Error adding gpio chip: %d\n" , ret); +return ret; + } + +for (i =0 ; i <GPE0A_PME_B0_VIRT_GPIO_PIN ; i++) +clear_bit (i, chip->irq_valid_mask); + +/* +* We manually request the irq here instead of passing a flow-handler
(quoted diff) +1
-0+ * to gpiochip_set_chained_irqchip, because the irq isshared.
Review
Quoted 1 line
(quoted diff) +1
-0+ */Linus, I'm just wondering if we can provide generic solution for such cases (AFAIU this is copied from some of Intel pin control driver, so, we have two or more users already).
For now let's go with current proposal.
Quoted 22 lines
(quoted diff) +2
-0+ ret = devm_request_irq(dev, irq, int0002_irq, + IRQF_SHARED | IRQF_NO_THREAD,"INT0002", chip);
(quoted diff) +2
-0+ if (ret) { + dev_err(dev, "Error requesting IRQ %d: %d\n", irq,ret);
drivers/gpio/gpio-int0002.c new file +14
-0+return ret; + } + + +static const struct acpi_device_id int0002_acpi_ids[] = { + {"INT0002" ,0 }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, int0002_acpi_ids); + +static struct platform_driver int0002_driver = { + .driver = { + .name =DRV_NAME , + .acpi_match_table =
Quoted 3 lines
Quoted 1 line
ACPI_PTR(int0002_acpi_ids),No #ifdef, so
ACPI_PTRcan be dropped.
Ack.
Quoted 5 lines
drivers/gpio/gpio-int0002.c line 204
Quoted 4 lines
drivers/gpio/gpio-int0002.c new file +3
-0+ }, + .probe = int0002_probe, +};
Regards,
Hans
Quoted 9 lines · Hans de Goede
Quoted 7 lines · Andy Shevchenko
drivers/gpio/Kconfig config GPIO_GPIO_MM · line 613
Quoted 3 lines · Hans de Goede
drivers/gpio/Kconfig +3
-0+config GPIO_INT0002 + tristate "Intel ACPI INT0002 Virtual GPIO" + depends on ACPI&& X86 (see below why)
Quoted 7 lines
This is part of:
menu "Port-mapped I/O GPIO drivers"
depends on X86 # Unconditional I/O space accessSo that is already required, which is why I dropped it (previous versions did have it).
OK!
Quoted 7 lines
Quoted 6 lines
drivers/gpio/gpio-int0002.c line 31
Quoted 3 lines
drivers/gpio/gpio-int0002.c new file +2
-0+#include <asm/cpu_device_id.h> +#include <asm/intel-family.h> Please, move this after <linux/*> headers with empty line in between.
Quoted 5 lines
I'm using alphabetic sort for #includes, I don't see how these are special its not like they are "local" headers, e.g.
drivers/gpio/gpio-aspeed.cdoes the same. What if this driver were to also need acpi/ headers should those go in their block too, etc. ?
Most of the drivers I saw are using such scheme
1. Most generic
2. Less generic
3. Local
<asm/*> category fits 2.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpio/gpio-int0002.c new file +4
-0+static int int0002_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +const struct x86_cpu_id *cpu_id;Quoted 8 lines
drivers/gpio/gpio-int0002.c line 134
Quoted 4 lines
drivers/gpio/gpio-int0002.c new file +4
-0+struct gpio_chip *chip; +int i, irq, ret; + +/* Menlow has a different INT0002 device? <sigh> */ Perhaps we can remove that all code. I will look at it when I have spare
time.
Quoted 6 lines
Even if we remove the code for the INT0002 Menlow device we still don't want to bind to it,
or are you talking about
dropping Menlow support in such a way that newer kernels will not boot on Menlow at all anymore ?
Latter.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy