1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1999-01-07 23:07:57 +00:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-05-14 16:43:10 +00:00
|
|
|
* by Lennart Augustsson (lennart@augustsson.net) at
|
1999-01-07 23:07:57 +00:00
|
|
|
* Carlstedt Research & Technology.
|
1998-11-26 23:13:13 +00: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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-05-01 13:17:47 +00:00
|
|
|
/*
|
2004-05-23 17:09:07 +00:00
|
|
|
* HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
|
1999-05-01 13:17:47 +00:00
|
|
|
*/
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/file.h>
|
2001-01-09 04:33:49 +00:00
|
|
|
#if __FreeBSD_version >= 500014
|
|
|
|
#include <sys/selinfo.h>
|
|
|
|
#else
|
1998-11-26 23:13:13 +00:00
|
|
|
#include <sys/select.h>
|
2001-01-09 04:33:49 +00:00
|
|
|
#endif
|
1998-11-26 23:13:13 +00:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/poll.h>
|
2002-07-31 13:33:55 +00:00
|
|
|
#include <sys/sysctl.h>
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
#include <dev/usb/usbhid.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
2004-06-27 12:41:44 +00:00
|
|
|
#include "usbdevs.h"
|
1998-11-26 23:13:13 +00:00
|
|
|
#include <dev/usb/usb_quirks.h>
|
|
|
|
#include <dev/usb/hid.h>
|
|
|
|
|
2003-10-04 21:41:01 +00:00
|
|
|
#if __FreeBSD_version >= 500000
|
2000-10-09 08:08:36 +00:00
|
|
|
#include <sys/mouse.h>
|
2003-10-04 21:41:01 +00:00
|
|
|
#else
|
|
|
|
#include <machine/mouse.h>
|
|
|
|
#endif
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2002-07-31 14:34:36 +00:00
|
|
|
#ifdef USB_DEBUG
|
1999-04-11 20:50:33 +00:00
|
|
|
#define DPRINTF(x) if (umsdebug) logprintf x
|
|
|
|
#define DPRINTFN(n,x) if (umsdebug>(n)) logprintf x
|
2002-07-31 14:34:36 +00:00
|
|
|
int umsdebug = 0;
|
2002-08-08 12:05:51 +00:00
|
|
|
SYSCTL_NODE(_hw_usb, OID_AUTO, ums, CTLFLAG_RW, 0, "USB ums");
|
|
|
|
SYSCTL_INT(_hw_usb_ums, OID_AUTO, debug, CTLFLAG_RW,
|
2002-07-31 13:33:55 +00:00
|
|
|
&umsdebug, 0, "ums debug level");
|
1998-11-26 23:13:13 +00:00
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define UMSUNIT(s) (minor(s)&0x1f)
|
|
|
|
|
2003-07-04 01:50:39 +00:00
|
|
|
#define MS_TO_TICKS(ms) ((ms) * hz / 1000)
|
1999-11-08 23:58:33 +00:00
|
|
|
|
1999-02-21 16:20:19 +00:00
|
|
|
#define QUEUE_BUFSIZE 400 /* MUST be divisible by 5 _and_ 8 */
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
struct ums_softc {
|
1999-10-07 18:50:46 +00:00
|
|
|
device_t sc_dev; /* base device */
|
1998-11-26 23:13:13 +00:00
|
|
|
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;
|
2004-12-12 05:34:20 +00:00
|
|
|
struct hid_location sc_loc_x, sc_loc_y, sc_loc_z, sc_loc_t;
|
1998-11-26 23:13:13 +00:00
|
|
|
struct hid_location *sc_loc_btn;
|
|
|
|
|
Huge merge from NetBSD:
usbdi.c (1.61):
===================================================================
revision 1.61
date: 2000/01/31 20:13:07; author: augustss; lines: +20 -4
Change the way the HC done method is invoked a little.
===================================================================
usbdi.c (1.65):
===================================================================
revision 1.65
date: 2000/03/08 15:34:10; author: augustss; lines: +4 -2
Get the status right when a polled transfer times out.
===================================================================
ohci.c (1.79), uhci.c (1.89), uhcivar.h (1.24), usb_port.h (1.22),
usbdivar.h (1.48):
===================================================================
date: 2000/03/23 07:01:46; author: thorpej;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.
The old timeout()/untimeout() API has been removed from the kernel.
===================================================================
uhci.c (1.80), usbdi.c (1.66):
===================================================================
date: 2000/03/23 18:59:10; author: thorpej;
Shake out some bugs from the callout changes.
===================================================================
ohci.c (1.80), uhci.c (1.91), uhcivar.h (1.25), usb_port.h (1.23),
usbdi.c (1.67), usbdivar.h (1.49):
===================================================================
date: 2000/03/24 22:03:30; author: augustss;
Some cleanup and renaming of the callouts used in USB drivers.
===================================================================
uhci.c (1.92), uhcivar.h (1.26):
===================================================================
date: 2000/03/24 22:57:58; author: augustss;
Two major changes:
Make each xfer have its own intr_info. This is necessary if we want
to queue multiple xfers on an endpoint. This should get rid of the
(mostly harmless) DIAGNOSTICs about intr_infos (not) being done.
Change (again!) how xfers are aborted. Aborting a TD is a nightmare
on the braindead UHCI controller. (Unless you stop the HC, thereby
losing isoc traffic.) Hopefully I got it right this time.
===================================================================
usbdivar.h (1.50):
===================================================================
revision 1.50
date: 2000/03/25 00:10:19; author: augustss; lines: +4 -2
GC an unsued field and add some DIAGNOSTIC in xfer.
===================================================================
ums.c: Use the callout functions instead of the timeout ones.
uhci.c (1.93):
===================================================================
revision 1.93
date: 2000/03/25 00:11:21; author: augustss;
lines: +26 -1
Add more DIAGNOSTIC when aborting isoc.
===================================================================
uhci.c (1.94), usbdivar.h (1.51):
===================================================================
date: 2000/03/25 07:13:05; author: augustss;
More DIAGNOSTIC.
Initialize a callout handle I forgot.
===================================================================
uhci.c (1.95):
===================================================================
revision 1.95
date: 2000/03/25 07:23:12; author: augustss;
Exp; lines: +24 -7
Improve uhci_dump_ii().
===================================================================
ohci.c (1.81), uhci.c (1.96), uhcivar.h (1.27), usb_subr.c (1.68),
usbdi.c (1.68), usbdivar.h (1.52):
===================================================================
date: 2000/03/25 18:02:33; author: augustss;
Rename and move around callout handles to make it more sane.
Add some DIAGNOSTIC.
Fix buglet in isoc abort on UHCI.
===================================================================
uhci.c (1.98):
===================================================================
revision 1.98
date: 2000/03/27 07:39:48; author: augustss; lines: +12 -4
Make it compile without DIAGNOSTIC.
===================================================================
uhci.c (1.99):
===================================================================
revision 1.99
date: 2000/03/27 08:01:09; author: augustss; lines: +1 -5
Remove some debug nonsense.
===================================================================
uhci.c (1.100):
===================================================================
revision 1.100
date: 2000/03/27 09:41:36; author: augustss; lines: +13 -3
Don't mess with QH in bulk abort for the moment.
===================================================================
uhci.c (1.102):
===================================================================
revision 1.102
date: 2000/03/27 22:42:57; author: augustss; lines: +66 -26
Be a little more careful when aborting.
Preallocate some TDs for large buffers.
===================================================================
uhci.c (1.103):
===================================================================
date: 2000/03/28 09:47:10; author: augustss; lines: +11 -1
Another patch for xfer abort...
XXX The current xfer queueing and aborting semantics should really
XXX be changed. It cannot be implemented in a sane way on UHCI.
XXX One day when I have lots of time I'll redesign it...
===================================================================
uhci.c (1.104): Correct a debug message.
uhci.c (1.105): Be more defensive in a DIAGNOSTIC test.
uhci.c (1.106):
===================================================================
revision 1.106
date: 2000/03/29 01:49:13; author: augustss; lines: +14 -309
*SIGH* Revert back to the old method of aborting xfers.
I had tested the new stuff for two months now, but as soon as I commited
it the problems started to appear. Murphy, no doubt...
===================================================================
usb_subr.c (1.70), usbdi.c (1.71), usbdivar.h (1.53):
===================================================================
revision 1.70
date: 2000/03/29 01:45:20; author: augustss; lines: +2 -1
Do not accept new xfers for queuing while a pipe is aborting.
===================================================================
2002-03-16 12:06:01 +00:00
|
|
|
usb_callout_t callout_handle; /* for spurious button ups */
|
1999-11-08 23:58:33 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
int sc_enabled;
|
|
|
|
int sc_disconnected; /* device is gone */
|
|
|
|
|
|
|
|
int flags; /* device configuration */
|
1999-01-07 23:07:57 +00:00
|
|
|
#define UMS_Z 0x01 /* z direction available */
|
2004-12-12 05:34:20 +00:00
|
|
|
#define UMS_T 0x02 /* aa direction available (tilt) */
|
1999-11-08 23:58:33 +00:00
|
|
|
#define UMS_SPUR_BUT_UP 0x02 /* spurious button up events */
|
1998-11-26 23:13:13 +00:00
|
|
|
int nbuttons;
|
1999-01-10 18:42:54 +00:00
|
|
|
#define MAX_BUTTONS 7 /* chosen because sc_buttons is u_char */
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-01-12 01:21:15 +00:00
|
|
|
u_char qbuf[QUEUE_BUFSIZE]; /* must be divisable by 3&4 */
|
1999-01-10 18:42:54 +00:00
|
|
|
u_char dummy[100]; /* XXX just for safety and for now */
|
1998-11-26 23:13:13 +00:00
|
|
|
int qcount, qhead, qtail;
|
|
|
|
mousehw_t hw;
|
|
|
|
mousemode_t mode;
|
|
|
|
mousestatus_t status;
|
|
|
|
|
|
|
|
int state;
|
|
|
|
# define UMS_ASLEEP 0x01 /* readFromDevice is waiting */
|
|
|
|
# define UMS_SELECT 0x02 /* select is waiting */
|
|
|
|
struct selinfo rsel; /* process waiting in select */
|
1999-10-07 21:06:52 +00:00
|
|
|
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *dev; /* specfs */
|
1998-11-26 23:13:13 +00:00
|
|
|
};
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
#define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
|
|
|
|
#define MOUSE_FLAGS (HIO_RELATIVE)
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2000-07-17 18:41:20 +00:00
|
|
|
Static void ums_intr(usbd_xfer_handle xfer,
|
|
|
|
usbd_private_handle priv, usbd_status status);
|
1999-11-08 23:58:33 +00:00
|
|
|
|
2000-07-17 18:41:20 +00:00
|
|
|
Static void ums_add_to_queue(struct ums_softc *sc,
|
2004-12-12 05:34:20 +00:00
|
|
|
int dx, int dy, int dz, int dt, int buttons);
|
2000-07-17 18:41:20 +00:00
|
|
|
Static void ums_add_to_queue_timeout(void *priv);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2000-07-17 18:41:20 +00:00
|
|
|
Static int ums_enable(void *);
|
|
|
|
Static void ums_disable(void *);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static d_open_t ums_open;
|
|
|
|
Static d_close_t ums_close;
|
|
|
|
Static d_read_t ums_read;
|
|
|
|
Static d_ioctl_t ums_ioctl;
|
|
|
|
Static d_poll_t ums_poll;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static struct cdevsw ums_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_flags = D_NEEDGIANT,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = ums_open,
|
|
|
|
.d_close = ums_close,
|
|
|
|
.d_read = ums_read,
|
|
|
|
.d_ioctl = ums_ioctl,
|
|
|
|
.d_poll = ums_poll,
|
|
|
|
.d_name = "ums",
|
2003-08-25 22:10:52 +00:00
|
|
|
#if __FreeBSD_version < 500014
|
|
|
|
.d_bmaj -1
|
|
|
|
#endif
|
1998-11-26 23:13:13 +00:00
|
|
|
};
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_DECLARE_DRIVER(ums);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_MATCH(ums)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_MATCH_START(ums, uaa);
|
1998-11-26 23:13:13 +00:00
|
|
|
usb_interface_descriptor_t *id;
|
|
|
|
int size, ret;
|
|
|
|
void *desc;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
2003-07-04 01:50:39 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
if (!uaa->iface)
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
id = usbd_get_interface_descriptor(uaa->iface);
|
2002-01-02 18:28:45 +00:00
|
|
|
if (!id || id->bInterfaceClass != UICLASS_HID)
|
1998-11-26 23:13:13 +00:00
|
|
|
return (UMATCH_NONE);
|
|
|
|
|
2002-04-07 17:13:00 +00:00
|
|
|
err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err)
|
1998-11-26 23:13:13 +00:00
|
|
|
return (UMATCH_NONE);
|
|
|
|
|
2003-07-04 01:50:39 +00:00
|
|
|
if (hid_is_collection(desc, size,
|
1998-11-26 23:13:13 +00:00
|
|
|
HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE)))
|
|
|
|
ret = UMATCH_IFACECLASS;
|
|
|
|
else
|
|
|
|
ret = UMATCH_NONE;
|
|
|
|
|
|
|
|
free(desc, M_TEMP);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_ATTACH(ums)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_ATTACH_START(ums, sc, uaa);
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_interface_handle iface = uaa->iface;
|
|
|
|
usb_interface_descriptor_t *id;
|
|
|
|
usb_endpoint_descriptor_t *ed;
|
|
|
|
int size;
|
|
|
|
void *desc;
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
1999-01-07 23:07:57 +00:00
|
|
|
char devinfo[1024];
|
1998-11-26 23:13:13 +00:00
|
|
|
u_int32_t flags;
|
|
|
|
int i;
|
1999-01-07 23:07:57 +00:00
|
|
|
struct hid_location loc_btn;
|
2003-07-04 01:50:39 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
sc->sc_disconnected = 1;
|
|
|
|
sc->sc_iface = iface;
|
|
|
|
id = usbd_get_interface_descriptor(iface);
|
2004-08-15 23:39:18 +00:00
|
|
|
usbd_devinfo(uaa->device, USBD_SHOW_INTERFACE_CLASS, devinfo);
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_ATTACH_SETUP;
|
1998-11-26 23:13:13 +00:00
|
|
|
ed = usbd_interface2endpoint_descriptor(iface, 0);
|
|
|
|
if (!ed) {
|
1999-01-07 23:07:57 +00:00
|
|
|
printf("%s: could not read endpoint descriptor\n",
|
|
|
|
USBDEVNAME(sc->sc_dev));
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTFN(10,("ums_attach: bLength=%d bDescriptorType=%d "
|
1999-01-07 23:07:57 +00:00
|
|
|
"bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d"
|
|
|
|
" bInterval=%d\n",
|
2003-07-04 01:50:39 +00:00
|
|
|
ed->bLength, ed->bDescriptorType,
|
1999-10-07 18:50:46 +00:00
|
|
|
UE_GET_ADDR(ed->bEndpointAddress),
|
|
|
|
UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN ? "in":"out",
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes),
|
1999-01-07 23:07:57 +00:00
|
|
|
UGETW(ed->wMaxPacketSize), ed->bInterval));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-10-07 18:50:46 +00:00
|
|
|
if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN ||
|
|
|
|
UE_GET_XFERTYPE(ed->bmAttributes) != UE_INTERRUPT) {
|
1999-01-07 23:07:57 +00:00
|
|
|
printf("%s: unexpected endpoint\n",
|
|
|
|
USBDEVNAME(sc->sc_dev));
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
2002-04-07 17:13:00 +00:00
|
|
|
err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err)
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
|
|
|
|
hid_input, &sc->sc_loc_x, &flags)) {
|
1999-01-07 23:07:57 +00:00
|
|
|
printf("%s: mouse has no X report\n", USBDEVNAME(sc->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);
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
|
|
|
|
hid_input, &sc->sc_loc_y, &flags)) {
|
1999-01-07 23:07:57 +00:00
|
|
|
printf("%s: mouse has no Y report\n", USBDEVNAME(sc->sc_dev));
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-01-07 23:07:57 +00:00
|
|
|
if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
|
|
|
|
printf("%s: Y report 0x%04x not supported\n",
|
|
|
|
USBDEVNAME(sc->sc_dev), flags);
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* try to guess the Z activator: first check Z, then WHEEL */
|
|
|
|
if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
|
|
|
|
hid_input, &sc->sc_loc_z, &flags) ||
|
|
|
|
hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
|
2004-12-12 05:34:20 +00:00
|
|
|
hid_input, &sc->sc_loc_z, &flags) ||
|
|
|
|
hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_TWHEEL),
|
1998-11-26 23:13:13 +00:00
|
|
|
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 {
|
|
|
|
sc->flags |= UMS_Z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-12 05:34:20 +00:00
|
|
|
/* The Microsoft Wireless Intellimouse 2.0 reports it's wheel
|
|
|
|
* using 0x0048 (i've called it HUG_TWHEEL) and seems to expect
|
|
|
|
* you to know that the byte after the wheel is the tilt axis.
|
|
|
|
* There are no other HID axis descriptors other than X,Y and
|
|
|
|
* TWHEEL */
|
|
|
|
if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_TWHEEL),
|
|
|
|
hid_input, &sc->sc_loc_t, &flags)) {
|
|
|
|
sc->sc_loc_t.pos = sc->sc_loc_t.pos + 8;
|
|
|
|
sc->flags |= UMS_T;
|
|
|
|
}
|
|
|
|
|
1999-01-10 18:42:54 +00:00
|
|
|
/* figure out the number of buttons */
|
|
|
|
for (i = 1; i <= MAX_BUTTONS; i++)
|
1998-11-26 23:13:13 +00:00
|
|
|
if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i),
|
|
|
|
hid_input, &loc_btn, 0))
|
|
|
|
break;
|
|
|
|
sc->nbuttons = i - 1;
|
2003-07-04 01:50:39 +00:00
|
|
|
sc->sc_loc_btn = malloc(sizeof(struct hid_location)*sc->nbuttons,
|
1999-01-07 23:07:57 +00:00
|
|
|
M_USBDEV, M_NOWAIT);
|
1999-01-21 23:06:02 +00:00
|
|
|
if (!sc->sc_loc_btn) {
|
|
|
|
printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1999-01-21 23:06:02 +00:00
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2004-12-12 05:34:20 +00:00
|
|
|
printf("%s: %d buttons%s%s.\n", USBDEVNAME(sc->sc_dev),
|
|
|
|
sc->nbuttons, sc->flags & UMS_Z? " and Z dir" : "",
|
|
|
|
sc->flags & UMS_T?" and a TILT dir": "");
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
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_USB, M_NOWAIT);
|
|
|
|
if (!sc->sc_ibuf) {
|
1999-01-21 23:06:02 +00:00
|
|
|
printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
|
1998-11-26 23:13:13 +00:00
|
|
|
free(sc->sc_loc_btn, M_USB);
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_ATTACH_ERROR_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_ep_addr = ed->bEndpointAddress;
|
|
|
|
sc->sc_disconnected = 0;
|
|
|
|
free(desc, M_TEMP);
|
|
|
|
|
2002-07-31 14:34:36 +00:00
|
|
|
#ifdef USB_DEBUG
|
1998-11-26 23:13:13 +00:00
|
|
|
DPRINTF(("ums_attach: sc=%p\n", sc));
|
2003-07-04 01:50:39 +00:00
|
|
|
DPRINTF(("ums_attach: X\t%d/%d\n",
|
1998-11-26 23:13:13 +00:00
|
|
|
sc->sc_loc_x.pos, sc->sc_loc_x.size));
|
2003-07-04 01:50:39 +00:00
|
|
|
DPRINTF(("ums_attach: Y\t%d/%d\n",
|
1999-09-01 21:37:56 +00:00
|
|
|
sc->sc_loc_y.pos, sc->sc_loc_y.size));
|
1998-11-26 23:13:13 +00:00
|
|
|
if (sc->flags & UMS_Z)
|
2003-07-04 01:50:39 +00:00
|
|
|
DPRINTF(("ums_attach: Z\t%d/%d\n",
|
1998-11-26 23:13:13 +00: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));
|
|
|
|
}
|
|
|
|
DPRINTF(("ums_attach: size=%d, id=%d\n", sc->sc_isize, sc->sc_iid));
|
|
|
|
#endif
|
|
|
|
|
1999-02-21 16:20:19 +00:00
|
|
|
if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
|
|
|
|
sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
|
1998-11-26 23:13:13 +00:00
|
|
|
else
|
1999-02-21 16:20:19 +00:00
|
|
|
sc->hw.buttons = sc->nbuttons;
|
|
|
|
sc->hw.iftype = MOUSE_IF_USB;
|
|
|
|
sc->hw.type = MOUSE_MOUSE;
|
|
|
|
sc->hw.model = MOUSE_MODEL_GENERIC;
|
1998-11-26 23:13:13 +00:00
|
|
|
sc->hw.hwid = 0;
|
1999-02-21 16:20:19 +00:00
|
|
|
sc->mode.protocol = MOUSE_PROTO_MSC;
|
1998-11-26 23:13:13 +00:00
|
|
|
sc->mode.rate = -1;
|
1999-02-21 16:20:19 +00:00
|
|
|
sc->mode.resolution = MOUSE_RES_UNKNOWN;
|
|
|
|
sc->mode.accelfactor = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
sc->mode.level = 0;
|
1999-02-21 16:20:19 +00:00
|
|
|
sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
|
|
|
|
sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
|
|
|
|
sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
sc->status.flags = 0;
|
|
|
|
sc->status.button = sc->status.obutton = 0;
|
|
|
|
sc->status.dx = sc->status.dy = sc->status.dz = 0;
|
|
|
|
|
2002-03-14 01:32:30 +00:00
|
|
|
#ifndef __FreeBSD__
|
1998-11-26 23:13:13 +00:00
|
|
|
sc->rsel.si_flags = 0;
|
|
|
|
sc->rsel.si_pid = 0;
|
2002-03-14 01:32:30 +00:00
|
|
|
#endif
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-11-08 23:58:33 +00:00
|
|
|
sc->dev = make_dev(&ums_cdevsw, device_get_unit(self),
|
|
|
|
UID_ROOT, GID_OPERATOR,
|
1999-10-07 21:06:52 +00:00
|
|
|
0644, "ums%d", device_get_unit(self));
|
|
|
|
|
1999-11-08 23:58:33 +00:00
|
|
|
if (usbd_get_quirks(uaa->device)->uq_flags & UQ_SPUR_BUT_UP) {
|
|
|
|
DPRINTF(("%s: Spurious button up events\n",
|
|
|
|
USBDEVNAME(sc->sc_dev)));
|
|
|
|
sc->flags |= UMS_SPUR_BUT_UP;
|
|
|
|
}
|
|
|
|
|
1999-01-07 23:07:57 +00:00
|
|
|
USB_ATTACH_SUCCESS_RETURN;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static int
|
1998-11-26 23:13:13 +00:00
|
|
|
ums_detach(device_t self)
|
|
|
|
{
|
|
|
|
struct ums_softc *sc = device_get_softc(self);
|
|
|
|
|
1999-05-30 12:48:49 +00:00
|
|
|
if (sc->sc_enabled)
|
|
|
|
ums_disable(sc);
|
1999-01-21 23:06:02 +00:00
|
|
|
|
|
|
|
DPRINTF(("%s: disconnected\n", USBDEVNAME(self)));
|
1999-08-28 11:35:36 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
free(sc->sc_loc_btn, M_USB);
|
|
|
|
free(sc->sc_ibuf, M_USB);
|
|
|
|
|
1999-11-21 17:25:30 +00:00
|
|
|
/* someone waiting for data */
|
1999-05-30 12:48:49 +00:00
|
|
|
/*
|
|
|
|
* XXX If we wakeup the process here, the device will be gone by
|
|
|
|
* the time the process gets a chance to notice. *_close and friends
|
|
|
|
* should be fixed to handle this case.
|
|
|
|
* Or we should do a delayed detach for this.
|
1999-06-13 20:49:12 +00:00
|
|
|
* Does this delay now force tsleep to exit with an error?
|
1999-05-30 12:48:49 +00:00
|
|
|
*/
|
1999-01-21 23:06:02 +00:00
|
|
|
if (sc->state & UMS_ASLEEP) {
|
1999-02-21 16:20:19 +00:00
|
|
|
sc->state &= ~UMS_ASLEEP;
|
1999-01-21 23:06:02 +00:00
|
|
|
wakeup(sc);
|
|
|
|
}
|
|
|
|
if (sc->state & UMS_SELECT) {
|
1999-02-21 16:20:19 +00:00
|
|
|
sc->state &= ~UMS_SELECT;
|
2003-11-09 09:17:26 +00:00
|
|
|
selwakeuppri(&sc->rsel, PZERO);
|
1999-01-21 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
1999-11-08 07:44:01 +00:00
|
|
|
destroy_dev(sc->dev);
|
1999-10-07 21:06:52 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-11-17 22:33:51 +00:00
|
|
|
ums_intr(xfer, addr, status)
|
|
|
|
usbd_xfer_handle xfer;
|
1998-11-26 23:13:13 +00:00
|
|
|
usbd_private_handle addr;
|
|
|
|
usbd_status status;
|
|
|
|
{
|
|
|
|
struct ums_softc *sc = addr;
|
|
|
|
u_char *ibuf;
|
2004-12-12 05:34:20 +00:00
|
|
|
int dx, dy, dz, dt;
|
1998-11-26 23:13:13 +00:00
|
|
|
u_char buttons = 0;
|
|
|
|
int i;
|
1999-01-10 18:42:54 +00:00
|
|
|
|
1999-02-21 16:20:19 +00:00
|
|
|
#define UMS_BUT(i) ((i) < 3 ? (((i) + 2) % 3) : (i))
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
DPRINTFN(5, ("ums_intr: sc=%p status=%d\n", sc, status));
|
2004-12-12 05:34:20 +00:00
|
|
|
DPRINTFN(5, ("ums_intr: data = %02x %02x %02x %02x %02x %02x\n",
|
|
|
|
sc->sc_ibuf[0], sc->sc_ibuf[1], sc->sc_ibuf[2], sc->sc_ibuf[3], sc->sc_ibuf[4], sc->sc_ibuf[5]));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
if (status == USBD_CANCELLED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (status != USBD_NORMAL_COMPLETION) {
|
|
|
|
DPRINTF(("ums_intr: status=%d\n", status));
|
2001-09-02 09:26:14 +00:00
|
|
|
if (status == USBD_STALLED)
|
|
|
|
usbd_clear_endpoint_stall_async(sc->sc_intrpipe);
|
2004-12-12 05:34:20 +00:00
|
|
|
if(status != USBD_IOERROR)
|
|
|
|
return;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ibuf = sc->sc_ibuf;
|
|
|
|
if (sc->sc_iid) {
|
2004-12-12 05:34:20 +00:00
|
|
|
ibuf++;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-01-10 18:42:54 +00:00
|
|
|
|
2004-12-12 05:34:20 +00:00
|
|
|
/* The M$ Wireless Intellimouse 2.0 sends 1 extra leading byte of
|
|
|
|
* data compared to most USB mice. This byte frequently switches
|
|
|
|
* from 0x01 (usual state) to 0x02. I assume it is to allow
|
|
|
|
* extra, non-standard, reporting (say battery-life). However
|
|
|
|
* at the same time it generates a left-click message on the button
|
|
|
|
* byte which causes spurious left-click's where there shouldn't be.
|
|
|
|
* This should sort that. */
|
|
|
|
if ((sc->sc_ibuf != ibuf) && (sc->sc_ibuf[0] == 0x02))
|
|
|
|
return;
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
dx = hid_get_data(ibuf, &sc->sc_loc_x);
|
|
|
|
dy = -hid_get_data(ibuf, &sc->sc_loc_y);
|
1999-05-01 13:17:47 +00:00
|
|
|
dz = -hid_get_data(ibuf, &sc->sc_loc_z);
|
2004-12-12 05:34:20 +00:00
|
|
|
dt = -hid_get_data(ibuf, &sc->sc_loc_t);
|
1999-01-07 23:07:57 +00:00
|
|
|
for (i = 0; i < sc->nbuttons; i++)
|
|
|
|
if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
|
|
|
|
buttons |= (1 << UMS_BUT(i));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
2004-12-12 05:34:20 +00:00
|
|
|
if (dx || dy || dz || dt || (sc->flags & UMS_Z)
|
1999-01-12 01:21:15 +00:00
|
|
|
|| buttons != sc->status.button) {
|
2004-12-12 05:34:20 +00:00
|
|
|
DPRINTFN(5, ("ums_intr: x:%d y:%d z:%d aa:%d buttons:0x%x\n",
|
|
|
|
dx, dy, dz, dt, buttons));
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
sc->status.button = buttons;
|
|
|
|
sc->status.dx += dx;
|
|
|
|
sc->status.dy += dy;
|
|
|
|
sc->status.dz += dz;
|
2004-12-12 05:34:20 +00:00
|
|
|
sc->status.dt += dt;
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
/* Discard data in case of full buffer */
|
|
|
|
if (sc->qcount == sizeof(sc->qbuf)) {
|
|
|
|
DPRINTF(("Buffer full, discarded packet"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-11-08 23:58:33 +00:00
|
|
|
/*
|
|
|
|
* The Qtronix keyboard has a built in PS/2 port for a mouse.
|
|
|
|
* The firmware once in a while posts a spurious button up
|
|
|
|
* event. This event we ignore by doing a timeout for 50 msecs.
|
|
|
|
* If we receive dx=dy=dz=buttons=0 before we add the event to
|
|
|
|
* the queue.
|
|
|
|
* In any other case we delete the timeout event.
|
|
|
|
*/
|
|
|
|
if (sc->flags & UMS_SPUR_BUT_UP &&
|
2004-12-12 05:34:20 +00:00
|
|
|
dx == 0 && dy == 0 && dz == 0 && dt == 0 && buttons == 0) {
|
Huge merge from NetBSD:
usbdi.c (1.61):
===================================================================
revision 1.61
date: 2000/01/31 20:13:07; author: augustss; lines: +20 -4
Change the way the HC done method is invoked a little.
===================================================================
usbdi.c (1.65):
===================================================================
revision 1.65
date: 2000/03/08 15:34:10; author: augustss; lines: +4 -2
Get the status right when a polled transfer times out.
===================================================================
ohci.c (1.79), uhci.c (1.89), uhcivar.h (1.24), usb_port.h (1.22),
usbdivar.h (1.48):
===================================================================
date: 2000/03/23 07:01:46; author: thorpej;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.
The old timeout()/untimeout() API has been removed from the kernel.
===================================================================
uhci.c (1.80), usbdi.c (1.66):
===================================================================
date: 2000/03/23 18:59:10; author: thorpej;
Shake out some bugs from the callout changes.
===================================================================
ohci.c (1.80), uhci.c (1.91), uhcivar.h (1.25), usb_port.h (1.23),
usbdi.c (1.67), usbdivar.h (1.49):
===================================================================
date: 2000/03/24 22:03:30; author: augustss;
Some cleanup and renaming of the callouts used in USB drivers.
===================================================================
uhci.c (1.92), uhcivar.h (1.26):
===================================================================
date: 2000/03/24 22:57:58; author: augustss;
Two major changes:
Make each xfer have its own intr_info. This is necessary if we want
to queue multiple xfers on an endpoint. This should get rid of the
(mostly harmless) DIAGNOSTICs about intr_infos (not) being done.
Change (again!) how xfers are aborted. Aborting a TD is a nightmare
on the braindead UHCI controller. (Unless you stop the HC, thereby
losing isoc traffic.) Hopefully I got it right this time.
===================================================================
usbdivar.h (1.50):
===================================================================
revision 1.50
date: 2000/03/25 00:10:19; author: augustss; lines: +4 -2
GC an unsued field and add some DIAGNOSTIC in xfer.
===================================================================
ums.c: Use the callout functions instead of the timeout ones.
uhci.c (1.93):
===================================================================
revision 1.93
date: 2000/03/25 00:11:21; author: augustss;
lines: +26 -1
Add more DIAGNOSTIC when aborting isoc.
===================================================================
uhci.c (1.94), usbdivar.h (1.51):
===================================================================
date: 2000/03/25 07:13:05; author: augustss;
More DIAGNOSTIC.
Initialize a callout handle I forgot.
===================================================================
uhci.c (1.95):
===================================================================
revision 1.95
date: 2000/03/25 07:23:12; author: augustss;
Exp; lines: +24 -7
Improve uhci_dump_ii().
===================================================================
ohci.c (1.81), uhci.c (1.96), uhcivar.h (1.27), usb_subr.c (1.68),
usbdi.c (1.68), usbdivar.h (1.52):
===================================================================
date: 2000/03/25 18:02:33; author: augustss;
Rename and move around callout handles to make it more sane.
Add some DIAGNOSTIC.
Fix buglet in isoc abort on UHCI.
===================================================================
uhci.c (1.98):
===================================================================
revision 1.98
date: 2000/03/27 07:39:48; author: augustss; lines: +12 -4
Make it compile without DIAGNOSTIC.
===================================================================
uhci.c (1.99):
===================================================================
revision 1.99
date: 2000/03/27 08:01:09; author: augustss; lines: +1 -5
Remove some debug nonsense.
===================================================================
uhci.c (1.100):
===================================================================
revision 1.100
date: 2000/03/27 09:41:36; author: augustss; lines: +13 -3
Don't mess with QH in bulk abort for the moment.
===================================================================
uhci.c (1.102):
===================================================================
revision 1.102
date: 2000/03/27 22:42:57; author: augustss; lines: +66 -26
Be a little more careful when aborting.
Preallocate some TDs for large buffers.
===================================================================
uhci.c (1.103):
===================================================================
date: 2000/03/28 09:47:10; author: augustss; lines: +11 -1
Another patch for xfer abort...
XXX The current xfer queueing and aborting semantics should really
XXX be changed. It cannot be implemented in a sane way on UHCI.
XXX One day when I have lots of time I'll redesign it...
===================================================================
uhci.c (1.104): Correct a debug message.
uhci.c (1.105): Be more defensive in a DIAGNOSTIC test.
uhci.c (1.106):
===================================================================
revision 1.106
date: 2000/03/29 01:49:13; author: augustss; lines: +14 -309
*SIGH* Revert back to the old method of aborting xfers.
I had tested the new stuff for two months now, but as soon as I commited
it the problems started to appear. Murphy, no doubt...
===================================================================
usb_subr.c (1.70), usbdi.c (1.71), usbdivar.h (1.53):
===================================================================
revision 1.70
date: 2000/03/29 01:45:20; author: augustss; lines: +2 -1
Do not accept new xfers for queuing while a pipe is aborting.
===================================================================
2002-03-16 12:06:01 +00:00
|
|
|
usb_callout(sc->callout_handle, MS_TO_TICKS(50 /*msecs*/),
|
|
|
|
ums_add_to_queue_timeout, (void *) sc);
|
1999-11-08 23:58:33 +00:00
|
|
|
} else {
|
Huge merge from NetBSD:
usbdi.c (1.61):
===================================================================
revision 1.61
date: 2000/01/31 20:13:07; author: augustss; lines: +20 -4
Change the way the HC done method is invoked a little.
===================================================================
usbdi.c (1.65):
===================================================================
revision 1.65
date: 2000/03/08 15:34:10; author: augustss; lines: +4 -2
Get the status right when a polled transfer times out.
===================================================================
ohci.c (1.79), uhci.c (1.89), uhcivar.h (1.24), usb_port.h (1.22),
usbdivar.h (1.48):
===================================================================
date: 2000/03/23 07:01:46; author: thorpej;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.
The old timeout()/untimeout() API has been removed from the kernel.
===================================================================
uhci.c (1.80), usbdi.c (1.66):
===================================================================
date: 2000/03/23 18:59:10; author: thorpej;
Shake out some bugs from the callout changes.
===================================================================
ohci.c (1.80), uhci.c (1.91), uhcivar.h (1.25), usb_port.h (1.23),
usbdi.c (1.67), usbdivar.h (1.49):
===================================================================
date: 2000/03/24 22:03:30; author: augustss;
Some cleanup and renaming of the callouts used in USB drivers.
===================================================================
uhci.c (1.92), uhcivar.h (1.26):
===================================================================
date: 2000/03/24 22:57:58; author: augustss;
Two major changes:
Make each xfer have its own intr_info. This is necessary if we want
to queue multiple xfers on an endpoint. This should get rid of the
(mostly harmless) DIAGNOSTICs about intr_infos (not) being done.
Change (again!) how xfers are aborted. Aborting a TD is a nightmare
on the braindead UHCI controller. (Unless you stop the HC, thereby
losing isoc traffic.) Hopefully I got it right this time.
===================================================================
usbdivar.h (1.50):
===================================================================
revision 1.50
date: 2000/03/25 00:10:19; author: augustss; lines: +4 -2
GC an unsued field and add some DIAGNOSTIC in xfer.
===================================================================
ums.c: Use the callout functions instead of the timeout ones.
uhci.c (1.93):
===================================================================
revision 1.93
date: 2000/03/25 00:11:21; author: augustss;
lines: +26 -1
Add more DIAGNOSTIC when aborting isoc.
===================================================================
uhci.c (1.94), usbdivar.h (1.51):
===================================================================
date: 2000/03/25 07:13:05; author: augustss;
More DIAGNOSTIC.
Initialize a callout handle I forgot.
===================================================================
uhci.c (1.95):
===================================================================
revision 1.95
date: 2000/03/25 07:23:12; author: augustss;
Exp; lines: +24 -7
Improve uhci_dump_ii().
===================================================================
ohci.c (1.81), uhci.c (1.96), uhcivar.h (1.27), usb_subr.c (1.68),
usbdi.c (1.68), usbdivar.h (1.52):
===================================================================
date: 2000/03/25 18:02:33; author: augustss;
Rename and move around callout handles to make it more sane.
Add some DIAGNOSTIC.
Fix buglet in isoc abort on UHCI.
===================================================================
uhci.c (1.98):
===================================================================
revision 1.98
date: 2000/03/27 07:39:48; author: augustss; lines: +12 -4
Make it compile without DIAGNOSTIC.
===================================================================
uhci.c (1.99):
===================================================================
revision 1.99
date: 2000/03/27 08:01:09; author: augustss; lines: +1 -5
Remove some debug nonsense.
===================================================================
uhci.c (1.100):
===================================================================
revision 1.100
date: 2000/03/27 09:41:36; author: augustss; lines: +13 -3
Don't mess with QH in bulk abort for the moment.
===================================================================
uhci.c (1.102):
===================================================================
revision 1.102
date: 2000/03/27 22:42:57; author: augustss; lines: +66 -26
Be a little more careful when aborting.
Preallocate some TDs for large buffers.
===================================================================
uhci.c (1.103):
===================================================================
date: 2000/03/28 09:47:10; author: augustss; lines: +11 -1
Another patch for xfer abort...
XXX The current xfer queueing and aborting semantics should really
XXX be changed. It cannot be implemented in a sane way on UHCI.
XXX One day when I have lots of time I'll redesign it...
===================================================================
uhci.c (1.104): Correct a debug message.
uhci.c (1.105): Be more defensive in a DIAGNOSTIC test.
uhci.c (1.106):
===================================================================
revision 1.106
date: 2000/03/29 01:49:13; author: augustss; lines: +14 -309
*SIGH* Revert back to the old method of aborting xfers.
I had tested the new stuff for two months now, but as soon as I commited
it the problems started to appear. Murphy, no doubt...
===================================================================
usb_subr.c (1.70), usbdi.c (1.71), usbdivar.h (1.53):
===================================================================
revision 1.70
date: 2000/03/29 01:45:20; author: augustss; lines: +2 -1
Do not accept new xfers for queuing while a pipe is aborting.
===================================================================
2002-03-16 12:06:01 +00:00
|
|
|
usb_uncallout(sc->callout_handle,
|
|
|
|
ums_add_to_queue_timeout, (void *) sc);
|
2004-12-12 05:34:20 +00:00
|
|
|
ums_add_to_queue(sc, dx, dy, dz, dt, buttons);
|
1999-01-12 01:21:15 +00:00
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static void
|
1999-11-08 23:58:33 +00:00
|
|
|
ums_add_to_queue_timeout(void *priv)
|
|
|
|
{
|
|
|
|
struct ums_softc *sc = priv;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splusb();
|
2004-12-12 05:34:20 +00:00
|
|
|
ums_add_to_queue(sc, 0, 0, 0, 0, 0);
|
1999-11-08 23:58:33 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static void
|
2004-12-12 05:34:20 +00:00
|
|
|
ums_add_to_queue(struct ums_softc *sc, int dx, int dy, int dz, int dt, int buttons)
|
1999-11-08 23:58:33 +00:00
|
|
|
{
|
|
|
|
/* Discard data in case of full buffer */
|
|
|
|
if (sc->qhead+sc->mode.packetsize > sizeof(sc->qbuf)) {
|
|
|
|
DPRINTF(("Buffer full, discarded packet"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dx > 254) dx = 254;
|
|
|
|
if (dx < -256) dx = -256;
|
|
|
|
if (dy > 254) dy = 254;
|
|
|
|
if (dy < -256) dy = -256;
|
|
|
|
if (dz > 126) dz = 126;
|
|
|
|
if (dz < -128) dz = -128;
|
2004-12-12 05:34:20 +00:00
|
|
|
if (dt > 126) dt = 126;
|
|
|
|
if (dt < -128) dt = -128;
|
1999-11-08 23:58:33 +00:00
|
|
|
|
|
|
|
sc->qbuf[sc->qhead] = sc->mode.syncmask[1];
|
|
|
|
sc->qbuf[sc->qhead] |= ~buttons & MOUSE_MSC_BUTTONS;
|
|
|
|
sc->qbuf[sc->qhead+1] = dx >> 1;
|
|
|
|
sc->qbuf[sc->qhead+2] = dy >> 1;
|
|
|
|
sc->qbuf[sc->qhead+3] = dx - (dx >> 1);
|
|
|
|
sc->qbuf[sc->qhead+4] = dy - (dy >> 1);
|
|
|
|
|
|
|
|
if (sc->mode.level == 1) {
|
|
|
|
sc->qbuf[sc->qhead+5] = dz >> 1;
|
|
|
|
sc->qbuf[sc->qhead+6] = dz - (dz >> 1);
|
|
|
|
sc->qbuf[sc->qhead+7] = ((~buttons >> 3)
|
|
|
|
& MOUSE_SYS_EXTBUTTONS);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->qhead += sc->mode.packetsize;
|
|
|
|
sc->qcount += sc->mode.packetsize;
|
|
|
|
/* wrap round at end of buffer */
|
|
|
|
if (sc->qhead >= sizeof(sc->qbuf))
|
|
|
|
sc->qhead = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-11-08 23:58:33 +00:00
|
|
|
/* someone waiting for data */
|
|
|
|
if (sc->state & UMS_ASLEEP) {
|
|
|
|
sc->state &= ~UMS_ASLEEP;
|
|
|
|
wakeup(sc);
|
|
|
|
}
|
|
|
|
if (sc->state & UMS_SELECT) {
|
|
|
|
sc->state &= ~UMS_SELECT;
|
2003-11-09 09:17:26 +00:00
|
|
|
selwakeuppri(&sc->rsel, PZERO);
|
1999-11-08 23:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
2000-04-03 20:58:30 +00:00
|
|
|
Static int
|
1998-11-26 23:13:13 +00:00
|
|
|
ums_enable(v)
|
|
|
|
void *v;
|
|
|
|
{
|
|
|
|
struct ums_softc *sc = v;
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
usbd_status err;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
sc->sc_enabled = 1;
|
|
|
|
sc->qcount = 0;
|
|
|
|
sc->qhead = sc->qtail = 0;
|
|
|
|
sc->status.flags = 0;
|
|
|
|
sc->status.button = sc->status.obutton = 0;
|
2004-12-12 05:34:20 +00:00
|
|
|
sc->status.dx = sc->status.dy = sc->status.dz = sc->status.dt = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
Huge merge from NetBSD:
usbdi.c (1.61):
===================================================================
revision 1.61
date: 2000/01/31 20:13:07; author: augustss; lines: +20 -4
Change the way the HC done method is invoked a little.
===================================================================
usbdi.c (1.65):
===================================================================
revision 1.65
date: 2000/03/08 15:34:10; author: augustss; lines: +4 -2
Get the status right when a polled transfer times out.
===================================================================
ohci.c (1.79), uhci.c (1.89), uhcivar.h (1.24), usb_port.h (1.22),
usbdivar.h (1.48):
===================================================================
date: 2000/03/23 07:01:46; author: thorpej;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.
The old timeout()/untimeout() API has been removed from the kernel.
===================================================================
uhci.c (1.80), usbdi.c (1.66):
===================================================================
date: 2000/03/23 18:59:10; author: thorpej;
Shake out some bugs from the callout changes.
===================================================================
ohci.c (1.80), uhci.c (1.91), uhcivar.h (1.25), usb_port.h (1.23),
usbdi.c (1.67), usbdivar.h (1.49):
===================================================================
date: 2000/03/24 22:03:30; author: augustss;
Some cleanup and renaming of the callouts used in USB drivers.
===================================================================
uhci.c (1.92), uhcivar.h (1.26):
===================================================================
date: 2000/03/24 22:57:58; author: augustss;
Two major changes:
Make each xfer have its own intr_info. This is necessary if we want
to queue multiple xfers on an endpoint. This should get rid of the
(mostly harmless) DIAGNOSTICs about intr_infos (not) being done.
Change (again!) how xfers are aborted. Aborting a TD is a nightmare
on the braindead UHCI controller. (Unless you stop the HC, thereby
losing isoc traffic.) Hopefully I got it right this time.
===================================================================
usbdivar.h (1.50):
===================================================================
revision 1.50
date: 2000/03/25 00:10:19; author: augustss; lines: +4 -2
GC an unsued field and add some DIAGNOSTIC in xfer.
===================================================================
ums.c: Use the callout functions instead of the timeout ones.
uhci.c (1.93):
===================================================================
revision 1.93
date: 2000/03/25 00:11:21; author: augustss;
lines: +26 -1
Add more DIAGNOSTIC when aborting isoc.
===================================================================
uhci.c (1.94), usbdivar.h (1.51):
===================================================================
date: 2000/03/25 07:13:05; author: augustss;
More DIAGNOSTIC.
Initialize a callout handle I forgot.
===================================================================
uhci.c (1.95):
===================================================================
revision 1.95
date: 2000/03/25 07:23:12; author: augustss;
Exp; lines: +24 -7
Improve uhci_dump_ii().
===================================================================
ohci.c (1.81), uhci.c (1.96), uhcivar.h (1.27), usb_subr.c (1.68),
usbdi.c (1.68), usbdivar.h (1.52):
===================================================================
date: 2000/03/25 18:02:33; author: augustss;
Rename and move around callout handles to make it more sane.
Add some DIAGNOSTIC.
Fix buglet in isoc abort on UHCI.
===================================================================
uhci.c (1.98):
===================================================================
revision 1.98
date: 2000/03/27 07:39:48; author: augustss; lines: +12 -4
Make it compile without DIAGNOSTIC.
===================================================================
uhci.c (1.99):
===================================================================
revision 1.99
date: 2000/03/27 08:01:09; author: augustss; lines: +1 -5
Remove some debug nonsense.
===================================================================
uhci.c (1.100):
===================================================================
revision 1.100
date: 2000/03/27 09:41:36; author: augustss; lines: +13 -3
Don't mess with QH in bulk abort for the moment.
===================================================================
uhci.c (1.102):
===================================================================
revision 1.102
date: 2000/03/27 22:42:57; author: augustss; lines: +66 -26
Be a little more careful when aborting.
Preallocate some TDs for large buffers.
===================================================================
uhci.c (1.103):
===================================================================
date: 2000/03/28 09:47:10; author: augustss; lines: +11 -1
Another patch for xfer abort...
XXX The current xfer queueing and aborting semantics should really
XXX be changed. It cannot be implemented in a sane way on UHCI.
XXX One day when I have lots of time I'll redesign it...
===================================================================
uhci.c (1.104): Correct a debug message.
uhci.c (1.105): Be more defensive in a DIAGNOSTIC test.
uhci.c (1.106):
===================================================================
revision 1.106
date: 2000/03/29 01:49:13; author: augustss; lines: +14 -309
*SIGH* Revert back to the old method of aborting xfers.
I had tested the new stuff for two months now, but as soon as I commited
it the problems started to appear. Murphy, no doubt...
===================================================================
usb_subr.c (1.70), usbdi.c (1.71), usbdivar.h (1.53):
===================================================================
revision 1.70
date: 2000/03/29 01:45:20; author: augustss; lines: +2 -1
Do not accept new xfers for queuing while a pipe is aborting.
===================================================================
2002-03-16 12:06:01 +00:00
|
|
|
callout_handle_init((struct callout_handle *)&sc->callout_handle);
|
1999-11-08 23:58:33 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
/* Set up interrupt pipe. */
|
2003-07-04 01:50:39 +00:00
|
|
|
err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
|
|
|
|
USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc,
|
More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
following improvements:
o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
quirk. This allows drivers to specify busy waiting only for
certain transfers (namely control transfers for reading/writing
registers and stuff).
o New USBD_FORCE_SHORT_XFER flag can be used to deal with
devices like the ADMtek Pegasus that sense the end of bulk OUT
transfers in a special way (if a transfer is exactly a multiple
of 64 bytes in size, you need to send an extra empty packet
to terminate the transfer).
o usbd_open_pipe_intr() now accepts an interval argument which
can be used to change the rate at which the interrupt callback
routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
value specified in the device's config data, but drivers can
override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
control transfers. We no longer force the non-tsleep hack for
bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
when a device has been detached, and use this flag to perform
tests to prevent the drivers from trying to do control transfers
if this is the case. This is necessary because calling if_detach()
with INET6 enabled will eventually result in a call to the driver's
ioctl() routine to delete the multicast groups on the interface,
which will result in attempts to perform control transfers. (It's
possible this also happens even without INET6 support enabled.) This
is pointless since we know that if the detach method has been called,
the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
to initialize the device states without trying to close and re-open the
pipes. This is partly because we don't want to frob things at interrupt
context, but also because this doesn't seem to work right and I don't
want to panic the system just because a USB device may have stopped
responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
transfer is needed. Unfortunately, the design of the chip makes it hard
to get this exactly right. Hopefully, this will go away once either
Nick or Lennart finds the bug in the uhci driver that makes this ugly
hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
|
|
|
sc->sc_ibuf, sc->sc_isize, ums_intr,
|
|
|
|
USBD_DEFAULT_INTERVAL);
|
1999-11-17 22:33:51 +00:00
|
|
|
if (err) {
|
1998-11-26 23:13:13 +00:00
|
|
|
DPRINTF(("ums_enable: usbd_open_pipe_intr failed, error=%d\n",
|
1999-11-17 22:33:51 +00:00
|
|
|
err));
|
1998-11-26 23:13:13 +00:00
|
|
|
sc->sc_enabled = 0;
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static void
|
1999-10-07 18:50:46 +00:00
|
|
|
ums_disable(priv)
|
|
|
|
void *priv;
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-10-07 18:50:46 +00:00
|
|
|
struct ums_softc *sc = priv;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
Huge merge from NetBSD:
usbdi.c (1.61):
===================================================================
revision 1.61
date: 2000/01/31 20:13:07; author: augustss; lines: +20 -4
Change the way the HC done method is invoked a little.
===================================================================
usbdi.c (1.65):
===================================================================
revision 1.65
date: 2000/03/08 15:34:10; author: augustss; lines: +4 -2
Get the status right when a polled transfer times out.
===================================================================
ohci.c (1.79), uhci.c (1.89), uhcivar.h (1.24), usb_port.h (1.22),
usbdivar.h (1.48):
===================================================================
date: 2000/03/23 07:01:46; author: thorpej;
New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.
The old timeout()/untimeout() API has been removed from the kernel.
===================================================================
uhci.c (1.80), usbdi.c (1.66):
===================================================================
date: 2000/03/23 18:59:10; author: thorpej;
Shake out some bugs from the callout changes.
===================================================================
ohci.c (1.80), uhci.c (1.91), uhcivar.h (1.25), usb_port.h (1.23),
usbdi.c (1.67), usbdivar.h (1.49):
===================================================================
date: 2000/03/24 22:03:30; author: augustss;
Some cleanup and renaming of the callouts used in USB drivers.
===================================================================
uhci.c (1.92), uhcivar.h (1.26):
===================================================================
date: 2000/03/24 22:57:58; author: augustss;
Two major changes:
Make each xfer have its own intr_info. This is necessary if we want
to queue multiple xfers on an endpoint. This should get rid of the
(mostly harmless) DIAGNOSTICs about intr_infos (not) being done.
Change (again!) how xfers are aborted. Aborting a TD is a nightmare
on the braindead UHCI controller. (Unless you stop the HC, thereby
losing isoc traffic.) Hopefully I got it right this time.
===================================================================
usbdivar.h (1.50):
===================================================================
revision 1.50
date: 2000/03/25 00:10:19; author: augustss; lines: +4 -2
GC an unsued field and add some DIAGNOSTIC in xfer.
===================================================================
ums.c: Use the callout functions instead of the timeout ones.
uhci.c (1.93):
===================================================================
revision 1.93
date: 2000/03/25 00:11:21; author: augustss;
lines: +26 -1
Add more DIAGNOSTIC when aborting isoc.
===================================================================
uhci.c (1.94), usbdivar.h (1.51):
===================================================================
date: 2000/03/25 07:13:05; author: augustss;
More DIAGNOSTIC.
Initialize a callout handle I forgot.
===================================================================
uhci.c (1.95):
===================================================================
revision 1.95
date: 2000/03/25 07:23:12; author: augustss;
Exp; lines: +24 -7
Improve uhci_dump_ii().
===================================================================
ohci.c (1.81), uhci.c (1.96), uhcivar.h (1.27), usb_subr.c (1.68),
usbdi.c (1.68), usbdivar.h (1.52):
===================================================================
date: 2000/03/25 18:02:33; author: augustss;
Rename and move around callout handles to make it more sane.
Add some DIAGNOSTIC.
Fix buglet in isoc abort on UHCI.
===================================================================
uhci.c (1.98):
===================================================================
revision 1.98
date: 2000/03/27 07:39:48; author: augustss; lines: +12 -4
Make it compile without DIAGNOSTIC.
===================================================================
uhci.c (1.99):
===================================================================
revision 1.99
date: 2000/03/27 08:01:09; author: augustss; lines: +1 -5
Remove some debug nonsense.
===================================================================
uhci.c (1.100):
===================================================================
revision 1.100
date: 2000/03/27 09:41:36; author: augustss; lines: +13 -3
Don't mess with QH in bulk abort for the moment.
===================================================================
uhci.c (1.102):
===================================================================
revision 1.102
date: 2000/03/27 22:42:57; author: augustss; lines: +66 -26
Be a little more careful when aborting.
Preallocate some TDs for large buffers.
===================================================================
uhci.c (1.103):
===================================================================
date: 2000/03/28 09:47:10; author: augustss; lines: +11 -1
Another patch for xfer abort...
XXX The current xfer queueing and aborting semantics should really
XXX be changed. It cannot be implemented in a sane way on UHCI.
XXX One day when I have lots of time I'll redesign it...
===================================================================
uhci.c (1.104): Correct a debug message.
uhci.c (1.105): Be more defensive in a DIAGNOSTIC test.
uhci.c (1.106):
===================================================================
revision 1.106
date: 2000/03/29 01:49:13; author: augustss; lines: +14 -309
*SIGH* Revert back to the old method of aborting xfers.
I had tested the new stuff for two months now, but as soon as I commited
it the problems started to appear. Murphy, no doubt...
===================================================================
usb_subr.c (1.70), usbdi.c (1.71), usbdivar.h (1.53):
===================================================================
revision 1.70
date: 2000/03/29 01:45:20; author: augustss; lines: +2 -1
Do not accept new xfers for queuing while a pipe is aborting.
===================================================================
2002-03-16 12:06:01 +00:00
|
|
|
usb_uncallout(sc->callout_handle, ums_add_to_queue_timeout, sc);
|
1999-11-08 23:58:33 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
/* Disable interrupts. */
|
|
|
|
usbd_abort_pipe(sc->sc_intrpipe);
|
|
|
|
usbd_close_pipe(sc->sc_intrpipe);
|
|
|
|
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
|
|
|
|
if (sc->qcount != 0)
|
|
|
|
DPRINTF(("Discarded %d bytes in queue\n", sc->qcount));
|
|
|
|
}
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static int
|
2004-06-16 09:47:26 +00:00
|
|
|
ums_open(struct cdev *dev, int flag, int fmt, usb_proc_ptr p)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-11-17 22:33:51 +00:00
|
|
|
struct ums_softc *sc;
|
|
|
|
|
1999-01-12 01:21:15 +00:00
|
|
|
USB_GET_SC_OPEN(ums, UMSUNIT(dev), sc);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
|
|
|
return ums_enable(sc);
|
|
|
|
}
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static int
|
2004-06-16 09:47:26 +00:00
|
|
|
ums_close(struct cdev *dev, int flag, int fmt, usb_proc_ptr p)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-11-17 22:33:51 +00:00
|
|
|
struct ums_softc *sc;
|
|
|
|
|
1999-01-12 01:21:15 +00:00
|
|
|
USB_GET_SC(ums, UMSUNIT(dev), sc);
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-06-13 20:49:12 +00:00
|
|
|
if (!sc)
|
1999-05-30 12:48:49 +00:00
|
|
|
return 0;
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
if (sc->sc_enabled)
|
|
|
|
ums_disable(sc);
|
1999-01-12 01:21:15 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static int
|
2004-06-16 09:47:26 +00:00
|
|
|
ums_read(struct cdev *dev, struct uio *uio, int flag)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-11-17 22:33:51 +00:00
|
|
|
struct ums_softc *sc;
|
1998-11-26 23:13:13 +00:00
|
|
|
int s;
|
|
|
|
char buf[sizeof(sc->qbuf)];
|
|
|
|
int l = 0;
|
|
|
|
int error;
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
USB_GET_SC(ums, UMSUNIT(dev), sc);
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
s = splusb();
|
1999-06-13 20:49:12 +00:00
|
|
|
if (!sc) {
|
|
|
|
splx(s);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
while (sc->qcount == 0 ) {
|
1999-06-13 20:49:12 +00:00
|
|
|
if (flag & IO_NDELAY) { /* non-blocking I/O */
|
1998-11-26 23:13:13 +00:00
|
|
|
splx(s);
|
|
|
|
return EWOULDBLOCK;
|
1999-06-13 20:49:12 +00:00
|
|
|
}
|
2003-07-04 01:50:39 +00:00
|
|
|
|
1999-06-13 20:49:12 +00:00
|
|
|
sc->state |= UMS_ASLEEP; /* blocking I/O */
|
1998-11-26 23:13:13 +00:00
|
|
|
error = tsleep(sc, PZERO | PCATCH, "umsrea", 0);
|
|
|
|
if (error) {
|
|
|
|
splx(s);
|
|
|
|
return error;
|
1999-01-22 00:59:52 +00:00
|
|
|
} else if (!sc->sc_enabled) {
|
|
|
|
splx(s);
|
|
|
|
return EINTR;
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-06-13 20:49:12 +00:00
|
|
|
/* check whether the device is still there */
|
|
|
|
|
|
|
|
sc = devclass_get_softc(ums_devclass, UMSUNIT(dev));
|
|
|
|
if (!sc) {
|
|
|
|
splx(s);
|
|
|
|
return EIO;
|
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
|
|
|
|
1999-06-13 20:49:12 +00:00
|
|
|
/*
|
|
|
|
* XXX we could optimise the use of splx/splusb somewhat. The writer
|
|
|
|
* process only extends qcount and qtail. We could copy them and use the copies
|
|
|
|
* to do the copying out of the queue.
|
|
|
|
*/
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
while ((sc->qcount > 0) && (uio->uio_resid > 0)) {
|
|
|
|
l = (sc->qcount < uio->uio_resid? sc->qcount:uio->uio_resid);
|
|
|
|
if (l > sizeof(buf))
|
|
|
|
l = sizeof(buf);
|
|
|
|
if (l > sizeof(sc->qbuf) - sc->qtail) /* transfer till end of buf */
|
|
|
|
l = sizeof(sc->qbuf) - sc->qtail;
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
uiomove(&sc->qbuf[sc->qtail], l, uio);
|
|
|
|
s = splusb();
|
|
|
|
|
|
|
|
if ( sc->qcount - l < 0 ) {
|
|
|
|
DPRINTF(("qcount below 0, count=%d l=%d\n", sc->qcount, l));
|
|
|
|
sc->qcount = l;
|
|
|
|
}
|
|
|
|
sc->qcount -= l; /* remove the bytes from the buffer */
|
|
|
|
sc->qtail = (sc->qtail + l) % sizeof(sc->qbuf);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-03 20:58:30 +00:00
|
|
|
Static int
|
2004-06-16 09:47:26 +00:00
|
|
|
ums_poll(struct cdev *dev, int events, usb_proc_ptr p)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-11-17 22:33:51 +00:00
|
|
|
struct ums_softc *sc;
|
1998-11-26 23:13:13 +00:00
|
|
|
int revents = 0;
|
|
|
|
int s;
|
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
USB_GET_SC(ums, UMSUNIT(dev), sc);
|
|
|
|
|
1999-06-13 20:49:12 +00:00
|
|
|
if (!sc)
|
|
|
|
return 0;
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
s = splusb();
|
1999-01-12 01:21:15 +00:00
|
|
|
if (events & (POLLIN | POLLRDNORM)) {
|
1998-11-26 23:13:13 +00:00
|
|
|
if (sc->qcount) {
|
|
|
|
revents = events & (POLLIN | POLLRDNORM);
|
|
|
|
} else {
|
|
|
|
sc->state |= UMS_SELECT;
|
2002-01-02 16:33:53 +00:00
|
|
|
selrecord(p, &sc->rsel);
|
1998-11-26 23:13:13 +00:00
|
|
|
}
|
1999-01-12 01:21:15 +00:00
|
|
|
}
|
1998-11-26 23:13:13 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return revents;
|
|
|
|
}
|
2003-07-04 01:50:39 +00:00
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
int
|
2004-06-16 09:47:26 +00:00
|
|
|
ums_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p)
|
1998-11-26 23:13:13 +00:00
|
|
|
{
|
1999-11-17 22:33:51 +00:00
|
|
|
struct ums_softc *sc;
|
1998-11-26 23:13:13 +00:00
|
|
|
int error = 0;
|
|
|
|
int s;
|
1999-02-21 16:20:19 +00:00
|
|
|
mousemode_t mode;
|
1998-11-26 23:13:13 +00:00
|
|
|
|
1999-11-17 22:33:51 +00:00
|
|
|
USB_GET_SC(ums, UMSUNIT(dev), sc);
|
|
|
|
|
1999-06-13 20:49:12 +00:00
|
|
|
if (!sc)
|
|
|
|
return EIO;
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
switch(cmd) {
|
|
|
|
case MOUSE_GETHWINFO:
|
|
|
|
*(mousehw_t *)addr = sc->hw;
|
|
|
|
break;
|
|
|
|
case MOUSE_GETMODE:
|
|
|
|
*(mousemode_t *)addr = sc->mode;
|
1999-02-21 16:20:19 +00:00
|
|
|
break;
|
|
|
|
case MOUSE_SETMODE:
|
|
|
|
mode = *(mousemode_t *)addr;
|
|
|
|
|
|
|
|
if (mode.level == -1)
|
|
|
|
/* don't change the current setting */
|
|
|
|
;
|
|
|
|
else if ((mode.level < 0) || (mode.level > 1))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
sc->mode.level = mode.level;
|
|
|
|
|
|
|
|
if (sc->mode.level == 0) {
|
|
|
|
if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
|
|
|
|
sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
|
|
|
|
else
|
|
|
|
sc->hw.buttons = sc->nbuttons;
|
|
|
|
sc->mode.protocol = MOUSE_PROTO_MSC;
|
|
|
|
sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
|
|
|
|
sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
|
|
|
|
sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
|
|
|
|
} else if (sc->mode.level == 1) {
|
|
|
|
if (sc->nbuttons > MOUSE_SYS_MAXBUTTON)
|
|
|
|
sc->hw.buttons = MOUSE_SYS_MAXBUTTON;
|
|
|
|
else
|
|
|
|
sc->hw.buttons = sc->nbuttons;
|
|
|
|
sc->mode.protocol = MOUSE_PROTO_SYSMOUSE;
|
|
|
|
sc->mode.packetsize = MOUSE_SYS_PACKETSIZE;
|
|
|
|
sc->mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
|
|
|
|
sc->mode.syncmask[1] = MOUSE_SYS_SYNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(sc->qbuf, sizeof(sc->qbuf));
|
|
|
|
sc->qhead = sc->qtail = sc->qcount = 0;
|
|
|
|
splx(s);
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
break;
|
|
|
|
case MOUSE_GETLEVEL:
|
|
|
|
*(int *)addr = sc->mode.level;
|
1999-02-21 16:20:19 +00:00
|
|
|
break;
|
|
|
|
case MOUSE_SETLEVEL:
|
|
|
|
if (*(int *)addr < 0 || *(int *)addr > 1)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
sc->mode.level = *(int *)addr;
|
|
|
|
|
|
|
|
if (sc->mode.level == 0) {
|
|
|
|
if (sc->nbuttons > MOUSE_MSC_MAXBUTTON)
|
|
|
|
sc->hw.buttons = MOUSE_MSC_MAXBUTTON;
|
|
|
|
else
|
|
|
|
sc->hw.buttons = sc->nbuttons;
|
|
|
|
sc->mode.protocol = MOUSE_PROTO_MSC;
|
|
|
|
sc->mode.packetsize = MOUSE_MSC_PACKETSIZE;
|
|
|
|
sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK;
|
|
|
|
sc->mode.syncmask[1] = MOUSE_MSC_SYNC;
|
|
|
|
} else if (sc->mode.level == 1) {
|
|
|
|
if (sc->nbuttons > MOUSE_SYS_MAXBUTTON)
|
|
|
|
sc->hw.buttons = MOUSE_SYS_MAXBUTTON;
|
|
|
|
else
|
|
|
|
sc->hw.buttons = sc->nbuttons;
|
|
|
|
sc->mode.protocol = MOUSE_PROTO_SYSMOUSE;
|
|
|
|
sc->mode.packetsize = MOUSE_SYS_PACKETSIZE;
|
|
|
|
sc->mode.syncmask[0] = MOUSE_SYS_SYNCMASK;
|
|
|
|
sc->mode.syncmask[1] = MOUSE_SYS_SYNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(sc->qbuf, sizeof(sc->qbuf));
|
|
|
|
sc->qhead = sc->qtail = sc->qcount = 0;
|
|
|
|
splx(s);
|
|
|
|
|
1998-11-26 23:13:13 +00:00
|
|
|
break;
|
|
|
|
case MOUSE_GETSTATUS: {
|
|
|
|
mousestatus_t *status = (mousestatus_t *) addr;
|
|
|
|
|
|
|
|
s = splusb();
|
|
|
|
*status = sc->status;
|
|
|
|
sc->status.obutton = sc->status.button;
|
|
|
|
sc->status.button = 0;
|
2004-12-12 05:34:20 +00:00
|
|
|
sc->status.dx = sc->status.dy = sc->status.dz = sc->status.dt = 0;
|
1998-11-26 23:13:13 +00:00
|
|
|
splx(s);
|
|
|
|
|
2004-12-12 05:34:20 +00:00
|
|
|
if (status->dx || status->dy || status->dz || status->dt)
|
1998-11-26 23:13:13 +00:00
|
|
|
status->flags |= MOUSE_POSCHANGED;
|
|
|
|
if (status->button != status->obutton)
|
|
|
|
status->flags |= MOUSE_BUTTONSCHANGED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1999-11-08 07:10:48 +00:00
|
|
|
DRIVER_MODULE(ums, uhub, ums_driver, ums_devclass, usbd_driver_load, 0);
|