File: /usr/src/linux/drivers/char/dn_keyb.c

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