2004-01-16 00:30:56 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* (C) Copyright 2004
|
|
|
|
* DENX Software Engineering
|
|
|
|
* Wolfgang Denk, wd@denx.de
|
|
|
|
*
|
|
|
|
* Keyboard driver
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
#include <console.h>
|
2015-11-11 17:05:48 +00:00
|
|
|
#include <input.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
|
|
|
|
#include <stdio_dev.h>
|
2004-01-16 00:30:56 +00:00
|
|
|
#include <keyboard.h>
|
2015-11-11 17:05:48 +00:00
|
|
|
#include <stdio_dev.h>
|
2004-01-16 00:30:56 +00:00
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
static struct input_config config;
|
2004-01-16 00:30:56 +00:00
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
static int kbd_read_keys(struct input_config *config)
|
|
|
|
{
|
2017-06-14 03:49:40 +00:00
|
|
|
#if defined(CONFIG_ARCH_MPC8540) || \
|
2016-11-16 19:23:23 +00:00
|
|
|
defined(CONFIG_ARCH_MPC8541) || defined(CONFIG_ARCH_MPC8555)
|
2015-11-11 17:05:48 +00:00
|
|
|
/* no ISR is used, so received chars must be polled */
|
|
|
|
ps2ser_check();
|
2004-12-12 22:06:17 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2004-01-16 00:30:56 +00:00
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
static int check_leds(int ret)
|
|
|
|
{
|
|
|
|
int leds;
|
2004-01-16 00:30:56 +00:00
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
leds = input_leds_changed(&config);
|
|
|
|
if (leds >= 0)
|
|
|
|
pckbd_leds(leds);
|
2004-01-16 00:30:56 +00:00
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
return ret;
|
2004-01-16 00:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* test if a character is in the queue */
|
2014-07-23 12:54:59 +00:00
|
|
|
static int kbd_testc(struct stdio_dev *dev)
|
2004-01-16 00:30:56 +00:00
|
|
|
{
|
2015-11-11 17:05:48 +00:00
|
|
|
return check_leds(input_tstc(&config));
|
2004-01-16 00:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* gets the character from the queue */
|
2014-07-23 12:54:59 +00:00
|
|
|
static int kbd_getc(struct stdio_dev *dev)
|
2004-01-16 00:30:56 +00:00
|
|
|
{
|
2015-11-11 17:05:48 +00:00
|
|
|
return check_leds(input_getc(&config));
|
2004-01-16 00:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
void handle_scancode(unsigned char scan_code)
|
2004-01-16 00:30:56 +00:00
|
|
|
{
|
2015-11-11 17:05:48 +00:00
|
|
|
bool release = false;
|
2004-01-16 00:30:56 +00:00
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
/* Compare with i8042_kbd_check() in i8042.c if some logic is missing */
|
|
|
|
if (scan_code & 0x80) {
|
|
|
|
scan_code &= 0x7f;
|
|
|
|
release = true;
|
2004-01-16 00:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
input_add_keycode(&config, scan_code, release);
|
2004-01-16 00:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
/* TODO: convert to driver model */
|
2004-01-16 00:30:56 +00:00
|
|
|
int kbd_init (void)
|
|
|
|
{
|
2015-11-11 17:05:48 +00:00
|
|
|
struct stdio_dev kbddev;
|
|
|
|
struct input_config *input = &config;
|
2004-01-16 00:30:56 +00:00
|
|
|
|
|
|
|
if(kbd_init_hw()==-1)
|
|
|
|
return -1;
|
2008-05-20 14:00:29 +00:00
|
|
|
memset (&kbddev, 0, sizeof(kbddev));
|
2015-11-11 17:05:48 +00:00
|
|
|
strcpy(kbddev.name, "kbd");
|
2015-11-04 07:23:37 +00:00
|
|
|
kbddev.flags = DEV_FLAGS_INPUT;
|
2015-11-11 17:05:48 +00:00
|
|
|
kbddev.getc = kbd_getc;
|
|
|
|
kbddev.tstc = kbd_testc;
|
2004-01-16 00:30:56 +00:00
|
|
|
|
2015-11-11 17:05:48 +00:00
|
|
|
input_init(input, 0);
|
|
|
|
input->read_keys = kbd_read_keys;
|
|
|
|
input_add_tables(input, true);
|
|
|
|
|
|
|
|
return input_stdio_register(&kbddev);
|
2004-01-16 00:30:56 +00:00
|
|
|
}
|