From d79e141c1c6ea7cb70c169971d522b88c8d5b419 Mon Sep 17 00:00:00 2001
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Fri, 9 Dec 2016 12:57:39 -0800
Subject: [PATCH] Input: i8042 - Trust firmware a bit more when probing on X86
Git-commit: d79e141c1c6ea7cb70c169971d522b88c8d5b419
Patch-mainline: 4.10-rc1
References: bsc#1011660

The error message "Can't read CTR while initializing i8042" appears on
Cherry Trail-based devices at each boot time:

  i8042: PNP: No PS/2 controller found. Probing ports directly.
  i8042: Can't read CTR while initializing i8042
  i8042: probe of i8042 failed with error -5

This happens because we historically do not trust firmware on X86 and,
while noting that PNP does not show keyboard or mouse devices, we still
charge ahead and try to probe the controller. Let's relax this a bit and if
results of PNP probe agree with the results of platform
initialization/quirks conclude that there is, in fact, no i8042.

While at it, let's avoid using x86_platform.i8042_detect() and instead
abort execution early if platform indicates that it can not possibly have
i8042 (x86_platform.legacy.i8042 equals X86_LEGACY_I8042_PLATFORM_ABSENT).

Reported-and-tested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
Cc: linux-input@vger.kernel.org
Link: http://lkml.kernel.org/r/1481317061-31486-3-git-send-email-dmitry.torokhov@gmail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 drivers/input/serio/i8042-x86ia64io.h |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -891,6 +891,7 @@ static const struct dmi_system_id __init
 
 #ifdef CONFIG_PNP
 #include <linux/pnp.h>
+#include <linux/acpi.h>
 
 static bool i8042_pnp_kbd_registered;
 static unsigned int i8042_pnp_kbd_devices;
@@ -1055,7 +1056,15 @@ static int __init i8042_pnp_init(void)
 #if defined(__ia64__)
 		return -ENODEV;
 #else
-		pr_info("PNP: No PS/2 controller found. Probing ports directly.\n");
+		pr_info("PNP: No PS/2 controller found.\n");
+#ifdef CONFIG_ACPI
+		if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
+		    !(acpi_gbl_FADT.boot_flags & ACPI_FADT_8042)) {
+			pr_debug("ACPI: i8042 controller is absent\n");
+			return -ENODEV;
+		}
+#endif
+		pr_info("Probing ports directly.\n");
 		return 0;
 #endif
 	}
@@ -1142,7 +1151,7 @@ static int __init i8042_platform_init(vo
 
 #ifdef CONFIG_X86
 	u8 a20_on = 0xdf;
-	/* Just return if pre-detection shows no i8042 controller exist */
+	/* Just return if platform does not have i8042 controller */
 	if (!x86_platform.i8042_detect())
 		return -ENODEV;
 #endif
