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