keyboard.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /***********************************************************************
  2. *
  3. * (C) Copyright 2004
  4. * DENX Software Engineering
  5. * Wolfgang Denk, wd@denx.de
  6. *
  7. * Keyboard driver
  8. *
  9. ***********************************************************************/
  10. #include <common.h>
  11. #include <console.h>
  12. #include <input.h>
  13. #include <stdio_dev.h>
  14. #include <keyboard.h>
  15. #include <stdio_dev.h>
  16. static struct input_config config;
  17. static int kbd_read_keys(struct input_config *config)
  18. {
  19. #if defined(CONFIG_ARCH_MPC8540) || \
  20. defined(CONFIG_ARCH_MPC8541) || defined(CONFIG_ARCH_MPC8555)
  21. /* no ISR is used, so received chars must be polled */
  22. ps2ser_check();
  23. #endif
  24. return 1;
  25. }
  26. static int check_leds(int ret)
  27. {
  28. int leds;
  29. leds = input_leds_changed(&config);
  30. if (leds >= 0)
  31. pckbd_leds(leds);
  32. return ret;
  33. }
  34. /* test if a character is in the queue */
  35. static int kbd_testc(struct stdio_dev *dev)
  36. {
  37. return check_leds(input_tstc(&config));
  38. }
  39. /* gets the character from the queue */
  40. static int kbd_getc(struct stdio_dev *dev)
  41. {
  42. return check_leds(input_getc(&config));
  43. }
  44. void handle_scancode(unsigned char scan_code)
  45. {
  46. bool release = false;
  47. /* Compare with i8042_kbd_check() in i8042.c if some logic is missing */
  48. if (scan_code & 0x80) {
  49. scan_code &= 0x7f;
  50. release = true;
  51. }
  52. input_add_keycode(&config, scan_code, release);
  53. }
  54. /* TODO: convert to driver model */
  55. int kbd_init (void)
  56. {
  57. struct stdio_dev kbddev;
  58. struct input_config *input = &config;
  59. if(kbd_init_hw()==-1)
  60. return -1;
  61. memset (&kbddev, 0, sizeof(kbddev));
  62. strcpy(kbddev.name, "kbd");
  63. kbddev.flags = DEV_FLAGS_INPUT;
  64. kbddev.getc = kbd_getc;
  65. kbddev.tstc = kbd_testc;
  66. input_init(input, 0);
  67. input->read_keys = kbd_read_keys;
  68. input_add_tables(input, true);
  69. return input_stdio_register(&kbddev);
  70. }