Home | History | Annotate | Line # | Download | only in dec
dzkbd.c revision 1.7
      1 /*	$NetBSD: dzkbd.c,v 1.7 2002/03/17 19:40:54 atatat 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/cdefs.h>
     52 __KERNEL_RCSID(0, "$NetBSD: dzkbd.c,v 1.7 2002/03/17 19:40:54 atatat Exp $");
     53 
     54 #include <sys/param.h>
     55 #include <sys/systm.h>
     56 #include <sys/device.h>
     57 #include <sys/ioctl.h>
     58 #include <sys/syslog.h>
     59 #include <sys/malloc.h>
     60 
     61 #include <dev/wscons/wsconsio.h>
     62 #include <dev/wscons/wskbdvar.h>
     63 #include <dev/wscons/wsksymdef.h>
     64 #include <dev/wscons/wsksymvar.h>
     65 #include <dev/dec/wskbdmap_lk201.h>
     66 
     67 #include <machine/bus.h>
     68 
     69 #include <dev/dec/dzreg.h>
     70 #include <dev/dec/dzvar.h>
     71 #include <dev/dec/dzkbdvar.h>
     72 #include <dev/dec/lk201reg.h>
     73 #include <dev/dec/lk201var.h>
     74 
     75 #include "locators.h"
     76 
     77 struct dzkbd_internal {
     78 	struct dz_linestate *dzi_ls;
     79 	struct lk201_state dzi_ks;
     80 };
     81 
     82 struct dzkbd_internal dzkbd_console_internal;
     83 
     84 struct dzkbd_softc {
     85 	struct device dzkbd_dev;	/* required first: base device */
     86 
     87 	struct dzkbd_internal *sc_itl;
     88 
     89 	int sc_enabled;
     90 	int kbd_type;
     91 
     92 	struct device *sc_wskbddev;
     93 };
     94 
     95 static int	dzkbd_input __P((void *, int));
     96 
     97 static int	dzkbd_match __P((struct device *, struct cfdata *, void *));
     98 static void	dzkbd_attach __P((struct device *, struct device *, void *));
     99 
    100 struct cfattach dzkbd_ca = {
    101 	sizeof(struct dzkbd_softc), dzkbd_match, dzkbd_attach,
    102 };
    103 
    104 static int	dzkbd_enable __P((void *, int));
    105 static void	dzkbd_set_leds __P((void *, int));
    106 static int	dzkbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    107 
    108 const struct wskbd_accessops dzkbd_accessops = {
    109 	dzkbd_enable,
    110 	dzkbd_set_leds,
    111 	dzkbd_ioctl,
    112 };
    113 
    114 static void	dzkbd_cngetc(void *, u_int *, int *);
    115 static void	dzkbd_cnpollc(void *, int);
    116 
    117 const struct wskbd_consops dzkbd_consops = {
    118 	dzkbd_cngetc,
    119 	dzkbd_cnpollc,
    120 };
    121 
    122 static int dzkbd_sendchar __P((void *, u_char));
    123 
    124 const struct wskbd_mapdata dzkbd_keymapdata = {
    125 	lkkbd_keydesctab,
    126 #ifdef DZKBD_LAYOUT
    127 	DZKBD_LAYOUT,
    128 #else
    129 	KB_US | KB_LK401,
    130 #endif
    131 };
    132 
    133 /*
    134  * kbd_match: how is this dz line configured?
    135  */
    136 static int
    137 dzkbd_match(struct device *parent, struct cfdata *cf, void *aux)
    138 {
    139 	struct dzkm_attach_args *daa = aux;
    140 
    141 	/* Exact match is better than wildcard. */
    142 	if (cf->cf_loc[DZCF_LINE] == daa->daa_line)
    143 		return 2;
    144 
    145 	/* This driver accepts wildcard. */
    146 	if (cf->cf_loc[DZCF_LINE] == DZCF_LINE_DEFAULT)
    147 		return 1;
    148 
    149 	return 0;
    150 }
    151 
    152 static void
    153 dzkbd_attach(struct device *parent, struct device *self, void *aux)
    154 {
    155 	struct dz_softc *dz = (void *)parent;
    156 	struct dzkbd_softc *dzkbd = (void *)self;
    157 	struct dzkm_attach_args *daa = aux;
    158 	struct dz_linestate *ls;
    159 	struct dzkbd_internal *dzi;
    160 	struct wskbddev_attach_args a;
    161 	int isconsole;
    162 
    163 	dz->sc_dz[daa->daa_line].dz_catch = dzkbd_input;
    164 	dz->sc_dz[daa->daa_line].dz_private = dzkbd;
    165 	ls = &dz->sc_dz[daa->daa_line];
    166 
    167 	isconsole = (daa->daa_flags & DZKBD_CONSOLE);
    168 
    169 	if (isconsole) {
    170 		dzi = &dzkbd_console_internal;
    171 	} else {
    172 		dzi = malloc(sizeof(struct dzkbd_internal),
    173 				       M_DEVBUF, M_NOWAIT);
    174 		dzi->dzi_ks.attmt.sendchar = dzkbd_sendchar;
    175 		dzi->dzi_ks.attmt.cookie = ls;
    176 		dzi->dzi_ls = ls;
    177 	}
    178 	dzkbd->sc_itl = dzi;
    179 
    180 	printf("\n");
    181 
    182 	if (!isconsole)
    183 		lk201_init(&dzi->dzi_ks);
    184 
    185 	/* XXX should identify keyboard ID here XXX */
    186 	/* XXX layout and the number of LED is varying XXX */
    187 
    188 	dzkbd->kbd_type = WSKBD_TYPE_LK201;
    189 
    190 	dzkbd->sc_enabled = 1;
    191 
    192 	a.console = isconsole;
    193 	a.keymap = &dzkbd_keymapdata;
    194 	a.accessops = &dzkbd_accessops;
    195 	a.accesscookie = dzkbd;
    196 
    197 	dzkbd->sc_wskbddev = config_found(self, &a, wskbddevprint);
    198 }
    199 
    200 int
    201 dzkbd_cnattach(ls)
    202 	struct dz_linestate *ls;
    203 {
    204 
    205 	dzkbd_console_internal.dzi_ks.attmt.sendchar = dzkbd_sendchar;
    206 	dzkbd_console_internal.dzi_ks.attmt.cookie = ls;
    207 	lk201_init(&dzkbd_console_internal.dzi_ks);
    208 	dzkbd_console_internal.dzi_ls = ls;
    209 
    210 	wskbd_cnattach(&dzkbd_consops, &dzkbd_console_internal,
    211 		       &dzkbd_keymapdata);
    212 
    213 	return 0;
    214 }
    215 
    216 static int
    217 dzkbd_enable(v, on)
    218 	void *v;
    219 	int on;
    220 {
    221 	struct dzkbd_softc *sc = v;
    222 
    223 	sc->sc_enabled = on;
    224 	return 0;
    225 }
    226 
    227 static int
    228 dzkbd_sendchar(v, c)
    229 	void *v;
    230 	u_char c;
    231 {
    232 	struct dz_linestate *ls = v;
    233 	int s;
    234 
    235 	s = spltty();
    236 	dzputc(ls, c);
    237 	splx(s);
    238 	return (0);
    239 }
    240 
    241 static void
    242 dzkbd_cngetc(v, type, data)
    243 	void *v;
    244 	u_int *type;
    245 	int *data;
    246 {
    247 	struct dzkbd_internal *dzi = v;
    248 	int c;
    249 
    250 	do {
    251 		c = dzgetc(dzi->dzi_ls);
    252 	} while (!lk201_decode(&dzi->dzi_ks, c, type, data));
    253 }
    254 
    255 static void
    256 dzkbd_cnpollc(v, on)
    257 	void *v;
    258         int on;
    259 {
    260 #if 0
    261 	struct dzkbd_internal *dzi = v;
    262 #endif
    263 }
    264 
    265 static void
    266 dzkbd_set_leds(v, leds)
    267 	void *v;
    268 	int leds;
    269 {
    270 	struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
    271 
    272 //printf("dzkbd_set_leds\n");
    273 	lk201_set_leds(&sc->sc_itl->dzi_ks, leds);
    274 }
    275 
    276 static int
    277 dzkbd_ioctl(v, cmd, data, flag, p)
    278 	void *v;
    279 	u_long cmd;
    280 	caddr_t data;
    281 	int flag;
    282 	struct proc *p;
    283 {
    284 	struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
    285 
    286 	switch (cmd) {
    287 	case WSKBDIO_GTYPE:
    288 		*(int *)data = sc->kbd_type;
    289 		return 0;
    290 	case WSKBDIO_SETLEDS:
    291 		lk201_set_leds(&sc->sc_itl->dzi_ks, *(int *)data);
    292 		return 0;
    293 	case WSKBDIO_GETLEDS:
    294 		/* XXX don't dig in kbd internals */
    295 		*(int *)data = sc->sc_itl->dzi_ks.leds_state;
    296 		return 0;
    297 	case WSKBDIO_COMPLEXBELL:
    298 		lk201_bell(&sc->sc_itl->dzi_ks,
    299 			   (struct wskbd_bell_data *)data);
    300 		return 0;
    301 	case WSKBDIO_SETKEYCLICK:
    302 		lk201_set_keyclick(&sc->sc_itl->dzi_ks, *(int *)data);
    303 		return 0;
    304 	case WSKBDIO_GETKEYCLICK:
    305 		/* XXX don't dig in kbd internals */
    306 		*(int *)data = sc->sc_itl->dzi_ks.kcvol;
    307 		return 0;
    308 	}
    309 	return (EPASSTHROUGH);
    310 }
    311 
    312 static int
    313 dzkbd_input(v, data)
    314 	void *v;
    315 	int data;
    316 {
    317 	struct dzkbd_softc *sc = (struct dzkbd_softc *)v;
    318 	u_int type;
    319 	int val;
    320 
    321 	if (sc->sc_enabled == 0)
    322 		return(0);
    323 
    324 	if (lk201_decode(&sc->sc_itl->dzi_ks, data, &type, &val))
    325 		wskbd_input(sc->sc_wskbddev, type, val);
    326 	return(1);
    327 }
    328 
    329