Home | History | Annotate | Line # | Download | only in sun
kbd.c revision 1.36
      1  1.36   darrenr /*	$NetBSD: kbd.c,v 1.36 2003/06/29 09:56:31 darrenr Exp $	*/
      2   1.1       gwr 
      3   1.1       gwr /*
      4   1.1       gwr  * Copyright (c) 1992, 1993
      5   1.1       gwr  *	The Regents of the University of California.  All rights reserved.
      6   1.1       gwr  *
      7   1.1       gwr  * This software was developed by the Computer Systems Engineering group
      8   1.1       gwr  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9   1.1       gwr  * contributed to Berkeley.
     10   1.1       gwr  *
     11   1.1       gwr  * All advertising materials mentioning features or use of this software
     12   1.1       gwr  * must display the following acknowledgement:
     13   1.1       gwr  *	This product includes software developed by the University of
     14   1.1       gwr  *	California, Lawrence Berkeley Laboratory.
     15   1.1       gwr  *
     16   1.1       gwr  * Redistribution and use in source and binary forms, with or without
     17   1.1       gwr  * modification, are permitted provided that the following conditions
     18   1.1       gwr  * are met:
     19   1.1       gwr  * 1. Redistributions of source code must retain the above copyright
     20   1.1       gwr  *    notice, this list of conditions and the following disclaimer.
     21   1.1       gwr  * 2. Redistributions in binary form must reproduce the above copyright
     22   1.1       gwr  *    notice, this list of conditions and the following disclaimer in the
     23   1.1       gwr  *    documentation and/or other materials provided with the distribution.
     24   1.1       gwr  * 3. All advertising materials mentioning features or use of this software
     25   1.1       gwr  *    must display the following acknowledgement:
     26   1.1       gwr  *	This product includes software developed by the University of
     27   1.1       gwr  *	California, Berkeley and its contributors.
     28   1.1       gwr  * 4. Neither the name of the University nor the names of its contributors
     29   1.1       gwr  *    may be used to endorse or promote products derived from this software
     30   1.1       gwr  *    without specific prior written permission.
     31   1.1       gwr  *
     32   1.1       gwr  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33   1.1       gwr  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34   1.1       gwr  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35   1.1       gwr  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36   1.1       gwr  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37   1.1       gwr  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38   1.1       gwr  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39   1.1       gwr  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40   1.1       gwr  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41   1.1       gwr  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42   1.1       gwr  * SUCH DAMAGE.
     43   1.1       gwr  *
     44   1.1       gwr  *	@(#)kbd.c	8.2 (Berkeley) 10/30/93
     45   1.1       gwr  */
     46   1.1       gwr 
     47   1.1       gwr /*
     48   1.1       gwr  * Keyboard driver (/dev/kbd -- note that we do not have minor numbers
     49   1.1       gwr  * [yet?]).  Translates incoming bytes to ASCII or to `firm_events' and
     50   1.1       gwr  * passes them up to the appropriate reader.
     51   1.1       gwr  */
     52  1.29     lukem 
     53  1.29     lukem #include <sys/cdefs.h>
     54  1.36   darrenr __KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.36 2003/06/29 09:56:31 darrenr Exp $");
     55   1.1       gwr 
     56   1.1       gwr #include <sys/param.h>
     57   1.1       gwr #include <sys/systm.h>
     58  1.13       gwr #include <sys/conf.h>
     59   1.1       gwr #include <sys/device.h>
     60   1.1       gwr #include <sys/ioctl.h>
     61  1.13       gwr #include <sys/kernel.h>
     62  1.13       gwr #include <sys/proc.h>
     63  1.33       uwe #include <sys/malloc.h>
     64  1.13       gwr #include <sys/signal.h>
     65  1.13       gwr #include <sys/signalvar.h>
     66   1.1       gwr #include <sys/time.h>
     67   1.1       gwr #include <sys/syslog.h>
     68   1.9       mrg #include <sys/select.h>
     69   1.9       mrg #include <sys/poll.h>
     70  1.27       eeh #include <sys/file.h>
     71   1.1       gwr 
     72  1.35    martin #include <dev/wscons/wsksymdef.h>
     73  1.35    martin 
     74  1.33       uwe #include <dev/sun/kbd_reg.h>
     75  1.33       uwe #include <dev/sun/kbio.h>
     76  1.33       uwe #include <dev/sun/vuid_event.h>
     77  1.22       mrg #include <dev/sun/event_var.h>
     78  1.22       mrg #include <dev/sun/kbd_xlate.h>
     79  1.22       mrg #include <dev/sun/kbdvar.h>
     80   1.1       gwr 
     81  1.14       jtk #include "locators.h"
     82   1.1       gwr 
     83  1.31   gehenna extern struct cfdriver kbd_cd;
     84   1.1       gwr 
     85  1.31   gehenna dev_type_open(kbdopen);
     86  1.31   gehenna dev_type_close(kbdclose);
     87  1.31   gehenna dev_type_read(kbdread);
     88  1.31   gehenna dev_type_ioctl(kbdioctl);
     89  1.31   gehenna dev_type_poll(kbdpoll);
     90  1.34  jdolecek dev_type_kqfilter(kbdkqfilter);
     91  1.31   gehenna 
     92  1.31   gehenna const struct cdevsw kbd_cdevsw = {
     93  1.31   gehenna 	kbdopen, kbdclose, kbdread, nowrite, kbdioctl,
     94  1.34  jdolecek 	nostop, notty, kbdpoll, nommap, kbdkqfilter
     95  1.31   gehenna };
     96   1.1       gwr 
     97  1.35    martin #if NWSKBD > 0
     98  1.35    martin int	wssunkbd_enable __P((void *, int));
     99  1.35    martin void	wssunkbd_set_leds __P((void *, int));
    100  1.36   darrenr int	wssunkbd_ioctl __P((void *, u_long, caddr_t, int, struct lwp *));
    101  1.35    martin 
    102  1.35    martin void    sunkbd_wskbd_cngetc __P((void *, u_int *, int *));
    103  1.35    martin void    sunkbd_wskbd_cnpollc __P((void *, int));
    104  1.35    martin void    sunkbd_wskbd_cnbell __P((void *, u_int, u_int, u_int));
    105  1.35    martin static void sunkbd_bell_off(void *v);
    106  1.35    martin 
    107  1.35    martin const struct wskbd_accessops sunkbd_wskbd_accessops = {
    108  1.35    martin 	wssunkbd_enable,
    109  1.35    martin 	wssunkbd_set_leds,
    110  1.35    martin 	wssunkbd_ioctl,
    111  1.35    martin };
    112  1.35    martin 
    113  1.35    martin extern const struct wscons_keydesc wssun_keydesctab[];
    114  1.35    martin const struct wskbd_mapdata sunkbd_wskbd_keymapdata = {
    115  1.35    martin 	wssun_keydesctab,
    116  1.35    martin #ifdef SUNKBD_LAYOUT
    117  1.35    martin 	SUNKBD_LAYOUT,
    118  1.35    martin #else
    119  1.35    martin 	KB_US,
    120  1.35    martin #endif
    121  1.35    martin };
    122  1.35    martin 
    123  1.35    martin const struct wskbd_consops sunkbd_wskbd_consops = {
    124  1.35    martin         sunkbd_wskbd_cngetc,
    125  1.35    martin         sunkbd_wskbd_cnpollc,
    126  1.35    martin         sunkbd_wskbd_cnbell,
    127  1.35    martin };
    128  1.35    martin 
    129  1.35    martin void kbd_wskbd_attach(struct kbd_softc *k, int isconsole);
    130  1.35    martin #endif
    131  1.32       uwe 
    132  1.32       uwe /* ioctl helpers */
    133  1.32       uwe static int kbd_iockeymap(struct kbd_state *ks,
    134  1.32       uwe 			 u_long cmd, struct kiockeymap *kio);
    135  1.32       uwe #ifdef KIOCGETKEY
    136  1.32       uwe static int kbd_oldkeymap(struct kbd_state *ks,
    137  1.32       uwe 			 u_long cmd, struct okiockey *okio);
    138  1.32       uwe #endif
    139  1.32       uwe 
    140  1.33       uwe 
    141  1.33       uwe /* callbacks for console driver */
    142  1.33       uwe static int kbd_cc_open(struct cons_channel *);
    143  1.33       uwe static int kbd_cc_close(struct cons_channel *);
    144  1.33       uwe 
    145  1.33       uwe /* console input */
    146  1.33       uwe static void	kbd_input_console(struct kbd_softc *, int);
    147  1.33       uwe static void	kbd_repeat(void *);
    148  1.33       uwe static int	kbd_input_keysym(struct kbd_softc *, int);
    149  1.33       uwe static void	kbd_input_string(struct kbd_softc *, char *);
    150  1.33       uwe static void	kbd_input_funckey(struct kbd_softc *, int);
    151  1.33       uwe static void	kbd_update_leds(struct kbd_softc *);
    152  1.33       uwe 
    153  1.35    martin #if NWSKBD > 0
    154  1.35    martin static void	kbd_input_wskbd(struct kbd_softc *, int);
    155  1.35    martin #endif
    156  1.35    martin 
    157  1.33       uwe /* firm events input */
    158  1.33       uwe static void	kbd_input_event(struct kbd_softc *, int);
    159  1.33       uwe 
    160  1.32       uwe 
    161  1.32       uwe 
    162   1.1       gwr /****************************************************************
    163   1.1       gwr  *  Entry points for /dev/kbd
    164   1.1       gwr  *  (open,close,read,write,...)
    165   1.1       gwr  ****************************************************************/
    166   1.1       gwr 
    167   1.1       gwr /*
    168   1.1       gwr  * Open:
    169   1.1       gwr  * Check exclusion, open actual device (_iopen),
    170   1.1       gwr  * setup event channel, clear ASCII repeat stuff.
    171   1.1       gwr  */
    172   1.1       gwr int
    173  1.36   darrenr kbdopen(dev, flags, mode, l)
    174   1.1       gwr 	dev_t dev;
    175   1.1       gwr 	int flags, mode;
    176  1.36   darrenr 	struct lwp *l;
    177   1.1       gwr {
    178   1.1       gwr 	struct kbd_softc *k;
    179  1.13       gwr 	int error, unit;
    180   1.1       gwr 
    181  1.32       uwe 	/* locate device */
    182   1.1       gwr 	unit = minor(dev);
    183   1.5   thorpej 	if (unit >= kbd_cd.cd_ndevs)
    184   1.1       gwr 		return (ENXIO);
    185   1.5   thorpej 	k = kbd_cd.cd_devs[unit];
    186   1.1       gwr 	if (k == NULL)
    187   1.1       gwr 		return (ENXIO);
    188   1.1       gwr 
    189  1.33       uwe 	/*
    190  1.33       uwe 	 * NB: wscons support: while we can track if wskbd has called
    191  1.33       uwe 	 * enable(), we can't tell if that's for console input or for
    192  1.33       uwe 	 * events input, so we should probably just let the open to
    193  1.33       uwe 	 * always succeed regardless (e.g. Xsun opening /dev/kbd).
    194  1.33       uwe 	 */
    195  1.33       uwe 
    196  1.32       uwe 	/* exclusive open required for /dev/kbd */
    197   1.1       gwr 	if (k->k_events.ev_io)
    198   1.1       gwr 		return (EBUSY);
    199  1.36   darrenr 	k->k_events.ev_io = l->l_proc;
    200   1.1       gwr 
    201  1.33       uwe 	/* stop pending autorepeat of console input */
    202  1.33       uwe 	if (k->k_repeating) {
    203  1.33       uwe 		k->k_repeating = 0;
    204  1.33       uwe 		callout_stop(&k->k_repeat_ch);
    205  1.33       uwe 	}
    206  1.33       uwe 
    207  1.32       uwe 	/* open actual underlying device */
    208  1.32       uwe 	if (k->k_ops != NULL && k->k_ops->open != NULL)
    209  1.32       uwe 		if ((error = (*k->k_ops->open)(k)) != 0) {
    210  1.32       uwe 			k->k_events.ev_io = NULL;
    211  1.32       uwe 			return (error);
    212  1.32       uwe 		}
    213  1.32       uwe 
    214   1.1       gwr 	ev_init(&k->k_events);
    215  1.27       eeh 	k->k_evmode = 0;	/* XXX: OK? */
    216   1.1       gwr 
    217   1.1       gwr 	return (0);
    218   1.1       gwr }
    219   1.1       gwr 
    220  1.32       uwe 
    221   1.1       gwr /*
    222   1.1       gwr  * Close:
    223   1.1       gwr  * Turn off event mode, dump the queue, and close the keyboard
    224   1.1       gwr  * unless it is supplying console input.
    225   1.1       gwr  */
    226   1.1       gwr int
    227  1.36   darrenr kbdclose(dev, flags, mode, l)
    228   1.1       gwr 	dev_t dev;
    229   1.1       gwr 	int flags, mode;
    230  1.36   darrenr 	struct lwp *l;
    231   1.1       gwr {
    232   1.1       gwr 	struct kbd_softc *k;
    233   1.1       gwr 
    234   1.5   thorpej 	k = kbd_cd.cd_devs[minor(dev)];
    235   1.1       gwr 	k->k_evmode = 0;
    236   1.1       gwr 	ev_fini(&k->k_events);
    237   1.1       gwr 	k->k_events.ev_io = NULL;
    238  1.32       uwe 
    239  1.32       uwe 	if (k->k_ops != NULL && k->k_ops->close != NULL) {
    240  1.32       uwe 		int error;
    241  1.32       uwe 		if ((error = (*k->k_ops->close)(k)) != 0)
    242  1.32       uwe 			return (error);
    243  1.32       uwe 	}
    244   1.1       gwr 	return (0);
    245   1.1       gwr }
    246   1.1       gwr 
    247  1.32       uwe 
    248   1.1       gwr int
    249   1.1       gwr kbdread(dev, uio, flags)
    250   1.1       gwr 	dev_t dev;
    251   1.1       gwr 	struct uio *uio;
    252   1.1       gwr 	int flags;
    253   1.1       gwr {
    254   1.1       gwr 	struct kbd_softc *k;
    255   1.1       gwr 
    256   1.5   thorpej 	k = kbd_cd.cd_devs[minor(dev)];
    257   1.1       gwr 	return (ev_read(&k->k_events, uio, flags));
    258   1.1       gwr }
    259   1.1       gwr 
    260  1.32       uwe 
    261   1.1       gwr int
    262  1.36   darrenr kbdpoll(dev, events, l)
    263   1.1       gwr 	dev_t dev;
    264   1.9       mrg 	int events;
    265  1.36   darrenr 	struct lwp *l;
    266   1.1       gwr {
    267   1.1       gwr 	struct kbd_softc *k;
    268   1.1       gwr 
    269   1.5   thorpej 	k = kbd_cd.cd_devs[minor(dev)];
    270  1.36   darrenr 	return (ev_poll(&k->k_events, events, l));
    271   1.1       gwr }
    272   1.1       gwr 
    273  1.34  jdolecek int
    274  1.34  jdolecek kbdkqfilter(dev, kn)
    275  1.34  jdolecek 	dev_t dev;
    276  1.34  jdolecek 	struct knote *kn;
    277  1.34  jdolecek {
    278  1.34  jdolecek 	struct kbd_softc *k;
    279  1.34  jdolecek 
    280  1.34  jdolecek 	k = kbd_cd.cd_devs[minor(dev)];
    281  1.34  jdolecek 	return (ev_kqfilter(&k->k_events, kn));
    282  1.34  jdolecek }
    283   1.1       gwr 
    284   1.1       gwr int
    285  1.36   darrenr kbdioctl(dev, cmd, data, flag, l)
    286   1.1       gwr 	dev_t dev;
    287   1.1       gwr 	u_long cmd;
    288  1.23        pk 	caddr_t data;
    289   1.1       gwr 	int flag;
    290  1.36   darrenr 	struct lwp *l;
    291   1.1       gwr {
    292   1.1       gwr 	struct kbd_softc *k;
    293   1.1       gwr 	struct kbd_state *ks;
    294   1.1       gwr 	int error = 0;
    295   1.1       gwr 
    296   1.5   thorpej 	k = kbd_cd.cd_devs[minor(dev)];
    297   1.1       gwr 	ks = &k->k_state;
    298   1.1       gwr 
    299   1.1       gwr 	switch (cmd) {
    300   1.1       gwr 
    301   1.1       gwr 	case KIOCTRANS: 	/* Set translation mode */
    302   1.1       gwr 		/* We only support "raw" mode on /dev/kbd */
    303  1.16       gwr 		if (*(int *)data != TR_UNTRANS_EVENT)
    304   1.1       gwr 			error = EINVAL;
    305   1.1       gwr 		break;
    306   1.1       gwr 
    307   1.1       gwr 	case KIOCGTRANS:	/* Get translation mode */
    308   1.1       gwr 		/* We only support "raw" mode on /dev/kbd */
    309  1.16       gwr 		*(int *)data = TR_UNTRANS_EVENT;
    310   1.1       gwr 		break;
    311   1.1       gwr 
    312  1.32       uwe #ifdef KIOCGETKEY
    313   1.1       gwr 	case KIOCGETKEY:	/* Get keymap entry (old format) */
    314   1.1       gwr 		error = kbd_oldkeymap(ks, cmd, (struct okiockey *)data);
    315   1.1       gwr 		break;
    316  1.32       uwe #endif /* KIOCGETKEY */
    317   1.1       gwr 
    318   1.1       gwr 	case KIOCSKEY:  	/* Set keymap entry */
    319  1.32       uwe 		/* FALLTHROUGH */
    320   1.1       gwr 	case KIOCGKEY:  	/* Get keymap entry */
    321   1.1       gwr 		error = kbd_iockeymap(ks, cmd, (struct kiockeymap *)data);
    322   1.1       gwr 		break;
    323   1.1       gwr 
    324  1.32       uwe 	case KIOCCMD:		/* Send a command to the keyboard */
    325  1.32       uwe 		/* pass it to the middle layer */
    326  1.32       uwe 		if (k->k_ops != NULL && k->k_ops->docmd != NULL)
    327  1.32       uwe 			error = (*k->k_ops->docmd)(k, *(int *)data, 1);
    328   1.1       gwr 		break;
    329   1.1       gwr 
    330  1.32       uwe 	case KIOCTYPE:		/* Get keyboard type */
    331  1.16       gwr 		*(int *)data = ks->kbd_id;
    332   1.1       gwr 		break;
    333   1.1       gwr 
    334  1.32       uwe 	case KIOCSDIRECT:	/* Where to send input */
    335  1.16       gwr 		k->k_evmode = *(int *)data;
    336   1.1       gwr 		break;
    337   1.1       gwr 
    338   1.1       gwr 	case KIOCLAYOUT:	/* Get keyboard layout */
    339  1.16       gwr 		*(int *)data = ks->kbd_layout;
    340   1.1       gwr 		break;
    341   1.1       gwr 
    342  1.32       uwe 	case KIOCSLED:		/* Set keyboard LEDs */
    343  1.32       uwe 		/* pass the request to the middle layer */
    344  1.32       uwe 		if (k->k_ops != NULL && k->k_ops->setleds != NULL)
    345  1.32       uwe 			error = (*k->k_ops->setleds)(k, *(char *)data, 1);
    346   1.1       gwr 		break;
    347   1.1       gwr 
    348  1.32       uwe 	case KIOCGLED:		/* Get keyboard LEDs */
    349   1.1       gwr 		*(char *)data = ks->kbd_leds;
    350   1.1       gwr 		break;
    351   1.1       gwr 
    352   1.1       gwr 	case FIONBIO:		/* we will remove this someday (soon???) */
    353   1.1       gwr 		break;
    354   1.1       gwr 
    355   1.1       gwr 	case FIOASYNC:
    356  1.32       uwe 		k->k_events.ev_async = (*(int *)data != 0);
    357   1.1       gwr 		break;
    358   1.1       gwr 
    359   1.1       gwr 	case TIOCSPGRP:
    360  1.16       gwr 		if (*(int *)data != k->k_events.ev_io->p_pgid)
    361   1.1       gwr 			error = EPERM;
    362   1.1       gwr 		break;
    363   1.1       gwr 
    364  1.16       gwr 	default:
    365  1.16       gwr 		error = ENOTTY;
    366  1.16       gwr 		break;
    367   1.1       gwr 	}
    368   1.1       gwr 
    369   1.1       gwr 	return (error);
    370   1.1       gwr }
    371   1.1       gwr 
    372  1.32       uwe 
    373   1.1       gwr /****************************************************************
    374   1.1       gwr  * ioctl helpers
    375   1.1       gwr  ****************************************************************/
    376   1.1       gwr 
    377   1.1       gwr /*
    378   1.1       gwr  * Get/Set keymap entry
    379   1.1       gwr  */
    380   1.7       gwr static int
    381   1.1       gwr kbd_iockeymap(ks, cmd, kio)
    382   1.1       gwr 	struct kbd_state *ks;
    383   1.1       gwr 	u_long cmd;
    384   1.1       gwr 	struct kiockeymap *kio;
    385   1.1       gwr {
    386  1.13       gwr 	u_short *km;
    387   1.1       gwr 	u_int station;
    388   1.1       gwr 
    389   1.1       gwr 	switch (kio->kio_tablemask) {
    390   1.1       gwr 	case KIOC_NOMASK:
    391   1.1       gwr 		km = ks->kbd_k.k_normal;
    392   1.1       gwr 		break;
    393   1.1       gwr 	case KIOC_SHIFTMASK:
    394   1.1       gwr 		km = ks->kbd_k.k_shifted;
    395   1.1       gwr 		break;
    396   1.1       gwr 	case KIOC_CTRLMASK:
    397   1.1       gwr 		km = ks->kbd_k.k_control;
    398   1.1       gwr 		break;
    399   1.1       gwr 	case KIOC_UPMASK:
    400   1.1       gwr 		km = ks->kbd_k.k_release;
    401   1.1       gwr 		break;
    402   1.1       gwr 	default:
    403   1.1       gwr 		/* Silently ignore unsupported masks */
    404   1.1       gwr 		return (0);
    405   1.1       gwr 	}
    406   1.1       gwr 
    407   1.1       gwr 	/* Range-check the table position. */
    408   1.1       gwr 	station = kio->kio_station;
    409   1.1       gwr 	if (station >= KEYMAP_SIZE)
    410   1.1       gwr 		return (EINVAL);
    411   1.1       gwr 
    412   1.1       gwr 	switch (cmd) {
    413   1.1       gwr 
    414   1.1       gwr 	case KIOCGKEY:	/* Get keymap entry */
    415  1.13       gwr 		kio->kio_entry = km[station];
    416   1.1       gwr 		break;
    417   1.1       gwr 
    418   1.1       gwr 	case KIOCSKEY:	/* Set keymap entry */
    419  1.13       gwr 		km[station] = kio->kio_entry;
    420   1.1       gwr 		break;
    421   1.1       gwr 
    422   1.1       gwr 	default:
    423   1.1       gwr 		return(ENOTTY);
    424   1.1       gwr 	}
    425   1.1       gwr 	return (0);
    426   1.1       gwr }
    427   1.1       gwr 
    428  1.32       uwe 
    429  1.32       uwe #ifdef KIOCGETKEY
    430   1.1       gwr /*
    431   1.1       gwr  * Get/Set keymap entry,
    432   1.1       gwr  * old format (compatibility)
    433   1.1       gwr  */
    434   1.1       gwr int
    435   1.1       gwr kbd_oldkeymap(ks, cmd, kio)
    436   1.1       gwr 	struct kbd_state *ks;
    437   1.1       gwr 	u_long cmd;
    438   1.1       gwr 	struct okiockey *kio;
    439   1.1       gwr {
    440   1.1       gwr 	int error = 0;
    441   1.1       gwr 
    442   1.1       gwr 	switch (cmd) {
    443   1.1       gwr 
    444   1.1       gwr 	case KIOCGETKEY:
    445   1.1       gwr 		if (kio->kio_station == 118) {
    446   1.1       gwr 			/*
    447   1.1       gwr 			 * This is X11 asking if a type 3 keyboard is
    448   1.1       gwr 			 * really a type 3 keyboard.  Say yes, it is,
    449   1.1       gwr 			 * by reporting key station 118 as a "hole".
    450   1.1       gwr 			 * Note old (SunOS 3.5) definition of HOLE!
    451   1.1       gwr 			 */
    452   1.1       gwr 			kio->kio_entry = 0xA2;
    453   1.1       gwr 			break;
    454   1.1       gwr 		}
    455   1.1       gwr 		/* fall through */
    456   1.1       gwr 
    457   1.1       gwr 	default:
    458   1.1       gwr 		error = ENOTTY;
    459   1.1       gwr 		break;
    460   1.1       gwr 	}
    461   1.1       gwr 
    462   1.1       gwr 	return (error);
    463   1.1       gwr }
    464  1.32       uwe #endif /* KIOCGETKEY */
    465   1.1       gwr 
    466   1.7       gwr 
    467  1.33       uwe 
    468  1.32       uwe /****************************************************************
    469  1.33       uwe  *  Keyboard input - called by middle layer at spltty().
    470  1.32       uwe  ****************************************************************/
    471  1.32       uwe 
    472  1.33       uwe void
    473  1.33       uwe kbd_input(k, code)
    474  1.33       uwe 	struct kbd_softc *k;
    475  1.33       uwe 	int code;
    476  1.33       uwe {
    477  1.35    martin 	if (k->k_evmode) {
    478  1.35    martin 
    479  1.35    martin #ifdef KBD_IDLE_EVENTS
    480  1.35    martin 		/*
    481  1.35    martin 		 * XXX: is this still true?
    482  1.35    martin 		 * IDLEs confuse the MIT X11R4 server badly, so we must drop them.
    483  1.35    martin 		 * This is bad as it means the server will not automatically resync
    484  1.35    martin 		 * on all-up IDLEs, but I did not drop them before, and the server
    485  1.35    martin 		 * goes crazy when it comes time to blank the screen....
    486  1.35    martin 		 */
    487  1.35    martin 		if (code == KBD_IDLE)
    488  1.35    martin 			return;
    489  1.35    martin #endif
    490  1.33       uwe 
    491  1.35    martin 		/*
    492  1.35    martin 		 * Keyboard is generating firm events.  Turn this keystroke
    493  1.35    martin 		 * into an event and put it in the queue.
    494  1.35    martin 		 */
    495  1.35    martin 		kbd_input_event(k, code);
    496  1.33       uwe 		return;
    497  1.33       uwe 	}
    498  1.33       uwe 
    499  1.35    martin #if NWSKBD > 0
    500  1.35    martin 	if (k->k_wskbd != NULL && k->k_wsenabled) {
    501  1.35    martin 		/*
    502  1.35    martin 		 * We are using wskbd input mode, pass the event up.
    503  1.35    martin 		 */
    504  1.35    martin 		kbd_input_wskbd(k, code);
    505  1.33       uwe 		return;
    506  1.35    martin 	}
    507  1.35    martin #endif
    508  1.33       uwe 
    509  1.33       uwe 	/*
    510  1.35    martin 	 * If /dev/kbd is not connected in event mode, or wskbd mode,
    511  1.35    martin 	 * translate and send upstream (to console).
    512  1.33       uwe 	 */
    513  1.35    martin 	kbd_input_console(k, code);
    514  1.33       uwe }
    515  1.33       uwe 
    516  1.33       uwe 
    517  1.33       uwe 
    518  1.33       uwe /****************************************************************
    519  1.33       uwe  *  Open/close routines called upon opening /dev/console
    520  1.33       uwe  *  if we serve console input.
    521  1.33       uwe  ****************************************************************/
    522  1.33       uwe 
    523  1.33       uwe struct cons_channel *
    524  1.33       uwe kbd_cc_alloc(k)
    525  1.33       uwe 	struct kbd_softc *k;
    526  1.33       uwe {
    527  1.33       uwe 	struct cons_channel *cc;
    528  1.33       uwe 
    529  1.33       uwe 	if ((cc = malloc(sizeof *cc, M_DEVBUF, M_NOWAIT)) == NULL)
    530  1.33       uwe 		return (NULL);
    531  1.33       uwe 
    532  1.33       uwe 	/* our callbacks for the console driver */
    533  1.33       uwe 	cc->cc_dev = k;
    534  1.33       uwe 	cc->cc_iopen = kbd_cc_open;
    535  1.33       uwe 	cc->cc_iclose = kbd_cc_close;
    536  1.33       uwe 
    537  1.33       uwe 	/* will be provided by the console driver so that we can feed input */
    538  1.33       uwe 	cc->cc_upstream = NULL;
    539  1.33       uwe 
    540  1.33       uwe 	/*
    541  1.33       uwe 	 * TODO: clean up cons_attach_input() vs kd_attach_input() in
    542  1.33       uwe 	 * lower layers and move that code here.
    543  1.33       uwe 	 */
    544  1.33       uwe 
    545  1.33       uwe 	k->k_cc = cc;
    546  1.33       uwe 	return (cc);
    547  1.33       uwe }
    548  1.33       uwe 
    549  1.33       uwe 
    550  1.33       uwe static int
    551  1.32       uwe kbd_cc_open(cc)
    552  1.32       uwe 	struct cons_channel *cc;
    553  1.15       gwr {
    554   1.7       gwr 	struct kbd_softc *k;
    555  1.33       uwe 	int ret;
    556  1.15       gwr 
    557  1.32       uwe 	if (cc == NULL)
    558  1.33       uwe 		return (0);
    559   1.7       gwr 
    560  1.32       uwe 	k = (struct kbd_softc *)cc->cc_dev;
    561  1.33       uwe 	if (k == NULL)
    562  1.33       uwe 		return (0);
    563  1.33       uwe 
    564  1.33       uwe 	if (k->k_ops != NULL && k->k_ops->open != NULL)
    565  1.33       uwe 		ret = (*k->k_ops->open)(k);
    566  1.32       uwe 	else
    567  1.33       uwe 		ret = 0;
    568  1.33       uwe 
    569  1.33       uwe 	/* XXX: verify that callout is not active? */
    570  1.33       uwe 	k->k_repeat_start = hz/2;
    571  1.33       uwe 	k->k_repeat_step = hz/20;
    572  1.33       uwe 	callout_init(&k->k_repeat_ch);
    573  1.33       uwe 
    574  1.33       uwe 	return (ret);
    575  1.32       uwe }
    576   1.7       gwr 
    577   1.7       gwr 
    578  1.33       uwe static int
    579  1.32       uwe kbd_cc_close(cc)
    580  1.32       uwe 	struct cons_channel *cc;
    581  1.32       uwe {
    582   1.7       gwr 	struct kbd_softc *k;
    583  1.33       uwe 	int ret;
    584   1.7       gwr 
    585  1.32       uwe 	if (cc == NULL)
    586  1.33       uwe 		return (0);
    587   1.7       gwr 
    588  1.32       uwe 	k = (struct kbd_softc *)cc->cc_dev;
    589  1.33       uwe 	if (k == NULL)
    590  1.33       uwe 		return (0);
    591  1.33       uwe 
    592  1.33       uwe 	if (k->k_ops != NULL && k->k_ops->close != NULL)
    593  1.33       uwe 		ret = (*k->k_ops->close)(k);
    594  1.32       uwe 	else
    595  1.33       uwe 		ret = 0;
    596  1.33       uwe 
    597  1.33       uwe 	/* stop any pending auto-repeat */
    598  1.33       uwe 	if (k->k_repeating) {
    599  1.33       uwe 		k->k_repeating = 0;
    600  1.33       uwe 		callout_stop(&k->k_repeat_ch);
    601  1.33       uwe 	}
    602  1.33       uwe 
    603  1.33       uwe 	return (ret);
    604   1.7       gwr }
    605   1.7       gwr 
    606   1.7       gwr 
    607  1.33       uwe 
    608   1.1       gwr /****************************************************************
    609  1.32       uwe  *  Console input - called by middle layer at spltty().
    610   1.1       gwr  ****************************************************************/
    611   1.1       gwr 
    612  1.33       uwe static void
    613  1.33       uwe kbd_input_console(k, code)
    614  1.33       uwe 	struct kbd_softc *k;
    615  1.33       uwe 	int code;
    616  1.33       uwe {
    617  1.33       uwe 	struct kbd_state *ks= &k->k_state;
    618  1.33       uwe 	int keysym;
    619  1.33       uwe 
    620  1.33       uwe 	/* any input stops auto-repeat (i.e. key release) */
    621  1.33       uwe 	if (k->k_repeating) {
    622  1.33       uwe 		k->k_repeating = 0;
    623  1.33       uwe 		callout_stop(&k->k_repeat_ch);
    624  1.33       uwe 	}
    625  1.33       uwe 
    626  1.33       uwe 	keysym = kbd_code_to_keysym(ks, code);
    627  1.33       uwe 
    628  1.33       uwe 	/* pass to console */
    629  1.33       uwe 	if (kbd_input_keysym(k, keysym)) {
    630  1.33       uwe 		log(LOG_WARNING, "%s: code=0x%x with mod=0x%x"
    631  1.33       uwe 		    " produced unexpected keysym 0x%x\n",
    632  1.33       uwe 		    k->k_dev.dv_xname,
    633  1.33       uwe 		    code, ks->kbd_modbits, keysym);
    634  1.33       uwe 		return;		/* no point in auto-repeat here */
    635  1.33       uwe 	}
    636  1.33       uwe 
    637  1.33       uwe 	if (KEYSYM_NOREPEAT(keysym))
    638  1.33       uwe 		return;
    639  1.33       uwe 
    640  1.33       uwe 	/* setup for auto-repeat after initial delay */
    641  1.33       uwe 	k->k_repeating = 1;
    642  1.33       uwe 	k->k_repeatsym = keysym;
    643  1.33       uwe 	callout_reset(&k->k_repeat_ch, k->k_repeat_start,
    644  1.33       uwe 		      kbd_repeat, k);
    645  1.33       uwe }
    646  1.33       uwe 
    647  1.33       uwe 
    648  1.33       uwe /*
    649  1.33       uwe  * This is the autorepeat callout function scheduled by kbd_input() above.
    650  1.33       uwe  * Called at splsoftclock().
    651  1.33       uwe  */
    652  1.33       uwe static void
    653  1.33       uwe kbd_repeat(arg)
    654  1.33       uwe 	void *arg;
    655  1.33       uwe {
    656  1.33       uwe 	struct kbd_softc *k = (struct kbd_softc *)arg;
    657  1.33       uwe 	int s;
    658  1.33       uwe 
    659  1.33       uwe 	s = spltty();
    660  1.33       uwe 	if (k->k_repeating && k->k_repeatsym >= 0) {
    661  1.33       uwe 		/* feed typematic keysym to the console */
    662  1.33       uwe 		(void)kbd_input_keysym(k, k->k_repeatsym);
    663  1.33       uwe 
    664  1.33       uwe 		/* reschedule next repeat */
    665  1.33       uwe 		callout_reset(&k->k_repeat_ch, k->k_repeat_step,
    666  1.33       uwe 			      kbd_repeat, k);
    667  1.33       uwe 	}
    668  1.33       uwe 	splx(s);
    669  1.33       uwe }
    670  1.33       uwe 
    671  1.33       uwe 
    672  1.33       uwe 
    673   1.1       gwr /*
    674  1.33       uwe  * Supply keysym as console input.  Convert keysym to character(s) and
    675  1.33       uwe  * pass them up to cons_channel's upstream hook.
    676  1.17       gwr  *
    677  1.32       uwe  * Return zero on success, else the keysym that we could not handle
    678  1.32       uwe  * (so that the caller may complain).
    679   1.1       gwr  */
    680  1.33       uwe static int
    681   1.1       gwr kbd_input_keysym(k, keysym)
    682   1.1       gwr 	struct kbd_softc *k;
    683  1.23        pk 	int keysym;
    684   1.1       gwr {
    685   1.1       gwr 	struct kbd_state *ks = &k->k_state;
    686  1.23        pk 	int data;
    687  1.30        pk 
    688  1.30        pk 	/* Check if a recipient has been configured */
    689  1.32       uwe 	if (k->k_cc == NULL || k->k_cc->cc_upstream == NULL)
    690  1.30        pk 		return (0);
    691   1.1       gwr 
    692   1.4       gwr 	switch (KEYSYM_CLASS(keysym)) {
    693   1.1       gwr 
    694   1.1       gwr 	case KEYSYM_ASCII:
    695   1.1       gwr 		data = KEYSYM_DATA(keysym);
    696   1.1       gwr 		if (ks->kbd_modbits & KBMOD_META_MASK)
    697   1.1       gwr 			data |= 0x80;
    698  1.23        pk 		(*k->k_cc->cc_upstream)(data);
    699   1.1       gwr 		break;
    700   1.1       gwr 
    701   1.1       gwr 	case KEYSYM_STRING:
    702   1.1       gwr 		data = keysym & 0xF;
    703   1.1       gwr 		kbd_input_string(k, kbd_stringtab[data]);
    704   1.1       gwr 		break;
    705   1.1       gwr 
    706   1.1       gwr 	case KEYSYM_FUNC:
    707   1.1       gwr 		kbd_input_funckey(k, keysym);
    708   1.1       gwr 		break;
    709   1.1       gwr 
    710   1.1       gwr 	case KEYSYM_CLRMOD:
    711   1.1       gwr 		data = 1 << (keysym & 0x1F);
    712   1.1       gwr 		ks->kbd_modbits &= ~data;
    713   1.1       gwr 		break;
    714   1.1       gwr 
    715   1.1       gwr 	case KEYSYM_SETMOD:
    716   1.1       gwr 		data = 1 << (keysym & 0x1F);
    717   1.1       gwr 		ks->kbd_modbits |= data;
    718   1.1       gwr 		break;
    719   1.1       gwr 
    720   1.1       gwr 	case KEYSYM_INVMOD:
    721   1.1       gwr 		data = 1 << (keysym & 0x1F);
    722   1.1       gwr 		ks->kbd_modbits ^= data;
    723   1.4       gwr 		kbd_update_leds(k);
    724   1.1       gwr 		break;
    725   1.1       gwr 
    726   1.1       gwr 	case KEYSYM_ALL_UP:
    727   1.1       gwr 		ks->kbd_modbits &= ~0xFFFF;
    728   1.1       gwr 		break;
    729   1.1       gwr 
    730   1.1       gwr 	case KEYSYM_SPECIAL:
    731   1.1       gwr 		if (keysym == KEYSYM_NOP)
    732   1.1       gwr 			break;
    733  1.32       uwe 		/* FALLTHROUGH */
    734   1.1       gwr 	default:
    735  1.17       gwr 		/* We could not handle it. */
    736  1.17       gwr 		return (keysym);
    737   1.1       gwr 	}
    738  1.32       uwe 
    739  1.17       gwr 	return (0);
    740   1.1       gwr }
    741   1.1       gwr 
    742  1.32       uwe 
    743   1.1       gwr /*
    744  1.32       uwe  * Send string upstream.
    745   1.1       gwr  */
    746  1.13       gwr static void
    747  1.32       uwe kbd_input_string(k, str)
    748  1.32       uwe 	struct kbd_softc *k;
    749  1.32       uwe 	char *str;
    750   1.1       gwr {
    751   1.1       gwr 
    752  1.32       uwe 	while (*str) {
    753  1.32       uwe 		(*k->k_cc->cc_upstream)(*str);
    754  1.32       uwe 		++str;
    755   1.1       gwr 	}
    756   1.1       gwr }
    757   1.1       gwr 
    758  1.32       uwe 
    759   1.1       gwr /*
    760  1.32       uwe  * Format the F-key sequence and send as a string.
    761  1.32       uwe  * XXX: Ugly compatibility mappings.
    762   1.1       gwr  */
    763  1.32       uwe static void
    764  1.32       uwe kbd_input_funckey(k, keysym)
    765   1.1       gwr 	struct kbd_softc *k;
    766  1.32       uwe 	int keysym;
    767   1.1       gwr {
    768  1.32       uwe 	int n;
    769  1.32       uwe 	char str[12];
    770  1.32       uwe 
    771  1.32       uwe 	n = 0xC0 + (keysym & 0x3F);
    772  1.32       uwe 	sprintf(str, "\033[%dz", n);
    773  1.32       uwe 	kbd_input_string(k, str);
    774  1.32       uwe }
    775   1.1       gwr 
    776   1.1       gwr 
    777  1.32       uwe /*
    778  1.32       uwe  * Update LEDs to reflect console input state.
    779  1.32       uwe  */
    780  1.32       uwe static void
    781  1.32       uwe kbd_update_leds(k)
    782  1.32       uwe 	struct kbd_softc *k;
    783  1.32       uwe {
    784  1.32       uwe 	struct kbd_state *ks = &k->k_state;
    785  1.32       uwe 	char leds;
    786   1.1       gwr 
    787  1.32       uwe 	leds = ks->kbd_leds;
    788  1.32       uwe 	leds &= ~(LED_CAPS_LOCK|LED_NUM_LOCK);
    789   1.1       gwr 
    790  1.32       uwe 	if (ks->kbd_modbits & (1 << KBMOD_CAPSLOCK))
    791  1.32       uwe 		leds |= LED_CAPS_LOCK;
    792  1.32       uwe 	if (ks->kbd_modbits & (1 << KBMOD_NUMLOCK))
    793  1.32       uwe 		leds |= LED_NUM_LOCK;
    794   1.1       gwr 
    795  1.32       uwe 	if (k->k_ops != NULL && k->k_ops->setleds != NULL)
    796  1.32       uwe 		(void)(*k->k_ops->setleds)(k, leds, 0);
    797  1.32       uwe }
    798   1.1       gwr 
    799   1.1       gwr 
    800   1.1       gwr 
    801  1.32       uwe /****************************************************************
    802  1.32       uwe  *  Events input - called by middle layer at spltty().
    803  1.32       uwe  ****************************************************************/
    804   1.1       gwr 
    805  1.32       uwe /*
    806  1.33       uwe  * Supply raw keystrokes when keyboard is open in firm event mode.
    807  1.32       uwe  *
    808  1.32       uwe  * Turn the keystroke into an event and put it in the queue.
    809  1.32       uwe  * If the queue is full, the keystroke is lost (sorry!).
    810  1.32       uwe  */
    811  1.33       uwe static void
    812  1.33       uwe kbd_input_event(k, code)
    813  1.32       uwe 	struct kbd_softc *k;
    814  1.33       uwe 	int code;
    815  1.32       uwe {
    816  1.32       uwe 	struct firm_event *fe;
    817  1.32       uwe 	int put;
    818   1.1       gwr 
    819  1.32       uwe #ifdef DIAGNOSTIC
    820  1.32       uwe 	if (!k->k_evmode) {
    821  1.32       uwe 		printf("%s: kbd_input_event called when not in event mode\n",
    822  1.32       uwe 		       k->k_dev.dv_xname);
    823   1.1       gwr 		return;
    824   1.1       gwr 	}
    825  1.32       uwe #endif
    826   1.1       gwr 	put = k->k_events.ev_put;
    827   1.1       gwr 	fe = &k->k_events.ev_q[put];
    828   1.1       gwr 	put = (put + 1) % EV_QSIZE;
    829   1.1       gwr 	if (put == k->k_events.ev_get) {
    830   1.1       gwr 		log(LOG_WARNING, "%s: event queue overflow\n",
    831  1.32       uwe 		    k->k_dev.dv_xname);
    832   1.1       gwr 		return;
    833   1.1       gwr 	}
    834  1.33       uwe 
    835  1.33       uwe 	fe->id = KEY_CODE(code);
    836  1.33       uwe 	fe->value = KEY_UP(code) ? VKEY_UP : VKEY_DOWN;
    837   1.1       gwr 	fe->time = time;
    838   1.1       gwr 	k->k_events.ev_put = put;
    839   1.1       gwr 	EV_WAKEUP(&k->k_events);
    840   1.1       gwr }
    841   1.1       gwr 
    842  1.32       uwe 
    843  1.33       uwe 
    844  1.32       uwe /****************************************************************
    845  1.32       uwe  *  Translation stuff declared in kbd_xlate.h
    846  1.32       uwe  ****************************************************************/
    847  1.24        pk 
    848  1.24        pk /*
    849  1.32       uwe  * Initialization - called by either lower layer attach or by kdcninit.
    850  1.24        pk  */
    851  1.32       uwe void
    852  1.32       uwe kbd_xlate_init(ks)
    853  1.32       uwe 	struct kbd_state *ks;
    854  1.24        pk {
    855  1.32       uwe 	struct keyboard *ktbls;
    856  1.32       uwe 	int id;
    857  1.32       uwe 
    858  1.32       uwe 	id = ks->kbd_id;
    859  1.32       uwe 	if (id < KBD_MIN_TYPE)
    860  1.32       uwe 		id = KBD_MIN_TYPE;
    861  1.32       uwe 	if (id > kbd_max_type)
    862  1.32       uwe 		id = kbd_max_type;
    863  1.32       uwe 	ktbls = keyboards[id];
    864  1.24        pk 
    865  1.32       uwe 	ks->kbd_k = *ktbls; 	/* struct assignment */
    866  1.32       uwe 	ks->kbd_modbits = 0;
    867  1.24        pk }
    868   1.1       gwr 
    869   1.1       gwr /*
    870  1.32       uwe  * Turn keyboard up/down codes into a KEYSYM.
    871  1.32       uwe  * Note that the "kd" driver (on sun3 and sparc64) uses this too!
    872   1.1       gwr  */
    873   1.1       gwr int
    874  1.32       uwe kbd_code_to_keysym(ks, c)
    875  1.32       uwe 	struct kbd_state *ks;
    876  1.32       uwe 	int c;
    877   1.1       gwr {
    878  1.32       uwe 	u_short *km;
    879  1.32       uwe 	int keysym;
    880   1.1       gwr 
    881  1.32       uwe 	/*
    882  1.32       uwe 	 * Get keymap pointer.  One of these:
    883  1.32       uwe 	 * release, control, shifted, normal, ...
    884  1.32       uwe 	 */
    885  1.32       uwe 	if (KEY_UP(c))
    886  1.32       uwe 		km = ks->kbd_k.k_release;
    887  1.32       uwe 	else if (ks->kbd_modbits & KBMOD_CTRL_MASK)
    888  1.32       uwe 		km = ks->kbd_k.k_control;
    889  1.32       uwe 	else if (ks->kbd_modbits & KBMOD_SHIFT_MASK)
    890  1.32       uwe 		km = ks->kbd_k.k_shifted;
    891  1.32       uwe 	else
    892  1.32       uwe 		km = ks->kbd_k.k_normal;
    893  1.23        pk 
    894  1.32       uwe 	if (km == NULL) {
    895   1.1       gwr 		/*
    896  1.32       uwe 		 * Do not know how to translate yet.
    897  1.32       uwe 		 * We will find out when a RESET comes along.
    898   1.1       gwr 		 */
    899  1.32       uwe 		return (KEYSYM_NOP);
    900   1.1       gwr 	}
    901  1.32       uwe 	keysym = km[KEY_CODE(c)];
    902   1.1       gwr 
    903   1.1       gwr 	/*
    904  1.32       uwe 	 * Post-processing for Caps-lock
    905   1.1       gwr 	 */
    906  1.32       uwe 	if ((ks->kbd_modbits & (1 << KBMOD_CAPSLOCK)) &&
    907  1.32       uwe 		(KEYSYM_CLASS(keysym) == KEYSYM_ASCII) )
    908  1.32       uwe 	{
    909  1.32       uwe 		if (('a' <= keysym) && (keysym <= 'z'))
    910  1.32       uwe 			keysym -= ('a' - 'A');
    911   1.1       gwr 	}
    912   1.1       gwr 
    913   1.1       gwr 	/*
    914  1.32       uwe 	 * Post-processing for Num-lock.  All "function"
    915  1.32       uwe 	 * keysyms get indirected through another table.
    916  1.32       uwe 	 * (XXX: Only if numlock on.  Want off also!)
    917   1.1       gwr 	 */
    918  1.32       uwe 	if ((ks->kbd_modbits & (1 << KBMOD_NUMLOCK)) &&
    919  1.32       uwe 		(KEYSYM_CLASS(keysym) == KEYSYM_FUNC) )
    920  1.32       uwe 	{
    921  1.32       uwe 		keysym = kbd_numlock_map[keysym & 0x3F];
    922   1.1       gwr 	}
    923   1.7       gwr 
    924  1.32       uwe 	return (keysym);
    925   1.1       gwr }
    926   1.1       gwr 
    927   1.1       gwr 
    928   1.7       gwr /*
    929  1.32       uwe  * Back door for rcons (fb.c)
    930   1.7       gwr  */
    931  1.22       mrg void
    932  1.32       uwe kbd_bell(on)
    933  1.32       uwe 	int on;
    934   1.1       gwr {
    935  1.33       uwe 	struct kbd_softc *k = kbd_cd.cd_devs[0]; /* XXX: hardcoded minor */
    936  1.33       uwe 
    937  1.33       uwe 	if (k == NULL || k->k_ops == NULL || k->k_ops->docmd == NULL)
    938  1.33       uwe 		return;
    939  1.33       uwe 
    940  1.33       uwe 	(void)(*k->k_ops->docmd)(k, on ? KBD_CMD_BELL : KBD_CMD_NOBELL, 0);
    941   1.1       gwr }
    942  1.35    martin 
    943  1.35    martin #if NWSKBD > 0
    944  1.35    martin static void
    945  1.35    martin kbd_input_wskbd(struct kbd_softc *k, int code)
    946  1.35    martin {
    947  1.35    martin 	int type, key;
    948  1.35    martin 
    949  1.35    martin 	type = KEY_UP(code) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
    950  1.35    martin 	key = KEY_CODE(code);
    951  1.35    martin 	wskbd_input(k->k_wskbd, type, key);
    952  1.35    martin }
    953  1.35    martin 
    954  1.35    martin int
    955  1.35    martin wssunkbd_enable(v, on)
    956  1.35    martin 	void *v;
    957  1.35    martin 	int on;
    958  1.35    martin {
    959  1.35    martin 	struct kbd_softc *k = v;
    960  1.35    martin 
    961  1.35    martin 	k->k_wsenabled = on;
    962  1.35    martin 	if (on) {
    963  1.35    martin 		/* open actual underlying device */
    964  1.35    martin 		if (k->k_ops != NULL && k->k_ops->open != NULL)
    965  1.35    martin 			(*k->k_ops->open)(k);
    966  1.35    martin 		ev_init(&k->k_events);
    967  1.35    martin 		k->k_evmode = 0;	/* XXX: OK? */
    968  1.35    martin 	} else {
    969  1.35    martin 		/* close underlying device */
    970  1.35    martin 		if (k->k_ops != NULL && k->k_ops->close != NULL)
    971  1.35    martin 			(*k->k_ops->close)(k);
    972  1.35    martin 	}
    973  1.35    martin 
    974  1.35    martin 	return 0;
    975  1.35    martin }
    976  1.35    martin 
    977  1.35    martin void
    978  1.35    martin wssunkbd_set_leds(v, leds)
    979  1.35    martin 	void *v;
    980  1.35    martin 	int leds;
    981  1.35    martin {
    982  1.35    martin 	struct kbd_softc *k = v;
    983  1.35    martin 	int l = 0;
    984  1.35    martin 
    985  1.35    martin 	if (leds & WSKBD_LED_CAPS)
    986  1.35    martin 		l |= LED_CAPS_LOCK;
    987  1.35    martin 	if (leds & WSKBD_LED_NUM)
    988  1.35    martin 		l |= LED_NUM_LOCK;
    989  1.35    martin 	if (leds & WSKBD_LED_SCROLL)
    990  1.35    martin 		l |= LED_SCROLL_LOCK;
    991  1.35    martin 	if (leds & WSKBD_LED_COMPOSE)
    992  1.35    martin 		l |= LED_COMPOSE;
    993  1.35    martin 	if (k->k_ops != NULL && k->k_ops->setleds != NULL)
    994  1.35    martin 		(*k->k_ops->setleds)(k, l, 0);
    995  1.35    martin }
    996  1.35    martin 
    997  1.35    martin int
    998  1.36   darrenr wssunkbd_ioctl(v, cmd, data, flag, l)
    999  1.35    martin 	void *v;
   1000  1.35    martin 	u_long cmd;
   1001  1.35    martin 	caddr_t data;
   1002  1.35    martin 	int flag;
   1003  1.36   darrenr 	struct lwp *l;
   1004  1.35    martin {
   1005  1.35    martin 	return EPASSTHROUGH;
   1006  1.35    martin }
   1007  1.35    martin 
   1008  1.35    martin void
   1009  1.35    martin sunkbd_wskbd_cngetc(v, type, data)
   1010  1.35    martin 	void *v;
   1011  1.35    martin 	u_int *type;
   1012  1.35    martin 	int *data;
   1013  1.35    martin {
   1014  1.35    martin 	/* struct kbd_sun_softc *k = v; */
   1015  1.35    martin }
   1016  1.35    martin 
   1017  1.35    martin void
   1018  1.35    martin sunkbd_wskbd_cnpollc(v, on)
   1019  1.35    martin 	void *v;
   1020  1.35    martin 	int on;
   1021  1.35    martin {
   1022  1.35    martin }
   1023  1.35    martin 
   1024  1.35    martin static void
   1025  1.35    martin sunkbd_bell_off(v)
   1026  1.35    martin 	void *v;
   1027  1.35    martin {
   1028  1.35    martin 	struct kbd_softc *k = v;
   1029  1.35    martin 	k->k_ops->docmd(k, KBD_CMD_NOBELL, 0);
   1030  1.35    martin }
   1031  1.35    martin 
   1032  1.35    martin void
   1033  1.35    martin sunkbd_wskbd_cnbell(v, pitch, period, volume)
   1034  1.35    martin 	void *v;
   1035  1.35    martin 	u_int pitch, period, volume;
   1036  1.35    martin {
   1037  1.35    martin 	struct kbd_softc *k = v;
   1038  1.35    martin 
   1039  1.35    martin 	callout_reset(&k->k_wsbell, period*1000/hz, sunkbd_bell_off, v);
   1040  1.35    martin 	k->k_ops->docmd(k, KBD_CMD_BELL, 0);
   1041  1.35    martin }
   1042  1.35    martin 
   1043  1.35    martin void
   1044  1.35    martin kbd_wskbd_attach(k, isconsole)
   1045  1.35    martin 	struct kbd_softc *k;
   1046  1.35    martin 	int isconsole;
   1047  1.35    martin {
   1048  1.35    martin 	struct wskbddev_attach_args a;
   1049  1.35    martin 
   1050  1.35    martin 	a.console = isconsole;
   1051  1.35    martin 
   1052  1.35    martin 	if (a.console)
   1053  1.35    martin 		wskbd_cnattach(&sunkbd_wskbd_consops, k, &sunkbd_wskbd_keymapdata);
   1054  1.35    martin 
   1055  1.35    martin 	a.keymap = &sunkbd_wskbd_keymapdata;
   1056  1.35    martin 
   1057  1.35    martin 	a.accessops = &sunkbd_wskbd_accessops;
   1058  1.35    martin 	a.accesscookie = k;
   1059  1.35    martin 
   1060  1.35    martin 	/* Attach the wskbd */
   1061  1.35    martin 	k->k_wskbd = config_found(&k->k_dev, &a, wskbddevprint);
   1062  1.35    martin 	k->k_wsenabled = 0;
   1063  1.35    martin 	callout_init(&k->k_wsbell);
   1064  1.35    martin }
   1065  1.35    martin #endif
   1066