Linux 2.3.7pre1
[davej-history.git] / drivers / char / dn_keyb.c
blob29e9f7f81f417d7d0dfdeb9be1b03b24c1fc770e
1 #include <linux/types.h>
2 #include <linux/sched.h>
3 #include <linux/interrupt.h>
4 #include <linux/errno.h>
5 #include <linux/keyboard.h>
6 #include <linux/delay.h>
7 #include <linux/timer.h>
8 #include <linux/kd.h>
9 #include <linux/random.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/poll.h>
13 #include <linux/miscdevice.h>
14 #include <linux/init.h>
16 #include <asm/setup.h>
17 #include <asm/irq.h>
18 #include <asm/apollohw.h>
19 #include <asm/uaccess.h>
22 extern void handle_scancode(unsigned char);
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
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
40 #define MSE_UPDATE_ON() mouse_update_allowed=1
41 #define MSE_UPDATE_OFF() mouse_update_allowed=0
43 static u_char keyb_cmds[APOLLO_KEYB_CMD_ENTRIES];
44 static short keyb_cmd_read=0, keyb_cmd_write=0;
45 static int keyb_cmd_transmit=0;
47 static unsigned int kbd_mode=APOLLO_KBD_MODE_KEYB;
48 static short mouse_dx,mouse_dy,mouse_buttons;
49 static int mouse_ready=0,mouse_update_allowed=0,mouse_active=0;
50 static DECLARE_WAIT_QUEUE_HEAD(mouse_wait);
51 static struct fasync_struct *mouse_fasyncptr=NULL;
53 #if 0
54 static void debug_keyb_timer_handler(unsigned long ignored);
55 static u_char debug_buf1[4096],debug_buf2[4096],*debug_buf=&debug_buf1[0];
56 static u_char *shadow_buf=&debug_buf2[0];
57 static short debug_buf_count=0;
58 static int debug_buf_overrun=0,debug_timer_running=0,debug_buffer_updated=0;
59 static struct timer_list debug_keyb_timer = { NULL, NULL, 0, 0,
60 debug_keyb_timer_handler };
61 #endif
63 static u_short dnplain_map[NR_KEYS] __initdata = {
64 /* ins del del F1 F2 F3 F4
65 mark line char */
66 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
67 /* F5 F6 F7 F8 F9 F0 Again Read */
68 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
69 /* Edit Exit Hold Copy Paste Grow ESC */
70 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b,
71 /* 1 2 3 4 5 6 7 8 */
72 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036, 0xf037, 0xf038,
73 /* 9 0 - = ` Back |<--
74 Space */
75 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf060, 0xf07f, 0xf200, 0xf200,
76 /* Shell -->| Tab q w e
77 Cmd */
78 0xf200, 0xf200, 0xf200, 0xf200, 0xf009, 0xfb71, 0xfb77, 0xfb65,
79 /* r t y u i o p [ */
80 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69, 0xfb6f, 0xfb70, 0xf05b,
81 /* ] Del 7 8 9 + */
82 0xf05d, 0xf200, 0xf200, 0xf200, 0xf307, 0xf308, 0xf300, 0xf30a,
83 /* [<--] Up [-->] Ctrl a s */
84 0xf200, 0xf600, 0xf200, 0xf702, 0xf200, 0xf200, 0xfb61, 0xfb73,
85 /* d f g h j k l ; */
86 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
87 /* ' Return \ 4 5 6 */
88 0xf027, 0xf200, 0xf201, 0xf05c, 0xf200, 0xf304, 0xf305, 0xf306,
89 /* - <-- Next --> Rept Shift
90 Window */
91 0xf30b, 0xf601, 0xf200, 0xf602, 0xf200, 0xf200, 0xf700, 0xf200,
92 /* z x c v b n m , */
93 0xfb7a, 0xfb78, 0xfb63, 0xfb76, 0xfb62, 0xfb6e, 0xfb6d, 0xf02c,
94 /* . / Shift Pop 1 2 */
95 0xf02e, 0xf02f, 0xf700, 0xf200, 0xf200, 0xf200, 0xf301, 0xf302,
96 /* 3 PgUp Down PgDn Alt Space Alt */
97 0xf303, 0xf200, 0xf118, 0xf603, 0xf119, 0xf703, 0xf020, 0xf701,
98 /* 0 . Enter */
99 0xf200, 0xf300, 0xf200, 0xf310, 0xf30e, 0xf200, 0xf700, 0xf200,
102 static u_short dnshift_map[NR_KEYS] __initdata = {
103 /* ins del del F1 F2 F3 F4
104 mark line char */
105 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
106 /* F5 F6 F7 F8 F9 F0 Again Read */
107 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
108 /* Save Abort Help Cut Undo Grow ESC */
109 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b,
110 /* ! @ # $ % ^ & * */
111 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e, 0xf026, 0xf02a,
112 /* ( ) _ + ~ Back |<--
113 Space */
114 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07e, 0xf07f, 0xf200, 0xf200,
115 /* Shell -->| Tab Q W E
116 Cmd */
117 0xf200, 0xf200, 0xf200, 0xf200, 0xf009, 0xfb51, 0xfb57, 0xfb45,
118 /* R T Y U I O P { */
119 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49, 0xfb4f, 0xfb50, 0xf07b,
120 /* } Del 7 8 9 + */
121 0xf07d, 0xf200, 0xf200, 0xf200, 0xf307, 0xf308, 0xf300, 0xf30a,
122 /* [<--] Up [-->] Ctrl A S */
123 0xf200, 0xf600, 0xf200, 0xf702, 0xf200, 0xf200, 0xfb41, 0xfb53,
124 /* D F G H J K L : */
125 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
126 /* " Return | 4 5 6 */
127 0xf022, 0xf200, 0xf201, 0xf07c, 0xf200, 0xf304, 0xf305, 0xf306,
128 /* - <-- Next --> Rept Shift
129 Window */
130 0xf30b, 0xf601, 0xf200, 0xf602, 0xf200, 0xf200, 0xf700, 0xf200,
131 /* Z X C V B N M < */
132 0xfb5a, 0xfb58, 0xfb43, 0xfb56, 0xfb42, 0xfb4e, 0xfb4d, 0xf03c,
133 /* > ? Shift Pop 1 2 */
134 0xf03e, 0xf03f, 0xf700, 0xf200, 0xf200, 0xf200, 0xf301, 0xf302,
135 /* 3 PgUp Down PgDn Alt Space Alt */
136 0xf303, 0xf200, 0xf118, 0xf603, 0xf119, 0xf703, 0xf020, 0xf701,
137 /* 0 . Enter */
138 0xf200, 0xf300, 0xf200, 0xf310, 0xf30e, 0xf200, 0xf708, 0xf200,
141 static u_short dnctrl_map[NR_KEYS] __initdata = {
142 /* ins del del F1 F2 F3 F4
143 mark line char */
144 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
145 /* F5 F6 F7 F8 F9 F0 Again Read */
146 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
147 /* Save Abort Help Cut Undo Grow ESC */
148 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b,
149 /* ! @ # $ % ^ & * */
150 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01d, 0xf01e, 0xf01f, 0xf07f,
151 /* ( ) _ + ~ Back |<--
152 Space */
153 0xf200, 0xf200, 0xf01f, 0xf200, 0xf01c, 0xf200, 0xf200, 0xf200,
154 /* Shell -->| Tab Q W E
155 Cmd */
156 0xf200, 0xf200, 0xf200, 0xf200, 0xf009, 0xf011, 0xf017, 0xf005,
157 /* R T Y U I O P { */
158 0xf012, 0xf014, 0xf019, 0xf015, 0xf009, 0xf00f, 0xf010, 0xf01b,
159 /* } Del 7 8 9 + */
160 0xf01d, 0xf200, 0xf200, 0xf200, 0xf307, 0xf308, 0xf300, 0xf30a,
161 /* [<--] Up [-->] Ctrl A S */
162 0xf200, 0xf600, 0xf200, 0xf702, 0xf200, 0xf200, 0xfb01, 0xfb53,
163 /* D F G H J K L : */
164 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
165 /* " Return | 4 5 6 */
166 0xf200, 0xf200, 0xf201, 0xf01c, 0xf200, 0xf304, 0xf305, 0xf306,
167 /* - <-- Next --> Rept Shift
168 Window */
169 0xf30b, 0xf601, 0xf200, 0xf602, 0xf200, 0xf200, 0xf704, 0xf200,
170 /* Z X C V B N M < */
171 0xf01a, 0xf018, 0xf003, 0xf016, 0xf002, 0xf00e, 0xf01d, 0xf03c,
172 /* > ? Shift Pop 1 2 */
173 0xf03e, 0xf03f, 0xf705, 0xf200, 0xf200, 0xf200, 0xf301, 0xf302,
174 /* 3 PgUp Down PgDn Alt Space Alt */
175 0xf303, 0xf200, 0xf118, 0xf603, 0xf119, 0xf703, 0xf020, 0xf701,
176 /* 0 . Enter */
177 0xf200, 0xf300, 0xf200, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200,
180 static u_short dnalt_map[NR_KEYS] __initdata = {
181 /* ins del del F1 F2 F3 F4
182 mark line char */
183 0xf200, 0xf200, 0xf200, 0xf200, 0xf500, 0xf501, 0xf502, 0xf503,
184 /* F5 F6 F7 F8 F9 F0 Again Read */
185 0xf504, 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf200, 0xf200,
186 /* Edit Exit Hold Copy Paste Grow ESC */
187 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf01b,
188 /* 1 2 3 4 5 6 7 8 */
189 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836, 0xf837, 0xf838,
190 /* 9 0 - = ` Back |<--
191 Space */
192 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf860, 0xf87f, 0xf200, 0xf200,
193 /* Shell -->| Tab q w e
194 Cmd */
195 0xf200, 0xf200, 0xf200, 0xf200, 0xf809, 0xf871, 0xf877, 0xf865,
196 /* r t y u i o p [ */
197 0xf872, 0xf874, 0xf879, 0xf875, 0xf869, 0xf86f, 0xf870, 0xf85b,
198 /* ] Del 7 8 9 + */
199 0xf05d, 0xf200, 0xf200, 0xf200, 0xf307, 0xf308, 0xf300, 0xf30a,
200 /* [<--] Up [-->] Ctrl a s */
201 0xf200, 0xf600, 0xf200, 0xf702, 0xf200, 0xf200, 0xf861, 0xf873,
202 /* d f g h j k l ; */
203 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf03b,
204 /* ' Return \ 4 5 6 */
205 0xf027, 0xf200, 0xf201, 0xf05c, 0xf200, 0xf304, 0xf305, 0xf306,
206 /* - <-- Next --> Rept Shift
207 Window */
208 0xf30b, 0xf601, 0xf200, 0xf602, 0xf200, 0xf200, 0xf704, 0xf200,
209 /* z x c v b n m , */
210 0xf87a, 0xf878, 0xf863, 0xf876, 0xf862, 0xf86e, 0xf86d, 0xf82c,
211 /* . / Shift Pop 1 2 */
212 0xf82e, 0xf82f, 0xf705, 0xf200, 0xf200, 0xf200, 0xf301, 0xf302,
213 /* 3 PgUp Down PgDn Alt Space Alt */
214 0xf303, 0xf200, 0xf118, 0xf603, 0xf119, 0xf703, 0xf820, 0xf701,
215 /* 0 . Enter */
216 0xf200, 0xf300, 0xf200, 0xf310, 0xf30e, 0xf200, 0xf200, 0xf200,
219 static u_short dnaltgr_map[NR_KEYS] __initdata = {
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 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
238 static u_short dnshift_ctrl_map[NR_KEYS] __initdata = {
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 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
254 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
257 static u_short dnctrl_alt_map[NR_KEYS] __initdata = {
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 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
269 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
270 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
271 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
272 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
273 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200
276 #if 0
277 static void debug_keyb_timer_handler(unsigned long ignored) {
279 unsigned long flags;
280 u_char *swap;
281 short length,i;
283 if((jiffies-debug_buffer_updated) > 100) {
284 save_flags(flags);
285 cli();
286 length=debug_buf_count;
287 swap=debug_buf;
288 debug_buf=shadow_buf;
289 shadow_buf=swap;
290 debug_buf_count=0;
291 debug_timer_running=0;
292 restore_flags(flags);
293 for(i=1;length;length--,i++)
294 printk("%02x%c",*(swap++), (i % 25) ? ' ' : '\n');
295 printk("\n");
297 else {
298 debug_keyb_timer.expires=jiffies+10;
299 add_timer(&debug_keyb_timer);
302 #endif
304 static unsigned int mouse_poll(struct file *file, poll_table * wait)
306 poll_wait(&mouse_wait, wait);
307 if (mouse_ready)
308 return POLLIN | POLLRDNORM;
309 return 0;
312 static ssize_t write_mouse(struct file * file, const char * buffer,
313 size_t count, loff_t *ppos)
315 return -EINVAL;
318 static ssize_t read_mouse(struct file * file, char * buffer,
319 size_t count, loff_t *ppos)
321 int dx,dy,r;
322 unsigned char buttons;
324 if (count < 3)
325 return -EINVAL;
326 if ((r = verify_area(VERIFY_WRITE, buffer, count)))
327 return r;
328 if (!mouse_ready)
329 return -EAGAIN;
331 MSE_UPDATE_OFF();
332 dx=mouse_dx;
333 dy=mouse_dy;
334 if (dx < -127)
335 dx = -127;
336 else
337 if (dx > 127)
338 dx = 127;
339 if (dy < -127)
340 dy = -127;
341 else
342 if (dy > 127)
343 dy = 127;
344 buttons=(mouse_buttons & 1 ? 4 : 0) |
345 (mouse_buttons & 2 ? 1 : 0) |
346 (mouse_buttons & 4 ? 2 : 0);
348 mouse_dx-=dx;
349 mouse_dy-=dy;
350 MSE_UPDATE_ON();
352 if (put_user(buttons | 0x80, buffer++) ||
353 put_user((char)dx, buffer++) ||
354 put_user((char)dy, buffer++))
355 return -EINVAL;
357 if (count > 3)
358 if (clear_user(buffer, count - 3))
359 return -EFAULT;
360 return count;
363 static int fasync_mouse(int fd, struct file *filp, int on)
365 int retval;
367 retval = fasync_helper(fd, filp, on, &mouse_fasyncptr);
368 if (retval < 0)
369 return retval;
370 return 0;
374 static int release_mouse(struct inode * inode, struct file * file)
376 fasync_mouse(-1, file, 0);
377 if (--mouse_active)
378 return 0;
379 MSE_UPDATE_OFF();
380 MOD_DEC_USE_COUNT;
381 return 0;
384 static int open_mouse(struct inode * inode, struct file * file)
386 if (mouse_active++)
387 return 0;
389 * use VBL to poll mouse deltas
392 mouse_dx = 0;
393 mouse_dy = 0;
394 mouse_buttons = 0;
395 mouse_active = 1;
396 MOD_INC_USE_COUNT;
397 MSE_UPDATE_ON();
398 return 0;
401 static void dn_keyb_process_key_event(unsigned char scancode) {
403 static unsigned char lastscancode;
404 unsigned char prev_scancode=lastscancode;
405 static unsigned int lastkeypress;
407 lastscancode=scancode;
409 /* printk("scan: %02x, lastscan: %02X, prev_scancode: %02X\n",scancode,lastscancode,prev_scancode); */
411 if(prev_scancode==APOLLO_KBD_MODE_CHANGE) {
412 kbd_mode=scancode;
413 /* printk("modechange: %d\n",scancode);*/
415 else if((scancode & (~BREAK_FLAG)) == DNKEY_CAPS) {
416 /* printk("handle_scancode: %02x\n",DNKEY_CAPS); */
417 handle_scancode(DNKEY_CAPS, 1);
418 /* printk("handle_scancode: %02x\n",BREAK_FLAG | DNKEY_CAPS); */
419 handle_scancode(DNKEY_CAPS, 0);
421 else if( (scancode == DNKEY_REPEAT) && (prev_scancode < 0x7e) &&
422 !(prev_scancode==DNKEY_CTRL || prev_scancode==DNKEY_LSHIFT ||
423 prev_scancode==DNKEY_RSHIFT || prev_scancode==DNKEY_REPT ||
424 prev_scancode==DNKEY_LALT || prev_scancode==DNKEY_RALT)) {
425 if(jiffies-lastkeypress > DNKEY_REPEAT_DELAY) {
426 /* printk("handle_scancode: %02x\n",prev_scancode); */
427 handle_scancode(prev_scancode, 1);
429 lastscancode=prev_scancode;
431 else {
432 /* printk("handle_scancode: %02x\n",scancode); */
433 handle_scancode(scancode & ~BREAK_FLAG, !(scancode & BREAK_FLAG));
434 lastkeypress=jiffies;
438 static void dn_keyb_process_mouse_event(unsigned char mouse_data) {
440 static short mouse_byte_count=0;
441 static u_char mouse_packet[3];
443 mouse_packet[mouse_byte_count++]=mouse_data;
445 if(mouse_byte_count==3) {
446 if(mouse_packet[0]==APOLLO_KBD_MODE_CHANGE) {
447 kbd_mode=mouse_packet[1];
448 mouse_byte_count=0;
449 /* printk("modechange: %d\n",mouse_packet[1]); */
450 if(kbd_mode==APOLLO_KBD_MODE_KEYB)
451 dn_keyb_process_key_event(mouse_packet[2]);
453 if((mouse_packet[0] & 0x8f) == 0x80) {
454 if(mouse_update_allowed) {
455 mouse_ready=1;
456 mouse_buttons=(mouse_packet[0] >> 4) & 0x7;
457 mouse_dx+=mouse_packet[1] == 0xff ? 0 : (signed char)mouse_packet[1];
458 mouse_dy+=mouse_packet[2] == 0xff ? 0 : (signed char)mouse_packet[2];
459 wake_up_interruptible(&mouse_wait);
460 if (mouse_dx < -2048)
461 mouse_dx = -2048;
462 else
463 if (mouse_dx > 2048)
464 mouse_dx = 2048;
465 if (mouse_dy < -2048)
466 mouse_dy = -2048;
467 else
468 if (mouse_dy > 2048)
469 mouse_dy = 2048;
470 if (mouse_fasyncptr)
471 kill_fasync(mouse_fasyncptr, SIGIO);
473 mouse_byte_count=0;
474 /* printk("mouse: %d, %d, %x\n",mouse_x,mouse_y,buttons); */
479 static void dn_keyb_int(int irq, void *dummy, struct pt_regs *fp) {
481 unsigned char data;
482 unsigned long flags;
483 int scn2681_ints;
485 do {
486 scn2681_ints=sio01.isr_imr & 3;
487 if(scn2681_ints & 2) {
488 data=sio01.rhra_thra;
489 #if 0
490 if(debug_buf_count<4096) {
491 debug_buf[debug_buf_count++]=data;
492 debug_buffer_updated=jiffies;
493 if(!debug_timer_running) {
494 add_timer(&debug_keyb_timer);
495 debug_keyb_timer.expires=jiffies+10;
496 debug_timer_running=1;
499 else
500 debug_buf_overrun=1;
501 #endif
502 if(sio01.sra_csra & 0x10) {
503 printk("whaa overrun !\n");
504 continue;
507 if(kbd_mode==APOLLO_KBD_MODE_KEYB)
508 dn_keyb_process_key_event(data);
509 else
510 dn_keyb_process_mouse_event(data);
513 if(scn2681_ints & 1) {
514 save_flags(flags);
515 cli();
516 if(keyb_cmd_write!=keyb_cmd_read) {
517 sio01.rhra_thra=keyb_cmds[keyb_cmd_read++];
518 if(keyb_cmd_read==APOLLO_KEYB_CMD_ENTRIES)
519 keyb_cmd_read=0;
520 keyb_cmd_transmit=1;
522 else {
523 keyb_cmd_transmit=0;
524 sio01.BRGtest_cra=9;
526 restore_flags(flags);
528 } while(scn2681_ints) ;
531 void write_keyb_cmd(u_short length, u_char *cmd) {
533 unsigned long flags;
535 if((keyb_cmd_write==keyb_cmd_read) && keyb_cmd_transmit)
536 return;
538 save_flags(flags);
539 cli();
540 for(;length;length--) {
541 keyb_cmds[keyb_cmd_write++]=*(cmd++);
542 if(keyb_cmd_write==keyb_cmd_read)
543 return;
544 if(keyb_cmd_write==APOLLO_KEYB_CMD_ENTRIES)
545 keyb_cmd_write=0;
547 if(!keyb_cmd_transmit) {
548 sio01.BRGtest_cra=5;
550 restore_flags(flags);
554 struct file_operations apollo_mouse_fops = {
555 NULL, /* mouse_seek */
556 read_mouse,
557 write_mouse,
558 NULL, /* mouse_readdir */
559 mouse_poll, /* mouse_poll */
560 NULL, /* mouse_ioctl */
561 NULL, /* mouse_mmap */
562 open_mouse,
563 NULL, /* flush */
564 release_mouse,
565 NULL,
566 fasync_mouse,
569 static struct miscdevice apollo_mouse = {
570 APOLLO_MOUSE_MINOR, "apollomouse", &apollo_mouse_fops
573 __initfunc(int dn_keyb_init(void)) {
575 /* printk("dn_keyb_init\n"); */
577 memcpy(key_maps[0], dnplain_map, sizeof(plain_map));
578 memcpy(key_maps[1], dnshift_map, sizeof(plain_map));
579 memcpy(key_maps[2], dnaltgr_map, sizeof(plain_map));
580 memcpy(key_maps[4], dnctrl_map, sizeof(plain_map));
581 memcpy(key_maps[5], dnshift_ctrl_map, sizeof(plain_map));
582 memcpy(key_maps[8], dnalt_map, sizeof(plain_map));
583 memcpy(key_maps[12], dnctrl_alt_map, sizeof(plain_map));
585 mouse_dx=0;
586 mouse_dy=0;
587 mouse_buttons=0;
588 mouse_wait=NULL;
590 misc_register(&apollo_mouse);
592 /* program UpDownMode */
594 while(!(sio01.sra_csra & 0x4));
595 sio01.rhra_thra=0xff;
597 while(!(sio01.sra_csra & 0x4));
598 sio01.rhra_thra=0x1;
600 request_irq(1, dn_keyb_int,0,NULL,NULL);
602 /* enable receive int on DUART */
603 sio01.isr_imr=3;
605 return 0;
609 int dn_dummy_kbdrate(struct kbd_repeat *k) {
611 printk("dn_dummy_kbdrate\n");
613 return 0;