Skip to contentSkip to conversation

Input: atkbd - filter buggy codes on ASUS Q500A

PATCH In review Oleksij Rempel 3 participants 5 messages Jul 29, 2016 – Sep 24, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: atkbd - filter buggy codes on ASUS Q500A

Some revision of ASUS Q500A series have keyboard related issue which is reproducible only if Windows with installed ASUS tools was ever started.
In this case the Linux side will have blocked keyboard or report wrong or incomplete hotkey events.
To make Linux work properly again complete power down (unplug power supply and remove battery) should be made.

Linux/atkbd after clean start will get fallowing code on VOLUME_UP
key: {0xe0, 0x30, 0xe0, 0xb0}. After Windows, same key will generate this
codes: {0xe1, 0x23, 0xe0, 0x30, 0xe0, 0xb0}. As result atkdb will be confused by buggy codes.

This patch is filtering this buggy code out.

https://bugzilla.kernel.org/show_bug.cgi?id=119391

---
 drivers/input/keyboard/atkbd.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/input/keyboard/atkbd.c +19 -0
index ec876b5..949c199 100644
@@ -996,6 +996,17 @@ static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd,
 	return code;
 }
 
+static unsigned int atkbd_asus_q500a_scancode_fixup(struct atkbd *atkbd,
+						    unsigned int code)
+{
+	if (atkbd->translated && atkbd->emul == 2 && code == 0x23) {
+		atkbd->emul = 0;
+		return ATKBD_RET_ERR;
+	}
+
+	return code;
+}
+
 /*
  * atkbd_set_keycode_table() initializes keyboard's keycode table
  * according to the selected scancode set
@@ -1802,6 +1813,14 @@ static const struct dmi_system_id atkbd_dmi_quirk_table[] __initconst = {
 		},
 		.callback = atkbd_deactivate_fixup,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Q500A"),
+		},
+		.callback = atkbd_setup_scancode_fixup,
+		.driver_data = atkbd_asus_q500a_scancode_fixup,
+	},
 	{ }
 };
 
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Hi Oleksij,

Quoted 13 lines · Oleksij Rempel

Some revision of ASUS Q500A series have keyboard related issue which is reproducible only if Windows with installed ASUS tools was ever started.
In this case the Linux side will have blocked keyboard or report wrong or incomplete hotkey events.
To make Linux work properly again complete power down (unplug power supply and remove battery) should be made.

Linux/atkbd after clean start will get fallowing code on VOLUME_UP
key: {0xe0, 0x30, 0xe0, 0xb0}. After Windows, same key will generate this
codes: {0xe1, 0x23, 0xe0, 0x30, 0xe0, 0xb0}. As result atkdb will be confused by buggy codes.

Quoted 7 lines

This patch is filtering this buggy code out.

https://bugzilla.kernel.org/show_bug.cgi?id=119391

I'd prefer it was done as a i8042_filter() installed in a platform driver (asus-laptop.c?). I a filter you'd need to note the fact that you received e1 and when you receive next character you either swallo both or re-inject e1 and the new character. See filter implementation in ./drivers/input/misc/ideapad_slidebar.c.

The scancode fixup method is quite old and is better suited when you actually want to use the scancode, just a different one. Here you are forced to user ATKBD_RET_ERR which causes debug messages and increment error counter.

Thanks.

Quoted 44 lines
---
 drivers/input/keyboard/atkbd.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/input/keyboard/atkbd.c +19 -0
index ec876b5..949c199 100644
@@ -996,6 +996,17 @@ static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd,
 	return code;
 }
 
+static unsigned int atkbd_asus_q500a_scancode_fixup(struct atkbd *atkbd,
+						    unsigned int code)
+{
+	if (atkbd->translated && atkbd->emul == 2 && code == 0x23) {
+		atkbd->emul = 0;
+		return ATKBD_RET_ERR;
+	}
+
+	return code;
+}
+
 /*
  * atkbd_set_keycode_table() initializes keyboard's keycode table
  * according to the selected scancode set
@@ -1802,6 +1813,14 @@ static const struct dmi_system_id atkbd_dmi_quirk_table[] __initconst = {
 		},
 		.callback = atkbd_deactivate_fixup,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Q500A"),
+		},
+		.callback = atkbd_setup_scancode_fixup,
+		.driver_data = atkbd_asus_q500a_scancode_fixup,
+	},
 	{ }
 };
 
Signature · 1 line
2.7.4
Signature · 1 line
Dmitry
#2 lore raw

Am 04.08.2016 um 02:50 schrieb Dmitry Torokhov:

Quoted 30 lines

Hi Oleksij,

Quoted 13 lines · Oleksij Rempel

Some revision of ASUS Q500A series have keyboard related issue which is reproducible only if Windows with installed ASUS tools was ever started.
In this case the Linux side will have blocked keyboard or report wrong or incomplete hotkey events.
To make Linux work properly again complete power down (unplug power supply and remove battery) should be made.

Linux/atkbd after clean start will get fallowing code on VOLUME_UP
key: {0xe0, 0x30, 0xe0, 0xb0}. After Windows, same key will generate this
codes: {0xe1, 0x23, 0xe0, 0x30, 0xe0, 0xb0}. As result atkdb will be confused by buggy codes.

Quoted 7 lines

This patch is filtering this buggy code out.

https://bugzilla.kernel.org/show_bug.cgi?id=119391

I'd prefer it was done as a i8042_filter() installed in a platform driver (asus-laptop.c?). I a filter you'd need to note the fact that you received e1 and when you receive next character you either swallo both or re-inject e1 and the new character. See filter implementation in ./drivers/input/misc/ideapad_slidebar.c.

Quoted 4 lines

The scancode fixup method is quite old and is better suited when you actually want to use the scancode, just a different one. Here you are forced to user ATKBD_RET_ERR which causes debug messages and increment error counter.

Hm... i was seeking for a proper place for this filter and noticed fallowing issue. If asus_nb_wmi driver is loaded and machine is in bad state after windows start i get this scan codes:

0x5f 0xdf
0x5f 0xdf 0x23
0x5f 0xdf
0x5f 0xdf 0x23
0xe0 0x1f 0xe0 0x9f
0xe0 0x1f 0xe0 0x9f 0x23
0xe0 0x1f 0xe0 0x9f
0xe0 0x1f 0xe0 0x9f 0x23
0xe0 0x3b 0xe0 0xbb
0xe0 0x3b 0xe0 0xbb 0x23
0xe0 0x3b 0xe0 0xbb
0xe0 0x3b 0xe0 0xbb 0x23

--- 0x23 is a good indicator for previously described corrupted codes.

If i remove asus_nb_wmi driver, i'll get only 0x23 on each second hot kay event:

0x23
0x23
0x23

I ask my self if it make any sense to filter it in platform driver. Because in case it is not loaded i still have broken keyboard. If atkbd is not load, there is no issue - it is just not working ;)

Quoted 47 lines

Thanks.

Quoted 44 lines
---
 drivers/input/keyboard/atkbd.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/input/keyboard/atkbd.c +19 -0
index ec876b5..949c199 100644
@@ -996,6 +996,17 @@ static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd,
 	return code;
 }
 
+static unsigned int atkbd_asus_q500a_scancode_fixup(struct atkbd *atkbd,
+						    unsigned int code)
+{
+	if (atkbd->translated && atkbd->emul == 2 && code == 0x23) {
+		atkbd->emul = 0;
+		return ATKBD_RET_ERR;
+	}
+
+	return code;
+}
+
 /*
  * atkbd_set_keycode_table() initializes keyboard's keycode table
  * according to the selected scancode set
@@ -1802,6 +1813,14 @@ static const struct dmi_system_id atkbd_dmi_quirk_table[] __initconst = {
 		},
 		.callback = atkbd_deactivate_fixup,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Q500A"),
+		},
+		.callback = atkbd_setup_scancode_fixup,
+		.driver_data = atkbd_asus_q500a_scancode_fixup,
+	},
 	{ }
 };
 
Signature · 1 line
2.7.4
Signature · 2 lines
Regards,
Oleksij
#3 lore raw

PATCH 1/1 asus-wmi: filter buggy scan codes on ASUS Q500A

In reply to Dmitry Torokhov

Some revision of ASUS Q500A series have keyboard related issue which is reproducible only if Windows with installed ASUS tools was ever started.
In this case the Linux side will have blocked keyboard or report wrong or incomplete hotkey events.
To make Linux work properly again complete power down (unplug power supply and remove battery) should be made.

Linux/atkbd after clean start will get fallowing code on VOLUME_UP
key: {0xe0, 0x30, 0xe0, 0xb0}. After Windows, same key will generate this
codes: {0xe1, 0x23, 0xe0, 0x30, 0xe0, 0xb0}. As result atkdb will be confused by buggy codes.

This patch is filtering this buggy code out.

https://bugzilla.kernel.org/show_bug.cgi?id=119391

---
 drivers/platform/x86/asus-nb-wmi.c | 45 ++++++++++++++++++++++++++++++++++++++
 drivers/platform/x86/asus-wmi.h    |  4 ++++
 2 files changed, 49 insertions(+)
drivers/platform/x86/asus-nb-wmi.c +45 -0
index adecc1c..787da83 100644
@@ -27,6 +27,7 @@
 #include <linux/input/sparse-keymap.h>
 #include <linux/fb.h>
 #include <linux/dmi.h>
+#include <linux/i8042.h>
 
 #include "asus-wmi.h"
 
@@ -55,10 +56,35 @@ MODULE_PARM_DESC(wapf, "WAPF value");
 
 static struct quirk_entry *quirks;
 
+static bool asus_q500a_i8042_filter(unsigned char data, unsigned char str,
+			      struct serio *port)
+{
+	static bool extended;
+	bool ret = false;
+
+
+	if (str & I8042_STR_AUXDATA)
+		return false;
+
+	if (unlikely(data == 0xe1)) {
+		extended = true;
+		ret = true;
+	} else if (unlikely(extended)) {
+		extended = false;
+		ret = true;
+	}
+
+	return ret;
+}
+
 static struct quirk_entry quirk_asus_unknown = {
 	.wapf = 0,
 };
 
+static struct quirk_entry quirk_asus_q500a = {
+	.i8042_filter = asus_q500a_i8042_filter,
+};
+
 /*
  * For those machines that need software to control bt/wifi status
  * and can't adjust brightness through ACPI interface
@@ -96,6 +122,15 @@ static int dmi_matched(const struct dmi_system_id *dmi)
 static const struct dmi_system_id asus_quirks[] = {
 	{
 		.callback = dmi_matched,
+		.ident = "ASUSTeK COMPUTER INC. Q500A",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Q500A"),
+		},
+		.driver_data = &quirk_asus_q500a,
+	},
+	{
+		.callback = dmi_matched,
 		.ident = "ASUSTeK COMPUTER INC. U32U",
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
@@ -356,6 +391,8 @@ static const struct dmi_system_id asus_quirks[] = {
 
 static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver)
 {
+	int ret;
+
 	quirks = &quirk_asus_unknown;
 	dmi_check_system(asus_quirks);
 
@@ -367,6 +404,14 @@ static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver)
 		quirks->wapf = wapf;
 	else
 		wapf = quirks->wapf;
+
+	if (quirks->i8042_filter) {
+		ret = i8042_install_filter(quirks->i8042_filter);
+		if (ret) {
+			pr_warn("Unable to install key filter\n");
+		}
+		pr_info("Using i8042 filter function for receiving events\n");
+	}
 }
 
 static const struct key_entry asus_nb_wmi_keymap[] = {
drivers/platform/x86/asus-wmi.h +4 -0
index 5de1df5..dd2e6cc 100644
@@ -28,6 +28,7 @@
 #define _ASUS_WMI_H_
 
 #include <linux/platform_device.h>
+#include <linux/i8042.h>
 
 #define ASUS_WMI_KEY_IGNORE (-1)
 #define ASUS_WMI_BRN_DOWN	0x20
@@ -51,6 +52,9 @@ struct quirk_entry {
 	 * and let the ACPI interrupt to send out the key event.
 	 */
 	int no_display_toggle;
