Home | History | Annotate | Line # | Download | only in sun
kbdsun.c revision 1.1
      1  1.1  uwe /*	$NetBSD: kbdsun.c,v 1.1 2002/10/03 16:13:26 uwe Exp $	*/
      2  1.1  uwe /*	NetBSD: kbd.c,v 1.29 2001/11/13 06:54:32 lukem Exp	*/
      3  1.1  uwe 
      4  1.1  uwe /*
      5  1.1  uwe  * Copyright (c) 1992, 1993
      6  1.1  uwe  *	The Regents of the University of California.  All rights reserved.
      7  1.1  uwe  *
      8  1.1  uwe  * This software was developed by the Computer Systems Engineering group
      9  1.1  uwe  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     10  1.1  uwe  * contributed to Berkeley.
     11  1.1  uwe  *
     12  1.1  uwe  * All advertising materials mentioning features or use of this software
     13  1.1  uwe  * must display the following acknowledgement:
     14  1.1  uwe  *	This product includes software developed by the University of
     15  1.1  uwe  *	California, Lawrence Berkeley Laboratory.
     16  1.1  uwe  *
     17  1.1  uwe  * Redistribution and use in source and binary forms, with or without
     18  1.1  uwe  * modification, are permitted provided that the following conditions
     19  1.1  uwe  * are met:
     20  1.1  uwe  * 1. Redistributions of source code must retain the above copyright
     21  1.1  uwe  *    notice, this list of conditions and the following disclaimer.
     22  1.1  uwe  * 2. Redistributions in binary form must reproduce the above copyright
     23  1.1  uwe  *    notice, this list of conditions and the following disclaimer in the
     24  1.1  uwe  *    documentation and/or other materials provided with the distribution.
     25  1.1  uwe  * 3. All advertising materials mentioning features or use of this software
     26  1.1  uwe  *    must display the following acknowledgement:
     27  1.1  uwe  *	This product includes software developed by the University of
     28  1.1  uwe  *	California, Berkeley and its contributors.
     29  1.1  uwe  * 4. Neither the name of the University nor the names of its contributors
     30  1.1  uwe  *    may be used to endorse or promote products derived from this software
     31  1.1  uwe  *    without specific prior written permission.
     32  1.1  uwe  *
     33  1.1  uwe  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     34  1.1  uwe  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     35  1.1  uwe  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     36  1.1  uwe  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     37  1.1  uwe  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     38  1.1  uwe  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     39  1.1  uwe  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     40  1.1  uwe  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     41  1.1  uwe  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     42  1.1  uwe  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     43  1.1  uwe  * SUCH DAMAGE.
     44  1.1  uwe  *
     45  1.1  uwe  *	@(#)kbd.c	8.2 (Berkeley) 10/30/93
     46  1.1  uwe  */
     47  1.1  uwe 
     48  1.1  uwe /*
     49  1.1  uwe  * /dev/kbd middle layer for sun keyboard off a serial line
     50  1.1  uwe  * This code is used by kbd_zs and sunkbd drivers (lower layer).
     51  1.1  uwe  */
     52  1.1  uwe 
     53  1.1  uwe #include <sys/cdefs.h>
     54  1.1  uwe __KERNEL_RCSID(0, "$NetBSD: kbdsun.c,v 1.1 2002/10/03 16:13:26 uwe Exp $");
     55  1.1  uwe 
     56  1.1  uwe #include <sys/param.h>
     57  1.1  uwe #include <sys/systm.h>
     58  1.1  uwe #include <sys/conf.h>
     59  1.1  uwe #include <sys/device.h>
     60  1.1  uwe #include <sys/ioctl.h>
     61  1.1  uwe #include <sys/kernel.h>
     62  1.1  uwe #include <sys/proc.h>
     63  1.1  uwe #include <sys/signal.h>
     64  1.1  uwe #include <sys/signalvar.h>
     65  1.1  uwe #include <sys/time.h>
     66  1.1  uwe #include <sys/syslog.h>
     67  1.1  uwe #include <sys/select.h>
     68  1.1  uwe #include <sys/poll.h>
     69  1.1  uwe #include <sys/file.h>
     70  1.1  uwe 
     71  1.1  uwe #include <machine/vuid_event.h>
     72  1.1  uwe #include <machine/kbd.h>
     73  1.1  uwe #include <machine/kbio.h>
     74  1.1  uwe #include <dev/sun/event_var.h>
     75  1.1  uwe #include <dev/sun/kbd_xlate.h>
     76  1.1  uwe 
     77  1.1  uwe #include <dev/sun/kbdvar.h>
     78  1.1  uwe #include <dev/sun/kbdsunvar.h>
     79  1.1  uwe 
     80  1.1  uwe 
     81  1.1  uwe /* callbacks for the upper /dev/kbd layer */
     82  1.1  uwe static int	kbd_sun_open(struct kbd_softc *);
     83  1.1  uwe static int	kbd_sun_close(struct kbd_softc *);
     84  1.1  uwe static int	kbd_sun_do_cmd(struct kbd_softc *, int, int);
     85  1.1  uwe static int	kbd_sun_set_leds(struct kbd_softc *, int, int);
     86  1.1  uwe 
     87  1.1  uwe static void	kbd_sun_set_leds1(struct kbd_softc *, int); /* aux */
     88  1.1  uwe 
     89  1.1  uwe struct kbd_ops kbd_ops_sun = {
     90  1.1  uwe 	kbd_sun_open,
     91  1.1  uwe 	kbd_sun_close,
     92  1.1  uwe 	kbd_sun_do_cmd,
     93  1.1  uwe 	kbd_sun_set_leds
     94  1.1  uwe };
     95  1.1  uwe 
     96  1.1  uwe /* in user context, wait for keyboard output to finish */
     97  1.1  uwe static int 	kbd_sun_drain_tx(struct kbd_sun_softc *);
     98  1.1  uwe 
     99  1.1  uwe /* helper functions for kbd_sun_input */
    100  1.1  uwe static void	kbd_sun_was_reset(struct kbd_sun_softc *);
    101  1.1  uwe static void	kbd_sun_new_layout(struct kbd_sun_softc *);
    102  1.1  uwe static void	kbd_sun_repeat(void *);
    103  1.1  uwe 
    104  1.1  uwe 
    105  1.1  uwe /***********************************************************************
    106  1.1  uwe  *		      Callbacks for upper layer.
    107  1.1  uwe  */
    108  1.1  uwe 
    109  1.1  uwe /*
    110  1.1  uwe  * Initialization to be done at first open.
    111  1.1  uwe  * This is called from kbdopen() or kd_cc_open()
    112  1.1  uwe  * Called with user context.
    113  1.1  uwe  */
    114  1.1  uwe static int
    115  1.1  uwe kbd_sun_open(kbd)
    116  1.1  uwe 	struct kbd_softc *kbd;
    117  1.1  uwe {
    118  1.1  uwe 	struct kbd_sun_softc *k = (struct kbd_sun_softc *)kbd;
    119  1.1  uwe 	struct kbd_state *ks;
    120  1.1  uwe 	int error, s;
    121  1.1  uwe 
    122  1.1  uwe 	if (kbd == NULL)
    123  1.1  uwe 		return (ENXIO);
    124  1.1  uwe 
    125  1.1  uwe 	ks = &kbd->k_state;
    126  1.1  uwe 
    127  1.1  uwe 	/* tolerate extra calls. */
    128  1.1  uwe 	if (k->k_isopen)
    129  1.1  uwe 		return (0);
    130  1.1  uwe 
    131  1.1  uwe 	/* stop pending autorepeat */
    132  1.1  uwe 	if (k->k_repeating) {
    133  1.1  uwe 		k->k_repeating = 0;
    134  1.1  uwe 		callout_stop(&k->k_repeat_ch);
    135  1.1  uwe 	}
    136  1.1  uwe 
    137  1.1  uwe 	/* open internal device */
    138  1.1  uwe 	if (k->k_deviopen)
    139  1.1  uwe 		(*k->k_deviopen)((struct device *)k, FREAD|FWRITE);
    140  1.1  uwe 
    141  1.1  uwe 	s = spltty();
    142  1.1  uwe 
    143  1.1  uwe 	/* reset the keyboard and find out its type */
    144  1.1  uwe 	kbd_sun_output(k, KBD_CMD_RESET);
    145  1.1  uwe 	kbd_sun_start_tx(k);
    146  1.1  uwe 	kbd_sun_drain_tx(k);
    147  1.1  uwe 
    148  1.1  uwe 	/* the wakeup for this is in kbd_was_reset(). */
    149  1.1  uwe 	error = tsleep((caddr_t)&ks->kbd_id, PZERO | PCATCH, devopn, hz);
    150  1.1  uwe 	if (error == EWOULDBLOCK) { /* no response */
    151  1.1  uwe 		log(LOG_ERR, "%s: reset failed\n", kbd->k_dev.dv_xname);
    152  1.1  uwe 
    153  1.1  uwe 		/*
    154  1.1  uwe 		 * Allow the open anyway (to keep getty happy)
    155  1.1  uwe 		 * but assume the "least common denominator".
    156  1.1  uwe 		 */
    157  1.1  uwe 		error = 0;
    158  1.1  uwe 		ks->kbd_id = KB_SUN2;
    159  1.1  uwe 	}
    160  1.1  uwe 
    161  1.1  uwe 	/* initialize the table pointers for this type */
    162  1.1  uwe 	kbd_xlate_init(ks);
    163  1.1  uwe 
    164  1.1  uwe 	/* earlier than type 4 does not know "layout" */
    165  1.1  uwe 	if (ks->kbd_id < KB_SUN4)
    166  1.1  uwe 		goto done;
    167  1.1  uwe 
    168  1.1  uwe 	/* ask for the layout */
    169  1.1  uwe 	kbd_sun_output(k, KBD_CMD_GETLAYOUT);
    170  1.1  uwe 	kbd_sun_start_tx(k);
    171  1.1  uwe 	kbd_sun_drain_tx(k);
    172  1.1  uwe 
    173  1.1  uwe 	/* the wakeup for this is in kbd_new_layout() */
    174  1.1  uwe 	error = tsleep((caddr_t)&ks->kbd_layout, PZERO | PCATCH, devopn, hz);
    175  1.1  uwe 	if (error == EWOULDBLOCK) { 	/* no response */
    176  1.1  uwe 		log(LOG_ERR, "%s: no response to get_layout\n",
    177  1.1  uwe 		    kbd->k_dev.dv_xname);
    178  1.1  uwe 		error = 0;
    179  1.1  uwe 		ks->kbd_layout = 0; /* US layout */
    180  1.1  uwe 	}
    181  1.1  uwe   done:
    182  1.1  uwe 	splx(s);
    183  1.1  uwe 
    184  1.1  uwe 	if (error == 0)
    185  1.1  uwe 		k->k_isopen = 1;
    186  1.1  uwe 
    187  1.1  uwe 	return (error);
    188  1.1  uwe }
    189  1.1  uwe 
    190  1.1  uwe 
    191  1.1  uwe static int
    192  1.1  uwe kbd_sun_close(kbd)
    193  1.1  uwe 	struct kbd_softc *kbd;
    194  1.1  uwe {
    195  1.1  uwe 
    196  1.1  uwe 	return (0);		/* nothing to do so far */
    197  1.1  uwe }
    198  1.1  uwe 
    199  1.1  uwe 
    200  1.1  uwe /*
    201  1.1  uwe  * keyboard command ioctl
    202  1.1  uwe  * ``unimplemented commands are ignored'' (blech)
    203  1.1  uwe  * XXX: This is also exported to the fb driver (for bell).
    204  1.1  uwe  */
    205  1.1  uwe static int
    206  1.1  uwe kbd_sun_do_cmd(kbd, cmd, isioctl)
    207  1.1  uwe 	struct kbd_softc *kbd;
    208  1.1  uwe 	int cmd;
    209  1.1  uwe 	int isioctl;
    210  1.1  uwe {
    211  1.1  uwe 	struct kbd_sun_softc *k = (struct kbd_sun_softc *)kbd;
    212  1.1  uwe 	struct kbd_state *ks;
    213  1.1  uwe 	int error, s;
    214  1.1  uwe 
    215  1.1  uwe 	error = 0;
    216  1.1  uwe 	ks = &kbd->k_state;
    217  1.1  uwe 
    218  1.1  uwe 	switch (cmd) {
    219  1.1  uwe 
    220  1.1  uwe 	case KBD_CMD_BELL:
    221  1.1  uwe 	case KBD_CMD_NOBELL:
    222  1.1  uwe 		/* Supported by type 2, 3, and 4 keyboards */
    223  1.1  uwe 		break;
    224  1.1  uwe 
    225  1.1  uwe 	case KBD_CMD_CLICK:
    226  1.1  uwe 	case KBD_CMD_NOCLICK:
    227  1.1  uwe 		/* Unsupported by type 2 keyboards */
    228  1.1  uwe 		if (ks->kbd_id <= KB_SUN2)
    229  1.1  uwe 			return (0);
    230  1.1  uwe 		ks->kbd_click = (cmd == KBD_CMD_CLICK);
    231  1.1  uwe 		break;
    232  1.1  uwe 
    233  1.1  uwe 	default:
    234  1.1  uwe 		return (0);
    235  1.1  uwe 	}
    236  1.1  uwe 
    237  1.1  uwe 	s = spltty();
    238  1.1  uwe 
    239  1.1  uwe 	if (isioctl)
    240  1.1  uwe 		error = kbd_sun_drain_tx(k);
    241  1.1  uwe 
    242  1.1  uwe 	if (error == 0) {
    243  1.1  uwe 		kbd_sun_output(k, cmd);
    244  1.1  uwe 		kbd_sun_start_tx(k);
    245  1.1  uwe 	}
    246  1.1  uwe 
    247  1.1  uwe 	splx(s);
    248  1.1  uwe 
    249  1.1  uwe 	return (error);
    250  1.1  uwe }
    251  1.1  uwe 
    252  1.1  uwe 
    253  1.1  uwe /*
    254  1.1  uwe  * KIOCSLED.  Has user context.
    255  1.1  uwe  * Take care about spl and call kbd_sun_set_leds.
    256  1.1  uwe  */
    257  1.1  uwe static int
    258  1.1  uwe kbd_sun_set_leds(kbd, leds, isioctl)
    259  1.1  uwe 	struct kbd_softc *kbd;
    260  1.1  uwe 	int leds;
    261  1.1  uwe 	int isioctl;
    262  1.1  uwe {
    263  1.1  uwe 	struct kbd_sun_softc *k = (struct kbd_sun_softc *)kbd;
    264  1.1  uwe 
    265  1.1  uwe 	if (isioctl) {
    266  1.1  uwe 		int error, s;
    267  1.1  uwe 		s = spltty();
    268  1.1  uwe 		error = kbd_sun_drain_tx(k);
    269  1.1  uwe 		if (error == 0) {
    270  1.1  uwe 			kbd_sun_set_leds1(kbd, leds);
    271  1.1  uwe 		}
    272  1.1  uwe 		splx(s);
    273  1.1  uwe 		return (error);
    274  1.1  uwe 	}
    275  1.1  uwe 	else {
    276  1.1  uwe 		kbd_sun_set_leds1(kbd, leds);
    277  1.1  uwe 		return (0);
    278  1.1  uwe 	}
    279  1.1  uwe }
    280  1.1  uwe 
    281  1.1  uwe 
    282  1.1  uwe /*
    283  1.1  uwe  * Safe to call from intterupt handler.  Called at spltty()
    284  1.1  uwe  * by kbd_sun_iocsled and kbd_sun_input (via kbd_update_leds).
    285  1.1  uwe  */
    286  1.1  uwe static void
    287  1.1  uwe kbd_sun_set_leds1(kbd, new_leds)
    288  1.1  uwe 	struct kbd_softc *kbd;
    289  1.1  uwe 	int new_leds;
    290  1.1  uwe {
    291  1.1  uwe 	struct kbd_sun_softc *k = (struct kbd_sun_softc *)kbd;
    292  1.1  uwe 	struct kbd_state *ks = &kbd->k_state;
    293  1.1  uwe 
    294  1.1  uwe 	/* Don't send unless state changes. */
    295  1.1  uwe 	if (ks->kbd_leds == new_leds)
    296  1.1  uwe 		return;
    297  1.1  uwe 
    298  1.1  uwe 	ks->kbd_leds = new_leds;
    299  1.1  uwe 
    300  1.1  uwe 	/* Only type 4 and later has LEDs anyway. */
    301  1.1  uwe 	if (ks->kbd_id < KB_SUN4)
    302  1.1  uwe 		return;
    303  1.1  uwe 
    304  1.1  uwe 	kbd_sun_output(k, KBD_CMD_SETLED);
    305  1.1  uwe 	kbd_sun_output(k, new_leds);
    306  1.1  uwe 	kbd_sun_start_tx(k);
    307  1.1  uwe }
    308  1.1  uwe 
    309  1.1  uwe 
    310  1.1  uwe 
    311  1.1  uwe /***********************************************************************
    312  1.1  uwe  *	Methods for lower layer to call and related functions.
    313  1.1  uwe  */
    314  1.1  uwe 
    315  1.1  uwe /*
    316  1.1  uwe  * Enqueue some output for the keyboard
    317  1.1  uwe  * Called at spltty().
    318  1.1  uwe  */
    319  1.1  uwe void
    320  1.1  uwe kbd_sun_output(k, c)
    321  1.1  uwe 	struct kbd_sun_softc *k;
    322  1.1  uwe 	int c;	/* the data */
    323  1.1  uwe {
    324  1.1  uwe 	int put;
    325  1.1  uwe 
    326  1.1  uwe 	put = k->k_tbput;
    327  1.1  uwe 	k->k_tbuf[put] = (u_char)c;
    328  1.1  uwe 	put = (put + 1) & KBD_TX_RING_MASK;
    329  1.1  uwe 
    330  1.1  uwe 	/* Would overrun if increment makes (put == get) */
    331  1.1  uwe 	if (put == k->k_tbget) {
    332  1.1  uwe 		log(LOG_WARNING, "%s: output overrun\n",
    333  1.1  uwe 		    k->k_kbd.k_dev.dv_xname);
    334  1.1  uwe 	} else {
    335  1.1  uwe 		/* OK, really increment. */
    336  1.1  uwe 		k->k_tbput = put;
    337  1.1  uwe 	}
    338  1.1  uwe }
    339  1.1  uwe 
    340  1.1  uwe 
    341  1.1  uwe /*
    342  1.1  uwe  * In user context.  Called at spltty().
    343  1.1  uwe  * Wait for output to keyboard to finish.
    344  1.1  uwe  */
    345  1.1  uwe static int
    346  1.1  uwe kbd_sun_drain_tx(k)
    347  1.1  uwe 	struct kbd_sun_softc *k;
    348  1.1  uwe {
    349  1.1  uwe 	int error = 0;
    350  1.1  uwe 
    351  1.1  uwe 	while (k->k_txflags & K_TXBUSY && !error) {
    352  1.1  uwe 		k->k_txflags |= K_TXWANT;
    353  1.1  uwe 		error = tsleep((caddr_t)&k->k_txflags,
    354  1.1  uwe 			       PZERO | PCATCH, "kbdout", 0);
    355  1.1  uwe 	}
    356  1.1  uwe 
    357  1.1  uwe 	return (error);
    358  1.1  uwe }
    359  1.1  uwe 
    360  1.1  uwe /*
    361  1.1  uwe  * Start the sending data from the output queue
    362  1.1  uwe  * Called at spltty().
    363  1.1  uwe  */
    364  1.1  uwe void
    365  1.1  uwe kbd_sun_start_tx(k)
    366  1.1  uwe 	struct kbd_sun_softc *k;
    367  1.1  uwe {
    368  1.1  uwe 	int get;
    369  1.1  uwe 	u_char c;
    370  1.1  uwe 
    371  1.1  uwe 	if (k->k_txflags & K_TXBUSY)
    372  1.1  uwe 		return;
    373  1.1  uwe 
    374  1.1  uwe 	/* Is there anything to send? */
    375  1.1  uwe 	get = k->k_tbget;
    376  1.1  uwe 	if (get == k->k_tbput) {
    377  1.1  uwe 		/* Nothing to send.  Wake drain waiters. */
    378  1.1  uwe 		if (k->k_txflags & K_TXWANT) {
    379  1.1  uwe 			k->k_txflags &= ~K_TXWANT;
    380  1.1  uwe 			wakeup((caddr_t)&k->k_txflags);
    381  1.1  uwe 		}
    382  1.1  uwe 		return;
    383  1.1  uwe 	}
    384  1.1  uwe 
    385  1.1  uwe 	/* Have something to send. */
    386  1.1  uwe 	c = k->k_tbuf[get];
    387  1.1  uwe 	get = (get + 1) & KBD_TX_RING_MASK;
    388  1.1  uwe 	k->k_tbget = get;
    389  1.1  uwe 	k->k_txflags |= K_TXBUSY;
    390  1.1  uwe 
    391  1.1  uwe 	/* Pass data down to the underlying device. */
    392  1.1  uwe 	(*k->k_write_data)(k, c);
    393  1.1  uwe }
    394  1.1  uwe 
    395  1.1  uwe 
    396  1.1  uwe /*
    397  1.1  uwe  * Called by underlying driver's softint() routine on input,
    398  1.1  uwe  * which passes us the raw hardware scan codes.
    399  1.1  uwe  * Called at spltty()
    400  1.1  uwe  */
    401  1.1  uwe void
    402  1.1  uwe kbd_sun_input(k, c)
    403  1.1  uwe 	struct kbd_sun_softc *k;
    404  1.1  uwe 	int c;
    405  1.1  uwe {
    406  1.1  uwe 	struct kbd_softc *kbd = (struct kbd_softc *)k;
    407  1.1  uwe 	struct kbd_state *ks = &kbd->k_state;
    408  1.1  uwe 	int keysym;
    409  1.1  uwe 
    410  1.1  uwe 	/* XXX - Input errors already handled. */
    411  1.1  uwe 
    412  1.1  uwe 	/* Are we expecting special input? */
    413  1.1  uwe 	if (k->k_expect) {
    414  1.1  uwe 		if (k->k_expect & KBD_EXPECT_IDCODE) {
    415  1.1  uwe 			/* We read a KBD_RESET last time. */
    416  1.1  uwe 			ks->kbd_id = c;
    417  1.1  uwe 			kbd_sun_was_reset(k);
    418  1.1  uwe 		}
    419  1.1  uwe 		if (k->k_expect & KBD_EXPECT_LAYOUT) {
    420  1.1  uwe 			/* We read a KBD_LAYOUT last time. */
    421  1.1  uwe 			ks->kbd_layout = c;
    422  1.1  uwe 			kbd_sun_new_layout(k);
    423  1.1  uwe 		}
    424  1.1  uwe 		k->k_expect = 0;
    425  1.1  uwe 		return;
    426  1.1  uwe 	}
    427  1.1  uwe 
    428  1.1  uwe 	/* Is this one of the "special" input codes? */
    429  1.1  uwe 	if (KBD_SPECIAL(c)) {
    430  1.1  uwe 		switch (c) {
    431  1.1  uwe 		case KBD_RESET:
    432  1.1  uwe 			k->k_expect |= KBD_EXPECT_IDCODE;
    433  1.1  uwe 			/* Fake an "all-up" to resync. translation. */
    434  1.1  uwe 			c = KBD_IDLE;
    435  1.1  uwe 			break;
    436  1.1  uwe 
    437  1.1  uwe 		case KBD_LAYOUT:
    438  1.1  uwe 			k->k_expect |= KBD_EXPECT_LAYOUT;
    439  1.1  uwe 			return;
    440  1.1  uwe 
    441  1.1  uwe 		case KBD_ERROR:
    442  1.1  uwe 			log(LOG_WARNING, "%s: received error indicator\n",
    443  1.1  uwe 			    kbd->k_dev.dv_xname);
    444  1.1  uwe 			return;
    445  1.1  uwe 
    446  1.1  uwe 		case KBD_IDLE:
    447  1.1  uwe 			/* Let this go to the translator. */
    448  1.1  uwe 			break;
    449  1.1  uwe 		}
    450  1.1  uwe 	}
    451  1.1  uwe 
    452  1.1  uwe 	/*
    453  1.1  uwe 	 * If /dev/kbd is not connected in event mode,
    454  1.1  uwe 	 * translate and send upstream (to console).
    455  1.1  uwe 	 */
    456  1.1  uwe 	if (!kbd->k_evmode) {
    457  1.1  uwe 
    458  1.1  uwe 		/* Any input stops auto-repeat (i.e. key release). */
    459  1.1  uwe 		if (k->k_repeating) {
    460  1.1  uwe 			k->k_repeating = 0;
    461  1.1  uwe 			callout_stop(&k->k_repeat_ch);
    462  1.1  uwe 		}
    463  1.1  uwe 
    464  1.1  uwe 		/* Translate this code to a keysym */
    465  1.1  uwe 		keysym = kbd_code_to_keysym(ks, c);
    466  1.1  uwe 
    467  1.1  uwe 		/* Pass up to the next layer. */
    468  1.1  uwe 		if (kbd_input_keysym(kbd, keysym)) {
    469  1.1  uwe 			log(LOG_WARNING, "%s: code=0x%x with mod=0x%x"
    470  1.1  uwe 					 " produced unexpected keysym 0x%x\n",
    471  1.1  uwe 			    kbd->k_dev.dv_xname,
    472  1.1  uwe 			    c, ks->kbd_modbits, keysym);
    473  1.1  uwe 			/* No point in auto-repeat here. */
    474  1.1  uwe 			return;
    475  1.1  uwe 		}
    476  1.1  uwe 
    477  1.1  uwe 		/* Does this symbol get auto-repeat? */
    478  1.1  uwe 		if (KEYSYM_NOREPEAT(keysym))
    479  1.1  uwe 			return;
    480  1.1  uwe 
    481  1.1  uwe 		/* Setup for auto-repeat after initial delay. */
    482  1.1  uwe 		k->k_repeating = 1;
    483  1.1  uwe 		k->k_repeatsym = keysym;
    484  1.1  uwe 		callout_reset(&k->k_repeat_ch, k->k_repeat_start,
    485  1.1  uwe 			      kbd_sun_repeat, k);
    486  1.1  uwe 		return;
    487  1.1  uwe 	}
    488  1.1  uwe 
    489  1.1  uwe 	/*
    490  1.1  uwe 	 * IDLEs confuse the MIT X11R4 server badly, so we must drop them.
    491  1.1  uwe 	 * This is bad as it means the server will not automatically resync
    492  1.1  uwe 	 * on all-up IDLEs, but I did not drop them before, and the server
    493  1.1  uwe 	 * goes crazy when it comes time to blank the screen....
    494  1.1  uwe 	 */
    495  1.1  uwe 	if (c == KBD_IDLE)
    496  1.1  uwe 		return;
    497  1.1  uwe 
    498  1.1  uwe 	/*
    499  1.1  uwe 	 * Keyboard is generating events.  Turn this keystroke into an
    500  1.1  uwe 	 * event and put it in the queue.
    501  1.1  uwe 	 */
    502  1.1  uwe 	kbd_input_event(kbd, c);
    503  1.1  uwe }
    504  1.1  uwe 
    505  1.1  uwe 
    506  1.1  uwe /*
    507  1.1  uwe  * Called by kbd_sun_input to handle keyboard's response to reset.
    508  1.1  uwe  * Called at spltty().
    509  1.1  uwe  */
    510  1.1  uwe static void
    511  1.1  uwe kbd_sun_was_reset(k)
    512  1.1  uwe 	struct kbd_sun_softc *k;
    513  1.1  uwe {
    514  1.1  uwe 	struct kbd_state *ks = &k->k_kbd.k_state;
    515  1.1  uwe 
    516  1.1  uwe 	/*
    517  1.1  uwe 	 * On first identification, wake up anyone waiting for type
    518  1.1  uwe 	 * and set up the table pointers.
    519  1.1  uwe 	 */
    520  1.1  uwe 	wakeup((caddr_t)&ks->kbd_id);
    521  1.1  uwe 
    522  1.1  uwe 	/* Restore keyclick, if necessary */
    523  1.1  uwe 	switch (ks->kbd_id) {
    524  1.1  uwe 
    525  1.1  uwe 	case KB_SUN2:
    526  1.1  uwe 		/* Type 2 keyboards don't support keyclick */
    527  1.1  uwe 		break;
    528  1.1  uwe 
    529  1.1  uwe 	case KB_SUN3:
    530  1.1  uwe 		/* Type 3 keyboards come up with keyclick on */
    531  1.1  uwe 		if (!ks->kbd_click) {
    532  1.1  uwe 			/* turn off the click */
    533  1.1  uwe 			kbd_sun_output(k, KBD_CMD_NOCLICK);
    534  1.1  uwe 			kbd_sun_start_tx(k);
    535  1.1  uwe 		}
    536  1.1  uwe 		break;
    537  1.1  uwe 
    538  1.1  uwe 	case KB_SUN4:
    539  1.1  uwe 		/* Type 4 keyboards come up with keyclick off */
    540  1.1  uwe 		if (ks->kbd_click) {
    541  1.1  uwe 			/* turn on the click */
    542  1.1  uwe 			kbd_sun_output(k, KBD_CMD_CLICK);
    543  1.1  uwe 			kbd_sun_start_tx(k);
    544  1.1  uwe 		}
    545  1.1  uwe 		break;
    546  1.1  uwe 	}
    547  1.1  uwe 
    548  1.1  uwe 	/* LEDs are off after reset. */
    549  1.1  uwe 	ks->kbd_leds = 0;
    550  1.1  uwe }
    551  1.1  uwe 
    552  1.1  uwe /*
    553  1.1  uwe  * Called by kbd_sun_input to handle response to layout request.
    554  1.1  uwe  * Called at spltty().
    555  1.1  uwe  */
    556  1.1  uwe static void
    557  1.1  uwe kbd_sun_new_layout(k)
    558  1.1  uwe 	struct kbd_sun_softc *k;
    559  1.1  uwe {
    560  1.1  uwe 	struct kbd_state *ks = &k->k_kbd.k_state;
    561  1.1  uwe 
    562  1.1  uwe 	/*
    563  1.1  uwe 	 * On first identification, wake up anyone waiting for type
    564  1.1  uwe 	 * and set up the table pointers.
    565  1.1  uwe 	 */
    566  1.1  uwe 	wakeup((caddr_t)&ks->kbd_layout);
    567  1.1  uwe 
    568  1.1  uwe 	/* XXX: switch decoding tables? */
    569  1.1  uwe }
    570  1.1  uwe 
    571  1.1  uwe 
    572  1.1  uwe /*
    573  1.1  uwe  * This is the autorepeat callout function.
    574  1.1  uwe  * Autorepeat is scheduled by kbd_sun_input.
    575  1.1  uwe  * Called at splsoftclock().
    576  1.1  uwe  */
    577  1.1  uwe static void
    578  1.1  uwe kbd_sun_repeat(arg)
    579  1.1  uwe 	void *arg;
    580  1.1  uwe {
    581  1.1  uwe 	struct kbd_sun_softc *k = (struct kbd_sun_softc *)arg;
    582  1.1  uwe 	int s;
    583  1.1  uwe 
    584  1.1  uwe 	s = spltty();
    585  1.1  uwe 	if (k->k_repeating && k->k_repeatsym >= 0) {
    586  1.1  uwe 
    587  1.1  uwe 		/* feed typematic keysym to the upper layer */
    588  1.1  uwe 		(void)kbd_input_keysym(&k->k_kbd, k->k_repeatsym);
    589  1.1  uwe 
    590  1.1  uwe 		/* reschedule next repeat */
    591  1.1  uwe 		callout_reset(&k->k_repeat_ch, k->k_repeat_step,
    592  1.1  uwe 			      kbd_sun_repeat, k);
    593  1.1  uwe 	}
    594  1.1  uwe 	splx(s);
    595  1.1  uwe }
    596