diff mbox series

[v2] Input: atkbd - Skip ATKBD_CMD_GETID in translated mode

Message ID 20231115174625.7462-1-hdegoede@redhat.com (mailing list archive)
State New
Headers show
Series [v2] Input: atkbd - Skip ATKBD_CMD_GETID in translated mode | expand

Commit Message

Hans de Goede Nov. 15, 2023, 5:46 p.m. UTC
There have been multiple reports of keyboard issues on recent laptop models
which can be worked around by setting i8042.dumbkbd, with the downside
being this breaks the capslock LED.

It seems that these issues are caused by recent laptops getting confused by
ATKBD_CMD_GETID. Rather then adding and endless growing list of quirks for
this, just skip ATKBD_CMD_GETID alltogether on laptops in translated mode.

The main goal of sending ATKBD_CMD_GETID is to skip binding to ps/2
mice/touchpads and those are never used in translated mode.

Examples of laptop models which benefit from skipping ATKBD_CMD_GETID:

* "HP Laptop 15s-fq2xxx", "HP laptop 15s-fq4xxx" and "HP Laptop 15-dy2xxx"
  models the kbd stops working for the first 2 - 5 minutes after boot
  (waiting for EC watchdog reset?)

* On "HP Spectre x360 13-aw2xxx" atkbd fails to probe the keyboard

* At least 9 different Lenovo models have issues with ATKBD_CMD_GETID, see:
  https://github.com/yescallop/atkbd-nogetid

This has been tested on:

1. A MSI B550M PRO-VDH WIFI desktop, where the i8042 controller is not
   in translated mode when no keyboard is plugged in and with a ps/2 kbd
   a "AT Translated Set 2 keyboard" /dev/input/event# node shows up

2. A Lenovo ThinkPad X1 Yoga gen 8 (always has a translated set 2 keyboard)

Reported-by: Shang Ye <yesh25@mail2.sysu.edu.cn>
Closes: https://lore.kernel.org/linux-input/886D6167733841AE+20231017135318.11142-1-yesh25@mail2.sysu.edu.cn/
Closes: https://github.com/yescallop/atkbd-nogetid
Reported-by: gurevitch <mail@gurevit.ch>
Closes: https://lore.kernel.org/linux-input/2iAJTwqZV6lQs26cTb38RNYqxvsink6SRmrZ5h0cBUSuf9NT0tZTsf9fEAbbto2maavHJEOP8GA1evlKa6xjKOsaskDhtJWxjcnrgPigzVo=@gurevit.ch/
Reported-by: Egor Ignatov <egori@altlinux.org>
Closes: https://lore.kernel.org/all/20210609073333.8425-1-egori@altlinux.org/
Reported-by: Anton Zhilyaev <anton@cpp.in>
Closes: https://lore.kernel.org/linux-input/20210201160336.16008-1-anton@cpp.in/
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2086156
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Note this supersedes my previous atkbd series:
https://lore.kernel.org/linux-input/20231005201544.26983-1-hdegoede@redhat.com/
---
Changes in v2:
- Add DMI check for laptop chassis types and only skip ATKBD_CMD_GETID
  on laptops with the i8042 in translated mode
---
 drivers/input/keyboard/atkbd.c | 61 +++++++++++++++++++++++++++++++---
 1 file changed, 57 insertions(+), 4 deletions(-)

Comments

Dmitry Torokhov Nov. 25, 2023, 4:30 a.m. UTC | #1
Hi Hans,

On Wed, Nov 15, 2023 at 06:46:25PM +0100, Hans de Goede wrote:
> There have been multiple reports of keyboard issues on recent laptop models
> which can be worked around by setting i8042.dumbkbd, with the downside
> being this breaks the capslock LED.
> 
> It seems that these issues are caused by recent laptops getting confused by
> ATKBD_CMD_GETID. Rather then adding and endless growing list of quirks for
> this, just skip ATKBD_CMD_GETID alltogether on laptops in translated mode.
> 
> The main goal of sending ATKBD_CMD_GETID is to skip binding to ps/2
> mice/touchpads and those are never used in translated mode.
> 
> Examples of laptop models which benefit from skipping ATKBD_CMD_GETID:
> 
> * "HP Laptop 15s-fq2xxx", "HP laptop 15s-fq4xxx" and "HP Laptop 15-dy2xxx"
>   models the kbd stops working for the first 2 - 5 minutes after boot
>   (waiting for EC watchdog reset?)
> 
> * On "HP Spectre x360 13-aw2xxx" atkbd fails to probe the keyboard
> 
> * At least 9 different Lenovo models have issues with ATKBD_CMD_GETID, see:
>   https://github.com/yescallop/atkbd-nogetid
> 
> This has been tested on:
> 
> 1. A MSI B550M PRO-VDH WIFI desktop, where the i8042 controller is not
>    in translated mode when no keyboard is plugged in and with a ps/2 kbd
>    a "AT Translated Set 2 keyboard" /dev/input/event# node shows up
> 
> 2. A Lenovo ThinkPad X1 Yoga gen 8 (always has a translated set 2 keyboard)
> 
> Reported-by: Shang Ye <yesh25@mail2.sysu.edu.cn>
> Closes: https://lore.kernel.org/linux-input/886D6167733841AE+20231017135318.11142-1-yesh25@mail2.sysu.edu.cn/
> Closes: https://github.com/yescallop/atkbd-nogetid
> Reported-by: gurevitch <mail@gurevit.ch>
> Closes: https://lore.kernel.org/linux-input/2iAJTwqZV6lQs26cTb38RNYqxvsink6SRmrZ5h0cBUSuf9NT0tZTsf9fEAbbto2maavHJEOP8GA1evlKa6xjKOsaskDhtJWxjcnrgPigzVo=@gurevit.ch/
> Reported-by: Egor Ignatov <egori@altlinux.org>
> Closes: https://lore.kernel.org/all/20210609073333.8425-1-egori@altlinux.org/
> Reported-by: Anton Zhilyaev <anton@cpp.in>
> Closes: https://lore.kernel.org/linux-input/20210201160336.16008-1-anton@cpp.in/
> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2086156
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Note this supersedes my previous atkbd series:
> https://lore.kernel.org/linux-input/20231005201544.26983-1-hdegoede@redhat.com/
> ---
> Changes in v2:
> - Add DMI check for laptop chassis types and only skip ATKBD_CMD_GETID
>   on laptops with the i8042 in translated mode
> ---
>  drivers/input/keyboard/atkbd.c | 61 +++++++++++++++++++++++++++++++---
>  1 file changed, 57 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
> index c92e544c792d..5667f1e80839 100644
> --- a/drivers/input/keyboard/atkbd.c
> +++ b/drivers/input/keyboard/atkbd.c
> @@ -765,6 +765,59 @@ static void atkbd_deactivate(struct atkbd *atkbd)
>  			ps2dev->serio->phys);
>  }
>  
> +#ifdef CONFIG_X86
> +static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32"), /* Detachable */
> +		},
> +	},
> +	{ }
> +};

