dn_keyb.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:20k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. #include <linux/sched.h>
  2. #include <linux/interrupt.h>
  3. #include <linux/errno.h>
  4. #include <linux/keyboard.h>
  5. #include <linux/delay.h>
  6. #include <linux/timer.h>
  7. #include <linux/kd.h>
  8. #include <linux/random.h>
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/poll.h>
  12. #include <linux/miscdevice.h>
  13. #include <linux/init.h>
  14. #include <asm/setup.h>
  15. #include <asm/irq.h>
  16. #include <asm/apollohw.h>
  17. #include <asm/uaccess.h>
  18. #include "busmouse.h"
  19. /* extern void handle_scancode(unsigned char,int ); */
  20. #define DNKEY_CAPS 0x7e
  21. #define BREAK_FLAG 0x80
  22. #define DNKEY_REPEAT_DELAY 50
  23. #define DNKEY_CTRL 0x43
  24. #define DNKEY_LSHIFT 0x5e
  25. #define DNKEY_RSHIFT 0x6a
  26. #define DNKEY_REPT 0x5d
  27. #define DNKEY_REPEAT 0x7f
  28. #define DNKEY_LALT 0x75
  29. #define DNKEY_RALT 0x77
  30. #define APOLLO_KEYB_CMD_ENTRIES 16
  31. #define APOLLO_KBD_MODE_KEYB   0x01
  32. #define APOLLO_KBD_MODE_MOUSE   0x02
  33. #define APOLLO_KBD_MODE_CHANGE 0xff
  34. static u_char keyb_cmds[APOLLO_KEYB_CMD_ENTRIES];
  35. static short keyb_cmd_read=0, keyb_cmd_write=0;
  36. static int keyb_cmd_transmit=0;
  37. static int msedev;
  38. static unsigned int kbd_mode=APOLLO_KBD_MODE_KEYB;
  39. #if 0
  40. static void debug_keyb_timer_handler(unsigned long ignored);
  41. static u_char debug_buf1[4096],debug_buf2[4096],*debug_buf=&debug_buf1[0];
  42. static u_char *shadow_buf=&debug_buf2[0];
  43. static short debug_buf_count=0;
  44. static int debug_buf_overrun=0,debug_timer_running=0;
  45. static unsigned long debug_buffer_updated=0;
  46. static struct timer_list debug_keyb_timer = { function: debug_keyb_timer_handler };
  47. #endif
  48. static u_short dnplain_map[NR_KEYS] __initdata = {
  49. /*         ins     del     del     F1      F2      F3      F4  
  50.            mark    line    char                                 */
  51.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  52. /* F5      F6      F7      F8      F9      F0      Again   Read */
  53.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  54. /* Edit    Exit    Hold    Copy    Paste   Grow            ESC  */
  55.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b,
  56. /* 1       2       3       4       5       6       7       8    */
  57.    0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036, 0xf037, 0xf038,
  58. /* 9       0       -       =       `       Back            |<--
  59.                                            Space                */
  60.    0xf039, 0xf030, 0xf02d, 0xf03d, 0xf060, 0xf07f, 0xf200, 0xf200,
  61. /* Shell   -->|                    Tab     q       w       e
  62.    Cmd                                                          */
  63.    0xf200, 0xf200, 0xf200, 0xf200, 0xf009, 0xfb71, 0xfb77, 0xfb65,
  64. /* r       t       y       u       i       o       p       [    */
  65.    0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69, 0xfb6f, 0xfb70, 0xf05b,
  66. /* ]               Del             7       8       9       +    */
  67.    0xf05d, 0xf200, 0xf200, 0xf200, 0xf307, 0xf308, 0xf300, 0xf30a,
  68. /* [<--]   Up      [-->]   Ctrl                    a       s    */
  69.    0xf200, 0xf600, 0xf200, 0xf702, 0xf200, 0xf200, 0xfb61, 0xfb73,
  70. /* d       f       g       h       j       k       l       ;    */
  71.    0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
  72. /* '               Return                 4       5       6    */
  73.    0xf027, 0xf200, 0xf201, 0xf05c, 0xf200, 0xf304, 0xf305, 0xf306,
  74. /* -       <--     Next    -->             Rept    Shift        
  75.                    Window                                       */
  76.    0xf30b, 0xf601, 0xf200, 0xf602, 0xf200, 0xf200, 0xf700, 0xf200,
  77. /* z       x       c       v       b       n       m       ,    */
  78.    0xfb7a, 0xfb78, 0xfb63, 0xfb76, 0xfb62, 0xfb6e, 0xfb6d, 0xf02c,
  79. /* .       /       Shift           Pop             1       2    */
  80.    0xf02e, 0xf02f, 0xf700, 0xf200, 0xf200, 0xf200, 0xf301, 0xf302,
  81. /* 3               PgUp    Down    PgDn    Alt     Space   Alt  */
  82.    0xf303, 0xf200, 0xf118, 0xf603, 0xf119, 0xf703, 0xf020, 0xf701,
  83. /*         0               .       Enter                        */
  84.    0xf200, 0xf300, 0xf200, 0xf310, 0xf30e, 0xf200, 0xf700, 0xf200,
  85. };
  86. static u_short dnshift_map[NR_KEYS] __initdata = {
  87. /*         ins     del     del     F1      F2      F3      F4
  88.            mark    line    char                                 */
  89.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  90. /* F5      F6      F7      F8      F9      F0      Again   Read */
  91.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  92. /* Save    Abort   Help    Cut     Undo    Grow            ESC  */
  93.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b,
  94. /* !       @       #       $       %       ^       &       *    */
  95.    0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e, 0xf026, 0xf02a,
  96. /* (       )       _       +       ~       Back            |<--
  97.                                            Space                */
  98.    0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07e, 0xf07f, 0xf200, 0xf200,
  99. /* Shell   -->|                    Tab     Q       W       E
  100.    Cmd                                                          */
  101.    0xf200, 0xf200, 0xf200, 0xf200, 0xf009, 0xfb51, 0xfb57, 0xfb45,
  102. /* R       T       Y       U       I       O       P       {    */
  103.    0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49, 0xfb4f, 0xfb50, 0xf07b,
  104. /* }               Del             7       8       9       +    */
  105.    0xf07d, 0xf200, 0xf200, 0xf200, 0xf307, 0xf308, 0xf300, 0xf30a,
  106. /* [<--]   Up      [-->]   Ctrl                    A       S    */
  107.    0xf200, 0xf600, 0xf200, 0xf702, 0xf200, 0xf200, 0xfb41, 0xfb53,
  108. /* D       F       G       H       J       K       L       :    */
  109.    0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
  110. /* "               Return  |               4       5       6    */
  111.    0xf022, 0xf200, 0xf201, 0xf07c, 0xf200, 0xf304, 0xf305, 0xf306,
  112. /* -       <--     Next    -->             Rept    Shift        
  113.                    Window                                       */
  114.    0xf30b, 0xf601, 0xf200, 0xf602, 0xf200, 0xf200, 0xf700, 0xf200,
  115. /* Z       X       C       V       B       N       M       <    */
  116.    0xfb5a, 0xfb58, 0xfb43, 0xfb56, 0xfb42, 0xfb4e, 0xfb4d, 0xf03c,
  117. /* >       ?       Shift           Pop             1       2    */
  118.    0xf03e, 0xf03f, 0xf700, 0xf200, 0xf200, 0xf200, 0xf301, 0xf302,
  119. /* 3               PgUp    Down    PgDn    Alt     Space   Alt  */
  120.    0xf303, 0xf200, 0xf118, 0xf603, 0xf119, 0xf703, 0xf020, 0xf701,
  121. /*         0               .       Enter                        */
  122.    0xf200, 0xf300, 0xf200, 0xf310, 0xf30e, 0xf200, 0xf708, 0xf200,
  123. };
  124. static u_short dnctrl_map[NR_KEYS] __initdata = {
  125. /*         ins     del     del     F1      F2      F3      F4
  126.            mark    line    char                                 */
  127.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  128. /* F5      F6      F7      F8      F9      F0      Again   Read */
  129.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  130. /* Save    Abort   Help    Cut     Undo    Grow            ESC  */
  131.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b,
  132. /* !       @       #       $       %       ^       &       *    */
  133.    0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01d, 0xf01e, 0xf01f, 0xf07f,
  134. /* (       )       _       +       ~       Back            |<--
  135.                                            Space                */
  136.    0xf200, 0xf200, 0xf01f, 0xf200, 0xf01c, 0xf200, 0xf200, 0xf200,
  137. /* Shell   -->|                    Tab     Q       W       E
  138.    Cmd                                                          */
  139.    0xf200, 0xf200, 0xf200, 0xf200, 0xf009, 0xf011, 0xf017, 0xf005,
  140. /* R       T       Y       U       I       O       P       {    */
  141.    0xf012, 0xf014, 0xf019, 0xf015, 0xf009, 0xf00f, 0xf010, 0xf01b,
  142. /* }               Del             7       8       9       +    */
  143.    0xf01d, 0xf200, 0xf200, 0xf200, 0xf307, 0xf308, 0xf300, 0xf30a,
  144. /* [<--]   Up      [-->]   Ctrl                    A       S    */
  145.    0xf200, 0xf600, 0xf200, 0xf702, 0xf200, 0xf200, 0xfb01, 0xfb53,
  146. /* D       F       G       H       J       K       L       :    */
  147.    0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
  148. /* "               Return  |               4       5       6    */
  149.    0xf200, 0xf200, 0xf201, 0xf01c, 0xf200, 0xf304, 0xf305, 0xf306,
  150. /* -       <--     Next    -->             Rept    Shift        
  151.                    Window                                       */
  152.    0xf30b, 0xf601, 0xf200, 0xf602, 0xf200, 0xf200, 0xf704, 0xf200,
  153. /* Z       X       C       V       B       N       M       <    */
  154.    0xf01a, 0xf018, 0xf003, 0xf016, 0xf002, 0xf00e, 0xf01d, 0xf03c,
  155. /* >       ?       Shift           Pop             1       2    */
  156.    0xf03e, 0xf03f, 0xf705, 0xf200, 0xf200, 0xf200, 0xf301, 0xf302,
  157. /* 3               PgUp    Down    PgDn    Alt     Space   Alt  */
  158.    0xf303, 0xf200, 0xf118, 0xf603, 0xf119, 0xf703, 0xf020, 0xf701,
  159. /*         0               .       Enter                        */
  160.    0xf200, 0xf300, 0xf200, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200,
  161. };
  162. static u_short dnalt_map[NR_KEYS] __initdata = {
  163. /*         ins     del     del     F1      F2      F3      F4  
  164.            mark    line    char                                 */
  165.    0xf200, 0xf200, 0xf200, 0xf200, 0xf500, 0xf501, 0xf502, 0xf503,
  166. /* F5      F6      F7      F8      F9      F0      Again   Read */
  167.    0xf504, 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf200, 0xf200,
  168. /* Edit    Exit    Hold    Copy    Paste   Grow            ESC  */
  169.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b,
  170. /* 1       2       3       4       5       6       7       8    */
  171.    0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836, 0xf837, 0xf838,
  172. /* 9       0       -       =       `       Back            |<--
  173.                                            Space                */
  174.    0xf839, 0xf830, 0xf82d, 0xf83d, 0xf860, 0xf87f, 0xf200, 0xf200,
  175. /* Shell   -->|                    Tab     q       w       e
  176.    Cmd                                                          */
  177.    0xf200, 0xf200, 0xf200, 0xf200, 0xf809, 0xf871, 0xf877, 0xf865,
  178. /* r       t       y       u       i       o       p       [    */
  179.    0xf872, 0xf874, 0xf879, 0xf875, 0xf869, 0xf86f, 0xf870, 0xf85b,
  180. /* ]               Del             7       8       9       +    */
  181.    0xf05d, 0xf200, 0xf200, 0xf200, 0xf307, 0xf308, 0xf300, 0xf30a,
  182. /* [<--]   Up      [-->]   Ctrl                    a       s    */
  183.    0xf200, 0xf600, 0xf200, 0xf702, 0xf200, 0xf200, 0xf861, 0xf873,
  184. /* d       f       g       h       j       k       l       ;    */
  185.    0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf03b,
  186. /* '               Return                 4       5       6    */
  187.    0xf027, 0xf200, 0xf201, 0xf05c, 0xf200, 0xf304, 0xf305, 0xf306,
  188. /* -       <--     Next    -->             Rept    Shift        
  189.                    Window                                       */
  190.    0xf30b, 0xf601, 0xf200, 0xf602, 0xf200, 0xf200, 0xf704, 0xf200,
  191. /* z       x       c       v       b       n       m       ,    */
  192.    0xf87a, 0xf878, 0xf863, 0xf876, 0xf862, 0xf86e, 0xf86d, 0xf82c,
  193. /* .       /       Shift           Pop             1       2    */
  194.    0xf82e, 0xf82f, 0xf705, 0xf200, 0xf200, 0xf200, 0xf301, 0xf302,
  195. /* 3               PgUp    Down    PgDn    Alt     Space   Alt  */
  196.    0xf303, 0xf200, 0xf118, 0xf603, 0xf119, 0xf703, 0xf820, 0xf701,
  197. /*         0               .       Enter                        */
  198.    0xf200, 0xf300, 0xf200, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200,
  199. };
  200. static u_short dnaltgr_map[NR_KEYS] __initdata = {
  201.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  202.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  203.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  204.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  205.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  206.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  207.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  208.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  209.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  210.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  211.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  212.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  213.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  214.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  215.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  216.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
  217. };
  218. static u_short dnshift_ctrl_map[NR_KEYS] __initdata = {
  219.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  220.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  221.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  222.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  223.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  224.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  225.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  226.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  227.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  228.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  229.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  230.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  231.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  232.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  233.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  234.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
  235. };
  236. static u_short dnctrl_alt_map[NR_KEYS] __initdata = {
  237.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  238.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  239.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  240.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  241.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  242.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  243.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  244.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  245.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  246.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  247.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  248.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  249.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  250.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  251.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
  252.    0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
  253. };
  254. #if 0
  255. static void debug_keyb_timer_handler(unsigned long ignored) {
  256. unsigned long flags;
  257. u_char *swap;
  258. short length,i;
  259. if (time_after(jiffies, debug_buffer_updated + 100)) {
  260. save_flags(flags);
  261. cli();
  262. length=debug_buf_count;
  263. swap=debug_buf;
  264. debug_buf=shadow_buf;
  265. shadow_buf=swap;
  266. debug_buf_count=0;
  267. debug_timer_running=0;
  268. restore_flags(flags);
  269. for(i=1;length;length--,i++)
  270. printk("%02x%c",*(swap++), (i % 25) ? ' ' : 'n');
  271. printk("n");
  272. }
  273. else {
  274. debug_keyb_timer.expires=jiffies+10;
  275. add_timer(&debug_keyb_timer);
  276. }
  277. }
  278. #endif
  279. static void dn_keyb_process_key_event(unsigned char scancode) {
  280. static unsigned char lastscancode;
  281. unsigned char prev_scancode=lastscancode;
  282. static unsigned int lastkeypress;
  283. lastscancode=scancode;
  284. /*  printk("scan: %02x, lastscan: %02X, prev_scancode: %02Xn",scancode,lastscancode,prev_scancode); */
  285. if(prev_scancode==APOLLO_KBD_MODE_CHANGE) {
  286. kbd_mode=scancode;
  287. /* printk("modechange: %dn",scancode); */
  288. }
  289. else if((scancode & (~BREAK_FLAG)) == DNKEY_CAPS) {
  290.      /* printk("handle_scancode: %02xn",DNKEY_CAPS); */
  291. handle_scancode(DNKEY_CAPS, 1);
  292. /*    printk("handle_scancode: %02xn",BREAK_FLAG | DNKEY_CAPS); */
  293. handle_scancode(DNKEY_CAPS, 0);
  294. }
  295. else if( (scancode == DNKEY_REPEAT) && (prev_scancode < 0x7e) &&
  296.     !(prev_scancode==DNKEY_CTRL || prev_scancode==DNKEY_LSHIFT ||
  297.             prev_scancode==DNKEY_RSHIFT || prev_scancode==DNKEY_REPT ||
  298.            prev_scancode==DNKEY_LALT || prev_scancode==DNKEY_RALT)) {
  299. if (time_after(jiffies, lastkeypress + DNKEY_REPEAT_DELAY)) {
  300. /*     printk("handle_scancode: %02xn",prev_scancode); */
  301.             handle_scancode(prev_scancode, 1);
  302.    }
  303.     lastscancode=prev_scancode;
  304.    }
  305.    else {
  306. /*     printk("handle_scancode: %02xn",scancode);  */
  307.     handle_scancode(scancode & ~BREAK_FLAG, !(scancode & BREAK_FLAG));
  308.     lastkeypress=jiffies;
  309.    }
  310. }
  311. static void dn_keyb_process_mouse_event(unsigned char mouse_data) {
  312. static short mouse_byte_count=0;
  313. static u_char mouse_packet[3];
  314. short mouse_buttons;
  315. mouse_packet[mouse_byte_count++]=mouse_data;
  316. if(mouse_byte_count==3) {
  317. if(mouse_packet[0]==APOLLO_KBD_MODE_CHANGE) {
  318. kbd_mode=mouse_packet[1];
  319. mouse_byte_count=0;
  320. /* printk("modechange: %dn",mouse_packet[1]); */
  321. if(kbd_mode==APOLLO_KBD_MODE_KEYB)
  322. dn_keyb_process_key_event(mouse_packet[2]);
  323. }
  324. if((mouse_packet[0] & 0x8f) == 0x80) {
  325. if(mouse_update_allowed) {
  326. mouse_ready=1;
  327. mouse_buttons=(mouse_packet[0] >> 4) & 0x7;
  328. mouse_dx+=mouse_packet[1] == 0xff ? 0 : (signed char)mouse_packet[1];
  329. mouse_dy+=mouse_packet[2] == 0xff ? 0 : (signed char)mouse_packet[2];
  330. wake_up_interruptible(&mouse_wait);
  331. if (mouse_dx < -2048)
  332.                mouse_dx = -2048;
  333.            else if (mouse_dx >  2048)
  334.                mouse_dx =  2048;
  335.             if (mouse_dy < -2048)
  336.                mouse_dy = -2048;
  337.            else if (mouse_dy >  2048)
  338.                 mouse_dy =  2048;
  339.                kill_fasync(&mouse_fasyncptr, SIGIO, POLL_IN);
  340. }
  341. mouse_byte_count=0;
  342. /* printk("mouse: %d, %d, %xn",mouse_x,mouse_y,buttons); */
  343. }
  344. }
  345. }
  346. static void dn_keyb_int(int irq, void *dummy, struct pt_regs *fp) {
  347. unsigned char data;
  348.    unsigned long flags;
  349.    int scn2681_ints;
  350. do {
  351. scn2681_ints=sio01.isr_imr & 3;
  352. if(scn2681_ints & 2) {
  353. data=sio01.rhra_thra;
  354. #if 0
  355. if(debug_buf_count<4096) {
  356. debug_buf[debug_buf_count++]=data;
  357. debug_buffer_updated=jiffies;
  358. if(!debug_timer_running) {
  359. debug_keyb_timer.expires=jiffies+10;
  360. add_timer(&debug_keyb_timer);
  361. debug_timer_running=1;
  362. }
  363. }
  364. else
  365. debug_buf_overrun=1;
  366. #endif
  367. if(sio01.sra_csra & 0x10) {
  368. printk("whaa overrun !n");
  369. continue;
  370. }
  371. if(kbd_mode==APOLLO_KBD_MODE_KEYB)
  372. dn_keyb_process_key_event(data);
  373. else
  374. dn_keyb_process_mouse_event(data);
  375. }
  376. if(scn2681_ints & 1) {
  377. save_flags(flags);
  378. cli();
  379. if(keyb_cmd_write!=keyb_cmd_read) {
  380. sio01.rhra_thra=keyb_cmds[keyb_cmd_read++];
  381. if(keyb_cmd_read==APOLLO_KEYB_CMD_ENTRIES)
  382. keyb_cmd_read=0;
  383. keyb_cmd_transmit=1;
  384. }
  385. else {
  386. keyb_cmd_transmit=0;
  387. sio01.BRGtest_cra=9;
  388. }
  389. restore_flags(flags);
  390. }
  391. } while(scn2681_ints) ;
  392. }
  393. void write_keyb_cmd(u_short length, u_char *cmd) {
  394.    unsigned long flags;
  395. if((keyb_cmd_write==keyb_cmd_read) && keyb_cmd_transmit)
  396. return;
  397. save_flags(flags);
  398. cli();
  399. for(;length;length--) {
  400. keyb_cmds[keyb_cmd_write++]=*(cmd++);
  401. if(keyb_cmd_write==keyb_cmd_read)
  402. return;
  403. if(keyb_cmd_write==APOLLO_KEYB_CMD_ENTRIES)
  404. keyb_cmd_write=0;
  405. }
  406. if(!keyb_cmd_transmit)  {
  407.      sio01.BRGtest_cra=5;
  408. }
  409. restore_flags(flags);
  410. }
  411. static struct busmouse apollo_mouse = {
  412.         APOLLO_MOUSE_MINOR, "apollomouse", THIS_MODULE, NULL, NULL, 7
  413. };
  414. int __init dn_keyb_init(void){
  415. /*  printk("dn_keyb_initn"); */
  416.   memcpy(key_maps[0], dnplain_map, sizeof(plain_map));
  417.   memcpy(key_maps[1], dnshift_map, sizeof(plain_map));
  418.   memcpy(key_maps[2], dnaltgr_map, sizeof(plain_map));
  419.   memcpy(key_maps[4], dnctrl_map, sizeof(plain_map));
  420.   memcpy(key_maps[5], dnshift_ctrl_map, sizeof(plain_map));
  421.   memcpy(key_maps[8], dnalt_map, sizeof(plain_map));
  422.   memcpy(key_maps[12], dnctrl_alt_map, sizeof(plain_map));
  423.   msedev=register_busmouse(&apollo_mouse);
  424.   if (msedev < 0)
  425.       printk(KERN_WARNING "Unable to install Apollo mouse driver.n");
  426.    else
  427.       printk(KERN_INFO "Apollo mouse installed.n");
  428.   /* program UpDownMode */
  429.   while(!(sio01.sra_csra & 0x4));
  430.   sio01.rhra_thra=0xff;
  431.   while(!(sio01.sra_csra & 0x4));
  432.   sio01.rhra_thra=0x1;
  433.   request_irq(1, dn_keyb_int,0,NULL,NULL);
  434.   
  435.   /* enable receive int on DUART */
  436.   sio01.isr_imr=3;
  437.   return 0;
  438. }
  439. int dn_dummy_kbdrate(struct kbd_repeat *k) {
  440.   printk("dn_dummy_kbdraten");
  441.   return 0;
  442. }