Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

keyboard: Use BIOS Keyboard variable to set Numlock

The PC BIOS does provide a NUMLOCK flag containing the desired state
of this LED. This patch sets the current state according to the data
in the bios.

[ hpa: fixed __weak declaration without definition, changed "inline"
to "static inline" ]

Signed-Off-By: Joshua Cov <joshuacov@googlemail.com>
Link: http://lkml.kernel.org/r/CAKL7Q7rvq87TNS1T_Km8fW_5OzS%2BSbYazLXKxW-6ztOxo3zorg@mail.gmail.com
Acked-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>

authored by

Joshua Cov and committed by
H. Peter Anvin
b2d0b7a0 c2c21e9b

+58 -19
+19
arch/parisc/include/asm/kbdleds.h
··· 1 + #ifndef _ASM_PARISC_KBDLEDS_H 2 + #define _ASM_PARISC_KBDLEDS_H 3 + 4 + /* 5 + * On HIL keyboards of PARISC machines there is no NumLock key and 6 + * everyone expects the keypad to be used for numbers. That's why 7 + * we can safely turn on the NUMLOCK bit. 8 + */ 9 + 10 + static inline int kbd_defleds(void) 11 + { 12 + #if defined(CONFIG_KEYBOARD_HIL) || defined(CONFIG_KEYBOARD_HIL_OLD) 13 + return 1 << VC_NUMLOCK; 14 + #else 15 + return 0; 16 + #endif 17 + } 18 + 19 + #endif /* _ASM_PARISC_KBDLEDS_H */
+12 -6
arch/x86/boot/main.c
··· 57 57 } 58 58 59 59 /* 60 - * Set the keyboard repeat rate to maximum. Unclear why this 60 + * Query the keyboard lock status as given by the BIOS, and 61 + * set the keyboard repeat rate to maximum. Unclear why the latter 61 62 * is done here; this might be possible to kill off as stale code. 62 63 */ 63 - static void keyboard_set_repeat(void) 64 + static void keyboard_init(void) 64 65 { 65 - struct biosregs ireg; 66 + struct biosregs ireg, oreg; 66 67 initregs(&ireg); 67 - ireg.ax = 0x0305; 68 + 69 + ireg.ah = 0x02; /* Get keyboard status */ 70 + intcall(0x16, &ireg, &oreg); 71 + boot_params.kbd_status = oreg.al; 72 + 73 + ireg.ax = 0x0305; /* Set keyboard repeat rate */ 68 74 intcall(0x16, &ireg, NULL); 69 75 } 70 76 ··· 157 151 /* Detect memory layout */ 158 152 detect_memory(); 159 153 160 - /* Set keyboard repeat rate (why?) */ 161 - keyboard_set_repeat(); 154 + /* Set keyboard repeat rate (why?) and query the lock flags */ 155 + keyboard_init(); 162 156 163 157 /* Query MCA information */ 164 158 query_mca();
+2 -1
arch/x86/include/asm/bootparam.h
··· 112 112 __u8 e820_entries; /* 0x1e8 */ 113 113 __u8 eddbuf_entries; /* 0x1e9 */ 114 114 __u8 edd_mbr_sig_buf_entries; /* 0x1ea */ 115 - __u8 _pad6[6]; /* 0x1eb */ 115 + __u8 kbd_status; /* 0x1eb */ 116 + __u8 _pad6[5]; /* 0x1ec */ 116 117 struct setup_header hdr; /* setup header */ /* 0x1f1 */ 117 118 __u8 _pad7[0x290-0x1f1-sizeof(struct setup_header)]; 118 119 __u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX]; /* 0x290 */
+17
arch/x86/include/asm/kbdleds.h
··· 1 + #ifndef _ASM_X86_KBDLEDS_H 2 + #define _ASM_X86_KBDLEDS_H 3 + 4 + /* 5 + * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on. 6 + * This seems a good reason to start with NumLock off. That's why on X86 we 7 + * ask the bios for the correct state. 8 + */ 9 + 10 + #include <asm/setup.h> 11 + 12 + static inline int kbd_defleds(void) 13 + { 14 + return boot_params.kbd_status & 0x20 ? (1 << VC_NUMLOCK) : 0; 15 + } 16 + 17 + #endif /* _ASM_X86_KBDLEDS_H */
+8 -12
drivers/tty/vt/keyboard.c
··· 53 53 54 54 #define KBD_DEFMODE ((1 << VC_REPEAT) | (1 << VC_META)) 55 55 56 - /* 57 - * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on. 58 - * This seems a good reason to start with NumLock off. On HIL keyboards 59 - * of PARISC machines however there is no NumLock key and everyone expects the 60 - * keypad to be used for numbers. 61 - */ 62 - 63 - #if defined(CONFIG_PARISC) && (defined(CONFIG_KEYBOARD_HIL) || defined(CONFIG_KEYBOARD_HIL_OLD)) 64 - #define KBD_DEFLEDS (1 << VC_NUMLOCK) 56 + #if defined(CONFIG_X86) || defined(CONFIG_PARISC) 57 + #include <asm/kbdleds.h> 65 58 #else 66 - #define KBD_DEFLEDS 0 59 + static inline int kbd_defleds(void) 60 + { 61 + return 0; 62 + } 67 63 #endif 68 64 69 65 #define KBD_DEFLOCK 0 ··· 1508 1512 int error; 1509 1513 1510 1514 for (i = 0; i < MAX_NR_CONSOLES; i++) { 1511 - kbd_table[i].ledflagstate = KBD_DEFLEDS; 1512 - kbd_table[i].default_ledflagstate = KBD_DEFLEDS; 1515 + kbd_table[i].ledflagstate = kbd_defleds(); 1516 + kbd_table[i].default_ledflagstate = kbd_defleds(); 1513 1517 kbd_table[i].ledmode = LED_SHOW_FLAGS; 1514 1518 kbd_table[i].lockstate = KBD_DEFLOCK; 1515 1519 kbd_table[i].slockstate = 0;