+
+	bool (*i8042_filter)(unsigned char data, unsigned char str,
+			     struct serio *serio);
 };
 
 struct asus_wmi_driver {
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH] asus-wmi: filter buggy scan codes on ASUS Q500A

Quoted 8 lines · Oleksij Rempel

Some revision of ASUS Q500A series have keyboard related issue which is reproducible only if Windows with installed ASUS tools was ever started.
In this case the Linux side will have blocked keyboard or report wrong or incomplete hotkey events.
To make Linux work properly again complete power down (unplug power supply and remove battery) should be made.

Quoted 8 lines

Linux/atkbd after clean start will get fallowing code on VOLUME_UP
key: {0xe0, 0x30, 0xe0, 0xb0}. After Windows, same key will generate this
codes: {0xe1, 0x23, 0xe0, 0x30, 0xe0, 0xb0}. As result atkdb will be confused by buggy codes.

This patch is filtering this buggy code out.

https://bugzilla.kernel.org/show_bug.cgi?id=119391

First of all - wow - what a bunch of work. Nice job tracking this all down.

A couple of minor nits below, which I've taken care of.

Queued to testing.

Quoted 27 lines
---
 drivers/platform/x86/asus-nb-wmi.c | 45 ++++++++++++++++++++++++++++++++++++++
 drivers/platform/x86/asus-wmi.h    |  4 ++++
 2 files changed, 49 insertions(+)
