1 /*********************************************************************** 2 * 3 * (C) Copyright 2004 4 * DENX Software Engineering 5 * Wolfgang Denk, wd@denx.de 6 * 7 * Keyboard driver 8 * 9 ***********************************************************************/ 10 11 #include <common.h> 12 #include <input.h> 13 #include <keyboard.h> 14 #include <stdio_dev.h> 15 16 static struct input_config config; 17 18 static 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(); 24 #endif 25 26 return 1; 27 } 28 29 static int check_leds(int ret) 30 { 31 int leds; 32 33 leds = input_leds_changed(&config); 34 if (leds >= 0) 35 pckbd_leds(leds); 36 37 return ret; 38 } 39 40 /* test if a character is in the queue */ 41 static int kbd_testc(struct stdio_dev *dev) 42 { 43 return check_leds(input_tstc(&config)); 44 } 45 46 /* gets the character from the queue */ 47 static int kbd_getc(struct stdio_dev *dev) 48 { 49 return check_leds(input_getc(&config)); 50 } 51 52 void handle_scancode(unsigned char scan_code) 53 { 54 bool release = false; 55 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; 60 } 61 62 input_add_keycode(&config, scan_code, release); 63 } 64 65 /* TODO: convert to driver model */ 66 int kbd_init (void) 67 { 68 struct stdio_dev kbddev; 69 struct input_config *input = &config; 70 71 if(kbd_init_hw()==-1) 72 return -1; 73 memset (&kbddev, 0, sizeof(kbddev)); 74 strcpy(kbddev.name, "kbd"); 75 kbddev.flags = DEV_FLAGS_INPUT; 76 kbddev.getc = kbd_getc; 77 kbddev.tstc = kbd_testc; 78 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); 84 } 85