xref: /rk3399_rockchip-uboot/drivers/input/keyboard.c (revision 064b55cfcb25c0f7692ecf6d4a38f12cd82739f7)
116b195c8SJean-Christophe PLAGNIOL-VILLARD /***********************************************************************
216b195c8SJean-Christophe PLAGNIOL-VILLARD  *
316b195c8SJean-Christophe PLAGNIOL-VILLARD  * (C) Copyright 2004
416b195c8SJean-Christophe PLAGNIOL-VILLARD  * DENX Software Engineering
516b195c8SJean-Christophe PLAGNIOL-VILLARD  * Wolfgang Denk, wd@denx.de
616b195c8SJean-Christophe PLAGNIOL-VILLARD  *
716b195c8SJean-Christophe PLAGNIOL-VILLARD  * Keyboard driver
816b195c8SJean-Christophe PLAGNIOL-VILLARD  *
916b195c8SJean-Christophe PLAGNIOL-VILLARD  ***********************************************************************/
1016b195c8SJean-Christophe PLAGNIOL-VILLARD 
1116b195c8SJean-Christophe PLAGNIOL-VILLARD #include <common.h>
1224b852a7SSimon Glass #include <console.h>
1391f81545SSimon Glass #include <input.h>
1424b852a7SSimon Glass 
1524b852a7SSimon Glass #include <stdio_dev.h>
1616b195c8SJean-Christophe PLAGNIOL-VILLARD #include <keyboard.h>
1791f81545SSimon Glass #include <stdio_dev.h>
1816b195c8SJean-Christophe PLAGNIOL-VILLARD 
1991f81545SSimon Glass static struct input_config config;
2016b195c8SJean-Christophe PLAGNIOL-VILLARD 
kbd_read_keys(struct input_config * config)2191f81545SSimon Glass static int kbd_read_keys(struct input_config *config)
2216b195c8SJean-Christophe PLAGNIOL-VILLARD {
23*064b55cfSHeiko Schocher #if defined(CONFIG_ARCH_MPC8540) || \
243c3d8ab5SYork Sun 		defined(CONFIG_ARCH_MPC8541) || defined(CONFIG_ARCH_MPC8555)
2591f81545SSimon Glass 	/* no ISR is used, so received chars must be polled */
2691f81545SSimon Glass 	ps2ser_check();
2791f81545SSimon Glass #endif
2891f81545SSimon Glass 
2991f81545SSimon Glass 	return 1;
3016b195c8SJean-Christophe PLAGNIOL-VILLARD }
3191f81545SSimon Glass 
check_leds(int ret)3291f81545SSimon Glass static int check_leds(int ret)
3391f81545SSimon Glass {
3491f81545SSimon Glass 	int leds;
3591f81545SSimon Glass 
3691f81545SSimon Glass 	leds = input_leds_changed(&config);
3791f81545SSimon Glass 	if (leds >= 0)
3891f81545SSimon Glass 		pckbd_leds(leds);
3991f81545SSimon Glass 
4091f81545SSimon Glass 	return ret;
4116b195c8SJean-Christophe PLAGNIOL-VILLARD }
4216b195c8SJean-Christophe PLAGNIOL-VILLARD 
4316b195c8SJean-Christophe PLAGNIOL-VILLARD /* test if a character is in the queue */
kbd_testc(struct stdio_dev * dev)44709ea543SSimon Glass static int kbd_testc(struct stdio_dev *dev)
4516b195c8SJean-Christophe PLAGNIOL-VILLARD {
4691f81545SSimon Glass 	return check_leds(input_tstc(&config));
4716b195c8SJean-Christophe PLAGNIOL-VILLARD }
4816b195c8SJean-Christophe PLAGNIOL-VILLARD 
4916b195c8SJean-Christophe PLAGNIOL-VILLARD /* gets the character from the queue */
kbd_getc(struct stdio_dev * dev)50709ea543SSimon Glass static int kbd_getc(struct stdio_dev *dev)
5116b195c8SJean-Christophe PLAGNIOL-VILLARD {
5291f81545SSimon Glass 	return check_leds(input_getc(&config));
5316b195c8SJean-Christophe PLAGNIOL-VILLARD }
5416b195c8SJean-Christophe PLAGNIOL-VILLARD 
handle_scancode(unsigned char scan_code)5591f81545SSimon Glass void handle_scancode(unsigned char scan_code)
5616b195c8SJean-Christophe PLAGNIOL-VILLARD {
5791f81545SSimon Glass 	bool release = false;
5816b195c8SJean-Christophe PLAGNIOL-VILLARD 
5991f81545SSimon Glass 	/* Compare with i8042_kbd_check() in i8042.c if some logic is missing */
6091f81545SSimon Glass 	if (scan_code & 0x80) {
6191f81545SSimon Glass 		scan_code &= 0x7f;
6291f81545SSimon Glass 		release = true;
6316b195c8SJean-Christophe PLAGNIOL-VILLARD 	}
6416b195c8SJean-Christophe PLAGNIOL-VILLARD 
6591f81545SSimon Glass 	input_add_keycode(&config, scan_code, release);
6616b195c8SJean-Christophe PLAGNIOL-VILLARD }
6716b195c8SJean-Christophe PLAGNIOL-VILLARD 
6891f81545SSimon Glass /* TODO: convert to driver model */
kbd_init(void)6916b195c8SJean-Christophe PLAGNIOL-VILLARD int kbd_init (void)
7016b195c8SJean-Christophe PLAGNIOL-VILLARD {
7152cb4d4fSJean-Christophe PLAGNIOL-VILLARD 	struct stdio_dev kbddev;
7291f81545SSimon Glass 	struct input_config *input = &config;
7316b195c8SJean-Christophe PLAGNIOL-VILLARD 
7416b195c8SJean-Christophe PLAGNIOL-VILLARD 	if(kbd_init_hw()==-1)
7516b195c8SJean-Christophe PLAGNIOL-VILLARD 		return -1;
7616b195c8SJean-Christophe PLAGNIOL-VILLARD 	memset (&kbddev, 0, sizeof(kbddev));
7791f81545SSimon Glass 	strcpy(kbddev.name, "kbd");
781caf934aSBin Meng 	kbddev.flags =  DEV_FLAGS_INPUT;
7916b195c8SJean-Christophe PLAGNIOL-VILLARD 	kbddev.getc = kbd_getc;
8016b195c8SJean-Christophe PLAGNIOL-VILLARD 	kbddev.tstc = kbd_testc;
8116b195c8SJean-Christophe PLAGNIOL-VILLARD 
8291f81545SSimon Glass 	input_init(input, 0);
8391f81545SSimon Glass 	input->read_keys = kbd_read_keys;
8491f81545SSimon Glass 	input_add_tables(input, true);
8591f81545SSimon Glass 
8691f81545SSimon Glass 	return input_stdio_register(&kbddev);
8716b195c8SJean-Christophe PLAGNIOL-VILLARD }
88