Thank you for making the changes, however I wonder if we should
open-code check for the chassis type, as DMI can be quite bloated and
here we are dealing with exactly one field. Something like this:

diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 5667f1e80839..786f00f6b7fd 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -766,39 +766,24 @@ static void atkbd_deactivate(struct atkbd *atkbd)
 }
 
 #ifdef CONFIG_X86
-static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
-	{
-		.matches = {
-			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
-		},
-	},
-	{
-		.matches = {
-			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
-		},
-	},
-	{
-		.matches = {
-			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
-		},
-	},
-	{
-		.matches = {
-			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
-		},
-	},
-	{
-		.matches = {
-			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible */
-		},
-	},
-	{
-		.matches = {
-			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32"), /* Detachable */
-		},
-	},
-	{ }
-};
+static bool atkbd_is_portable_device(void)
+{
+	static const char * const chassis_types[] = {
+		"8",	/* Portable */
+		"9",	/* Laptop */
+		"10",	/* Notebook */
+		"14",	/* Sub-Notebook */
+		"31",	/* Convertible */
+		"32",	/* Detachable */
+	};
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(chassis_types); i++)
+		if (dmi_match(DMI_CHASSIS_TYPE, chassis_types[i]))
+			return true;
+
+	return false;
+}
 
 /*
  * On many modern laptops ATKBD_CMD_GETID may cause problems, on these laptops
@@ -812,7 +797,7 @@ static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
  */
 static bool atkbd_skip_getid(struct atkbd *atkbd)
 {
-	return atkbd->translated && dmi_check_system(atkbd_dmi_laptop_table);
+	return atkbd->translated && atkbd_is_portable_device();
 }
 #else
 static inline bool atkbd_skip_getid(struct atkbd *atkbd) { return false; }


It gives me slightly smaller output:

dtor@dtor-ws:~/kernel/work (master *)$ size drivers/input/keyboard/atkbd.o.old
   text    data     bss     dec     hex filename
  28407    1512      37   29956    7504 drivers/input/keyboard/atkbd.o.old
dtor@dtor-ws:~/kernel/work (master *)$ size drivers/input/keyboard/atkbd.o
   text    data     bss     dec     hex filename
  26107    1512      37   27656    6c08 drivers/input/keyboard/atkbd.o

Please let me know if this works for you and I can combine on my end.

Thanks.
Hans de Goede Nov. 25, 2023, 1:43 p.m. UTC | #2
Hi Dmitry,

