summaryrefslogtreecommitdiff
path: root/sys/dev/usb/ums.c
diff options
context:
space:
mode:
authorNathan Binkert <nate@cvs.openbsd.org>2002-05-07 18:08:06 +0000
committerNathan Binkert <nate@cvs.openbsd.org>2002-05-07 18:08:06 +0000
commit98e3a0a3b6a5b0271467c9f199a555d22161f072 (patch)
tree04221a5a893956a1fe82881463802b2e507063b3 /sys/dev/usb/ums.c
parent3a7a8acd4f0393073cd00591e53b1b8a4eb1bd60 (diff)
Sync ulpt driver with NetBSD
Diffstat (limited to 'sys/dev/usb/ums.c')
-rw-r--r--sys/dev/usb/ums.c197
1 files changed, 44 insertions, 153 deletions
diff --git a/sys/dev/usb/ums.c b/sys/dev/usb/ums.c
index 8505da52f67..d2b058ca11e 100644
--- a/sys/dev/usb/ums.c
+++ b/sys/dev/usb/ums.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: ums.c,v 1.6 2001/10/31 04:24:44 nate Exp $ */
-/* $NetBSD: ums.c,v 1.49 2001/10/26 17:58:21 augustss Exp $ */
+/* $OpenBSD: ums.c,v 1.7 2002/05/07 18:08:04 nate Exp $ */
+/* $NetBSD: ums.c,v 1.55 2001/12/31 12:15:22 augustss Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -42,8 +42,6 @@
* HID spec: http://www.usb.org/developers/data/devclass/hid1_1.pdf
*/
-/* XXX complete SPUR_UP change */
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@@ -64,6 +62,7 @@
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbdevs.h>
#include <dev/usb/usb_quirks.h>
+#include <dev/usb/uhidev.h>
#include <dev/usb/hid.h>
#include <dev/wscons/wsconsio.h>
@@ -87,18 +86,13 @@ int umsdebug = 0;
#define PS2MBUTMASK x04
#define PS2BUTMASK 0x0f
+#define MAX_BUTTONS 7 /* must not exceed size of sc_buttons */
+
struct ums_softc {
- USBBASEDEVICE sc_dev; /* base device */
- usbd_device_handle sc_udev;
- usbd_interface_handle sc_iface; /* interface */
- usbd_pipe_handle sc_intrpipe; /* interrupt pipe */
- int sc_ep_addr;
-
- u_char *sc_ibuf;
- u_int8_t sc_iid;
- int sc_isize;
+ struct uhidev sc_hdev;
+
struct hid_location sc_loc_x, sc_loc_y, sc_loc_z;
- struct hid_location *sc_loc_btn;
+ struct hid_location sc_loc_btn[MAX_BUTTONS];
int sc_enabled;
@@ -108,7 +102,6 @@ struct ums_softc {
#define UMS_REVZ 0x04 /* Z-axis is reversed */
int nbuttons;
-#define MAX_BUTTONS 31 /* chosen because sc_buttons is u_int32_t */
u_int32_t sc_buttons; /* mouse button status */
struct device *sc_wsmousedev;
@@ -119,11 +112,11 @@ struct ums_softc {
#define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
#define MOUSE_FLAGS (HIO_RELATIVE)
-Static void ums_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
+Static void ums_intr(struct uhidev *addr, void *ibuf, u_int len);
Static int ums_enable(void *);
Static void ums_disable(void *);
-Static int ums_ioctl(void *, u_long, caddr_t, int, struct proc *);
+Static int ums_ioctl(void *, u_long, caddr_t, int, usb_proc_ptr);
const struct wsmouse_accessops ums_accessops = {
ums_enable,
@@ -136,115 +129,72 @@ USB_DECLARE_DRIVER(ums);
USB_MATCH(ums)
{
USB_MATCH_START(ums, uaa);
- usb_interface_descriptor_t *id;
- int size, ret;
+ struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)uaa;
+ int size;
void *desc;
- usbd_status err;
- if (uaa->iface == NULL)
- return (UMATCH_NONE);
- id = usbd_get_interface_descriptor(uaa->iface);
- if (id == NULL || id->bInterfaceClass != UICLASS_HID)
+ uhidev_get_report_desc(uha->parent, &desc, &size);
+ if (!hid_is_collection(desc, size, uha->reportid,
+ HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)))
return (UMATCH_NONE);
- err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP);
- if (err)
- return (UMATCH_NONE);
-
- if (hid_is_collection(desc, size,
- HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)))
- ret = UMATCH_IFACECLASS;
- else
- ret = UMATCH_NONE;
-
- free(desc, M_TEMP);
- return (ret);
+ return (UMATCH_IFACECLASS);
}
USB_ATTACH(ums)
{
USB_ATTACH_START(ums, sc, uaa);
- usbd_interface_handle iface = uaa->iface;
- usb_interface_descriptor_t *id;
- usb_endpoint_descriptor_t *ed;
+ struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)uaa;
struct wsmousedev_attach_args a;
int size;
void *desc;
- usbd_status err;
- char devinfo[1024];
u_int32_t flags, quirks;
int i, wheel;
struct hid_location loc_btn;
-
- sc->sc_udev = uaa->device;
- sc->sc_iface = iface;
- id = usbd_get_interface_descriptor(iface);
- usbd_devinfo(uaa->device, 0, devinfo);
- USB_ATTACH_SETUP;
- printf("%s: %s, iclass %d/%d\n", USBDEVNAME(sc->sc_dev),
- devinfo, id->bInterfaceClass, id->bInterfaceSubClass);
- ed = usbd_interface2endpoint_descriptor(iface, 0);
- if (ed == NULL) {
- printf("%s: could not read endpoint descriptor\n",
- USBDEVNAME(sc->sc_dev));
- USB_ATTACH_ERROR_RETURN;
- }
- DPRINTFN(10,("ums_attach: bLength=%d bDescriptorType=%d "
- "bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d"
- " bInterval=%d\n",
- ed->bLength, ed->bDescriptorType,
- ed->bEndpointAddress & UE_ADDR,
- UE_GET_DIR(ed->bEndpointAddress)==UE_DIR_IN? "in" : "out",
- ed->bmAttributes & UE_XFERTYPE,
- UGETW(ed->wMaxPacketSize), ed->bInterval));
-
- if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
- (ed->bmAttributes & UE_XFERTYPE) != UE_INTERRUPT) {
- printf("%s: unexpected endpoint\n",
- USBDEVNAME(sc->sc_dev));
- USB_ATTACH_ERROR_RETURN;
- }
+ sc->sc_hdev.sc_intr = ums_intr;
+ sc->sc_hdev.sc_parent = uha->parent;
+ sc->sc_hdev.sc_report_id = uha->reportid;
- quirks = usbd_get_quirks(uaa->device)->uq_flags;
+ quirks = usbd_get_quirks(uha->parent->sc_udev)->uq_flags;
if (quirks & UQ_MS_REVZ)
sc->flags |= UMS_REVZ;
if (quirks & UQ_SPUR_BUT_UP)
sc->flags |= UMS_SPUR_BUT_UP;
- err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP);
- if (err)
- USB_ATTACH_ERROR_RETURN;
+ uhidev_get_report_desc(uha->parent, &desc, &size);
if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
- hid_input, &sc->sc_loc_x, &flags)) {
- printf("%s: mouse has no X report\n", USBDEVNAME(sc->sc_dev));
+ uha->reportid, hid_input, &sc->sc_loc_x, &flags)) {
+ printf("\n%s: mouse has no X report\n",
+ USBDEVNAME(sc->sc_hdev.sc_dev));
USB_ATTACH_ERROR_RETURN;
}
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
- printf("%s: X report 0x%04x not supported\n",
- USBDEVNAME(sc->sc_dev), flags);
+ printf("\n%s: X report 0x%04x not supported\n",
+ USBDEVNAME(sc->sc_hdev.sc_dev), flags);
USB_ATTACH_ERROR_RETURN;
}
if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
- hid_input, &sc->sc_loc_y, &flags)) {
- printf("%s: mouse has no Y report\n", USBDEVNAME(sc->sc_dev));
+ uha->reportid, hid_input, &sc->sc_loc_y, &flags)) {
+ printf("\n%s: mouse has no Y report\n",
+ USBDEVNAME(sc->sc_hdev.sc_dev));
USB_ATTACH_ERROR_RETURN;
}
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
- printf("%s: Y report 0x%04x not supported\n",
- USBDEVNAME(sc->sc_dev), flags);
+ printf("\n%s: Y report 0x%04x not supported\n",
+ USBDEVNAME(sc->sc_hdev.sc_dev), flags);
USB_ATTACH_ERROR_RETURN;
}
/* Try to guess the Z activator: first check Z, then WHEEL. */
wheel = 0;
if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
- hid_input, &sc->sc_loc_z, &flags) ||
+ uha->reportid, hid_input, &sc->sc_loc_z, &flags) ||
(wheel = hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
HUG_WHEEL),
- hid_input, &sc->sc_loc_z, &flags))) {
+ uha->reportid, hid_input, &sc->sc_loc_z, &flags))) {
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
sc->sc_loc_z.size = 0; /* Bad Z coord, ignore it */
} else {
@@ -258,34 +208,18 @@ USB_ATTACH(ums)
/* figure out the number of buttons */
for (i = 1; i <= MAX_BUTTONS; i++)
if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
- hid_input, &loc_btn, 0))
+ uha->reportid, hid_input, &loc_btn, 0))
break;
sc->nbuttons = i - 1;
- sc->sc_loc_btn = malloc(sizeof(struct hid_location) * sc->nbuttons,
- M_USBDEV, M_NOWAIT);
- if (!sc->sc_loc_btn) {
- printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
- USB_ATTACH_ERROR_RETURN;
- }
- printf("%s: %d button%s%s\n", USBDEVNAME(sc->sc_dev),
+ printf(": %d button%s%s\n",
sc->nbuttons, sc->nbuttons == 1 ? "" : "s",
sc->flags & UMS_Z ? " and Z dir." : "");
for (i = 1; i <= sc->nbuttons; i++)
hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
- hid_input, &sc->sc_loc_btn[i-1], 0);
-
- sc->sc_isize = hid_report_size(desc, size, hid_input, &sc->sc_iid);
- sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_NOWAIT);
- if (sc->sc_ibuf == NULL) {
- printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
- free(sc->sc_loc_btn, M_USBDEV);
- USB_ATTACH_ERROR_RETURN;
- }
-
- sc->sc_ep_addr = ed->bEndpointAddress;
- free(desc, M_TEMP);
+ uha->reportid, hid_input,
+ &sc->sc_loc_btn[i-1], 0);
#ifdef USB_DEBUG
DPRINTF(("ums_attach: sc=%p\n", sc));
@@ -300,15 +234,11 @@ USB_ATTACH(ums)
DPRINTF(("ums_attach: B%d\t%d/%d\n",
i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size));
}
- DPRINTF(("ums_attach: size=%d, id=%d\n", sc->sc_isize, sc->sc_iid));
#endif
a.accessops = &ums_accessops;
a.accesscookie = sc;
- usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
- USBDEV(sc->sc_dev));
-
sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
USB_ATTACH_SUCCESS_RETURN;
@@ -344,45 +274,21 @@ USB_DETACH(ums)
/* 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);
- if (rv == 0) {
- free(sc->sc_loc_btn, M_USBDEV);
- free(sc->sc_ibuf, M_USBDEV);
- }
-
- usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
- USBDEV(sc->sc_dev));
return (rv);
}
void
-ums_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
+ums_intr(struct uhidev *addr, void *ibuf, u_int len)
{
- struct ums_softc *sc = addr;
- u_char *ibuf;
+ struct ums_softc *sc = (struct ums_softc *)addr;
int dx, dy, dz;
u_int32_t buttons = 0;
int i;
int s;
- DPRINTFN(5, ("ums_intr: sc=%p status=%d\n", sc, status));
- DPRINTFN(5, ("ums_intr: data = %02x %02x %02x\n",
- sc->sc_ibuf[0], sc->sc_ibuf[1], sc->sc_ibuf[2]));
-
- if (status == USBD_CANCELLED)
- return;
-
- if (status) {
- DPRINTF(("ums_intr: status=%d\n", status));
- usbd_clear_endpoint_stall_async(sc->sc_intrpipe);
- return;
- }
+ DPRINTFN(5,("ums_intr: len=%d\n", len));
- ibuf = sc->sc_ibuf;
- if (sc->sc_iid != 0) {
- if (*ibuf++ != sc->sc_iid)
- return;
- }
dx = hid_get_data(ibuf, &sc->sc_loc_x);
dy = -hid_get_data(ibuf, &sc->sc_loc_y);
dz = hid_get_data(ibuf, &sc->sc_loc_z);
@@ -410,8 +316,6 @@ ums_enable(void *v)
{
struct ums_softc *sc = v;
- usbd_status err;
-
DPRINTFN(1,("ums_enable: sc=%p\n", sc));
if (sc->sc_dying)
@@ -423,17 +327,7 @@ ums_enable(void *v)
sc->sc_enabled = 1;
sc->sc_buttons = 0;
- /* Set up interrupt pipe. */
- err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
- USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc,
- sc->sc_ibuf, sc->sc_isize, ums_intr, USBD_DEFAULT_INTERVAL);
- if (err) {
- DPRINTF(("ums_enable: usbd_open_pipe_intr failed, error=%d\n",
- err));
- sc->sc_enabled = 0;
- return (EIO);
- }
- return (0);
+ return (uhidev_open(&sc->sc_hdev));
}
Static void
@@ -449,15 +343,12 @@ ums_disable(void *v)
}
#endif
- /* Disable interrupts. */
- usbd_abort_pipe(sc->sc_intrpipe);
- usbd_close_pipe(sc->sc_intrpipe);
-
sc->sc_enabled = 0;
+ return (uhidev_close(&sc->sc_hdev));
}
Static int
-ums_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
+ums_ioctl(void *v, u_long cmd, caddr_t data, int flag, usb_proc_ptr p)
{
switch (cmd) {