1998-12-30 22:25:27 +03:00
|
|
|
/* $NetBSD: ukbd.c,v 1.20 1998/12/30 19:25:27 augustss Exp $ */
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-11-26 01:32:04 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Lennart Augustsson (augustss@carlstedt.se) at
|
|
|
|
* Carlstedt Research & Technology.
|
1998-07-12 23:51:55 +04: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.
|
|
|
|
*/
|
|
|
|
|
1998-12-28 15:52:38 +03:00
|
|
|
/*
|
|
|
|
* Information about USB keyboard can be found in the USB HID spec.
|
|
|
|
*/
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/ioctl.h>
|
1998-12-26 15:53:00 +03:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
1998-07-25 19:36:30 +04:00
|
|
|
#include <dev/usb/usbhid.h>
|
1998-07-12 23:51:55 +04:00
|
|
|
#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>
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-07-25 19:36:30 +04:00
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wskbdvar.h>
|
|
|
|
#include <dev/wscons/wsksymdef.h>
|
|
|
|
#include <dev/wscons/wsksymvar.h>
|
|
|
|
#include <dev/wscons/wskbdmap_mfii.h>
|
|
|
|
|
|
|
|
#include "opt_pckbd_layout.h"
|
|
|
|
#include "opt_wsdisplay_compat.h"
|
1998-12-26 15:53:00 +03:00
|
|
|
#endif
|
1998-07-25 19:36:30 +04:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
#ifdef USB_DEBUG
|
|
|
|
#define DPRINTF(x) if (ukbddebug) printf x
|
|
|
|
#define DPRINTFN(n,x) if (ukbddebug>(n)) printf x
|
|
|
|
int ukbddebug = 0;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define UPROTO_BOOT_KEYBOARD 1
|
|
|
|
|
|
|
|
#define NKEYCODE 6
|
|
|
|
|
1998-07-25 19:36:30 +04:00
|
|
|
#define NUM_LOCK 0x01
|
|
|
|
#define CAPS_LOCK 0x02
|
|
|
|
#define SCROLL_LOCK 0x04
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
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];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PRESS 0
|
1998-08-01 21:46:22 +04:00
|
|
|
#define RELEASE 0x100
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
#define NMOD 6
|
|
|
|
static struct {
|
|
|
|
int mask, key;
|
|
|
|
} ukbd_mods[NMOD] = {
|
|
|
|
{ MOD_CONTROL_L, 29 },
|
|
|
|
{ MOD_CONTROL_R, 58 },
|
|
|
|
{ MOD_SHIFT_L, 42 },
|
|
|
|
{ MOD_SHIFT_R, 54 },
|
|
|
|
{ MOD_ALT_L, 56 },
|
1998-08-01 21:46:22 +04:00
|
|
|
{ MOD_ALT_R, 184 },
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
1998-08-01 21:46:22 +04:00
|
|
|
#define NN 0 /* no translation */
|
1998-12-30 21:03:37 +03:00
|
|
|
/*
|
|
|
|
* Translate USB keycodes to US keyboard AT scancodes.
|
|
|
|
* Scancodes >= 128 represent EXTENDED keycodes.
|
|
|
|
*/
|
1998-08-01 21:46:22 +04:00
|
|
|
static u_int8_t ukbd_trtab[256] = {
|
|
|
|
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, NN, 39, 40, 41, 51, 52, /* 30 - 37 */
|
|
|
|
53, 58, 59, 60, 61, 62, 63, 64, /* 38 - 3F */
|
|
|
|
65, 66, 67, 68, 87, 88, 170, 70, /* 40 - 47 */
|
|
|
|
127, 210, 199, 201, 211, 207, 209, 205, /* 48 - 4F */
|
|
|
|
203, 208, 200, 69, 181, 55, 74, 78, /* 50 - 57 */
|
|
|
|
156, 79, 80, 81, 75, 76, 77, 71, /* 58 - 5F */
|
|
|
|
72, 73, 82, 83, NN, NN, NN, NN, /* 60 - 67 */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 68 - 6F */
|
|
|
|
NN, NN, NN, NN, NN, NN, 221, NN, /* 70 - 77 */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 78 - 7F */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 80 - 87 */
|
|
|
|
NN, NN, NN, NN, 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 */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* E0 - E7 */
|
|
|
|
NN, NN, NN, 219, NN, NN, NN, 220, /* E8 - EF */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* F0 - F7 */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* F8 - FF */
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define KEY_ERROR 0x01
|
|
|
|
|
1998-12-30 22:25:27 +03:00
|
|
|
#define MAXKEYS (NMOD+2*NKEYCODE)
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
struct ukbd_softc {
|
1998-12-26 15:53:00 +03:00
|
|
|
bdevice sc_dev; /* base device */
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_interface_handle sc_iface; /* interface */
|
|
|
|
usbd_pipe_handle sc_intrpipe; /* interrupt pipe */
|
|
|
|
int sc_ep_addr;
|
|
|
|
|
|
|
|
struct ukbd_data sc_ndata;
|
|
|
|
struct ukbd_data sc_odata;
|
|
|
|
|
1998-08-03 02:27:01 +04:00
|
|
|
char sc_enabled;
|
|
|
|
char sc_disconnected; /* device is gone */
|
1998-07-25 19:36:30 +04:00
|
|
|
|
|
|
|
int sc_leds;
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-07-25 19:36:30 +04:00
|
|
|
struct device *sc_wskbddev;
|
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
1998-12-30 22:25:27 +03:00
|
|
|
#define REP_DELAY1 400
|
|
|
|
#define REP_DELAYN 100
|
1998-07-25 19:36:30 +04:00
|
|
|
int sc_rawkbd;
|
1998-12-30 22:25:27 +03:00
|
|
|
int sc_nrep;
|
|
|
|
char sc_rep[MAXKEYS];
|
1998-07-25 19:36:30 +04:00
|
|
|
#endif
|
1998-07-26 21:42:48 +04:00
|
|
|
|
|
|
|
int sc_polling;
|
|
|
|
int sc_pollchar;
|
1998-12-30 22:25:27 +03:00
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define UKBDUNIT(dev) (minor(dev))
|
|
|
|
#define UKBD_CHUNK 128 /* chunk size for read */
|
|
|
|
#define UKBD_BSIZE 1020 /* buffer size */
|
|
|
|
|
1998-07-26 21:42:48 +04:00
|
|
|
void ukbd_cngetc __P((void *, u_int *, int *));
|
|
|
|
void ukbd_cnpollc __P((void *, int));
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-08-02 18:22:25 +04:00
|
|
|
const struct wskbd_consops ukbd_consops = {
|
|
|
|
ukbd_cngetc,
|
|
|
|
ukbd_cnpollc,
|
|
|
|
};
|
1998-12-26 15:53:00 +03:00
|
|
|
#endif
|
1998-08-02 18:22:25 +04:00
|
|
|
|
1998-07-25 19:36:30 +04:00
|
|
|
void ukbd_intr __P((usbd_request_handle, usbd_private_handle, usbd_status));
|
|
|
|
void ukbd_disco __P((void *));
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1998-08-02 18:22:25 +04:00
|
|
|
int ukbd_enable __P((void *, int));
|
1998-07-25 19:36:30 +04:00
|
|
|
void ukbd_set_leds __P((void *, int));
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-07-25 19:36:30 +04:00
|
|
|
int ukbd_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
|
1998-12-29 18:42:30 +03:00
|
|
|
int ukbd_cnattach __P((void *v));
|
1998-12-30 22:25:27 +03:00
|
|
|
void ukbd_rawrepeat __P((void *v));
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1998-08-02 18:22:25 +04:00
|
|
|
const struct wskbd_accessops ukbd_accessops = {
|
|
|
|
ukbd_enable,
|
|
|
|
ukbd_set_leds,
|
|
|
|
ukbd_ioctl,
|
1998-12-30 21:03:37 +03:00
|
|
|
#if 0
|
|
|
|
ukbd_cnattach,
|
|
|
|
#endif
|
1998-08-02 18:22:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct wskbd_mapdata ukbd_keymapdata = {
|
|
|
|
pckbd_keydesctab,
|
|
|
|
#ifdef PCKBD_LAYOUT
|
|
|
|
PCKBD_LAYOUT,
|
|
|
|
#else
|
|
|
|
KB_US,
|
|
|
|
#endif
|
|
|
|
};
|
1998-12-26 15:53:00 +03:00
|
|
|
#endif
|
1998-08-02 18:22:25 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_DECLARE_DRIVER(ukbd);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_MATCH(ukbd)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_MATCH_START(ukbd, uaa);
|
1998-07-12 23:51:55 +04:00
|
|
|
usb_interface_descriptor_t *id;
|
|
|
|
|
|
|
|
/* Check that this is a keyboard that speaks the boot protocol. */
|
|
|
|
if (!uaa->iface)
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
id = usbd_get_interface_descriptor(uaa->iface);
|
1998-12-09 03:18:10 +03:00
|
|
|
if (!id ||
|
|
|
|
id->bInterfaceClass != UCLASS_HID ||
|
1998-07-12 23:51:55 +04:00
|
|
|
id->bInterfaceSubClass != USUBCLASS_BOOT ||
|
|
|
|
id->bInterfaceProtocol != UPROTO_BOOT_KEYBOARD)
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO);
|
|
|
|
}
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH(ukbd)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_START(ukbd, sc, uaa);
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_interface_handle iface = uaa->iface;
|
|
|
|
usb_interface_descriptor_t *id;
|
|
|
|
usb_endpoint_descriptor_t *ed;
|
|
|
|
usbd_status r;
|
|
|
|
char devinfo[1024];
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-07-25 19:36:30 +04:00
|
|
|
struct wskbddev_attach_args a;
|
1998-12-26 15:53:00 +03:00
|
|
|
#else
|
|
|
|
int i;
|
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
sc->sc_disconnected = 1;
|
|
|
|
sc->sc_iface = iface;
|
|
|
|
id = usbd_get_interface_descriptor(iface);
|
|
|
|
usbd_devinfo(uaa->device, 0, devinfo);
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_SETUP;
|
|
|
|
printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
|
1998-12-02 20:20:20 +03:00
|
|
|
devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
|
1998-12-26 15:53:00 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
ed = usbd_interface2endpoint_descriptor(iface, 0);
|
|
|
|
if (!ed) {
|
|
|
|
printf("%s: could not read endpoint descriptor\n",
|
1998-12-26 15:53:00 +03:00
|
|
|
USBDEVNAME(sc->sc_dev));
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-11 02:16:47 +03:00
|
|
|
DPRINTFN(10,("ukbd_attach: bLength=%d bDescriptorType=%d "
|
|
|
|
"bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d"
|
|
|
|
" bInterval=%d\n",
|
|
|
|
ed->bLength, ed->bDescriptorType,
|
|
|
|
ed->bEndpointAddress & UE_ADDR,
|
|
|
|
ed->bEndpointAddress & UE_IN ? "in" : "out",
|
|
|
|
ed->bmAttributes & UE_XFERTYPE,
|
|
|
|
UGETW(ed->wMaxPacketSize), ed->bInterval));
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
if ((ed->bEndpointAddress & UE_IN) != UE_IN ||
|
|
|
|
(ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
|
|
|
|
printf("%s: unexpected endpoint\n",
|
1998-12-26 15:53:00 +03:00
|
|
|
USBDEVNAME(sc->sc_dev));
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((usbd_get_quirks(uaa->device)->uq_flags & UQ_NO_SET_PROTO) == 0) {
|
|
|
|
r = usbd_set_protocol(iface, 0);
|
|
|
|
DPRINTFN(5, ("ukbd_attach: protocol set\n"));
|
|
|
|
if (r != USBD_NORMAL_COMPLETION) {
|
|
|
|
printf("%s: set protocol failed\n",
|
1998-12-26 15:53:00 +03:00
|
|
|
USBDEVNAME(sc->sc_dev));
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
1998-12-30 22:25:27 +03:00
|
|
|
|
1998-08-01 22:16:19 +04:00
|
|
|
/* Ignore if SETIDLE fails since it is not crucial. */
|
1998-08-01 21:46:22 +04:00
|
|
|
usbd_set_idle(iface, 0, 0);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
sc->sc_ep_addr = ed->bEndpointAddress;
|
|
|
|
sc->sc_disconnected = 0;
|
1998-07-25 19:36:30 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-12-30 21:03:37 +03:00
|
|
|
a.console = 0;
|
1998-08-02 18:22:25 +04:00
|
|
|
|
|
|
|
a.keymap = &ukbd_keymapdata;
|
|
|
|
|
|
|
|
a.accessops = &ukbd_accessops;
|
1998-07-25 19:36:30 +04:00
|
|
|
a.accesscookie = sc;
|
1998-08-02 18:22:25 +04:00
|
|
|
|
1998-12-30 21:03:37 +03:00
|
|
|
/* Flash the leds; no real purpose, just shows we're alive. */
|
|
|
|
ukbd_set_leds(sc, WSKBD_LED_SCROLL | WSKBD_LED_NUM | WSKBD_LED_CAPS);
|
|
|
|
usbd_delay_ms(uaa->device, 300);
|
|
|
|
ukbd_set_leds(sc, 0);
|
|
|
|
|
1998-12-30 22:25:27 +03:00
|
|
|
sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
/* XXX why waste CPU in delay() ? */
|
|
|
|
/* It's alive! IT'S ALIVE! Do a little song and dance. */
|
|
|
|
ukbd_set_leds(sc, NUM_LOCK);
|
|
|
|
delay(15000);
|
|
|
|
ukbd_set_leds(sc, CAPS_LOCK);
|
|
|
|
delay(20000);
|
|
|
|
ukbd_set_leds(sc, SCROLL_LOCK);
|
|
|
|
delay(30000);
|
|
|
|
ukbd_set_leds(sc, CAPS_LOCK);
|
|
|
|
delay(50000);
|
|
|
|
ukbd_set_leds(sc, NUM_LOCK);
|
|
|
|
|
|
|
|
ukbd_enable(sc, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
USB_ATTACH_SUCCESS_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
int
|
|
|
|
ukbd_detach(device_t self)
|
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = device_get_softc(self);
|
|
|
|
char *devinfo = (char *) device_get_desc(self);
|
|
|
|
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (devinfo) {
|
|
|
|
device_set_desc(self, NULL);
|
|
|
|
free(devinfo, M_USB);
|
|
|
|
}
|
|
|
|
|
1998-12-28 15:52:38 +03:00
|
|
|
return (0);
|
1998-12-26 15:53:00 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
void
|
|
|
|
ukbd_disco(p)
|
|
|
|
void *p;
|
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = p;
|
1998-08-02 00:11:38 +04:00
|
|
|
|
|
|
|
DPRINTF(("ukbd_disco: sc=%p\n", sc));
|
|
|
|
usbd_abort_pipe(sc->sc_intrpipe);
|
1998-07-12 23:51:55 +04:00
|
|
|
sc->sc_disconnected = 1;
|
|
|
|
}
|
|
|
|
|
1998-08-02 18:22:25 +04:00
|
|
|
int
|
|
|
|
ukbd_enable(v, on)
|
|
|
|
void *v;
|
|
|
|
int on;
|
|
|
|
{
|
1998-08-03 02:27:01 +04:00
|
|
|
struct ukbd_softc *sc = v;
|
|
|
|
usbd_status r;
|
|
|
|
|
|
|
|
if (on) {
|
|
|
|
/* Set up interrupt pipe. */
|
|
|
|
if (sc->sc_enabled)
|
1998-12-28 15:52:38 +03:00
|
|
|
return (EBUSY);
|
1998-08-03 02:27:01 +04:00
|
|
|
|
|
|
|
sc->sc_enabled = 1;
|
|
|
|
r = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
|
|
|
|
USBD_SHORT_XFER_OK,
|
|
|
|
&sc->sc_intrpipe, sc, &sc->sc_ndata,
|
|
|
|
sizeof(sc->sc_ndata), ukbd_intr);
|
|
|
|
if (r != USBD_NORMAL_COMPLETION)
|
|
|
|
return (EIO);
|
|
|
|
usbd_set_disco(sc->sc_intrpipe, ukbd_disco, sc);
|
|
|
|
} else {
|
|
|
|
/* Disable interrupts. */
|
|
|
|
usbd_abort_pipe(sc->sc_intrpipe);
|
|
|
|
usbd_close_pipe(sc->sc_intrpipe);
|
|
|
|
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
}
|
|
|
|
|
1998-08-02 18:22:25 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
void
|
|
|
|
ukbd_intr(reqh, addr, status)
|
|
|
|
usbd_request_handle reqh;
|
|
|
|
usbd_private_handle addr;
|
|
|
|
usbd_status status;
|
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = addr;
|
|
|
|
struct ukbd_data *ud = &sc->sc_ndata;
|
|
|
|
int mod, omod;
|
1998-12-30 21:03:37 +03:00
|
|
|
int ibuf[MAXKEYS]; /* chars events */
|
1998-07-12 23:51:55 +04:00
|
|
|
int nkeys, i, j;
|
1998-07-25 19:36:30 +04:00
|
|
|
int key, c;
|
1998-07-12 23:51:55 +04:00
|
|
|
#define ADDKEY(c) ibuf[nkeys++] = (c)
|
|
|
|
|
|
|
|
DPRINTFN(5, ("ukbd_intr: status=%d\n", status));
|
|
|
|
if (status == USBD_CANCELLED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
|
|
|
DPRINTF(("ukbd_intr: status=%d\n", status));
|
1998-07-30 00:50:11 +04:00
|
|
|
usbd_clear_endpoint_stall_async(sc->sc_intrpipe);
|
1998-07-12 23:51:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTFN(5, (" mod=0x%02x key0=0x%02x key1=0x%02x\n",
|
|
|
|
ud->modifiers, ud->keycode[0], ud->keycode[1]));
|
|
|
|
|
|
|
|
if (ud->keycode[0] == KEY_ERROR)
|
|
|
|
return; /* ignore */
|
|
|
|
nkeys = 0;
|
|
|
|
mod = ud->modifiers;
|
|
|
|
omod = sc->sc_odata.modifiers;
|
|
|
|
if (mod != omod)
|
|
|
|
for (i = 0; i < NMOD; i++)
|
|
|
|
if (( mod & ukbd_mods[i].mask) !=
|
|
|
|
(omod & ukbd_mods[i].mask))
|
|
|
|
ADDKEY(ukbd_mods[i].key |
|
|
|
|
(mod & ukbd_mods[i].mask
|
|
|
|
? PRESS : RELEASE));
|
|
|
|
if (memcmp(ud->keycode, sc->sc_odata.keycode, NKEYCODE) != 0) {
|
|
|
|
/* Check for released keys. */
|
|
|
|
for (i = 0; i < NKEYCODE; i++) {
|
|
|
|
key = sc->sc_odata.keycode[i];
|
|
|
|
if (key == 0)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < NKEYCODE; j++)
|
|
|
|
if (key == ud->keycode[j])
|
|
|
|
goto rfound;
|
1998-07-25 19:36:30 +04:00
|
|
|
c = ukbd_trtab[key];
|
|
|
|
if (c)
|
|
|
|
ADDKEY(c | RELEASE);
|
1998-07-12 23:51:55 +04:00
|
|
|
rfound:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for pressed keys. */
|
|
|
|
for (i = 0; i < NKEYCODE; i++) {
|
|
|
|
key = ud->keycode[i];
|
|
|
|
if (key == 0)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < NKEYCODE; j++)
|
|
|
|
if (key == sc->sc_odata.keycode[j])
|
|
|
|
goto pfound;
|
1998-07-25 19:36:30 +04:00
|
|
|
c = ukbd_trtab[key];
|
1998-08-01 21:46:22 +04:00
|
|
|
DPRINTFN(2,("ukbd_intr: press key=0x%02x -> 0x%02x\n",
|
|
|
|
key, c));
|
1998-07-25 19:36:30 +04:00
|
|
|
if (c)
|
|
|
|
ADDKEY(c | PRESS);
|
1998-07-12 23:51:55 +04:00
|
|
|
pfound:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->sc_odata = *ud;
|
|
|
|
|
1998-12-30 22:25:27 +03:00
|
|
|
if (nkeys == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if defined(__NetBSD__)
|
1998-07-26 21:42:48 +04:00
|
|
|
if (sc->sc_polling) {
|
1998-12-30 21:03:37 +03:00
|
|
|
DPRINTFN(1,("ukbd_intr: pollchar = 0x%02x\n", ibuf[0]));
|
1998-07-26 21:42:48 +04:00
|
|
|
if (nkeys > 0)
|
1998-08-01 22:16:19 +04:00
|
|
|
sc->sc_pollchar = ibuf[0]; /* XXX lost keys? */
|
1998-07-26 21:42:48 +04:00
|
|
|
return;
|
|
|
|
}
|
1998-12-30 22:25:27 +03:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
1998-12-30 21:03:37 +03:00
|
|
|
if (sc->sc_rawkbd) {
|
|
|
|
char cbuf[MAXKEYS * 2];
|
1998-12-30 22:25:27 +03:00
|
|
|
int npress;
|
|
|
|
|
|
|
|
for (npress = i = j = 0; i < nkeys; i++, j++) {
|
1998-12-30 21:03:37 +03:00
|
|
|
c = ibuf[i];
|
|
|
|
if (c & 0x80)
|
|
|
|
cbuf[j++] = 0xe0;
|
|
|
|
cbuf[j] = c & 0x7f;
|
|
|
|
if (c & RELEASE)
|
|
|
|
cbuf[j] |= 0x80;
|
1998-12-30 22:25:27 +03:00
|
|
|
else {
|
|
|
|
/* remember keys for autorepeat */
|
|
|
|
if (c & 0x80)
|
|
|
|
sc->sc_rep[npress++] = 0xe0;
|
|
|
|
sc->sc_rep[npress++] = c & 0x7f;
|
|
|
|
}
|
1998-12-30 21:03:37 +03:00
|
|
|
}
|
|
|
|
wskbd_rawinput(sc->sc_wskbddev, cbuf, j);
|
1998-12-30 22:25:27 +03:00
|
|
|
untimeout(ukbd_rawrepeat, sc);
|
|
|
|
if (npress != 0) {
|
|
|
|
sc->sc_nrep = npress;
|
|
|
|
timeout(ukbd_rawrepeat, sc, hz * REP_DELAY1 / 1000);
|
|
|
|
}
|
1998-12-30 21:03:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-25 19:36:30 +04:00
|
|
|
for (i = 0; i < nkeys; i++) {
|
|
|
|
c = ibuf[i];
|
|
|
|
wskbd_input(sc->sc_wskbddev,
|
1998-08-01 21:46:22 +04:00
|
|
|
c & RELEASE ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN,
|
|
|
|
c & 0xff);
|
1998-12-30 22:25:27 +03:00
|
|
|
}
|
1998-12-26 15:53:00 +03:00
|
|
|
#elif defined(__FreeBSD__)
|
1998-12-30 22:25:27 +03:00
|
|
|
/* XXX shouldn't the keys be used? */
|
|
|
|
for (i = 0; i < nkeys; i++) {
|
|
|
|
c = ibuf[i];
|
1998-12-28 15:52:38 +03:00
|
|
|
printf("%c (%d) %s\n",
|
|
|
|
((c&0xff) < 32 || (c&0xff) > 126? '.':(c&0xff)), c,
|
|
|
|
(c&RELEASE? "released":"pressed"));
|
1998-12-26 15:53:00 +03:00
|
|
|
if (ud->modifiers)
|
|
|
|
printf("0x%04x\n", ud->modifiers);
|
|
|
|
for (i = 0; i < NKEYCODE; i++)
|
|
|
|
if (ud->keycode[i])
|
|
|
|
printf("%d ", ud->keycode[i]);
|
|
|
|
printf("\n");
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
1998-12-30 22:25:27 +03:00
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-07-25 19:36:30 +04:00
|
|
|
void
|
|
|
|
ukbd_set_leds(v, leds)
|
|
|
|
void *v;
|
|
|
|
int leds;
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
1998-07-25 19:36:30 +04:00
|
|
|
struct ukbd_softc *sc = v;
|
|
|
|
u_int8_t res;
|
|
|
|
|
|
|
|
DPRINTF(("ukbd_set_leds: sc=%p leds=%d\n", sc, leds));
|
|
|
|
|
|
|
|
sc->sc_leds = leds;
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-07-25 19:36:30 +04:00
|
|
|
res = 0;
|
|
|
|
if (leds & WSKBD_LED_SCROLL)
|
|
|
|
res |= SCROLL_LOCK;
|
|
|
|
if (leds & WSKBD_LED_NUM)
|
|
|
|
res |= NUM_LOCK;
|
|
|
|
if (leds & WSKBD_LED_CAPS)
|
|
|
|
res |= CAPS_LOCK;
|
1998-12-26 15:53:00 +03:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
res = leds;
|
|
|
|
#endif
|
1998-07-30 00:50:11 +04:00
|
|
|
usbd_set_report_async(sc->sc_iface, UHID_OUTPUT_REPORT, 0, &res, 1);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
1998-12-30 22:25:27 +03:00
|
|
|
|
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
void
|
|
|
|
ukbd_rawrepeat(v)
|
|
|
|
void *v;
|
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = v;
|
|
|
|
|
|
|
|
wskbd_rawinput(sc->sc_wskbddev, sc->sc_rep, sc->sc_nrep);
|
|
|
|
timeout(ukbd_rawrepeat, sc, hz * REP_DELAYN / 1000);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
int
|
1998-07-25 19:36:30 +04:00
|
|
|
ukbd_ioctl(v, cmd, data, flag, p)
|
|
|
|
void *v;
|
1998-07-12 23:51:55 +04:00
|
|
|
u_long cmd;
|
1998-07-25 19:36:30 +04:00
|
|
|
caddr_t data;
|
1998-07-12 23:51:55 +04:00
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1998-07-25 19:36:30 +04:00
|
|
|
struct ukbd_softc *sc = v;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WSKBDIO_GTYPE:
|
1998-12-30 22:25:27 +03:00
|
|
|
*(int *)data = WSKBD_TYPE_USB;
|
1998-12-28 15:52:38 +03:00
|
|
|
return (0);
|
1998-07-25 19:36:30 +04:00
|
|
|
case WSKBDIO_SETLEDS:
|
|
|
|
ukbd_set_leds(v, *(int *)data);
|
1998-12-28 15:52:38 +03:00
|
|
|
return (0);
|
1998-07-25 19:36:30 +04:00
|
|
|
case WSKBDIO_GETLEDS:
|
|
|
|
*(int *)data = sc->sc_leds;
|
|
|
|
return (0);
|
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
case WSKBDIO_SETMODE:
|
1998-12-30 21:03:37 +03:00
|
|
|
DPRINTF(("ukbd_ioctl: set raw = %d\n", *(int *)data));
|
1998-07-25 19:36:30 +04:00
|
|
|
sc->sc_rawkbd = *(int *)data == WSKBD_RAW;
|
1998-12-30 22:25:27 +03:00
|
|
|
untimeout(ukbd_rawrepeat, sc);
|
1998-07-25 19:36:30 +04:00
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
}
|
1998-12-28 15:52:38 +03:00
|
|
|
return (-1);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
1998-08-02 00:11:38 +04:00
|
|
|
|
|
|
|
/* Console interface. */
|
1998-07-26 21:42:48 +04:00
|
|
|
void
|
|
|
|
ukbd_cngetc(v, type, data)
|
|
|
|
void *v;
|
|
|
|
u_int *type;
|
|
|
|
int *data;
|
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = v;
|
|
|
|
usbd_lock_token s;
|
1998-07-30 00:50:11 +04:00
|
|
|
int c;
|
1998-07-26 21:42:48 +04:00
|
|
|
|
1998-07-30 00:50:11 +04:00
|
|
|
DPRINTFN(1,("ukbd_cngetc: enter\n"));
|
1998-07-26 21:42:48 +04:00
|
|
|
s = usbd_lock();
|
|
|
|
sc->sc_polling = 1;
|
|
|
|
sc->sc_pollchar = -1;
|
|
|
|
while(sc->sc_pollchar == -1)
|
|
|
|
usbd_dopoll(sc->sc_iface);
|
|
|
|
sc->sc_polling = 0;
|
1998-07-30 00:50:11 +04:00
|
|
|
c = sc->sc_pollchar;
|
1998-08-01 22:16:19 +04:00
|
|
|
*type = c & RELEASE ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
|
|
|
|
*data = c & 0xff;
|
1998-07-26 21:42:48 +04:00
|
|
|
usbd_unlock(s);
|
1998-07-30 00:50:11 +04:00
|
|
|
DPRINTFN(1,("ukbd_cngetc: return 0x%02x\n", c));
|
1998-07-26 21:42:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ukbd_cnpollc(v, on)
|
|
|
|
void *v;
|
|
|
|
int on;
|
|
|
|
{
|
1998-08-01 22:16:19 +04:00
|
|
|
struct ukbd_softc *sc = v;
|
|
|
|
|
1998-12-30 21:03:37 +03:00
|
|
|
DPRINTFN(2,("ukbd_cnpollc: sc=%p on=%d\n", v, on));
|
1998-08-01 22:16:19 +04:00
|
|
|
|
|
|
|
usbd_set_polling(sc->sc_iface, on);
|
1998-07-26 21:42:48 +04:00
|
|
|
}
|
1998-12-29 18:42:30 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
ukbd_cnattach(v)
|
|
|
|
void *v;
|
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = v;
|
|
|
|
|
1998-12-30 21:03:37 +03:00
|
|
|
DPRINTF(("ukbd_cnattach: sc=%p\n", sc));
|
1998-12-29 18:42:30 +03:00
|
|
|
wskbd_cnattach(&ukbd_consops, sc, &ukbd_keymapdata);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-12-30 22:25:27 +03:00
|
|
|
#endif /* NetBSD */
|
1998-12-26 15:53:00 +03:00
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
DRIVER_MODULE(ukbd, usb, ukbd_driver, ukbd_devclass, usb_driver_load, 0);
|
|
|
|
#endif
|