dzkbd.c revision 1.24 1 /* $NetBSD: dzkbd.c,v 1.24 2012/07/16 12:52:47 abs Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)kbd.c 8.2 (Berkeley) 10/30/93
41 */
42
43 /*
44 * LK200/LK400 keyboard attached to line 0 of the DZ*-11
45 */
46
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: dzkbd.c,v 1.24 2012/07/16 12:52:47 abs Exp $");
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/device.h>
53 #include <sys/ioctl.h>
54 #include <sys/syslog.h>
55 #include <sys/malloc.h>
56 #include <sys/intr.h>
57
58 #include <dev/wscons/wsconsio.h>
59 #include <dev/wscons/wskbdvar.h>
60 #include <dev/wscons/wsksymdef.h>
61 #include <dev/wscons/wsksymvar.h>
62 #include <dev/dec/wskbdmap_lk201.h>
63
64 #include <sys/bus.h>
65
66 #include <dev/dec/dzreg.h>
67 #include <dev/dec/dzvar.h>
68 #include <dev/dec/dzkbdvar.h>
69 #include <dev/dec/lk201reg.h>
70 #include <dev/dec/lk201var.h>
71
72 #include "locators.h"
73
74 struct dzkbd_internal {
75 struct dz_linestate *dzi_ls;
76 struct lk201_state dzi_ks;
77 };
78
79 struct dzkbd_internal dzkbd_console_internal;
80
81 struct dzkbd_softc {
82 struct device dzkbd_dev; /* required first: base device */
83
84 struct dzkbd_internal *sc_itl;
85
86 int sc_enabled;
87 int kbd_type;
88 int wsraw;
89
90 device_t sc_wskbddev;
91 };
92
93 static int dzkbd_input(void *, int);
94
95 static int dzkbd_match(device_t, cfdata_t, void *);
96 static void dzkbd_attach(device_t, device_t, void *);
97
98 CFATTACH_DECL(dzkbd, sizeof(struct dzkbd_softc),
99 dzkbd_match, dzkbd_attach, NULL, NULL);
100
101 static int dzkbd_enable(void *, int);
102 static void dzkbd_set_leds(void *, int);
103 static int dzkbd_ioctl(void *, u_long, void *, int, struct lwp *);
104
105 const struct wskbd_accessops dzkbd_accessops = {
106 dzkbd_enable,
107 dzkbd_set_leds,
108 dzkbd_ioctl,
109 };
110
111 static void dzkbd_cngetc(void *, u_int *, int *);
112 static void dzkbd_cnpollc(void *, int);
113
114 const struct wskbd_consops dzkbd_consops = {
115 dzkbd_cngetc,
116 dzkbd_cnpollc,
117 };
118
119 static int dzkbd_sendchar(void *, u_char);
120
121 const struct wskbd_mapdata dzkbd_keymapdata = {
122 lkkbd_keydesctab,
123 #ifdef DZKBD_LAYOUT
124 DZKBD_LAYOUT,
125 #else
126 KB_US | KB_LK401,
127 #endif
128 };
129
130 /*
131 * kbd_match: how is this dz line configured?
132 */
133 static int
134 dzkbd_match(device_t parent, cfdata_t cf, void *aux)
135 {
136 struct dzkm_attach_args *daa = aux;
137
138 /* Exact match is better than wildcard. */
139 if (cf->cf_loc[DZCF_LINE] == daa->daa_line)
140 return 2;
141
142 /* This driver accepts wildcard. */
143 if (cf->cf_loc[DZCF_LINE] == DZCF_LINE_DEFAULT)
144 return 1;
145
146 return 0;
147 }
148
149 static void
150 dzkbd_attach(device_t parent, device_t self, void *aux)
151 {
152 struct dz_softc *dz = device_private(parent);
153 struct dzkbd_softc *dzkbd = device_private(self);
154 struct dzkm_attach_args *daa = aux;
155 struct dz_linestate *ls;
156 struct dzkbd_internal *dzi;
157 struct wskbddev_attach_args a;
158 int isconsole;
159
160 dz->sc_dz[daa->daa_line].dz_catch = dzkbd_input;
161 dz->sc_dz[daa->daa_line].dz_private = dzkbd;
162 ls = &dz->sc_dz[daa->daa_line];
163
164 isconsole = (daa->daa_flags & DZKBD_CONSOLE);
165
166 if (isconsole) {
167 dzi = &dzkbd_console_internal;
168 } else {
169 dzi = malloc(sizeof(struct dzkbd_internal),
170 M_DEVBUF, M_NOWAIT);
171 dzi->dzi_ks.attmt.sendchar = dzkbd_sendchar;
172 dzi->dzi_ks.attmt.cookie = ls;
173 }
174 dzi->dzi_ls = ls;
175 dzkbd->sc_itl = dzi;
176
177 printf("\n");
178
179 if (!isconsole) {
180 DELAY(100000);
181 lk201_init(&dzi->dzi_ks);
182 }
183
184 /* XXX should identify keyboard ID here XXX */
185 /* XXX layout and the number of LED is varying XXX */
186
187 dzkbd->kbd_type = WSKBD_TYPE_LK201;
188
189 dzkbd->sc_enabled = 1;
190
191 a.console = isconsole;
192 a.keymap = &dzkbd_keymapdata;
193 a.accessops = &dzkbd_accessops;
194 a.accesscookie = dzkbd;
195
196 dzkbd->sc_wskbddev = config_found(self, &a, wskbddevprint);
197 }
198
199 int
200 dzkbd_cnattach(struct dz_linestate *ls)
201 {
202
203 dzkbd_console_internal.dzi_ks.attmt.sendchar = dzkbd_sendchar;
204 dzkbd_console_internal.dzi_ks.attmt.cookie = ls;
205 lk201_init(&dzkbd_console_internal.dzi_ks);
206 dzkbd_console_internal.dzi_ls = ls;
207
208 wskbd_cnattach(&dzkbd_consops, &dzkbd_console_internal,
209 &dzkbd_keymapdata);
210
211 return 0;
212 }
213
214 static int
215 dzkbd_enable(void *v, int on)
216 {
217 struct dzkbd_softc *sc = v;
218
219 sc->sc_enabled = on;
220 return 0;
221 }
222
223 static int
224 dzkbd_sendchar(void *v, u_char c)
225 {
226 struct dz_linestate *ls = v;
227 int s;
228
229 s = spltty();
230 dzputc(ls, c);
231 splx(s);
232 return (0);
233 }
234
235 static void
236 dzkbd_cngetc(void *v, u_int *type, int *data)
237 {
238 struct dzkbd_internal *dzi = v;
239 int c;
240
241 do {
242 c = dzgetc(dzi->dzi_ls);
243 } while (!lk201_decode(&dzi->dzi_ks, c, type, data));
244 }
245
246 static void
247 dzkbd_cnpollc(void *v, int on)
248 {
249 #if 0
250 struct dzkbd_internal *dzi = v;
251 #endif
252 }
253
254 static void
255 dzkbd_set_leds(void *v, int leds)
256 {
257 struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
258
259 //printf("dzkbd_set_leds\n");
260 lk201_set_leds(&sc->sc_itl->dzi_ks, leds);
261 }
262
263 static int
264 dzkbd_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
265 {
266 struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
267
268 switch (cmd) {
269 case WSKBDIO_GTYPE:
270 *(int *)data = sc->kbd_type;
271 return 0;
272 case WSKBDIO_SETLEDS:
273 lk201_set_leds(&sc->sc_itl->dzi_ks, *(int *)data);
274 return 0;
275 case WSKBDIO_GETLEDS:
276 /* XXX don't dig in kbd internals */
277 *(int *)data = sc->sc_itl->dzi_ks.leds_state;
278 return 0;
279 case WSKBDIO_COMPLEXBELL:
280 lk201_bell(&sc->sc_itl->dzi_ks,
281 (struct wskbd_bell_data *)data);
282 return 0;
283 case WSKBDIO_SETKEYCLICK:
284 lk201_set_keyclick(&sc->sc_itl->dzi_ks, *(int *)data);
285 return 0;
286 case WSKBDIO_GETKEYCLICK:
287 /* XXX don't dig in kbd internals */
288 *(int *)data = sc->sc_itl->dzi_ks.kcvol;
289 return 0;
290 #ifdef WSDISPLAY_COMPAT_RAWKBD
291 case WSKBDIO_SETMODE:
292 sc->wsraw = *(int *)data == WSKBD_RAW;
293 return 0;
294 #endif
295 }
296 return (EPASSTHROUGH);
297 }
298
299 static int
300 dzkbd_input(void *v, int data)
301 {
302 struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
303 u_int type;
304 int val;
305
306 if (sc->sc_enabled == 0)
307 return(0);
308
309 if (lk201_decode(&sc->sc_itl->dzi_ks, data, &type, &val))
310 wskbd_input(sc->sc_wskbddev, type, val);
311 return(1);
312 }
313
314