Skip to content

Commit b68e182

Browse files
committed
platform/x86: intel_int0002_vgpio: Only call enable_irq_wake() when using s2idle
Commit 871f1f2 ("platform/x86: intel_int0002_vgpio: Only implement irq_set_wake on Bay Trail") stopped passing irq_set_wake requests on to the parents IRQ because this was breaking suspend (causing immediate wakeups) on an Asus E202SA. This workaround for the Asus E202SA is causing wakeup by USB keyboard to not work on other devices with Airmont CPU cores such as the Medion Akoya E1239T. In hindsight the problem with the Asus E202SA has nothing to do with Silvermont vs Airmont CPU cores, so the differentiation between the 2 types of CPU cores introduced by the previous fix is wrong. The real issue at hand is s2idle vs S3 suspend where the suspend is mostly handled by firmware. The parent IRQ for the INT0002 device is shared with the ACPI SCI and the real problem is that the INT0002 code should not be messing with the wakeup settings of that IRQ when suspend/resume is being handled by the firmware. Note that on systems which support both s2idle and S3 suspend, which suspend method to use can be changed at runtime. This patch fixes both the Asus E202SA spurious wakeups issue as well as the wakeup by USB keyboard not working on the Medion Akoya E1239T issue. These are both fixed by replacing the old workaround with delaying the enable_irq_wake(parent_irq) call till system-suspend time and protecting it with a !pm_suspend_via_firmware() check so that we still do not call it on devices using firmware-based (S3) suspend such as the Asus E202SA. Note rather then adding #ifdef CONFIG_PM_SLEEP, this commit simply adds a "depends on PM_SLEEP" to the Kconfig since this drivers whole purpose is to deal with wakeup events, so using it without CONFIG_PM_SLEEP makes no sense. Cc: Maxim Mikityanskiy <maxtram95@gmail.com> Fixes: 871f1f2 ("platform/x86: intel_int0002_vgpio: Only implement irq_set_wake on Bay Trail") Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://lore.kernel.org/r/20210512125523.55215-2-hdegoede@redhat.com
1 parent dac282d commit b68e182

2 files changed

Lines changed: 57 additions & 25 deletions

File tree

‎drivers/platform/x86/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ config INTEL_HID_EVENT
711711

712712
config INTEL_INT0002_VGPIO
713713
tristate "Intel ACPI INT0002 Virtual GPIO driver"
714-
depends on GPIOLIB && ACPI
714+
depends on GPIOLIB && ACPI && PM_SLEEP
715715
select GPIOLIB_IRQCHIP
716716
help
717717
Some peripherals on Bay Trail and Cherry Trail platforms signal a

‎drivers/platform/x86/intel_int0002_vgpio.c‎

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
#define GPE0A_STS_PORT 0x420
5252
#define GPE0A_EN_PORT 0x428
5353

54+
struct int0002_data {
55+
struct gpio_chip chip;
56+
int parent_irq;
57+
int wake_enable_count;
58+
};
59+
5460
/*
5561
* As this is not a real GPIO at all, but just a hack to model an event in
5662
* ACPI the get / set functions are dummy functions.
@@ -98,14 +104,16 @@ static void int0002_irq_mask(struct irq_data *data)
98104
static int int0002_irq_set_wake(struct irq_data *data, unsigned int on)
99105
{
100106
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
101-
struct platform_device *pdev = to_platform_device(chip->parent);
102-
int irq = platform_get_irq(pdev, 0);
107+
struct int0002_data *int0002 = container_of(chip, struct int0002_data, chip);
103108

104-
/* Propagate to parent irq */
109+
/*
110+
* Applying of the wakeup flag to our parent IRQ is delayed till system
111+
* suspend, because we only want to do this when using s2idle.
112+
*/
105113
if (on)
106-
enable_irq_wake(irq);
114+
int0002->wake_enable_count++;
107115
else
108-
disable_irq_wake(irq);
116+
int0002->wake_enable_count--;
109117

110118
return 0;
111119
}
@@ -135,29 +143,17 @@ static bool int0002_check_wake(void *data)
135143
return (gpe_sts_reg & GPE0A_PME_B0_STS_BIT);
136144
}
137145

