[BACK]Return to dzkbd.c CVS log [TXT][DIR] Up to [local] / sys / arch / vax / dec

Annotation of sys/arch/vax/dec/dzkbd.c, Revision 1.1

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

CVSweb