All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	<linux-kernel@vger.kernel.org>
Cc: Mario Limonciello <mario.limonciello@amd.com>,
	Xaver Hugl <xaver.hugl@gmail.com>, <linux-input@vger.kernel.org>
Subject: [PATCH] Input: i8042: Disable wake from keyboard by default on several AMD systems
Date: Mon, 16 Jan 2023 12:48:30 -0600	[thread overview]
Message-ID: <20230116184830.30573-1-mario.limonciello@amd.com> (raw)

By default when the system is configured for suspend to idle by default
the keyboard is set up as a wake source.  This matches the behavior that
Windows uses for Modern Standby as well.

It has been reported that a variety of AMD based designs there are
spurious wakeups are happening where two IRQ sources are active.

```
PM: Triggering wakeup from IRQ 9
PM: Triggering wakeup from IRQ 1
```

In these designs IRQ 9 is the ACPI SCI and IRQ 1 is the PS/2 keyboard.
An example way to trigger this is to suspend the system and then unplug
the AC adapter.  The SOC will be in a hardware sleep state and plugging
in the AC adapter returns control to the kernel's s2idle loop.

Normally if just IRQ 9 was active the s2idle loop would advance any EC
transactions and no other IRQ being active would cause the s2idle loop
to put the SOC back into hardware sleep state.

When this bug occurred IRQ 1 is also active even if no keyboard activity
occurred. This causes the s2idle loop to break and the system to wake.

This is a platform firmware bug triggering IRQ1 without keyboard activity.
This occurs in Windows as well, but Windows will enter "SW DRIPS" and
then with no activity enters back into "HW DRIPS" (hardware sleep state).

This issue affects Renoir, Lucienne, Cezanne, and Barcelo based platforms
that use LPC EC. It does not happen on newer systems such as Mendocino or
Rembrandt.

It's been fixed in newer platform firmware, but determining whether the
system vendor uses an LPC EC and has deployed the fix is not possible.

To avoid triggering the bug check the CPU model and adjust the policy for
s2idle wakeup from keyboard on these systems to be disabled by default.

Users who know that their firmware is fixed and want to use wakeup from
keyboard can manually enable wakeup from sysfs by modifying
`/sys/bus/serio/devices/serio0/power/wakeup`.

Reported-by: Xaver Hugl <xaver.hugl@gmail.com>
Tested-by: Xaver Hugl <xaver.hugl@gmail.com>
Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2115#note_1724008
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/input/serio/i8042.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 6dac7c1853a54..c9eeca18c0816 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -23,6 +23,7 @@
 #include <linux/suspend.h>
 #include <linux/property.h>
 
+#include <asm/cpu_device_id.h>
 #include <asm/io.h>
 
 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
@@ -433,6 +434,26 @@ static void i8042_port_close(struct serio *serio)
 	i8042_interrupt(0, NULL);
 }
 
+static bool i8042_should_wakeup_by_default(struct serio *serio)
+{
+#ifdef CONFIG_X86
+	const struct x86_cpu_id irq1_bug_cpu_ids[] = {
+		X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 96, NULL),	/* Renoir */
+		X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 104, NULL),	/* Lucienne */
+		X86_MATCH_VENDOR_FAM_MODEL(AMD, 25, 80, NULL),	/* Cezanne/Barcelo */
+		{}
+	};
+
+	if (x86_match_cpu(irq1_bug_cpu_ids)) {
+		pr_info_once("Disabling wakeup from keyboard to avoid firmware bug\n");
+		return false;
+	}
+#endif
+	if (!pm_suspend_default_s2idle())
+		return false;
+	return serio == i8042_ports[I8042_KBD_PORT_NO].serio;
+}
+
 /*
  * i8042_start() is called by serio core when port is about to finish
  * registering. It will mark port as existing so i8042_interrupt can
@@ -451,10 +472,8 @@ static int i8042_start(struct serio *serio)
 	 * behavior on many platforms using suspend-to-RAM (ACPI S3)
 	 * by default.
 	 */
-	if (pm_suspend_default_s2idle() &&
-	    serio == i8042_ports[I8042_KBD_PORT_NO].serio) {
+	if (i8042_should_wakeup_by_default(serio))
 		device_set_wakeup_enable(&serio->dev, true);
-	}
 
 	spin_lock_irq(&i8042_lock);
 	port->exists = true;
-- 
2.34.1


             reply	other threads:[~2023-01-16 18:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16 18:48 Mario Limonciello [this message]
2023-01-16 22:59 ` [PATCH] Input: i8042: Disable wake from keyboard by default on several AMD systems Dmitry Torokhov
2023-01-17  2:51 ` Limonciello, Mario

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230116184830.30573-1-mario.limonciello@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xaver.hugl@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.