[BACK]Return to lunaws.c CVS log [TXT][DIR] Up to [local] / sys / arch / luna88k / dev

Annotation of sys/arch/luna88k/dev/lunaws.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: lunaws.c,v 1.5 2007/04/10 22:37:17 miod Exp $ */
                      2: /* $NetBSD: lunaws.c,v 1.6 2002/03/17 19:40:42 atatat Exp $ */
                      3:
                      4: /*-
                      5:  * Copyright (c) 2000 The NetBSD Foundation, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to The NetBSD Foundation
                      9:  * by Tohru Nishimura.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *     This product includes software developed by the NetBSD
                     22:  *     Foundation, Inc. and its contributors.
                     23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     24:  *    contributors may be used to endorse or promote products derived
                     25:  *    from this software without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     37:  * POSSIBILITY OF SUCH DAMAGE.
                     38:  */
                     39:
                     40: #include "wsmouse.h"
                     41:
                     42: #include <sys/param.h>
                     43: #include <sys/systm.h>
                     44: #include <sys/conf.h>
                     45: #include <sys/device.h>
                     46:
                     47: #include <dev/wscons/wsconsio.h>
                     48: #include <dev/wscons/wskbdvar.h>
                     49: #include <dev/wscons/wsksymdef.h>
                     50: #include <dev/wscons/wsksymvar.h>
                     51: #include <dev/wscons/wsmousevar.h>
                     52:
                     53: #include <luna88k/dev/sioreg.h>
                     54: #include <luna88k/dev/siovar.h>
                     55:
                     56: static const u_int8_t ch1_regs[6] = {
                     57:        WR0_RSTINT,                             /* Reset E/S Interrupt */
                     58:        WR1_RXALLS,                             /* Rx per char, No Tx */
                     59:        0,                                      /* */
                     60:        WR3_RX8BIT | WR3_RXENBL,                /* Rx */
                     61:        WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY,   /* Tx/Rx */
                     62:        WR5_TX8BIT | WR5_TXENBL,                /* Tx */
                     63: };
                     64:
                     65: struct ws_softc {
                     66:        struct device   sc_dv;
                     67:        struct sioreg   *sc_ctl;
                     68:        u_int8_t        sc_wr[6];
                     69:        struct device   *sc_wskbddev;
                     70: #if NWSMOUSE > 0
                     71:        struct device   *sc_wsmousedev;
                     72:        int             sc_msreport;
                     73:        int             buttons, dx, dy;
                     74: #endif
                     75: };
                     76:
                     77: void omkbd_input(void *, int);
                     78: void omkbd_decode(void *, int, u_int *, int *);
                     79: int  omkbd_enable(void *, int);
                     80: void omkbd_set_leds(void *, int);
                     81: int  omkbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
                     82:
                     83: struct wscons_keydesc omkbd_keydesctab[];
                     84:
                     85: const struct wskbd_mapdata omkbd_keymapdata = {
                     86:        omkbd_keydesctab,
                     87: #ifdef OMKBD_LAYOUT
                     88:        OMKBD_LAYOUT,
                     89: #else
                     90:        KB_JP,
                     91: #endif
                     92: };
                     93:
                     94: const struct wskbd_accessops omkbd_accessops = {
                     95:        omkbd_enable,
                     96:        omkbd_set_leds,
                     97:        omkbd_ioctl,
                     98: };
                     99:
                    100: void   ws_cnattach(void);
                    101: void ws_cngetc(void *, u_int *, int *);
                    102: void ws_cnpollc(void *, int);
                    103: const struct wskbd_consops ws_consops = {
                    104:        ws_cngetc,
                    105:        ws_cnpollc,
                    106:        NULL    /* bell */
                    107: };
                    108:
                    109: #if NWSMOUSE > 0
                    110: int  omms_enable(void *);
                    111: int  omms_ioctl(void *, u_long, caddr_t, int, struct proc *);
                    112: void omms_disable(void *);
                    113:
                    114: const struct wsmouse_accessops omms_accessops = {
                    115:        omms_enable,
                    116:        omms_ioctl,
                    117:        omms_disable,
                    118: };
                    119: #endif
                    120:
                    121: void wsintr(int);
                    122:
                    123: int  wsmatch(struct device *, void *, void *);
                    124: void wsattach(struct device *, struct device *, void *);
                    125: int  ws_submatch_kbd(struct device *, void *, void *);
                    126: #if NWSMOUSE > 0
                    127: int  ws_submatch_mouse(struct device *, void *, void *);
                    128: #endif
                    129:
                    130: const struct cfattach ws_ca = {
                    131:        sizeof(struct ws_softc), wsmatch, wsattach
                    132: };
                    133:
                    134: struct cfdriver ws_cd = {
                    135:         NULL, "ws", DV_TTY
                    136: };
                    137:
                    138: extern int  syscngetc(dev_t);
                    139: extern void syscnputc(dev_t, int);
                    140:
                    141: int
                    142: wsmatch(parent, match, aux)
                    143:        struct device *parent;
                    144:        void *match, *aux;
                    145: {
                    146:        struct sio_attach_args *args = aux;
                    147:
                    148:        if (args->channel != 1)
                    149:                return 0;
                    150:        return 1;
                    151: }
                    152:
                    153: void
                    154: wsattach(parent, self, aux)
                    155:        struct device *parent;
                    156:        struct device *self;
                    157:        void *aux;
                    158: {
                    159:        struct ws_softc *sc = (struct ws_softc *)self;
                    160:        struct sio_softc *scp = (struct sio_softc *)parent;
                    161:        struct sio_attach_args *args = aux;
                    162:        struct wskbddev_attach_args a;
                    163:
                    164:        sc->sc_ctl = (struct sioreg *)scp->scp_ctl + 1;
                    165:        bcopy(ch1_regs, sc->sc_wr, sizeof(ch1_regs));
                    166:        scp->scp_intr[1] = wsintr;
                    167:
                    168:        setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
                    169:        setsioreg(sc->sc_ctl, WR4, sc->sc_wr[WR4]);
                    170:        setsioreg(sc->sc_ctl, WR3, sc->sc_wr[WR3]);
                    171:        setsioreg(sc->sc_ctl, WR5, sc->sc_wr[WR5]);
                    172:        setsioreg(sc->sc_ctl, WR0, sc->sc_wr[WR0]);
                    173:        setsioreg(sc->sc_ctl, WR1, sc->sc_wr[WR1]);
                    174:
                    175:        syscnputc((dev_t)1, 0x20); /* keep quiet mouse */
                    176:
                    177:        printf("\n");
                    178:
                    179:        a.console = (args->hwflags == 1);
                    180:        a.keymap = &omkbd_keymapdata;
                    181:        a.accessops = &omkbd_accessops;
                    182:        a.accesscookie = (void *)sc;
                    183:        sc->sc_wskbddev = config_found_sm(self, &a, wskbddevprint,
                    184:                                        ws_submatch_kbd);
                    185:
                    186: #if NWSMOUSE > 0
                    187:        {
                    188:        struct wsmousedev_attach_args b;
                    189:        b.accessops = &omms_accessops;
                    190:        b.accesscookie = (void *)sc;
                    191:        sc->sc_wsmousedev = config_found_sm(self, &b, wsmousedevprint,
                    192:                                        ws_submatch_mouse);
                    193:        sc->sc_msreport = 0;
                    194:        }
                    195: #endif
                    196: }
                    197:
                    198: int
                    199: ws_submatch_kbd(parent, match, aux)
                    200:         struct device *parent;
                    201:         void *match, *aux;
                    202: {
                    203:        struct cfdata *cf = match;
                    204:
                    205:         if (strcmp(cf->cf_driver->cd_name, "wskbd"))
                    206:                 return (0);
                    207:         return ((*cf->cf_attach->ca_match)(parent, cf, aux));
                    208: }
                    209:
                    210: #if NWSMOUSE > 0
                    211:
                    212: int
                    213: ws_submatch_mouse(parent, match, aux)
                    214:         struct device *parent;
                    215:         void *match, *aux;
                    216: {
                    217:        struct cfdata *cf = match;
                    218:
                    219:         if (strcmp(cf->cf_driver->cd_name, "wsmouse"))
                    220:                 return (0);
                    221:         return ((*cf->cf_attach->ca_match)(parent, cf, aux));
                    222: }
                    223:
                    224: #endif
                    225:
                    226: /*ARGSUSED*/
                    227: void
                    228: wsintr(chan)
                    229:        int chan;
                    230: {
                    231:        struct ws_softc *sc = ws_cd.cd_devs[0];
                    232:        struct sioreg *sio = sc->sc_ctl;
                    233:        u_int code;
                    234:        int rr;
                    235:
                    236:        rr = getsiocsr(sio);
                    237:        if (rr & RR_RXRDY) {
                    238:                do {
                    239:                        code = sio->sio_data;
                    240:                        if (rr & (RR_FRAMING | RR_OVERRUN | RR_PARITY)) {
                    241:                                sio->sio_cmd = WR0_ERRRST;
                    242:                                continue;
                    243:                        }
                    244: #if NWSMOUSE > 0
                    245:                        /*
                    246:                         * if (code >= 0x80 && code <= 0x87), then
                    247:                         * it's the first byte of 3 byte long mouse report
                    248:                         *      code[0] & 07 -> LMR button condition
                    249:                         *      code[1], [2] -> x,y delta
                    250:                         * otherwise, key press or release event.
                    251:                         */
                    252:                        if (sc->sc_msreport == 0) {
                    253:                                if (code < 0x80 || code > 0x87) {
                    254:                                        omkbd_input(sc, code);
                    255:                                        continue;
                    256:                                }
                    257:                                code = (code & 07) ^ 07;
                    258:                                /* LMR->RML: wsevent counts 0 for leftmost */
                    259:                                sc->buttons = (code & 02);
                    260:                                if (code & 01)
                    261:                                        sc->buttons |= 04;
                    262:                                if (code & 04)
                    263:                                        sc->buttons |= 01;
                    264:                                sc->sc_msreport = 1;
                    265:                        }
                    266:                        else if (sc->sc_msreport == 1) {
                    267:                                sc->dx = (signed char)code;
                    268:                                sc->sc_msreport = 2;
                    269:                        }
                    270:                        else if (sc->sc_msreport == 2) {
                    271:                                sc->dy = (signed char)code;
                    272:                                if (sc->sc_wsmousedev != NULL)
                    273:                                        wsmouse_input(sc->sc_wsmousedev,
                    274:                                            sc->buttons, sc->dx, sc->dy, 0, 0,
                    275:                                            WSMOUSE_INPUT_DELTA);
                    276:                                sc->sc_msreport = 0;
                    277:                        }
                    278: #else
                    279:                        omkbd_input(sc, code);
                    280: #endif
                    281:                } while ((rr = getsiocsr(sio)) & RR_RXRDY);
                    282:        }
                    283:        if (rr && RR_TXRDY)
                    284:                sio->sio_cmd = WR0_RSTPEND;
                    285:        /* not capable of transmit, yet */
                    286: }
                    287:
                    288: void
                    289: omkbd_input(v, data)
                    290:        void *v;
                    291:        int data;
                    292: {
                    293:        struct ws_softc *sc = v;
                    294:        u_int type;
                    295:        int key;
                    296:
                    297:        omkbd_decode(v, data, &type, &key);
                    298:        if (sc->sc_wskbddev != NULL)
                    299:                wskbd_input(sc->sc_wskbddev, type, key);
                    300: }
                    301:
                    302: void
                    303: omkbd_decode(v, datain, type, dataout)
                    304:        void *v;
                    305:        int datain;
                    306:        u_int *type;
                    307:        int *dataout;
                    308: {
                    309:        *type = (datain & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
                    310:        *dataout = datain & 0x7f;
                    311: }
                    312:
                    313: #define KC(n) KS_KEYCODE(n)
                    314:
                    315: static const keysym_t omkbd_keydesc_1[] = {
                    316: /*  pos      command           normal          shifted */
                    317:     KC(0x9),                   KS_Tab,
                    318:     KC(0xa),                   KS_Control_L,
                    319:     KC(0xb),                   KS_Mode_switch, /* Kana */
                    320:     KC(0xc),                   KS_Shift_R,
                    321:     KC(0xd),                   KS_Shift_L,
                    322:     KC(0xe),                   KS_Caps_Lock,
                    323:     KC(0xf),                   KS_Meta_L,      /* Zenmen */
                    324:     KC(0x10),                  KS_Escape,
                    325:     KC(0x11),                  KS_BackSpace,
                    326:     KC(0x12),                  KS_Return,
                    327:     KC(0x14),                  KS_space,
                    328:     KC(0x15),                  KS_Delete,
                    329:     KC(0x16),                  KS_Alt_L,       /* Henkan */
                    330:     KC(0x17),                  KS_Alt_R,       /* Kakutei */
                    331:     KC(0x18),                  KS_f11,         /* Shokyo */
                    332:     KC(0x19),                  KS_f12,         /* Yobidashi */
                    333:     KC(0x1a),                  KS_f13,         /* Bunsetsu L */
                    334:     KC(0x1b),                  KS_f14,         /* Bunsetsu R */
                    335:     KC(0x1c),                  KS_KP_Up,
                    336:     KC(0x1d),                  KS_KP_Left,
                    337:     KC(0x1e),                  KS_KP_Right,
                    338:     KC(0x1f),                  KS_KP_Down,
                    339:  /* KC(0x20),                  KS_f11, */
                    340:  /* KC(0x21),                  KS_f12, */
                    341:     KC(0x22),                          KS_1,           KS_exclam,
                    342:     KC(0x23),                  KS_2,           KS_quotedbl,
                    343:     KC(0x24),                  KS_3,           KS_numbersign,
                    344:     KC(0x25),                  KS_4,           KS_dollar,
                    345:     KC(0x26),                  KS_5,           KS_percent,
                    346:     KC(0x27),                  KS_6,           KS_ampersand,
                    347:     KC(0x28),                  KS_7,           KS_apostrophe,
                    348:     KC(0x29),                  KS_8,           KS_parenleft,
                    349:     KC(0x2a),                  KS_9,           KS_parenright,
                    350:     KC(0x2b),                  KS_0,
                    351:     KC(0x2c),                  KS_minus,       KS_equal,
                    352:     KC(0x2d),                  KS_asciicircum, KS_asciitilde,
                    353:     KC(0x2e),                  KS_backslash,   KS_bar,
                    354:  /* KC(0x30),                  KS_f13, */
                    355:  /* KC(0x31),                  KS_f14, */
                    356:     KC(0x32),                  KS_q,
                    357:     KC(0x33),                  KS_w,
                    358:     KC(0x34),                  KS_e,
                    359:     KC(0x35),                  KS_r,
                    360:     KC(0x36),                  KS_t,
                    361:     KC(0x37),                  KS_y,
                    362:     KC(0x38),                  KS_u,
                    363:     KC(0x39),                  KS_i,
                    364:     KC(0x3a),                  KS_o,
                    365:     KC(0x3b),                  KS_p,
                    366:     KC(0x3c),                  KS_at,          KS_grave,
                    367:     KC(0x3d),                  KS_bracketleft, KS_braceleft,
                    368:     KC(0x42),                  KS_a,
                    369:     KC(0x43),                  KS_s,
                    370:     KC(0x44),                  KS_d,
                    371:     KC(0x45),                  KS_f,
                    372:     KC(0x46),                  KS_g,
                    373:     KC(0x47),                  KS_h,
                    374:     KC(0x48),                  KS_j,
                    375:     KC(0x49),                  KS_k,
                    376:     KC(0x4a),                  KS_l,
                    377:     KC(0x4b),                  KS_semicolon,   KS_plus,
                    378:     KC(0x4c),                  KS_colon,       KS_asterisk,
                    379:     KC(0x4d),                  KS_bracketright, KS_braceright,
                    380:     KC(0x52),                  KS_z,
                    381:     KC(0x53),                  KS_x,
                    382:     KC(0x54),                  KS_c,
                    383:     KC(0x55),                  KS_v,
                    384:     KC(0x56),                  KS_b,
                    385:     KC(0x57),                  KS_n,
                    386:     KC(0x58),                  KS_m,
                    387:     KC(0x59),                  KS_comma,       KS_less,
                    388:     KC(0x5a),                  KS_period,      KS_greater,
                    389:     KC(0x5b),                  KS_slash,       KS_question,
                    390:     KC(0x5c),                  KS_underscore,
                    391:     KC(0x60),                  KS_KP_Delete,
                    392:     KC(0x61),                  KS_KP_Add,
                    393:     KC(0x62),                  KS_KP_Subtract,
                    394:     KC(0x63),                  KS_KP_7,
                    395:     KC(0x64),                  KS_KP_8,
                    396:     KC(0x65),                  KS_KP_9,
                    397:     KC(0x66),                  KS_KP_4,
                    398:     KC(0x67),                  KS_KP_5,
                    399:     KC(0x68),                  KS_KP_6,
                    400:     KC(0x69),                  KS_KP_1,
                    401:     KC(0x6a),                  KS_KP_2,
                    402:     KC(0x6b),                  KS_KP_3,
                    403:     KC(0x6c),                  KS_KP_0,
                    404:     KC(0x6d),                  KS_KP_Decimal,
                    405:     KC(0x6e),                  KS_KP_Enter,
                    406:     KC(0x72),                  KS_f1,
                    407:     KC(0x73),                  KS_f2,
                    408:     KC(0x74),                  KS_f3,
                    409:     KC(0x75),                  KS_f4,
                    410:     KC(0x76),                  KS_f5,
                    411:     KC(0x77),                  KS_f6,
                    412:     KC(0x78),                  KS_f7,
                    413:     KC(0x79),                  KS_f8,
                    414:     KC(0x7a),                  KS_f9,
                    415:     KC(0x7b),                  KS_f10,
                    416:     KC(0x7c),                  KS_KP_Multiply,
                    417:     KC(0x7d),                  KS_KP_Divide,
                    418:     KC(0x7e),                  KS_KP_Equal,
                    419:     KC(0x7f),                  KS_KP_Separator,
                    420: };
                    421:
                    422: #define        SIZE(map) (sizeof(map)/sizeof(keysym_t))
                    423:
                    424: struct wscons_keydesc omkbd_keydesctab[] = {
                    425:        { KB_JP, 0, SIZE(omkbd_keydesc_1), omkbd_keydesc_1, },
                    426:        { 0, 0, 0, 0 },
                    427: };
                    428:
                    429: void
                    430: ws_cngetc(v, type, data)
                    431:        void *v;
                    432:        u_int *type;
                    433:        int *data;
                    434: {
                    435:        int code;
                    436:
                    437:        code = syscngetc((dev_t)1);
                    438:        omkbd_decode(v, code, type, data);
                    439: }
                    440:
                    441: void
                    442: ws_cnpollc(v, on)
                    443:        void *v;
                    444:         int on;
                    445: {
                    446: }
                    447:
                    448: /* EXPORT */ void
                    449: ws_cnattach()
                    450: {
                    451:        static int voidfill;
                    452:
                    453:        /* XXX need CH.B initialization XXX */
                    454:
                    455:        wskbd_cnattach(&ws_consops, &voidfill, &omkbd_keymapdata);
                    456: }
                    457:
                    458: int
                    459: omkbd_enable(v, on)
                    460:        void *v;
                    461:        int on;
                    462: {
                    463:        return 0;
                    464: }
                    465:
                    466: void
                    467: omkbd_set_leds(v, leds)
                    468:        void *v;
                    469:        int leds;
                    470: {
                    471: #if 0
                    472:        syscnputc((dev_t)1, 0x10); /* kana LED on */
                    473:        syscnputc((dev_t)1, 0x00); /* kana LED off */
                    474:        syscnputc((dev_t)1, 0x11); /* caps LED on */
                    475:        syscnputc((dev_t)1, 0x01); /* caps LED off */
                    476: #endif
                    477: }
                    478:
                    479: int
                    480: omkbd_ioctl(v, cmd, data, flag, p)
                    481:        void *v;
                    482:        u_long cmd;
                    483:        caddr_t data;
                    484:        int flag;
                    485:        struct proc *p;
                    486: {
                    487: #if 0
                    488:        struct ws_softc *sc = v;
                    489: #endif
                    490:
                    491:        switch (cmd) {
                    492:        case WSKBDIO_GTYPE:
                    493:                *(int *)data = WSKBD_TYPE_LUNA;
                    494:                return 0;
                    495:        case WSKBDIO_SETLEDS:
                    496:        case WSKBDIO_GETLEDS:
                    497:        case WSKBDIO_COMPLEXBELL:       /* XXX capable of complex bell */
                    498:                return -1;
                    499:        }
                    500:        return -1;
                    501: }
                    502:
                    503: #if NWSMOUSE > 0
                    504:
                    505: int
                    506: omms_enable(v)
                    507:        void *v;
                    508: {
                    509:        struct ws_softc *sc = v;
                    510:
                    511:        syscnputc((dev_t)1, 0x60); /* enable 3 byte long mouse reporting */
                    512:        sc->sc_msreport = 0;
                    513:        return 0;
                    514: }
                    515:
                    516: /*ARGUSED*/
                    517: int
                    518: omms_ioctl(v, cmd, data, flag, p)
                    519:        void *v;
                    520:        u_long cmd;
                    521:        caddr_t data;
                    522:        int flag;
                    523:        struct proc *p;
                    524: {
                    525: #if 0
                    526:        struct ws_softc *sc = v;
                    527: #endif
                    528:
                    529:        switch (cmd) {
                    530:        case WSMOUSEIO_GTYPE:
                    531:                *(u_int *)data = WSMOUSE_TYPE_LUNA;
                    532:                return 0;
                    533:        }
                    534:
                    535:        return -1;
                    536: }
                    537:
                    538: void
                    539: omms_disable(v)
                    540:        void *v;
                    541: {
                    542:        struct ws_softc *sc = v;
                    543:
                    544:        syscnputc((dev_t)1, 0x20); /* quiet mouse */
                    545:        sc->sc_msreport = 0;
                    546: }
                    547: #endif

CVSweb