1999-05-14 10:42:02 +04:00
|
|
|
/* $NetBSD: kbd.c,v 1.22 1999/05/14 06:42:02 mrg Exp $ */
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)kbd.c 8.2 (Berkeley) 10/30/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keyboard driver (/dev/kbd -- note that we do not have minor numbers
|
|
|
|
* [yet?]). Translates incoming bytes to ASCII or to `firm_events' and
|
|
|
|
* passes them up to the appropriate reader.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the "slave" driver that will be attached to
|
|
|
|
* the "zsc" driver for a Sun keyboard.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
1996-12-17 23:46:11 +03:00
|
|
|
#include <sys/device.h>
|
1996-01-24 04:15:34 +03:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/kernel.h>
|
1996-12-17 23:46:11 +03:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/time.h>
|
1996-01-24 04:15:34 +03:00
|
|
|
#include <sys/syslog.h>
|
1996-10-09 04:50:55 +04:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/poll.h>
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
#include <dev/ic/z8530reg.h>
|
|
|
|
#include <machine/z8530var.h>
|
|
|
|
#include <machine/vuid_event.h>
|
|
|
|
#include <machine/kbd.h>
|
|
|
|
#include <machine/kbio.h>
|
1999-05-14 10:42:02 +04:00
|
|
|
#include <dev/sun/event_var.h>
|
|
|
|
#include <dev/sun/kbd_xlate.h>
|
|
|
|
#include <dev/sun/kbdvar.h>
|
1996-01-24 04:15:34 +03:00
|
|
|
|
1997-07-17 05:17:45 +04:00
|
|
|
#include "locators.h"
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ideas:
|
|
|
|
* /dev/kbd is not a tty (plain device)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Prototypes */
|
1996-12-17 23:46:11 +03:00
|
|
|
static void kbd_new_layout(struct kbd_softc *k);
|
|
|
|
static void kbd_repeat(void *arg);
|
|
|
|
static void kbd_set_leds(struct kbd_softc *k, int leds);
|
|
|
|
static void kbd_update_leds(struct kbd_softc *k);
|
|
|
|
static void kbd_was_reset(struct kbd_softc *k);
|
|
|
|
static int kbd_drain_tx(struct kbd_softc *k);
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
cdev_decl(kbd); /* open, close, read, write, ioctl, stop, ... */
|
|
|
|
|
1998-01-12 12:36:53 +03:00
|
|
|
extern struct cfdriver kbd_cd;
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Entry points for /dev/kbd
|
|
|
|
* (open,close,read,write,...)
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open:
|
|
|
|
* Check exclusion, open actual device (_iopen),
|
|
|
|
* setup event channel, clear ASCII repeat stuff.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
kbdopen(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct kbd_softc *k;
|
1996-12-17 23:46:11 +03:00
|
|
|
int error, unit;
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
unit = minor(dev);
|
1996-03-17 03:57:14 +03:00
|
|
|
if (unit >= kbd_cd.cd_ndevs)
|
1996-01-24 04:15:34 +03:00
|
|
|
return (ENXIO);
|
1996-03-17 03:57:14 +03:00
|
|
|
k = kbd_cd.cd_devs[unit];
|
1996-01-24 04:15:34 +03:00
|
|
|
if (k == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/* Exclusive open required for /dev/kbd */
|
|
|
|
if (k->k_events.ev_io)
|
|
|
|
return (EBUSY);
|
|
|
|
k->k_events.ev_io = p;
|
|
|
|
|
|
|
|
if ((error = kbd_iopen(unit)) != 0) {
|
|
|
|
k->k_events.ev_io = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
ev_init(&k->k_events);
|
|
|
|
k->k_evmode = 1; /* XXX: OK? */
|
|
|
|
|
|
|
|
if (k->k_repeating) {
|
|
|
|
k->k_repeating = 0;
|
|
|
|
untimeout(kbd_repeat, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close:
|
|
|
|
* Turn off event mode, dump the queue, and close the keyboard
|
|
|
|
* unless it is supplying console input.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
kbdclose(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct kbd_softc *k;
|
|
|
|
|
1996-03-17 03:57:14 +03:00
|
|
|
k = kbd_cd.cd_devs[minor(dev)];
|
1996-01-24 04:15:34 +03:00
|
|
|
k->k_evmode = 0;
|
|
|
|
ev_fini(&k->k_events);
|
|
|
|
k->k_events.ev_io = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
kbdread(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct kbd_softc *k;
|
|
|
|
|
1996-03-17 03:57:14 +03:00
|
|
|
k = kbd_cd.cd_devs[minor(dev)];
|
1996-01-24 04:15:34 +03:00
|
|
|
return (ev_read(&k->k_events, uio, flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this routine should not exist, but is convenient to write here for now */
|
|
|
|
int
|
|
|
|
kbdwrite(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-10-09 04:50:55 +04:00
|
|
|
kbdpoll(dev, events, p)
|
1996-01-24 04:15:34 +03:00
|
|
|
dev_t dev;
|
1996-10-09 04:50:55 +04:00
|
|
|
int events;
|
1996-01-24 04:15:34 +03:00
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct kbd_softc *k;
|
|
|
|
|
1996-03-17 03:57:14 +03:00
|
|
|
k = kbd_cd.cd_devs[minor(dev)];
|
1996-10-09 04:50:55 +04:00
|
|
|
return (ev_poll(&k->k_events, events, p));
|
1996-01-24 04:15:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int kbd_iockeymap __P((struct kbd_state *ks,
|
|
|
|
u_long cmd, struct kiockeymap *kio));
|
|
|
|
|
1997-11-03 08:05:45 +03:00
|
|
|
static int kbd_iocsled(struct kbd_softc *k, char *data);
|
1996-04-11 01:44:35 +04:00
|
|
|
|
|
|
|
#ifdef KIOCGETKEY
|
|
|
|
static int kbd_oldkeymap __P((struct kbd_state *ks,
|
|
|
|
u_long cmd, struct okiockey *okio));
|
|
|
|
#endif
|
|
|
|
|
1996-01-24 04:15:34 +03:00
|
|
|
int
|
|
|
|
kbdioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
register caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct kbd_softc *k;
|
|
|
|
struct kbd_state *ks;
|
|
|
|
int error = 0;
|
|
|
|
|
1996-03-17 03:57:14 +03:00
|
|
|
k = kbd_cd.cd_devs[minor(dev)];
|
1996-01-24 04:15:34 +03:00
|
|
|
ks = &k->k_state;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case KIOCTRANS: /* Set translation mode */
|
|
|
|
/* We only support "raw" mode on /dev/kbd */
|
1997-10-21 19:17:31 +04:00
|
|
|
if (*(int *)data != TR_UNTRANS_EVENT)
|
1996-01-24 04:15:34 +03:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KIOCGTRANS: /* Get translation mode */
|
|
|
|
/* We only support "raw" mode on /dev/kbd */
|
1997-10-21 19:17:31 +04:00
|
|
|
*(int *)data = TR_UNTRANS_EVENT;
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef KIOCGETKEY
|
|
|
|
case KIOCGETKEY: /* Get keymap entry (old format) */
|
|
|
|
error = kbd_oldkeymap(ks, cmd, (struct okiockey *)data);
|
|
|
|
break;
|
|
|
|
#endif KIOCGETKEY */
|
|
|
|
|
|
|
|
case KIOCSKEY: /* Set keymap entry */
|
|
|
|
/* fallthrough */
|
|
|
|
case KIOCGKEY: /* Get keymap entry */
|
|
|
|
error = kbd_iockeymap(ks, cmd, (struct kiockeymap *)data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KIOCCMD: /* Send a command to the keyboard */
|
1997-10-21 19:17:31 +04:00
|
|
|
error = kbd_docmd(*(int *)data, 1);
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KIOCTYPE: /* Get keyboard type */
|
1997-10-21 19:17:31 +04:00
|
|
|
*(int *)data = ks->kbd_id;
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KIOCSDIRECT: /* where to send input */
|
1997-10-21 19:17:31 +04:00
|
|
|
k->k_evmode = *(int *)data;
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KIOCLAYOUT: /* Get keyboard layout */
|
1997-10-21 19:17:31 +04:00
|
|
|
*(int *)data = ks->kbd_layout;
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KIOCSLED:
|
1997-11-03 08:05:45 +03:00
|
|
|
error = kbd_iocsled(k, (char *)data);
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KIOCGLED:
|
|
|
|
*(char *)data = ks->kbd_leds;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIONBIO: /* we will remove this someday (soon???) */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIOASYNC:
|
|
|
|
k->k_events.ev_async = *(int *)data != 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCSPGRP:
|
1997-10-21 19:17:31 +04:00
|
|
|
if (*(int *)data != k->k_events.ev_io->p_pgid)
|
1996-01-24 04:15:34 +03:00
|
|
|
error = EPERM;
|
|
|
|
break;
|
|
|
|
|
1997-10-21 19:17:31 +04:00
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
1996-01-24 04:15:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* ioctl helpers
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get/Set keymap entry
|
|
|
|
*/
|
1996-04-11 01:44:35 +04:00
|
|
|
static int
|
1996-01-24 04:15:34 +03:00
|
|
|
kbd_iockeymap(ks, cmd, kio)
|
|
|
|
struct kbd_state *ks;
|
|
|
|
u_long cmd;
|
|
|
|
struct kiockeymap *kio;
|
|
|
|
{
|
1996-12-17 23:46:11 +03:00
|
|
|
u_short *km;
|
1996-01-24 04:15:34 +03:00
|
|
|
u_int station;
|
|
|
|
|
|
|
|
switch (kio->kio_tablemask) {
|
|
|
|
case KIOC_NOMASK:
|
|
|
|
km = ks->kbd_k.k_normal;
|
|
|
|
break;
|
|
|
|
case KIOC_SHIFTMASK:
|
|
|
|
km = ks->kbd_k.k_shifted;
|
|
|
|
break;
|
|
|
|
case KIOC_CTRLMASK:
|
|
|
|
km = ks->kbd_k.k_control;
|
|
|
|
break;
|
|
|
|
case KIOC_UPMASK:
|
|
|
|
km = ks->kbd_k.k_release;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Silently ignore unsupported masks */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Range-check the table position. */
|
|
|
|
station = kio->kio_station;
|
|
|
|
if (station >= KEYMAP_SIZE)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case KIOCGKEY: /* Get keymap entry */
|
1996-12-17 23:46:11 +03:00
|
|
|
kio->kio_entry = km[station];
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KIOCSKEY: /* Set keymap entry */
|
1996-12-17 23:46:11 +03:00
|
|
|
km[station] = kio->kio_entry;
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return(ENOTTY);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KIOCGETKEY
|
|
|
|
/*
|
|
|
|
* Get/Set keymap entry,
|
|
|
|
* old format (compatibility)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
kbd_oldkeymap(ks, cmd, kio)
|
|
|
|
struct kbd_state *ks;
|
|
|
|
u_long cmd;
|
|
|
|
struct okiockey *kio;
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case KIOCGETKEY:
|
|
|
|
if (kio->kio_station == 118) {
|
|
|
|
/*
|
|
|
|
* This is X11 asking if a type 3 keyboard is
|
|
|
|
* really a type 3 keyboard. Say yes, it is,
|
|
|
|
* by reporting key station 118 as a "hole".
|
|
|
|
* Note old (SunOS 3.5) definition of HOLE!
|
|
|
|
*/
|
|
|
|
kio->kio_entry = 0xA2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#endif /* KIOCGETKEY */
|
|
|
|
|
1996-04-11 01:44:35 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* keyboard command ioctl
|
|
|
|
* ``unimplemented commands are ignored'' (blech)
|
1997-10-04 03:04:46 +04:00
|
|
|
* This is also export to the fb driver.
|
1996-04-11 01:44:35 +04:00
|
|
|
*/
|
1997-10-04 03:04:46 +04:00
|
|
|
int
|
|
|
|
kbd_docmd(cmd, isuser)
|
|
|
|
int cmd;
|
|
|
|
int isuser;
|
1996-04-11 01:44:35 +04:00
|
|
|
{
|
1997-10-04 03:04:46 +04:00
|
|
|
struct kbd_softc *k;
|
|
|
|
struct kbd_state *ks;
|
|
|
|
int error, s;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
k = kbd_cd.cd_devs[0];
|
|
|
|
ks = &k->k_state;
|
1996-04-11 01:44:35 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case KBD_CMD_BELL:
|
|
|
|
case KBD_CMD_NOBELL:
|
|
|
|
/* Supported by type 2, 3, and 4 keyboards */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KBD_CMD_CLICK:
|
|
|
|
case KBD_CMD_NOCLICK:
|
|
|
|
/* Unsupported by type 2 keyboards */
|
|
|
|
if (ks->kbd_id <= KB_SUN2)
|
|
|
|
return (0);
|
|
|
|
ks->kbd_click = (cmd == KBD_CMD_CLICK);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
1997-10-04 03:04:46 +04:00
|
|
|
if (isuser)
|
|
|
|
error = kbd_drain_tx(k);
|
|
|
|
|
1996-04-11 01:44:35 +04:00
|
|
|
if (error == 0) {
|
|
|
|
kbd_output(k, cmd);
|
|
|
|
kbd_start_tx(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set LEDs ioctl.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
kbd_iocsled(k, data)
|
|
|
|
struct kbd_softc *k;
|
1997-11-03 08:05:45 +03:00
|
|
|
char *data;
|
1996-04-11 01:44:35 +04:00
|
|
|
{
|
|
|
|
int leds, error, s;
|
|
|
|
|
|
|
|
leds = *data;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
error = kbd_drain_tx(k);
|
|
|
|
if (error == 0) {
|
|
|
|
kbd_set_leds(k, leds);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-01-24 04:15:34 +03:00
|
|
|
/****************************************************************
|
|
|
|
* middle layers:
|
|
|
|
* - keysym to ASCII sequence
|
|
|
|
* - raw key codes to keysym
|
|
|
|
****************************************************************/
|
|
|
|
|
1996-12-17 23:46:11 +03:00
|
|
|
static void kbd_input_string __P((struct kbd_softc *, char *));
|
|
|
|
static void kbd_input_funckey __P((struct kbd_softc *, int));
|
1997-10-28 09:14:17 +03:00
|
|
|
static int kbd_input_keysym __P((struct kbd_softc *, int));
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization done by either kdcninit or kbd_iopen
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
kbd_xlate_init(ks)
|
|
|
|
struct kbd_state *ks;
|
|
|
|
{
|
|
|
|
struct keyboard *ktbls;
|
|
|
|
int id;
|
|
|
|
|
|
|
|
id = ks->kbd_id;
|
|
|
|
if (id < KBD_MIN_TYPE)
|
|
|
|
id = KBD_MIN_TYPE;
|
|
|
|
if (id > kbd_max_type)
|
|
|
|
id = kbd_max_type;
|
|
|
|
ktbls = keyboards[id];
|
|
|
|
|
|
|
|
ks->kbd_k = *ktbls; /* struct assignment */
|
|
|
|
ks->kbd_modbits = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn keyboard up/down codes into a KEYSYM.
|
|
|
|
* Note that the "kd" driver uses this too!
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
kbd_code_to_keysym(ks, c)
|
|
|
|
register struct kbd_state *ks;
|
|
|
|
register int c;
|
|
|
|
{
|
1996-12-17 23:46:11 +03:00
|
|
|
u_short *km;
|
1996-01-24 04:15:34 +03:00
|
|
|
int keysym;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get keymap pointer. One of these:
|
|
|
|
* release, control, shifted, normal, ...
|
|
|
|
*/
|
|
|
|
if (KEY_UP(c))
|
|
|
|
km = ks->kbd_k.k_release;
|
1996-02-29 22:32:14 +03:00
|
|
|
else if (ks->kbd_modbits & KBMOD_CTRL_MASK)
|
|
|
|
km = ks->kbd_k.k_control;
|
|
|
|
else if (ks->kbd_modbits & KBMOD_SHIFT_MASK)
|
|
|
|
km = ks->kbd_k.k_shifted;
|
|
|
|
else
|
|
|
|
km = ks->kbd_k.k_normal;
|
|
|
|
|
1996-01-24 04:15:34 +03:00
|
|
|
if (km == NULL) {
|
|
|
|
/*
|
|
|
|
* Do not know how to translate yet.
|
|
|
|
* We will find out when a RESET comes along.
|
|
|
|
*/
|
1996-02-29 22:32:14 +03:00
|
|
|
return (KEYSYM_NOP);
|
|
|
|
}
|
1996-12-17 23:46:11 +03:00
|
|
|
keysym = km[KEY_CODE(c)];
|
1996-02-29 22:32:14 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Post-processing for Caps-lock
|
|
|
|
*/
|
|
|
|
if ((ks->kbd_modbits & (1 << KBMOD_CAPSLOCK)) &&
|
|
|
|
(KEYSYM_CLASS(keysym) == KEYSYM_ASCII) )
|
|
|
|
{
|
|
|
|
if (('a' <= keysym) && (keysym <= 'z'))
|
|
|
|
keysym -= ('a' - 'A');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-10-28 09:14:17 +03:00
|
|
|
* Post-processing for Num-lock. All "function"
|
|
|
|
* keysyms get indirected through another table.
|
|
|
|
* (XXX: Only if numlock on. Want off also!)
|
1996-02-29 22:32:14 +03:00
|
|
|
*/
|
|
|
|
if ((ks->kbd_modbits & (1 << KBMOD_NUMLOCK)) &&
|
|
|
|
(KEYSYM_CLASS(keysym) == KEYSYM_FUNC) )
|
|
|
|
{
|
|
|
|
keysym = kbd_numlock_map[keysym & 0x3F];
|
|
|
|
}
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
return (keysym);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kbd_input_string(k, str)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
char *str;
|
|
|
|
{
|
1999-05-14 10:42:02 +04:00
|
|
|
|
1996-01-24 04:15:34 +03:00
|
|
|
while (*str) {
|
|
|
|
kd_input(*str);
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kbd_input_funckey(k, keysym)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
register int keysym;
|
|
|
|
{
|
|
|
|
register int n;
|
|
|
|
char str[12];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format the F-key sequence and send as a string.
|
|
|
|
* XXX: Ugly compatibility mappings.
|
|
|
|
*/
|
|
|
|
n = 0xC0 + (keysym & 0x3F);
|
1996-10-13 05:37:04 +04:00
|
|
|
sprintf(str, "\033[%dz", n);
|
1996-01-24 04:15:34 +03:00
|
|
|
kbd_input_string(k, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called by kbd_input_raw() or by kb_repeat()
|
1996-04-11 01:44:35 +04:00
|
|
|
* to deliver ASCII input. Called at spltty().
|
1997-10-28 09:14:17 +03:00
|
|
|
*
|
|
|
|
* Return zero on success, else the keysym that we
|
|
|
|
* could not handle (so the caller may complain).
|
1996-01-24 04:15:34 +03:00
|
|
|
*/
|
1997-10-28 09:14:17 +03:00
|
|
|
int
|
1996-01-24 04:15:34 +03:00
|
|
|
kbd_input_keysym(k, keysym)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
register int keysym;
|
|
|
|
{
|
|
|
|
struct kbd_state *ks = &k->k_state;
|
1996-02-29 22:32:14 +03:00
|
|
|
register int data;
|
1996-01-24 04:15:34 +03:00
|
|
|
|
1996-02-29 22:32:14 +03:00
|
|
|
switch (KEYSYM_CLASS(keysym)) {
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
case KEYSYM_ASCII:
|
|
|
|
data = KEYSYM_DATA(keysym);
|
|
|
|
if (ks->kbd_modbits & KBMOD_META_MASK)
|
|
|
|
data |= 0x80;
|
|
|
|
kd_input(data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSYM_STRING:
|
|
|
|
data = keysym & 0xF;
|
|
|
|
kbd_input_string(k, kbd_stringtab[data]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSYM_FUNC:
|
|
|
|
kbd_input_funckey(k, keysym);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSYM_CLRMOD:
|
|
|
|
data = 1 << (keysym & 0x1F);
|
|
|
|
ks->kbd_modbits &= ~data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSYM_SETMOD:
|
|
|
|
data = 1 << (keysym & 0x1F);
|
|
|
|
ks->kbd_modbits |= data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSYM_INVMOD:
|
|
|
|
data = 1 << (keysym & 0x1F);
|
|
|
|
ks->kbd_modbits ^= data;
|
1996-02-29 22:32:14 +03:00
|
|
|
kbd_update_leds(k);
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSYM_ALL_UP:
|
|
|
|
ks->kbd_modbits &= ~0xFFFF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEYSYM_SPECIAL:
|
|
|
|
if (keysym == KEYSYM_NOP)
|
|
|
|
break;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
1997-10-28 09:14:17 +03:00
|
|
|
/* We could not handle it. */
|
|
|
|
return (keysym);
|
1996-01-24 04:15:34 +03:00
|
|
|
}
|
1997-10-28 09:14:17 +03:00
|
|
|
return (0);
|
1996-01-24 04:15:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the autorepeat timeout function.
|
1996-04-11 01:44:35 +04:00
|
|
|
* Called at splsoftclock().
|
1996-01-24 04:15:34 +03:00
|
|
|
*/
|
1996-12-17 23:46:11 +03:00
|
|
|
static void
|
1999-05-14 10:42:02 +04:00
|
|
|
kbd_repeat(arg)
|
|
|
|
void *arg;
|
1996-01-24 04:15:34 +03:00
|
|
|
{
|
|
|
|
struct kbd_softc *k = (struct kbd_softc *)arg;
|
1996-04-11 01:44:35 +04:00
|
|
|
int s = spltty();
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
if (k->k_repeating && k->k_repeatsym >= 0) {
|
1997-10-28 09:14:17 +03:00
|
|
|
(void)kbd_input_keysym(k, k->k_repeatsym);
|
1996-01-24 04:15:34 +03:00
|
|
|
timeout(kbd_repeat, k, k->k_repeat_step);
|
|
|
|
}
|
1996-04-11 01:44:35 +04:00
|
|
|
splx(s);
|
1996-01-24 04:15:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by our kbd_softint() routine on input,
|
|
|
|
* which passes the raw hardware scan codes.
|
1996-04-11 01:44:35 +04:00
|
|
|
* Called at spltty()
|
1996-01-24 04:15:34 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
kbd_input_raw(k, c)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
register int c;
|
|
|
|
{
|
|
|
|
struct kbd_state *ks = &k->k_state;
|
|
|
|
struct firm_event *fe;
|
|
|
|
int put, keysym;
|
|
|
|
|
|
|
|
/* XXX - Input errors already handled. */
|
|
|
|
|
|
|
|
/* Are we expecting special input? */
|
|
|
|
if (ks->kbd_expect) {
|
|
|
|
if (ks->kbd_expect & KBD_EXPECT_IDCODE) {
|
|
|
|
/* We read a KBD_RESET last time. */
|
|
|
|
ks->kbd_id = c;
|
|
|
|
kbd_was_reset(k);
|
|
|
|
}
|
|
|
|
if (ks->kbd_expect & KBD_EXPECT_LAYOUT) {
|
|
|
|
/* We read a KBD_LAYOUT last time. */
|
|
|
|
ks->kbd_layout = c;
|
|
|
|
kbd_new_layout(k);
|
|
|
|
}
|
|
|
|
ks->kbd_expect = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is this one of the "special" input codes? */
|
|
|
|
if (KBD_SPECIAL(c)) {
|
|
|
|
switch (c) {
|
|
|
|
case KBD_RESET:
|
|
|
|
ks->kbd_expect |= KBD_EXPECT_IDCODE;
|
|
|
|
/* Fake an "all-up" to resync. translation. */
|
|
|
|
c = KBD_IDLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KBD_LAYOUT:
|
|
|
|
ks->kbd_expect |= KBD_EXPECT_LAYOUT;
|
|
|
|
return;
|
|
|
|
|
|
|
|
case KBD_ERROR:
|
|
|
|
log(LOG_WARNING, "%s: received error indicator\n",
|
|
|
|
k->k_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case KBD_IDLE:
|
|
|
|
/* Let this go to the translator. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If /dev/kbd is not connected in event mode,
|
|
|
|
* translate and send upstream (to console).
|
|
|
|
*/
|
|
|
|
if (!k->k_evmode) {
|
|
|
|
|
|
|
|
/* Any input stops auto-repeat (i.e. key release). */
|
|
|
|
if (k->k_repeating) {
|
|
|
|
k->k_repeating = 0;
|
|
|
|
untimeout(kbd_repeat, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate this code to a keysym */
|
|
|
|
keysym = kbd_code_to_keysym(ks, c);
|
|
|
|
|
|
|
|
/* Pass up to the next layer. */
|
1997-10-28 09:14:17 +03:00
|
|
|
if (kbd_input_keysym(k, keysym)) {
|
|
|
|
log(LOG_WARNING, "%s: code=0x%x with mod=0x%x"
|
|
|
|
" produced unexpected keysym 0x%x\n",
|
|
|
|
k->k_dev.dv_xname, c,
|
|
|
|
ks->kbd_modbits, keysym);
|
|
|
|
/* No point in auto-repeat here. */
|
|
|
|
return;
|
|
|
|
}
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
/* Does this symbol get auto-repeat? */
|
|
|
|
if (KEYSYM_NOREPEAT(keysym))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Setup for auto-repeat after initial delay. */
|
|
|
|
k->k_repeating = 1;
|
|
|
|
k->k_repeatsym = keysym;
|
|
|
|
timeout(kbd_repeat, k, k->k_repeat_start);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IDLEs confuse the MIT X11R4 server badly, so we must drop them.
|
|
|
|
* This is bad as it means the server will not automatically resync
|
|
|
|
* on all-up IDLEs, but I did not drop them before, and the server
|
|
|
|
* goes crazy when it comes time to blank the screen....
|
|
|
|
*/
|
|
|
|
if (c == KBD_IDLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keyboard is generating events. Turn this keystroke into an
|
|
|
|
* event and put it in the queue. If the queue is full, the
|
|
|
|
* keystroke is lost (sorry!).
|
|
|
|
*/
|
|
|
|
put = k->k_events.ev_put;
|
|
|
|
fe = &k->k_events.ev_q[put];
|
|
|
|
put = (put + 1) % EV_QSIZE;
|
|
|
|
if (put == k->k_events.ev_get) {
|
|
|
|
log(LOG_WARNING, "%s: event queue overflow\n",
|
|
|
|
k->k_dev.dv_xname); /* ??? */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fe->id = KEY_CODE(c);
|
|
|
|
fe->value = KEY_UP(c) ? VKEY_UP : VKEY_DOWN;
|
|
|
|
fe->time = time;
|
|
|
|
k->k_events.ev_put = put;
|
|
|
|
EV_WAKEUP(&k->k_events);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* misc...
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization to be done at first open.
|
|
|
|
* This is called from kbdopen or kdopen (in kd.c)
|
1996-04-11 01:44:35 +04:00
|
|
|
* Called with user context.
|
1996-01-24 04:15:34 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
kbd_iopen(unit)
|
|
|
|
int unit;
|
|
|
|
{
|
|
|
|
struct kbd_softc *k;
|
|
|
|
struct kbd_state *ks;
|
|
|
|
int error, s;
|
|
|
|
|
1996-03-17 03:57:14 +03:00
|
|
|
if (unit >= kbd_cd.cd_ndevs)
|
1996-01-24 04:15:34 +03:00
|
|
|
return (ENXIO);
|
1996-03-17 03:57:14 +03:00
|
|
|
k = kbd_cd.cd_devs[unit];
|
1996-01-24 04:15:34 +03:00
|
|
|
if (k == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
ks = &k->k_state;
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
/* Tolerate extra calls. */
|
|
|
|
if (k->k_isopen)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
/* Reset the keyboard and find out its type. */
|
|
|
|
kbd_output(k, KBD_CMD_RESET);
|
|
|
|
kbd_start_tx(k);
|
|
|
|
kbd_drain_tx(k);
|
|
|
|
/* The wakeup for this is in kbd_was_reset(). */
|
|
|
|
error = tsleep((caddr_t)&ks->kbd_id,
|
|
|
|
PZERO | PCATCH, devopn, hz);
|
|
|
|
if (error == EWOULDBLOCK) { /* no response */
|
|
|
|
error = 0;
|
|
|
|
log(LOG_ERR, "%s: reset failed\n",
|
|
|
|
k->k_dev.dv_xname);
|
|
|
|
/*
|
|
|
|
* Allow the open anyway (to keep getty happy)
|
|
|
|
* but assume the "least common denominator".
|
|
|
|
*/
|
|
|
|
ks->kbd_id = KB_SUN2;
|
|
|
|
}
|
|
|
|
|
1997-10-28 09:14:17 +03:00
|
|
|
/* Initialize the table pointers for this type. */
|
|
|
|
kbd_xlate_init(ks);
|
|
|
|
|
1996-01-24 04:15:34 +03:00
|
|
|
/* Earlier than type 4 does not know "layout". */
|
|
|
|
if (ks->kbd_id < KB_SUN4)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Ask for the layout. */
|
|
|
|
kbd_output(k, KBD_CMD_GETLAYOUT);
|
|
|
|
kbd_start_tx(k);
|
|
|
|
kbd_drain_tx(k);
|
|
|
|
/* The wakeup for this is in kbd_new_layout(). */
|
|
|
|
error = tsleep((caddr_t)&ks->kbd_layout,
|
|
|
|
PZERO | PCATCH, devopn, hz);
|
|
|
|
if (error == EWOULDBLOCK) { /* no response */
|
|
|
|
error = 0;
|
|
|
|
log(LOG_ERR, "%s: no response to get_layout\n",
|
|
|
|
k->k_dev.dv_xname);
|
|
|
|
ks->kbd_layout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (error == 0)
|
|
|
|
k->k_isopen = 1;
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1996-04-11 01:44:35 +04:00
|
|
|
/*
|
|
|
|
* Called by kbd_input_raw, at spltty()
|
|
|
|
*/
|
1996-12-17 23:46:11 +03:00
|
|
|
static void
|
1996-01-24 04:15:34 +03:00
|
|
|
kbd_was_reset(k)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
{
|
|
|
|
struct kbd_state *ks = &k->k_state;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On first identification, wake up anyone waiting for type
|
|
|
|
* and set up the table pointers.
|
|
|
|
*/
|
|
|
|
wakeup((caddr_t)&ks->kbd_id);
|
|
|
|
|
|
|
|
/* Restore keyclick, if necessary */
|
|
|
|
switch (ks->kbd_id) {
|
|
|
|
|
|
|
|
case KB_SUN2:
|
|
|
|
/* Type 2 keyboards don't support keyclick */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KB_SUN3:
|
|
|
|
/* Type 3 keyboards come up with keyclick on */
|
1996-04-11 01:44:35 +04:00
|
|
|
if (!ks->kbd_click) {
|
|
|
|
/* turn off the click */
|
|
|
|
kbd_output(k, KBD_CMD_NOCLICK);
|
|
|
|
kbd_start_tx(k);
|
|
|
|
}
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KB_SUN4:
|
|
|
|
/* Type 4 keyboards come up with keyclick off */
|
1996-04-11 01:44:35 +04:00
|
|
|
if (ks->kbd_click) {
|
|
|
|
/* turn on the click */
|
|
|
|
kbd_output(k, KBD_CMD_CLICK);
|
|
|
|
kbd_start_tx(k);
|
|
|
|
}
|
1996-01-24 04:15:34 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LEDs are off after reset. */
|
|
|
|
ks->kbd_leds = 0;
|
|
|
|
}
|
|
|
|
|
1996-04-11 01:44:35 +04:00
|
|
|
/*
|
|
|
|
* Called by kbd_input_raw, at spltty()
|
|
|
|
*/
|
1996-12-17 23:46:11 +03:00
|
|
|
static void
|
1996-01-24 04:15:34 +03:00
|
|
|
kbd_new_layout(k)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
{
|
|
|
|
struct kbd_state *ks = &k->k_state;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On first identification, wake up anyone waiting for type
|
|
|
|
* and set up the table pointers.
|
|
|
|
*/
|
|
|
|
wakeup((caddr_t)&ks->kbd_layout);
|
|
|
|
|
|
|
|
/* XXX: switch decoding tables? */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for output to finish.
|
1996-04-11 01:44:35 +04:00
|
|
|
* Called at spltty(). Has user context.
|
1996-01-24 04:15:34 +03:00
|
|
|
*/
|
1996-12-17 23:46:11 +03:00
|
|
|
static int
|
1996-01-24 04:15:34 +03:00
|
|
|
kbd_drain_tx(k)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
{
|
1996-04-11 01:44:35 +04:00
|
|
|
int error;
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
error = 0;
|
1996-04-11 01:44:35 +04:00
|
|
|
|
1996-01-24 04:15:34 +03:00
|
|
|
while (k->k_txflags & K_TXBUSY) {
|
|
|
|
k->k_txflags |= K_TXWANT;
|
|
|
|
error = tsleep((caddr_t)&k->k_txflags,
|
|
|
|
PZERO | PCATCH, "kbdout", 0);
|
|
|
|
}
|
1996-04-11 01:44:35 +04:00
|
|
|
|
1996-01-24 04:15:34 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-04-11 01:44:35 +04:00
|
|
|
* Enqueue some output for the keyboard
|
|
|
|
* Called at spltty().
|
1996-01-24 04:15:34 +03:00
|
|
|
*/
|
1999-05-14 10:42:02 +04:00
|
|
|
void
|
1996-01-24 04:15:34 +03:00
|
|
|
kbd_output(k, c)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
int c; /* the data */
|
|
|
|
{
|
1996-04-11 01:44:35 +04:00
|
|
|
int put;
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
put = k->k_tbput;
|
|
|
|
k->k_tbuf[put] = (u_char)c;
|
|
|
|
put = (put + 1) & KBD_TX_RING_MASK;
|
|
|
|
|
|
|
|
/* Would overrun if increment makes (put==get). */
|
|
|
|
if (put == k->k_tbget) {
|
|
|
|
log(LOG_WARNING, "%s: output overrun\n",
|
|
|
|
k->k_dev.dv_xname);
|
|
|
|
} else {
|
|
|
|
/* OK, really increment. */
|
|
|
|
k->k_tbput = put;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-04-11 01:44:35 +04:00
|
|
|
/*
|
|
|
|
* Start the sending data from the output queue
|
|
|
|
* Called at spltty().
|
|
|
|
*/
|
1999-05-14 10:42:02 +04:00
|
|
|
void
|
1996-01-24 04:15:34 +03:00
|
|
|
kbd_start_tx(k)
|
1999-05-14 10:42:02 +04:00
|
|
|
struct kbd_softc *k;
|
1996-01-24 04:15:34 +03:00
|
|
|
{
|
1999-05-14 10:42:02 +04:00
|
|
|
int get;
|
1996-01-24 04:15:34 +03:00
|
|
|
u_char c;
|
|
|
|
|
|
|
|
if (k->k_txflags & K_TXBUSY)
|
1996-04-11 01:44:35 +04:00
|
|
|
return;
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
/* Is there anything to send? */
|
|
|
|
get = k->k_tbget;
|
|
|
|
if (get == k->k_tbput) {
|
|
|
|
/* Nothing to send. Wake drain waiters. */
|
|
|
|
if (k->k_txflags & K_TXWANT) {
|
|
|
|
k->k_txflags &= ~K_TXWANT;
|
|
|
|
wakeup((caddr_t)&k->k_txflags);
|
|
|
|
}
|
1996-04-11 01:44:35 +04:00
|
|
|
return;
|
1996-01-24 04:15:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Have something to send. */
|
|
|
|
c = k->k_tbuf[get];
|
|
|
|
get = (get + 1) & KBD_TX_RING_MASK;
|
|
|
|
k->k_tbget = get;
|
|
|
|
k->k_txflags |= K_TXBUSY;
|
|
|
|
|
1999-05-14 10:42:02 +04:00
|
|
|
k->k_write_data(k, c);
|
1996-01-24 04:15:34 +03:00
|
|
|
}
|
|
|
|
|
1996-04-11 01:44:35 +04:00
|
|
|
/*
|
|
|
|
* Called at spltty by:
|
|
|
|
* kbd_update_leds, kbd_iocsled
|
|
|
|
*/
|
1996-12-17 23:46:11 +03:00
|
|
|
static void
|
1996-02-29 22:32:14 +03:00
|
|
|
kbd_set_leds(k, new_leds)
|
1996-01-24 04:15:34 +03:00
|
|
|
struct kbd_softc *k;
|
1996-02-29 22:32:14 +03:00
|
|
|
int new_leds;
|
1996-01-24 04:15:34 +03:00
|
|
|
{
|
|
|
|
struct kbd_state *ks = &k->k_state;
|
|
|
|
|
|
|
|
/* Don't send unless state changes. */
|
|
|
|
if (ks->kbd_leds == new_leds)
|
1996-04-11 01:44:35 +04:00
|
|
|
return;
|
|
|
|
|
1996-01-24 04:15:34 +03:00
|
|
|
ks->kbd_leds = new_leds;
|
|
|
|
|
|
|
|
/* Only type 4 and later has LEDs anyway. */
|
1997-11-03 23:18:00 +03:00
|
|
|
if (ks->kbd_id < KB_SUN4)
|
1996-04-11 01:44:35 +04:00
|
|
|
return;
|
1996-01-24 04:15:34 +03:00
|
|
|
|
|
|
|
kbd_output(k, KBD_CMD_SETLED);
|
|
|
|
kbd_output(k, new_leds);
|
|
|
|
kbd_start_tx(k);
|
1996-02-29 22:32:14 +03:00
|
|
|
}
|
|
|
|
|
1996-04-11 01:44:35 +04:00
|
|
|
/*
|
|
|
|
* Called at spltty by:
|
|
|
|
* kbd_input_keysym
|
|
|
|
*/
|
1996-12-17 23:46:11 +03:00
|
|
|
static void
|
1996-02-29 22:32:14 +03:00
|
|
|
kbd_update_leds(k)
|
|
|
|
struct kbd_softc *k;
|
|
|
|
{
|
1997-10-28 09:14:17 +03:00
|
|
|
struct kbd_state *ks = &k->k_state;
|
|
|
|
register char leds;
|
1996-02-29 22:32:14 +03:00
|
|
|
|
|
|
|
leds = ks->kbd_leds;
|
|
|
|
leds &= ~(LED_CAPS_LOCK|LED_NUM_LOCK);
|
|
|
|
|
|
|
|
if (ks->kbd_modbits & (1 << KBMOD_CAPSLOCK))
|
|
|
|
leds |= LED_CAPS_LOCK;
|
|
|
|
if (ks->kbd_modbits & (1 << KBMOD_NUMLOCK))
|
|
|
|
leds |= LED_NUM_LOCK;
|
|
|
|
|
|
|
|
kbd_set_leds(k, leds);
|
1996-01-24 04:15:34 +03:00
|
|
|
}
|
|
|
|
|