wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 1 | /*********************************************************************** |
2 | * | ||||
3 | * (C) Copyright 2004 | ||||
4 | * DENX Software Engineering | ||||
5 | * Wolfgang Denk, wd@denx.de | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 6 | * |
7 | * Keyboard driver | ||||
8 | * | ||||
9 | ***********************************************************************/ | ||||
10 | |||||
11 | #include <common.h> | ||||
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 12 | #include <console.h> |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 13 | #include <input.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 14 | |
15 | #include <stdio_dev.h> | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 16 | #include <keyboard.h> |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 17 | #include <stdio_dev.h> |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 18 | |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 19 | static struct input_config config; |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 20 | |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 21 | static int kbd_read_keys(struct input_config *config) |
22 | { | ||||
York Sun | 5ddce89 | 2016-11-16 11:13:06 -0800 | [diff] [blame^] | 23 | #if defined(CONFIG_MPC5xxx) || defined(CONFIG_ARCH_MPC8540) || \ |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 24 | defined(CONFIG_MPC8541) || defined(CONFIG_MPC8555) |
25 | /* no ISR is used, so received chars must be polled */ | ||||
26 | ps2ser_check(); | ||||
wdenk | dc13044 | 2004-12-12 22:06:17 +0000 | [diff] [blame] | 27 | #endif |
28 | |||||
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 29 | return 1; |
30 | } | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 31 | |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 32 | static int check_leds(int ret) |
33 | { | ||||
34 | int leds; | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 35 | |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 36 | leds = input_leds_changed(&config); |
37 | if (leds >= 0) | ||||
38 | pckbd_leds(leds); | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 39 | |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 40 | return ret; |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 41 | } |
42 | |||||
43 | /* test if a character is in the queue */ | ||||
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 44 | static int kbd_testc(struct stdio_dev *dev) |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 45 | { |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 46 | return check_leds(input_tstc(&config)); |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 47 | } |
48 | |||||
49 | /* gets the character from the queue */ | ||||
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 50 | static int kbd_getc(struct stdio_dev *dev) |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 51 | { |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 52 | return check_leds(input_getc(&config)); |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 53 | } |
54 | |||||
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 55 | void handle_scancode(unsigned char scan_code) |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 56 | { |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 57 | bool release = false; |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 58 | |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 59 | /* Compare with i8042_kbd_check() in i8042.c if some logic is missing */ |
60 | if (scan_code & 0x80) { | ||||
61 | scan_code &= 0x7f; | ||||
62 | release = true; | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 63 | } |
64 | |||||
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 65 | input_add_keycode(&config, scan_code, release); |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 66 | } |
67 | |||||
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 68 | /* TODO: convert to driver model */ |
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 69 | int kbd_init (void) |
70 | { | ||||
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 71 | struct stdio_dev kbddev; |
72 | struct input_config *input = &config; | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 73 | |
74 | if(kbd_init_hw()==-1) | ||||
75 | return -1; | ||||
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 76 | memset (&kbddev, 0, sizeof(kbddev)); |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 77 | strcpy(kbddev.name, "kbd"); |
Bin Meng | 6abe4b6 | 2015-11-03 23:23:37 -0800 | [diff] [blame] | 78 | kbddev.flags = DEV_FLAGS_INPUT; |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 79 | kbddev.getc = kbd_getc; |
80 | kbddev.tstc = kbd_testc; | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 81 | |
Simon Glass | 139309b | 2015-11-11 10:05:48 -0700 | [diff] [blame] | 82 | input_init(input, 0); |
83 | input->read_keys = kbd_read_keys; | ||||
84 | input_add_tables(input, true); | ||||
85 | |||||
86 | return input_stdio_register(&kbddev); | ||||
wdenk | b983fa2 | 2004-01-16 00:30:56 +0000 | [diff] [blame] | 87 | } |