summaryrefslogtreecommitdiff
path: root/drivers/input/keyboard.c
blob: 7af5868dea727b1bf11fbabac38c54b3e98d3690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***********************************************************************
 *
 * (C) Copyright 2004
 * DENX Software Engineering
 * Wolfgang Denk, wd@denx.de
 *
 * Keyboard driver
 *
 ***********************************************************************/

#include <common.h>
#include <console.h>
#include <input.h>

#include <stdio_dev.h>
#include <keyboard.h>
#include <stdio_dev.h>

static struct input_config config;

static int kbd_read_keys(struct input_config *config)
{
#if defined(CONFIG_MPC5xxx) || defined(CONFIG_ARCH_MPC8540) || \
		defined(CONFIG_ARCH_MPC8541) || defined(CONFIG_ARCH_MPC8555)
	/* no ISR is used, so received chars must be polled */
	ps2ser_check();
#endif

	return 1;
}

static int check_leds(int ret)
{
	int leds;

	leds = input_leds_changed(&config);
	if (leds >= 0)
		pckbd_leds(leds);

	return ret;
}

/* test if a character is in the queue */
static int kbd_testc(struct stdio_dev *dev)
{
	return check_leds(input_tstc(&config));
}

/* gets the character from the queue */
static int kbd_getc(struct stdio_dev *dev)
{
	return check_leds(input_getc(&config));
}

void handle_scancode(unsigned char scan_code)
{
	bool release = false;

	/* Compare with i8042_kbd_check() in i8042.c if some logic is missing */
	if (scan_code & 0x80) {
		scan_code &= 0x7f;
		release = true;
	}

	input_add_keycode(&config, scan_code, release);
}

/* TODO: convert to driver model */
int kbd_init (void)
{
	struct stdio_dev kbddev;
	struct input_config *input = &config;

	if(kbd_init_hw()==-1)
		return -1;
	memset (&kbddev, 0, sizeof(kbddev));
	strcpy(kbddev.name, "kbd");
	kbddev.flags =  DEV_FLAGS_INPUT;
	kbddev.getc = kbd_getc;
	kbddev.tstc = kbd_testc;

	input_init(input, 0);
	input->read_keys = kbd_read_keys;
	input_add_tables(input, true);

	return input_stdio_register(&kbddev);
}