]> git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/input/keyboard.c
Convert CONFIG_BOOTCOUNT_RAM to Kconfig
[people/ms/u-boot.git] / drivers / input / keyboard.c
1 /***********************************************************************
2 *
3 * (C) Copyright 2004
4 * DENX Software Engineering
5 * Wolfgang Denk, wd@denx.de
6 *
7 * Keyboard driver
8 *
9 ***********************************************************************/
10
11 #include <common.h>
12 #include <console.h>
13 #include <input.h>
14
15 #include <stdio_dev.h>
16 #include <keyboard.h>
17 #include <stdio_dev.h>
18
19 static struct input_config config;
20
21 static int kbd_read_keys(struct input_config *config)
22 {
23 #if defined(CONFIG_ARCH_MPC8540) || \
24 defined(CONFIG_ARCH_MPC8541) || defined(CONFIG_ARCH_MPC8555)
25 /* no ISR is used, so received chars must be polled */
26 ps2ser_check();
27 #endif
28
29 return 1;
30 }
31
32 static int check_leds(int ret)
33 {
34 int leds;
35
36 leds = input_leds_changed(&config);
37 if (leds >= 0)
38 pckbd_leds(leds);
39
40 return ret;
41 }
42
43 /* test if a character is in the queue */
44 static int kbd_testc(struct stdio_dev *dev)
45 {
46 return check_leds(input_tstc(&config));
47 }
48
49 /* gets the character from the queue */
50 static int kbd_getc(struct stdio_dev *dev)
51 {
52 return check_leds(input_getc(&config));
53 }
54
55 void handle_scancode(unsigned char scan_code)
56 {
57 bool release = false;
58
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;
63 }
64
65 input_add_keycode(&config, scan_code, release);
66 }
67
68 /* TODO: convert to driver model */
69 int kbd_init (void)
70 {
71 struct stdio_dev kbddev;
72 struct input_config *input = &config;
73
74 if(kbd_init_hw()==-1)
75 return -1;
76 memset (&kbddev, 0, sizeof(kbddev));
77 strcpy(kbddev.name, "kbd");
78 kbddev.flags = DEV_FLAGS_INPUT;
79 kbddev.getc = kbd_getc;
80 kbddev.tstc = kbd_testc;
81
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);
87 }