1998-12-14 09:32:25 +00:00
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
1999-01-07 23:07:57 +00:00
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-05-14 16:43:10 +00:00
|
|
|
|
* by Lennart Augustsson (lennart@augustsson.net) at
|
1999-01-07 23:07:57 +00:00
|
|
|
|
* Carlstedt Research & Technology.
|
1998-11-26 23:13:13 +00:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
2004-01-03 15:01:04 +00:00
|
|
|
|
*
|
|
|
|
|
* Modifications for SUN TYPE 6 USB Keyboard by
|
|
|
|
|
* J<EFBFBD>rg Peter Schley (jps@scxnet.de)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
|
/*
|
2004-02-23 15:36:40 +00:00
|
|
|
|
* HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
|
1999-01-07 23:07:57 +00:00
|
|
|
|
*/
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
#include "opt_kbd.h"
|
2000-01-11 13:39:05 +00:00
|
|
|
|
#include "opt_ukbd.h"
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
|
#include <sys/module.h>
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
|
#include <sys/file.h>
|
2003-10-04 21:41:01 +00:00
|
|
|
|
#if __FreeBSD_version >= 500000
|
2003-04-29 13:36:06 +00:00
|
|
|
|
#include <sys/limits.h>
|
2003-10-04 21:41:01 +00:00
|
|
|
|
#else
|
|
|
|
|
#include <machine/limits.h>
|
|
|
|
|
#endif
|
2001-01-09 04:33:49 +00:00
|
|
|
|
#if __FreeBSD_version >= 500014
|
|
|
|
|
#include <sys/selinfo.h>
|
|
|
|
|
#else
|
1998-11-26 23:13:13 +00:00
|
|
|
|
#include <sys/select.h>
|
2001-01-09 04:33:49 +00:00
|
|
|
|
#endif
|
1998-11-26 23:13:13 +00:00
|
|
|
|
#include <sys/vnode.h>
|
2002-07-31 13:33:55 +00:00
|
|
|
|
#include <sys/sysctl.h>
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
|
#include <dev/usb/usbhid.h>
|
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
|
|
|
|
#include <dev/usb/usbdevs.h>
|
|
|
|
|
#include <dev/usb/usb_quirks.h>
|
|
|
|
|
#include <dev/usb/hid.h>
|
|
|
|
|
|
2001-07-20 13:05:57 +00:00
|
|
|
|
#include <sys/kbio.h>
|
1999-03-22 19:55:30 +00:00
|
|
|
|
#include <dev/kbd/kbdreg.h>
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
#define UKBD_EMULATE_ATSCANCODE 1
|
|
|
|
|
|
|
|
|
|
#define DRIVER_NAME "ukbd"
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
|
|
|
|
#define delay(d) DELAY(d)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
2002-07-31 14:34:36 +00:00
|
|
|
|
#ifdef USB_DEBUG
|
1999-04-11 16:49:15 +00:00
|
|
|
|
#define DPRINTF(x) if (ukbddebug) logprintf x
|
|
|
|
|
#define DPRINTFN(n,x) if (ukbddebug>(n)) logprintf x
|
2002-07-31 14:34:36 +00:00
|
|
|
|
int ukbddebug = 0;
|
2002-08-08 12:05:51 +00:00
|
|
|
|
SYSCTL_NODE(_hw_usb, OID_AUTO, ukbd, CTLFLAG_RW, 0, "USB ukbd");
|
|
|
|
|
SYSCTL_INT(_hw_usb_ukbd, OID_AUTO, debug, CTLFLAG_RW,
|
2002-07-31 13:33:55 +00:00
|
|
|
|
&ukbddebug, 0, "ukbd debug level");
|
1999-01-07 23:07:57 +00:00
|
|
|
|
#else
|
1998-11-26 23:13:13 +00:00
|
|
|
|
#define DPRINTF(x)
|
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define UPROTO_BOOT_KEYBOARD 1
|
|
|
|
|
|
|
|
|
|
#define NKEYCODE 6
|
|
|
|
|
|
|
|
|
|
struct ukbd_data {
|
|
|
|
|
u_int8_t modifiers;
|
|
|
|
|
#define MOD_CONTROL_L 0x01
|
|
|
|
|
#define MOD_CONTROL_R 0x10
|
|
|
|
|
#define MOD_SHIFT_L 0x02
|
|
|
|
|
#define MOD_SHIFT_R 0x20
|
|
|
|
|
#define MOD_ALT_L 0x04
|
|
|
|
|
#define MOD_ALT_R 0x40
|
|
|
|
|
#define MOD_WIN_L 0x08
|
|
|
|
|
#define MOD_WIN_R 0x80
|
|
|
|
|
u_int8_t reserved;
|
|
|
|
|
u_int8_t keycode[NKEYCODE];
|
|
|
|
|
};
|
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
|
#define MAXKEYS (NMOD+2*NKEYCODE)
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
typedef struct ukbd_softc {
|
1999-10-07 18:53:08 +00:00
|
|
|
|
device_t sc_dev; /* base device */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
} ukbd_softc_t;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
|
|
#define UKBD_CHUNK 128 /* chunk size for read */
|
|
|
|
|
#define UKBD_BSIZE 1020 /* buffer size */
|
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
|
typedef void usbd_intr_t(usbd_xfer_handle, usbd_private_handle, usbd_status);
|
1999-04-11 16:49:15 +00:00
|
|
|
|
typedef void usbd_disco_t(void *);
|
|
|
|
|
|
2001-06-30 10:02:32 +00:00
|
|
|
|
Static int ukbd_resume(device_t self);
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static usbd_intr_t ukbd_intr;
|
|
|
|
|
Static int ukbd_driver_load(module_t mod, int what, void *arg);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
2001-06-30 10:02:32 +00:00
|
|
|
|
USB_DECLARE_DRIVER_INIT(ukbd, DEVMETHOD(device_resume, ukbd_resume));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
|
USB_MATCH(ukbd)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
{
|
1999-01-07 23:07:57 +00:00
|
|
|
|
USB_MATCH_START(ukbd, uaa);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
keyboard_switch_t *sw;
|
1999-10-07 18:53:08 +00:00
|
|
|
|
void *arg[2];
|
1999-06-26 12:55:25 +00:00
|
|
|
|
int unit = device_get_unit(self);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
sw = kbd_get_switch(DRIVER_NAME);
|
|
|
|
|
if (sw == NULL)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
return (UMATCH_NONE);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
arg[0] = (void *)uaa;
|
|
|
|
|
arg[1] = (void *)ukbd_intr;
|
|
|
|
|
if ((*sw->probe)(unit, (void *)arg, 0))
|
1998-11-26 23:13:13 +00:00
|
|
|
|
return (UMATCH_NONE);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
|
return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
|
USB_ATTACH(ukbd)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
{
|
1999-01-07 23:07:57 +00:00
|
|
|
|
USB_ATTACH_START(ukbd, sc, uaa);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
usbd_interface_handle iface = uaa->iface;
|
|
|
|
|
usb_interface_descriptor_t *id;
|
|
|
|
|
char devinfo[1024];
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
keyboard_switch_t *sw;
|
1999-08-22 09:52:33 +00:00
|
|
|
|
keyboard_t *kbd;
|
1999-10-07 18:53:08 +00:00
|
|
|
|
void *arg[2];
|
1999-03-22 19:55:30 +00:00
|
|
|
|
int unit = device_get_unit(self);
|
|
|
|
|
|
|
|
|
|
sw = kbd_get_switch(DRIVER_NAME);
|
|
|
|
|
if (sw == NULL)
|
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
|
id = usbd_get_interface_descriptor(iface);
|
|
|
|
|
usbd_devinfo(uaa->device, 0, devinfo);
|
1999-01-07 23:07:57 +00:00
|
|
|
|
USB_ATTACH_SETUP;
|
|
|
|
|
printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
|
|
|
|
|
devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
arg[0] = (void *)uaa;
|
|
|
|
|
arg[1] = (void *)ukbd_intr;
|
1999-08-22 09:52:33 +00:00
|
|
|
|
kbd = NULL;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if ((*sw->probe)(unit, (void *)arg, 0))
|
1999-01-07 23:07:57 +00:00
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1999-08-22 09:52:33 +00:00
|
|
|
|
if ((*sw->init)(unit, &kbd, (void *)arg, 0))
|
1999-01-07 23:07:57 +00:00
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1999-08-22 09:52:33 +00:00
|
|
|
|
(*sw->enable)(kbd);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
#ifdef KBD_INSTALL_CDEV
|
1999-08-22 09:52:33 +00:00
|
|
|
|
if (kbd_attach(kbd))
|
1999-03-22 19:55:30 +00:00
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
#endif
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (bootverbose)
|
1999-08-22 09:52:33 +00:00
|
|
|
|
(*sw->diag)(kbd, bootverbose);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
|
USB_ATTACH_SUCCESS_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
ukbd_detach(device_t self)
|
|
|
|
|
{
|
1999-08-22 09:52:33 +00:00
|
|
|
|
keyboard_t *kbd;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
int error;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-08-22 09:52:33 +00:00
|
|
|
|
kbd = kbd_get_keyboard(kbd_find_keyboard(DRIVER_NAME,
|
|
|
|
|
device_get_unit(self)));
|
|
|
|
|
if (kbd == NULL) {
|
|
|
|
|
DPRINTF(("%s: keyboard not attached!?\n", USBDEVNAME(self)));
|
|
|
|
|
return ENXIO;
|
|
|
|
|
}
|
1999-10-07 18:53:08 +00:00
|
|
|
|
(*kbdsw[kbd->kb_index]->disable)(kbd);
|
|
|
|
|
|
1999-08-22 09:52:33 +00:00
|
|
|
|
#ifdef KBD_INSTALL_CDEV
|
|
|
|
|
error = kbd_detach(kbd);
|
|
|
|
|
if (error)
|
|
|
|
|
return error;
|
|
|
|
|
#endif
|
|
|
|
|
error = (*kbdsw[kbd->kb_index]->term)(kbd);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (error)
|
|
|
|
|
return error;
|
1999-04-11 16:49:15 +00:00
|
|
|
|
|
|
|
|
|
DPRINTF(("%s: disconnected\n", USBDEVNAME(self)));
|
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
|
return (0);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
2001-06-30 10:02:32 +00:00
|
|
|
|
Static int
|
|
|
|
|
ukbd_resume(device_t self)
|
|
|
|
|
{
|
|
|
|
|
keyboard_t *kbd;
|
|
|
|
|
|
|
|
|
|
kbd = kbd_get_keyboard(kbd_find_keyboard(DRIVER_NAME,
|
|
|
|
|
device_get_unit(self)));
|
|
|
|
|
if (kbd)
|
|
|
|
|
(*kbdsw[kbd->kb_index]->clear_state)(kbd);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
|
void
|
1999-11-17 22:33:51 +00:00
|
|
|
|
ukbd_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
{
|
1999-03-22 19:55:30 +00:00
|
|
|
|
keyboard_t *kbd = (keyboard_t *)addr;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
(*kbdsw[kbd->kb_index]->intr)(kbd, (void *)status);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-13 10:36:36 +00:00
|
|
|
|
DRIVER_MODULE(ukbd, uhub, ukbd_driver, ukbd_devclass, ukbd_driver_load, 0);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define UKBD_DEFAULT 0
|
|
|
|
|
|
|
|
|
|
#define KEY_ERROR 0x01
|
|
|
|
|
|
|
|
|
|
#define KEY_PRESS 0
|
|
|
|
|
#define KEY_RELEASE 0x400
|
|
|
|
|
#define KEY_INDEX(c) ((c) & ~KEY_RELEASE)
|
|
|
|
|
|
|
|
|
|
#define SCAN_PRESS 0
|
|
|
|
|
#define SCAN_RELEASE 0x80
|
|
|
|
|
#define SCAN_PREFIX_E0 0x100
|
|
|
|
|
#define SCAN_PREFIX_E1 0x200
|
|
|
|
|
#define SCAN_PREFIX_CTL 0x400
|
|
|
|
|
#define SCAN_PREFIX_SHIFT 0x800
|
|
|
|
|
#define SCAN_PREFIX (SCAN_PREFIX_E0 | SCAN_PREFIX_E1 | SCAN_PREFIX_CTL \
|
|
|
|
|
| SCAN_PREFIX_SHIFT)
|
|
|
|
|
#define SCAN_CHAR(c) ((c) & 0x7f)
|
|
|
|
|
|
|
|
|
|
#define NMOD 8
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static struct {
|
1999-03-22 19:55:30 +00:00
|
|
|
|
int mask, key;
|
|
|
|
|
} ukbd_mods[NMOD] = {
|
|
|
|
|
{ MOD_CONTROL_L, 0xe0 },
|
|
|
|
|
{ MOD_CONTROL_R, 0xe4 },
|
|
|
|
|
{ MOD_SHIFT_L, 0xe1 },
|
|
|
|
|
{ MOD_SHIFT_R, 0xe5 },
|
|
|
|
|
{ MOD_ALT_L, 0xe2 },
|
|
|
|
|
{ MOD_ALT_R, 0xe6 },
|
|
|
|
|
{ MOD_WIN_L, 0xe3 },
|
|
|
|
|
{ MOD_WIN_R, 0xe7 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define NN 0 /* no translation */
|
2003-07-04 01:50:39 +00:00
|
|
|
|
/*
|
1999-04-11 16:49:15 +00:00
|
|
|
|
* Translate USB keycodes to AT keyboard scancodes.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* FIXME: Mac USB keyboard generates:
|
|
|
|
|
* 0x53: keypad NumLock/Clear
|
|
|
|
|
* 0x66: Power
|
|
|
|
|
* 0x67: keypad =
|
|
|
|
|
* 0x68: F13
|
|
|
|
|
* 0x69: F14
|
|
|
|
|
* 0x6a: F15
|
1999-03-22 19:55:30 +00:00
|
|
|
|
*/
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static u_int8_t ukbd_trtab[256] = {
|
1999-03-22 19:55:30 +00:00
|
|
|
|
0, 0, 0, 0, 30, 48, 46, 32, /* 00 - 07 */
|
|
|
|
|
18, 33, 34, 35, 23, 36, 37, 38, /* 08 - 0F */
|
|
|
|
|
50, 49, 24, 25, 16, 19, 31, 20, /* 10 - 17 */
|
|
|
|
|
22, 47, 17, 45, 21, 44, 2, 3, /* 18 - 1F */
|
|
|
|
|
4, 5, 6, 7, 8, 9, 10, 11, /* 20 - 27 */
|
|
|
|
|
28, 1, 14, 15, 57, 12, 13, 26, /* 28 - 2F */
|
|
|
|
|
27, 43, 43, 39, 40, 41, 51, 52, /* 30 - 37 */
|
|
|
|
|
53, 58, 59, 60, 61, 62, 63, 64, /* 38 - 3F */
|
|
|
|
|
65, 66, 67, 68, 87, 88, 92, 70, /* 40 - 47 */
|
|
|
|
|
104, 102, 94, 96, 103, 99, 101, 98, /* 48 - 4F */
|
|
|
|
|
97, 100, 95, 69, 91, 55, 74, 78, /* 50 - 57 */
|
|
|
|
|
89, 79, 80, 81, 75, 76, 77, 71, /* 58 - 5F */
|
2004-01-03 15:01:04 +00:00
|
|
|
|
72, 73, 82, 83, 86, 107, 122, NN, /* 60 - 67 */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 68 - 6F */
|
2004-01-03 15:01:04 +00:00
|
|
|
|
NN, NN, NN, NN, 115, 108, 111, 113, /* 70 - 77 */
|
|
|
|
|
109, 110, 112, 118, 114, 116, 117, 119, /* 78 - 7F */
|
|
|
|
|
121, 120, NN, NN, NN, NN, NN, 115, /* 80 - 87 */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
112, 125, 121, 123, NN, NN, NN, NN, /* 88 - 8F */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 90 - 97 */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 98 - 9F */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* A0 - A7 */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* A8 - AF */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* B0 - B7 */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* B8 - BF */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* C0 - C7 */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* C8 - CF */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* D0 - D7 */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* D8 - DF */
|
|
|
|
|
29, 42, 56, 105, 90, 54, 93, 106, /* E0 - E7 */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* E8 - EF */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* F0 - F7 */
|
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* F8 - FF */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct ukbd_state {
|
|
|
|
|
usbd_interface_handle ks_iface; /* interface */
|
|
|
|
|
usbd_pipe_handle ks_intrpipe; /* interrupt pipe */
|
|
|
|
|
struct usb_attach_arg *ks_uaa;
|
|
|
|
|
int ks_ep_addr;
|
|
|
|
|
|
|
|
|
|
struct ukbd_data ks_ndata;
|
|
|
|
|
struct ukbd_data ks_odata;
|
|
|
|
|
u_long ks_ntime[NKEYCODE];
|
|
|
|
|
u_long ks_otime[NKEYCODE];
|
|
|
|
|
|
|
|
|
|
#define INPUTBUFSIZE (NMOD + 2*NKEYCODE)
|
|
|
|
|
u_int ks_input[INPUTBUFSIZE]; /* input buffer */
|
|
|
|
|
int ks_inputs;
|
|
|
|
|
int ks_inputhead;
|
|
|
|
|
int ks_inputtail;
|
|
|
|
|
|
|
|
|
|
int ks_ifstate;
|
|
|
|
|
#define INTRENABLED (1 << 0)
|
|
|
|
|
#define DISCONNECTED (1 << 1)
|
|
|
|
|
|
|
|
|
|
struct callout_handle ks_timeout_handle;
|
|
|
|
|
|
|
|
|
|
int ks_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */
|
|
|
|
|
int ks_flags; /* flags */
|
|
|
|
|
#define COMPOSE (1 << 0)
|
|
|
|
|
int ks_polling;
|
|
|
|
|
int ks_state; /* shift/lock key state */
|
|
|
|
|
int ks_accents; /* accent key index (> 0) */
|
|
|
|
|
u_int ks_composed_char; /* composed char code (> 0) */
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
u_int ks_buffered_char[2];
|
|
|
|
|
#endif
|
|
|
|
|
} ukbd_state_t;
|
|
|
|
|
|
|
|
|
|
/* keyboard driver declaration */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int ukbd_configure(int flags);
|
|
|
|
|
Static kbd_probe_t ukbd_probe;
|
|
|
|
|
Static kbd_init_t ukbd_init;
|
|
|
|
|
Static kbd_term_t ukbd_term;
|
|
|
|
|
Static kbd_intr_t ukbd_interrupt;
|
|
|
|
|
Static kbd_test_if_t ukbd_test_if;
|
|
|
|
|
Static kbd_enable_t ukbd_enable;
|
|
|
|
|
Static kbd_disable_t ukbd_disable;
|
|
|
|
|
Static kbd_read_t ukbd_read;
|
|
|
|
|
Static kbd_check_t ukbd_check;
|
|
|
|
|
Static kbd_read_char_t ukbd_read_char;
|
|
|
|
|
Static kbd_check_char_t ukbd_check_char;
|
|
|
|
|
Static kbd_ioctl_t ukbd_ioctl;
|
|
|
|
|
Static kbd_lock_t ukbd_lock;
|
|
|
|
|
Static kbd_clear_state_t ukbd_clear_state;
|
|
|
|
|
Static kbd_get_state_t ukbd_get_state;
|
|
|
|
|
Static kbd_set_state_t ukbd_set_state;
|
|
|
|
|
Static kbd_poll_mode_t ukbd_poll;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
keyboard_switch_t ukbdsw = {
|
|
|
|
|
ukbd_probe,
|
|
|
|
|
ukbd_init,
|
|
|
|
|
ukbd_term,
|
|
|
|
|
ukbd_interrupt,
|
|
|
|
|
ukbd_test_if,
|
1999-04-11 16:49:15 +00:00
|
|
|
|
ukbd_enable,
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_disable,
|
|
|
|
|
ukbd_read,
|
|
|
|
|
ukbd_check,
|
|
|
|
|
ukbd_read_char,
|
|
|
|
|
ukbd_check_char,
|
|
|
|
|
ukbd_ioctl,
|
|
|
|
|
ukbd_lock,
|
|
|
|
|
ukbd_clear_state,
|
|
|
|
|
ukbd_get_state,
|
|
|
|
|
ukbd_set_state,
|
|
|
|
|
genkbd_get_fkeystr,
|
|
|
|
|
ukbd_poll,
|
|
|
|
|
genkbd_diag,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
KEYBOARD_DRIVER(ukbd, ukbdsw, ukbd_configure);
|
|
|
|
|
|
|
|
|
|
/* local functions */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int ukbd_enable_intr(keyboard_t *kbd, int on,
|
1999-03-22 19:55:30 +00:00
|
|
|
|
usbd_intr_t *func);
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static timeout_t ukbd_timeout;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int ukbd_getc(ukbd_state_t *state);
|
|
|
|
|
Static int probe_keyboard(struct usb_attach_arg *uaa, int flags);
|
|
|
|
|
Static int init_keyboard(ukbd_state_t *state, int *type,
|
1999-03-22 19:55:30 +00:00
|
|
|
|
int flags);
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static void set_leds(ukbd_state_t *state, int leds);
|
|
|
|
|
Static int set_typematic(keyboard_t *kbd, int code);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int keycode2scancode(int keycode, int shift, int up);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* local variables */
|
|
|
|
|
|
|
|
|
|
/* the initial key map, accent map and fkey strings */
|
|
|
|
|
#ifdef UKBD_DFLT_KEYMAP
|
|
|
|
|
#define KBD_DFLT_KEYMAP
|
|
|
|
|
#include "ukbdmap.h"
|
|
|
|
|
#endif
|
|
|
|
|
#include <dev/kbd/kbdtables.h>
|
|
|
|
|
|
|
|
|
|
/* structures for the default keyboard */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static keyboard_t default_kbd;
|
|
|
|
|
Static ukbd_state_t default_kbd_state;
|
|
|
|
|
Static keymap_t default_keymap;
|
|
|
|
|
Static accentmap_t default_accentmap;
|
|
|
|
|
Static fkeytab_t default_fkeytab[NUM_FKEYS];
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
2003-07-04 01:50:39 +00:00
|
|
|
|
/*
|
1999-03-22 19:55:30 +00:00
|
|
|
|
* The back door to the keyboard driver!
|
|
|
|
|
* This function is called by the console driver, via the kbdio module,
|
|
|
|
|
* to tickle keyboard drivers when the low-level console is being initialized.
|
|
|
|
|
* Almost nothing in the kernel has been initialied yet. Try to probe
|
|
|
|
|
* keyboards if possible.
|
|
|
|
|
* NOTE: because of the way the low-level conole is initialized, this routine
|
|
|
|
|
* may be called more than once!!
|
|
|
|
|
*/
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_configure(int flags)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
#if 0 /* not yet */
|
|
|
|
|
keyboard_t *kbd;
|
|
|
|
|
device_t device;
|
|
|
|
|
struct usb_attach_arg *uaa;
|
1999-10-07 18:53:08 +00:00
|
|
|
|
void *arg[2];
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
device = devclass_get_device(ukbd_devclass, UKBD_DEFAULT);
|
|
|
|
|
if (device == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
uaa = (struct usb_attach_arg *)device_get_ivars(device);
|
|
|
|
|
if (uaa == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* probe the default keyboard */
|
|
|
|
|
arg[0] = (void *)uaa;
|
|
|
|
|
arg[1] = (void *)ukbd_intr;
|
|
|
|
|
kbd = NULL;
|
|
|
|
|
if (ukbd_probe(UKBD_DEFAULT, arg, flags))
|
|
|
|
|
return 0;
|
|
|
|
|
if (ukbd_init(UKBD_DEFAULT, &kbd, arg, flags))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* return the number of found keyboards */
|
|
|
|
|
return 1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* low-level functions */
|
|
|
|
|
|
|
|
|
|
/* detect a keyboard */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_probe(int unit, void *arg, int flags)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
{
|
1999-03-22 19:55:30 +00:00
|
|
|
|
void **data;
|
|
|
|
|
struct usb_attach_arg *uaa;
|
|
|
|
|
|
|
|
|
|
data = (void **)arg;
|
|
|
|
|
uaa = (struct usb_attach_arg *)data[0];
|
|
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
|
if (unit == UKBD_DEFAULT) {
|
|
|
|
|
if (KBD_IS_PROBED(&default_kbd))
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (probe_keyboard(uaa, flags))
|
|
|
|
|
return ENXIO;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* reset and initialize the device */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
|
|
|
|
|
{
|
|
|
|
|
keyboard_t *kbd;
|
|
|
|
|
ukbd_state_t *state;
|
|
|
|
|
keymap_t *keymap;
|
|
|
|
|
accentmap_t *accmap;
|
|
|
|
|
fkeytab_t *fkeymap;
|
|
|
|
|
int fkeymap_size;
|
|
|
|
|
void **data = (void **)arg;
|
|
|
|
|
struct usb_attach_arg *uaa = (struct usb_attach_arg *)data[0];
|
|
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
|
if (unit == UKBD_DEFAULT) {
|
|
|
|
|
*kbdp = kbd = &default_kbd;
|
|
|
|
|
if (KBD_IS_INITIALIZED(kbd) && KBD_IS_CONFIGURED(kbd))
|
|
|
|
|
return 0;
|
|
|
|
|
state = &default_kbd_state;
|
|
|
|
|
keymap = &default_keymap;
|
|
|
|
|
accmap = &default_accentmap;
|
|
|
|
|
fkeymap = default_fkeytab;
|
|
|
|
|
fkeymap_size =
|
|
|
|
|
sizeof(default_fkeytab)/sizeof(default_fkeytab[0]);
|
|
|
|
|
} else if (*kbdp == NULL) {
|
|
|
|
|
*kbdp = kbd = malloc(sizeof(*kbd), M_DEVBUF, M_NOWAIT);
|
|
|
|
|
if (kbd == NULL)
|
|
|
|
|
return ENOMEM;
|
|
|
|
|
bzero(kbd, sizeof(*kbd));
|
|
|
|
|
state = malloc(sizeof(*state), M_DEVBUF, M_NOWAIT);
|
|
|
|
|
keymap = malloc(sizeof(key_map), M_DEVBUF, M_NOWAIT);
|
|
|
|
|
accmap = malloc(sizeof(accent_map), M_DEVBUF, M_NOWAIT);
|
|
|
|
|
fkeymap = malloc(sizeof(fkey_tab), M_DEVBUF, M_NOWAIT);
|
|
|
|
|
fkeymap_size = sizeof(fkey_tab)/sizeof(fkey_tab[0]);
|
|
|
|
|
if ((state == NULL) || (keymap == NULL) || (accmap == NULL)
|
|
|
|
|
|| (fkeymap == NULL)) {
|
|
|
|
|
if (state != NULL)
|
|
|
|
|
free(state, M_DEVBUF);
|
|
|
|
|
if (keymap != NULL)
|
|
|
|
|
free(keymap, M_DEVBUF);
|
|
|
|
|
if (accmap != NULL)
|
|
|
|
|
free(accmap, M_DEVBUF);
|
|
|
|
|
if (fkeymap != NULL)
|
|
|
|
|
free(fkeymap, M_DEVBUF);
|
|
|
|
|
free(kbd, M_DEVBUF);
|
|
|
|
|
return ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
} else if (KBD_IS_INITIALIZED(*kbdp) && KBD_IS_CONFIGURED(*kbdp)) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
kbd = *kbdp;
|
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
|
|
|
|
keymap = kbd->kb_keymap;
|
|
|
|
|
accmap = kbd->kb_accentmap;
|
|
|
|
|
fkeymap = kbd->kb_fkeytab;
|
|
|
|
|
fkeymap_size = kbd->kb_fkeytab_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!KBD_IS_PROBED(kbd)) {
|
|
|
|
|
kbd_init_struct(kbd, DRIVER_NAME, KB_OTHER, unit, flags, 0, 0);
|
1999-04-11 16:49:15 +00:00
|
|
|
|
bzero(state, sizeof(*state));
|
1999-03-22 19:55:30 +00:00
|
|
|
|
bcopy(&key_map, keymap, sizeof(key_map));
|
|
|
|
|
bcopy(&accent_map, accmap, sizeof(accent_map));
|
|
|
|
|
bcopy(fkey_tab, fkeymap,
|
|
|
|
|
imin(fkeymap_size*sizeof(fkeymap[0]), sizeof(fkey_tab)));
|
|
|
|
|
kbd_set_maps(kbd, keymap, accmap, fkeymap, fkeymap_size);
|
|
|
|
|
kbd->kb_data = (void *)state;
|
|
|
|
|
|
|
|
|
|
if (probe_keyboard(uaa, flags))
|
|
|
|
|
return ENXIO;
|
|
|
|
|
else
|
|
|
|
|
KBD_FOUND_DEVICE(kbd);
|
|
|
|
|
ukbd_clear_state(kbd);
|
|
|
|
|
state->ks_mode = K_XLATE;
|
|
|
|
|
state->ks_iface = uaa->iface;
|
|
|
|
|
state->ks_uaa = uaa;
|
|
|
|
|
state->ks_ifstate = 0;
|
|
|
|
|
callout_handle_init(&state->ks_timeout_handle);
|
2003-07-04 01:50:39 +00:00
|
|
|
|
/*
|
1999-03-22 19:55:30 +00:00
|
|
|
|
* FIXME: set the initial value for lock keys in ks_state
|
|
|
|
|
* according to the BIOS data?
|
|
|
|
|
*/
|
|
|
|
|
KBD_PROBE_DONE(kbd);
|
|
|
|
|
}
|
|
|
|
|
if (!KBD_IS_INITIALIZED(kbd) && !(flags & KB_CONF_PROBE_ONLY)) {
|
|
|
|
|
if (KBD_HAS_DEVICE(kbd)
|
|
|
|
|
&& init_keyboard((ukbd_state_t *)kbd->kb_data,
|
|
|
|
|
&kbd->kb_type, kbd->kb_flags))
|
|
|
|
|
return ENXIO;
|
|
|
|
|
ukbd_ioctl(kbd, KDSETLED, (caddr_t)&(state->ks_state));
|
|
|
|
|
KBD_INIT_DONE(kbd);
|
|
|
|
|
}
|
|
|
|
|
if (!KBD_IS_CONFIGURED(kbd)) {
|
|
|
|
|
if (kbd_register(kbd) < 0)
|
|
|
|
|
return ENXIO;
|
1999-10-07 18:53:08 +00:00
|
|
|
|
if (ukbd_enable_intr(kbd, TRUE, (usbd_intr_t *)data[1]) == 0)
|
1999-04-11 16:49:15 +00:00
|
|
|
|
ukbd_timeout((void *)kbd);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
KBD_CONFIG_DONE(kbd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_enable_intr(keyboard_t *kbd, int on, usbd_intr_t *func)
|
|
|
|
|
{
|
|
|
|
|
ukbd_state_t *state = (ukbd_state_t *)kbd->kb_data;
|
1999-11-17 22:33:51 +00:00
|
|
|
|
usbd_status err;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
|
|
if (on) {
|
|
|
|
|
/* Set up interrupt pipe. */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (state->ks_ifstate & INTRENABLED)
|
|
|
|
|
return EBUSY;
|
2003-07-04 01:50:39 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
state->ks_ifstate |= INTRENABLED;
|
2003-07-04 01:50:39 +00:00
|
|
|
|
err = usbd_open_pipe_intr(state->ks_iface, state->ks_ep_addr,
|
1998-11-26 23:13:13 +00:00
|
|
|
|
USBD_SHORT_XFER_OK,
|
1999-03-22 19:55:30 +00:00
|
|
|
|
&state->ks_intrpipe, kbd,
|
2003-07-04 01:50:39 +00:00
|
|
|
|
&state->ks_ndata,
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
|
sizeof(state->ks_ndata), func,
|
|
|
|
|
USBD_DEFAULT_INTERVAL);
|
1999-11-17 22:33:51 +00:00
|
|
|
|
if (err)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
return (EIO);
|
|
|
|
|
} else {
|
|
|
|
|
/* Disable interrupts. */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
usbd_abort_pipe(state->ks_intrpipe);
|
|
|
|
|
usbd_close_pipe(state->ks_intrpipe);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
state->ks_ifstate &= ~INTRENABLED;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* finish using this keyboard */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_term(keyboard_t *kbd)
|
|
|
|
|
{
|
|
|
|
|
ukbd_state_t *state;
|
1999-04-11 16:49:15 +00:00
|
|
|
|
int error;
|
|
|
|
|
int s;
|
|
|
|
|
|
|
|
|
|
s = splusb();
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
1999-04-11 16:49:15 +00:00
|
|
|
|
DPRINTF(("ukbd_term: ks_ifstate=0x%x\n", state->ks_ifstate));
|
|
|
|
|
|
|
|
|
|
untimeout(ukbd_timeout, (void *)kbd, state->ks_timeout_handle);
|
|
|
|
|
callout_handle_init(&state->ks_timeout_handle);
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (state->ks_ifstate & INTRENABLED)
|
1999-04-11 16:49:15 +00:00
|
|
|
|
ukbd_enable_intr(kbd, FALSE, NULL);
|
|
|
|
|
if (state->ks_ifstate & INTRENABLED) {
|
|
|
|
|
splx(s);
|
|
|
|
|
DPRINTF(("ukbd_term: INTRENABLED!\n"));
|
1999-03-22 19:55:30 +00:00
|
|
|
|
return ENXIO;
|
1999-04-11 16:49:15 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
1999-04-11 16:49:15 +00:00
|
|
|
|
error = kbd_unregister(kbd);
|
|
|
|
|
DPRINTF(("ukbd_term: kbd_unregister() %d\n", error));
|
|
|
|
|
if (error == 0) {
|
|
|
|
|
kbd->kb_flags = 0;
|
|
|
|
|
if (kbd != &default_kbd) {
|
|
|
|
|
free(kbd->kb_keymap, M_DEVBUF);
|
|
|
|
|
free(kbd->kb_accentmap, M_DEVBUF);
|
|
|
|
|
free(kbd->kb_fkeytab, M_DEVBUF);
|
|
|
|
|
free(state, M_DEVBUF);
|
|
|
|
|
free(kbd, M_DEVBUF);
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
1999-04-11 16:49:15 +00:00
|
|
|
|
splx(s);
|
|
|
|
|
return error;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* keyboard interrupt routine */
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static void
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_timeout(void *arg)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
{
|
1999-03-22 19:55:30 +00:00
|
|
|
|
keyboard_t *kbd;
|
|
|
|
|
ukbd_state_t *state;
|
|
|
|
|
int s;
|
|
|
|
|
|
|
|
|
|
kbd = (keyboard_t *)arg;
|
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
|
|
|
|
s = splusb();
|
|
|
|
|
(*kbdsw[kbd->kb_index]->intr)(kbd, (void *)USBD_NORMAL_COMPLETION);
|
|
|
|
|
state->ks_timeout_handle = timeout(ukbd_timeout, arg, hz/40);
|
|
|
|
|
splx(s);
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_interrupt(keyboard_t *kbd, void *arg)
|
|
|
|
|
{
|
|
|
|
|
usbd_status status = (usbd_status)arg;
|
2001-09-01 09:38:45 +00:00
|
|
|
|
ukbd_state_t *state;
|
|
|
|
|
struct ukbd_data *ud;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
struct timeval tv;
|
|
|
|
|
u_long now;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
int mod, omod;
|
|
|
|
|
int key, c;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
int i, j;
|
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
|
DPRINTFN(5, ("ukbd_intr: status=%d\n", status));
|
|
|
|
|
if (status == USBD_CANCELLED)
|
1999-03-22 19:55:30 +00:00
|
|
|
|
return 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
2001-09-01 09:38:45 +00:00
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
|
|
|
|
ud = &state->ks_ndata;
|
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
|
|
|
|
DPRINTF(("ukbd_intr: status=%d\n", status));
|
2001-09-02 09:26:14 +00:00
|
|
|
|
if (status == USBD_STALLED)
|
|
|
|
|
usbd_clear_endpoint_stall_async(state->ks_intrpipe);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
return 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ud->keycode[0] == KEY_ERROR)
|
1999-03-22 19:55:30 +00:00
|
|
|
|
return 0; /* ignore */
|
|
|
|
|
|
|
|
|
|
getmicrouptime(&tv);
|
|
|
|
|
now = (u_long)tv.tv_sec*1000 + (u_long)tv.tv_usec/1000;
|
|
|
|
|
|
2001-09-01 09:38:45 +00:00
|
|
|
|
#define ADDKEY1(c) \
|
|
|
|
|
if (state->ks_inputs < INPUTBUFSIZE) { \
|
|
|
|
|
state->ks_input[state->ks_inputtail] = (c); \
|
|
|
|
|
++state->ks_inputs; \
|
|
|
|
|
state->ks_inputtail = (state->ks_inputtail + 1)%INPUTBUFSIZE; \
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
|
mod = ud->modifiers;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
omod = state->ks_odata.modifiers;
|
|
|
|
|
if (mod != omod) {
|
1998-11-26 23:13:13 +00:00
|
|
|
|
for (i = 0; i < NMOD; i++)
|
2003-07-04 01:50:39 +00:00
|
|
|
|
if (( mod & ukbd_mods[i].mask) !=
|
1998-11-26 23:13:13 +00:00
|
|
|
|
(omod & ukbd_mods[i].mask))
|
2003-07-04 01:50:39 +00:00
|
|
|
|
ADDKEY1(ukbd_mods[i].key |
|
|
|
|
|
(mod & ukbd_mods[i].mask
|
1999-03-22 19:55:30 +00:00
|
|
|
|
? KEY_PRESS : KEY_RELEASE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check for released keys. */
|
|
|
|
|
for (i = 0; i < NKEYCODE; i++) {
|
|
|
|
|
key = state->ks_odata.keycode[i];
|
|
|
|
|
if (key == 0)
|
2004-02-23 15:36:40 +00:00
|
|
|
|
continue;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
for (j = 0; j < NKEYCODE; j++) {
|
|
|
|
|
if (ud->keycode[j] == 0)
|
2004-02-23 15:36:40 +00:00
|
|
|
|
continue;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (key == ud->keycode[j])
|
|
|
|
|
goto rfound;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ADDKEY1(key | KEY_RELEASE);
|
|
|
|
|
rfound:
|
|
|
|
|
;
|
|
|
|
|
}
|
2003-07-04 01:50:39 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* Check for pressed keys. */
|
|
|
|
|
for (i = 0; i < NKEYCODE; i++) {
|
|
|
|
|
key = ud->keycode[i];
|
|
|
|
|
if (key == 0)
|
2004-02-23 15:36:40 +00:00
|
|
|
|
continue;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
state->ks_ntime[i] = now + kbd->kb_delay1;
|
|
|
|
|
for (j = 0; j < NKEYCODE; j++) {
|
|
|
|
|
if (state->ks_odata.keycode[j] == 0)
|
2004-02-23 15:36:40 +00:00
|
|
|
|
continue;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (key == state->ks_odata.keycode[j]) {
|
|
|
|
|
state->ks_ntime[i] = state->ks_otime[j];
|
|
|
|
|
if (state->ks_otime[j] > now)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
goto pfound;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
state->ks_ntime[i] = now + kbd->kb_delay2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ADDKEY1(key | KEY_PRESS);
|
|
|
|
|
pfound:
|
|
|
|
|
;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
state->ks_odata = *ud;
|
|
|
|
|
bcopy(state->ks_ntime, state->ks_otime, sizeof(state->ks_ntime));
|
|
|
|
|
if (state->ks_inputs <= 0)
|
|
|
|
|
return 0;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
2002-07-31 14:34:36 +00:00
|
|
|
|
#ifdef USB_DEBUG
|
1999-03-22 19:55:30 +00:00
|
|
|
|
for (i = state->ks_inputhead, j = 0; j < state->ks_inputs; ++j,
|
|
|
|
|
i = (i + 1)%INPUTBUFSIZE) {
|
|
|
|
|
c = state->ks_input[i];
|
1999-10-07 18:53:08 +00:00
|
|
|
|
DPRINTF(("0x%x (%d) %s\n", c, c,
|
|
|
|
|
(c & KEY_RELEASE) ? "released":"pressed"));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (ud->modifiers)
|
1999-10-07 18:53:08 +00:00
|
|
|
|
DPRINTF(("mod:0x%04x ", ud->modifiers));
|
1999-03-22 19:55:30 +00:00
|
|
|
|
for (i = 0; i < NKEYCODE; i++) {
|
|
|
|
|
if (ud->keycode[i])
|
1999-10-07 18:53:08 +00:00
|
|
|
|
DPRINTF(("%d ", ud->keycode[i]));
|
1999-01-07 23:07:57 +00:00
|
|
|
|
}
|
1999-10-07 18:53:08 +00:00
|
|
|
|
DPRINTF(("\n"));
|
2002-07-31 14:34:36 +00:00
|
|
|
|
#endif /* USB_DEBUG */
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (state->ks_polling)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (KBD_IS_ACTIVE(kbd) && KBD_IS_BUSY(kbd)) {
|
|
|
|
|
/* let the callback function to process the input */
|
|
|
|
|
(*kbd->kb_callback.kc_func)(kbd, KBDIO_KEYINPUT,
|
|
|
|
|
kbd->kb_callback.kc_arg);
|
|
|
|
|
} else {
|
|
|
|
|
/* read and discard the input; no one is waiting for it */
|
|
|
|
|
do {
|
|
|
|
|
c = ukbd_read_char(kbd, FALSE);
|
|
|
|
|
} while (c != NOKEY);
|
1999-01-07 23:07:57 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_getc(ukbd_state_t *state)
|
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
int s;
|
|
|
|
|
|
|
|
|
|
if (state->ks_polling) {
|
|
|
|
|
DPRINTFN(1,("ukbd_getc: polling\n"));
|
1999-10-07 18:53:08 +00:00
|
|
|
|
s = splusb();
|
1999-03-22 19:55:30 +00:00
|
|
|
|
while (state->ks_inputs <= 0)
|
|
|
|
|
usbd_dopoll(state->ks_iface);
|
1999-10-07 18:53:08 +00:00
|
|
|
|
splx(s);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
s = splusb();
|
|
|
|
|
if (state->ks_inputs <= 0) {
|
|
|
|
|
c = -1;
|
|
|
|
|
} else {
|
|
|
|
|
c = state->ks_input[state->ks_inputhead];
|
|
|
|
|
--state->ks_inputs;
|
|
|
|
|
state->ks_inputhead = (state->ks_inputhead + 1)%INPUTBUFSIZE;
|
|
|
|
|
}
|
|
|
|
|
splx(s);
|
|
|
|
|
return c;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* test the interface to the device */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_test_if(keyboard_t *kbd)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 01:50:39 +00:00
|
|
|
|
/*
|
1999-03-22 19:55:30 +00:00
|
|
|
|
* Enable the access to the device; until this function is called,
|
|
|
|
|
* the client cannot read from the keyboard.
|
|
|
|
|
*/
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-04-11 16:49:15 +00:00
|
|
|
|
ukbd_enable(keyboard_t *kbd)
|
1999-03-22 19:55:30 +00:00
|
|
|
|
{
|
|
|
|
|
int s;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
s = splusb();
|
|
|
|
|
KBD_ACTIVATE(kbd);
|
|
|
|
|
splx(s);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* disallow the access to the device */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_disable(keyboard_t *kbd)
|
1999-01-07 23:07:57 +00:00
|
|
|
|
{
|
1999-03-22 19:55:30 +00:00
|
|
|
|
int s;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
s = splusb();
|
|
|
|
|
KBD_DEACTIVATE(kbd);
|
|
|
|
|
splx(s);
|
|
|
|
|
return 0;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
/* read one byte from the keyboard if it's allowed */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_read(keyboard_t *kbd, int wait)
|
|
|
|
|
{
|
|
|
|
|
ukbd_state_t *state;
|
|
|
|
|
int usbcode;
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
int keycode;
|
|
|
|
|
int scancode;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
if (state->ks_buffered_char[0]) {
|
|
|
|
|
scancode = state->ks_buffered_char[0];
|
|
|
|
|
if (scancode & SCAN_PREFIX) {
|
|
|
|
|
state->ks_buffered_char[0] = scancode & ~SCAN_PREFIX;
|
|
|
|
|
return ((scancode & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
|
|
|
|
|
} else {
|
|
|
|
|
state->ks_buffered_char[0] = state->ks_buffered_char[1];
|
|
|
|
|
state->ks_buffered_char[1] = 0;
|
|
|
|
|
return scancode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* UKBD_EMULATE_ATSCANCODE */
|
|
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
|
usbcode = ukbd_getc(state);
|
|
|
|
|
if (!KBD_IS_ACTIVE(kbd) || (usbcode == -1))
|
|
|
|
|
return -1;
|
2000-01-11 13:39:05 +00:00
|
|
|
|
++kbd->kb_count;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
keycode = ukbd_trtab[KEY_INDEX(usbcode)];
|
|
|
|
|
if (keycode == NN)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
scancode = keycode2scancode(keycode, state->ks_ndata.modifiers,
|
|
|
|
|
usbcode & KEY_RELEASE);
|
|
|
|
|
if (scancode & SCAN_PREFIX) {
|
|
|
|
|
if (scancode & SCAN_PREFIX_CTL) {
|
2003-07-04 01:50:39 +00:00
|
|
|
|
state->ks_buffered_char[0] =
|
1999-03-22 19:55:30 +00:00
|
|
|
|
0x1d | (scancode & SCAN_RELEASE); /* Ctrl */
|
|
|
|
|
state->ks_buffered_char[1] = scancode & ~SCAN_PREFIX;
|
|
|
|
|
} else if (scancode & SCAN_PREFIX_SHIFT) {
|
2003-07-04 01:50:39 +00:00
|
|
|
|
state->ks_buffered_char[0] =
|
1999-03-22 19:55:30 +00:00
|
|
|
|
0x2a | (scancode & SCAN_RELEASE); /* Shift */
|
2003-07-04 01:50:39 +00:00
|
|
|
|
state->ks_buffered_char[1] =
|
1999-03-22 19:55:30 +00:00
|
|
|
|
scancode & ~SCAN_PREFIX_SHIFT;
|
|
|
|
|
} else {
|
|
|
|
|
state->ks_buffered_char[0] = scancode & ~SCAN_PREFIX;
|
|
|
|
|
state->ks_buffered_char[1] = 0;
|
|
|
|
|
}
|
|
|
|
|
return ((scancode & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
|
|
|
|
|
}
|
|
|
|
|
return scancode;
|
|
|
|
|
#else /* !UKBD_EMULATE_ATSCANCODE */
|
|
|
|
|
return usbcode;
|
|
|
|
|
#endif /* UKBD_EMULATE_ATSCANCODE */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check if data is waiting */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_check(keyboard_t *kbd)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
{
|
1999-03-22 19:55:30 +00:00
|
|
|
|
if (!KBD_IS_ACTIVE(kbd))
|
|
|
|
|
return FALSE;
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
if (((ukbd_state_t *)kbd->kb_data)->ks_buffered_char[0])
|
|
|
|
|
return TRUE;
|
|
|
|
|
#endif
|
|
|
|
|
if (((ukbd_state_t *)kbd->kb_data)->ks_inputs > 0)
|
|
|
|
|
return TRUE;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* read char from the keyboard */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static u_int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_read_char(keyboard_t *kbd, int wait)
|
|
|
|
|
{
|
|
|
|
|
ukbd_state_t *state;
|
|
|
|
|
u_int action;
|
|
|
|
|
int usbcode;
|
|
|
|
|
int keycode;
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
int scancode;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
#endif
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
|
|
|
|
next_code:
|
|
|
|
|
/* do we have a composed char to return? */
|
|
|
|
|
if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0)) {
|
|
|
|
|
action = state->ks_composed_char;
|
|
|
|
|
state->ks_composed_char = 0;
|
|
|
|
|
if (action > UCHAR_MAX)
|
|
|
|
|
return ERRKEY;
|
|
|
|
|
return action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
/* do we have a pending raw scan code? */
|
|
|
|
|
if (state->ks_mode == K_RAW) {
|
|
|
|
|
if (state->ks_buffered_char[0]) {
|
|
|
|
|
scancode = state->ks_buffered_char[0];
|
|
|
|
|
if (scancode & SCAN_PREFIX) {
|
|
|
|
|
state->ks_buffered_char[0] =
|
|
|
|
|
scancode & ~SCAN_PREFIX;
|
|
|
|
|
return ((scancode & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
|
|
|
|
|
} else {
|
|
|
|
|
state->ks_buffered_char[0] =
|
|
|
|
|
state->ks_buffered_char[1];
|
|
|
|
|
state->ks_buffered_char[1] = 0;
|
|
|
|
|
return scancode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* UKBD_EMULATE_ATSCANCODE */
|
|
|
|
|
|
|
|
|
|
/* see if there is something in the keyboard port */
|
|
|
|
|
/* XXX */
|
|
|
|
|
usbcode = ukbd_getc(state);
|
|
|
|
|
if (usbcode == -1)
|
|
|
|
|
return NOKEY;
|
2000-01-11 13:39:05 +00:00
|
|
|
|
++kbd->kb_count;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
/* USB key index -> key code -> AT scan code */
|
|
|
|
|
keycode = ukbd_trtab[KEY_INDEX(usbcode)];
|
|
|
|
|
if (keycode == NN)
|
|
|
|
|
return NOKEY;
|
|
|
|
|
|
|
|
|
|
/* return an AT scan code for the K_RAW mode */
|
|
|
|
|
if (state->ks_mode == K_RAW) {
|
|
|
|
|
scancode = keycode2scancode(keycode, state->ks_ndata.modifiers,
|
|
|
|
|
usbcode & KEY_RELEASE);
|
|
|
|
|
if (scancode & SCAN_PREFIX) {
|
|
|
|
|
if (scancode & SCAN_PREFIX_CTL) {
|
2003-07-04 01:50:39 +00:00
|
|
|
|
state->ks_buffered_char[0] =
|
1999-03-22 19:55:30 +00:00
|
|
|
|
0x1d | (scancode & SCAN_RELEASE);
|
|
|
|
|
state->ks_buffered_char[1] =
|
|
|
|
|
scancode & ~SCAN_PREFIX;
|
|
|
|
|
} else if (scancode & SCAN_PREFIX_SHIFT) {
|
2003-07-04 01:50:39 +00:00
|
|
|
|
state->ks_buffered_char[0] =
|
1999-03-22 19:55:30 +00:00
|
|
|
|
0x2a | (scancode & SCAN_RELEASE);
|
|
|
|
|
state->ks_buffered_char[1] =
|
|
|
|
|
scancode & ~SCAN_PREFIX_SHIFT;
|
|
|
|
|
} else {
|
|
|
|
|
state->ks_buffered_char[0] =
|
|
|
|
|
scancode & ~SCAN_PREFIX;
|
|
|
|
|
state->ks_buffered_char[1] = 0;
|
|
|
|
|
}
|
|
|
|
|
return ((scancode & SCAN_PREFIX_E0) ? 0xe0 : 0xe1);
|
|
|
|
|
}
|
|
|
|
|
return scancode;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
1999-03-22 19:55:30 +00:00
|
|
|
|
#else /* !UKBD_EMULATE_ATSCANCODE */
|
|
|
|
|
/* return the byte as is for the K_RAW mode */
|
|
|
|
|
if (state->ks_mode == K_RAW)
|
|
|
|
|
return usbcode;
|
|
|
|
|
|
|
|
|
|
/* USB key index -> key code */
|
|
|
|
|
keycode = ukbd_trtab[KEY_INDEX(usbcode)];
|
|
|
|
|
if (keycode == NN)
|
|
|
|
|
return NOKEY;
|
|
|
|
|
#endif /* UKBD_EMULATE_ATSCANCODE */
|
|
|
|
|
|
|
|
|
|
switch (keycode) {
|
|
|
|
|
case 0x38: /* left alt (compose key) */
|
|
|
|
|
if (usbcode & KEY_RELEASE) {
|
|
|
|
|
if (state->ks_flags & COMPOSE) {
|
|
|
|
|
state->ks_flags &= ~COMPOSE;
|
|
|
|
|
if (state->ks_composed_char > UCHAR_MAX)
|
|
|
|
|
state->ks_composed_char = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!(state->ks_flags & COMPOSE)) {
|
|
|
|
|
state->ks_flags |= COMPOSE;
|
|
|
|
|
state->ks_composed_char = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
/* XXX: I don't like these... */
|
|
|
|
|
case 0x5c: /* print screen */
|
|
|
|
|
if (state->ks_flags & ALTS)
|
|
|
|
|
keycode = 0x54; /* sysrq */
|
|
|
|
|
break;
|
|
|
|
|
case 0x68: /* pause/break */
|
|
|
|
|
if (state->ks_flags & CTLS)
|
|
|
|
|
keycode = 0x6c; /* break */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return the key code in the K_CODE mode */
|
|
|
|
|
if (usbcode & KEY_RELEASE)
|
|
|
|
|
keycode |= SCAN_RELEASE;
|
|
|
|
|
if (state->ks_mode == K_CODE)
|
|
|
|
|
return keycode;
|
|
|
|
|
|
|
|
|
|
/* compose a character code */
|
|
|
|
|
if (state->ks_flags & COMPOSE) {
|
|
|
|
|
switch (keycode) {
|
|
|
|
|
/* key pressed, process it */
|
|
|
|
|
case 0x47: case 0x48: case 0x49: /* keypad 7,8,9 */
|
|
|
|
|
state->ks_composed_char *= 10;
|
|
|
|
|
state->ks_composed_char += keycode - 0x40;
|
|
|
|
|
if (state->ks_composed_char > UCHAR_MAX)
|
|
|
|
|
return ERRKEY;
|
|
|
|
|
goto next_code;
|
|
|
|
|
case 0x4B: case 0x4C: case 0x4D: /* keypad 4,5,6 */
|
|
|
|
|
state->ks_composed_char *= 10;
|
|
|
|
|
state->ks_composed_char += keycode - 0x47;
|
|
|
|
|
if (state->ks_composed_char > UCHAR_MAX)
|
|
|
|
|
return ERRKEY;
|
|
|
|
|
goto next_code;
|
|
|
|
|
case 0x4F: case 0x50: case 0x51: /* keypad 1,2,3 */
|
|
|
|
|
state->ks_composed_char *= 10;
|
|
|
|
|
state->ks_composed_char += keycode - 0x4E;
|
|
|
|
|
if (state->ks_composed_char > UCHAR_MAX)
|
|
|
|
|
return ERRKEY;
|
|
|
|
|
goto next_code;
|
|
|
|
|
case 0x52: /* keypad 0 */
|
|
|
|
|
state->ks_composed_char *= 10;
|
|
|
|
|
if (state->ks_composed_char > UCHAR_MAX)
|
|
|
|
|
return ERRKEY;
|
|
|
|
|
goto next_code;
|
|
|
|
|
|
|
|
|
|
/* key released, no interest here */
|
|
|
|
|
case SCAN_RELEASE | 0x47:
|
|
|
|
|
case SCAN_RELEASE | 0x48:
|
|
|
|
|
case SCAN_RELEASE | 0x49: /* keypad 7,8,9 */
|
|
|
|
|
case SCAN_RELEASE | 0x4B:
|
|
|
|
|
case SCAN_RELEASE | 0x4C:
|
|
|
|
|
case SCAN_RELEASE | 0x4D: /* keypad 4,5,6 */
|
|
|
|
|
case SCAN_RELEASE | 0x4F:
|
|
|
|
|
case SCAN_RELEASE | 0x50:
|
|
|
|
|
case SCAN_RELEASE | 0x51: /* keypad 1,2,3 */
|
|
|
|
|
case SCAN_RELEASE | 0x52: /* keypad 0 */
|
|
|
|
|
goto next_code;
|
|
|
|
|
|
|
|
|
|
case 0x38: /* left alt key */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (state->ks_composed_char > 0) {
|
|
|
|
|
state->ks_flags &= ~COMPOSE;
|
|
|
|
|
state->ks_composed_char = 0;
|
|
|
|
|
return ERRKEY;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* keycode to key action */
|
|
|
|
|
action = genkbd_keyaction(kbd, SCAN_CHAR(keycode),
|
|
|
|
|
keycode & SCAN_RELEASE, &state->ks_state,
|
|
|
|
|
&state->ks_accents);
|
|
|
|
|
if (action == NOKEY)
|
|
|
|
|
goto next_code;
|
|
|
|
|
else
|
|
|
|
|
return action;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* check if char is waiting */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_check_char(keyboard_t *kbd)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
{
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_state_t *state;
|
|
|
|
|
|
|
|
|
|
if (!KBD_IS_ACTIVE(kbd))
|
|
|
|
|
return FALSE;
|
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
|
|
|
|
if (!(state->ks_flags & COMPOSE) && (state->ks_composed_char > 0))
|
|
|
|
|
return TRUE;
|
|
|
|
|
if (state->ks_inputs > 0)
|
|
|
|
|
return TRUE;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* some useful control functions */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
|
|
|
|
|
{
|
|
|
|
|
/* trasnlate LED_XXX bits into the device specific bits */
|
|
|
|
|
static u_char ledmap[8] = {
|
|
|
|
|
0, 2, 1, 3, 4, 6, 5, 7,
|
|
|
|
|
};
|
|
|
|
|
ukbd_state_t *state = kbd->kb_data;
|
|
|
|
|
int s;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
|
|
case KDGKBMODE: /* get keyboard mode */
|
|
|
|
|
*(int *)arg = state->ks_mode;
|
|
|
|
|
break;
|
|
|
|
|
case KDSKBMODE: /* set keyboard mode */
|
|
|
|
|
switch (*(int *)arg) {
|
|
|
|
|
case K_XLATE:
|
|
|
|
|
if (state->ks_mode != K_XLATE) {
|
|
|
|
|
/* make lock key state and LED state match */
|
|
|
|
|
state->ks_state &= ~LOCK_MASK;
|
|
|
|
|
state->ks_state |= KBD_LED_VAL(kbd);
|
|
|
|
|
}
|
2002-08-25 13:23:09 +00:00
|
|
|
|
/* FALLTHROUGH */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
case K_RAW:
|
|
|
|
|
case K_CODE:
|
|
|
|
|
if (state->ks_mode != *(int *)arg) {
|
|
|
|
|
ukbd_clear_state(kbd);
|
|
|
|
|
state->ks_mode = *(int *)arg;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
splx(s);
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case KDGETLED: /* get keyboard LED */
|
|
|
|
|
*(int *)arg = KBD_LED_VAL(kbd);
|
|
|
|
|
break;
|
|
|
|
|
case KDSETLED: /* set keyboard LED */
|
|
|
|
|
/* NOTE: lock key state in ks_state won't be changed */
|
|
|
|
|
if (*(int *)arg & ~LOCK_MASK) {
|
|
|
|
|
splx(s);
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
i = *(int *)arg;
|
|
|
|
|
/* replace CAPS LED with ALTGR LED for ALTGR keyboards */
|
|
|
|
|
if (kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
|
|
|
|
|
if (i & ALKED)
|
|
|
|
|
i |= CLKED;
|
|
|
|
|
else
|
|
|
|
|
i &= ~CLKED;
|
|
|
|
|
}
|
|
|
|
|
if (KBD_HAS_DEVICE(kbd)) {
|
|
|
|
|
set_leds(state, ledmap[i & LED_MASK]);
|
|
|
|
|
/* XXX: error check? */
|
|
|
|
|
}
|
|
|
|
|
KBD_LED_VAL(kbd) = *(int *)arg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case KDGKBSTATE: /* get lock key state */
|
|
|
|
|
*(int *)arg = state->ks_state & LOCK_MASK;
|
|
|
|
|
break;
|
|
|
|
|
case KDSKBSTATE: /* set lock key state */
|
|
|
|
|
if (*(int *)arg & ~LOCK_MASK) {
|
|
|
|
|
splx(s);
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
state->ks_state &= ~LOCK_MASK;
|
|
|
|
|
state->ks_state |= *(int *)arg;
|
|
|
|
|
splx(s);
|
|
|
|
|
/* set LEDs and quit */
|
|
|
|
|
return ukbd_ioctl(kbd, KDSETLED, arg);
|
|
|
|
|
|
|
|
|
|
case KDSETREPEAT: /* set keyboard repeat rate (new interface) */
|
|
|
|
|
splx(s);
|
|
|
|
|
if (!KBD_HAS_DEVICE(kbd))
|
|
|
|
|
return 0;
|
|
|
|
|
if (((int *)arg)[1] < 0)
|
|
|
|
|
return EINVAL;
|
|
|
|
|
if (((int *)arg)[0] < 0)
|
|
|
|
|
return EINVAL;
|
|
|
|
|
else if (((int *)arg)[0] == 0) /* fastest possible value */
|
|
|
|
|
kbd->kb_delay1 = 200;
|
|
|
|
|
else
|
|
|
|
|
kbd->kb_delay1 = ((int *)arg)[0];
|
|
|
|
|
kbd->kb_delay2 = ((int *)arg)[1];
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
case KDSETRAD: /* set keyboard repeat rate (old interface) */
|
|
|
|
|
splx(s);
|
|
|
|
|
return set_typematic(kbd, *(int *)arg);
|
|
|
|
|
|
|
|
|
|
case PIO_KEYMAP: /* set keyboard translation table */
|
|
|
|
|
case PIO_KEYMAPENT: /* set keyboard translation table entry */
|
|
|
|
|
case PIO_DEADKEYMAP: /* set accent key translation table */
|
|
|
|
|
state->ks_accents = 0;
|
2002-08-25 13:23:09 +00:00
|
|
|
|
/* FALLTHROUGH */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
default:
|
|
|
|
|
splx(s);
|
|
|
|
|
return genkbd_commonioctl(kbd, cmd, arg);
|
1999-12-13 10:36:36 +00:00
|
|
|
|
|
2002-07-31 14:34:36 +00:00
|
|
|
|
#ifdef USB_DEBUG
|
1999-12-13 10:36:36 +00:00
|
|
|
|
case USB_SETDEBUG:
|
|
|
|
|
ukbddebug = *(int *)arg;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
1999-03-22 19:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
return 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* lock the access to the keyboard */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_lock(keyboard_t *kbd, int lock)
|
|
|
|
|
{
|
|
|
|
|
/* XXX ? */
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* clear the internal state of the keyboard */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static void
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_clear_state(keyboard_t *kbd)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
{
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_state_t *state;
|
|
|
|
|
|
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
|
|
|
|
state->ks_flags = 0;
|
|
|
|
|
state->ks_polling = 0;
|
|
|
|
|
state->ks_state &= LOCK_MASK; /* preserve locking key state */
|
|
|
|
|
state->ks_accents = 0;
|
|
|
|
|
state->ks_composed_char = 0;
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
|
|
|
|
state->ks_buffered_char[0] = 0;
|
|
|
|
|
state->ks_buffered_char[1] = 0;
|
|
|
|
|
#endif
|
|
|
|
|
bzero(&state->ks_ndata, sizeof(state->ks_ndata));
|
|
|
|
|
bzero(&state->ks_odata, sizeof(state->ks_odata));
|
|
|
|
|
bzero(&state->ks_ntime, sizeof(state->ks_ntime));
|
|
|
|
|
bzero(&state->ks_otime, sizeof(state->ks_otime));
|
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* save the internal state */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_get_state(keyboard_t *kbd, void *buf, size_t len)
|
|
|
|
|
{
|
|
|
|
|
if (len == 0)
|
|
|
|
|
return sizeof(ukbd_state_t);
|
|
|
|
|
if (len < sizeof(ukbd_state_t))
|
|
|
|
|
return -1;
|
|
|
|
|
bcopy(kbd->kb_data, buf, sizeof(ukbd_state_t));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* set the internal state */
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_set_state(keyboard_t *kbd, void *buf, size_t len)
|
|
|
|
|
{
|
|
|
|
|
if (len < sizeof(ukbd_state_t))
|
|
|
|
|
return ENOMEM;
|
|
|
|
|
bcopy(buf, kbd->kb_data, sizeof(ukbd_state_t));
|
|
|
|
|
return 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_poll(keyboard_t *kbd, int on)
|
1999-01-07 23:07:57 +00:00
|
|
|
|
{
|
1999-03-22 19:55:30 +00:00
|
|
|
|
ukbd_state_t *state;
|
2002-04-07 13:16:18 +00:00
|
|
|
|
usbd_device_handle dev;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
int s;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
state = (ukbd_state_t *)kbd->kb_data;
|
2002-04-07 13:16:18 +00:00
|
|
|
|
usbd_interface2device_handle(state->ks_iface, &dev);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
|
if (on) {
|
|
|
|
|
if (state->ks_polling == 0)
|
2002-04-07 13:16:18 +00:00
|
|
|
|
usbd_set_polling(dev, on);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
++state->ks_polling;
|
|
|
|
|
} else {
|
|
|
|
|
--state->ks_polling;
|
|
|
|
|
if (state->ks_polling == 0)
|
2002-04-07 13:16:18 +00:00
|
|
|
|
usbd_set_polling(dev, on);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
splx(s);
|
|
|
|
|
return 0;
|
1999-01-07 23:07:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
/* local functions */
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
probe_keyboard(struct usb_attach_arg *uaa, int flags)
|
|
|
|
|
{
|
|
|
|
|
usb_interface_descriptor_t *id;
|
2003-07-04 01:50:39 +00:00
|
|
|
|
|
1999-05-03 23:16:05 +00:00
|
|
|
|
if (!uaa->iface) /* we attach to ifaces only */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
return EINVAL;
|
1999-04-11 20:50:33 +00:00
|
|
|
|
|
|
|
|
|
/* Check that this is a keyboard that speaks the boot protocol. */
|
1999-03-22 19:55:30 +00:00
|
|
|
|
id = usbd_get_interface_descriptor(uaa->iface);
|
1999-04-11 20:50:33 +00:00
|
|
|
|
if (id
|
2002-01-02 18:28:45 +00:00
|
|
|
|
&& id->bInterfaceClass == UICLASS_HID
|
|
|
|
|
&& id->bInterfaceSubClass == UISUBCLASS_BOOT
|
1999-04-11 20:50:33 +00:00
|
|
|
|
&& id->bInterfaceProtocol == UPROTO_BOOT_KEYBOARD)
|
1999-05-03 23:16:05 +00:00
|
|
|
|
return 0; /* found it */
|
|
|
|
|
|
1999-04-11 20:50:33 +00:00
|
|
|
|
return EINVAL;
|
1999-03-22 19:55:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
init_keyboard(ukbd_state_t *state, int *type, int flags)
|
|
|
|
|
{
|
|
|
|
|
usb_endpoint_descriptor_t *ed;
|
1999-11-17 22:33:51 +00:00
|
|
|
|
usbd_status err;
|
2003-07-04 01:50:39 +00:00
|
|
|
|
|
1999-03-22 19:55:30 +00:00
|
|
|
|
*type = KB_OTHER;
|
|
|
|
|
|
|
|
|
|
state->ks_ifstate |= DISCONNECTED;
|
|
|
|
|
|
|
|
|
|
ed = usbd_interface2endpoint_descriptor(state->ks_iface, 0);
|
|
|
|
|
if (!ed) {
|
|
|
|
|
printf("ukbd: could not read endpoint descriptor\n");
|
|
|
|
|
return EIO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DPRINTFN(10,("ukbd:init_keyboard: \
|
|
|
|
|
bLength=%d bDescriptorType=%d bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d bInterval=%d\n",
|
1999-10-07 18:53:08 +00:00
|
|
|
|
ed->bLength, ed->bDescriptorType,
|
|
|
|
|
UE_GET_ADDR(ed->bEndpointAddress),
|
|
|
|
|
UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN ? "in":"out",
|
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes),
|
1999-03-22 19:55:30 +00:00
|
|
|
|
UGETW(ed->wMaxPacketSize), ed->bInterval));
|
|
|
|
|
|
1999-10-07 18:53:08 +00:00
|
|
|
|
if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
|
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes) != UE_INTERRUPT) {
|
1999-03-22 19:55:30 +00:00
|
|
|
|
printf("ukbd: unexpected endpoint\n");
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((usbd_get_quirks(state->ks_uaa->device)->uq_flags & UQ_NO_SET_PROTO) == 0) {
|
1999-11-17 22:33:51 +00:00
|
|
|
|
err = usbd_set_protocol(state->ks_iface, 0);
|
1999-03-22 19:55:30 +00:00
|
|
|
|
DPRINTFN(5, ("ukbd:init_keyboard: protocol set\n"));
|
1999-11-17 22:33:51 +00:00
|
|
|
|
if (err) {
|
1999-03-22 19:55:30 +00:00
|
|
|
|
printf("ukbd: set protocol failed\n");
|
|
|
|
|
return EIO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Ignore if SETIDLE fails since it is not crucial. */
|
|
|
|
|
usbd_set_idle(state->ks_iface, 0, 0);
|
|
|
|
|
|
|
|
|
|
state->ks_ep_addr = ed->bEndpointAddress;
|
|
|
|
|
state->ks_ifstate &= ~DISCONNECTED;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static void
|
1999-03-22 19:55:30 +00:00
|
|
|
|
set_leds(ukbd_state_t *state, int leds)
|
|
|
|
|
{
|
|
|
|
|
u_int8_t res = leds;
|
|
|
|
|
|
|
|
|
|
DPRINTF(("ukbd:set_leds: state=%p leds=%d\n", state, leds));
|
|
|
|
|
|
|
|
|
|
usbd_set_report_async(state->ks_iface, UHID_OUTPUT_REPORT, 0, &res, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
set_typematic(keyboard_t *kbd, int code)
|
|
|
|
|
{
|
|
|
|
|
static int delays[] = { 250, 500, 750, 1000 };
|
|
|
|
|
static int rates[] = { 34, 38, 42, 46, 50, 55, 59, 63,
|
|
|
|
|
68, 76, 84, 92, 100, 110, 118, 126,
|
|
|
|
|
136, 152, 168, 184, 200, 220, 236, 252,
|
|
|
|
|
272, 304, 336, 368, 400, 440, 472, 504 };
|
|
|
|
|
|
|
|
|
|
if (code & ~0x7f)
|
|
|
|
|
return EINVAL;
|
|
|
|
|
kbd->kb_delay1 = delays[(code >> 5) & 3];
|
|
|
|
|
kbd->kb_delay2 = rates[code & 0x1f];
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef UKBD_EMULATE_ATSCANCODE
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-03-22 19:55:30 +00:00
|
|
|
|
keycode2scancode(int keycode, int shift, int up)
|
|
|
|
|
{
|
|
|
|
|
static int scan[] = {
|
2003-07-04 01:50:39 +00:00
|
|
|
|
0x1c, 0x1d, 0x35,
|
1999-03-22 19:55:30 +00:00
|
|
|
|
0x37 | SCAN_PREFIX_SHIFT, /* PrintScreen */
|
2003-07-04 01:50:39 +00:00
|
|
|
|
0x38, 0x47, 0x48, 0x49, 0x4b, 0x4d, 0x4f,
|
|
|
|
|
0x50, 0x51, 0x52, 0x53,
|
1999-03-22 19:55:30 +00:00
|
|
|
|
0x46, /* XXX Pause/Break */
|
|
|
|
|
0x5b, 0x5c, 0x5d,
|
2004-01-03 15:01:04 +00:00
|
|
|
|
/* SUN TYPE 6 USB KEYBOARD */
|
|
|
|
|
0x68, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,
|
|
|
|
|
0x64, 0x65, 0x66, 0x67, 0x25, 0x1f, 0x1e,
|
|
|
|
|
0x20,
|
1999-03-22 19:55:30 +00:00
|
|
|
|
};
|
|
|
|
|
int scancode;
|
|
|
|
|
|
|
|
|
|
scancode = keycode;
|
|
|
|
|
if ((keycode >= 89) && (keycode < 89 + sizeof(scan)/sizeof(scan[0])))
|
|
|
|
|
scancode = scan[keycode - 89] | SCAN_PREFIX_E0;
|
|
|
|
|
/* Pause/Break */
|
|
|
|
|
if ((keycode == 104) && !(shift & (MOD_CONTROL_L | MOD_CONTROL_R)))
|
|
|
|
|
scancode = 0x45 | SCAN_PREFIX_E1 | SCAN_PREFIX_CTL;
|
|
|
|
|
if (shift & (MOD_SHIFT_L | MOD_SHIFT_R))
|
|
|
|
|
scancode &= ~SCAN_PREFIX_SHIFT;
|
|
|
|
|
return (scancode | (up ? SCAN_RELEASE : SCAN_PRESS));
|
|
|
|
|
}
|
|
|
|
|
#endif /* UKBD_EMULATE_ATSCANCODE */
|
1999-12-13 10:36:36 +00:00
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
|
Static int
|
1999-12-13 10:36:36 +00:00
|
|
|
|
ukbd_driver_load(module_t mod, int what, void *arg)
|
|
|
|
|
{
|
|
|
|
|
switch (what) {
|
|
|
|
|
case MOD_LOAD:
|
|
|
|
|
kbd_add_driver(&ukbd_kbd_driver);
|
|
|
|
|
break;
|
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
|
kbd_delete_driver(&ukbd_kbd_driver);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return usbd_driver_load(mod, what, 0);
|
|
|
|
|
}
|