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