lunaws.c revision 1.23.8.3 1 1.23.8.3 msaitoh /* $NetBSD: lunaws.c,v 1.23.8.3 2014/11/09 07:34:12 msaitoh Exp $ */
2 1.1 nisimura
3 1.1 nisimura /*-
4 1.1 nisimura * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 nisimura * All rights reserved.
6 1.1 nisimura *
7 1.1 nisimura * This code is derived from software contributed to The NetBSD Foundation
8 1.1 nisimura * by Tohru Nishimura.
9 1.1 nisimura *
10 1.1 nisimura * Redistribution and use in source and binary forms, with or without
11 1.1 nisimura * modification, are permitted provided that the following conditions
12 1.1 nisimura * are met:
13 1.1 nisimura * 1. Redistributions of source code must retain the above copyright
14 1.1 nisimura * notice, this list of conditions and the following disclaimer.
15 1.1 nisimura * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 nisimura * notice, this list of conditions and the following disclaimer in the
17 1.1 nisimura * documentation and/or other materials provided with the distribution.
18 1.1 nisimura *
19 1.1 nisimura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 nisimura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 nisimura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 nisimura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 nisimura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 nisimura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 nisimura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 nisimura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 nisimura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 nisimura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 nisimura * POSSIBILITY OF SUCH DAMAGE.
30 1.1 nisimura */
31 1.1 nisimura
32 1.1 nisimura #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33 1.1 nisimura
34 1.23.8.3 msaitoh __KERNEL_RCSID(0, "$NetBSD: lunaws.c,v 1.23.8.3 2014/11/09 07:34:12 msaitoh Exp $");
35 1.1 nisimura
36 1.23.8.3 msaitoh #include "opt_wsdisplay_compat.h"
37 1.1 nisimura #include "wsmouse.h"
38 1.1 nisimura
39 1.1 nisimura #include <sys/param.h>
40 1.1 nisimura #include <sys/systm.h>
41 1.1 nisimura #include <sys/conf.h>
42 1.1 nisimura #include <sys/device.h>
43 1.1 nisimura
44 1.1 nisimura #include <dev/wscons/wsconsio.h>
45 1.1 nisimura #include <dev/wscons/wskbdvar.h>
46 1.1 nisimura #include <dev/wscons/wsksymdef.h>
47 1.1 nisimura #include <dev/wscons/wsksymvar.h>
48 1.1 nisimura #include <dev/wscons/wsmousevar.h>
49 1.1 nisimura
50 1.23.8.3 msaitoh #include <luna68k/dev/omkbdmap.h>
51 1.1 nisimura #include <luna68k/dev/sioreg.h>
52 1.1 nisimura #include <luna68k/dev/siovar.h>
53 1.1 nisimura
54 1.22 tsutsui #include "ioconf.h"
55 1.22 tsutsui
56 1.23.8.2 bouyer #define OMKBD_RXQ_LEN 64
57 1.23.8.2 bouyer #define OMKBD_RXQ_LEN_MASK (OMKBD_RXQ_LEN - 1)
58 1.23.8.2 bouyer #define OMKBD_NEXTRXQ(x) (((x) + 1) & OMKBD_RXQ_LEN_MASK)
59 1.23.8.2 bouyer
60 1.23 tsutsui static const uint8_t ch1_regs[6] = {
61 1.1 nisimura WR0_RSTINT, /* Reset E/S Interrupt */
62 1.1 nisimura WR1_RXALLS, /* Rx per char, No Tx */
63 1.1 nisimura 0, /* */
64 1.1 nisimura WR3_RX8BIT | WR3_RXENBL, /* Rx */
65 1.1 nisimura WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY, /* Tx/Rx */
66 1.1 nisimura WR5_TX8BIT | WR5_TXENBL, /* Tx */
67 1.1 nisimura };
68 1.1 nisimura
69 1.1 nisimura struct ws_softc {
70 1.22 tsutsui device_t sc_dev;
71 1.3 nisimura struct sioreg *sc_ctl;
72 1.23 tsutsui uint8_t sc_wr[6];
73 1.23.8.2 bouyer device_t sc_wskbddev;
74 1.23.8.2 bouyer uint8_t sc_rxq[OMKBD_RXQ_LEN];
75 1.23.8.2 bouyer u_int sc_rxqhead;
76 1.23.8.2 bouyer u_int sc_rxqtail;
77 1.3 nisimura #if NWSMOUSE > 0
78 1.23.8.2 bouyer device_t sc_wsmousedev;
79 1.3 nisimura int sc_msreport;
80 1.23.8.2 bouyer int sc_msbuttons, sc_msdx, sc_msdy;
81 1.3 nisimura #endif
82 1.23.8.2 bouyer void *sc_si;
83 1.23.8.3 msaitoh int sc_rawkbd;
84 1.1 nisimura };
85 1.1 nisimura
86 1.16 dsl static void omkbd_input(void *, int);
87 1.23.8.3 msaitoh static void omkbd_decode(void *, int, u_int *, int *);
88 1.16 dsl static int omkbd_enable(void *, int);
89 1.16 dsl static void omkbd_set_leds(void *, int);
90 1.16 dsl static int omkbd_ioctl(void *, u_long, void *, int, struct lwp *);
91 1.1 nisimura
92 1.1 nisimura static const struct wskbd_mapdata omkbd_keymapdata = {
93 1.1 nisimura omkbd_keydesctab,
94 1.1 nisimura KB_JP,
95 1.1 nisimura };
96 1.1 nisimura static const struct wskbd_accessops omkbd_accessops = {
97 1.1 nisimura omkbd_enable,
98 1.1 nisimura omkbd_set_leds,
99 1.1 nisimura omkbd_ioctl,
100 1.1 nisimura };
101 1.1 nisimura
102 1.16 dsl void ws_cnattach(void);
103 1.16 dsl static void ws_cngetc(void *, u_int *, int *);
104 1.16 dsl static void ws_cnpollc(void *, int);
105 1.1 nisimura static const struct wskbd_consops ws_consops = {
106 1.1 nisimura ws_cngetc,
107 1.1 nisimura ws_cnpollc,
108 1.1 nisimura };
109 1.1 nisimura
110 1.1 nisimura #if NWSMOUSE > 0
111 1.16 dsl static int omms_enable(void *);
112 1.16 dsl static int omms_ioctl(void *, u_long, void *, int, struct lwp *);
113 1.16 dsl static void omms_disable(void *);
114 1.1 nisimura
115 1.1 nisimura static const struct wsmouse_accessops omms_accessops = {
116 1.1 nisimura omms_enable,
117 1.1 nisimura omms_ioctl,
118 1.1 nisimura omms_disable,
119 1.1 nisimura };
120 1.1 nisimura #endif
121 1.1 nisimura
122 1.16 dsl static void wsintr(int);
123 1.23.8.2 bouyer static void wssoftintr(void *);
124 1.1 nisimura
125 1.22 tsutsui static int wsmatch(device_t, cfdata_t, void *);
126 1.22 tsutsui static void wsattach(device_t, device_t, void *);
127 1.1 nisimura
128 1.22 tsutsui CFATTACH_DECL_NEW(ws, sizeof(struct ws_softc),
129 1.9 thorpej wsmatch, wsattach, NULL, NULL);
130 1.1 nisimura
131 1.16 dsl extern int syscngetc(dev_t);
132 1.16 dsl extern void syscnputc(dev_t, int);
133 1.1 nisimura
134 1.1 nisimura static int
135 1.22 tsutsui wsmatch(device_t parent, cfdata_t cf, void *aux)
136 1.1 nisimura {
137 1.1 nisimura struct sio_attach_args *args = aux;
138 1.1 nisimura
139 1.1 nisimura if (args->channel != 1)
140 1.1 nisimura return 0;
141 1.1 nisimura return 1;
142 1.1 nisimura }
143 1.1 nisimura
144 1.1 nisimura static void
145 1.22 tsutsui wsattach(device_t parent, device_t self, void *aux)
146 1.1 nisimura {
147 1.22 tsutsui struct ws_softc *sc = device_private(self);
148 1.22 tsutsui struct sio_softc *scp = device_private(parent);
149 1.1 nisimura struct sio_attach_args *args = aux;
150 1.1 nisimura struct wskbddev_attach_args a;
151 1.1 nisimura
152 1.22 tsutsui sc->sc_dev = self;
153 1.1 nisimura sc->sc_ctl = (struct sioreg *)scp->scp_ctl + 1;
154 1.20 cegger memcpy(sc->sc_wr, ch1_regs, sizeof(ch1_regs));
155 1.1 nisimura scp->scp_intr[1] = wsintr;
156 1.23.8.2 bouyer
157 1.1 nisimura setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
158 1.1 nisimura setsioreg(sc->sc_ctl, WR4, sc->sc_wr[WR4]);
159 1.1 nisimura setsioreg(sc->sc_ctl, WR3, sc->sc_wr[WR3]);
160 1.1 nisimura setsioreg(sc->sc_ctl, WR5, sc->sc_wr[WR5]);
161 1.1 nisimura setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
162 1.1 nisimura setsioreg(sc->sc_ctl, WR1, sc->sc_wr[WR1]);
163 1.1 nisimura
164 1.1 nisimura syscnputc((dev_t)1, 0x20); /* keep quiet mouse */
165 1.1 nisimura
166 1.23.8.2 bouyer sc->sc_rxqhead = 0;
167 1.23.8.2 bouyer sc->sc_rxqtail = 0;
168 1.23.8.2 bouyer
169 1.23.8.2 bouyer sc->sc_si = softint_establish(SOFTINT_SERIAL, wssoftintr, sc);
170 1.23.8.2 bouyer
171 1.22 tsutsui aprint_normal("\n");
172 1.1 nisimura
173 1.1 nisimura a.console = (args->hwflags == 1);
174 1.1 nisimura a.keymap = &omkbd_keymapdata;
175 1.1 nisimura a.accessops = &omkbd_accessops;
176 1.1 nisimura a.accesscookie = (void *)sc;
177 1.23 tsutsui sc->sc_wskbddev = config_found_ia(self, "wskbddev", &a, wskbddevprint);
178 1.1 nisimura
179 1.1 nisimura #if NWSMOUSE > 0
180 1.1 nisimura {
181 1.1 nisimura struct wsmousedev_attach_args b;
182 1.1 nisimura b.accessops = &omms_accessops;
183 1.23.8.2 bouyer b.accesscookie = (void *)sc;
184 1.23 tsutsui sc->sc_wsmousedev =
185 1.23 tsutsui config_found_ia(self, "wsmousedev", &b, wsmousedevprint);
186 1.3 nisimura sc->sc_msreport = 0;
187 1.1 nisimura }
188 1.1 nisimura #endif
189 1.1 nisimura }
190 1.1 nisimura
191 1.1 nisimura /*ARGSUSED*/
192 1.1 nisimura static void
193 1.15 cegger wsintr(int chan)
194 1.1 nisimura {
195 1.15 cegger struct ws_softc *sc = device_lookup_private(&ws_cd, 0);
196 1.1 nisimura struct sioreg *sio = sc->sc_ctl;
197 1.23.8.2 bouyer uint8_t code;
198 1.1 nisimura int rr;
199 1.1 nisimura
200 1.1 nisimura rr = getsiocsr(sio);
201 1.1 nisimura if (rr & RR_RXRDY) {
202 1.1 nisimura do {
203 1.1 nisimura code = sio->sio_data;
204 1.1 nisimura if (rr & (RR_FRAMING | RR_OVERRUN | RR_PARITY)) {
205 1.1 nisimura sio->sio_cmd = WR0_ERRRST;
206 1.1 nisimura continue;
207 1.1 nisimura }
208 1.23.8.2 bouyer sc->sc_rxq[sc->sc_rxqtail] = code;
209 1.23.8.2 bouyer sc->sc_rxqtail = OMKBD_NEXTRXQ(sc->sc_rxqtail);
210 1.1 nisimura } while ((rr = getsiocsr(sio)) & RR_RXRDY);
211 1.23.8.2 bouyer softint_schedule(sc->sc_si);
212 1.1 nisimura }
213 1.23.8.1 martin if (rr & RR_TXRDY)
214 1.1 nisimura sio->sio_cmd = WR0_RSTPEND;
215 1.1 nisimura /* not capable of transmit, yet */
216 1.1 nisimura }
217 1.1 nisimura
218 1.1 nisimura static void
219 1.23.8.2 bouyer wssoftintr(void *arg)
220 1.23.8.2 bouyer {
221 1.23.8.2 bouyer struct ws_softc *sc = arg;
222 1.23.8.2 bouyer uint8_t code;
223 1.23.8.2 bouyer
224 1.23.8.2 bouyer while (sc->sc_rxqhead != sc->sc_rxqtail) {
225 1.23.8.2 bouyer code = sc->sc_rxq[sc->sc_rxqhead];
226 1.23.8.2 bouyer sc->sc_rxqhead = OMKBD_NEXTRXQ(sc->sc_rxqhead);
227 1.23.8.2 bouyer #if NWSMOUSE > 0
228 1.23.8.2 bouyer /*
229 1.23.8.2 bouyer * if (code >= 0x80 && code <= 0x87), then
230 1.23.8.2 bouyer * it's the first byte of 3 byte long mouse report
231 1.23.8.2 bouyer * code[0] & 07 -> LMR button condition
232 1.23.8.2 bouyer * code[1], [2] -> x,y delta
233 1.23.8.2 bouyer * otherwise, key press or release event.
234 1.23.8.2 bouyer */
235 1.23.8.2 bouyer if (sc->sc_msreport == 0) {
236 1.23.8.2 bouyer if (code < 0x80 || code > 0x87) {
237 1.23.8.2 bouyer omkbd_input(sc, code);
238 1.23.8.2 bouyer continue;
239 1.23.8.2 bouyer }
240 1.23.8.2 bouyer code = (code & 07) ^ 07;
241 1.23.8.2 bouyer /* LMR->RML: wsevent counts 0 for leftmost */
242 1.23.8.2 bouyer sc->sc_msbuttons = (code & 02);
243 1.23.8.2 bouyer if (code & 01)
244 1.23.8.2 bouyer sc->sc_msbuttons |= 04;
245 1.23.8.2 bouyer if (code & 04)
246 1.23.8.2 bouyer sc->sc_msbuttons |= 01;
247 1.23.8.2 bouyer sc->sc_msreport = 1;
248 1.23.8.2 bouyer } else if (sc->sc_msreport == 1) {
249 1.23.8.2 bouyer sc->sc_msdx = (int8_t)code;
250 1.23.8.2 bouyer sc->sc_msreport = 2;
251 1.23.8.2 bouyer } else if (sc->sc_msreport == 2) {
252 1.23.8.2 bouyer sc->sc_msdy = (int8_t)code;
253 1.23.8.2 bouyer wsmouse_input(sc->sc_wsmousedev,
254 1.23.8.2 bouyer sc->sc_msbuttons, sc->sc_msdx, sc->sc_msdy, 0, 0,
255 1.23.8.2 bouyer WSMOUSE_INPUT_DELTA);
256 1.23.8.2 bouyer
257 1.23.8.2 bouyer sc->sc_msreport = 0;
258 1.23.8.2 bouyer }
259 1.23.8.2 bouyer #else
260 1.23.8.2 bouyer omkbd_input(sc, code);
261 1.23.8.2 bouyer #endif
262 1.23.8.2 bouyer }
263 1.23.8.2 bouyer }
264 1.23.8.2 bouyer
265 1.23.8.2 bouyer static void
266 1.17 dsl omkbd_input(void *v, int data)
267 1.1 nisimura {
268 1.1 nisimura struct ws_softc *sc = v;
269 1.1 nisimura u_int type;
270 1.1 nisimura int key;
271 1.1 nisimura
272 1.23.8.3 msaitoh omkbd_decode(v, data, &type, &key);
273 1.23.8.3 msaitoh
274 1.23.8.3 msaitoh #ifdef WSDISPLAY_COMPAT_RAWKBD
275 1.23.8.3 msaitoh if (sc->sc_rawkbd) {
276 1.23.8.3 msaitoh uint8_t cbuf[2];
277 1.23.8.3 msaitoh int c, j = 0;
278 1.23.8.3 msaitoh
279 1.23.8.3 msaitoh c = omkbd_raw[key];
280 1.23.8.3 msaitoh if (c != 0x00) {
281 1.23.8.3 msaitoh /* fake extended scancode if necessary */
282 1.23.8.3 msaitoh if (c & 0x80)
283 1.23.8.3 msaitoh cbuf[j++] = 0xe0;
284 1.23.8.3 msaitoh cbuf[j] = c & 0x7f;
285 1.23.8.3 msaitoh if (type == WSCONS_EVENT_KEY_UP)
286 1.23.8.3 msaitoh cbuf[j] |= 0x80;
287 1.23.8.3 msaitoh j++;
288 1.23.8.3 msaitoh
289 1.23.8.3 msaitoh wskbd_rawinput(sc->sc_wskbddev, cbuf, j);
290 1.23.8.3 msaitoh }
291 1.23.8.3 msaitoh } else
292 1.23.8.3 msaitoh #endif
293 1.23.8.3 msaitoh {
294 1.23.8.3 msaitoh if (sc->sc_wskbddev != NULL)
295 1.23.8.3 msaitoh wskbd_input(sc->sc_wskbddev, type, key);
296 1.23.8.3 msaitoh }
297 1.1 nisimura }
298 1.1 nisimura
299 1.23.8.3 msaitoh static void
300 1.17 dsl omkbd_decode(void *v, int datain, u_int *type, int *dataout)
301 1.1 nisimura {
302 1.23 tsutsui
303 1.1 nisimura *type = (datain & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
304 1.1 nisimura *dataout = datain & 0x7f;
305 1.1 nisimura }
306 1.1 nisimura
307 1.1 nisimura static void
308 1.17 dsl ws_cngetc(void *v, u_int *type, int *data)
309 1.1 nisimura {
310 1.1 nisimura int code;
311 1.1 nisimura
312 1.23.8.3 msaitoh code = syscngetc((dev_t)1);
313 1.23.8.3 msaitoh omkbd_decode(v, code, type, data);
314 1.1 nisimura }
315 1.1 nisimura
316 1.1 nisimura static void
317 1.17 dsl ws_cnpollc(void *v, int on)
318 1.1 nisimura {
319 1.1 nisimura }
320 1.1 nisimura
321 1.1 nisimura /* EXPORT */ void
322 1.18 cegger ws_cnattach(void)
323 1.1 nisimura {
324 1.1 nisimura static int voidfill;
325 1.1 nisimura
326 1.3 nisimura /* XXX need CH.B initialization XXX */
327 1.3 nisimura
328 1.1 nisimura wskbd_cnattach(&ws_consops, &voidfill, &omkbd_keymapdata);
329 1.1 nisimura }
330 1.1 nisimura
331 1.1 nisimura static int
332 1.17 dsl omkbd_enable(void *v, int on)
333 1.1 nisimura {
334 1.23 tsutsui
335 1.1 nisimura return 0;
336 1.1 nisimura }
337 1.1 nisimura
338 1.1 nisimura static void
339 1.17 dsl omkbd_set_leds(void *v, int leds)
340 1.1 nisimura {
341 1.23 tsutsui
342 1.1 nisimura #if 0
343 1.1 nisimura syscnputc((dev_t)1, 0x10); /* kana LED on */
344 1.1 nisimura syscnputc((dev_t)1, 0x00); /* kana LED off */
345 1.2 nisimura syscnputc((dev_t)1, 0x11); /* caps LED on */
346 1.1 nisimura syscnputc((dev_t)1, 0x01); /* caps LED off */
347 1.1 nisimura #endif
348 1.1 nisimura }
349 1.1 nisimura
350 1.1 nisimura static int
351 1.17 dsl omkbd_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
352 1.1 nisimura {
353 1.23.8.3 msaitoh #ifdef WSDISPLAY_COMPAT_RAWKBD
354 1.23.8.3 msaitoh struct ws_softc *sc = v;
355 1.23.8.3 msaitoh #endif
356 1.23 tsutsui
357 1.1 nisimura switch (cmd) {
358 1.23 tsutsui case WSKBDIO_GTYPE:
359 1.21 tsutsui *(int *)data = WSKBD_TYPE_LUNA;
360 1.1 nisimura return 0;
361 1.23 tsutsui case WSKBDIO_SETLEDS:
362 1.23 tsutsui case WSKBDIO_GETLEDS:
363 1.23 tsutsui case WSKBDIO_COMPLEXBELL: /* XXX capable of complex bell */
364 1.1 nisimura return 0;
365 1.23.8.3 msaitoh #ifdef WSDISPLAY_COMPAT_RAWKBD
366 1.23.8.3 msaitoh case WSKBDIO_SETMODE:
367 1.23.8.3 msaitoh sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
368 1.23.8.3 msaitoh return 0;
369 1.23.8.3 msaitoh case WSKBDIO_GETMODE:
370 1.23.8.3 msaitoh *(int *)data = sc->sc_rawkbd;
371 1.23.8.3 msaitoh return 0;
372 1.23.8.3 msaitoh #endif
373 1.1 nisimura }
374 1.6 atatat return EPASSTHROUGH;
375 1.1 nisimura }
376 1.1 nisimura
377 1.1 nisimura #if NWSMOUSE > 0
378 1.1 nisimura
379 1.1 nisimura static int
380 1.17 dsl omms_enable(void *v)
381 1.1 nisimura {
382 1.3 nisimura struct ws_softc *sc = v;
383 1.3 nisimura
384 1.1 nisimura syscnputc((dev_t)1, 0x60); /* enable 3 byte long mouse reporting */
385 1.3 nisimura sc->sc_msreport = 0;
386 1.1 nisimura return 0;
387 1.1 nisimura }
388 1.1 nisimura
389 1.1 nisimura /*ARGUSED*/
390 1.1 nisimura static int
391 1.17 dsl omms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
392 1.1 nisimura {
393 1.23 tsutsui
394 1.1 nisimura if (cmd == WSMOUSEIO_GTYPE) {
395 1.1 nisimura *(u_int *)data = 0x19991005; /* XXX */
396 1.1 nisimura return 0;
397 1.1 nisimura }
398 1.6 atatat return EPASSTHROUGH;
399 1.1 nisimura }
400 1.1 nisimura
401 1.1 nisimura static void
402 1.17 dsl omms_disable(void *v)
403 1.1 nisimura {
404 1.3 nisimura struct ws_softc *sc = v;
405 1.3 nisimura
406 1.1 nisimura syscnputc((dev_t)1, 0x20); /* quiet mouse */
407 1.3 nisimura sc->sc_msreport = 0;
408 1.1 nisimura }
409 1.1 nisimura #endif
410