lunaws.c revision 1.13.40.1 1 /* $NetBSD: lunaws.c,v 1.13.40.1 2008/06/02 13:22:21 mjf Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33
34 __KERNEL_RCSID(0, "$NetBSD: lunaws.c,v 1.13.40.1 2008/06/02 13:22:21 mjf Exp $");
35
36 #include "wsmouse.h"
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/conf.h>
41 #include <sys/device.h>
42
43 #include <dev/wscons/wsconsio.h>
44 #include <dev/wscons/wskbdvar.h>
45 #include <dev/wscons/wsksymdef.h>
46 #include <dev/wscons/wsksymvar.h>
47 #include <dev/wscons/wsmousevar.h>
48
49 #include <luna68k/dev/sioreg.h>
50 #include <luna68k/dev/siovar.h>
51
52 static const u_int8_t ch1_regs[6] = {
53 WR0_RSTINT, /* Reset E/S Interrupt */
54 WR1_RXALLS, /* Rx per char, No Tx */
55 0, /* */
56 WR3_RX8BIT | WR3_RXENBL, /* Rx */
57 WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY, /* Tx/Rx */
58 WR5_TX8BIT | WR5_TXENBL, /* Tx */
59 };
60
61 struct ws_softc {
62 struct device sc_dv;
63 struct sioreg *sc_ctl;
64 u_int8_t sc_wr[6];
65 struct device *sc_wskbddev;
66 #if NWSMOUSE > 0
67 struct device *sc_wsmousedev;
68 int sc_msreport;
69 int buttons, dx, dy;
70 #endif
71 };
72
73 static void omkbd_input __P((void *, int));
74 static int omkbd_decode __P((void *, int, u_int *, int *));
75 static int omkbd_enable __P((void *, int));
76 static void omkbd_set_leds __P((void *, int));
77 static int omkbd_ioctl __P((void *, u_long, void *, int, struct lwp *));
78
79 struct wscons_keydesc omkbd_keydesctab[];
80
81 static const struct wskbd_mapdata omkbd_keymapdata = {
82 omkbd_keydesctab,
83 KB_JP,
84 };
85 static const struct wskbd_accessops omkbd_accessops = {
86 omkbd_enable,
87 omkbd_set_leds,
88 omkbd_ioctl,
89 };
90
91 void ws_cnattach __P((void));
92 static void ws_cngetc __P((void *, u_int *, int *));
93 static void ws_cnpollc __P((void *, int));
94 static const struct wskbd_consops ws_consops = {
95 ws_cngetc,
96 ws_cnpollc,
97 };
98
99 #if NWSMOUSE > 0
100 static int omms_enable __P((void *));
101 static int omms_ioctl __P((void *, u_long, void *, int, struct lwp *));
102 static void omms_disable __P((void *));
103
104 static const struct wsmouse_accessops omms_accessops = {
105 omms_enable,
106 omms_ioctl,
107 omms_disable,
108 };
109 #endif
110
111 static void wsintr __P((int));
112
113 static int wsmatch __P((struct device *, struct cfdata *, void *));
114 static void wsattach __P((struct device *, struct device *, void *));
115
116 CFATTACH_DECL(ws, sizeof(struct ws_softc),
117 wsmatch, wsattach, NULL, NULL);
118 extern struct cfdriver ws_cd;
119
120 extern int syscngetc __P((dev_t));
121 extern void syscnputc __P((dev_t, int));
122
123 static int
124 wsmatch(parent, match, aux)
125 struct device *parent;
126 struct cfdata *match;
127 void *aux;
128 {
129 struct sio_attach_args *args = aux;
130
131 if (args->channel != 1)
132 return 0;
133 return 1;
134 }
135
136 static void
137 wsattach(parent, self, aux)
138 struct device *parent;
139 struct device *self;
140 void *aux;
141 {
142 struct ws_softc *sc = (struct ws_softc *)self;
143 struct sio_softc *scp = (struct sio_softc *)parent;
144 struct sio_attach_args *args = aux;
145 struct wskbddev_attach_args a;
146
147 sc->sc_ctl = (struct sioreg *)scp->scp_ctl + 1;
148 bcopy(ch1_regs, sc->sc_wr, sizeof(ch1_regs));
149 scp->scp_intr[1] = wsintr;
150
151 setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
152 setsioreg(sc->sc_ctl, WR4, sc->sc_wr[WR4]);
153 setsioreg(sc->sc_ctl, WR3, sc->sc_wr[WR3]);
154 setsioreg(sc->sc_ctl, WR5, sc->sc_wr[WR5]);
155 setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
156 setsioreg(sc->sc_ctl, WR1, sc->sc_wr[WR1]);
157
158 syscnputc((dev_t)1, 0x20); /* keep quiet mouse */
159
160 printf("\n");
161
162 a.console = (args->hwflags == 1);
163 a.keymap = &omkbd_keymapdata;
164 a.accessops = &omkbd_accessops;
165 a.accesscookie = (void *)sc;
166 sc->sc_wskbddev = config_found_ia(self, "wskbddev", &a,
167 wskbddevprint);
168
169 #if NWSMOUSE > 0
170 {
171 struct wsmousedev_attach_args b;
172 b.accessops = &omms_accessops;
173 b.accesscookie = (void *)sc;
174 sc->sc_wsmousedev = config_found_ia(self, "wsmousedev", &b,
175 wsmousedevprint);
176 sc->sc_msreport = 0;
177 }
178 #endif
179 }
180
181 /*ARGSUSED*/
182 static void
183 wsintr(chan)
184 int chan;
185 {
186 struct ws_softc *sc = ws_cd.cd_devs[0];
187 struct sioreg *sio = sc->sc_ctl;
188 u_int code;
189 int rr;
190
191 rr = getsiocsr(sio);
192 if (rr & RR_RXRDY) {
193 do {
194 code = sio->sio_data;
195 if (rr & (RR_FRAMING | RR_OVERRUN | RR_PARITY)) {
196 sio->sio_cmd = WR0_ERRRST;
197 continue;
198 }
199 #if NWSMOUSE > 0
200 /*
201 * if (code >= 0x80 && code <= 0x87), then
202 * it's the first byte of 3 byte long mouse report
203 * code[0] & 07 -> LMR button condition
204 * code[1], [2] -> x,y delta
205 * otherwise, key press or release event.
206 */
207 if (sc->sc_msreport == 0) {
208 if (code < 0x80 || code > 0x87) {
209 omkbd_input(sc, code);
210 continue;
211 }
212 code = (code & 07) ^ 07;
213 /* LMR->RML: wsevent counts 0 for leftmost */
214 sc->buttons = (code & 02);
215 if (code & 01)
216 sc->buttons |= 04;
217 if (code & 04)
218 sc->buttons |= 01;
219 sc->sc_msreport = 1;
220 }
221 else if (sc->sc_msreport == 1) {
222 sc->dx = (signed char)code;
223 sc->sc_msreport = 2;
224 }
225 else if (sc->sc_msreport == 2) {
226 sc->dy = (signed char)code;
227 wsmouse_input(sc->sc_wsmousedev,
228 sc->buttons,
229 sc->dx, sc->dy, 0, 0,
230 WSMOUSE_INPUT_DELTA);
231
232 sc->sc_msreport = 0;
233 }
234 #else
235 omkbd_input(sc, code);
236 #endif
237 } while ((rr = getsiocsr(sio)) & RR_RXRDY);
238 }
239 if (rr && RR_TXRDY)
240 sio->sio_cmd = WR0_RSTPEND;
241 /* not capable of transmit, yet */
242 }
243
244 static void
245 omkbd_input(v, data)
246 void *v;
247 int data;
248 {
249 struct ws_softc *sc = v;
250 u_int type;
251 int key;
252
253 if (omkbd_decode(v, data, &type, &key))
254 wskbd_input(sc->sc_wskbddev, type, key);
255 }
256
257 static int
258 omkbd_decode(v, datain, type, dataout)
259 void *v;
260 int datain;
261 u_int *type;
262 int *dataout;
263 {
264 *type = (datain & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
265 *dataout = datain & 0x7f;
266 return 1;
267 }
268
269 #define KC(n) KS_KEYCODE(n)
270
271 static const keysym_t omkbd_keydesc_1[] = {
272 /* pos command normal shifted */
273 KC(0x9), KS_Tab,
274 KC(0xa), KS_Control_L,
275 KC(0xb), KS_Mode_switch, /* Kana */
276 KC(0xc), KS_Shift_R,
277 KC(0xd), KS_Shift_L,
278 KC(0xe), KS_Caps_Lock,
279 KC(0xf), KS_Meta_L, /* Zenmen */
280 KC(0x10), KS_Escape,
281 KC(0x11), KS_BackSpace,
282 KC(0x12), KS_Return,
283 KC(0x14), KS_space,
284 KC(0x15), KS_Delete,
285 KC(0x16), KS_Alt_L, /* Henkan */
286 KC(0x17), KS_Alt_R, /* Kakutei */
287 KC(0x18), KS_f11, /* Shokyo */
288 KC(0x19), KS_f12, /* Yobidashi */
289 KC(0x1a), KS_f13, /* Bunsetsu L */
290 KC(0x1b), KS_f14, /* Bunsetsu R */
291 KC(0x1c), KS_KP_Up,
292 KC(0x1d), KS_KP_Left,
293 KC(0x1e), KS_KP_Right,
294 KC(0x1f), KS_KP_Down,
295 /* KC(0x20), KS_f11, */
296 /* KC(0x21), KS_f12, */
297 KC(0x22), KS_1, KS_exclam,
298 KC(0x23), KS_2, KS_quotedbl,
299 KC(0x24), KS_3, KS_numbersign,
300 KC(0x25), KS_4, KS_dollar,
301 KC(0x26), KS_5, KS_percent,
302 KC(0x27), KS_6, KS_ampersand,
303 KC(0x28), KS_7, KS_apostrophe,
304 KC(0x29), KS_8, KS_parenleft,
305 KC(0x2a), KS_9, KS_parenright,
306 KC(0x2b), KS_0,
307 KC(0x2c), KS_minus, KS_equal,
308 KC(0x2d), KS_asciicircum, KS_asciitilde,
309 KC(0x2e), KS_backslash, KS_bar,
310 /* KC(0x30), KS_f13, */
311 /* KC(0x31), KS_f14, */
312 KC(0x32), KS_q,
313 KC(0x33), KS_w,
314 KC(0x34), KS_e,
315 KC(0x35), KS_r,
316 KC(0x36), KS_t,
317 KC(0x37), KS_y,
318 KC(0x38), KS_u,
319 KC(0x39), KS_i,
320 KC(0x3a), KS_o,
321 KC(0x3b), KS_p,
322 KC(0x3c), KS_at, KS_grave,
323 KC(0x3d), KS_bracketleft, KS_braceleft,
324 KC(0x42), KS_a,
325 KC(0x43), KS_s,
326 KC(0x44), KS_d,
327 KC(0x45), KS_f,
328 KC(0x46), KS_g,
329 KC(0x47), KS_h,
330 KC(0x48), KS_j,
331 KC(0x49), KS_k,
332 KC(0x4a), KS_l,
333 KC(0x4b), KS_semicolon, KS_plus,
334 KC(0x4c), KS_colon, KS_asterisk,
335 KC(0x4d), KS_bracketright, KS_braceright,
336 KC(0x52), KS_z,
337 KC(0x53), KS_x,
338 KC(0x54), KS_c,
339 KC(0x55), KS_v,
340 KC(0x56), KS_b,
341 KC(0x57), KS_n,
342 KC(0x58), KS_m,
343 KC(0x59), KS_comma, KS_less,
344 KC(0x5a), KS_period, KS_greater,
345 KC(0x5b), KS_slash, KS_question,
346 KC(0x5c), KS_underscore,
347 KC(0x60), KS_KP_Delete,
348 KC(0x61), KS_KP_Add,
349 KC(0x62), KS_KP_Subtract,
350 KC(0x63), KS_KP_7,
351 KC(0x64), KS_KP_8,
352 KC(0x65), KS_KP_9,
353 KC(0x66), KS_KP_4,
354 KC(0x67), KS_KP_5,
355 KC(0x68), KS_KP_6,
356 KC(0x69), KS_KP_1,
357 KC(0x6a), KS_KP_2,
358 KC(0x6b), KS_KP_3,
359 KC(0x6c), KS_KP_0,
360 KC(0x6d), KS_KP_Decimal,
361 KC(0x6e), KS_KP_Enter,
362 KC(0x72), KS_f1,
363 KC(0x73), KS_f2,
364 KC(0x74), KS_f3,
365 KC(0x75), KS_f4,
366 KC(0x76), KS_f5,
367 KC(0x77), KS_f6,
368 KC(0x78), KS_f7,
369 KC(0x79), KS_f8,
370 KC(0x7a), KS_f9,
371 KC(0x7b), KS_f10,
372 KC(0x7c), KS_KP_Multiply,
373 KC(0x7d), KS_KP_Divide,
374 KC(0x7e), KS_KP_Equal,
375 KC(0x7f), KS_KP_Separator,
376 };
377
378 #define SIZE(map) (sizeof(map)/sizeof(keysym_t))
379
380 struct wscons_keydesc omkbd_keydesctab[] = {
381 { KB_JP, 0, SIZE(omkbd_keydesc_1), omkbd_keydesc_1, },
382 { 0, 0, 0, 0 },
383 };
384
385 static void
386 ws_cngetc(v, type, data)
387 void *v;
388 u_int *type;
389 int *data;
390 {
391 int code;
392
393 do {
394 code = syscngetc((dev_t)1);
395 } while (!omkbd_decode(v, code, type, data));
396 }
397
398 static void
399 ws_cnpollc(v, on)
400 void *v;
401 int on;
402 {
403 }
404
405 /* EXPORT */ void
406 ws_cnattach()
407 {
408 static int voidfill;
409
410 /* XXX need CH.B initialization XXX */
411
412 wskbd_cnattach(&ws_consops, &voidfill, &omkbd_keymapdata);
413 }
414
415 static int
416 omkbd_enable(v, on)
417 void *v;
418 int on;
419 {
420 return 0;
421 }
422
423 static void
424 omkbd_set_leds(v, leds)
425 void *v;
426 int leds;
427 {
428 #if 0
429 syscnputc((dev_t)1, 0x10); /* kana LED on */
430 syscnputc((dev_t)1, 0x00); /* kana LED off */
431 syscnputc((dev_t)1, 0x11); /* caps LED on */
432 syscnputc((dev_t)1, 0x01); /* caps LED off */
433 #endif
434 }
435
436 static int
437 omkbd_ioctl(v, cmd, data, flag, l)
438 void *v;
439 u_long cmd;
440 void *data;
441 int flag;
442 struct lwp *l;
443 {
444 switch (cmd) {
445 case WSKBDIO_GTYPE:
446 *(int *)data = 0x19991005 /* XXX */;
447 return 0;
448 case WSKBDIO_SETLEDS:
449 case WSKBDIO_GETLEDS:
450 case WSKBDIO_COMPLEXBELL: /* XXX capable of complex bell */
451 return 0;
452 }
453 return EPASSTHROUGH;
454 }
455
456 #if NWSMOUSE > 0
457
458 static int
459 omms_enable(v)
460 void *v;
461 {
462 struct ws_softc *sc = v;
463
464 syscnputc((dev_t)1, 0x60); /* enable 3 byte long mouse reporting */
465 sc->sc_msreport = 0;
466 return 0;
467 }
468
469 /*ARGUSED*/
470 static int
471 omms_ioctl(v, cmd, data, flag, l)
472 void *v;
473 u_long cmd;
474 void *data;
475 int flag;
476 struct lwp *l;
477 {
478 if (cmd == WSMOUSEIO_GTYPE) {
479 *(u_int *)data = 0x19991005; /* XXX */
480 return 0;
481 }
482 return EPASSTHROUGH;
483 }
484
485 static void
486 omms_disable(v)
487 void *v;
488 {
489 struct ws_softc *sc = v;
490
491 syscnputc((dev_t)1, 0x20); /* quiet mouse */
492 sc->sc_msreport = 0;
493 }
494 #endif
495