Annotation of sys/arch/vax/vxt/qsckbd.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: qsckbd.c,v 1.1 2006/08/27 16:55:41 miod Exp $ */
! 2: /* from OpenBSD: dzkbd.c,v 1.11 2006/08/05 22:05:55 miod Exp */
! 3: /*
! 4: * Copyright (c) 2006 Miodrag Vallat.
! 5: *
! 6: * Permission to use, copy, modify, and distribute this software for any
! 7: * purpose with or without fee is hereby granted, provided that the above
! 8: * copyright notice, this permission notice, and the disclaimer below
! 9: * appear in all copies.
! 10: *
! 11: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
! 12: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
! 13: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
! 14: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
! 15: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
! 16: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
! 17: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
! 18: */
! 19:
! 20: /*
! 21: * Copyright (c) 1992, 1993
! 22: * The Regents of the University of California. All rights reserved.
! 23: *
! 24: * This software was developed by the Computer Systems Engineering group
! 25: * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
! 26: * contributed to Berkeley.
! 27: *
! 28: * All advertising materials mentioning features or use of this software
! 29: * must display the following acknowledgement:
! 30: * This product includes software developed by the University of
! 31: * California, Lawrence Berkeley Laboratory.
! 32: *
! 33: * Redistribution and use in source and binary forms, with or without
! 34: * modification, are permitted provided that the following conditions
! 35: * are met:
! 36: * 1. Redistributions of source code must retain the above copyright
! 37: * notice, this list of conditions and the following disclaimer.
! 38: * 2. Redistributions in binary form must reproduce the above copyright
! 39: * notice, this list of conditions and the following disclaimer in the
! 40: * documentation and/or other materials provided with the distribution.
! 41: * 3. Neither the name of the University nor the names of its contributors
! 42: * may be used to endorse or promote products derived from this software
! 43: * without specific prior written permission.
! 44: *
! 45: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 46: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 47: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 48: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 49: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 50: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 51: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 52: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 53: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 54: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 55: * SUCH DAMAGE.
! 56: *
! 57: * @(#)kbd.c 8.2 (Berkeley) 10/30/93
! 58: */
! 59:
! 60: /*
! 61: * LK200/LK400 keyboard attached to line C of the SC26C94
! 62: */
! 63:
! 64: #include <sys/param.h>
! 65: #include <sys/systm.h>
! 66: #include <sys/device.h>
! 67: #include <sys/ioctl.h>
! 68: #include <sys/syslog.h>
! 69: #include <sys/malloc.h>
! 70: #include <sys/timeout.h>
! 71:
! 72: #include <dev/wscons/wsconsio.h>
! 73: #include <dev/wscons/wskbdvar.h>
! 74: #include <dev/wscons/wsksymdef.h>
! 75: #include <dev/wscons/wsksymvar.h>
! 76: #include <vax/dec/wskbdmap_lk201.h>
! 77:
! 78: #include <machine/bus.h>
! 79:
! 80: #include <vax/dec/lk201reg.h>
! 81: #include <vax/dec/lk201var.h>
! 82:
! 83: #include <vax/vxt/qscvar.h>
! 84:
! 85: struct qsckbd_internal {
! 86: u_int dzi_line;
! 87: struct lk201_state dzi_ks;
! 88: };
! 89:
! 90: struct qsckbd_internal qsckbd_console_internal;
! 91:
! 92: struct qsckbd_softc {
! 93: struct device qsckbd_dev; /* required first: base device */
! 94:
! 95: struct qsckbd_internal *sc_itl;
! 96: int sc_enabled;
! 97: struct device *sc_wskbddev;
! 98: };
! 99:
! 100: int qsckbd_match(struct device *, void *, void *);
! 101: void qsckbd_attach(struct device *, struct device *, void *);
! 102:
! 103: struct cfattach qsckbd_ca = {
! 104: sizeof(struct qsckbd_softc), qsckbd_match, qsckbd_attach,
! 105: };
! 106:
! 107: int qsckbd_enable(void *, int);
! 108: void qsckbd_set_leds(void *, int);
! 109: int qsckbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
! 110:
! 111: const struct wskbd_accessops qsckbd_accessops = {
! 112: qsckbd_enable,
! 113: qsckbd_set_leds,
! 114: qsckbd_ioctl,
! 115: };
! 116:
! 117: void qsckbd_cngetc(void *, u_int *, int *);
! 118: void qsckbd_cnpollc(void *, int);
! 119:
! 120: const struct wskbd_consops qsckbd_consops = {
! 121: qsckbd_cngetc,
! 122: qsckbd_cnpollc,
! 123: };
! 124:
! 125: const struct wskbd_mapdata qsckbd_keymapdata = {
! 126: lkkbd_keydesctab,
! 127: #ifdef LKKBD_LAYOUT
! 128: LKKBD_LAYOUT,
! 129: #else
! 130: KB_US,
! 131: #endif
! 132: };
! 133:
! 134: int qsckbd_input(void *, int);
! 135: int qsckbd_sendchar(void *, int);
! 136:
! 137: int
! 138: qsckbd_match(struct device *parent, void *vcf, void *aux)
! 139: {
! 140: struct qsc_attach_args *qa = aux;
! 141: struct cfdata *cf = vcf;
! 142:
! 143: if (cf->cf_loc[0] == qa->qa_line)
! 144: return 1;
! 145:
! 146: return 0;
! 147: }
! 148:
! 149: void
! 150: qsckbd_attach(struct device *parent, struct device *self, void *aux)
! 151: {
! 152: struct qsckbd_softc *sc = (void *)self;
! 153: struct qsc_attach_args *qa = aux;
! 154: struct qsckbd_internal *dzi;
! 155: struct wskbddev_attach_args a;
! 156: int isconsole;
! 157:
! 158: qa->qa_hook->fn = qsckbd_input;
! 159: qa->qa_hook->arg = self;
! 160:
! 161: isconsole = qa->qa_console;
! 162:
! 163: if (isconsole) {
! 164: dzi = &qsckbd_console_internal;
! 165: sc->sc_enabled = 1;
! 166: } else {
! 167: dzi = malloc(sizeof(struct qsckbd_internal), M_DEVBUF, M_NOWAIT);
! 168: if (dzi == NULL) {
! 169: printf(": out of memory\n");
! 170: return;
! 171: }
! 172: dzi->dzi_ks.attmt.sendchar = qsckbd_sendchar;
! 173: dzi->dzi_ks.attmt.cookie = (void *)qa->qa_line;
! 174: }
! 175: dzi->dzi_ks.device = self;
! 176: dzi->dzi_line = qa->qa_line;
! 177: sc->sc_itl = dzi;
! 178:
! 179: printf("\n");
! 180:
! 181: if (!isconsole)
! 182: lk201_init(&dzi->dzi_ks);
! 183:
! 184: a.console = dzi == &qsckbd_console_internal;
! 185: a.keymap = &qsckbd_keymapdata;
! 186: a.accessops = &qsckbd_accessops;
! 187: a.accesscookie = sc;
! 188:
! 189: sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
! 190: }
! 191:
! 192: int
! 193: qsckbd_cnattach(u_int line)
! 194: {
! 195:
! 196: qsckbd_console_internal.dzi_ks.attmt.sendchar = qsckbd_sendchar;
! 197: qsckbd_console_internal.dzi_ks.attmt.cookie = (void *)line;
! 198: lk201_init(&qsckbd_console_internal.dzi_ks);
! 199: qsckbd_console_internal.dzi_line = line;
! 200:
! 201: wskbd_cnattach(&qsckbd_consops, &qsckbd_console_internal,
! 202: &qsckbd_keymapdata);
! 203:
! 204: return 0;
! 205: }
! 206:
! 207: int
! 208: qsckbd_enable(void *v, int on)
! 209: {
! 210: struct qsckbd_softc *sc = v;
! 211:
! 212: sc->sc_enabled = on;
! 213: return 0;
! 214: }
! 215:
! 216: void
! 217: qsckbd_cngetc(void *v, u_int *type, int *data)
! 218: {
! 219: struct qsckbd_internal *dzi = v;
! 220: int c;
! 221:
! 222: do {
! 223: c = qscgetc(dzi->dzi_line);
! 224: } while (lk201_decode(&dzi->dzi_ks, 1, 0, c, type, data) == LKD_NODATA);
! 225: }
! 226:
! 227: void
! 228: qsckbd_cnpollc(void *v, int on)
! 229: {
! 230: }
! 231:
! 232: void
! 233: qsckbd_set_leds(void *v, int leds)
! 234: {
! 235: struct qsckbd_softc *sc = (struct qsckbd_softc *)v;
! 236:
! 237: lk201_set_leds(&sc->sc_itl->dzi_ks, leds);
! 238: }
! 239:
! 240: int
! 241: qsckbd_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
! 242: {
! 243: struct qsckbd_softc *sc = (struct qsckbd_softc *)v;
! 244:
! 245: switch (cmd) {
! 246: case WSKBDIO_GTYPE:
! 247: *(int *)data = lk201_get_type(&sc->sc_itl->dzi_ks);
! 248: return 0;
! 249: case WSKBDIO_SETLEDS:
! 250: lk201_set_leds(&sc->sc_itl->dzi_ks, *(int *)data);
! 251: return 0;
! 252: case WSKBDIO_GETLEDS:
! 253: *(int *)data = lk201_get_leds(&sc->sc_itl->dzi_ks);
! 254: return 0;
! 255: case WSKBDIO_COMPLEXBELL:
! 256: lk201_bell(&sc->sc_itl->dzi_ks,
! 257: (struct wskbd_bell_data *)data);
! 258: return 0;
! 259: }
! 260: return -1;
! 261: }
! 262:
! 263: int
! 264: qsckbd_input(void *v, int data)
! 265: {
! 266: struct qsckbd_softc *sc = (struct qsckbd_softc *)v;
! 267: u_int type;
! 268: int val;
! 269: int decode;
! 270:
! 271: /*
! 272: * We want to run through lk201_decode always, so that a late plugged
! 273: * keyboard will get configured correctly.
! 274: */
! 275: do {
! 276: decode = lk201_decode(&sc->sc_itl->dzi_ks, sc->sc_enabled, 1,
! 277: data, &type, &val);
! 278: if (decode != LKD_NODATA)
! 279: wskbd_input(sc->sc_wskbddev, type, val);
! 280: } while (decode == LKD_MORE);
! 281:
! 282: return(1);
! 283: }
! 284:
! 285: int
! 286: qsckbd_sendchar(void *v, int c)
! 287: {
! 288: qscputc((u_int)v, c);
! 289: return (0);
! 290: }
CVSweb