Home | History | Annotate | Line # | Download | only in dev
kbd.c revision 1.35
      1 /*	$NetBSD: kbd.c,v 1.35 2001/02/02 21:52:11 is Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	kbd.c
     36  */
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/tty.h>
     42 #include <sys/proc.h>
     43 #include <sys/file.h>
     44 #include <sys/kernel.h>
     45 #include <sys/syslog.h>
     46 #include <sys/signalvar.h>
     47 #include <dev/cons.h>
     48 #include <machine/cpu.h>
     49 #include <amiga/amiga/device.h>
     50 #include <amiga/amiga/custom.h>
     51 #ifdef DRACO
     52 #include <m68k/asm_single.h>
     53 #include <amiga/amiga/drcustom.h>
     54 #endif
     55 #include <amiga/amiga/cia.h>
     56 #include <amiga/dev/itevar.h>
     57 #include <amiga/dev/kbdreg.h>
     58 #include <amiga/dev/kbdmap.h>
     59 #include <amiga/dev/event_var.h>
     60 #include <amiga/dev/vuid_event.h>
     61 
     62 #include "kbd.h"
     63 #include "ite.h"
     64 
     65 /* WSKBD */
     66 
     67 /*
     68  * If NWSKBD>0 we try to attach an wskbd device to us. What follows
     69  * is definitions of callback functions and structures that are passed
     70  * to wscons when initializing.
     71  */
     72 
     73 #include "wskbd.h"
     74 
     75 #if NWSKBD>0
     76 #include <dev/wscons/wsconsio.h>
     77 #include <dev/wscons/wskbdvar.h>
     78 #include <dev/wscons/wsksymdef.h>
     79 #include <dev/wscons/wsksymvar.h>
     80 #include <amiga/dev/wskbdmap_amiga.h>
     81 
     82 /* accessops */
     83 int     kbd_enable    __P((void *, int));
     84 void    kbd_set_leds  __P((void *, int));
     85 int     kbd_ioctl     __P((void *, u_long, caddr_t, int, struct proc *));
     86 
     87 /* console ops */
     88 void    kbd_getc      __P((void *, u_int *, int *));
     89 void    kbd_pollc     __P((void *, int));
     90 void    kbd_bell      __P((void *, u_int, u_int, u_int));
     91 
     92 static struct wskbd_accessops kbd_accessops = {
     93 	kbd_enable,
     94 	kbd_set_leds,
     95 	kbd_ioctl
     96 };
     97 
     98 static struct wskbd_consops kbd_consops = {
     99 	kbd_getc,
    100 	kbd_pollc,
    101 	kbd_bell
    102 };
    103 
    104 /*
    105  * Pointer to keymap. It is defined in wskbdmap_amiga.c.
    106  */
    107 static struct wskbd_mapdata kbd_mapdata = {
    108 	amigakbd_keydesctab,
    109 	KB_US
    110 };
    111 
    112 #endif /* WSKBD */
    113 
    114 
    115 #include <sys/conf.h>
    116 #include <machine/conf.h>
    117 
    118 struct kbd_softc {
    119 	int k_event_mode;	/* if true, collect events, else pass to ite */
    120 	struct evvar k_events;	/* event queue state */
    121 #ifdef DRACO
    122 	u_char k_rlprfx;	/* MF-II rel. prefix has been seen */
    123 	u_char k_mf2;
    124 #endif
    125 
    126 #if NWSKBD>0
    127 	struct device *k_wskbddev; /* pointer to wskbd for sending strokes */
    128 	int k_pollingmode;         /* polling mode on? whatever it isss... */
    129 #endif
    130 };
    131 struct kbd_softc kbd_softc;
    132 
    133 int kbdmatch __P((struct device *, struct cfdata *, void *));
    134 void kbdattach __P((struct device *, struct device *, void *));
    135 void kbdintr __P((int));
    136 void kbdstuffchar __P((u_char));
    137 
    138 int drkbdgetc __P((void));
    139 int drkbdrputc __P((int));
    140 int drkbdputc __P((int));
    141 int drkbdputc2 __P((int, int));
    142 int drkbdwaitfor __P((int));
    143 
    144 struct cfattach kbd_ca = {
    145 	sizeof(struct device), kbdmatch, kbdattach
    146 };
    147 
    148 /*ARGSUSED*/
    149 int
    150 kbdmatch(pdp, cfp, auxp)
    151 	struct device *pdp;
    152 	struct cfdata *cfp;
    153 	void *auxp;
    154 {
    155 
    156 	if (matchname((char *)auxp, "kbd"))
    157 		return(1);
    158 	return(0);
    159 }
    160 
    161 /*ARGSUSED*/
    162 void
    163 kbdattach(pdp, dp, auxp)
    164 	struct device *pdp, *dp;
    165 	void *auxp;
    166 {
    167 #ifdef DRACO
    168 	kbdenable();
    169 	if (kbd_softc.k_mf2)
    170 		printf(": QuickLogic type MF-II\n");
    171 	else
    172 		printf(": CIA A type Amiga\n");
    173 #else
    174 	printf(": CIA A type Amiga\n");
    175 #endif
    176 
    177 #if NWSKBD>0
    178 	if (dp != NULL) {
    179 		/*
    180 		 * Try to attach the wskbd.
    181 		 */
    182 		struct wskbddev_attach_args waa;
    183 
    184 		/* Maybe should be done before this?... */
    185 		wskbd_cnattach(&kbd_consops, NULL, &kbd_mapdata);
    186 
    187 		waa.console = 1;
    188 		waa.keymap = &kbd_mapdata;
    189 		waa.accessops = &kbd_accessops;
    190 		waa.accesscookie = NULL;
    191 		kbd_softc.k_wskbddev = config_found(dp, &waa, wskbddevprint);
    192 
    193 		kbd_softc.k_pollingmode = 0;
    194 	}
    195 	kbdenable();
    196 #endif /* WSKBD */
    197 }
    198 
    199 /* definitions for amiga keyboard encoding. */
    200 #define KEY_CODE(c)  ((c) & 0x7f)
    201 #define KEY_UP(c)    ((c) & 0x80)
    202 
    203 #define DATLO single_inst_bclr_b(draco_ioct->io_control, DRCNTRL_KBDDATOUT)
    204 #define DATHI single_inst_bset_b(draco_ioct->io_control, DRCNTRL_KBDDATOUT)
    205 
    206 #define CLKLO single_inst_bclr_b(draco_ioct->io_control, DRCNTRL_KBDCLKOUT)
    207 #define CLKHI single_inst_bset_b(draco_ioct->io_control, DRCNTRL_KBDCLKOUT)
    208 
    209 void
    210 kbdenable()
    211 {
    212 	static int kbd_inited = 0;
    213 
    214 	int s;
    215 
    216 #ifdef DRACO
    217 	int id;
    218 #endif
    219 	/*
    220 	 * collides with external ints from SCSI, watch out for this when
    221 	 * enabling/disabling interrupts there !!
    222 	 */
    223 	s = splhigh();	/* don't lower; might be called from early ddb */
    224 	if (kbd_inited) {
    225 		splx(s);
    226 		return;
    227 	}
    228 	kbd_inited = 1;
    229 #ifdef DRACO
    230 	if (is_draco()) {
    231 
    232 		CLKLO;
    233 		delay(5000);
    234 		draco_ioct->io_kbdrst = 0;
    235 
    236 		if (drkbdputc(0xf2))
    237 			goto LnoMFII;
    238 
    239 		id = drkbdgetc() << 8;
    240 		id |= drkbdgetc();
    241 
    242 		if (id != 0xab83)
    243 			goto LnoMFII;
    244 
    245 		if (drkbdputc2(0xf0, 3))	/* mode 3 */
    246 			goto LnoMFII;
    247 
    248 		if (drkbdputc(0xf8))		/* make/break, no typematic */
    249 			goto LnoMFII;
    250 
    251 		if (drkbdputc(0xf4))		/* enable */
    252 			goto LnoMFII;
    253 		kbd_softc.k_mf2 = 1;
    254 		single_inst_bclr_b(draco_ioct->io_control, DRCNTRL_KBDINTENA);
    255 
    256 		ciaa.icr = CIA_ICR_SP;  /* CIA SP interrupt disable */
    257 		ciaa.cra &= ~(1<<6);	/* serial line == input */
    258 		splx(s);
    259 		return;
    260 
    261 	LnoMFII:
    262 		kbd_softc.k_mf2 = 0;
    263 		single_inst_bset_b(*draco_intena, DRIRQ_INT2);
    264 		ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_SP;
    265 					/* SP interrupt enable */
    266 		ciaa.cra &= ~(1<<6);	/* serial line == input */
    267 		splx(s);
    268 		return;
    269 
    270 	} else {
    271 #endif
    272 	custom.intena = INTF_SETCLR | INTF_PORTS;
    273 	ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_SP;  /* SP interrupt enable */
    274 	ciaa.cra &= ~(1<<6);		/* serial line == input */
    275 #ifdef DRACO
    276 	}
    277 #endif
    278 	kbd_softc.k_event_mode = 0;
    279 	kbd_softc.k_events.ev_io = 0;
    280 	splx(s);
    281 }
    282 
    283 #ifdef DRACO
    284 /*
    285  * call this with kbd interupt blocked
    286  */
    287 
    288 int
    289 drkbdgetc()
    290 {
    291 	u_int8_t in;
    292 
    293 	while ((draco_ioct->io_status & DRSTAT_KBDRECV) == 0);
    294 	in = draco_ioct->io_kbddata;
    295 	draco_ioct->io_kbdrst = 0;
    296 
    297 	return in;
    298 }
    299 
    300 #define WAIT0 if (drkbdwaitfor(0)) goto Ltimeout
    301 #define WAIT1 if (drkbdwaitfor(DRSTAT_KBDCLKIN)) goto Ltimeout
    302 
    303 int
    304 drkbdwaitfor(bit)
    305 	int bit;
    306 {
    307 	int i;
    308 
    309 
    310 
    311 	i = 60000;	/* about 50 ms max */
    312 
    313 	do {
    314 		if ((draco_ioct->io_status & DRSTAT_KBDCLKIN) == bit)
    315 			return 0;
    316 
    317 	} while (--i >= 0);
    318 
    319 	return 1;
    320 }
    321 
    322 /*
    323  * Output a raw byte to the keyboard (+ parity and stop bit).
    324  * return 0 on success, 1 on timeout.
    325  */
    326 int
    327 drkbdrputc(c)
    328 	u_int8_t c;
    329 {
    330 	u_int8_t parity;
    331 	int bitcnt;
    332 
    333 	DATLO; CLKHI; WAIT1;
    334 	parity = 0;
    335 
    336 	for (bitcnt=7; bitcnt >= 0; bitcnt--) {
    337 		WAIT0;
    338 		if (c & 1) {
    339 			DATHI;
    340 		} else {
    341 			++parity;
    342 			DATLO;
    343 		}
    344 		c >>= 1;
    345 		WAIT1;
    346 	}
    347 	WAIT0;
    348 	/* parity bit */
    349 	if (parity & 1) {
    350 		DATLO;
    351 	} else {
    352 		DATHI;
    353 	}
    354 	WAIT1;
    355 	/* stop bit */
    356 	WAIT0; DATHI; WAIT1;
    357 
    358 	WAIT0; /* XXX should check the ack bit here... */
    359 	WAIT1;
    360 	draco_ioct->io_kbdrst = 0;
    361 	return 0;
    362 
    363 Ltimeout:
    364 	DATHI;
    365 	draco_ioct->io_kbdrst = 0;
    366 	return 1;
    367 }
    368 
    369 /*
    370  * Output one cooked byte to the keyboard, with wait for ACK or RESEND,
    371  * and retry if necessary. 0 == success, 1 == timeout
    372  */
    373 int
    374 drkbdputc(c)
    375 	u_int8_t c;
    376 {
    377 	int rc;
    378 
    379 	do {
    380 		if (drkbdrputc(c))
    381 			return(-1);
    382 
    383 		rc = drkbdgetc();
    384 	} while (rc == 0xfe);
    385 	return (!(rc == 0xfa));
    386 }
    387 
    388 /*
    389  * same for twobyte sequence
    390  */
    391 
    392 int
    393 drkbdputc2(c1, c2)
    394 	u_int8_t c1, c2;
    395 {
    396 	int rc;
    397 
    398 	do {
    399 		do {
    400 			if (drkbdrputc(c1))
    401 				return(-1);
    402 
    403 			rc = drkbdgetc();
    404 		} while (rc == 0xfe);
    405 		if (rc != 0xfa)
    406 			return (-1);
    407 
    408 		if (drkbdrputc(c2))
    409 			return(-1);
    410 
    411 		rc = drkbdgetc();
    412 	} while (rc == 0xfe);
    413 	return (!(rc == 0xfa));
    414 }
    415 #endif
    416 
    417 int
    418 kbdopen(dev, flags, mode, p)
    419 	dev_t dev;
    420 	int flags, mode;
    421 	struct proc *p;
    422 {
    423 
    424 	kbdenable();
    425 	if (kbd_softc.k_events.ev_io)
    426 		return EBUSY;
    427 
    428 	kbd_softc.k_events.ev_io = p;
    429 	ev_init(&kbd_softc.k_events);
    430 	return (0);
    431 }
    432 
    433 int
    434 kbdclose(dev, flags, mode, p)
    435 	dev_t dev;
    436 	int flags, mode;
    437 	struct proc *p;
    438 {
    439 
    440 	/* Turn off event mode, dump the queue */
    441 	kbd_softc.k_event_mode = 0;
    442 	ev_fini(&kbd_softc.k_events);
    443 	kbd_softc.k_events.ev_io = NULL;
    444 	return (0);
    445 }
    446 
    447 int
    448 kbdread(dev, uio, flags)
    449 	dev_t dev;
    450 	struct uio *uio;
    451 	int flags;
    452 {
    453 	return ev_read (&kbd_softc.k_events, uio, flags);
    454 }
    455 
    456 int
    457 kbdioctl(dev, cmd, data, flag, p)
    458 	dev_t dev;
    459 	u_long cmd;
    460 	register caddr_t data;
    461 	int flag;
    462 	struct proc *p;
    463 {
    464 	register struct kbd_softc *k = &kbd_softc;
    465 
    466 	switch (cmd) {
    467 		case KIOCTRANS:
    468 			if (*(int *)data == TR_UNTRANS_EVENT)
    469 				return 0;
    470 			break;
    471 
    472 		case KIOCGTRANS:
    473 			/* Get translation mode */
    474 			*(int *)data = TR_UNTRANS_EVENT;
    475 			return 0;
    476 
    477 		case KIOCSDIRECT:
    478 			k->k_event_mode = *(int *)data;
    479 			return 0;
    480 
    481 		case FIONBIO:	/* we will remove this someday (soon???) */
    482 			return 0;
    483 
    484 		case FIOASYNC:
    485 			k->k_events.ev_async = *(int *)data != 0;
    486 			return 0;
    487 
    488 		case TIOCSPGRP:
    489 			if (*(int *)data != k->k_events.ev_io->p_pgid)
    490 				return EPERM;
    491 			return 0;
    492 
    493 		default:
    494 			return ENOTTY;
    495 	}
    496 
    497 	/* We identified the ioctl, but we do not handle it. */
    498 	return EOPNOTSUPP;	/* misuse, but what the heck */
    499 }
    500 
    501 int
    502 kbdpoll(dev, events, p)
    503 	dev_t dev;
    504 	int events;
    505 	struct proc *p;
    506 {
    507 	return ev_poll (&kbd_softc.k_events, events, p);
    508 }
    509 
    510 
    511 void
    512 kbdintr(mask)
    513 	int mask;
    514 {
    515 	u_char c;
    516 #ifdef KBDRESET
    517 	static int reset_warn;
    518 #endif
    519 
    520 	/*
    521 	 * now only invoked from generic CIA interrupt handler if there *is*
    522 	 * a keyboard interrupt pending
    523 	 */
    524 
    525 	c = ~ciaa.sdr;	/* keyboard data is inverted */
    526 	/* ack */
    527 	ciaa.cra |= (1 << 6);	/* serial line output */
    528 #ifdef KBDRESET
    529 	if (reset_warn && c == 0xf0) {
    530 #ifdef DEBUG
    531 		printf ("kbdintr: !!!! Reset Warning !!!!\n");
    532 #endif
    533 		bootsync();
    534 		reset_warn = 0;
    535 		DELAY(30000000);
    536 	}
    537 #endif
    538 	/* wait 200 microseconds (for bloody Cherry keyboards..) */
    539 	DELAY(2000);			/* fudge delay a bit for some keyboards */
    540 	ciaa.cra &= ~(1 << 6);
    541 
    542 	/* process the character */
    543 	c = (c >> 1) | (c << 7);	/* rotate right once */
    544 
    545 #ifdef KBDRESET
    546 	if (c == 0x78) {
    547 #ifdef DEBUG
    548 		printf ("kbdintr: Reset Warning started\n");
    549 #endif
    550 		++reset_warn;
    551 		return;
    552 	}
    553 #endif
    554 	kbdstuffchar(c);
    555 }
    556 
    557 #ifdef DRACO
    558 /* maps MF-II keycodes to Amiga keycodes */
    559 
    560 const u_char drkbdtab[] = {
    561 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50,
    562 	0x45, 0xff, 0xff, 0xff, 0xff, 0x42, 0x00, 0x51,
    563 
    564 	0xff, 0x64, 0x60, 0x30, 0x63, 0x10, 0x01, 0x52,
    565 	0xff, 0x66, 0x31, 0x21, 0x20, 0x11, 0x02, 0x53,
    566 
    567 	0xff, 0x33, 0x32, 0x22, 0x12, 0x04, 0x03, 0x54,
    568 	0xff, 0x40, 0x34, 0x23, 0x14, 0x13, 0x05, 0x55,
    569 
    570 	0xff, 0x36, 0x35, 0x25, 0x24, 0x15, 0x06, 0x56,
    571 	0xff, 0x67, 0x37, 0x26, 0x16, 0x07, 0x08, 0x57,
    572 	/* --- */
    573 	0xff, 0x38, 0x27, 0x17, 0x18, 0x0a, 0x09, 0x58,
    574 	0xff, 0x39, 0x3a, 0x28, 0x29, 0x19, 0x0b, 0x59,
    575 
    576 	0xff, 0xff, 0x2a, 0x2b, 0x1a, 0x0c, 0x4b, 0xff,
    577 	0x65, 0x61, 0x44, 0x1b, 0xff, 0xff, 0x6f, 0xff,
    578 
    579 	0x4d, 0x4f, 0xff, 0x4c, 0x0d, 0xff, 0x41, 0x46,
    580 	0xff, 0x1d, 0x4e, 0x2d, 0x3d, 0x4a, 0x5f, 0x62,
    581 
    582 	0x0f, 0x3c, 0x1e, 0x2e, 0x2f, 0x3e, 0x5a, 0x5b,
    583 	0xff, 0x43, 0x1f, 0xff, 0x5e, 0x3f, 0x5c, 0xff,
    584 	/* --- */
    585 	0xff, 0xff, 0xff, 0xff, 0x5d
    586 };
    587 #endif
    588 
    589 
    590 int
    591 kbdgetcn ()
    592 {
    593 	int s;
    594 	u_char ints, mask, c, in;
    595 
    596 #ifdef DRACO
    597 	if (is_draco() && kbd_softc.k_mf2) {
    598 		do {
    599 			c = 0;
    600 			s = spltty ();
    601 			while ((draco_ioct->io_status & DRSTAT_KBDRECV) == 0);
    602 			in = draco_ioct->io_kbddata;
    603 			draco_ioct->io_kbdrst = 0;
    604 			if (in == 0xF0) { /* release prefix */
    605 				c = 0x80;
    606 				while ((draco_ioct->io_status &
    607 				    DRSTAT_KBDRECV) == 0);
    608 				in = draco_ioct->io_kbddata;
    609 				draco_ioct->io_kbdrst = 0;
    610 			}
    611 			splx(s);
    612 #ifdef DRACORAWKEYDEBUG
    613 			printf("<%02x>", in);
    614 #endif
    615 			c |= in>=sizeof(drkbdtab) ? 0xff : drkbdtab[in];
    616 		} while (c == 0xff);
    617 		return (c);
    618 	}
    619 #endif
    620 	s = spltty();
    621 	for (ints = 0; ! ((mask = ciaa.icr) & CIA_ICR_SP);
    622 	    ints |= mask) ;
    623 
    624 	in = ciaa.sdr;
    625 	c = ~in;
    626 
    627 	/* ack */
    628 	ciaa.cra |= (1 << 6);	/* serial line output */
    629 	ciaa.sdr = 0xff;	/* ack */
    630 	/* wait 200 microseconds */
    631 	DELAY(2000);	/* XXXX only works as long as DELAY doesn't
    632 			 * use a timer and waits.. */
    633 	ciaa.cra &= ~(1 << 6);
    634 	ciaa.sdr = in;
    635 
    636 	splx (s);
    637 	c = (c >> 1) | (c << 7);
    638 
    639 	/* take care that no CIA-interrupts are lost */
    640 	if (ints)
    641 		dispatch_cia_ints (0, ints);
    642 
    643 	return c;
    644 }
    645 
    646 void
    647 kbdstuffchar(c)
    648 	u_char c;
    649 {
    650 	struct firm_event *fe;
    651 	struct kbd_softc *k = &kbd_softc;
    652 	int put;
    653 
    654 #if NWSKBD>0
    655 	/*
    656 	 * If we have attached a wskbd and not in polling mode and
    657 	 * nobody has opened us directly, then send the keystroke
    658 	 * to the wskbd.
    659 	 */
    660 
    661 	if (kbd_softc.k_pollingmode == 0
    662 	    && kbd_softc.k_wskbddev != NULL
    663 	    && k->k_event_mode == 0) {
    664 		wskbd_input(kbd_softc.k_wskbddev,
    665 			    KEY_UP(c) ?
    666 			    WSCONS_EVENT_KEY_UP :
    667 			    WSCONS_EVENT_KEY_DOWN,
    668 			    KEY_CODE(c));
    669 		return;
    670 	}
    671 
    672 #endif /* NWSKBD */
    673 
    674 	/*
    675 	 * If not in event mode, deliver straight to ite to process
    676 	 * key stroke
    677 	 */
    678 
    679 	if (! k->k_event_mode) {
    680 #if NITE>0
    681 		ite_filter (c, ITEFILT_TTY);
    682 #endif
    683 		return;
    684 	}
    685 
    686 	/*
    687 	 * Keyboard is generating events. Turn this keystroke into an
    688 	 * event and put it in the queue. If the queue is full, the
    689 	 * keystroke is lost (sorry!).
    690 	 */
    691 
    692 	put = k->k_events.ev_put;
    693 	fe = &k->k_events.ev_q[put];
    694 	put = (put + 1) % EV_QSIZE;
    695 	if (put == k->k_events.ev_get) {
    696 		log(LOG_WARNING, "keyboard event queue overflow\n");
    697 			/* ??? */
    698 		return;
    699 	}
    700 	fe->id = KEY_CODE(c);
    701 	fe->value = KEY_UP(c) ? VKEY_UP : VKEY_DOWN;
    702 	fe->time = time;
    703 	k->k_events.ev_put = put;
    704 	EV_WAKEUP(&k->k_events);
    705 }
    706 
    707 
    708 #ifdef DRACO
    709 void
    710 drkbdintr()
    711 {
    712 	u_char in;
    713 	struct kbd_softc *k = &kbd_softc;
    714 
    715 	in = draco_ioct->io_kbddata;
    716 	draco_ioct->io_kbdrst = 0;
    717 
    718 	if (in == 0xF0)
    719 		k->k_rlprfx = 0x80;
    720 	else {
    721 		kbdstuffchar(in>=sizeof(drkbdtab) ? 0xff :
    722 		    drkbdtab[in] | k->k_rlprfx);
    723 		k->k_rlprfx = 0;
    724 	}
    725 }
    726 
    727 #endif
    728 
    729 
    730 #if NWSKBD>0
    731 /*
    732  * These are the callback functions that are passed to wscons.
    733  * They really don't do anything worth noting, just call the
    734  * other functions above.
    735  */
    736 
    737 int
    738 kbd_enable(c, on)
    739 	void *c;
    740 	int   on;
    741 {
    742 	/* Wonder what this is supposed to do... */
    743 	return (0);
    744 }
    745 
    746 void
    747 kbd_set_leds(c, leds)
    748 	void *c;
    749 	int   leds;
    750 {
    751 }
    752 
    753 int
    754 kbd_ioctl(c, cmd, data, flag, p)
    755 	void        *c;
    756 	u_long       cmd;
    757 	caddr_t      data;
    758 	int          flag;
    759 	struct proc *p;
    760 {
    761 	switch (cmd)
    762 	{
    763 	case WSKBDIO_COMPLEXBELL:
    764 		return 0;
    765 	case WSKBDIO_SETLEDS:
    766 		return 0;
    767 	case WSKBDIO_GETLEDS:
    768 		*(int*)data = 0;
    769 		return 0;
    770 	case WSKBDIO_GTYPE:
    771 		/* XXX well is it, dont think so */
    772 		*(u_int*)data = WSKBD_TYPE_PC_AT;
    773 		return 0;
    774 	}
    775 
    776 	/* We are supposed to return -1 to wscons if we didnt understand */
    777 	return (-1);
    778 }
    779 
    780 void
    781 kbd_getc(c, type, data)
    782 	void  *c;
    783 	u_int *type;
    784 	int   *data;
    785 {
    786 	int key;
    787 
    788 	key = kbdgetcn();
    789 
    790 	*data = KEY_CODE(key);
    791 	*type = KEY_UP(key) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
    792 }
    793 
    794 void
    795 kbd_pollc(c, on)
    796 	void *c;
    797 	int   on;
    798 {
    799 	kbd_softc.k_pollingmode = on;
    800 }
    801 
    802 void
    803 kbd_bell(c, x, y, z)
    804 	void  *c;
    805 	u_int  x;
    806 	u_int  y;
    807 	u_int  z;
    808 {
    809 }
    810 #endif /* WSKBD */
    811