FreeBSD/Linux Kernel Cross Reference
sys/dev/dec/dzkbd.c
1 /* $NetBSD: dzkbd.c,v 1.30 2021/08/07 16:19:10 thorpej 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.30 2021/08/07 16:19:10 thorpej 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 dzkbd_internal *sc_itl;
83
84 int sc_enabled;
85 int kbd_type;
86
87 device_t sc_wskbddev;
88 };
89
90 static int dzkbd_input(void *, int);
91
92 static int dzkbd_match(device_t, cfdata_t, void *);
93 static void dzkbd_attach(device_t, device_t, void *);
94
95 CFATTACH_DECL_NEW(dzkbd, sizeof(struct dzkbd_softc),
96 dzkbd_match, dzkbd_attach, NULL, NULL);
97
98 static int dzkbd_enable(void *, int);
99 static void dzkbd_set_leds(void *, int);
100 static int dzkbd_ioctl(void *, u_long, void *, int, struct lwp *);
101
102 const struct wskbd_accessops dzkbd_accessops = {
103 dzkbd_enable,
104 dzkbd_set_leds,
105 dzkbd_ioctl,
106 };
107
108 static void dzkbd_cngetc(void *, u_int *, int *);
109 static void dzkbd_cnpollc(void *, int);
110
111 const struct wskbd_consops dzkbd_consops = {
112 dzkbd_cngetc,
113 dzkbd_cnpollc,
114 };
115
116 static int dzkbd_sendchar(void *, u_char);
117
118 const struct wskbd_mapdata dzkbd_keymapdata = {
119 lkkbd_keydesctab,
120 #ifdef DZKBD_LAYOUT
121 DZKBD_LAYOUT,
122 #else
123 KB_US | KB_LK401,
124 #endif
125 };
126
127 /*
128 * kbd_match: how is this dz line configured?
129 */
130 static int
131 dzkbd_match(device_t parent, cfdata_t cf, void *aux)
132 {
133 struct dzkm_attach_args *daa = aux;
134
135 /* Exact match is better than wildcard. */
136 if (cf->cf_loc[DZCF_LINE] == daa->daa_line)
137 return 2;
138
139 /* This driver accepts wildcard. */
140 if (cf->cf_loc[DZCF_LINE] == DZCF_LINE_DEFAULT)
141 return 1;
142
143 return 0;
144 }
145
146 static void
147 dzkbd_attach(device_t parent, device_t self, void *aux)
148 {
149 struct dz_softc *dz = device_private(parent);
150 struct dzkbd_softc *dzkbd = device_private(self);
151 struct dzkm_attach_args *daa = aux;
152 struct dz_linestate *ls;
153 struct dzkbd_internal *dzi;
154 struct wskbddev_attach_args a;
155 int isconsole;
156
157 dz->sc_dz[daa->daa_line].dz_catch = dzkbd_input;
158 dz->sc_dz[daa->daa_line].dz_private = dzkbd;
159 ls = &dz->sc_dz[daa->daa_line];
160
161 isconsole = (daa->daa_flags & DZKBD_CONSOLE);
162
163 if (isconsole) {
164 dzi = &dzkbd_console_internal;
165 } else {
166 dzi = malloc(sizeof(struct dzkbd_internal),
167 M_DEVBUF, M_WAITOK);
168 dzi->dzi_ks.attmt.sendchar = dzkbd_sendchar;
169 dzi->dzi_ks.attmt.cookie = ls;
170 }
171 dzi->dzi_ls = ls;
172 dzkbd->sc_itl = dzi;
173
174 printf("\n");
175
176 if (!isconsole) {
177 DELAY(100000);
178 lk201_init(&dzi->dzi_ks);
179 }
180
181 /* XXX should identify keyboard ID here XXX */
182 /* XXX layout and the number of LED is varying XXX */
183
184 dzkbd->kbd_type = WSKBD_TYPE_LK201;
185
186 dzkbd->sc_enabled = 1;
187
188 a.console = isconsole;
189 a.keymap = &dzkbd_keymapdata;
190 a.accessops = &dzkbd_accessops;
191 a.accesscookie = dzkbd;
192
193 dzkbd->sc_wskbddev = config_found(self, &a, wskbddevprint, CFARGS_NONE);
194 }
195
196 int
197 dzkbd_cnattach(struct dz_linestate *ls)
198 {
199
200 dzkbd_console_internal.dzi_ks.attmt.sendchar = dzkbd_sendchar;
201 dzkbd_console_internal.dzi_ks.attmt.cookie = ls;
202 lk201_init(&dzkbd_console_internal.dzi_ks);
203 dzkbd_console_internal.dzi_ls = ls;
204
205 wskbd_cnattach(&dzkbd_consops, &dzkbd_console_internal,
206 &dzkbd_keymapdata);
207
208 return 0;
209 }
210
211 static int
212 dzkbd_enable(void *v, int on)
213 {
214 struct dzkbd_softc *sc = v;
215
216 sc->sc_enabled = on;
217 return 0;
218 }
219
220 static int
221 dzkbd_sendchar(void *v, u_char c)
222 {
223 struct dz_linestate *ls = v;
224 int s;
225
226 s = spltty();
227 dzputc(ls, c);
228 splx(s);
229 return (0);
230 }
231
232 static void
233 dzkbd_cngetc(void *v, u_int *type, int *data)
234 {
235 struct dzkbd_internal *dzi = v;
236 int c;
237
238 do {
239 c = dzgetc(dzi->dzi_ls);
240 } while (!lk201_decode(&dzi->dzi_ks, 0, c, type, data) == LKD_NODATA);
241 }
242
243 static void
244 dzkbd_cnpollc(void *v, int on)
245 {
246 #if 0
247 struct dzkbd_internal *dzi = v;
248 #endif
249 }
250
251 static void
252 dzkbd_set_leds(void *v, int leds)
253 {
254 struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
255
256 //printf("dzkbd_set_leds\n");
257 lk201_set_leds(&sc->sc_itl->dzi_ks, leds);
258 }
259
260 static int
261 dzkbd_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
262 {
263 struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
264
265 switch (cmd) {
266 case WSKBDIO_GTYPE:
267 *(int *)data = sc->kbd_type;
268 return 0;
269 case WSKBDIO_SETLEDS:
270 lk201_set_leds(&sc->sc_itl->dzi_ks, *(int *)data);
271 return 0;
272 case WSKBDIO_GETLEDS:
273 /* XXX don't dig in kbd internals */
274 *(int *)data = sc->sc_itl->dzi_ks.leds_state;
275 return 0;
276 case WSKBDIO_COMPLEXBELL:
277 lk201_bell(&sc->sc_itl->dzi_ks,
278 (struct wskbd_bell_data *)data);
279 return 0;
280 case WSKBDIO_SETKEYCLICK:
281 lk201_set_keyclick(&sc->sc_itl->dzi_ks, *(int *)data);
282 return 0;
283 case WSKBDIO_GETKEYCLICK:
284 /* XXX don't dig in kbd internals */
285 *(int *)data = sc->sc_itl->dzi_ks.kcvol;
286 return 0;
287 }
288 return (EPASSTHROUGH);
289 }
290
291 static int
292 dzkbd_input(void *v, int data)
293 {
294 struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
295 u_int type;
296 int val;
297 int decode;
298
299 do {
300 decode = lk201_decode(&sc->sc_itl->dzi_ks, 1,
301 data, &type, &val);
302 if (decode != LKD_NODATA)
303 wskbd_input(sc->sc_wskbddev, type, val);
304 } while (decode == LKD_MORE);
305
306 return(1);
307 }
Cache object: c0567e9e016399d114a99c72bdf594b8
|