]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/input/keyboard.c
input: Convert 'keyboard' driver to use input library
[people/ms/u-boot.git] / drivers / input / keyboard.c
CommitLineData
1c43771b
WD
1/***********************************************************************
2 *
3 * (C) Copyright 2004
4 * DENX Software Engineering
5 * Wolfgang Denk, wd@denx.de
1c43771b
WD
6 *
7 * Keyboard driver
8 *
9 ***********************************************************************/
10
11#include <common.h>
91f81545 12#include <input.h>
1c43771b 13#include <keyboard.h>
91f81545 14#include <stdio_dev.h>
1c43771b 15
91f81545 16static struct input_config config;
1c43771b 17
91f81545
SG
18static int kbd_read_keys(struct input_config *config)
19{
20#if defined(CONFIG_MPC5xxx) || defined(CONFIG_MPC8540) || \
21 defined(CONFIG_MPC8541) || defined(CONFIG_MPC8555)
22 /* no ISR is used, so received chars must be polled */
23 ps2ser_check();
7e6bf358
WD
24#endif
25
91f81545
SG
26 return 1;
27}
1c43771b 28
91f81545
SG
29static int check_leds(int ret)
30{
31 int leds;
1c43771b 32
91f81545
SG
33 leds = input_leds_changed(&config);
34 if (leds >= 0)
35 pckbd_leds(leds);
1c43771b 36
91f81545 37 return ret;
1c43771b
WD
38}
39
40/* test if a character is in the queue */
709ea543 41static int kbd_testc(struct stdio_dev *dev)
1c43771b 42{
91f81545 43 return check_leds(input_tstc(&config));
1c43771b
WD
44}
45
46/* gets the character from the queue */
709ea543 47static int kbd_getc(struct stdio_dev *dev)
1c43771b 48{
91f81545 49 return check_leds(input_getc(&config));
1c43771b
WD
50}
51
91f81545 52void handle_scancode(unsigned char scan_code)
1c43771b 53{
91f81545 54 bool release = false;
1c43771b 55
91f81545
SG
56 /* Compare with i8042_kbd_check() in i8042.c if some logic is missing */
57 if (scan_code & 0x80) {
58 scan_code &= 0x7f;
59 release = true;
1c43771b
WD
60 }
61
91f81545 62 input_add_keycode(&config, scan_code, release);
1c43771b
WD
63}
64
91f81545 65/* TODO: convert to driver model */
1c43771b
WD
66int kbd_init (void)
67{
91f81545
SG
68 struct stdio_dev kbddev;
69 struct input_config *input = &config;
1c43771b
WD
70
71 if(kbd_init_hw()==-1)
72 return -1;
53677ef1 73 memset (&kbddev, 0, sizeof(kbddev));
91f81545 74 strcpy(kbddev.name, "kbd");
1caf934a 75 kbddev.flags = DEV_FLAGS_INPUT;
91f81545
SG
76 kbddev.getc = kbd_getc;
77 kbddev.tstc = kbd_testc;
1c43771b 78
91f81545
SG
79 input_init(input, 0);
80 input->read_keys = kbd_read_keys;
81 input_add_tables(input, true);
82
83 return input_stdio_register(&kbddev);
1c43771b 84}