atakbd.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * atakbd.c
  3. *
  4. * Copyright (c) 2005 Michael Schmitz
  5. *
  6. * Based on amikbd.c, which is
  7. *
  8. * Copyright (c) 2000-2001 Vojtech Pavlik
  9. *
  10. * Based on the work of:
  11. * Hamish Macdonald
  12. */
  13. /*
  14. * Atari keyboard driver for Linux/m68k
  15. *
  16. * The low level init and interrupt stuff is handled in arch/mm68k/atari/atakeyb.c
  17. * (the keyboard ACIA also handles the mouse and joystick data, and the keyboard
  18. * interrupt is shared with the MIDI ACIA so MIDI data also get handled there).
  19. * This driver only deals with handing key events off to the input layer.
  20. */
  21. /*
  22. * This program is free software; you can redistribute it and/or modify
  23. * it under the terms of the GNU General Public License as published by
  24. * the Free Software Foundation; either version 2 of the License, or
  25. * (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public License
  33. * along with this program; if not, write to the Free Software
  34. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  35. *
  36. * Should you need to contact me, the author, you can do so either by
  37. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  38. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  39. */
  40. #include <linux/module.h>
  41. #include <linux/init.h>
  42. #include <linux/input.h>
  43. #include <linux/delay.h>
  44. #include <linux/interrupt.h>
  45. #include <asm/atariints.h>
  46. #include <asm/atarihw.h>
  47. #include <asm/atarikb.h>
  48. #include <asm/irq.h>
  49. MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
  50. MODULE_DESCRIPTION("Atari keyboard driver");
  51. MODULE_LICENSE("GPL");
  52. static unsigned char atakbd_keycode[0x72];
  53. static struct input_dev *atakbd_dev;
  54. static void atakbd_interrupt(unsigned char scancode, char down)
  55. {
  56. if (scancode < 0x72) { /* scancodes < 0xf2 are keys */
  57. // report raw events here?
  58. scancode = atakbd_keycode[scancode];
  59. if (scancode == KEY_CAPSLOCK) { /* CapsLock is a toggle switch key on Amiga */
  60. input_report_key(atakbd_dev, scancode, 1);
  61. input_report_key(atakbd_dev, scancode, 0);
  62. input_sync(atakbd_dev);
  63. } else {
  64. input_report_key(atakbd_dev, scancode, down);
  65. input_sync(atakbd_dev);
  66. }
  67. } else /* scancodes >= 0xf2 are mouse data, most likely */
  68. printk(KERN_INFO "atakbd: unhandled scancode %x\n", scancode);
  69. return;
  70. }
  71. static int __init atakbd_init(void)
  72. {
  73. int i;
  74. if (!ATARIHW_PRESENT(ST_MFP))
  75. return -EIO;
  76. // TODO: request_mem_region if not done in arch code
  77. if (!(atakbd_dev = input_allocate_device()))
  78. return -ENOMEM;
  79. // need to init core driver if not already done so
  80. if (atari_keyb_init())
  81. return -ENODEV;
  82. atakbd_dev->name = "Atari Keyboard";
  83. atakbd_dev->phys = "atakbd/input0";
  84. atakbd_dev->id.bustype = BUS_ATARI;
  85. atakbd_dev->id.vendor = 0x0001;
  86. atakbd_dev->id.product = 0x0001;
  87. atakbd_dev->id.version = 0x0100;
  88. atakbd_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
  89. atakbd_dev->keycode = atakbd_keycode;
  90. atakbd_dev->keycodesize = sizeof(unsigned char);
  91. atakbd_dev->keycodemax = ARRAY_SIZE(atakbd_keycode);
  92. for (i = 1; i < 0x72; i++) {
  93. atakbd_keycode[i] = i;
  94. set_bit(atakbd_keycode[i], atakbd_dev->keybit);
  95. }
  96. input_register_device(atakbd_dev);
  97. atari_input_keyboard_interrupt_hook = atakbd_interrupt;
  98. printk(KERN_INFO "input: %s at IKBD ACIA\n", atakbd_dev->name);
  99. return 0;
  100. }
  101. static void __exit atakbd_exit(void)
  102. {
  103. atari_input_keyboard_interrupt_hook = NULL;
  104. input_unregister_device(atakbd_dev);
  105. }
  106. module_init(atakbd_init);
  107. module_exit(atakbd_exit);