138-
static struct irq_chip int0002_byt_irqchip = {
146+
static struct irq_chip int0002_irqchip = {
139147
.name = DRV_NAME,
140148
.irq_ack = int0002_irq_ack,
141149
.irq_mask = int0002_irq_mask,
142150
.irq_unmask = int0002_irq_unmask,
143151
.irq_set_wake = int0002_irq_set_wake,
144152
};
145153

146-
static struct irq_chip int0002_cht_irqchip = {
147-
.name = DRV_NAME,
148-
.irq_ack = int0002_irq_ack,
149-
.irq_mask = int0002_irq_mask,
150-
.irq_unmask = int0002_irq_unmask,
151-
/*
152-
* No set_wake, on CHT the IRQ is typically shared with the ACPI SCI
153-
* and we don't want to mess with the ACPI SCI irq settings.
154-
*/
155-
.flags = IRQCHIP_SKIP_SET_WAKE,
156-
};
157-
158154
static const struct x86_cpu_id int0002_cpu_ids[] = {
159-
X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT, &int0002_byt_irqchip),
160-
X86_MATCH_INTEL_FAM6_MODEL(ATOM_AIRMONT, &int0002_cht_irqchip),
155+
X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT, NULL),
156+
X86_MATCH_INTEL_FAM6_MODEL(ATOM_AIRMONT, NULL),
161157
{}
162158
};
163159

@@ -172,8 +168,9 @@ static int int0002_probe(struct platform_device *pdev)
172168
{
173169
struct device *dev = &pdev->dev;
174170
const struct x86_cpu_id *cpu_id;
175-
struct gpio_chip *chip;
171+
struct int0002_data *int0002;
176172
struct gpio_irq_chip *girq;
173+
struct gpio_chip *chip;
177174
int irq, ret;
178175

179176
/* Menlow has a different INT0002 device? <sigh> */
@@ -185,10 +182,13 @@ static int int0002_probe(struct platform_device *pdev)
185182
if (irq < 0)
186183
return irq;
187184

188-
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
189-
if (!chip)
185+
int0002 = devm_kzalloc(dev, sizeof(*int0002), GFP_KERNEL);
186+
if (!int0002)
190187
return -ENOMEM;
191188

189+
int0002->parent_irq = irq;
190+
191+
chip = &int0002->chip;
192192
chip->label = DRV_NAME;
193193
chip->parent = dev;
194194
chip->owner = THIS_MODULE;
@@ -214,7 +214,7 @@ static int int0002_probe(struct platform_device *pdev)
214214
}
215215

216216
girq = &chip->irq;
217-
girq->chip = (struct irq_chip *)cpu_id->driver_data;
217+
girq->chip = &int0002_irqchip;
218218
/* This let us handle the parent IRQ in the driver */
219219
girq->parent_handler = NULL;
220220
girq->num_parents = 0;
@@ -230,6 +230,7 @@ static int int0002_probe(struct platform_device *pdev)
230230

231231
acpi_register_wakeup_handler(irq, int0002_check_wake, NULL);
232232
device_init_wakeup(dev, true);
233+
dev_set_drvdata(dev, int0002);
233234
return 0;
234235
}
235236

@@ -240,6 +241,36 @@ static int int0002_remove(struct platform_device *pdev)
240241
return 0;
241242
}
242243

244+
static int int0002_suspend(struct device *dev)
245+
{
246+
struct int0002_data *int0002 = dev_get_drvdata(dev);
247+
248+
/*
249+
* The INT0002 parent IRQ is often shared with the ACPI GPE IRQ, don't
250+
* muck with it when firmware based suspend is used, otherwise we may
251+
* cause spurious wakeups from firmware managed suspend.
252+
*/
253+
if (!pm_suspend_via_firmware() && int0002->wake_enable_count)
254+
enable_irq_wake(int0002->parent_irq);
255+
256+
return 0;
257+
}
258+
259+
static int int0002_resume(struct device *dev)
260+
{
261+
struct int0002_data *int0002 = dev_get_drvdata(dev);
262+
263+
if (!pm_suspend_via_firmware() && int0002->wake_enable_count)
264+
disable_irq_wake(int0002->parent_irq);
265+
266+
return 0;
267+
}
268+
269+
static const struct dev_pm_ops int0002_pm_ops = {
270+
.suspend = int0002_suspend,
271+
.resume = int0002_resume,
272+
};
273+
243274
static const struct acpi_device_id int0002_acpi_ids[] = {
244275
{ "INT0002", 0 },
245276
{ },
@@ -250,6 +281,7 @@ static struct platform_driver int0002_driver = {
250281
.driver = {
251282
.name = DRV_NAME,
252283
.acpi_match_table = int0002_acpi_ids,
284+
.pm = &int0002_pm_ops,
253285
},
254286
.probe = int0002_probe,
255287
.remove = int0002_remove,

0 commit comments

Comments
 (0)