2008-05-24 20:40:58 +04:00
|
|
|
/* $NetBSD: ums.c,v 1.73 2008/05/24 16:40:58 cube 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1999-01-10 14:13:36 +03:00
|
|
|
/*
|
2003-03-11 19:44:00 +03:00
|
|
|
* HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
|
1999-01-10 14:13:36 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-13 09:24:53 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-05-24 20:40:58 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ums.c,v 1.73 2008/05/24 16:40:58 cube 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>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.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>
|
|
|
|
#include <dev/usb/usbhid.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
|
|
|
#include <dev/usb/usbdevs.h>
|
|
|
|
#include <dev/usb/usb_quirks.h>
|
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>
|
|
|
|
|
1998-07-25 05:46:38 +04:00
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wsmousevar.h>
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
#ifdef USB_DEBUG
|
1999-08-14 18:49:31 +04:00
|
|
|
#define DPRINTF(x) if (umsdebug) logprintf x
|
|
|
|
#define DPRINTFN(n,x) if (umsdebug>(n)) logprintf x
|
1998-07-12 23:51:55 +04:00
|
|
|
int umsdebug = 0;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
1999-08-17 03:36:25 +04:00
|
|
|
#define UMS_BUT(i) ((i) == 1 || (i) == 2 ? 3 - (i) : i)
|
|
|
|
|
|
|
|
#define UMSUNIT(s) (minor(s))
|
1998-12-26 15:53:00 +03:00
|
|
|
|
|
|
|
#define PS2LBUTMASK x01
|
|
|
|
#define PS2RBUTMASK x02
|
|
|
|
#define PS2MBUTMASK x04
|
1998-07-12 23:51:55 +04:00
|
|
|
#define PS2BUTMASK 0x0f
|
|
|
|
|
2005-08-13 18:55:39 +04:00
|
|
|
#define MAX_BUTTONS 31 /* must not exceed size of sc_buttons */
|
2001-12-28 20:32:36 +03:00
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
struct ums_softc {
|
2001-12-28 20:32:36 +03:00
|
|
|
struct uhidev sc_hdev;
|
|
|
|
|
2005-11-23 12:41:28 +03:00
|
|
|
struct hid_location sc_loc_x, sc_loc_y, sc_loc_z, sc_loc_w;
|
2001-12-28 20:32:36 +03:00
|
|
|
struct hid_location sc_loc_btn[MAX_BUTTONS];
|
1998-07-12 23:51:55 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
int sc_enabled;
|
1998-07-25 05:46:38 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
int flags; /* device configuration */
|
|
|
|
#define UMS_Z 0x01 /* z direction available */
|
1999-11-16 01:04:14 +03:00
|
|
|
#define UMS_SPUR_BUT_UP 0x02 /* spurious button up events */
|
|
|
|
#define UMS_REVZ 0x04 /* Z-axis is reversed */
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
int nbuttons;
|
|
|
|
|
1999-08-17 03:36:25 +04:00
|
|
|
u_int32_t sc_buttons; /* mouse button status */
|
2008-02-18 08:24:24 +03:00
|
|
|
device_t sc_wsmousedev;
|
1999-08-24 02:55:14 +04:00
|
|
|
|
|
|
|
char sc_dying;
|
1998-07-12 23:51:55 +04:00
|
|
|
};
|
|
|
|
|
1998-07-25 00:59:57 +04:00
|
|
|
#define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
|
|
|
|
#define MOUSE_FLAGS (HIO_RELATIVE)
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
Static void ums_intr(struct uhidev *addr, void *ibuf, u_int len);
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2000-06-01 18:28:57 +04:00
|
|
|
Static int ums_enable(void *);
|
|
|
|
Static void ums_disable(void *);
|
2007-03-04 08:59:00 +03:00
|
|
|
Static int ums_ioctl(void *, u_long, void *, int, struct lwp * );
|
1998-07-25 05:46:38 +04:00
|
|
|
|
|
|
|
const struct wsmouse_accessops ums_accessops = {
|
|
|
|
ums_enable,
|
|
|
|
ums_ioctl,
|
|
|
|
ums_disable,
|
|
|
|
};
|
|
|
|
|
2008-05-24 20:40:58 +04:00
|
|
|
int ums_match(device_t, cfdata_t, void *);
|
2008-02-18 08:24:24 +03:00
|
|
|
void ums_attach(device_t, device_t, void *);
|
|
|
|
void ums_childdet(device_t, device_t);
|
|
|
|
int ums_detach(device_t, int);
|
|
|
|
int ums_activate(device_t, enum devact);
|
|
|
|
extern struct cfdriver ums_cd;
|
2008-05-24 20:40:58 +04:00
|
|
|
CFATTACH_DECL2_NEW(ums, sizeof(struct ums_softc), ums_match, ums_attach,
|
2008-02-18 08:24:24 +03:00
|
|
|
ums_detach, ums_activate, NULL, ums_childdet);
|
1998-12-26 15:53:00 +03:00
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
int
|
2008-05-24 20:40:58 +04:00
|
|
|
ums_match(device_t parent, cfdata_t 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;
|
1998-07-12 23:51:55 +04:00
|
|
|
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_MOUSE)))
|
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
|
2008-05-24 20:40:58 +04:00
|
|
|
ums_attach(device_t parent, device_t self, void *aux)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2008-05-24 20:40:58 +04:00
|
|
|
struct ums_softc *sc = device_private(self);
|
2001-12-28 20:32:36 +03:00
|
|
|
struct uhidev_attach_arg *uha = aux;
|
1998-07-25 05:46:38 +04:00
|
|
|
struct wsmousedev_attach_args a;
|
1998-07-12 23:51:55 +04:00
|
|
|
int size;
|
|
|
|
void *desc;
|
1999-11-16 01:04:14 +03:00
|
|
|
u_int32_t flags, quirks;
|
1999-12-24 04:14:01 +03:00
|
|
|
int i, wheel;
|
1998-12-26 15:53:00 +03:00
|
|
|
struct hid_location loc_btn;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_naive("\n");
|
|
|
|
|
2008-05-24 20:40:58 +04:00
|
|
|
sc->sc_hdev.sc_dev = self;
|
2001-12-28 20:32:36 +03:00
|
|
|
sc->sc_hdev.sc_intr = ums_intr;
|
|
|
|
sc->sc_hdev.sc_parent = uha->parent;
|
|
|
|
sc->sc_hdev.sc_report_id = uha->reportid;
|
1998-07-12 23:51:55 +04:00
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
quirks = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
|
1999-11-16 01:04:14 +03:00
|
|
|
if (quirks & UQ_MS_REVZ)
|
|
|
|
sc->flags |= UMS_REVZ;
|
|
|
|
if (quirks & UQ_SPUR_BUT_UP)
|
|
|
|
sc->flags |= UMS_SPUR_BUT_UP;
|
1999-06-26 04:09:15 +04:00
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
uhidev_get_report_desc(uha->parent, &desc, &size);
|
1998-12-26 15:53:00 +03:00
|
|
|
|
2007-12-11 06:45:57 +03:00
|
|
|
if (!pmf_device_register(self, NULL, NULL))
|
|
|
|
aprint_error_dev(self, "couldn't establish power handler\n");
|
|
|
|
|
1998-07-25 00:59:57 +04:00
|
|
|
if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
|
2001-12-28 20:32:36 +03:00
|
|
|
uha->reportid, hid_input, &sc->sc_loc_x, &flags)) {
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_error("\n%s: mouse has no X report\n",
|
2001-12-28 20:32:36 +03:00
|
|
|
USBDEVNAME(sc->sc_hdev.sc_dev));
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
|
|
|
}
|
|
|
|
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_error("\n%s: X report 0x%04x not supported\n",
|
2001-12-28 20:32:36 +03:00
|
|
|
USBDEVNAME(sc->sc_hdev.sc_dev), flags);
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
1998-11-21 21:57:09 +03:00
|
|
|
|
1998-07-25 00:59:57 +04:00
|
|
|
if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
|
2001-12-28 20:32:36 +03:00
|
|
|
uha->reportid, hid_input, &sc->sc_loc_y, &flags)) {
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_error("\n%s: mouse has no Y report\n",
|
2001-12-28 20:32:36 +03:00
|
|
|
USBDEVNAME(sc->sc_hdev.sc_dev));
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
|
|
|
}
|
|
|
|
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_error("\n%s: Y report 0x%04x not supported\n",
|
2001-12-28 20:32:36 +03:00
|
|
|
USBDEVNAME(sc->sc_hdev.sc_dev), flags);
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
1998-11-21 21:57:09 +03:00
|
|
|
|
2005-11-23 12:41:28 +03:00
|
|
|
/* Try the wheel first as the Z activator since it's tradition. */
|
|
|
|
wheel = hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
|
|
|
|
HUG_WHEEL),
|
|
|
|
uha->reportid, hid_input, &sc->sc_loc_z, &flags);
|
|
|
|
if (wheel) {
|
1998-12-26 15:53:00 +03:00
|
|
|
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_verbose("\n%s: Wheel report 0x%04x not "
|
|
|
|
"supported\n", USBDEVNAME(sc->sc_hdev.sc_dev),
|
|
|
|
flags);
|
1998-12-26 15:53:00 +03:00
|
|
|
sc->sc_loc_z.size = 0; /* Bad Z coord, ignore it */
|
|
|
|
} else {
|
|
|
|
sc->flags |= UMS_Z;
|
1999-12-24 04:14:01 +03:00
|
|
|
/* Wheels need the Z axis reversed. */
|
2005-11-23 12:41:28 +03:00
|
|
|
sc->flags ^= UMS_REVZ;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We might have both a wheel and Z direction, if so put
|
|
|
|
* put the Z on the W coordinate.
|
|
|
|
*/
|
|
|
|
if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
|
|
|
|
HUG_Z),
|
|
|
|
uha->reportid, hid_input, &sc->sc_loc_w, &flags)) {
|
|
|
|
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_verbose("\n%s: Z report 0x%04x not "
|
|
|
|
"supported\n",
|
2005-11-23 12:41:28 +03:00
|
|
|
USBDEVNAME(sc->sc_hdev.sc_dev), flags);
|
|
|
|
sc->sc_loc_w.size = 0; /* Bad Z, ignore */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
|
|
|
|
HUG_Z),
|
|
|
|
uha->reportid, hid_input, &sc->sc_loc_z, &flags)) {
|
|
|
|
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_verbose("\n%s: Z report 0x%04x not supported\n",
|
2005-11-23 12:41:28 +03:00
|
|
|
USBDEVNAME(sc->sc_hdev.sc_dev), flags);
|
|
|
|
sc->sc_loc_z.size = 0; /* Bad Z coord, ignore it */
|
|
|
|
} else {
|
|
|
|
sc->flags |= UMS_Z;
|
1998-12-26 15:53:00 +03:00
|
|
|
}
|
1998-07-29 01:21:47 +04:00
|
|
|
}
|
|
|
|
|
2005-11-23 12:41:28 +03:00
|
|
|
|
1999-01-10 22:13:15 +03:00
|
|
|
/* figure out the number of buttons */
|
|
|
|
for (i = 1; i <= MAX_BUTTONS; i++)
|
1998-12-26 15:53:00 +03:00
|
|
|
if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
|
2001-12-28 20:32:36 +03:00
|
|
|
uha->reportid, hid_input, &loc_btn, 0))
|
1998-12-26 15:53:00 +03:00
|
|
|
break;
|
|
|
|
sc->nbuttons = i - 1;
|
|
|
|
|
2007-12-02 02:40:28 +03:00
|
|
|
aprint_normal(": %d button%s%s\n",
|
2000-10-09 00:52:18 +04:00
|
|
|
sc->nbuttons, sc->nbuttons == 1 ? "" : "s",
|
|
|
|
sc->flags & UMS_Z ? " and Z dir." : "");
|
1998-12-26 15:53:00 +03:00
|
|
|
|
|
|
|
for (i = 1; i <= sc->nbuttons; i++)
|
|
|
|
hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
|
2001-12-28 20:32:36 +03:00
|
|
|
uha->reportid, hid_input,
|
|
|
|
&sc->sc_loc_btn[i-1], 0);
|
1998-07-25 05:46:38 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
#ifdef USB_DEBUG
|
|
|
|
DPRINTF(("ums_attach: sc=%p\n", sc));
|
2002-07-12 01:14:24 +04:00
|
|
|
DPRINTF(("ums_attach: X\t%d/%d\n",
|
1998-12-26 15:53:00 +03:00
|
|
|
sc->sc_loc_x.pos, sc->sc_loc_x.size));
|
2002-07-12 01:14:24 +04:00
|
|
|
DPRINTF(("ums_attach: Y\t%d/%d\n",
|
2001-10-25 17:45:16 +04:00
|
|
|
sc->sc_loc_y.pos, sc->sc_loc_y.size));
|
1998-12-26 15:53:00 +03:00
|
|
|
if (sc->flags & UMS_Z)
|
2002-07-12 01:14:24 +04:00
|
|
|
DPRINTF(("ums_attach: Z\t%d/%d\n",
|
1998-12-26 15:53:00 +03:00
|
|
|
sc->sc_loc_z.pos, sc->sc_loc_z.size));
|
|
|
|
for (i = 1; i <= sc->nbuttons; i++) {
|
|
|
|
DPRINTF(("ums_attach: B%d\t%d/%d\n",
|
|
|
|
i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-25 05:46:38 +04:00
|
|
|
a.accessops = &ums_accessops;
|
|
|
|
a.accesscookie = sc;
|
|
|
|
|
2001-01-23 17:04:13 +03:00
|
|
|
sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
|
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
USB_ATTACH_SUCCESS_RETURN;
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
int
|
2000-06-01 18:28:57 +04:00
|
|
|
ums_activate(device_ptr_t self, enum devact act)
|
1998-12-26 15:53:00 +03:00
|
|
|
{
|
2008-05-24 20:40:58 +04:00
|
|
|
struct ums_softc *sc = device_private(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_wsmousedev != NULL)
|
1999-09-12 12:21:49 +04:00
|
|
|
rv = config_deactivate(sc->sc_wsmousedev);
|
1999-08-24 02:55:14 +04:00
|
|
|
sc->sc_dying = 1;
|
|
|
|
break;
|
|
|
|
}
|
1999-09-12 12:21:49 +04:00
|
|
|
return (rv);
|
1998-12-26 15:53:00 +03:00
|
|
|
}
|
|
|
|
|
2008-02-18 08:24:24 +03:00
|
|
|
void
|
|
|
|
ums_childdet(device_t self, device_t child)
|
|
|
|
{
|
|
|
|
struct ums_softc *sc = device_private(self);
|
|
|
|
|
|
|
|
KASSERT(sc->sc_wsmousedev == child);
|
|
|
|
sc->sc_wsmousedev = NULL;
|
|
|
|
}
|
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
int
|
2008-02-18 08:24:24 +03:00
|
|
|
ums_detach(device_t self, int flags)
|
1998-07-12 23:51:55 +04:00
|
|
|
{
|
2008-02-18 08:24:24 +03:00
|
|
|
struct ums_softc *sc = device_private(self);
|
1999-06-30 10:44:22 +04:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
DPRINTF(("ums_detach: sc=%p flags=%d\n", sc, flags));
|
1999-10-13 12:10:55 +04:00
|
|
|
|
2001-11-07 17:13:35 +03:00
|
|
|
/* No need to do reference counting of ums, wsmouse has all the goo. */
|
|
|
|
if (sc->sc_wsmousedev != NULL)
|
|
|
|
rv = config_detach(sc->sc_wsmousedev, flags);
|
2000-02-02 16:18:45 +03:00
|
|
|
|
2007-12-11 06:45:57 +03:00
|
|
|
pmf_device_deregister(self);
|
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
return (rv);
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-11-16 04:32:37 +03:00
|
|
|
ums_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 ums_softc *sc = (struct ums_softc *)addr;
|
2005-11-23 12:41:28 +03:00
|
|
|
int dx, dy, dz, dw;
|
1999-08-17 03:36:25 +04:00
|
|
|
u_int32_t buttons = 0;
|
1998-12-26 15:53:00 +03:00
|
|
|
int i;
|
1999-05-09 19:10:30 +04:00
|
|
|
int s;
|
1999-01-10 22:13:15 +03:00
|
|
|
|
2001-12-29 19:15:42 +03:00
|
|
|
DPRINTFN(5,("ums_intr: len=%d\n", len));
|
|
|
|
|
1998-07-12 23:51:55 +04:00
|
|
|
dx = hid_get_data(ibuf, &sc->sc_loc_x);
|
|
|
|
dy = -hid_get_data(ibuf, &sc->sc_loc_y);
|
1998-07-29 01:21:47 +04:00
|
|
|
dz = hid_get_data(ibuf, &sc->sc_loc_z);
|
2005-11-23 12:41:28 +03:00
|
|
|
dw = hid_get_data(ibuf, &sc->sc_loc_w);
|
1999-11-16 01:04:14 +03:00
|
|
|
if (sc->flags & UMS_REVZ)
|
1999-06-26 04:09:15 +04:00
|
|
|
dz = -dz;
|
1998-12-26 15:53:00 +03:00
|
|
|
for (i = 0; i < sc->nbuttons; i++)
|
|
|
|
if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
|
|
|
|
buttons |= (1 << UMS_BUT(i));
|
|
|
|
|
2005-11-23 12:41:28 +03:00
|
|
|
if (dx != 0 || dy != 0 || dz != 0 || dw != 0 ||
|
|
|
|
buttons != sc->sc_buttons) {
|
|
|
|
DPRINTFN(10, ("ums_intr: x:%d y:%d z:%d w:%d buttons:0x%x\n",
|
|
|
|
dx, dy, dz, dw, buttons));
|
1998-07-27 22:51:32 +04:00
|
|
|
sc->sc_buttons = buttons;
|
1999-11-16 01:04:14 +03:00
|
|
|
if (sc->sc_wsmousedev != NULL) {
|
1999-05-09 19:10:30 +04:00
|
|
|
s = spltty();
|
2006-11-12 22:00:42 +03:00
|
|
|
wsmouse_input(sc->sc_wsmousedev,
|
|
|
|
buttons,
|
|
|
|
dx, dy, dz, dw,
|
|
|
|
WSMOUSE_INPUT_DELTA);
|
1999-05-09 19:10:30 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
1998-07-12 23:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
1998-07-25 05:46:38 +04:00
|
|
|
|
2000-03-27 16:33:53 +04:00
|
|
|
Static int
|
2000-06-01 18:28:57 +04:00
|
|
|
ums_enable(void *v)
|
1998-07-25 05:46:38 +04:00
|
|
|
{
|
|
|
|
struct ums_softc *sc = v;
|
1998-12-26 15:53:00 +03:00
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
DPRINTFN(1,("ums_enable: sc=%p\n", sc));
|
1999-08-24 02:55:14 +04:00
|
|
|
|
|
|
|
if (sc->sc_dying)
|
|
|
|
return (EIO);
|
|
|
|
|
1998-07-25 05:46:38 +04:00
|
|
|
if (sc->sc_enabled)
|
1999-08-24 02:55:14 +04:00
|
|
|
return (EBUSY);
|
1998-07-25 05:46:38 +04:00
|
|
|
|
|
|
|
sc->sc_enabled = 1;
|
1998-07-27 22:51:32 +04:00
|
|
|
sc->sc_buttons = 0;
|
1998-07-25 05:46:38 +04:00
|
|
|
|
2001-12-28 20:32:36 +03:00
|
|
|
return (uhidev_open(&sc->sc_hdev));
|
1998-07-25 05:46:38 +04:00
|
|
|
}
|
|
|
|
|
2000-03-27 16:33:53 +04:00
|
|
|
Static void
|
2000-06-01 18:28:57 +04:00
|
|
|
ums_disable(void *v)
|
1998-07-25 05:46:38 +04:00
|
|
|
{
|
|
|
|
struct ums_softc *sc = v;
|
|
|
|
|
1999-06-30 10:44:22 +04:00
|
|
|
DPRINTFN(1,("ums_disable: sc=%p\n", sc));
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (!sc->sc_enabled) {
|
|
|
|
printf("ums_disable: not enabled\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-25 05:46:38 +04:00
|
|
|
sc->sc_enabled = 0;
|
2002-09-23 09:59:01 +04:00
|
|
|
uhidev_close(&sc->sc_hdev);
|
1998-07-25 05:46:38 +04:00
|
|
|
}
|
|
|
|
|
2000-03-27 16:33:53 +04:00
|
|
|
Static int
|
2007-03-04 08:59:00 +03:00
|
|
|
ums_ioctl(void *v, u_long cmd, void *data, int flag,
|
2006-11-16 04:32:37 +03:00
|
|
|
struct lwp * p)
|
1998-07-25 05:46:38 +04:00
|
|
|
|
1998-12-26 15:53:00 +03:00
|
|
|
{
|
1998-07-25 05:46:38 +04:00
|
|
|
switch (cmd) {
|
|
|
|
case WSMOUSEIO_GTYPE:
|
1998-12-30 16:14:21 +03:00
|
|
|
*(u_int *)data = WSMOUSE_TYPE_USB;
|
1998-07-25 05:46:38 +04:00
|
|
|
return (0);
|
|
|
|
}
|
1998-12-26 15:53:00 +03:00
|
|
|
|
2002-03-17 22:40:26 +03:00
|
|
|
return (EPASSTHROUGH);
|
1998-07-25 05:46:38 +04:00
|
|
|
}
|