1999-03-26 15:39:13 +03:00
|
|
|
/* $NetBSD: pckbd.c,v 1.17 1999/03/26 12:39:13 drochner Exp $ */
|
1998-08-15 08:42:42 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum.
|
|
|
|
*
|
|
|
|
* 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 NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* William Jolitz and Don Ahn.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @(#)pccons.c 5.11 (Berkeley) 5/21/91
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* code to work keyboard for PC-style console
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/pckbcvar.h>
|
|
|
|
|
|
|
|
#include <dev/pckbc/pckbdreg.h>
|
|
|
|
#include <dev/pckbc/pckbdvar.h>
|
1998-09-17 22:21:04 +04:00
|
|
|
#include <dev/pckbc/wskbdmap_mfii.h>
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wskbdvar.h>
|
1998-04-07 17:43:16 +04:00
|
|
|
#include <dev/wscons/wsksymdef.h>
|
|
|
|
#include <dev/wscons/wsksymvar.h>
|
1998-03-22 18:41:27 +03:00
|
|
|
|
1998-08-07 14:28:36 +04:00
|
|
|
#if defined(__i386__) || defined(__alpha__)
|
1998-04-17 01:18:46 +04:00
|
|
|
#include <sys/kernel.h> /* XXX for hz */
|
|
|
|
#endif
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
#include "locators.h"
|
|
|
|
|
1998-06-16 15:26:04 +04:00
|
|
|
#include "opt_pckbd_layout.h"
|
1998-06-12 02:15:14 +04:00
|
|
|
#include "opt_wsdisplay_compat.h"
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
struct pckbd_internal {
|
|
|
|
int t_isconsole;
|
|
|
|
pckbc_tag_t t_kbctag;
|
1998-05-03 13:57:50 +04:00
|
|
|
pckbc_slot_t t_kbcslot;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
int t_lastchar;
|
|
|
|
int t_extended;
|
|
|
|
int t_extended1;
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
struct pckbd_softc *t_sc; /* back pointer */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pckbd_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
|
|
|
|
struct pckbd_internal *id;
|
1998-08-02 18:21:02 +04:00
|
|
|
int sc_enabled;
|
|
|
|
|
|
|
|
int sc_ledstate;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
struct device *sc_wskbddev;
|
1998-06-12 02:15:14 +04:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
int rawkbd;
|
|
|
|
#endif
|
1998-03-22 18:41:27 +03:00
|
|
|
};
|
|
|
|
|
1998-05-03 13:57:50 +04:00
|
|
|
static int pckbd_is_console __P((pckbc_tag_t, pckbc_slot_t));
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
int pckbdprobe __P((struct device *, struct cfdata *, void *));
|
|
|
|
void pckbdattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfattach pckbd_ca = {
|
|
|
|
sizeof(struct pckbd_softc), pckbdprobe, pckbdattach,
|
|
|
|
};
|
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
int pckbd_enable __P((void *, int));
|
1998-04-07 17:43:16 +04:00
|
|
|
void pckbd_set_leds __P((void *, int));
|
1998-03-22 18:41:27 +03:00
|
|
|
int pckbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
|
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
const struct wskbd_accessops pckbd_accessops = {
|
|
|
|
pckbd_enable,
|
|
|
|
pckbd_set_leds,
|
|
|
|
pckbd_ioctl,
|
|
|
|
};
|
|
|
|
|
1998-04-07 17:43:16 +04:00
|
|
|
void pckbd_cngetc __P((void *, u_int *, int *));
|
1998-03-22 18:41:27 +03:00
|
|
|
void pckbd_cnpollc __P((void *, int));
|
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
const struct wskbd_consops pckbd_consops = {
|
|
|
|
pckbd_cngetc,
|
|
|
|
pckbd_cnpollc,
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct wskbd_mapdata pckbd_keymapdata = {
|
|
|
|
pckbd_keydesctab,
|
|
|
|
#ifdef PCKBD_LAYOUT
|
|
|
|
PCKBD_LAYOUT,
|
|
|
|
#else
|
|
|
|
KB_US,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
int pckbd_set_xtscancode __P((pckbc_tag_t, pckbc_slot_t));
|
1998-04-18 13:49:58 +04:00
|
|
|
int pckbd_init __P((struct pckbd_internal *, pckbc_tag_t, pckbc_slot_t,
|
1998-03-22 18:41:27 +03:00
|
|
|
int));
|
|
|
|
void pckbd_input __P((void *, int));
|
1998-04-07 17:43:16 +04:00
|
|
|
|
1998-04-17 01:18:46 +04:00
|
|
|
static int pckbd_decode __P((struct pckbd_internal *, int,
|
|
|
|
u_int *, int *));
|
1998-04-07 17:43:16 +04:00
|
|
|
static int pckbd_led_encode __P((int));
|
|
|
|
static int pckbd_led_decode __P((int));
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
struct pckbd_internal pckbd_consdata;
|
|
|
|
|
|
|
|
int
|
|
|
|
pckbd_set_xtscancode(kbctag, kbcslot)
|
|
|
|
pckbc_tag_t kbctag;
|
|
|
|
pckbc_slot_t kbcslot;
|
|
|
|
{
|
|
|
|
u_char cmd[2];
|
|
|
|
int res;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some keyboard/8042 combinations do not seem to work if the keyboard
|
|
|
|
* is set to table 1; in fact, it would appear that some keyboards just
|
|
|
|
* ignore the command altogether. So by default, we use the AT scan
|
|
|
|
* codes and have the 8042 translate them. Unfortunately, this is
|
|
|
|
* known to not work on some PS/2 machines. We try desparately to deal
|
|
|
|
* with this by checking the (lack of a) translate bit in the 8042 and
|
|
|
|
* attempting to set the keyboard to XT mode. If this all fails, well,
|
|
|
|
* tough luck.
|
|
|
|
*
|
|
|
|
* XXX It would perhaps be a better choice to just use AT scan codes
|
|
|
|
* and not bother with this.
|
|
|
|
*/
|
|
|
|
if (pckbc_xt_translation(kbctag, kbcslot, 1)) {
|
|
|
|
/* The 8042 is translating for us; use AT codes. */
|
|
|
|
cmd[0] = KBC_SETTABLE;
|
|
|
|
cmd[1] = 2;
|
|
|
|
res = pckbc_poll_cmd(kbctag, kbcslot, cmd, 2, 0, 0, 0);
|
1999-03-26 15:39:13 +03:00
|
|
|
if (res) {
|
|
|
|
u_char cmd[1];
|
1998-05-03 13:57:50 +04:00
|
|
|
#ifdef DEBUG
|
1998-03-22 18:41:27 +03:00
|
|
|
printf("pckbd: error setting scanset 2\n");
|
1998-05-03 13:57:50 +04:00
|
|
|
#endif
|
1999-03-26 15:39:13 +03:00
|
|
|
/*
|
|
|
|
* XXX at least one keyboard is reported to lock up
|
|
|
|
* if a "set table" is attempted, thus the "reset".
|
|
|
|
* XXX ignore errors, scanset 2 should be
|
|
|
|
* default anyway.
|
|
|
|
*/
|
|
|
|
cmd[0] = KBC_RESET;
|
|
|
|
(void)pckbc_poll_cmd(kbctag, kbcslot, cmd, 1, 1, 0, 1);
|
|
|
|
pckbc_flush(kbctag, kbcslot);
|
|
|
|
res = 0;
|
|
|
|
}
|
1998-03-22 18:41:27 +03:00
|
|
|
} else {
|
|
|
|
/* Stupid 8042; set keyboard to XT codes. */
|
|
|
|
cmd[0] = KBC_SETTABLE;
|
|
|
|
cmd[1] = 1;
|
|
|
|
res = pckbc_poll_cmd(kbctag, kbcslot, cmd, 2, 0, 0, 0);
|
1998-05-03 13:57:50 +04:00
|
|
|
#ifdef DEBUG
|
1998-03-22 18:41:27 +03:00
|
|
|
if (res)
|
|
|
|
printf("pckbd: error setting scanset 1\n");
|
1998-05-03 13:57:50 +04:00
|
|
|
#endif
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
1998-05-03 13:57:50 +04:00
|
|
|
static int
|
|
|
|
pckbd_is_console(tag, slot)
|
|
|
|
pckbc_tag_t tag;
|
|
|
|
pckbc_slot_t slot;
|
|
|
|
{
|
|
|
|
return (pckbd_consdata.t_isconsole &&
|
|
|
|
(tag == pckbd_consdata.t_kbctag) &&
|
|
|
|
(slot == pckbd_consdata.t_kbcslot));
|
|
|
|
}
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
/*
|
|
|
|
* these are both bad jokes
|
|
|
|
*/
|
|
|
|
int
|
1998-04-18 13:49:58 +04:00
|
|
|
pckbdprobe(parent, cf, aux)
|
1998-03-22 18:41:27 +03:00
|
|
|
struct device *parent;
|
1998-04-18 13:49:58 +04:00
|
|
|
struct cfdata *cf;
|
1998-03-22 18:41:27 +03:00
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pckbc_attach_args *pa = aux;
|
|
|
|
u_char cmd[1], resp[1];
|
|
|
|
int res;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX There are rumours that a keyboard can be connected
|
|
|
|
* to the aux port as well. For me, this didn't work.
|
|
|
|
* For further experiments, allow it if explicitely
|
|
|
|
* wired in the config file.
|
|
|
|
*/
|
|
|
|
if ((pa->pa_slot != PCKBC_KBD_SLOT) &&
|
1998-04-18 13:49:58 +04:00
|
|
|
(cf->cf_loc[PCKBCCF_SLOT] == PCKBCCF_SLOT_DEFAULT))
|
1998-03-22 18:41:27 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Flush any garbage. */
|
|
|
|
pckbc_flush(pa->pa_tag, pa->pa_slot);
|
|
|
|
|
|
|
|
/* Reset the keyboard. */
|
|
|
|
cmd[0] = KBC_RESET;
|
|
|
|
res = pckbc_poll_cmd(pa->pa_tag, pa->pa_slot, cmd, 1, 1, resp, 1);
|
|
|
|
if (res) {
|
1998-05-03 13:57:50 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("pckbdprobe: reset error %d\n", res);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* There is probably no keyboard connected.
|
|
|
|
* Let the probe succeed if the keyboard is used
|
|
|
|
* as console input - it can be connected later.
|
|
|
|
*/
|
|
|
|
return (pckbd_is_console(pa->pa_tag, pa->pa_slot) ? 1 : 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
if (resp[0] != KBR_RSTDONE) {
|
1998-05-03 13:57:50 +04:00
|
|
|
printf("pckbdprobe: reset response 0x%x\n", resp[0]);
|
|
|
|
return (0);
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some keyboards seem to leave a second ack byte after the reset.
|
|
|
|
* This is kind of stupid, but we account for them anyway by just
|
|
|
|
* flushing the buffer.
|
|
|
|
*/
|
|
|
|
pckbc_flush(pa->pa_tag, pa->pa_slot);
|
|
|
|
|
|
|
|
if (pckbd_set_xtscancode(pa->pa_tag, pa->pa_slot))
|
1998-05-03 13:57:50 +04:00
|
|
|
return (0);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
return (2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pckbdattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pckbd_softc *sc = (void *)self;
|
|
|
|
struct pckbc_attach_args *pa = aux;
|
|
|
|
int isconsole;
|
|
|
|
struct wskbddev_attach_args a;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
1998-05-03 13:57:50 +04:00
|
|
|
isconsole = pckbd_is_console(pa->pa_tag, pa->pa_slot);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
if (isconsole) {
|
1998-03-22 18:41:27 +03:00
|
|
|
sc->id = &pckbd_consdata;
|
1998-08-02 18:21:02 +04:00
|
|
|
sc->sc_enabled = 1;
|
|
|
|
} else {
|
1998-09-03 00:01:15 +04:00
|
|
|
u_char cmd[1];
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
sc->id = malloc(sizeof(struct pckbd_internal),
|
|
|
|
M_DEVBUF, M_WAITOK);
|
1998-04-18 13:49:58 +04:00
|
|
|
(void) pckbd_init(sc->id, pa->pa_tag, pa->pa_slot, 0);
|
1998-08-02 18:21:02 +04:00
|
|
|
|
|
|
|
/* no interrupts until enabled */
|
1998-09-03 00:01:15 +04:00
|
|
|
cmd[0] = KBC_DISABLE;
|
|
|
|
(void) pckbc_poll_cmd(sc->id->t_kbctag, sc->id->t_kbcslot,
|
|
|
|
cmd, 1, 0, 0, 0);
|
|
|
|
sc->sc_enabled = 0;
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->id->t_sc = sc;
|
|
|
|
|
|
|
|
pckbc_set_inputhandler(sc->id->t_kbctag, sc->id->t_kbcslot,
|
|
|
|
pckbd_input, sc);
|
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
a.console = isconsole;
|
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
a.keymap = &pckbd_keymapdata;
|
1998-04-09 17:09:45 +04:00
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
a.accessops = &pckbd_accessops;
|
|
|
|
a.accesscookie = sc;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the wskbd, saving a handle to it.
|
|
|
|
* XXX XXX XXX
|
|
|
|
*/
|
|
|
|
sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
|
|
|
|
}
|
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
int
|
|
|
|
pckbd_enable(v, on)
|
|
|
|
void *v;
|
|
|
|
int on;
|
|
|
|
{
|
|
|
|
struct pckbd_softc *sc = v;
|
|
|
|
u_char cmd[1];
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (on) {
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
pckbc_slot_enable(sc->id->t_kbctag, sc->id->t_kbcslot, 1);
|
|
|
|
|
|
|
|
cmd[0] = KBC_ENABLE;
|
|
|
|
res = pckbc_enqueue_cmd(sc->id->t_kbctag, sc->id->t_kbcslot,
|
1999-01-26 14:07:25 +03:00
|
|
|
cmd, 1, 0, 0, 0);
|
1998-08-02 18:21:02 +04:00
|
|
|
if (res) {
|
|
|
|
printf("pckbd_enable: command error\n");
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = pckbd_set_xtscancode(sc->id->t_kbctag, sc->id->t_kbcslot);
|
|
|
|
if (res)
|
|
|
|
return (res);
|
|
|
|
|
|
|
|
sc->sc_enabled = 1;
|
|
|
|
} else {
|
|
|
|
if (sc->id->t_isconsole)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
cmd[0] = KBC_DISABLE;
|
|
|
|
res = pckbc_enqueue_cmd(sc->id->t_kbctag, sc->id->t_kbcslot,
|
1999-01-26 14:07:25 +03:00
|
|
|
cmd, 1, 0, 0, 0);
|
1998-08-02 18:21:02 +04:00
|
|
|
if (res) {
|
|
|
|
printf("pckbd_disable: command error\n");
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
pckbc_slot_enable(sc->id->t_kbctag, sc->id->t_kbcslot, 0);
|
|
|
|
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pckbd_decode(id, datain, type, dataout)
|
1998-04-09 17:09:45 +04:00
|
|
|
struct pckbd_internal *id;
|
1998-04-17 01:18:46 +04:00
|
|
|
int datain;
|
1998-04-07 17:43:16 +04:00
|
|
|
u_int *type;
|
1998-04-17 01:18:46 +04:00
|
|
|
int *dataout;
|
1998-04-07 17:43:16 +04:00
|
|
|
{
|
1998-04-17 01:18:46 +04:00
|
|
|
if (datain == KBR_EXTENDED0) {
|
1998-04-09 17:09:45 +04:00
|
|
|
id->t_extended = 1;
|
1998-04-07 17:43:16 +04:00
|
|
|
return(0);
|
1998-04-17 01:18:46 +04:00
|
|
|
} else if (datain == KBR_EXTENDED1) {
|
1998-04-09 17:09:45 +04:00
|
|
|
id->t_extended1 = 2;
|
1998-04-07 17:43:16 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process BREAK key (EXT1 1D 45 EXT1 9D C5) map to (unused) code 7F */
|
1998-04-17 01:18:46 +04:00
|
|
|
if (id->t_extended1 == 2 && (datain == 0x1d || datain == 0x9d)) {
|
1998-04-09 17:09:45 +04:00
|
|
|
id->t_extended1 = 1;
|
1998-04-07 17:43:16 +04:00
|
|
|
return(0);
|
1998-04-17 01:18:46 +04:00
|
|
|
} else if (id->t_extended1 == 1 && (datain == 0x45 || datain == 0xc5)) {
|
1998-04-09 17:09:45 +04:00
|
|
|
id->t_extended1 = 0;
|
1998-04-17 01:18:46 +04:00
|
|
|
datain = (datain & 0x80) | 0x7f;
|
1998-04-09 17:09:45 +04:00
|
|
|
} else if (id->t_extended1 > 0) {
|
|
|
|
id->t_extended1 = 0;
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Always ignore typematic keys */
|
1998-04-17 01:18:46 +04:00
|
|
|
if (datain == id->t_lastchar)
|
1998-04-07 17:43:16 +04:00
|
|
|
return(0);
|
1998-04-17 01:18:46 +04:00
|
|
|
id->t_lastchar = datain;
|
1998-04-07 17:43:16 +04:00
|
|
|
|
1998-04-17 01:18:46 +04:00
|
|
|
if (datain & 0x80)
|
1998-04-07 17:43:16 +04:00
|
|
|
*type = WSCONS_EVENT_KEY_UP;
|
|
|
|
else
|
|
|
|
*type = WSCONS_EVENT_KEY_DOWN;
|
|
|
|
|
|
|
|
/* map extended keys to (unused) codes 128-254 */
|
1998-04-17 01:18:46 +04:00
|
|
|
*dataout = (datain & 0x7f) | (id->t_extended ? 0x80 : 0);
|
1998-04-07 17:43:16 +04:00
|
|
|
|
1998-04-09 17:09:45 +04:00
|
|
|
id->t_extended = 0;
|
1998-04-07 17:43:16 +04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1998-04-18 13:49:58 +04:00
|
|
|
int
|
1998-03-22 18:41:27 +03:00
|
|
|
pckbd_init(t, kbctag, kbcslot, console)
|
|
|
|
struct pckbd_internal *t;
|
|
|
|
pckbc_tag_t kbctag;
|
|
|
|
pckbc_slot_t kbcslot;
|
|
|
|
int console;
|
|
|
|
{
|
1998-04-18 13:49:58 +04:00
|
|
|
bzero(t, sizeof(struct pckbd_internal));
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
t->t_isconsole = console;
|
|
|
|
t->t_kbctag = kbctag;
|
|
|
|
t->t_kbcslot = kbcslot;
|
1998-04-18 13:49:58 +04:00
|
|
|
|
|
|
|
return (pckbd_set_xtscancode(kbctag, kbcslot));
|
1998-04-07 17:43:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pckbd_led_encode(led)
|
|
|
|
int led;
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
if (led & WSKBD_LED_SCROLL)
|
|
|
|
res |= 0x01;
|
|
|
|
if (led & WSKBD_LED_NUM)
|
|
|
|
res |= 0x02;
|
|
|
|
if (led & WSKBD_LED_CAPS)
|
|
|
|
res |= 0x04;
|
|
|
|
return(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pckbd_led_decode(led)
|
|
|
|
int led;
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = 0;
|
|
|
|
if (led & 0x01)
|
|
|
|
res |= WSKBD_LED_SCROLL;
|
|
|
|
if (led & 0x02)
|
|
|
|
res |= WSKBD_LED_NUM;
|
|
|
|
if (led & 0x04)
|
|
|
|
res |= WSKBD_LED_CAPS;
|
|
|
|
return(res);
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-04-07 17:43:16 +04:00
|
|
|
pckbd_set_leds(v, leds)
|
|
|
|
void *v;
|
|
|
|
int leds;
|
1998-03-22 18:41:27 +03:00
|
|
|
{
|
1998-08-02 18:21:02 +04:00
|
|
|
struct pckbd_softc *sc = v;
|
1998-03-22 18:41:27 +03:00
|
|
|
u_char cmd[2];
|
|
|
|
|
|
|
|
cmd[0] = KBC_MODEIND;
|
1998-04-07 17:43:16 +04:00
|
|
|
cmd[1] = pckbd_led_encode(leds);
|
1998-08-02 18:21:02 +04:00
|
|
|
sc->sc_ledstate = cmd[1];
|
1998-03-22 18:41:27 +03:00
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
(void) pckbc_enqueue_cmd(sc->id->t_kbctag, sc->id->t_kbcslot,
|
|
|
|
cmd, 2, 0, 0, 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Got a console receive interrupt -
|
|
|
|
* the console processor wants to give us a character.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pckbd_input(vsc, data)
|
|
|
|
void *vsc;
|
|
|
|
int data;
|
|
|
|
{
|
|
|
|
struct pckbd_softc *sc = vsc;
|
1998-04-17 01:18:46 +04:00
|
|
|
int type, key;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
1998-06-12 02:15:14 +04:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
if (sc->rawkbd) {
|
|
|
|
char d = data;
|
|
|
|
wskbd_rawinput(sc->sc_wskbddev, &d, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
1998-04-17 01:18:46 +04:00
|
|
|
if (pckbd_decode(sc->id, data, &type, &key))
|
|
|
|
wskbd_input(sc->sc_wskbddev, type, key);
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pckbd_ioctl(v, cmd, data, flag, p)
|
|
|
|
void *v;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-08-02 18:21:02 +04:00
|
|
|
struct pckbd_softc *sc = v;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WSKBDIO_GTYPE:
|
|
|
|
*(int *)data = WSKBD_TYPE_PC_XT;
|
|
|
|
return 0;
|
|
|
|
case WSKBDIO_SETLEDS: {
|
|
|
|
char cmd[2];
|
|
|
|
int res;
|
|
|
|
cmd[0] = KBC_MODEIND;
|
1998-04-07 17:43:16 +04:00
|
|
|
cmd[1] = pckbd_led_encode(*(int *)data);
|
1998-08-02 18:21:02 +04:00
|
|
|
sc->sc_ledstate = cmd[1];
|
|
|
|
res = pckbc_enqueue_cmd(sc->id->t_kbctag, sc->id->t_kbcslot,
|
|
|
|
cmd, 2, 0, 1, 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
return (res);
|
|
|
|
}
|
1998-04-07 17:43:16 +04:00
|
|
|
case WSKBDIO_GETLEDS:
|
1998-08-02 18:21:02 +04:00
|
|
|
*(int *)data = pckbd_led_decode(sc->sc_ledstate);
|
1998-04-17 01:18:46 +04:00
|
|
|
return (0);
|
|
|
|
case WSKBDIO_COMPLEXBELL:
|
|
|
|
#define d ((struct wskbd_bell_data *)data)
|
|
|
|
/* keyboard can't beep - use md code */
|
|
|
|
#ifdef __i386__
|
|
|
|
sysbeep(d->pitch, d->period * hz / 1000);
|
|
|
|
/* comes in as ms, goes out as ticks; volume ignored */
|
|
|
|
#endif
|
1998-08-07 14:28:36 +04:00
|
|
|
#ifdef __alpha__
|
|
|
|
isabeep(d->pitch, d->period * hz / 1000);
|
|
|
|
/* comes in as ms, goes out as ticks; volume ignored */
|
|
|
|
#endif
|
1998-04-17 01:18:46 +04:00
|
|
|
#undef d
|
|
|
|
return (0);
|
1998-06-12 02:15:14 +04:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
case WSKBDIO_SETMODE:
|
1998-08-02 18:21:02 +04:00
|
|
|
sc->rawkbd = (*(int *)data == WSKBD_RAW);
|
1998-06-12 02:15:14 +04:00
|
|
|
return (0);
|
|
|
|
#endif
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pckbd_cnattach(kbctag, kbcslot)
|
|
|
|
pckbc_tag_t kbctag;
|
|
|
|
int kbcslot;
|
|
|
|
{
|
1998-08-02 18:21:02 +04:00
|
|
|
char cmd[1];
|
1998-04-18 13:49:58 +04:00
|
|
|
int res;
|
1998-04-09 17:09:45 +04:00
|
|
|
|
1998-04-18 13:49:58 +04:00
|
|
|
res = pckbd_init(&pckbd_consdata, kbctag, kbcslot, 1);
|
1998-05-03 13:57:50 +04:00
|
|
|
#if 0 /* we allow the console to be attached if no keyboard is present */
|
1998-04-18 13:49:58 +04:00
|
|
|
if (res)
|
|
|
|
return (res);
|
1998-05-03 13:57:50 +04:00
|
|
|
#endif
|
1998-03-22 18:41:27 +03:00
|
|
|
|
1998-08-02 18:21:02 +04:00
|
|
|
/* Just to be sure. */
|
|
|
|
cmd[0] = KBC_ENABLE;
|
|
|
|
res = pckbc_poll_cmd(kbctag, kbcslot, cmd, 1, 0, 0, 0);
|
|
|
|
#if 0
|
|
|
|
if (res)
|
|
|
|
return (res);
|
1998-04-09 17:09:45 +04:00
|
|
|
#endif
|
1998-08-02 18:21:02 +04:00
|
|
|
|
|
|
|
wskbd_cnattach(&pckbd_consops, &pckbd_consdata, &pckbd_keymapdata);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1998-04-07 17:43:16 +04:00
|
|
|
void
|
|
|
|
pckbd_cngetc(v, type, data)
|
1998-03-22 18:41:27 +03:00
|
|
|
void *v;
|
1998-04-07 17:43:16 +04:00
|
|
|
u_int *type;
|
|
|
|
int *data;
|
1998-03-22 18:41:27 +03:00
|
|
|
{
|
1998-04-09 17:09:45 +04:00
|
|
|
struct pckbd_internal *t = v;
|
1998-04-17 01:18:46 +04:00
|
|
|
int val;
|
1998-04-09 17:09:45 +04:00
|
|
|
|
1998-04-07 17:43:16 +04:00
|
|
|
for (;;) {
|
1998-04-17 01:18:46 +04:00
|
|
|
val = pckbc_poll_data(t->t_kbctag, t->t_kbcslot);
|
|
|
|
if ((val != -1) && pckbd_decode(t, val, type, data))
|
1998-04-07 17:43:16 +04:00
|
|
|
return;
|
|
|
|
}
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pckbd_cnpollc(v, on)
|
|
|
|
void *v;
|
|
|
|
int on;
|
|
|
|
{
|
1998-04-09 17:09:45 +04:00
|
|
|
struct pckbd_internal *t = v;
|
|
|
|
|
|
|
|
pckbc_set_poll(t->t_kbctag, t->t_kbcslot, on);
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|