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