On 11/25/23 05:30, Dmitry Torokhov wrote:
> Hi Hans,
> 
> On Wed, Nov 15, 2023 at 06:46:25PM +0100, Hans de Goede wrote:
>> There have been multiple reports of keyboard issues on recent laptop models
>> which can be worked around by setting i8042.dumbkbd, with the downside
>> being this breaks the capslock LED.
>>
>> It seems that these issues are caused by recent laptops getting confused by
>> ATKBD_CMD_GETID. Rather then adding and endless growing list of quirks for
>> this, just skip ATKBD_CMD_GETID alltogether on laptops in translated mode.
>>
>> The main goal of sending ATKBD_CMD_GETID is to skip binding to ps/2
>> mice/touchpads and those are never used in translated mode.
>>
>> Examples of laptop models which benefit from skipping ATKBD_CMD_GETID:
>>
>> * "HP Laptop 15s-fq2xxx", "HP laptop 15s-fq4xxx" and "HP Laptop 15-dy2xxx"
>>   models the kbd stops working for the first 2 - 5 minutes after boot
>>   (waiting for EC watchdog reset?)
>>
>> * On "HP Spectre x360 13-aw2xxx" atkbd fails to probe the keyboard
>>
>> * At least 9 different Lenovo models have issues with ATKBD_CMD_GETID, see:
>>   https://github.com/yescallop/atkbd-nogetid
>>
>> This has been tested on:
>>
>> 1. A MSI B550M PRO-VDH WIFI desktop, where the i8042 controller is not
>>    in translated mode when no keyboard is plugged in and with a ps/2 kbd
>>    a "AT Translated Set 2 keyboard" /dev/input/event# node shows up
>>
>> 2. A Lenovo ThinkPad X1 Yoga gen 8 (always has a translated set 2 keyboard)
>>
>> Reported-by: Shang Ye <yesh25@mail2.sysu.edu.cn>
>> Closes: https://lore.kernel.org/linux-input/886D6167733841AE+20231017135318.11142-1-yesh25@mail2.sysu.edu.cn/
>> Closes: https://github.com/yescallop/atkbd-nogetid
>> Reported-by: gurevitch <mail@gurevit.ch>
>> Closes: https://lore.kernel.org/linux-input/2iAJTwqZV6lQs26cTb38RNYqxvsink6SRmrZ5h0cBUSuf9NT0tZTsf9fEAbbto2maavHJEOP8GA1evlKa6xjKOsaskDhtJWxjcnrgPigzVo=@gurevit.ch/
>> Reported-by: Egor Ignatov <egori@altlinux.org>
>> Closes: https://lore.kernel.org/all/20210609073333.8425-1-egori@altlinux.org/
>> Reported-by: Anton Zhilyaev <anton@cpp.in>
>> Closes: https://lore.kernel.org/linux-input/20210201160336.16008-1-anton@cpp.in/
>> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2086156
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> Note this supersedes my previous atkbd series:
>> https://lore.kernel.org/linux-input/20231005201544.26983-1-hdegoede@redhat.com/
>> ---
>> Changes in v2:
>> - Add DMI check for laptop chassis types and only skip ATKBD_CMD_GETID
>>   on laptops with the i8042 in translated mode
>> ---
>>  drivers/input/keyboard/atkbd.c | 61 +++++++++++++++++++++++++++++++---
>>  1 file changed, 57 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
>> index c92e544c792d..5667f1e80839 100644
>> --- a/drivers/input/keyboard/atkbd.c
>> +++ b/drivers/input/keyboard/atkbd.c
>> @@ -765,6 +765,59 @@ static void atkbd_deactivate(struct atkbd *atkbd)
>>  			ps2dev->serio->phys);
>>  }
>>  
>> +#ifdef CONFIG_X86
>> +static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32"), /* Detachable */
>> +		},
>> +	},
>> +	{ }
>> +};
> 
> Thank you for making the changes, however I wonder if we should
> open-code check for the chassis type, as DMI can be quite bloated and
> here we are dealing with exactly one field. Something like this:
> 
> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
> index 5667f1e80839..786f00f6b7fd 100644
> --- a/drivers/input/keyboard/atkbd.c
> +++ b/drivers/input/keyboard/atkbd.c
> @@ -766,39 +766,24 @@ static void atkbd_deactivate(struct atkbd *atkbd)
>  }
>  
>  #ifdef CONFIG_X86
> -static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
> -	{
> -		.matches = {
> -			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
> -		},
> -	},
> -	{
> -		.matches = {
> -			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
> -		},
> -	},
> -	{
> -		.matches = {
> -			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
> -		},
> -	},
> -	{
> -		.matches = {
> -			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
> -		},
> -	},
> -	{
> -		.matches = {
> -			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible */
> -		},
> -	},
> -	{
> -		.matches = {
> -			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32"), /* Detachable */
> -		},
> -	},
> -	{ }
> -};
> +static bool atkbd_is_portable_device(void)
> +{
> +	static const char * const chassis_types[] = {
> +		"8",	/* Portable */
> +		"9",	/* Laptop */
> +		"10",	/* Notebook */
> +		"14",	/* Sub-Notebook */
> +		"31",	/* Convertible */
> +		"32",	/* Detachable */
> +	};
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(chassis_types); i++)
> +		if (dmi_match(DMI_CHASSIS_TYPE, chassis_types[i]))
> +			return true;
> +
> +	return false;
> +}
>  
>  /*
>   * On many modern laptops ATKBD_CMD_GETID may cause problems, on these laptops
> @@ -812,7 +797,7 @@ static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
>   */
>  static bool atkbd_skip_getid(struct atkbd *atkbd)
>  {
> -	return atkbd->translated && dmi_check_system(atkbd_dmi_laptop_table);
> +	return atkbd->translated && atkbd_is_portable_device();
>  }
>  #else
>  static inline bool atkbd_skip_getid(struct atkbd *atkbd) { return false; }
> 
> 
> It gives me slightly smaller output:
> 
> dtor@dtor-ws:~/kernel/work (master *)$ size drivers/input/keyboard/atkbd.o.old
>    text    data     bss     dec     hex filename
>   28407    1512      37   29956    7504 drivers/input/keyboard/atkbd.o.old
> dtor@dtor-ws:~/kernel/work (master *)$ size drivers/input/keyboard/atkbd.o
>    text    data     bss     dec     hex filename
>   26107    1512      37   27656    6c08 drivers/input/keyboard/atkbd.o
> 
> Please let me know if this works for you and I can combine on my end.

This works for me / squashing this change in is fine with me.

Thank you.

Regards,

Hans
Barnabás Pőcze Jan. 16, 2024, 12:21 a.m. UTC | #3
Hi


2023. november 15., szerda 18:46 keltezéssel, Hans de Goede írta:

> There have been multiple reports of keyboard issues on recent laptop models
> which can be worked around by setting i8042.dumbkbd, with the downside
> being this breaks the capslock LED.
> 
> It seems that these issues are caused by recent laptops getting confused by
> ATKBD_CMD_GETID. Rather then adding and endless growing list of quirks for
> this, just skip ATKBD_CMD_GETID alltogether on laptops in translated mode.
> 
> The main goal of sending ATKBD_CMD_GETID is to skip binding to ps/2
> mice/touchpads and those are never used in translated mode.
> 
> Examples of laptop models which benefit from skipping ATKBD_CMD_GETID:
> 
> * "HP Laptop 15s-fq2xxx", "HP laptop 15s-fq4xxx" and "HP Laptop 15-dy2xxx"
>   models the kbd stops working for the first 2 - 5 minutes after boot
>   (waiting for EC watchdog reset?)
> 
> * On "HP Spectre x360 13-aw2xxx" atkbd fails to probe the keyboard
> 
> * At least 9 different Lenovo models have issues with ATKBD_CMD_GETID, see:
>   https://github.com/yescallop/atkbd-nogetid
> 
> This has been tested on:
> 
> 1. A MSI B550M PRO-VDH WIFI desktop, where the i8042 controller is not
>    in translated mode when no keyboard is plugged in and with a ps/2 kbd
>    a "AT Translated Set 2 keyboard" /dev/input/event# node shows up
> 
> 2. A Lenovo ThinkPad X1 Yoga gen 8 (always has a translated set 2 keyboard)

