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> 12*91f81545SSimon Glass #include <input.h> 1316b195c8SJean-Christophe PLAGNIOL-VILLARD #include <keyboard.h> 14*91f81545SSimon Glass #include <stdio_dev.h> 1516b195c8SJean-Christophe PLAGNIOL-VILLARD 16*91f81545SSimon Glass static struct input_config config; 1716b195c8SJean-Christophe PLAGNIOL-VILLARD 18*91f81545SSimon Glass static int kbd_read_keys(struct input_config *config) 1916b195c8SJean-Christophe PLAGNIOL-VILLARD { 20*91f81545SSimon Glass #if defined(CONFIG_MPC5xxx) || defined(CONFIG_MPC8540) || \ 21*91f81545SSimon Glass defined(CONFIG_MPC8541) || defined(CONFIG_MPC8555) 22*91f81545SSimon Glass /* no ISR is used, so received chars must be polled */ 23*91f81545SSimon Glass ps2ser_check(); 24*91f81545SSimon Glass #endif 25*91f81545SSimon Glass 26*91f81545SSimon Glass return 1; 2716b195c8SJean-Christophe PLAGNIOL-VILLARD } 28*91f81545SSimon Glass 29*91f81545SSimon Glass static int check_leds(int ret) 30*91f81545SSimon Glass { 31*91f81545SSimon Glass int leds; 32*91f81545SSimon Glass 33*91f81545SSimon Glass leds = input_leds_changed(&config); 34*91f81545SSimon Glass if (leds >= 0) 35*91f81545SSimon Glass pckbd_leds(leds); 36*91f81545SSimon Glass 37*91f81545SSimon Glass return ret; 3816b195c8SJean-Christophe PLAGNIOL-VILLARD } 3916b195c8SJean-Christophe PLAGNIOL-VILLARD 4016b195c8SJean-Christophe PLAGNIOL-VILLARD /* test if a character is in the queue */ 41709ea543SSimon Glass static int kbd_testc(struct stdio_dev *dev) 4216b195c8SJean-Christophe PLAGNIOL-VILLARD { 43*91f81545SSimon Glass return check_leds(input_tstc(&config)); 4416b195c8SJean-Christophe PLAGNIOL-VILLARD } 4516b195c8SJean-Christophe PLAGNIOL-VILLARD 4616b195c8SJean-Christophe PLAGNIOL-VILLARD /* gets the character from the queue */ 47709ea543SSimon Glass static int kbd_getc(struct stdio_dev *dev) 4816b195c8SJean-Christophe PLAGNIOL-VILLARD { 49*91f81545SSimon Glass return check_leds(input_getc(&config)); 5016b195c8SJean-Christophe PLAGNIOL-VILLARD } 5116b195c8SJean-Christophe PLAGNIOL-VILLARD 52*91f81545SSimon Glass void handle_scancode(unsigned char scan_code) 5316b195c8SJean-Christophe PLAGNIOL-VILLARD { 54*91f81545SSimon Glass bool release = false; 5516b195c8SJean-Christophe PLAGNIOL-VILLARD 56*91f81545SSimon Glass /* Compare with i8042_kbd_check() in i8042.c if some logic is missing */ 57*91f81545SSimon Glass if (scan_code & 0x80) { 58*91f81545SSimon Glass scan_code &= 0x7f; 59*91f81545SSimon Glass release = true; 6016b195c8SJean-Christophe PLAGNIOL-VILLARD } 6116b195c8SJean-Christophe PLAGNIOL-VILLARD 62*91f81545SSimon Glass input_add_keycode(&config, scan_code, release); 6316b195c8SJean-Christophe PLAGNIOL-VILLARD } 6416b195c8SJean-Christophe PLAGNIOL-VILLARD 65*91f81545SSimon Glass /* TODO: convert to driver model */ 6616b195c8SJean-Christophe PLAGNIOL-VILLARD int kbd_init (void) 6716b195c8SJean-Christophe PLAGNIOL-VILLARD { 6852cb4d4fSJean-Christophe PLAGNIOL-VILLARD struct stdio_dev kbddev; 69*91f81545SSimon Glass struct input_config *input = &config; 7016b195c8SJean-Christophe PLAGNIOL-VILLARD 7116b195c8SJean-Christophe PLAGNIOL-VILLARD if(kbd_init_hw()==-1) 7216b195c8SJean-Christophe PLAGNIOL-VILLARD return -1; 7316b195c8SJean-Christophe PLAGNIOL-VILLARD memset (&kbddev, 0, sizeof(kbddev)); 74*91f81545SSimon Glass strcpy(kbddev.name, "kbd"); 751caf934aSBin Meng kbddev.flags = DEV_FLAGS_INPUT; 7616b195c8SJean-Christophe PLAGNIOL-VILLARD kbddev.getc = kbd_getc; 7716b195c8SJean-Christophe PLAGNIOL-VILLARD kbddev.tstc = kbd_testc; 7816b195c8SJean-Christophe PLAGNIOL-VILLARD 79*91f81545SSimon Glass input_init(input, 0); 80*91f81545SSimon Glass input->read_keys = kbd_read_keys; 81*91f81545SSimon Glass input_add_tables(input, true); 82*91f81545SSimon Glass 83*91f81545SSimon Glass return input_stdio_register(&kbddev); 8416b195c8SJean-Christophe PLAGNIOL-VILLARD } 85