2005-05-03 22:37:46 +04:00
|
|
|
/* $NetBSD: ukbd.c,v 1.88 2005/05/03 18:37:46 jonathan 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
|
|
|
/*
|
2003-03-11 19:44:00 +03:00
|
|
|
* HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
|
1998-12-28 15:52:38 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 09:24:53 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-05-03 22:37:46 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ukbd.c,v 1.88 2005/05/03 18:37:46 jonathan Exp $");
|
2001-11-13 09:24:53 +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>
|
2001-12-28 20:32:36 +03:00
|
|
|
#include <dev/usb/uhidev.h>
|
1998-07-12 23:51:55 +04:00
|
|
|
#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"
|
2001-10-25 01:02:18 +04:00
|
|
|
#include "opt_ddb.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
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
#define MAXKEYCODE 6
|
|
|
|
#define MAXMOD 8 /* max 32 */
|
1998-07-25 19:36:30 +04:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
struct ukbd_data {
|
2001-12-28 20:32:36 +03:00
|
|
|
u_int32_t modifiers;
|
|
|
|
u_int8_t keycode[MAXKEYCODE];
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
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
|
|
|
#if defined(__NetBSD__) && defined(WSDISPLAY_COMPAT_RAWKBD)
|
1998-08-01 21:46:22 +04:00
|
|
|
#define NN 0 /* no translation */
|
2002-07-12 01:14:24 +04:00
|
|
|
/*
|
1999-01-10 03:23:32 +03:00
|
|
|
* Translate USB keycodes to US keyboard XT scancodes.
|
2001-12-29 05:53:41 +03:00
|
|
|
* Scancodes >= 0x80 represent EXTENDED keycodes.
|
|
|
|
*
|
|
|
|
* See http://www.microsoft.com/HWDEV/TECH/input/Scancode.asp
|
1998-12-30 21:03:37 +03:00
|
|
|
*/
|
2001-02-22 00:39:52 +03:00
|
|
|
Static const u_int8_t ukbd_trtab[256] = {
|
2001-12-29 05:53:41 +03:00
|
|
|
NN, NN, NN, NN, 0x1e, 0x30, 0x2e, 0x20, /* 00 - 07 */
|
|
|
|
0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26, /* 08 - 0f */
|
|
|
|
0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1f, 0x14, /* 10 - 17 */
|
|
|
|
0x16, 0x2f, 0x11, 0x2d, 0x15, 0x2c, 0x02, 0x03, /* 18 - 1f */
|
|
|
|
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, /* 20 - 27 */
|
|
|
|
0x1c, 0x01, 0x0e, 0x0f, 0x39, 0x0c, 0x0d, 0x1a, /* 28 - 2f */
|
|
|
|
0x1b, 0x2b, 0x2b, 0x27, 0x28, 0x29, 0x33, 0x34, /* 30 - 37 */
|
|
|
|
0x35, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, /* 38 - 3f */
|
|
|
|
0x41, 0x42, 0x43, 0x44, 0x57, 0x58, 0xaa, 0x46, /* 40 - 47 */
|
|
|
|
0x7f, 0xd2, 0xc7, 0xc9, 0xd3, 0xcf, 0xd1, 0xcd, /* 48 - 4f */
|
|
|
|
0xcb, 0xd0, 0xc8, 0x45, 0xb5, 0x37, 0x4a, 0x4e, /* 50 - 57 */
|
|
|
|
0x9c, 0x4f, 0x50, 0x51, 0x4b, 0x4c, 0x4d, 0x47, /* 58 - 5f */
|
|
|
|
0x48, 0x49, 0x52, 0x53, 0x56, 0xdd, NN, 0x59, /* 60 - 67 */
|
|
|
|
0x5d, 0x5e, 0x5f, NN, NN, NN, NN, NN, /* 68 - 6f */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 70 - 77 */
|
|
|
|
NN, NN, NN, NN, NN, NN, NN, NN, /* 78 - 7f */
|
|
|
|
NN, NN, NN, NN, NN, 0x7e, NN, 0x73, /* 80 - 87 */
|
|
|
|
0x70, 0x7d, 0x79, 0x7b, 0x5c, NN, NN, NN, /* 88 - 8f */
|
|
|
|
NN, NN, 0x78, 0x77, 0x76, 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 */
|
|
|
|
0x1d, 0x2a, 0x38, 0xdb, 0x9d, 0x36, 0xb8, 0xdc, /* 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 */
|
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
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
#define MAXKEYS (MAXMOD+2*MAXKEYCODE)
|
1998-12-30 22:25:27 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
struct ukbd_softc {
|
2001-12-28 20:32:36 +03:00
|
|
|
struct uhidev sc_hdev;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
struct ukbd_data sc_ndata;
|
|
|
|
struct ukbd_data sc_odata;
|
2001-12-28 20:32:36 +03:00
|
|
|
struct hid_location sc_modloc[MAXMOD];
|
|
|
|
u_int sc_nmod;
|
|
|
|
struct {
|
|
|
|
u_int32_t mask;
|
|
|
|
u_int8_t key;
|
|
|
|
} sc_mods[MAXMOD];
|
|
|
|
|
|
|
|
struct hid_location sc_keycodeloc;
|
|
|
|
u_int sc_nkeycode;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
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 */
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_callout_t sc_delay; /* for quirk handling */
|
2000-08-21 02:30:17 +04:00
|
|
|
struct ukbd_data sc_data; /* for quirk handling */
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
struct hid_location sc_numloc;
|
|
|
|
struct hid_location sc_capsloc;
|
|
|
|
struct hid_location sc_scroloc;
|
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;
|
2005-05-03 17:15:21 +04:00
|
|
|
|
1999-01-10 03:23:32 +03:00
|
|
|
#if defined(WSDISPLAY_COMPAT_RAWKBD)
|
2005-05-03 17:15:21 +04:00
|
|
|
int sc_rawkbd;
|
|
|
|
#if defined(UKBD_REPEAT)
|
|
|
|
usb_callout_t sc_rawrepeat_ch;
|
1998-12-30 22:25:27 +03:00
|
|
|
#define REP_DELAY1 400
|
|
|
|
#define REP_DELAYN 100
|
|
|
|
int sc_nrep;
|
|
|
|
char sc_rep[MAXKEYS];
|
2005-05-03 17:15:21 +04:00
|
|
|
#endif /* defined(UKBD_REPEAT) */
|
1999-01-10 03:23:32 +03:00
|
|
|
#endif /* defined(WSDISPLAY_COMPAT_RAWKBD) */
|
1998-07-26 21:42:48 +04:00
|
|
|
|
2002-10-09 05:02:26 +04:00
|
|
|
int sc_spl;
|
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++) {
|
2002-07-12 01:14:24 +04:00
|
|
|
struct ukbdtraceinfo *p =
|
2000-08-21 02:30:17 +04:00
|
|
|
&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
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
Static const char *ukbd_parse_desc(struct ukbd_softc *sc);
|
|
|
|
|
|
|
|
Static void ukbd_intr(struct uhidev *addr, void *ibuf, u_int len);
|
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__)
|
2001-12-31 15:15:21 +03:00
|
|
|
Static int ukbd_ioctl(void *, u_long, caddr_t, int, usb_proc_ptr );
|
2005-05-03 22:37:46 +04:00
|
|
|
#if defined(WSDISPLAY_COMPAT_RAWKBD) && defined(UKBD_REPEAT)
|
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,
|
2005-04-29 21:02:06 +04:00
|
|
|
#if defined(UKBD_LAYOUT)
|
2001-04-07 02:54:15 +04:00
|
|
|
UKBD_LAYOUT,
|
2005-04-29 21:02:06 +04:00
|
|
|
#elif defined(PCKBD_LAYOUT)
|
|
|
|
PCKBD_LAYOUT,
|
2001-04-07 02:54:15 +04:00
|
|
|
#else
|
1998-08-02 18:22:25 +04:00
|
|
|
KB_US,
|
2001-04-07 02:54:15 +04:00
|
|
|
#endif
|
1998-08-02 18:22:25 +04:00
|
|
|
};
|
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
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
int
|
|
|
|
ukbd_match(struct device *parent, struct cfdata *match, void *aux)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2001-12-28 20:32:36 +03:00
|
|
|
struct uhidev_attach_arg *uha = aux;
|
|
|
|
int size;
|
|
|
|
void *desc;
|
2002-07-12 01:14:24 +04:00
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
uhidev_get_report_desc(uha->parent, &desc, &size);
|
|
|
|
if (!hid_is_collection(desc, size, uha->reportid,
|
|
|
|
HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_KEYBOARD)))
|
1998-07-12 23:51:55 +04:00
|
|
|
return (UMATCH_NONE);
|
2001-12-28 20:32:36 +03:00
|
|
|
|
|
|
|
return (UMATCH_IFACECLASS);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
void
|
|
|
|
ukbd_attach(struct device *parent, struct device *self, void *aux)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2001-12-28 20:32:36 +03:00
|
|
|
struct ukbd_softc *sc = (struct ukbd_softc *)self;
|
|
|
|
struct uhidev_attach_arg *uha = aux;
|
2000-08-21 02:30:17 +04:00
|
|
|
u_int32_t qflags;
|
2001-12-28 20:32:36 +03:00
|
|
|
const char *parseerr;
|
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
|
2002-07-12 01:14:24 +04:00
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
sc->sc_hdev.sc_intr = ukbd_intr;
|
|
|
|
sc->sc_hdev.sc_parent = uha->parent;
|
|
|
|
sc->sc_hdev.sc_report_id = uha->reportid;
|
|
|
|
|
|
|
|
parseerr = ukbd_parse_desc(sc);
|
|
|
|
if (parseerr != NULL) {
|
|
|
|
printf("\n%s: attach failed, %s\n",
|
|
|
|
sc->sc_hdev.sc_dev.dv_xname, parseerr);
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
2002-07-12 01:14:24 +04:00
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf(": %d modifier keys, %d key codes", sc->sc_nmod,
|
|
|
|
sc->sc_nkeycode);
|
|
|
|
#endif
|
|
|
|
printf("\n");
|
1998-07-12 23:51:55 +04:00
|
|
|
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
qflags = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
|
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
|
|
|
|
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
|
|
|
|
2005-05-03 17:15:21 +04:00
|
|
|
#ifdef UKBD_REPEAT
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_callout_init(sc->sc_rawrepeat_ch);
|
2005-05-03 17:15:21 +04:00
|
|
|
#endif
|
2000-03-23 10:01:25 +03:00
|
|
|
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_callout_init(sc->sc_delay);
|
2000-08-21 02:30:17 +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);
|
2001-12-28 20:32:36 +03:00
|
|
|
usbd_delay_ms(uha->parent->sc_udev, 400);
|
1998-12-30 21:03:37 +03:00
|
|
|
ukbd_set_leds(sc, 0);
|
|
|
|
|
2001-01-23 17:04:13 +03:00
|
|
|
sc->sc_wskbddev = config_found(self, &a, wskbddevprint);
|
|
|
|
|
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-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
|
2002-07-12 01:14:24 +04:00
|
|
|
printf("ukbd_enable: %s: bad call on=%d\n",
|
2001-12-28 20:32:36 +03:00
|
|
|
USBDEVNAME(sc->sc_hdev.sc_dev), on);
|
1999-07-24 05:40:19 +04:00
|
|
|
#endif
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
1999-06-10 19:48:27 +04:00
|
|
|
DPRINTF(("ukbd_enable: sc=%p on=%d\n", sc, on));
|
2001-12-28 20:32:36 +03:00
|
|
|
sc->sc_enabled = on;
|
1998-08-03 02:27:01 +04:00
|
|
|
if (on) {
|
2001-12-28 20:32:36 +03:00
|
|
|
return (uhidev_open(&sc->sc_hdev));
|
1998-08-03 02:27:01 +04:00
|
|
|
} else {
|
2001-12-28 20:32:36 +03:00
|
|
|
uhidev_close(&sc->sc_hdev);
|
|
|
|
return (0);
|
1998-08-03 02:27:01 +04:00
|
|
|
}
|
1998-08-02 18:22:25 +04:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
int
|
|
|
|
ukbd_detach(struct device *self, int flags)
|
1999-06-30 10:44:22 +04:00
|
|
|
{
|
2001-12-28 20:32:36 +03:00
|
|
|
struct ukbd_softc *sc = (struct ukbd_softc *)self;
|
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.
|
|
|
|
*/
|
2001-12-28 20:32:36 +03:00
|
|
|
printf("%s: was console keyboard\n",
|
|
|
|
USBDEVNAME(sc->sc_hdev.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
|
|
|
|
2001-10-24 19:31:06 +04:00
|
|
|
/* The console keyboard does not get a disable call, so check pipe. */
|
2001-12-28 20:32:36 +03:00
|
|
|
if (sc->sc_hdev.sc_state & UHIDEV_OPEN)
|
|
|
|
uhidev_close(&sc->sc_hdev);
|
2000-02-02 16:18:45 +03:00
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
void
|
2001-12-28 20:32:36 +03:00
|
|
|
ukbd_intr(struct uhidev *addr, void *ibuf, u_int len)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2001-12-28 20:32:36 +03:00
|
|
|
struct ukbd_softc *sc = (struct ukbd_softc *)addr;
|
1998-07-12 23:51:55 +04:00
|
|
|
struct ukbd_data *ud = &sc->sc_ndata;
|
2001-12-28 20:32:36 +03:00
|
|
|
int i;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2001-12-29 05:53:41 +03:00
|
|
|
#ifdef UKBD_DEBUG
|
|
|
|
if (ukbddebug > 5) {
|
|
|
|
printf("ukbd_intr: data");
|
|
|
|
for (i = 0; i < len; i++)
|
2001-12-30 22:22:28 +03:00
|
|
|
printf(" 0x%02x", ((u_char *)ibuf)[i]);
|
2001-12-29 05:53:41 +03:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
ud->modifiers = 0;
|
|
|
|
for (i = 0; i < sc->sc_nmod; i++)
|
|
|
|
if (hid_get_data(ibuf, &sc->sc_modloc[i]))
|
2001-12-31 15:15:21 +03:00
|
|
|
ud->modifiers |= sc->sc_mods[i].mask;
|
2001-12-28 20:32:36 +03:00
|
|
|
memcpy(ud->keycode, (char *)ibuf + sc->sc_keycodeloc.pos / 8,
|
|
|
|
sc->sc_nkeycode);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2001-10-25 01:02:18 +04:00
|
|
|
if (sc->sc_debounce && !sc->sc_polling) {
|
2000-08-21 02:30:17 +04:00
|
|
|
/*
|
|
|
|
* 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;
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_callout(sc->sc_delay, hz / 50, ukbd_delayed_decode, sc);
|
2001-11-28 08:45:27 +03:00
|
|
|
#ifdef DDB
|
2001-10-25 01:02:18 +04:00
|
|
|
} else if (sc->sc_console_keyboard && !sc->sc_polling) {
|
|
|
|
/*
|
|
|
|
* For the console keyboard we can't deliver CTL-ALT-ESC
|
|
|
|
* from the interrupt routine. Doing so would start
|
|
|
|
* polling from inside the interrupt routine and that
|
|
|
|
* loses bigtime.
|
|
|
|
*/
|
|
|
|
sc->sc_data = *ud;
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_callout(sc->sc_delay, 1, ukbd_delayed_decode, sc);
|
2001-10-25 01:02:18 +04:00
|
|
|
#endif
|
2000-08-21 02:30:17 +04:00
|
|
|
} 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
|
2002-07-12 01:14:24 +04:00
|
|
|
/*
|
2000-08-21 02:30:17 +04:00
|
|
|
* 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];
|
2001-12-28 20:32:36 +03:00
|
|
|
p->unit = sc->sc_hdev.sc_dev.dv_unit;
|
2000-08-21 02:30:17 +04:00
|
|
|
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)
|
2001-12-28 20:32:36 +03:00
|
|
|
for (i = 0; i < sc->sc_nmod; i++)
|
2002-07-12 01:14:24 +04:00
|
|
|
if (( mod & sc->sc_mods[i].mask) !=
|
2001-12-28 20:32:36 +03:00
|
|
|
(omod & sc->sc_mods[i].mask))
|
2002-07-12 01:14:24 +04:00
|
|
|
ADDKEY(sc->sc_mods[i].key |
|
|
|
|
(mod & sc->sc_mods[i].mask
|
1998-07-12 23:51:55 +04:00
|
|
|
? PRESS : RELEASE));
|
2001-12-28 20:32:36 +03:00
|
|
|
if (memcmp(ud->keycode, sc->sc_odata.keycode, sc->sc_nkeycode) != 0) {
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Check for released keys. */
|
2001-12-28 20:32:36 +03:00
|
|
|
for (i = 0; i < sc->sc_nkeycode; i++) {
|
1998-07-12 23:51:55 +04:00
|
|
|
key = sc->sc_odata.keycode[i];
|
|
|
|
if (key == 0)
|
|
|
|
continue;
|
2001-12-28 20:32:36 +03:00
|
|
|
for (j = 0; j < sc->sc_nkeycode; j++)
|
1998-07-12 23:51:55 +04:00
|
|
|
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:
|
|
|
|
;
|
|
|
|
}
|
2002-07-12 01:14:24 +04:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
/* Check for pressed keys. */
|
2001-12-28 20:32:36 +03:00
|
|
|
for (i = 0; i < sc->sc_nkeycode; i++) {
|
1998-07-12 23:51:55 +04:00
|
|
|
key = ud->keycode[i];
|
|
|
|
if (key == 0)
|
|
|
|
continue;
|
2001-12-28 20:32:36 +03:00
|
|
|
for (j = 0; j < sc->sc_nkeycode; j++)
|
1998-07-12 23:51:55 +04:00
|
|
|
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) {
|
2001-12-30 22:37:43 +03:00
|
|
|
u_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;
|
2005-05-03 17:15:21 +04:00
|
|
|
#if defined(UKBD_REPEAT)
|
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;
|
|
|
|
}
|
2005-05-03 17:15:21 +04:00
|
|
|
#endif
|
2002-07-12 01:14:24 +04:00
|
|
|
DPRINTFN(1,("ukbd_intr: raw = %s0x%02x\n",
|
1999-01-10 21:36:57 +03:00
|
|
|
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);
|
2005-05-03 17:15:21 +04:00
|
|
|
#ifdef UKBD_REPEAT
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_uncallout(sc->sc_rawrepeat_ch, ukbd_rawrepeat, sc);
|
1998-12-30 22:25:27 +03:00
|
|
|
if (npress != 0) {
|
|
|
|
sc->sc_nrep = npress;
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_callout(sc->sc_rawrepeat_ch,
|
2000-03-23 10:01:25 +03:00
|
|
|
hz * REP_DELAY1 / 1000, ukbd_rawrepeat, sc);
|
1998-12-30 22:25:27 +03:00
|
|
|
}
|
2005-05-03 17:15:21 +04:00
|
|
|
#endif
|
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];
|
2002-07-12 01:14:24 +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;
|
|
|
|
|
2001-11-07 05:52:47 +03:00
|
|
|
DPRINTF(("ukbd_set_leds: sc=%p leds=%d, sc_leds=%d\n",
|
|
|
|
sc, leds, sc->sc_leds));
|
1998-07-25 19:36:30 +04:00
|
|
|
|
1999-08-24 02:55:14 +04:00
|
|
|
if (sc->sc_dying)
|
|
|
|
return;
|
|
|
|
|
2001-11-07 05:52:47 +03:00
|
|
|
if (sc->sc_leds == leds)
|
|
|
|
return;
|
1998-07-25 19:36:30 +04:00
|
|
|
sc->sc_leds = leds;
|
|
|
|
res = 0;
|
2001-12-28 20:32:36 +03:00
|
|
|
/* XXX not really right */
|
|
|
|
if ((leds & WSKBD_LED_SCROLL) && sc->sc_scroloc.size == 1)
|
|
|
|
res |= 1 << sc->sc_scroloc.pos;
|
|
|
|
if ((leds & WSKBD_LED_NUM) && sc->sc_numloc.size == 1)
|
|
|
|
res |= 1 << sc->sc_numloc.pos;
|
|
|
|
if ((leds & WSKBD_LED_CAPS) && sc->sc_capsloc.size == 1)
|
|
|
|
res |= 1 << sc->sc_capsloc.pos;
|
|
|
|
uhidev_set_report_async(&sc->sc_hdev, UHID_OUTPUT_REPORT, &res, 1);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
2005-05-03 17:15:21 +04:00
|
|
|
#if defined(WSDISPLAY_COMPAT_RAWKBD) && defined(UKBD_REPEAT)
|
1998-12-30 22:25:27 +03:00
|
|
|
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);
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_callout(sc->sc_rawrepeat_ch, hz * REP_DELAYN / 1000,
|
2000-03-23 10:01:25 +03:00
|
|
|
ukbd_rawrepeat, sc);
|
1998-12-30 22:25:27 +03:00
|
|
|
}
|
2005-05-03 17:15:21 +04:00
|
|
|
#endif /* defined(WSDISPLAY_COMPAT_RAWKBD) && defined(UKBD_REPEAT) */
|
1998-12-30 22:25:27 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
int
|
2001-12-31 15:15:21 +03:00
|
|
|
ukbd_ioctl(void *v, u_long cmd, caddr_t data, int flag, usb_proc_ptr 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);
|
2005-05-03 17:15:21 +04:00
|
|
|
#if defined(WSDISPLAY_COMPAT_RAWKBD)
|
1998-07-25 19:36:30 +04:00
|
|
|
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;
|
2005-05-03 17:15:21 +04:00
|
|
|
#if defined(UKBD_REPEAT)
|
2001-10-28 19:53:21 +03:00
|
|
|
usb_uncallout(sc->sc_rawrepeat_ch, ukbd_rawrepeat, sc);
|
2005-05-03 17:15:21 +04:00
|
|
|
#endif
|
1998-07-25 19:36:30 +04:00
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
}
|
2002-03-17 22:40:26 +03:00
|
|
|
return (EPASSTHROUGH);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
1998-08-02 00:11:38 +04:00
|
|
|
|
2001-11-07 05:52:47 +03:00
|
|
|
/*
|
|
|
|
* This is a hack to work around some broken ports that don't call
|
|
|
|
* cnpollc() before cngetc().
|
|
|
|
*/
|
|
|
|
static int pollenter, warned;
|
|
|
|
|
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;
|
1998-07-30 00:50:11 +04:00
|
|
|
int c;
|
2001-11-07 05:52:47 +03:00
|
|
|
int broken;
|
|
|
|
|
|
|
|
if (pollenter == 0) {
|
|
|
|
if (!warned) {
|
|
|
|
printf("\n"
|
|
|
|
"This port is broken, it does not call cnpollc() before calling cngetc().\n"
|
|
|
|
"This should be fixed, but it will work anyway (for now).\n");
|
|
|
|
warned = 1;
|
|
|
|
}
|
|
|
|
broken = 1;
|
|
|
|
ukbd_cnpollc(v, 1);
|
|
|
|
} else
|
|
|
|
broken = 0;
|
1998-07-26 21:42:48 +04:00
|
|
|
|
1999-12-02 02:22:57 +03:00
|
|
|
DPRINTFN(0,("ukbd_cngetc: enter\n"));
|
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)
|
2001-12-28 20:32:36 +03:00
|
|
|
usbd_dopoll(sc->sc_hdev.sc_parent->sc_iface);
|
1998-07-26 21:42:48 +04:00
|
|
|
sc->sc_polling = 0;
|
1999-01-10 03:23:32 +03:00
|
|
|
c = sc->sc_pollchars[0];
|
|
|
|
sc->sc_npollchar--;
|
2002-07-12 01:14:24 +04:00
|
|
|
memcpy(sc->sc_pollchars, sc->sc_pollchars+1,
|
1999-01-10 03:23:32 +03:00
|
|
|
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-12-02 02:22:57 +03:00
|
|
|
DPRINTFN(0,("ukbd_cngetc: return 0x%02x\n", c));
|
2001-11-07 05:52:47 +03:00
|
|
|
if (broken)
|
|
|
|
ukbd_cnpollc(v, 0);
|
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
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
usbd_interface2device_handle(sc->sc_hdev.sc_parent->sc_iface, &dev);
|
2002-10-09 05:02:26 +04:00
|
|
|
if (on) {
|
|
|
|
sc->sc_spl = splusb();
|
|
|
|
pollenter++;
|
|
|
|
} else {
|
|
|
|
splx(sc->sc_spl);
|
|
|
|
pollenter--;
|
|
|
|
}
|
2000-01-16 12:37:18 +03:00
|
|
|
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);
|
|
|
|
}
|
2001-12-28 20:32:36 +03:00
|
|
|
|
|
|
|
const char *
|
|
|
|
ukbd_parse_desc(struct ukbd_softc *sc)
|
|
|
|
{
|
|
|
|
struct hid_data *d;
|
|
|
|
struct hid_item h;
|
|
|
|
int size;
|
|
|
|
void *desc;
|
|
|
|
int imod;
|
|
|
|
|
|
|
|
uhidev_get_report_desc(sc->sc_hdev.sc_parent, &desc, &size);
|
|
|
|
imod = 0;
|
|
|
|
sc->sc_nkeycode = 0;
|
|
|
|
d = hid_start_parse(desc, size, hid_input);
|
|
|
|
while (hid_get_item(d, &h)) {
|
|
|
|
/*printf("ukbd: id=%d kind=%d usage=0x%x flags=0x%x pos=%d size=%d cnt=%d\n",
|
|
|
|
h.report_ID, h.kind, h.usage, h.flags, h.loc.pos, h.loc.size, h.loc.count);*/
|
|
|
|
if (h.kind != hid_input || (h.flags & HIO_CONST) ||
|
|
|
|
HID_GET_USAGE_PAGE(h.usage) != HUP_KEYBOARD ||
|
|
|
|
h.report_ID != sc->sc_hdev.sc_report_id)
|
|
|
|
continue;
|
2001-12-30 22:37:43 +03:00
|
|
|
DPRINTF(("ukbd: imod=%d usage=0x%x flags=0x%x pos=%d size=%d "
|
|
|
|
"cnt=%d\n", imod,
|
|
|
|
h.usage, h.flags, h.loc.pos, h.loc.size, h.loc.count));
|
2001-12-28 20:32:36 +03:00
|
|
|
if (h.flags & HIO_VARIABLE) {
|
2001-12-31 15:15:21 +03:00
|
|
|
if (h.loc.size != 1)
|
|
|
|
return ("bad modifier size");
|
2001-12-28 20:32:36 +03:00
|
|
|
/* Single item */
|
|
|
|
if (imod < MAXMOD) {
|
|
|
|
sc->sc_modloc[imod] = h.loc;
|
|
|
|
sc->sc_mods[imod].mask = 1 << imod;
|
|
|
|
sc->sc_mods[imod].key = HID_GET_USAGE(h.usage);
|
|
|
|
imod++;
|
|
|
|
} else
|
|
|
|
return ("too many modifier keys");
|
|
|
|
} else {
|
|
|
|
/* Array */
|
|
|
|
if (h.loc.size != 8)
|
|
|
|
return ("key code size != 8");
|
|
|
|
if (h.loc.count > MAXKEYCODE)
|
|
|
|
return ("too many key codes");
|
|
|
|
if (h.loc.pos % 8 != 0)
|
|
|
|
return ("key codes not on byte boundary");
|
|
|
|
if (sc->sc_nkeycode != 0)
|
|
|
|
return ("multiple key code arrays\n");
|
|
|
|
sc->sc_keycodeloc = h.loc;
|
|
|
|
sc->sc_nkeycode = h.loc.count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->sc_nmod = imod;
|
|
|
|
hid_end_parse(d);
|
|
|
|
|
|
|
|
hid_locate(desc, size, HID_USAGE2(HUP_LEDS, HUD_LED_NUM_LOCK),
|
|
|
|
sc->sc_hdev.sc_report_id, hid_output, &sc->sc_numloc, NULL);
|
|
|
|
hid_locate(desc, size, HID_USAGE2(HUP_LEDS, HUD_LED_CAPS_LOCK),
|
|
|
|
sc->sc_hdev.sc_report_id, hid_output, &sc->sc_capsloc, NULL);
|
|
|
|
hid_locate(desc, size, HID_USAGE2(HUP_LEDS, HUD_LED_SCROLL_LOCK),
|
|
|
|
sc->sc_hdev.sc_report_id, hid_output, &sc->sc_scroloc, NULL);
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|