drivers/platform/x86/asus-nb-wmi.c +1 -0
index adecc1c..787da83 100644
@@ -27,6 +27,7 @@
 #include <linux/input/sparse-keymap.h>
 #include <linux/fb.h>
 #include <linux/dmi.h>
+#include <linux/i8042.h>
 
 #include "asus-wmi.h"
 

drivers/platform/x86/asus-nb-wmi.c MODULE_PARM_DESC(wapf, "WAPF value"); · line 65

Quoted 10 lines
drivers/platform/x86/asus-nb-wmi.c +7 -0
@@ -55,10 +56,35 @@ MODULE_PARM_DESC(wapf, "WAPF value");
 
 static struct quirk_entry *quirks;
 
+static bool asus_q500a_i8042_filter(unsigned char data, unsigned char str,
+			      struct serio *port)
+{
+	static bool extended;
+	bool ret = false;
+
+

Just one empty line is plenty

Quoted 51 lines
drivers/platform/x86/asus-nb-wmi.c +29 -0
+	if (str & I8042_STR_AUXDATA)
+		return false;
+
+	if (unlikely(data == 0xe1)) {
+		extended = true;
+		ret = true;
+	} else if (unlikely(extended)) {
+		extended = false;
+		ret = true;
+	}
+
+	return ret;
+}
+
 static struct quirk_entry quirk_asus_unknown = {
 	.wapf = 0,
 };
 
