/*
* Copyright (c) 2002 Valeriy E. Ushakov
* All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*-
* 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.
*
* 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.
*/
/*-
* 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. 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
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kbd_pckbport.c,v 1.7 2022/05/24 20:50:18 andvar Exp $");
/*
* Serve JavaStation-1 PS/2 keyboard as a Type5 keyboard with US101A
* layout. Since stock Xsun(1) knows this layout, JavaStation-1 gets
* X for free. When sparc port is switched to wscons and its X server
* knows how to talk wskbd, this driver will no longer be necessary,
* and we will be able to attach the keyboard with the MI pckbport(4) driver.
*/
static int
kbd_pckbport_set_xtscancode(pckbport_tag_t kbctag, pckbport_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 desperately 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 (pckbport_xt_translation(kbctag, kbcslot, 1)) {
/* The 8042 is translating for us; use AT codes. */
cmd[0] = KBC_SETTABLE;
cmd[1] = 2;
res = pckbport_poll_cmd(kbctag, kbcslot, cmd, 2, 0, 0, 0);
if (res) {
u_char resetcmd[1];
#ifdef DEBUG
printf("pckbd: error setting scanset 2\n");
#endif
/*
* 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.
*/
resetcmd[0] = KBC_RESET;
(void)pckbport_poll_cmd(kbctag, kbcslot, resetcmd,
1, 1, 0, 1);
pckbport_flush(kbctag, kbcslot);
res = 0;
}
} else {
/* Stupid 8042; set keyboard to XT codes. */
cmd[0] = KBC_SETTABLE;
cmd[1] = 1;
res = pckbport_poll_cmd(kbctag, kbcslot, cmd, 2, 0, 0, 0);
#ifdef DEBUG
if (res)
printf("pckbd: error setting scanset 1\n");
#endif
}
return (res);
}
/*
* Initialization to be done at first open.
* This is called from kbdopen() or kd_cc_open()
* Called with user context.
*/
static int
kbd_pckbport_open(struct kbd_softc *kbd)
{
struct kbd_pckbport_softc *sc = (struct kbd_pckbport_softc *)kbd;
struct kbd_state *ks;
int error = 0;
/* tolerate extra calls */
if (sc->sc_isopen)
return (0);
/* open internal device */
/* reset the keyboard (and enable interrupts?) */
/*
* Initialize the table pointers for this type/layout.
* NB: fixed type/layout were preset during attach.
*/
kbd_xlate_init(ks);
if (error == 0)
sc->sc_isopen = 1;
return (error);
}
static int
kbd_pckbport_close(struct kbd_softc *kbd)
{
#if 0
struct kbd_pckbport_softc *k = (struct kbd_pckbport_softc *)kbd;
#endif
return (0); /* nothing to do so far */
}
/*
* Upper layer talks sun keyboard protocol to us.
*/
/* ARGSUSED2 */
static int
kbd_pckbport_do_cmd(struct kbd_softc *kbd, int suncmd, int isioctl)
{
int error = 0;
switch (suncmd) {
case KBD_CMD_BELL: /* FALLTHROUGH */
case KBD_CMD_NOBELL: /* FALLTHROUGH */
case KBD_CMD_CLICK: /* FALLTHROUGH */
case KBD_CMD_NOCLICK:
/* not supported, do nothing */
DPRINTF(("%s: ignoring KIOCCMD 0x%02x\n",
device_xname(kbd->k_dev), suncmd));
break;
default:
error = EINVAL;
break;
}
return (error);
}
/* ARGSUSED2 */
static int
kbd_pckbport_set_leds(struct kbd_softc *kbd, int sunleds, int isioctl)
{
struct kbd_pckbport_softc *sc = (struct kbd_pckbport_softc *)kbd;
u_char pcleds;
u_char cmd[2];
int res;
/* re-encode sun leds into pckbd leds */
/* pckbd: 0 - scroll; 1 - num; 2 - caps */
pcleds = 0;
if (sunleds & LED_SCROLL_LOCK)
pcleds |= 0x01;
if (sunleds & LED_NUM_LOCK)
pcleds |= 0x02;
if (sunleds & LED_CAPS_LOCK)
pcleds |= 0x04;
if (pcleds == sc->sc_pcleds)
return (0);
sc->sc_pcleds = pcleds;
DPRINTF(("leds: sun %x, pc %x\n", sunleds, pcleds));
/* request the change */
cmd[0] = KBC_MODEIND;
cmd[1] = pcleds;
if (isioctl) /* user called KIOCSLED */
res = pckbport_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot,
cmd, 2, 0, 1, NULL);
else /* console updates leds - called from interrupt handler */
res = pckbport_poll_cmd(sc->sc_kbctag, sc->sc_kbcslot,
cmd, 2, 0, NULL, 0);
return (res);
}
/*
* Got a receive interrupt - pckbport wants to give us a byte.
*/
static void
kbd_pckbport_input(void *vsc, int data)
{
struct kbd_pckbport_softc *sc = vsc;
struct kbd_softc *kbd = &sc->sc_kbd;
int sunkey;
/* convert to sun make/break code */
if (!kbd_pckbport_decode(sc, data, &sunkey))
return;
kbd_input(kbd, sunkey);
}
/*
* Plagiarized from pckbd_decode
*/
static int
kbd_pckbport_decode(struct kbd_pckbport_softc *sc, int data, int *sundata)
{
int key, up;
int sunkey;