input: amikbd: fix scancode to key code conversion
Subsystems (3)
PATCH 1/1 input: amikbd: fix scancode to key code conversion
Previously the amikbd.c driver passed raw Amiga keyboard scancodes via input_report_key(). As a result incorrect key codes were transmitted to libinput and the input event framework, while a remapping was simultaneously being performed for the VT console via amikbd_init_console_keymaps().
This patch corrects the transmission of these scancodes by ensuring that the proper Linux key codes are passed to input_report_key() instead. Consequently, the remapping for the console is no longer necessary.
The Atari keyboard driver atakbd.c served as a reference for implementing this fix.
--- drivers/input/keyboard/amikbd.c | 42 ++++++++++----------------------- 1 file changed, 12 insertions(+), 30 deletions(-)
drivers/input/keyboard/amikbd.c +12 -30
@@ -27,7 +27,7 @@ MODULE_DESCRIPTION("Amiga keyboard driver");MODULE_LICENSE ("GPL" );#ifdef CONFIG_VT -static unsigned char amikbd_keycode[0x78 ]__initdata = { +static unsigned short amikbd_keycode[0x78 ] = { [0 ] =KEY_GRAVE , [1 ] =KEY_1 , [2] = KEY_2,
@@ -126,28 +126,6 @@ static unsigned char amikbd_keycode[0x78] __initdata = { [103] = KEY_RIGHTMETA }; -static void __init amikbd_init_console_keymaps (void ) -{ -/* We can spare 512 bytes on stack for temp_map in init path. */ -unsigned short temp_map[NR_KEYS ]; -int i, j; - -for (i =0 ; i <MAX_NR_KEYMAPS ; i++) { -if (!key_maps[i]) -continue ; -memset (temp_map,0 ,sizeof (temp_map)); -for (j =0 ; j <0x78 ; j++) { -if (!amikbd_keycode[j]) -continue ; - temp_map[j] = key_maps[i][amikbd_keycode[j]]; - } -for (j =0 ; j <NR_KEYS ; j++) { -if (!temp_map[j]) - temp_map[j] =0xf200 ; - } -memcpy (key_maps[i], temp_map,sizeof (temp_map)); - } -}#else /* !CONFIG_VT */ static inline void amikbd_init_console_keymaps (void ) {}#endif /* !CONFIG_VT */
@@ -177,11 +155,13 @@ static irqreturn_t amikbd_interrupt(int irq, void *data) scancode >>=1 ;if (scancode <0x78 ) {/* scancodes < 0x78 are keys */ +const unsigned short keycode = amikbd_keycode[scancode]; +if (scancode ==98 ) {/* CapsLock is a toggle switch key on Amiga */ -input_report_key (dev, scancode,1 ); -input_report_key (dev, scancode,0 ); +input_report_key (dev, keycode,1 ); +input_report_key (dev, keycode,0 ); }else { -input_report_key (dev, scancode, down); +input_report_key (dev, keycode, down); }input_sync (dev);
@@ -210,11 +190,13 @@ static int __init amikbd_probe(struct platform_device *pdev) dev->id.version =0x0100 ; dev->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_REP ); + dev->keycode = amikbd_keycode; + dev->keycodesize =sizeof (amikbd_keycode[0 ]); + dev->keycodemax =ARRAY_SIZE (amikbd_keycode); -for (i =0 ; i <0x78 ; i++) -set_bit (i, dev->keybit); - -amikbd_init_console_keymaps (); +for (i =0 ; i < dev->keycodemax; i++) +if (amikbd_keycode[i]) +set_bit (amikbd_keycode[i], dev->keybit); ciaa.cra &= ~0x41 ;/* serial data in, turn off TA */ err = devm_request_irq(&pdev->dev, IRQ_AMIGA_CIAA_SP, amikbd_interrupt,
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] Input: amikbd: build failure when CONFIG_VT=n due to #ifdef CONFIG_VT guard - [Low] Input: amikbd…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] Input: amikbd: build failure when CONFIG_VT=n due to #ifdef CONFIG_VT guard
- [Low] Input: amikbd: missing Fixes trailer for commit 5fa28ea42f28 --
commit 7a8125f16e2b07841a12c661705ac3a1a5ade03f
Author: Steffen A. Mork <[email protected]>
Quoted 12 lines
input: amikbd: fix scancode to key code conversion
Previously the
amikbd.cdriver passed raw Amiga keyboard scancodes viainput_report_key(). As a result incorrect key codes were transmitted to libinput and the input event framework, while a remapping was simultaneously being performed for the VT console viaamikbd_init_console_keymaps().This patch corrects the transmission of these scancodes by ensuring that the proper Linux key codes are passed to
input_report_key()instead. Consequently, the remapping for the console is no longer necessary.
Quoted 6 lines
The Atari keyboard driver
atakbd.cserved as a reference for implementing this fix.
[Severity: Low]
This fixes the raw scancode reporting introduced in commit 5fa28ea42f28. Should this include:
Quoted 32 lines
drivers/input/keyboard/amikbd.c +1
-16@@ -27,7 +27,7 @@ MODULE_DESCRIPTION("Amiga keyboard driver");MODULE_LICENSE ("GPL" );#ifdef CONFIG_VT -static unsigned char amikbd_keycode[0x78 ]__initdata = { +static unsigned short amikbd_keycode[0x78 ] = { [0 ] =KEY_GRAVE , [1 ] =KEY_1 , [2] = KEY_2,@@ -126,28 +126,6 @@ static unsigned char amikbd_keycode[0x78] __initdata = { [103] = KEY_RIGHTMETA }; -static void __init amikbd_init_console_keymaps (void ) -{ -/* We can spare 512 bytes on stack for temp_map in init path. */ -unsigned short temp_map[NR_KEYS ]; -int i, j; - -for (i =0 ; i <MAX_NR_KEYMAPS ; i++) { -if (!key_maps[i]) -continue ; -memset (temp_map,0 ,sizeof (temp_map)); -for (j =0 ; j <0x78 ; j++) { -if (!amikbd_keycode[j]) -continue ; - temp_map[j] = key_maps[i][amikbd_keycode[j]]; - }
drivers/input/keyboard/amikbd.c static unsigned char amikbd_keycode[0x78] __initdata = { · line 131
Quoted 10 lines
drivers/input/keyboard/amikbd.c +0
-7-for (j =0 ; j <NR_KEYS ; j++) { -if (!temp_map[j]) - temp_map[j] =0xf200 ; - } - memcpy(key_maps[i], temp_map, sizeof(temp_map)); - } -}#else /* !CONFIG_VT */ static inline void amikbd_init_console_keymaps (void ) {}#endif /* !CONFIG_VT */
[Severity: Medium]
Does this fail to build when CONFIG_VT is disabled? amikbd_keycode[] is now referenced unconditionally in amikbd_interrupt() and amikbd_probe(), so the #ifdef CONFIG_VT guard and the unused amikbd_init_console_keymaps() stub in the #else branch need to be removed as well.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1