Home | History | Annotate | Line # | Download | only in dev
kbd.c revision 1.51
      1  1.51   tsutsui /*	$NetBSD: kbd.c,v 1.51 2022/06/25 14:39:19 tsutsui Exp $	*/
      2   1.1       leo 
      3   1.1       leo /*
      4  1.28       leo  * Copyright (c) 1995 Leo Weppelman
      5   1.1       leo  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
      6   1.1       leo  * All rights reserved.
      7   1.1       leo  *
      8   1.1       leo  * Redistribution and use in source and binary forms, with or without
      9   1.1       leo  * modification, are permitted provided that the following conditions
     10   1.1       leo  * are met:
     11   1.1       leo  * 1. Redistributions of source code must retain the above copyright
     12   1.1       leo  *    notice, this list of conditions and the following disclaimer.
     13   1.1       leo  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1       leo  *    notice, this list of conditions and the following disclaimer in the
     15   1.1       leo  *    documentation and/or other materials provided with the distribution.
     16  1.26       agc  * 3. Neither the name of the University nor the names of its contributors
     17  1.26       agc  *    may be used to endorse or promote products derived from this software
     18  1.26       agc  *    without specific prior written permission.
     19  1.26       agc  *
     20  1.26       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     21  1.26       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  1.26       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  1.26       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     24  1.26       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  1.26       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  1.26       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  1.26       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  1.26       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  1.26       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  1.26       agc  * SUCH DAMAGE.
     31  1.26       agc  */
     32  1.26       agc 
     33  1.25     lukem #include <sys/cdefs.h>
     34  1.51   tsutsui __KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.51 2022/06/25 14:39:19 tsutsui Exp $");
     35   1.1       leo 
     36  1.23    thomas #include "mouse.h"
     37  1.23    thomas #include "ite.h"
     38  1.23    thomas #include "wskbd.h"
     39  1.23    thomas 
     40   1.1       leo #include <sys/param.h>
     41   1.1       leo #include <sys/systm.h>
     42   1.1       leo #include <sys/device.h>
     43   1.1       leo #include <sys/ioctl.h>
     44   1.1       leo #include <sys/tty.h>
     45   1.1       leo #include <sys/proc.h>
     46   1.1       leo #include <sys/conf.h>
     47   1.1       leo #include <sys/file.h>
     48   1.1       leo #include <sys/kernel.h>
     49   1.9       leo #include <sys/signalvar.h>
     50   1.1       leo #include <sys/syslog.h>
     51   1.1       leo #include <dev/cons.h>
     52   1.1       leo #include <machine/cpu.h>
     53   1.1       leo #include <machine/iomap.h>
     54   1.1       leo #include <machine/mfp.h>
     55   1.1       leo #include <machine/acia.h>
     56   1.1       leo #include <atari/dev/itevar.h>
     57   1.1       leo #include <atari/dev/event_var.h>
     58   1.1       leo #include <atari/dev/vuid_event.h>
     59   1.9       leo #include <atari/dev/ym2149reg.h>
     60   1.9       leo #include <atari/dev/kbdreg.h>
     61   1.9       leo #include <atari/dev/kbdvar.h>
     62  1.15       leo #include <atari/dev/kbdmap.h>
     63   1.9       leo #include <atari/dev/msvar.h>
     64   1.1       leo 
     65  1.23    thomas #if NWSKBD>0
     66  1.23    thomas #include <dev/wscons/wsconsio.h>
     67  1.23    thomas #include <dev/wscons/wskbdvar.h>
     68  1.23    thomas #include <dev/wscons/wsksymdef.h>
     69  1.23    thomas #include <dev/wscons/wsksymvar.h>
     70  1.23    thomas #include <atari/dev/wskbdmap_atari.h>
     71  1.23    thomas #endif
     72  1.23    thomas 
     73  1.51   tsutsui /*
     74  1.51   tsutsui  * The ringbuffer is the interface between the hard and soft interrupt handler.
     75  1.51   tsutsui  * The hard interrupt runs straight from the MFP interrupt.
     76  1.51   tsutsui  */
     77  1.51   tsutsui #define KBD_RING_SIZE	256   /* Sz of input ring buffer, must be power of 2 */
     78  1.51   tsutsui #define KBD_RING_MASK	255   /* Modulo mask for above			     */
     79  1.51   tsutsui 
     80  1.51   tsutsui struct kbd_softc {
     81  1.51   tsutsui 	int		k_event_mode;	/* if 1, collect events,	*/
     82  1.51   tsutsui 					/*   else pass to ite		*/
     83  1.51   tsutsui 	struct evvar	k_events;	/* event queue state		*/
     84  1.51   tsutsui 	uint8_t		k_soft_cs;	/* control-reg. copy		*/
     85  1.51   tsutsui 	uint8_t		k_package[20];	/* XXX package being build	*/
     86  1.51   tsutsui 	uint8_t		k_pkg_size;	/* Size of the package		*/
     87  1.51   tsutsui 	uint8_t		k_pkg_idx;	/* Running pkg assembly index	*/
     88  1.51   tsutsui 	uint8_t		k_pkg_type;	/* Type of package		*/
     89  1.51   tsutsui 	const uint8_t	*k_sendp;	/* Output pointer		*/
     90  1.51   tsutsui 	int		k_send_cnt;	/* Chars left for output	*/
     91  1.51   tsutsui #if NWSKBD > 0
     92  1.51   tsutsui 	device_t	k_wskbddev;   /* pointer to wskbd for sending strokes */
     93  1.51   tsutsui 	int		k_pollingmode;	/* polling mode on? whatever it is... */
     94  1.51   tsutsui #endif
     95  1.51   tsutsui 	void		*k_sicookie;	/* softint(9) cookie		*/
     96  1.51   tsutsui };
     97  1.51   tsutsui 
     98  1.23    thomas /* WSKBD */
     99  1.23    thomas /*
    100  1.23    thomas  * If NWSKBD>0 we try to attach an wskbd device to us. What follows
    101  1.23    thomas  * is definitions of callback functions and structures that are passed
    102  1.23    thomas  * to wscons when initializing.
    103  1.23    thomas  */
    104  1.23    thomas 
    105  1.23    thomas /*
    106  1.23    thomas  * Now with wscons this driver exhibits some weird behaviour.
    107  1.23    thomas  * It may act both as a driver of its own and the md part of the
    108  1.23    thomas  * wskbd driver. Therefore it can be accessed through /dev/kbd
    109  1.23    thomas  * and /dev/wskbd0 both.
    110  1.23    thomas  *
    111  1.23    thomas  * The data from they keyboard may end up in at least four different
    112  1.23    thomas  * places:
    113  1.23    thomas  * - If this driver has been opened (/dev/kbd) and the
    114  1.23    thomas  *   direct mode (TIOCDIRECT) has been set, data goes to
    115  1.23    thomas  *   the process who opened the device. Data will transmit itself
    116  1.23    thomas  *   as described by the firm_event structure.
    117  1.23    thomas  * - If wskbd support is compiled in and a wskbd driver has been
    118  1.23    thomas  *   attached then the data is sent to it. Wskbd in turn may
    119  1.23    thomas  *   - Send the data in the wscons_event form to a process that
    120  1.23    thomas  *     has opened /dev/wskbd0
    121  1.23    thomas  *   - Feed the data to a virtual terminal.
    122  1.23    thomas  * - If an ite is present the data may be fed to it.
    123  1.23    thomas  */
    124   1.5       leo 
    125  1.37   tsutsui uint8_t			kbd_modifier;	/* Modifier mask		*/
    126  1.15       leo 
    127  1.37   tsutsui static uint8_t		kbd_ring[KBD_RING_SIZE];
    128   1.1       leo static volatile u_int	kbd_rbput = 0;	/* 'put' index			*/
    129   1.1       leo static u_int		kbd_rbget = 0;	/* 'get' index			*/
    130   1.1       leo 
    131   1.1       leo static struct kbd_softc kbd_softc;
    132   1.1       leo 
    133   1.6       leo /* {b,c}devsw[] function prototypes */
    134  1.50   tsutsui static dev_type_open(kbdopen);
    135  1.50   tsutsui static dev_type_close(kbdclose);
    136  1.50   tsutsui static dev_type_read(kbdread);
    137  1.50   tsutsui static dev_type_ioctl(kbdioctl);
    138  1.50   tsutsui static dev_type_poll(kbdpoll);
    139  1.50   tsutsui static dev_type_kqfilter(kbdkqfilter);
    140   1.6       leo 
    141  1.39   tsutsui static void kbdsoft(void *);
    142  1.42   tsutsui static void kbdattach(device_t, device_t, void *);
    143  1.42   tsutsui static int  kbdmatch(device_t, cfdata_t, void *);
    144  1.50   tsutsui #if NITE > 0
    145  1.37   tsutsui static int  kbd_do_modifier(uint8_t);
    146  1.23    thomas #endif
    147  1.38   tsutsui static int  kbd_write_poll(const uint8_t *, int);
    148  1.37   tsutsui static void kbd_pkg_start(struct kbd_softc *, uint8_t);
    149   1.1       leo 
    150  1.42   tsutsui CFATTACH_DECL_NEW(kbd, 0,
    151  1.21   thorpej     kbdmatch, kbdattach, NULL, NULL);
    152  1.19   gehenna 
    153  1.19   gehenna const struct cdevsw kbd_cdevsw = {
    154  1.43  dholland 	.d_open = kbdopen,
    155  1.43  dholland 	.d_close = kbdclose,
    156  1.43  dholland 	.d_read = kbdread,
    157  1.43  dholland 	.d_write = nowrite,
    158  1.43  dholland 	.d_ioctl = kbdioctl,
    159  1.43  dholland 	.d_stop = nostop,
    160  1.43  dholland 	.d_tty = notty,
    161  1.43  dholland 	.d_poll = kbdpoll,
    162  1.43  dholland 	.d_mmap = nommap,
    163  1.43  dholland 	.d_kqfilter = kbdkqfilter,
    164  1.45  dholland 	.d_discard = nodiscard,
    165  1.43  dholland 	.d_flag = 0
    166   1.7   thorpej };
    167   1.9       leo 
    168  1.23    thomas #if NWSKBD>0
    169  1.23    thomas /* accessops */
    170  1.23    thomas static int	kbd_enable(void *, int);
    171  1.23    thomas static void	kbd_set_leds(void *, int);
    172  1.30  christos static int	kbd_ioctl(void *, u_long, void *, int, struct lwp *);
    173  1.23    thomas 
    174  1.23    thomas /* console ops */
    175  1.23    thomas static void	kbd_getc(void *, u_int *, int *);
    176  1.23    thomas static void	kbd_pollc(void *, int);
    177  1.23    thomas static void	kbd_bell(void *, u_int, u_int, u_int);
    178  1.23    thomas 
    179  1.23    thomas static struct wskbd_accessops kbd_accessops = {
    180  1.23    thomas 	kbd_enable,
    181  1.23    thomas 	kbd_set_leds,
    182  1.23    thomas 	kbd_ioctl
    183  1.23    thomas };
    184  1.23    thomas 
    185  1.23    thomas static struct wskbd_consops kbd_consops = {
    186  1.50   tsutsui 	kbd_getc,
    187  1.23    thomas 	kbd_pollc,
    188  1.23    thomas 	kbd_bell
    189  1.23    thomas };
    190  1.23    thomas 
    191  1.23    thomas /* Pointer to keymaps. */
    192  1.23    thomas static struct wskbd_mapdata kbd_mapdata = {
    193  1.50   tsutsui 	atarikbd_keydesctab,
    194  1.23    thomas 	KB_US
    195  1.23    thomas };
    196  1.23    thomas #endif /* WSKBD */
    197  1.23    thomas 
    198   1.1       leo /*ARGSUSED*/
    199  1.50   tsutsui static int
    200  1.42   tsutsui kbdmatch(device_t parent, cfdata_t cf, void *aux)
    201   1.1       leo {
    202  1.37   tsutsui 
    203  1.42   tsutsui 	if (!strcmp((char *)aux, "kbd"))
    204  1.37   tsutsui 		return 1;
    205  1.37   tsutsui 	return 0;
    206   1.1       leo }
    207   1.1       leo 
    208   1.1       leo /*ARGSUSED*/
    209   1.1       leo static void
    210  1.42   tsutsui kbdattach(device_t parent, device_t self, void *aux)
    211   1.1       leo {
    212  1.37   tsutsui 	int timeout;
    213  1.38   tsutsui 	const uint8_t kbd_rst[]  = { 0x80, 0x01 };
    214  1.38   tsutsui 	const uint8_t kbd_icmd[] = { 0x12, 0x15 };
    215   1.3       leo 
    216   1.3       leo 	/*
    217   1.3       leo 	 * Disable keyboard interrupts from MFP
    218   1.3       leo 	 */
    219   1.3       leo 	MFP->mf_ierb &= ~IB_AINT;
    220   1.3       leo 
    221   1.3       leo 	/*
    222  1.47  dholland 	 * Reset ACIA and initialize to:
    223   1.3       leo 	 *    divide by 16, 8 data, 1 stop, no parity, enable RX interrupts
    224   1.3       leo 	 */
    225   1.3       leo 	KBD->ac_cs = A_RESET;
    226   1.3       leo 	delay(100);	/* XXX: enough? */
    227   1.3       leo 	KBD->ac_cs = kbd_softc.k_soft_cs = KBD_INIT | A_RXINT;
    228   1.3       leo 
    229   1.3       leo 	/*
    230   1.3       leo 	 * Clear error conditions
    231   1.3       leo 	 */
    232  1.50   tsutsui 	while ((KBD->ac_cs & (A_IRQ | A_RXRDY)) != 0)
    233   1.3       leo 		timeout = KBD->ac_da;
    234   1.3       leo 
    235   1.3       leo 	/*
    236  1.46       snj 	 * Now send the reset string, and read+ignore its response
    237   1.3       leo 	 */
    238  1.50   tsutsui 	if (kbd_write_poll(kbd_rst, 2) == 0)
    239  1.12  christos 		printf("kbd: error cannot reset keyboard\n");
    240   1.3       leo 	for (timeout = 1000; timeout > 0; timeout--) {
    241  1.50   tsutsui 		if ((KBD->ac_cs & (A_IRQ | A_RXRDY)) != 0) {
    242   1.3       leo 			timeout = KBD->ac_da;
    243   1.3       leo 			timeout = 100;
    244   1.3       leo 		}
    245   1.3       leo 		delay(100);
    246   1.3       leo 	}
    247   1.4       leo 	/*
    248   1.4       leo 	 * Send init command: disable mice & joysticks
    249   1.4       leo 	 */
    250   1.4       leo 	kbd_write_poll(kbd_icmd, sizeof(kbd_icmd));
    251   1.3       leo 
    252  1.12  christos 	printf("\n");
    253  1.23    thomas 
    254  1.39   tsutsui 	kbd_softc.k_sicookie = softint_establish(SOFTINT_SERIAL, kbdsoft, NULL);
    255  1.39   tsutsui 
    256  1.50   tsutsui #if NWSKBD > 0
    257  1.42   tsutsui 	if (self != NULL) {
    258  1.23    thomas 		/*
    259  1.23    thomas 		 * Try to attach the wskbd.
    260  1.23    thomas 		 */
    261  1.23    thomas 		struct wskbddev_attach_args waa;
    262  1.23    thomas 
    263  1.23    thomas 		/* Maybe should be done before this?... */
    264  1.23    thomas 		wskbd_cnattach(&kbd_consops, NULL, &kbd_mapdata);
    265  1.23    thomas 
    266  1.23    thomas 		waa.console = 1;
    267  1.23    thomas 		waa.keymap = &kbd_mapdata;
    268  1.23    thomas 		waa.accessops = &kbd_accessops;
    269  1.23    thomas 		waa.accesscookie = NULL;
    270  1.48   thorpej 		kbd_softc.k_wskbddev = config_found(self, &waa, wskbddevprint,
    271  1.49   thorpej 		    CFARGS_NONE);
    272  1.23    thomas 
    273  1.23    thomas 		kbd_softc.k_pollingmode = 0;
    274  1.23    thomas 
    275  1.23    thomas 		kbdenable();
    276  1.23    thomas 	}
    277  1.23    thomas #endif /* WSKBD */
    278   1.1       leo }
    279   1.1       leo 
    280   1.1       leo void
    281  1.36    cegger kbdenable(void)
    282   1.1       leo {
    283  1.50   tsutsui 	int s;
    284   1.1       leo 
    285   1.1       leo 	s = spltty();
    286   1.3       leo 
    287   1.1       leo 	/*
    288   1.3       leo 	 * Clear error conditions...
    289   1.1       leo 	 */
    290  1.50   tsutsui 	while ((KBD->ac_cs & (A_IRQ | A_RXRDY)) != 0)
    291  1.50   tsutsui 		(void)KBD->ac_da;
    292   1.1       leo 	/*
    293   1.1       leo 	 * Enable interrupts from MFP
    294   1.1       leo 	 */
    295  1.50   tsutsui 	MFP->mf_iprb  = (uint8_t)~IB_AINT;
    296   1.1       leo 	MFP->mf_ierb |= IB_AINT;
    297   1.1       leo 	MFP->mf_imrb |= IB_AINT;
    298   1.1       leo 
    299   1.1       leo 	kbd_softc.k_event_mode   = 0;
    300   1.1       leo 	kbd_softc.k_events.ev_io = 0;
    301   1.3       leo 	kbd_softc.k_pkg_size     = 0;
    302   1.1       leo 	splx(s);
    303   1.1       leo }
    304   1.1       leo 
    305  1.50   tsutsui static int
    306  1.50   tsutsui kbdopen(dev_t dev, int flags, int mode, struct lwp *l)
    307   1.1       leo {
    308  1.37   tsutsui 
    309   1.3       leo 	if (kbd_softc.k_events.ev_io)
    310   1.1       leo 		return EBUSY;
    311   1.1       leo 
    312  1.29  christos 	kbd_softc.k_events.ev_io = l->l_proc;
    313   1.1       leo 	ev_init(&kbd_softc.k_events);
    314  1.37   tsutsui 	return 0;
    315   1.1       leo }
    316   1.1       leo 
    317  1.50   tsutsui static int
    318  1.29  christos kbdclose(dev_t dev, int flags, int mode, struct lwp *l)
    319   1.1       leo {
    320  1.37   tsutsui 
    321   1.1       leo 	/* Turn off event mode, dump the queue */
    322   1.1       leo 	kbd_softc.k_event_mode = 0;
    323   1.1       leo 	ev_fini(&kbd_softc.k_events);
    324   1.1       leo 	kbd_softc.k_events.ev_io = NULL;
    325  1.37   tsutsui 	return 0;
    326   1.1       leo }
    327   1.1       leo 
    328  1.50   tsutsui static int
    329   1.1       leo kbdread(dev_t dev, struct uio *uio, int flags)
    330   1.1       leo {
    331  1.37   tsutsui 
    332   1.1       leo 	return ev_read(&kbd_softc.k_events, uio, flags);
    333   1.1       leo }
    334   1.1       leo 
    335  1.50   tsutsui static int
    336  1.37   tsutsui kbdioctl(dev_t dev, u_long cmd, register void *data, int flag, struct lwp *l)
    337   1.1       leo {
    338  1.50   tsutsui 	struct kbd_softc *k = &kbd_softc;
    339  1.16       leo 	struct kbdbell	*kb;
    340   1.1       leo 
    341   1.1       leo 	switch (cmd) {
    342  1.50   tsutsui 	case KIOCTRANS:
    343  1.50   tsutsui 		if (*(int *)data == TR_UNTRANS_EVENT)
    344  1.50   tsutsui 			return 0;
    345  1.50   tsutsui 		break;
    346  1.50   tsutsui 
    347  1.50   tsutsui 	case KIOCGTRANS:
    348  1.50   tsutsui 		/*
    349  1.50   tsutsui 		 * Get translation mode
    350  1.50   tsutsui 		 */
    351  1.50   tsutsui 		*(int *)data = TR_UNTRANS_EVENT;
    352  1.50   tsutsui 		return 0;
    353  1.50   tsutsui 
    354  1.50   tsutsui 	case KIOCSDIRECT:
    355  1.50   tsutsui 		k->k_event_mode = *(int *)data;
    356  1.50   tsutsui 		return 0;
    357   1.1       leo 
    358  1.50   tsutsui 	case KIOCRINGBELL:
    359  1.50   tsutsui 		kb = (struct kbdbell *)data;
    360  1.50   tsutsui 		if (kb)
    361  1.50   tsutsui 			kbd_bell_sparms(kb->volume, kb->pitch,
    362  1.50   tsutsui 			    kb->duration);
    363  1.50   tsutsui 		kbdbell();
    364  1.50   tsutsui 		return 0;
    365   1.1       leo 
    366  1.50   tsutsui 	case FIONBIO:	/* we will remove this someday (soon???) */
    367  1.50   tsutsui 		return 0;
    368   1.1       leo 
    369  1.50   tsutsui 	case FIOASYNC:
    370  1.50   tsutsui 		k->k_events.ev_async = *(int *)data != 0;
    371  1.50   tsutsui 		return 0;
    372   1.1       leo 
    373  1.50   tsutsui 	case FIOSETOWN:
    374  1.50   tsutsui 		if (-*(int *)data != k->k_events.ev_io->p_pgid &&
    375  1.50   tsutsui 		    *(int *)data != k->k_events.ev_io->p_pid)
    376  1.50   tsutsui 			return EPERM;
    377  1.50   tsutsui 		return 0;
    378   1.1       leo 
    379  1.50   tsutsui 	case TIOCSPGRP:
    380  1.50   tsutsui 		if (*(int *)data != k->k_events.ev_io->p_pgid)
    381  1.50   tsutsui 			return EPERM;
    382  1.50   tsutsui 		return 0;
    383   1.1       leo 
    384  1.50   tsutsui 	default:
    385  1.50   tsutsui 		return ENOTTY;
    386   1.1       leo 	}
    387   1.1       leo 
    388   1.1       leo 	/*
    389   1.1       leo 	 * We identified the ioctl, but we do not handle it.
    390   1.1       leo 	 */
    391   1.1       leo 	return EOPNOTSUPP;		/* misuse, but what the heck */
    392   1.1       leo }
    393   1.1       leo 
    394  1.50   tsutsui static int
    395  1.50   tsutsui kbdpoll(dev_t dev, int events, struct lwp *l)
    396   1.1       leo {
    397  1.37   tsutsui 
    398  1.37   tsutsui 	return ev_poll(&kbd_softc.k_events, events, l);
    399  1.22  jdolecek }
    400  1.22  jdolecek 
    401  1.50   tsutsui static int
    402  1.22  jdolecek kbdkqfilter(dev_t dev, struct knote *kn)
    403  1.22  jdolecek {
    404  1.22  jdolecek 
    405  1.37   tsutsui 	return ev_kqfilter(&kbd_softc.k_events, kn);
    406   1.1       leo }
    407   1.1       leo 
    408   1.1       leo /*
    409   1.3       leo  * Keyboard interrupt handler called straight from MFP at spl6.
    410   1.1       leo  */
    411   1.6       leo void
    412  1.35       dsl kbdintr(int sr)
    413  1.50   tsutsui 	/* sr: sr at time of interrupt	*/
    414   1.1       leo {
    415  1.50   tsutsui 	uint8_t code;
    416  1.50   tsutsui 	bool got_char = false;
    417   1.1       leo 
    418   1.1       leo 	/*
    419   1.1       leo 	 * There may be multiple keys available. Read them all.
    420   1.1       leo 	 */
    421  1.50   tsutsui 	while ((KBD->ac_cs & (A_RXRDY | A_OE | A_PE)) != 0) {
    422  1.50   tsutsui 		got_char = true;
    423  1.50   tsutsui 		code = KBD->ac_da;
    424  1.50   tsutsui 		if ((KBD->ac_cs & (A_OE | A_PE)) != 0) {
    425  1.50   tsutsui 			/* Silently ignore errors */
    426   1.1       leo 			continue;
    427   1.1       leo 		}
    428  1.50   tsutsui 		kbd_ring[kbd_rbput++ & KBD_RING_MASK] = code;
    429   1.1       leo 	}
    430   1.3       leo 
    431   1.3       leo 	/*
    432   1.3       leo 	 * If characters are waiting for transmit, send them.
    433   1.3       leo 	 */
    434  1.50   tsutsui 	if ((kbd_softc.k_soft_cs & A_TXINT) != 0 &&
    435  1.50   tsutsui 	    (KBD->ac_cs & A_TXRDY) != 0) {
    436   1.3       leo 		if (kbd_softc.k_sendp != NULL)
    437   1.3       leo 			KBD->ac_da = *kbd_softc.k_sendp++;
    438   1.3       leo 		if (--kbd_softc.k_send_cnt <= 0) {
    439   1.3       leo 			/*
    440   1.3       leo 			 * The total package has been transmitted,
    441   1.3       leo 			 * wakeup anyone waiting for it.
    442   1.3       leo 			 */
    443   1.3       leo 			KBD->ac_cs = (kbd_softc.k_soft_cs &= ~A_TXINT);
    444   1.3       leo 			kbd_softc.k_sendp    = NULL;
    445   1.3       leo 			kbd_softc.k_send_cnt = 0;
    446  1.30  christos 			wakeup((void *)&kbd_softc.k_send_cnt);
    447   1.3       leo 		}
    448   1.3       leo 	}
    449   1.3       leo 
    450   1.3       leo 	/*
    451   1.3       leo 	 * Activate software-level to handle possible input.
    452   1.3       leo 	 */
    453  1.39   tsutsui 	if (got_char)
    454  1.39   tsutsui 		softint_schedule(kbd_softc.k_sicookie);
    455   1.1       leo }
    456   1.1       leo 
    457   1.1       leo /*
    458   1.1       leo  * Keyboard soft interrupt handler
    459   1.1       leo  */
    460  1.39   tsutsui static void
    461  1.39   tsutsui kbdsoft(void *junk1)
    462   1.1       leo {
    463  1.37   tsutsui 	int s;
    464  1.37   tsutsui 	uint8_t code;
    465  1.37   tsutsui 	struct kbd_softc *k = &kbd_softc;
    466  1.37   tsutsui 	struct firm_event *fe;
    467  1.37   tsutsui 	int put, get, n;
    468   1.1       leo 
    469  1.50   tsutsui 	get = kbd_rbget;
    470   1.1       leo 
    471   1.3       leo 	for (;;) {
    472   1.1       leo 		n = kbd_rbput;
    473   1.3       leo 		if (get == n) /* We're done	*/
    474   1.1       leo 			break;
    475   1.1       leo 		n -= get;
    476   1.3       leo 		if (n > KBD_RING_SIZE) { /* Ring buffer overflow	*/
    477   1.1       leo 			get += n - KBD_RING_SIZE;
    478   1.1       leo 			n    = KBD_RING_SIZE;
    479   1.1       leo 		}
    480   1.3       leo 		while (--n >= 0) {
    481   1.1       leo 			code = kbd_ring[get++ & KBD_RING_MASK];
    482   1.1       leo 
    483   1.1       leo 			/*
    484   1.3       leo 			 * If collecting a package, stuff it in and
    485   1.3       leo 			 * continue.
    486   1.3       leo 			 */
    487   1.3       leo 			if (k->k_pkg_size && (k->k_pkg_idx < k->k_pkg_size)) {
    488   1.9       leo 			    k->k_package[k->k_pkg_idx++] = code;
    489  1.50   tsutsui 				if (k->k_pkg_idx == k->k_pkg_size) {
    490  1.50   tsutsui 					/*
    491  1.50   tsutsui 					 * Package is complete.
    492  1.50   tsutsui 					 */
    493  1.50   tsutsui 					switch (k->k_pkg_type) {
    494   1.5       leo #if NMOUSE > 0
    495  1.50   tsutsui 					case KBD_AMS_PKG:
    496  1.50   tsutsui 					case KBD_RMS_PKG:
    497  1.50   tsutsui 					case KBD_JOY1_PKG:
    498  1.50   tsutsui 						mouse_soft(
    499  1.50   tsutsui 						    (REL_MOUSE *)k->k_package,
    500  1.50   tsutsui 						    k->k_pkg_size,
    501  1.50   tsutsui 						    k->k_pkg_type);
    502   1.5       leo #endif /* NMOUSE */
    503  1.50   tsutsui 					}
    504  1.50   tsutsui 					k->k_pkg_size = 0;
    505   1.3       leo 				}
    506  1.50   tsutsui 				continue;
    507   1.3       leo 			}
    508   1.3       leo 			/*
    509   1.3       leo 			 * If this is a package header, init pkg. handling.
    510   1.3       leo 			 */
    511  1.15       leo 			if (!KBD_IS_KEY(code)) {
    512   1.3       leo 				kbd_pkg_start(k, code);
    513   1.3       leo 				continue;
    514   1.3       leo 			}
    515  1.50   tsutsui #if NWSKBD > 0
    516  1.23    thomas 			/*
    517  1.37   tsutsui 			 * If we have attached a wskbd and not in polling mode
    518  1.37   tsutsui 			 * and nobody has opened us directly, then send the
    519  1.37   tsutsui 			 * keystroke to the wskbd.
    520  1.23    thomas 			 */
    521  1.23    thomas 
    522  1.50   tsutsui 			if (kbd_softc.k_pollingmode == 0 &&
    523  1.50   tsutsui 			    kbd_softc.k_wskbddev != NULL &&
    524  1.50   tsutsui 			    k->k_event_mode == 0) {
    525  1.23    thomas 				wskbd_input(kbd_softc.k_wskbddev,
    526  1.50   tsutsui 				    KBD_RELEASED(code) ?
    527  1.50   tsutsui 				    WSCONS_EVENT_KEY_UP :
    528  1.50   tsutsui 				    WSCONS_EVENT_KEY_DOWN,
    529  1.50   tsutsui 				    KBD_SCANCODE(code));
    530  1.23    thomas 				continue;
    531  1.23    thomas 			}
    532  1.23    thomas #endif /* NWSKBD */
    533  1.50   tsutsui #if NITE > 0
    534  1.15       leo 			if (kbd_do_modifier(code) && !k->k_event_mode)
    535  1.15       leo 				continue;
    536  1.23    thomas #endif
    537  1.50   tsutsui 
    538   1.3       leo 			/*
    539   1.1       leo 			 * if not in event mode, deliver straight to ite to
    540   1.1       leo 			 * process key stroke
    541   1.1       leo 			 */
    542   1.3       leo 			if (!k->k_event_mode) {
    543   1.1       leo 				/* Gets to spltty() by itself	*/
    544  1.50   tsutsui #if NITE > 0
    545   1.1       leo 				ite_filter(code, ITEFILT_TTY);
    546  1.23    thomas #endif
    547   1.1       leo 				continue;
    548   1.1       leo 			}
    549   1.1       leo 
    550   1.1       leo 			/*
    551   1.1       leo 			 * Keyboard is generating events.  Turn this keystroke
    552   1.1       leo 			 * into an event and put it in the queue.  If the queue
    553   1.1       leo 			 * is full, the keystroke is lost (sorry!).
    554   1.1       leo 			 */
    555   1.1       leo 			s = spltty();
    556   1.1       leo 			put = k->k_events.ev_put;
    557   1.1       leo 			fe  = &k->k_events.ev_q[put];
    558   1.1       leo 			put = (put + 1) % EV_QSIZE;
    559   1.3       leo 			if (put == k->k_events.ev_get) {
    560   1.1       leo 				log(LOG_WARNING,
    561  1.37   tsutsui 				    "keyboard event queue overflow\n");
    562   1.1       leo 				splx(s);
    563   1.1       leo 				continue;
    564   1.1       leo 			}
    565  1.15       leo 			fe->id    = KBD_SCANCODE(code);
    566  1.15       leo 			fe->value = KBD_RELEASED(code) ? VKEY_UP : VKEY_DOWN;
    567  1.32   tsutsui 			firm_gettime(fe);
    568   1.1       leo 			k->k_events.ev_put = put;
    569   1.1       leo 			EV_WAKEUP(&k->k_events);
    570   1.1       leo 			splx(s);
    571   1.1       leo 		}
    572   1.1       leo 		kbd_rbget = get;
    573   1.1       leo 	}
    574   1.1       leo }
    575   1.1       leo 
    576  1.37   tsutsui static	uint8_t sound[] = {
    577  1.37   tsutsui 	0xA8, 0x01, 0xA9, 0x01, 0xAA, 0x01, 0x00,
    578  1.37   tsutsui 	0xF8, 0x10, 0x10, 0x10, 0x00, 0x20, 0x03
    579   1.1       leo };
    580   1.1       leo 
    581   1.6       leo void
    582  1.36    cegger kbdbell(void)
    583   1.1       leo {
    584   1.3       leo 	register int	i, sps;
    585   1.1       leo 
    586   1.9       leo 	sps = splhigh();
    587   1.3       leo 	for (i = 0; i < sizeof(sound); i++) {
    588   1.8       leo 		YM2149->sd_selr = i;
    589   1.8       leo 		YM2149->sd_wdat = sound[i];
    590   1.3       leo 	}
    591   1.3       leo 	splx(sps);
    592  1.16       leo }
    593  1.16       leo 
    594  1.16       leo 
    595  1.16       leo /*
    596  1.16       leo  * Set the parameters of the 'default' beep.
    597  1.16       leo  */
    598  1.16       leo 
    599  1.16       leo #define KBDBELLCLOCK	125000	/* 2MHz / 16 */
    600  1.16       leo #define KBDBELLDURATION	128	/* 256 / 2MHz */
    601  1.16       leo 
    602  1.16       leo void
    603  1.35       dsl kbd_bell_gparms(u_int *volume, u_int *pitch, u_int *duration)
    604  1.16       leo {
    605  1.16       leo 	u_int	tmp;
    606  1.16       leo 
    607  1.16       leo 	tmp = sound[11] | (sound[12] << 8);
    608  1.16       leo 	*duration = (tmp * KBDBELLDURATION) / 1000;
    609  1.16       leo 
    610  1.16       leo 	tmp = sound[0] | (sound[1] << 8);
    611  1.16       leo 	*pitch = KBDBELLCLOCK / tmp;
    612  1.50   tsutsui 
    613  1.16       leo 	*volume = 0;
    614  1.16       leo }
    615  1.16       leo 
    616  1.16       leo void
    617  1.35       dsl kbd_bell_sparms(u_int volume, u_int pitch, u_int duration)
    618  1.16       leo {
    619  1.16       leo 	u_int	f, t;
    620  1.16       leo 
    621  1.16       leo 	f = pitch > 10 ? pitch : 10;	/* minimum pitch */
    622  1.16       leo 	if (f > 20000)
    623  1.16       leo 		f = 20000;		/* maximum pitch */
    624  1.16       leo 
    625  1.16       leo 	f = KBDBELLCLOCK / f;
    626  1.16       leo 
    627  1.16       leo 	t = (duration * 1000) / KBDBELLDURATION;
    628  1.16       leo 
    629  1.16       leo 	sound[ 0] = f & 0xff;
    630  1.16       leo 	sound[ 1] = (f >> 8) & 0xf;
    631  1.16       leo 	f -= 1;
    632  1.16       leo 	sound[ 2] = f & 0xff;
    633  1.16       leo 	sound[ 3] = (f >> 8) & 0xf;
    634  1.16       leo 	f += 2;
    635  1.16       leo 	sound[ 4] = f & 0xff;
    636  1.16       leo 	sound[ 5] = (f >> 8) & 0xf;
    637  1.50   tsutsui 
    638  1.16       leo 	sound[11] = t & 0xff;
    639  1.16       leo 	sound[12] = (t >> 8) & 0xff;
    640  1.16       leo 
    641  1.16       leo 	sound[13] = 0x03;
    642   1.1       leo }
    643   1.1       leo 
    644   1.1       leo int
    645  1.36    cegger kbdgetcn(void)
    646   1.1       leo {
    647  1.37   tsutsui 	uint8_t code;
    648  1.37   tsutsui 	int s = spltty();
    649  1.37   tsutsui 	int ints_active;
    650   1.1       leo 
    651   1.4       leo 	ints_active = 0;
    652  1.50   tsutsui 	if ((MFP->mf_imrb & IB_AINT) != 0) {
    653   1.4       leo 		ints_active   = 1;
    654   1.4       leo 		MFP->mf_imrb &= ~IB_AINT;
    655   1.4       leo 	}
    656   1.3       leo 	for (;;) {
    657   1.4       leo 		while (!((KBD->ac_cs & (A_IRQ|A_RXRDY)) == (A_IRQ|A_RXRDY)))
    658  1.50   tsutsui 			continue;	/* Wait for key	*/
    659  1.50   tsutsui 		if ((KBD->ac_cs & (A_OE | A_PE)) != 0) {
    660   1.3       leo 			code = KBD->ac_da;	/* Silently ignore errors */
    661   1.3       leo 			continue;
    662   1.3       leo 		}
    663  1.15       leo 		code = KBD->ac_da;
    664  1.23    thomas #if NITE>0
    665  1.15       leo 		if (!kbd_do_modifier(code))
    666  1.23    thomas #endif
    667  1.15       leo 			break;
    668   1.3       leo 	}
    669   1.1       leo 
    670   1.4       leo 	if (ints_active) {
    671  1.37   tsutsui 		MFP->mf_iprb  = (uint8_t)~IB_AINT;
    672   1.4       leo 		MFP->mf_imrb |=  IB_AINT;
    673   1.4       leo 	}
    674   1.1       leo 
    675  1.37   tsutsui 	splx(s);
    676   1.1       leo 	return code;
    677   1.3       leo }
    678   1.3       leo 
    679   1.3       leo /*
    680   1.3       leo  * Write a command to the keyboard in 'polled' mode.
    681   1.3       leo  */
    682   1.3       leo static int
    683  1.38   tsutsui kbd_write_poll(const uint8_t *cmd, int len)
    684   1.3       leo {
    685  1.50   tsutsui 	int timeout;
    686   1.3       leo 
    687   1.3       leo 	while (len-- > 0) {
    688   1.3       leo 		KBD->ac_da = *cmd++;
    689  1.50   tsutsui 		for (timeout = 100; (KBD->ac_cs & A_TXRDY) == 0; timeout--)
    690   1.3       leo 			delay(10);
    691  1.37   tsutsui 		if ((KBD->ac_cs & A_TXRDY) == 0)
    692  1.37   tsutsui 			return 0;
    693   1.3       leo 	}
    694  1.37   tsutsui 	return 1;
    695   1.3       leo }
    696   1.3       leo 
    697   1.3       leo /*
    698   1.3       leo  * Write a command to the keyboard. Return when command is send.
    699   1.3       leo  */
    700   1.4       leo void
    701  1.38   tsutsui kbd_write(const uint8_t *cmd, int len)
    702   1.3       leo {
    703   1.3       leo 	struct kbd_softc	*k = &kbd_softc;
    704  1.50   tsutsui 	int			s;
    705   1.3       leo 
    706   1.3       leo 	/*
    707   1.3       leo 	 * Get to splhigh, 'real' interrupts arrive at spl6!
    708   1.3       leo 	 */
    709  1.50   tsutsui 	s = splhigh();
    710   1.3       leo 
    711   1.3       leo 	/*
    712   1.3       leo 	 * Make sure any privious write has ended...
    713   1.3       leo 	 */
    714   1.3       leo 	while (k->k_sendp != NULL)
    715  1.30  christos 		tsleep((void *)&k->k_sendp, TTOPRI, "kbd_write1", 0);
    716   1.3       leo 
    717   1.3       leo 	/*
    718   1.3       leo 	 * If the KBD-acia is not currently busy, send the first
    719   1.3       leo 	 * character now.
    720   1.3       leo 	 */
    721   1.3       leo 	KBD->ac_cs = (k->k_soft_cs |= A_TXINT);
    722   1.3       leo 	if (KBD->ac_cs & A_TXRDY) {
    723   1.3       leo 		KBD->ac_da = *cmd++;
    724   1.3       leo 		len--;
    725   1.3       leo 	}
    726   1.3       leo 
    727   1.3       leo 	/*
    728   1.3       leo 	 * If we're not yet done, wait until all characters are send.
    729   1.3       leo 	 */
    730   1.3       leo 	if (len > 0) {
    731   1.3       leo 		k->k_sendp    = cmd;
    732   1.3       leo 		k->k_send_cnt = len;
    733  1.30  christos 		tsleep((void *)&k->k_send_cnt, TTOPRI, "kbd_write2", 0);
    734   1.3       leo 	}
    735  1.50   tsutsui 	splx(s);
    736   1.3       leo 
    737   1.3       leo 	/*
    738   1.3       leo 	 * Wakeup all procs waiting for us.
    739   1.3       leo 	 */
    740  1.30  christos 	wakeup((void *)&k->k_sendp);
    741   1.3       leo }
    742   1.3       leo 
    743   1.3       leo /*
    744   1.3       leo  * Setup softc-fields to assemble a keyboard package.
    745   1.3       leo  */
    746   1.3       leo static void
    747  1.37   tsutsui kbd_pkg_start(struct kbd_softc *kp, uint8_t msg_start)
    748   1.3       leo {
    749  1.37   tsutsui 
    750   1.3       leo 	kp->k_pkg_idx    = 1;
    751   1.3       leo 	kp->k_package[0] = msg_start;
    752   1.3       leo 	switch (msg_start) {
    753  1.50   tsutsui 	case 0xf6:
    754  1.50   tsutsui 		kp->k_pkg_type = KBD_MEM_PKG;
    755  1.50   tsutsui 		kp->k_pkg_size = 8;
    756  1.50   tsutsui 		break;
    757  1.50   tsutsui 	case 0xf7:
    758  1.50   tsutsui 		kp->k_pkg_type = KBD_AMS_PKG;
    759  1.50   tsutsui 		kp->k_pkg_size = 6;
    760  1.50   tsutsui 		break;
    761  1.50   tsutsui 	case 0xf8:
    762  1.50   tsutsui 	case 0xf9:
    763  1.50   tsutsui 	case 0xfa:
    764  1.50   tsutsui 	case 0xfb:
    765  1.50   tsutsui 		kp->k_pkg_type = KBD_RMS_PKG;
    766  1.50   tsutsui 		kp->k_pkg_size = 3;
    767  1.50   tsutsui 		break;
    768  1.50   tsutsui 	case 0xfc:
    769  1.50   tsutsui 		kp->k_pkg_type = KBD_CLK_PKG;
    770  1.50   tsutsui 		kp->k_pkg_size = 7;
    771  1.50   tsutsui 		break;
    772  1.50   tsutsui 	case 0xfe:
    773  1.50   tsutsui 		kp->k_pkg_type = KBD_JOY0_PKG;
    774  1.50   tsutsui 		kp->k_pkg_size = 2;
    775  1.50   tsutsui 		break;
    776  1.50   tsutsui 	case 0xff:
    777  1.50   tsutsui 		kp->k_pkg_type = KBD_JOY1_PKG;
    778  1.50   tsutsui 		kp->k_pkg_size = 2;
    779  1.50   tsutsui 		break;
    780  1.50   tsutsui 	default:
    781  1.50   tsutsui 		printf("kbd: Unknown packet 0x%x\n", msg_start);
    782  1.50   tsutsui 		break;
    783   1.3       leo 	}
    784   1.1       leo }
    785  1.15       leo 
    786  1.37   tsutsui #if NITE > 0
    787  1.15       leo /*
    788  1.15       leo  * Modifier processing
    789  1.15       leo  */
    790  1.15       leo static int
    791  1.37   tsutsui kbd_do_modifier(uint8_t code)
    792  1.15       leo {
    793  1.37   tsutsui 	uint8_t up, mask;
    794  1.15       leo 
    795  1.15       leo 	up   = KBD_RELEASED(code);
    796  1.15       leo 	mask = 0;
    797  1.15       leo 
    798  1.37   tsutsui 	switch (KBD_SCANCODE(code)) {
    799  1.50   tsutsui 	case KBD_LEFT_SHIFT:
    800  1.50   tsutsui 		mask = KBD_MOD_LSHIFT;
    801  1.50   tsutsui 		break;
    802  1.50   tsutsui 	case KBD_RIGHT_SHIFT:
    803  1.50   tsutsui 		mask = KBD_MOD_RSHIFT;
    804  1.50   tsutsui 		break;
    805  1.50   tsutsui 	case KBD_CTRL:
    806  1.50   tsutsui 		mask = KBD_MOD_CTRL;
    807  1.50   tsutsui 		break;
    808  1.50   tsutsui 	case KBD_ALT:
    809  1.50   tsutsui 		mask = KBD_MOD_ALT;
    810  1.50   tsutsui 		break;
    811  1.50   tsutsui 	case KBD_CAPS_LOCK:
    812  1.50   tsutsui 		/* CAPSLOCK is a toggle */
    813  1.50   tsutsui 		if (!up)
    814  1.50   tsutsui 			kbd_modifier ^= KBD_MOD_CAPS;
    815  1.50   tsutsui 		return 1;
    816  1.15       leo 	}
    817  1.37   tsutsui 	if (mask) {
    818  1.41   tsutsui 		if (up)
    819  1.15       leo 			kbd_modifier &= ~mask;
    820  1.15       leo 		else
    821  1.15       leo 			kbd_modifier |= mask;
    822  1.15       leo 		return 1;
    823  1.15       leo 	}
    824  1.15       leo 	return 0;
    825  1.50   tsutsui }
    826  1.23    thomas #endif
    827  1.23    thomas 
    828  1.50   tsutsui #if NWSKBD > 0
    829  1.23    thomas /*
    830  1.23    thomas  * These are the callback functions that are passed to wscons.
    831  1.23    thomas  * They really don't do anything worth noting, just call the
    832  1.23    thomas  * other functions above.
    833  1.23    thomas  */
    834  1.23    thomas 
    835  1.23    thomas static int
    836  1.23    thomas kbd_enable(void *c, int on)
    837  1.23    thomas {
    838  1.37   tsutsui 
    839  1.50   tsutsui 	/* Wonder what this is supposed to do... */
    840  1.23    thomas 	return 0;
    841  1.23    thomas }
    842  1.23    thomas 
    843  1.23    thomas static void
    844  1.23    thomas kbd_set_leds(void *c, int leds)
    845  1.23    thomas {
    846  1.37   tsutsui 
    847  1.50   tsutsui 	/* we can not set the leds */
    848  1.23    thomas }
    849  1.23    thomas 
    850  1.23    thomas static int
    851  1.40       abs kbd_ioctl(void *c, u_long cmd, void *data, int flag, struct lwp *p)
    852  1.23    thomas {
    853  1.23    thomas 	struct wskbd_bell_data *kd;
    854  1.23    thomas 
    855  1.37   tsutsui 	switch (cmd) {
    856  1.23    thomas 	case WSKBDIO_COMPLEXBELL:
    857  1.23    thomas 		kd = (struct wskbd_bell_data *)data;
    858  1.23    thomas 		kbd_bell(0, kd->pitch, kd->period, kd->volume);
    859  1.23    thomas 		return 0;
    860  1.23    thomas 	case WSKBDIO_SETLEDS:
    861  1.23    thomas 		return 0;
    862  1.23    thomas 	case WSKBDIO_GETLEDS:
    863  1.37   tsutsui 		*(int *)data = 0;
    864  1.23    thomas 		return 0;
    865  1.23    thomas 	case WSKBDIO_GTYPE:
    866  1.37   tsutsui 		*(u_int *)data = WSKBD_TYPE_ATARI;
    867  1.23    thomas 		return 0;
    868  1.23    thomas 	}
    869  1.23    thomas 
    870  1.23    thomas 	/*
    871  1.23    thomas 	 * We are supposed to return EPASSTHROUGH to wscons if we didn't
    872  1.23    thomas 	 * understand.
    873  1.23    thomas 	 */
    874  1.37   tsutsui 	return EPASSTHROUGH;
    875  1.23    thomas }
    876  1.23    thomas 
    877  1.23    thomas static void
    878  1.23    thomas kbd_getc(void *c, u_int *type, int *data)
    879  1.23    thomas {
    880  1.23    thomas 	int key;
    881  1.23    thomas 	key = kbdgetcn();
    882  1.23    thomas 
    883  1.23    thomas 	*data = KBD_SCANCODE(key);
    884  1.23    thomas 	*type = KBD_RELEASED(key) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
    885  1.23    thomas }
    886  1.23    thomas 
    887  1.23    thomas static void
    888  1.23    thomas kbd_pollc(void *c, int on)
    889  1.23    thomas {
    890  1.37   tsutsui 
    891  1.50   tsutsui 	kbd_softc.k_pollingmode = on;
    892  1.23    thomas }
    893  1.23    thomas 
    894  1.23    thomas static void
    895  1.23    thomas kbd_bell(void *v, u_int pitch, u_int duration, u_int volume)
    896  1.23    thomas {
    897  1.37   tsutsui 
    898  1.50   tsutsui 	kbd_bell_sparms(volume, pitch, duration);
    899  1.23    thomas 	kbdbell();
    900  1.23    thomas }
    901  1.23    thomas #endif /* NWSKBD */
    902