Just wanted to briefly mention that this broke my hwdb configuration because the
version field of the device (as shown in `/proc/bus/input/devices`) has changed
and it was included in the hwdb match rule.


Regards,
Barnabás Pőcze


> 
> Reported-by: Shang Ye <yesh25@mail2.sysu.edu.cn>
> Closes: https://lore.kernel.org/linux-input/886D6167733841AE+20231017135318.11142-1-yesh25@mail2.sysu.edu.cn/
> Closes: https://github.com/yescallop/atkbd-nogetid
> Reported-by: gurevitch <mail@gurevit.ch>
> Closes: https://lore.kernel.org/linux-input/2iAJTwqZV6lQs26cTb38RNYqxvsink6SRmrZ5h0cBUSuf9NT0tZTsf9fEAbbto2maavHJEOP8GA1evlKa6xjKOsaskDhtJWxjcnrgPigzVo=@gurevit.ch/
> Reported-by: Egor Ignatov <egori@altlinux.org>
> Closes: https://lore.kernel.org/all/20210609073333.8425-1-egori@altlinux.org/
> Reported-by: Anton Zhilyaev <anton@cpp.in>
> Closes: https://lore.kernel.org/linux-input/20210201160336.16008-1-anton@cpp.in/
> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2086156
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Note this supersedes my previous atkbd series:
> https://lore.kernel.org/linux-input/20231005201544.26983-1-hdegoede@redhat.com/
> ---
> Changes in v2:
> - Add DMI check for laptop chassis types and only skip ATKBD_CMD_GETID
>   on laptops with the i8042 in translated mode
> ---
>  drivers/input/keyboard/atkbd.c | 61 +++++++++++++++++++++++++++++++---
>  1 file changed, 57 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
> index c92e544c792d..5667f1e80839 100644
> --- a/drivers/input/keyboard/atkbd.c
> +++ b/drivers/input/keyboard/atkbd.c
> @@ -765,6 +765,59 @@ static void atkbd_deactivate(struct atkbd *atkbd)
>  			ps2dev->serio->phys);
>  }
> 
> +#ifdef CONFIG_X86
> +static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible */
> +		},
> +	},
> +	{
> +		.matches = {
> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32"), /* Detachable */
> +		},
> +	},
> +	{ }
> +};
> +
> +/*
> + * On many modern laptops ATKBD_CMD_GETID may cause problems, on these laptops
> + * the controller is always in translated mode. In this mode mice/touchpads will
> + * not work. So in this case simply assume a keyboard is connected to avoid
> + * confusing some laptop keyboards.
> + *
> + * Skipping ATKBD_CMD_GETID ends up using a fake keyboard id. Using a fake id is
> + * ok in translated mode, only atkbd_select_set() checks atkbd->id and in
> + * translated mode that is a no-op.
> + */
> +static bool atkbd_skip_getid(struct atkbd *atkbd)
> +{
> +	return atkbd->translated && dmi_check_system(atkbd_dmi_laptop_table);
> +}
> +#else
> +static inline bool atkbd_skip_getid(struct atkbd *atkbd) { return false; }
> +#endif
> +
>  /*
>   * atkbd_probe() probes for an AT keyboard on a serio port.
>   */
> @@ -794,12 +847,12 @@ static int atkbd_probe(struct atkbd *atkbd)
>   */
> 
>  	param[0] = param[1] = 0xa5;	/* initialize with invalid values */
> -	if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
> +	if (atkbd_skip_getid(atkbd) || ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
> 
>  /*
> - * If the get ID command failed, we check if we can at least set the LEDs on
> - * the keyboard. This should work on every keyboard out there. It also turns
> - * the LEDs off, which we want anyway.
> + * If the get ID command was skipped or failed, we check if we can at least set
> + * the LEDs on the keyboard. This should work on every keyboard out there.
> + * It also turns the LEDs off, which we want anyway.
>   */
>  		param[0] = 0;
>  		if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
> --
> 2.41.0
>
Hans de Goede Jan. 16, 2024, 9:34 a.m. UTC | #4
Hi Barnabás,

On 1/16/24 01:21, Barnabás Pőcze wrote:
> Hi
> 
> 
> 2023. november 15., szerda 18:46 keltezéssel, Hans de Goede írta:
> 
>> There have been multiple reports of keyboard issues on recent laptop models
>> which can be worked around by setting i8042.dumbkbd, with the downside
>> being this breaks the capslock LED.
>>
>> It seems that these issues are caused by recent laptops getting confused by
>> ATKBD_CMD_GETID. Rather then adding and endless growing list of quirks for
>> this, just skip ATKBD_CMD_GETID alltogether on laptops in translated mode.
>>
>> The main goal of sending ATKBD_CMD_GETID is to skip binding to ps/2
>> mice/touchpads and those are never used in translated mode.
>>
>> Examples of laptop models which benefit from skipping ATKBD_CMD_GETID:
>>
>> * "HP Laptop 15s-fq2xxx", "HP laptop 15s-fq4xxx" and "HP Laptop 15-dy2xxx"
>>   models the kbd stops working for the first 2 - 5 minutes after boot
>>   (waiting for EC watchdog reset?)
>>
>> * On "HP Spectre x360 13-aw2xxx" atkbd fails to probe the keyboard
>>
>> * At least 9 different Lenovo models have issues with ATKBD_CMD_GETID, see:
>>   https://github.com/yescallop/atkbd-nogetid
>>
>> This has been tested on:
>>
>> 1. A MSI B550M PRO-VDH WIFI desktop, where the i8042 controller is not
>>    in translated mode when no keyboard is plugged in and with a ps/2 kbd
>>    a "AT Translated Set 2 keyboard" /dev/input/event# node shows up
>>
>> 2. A Lenovo ThinkPad X1 Yoga gen 8 (always has a translated set 2 keyboard)
> 
> Just wanted to briefly mention that this broke my hwdb configuration because the
> version field of the device (as shown in `/proc/bus/input/devices`) has changed
> and it was included in the hwdb match rule.

That is unfortunate. Was this a custom rule or one from
the hwdb shipped with systemd ?

Either way can you share the match pattern of the rule before and
after? I want to check if there are any similar cases in
the hwdb shipped with systemd.

Regards,

Hans



>> Reported-by: Shang Ye <yesh25@mail2.sysu.edu.cn>
>> Closes: https://lore.kernel.org/linux-input/886D6167733841AE+20231017135318.11142-1-yesh25@mail2.sysu.edu.cn/
>> Closes: https://github.com/yescallop/atkbd-nogetid
>> Reported-by: gurevitch <mail@gurevit.ch>
>> Closes: https://lore.kernel.org/linux-input/2iAJTwqZV6lQs26cTb38RNYqxvsink6SRmrZ5h0cBUSuf9NT0tZTsf9fEAbbto2maavHJEOP8GA1evlKa6xjKOsaskDhtJWxjcnrgPigzVo=@gurevit.ch/
>> Reported-by: Egor Ignatov <egori@altlinux.org>
>> Closes: https://lore.kernel.org/all/20210609073333.8425-1-egori@altlinux.org/
>> Reported-by: Anton Zhilyaev <anton@cpp.in>
>> Closes: https://lore.kernel.org/linux-input/20210201160336.16008-1-anton@cpp.in/
>> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2086156
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> Note this supersedes my previous atkbd series:
>> https://lore.kernel.org/linux-input/20231005201544.26983-1-hdegoede@redhat.com/
>> ---
>> Changes in v2:
>> - Add DMI check for laptop chassis types and only skip ATKBD_CMD_GETID
>>   on laptops with the i8042 in translated mode
>> ---
>>  drivers/input/keyboard/atkbd.c | 61 +++++++++++++++++++++++++++++++---
>>  1 file changed, 57 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
>> index c92e544c792d..5667f1e80839 100644
>> --- a/drivers/input/keyboard/atkbd.c
>> +++ b/drivers/input/keyboard/atkbd.c
>> @@ -765,6 +765,59 @@ static void atkbd_deactivate(struct atkbd *atkbd)
>>  			ps2dev->serio->phys);
>>  }
>>
>> +#ifdef CONFIG_X86
>> +static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible */
>> +		},
>> +	},
>> +	{
>> +		.matches = {
>> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32"), /* Detachable */
>> +		},
>> +	},
>> +	{ }
>> +};
>> +
>> +/*
>> + * On many modern laptops ATKBD_CMD_GETID may cause problems, on these laptops
>> + * the controller is always in translated mode. In this mode mice/touchpads will
>> + * not work. So in this case simply assume a keyboard is connected to avoid
>> + * confusing some laptop keyboards.
>> + *
>> + * Skipping ATKBD_CMD_GETID ends up using a fake keyboard id. Using a fake id is
>> + * ok in translated mode, only atkbd_select_set() checks atkbd->id and in
>> + * translated mode that is a no-op.
>> + */
>> +static bool atkbd_skip_getid(struct atkbd *atkbd)
>> +{
>> +	return atkbd->translated && dmi_check_system(atkbd_dmi_laptop_table);
>> +}
>> +#else
>> +static inline bool atkbd_skip_getid(struct atkbd *atkbd) { return false; }
>> +#endif
>> +
>>  /*
>>   * atkbd_probe() probes for an AT keyboard on a serio port.
>>   */
>> @@ -794,12 +847,12 @@ static int atkbd_probe(struct atkbd *atkbd)
>>   */
>>
>>  	param[0] = param[1] = 0xa5;	/* initialize with invalid values */
>> -	if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
>> +	if (atkbd_skip_getid(atkbd) || ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
>>
>>  /*
>> - * If the get ID command failed, we check if we can at least set the LEDs on
>> - * the keyboard. This should work on every keyboard out there. It also turns
>> - * the LEDs off, which we want anyway.
>> + * If the get ID command was skipped or failed, we check if we can at least set
>> + * the LEDs on the keyboard. This should work on every keyboard out there.
>> + * It also turns the LEDs off, which we want anyway.
>>   */
>>  		param[0] = 0;
>>  		if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
>> --
>> 2.41.0
>>
>
Barnabás Pőcze Jan. 16, 2024, 1:32 p.m. UTC | #5
Hi


2024. január 16., kedd 10:34 keltezéssel, Hans de Goede írta:

> [...]
> > 2023. november 15., szerda 18:46 keltezéssel, Hans de Goede írta:
> >
> >> There have been multiple reports of keyboard issues on recent laptop models
> >> which can be worked around by setting i8042.dumbkbd, with the downside
> >> being this breaks the capslock LED.
> >>
> >> It seems that these issues are caused by recent laptops getting confused by
> >> ATKBD_CMD_GETID. Rather then adding and endless growing list of quirks for
> >> this, just skip ATKBD_CMD_GETID alltogether on laptops in translated mode.
> >>
> >> The main goal of sending ATKBD_CMD_GETID is to skip binding to ps/2
> >> mice/touchpads and those are never used in translated mode.
> >>
> >> Examples of laptop models which benefit from skipping ATKBD_CMD_GETID:
> >>
> >> * "HP Laptop 15s-fq2xxx", "HP laptop 15s-fq4xxx" and "HP Laptop 15-dy2xxx"
> >>   models the kbd stops working for the first 2 - 5 minutes after boot
> >>   (waiting for EC watchdog reset?)
> >>
> >> * On "HP Spectre x360 13-aw2xxx" atkbd fails to probe the keyboard
> >>
> >> * At least 9 different Lenovo models have issues with ATKBD_CMD_GETID, see:
> >>   https://github.com/yescallop/atkbd-nogetid
> >>
> >> This has been tested on:
> >>
> >> 1. A MSI B550M PRO-VDH WIFI desktop, where the i8042 controller is not
> >>    in translated mode when no keyboard is plugged in and with a ps/2 kbd
> >>    a "AT Translated Set 2 keyboard" /dev/input/event# node shows up
> >>
> >> 2. A Lenovo ThinkPad X1 Yoga gen 8 (always has a translated set 2 keyboard)
> >
> > Just wanted to briefly mention that this broke my hwdb configuration because the
> > version field of the device (as shown in `/proc/bus/input/devices`) has changed
> > and it was included in the hwdb match rule.
> 
> That is unfortunate. Was this a custom rule or one from
> the hwdb shipped with systemd ?
> 
> Either way can you share the match pattern of the rule before and
> after? I want to check if there are any similar cases in
> the hwdb shipped with systemd.
> [...]

It was a custom rule.

Before:

evdev:input:b0011v0001p0001eAB83*
 KEYBOARD_KEY_f8=fn
 KEYBOARD_KEY_76=f21

I: Bus=0011 Vendor=0001 Product=0001 Version=ab83
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input4


After:

evdev:input:b0011v0001p0001*
 KEYBOARD_KEY_f8=fn
 KEYBOARD_KEY_76=f21

I: Bus=0011 Vendor=0001 Product=0001 Version=abba
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input4


Regards,
Barnabás Pőcze


> 
> 
> >> Reported-by: Shang Ye <yesh25@mail2.sysu.edu.cn>
> >> Closes: https://lore.kernel.org/linux-input/886D6167733841AE+20231017135318.11142-1-yesh25@mail2.sysu.edu.cn/
> >> Closes: https://github.com/yescallop/atkbd-nogetid
> >> Reported-by: gurevitch <mail@gurevit.ch>
> >> Closes: https://lore.kernel.org/linux-input/2iAJTwqZV6lQs26cTb38RNYqxvsink6SRmrZ5h0cBUSuf9NT0tZTsf9fEAbbto2maavHJEOP8GA1evlKa6xjKOsaskDhtJWxjcnrgPigzVo=@gurevit.ch/
> >> Reported-by: Egor Ignatov <egori@altlinux.org>
> >> Closes: https://lore.kernel.org/all/20210609073333.8425-1-egori@altlinux.org/
> >> Reported-by: Anton Zhilyaev <anton@cpp.in>
> >> Closes: https://lore.kernel.org/linux-input/20210201160336.16008-1-anton@cpp.in/
> >> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2086156
> >> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> >> ---
> >> Note this supersedes my previous atkbd series:
> >> https://lore.kernel.org/linux-input/20231005201544.26983-1-hdegoede@redhat.com/
> >> ---
> >> Changes in v2:
> >> - Add DMI check for laptop chassis types and only skip ATKBD_CMD_GETID
> >>   on laptops with the i8042 in translated mode
> >> ---
> >>  drivers/input/keyboard/atkbd.c | 61 +++++++++++++++++++++++++++++++---
> >>  1 file changed, 57 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
> >> index c92e544c792d..5667f1e80839 100644
> >> --- a/drivers/input/keyboard/atkbd.c
> >> +++ b/drivers/input/keyboard/atkbd.c
> >> @@ -765,6 +765,59 @@ static void atkbd_deactivate(struct atkbd *atkbd)
> >>  			ps2dev->serio->phys);
> >>  }
> >>
> >> +#ifdef CONFIG_X86
> >> +static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
> >> +	{
> >> +		.matches = {
> >> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
> >> +		},
> >> +	},
> >> +	{
> >> +		.matches = {
> >> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
> >> +		},
> >> +	},
> >> +	{
> >> +		.matches = {
> >> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
> >> +		},
> >> +	},
> >> +	{
> >> +		.matches = {
> >> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
> >> +		},
> >> +	},
> >> +	{
> >> +		.matches = {
> >> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible */
> >> +		},
> >> +	},
> >> +	{
> >> +		.matches = {
> >> +			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32"), /* Detachable */
> >> +		},
> >> +	},
> >> +	{ }
> >> +};
> >> +
> >> +/*
> >> + * On many modern laptops ATKBD_CMD_GETID may cause problems, on these laptops
> >> + * the controller is always in translated mode. In this mode mice/touchpads will
> >> + * not work. So in this case simply assume a keyboard is connected to avoid
> >> + * confusing some laptop keyboards.
> >> + *
> >> + * Skipping ATKBD_CMD_GETID ends up using a fake keyboard id. Using a fake id is
> >> + * ok in translated mode, only atkbd_select_set() checks atkbd->id and in
> >> + * translated mode that is a no-op.
> >> + */
> >> +static bool atkbd_skip_getid(struct atkbd *atkbd)
> >> +{
> >> +	return atkbd->translated && dmi_check_system(atkbd_dmi_laptop_table);
> >> +}
> >> +#else
> >> +static inline bool atkbd_skip_getid(struct atkbd *atkbd) { return false; }
> >> +#endif
> >> +
> >>  /*
> >>   * atkbd_probe() probes for an AT keyboard on a serio port.
> >>   */
> >> @@ -794,12 +847,12 @@ static int atkbd_probe(struct atkbd *atkbd)
> >>   */
> >>
> >>  	param[0] = param[1] = 0xa5;	/* initialize with invalid values */
> >> -	if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
> >> +	if (atkbd_skip_getid(atkbd) || ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
> >>
> >>  /*
> >> - * If the get ID command failed, we check if we can at least set the LEDs on
> >> - * the keyboard. This should work on every keyboard out there. It also turns
> >> - * the LEDs off, which we want anyway.
> >> + * If the get ID command was skipped or failed, we check if we can at least set
> >> + * the LEDs on the keyboard. This should work on every keyboard out there.
> >> + * It also turns the LEDs off, which we want anyway.
> >>   */
> >>  		param[0] = 0;
> >>  		if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
> >> --
> >> 2.41.0
> >>
> >
>
Hans de Goede Jan. 16, 2024, 2:43 p.m. UTC | #6
Hi,

On 1/16/24 14:32, Barnabás Pőcze wrote:
> Hi
> 
> 
> 2024. január 16., kedd 10:34 keltezéssel, Hans de Goede írta:
> 
>> [...]
>>> 2023. november 15., szerda 18:46 keltezéssel, Hans de Goede írta:
>>>
>>>> There have been multiple reports of keyboard issues on recent laptop models
>>>> which can be worked around by setting i8042.dumbkbd, with the downside
>>>> being this breaks the capslock LED.
>>>>
>>>> It seems that these issues are caused by recent laptops getting confused by
>>>> ATKBD_CMD_GETID. Rather then adding and endless growing list of quirks for
>>>> this, just skip ATKBD_CMD_GETID alltogether on laptops in translated mode.
>>>>
>>>> The main goal of sending ATKBD_CMD_GETID is to skip binding to ps/2
>>>> mice/touchpads and those are never used in translated mode.
>>>>
>>>> Examples of laptop models which benefit from skipping ATKBD_CMD_GETID:
>>>>
>>>> * "HP Laptop 15s-fq2xxx", "HP laptop 15s-fq4xxx" and "HP Laptop 15-dy2xxx"
>>>>   models the kbd stops working for the first 2 - 5 minutes after boot
>>>>   (waiting for EC watchdog reset?)
>>>>
>>>> * On "HP Spectre x360 13-aw2xxx" atkbd fails to probe the keyboard
>>>>
>>>> * At least 9 different Lenovo models have issues with ATKBD_CMD_GETID, see:
>>>>   https://github.com/yescallop/atkbd-nogetid
>>>>
>>>> This has been tested on:
>>>>
>>>> 1. A MSI B550M PRO-VDH WIFI desktop, where the i8042 controller is not
>>>>    in translated mode when no keyboard is plugged in and with a ps/2 kbd
>>>>    a "AT Translated Set 2 keyboard" /dev/input/event# node shows up
>>>>
>>>> 2. A Lenovo ThinkPad X1 Yoga gen 8 (always has a translated set 2 keyboard)
>>>
>>> Just wanted to briefly mention that this broke my hwdb configuration because the
>>> version field of the device (as shown in `/proc/bus/input/devices`) has changed
>>> and it was included in the hwdb match rule.
>>
>> That is unfortunate. Was this a custom rule or one from
>> the hwdb shipped with systemd ?
>>
>> Either way can you share the match pattern of the rule before and
>> after? I want to check if there are any similar cases in
>> the hwdb shipped with systemd.
>> [...]
> 
> It was a custom rule.
> 
> Before:
> 
> evdev:input:b0011v0001p0001eAB83*
>  KEYBOARD_KEY_f8=fn
>  KEYBOARD_KEY_76=f21
> 
> I: Bus=0011 Vendor=0001 Product=0001 Version=ab83
> N: Name="AT Translated Set 2 keyboard"
> P: Phys=isa0060/serio0/input0
> S: Sysfs=/devices/platform/i8042/serio0/input/input4
> 
> 
> After:
> 
> evdev:input:b0011v0001p0001*
>  KEYBOARD_KEY_f8=fn
>  KEYBOARD_KEY_76=f21
> 
> I: Bus=0011 Vendor=0001 Product=0001 Version=abba
> N: Name="AT Translated Set 2 keyboard"
> P: Phys=isa0060/serio0/input0
> S: Sysfs=/devices/platform/i8042/serio0/input/input4

I see, thank you. There are no v0001p0001 matches
in the hwdb.d/60-keyboard.hwdb shipped with systems.

Typically laptop builtin keyboards use another match-type
so that they can do DMI matching e.g.:

evdev:atkbd:dmi:bvn*:bvr*:bd*:svnAcer*:pn*:*

So luckily for almost all users the e field in the match
rule changing should not be an issue. Sorry that this
was a problem for you.

Regards,

Hans
Dmitry Torokhov Jan. 16, 2024, 7:05 p.m. UTC | #7
On Tue, Jan 16, 2024 at 03:43:10PM +0100, Hans de Goede wrote:
> Hi,
> 
> On 1/16/24 14:32, Barnabás Pőcze wrote:
> > 
> > After:
> > 
> > evdev:input:b0011v0001p0001*
> >  KEYBOARD_KEY_f8=fn
> >  KEYBOARD_KEY_76=f21
> > 
> > I: Bus=0011 Vendor=0001 Product=0001 Version=abba
> > N: Name="AT Translated Set 2 keyboard"
> > P: Phys=isa0060/serio0/input0
> > S: Sysfs=/devices/platform/i8042/serio0/input/input4
> 
> I see, thank you. There are no v0001p0001 matches
> in the hwdb.d/60-keyboard.hwdb shipped with systems.
> 
> Typically laptop builtin keyboards use another match-type
> so that they can do DMI matching e.g.:
> 
> evdev:atkbd:dmi:bvn*:bvr*:bd*:svnAcer*:pn*:*
> 
> So luckily for almost all users the e field in the match
> rule changing should not be an issue. Sorry that this
> was a problem for you.

Hans, I wonder, if we skip "GET ID" command because it is a
portable/laptop, maybe we should assume that it is the standard "0xab83"
instead of "0xabba" that we assign if GET ID fails but SET LEDS
succeeds. What do you think?

Thanks.
Hans de Goede Jan. 16, 2024, 7:33 p.m. UTC | #8
Hi,

On 1/16/24 20:05, Dmitry Torokhov wrote:
> On Tue, Jan 16, 2024 at 03:43:10PM +0100, Hans de Goede wrote:
>> Hi,
>>
>> On 1/16/24 14:32, Barnabás Pőcze wrote:
>>>
>>> After:
>>>
>>> evdev:input:b0011v0001p0001*
>>>  KEYBOARD_KEY_f8=fn
>>>  KEYBOARD_KEY_76=f21
>>>
>>> I: Bus=0011 Vendor=0001 Product=0001 Version=abba
>>> N: Name="AT Translated Set 2 keyboard"
>>> P: Phys=isa0060/serio0/input0
>>> S: Sysfs=/devices/platform/i8042/serio0/input/input4
>>
>> I see, thank you. There are no v0001p0001 matches
>> in the hwdb.d/60-keyboard.hwdb shipped with systems.
>>
>> Typically laptop builtin keyboards use another match-type
>> so that they can do DMI matching e.g.:
>>
>> evdev:atkbd:dmi:bvn*:bvr*:bd*:svnAcer*:pn*:*
>>
>> So luckily for almost all users the e field in the match
>> rule changing should not be an issue. Sorry that this
>> was a problem for you.
> 
> Hans, I wonder, if we skip "GET ID" command because it is a
> portable/laptop, maybe we should assume that it is the standard "0xab83"
> instead of "0xabba" that we assign if GET ID fails but SET LEDS
> succeeds. What do you think?

That sounds like a good idea to me. I was already wondering
if there was a standard response.

Do you plan to write a fix yourself or shall I propose one ?

Regards,

Hans
Dmitry Torokhov Jan. 16, 2024, 7:50 p.m. UTC | #9
On Tue, Jan 16, 2024 at 08:33:39PM +0100, Hans de Goede wrote:
> Hi,
> 
> On 1/16/24 20:05, Dmitry Torokhov wrote:
> > On Tue, Jan 16, 2024 at 03:43:10PM +0100, Hans de Goede wrote:
> >> Hi,
> >>
> >> On 1/16/24 14:32, Barnabás Pőcze wrote:
> >>>
> >>> After:
> >>>
> >>> evdev:input:b0011v0001p0001*
> >>>  KEYBOARD_KEY_f8=fn
> >>>  KEYBOARD_KEY_76=f21
> >>>
> >>> I: Bus=0011 Vendor=0001 Product=0001 Version=abba
> >>> N: Name="AT Translated Set 2 keyboard"
> >>> P: Phys=isa0060/serio0/input0
> >>> S: Sysfs=/devices/platform/i8042/serio0/input/input4
> >>
> >> I see, thank you. There are no v0001p0001 matches
> >> in the hwdb.d/60-keyboard.hwdb shipped with systems.
> >>
> >> Typically laptop builtin keyboards use another match-type
> >> so that they can do DMI matching e.g.:
> >>
> >> evdev:atkbd:dmi:bvn*:bvr*:bd*:svnAcer*:pn*:*
> >>
> >> So luckily for almost all users the e field in the match
> >> rule changing should not be an issue. Sorry that this
> >> was a problem for you.
> > 
> > Hans, I wonder, if we skip "GET ID" command because it is a
> > portable/laptop, maybe we should assume that it is the standard "0xab83"
> > instead of "0xabba" that we assign if GET ID fails but SET LEDS
> > succeeds. What do you think?
> 
> That sounds like a good idea to me. I was already wondering
> if there was a standard response.
> 
> Do you plan to write a fix yourself or shall I propose one ?

Please propose a patch.

Thanks.
diff mbox series

Patch

diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index c92e544c792d..5667f1e80839 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -765,6 +765,59 @@  static void atkbd_deactivate(struct atkbd *atkbd)
 			ps2dev->serio->phys);
 }
 
