drivers/platform/x86: Add driver for INT0002 ACPI device
Subsystems (2)
PATCH 1/1 drivers/platform/x86: Add driver for INT0002 ACPI device
Some peripherals on Baytrail and Cherrytrail 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 modelled in ACPI through the INT0002 ACPI device.
This commit adds a driver which will bind to that device, call the ACPI event handler for the wakeup and clear the interrupt source avoiding the irq storm.
--- drivers/platform/x86/Kconfig | 10 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_int0002.c | 232 +++++++++++++++++++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 drivers/platform/x86/intel_int0002.c
drivers/platform/x86/Kconfig +10 -0
@@ -889,6 +889,16 @@ config INTEL_PMC_CORE Supported features: - SLP_S0_RESIDENCY counter. +config INTEL_INT0002 + tristate "Intel INT0002 Virtual GPIO ACPI device driver" + depends on X86 && ACPI + ---help--- + Some peripherals on Baytrail and Cherrytrail platforms signal + PME to the PMC to wakeup the system. When this happens software + needs to explictly clear the interrupt source to avoid an IRQ + storm on IRQ 9. This is modelled in ACPI through the INT0002 + ACPI device. This driver implements the clearing of the IRQ. + config IBM_RTL tristate "Device driver to enable PRTL support" depends on PCI
drivers/platform/x86/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o obj-$(CONFIG_INTEL_SCU_IPC_UTIL) += intel_scu_ipcutil.o obj-$(CONFIG_INTEL_MFLD_THERMAL) += intel_mid_thermal.o obj-$(CONFIG_INTEL_IPS) += intel_ips.o +obj-$(CONFIG_INTEL_INT0002) += intel_int0002.o obj-$(CONFIG_XO1_RFKILL) += xo1-rfkill.o obj-$(CONFIG_XO15_EBOOK) += xo15-ebook.o obj-$(CONFIG_IBM_RTL) += ibm_rtl.o
drivers/platform/x86/intel_int0002.c new file +232 -0
232 lines not on this page · raw message
Signature · 1 line
2.9.3
Quoted 5 lines · Hans de Goede
Some peripherals on Baytrail and Cherrytrail platforms signal PME to the PMC to wakeup the system. When this happens software needs to clear the
PME_B0_STSbit in theGPE0a_STSregister to avoid an IRQ storm on IRQ 9.
Quoted 7 lines
This is modelled in ACPI through the INT0002 ACPI device.
This commit adds a driver which will bind to that device, call the ACPI event handler for the wakeup and clear the interrupt source avoiding the irq storm.
Signed-off-by Hans de Goede <[email protected]>
This patch requires your previous "always present" patchset, right?
Some nitpicking:
Quoted 2 lines
drivers/platform/x86/intel_int0002.c new file +0
-0
...
drivers/platform/x86/intel_int0002.c line 62
Quoted 6 lines
drivers/platform/x86/intel_int0002.c new file +6
-0+struct int0002_data { +struct spinlock lock; +struct device *dev; +const struct x86_cpu_id *cpu_id; +acpi_handle handle; +char ev_name[5 ];
Are 5 bytes enough? I see the code below:
drivers/platform/x86/intel_int0002.c line 169
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+snprintf (data->ev_name,sizeof (data->ev_name),"_%c%02X" , + res->data.gpio.triggering ?'E' :'L' , + res->data.gpio.pin_table[0 ]);
So it counts 6 including NUL.
drivers/platform/x86/intel_int0002.c line 128
Quoted 13 lines
drivers/platform/x86/intel_int0002.c new file +13
-0+static int int0002_probe (struct platform_device *pdev) +{ +struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct device *dev = &pdev->dev; +struct int0002_data *data; +struct acpi_resource *res; +acpi_status status; +acpi_handle hdl; +int irq, ret; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) { +dev_err (dev,"can't allocate memory for int0002\n" );
The error message is mostly superfluous.
Quoted 4 lines
drivers/platform/x86/intel_int0002.c new file +4
-0+static int int0002_runtime_suspend (struct device *dev) +{ +return 0 ; +}
drivers/platform/x86/intel_int0002.c line 211
Quoted 10 lines
drivers/platform/x86/intel_int0002.c new file +10
-0+ +static int int0002_runtime_resume (struct device *dev) +{ +return 0 ; +} + +static const struct dev_pm_ops int0002_pm_ops = { + .runtime_suspend = int0002_runtime_suspend, + .runtime_resume = int0002_runtime_resume, +};
Do we need these runtime PM? If not, we can remove the header inclusion, too.
Other than that, I confirmed to work on my ASUS E200H.
thanks,
Takashi
Quoted 15 lines · Takashi Iwai
Quoted 5 lines · Hans de Goede
Some peripherals on Baytrail and Cherrytrail platforms signal PME to the PMC to wakeup the system. When this happens software needs to clear the
PME_B0_STSbit in theGPE0a_STSregister to avoid an IRQ storm on IRQ 9.Quoted 7 lines
This is modelled in ACPI through the INT0002 ACPI device.
This commit adds a driver which will bind to that device, call the ACPI event handler for the wakeup and clear the interrupt source avoiding the irq storm.
+ char ev_name[5];
Quoted 7 lines
Are 5 bytes enough? I see the code below:
drivers/platform/x86/intel_int0002.c line 169
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+snprintf (data->ev_name,sizeof (data->ev_name),"_%c%02X" , + res->data.gpio.triggering ?'E' :'L' , + res->data.gpio.pin_table[0 ]);So it counts 6 including NUL.
How? 4 + NUL = 5.
OTOH it looks like code duplication with existing drivers (GPIO ACPI library IIRC) which might make sense to make generic.
Quoted 15 lines
drivers/platform/x86/intel_int0002.c line 128
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+ data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) { +dev_err (dev,"can't allocate memory for int0002\n" );The error message is mostly superfluous.
Quoted 9 lines
drivers/platform/x86/intel_int0002.c new file +9
-0+static int int0002_runtime_suspend (struct device *dev) +{ +return 0 ; +} + +static int int0002_runtime_resume (struct device *dev) +{ +return 0 ; +}
Quoted 8 lines
drivers/platform/x86/intel_int0002.c line 211
Quoted 5 lines
drivers/platform/x86/intel_int0002.c new file +5
-0+ +static const struct dev_pm_ops int0002_pm_ops = { + .runtime_suspend = int0002_runtime_suspend, + .runtime_resume = int0002_runtime_resume, +};Do we need these runtime PM? If not, we can remove the header inclusion, too.
Yeah, and it needs attention when built with !CONFIG_PM.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 19 lines · Andy Shevchenko
Quoted 17 lines · Takashi Iwai
Quoted 5 lines · Hans de Goede
Some peripherals on Baytrail and Cherrytrail platforms signal PME to the PMC to wakeup the system. When this happens software needs to clear the
PME_B0_STSbit in theGPE0a_STSregister to avoid an IRQ storm on IRQ 9.Quoted 7 lines
This is modelled in ACPI through the INT0002 ACPI device.
This commit adds a driver which will bind to that device, call the ACPI event handler for the wakeup and clear the interrupt source avoiding the irq storm.
+ char ev_name[5];
Are 5 bytes enough? I see the code below:
Quoted 7 lines
Quoted 5 lines
drivers/platform/x86/intel_int0002.c line 169
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+snprintf (data->ev_name,sizeof (data->ev_name),"_%c%02X" , + res->data.gpio.triggering ?'E' :'L' , + res->data.gpio.pin_table[0 ]);So it counts 6 including NUL.
How? 4 + NUL = 5.
Well, "_E00X" is 5 letters, IIUC.
Quoted 27 lines
OTOH it looks like code duplication with existing drivers (GPIO ACPI library IIRC) which might make sense to make generic.
Quoted 15 lines
drivers/platform/x86/intel_int0002.c line 128
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+ data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) { +dev_err (dev,"can't allocate memory for int0002\n" );The error message is mostly superfluous.
Quoted 9 lines
drivers/platform/x86/intel_int0002.c new file +9
-0+static int int0002_runtime_suspend (struct device *dev) +{ +return 0 ; +} + +static int int0002_runtime_resume (struct device *dev) +{ +return 0 ; +}Quoted 8 lines
drivers/platform/x86/intel_int0002.c line 211
Quoted 5 lines
drivers/platform/x86/intel_int0002.c new file +5
-0+ +static const struct dev_pm_ops int0002_pm_ops = { + .runtime_suspend = int0002_runtime_suspend, + .runtime_resume = int0002_runtime_resume, +};Do we need these runtime PM? If not, we can remove the header inclusion, too.
Quoted 1 line
Yeah, and it needs attention when built with !CONFIG_PM.
Practically seen, we may build this only with CONFIG_PM, too. The virtual GPIO thing happens only when the machine gets resumed.
Takashi
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Takashi Iwai
Quoted 1 line · Hans de Goede
+ char ev_name[5];
Are 5 bytes enough? I see the code below:
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+snprintf (data->ev_name,sizeof (data->ev_name),"_%c%02X" , + res->data.gpio.triggering ?'E' :'L' , + res->data.gpio.pin_table[0 ]);
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
So it counts 6 including NUL.
How? 4 + NUL = 5.
Well, "
_E00X" is 5 letters, IIUC.
Well, today is Friday, yes.
But %02X means two capitalized hex characters.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
drivers/platform/x86/intel_int0002.c line 211
Quoted 9 lines
drivers/platform/x86/intel_int0002.c new file +9
-0+static int int0002_runtime_resume (struct device *dev) +{ +return 0 ; +} + +static const struct dev_pm_ops int0002_pm_ops = { + .runtime_suspend = int0002_runtime_suspend, + .runtime_resume = int0002_runtime_resume, +};Do we need these runtime PM? If not, we can remove the header inclusion, too.
Quoted 4 lines
Quoted 1 line
Yeah, and it needs attention when built with !CONFIG_PM.
Practically seen, we may build this only with
CONFIG_PM, too. The virtual GPIO thing happens only when the machine gets resumed.
Perhaps depend on PM then?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 16 lines · Andy Shevchenko
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Takashi Iwai
Quoted 1 line · Hans de Goede
+ char ev_name[5];
Are 5 bytes enough? I see the code below:
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+snprintf (data->ev_name,sizeof (data->ev_name),"_%c%02X" , + res->data.gpio.triggering ?'E' :'L' , + res->data.gpio.pin_table[0 ]);
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
So it counts 6 including NUL.
How? 4 + NUL = 5.
Well, "
_E00X" is 5 letters, IIUC.Well, today is Friday, yes.
But %02X means two capitalized hex characters.
Bah, of course, Friday morning, and I have to take a coffee.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
drivers/platform/x86/intel_int0002.c line 211
Quoted 9 lines
drivers/platform/x86/intel_int0002.c new file +9
-0+static int int0002_runtime_resume (struct device *dev) +{ +return 0 ; +} + +static const struct dev_pm_ops int0002_pm_ops = { + .runtime_suspend = int0002_runtime_suspend, + .runtime_resume = int0002_runtime_resume, +};Do we need these runtime PM? If not, we can remove the header inclusion, too.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Yeah, and it needs attention when built with !CONFIG_PM.
Practically seen, we may build this only with
CONFIG_PM, too. The virtual GPIO thing happens only when the machine gets resumed.Perhaps depend on PM then?
Yes, it may make our lives a bit easier.
We stumbled on this driver just because of the hang at resume, and who wants Cherrytrail device without PM?
thanks,
Takashi
Hi,
Quoted 9 lines · Takashi Iwai
Quoted 7 lines · Hans de Goede
Some peripherals on Baytrail and Cherrytrail platforms signal PME to the PMC to wakeup the system. When this happens software needs to clear the
PME_B0_STSbit in theGPE0a_STSregister to avoid an IRQ storm on IRQ 9.This is modelled in ACPI through the INT0002 ACPI device.
Quoted 7 lines
Quoted 5 lines
This commit adds a driver which will bind to that device, call the ACPI event handler for the wakeup and clear the interrupt source avoiding the irq storm.
Signed-off-by Hans de Goede <[email protected]>This patch requires your previous "always present" patchset, right?
On boards where the _STA for INT0002 returns 0, that patchset is needed for the driver to bind to the device, so yes it has a functional requirement on some (most it seems) board, but only at run-time, it can be merged independently.
Quoted 14 lines
Some nitpicking:
Quoted 2 lines
drivers/platform/x86/intel_int0002.c new file +0
-0...
drivers/platform/x86/intel_int0002.c line 62
Quoted 6 lines
drivers/platform/x86/intel_int0002.c new file +6
-0+struct int0002_data { +struct spinlock lock; +struct device *dev; +const struct x86_cpu_id *cpu_id; +acpi_handle handle; +char ev_name[5 ];Are 5 bytes enough? I see the code below:
Quoted 5 lines
drivers/platform/x86/intel_int0002.c line 169
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+snprintf (data->ev_name,sizeof (data->ev_name),"_%c%02X" , + res->data.gpio.triggering ?'E' :'L' , + res->data.gpio.pin_table[0 ]);So it counts 6 including NUL.
The name is e.g. _E02 or _L02 so 5 bytes including the NUL is enough :)
Quoted 16 lines
Quoted 4 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+static int int0002_probe (struct platform_device *pdev) +{ +struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER ,NULL };drivers/platform/x86/intel_int0002.c line 128
Quoted 10 lines
drivers/platform/x86/intel_int0002.c new file +10
-0+struct device *dev = &pdev->dev; +struct int0002_data *data; +struct acpi_resource *res; +acpi_status status; +acpi_handle hdl; +int irq, ret; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) { +dev_err (dev,"can't allocate memory for int0002\n" );The error message is mostly superfluous.
Agreed, will fix for v2.
Quoted 9 lines
Quoted 9 lines
drivers/platform/x86/intel_int0002.c new file +9
-0+static int int0002_runtime_suspend (struct device *dev) +{ +return 0 ; +} + +static int int0002_runtime_resume (struct device *dev) +{ +return 0 ; +}
Quoted 8 lines
drivers/platform/x86/intel_int0002.c line 211
Quoted 5 lines
drivers/platform/x86/intel_int0002.c new file +5
-0+ +static const struct dev_pm_ops int0002_pm_ops = { + .runtime_suspend = int0002_runtime_suspend, + .runtime_resume = int0002_runtime_resume, +};Do we need these runtime PM? If not, we can remove the header inclusion, too.
We enable runtime pm for this device, at which point these are mandatory.
Quoted 2 lines
Other than that, I confirmed to work on my ASUS E200H.
Tested-by Takashi Iwai <[email protected]>
Regards,
Hans
Hi,
Quoted 84 lines · Hans de Goede
Hi,
Quoted 9 lines · Takashi Iwai
Quoted 7 lines · Hans de Goede
Some peripherals on Baytrail and Cherrytrail platforms signal PME to the PMC to wakeup the system. When this happens software needs to clear the
PME_B0_STSbit in theGPE0a_STSregister to avoid an IRQ storm on IRQ 9.This is modelled in ACPI through the INT0002 ACPI device.
Quoted 7 lines
Quoted 5 lines
This commit adds a driver which will bind to that device, call the ACPI event handler for the wakeup and clear the interrupt source avoiding the irq storm.
Signed-off-by Hans de Goede <[email protected]>This patch requires your previous "always present" patchset, right?
On boards where the
_STAfor INT0002 returns 0, that patchset is needed for the driver to bind to the device, so yes it has a functional requirement on some (most it seems) board, but only at run-time, it can be merged independently.Quoted 12 lines
Some nitpicking:
Quoted 2 lines
drivers/platform/x86/intel_int0002.c new file +0
-0...
drivers/platform/x86/intel_int0002.c line 62
Quoted 6 lines
drivers/platform/x86/intel_int0002.c new file +6
-0+struct int0002_data { +struct spinlock lock; +struct device *dev; +const struct x86_cpu_id *cpu_id; +acpi_handle handle; +char ev_name[5 ];Quoted 7 lines
Are 5 bytes enough? I see the code below:
drivers/platform/x86/intel_int0002.c line 169
Quoted 3 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+snprintf (data->ev_name,sizeof (data->ev_name),"_%c%02X" , + res->data.gpio.triggering ?'E' :'L' , + res->data.gpio.pin_table[0 ]);So it counts 6 including NUL.
The name is e.g.
_E02or_L02so 5 bytes including the NUL is enough :)Quoted 16 lines
Quoted 4 lines
drivers/platform/x86/intel_int0002.c new file +3
-0+static int int0002_probe (struct platform_device *pdev) +{ +struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER ,NULL };drivers/platform/x86/intel_int0002.c line 128
Quoted 10 lines
drivers/platform/x86/intel_int0002.c new file +10
-0+struct device *dev = &pdev->dev; +struct int0002_data *data; +struct acpi_resource *res; +acpi_status status; +acpi_handle hdl; +int irq, ret; + + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) { +dev_err (dev,"can't allocate memory for int0002\n" );The error message is mostly superfluous.
Agreed, will fix for v2.
Quoted 9 lines
Quoted 9 lines
drivers/platform/x86/intel_int0002.c new file +9
-0+static int int0002_runtime_suspend (struct device *dev) +{ +return 0 ; +} + +static int int0002_runtime_resume (struct device *dev) +{ +return 0 ; +}Quoted 8 lines
drivers/platform/x86/intel_int0002.c line 211
Quoted 5 lines
drivers/platform/x86/intel_int0002.c new file +5
-0+ +static const struct dev_pm_ops int0002_pm_ops = { + .runtime_suspend = int0002_runtime_suspend, + .runtime_resume = int0002_runtime_resume, +};Do we need these runtime PM? If not, we can remove the header inclusion, too.
Quoted 2 lines
We enable runtime pm for this device, at which point these are mandatory.
Correction, I thought the driver was enabling runtime pm but it does not, so these can simply be removed. Will fix for v2.
Regards,
Hans
Quoted 18 lines · Hans de Goede
Some peripherals on Baytrail and Cherrytrail platforms signal PME to the PMC to wakeup the system. When this happens software needs to clear the
PME_B0_STSbit in theGPE0a_STSregister to avoid an IRQ storm on IRQ 9.This is modelled in ACPI through the INT0002 ACPI device.
This commit adds a driver which will bind to that device, call the ACPI event handler for the wakeup and clear the interrupt source avoiding the irq storm.
Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/Kconfig | 10 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/intel_int0002.c | 232 +++++++++++++++++++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 drivers/platform/x86/intel_int0002.c
[...snip]
Quoted 34 lines
drivers/platform/x86/intel_int0002.c new file +31
-0@@ -0,0 +1,232 @@ +/* +* Intel INT0002 "Virtual GPIO" driver +* +* Copyright (C) 2017 Hans de Goede <[email protected]> +* +* Loosely based on android x86 kernel code which is: +* +* Copyright (c) 2014, Intel Corporation. +* +* Author: Dyut Kumar Sil <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* Some peripherals on Baytrail and Cherrytrail 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 modelled in ACPI through the INT0002 ACPI device, which is +* called a "Virtual GPIO controller" in ACPI because it defines the event +* handler to call when the PME triggers through _AEI and _L02 / _E02 +* methods as would be done for a real GPIO interrupt. +* +* This driver will bind to the INT0002 device, call the ACPI event handler +* for the wakeup and clear the interrupt source avoiding the irq storm. +*/ + +#include <asm/cpu_device_id.h> +#include <asm/intel-family.h> +#include <asm/io.h>
drivers/platform/x86/intel_int0002.c line 41
Quoted 10 lines
drivers/platform/x86/intel_int0002.c new file +10
-0+#include <linux/acpi.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/slab.h> + +#define GPE0A_PME_STS_BIT 0x2000 +#define GPE0A_PME_EN_BIT 0x2000
Maybe it's minor. Could you please consider to change the name to GPE0A_PME_B0_STS_BIT and GPE0A_PME_B0_EN_BIT?
Because it's easy to confuse with the PME_STS/PME_EN bit (0x800, bit 11)
Thanks a lot!
Joey Lee