lunaws.c revision 1.15 1 /* $NetBSD: lunaws.c,v 1.15 2008/06/13 09:58:06 cegger 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.15 2008/06/13 09:58:06 cegger 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(int chan)
184 {
185 struct ws_softc *sc = device_lookup_private(&ws_cd, 0);
186 struct sioreg *sio = sc->sc_ctl;
187 u_int code;
188 int rr;
189
190 rr = getsiocsr(sio);
191 if (rr & RR_RXRDY) {
192 do {
193 code = sio->sio_data;
194 if (rr & (RR_FRAMING | RR_OVERRUN | RR_PARITY)) {
195 sio->sio_cmd = WR0_ERRRST;
196 continue;
197 }
198 #if NWSMOUSE > 0
199 /*
200 * if (code >= 0x80 && code <= 0x87), then
201 * it's the first byte of 3 byte long mouse report
202 * code[0] & 07 -> LMR button condition
203 * code[1], [2] -> x,y delta
204 * otherwise, key press or release event.
205 */
206 if (sc->sc_msreport == 0) {
207 if (code < 0x80 || code > 0x87) {
208 omkbd_input(sc, code);
209 continue;
210 }
211 code = (code & 07) ^ 07;
212 /* LMR->RML: wsevent counts 0 for leftmost */
213 sc->buttons = (code & 02);
214 if (code & 01)
215 sc->buttons |= 04;
216 if (code & 04)
217 sc->buttons |= 01;
218 sc->sc_msreport = 1;
219 }
220 else if (sc->sc_msreport == 1) {
221 sc->dx = (signed char)code;
222 sc->sc_msreport = 2;
223 }
224 else if (sc->sc_msreport == 2) {
225 sc->dy = (signed char)code;
226 wsmouse_input(sc->sc_wsmousedev,
227 sc->buttons,
228 sc->dx, sc->dy, 0, 0,
229 WSMOUSE_INPUT_DELTA);
230
231 sc->sc_msreport = 0;
232 }
233 #else
234 omkbd_input(sc, code);
235 #endif
236 } while ((rr = getsiocsr(sio)) & RR_RXRDY);
237 }
238 if (rr && RR_TXRDY)
239 sio->sio_cmd = WR0_RSTPEND;
240 /* not capable of transmit, yet */
241 }
242
243 static void
244 omkbd_input(v, data)
245 void *v;
246 int data;
247 {
248 struct ws_softc *sc = v;
249 u_int type;
250 int key;
251
252 if (omkbd_decode(v, data, &type, &key))
253 wskbd_input(sc->sc_wskbddev, type, key);
254 }
255
256 static int
257 omkbd_decode(v, datain, type, dataout)
258 void *v;
259 int datain;
260 u_int *type;
261 int *dataout;
262 {
263 *type = (datain & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
264 *dataout = datain & 0x7f;
265 return 1;
266 }
267
268 #define KC(n) KS_KEYCODE(n)
269
270 static const keysym_t omkbd_keydesc_1[] = {
271 /* pos command normal shifted */
272 KC(0x9), KS_Tab,
273 KC(0xa), KS_Control_L,
274 KC(0xb), KS_Mode_switch, /* Kana */
275 KC(0xc), KS_Shift_R,
276 KC(0xd), KS_Shift_L,
277 KC(0xe), KS_Caps_Lock,
278 KC(0xf), KS_Meta_L, /* Zenmen */
279 KC(0x10), KS_Escape,
280 KC(0x11), KS_BackSpace,
281 KC(0x12), KS_Return,
282 KC(0x14), KS_space,
283 KC(0x15), KS_Delete,
284 KC(0x16), KS_Alt_L, /* Henkan */
285 KC(0x17), KS_Alt_R, /* Kakutei */
286 KC(0x18), KS_f11, /* Shokyo */
287 KC(0x19), KS_f12, /* Yobidashi */
288 KC(0x1a), KS_f13, /* Bunsetsu L */
289 KC(0x1b), KS_f14, /* Bunsetsu R */
290 KC(0x1c), KS_KP_Up,
291 KC(0x1d), KS_KP_Left,
292 KC(0x1e), KS_KP_Right,
293 KC(0x1f), KS_KP_Down,
294 /* KC(0x20), KS_f11, */
295 /* KC(0x21), KS_f12, */
296 KC(0x22), KS_1, KS_exclam,
297 KC(0x23), KS_2, KS_quotedbl,
298 KC(0x24), KS_3, KS_numbersign,
299 KC(0x25), KS_4, KS_dollar,
300 KC(0x26), KS_5, KS_percent,
301 KC(0x27), KS_6, KS_ampersand,
302 KC(0x28), KS_7, KS_apostrophe,
303 KC(0x29), KS_8, KS_parenleft,
304 KC(0x2a), KS_9, KS_parenright,
305 KC(0x2b), KS_0,
306 KC(0x2c), KS_minus, KS_equal,
307 KC(0x2d), KS_asciicircum, KS_asciitilde,
308 KC(0x2e), KS_backslash, KS_bar,
309 /* KC(0x30), KS_f13, */
310 /* KC(0x31), KS_f14, */
311 KC(0x32), KS_q,
312 KC(0x33), KS_w,
313 KC(0x34), KS_e,
314 KC(0x35), KS_r,
315 KC(0x36), KS_t,
316 KC(0x37), KS_y,
317 KC(0x38), KS_u,
318 KC(0x39), KS_i,
319 KC(0x3a), KS_o,
320 KC(0x3b), KS_p,
321 KC(0x3c), KS_at, KS_grave,
322 KC(0x3d), KS_bracketleft, KS_braceleft,
323 KC(0x42), KS_a,
324 KC(0x43), KS_s,
325 KC(0x44), KS_d,
326 KC(0x45), KS_f,
327 KC(0x46), KS_g,
328 KC(0x47), KS_h,
329 KC(0x48), KS_j,
330 KC(0x49), KS_k,
331 KC(0x4a), KS_l,
332 KC(0x4b), KS_semicolon, KS_plus,
333 KC(0x4c), KS_colon, KS_asterisk,
334 KC(0x4d), KS_bracketright, KS_braceright,
335 KC(0x52), KS_z,
336 KC(0x53), KS_x,
337 KC(0x54), KS_c,
338 KC(0x55), KS_v,
339 KC(0x56), KS_b,
340 KC(0x57), KS_n,
341 KC(0x58), KS_m,
342 KC(0x59), KS_comma, KS_less,
343 KC(0x5a), KS_period, KS_greater,
344 KC(0x5b), KS_slash, KS_question,
345 KC(0x5c), KS_underscore,
346 KC(0x60), KS_KP_Delete,
347 KC(0x61), KS_KP_Add,
348 KC(0x62), KS_KP_Subtract,
349 KC(0x63), KS_KP_7,
350 KC(0x64), KS_KP_8,
351 KC(0x65), KS_KP_9,
352 KC(0x66), KS_KP_4,
353 KC(0x67), KS_KP_5,
354 KC(0x68), KS_KP_6,
355 KC(0x69), KS_KP_1,
356 KC(0x6a), KS_KP_2,
357 KC(0x6b), KS_KP_3,
358 KC(0x6c), KS_KP_0,
359 KC(0x6d), KS_KP_Decimal,
360 KC(0x6e), KS_KP_Enter,
361 KC(0x72), KS_f1,
362 KC(0x73), KS_f2,
363 KC(0x74), KS_f3,
364 KC(0x75), KS_f4,
365 KC(0x76), KS_f5,
366 KC(0x77), KS_f6,
367 KC(0x78), KS_f7,
368 KC(0x79), KS_f8,
369 KC(0x7a), KS_f9,
370 KC(0x7b), KS_f10,
371 KC(0x7c), KS_KP_Multiply,
372 KC(0x7d), KS_KP_Divide,
373 KC(0x7e), KS_KP_Equal,
374 KC(0x7f), KS_KP_Separator,
375 };
376
377 #define SIZE(map) (sizeof(map)/sizeof(keysym_t))
378
379 struct wscons_keydesc omkbd_keydesctab[] = {
380 { KB_JP, 0, SIZE(omkbd_keydesc_1), omkbd_keydesc_1, },
381 { 0, 0, 0, 0 },
382 };
383
384 static void
385 ws_cngetc(v, type, data)
386 void *v;
387 u_int *type;
388 int *data;
389 {
390 int code;
391
392 do {
393 code = syscngetc((dev_t)1);
394 } while (!omkbd_decode(v, code, type, data));
395 }
396
397 static void
398 ws_cnpollc(v, on)
399 void *v;
400 int on;
401 {
402 }
403
404 /* EXPORT */ void
405 ws_cnattach()
406 {
407 static int voidfill;
408
409 /* XXX need CH.B initialization XXX */
410
411 wskbd_cnattach(&ws_consops, &voidfill, &omkbd_keymapdata);
412 }
413
414 static int
415 omkbd_enable(v, on)
416 void *v;
417 int on;
418 {
419 return 0;
420 }
421
422 static void
423 omkbd_set_leds(v, leds)
424 void *v;
425 int leds;
426 {
427 #if 0
428 syscnputc((dev_t)1, 0x10); /* kana LED on */
429 syscnputc((dev_t)1, 0x00); /* kana LED off */
430 syscnputc((dev_t)1, 0x11); /* caps LED on */
431 syscnputc((dev_t)1, 0x01); /* caps LED off */
432 #endif
433 }
434
435 static int
436 omkbd_ioctl(v, cmd, data, flag, l)
437 void *v;
438 u_long cmd;
439 void *data;
440 int flag;
441 struct lwp *l;
442 {
443 switch (cmd) {
444 case WSKBDIO_GTYPE:
445 *(int *)data = 0x19991005 /* XXX */;
446 return 0;
447 case WSKBDIO_SETLEDS:
448 case WSKBDIO_GETLEDS:
449 case WSKBDIO_COMPLEXBELL: /* XXX capable of complex bell */
450 return 0;
451 }
452 return EPASSTHROUGH;
453 }
454
455 #if NWSMOUSE > 0
456
457 static int
458 omms_enable(v)
459 void *v;
460 {
461 struct ws_softc *sc = v;
462
463 syscnputc((dev_t)1, 0x60); /* enable 3 byte long mouse reporting */
464 sc->sc_msreport = 0;
465 return 0;
466 }
467
468 /*ARGUSED*/
469 static int
470 omms_ioctl(v, cmd, data, flag, l)
471 void *v;
472 u_long cmd;
473 void *data;
474 int flag;
475 struct lwp *l;
476 {
477 if (cmd == WSMOUSEIO_GTYPE) {
478 *(u_int *)data = 0x19991005; /* XXX */
479 return 0;
480 }
481 return EPASSTHROUGH;
482 }
483
484 static void
485 omms_disable(v)
486 void *v;
487 {
488 struct ws_softc *sc = v;
489
490 syscnputc((dev_t)1, 0x20); /* quiet mouse */
491 sc->sc_msreport = 0;
492 }
493 #endif
494