0004-at_keyboard-coreboot-force-scancodes2-translate.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. From 96c0bbe5d406b616360a7fce7cee67d7692c0d6d Mon Sep 17 00:00:00 2001
  2. From: Leah Rowe <leah@libreboot.org>
  3. Date: Mon, 30 Oct 2023 22:19:21 +0000
  4. Subject: [PATCH 1/1] at_keyboard coreboot: force scancodes2+translate
  5. Scan code set 2 with translation should be assumed in
  6. every case, as the default starting position.
  7. However, GRUB is trying to detect and use other modes
  8. such as set 2 without translation, or set 1 without
  9. translation from set 2; it also detects no-mode and
  10. assumes mode 1, on really old keyboards.
  11. The current behaviour has been retained, for everything
  12. except GRUB_MACHINE_COREBOOT; for the latter, scan code
  13. set 2 with translation is hardcoded, and forced in code.
  14. This is required to make keyboard initialisation work on
  15. the MEC5035 EC used by the Dell Latitude E6400, when
  16. running GRUB as a coreboot payload on that laptop. The
  17. EC reports scancode set 2 with translation when probed,
  18. but actually only outputs scancode set 1.
  19. Since GRUB is attempting to use it without translation,
  20. and since the machine reports set 2 with translation,
  21. but only ever outputs set 1 scancodes, this results in
  22. wrong keypresses for every key.
  23. This fix fixed that, by forcing set 2 with translation,
  24. treating it as set 1, but only on coreboot. This is the
  25. same behaviour used in GNU+Linux systems and SeaBIOS.
  26. With this change, GRUB keyboard initialisation now works
  27. just fine on those machines.
  28. This has *also* been tested on other coreboot machines
  29. running GRUB; several HP EliteBooks, ThinkPads and
  30. Dell Precision T1650. All seems to work just fine.
  31. Signed-off-by: Leah Rowe <leah@libreboot.org>
  32. ---
  33. grub-core/term/at_keyboard.c | 20 ++++++++++++++++++--
  34. 1 file changed, 18 insertions(+), 2 deletions(-)
  35. diff --git a/grub-core/term/at_keyboard.c b/grub-core/term/at_keyboard.c
  36. index f8a129eb7..8207225c2 100644
  37. --- a/grub-core/term/at_keyboard.c
  38. +++ b/grub-core/term/at_keyboard.c
  39. @@ -138,6 +138,7 @@ write_mode (int mode)
  40. return (i != GRUB_AT_TRIES);
  41. }
  42. +#if !defined (GRUB_MACHINE_COREBOOT)
  43. static int
  44. query_mode (void)
  45. {
  46. @@ -161,10 +162,12 @@ query_mode (void)
  47. return 3;
  48. return 0;
  49. }
  50. +#endif
  51. static void
  52. set_scancodes (void)
  53. {
  54. +#if !defined (GRUB_MACHINE_COREBOOT)
  55. /* You must have visited computer museum. Keyboard without scancode set
  56. knowledge. Assume XT. */
  57. if (!grub_keyboard_orig_set)
  58. @@ -173,20 +176,33 @@ set_scancodes (void)
  59. ps2_state.current_set = 1;
  60. return;
  61. }
  62. +#endif
  63. #if !USE_SCANCODE_SET
  64. ps2_state.current_set = 1;
  65. return;
  66. -#else
  67. +#endif
  68. +#if defined (GRUB_MACHINE_COREBOOT)
  69. + /* enable translation */
  70. + grub_keyboard_controller_write (grub_keyboard_controller_orig
  71. + & ~KEYBOARD_AT_DISABLE);
  72. +#else
  73. + /* if not coreboot, disable translation and try mode 2 first, before 1 */
  74. grub_keyboard_controller_write (grub_keyboard_controller_orig
  75. & ~KEYBOARD_AT_TRANSLATE
  76. & ~KEYBOARD_AT_DISABLE);
  77. +#endif
  78. keyboard_controller_wait_until_ready ();
  79. grub_outb (KEYBOARD_COMMAND_ENABLE, KEYBOARD_REG_DATA);
  80. -
  81. write_mode (2);
  82. +
  83. +#if defined (GRUB_MACHINE_COREBOOT)
  84. + /* mode 2 with translation, so make grub treat as set 1 */
  85. + ps2_state.current_set = 1;
  86. +#else
  87. + /* if not coreboot, translation isn't set; test 2 and fall back to 1 */
  88. ps2_state.current_set = query_mode ();
  89. grub_dprintf ("atkeyb", "returned set %d\n", ps2_state.current_set);
  90. if (ps2_state.current_set == 2)
  91. --
  92. 2.39.2