2000-12-29 04:24:55 +03:00
|
|
|
/* $NetBSD: ukbd.c,v 1.63 2000/12/29 01:24:57 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
|
2000-04-27 19:26:44 +04:00
|
|
|
* by Lennart Augustsson (lennart@augustsson.net) at
|
1998-11-26 01:32:04 +03:00
|
|
|
* 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
|
|
|
/*
|
2000-12-29 04:24:55 +03:00
|
|
|
* HID spec: http://www.usb.org/developers/data/devclass/hid1_1.pdf
|
1998-12-28 15:52:38 +03:00
|
|
|
*/
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1998-07-12 23:51:55 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#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>
|
1999-06-30 10:44:22 +04:00
|
|
|
|
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>
|
1999-05-14 03:34:38 +04:00
|
|
|
#include <dev/usb/ukbdvar.h>
|
1998-07-12 23:51:55 +04:00
|
|
|
|
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 "opt_wsdisplay_compat.h"
|
1999-01-08 14:58:25 +03:00
|
|
|
|
2000-08-21 02:30:17 +04:00
|
|
|
#ifdef UKBD_DEBUG
|
1999-08-14 18:49:31 +04:00
|
|
|
#define DPRINTF(x) if (ukbddebug) logprintf x
|
|
|
|
#define DPRINTFN(n,x) if (ukbddebug>(n)) logprintf x
|
1998-07-12 23:51:55 +04:00
|
|
|
int ukbddebug = 0;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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];
|
|
|
|
};
|
|
|
|
|
1999-01-10 03:23:32 +03:00
|
|
|
#define PRESS 0x000
|
|
|
|
#define RELEASE 0x100
|
|
|
|
#define CODEMASK 0x0ff
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-01-10 03:23:32 +03:00
|
|
|
/* Translate USB bitmap to USB keycode. */
|
1999-01-10 21:36:57 +03:00
|
|
|
#define NMOD 8
|
2000-03-27 16:33:53 +04:00
|
|
|
Static struct {
|
1998-07-12 23:51:55 +04:00
|
|
|
int mask, key;
|
|
|
|
} ukbd_mods[NMOD] = {
|
1999-01-10 03:23:32 +03:00
|
|
|
{ MOD_CONTROL_L, 224 },
|
|
|
|
{ MOD_CONTROL_R, 228 },
|
|
|
|
{ MOD_SHIFT_L, 225 },
|
|
|
|
{ MOD_SHIFT_R, 229 },
|
|
|
|
{ MOD_ALT_L, 226 },
|
|
|
|
{ MOD_ALT_R, 230 },
|
1999-01-10 21:36:57 +03:00
|
|
|
{ MOD_WIN_L, 227 },
|
|
|
|
{ MOD_WIN_R, 231 },
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
1999-01-10 03:23:32 +03:00
|
|
|
#if defined(__NetBSD__) && defined(WSDISPLAY_COMPAT_RAWKBD)
|
1998-08-01 21:46:22 +04:00
|
|
|
#define NN 0 /* no translation */
|
1998-12-30 21:03:37 +03:00
|
|
|
/*
|
1999-01-10 03:23:32 +03:00
|
|
|
* Translate USB keycodes to US keyboard XT scancodes.
|
1998-12-30 21:03:37 +03:00
|
|
|
* Scancodes >= 128 represent EXTENDED keycodes.
|
|
|
|
*/
|
2000-03-27 16:33:53 +04:00
|
|
|
Static u_int8_t ukbd_trtab[256] = {
|
1999-01-10 03:23:32 +03:00
|
|
|
NN, NN, NN, NN, 30, 48, 46, 32, /* 00 - 07 */
|
1998-08-01 21:46:22 +04:00
|
|
|
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 */
|
2000-08-18 03:08:07 +04:00
|
|
|
27, 43, 43, 39, 40, 41, 51, 52, /* 30 - 37 */
|
1998-08-01 21:46:22 +04:00
|
|
|
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 */
|
2000-08-18 03:08:07 +04:00
|
|
|
72, 73, 82, 83, 86, 221, NN, NN, /* 60 - 67 */
|
1998-08-01 21:46:22 +04:00
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 68 - 6F */
|
1999-01-10 21:36:57 +03:00
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 70 - 77 */
|
1998-08-01 21:46:22 +04:00
|
|
|
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 */
|
1999-01-10 16:11:25 +03:00
|
|
|
29, 42, 56, 219, 157, 54, 184,220, /* E0 - E7 */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* E8 - EF */
|
1998-08-01 21:46:22 +04:00
|
|
|
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
|
|
|
};
|
1999-01-10 03:23:32 +03:00
|
|
|
#endif /* defined(__NetBSD__) && defined(WSDISPLAY_COMPAT_RAWKBD) */
|
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 {
|
1999-09-05 23:32:18 +04:00
|
|
|
USBBASEDEVICE sc_dev; /* base device */
|
2000-02-02 16:18:45 +03:00
|
|
|
usbd_device_handle sc_udev;
|
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;
|
1998-07-25 19:36:30 +04:00
|
|
|
|
1999-05-06 23:12:22 +04:00
|
|
|
int sc_console_keyboard; /* we are the console keyboard */
|
|
|
|
|
2000-08-21 02:30:17 +04:00
|
|
|
char sc_debounce; /* for quirk handling */
|
|
|
|
struct callout sc_delay; /* for quirk handling */
|
|
|
|
struct ukbd_data sc_data; /* for quirk handling */
|
|
|
|
|
1998-07-25 19:36:30 +04:00
|
|
|
int sc_leds;
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
2000-03-23 10:01:25 +03:00
|
|
|
struct callout sc_rawrepeat_ch;
|
|
|
|
|
1998-07-25 19:36:30 +04:00
|
|
|
struct device *sc_wskbddev;
|
1999-01-10 03:23:32 +03:00
|
|
|
#if defined(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];
|
1999-01-10 03:23:32 +03:00
|
|
|
#endif /* defined(WSDISPLAY_COMPAT_RAWKBD) */
|
1998-07-26 21:42:48 +04:00
|
|
|
|
|
|
|
int sc_polling;
|
1999-01-10 03:23:32 +03:00
|
|
|
int sc_npollchar;
|
|
|
|
u_int16_t sc_pollchars[MAXKEYS];
|
|
|
|
#endif /* defined(__NetBSD__) */
|
1999-08-24 02:55:14 +04:00
|
|
|
|
|
|
|
u_char sc_dying;
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
2000-08-21 02:30:17 +04:00
|
|
|
#ifdef UKBD_DEBUG
|
|
|
|
#define UKBDTRACESIZE 64
|
|
|
|
struct ukbdtraceinfo {
|
|
|
|
int unit;
|
|
|
|
struct timeval tv;
|
|
|
|
struct ukbd_data ud;
|
|
|
|
};
|
|
|
|
struct ukbdtraceinfo ukbdtracedata[UKBDTRACESIZE];
|
|
|
|
int ukbdtraceindex = 0;
|
|
|
|
int ukbdtrace = 0;
|
|
|
|
void ukbdtracedump(void);
|
|
|
|
void
|
|
|
|
ukbdtracedump(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < UKBDTRACESIZE; i++) {
|
|
|
|
struct ukbdtraceinfo *p =
|
|
|
|
&ukbdtracedata[(i+ukbdtraceindex)%UKBDTRACESIZE];
|
|
|
|
printf("%lu.%06lu: mod=0x%02x key0=0x%02x key1=0x%02x "
|
|
|
|
"key2=0x%02x key3=0x%02x\n",
|
|
|
|
p->tv.tv_sec, p->tv.tv_usec,
|
|
|
|
p->ud.modifiers, p->ud.keycode[0], p->ud.keycode[1],
|
|
|
|
p->ud.keycode[2], p->ud.keycode[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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 */
|
|
|
|
|
2000-03-27 16:33:53 +04:00
|
|
|
Static int ukbd_is_console;
|
1999-05-14 03:34:38 +04:00
|
|
|
|
2000-06-01 18:28:57 +04:00
|
|
|
Static void ukbd_cngetc(void *, u_int *, int *);
|
|
|
|
Static void ukbd_cnpollc(void *, int);
|
1998-07-26 21:42:48 +04:00
|
|
|
|
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
|
|
|
|
2000-06-01 18:28:57 +04:00
|
|
|
Static void ukbd_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
|
2000-08-21 02:30:17 +04:00
|
|
|
Static void ukbd_decode(struct ukbd_softc *sc, struct ukbd_data *ud);
|
|
|
|
Static void ukbd_delayed_decode(void *addr);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2000-06-01 18:28:57 +04:00
|
|
|
Static int ukbd_enable(void *, int);
|
|
|
|
Static void ukbd_set_leds(void *, int);
|
1999-01-10 03:23:32 +03:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#if defined(__NetBSD__)
|
2000-06-01 18:28:57 +04:00
|
|
|
Static int ukbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
|
1999-11-12 22:11:25 +03:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
2000-06-01 18:28:57 +04:00
|
|
|
Static void ukbd_rawrepeat(void *v);
|
1999-11-12 22:11:25 +03:00
|
|
|
#endif
|
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,
|
|
|
|
};
|
|
|
|
|
1999-01-10 03:23:32 +03:00
|
|
|
extern const struct wscons_keydesc ukbd_keydesctab[];
|
|
|
|
|
1998-08-02 18:22:25 +04:00
|
|
|
const struct wskbd_mapdata ukbd_keymapdata = {
|
1999-01-10 03:23:32 +03:00
|
|
|
ukbd_keydesctab,
|
1998-08-02 18:22:25 +04:00
|
|
|
KB_US,
|
|
|
|
};
|
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. */
|
1999-11-12 03:34:57 +03:00
|
|
|
if (uaa->iface == NULL)
|
1998-07-12 23:51:55 +04:00
|
|
|
return (UMATCH_NONE);
|
|
|
|
id = usbd_get_interface_descriptor(uaa->iface);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (id == NULL ||
|
2000-03-01 00:37:00 +03:00
|
|
|
id->bInterfaceClass != UICLASS_HID ||
|
|
|
|
id->bInterfaceSubClass != UISUBCLASS_BOOT ||
|
|
|
|
id->bInterfaceProtocol != UIPROTO_BOOT_KEYBOARD)
|
1998-07-12 23:51:55 +04:00
|
|
|
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;
|
1999-11-12 03:34:57 +03:00
|
|
|
usbd_status err;
|
2000-08-21 02:30:17 +04:00
|
|
|
u_int32_t qflags;
|
1998-07-12 23:51:55 +04:00
|
|
|
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
|
|
|
|
2000-02-02 16:18:45 +03:00
|
|
|
sc->sc_udev = uaa->device;
|
1998-07-12 23:51:55 +04:00
|
|
|
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);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (ed == NULL) {
|
1998-07-12 23:51:55 +04:00
|
|
|
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,
|
1999-09-05 02:26:11 +04:00
|
|
|
UE_GET_DIR(ed->bEndpointAddress)==UE_DIR_IN? "in" : "out",
|
1998-12-11 02:16:47 +03:00
|
|
|
ed->bmAttributes & UE_XFERTYPE,
|
|
|
|
UGETW(ed->wMaxPacketSize), ed->bInterval));
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1999-09-05 02:26:11 +04:00
|
|
|
if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
|
1998-07-12 23:51:55 +04:00
|
|
|
(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
|
|
|
}
|
|
|
|
|
2000-08-21 02:30:17 +04:00
|
|
|
qflags = usbd_get_quirks(uaa->device)->uq_flags;
|
|
|
|
if ((qflags & UQ_NO_SET_PROTO) == 0) {
|
1999-11-12 03:34:57 +03:00
|
|
|
err = usbd_set_protocol(iface, 0);
|
1998-07-12 23:51:55 +04:00
|
|
|
DPRINTFN(5, ("ukbd_attach: protocol set\n"));
|
1999-11-12 03:34:57 +03:00
|
|
|
if (err) {
|
1998-07-12 23:51:55 +04:00
|
|
|
printf("%s: set protocol failed\n",
|
1999-11-12 03:34:57 +03:00
|
|
|
USBDEVNAME(sc->sc_dev));
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
2000-08-21 02:30:17 +04:00
|
|
|
sc->sc_debounce = (qflags & UQ_SPUR_BUT_UP) != 0;
|
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. */
|
2000-08-21 02:30:17 +04:00
|
|
|
(void)usbd_set_idle(iface, 0, 0);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
sc->sc_ep_addr = ed->bEndpointAddress;
|
1998-07-25 19:36:30 +04:00
|
|
|
|
1999-05-06 23:12:22 +04:00
|
|
|
/*
|
|
|
|
* Remember if we're the console keyboard.
|
|
|
|
*
|
1999-05-14 03:34:38 +04:00
|
|
|
* XXX This always picks the first keyboard on the
|
|
|
|
* first USB bus, but what else can we really do?
|
1999-05-06 23:12:22 +04:00
|
|
|
*/
|
1999-05-14 03:34:38 +04:00
|
|
|
if ((sc->sc_console_keyboard = ukbd_is_console) != 0) {
|
1999-05-06 23:12:22 +04:00
|
|
|
/* Don't let any other keyboard have it. */
|
1999-05-14 03:34:38 +04:00
|
|
|
ukbd_is_console = 0;
|
1999-05-06 23:12:22 +04:00
|
|
|
}
|
|
|
|
|
1999-05-14 03:34:38 +04:00
|
|
|
if (sc->sc_console_keyboard) {
|
1999-05-14 23:38:44 +04:00
|
|
|
DPRINTF(("ukbd_attach: console keyboard sc=%p\n", sc));
|
1999-05-14 03:34:38 +04:00
|
|
|
wskbd_cnattach(&ukbd_consops, sc, &ukbd_keymapdata);
|
1999-06-11 23:05:13 +04:00
|
|
|
ukbd_enable(sc, 1);
|
1999-05-14 03:34:38 +04:00
|
|
|
}
|
1999-05-06 23:12:22 +04:00
|
|
|
|
|
|
|
a.console = sc->sc_console_keyboard;
|
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
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&sc->sc_rawrepeat_ch);
|
|
|
|
|
2000-08-21 02:30:17 +04:00
|
|
|
callout_init(&sc->sc_delay);
|
|
|
|
|
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);
|
1999-01-10 03:23:32 +03:00
|
|
|
usbd_delay_ms(uaa->device, 400);
|
1998-12-30 21:03:37 +03:00
|
|
|
ukbd_set_leds(sc, 0);
|
|
|
|
|
1998-12-30 22:25:27 +03:00
|
|
|
sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
|
|
|
|
|
2000-02-02 16:18:45 +03:00
|
|
|
usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
|
|
|
|
USBDEV(sc->sc_dev));
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_SUCCESS_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-08-02 18:22:25 +04:00
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
ukbd_enable(void *v, int on)
|
1998-08-02 18:22:25 +04:00
|
|
|
{
|
1998-08-03 02:27:01 +04:00
|
|
|
struct ukbd_softc *sc = v;
|
1999-11-12 03:34:57 +03:00
|
|
|
usbd_status err;
|
1998-08-03 02:27:01 +04:00
|
|
|
|
1999-08-24 02:55:14 +04:00
|
|
|
if (on && sc->sc_dying)
|
|
|
|
return (EIO);
|
|
|
|
|
1999-07-24 05:40:19 +04:00
|
|
|
/* Should only be called to change state */
|
|
|
|
if (sc->sc_enabled == on) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("ukbd_enable: %s: bad call on=%d\n",
|
|
|
|
USBDEVNAME(sc->sc_dev), on);
|
|
|
|
#endif
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
1999-06-10 19:48:27 +04:00
|
|
|
DPRINTF(("ukbd_enable: sc=%p on=%d\n", sc, on));
|
1998-08-03 02:27:01 +04:00
|
|
|
if (on) {
|
|
|
|
/* Set up interrupt pipe. */
|
1999-11-12 03:34:57 +03:00
|
|
|
err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
|
|
|
|
USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc,
|
2000-01-19 03:23:58 +03:00
|
|
|
&sc->sc_ndata, sizeof(sc->sc_ndata), ukbd_intr,
|
|
|
|
USBD_DEFAULT_INTERVAL);
|
1999-11-12 03:34:57 +03:00
|
|
|
if (err)
|
1998-08-03 02:27:01 +04:00
|
|
|
return (EIO);
|
|
|
|
} else {
|
|
|
|
/* Disable interrupts. */
|
|
|
|
usbd_abort_pipe(sc->sc_intrpipe);
|
|
|
|
usbd_close_pipe(sc->sc_intrpipe);
|
|
|
|
}
|
1999-07-24 05:40:19 +04:00
|
|
|
sc->sc_enabled = on;
|
1998-08-03 02:27:01 +04:00
|
|
|
|
1998-08-02 18:22:25 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
ukbd_activate(device_ptr_t self, enum devact act)
|
1999-06-30 10:44:22 +04:00
|
|
|
{
|
1999-08-24 02:55:14 +04:00
|
|
|
struct ukbd_softc *sc = (struct ukbd_softc *)self;
|
1999-09-12 12:21:49 +04:00
|
|
|
int rv = 0;
|
1999-08-24 02:55:14 +04:00
|
|
|
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DVACT_DEACTIVATE:
|
1999-11-12 03:34:57 +03:00
|
|
|
if (sc->sc_wskbddev != NULL)
|
1999-09-12 12:21:49 +04:00
|
|
|
rv = config_deactivate(sc->sc_wskbddev);
|
1999-08-24 02:55:14 +04:00
|
|
|
sc->sc_dying = 1;
|
|
|
|
break;
|
|
|
|
}
|
1999-09-12 12:21:49 +04:00
|
|
|
return (rv);
|
1999-06-30 10:44:22 +04:00
|
|
|
}
|
|
|
|
|
1999-10-13 12:10:55 +04:00
|
|
|
USB_DETACH(ukbd)
|
1999-06-30 10:44:22 +04:00
|
|
|
{
|
1999-10-13 12:10:55 +04:00
|
|
|
USB_DETACH_START(ukbd, sc);
|
1999-06-30 10:44:22 +04:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
DPRINTF(("ukbd_detach: sc=%p flags=%d\n", sc, flags));
|
1999-10-13 12:10:55 +04:00
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
if (sc->sc_console_keyboard) {
|
1999-12-02 02:22:57 +03:00
|
|
|
#if 0
|
1999-06-30 10:44:22 +04:00
|
|
|
/*
|
|
|
|
* XXX Should probably disconnect our consops,
|
|
|
|
* XXX and either notify some other keyboard that
|
|
|
|
* XXX it can now be the console, or if there aren't
|
|
|
|
* XXX any more USB keyboards, set ukbd_is_console
|
|
|
|
* XXX back to 1 so that the next USB keyboard attached
|
|
|
|
* XXX to the system will get it.
|
|
|
|
*/
|
|
|
|
panic("ukbd_detach: console keyboard");
|
1999-12-02 02:22:57 +03:00
|
|
|
#else
|
1999-12-07 00:06:59 +03:00
|
|
|
/*
|
|
|
|
* Disconnect our consops and set ukbd_is_console
|
|
|
|
* back to 1 so that the next USB keyboard attached
|
|
|
|
* to the system will get it.
|
|
|
|
* XXX Should notify some other keyboard that it can be
|
|
|
|
* XXX console, if there are any other keyboards.
|
|
|
|
*/
|
|
|
|
printf("%s: was console keyboard\n", USBDEVNAME(sc->sc_dev));
|
1999-12-02 02:22:57 +03:00
|
|
|
wskbd_cndetach();
|
|
|
|
ukbd_is_console = 1;
|
|
|
|
#endif
|
1999-06-30 10:44:22 +04:00
|
|
|
}
|
1999-10-12 15:54:56 +04:00
|
|
|
/* No need to do reference counting of ukbd, wskbd has all the goo. */
|
1999-11-12 03:34:57 +03:00
|
|
|
if (sc->sc_wskbddev != NULL)
|
1999-06-30 10:44:22 +04:00
|
|
|
rv = config_detach(sc->sc_wskbddev, flags);
|
2000-02-02 16:18:45 +03:00
|
|
|
|
|
|
|
usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
|
|
|
|
USBDEV(sc->sc_dev));
|
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
void
|
1999-11-12 03:34:57 +03:00
|
|
|
ukbd_intr(xfer, addr, status)
|
|
|
|
usbd_xfer_handle xfer;
|
1998-07-12 23:51:55 +04:00
|
|
|
usbd_private_handle addr;
|
|
|
|
usbd_status status;
|
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = addr;
|
|
|
|
struct ukbd_data *ud = &sc->sc_ndata;
|
|
|
|
|
|
|
|
DPRINTFN(5, ("ukbd_intr: status=%d\n", status));
|
|
|
|
if (status == USBD_CANCELLED)
|
|
|
|
return;
|
|
|
|
|
1999-11-26 04:39:27 +03:00
|
|
|
if (status) {
|
1998-07-12 23:51:55 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-08-21 02:30:17 +04:00
|
|
|
if (sc->sc_debounce) {
|
|
|
|
/*
|
|
|
|
* Some keyboards have a peculiar quirk. They sometimes
|
|
|
|
* generate a key up followed by a key down for the same
|
|
|
|
* key after about 10 ms.
|
|
|
|
* We avoid this bug by holding off decoding for 20 ms.
|
|
|
|
*/
|
|
|
|
sc->sc_data = *ud;
|
|
|
|
callout_reset(&sc->sc_delay, hz / 50, ukbd_delayed_decode, sc);
|
|
|
|
} else {
|
|
|
|
ukbd_decode(sc, ud);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ukbd_delayed_decode(void *addr)
|
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = addr;
|
|
|
|
|
|
|
|
ukbd_decode(sc, &sc->sc_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ukbd_decode(struct ukbd_softc *sc, struct ukbd_data *ud)
|
|
|
|
{
|
|
|
|
int mod, omod;
|
|
|
|
u_int16_t ibuf[MAXKEYS]; /* chars events */
|
|
|
|
int s;
|
|
|
|
int nkeys, i, j;
|
|
|
|
int key;
|
|
|
|
#define ADDKEY(c) ibuf[nkeys++] = (c)
|
|
|
|
|
|
|
|
#ifdef UKBD_DEBUG
|
|
|
|
/*
|
|
|
|
* Keep a trace of the last events. Using printf changes the
|
|
|
|
* timing, so this can be useful sometimes.
|
|
|
|
*/
|
|
|
|
if (ukbdtrace) {
|
|
|
|
struct ukbdtraceinfo *p = &ukbdtracedata[ukbdtraceindex];
|
|
|
|
p->unit = sc->sc_dev.dv_unit;
|
|
|
|
microtime(&p->tv);
|
|
|
|
p->ud = *ud;
|
|
|
|
if (++ukbdtraceindex >= UKBDTRACESIZE)
|
|
|
|
ukbdtraceindex = 0;
|
|
|
|
}
|
|
|
|
if (ukbddebug > 5) {
|
|
|
|
struct timeval tv;
|
|
|
|
microtime(&tv);
|
|
|
|
DPRINTF((" at %lu.%06lu mod=0x%02x key0=0x%02x key1=0x%02x "
|
|
|
|
"key2=0x%02x key3=0x%02x\n",
|
|
|
|
tv.tv_sec, tv.tv_usec,
|
|
|
|
ud->modifiers, ud->keycode[0], ud->keycode[1],
|
|
|
|
ud->keycode[2], ud->keycode[3]));
|
|
|
|
}
|
|
|
|
#endif
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2000-01-16 12:41:22 +03:00
|
|
|
if (ud->keycode[0] == KEY_ERROR) {
|
|
|
|
DPRINTF(("ukbd_intr: KEY_ERROR\n"));
|
1998-07-12 23:51:55 +04:00
|
|
|
return; /* ignore */
|
2000-01-16 12:41:22 +03:00
|
|
|
}
|
1998-07-12 23:51:55 +04:00
|
|
|
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;
|
2000-08-21 02:30:17 +04:00
|
|
|
DPRINTFN(3,("ukbd_intr: relse key=0x%02x\n", key));
|
1999-01-10 03:23:32 +03:00
|
|
|
ADDKEY(key | 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;
|
1999-01-10 03:23:32 +03:00
|
|
|
DPRINTFN(2,("ukbd_intr: press key=0x%02x\n", key));
|
|
|
|
ADDKEY(key | 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;
|
|
|
|
|
1998-07-26 21:42:48 +04:00
|
|
|
if (sc->sc_polling) {
|
1999-01-10 03:23:32 +03:00
|
|
|
DPRINTFN(1,("ukbd_intr: pollchar = 0x%03x\n", ibuf[0]));
|
|
|
|
memcpy(sc->sc_pollchars, ibuf, nkeys * sizeof(u_int16_t));
|
|
|
|
sc->sc_npollchar = nkeys;
|
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];
|
1999-01-10 13:17:54 +03:00
|
|
|
int c;
|
1998-12-30 22:25:27 +03:00
|
|
|
int npress;
|
|
|
|
|
1999-01-10 03:23:32 +03:00
|
|
|
for (npress = i = j = 0; i < nkeys; i++) {
|
|
|
|
key = ibuf[i];
|
|
|
|
c = ukbd_trtab[key & CODEMASK];
|
|
|
|
if (c == NN)
|
|
|
|
continue;
|
1998-12-30 21:03:37 +03:00
|
|
|
if (c & 0x80)
|
|
|
|
cbuf[j++] = 0xe0;
|
|
|
|
cbuf[j] = c & 0x7f;
|
1999-01-10 03:23:32 +03:00
|
|
|
if (key & RELEASE)
|
1998-12-30 21:03:37 +03:00
|
|
|
cbuf[j] |= 0x80;
|
1998-12-30 22:25:27 +03:00
|
|
|
else {
|
1999-01-10 03:23:32 +03:00
|
|
|
/* remember pressed keys for autorepeat */
|
1998-12-30 22:25:27 +03:00
|
|
|
if (c & 0x80)
|
|
|
|
sc->sc_rep[npress++] = 0xe0;
|
|
|
|
sc->sc_rep[npress++] = c & 0x7f;
|
|
|
|
}
|
1999-01-10 21:36:57 +03:00
|
|
|
DPRINTFN(1,("ukbd_intr: raw = %s0x%02x\n",
|
|
|
|
c & 0x80 ? "0xe0 " : "",
|
|
|
|
cbuf[j]));
|
1999-01-10 03:23:32 +03:00
|
|
|
j++;
|
1998-12-30 21:03:37 +03:00
|
|
|
}
|
1999-05-09 19:10:30 +04:00
|
|
|
s = spltty();
|
1998-12-30 21:03:37 +03:00
|
|
|
wskbd_rawinput(sc->sc_wskbddev, cbuf, j);
|
1999-05-09 19:10:30 +04:00
|
|
|
splx(s);
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_rawrepeat_ch);
|
1998-12-30 22:25:27 +03:00
|
|
|
if (npress != 0) {
|
|
|
|
sc->sc_nrep = npress;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_rawrepeat_ch,
|
|
|
|
hz * REP_DELAY1 / 1000, ukbd_rawrepeat, sc);
|
1998-12-30 22:25:27 +03:00
|
|
|
}
|
1998-12-30 21:03:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-05-09 19:10:30 +04:00
|
|
|
s = spltty();
|
1998-07-25 19:36:30 +04:00
|
|
|
for (i = 0; i < nkeys; i++) {
|
1999-01-10 03:23:32 +03:00
|
|
|
key = ibuf[i];
|
1998-07-25 19:36:30 +04:00
|
|
|
wskbd_input(sc->sc_wskbddev,
|
1999-01-10 03:23:32 +03:00
|
|
|
key&RELEASE ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN,
|
|
|
|
key&CODEMASK);
|
1998-12-30 22:25:27 +03:00
|
|
|
}
|
1999-05-09 19:10:30 +04:00
|
|
|
splx(s);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1998-07-25 19:36:30 +04:00
|
|
|
void
|
2000-06-01 18:28:57 +04:00
|
|
|
ukbd_set_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));
|
|
|
|
|
1999-08-24 02:55:14 +04:00
|
|
|
if (sc->sc_dying)
|
|
|
|
return;
|
|
|
|
|
1998-07-25 19:36:30 +04:00
|
|
|
sc->sc_leds = leds;
|
|
|
|
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;
|
1999-06-11 23:05:13 +04:00
|
|
|
res |= leds & 0xf8;
|
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-30 22:25:27 +03:00
|
|
|
#ifdef WSDISPLAY_COMPAT_RAWKBD
|
|
|
|
void
|
2000-06-01 18:28:57 +04:00
|
|
|
ukbd_rawrepeat(void *v)
|
1998-12-30 22:25:27 +03:00
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = v;
|
1999-05-09 19:10:30 +04:00
|
|
|
int s;
|
1998-12-30 22:25:27 +03:00
|
|
|
|
1999-05-09 19:10:30 +04:00
|
|
|
s = spltty();
|
1998-12-30 22:25:27 +03:00
|
|
|
wskbd_rawinput(sc->sc_wskbddev, sc->sc_rep, sc->sc_nrep);
|
1999-05-09 19:10:30 +04:00
|
|
|
splx(s);
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_rawrepeat_ch, hz * REP_DELAYN / 1000,
|
|
|
|
ukbd_rawrepeat, sc);
|
1998-12-30 22:25:27 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
ukbd_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
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;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_rawrepeat_ch);
|
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
|
2000-06-01 18:28:57 +04:00
|
|
|
ukbd_cngetc(void *v, u_int *type, int *data)
|
1998-07-26 21:42:48 +04:00
|
|
|
{
|
|
|
|
struct ukbd_softc *sc = v;
|
1999-06-14 21:09:57 +04:00
|
|
|
int s;
|
1998-07-30 00:50:11 +04:00
|
|
|
int c;
|
1998-07-26 21:42:48 +04:00
|
|
|
|
1999-12-02 02:22:57 +03:00
|
|
|
DPRINTFN(0,("ukbd_cngetc: enter\n"));
|
1999-06-14 21:09:57 +04:00
|
|
|
s = splusb();
|
1998-07-26 21:42:48 +04:00
|
|
|
sc->sc_polling = 1;
|
1999-01-10 03:23:32 +03:00
|
|
|
while(sc->sc_npollchar <= 0)
|
1998-07-26 21:42:48 +04:00
|
|
|
usbd_dopoll(sc->sc_iface);
|
|
|
|
sc->sc_polling = 0;
|
1999-01-10 03:23:32 +03:00
|
|
|
c = sc->sc_pollchars[0];
|
|
|
|
sc->sc_npollchar--;
|
|
|
|
memcpy(sc->sc_pollchars, sc->sc_pollchars+1,
|
|
|
|
sc->sc_npollchar * sizeof(u_int16_t));
|
1998-08-01 22:16:19 +04:00
|
|
|
*type = c & RELEASE ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
|
1999-01-10 03:23:32 +03:00
|
|
|
*data = c & CODEMASK;
|
1999-06-14 21:09:57 +04:00
|
|
|
splx(s);
|
1999-12-02 02:22:57 +03:00
|
|
|
DPRINTFN(0,("ukbd_cngetc: return 0x%02x\n", c));
|
1998-07-26 21:42:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-01 18:28:57 +04:00
|
|
|
ukbd_cnpollc(void *v, int on)
|
1998-07-26 21:42:48 +04:00
|
|
|
{
|
1998-08-01 22:16:19 +04:00
|
|
|
struct ukbd_softc *sc = v;
|
2000-01-16 12:37:18 +03:00
|
|
|
usbd_device_handle dev;
|
1998-08-01 22:16:19 +04:00
|
|
|
|
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
|
|
|
|
2000-01-16 12:37:18 +03:00
|
|
|
(void)usbd_interface2device_handle(sc->sc_iface,&dev);
|
|
|
|
usbd_set_polling(dev, on);
|
1998-07-26 21:42:48 +04:00
|
|
|
}
|
1998-12-29 18:42:30 +03:00
|
|
|
|
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
ukbd_cnattach(void)
|
1998-12-29 18:42:30 +03:00
|
|
|
{
|
|
|
|
|
1999-05-14 03:34:38 +04:00
|
|
|
/*
|
|
|
|
* XXX USB requires too many parts of the kernel to be running
|
|
|
|
* XXX in order to work, so we can't do much for the console
|
|
|
|
* XXX keyboard until autconfiguration has run its course.
|
|
|
|
*/
|
|
|
|
ukbd_is_console = 1;
|
1998-12-29 18:42:30 +03:00
|
|
|
return (0);
|
|
|
|
}
|