+#ifdef CONFIG_X86
+static const struct dmi_system_id atkbd_dmi_laptop_table[] = {
+	{
+		.matches = {
+			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
+		},
+	},
+	{
+		.matches = {
+			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "9"), /* Laptop */
+		},
+	},
+	{
+		.matches = {
+			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "10"), /* Notebook */
+		},
+	},
+	{
+		.matches = {
+			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "14"), /* Sub-Notebook */
+		},
+	},
+	{
+		.matches = {
+			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "31"), /* Convertible */
+		},
+	},
+	{
+		.matches = {
+			DMI_EXACT_MATCH(DMI_CHASSIS_TYPE, "32"), /* Detachable */
+		},
+	},
+	{ }
+};
+
+/*
+ * On many modern laptops ATKBD_CMD_GETID may cause problems, on these laptops
+ * the controller is always in translated mode. In this mode mice/touchpads will
+ * not work. So in this case simply assume a keyboard is connected to avoid
+ * confusing some laptop keyboards.
+ *
+ * Skipping ATKBD_CMD_GETID ends up using a fake keyboard id. Using a fake id is
+ * ok in translated mode, only atkbd_select_set() checks atkbd->id and in
+ * translated mode that is a no-op.
+ */
+static bool atkbd_skip_getid(struct atkbd *atkbd)
+{
+	return atkbd->translated && dmi_check_system(atkbd_dmi_laptop_table);
+}
+#else
+static inline bool atkbd_skip_getid(struct atkbd *atkbd) { return false; }
+#endif
+
 /*
  * atkbd_probe() probes for an AT keyboard on a serio port.
  */
@@ -794,12 +847,12 @@  static int atkbd_probe(struct atkbd *atkbd)
  */
 
 	param[0] = param[1] = 0xa5;	/* initialize with invalid values */
-	if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
+	if (atkbd_skip_getid(atkbd) || ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
 
 /*
- * If the get ID command failed, we check if we can at least set the LEDs on
- * the keyboard. This should work on every keyboard out there. It also turns
- * the LEDs off, which we want anyway.
+ * If the get ID command was skipped or failed, we check if we can at least set
+ * the LEDs on the keyboard. This should work on every keyboard out there.
+ * It also turns the LEDs off, which we want anyway.
  */
 		param[0] = 0;
 		if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))