aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/keyboard.c')
-rw-r--r--drivers/char/keyboard.c114
1 files changed, 57 insertions, 57 deletions
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 523fd3c8bbaa..449d029ad4f4 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -14,7 +14,7 @@
14 * `Sticky' modifier keys, 951006. 14 * `Sticky' modifier keys, 951006.
15 * 15 *
16 * 11-11-96: SAK should now work in the raw mode (Martin Mares) 16 * 11-11-96: SAK should now work in the raw mode (Martin Mares)
17 * 17 *
18 * Modified to provide 'generic' keyboard support by Hamish Macdonald 18 * Modified to provide 'generic' keyboard support by Hamish Macdonald
19 * Merge with the m68k keyboard driver and split-off of the PC low-level 19 * Merge with the m68k keyboard driver and split-off of the PC low-level
20 * parts by Geert Uytterhoeven, May 1997 20 * parts by Geert Uytterhoeven, May 1997
@@ -52,7 +52,7 @@ extern void ctrl_alt_del(void);
52/* 52/*
53 * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on. 53 * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on.
54 * This seems a good reason to start with NumLock off. On HIL keyboards 54 * This seems a good reason to start with NumLock off. On HIL keyboards
55 * of PARISC machines however there is no NumLock key and everyone expects the keypad 55 * of PARISC machines however there is no NumLock key and everyone expects the keypad
56 * to be used for numbers. 56 * to be used for numbers.
57 */ 57 */
58 58
@@ -76,17 +76,17 @@ void compute_shiftstate(void);
76 k_meta, k_ascii, k_lock, k_lowercase,\ 76 k_meta, k_ascii, k_lock, k_lowercase,\
77 k_slock, k_dead2, k_ignore, k_ignore 77 k_slock, k_dead2, k_ignore, k_ignore
78 78
79typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value, 79typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value,
80 char up_flag, struct pt_regs *regs); 80 char up_flag, struct pt_regs *regs);
81static k_handler_fn K_HANDLERS; 81static k_handler_fn K_HANDLERS;
82static k_handler_fn *k_handler[16] = { K_HANDLERS }; 82static k_handler_fn *k_handler[16] = { K_HANDLERS };
83 83
84#define FN_HANDLERS\ 84#define FN_HANDLERS\
85 fn_null, fn_enter, fn_show_ptregs, fn_show_mem,\ 85 fn_null, fn_enter, fn_show_ptregs, fn_show_mem,\
86 fn_show_state, fn_send_intr, fn_lastcons, fn_caps_toggle,\ 86 fn_show_state, fn_send_intr, fn_lastcons, fn_caps_toggle,\
87 fn_num, fn_hold, fn_scroll_forw, fn_scroll_back,\ 87 fn_num, fn_hold, fn_scroll_forw, fn_scroll_back,\
88 fn_boot_it, fn_caps_on, fn_compose, fn_SAK,\ 88 fn_boot_it, fn_caps_on, fn_compose, fn_SAK,\
89 fn_dec_console, fn_inc_console, fn_spawn_con, fn_bare_num 89 fn_dec_console, fn_inc_console, fn_spawn_con, fn_bare_num
90 90
91typedef void (fn_handler_fn)(struct vc_data *vc, struct pt_regs *regs); 91typedef void (fn_handler_fn)(struct vc_data *vc, struct pt_regs *regs);
92static fn_handler_fn FN_HANDLERS; 92static fn_handler_fn FN_HANDLERS;
@@ -159,13 +159,13 @@ static int sysrq_alt;
159 */ 159 */
160int getkeycode(unsigned int scancode) 160int getkeycode(unsigned int scancode)
161{ 161{
162 struct list_head * node; 162 struct list_head *node;
163 struct input_dev *dev = NULL; 163 struct input_dev *dev = NULL;
164 164
165 list_for_each(node,&kbd_handler.h_list) { 165 list_for_each(node, &kbd_handler.h_list) {
166 struct input_handle * handle = to_handle_h(node); 166 struct input_handle *handle = to_handle_h(node);
167 if (handle->dev->keycodesize) { 167 if (handle->dev->keycodesize) {
168 dev = handle->dev; 168 dev = handle->dev;
169 break; 169 break;
170 } 170 }
171 } 171 }
@@ -181,15 +181,15 @@ int getkeycode(unsigned int scancode)
181 181
182int setkeycode(unsigned int scancode, unsigned int keycode) 182int setkeycode(unsigned int scancode, unsigned int keycode)
183{ 183{
184 struct list_head * node; 184 struct list_head *node;
185 struct input_dev *dev = NULL; 185 struct input_dev *dev = NULL;
186 unsigned int i, oldkey; 186 unsigned int i, oldkey;
187 187
188 list_for_each(node,&kbd_handler.h_list) { 188 list_for_each(node, &kbd_handler.h_list) {
189 struct input_handle *handle = to_handle_h(node); 189 struct input_handle *handle = to_handle_h(node);
190 if (handle->dev->keycodesize) { 190 if (handle->dev->keycodesize) {
191 dev = handle->dev; 191 dev = handle->dev;
192 break; 192 break;
193 } 193 }
194 } 194 }
195 195
@@ -200,7 +200,7 @@ int setkeycode(unsigned int scancode, unsigned int keycode)
200 return -EINVAL; 200 return -EINVAL;
201 if (keycode < 0 || keycode > KEY_MAX) 201 if (keycode < 0 || keycode > KEY_MAX)
202 return -EINVAL; 202 return -EINVAL;
203 if (keycode >> (dev->keycodesize * 8)) 203 if (dev->keycodesize < sizeof(keycode) && (keycode >> (dev->keycodesize * 8)))
204 return -EINVAL; 204 return -EINVAL;
205 205
206 oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode); 206 oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode);
@@ -216,11 +216,11 @@ int setkeycode(unsigned int scancode, unsigned int keycode)
216} 216}
217 217
218/* 218/*
219 * Making beeps and bells. 219 * Making beeps and bells.
220 */ 220 */
221static void kd_nosound(unsigned long ignored) 221static void kd_nosound(unsigned long ignored)
222{ 222{
223 struct list_head * node; 223 struct list_head *node;
224 224
225 list_for_each(node,&kbd_handler.h_list) { 225 list_for_each(node,&kbd_handler.h_list) {
226 struct input_handle *handle = to_handle_h(node); 226 struct input_handle *handle = to_handle_h(node);
@@ -233,17 +233,16 @@ static void kd_nosound(unsigned long ignored)
233 } 233 }
234} 234}
235 235
236static struct timer_list kd_mksound_timer = 236static DEFINE_TIMER(kd_mksound_timer, kd_nosound, 0, 0);
237 TIMER_INITIALIZER(kd_nosound, 0, 0);
238 237
239void kd_mksound(unsigned int hz, unsigned int ticks) 238void kd_mksound(unsigned int hz, unsigned int ticks)
240{ 239{
241 struct list_head * node; 240 struct list_head *node;
242 241
243 del_timer(&kd_mksound_timer); 242 del_timer(&kd_mksound_timer);
244 243
245 if (hz) { 244 if (hz) {
246 list_for_each_prev(node,&kbd_handler.h_list) { 245 list_for_each_prev(node, &kbd_handler.h_list) {
247 struct input_handle *handle = to_handle_h(node); 246 struct input_handle *handle = to_handle_h(node);
248 if (test_bit(EV_SND, handle->dev->evbit)) { 247 if (test_bit(EV_SND, handle->dev->evbit)) {
249 if (test_bit(SND_TONE, handle->dev->sndbit)) { 248 if (test_bit(SND_TONE, handle->dev->sndbit)) {
@@ -338,19 +337,19 @@ static void to_utf8(struct vc_data *vc, ushort c)
338 if (c < 0x80) 337 if (c < 0x80)
339 /* 0******* */ 338 /* 0******* */
340 put_queue(vc, c); 339 put_queue(vc, c);
341 else if (c < 0x800) { 340 else if (c < 0x800) {
342 /* 110***** 10****** */ 341 /* 110***** 10****** */
343 put_queue(vc, 0xc0 | (c >> 6)); 342 put_queue(vc, 0xc0 | (c >> 6));
344 put_queue(vc, 0x80 | (c & 0x3f)); 343 put_queue(vc, 0x80 | (c & 0x3f));
345 } else { 344 } else {
346 /* 1110**** 10****** 10****** */ 345 /* 1110**** 10****** 10****** */
347 put_queue(vc, 0xe0 | (c >> 12)); 346 put_queue(vc, 0xe0 | (c >> 12));
348 put_queue(vc, 0x80 | ((c >> 6) & 0x3f)); 347 put_queue(vc, 0x80 | ((c >> 6) & 0x3f));
349 put_queue(vc, 0x80 | (c & 0x3f)); 348 put_queue(vc, 0x80 | (c & 0x3f));
350 } 349 }
351} 350}
352 351
353/* 352/*
354 * Called after returning from RAW mode or when changing consoles - recompute 353 * Called after returning from RAW mode or when changing consoles - recompute
355 * shift_down[] and shift_state from key_down[] maybe called when keymap is 354 * shift_down[] and shift_state from key_down[] maybe called when keymap is
356 * undefined, so that shiftkey release is seen 355 * undefined, so that shiftkey release is seen
@@ -361,7 +360,7 @@ void compute_shiftstate(void)
361 360
362 shift_state = 0; 361 shift_state = 0;
363 memset(shift_down, 0, sizeof(shift_down)); 362 memset(shift_down, 0, sizeof(shift_down));
364 363
365 for (i = 0; i < ARRAY_SIZE(key_down); i++) { 364 for (i = 0; i < ARRAY_SIZE(key_down); i++) {
366 365
367 if (!key_down[i]) 366 if (!key_down[i])
@@ -500,9 +499,9 @@ static void fn_dec_console(struct vc_data *vc, struct pt_regs *regs)
500 if (want_console != -1) 499 if (want_console != -1)
501 cur = want_console; 500 cur = want_console;
502 501
503 for (i = cur-1; i != cur; i--) { 502 for (i = cur - 1; i != cur; i--) {
504 if (i == -1) 503 if (i == -1)
505 i = MAX_NR_CONSOLES-1; 504 i = MAX_NR_CONSOLES - 1;
506 if (vc_cons_allocated(i)) 505 if (vc_cons_allocated(i))
507 break; 506 break;
508 } 507 }
@@ -568,9 +567,9 @@ static void fn_compose(struct vc_data *vc, struct pt_regs *regs)
568 567
569static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs) 568static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs)
570{ 569{
571 if (spawnpid) 570 if (spawnpid)
572 if(kill_proc(spawnpid, spawnsig, 1)) 571 if (kill_proc(spawnpid, spawnsig, 1))
573 spawnpid = 0; 572 spawnpid = 0;
574} 573}
575 574
576static void fn_SAK(struct vc_data *vc, struct pt_regs *regs) 575static void fn_SAK(struct vc_data *vc, struct pt_regs *regs)
@@ -604,8 +603,8 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag, struct
604 return; 603 return;
605 if (value >= ARRAY_SIZE(fn_handler)) 604 if (value >= ARRAY_SIZE(fn_handler))
606 return; 605 return;
607 if ((kbd->kbdmode == VC_RAW || 606 if ((kbd->kbdmode == VC_RAW ||
608 kbd->kbdmode == VC_MEDIUMRAW) && 607 kbd->kbdmode == VC_MEDIUMRAW) &&
609 value != KVAL(K_SAK)) 608 value != KVAL(K_SAK))
610 return; /* SAK is allowed even in raw mode */ 609 return; /* SAK is allowed even in raw mode */
611 fn_handler[value](vc, regs); 610 fn_handler[value](vc, regs);
@@ -895,11 +894,11 @@ static inline unsigned char getleds(void)
895 894
896static void kbd_bh(unsigned long dummy) 895static void kbd_bh(unsigned long dummy)
897{ 896{
898 struct list_head * node; 897 struct list_head *node;
899 unsigned char leds = getleds(); 898 unsigned char leds = getleds();
900 899
901 if (leds != ledstate) { 900 if (leds != ledstate) {
902 list_for_each(node,&kbd_handler.h_list) { 901 list_for_each(node, &kbd_handler.h_list) {
903 struct input_handle * handle = to_handle_h(node); 902 struct input_handle * handle = to_handle_h(node);
904 input_event(handle->dev, EV_LED, LED_SCROLLL, !!(leds & 0x01)); 903 input_event(handle->dev, EV_LED, LED_SCROLLL, !!(leds & 0x01));
905 input_event(handle->dev, EV_LED, LED_NUML, !!(leds & 0x02)); 904 input_event(handle->dev, EV_LED, LED_NUML, !!(leds & 0x02));
@@ -964,11 +963,11 @@ static int sparc_l1_a_state = 0;
964extern void sun_do_break(void); 963extern void sun_do_break(void);
965#endif 964#endif
966 965
967static int emulate_raw(struct vc_data *vc, unsigned int keycode, 966static int emulate_raw(struct vc_data *vc, unsigned int keycode,
968 unsigned char up_flag) 967 unsigned char up_flag)
969{ 968{
970 if (keycode > 255 || !x86_keycodes[keycode]) 969 if (keycode > 255 || !x86_keycodes[keycode])
971 return -1; 970 return -1;
972 971
973 switch (keycode) { 972 switch (keycode) {
974 case KEY_PAUSE: 973 case KEY_PAUSE:
@@ -982,7 +981,7 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode,
982 case KEY_HANJA: 981 case KEY_HANJA:
983 if (!up_flag) put_queue(vc, 0xf2); 982 if (!up_flag) put_queue(vc, 0xf2);
984 return 0; 983 return 0;
985 } 984 }
986 985
987 if (keycode == KEY_SYSRQ && sysrq_alt) { 986 if (keycode == KEY_SYSRQ && sysrq_alt) {
988 put_queue(vc, 0x54 | up_flag); 987 put_queue(vc, 0x54 | up_flag);
@@ -1105,11 +1104,12 @@ static void kbd_keycode(unsigned int keycode, int down,
1105 else 1104 else
1106 clear_bit(keycode, key_down); 1105 clear_bit(keycode, key_down);
1107 1106
1108 if (rep && (!vc_kbd_mode(kbd, VC_REPEAT) || (tty && 1107 if (rep &&
1109 (!L_ECHO(tty) && tty->driver->chars_in_buffer(tty))))) { 1108 (!vc_kbd_mode(kbd, VC_REPEAT) ||
1109 (tty && !L_ECHO(tty) && tty->driver->chars_in_buffer(tty)))) {
1110 /* 1110 /*
1111 * Don't repeat a key if the input buffers are not empty and the 1111 * Don't repeat a key if the input buffers are not empty and the
1112 * characters get aren't echoed locally. This makes key repeat 1112 * characters get aren't echoed locally. This makes key repeat
1113 * usable with slow applications and under heavy loads. 1113 * usable with slow applications and under heavy loads.
1114 */ 1114 */
1115 return; 1115 return;
@@ -1131,7 +1131,8 @@ static void kbd_keycode(unsigned int keycode, int down,
1131 type = KTYP(keysym); 1131 type = KTYP(keysym);
1132 1132
1133 if (type < 0xf0) { 1133 if (type < 0xf0) {
1134 if (down && !raw_mode) to_utf8(vc, keysym); 1134 if (down && !raw_mode)
1135 to_utf8(vc, keysym);
1135 return; 1136 return;
1136 } 1137 }
1137 1138
@@ -1155,7 +1156,7 @@ static void kbd_keycode(unsigned int keycode, int down,
1155 kbd->slockstate = 0; 1156 kbd->slockstate = 0;
1156} 1157}
1157 1158
1158static void kbd_event(struct input_handle *handle, unsigned int event_type, 1159static void kbd_event(struct input_handle *handle, unsigned int event_type,
1159 unsigned int event_code, int value) 1160 unsigned int event_code, int value)
1160{ 1161{
1161 if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev)) 1162 if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev))
@@ -1167,15 +1168,13 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,
1167 schedule_console_callback(); 1168 schedule_console_callback();
1168} 1169}
1169 1170
1170static char kbd_name[] = "kbd";
1171
1172/* 1171/*
1173 * When a keyboard (or other input device) is found, the kbd_connect 1172 * When a keyboard (or other input device) is found, the kbd_connect
1174 * function is called. The function then looks at the device, and if it 1173 * function is called. The function then looks at the device, and if it
1175 * likes it, it can open it and get events from it. In this (kbd_connect) 1174 * likes it, it can open it and get events from it. In this (kbd_connect)
1176 * function, we should decide which VT to bind that keyboard to initially. 1175 * function, we should decide which VT to bind that keyboard to initially.
1177 */ 1176 */
1178static struct input_handle *kbd_connect(struct input_handler *handler, 1177static struct input_handle *kbd_connect(struct input_handler *handler,
1179 struct input_dev *dev, 1178 struct input_dev *dev,
1180 struct input_device_id *id) 1179 struct input_device_id *id)
1181{ 1180{
@@ -1183,18 +1182,19 @@ static struct input_handle *kbd_connect(struct input_handler *handler,
1183 int i; 1182 int i;
1184 1183
1185 for (i = KEY_RESERVED; i < BTN_MISC; i++) 1184 for (i = KEY_RESERVED; i < BTN_MISC; i++)
1186 if (test_bit(i, dev->keybit)) break; 1185 if (test_bit(i, dev->keybit))
1186 break;
1187 1187
1188 if ((i == BTN_MISC) && !test_bit(EV_SND, dev->evbit)) 1188 if (i == BTN_MISC && !test_bit(EV_SND, dev->evbit))
1189 return NULL; 1189 return NULL;
1190 1190
1191 if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL))) 1191 if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL)))
1192 return NULL; 1192 return NULL;
1193 memset(handle, 0, sizeof(struct input_handle)); 1193 memset(handle, 0, sizeof(struct input_handle));
1194 1194
1195 handle->dev = dev; 1195 handle->dev = dev;
1196 handle->handler = handler; 1196 handle->handler = handler;
1197 handle->name = kbd_name; 1197 handle->name = "kbd";
1198 1198
1199 input_open_device(handle); 1199 input_open_device(handle);
1200 kbd_refresh_leds(handle); 1200 kbd_refresh_leds(handle);
@@ -1213,11 +1213,11 @@ static struct input_device_id kbd_ids[] = {
1213 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1213 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
1214 .evbit = { BIT(EV_KEY) }, 1214 .evbit = { BIT(EV_KEY) },
1215 }, 1215 },
1216 1216
1217 { 1217 {
1218 .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 1218 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
1219 .evbit = { BIT(EV_SND) }, 1219 .evbit = { BIT(EV_SND) },
1220 }, 1220 },
1221 1221
1222 { }, /* Terminating entry */ 1222 { }, /* Terminating entry */
1223}; 1223};