+static struct quirk_entry quirk_asus_q500a = {
+	.i8042_filter = asus_q500a_i8042_filter,
+};
+
 /*
  * For those machines that need software to control bt/wifi status
  * and can't adjust brightness through ACPI interface
@@ -96,6 +122,15 @@ static int dmi_matched(const struct dmi_system_id *dmi)
 static const struct dmi_system_id asus_quirks[] = {
 	{
 		.callback = dmi_matched,
+		.ident = "ASUSTeK COMPUTER INC. Q500A",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Q500A"),
+		},
+		.driver_data = &quirk_asus_q500a,
+	},
+	{
+		.callback = dmi_matched,
 		.ident = "ASUSTeK COMPUTER INC. U32U",
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
@@ -356,6 +391,8 @@ static const struct dmi_system_id asus_quirks[] = {
 
 static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver)
 {
+	int ret;
+
 	quirks = &quirk_asus_unknown;
 	dmi_check_system(asus_quirks);
 

drivers/platform/x86/asus-nb-wmi.c static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver) · line 412

Quoted 9 lines
drivers/platform/x86/asus-nb-wmi.c +6 -0
@@ -367,6 +404,14 @@ static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver)
 		quirks->wapf = wapf;
 	else
 		wapf = quirks->wapf;
+
+	if (quirks->i8042_filter) {
+		ret = i8042_install_filter(quirks->i8042_filter);
+		if (ret) {
+			pr_warn("Unable to install key filter\n");
+		}

No braces for a single line block

drivers/platform/x86/asus-nb-wmi.c static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver) · line 413

Quoted 1 line
drivers/platform/x86/asus-nb-wmi.c +1 -0
+		pr_info("Using i8042 filter function for receiving events\n");

Well, then again, a return in the above block would make more sense.

		pr_warn
		return
	}
	pr_info

I've taken the liberty of making this change.... mostly to speed things a long since I've neglected this patch for so long! Apologies. This is queued to testing, let me know if you have any concerns. It'll hit linux-next this weekend.

Quoted 30 lines
drivers/platform/x86/asus-nb-wmi.c +1 -0
+	}
 }
 
 static const struct key_entry asus_nb_wmi_keymap[] = {
drivers/platform/x86/asus-wmi.h +4 -0
index 5de1df5..dd2e6cc 100644
@@ -28,6 +28,7 @@
 #define _ASUS_WMI_H_
 
 #include <linux/platform_device.h>
+#include <linux/i8042.h>
 
 #define ASUS_WMI_KEY_IGNORE (-1)
 #define ASUS_WMI_BRN_DOWN	0x20
@@ -51,6 +52,9 @@ struct quirk_entry {
 	 * and let the ACPI interrupt to send out the key event.
 	 */
 	int no_display_toggle;
+
+	bool (*i8042_filter)(unsigned char data, unsigned char str,
+			     struct serio *serio);
 };
 
 struct asus_wmi_driver {
Signature · 1 line
2.7.4
Signature · 2 lines
Darren Hart
Intel Open Source Technology Center