Subject: Re: Apple Mighty Mouse
To: None <tech-kern@NetBSD.org>
From: Kouichirou Hiratsuka <hira@po6.nsk.ne.jp>
List: tech-kern
Date: 09/11/2005 20:36:21
Hello,

At Tue, 06 Sep 2005 01:20:20 +0900,
I wrote:
>
> I bought the Apple Mighty Mouse.  It almost works fine.  However,
> the scroll ball has a problem.  I can scroll the firefox vertically
> by scrolling the scroll ball horizontally.
> 
> With this mouse, HUG_Z represents different data from HUG_WHEEL.
> HUG_Z reports horizontal scroll and HUG_WHEEL reports vertical
> scroll.  If HUG_Z is available, ums.c uses it and don't use
> HUG_WHEEL.  It's wrong for this mouse.
> 
How about this patch?

best regards.
--
 Kouichirou Hiratsuka
   hira@po6.nsk.ne.jp

Index: ums.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/ums.c,v
retrieving revision 1.61
diff -u -r1.61 ums.c
--- ums.c	13 Aug 2005 14:55:39 -0000	1.61
+++ ums.c	11 Sep 2005 10:53:47 -0000
@@ -102,6 +102,7 @@
 #define UMS_Z		0x01	/* z direction available */
 #define UMS_SPUR_BUT_UP	0x02	/* spurious button up events */
 #define UMS_REVZ	0x04	/* Z-axis is reversed */
+#define UMS_WHEEL_IS_Z	0x08	/* use wheel as Z-axis */
 
 	int nbuttons;
 
@@ -152,7 +153,7 @@
 	int size;
 	void *desc;
 	u_int32_t flags, quirks;
-	int i, wheel;
+	int i, z, wheel;
 	struct hid_location loc_btn;
 
 	sc->sc_hdev.sc_intr = ums_intr;
@@ -164,6 +165,8 @@
 		sc->flags |= UMS_REVZ;
 	if (quirks & UQ_SPUR_BUT_UP)
 		sc->flags |= UMS_SPUR_BUT_UP;
+	if (quirks & UQ_WHEEL_IS_Z)
+		sc->flags |= UMS_WHEEL_IS_Z;
 
 	uhidev_get_report_desc(uha->parent, &desc, &size);
 
@@ -193,11 +196,14 @@
 
 	/* 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),
-	       uha->reportid, hid_input, &sc->sc_loc_z, &flags) ||
-	    (wheel = hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
-						       HUG_WHEEL),
-	       uha->reportid, hid_input, &sc->sc_loc_z, &flags))) {
+	z = hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
+		       uha->reportid, hid_input, &sc->sc_loc_z, &flags);
+	if (!z || (sc->flags & UMS_WHEEL_IS_Z))
+		wheel = hid_locate(desc, size,
+				   HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
+				   uha->reportid, hid_input, &sc->sc_loc_z,
+				   &flags);
+	if (z || wheel) {
 		if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
 			sc->sc_loc_z.size = 0;	/* Bad Z coord, ignore it */
 		} else {
Index: usb_quirks.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/usb_quirks.c,v
retrieving revision 1.52
diff -u -r1.52 usb_quirks.c
--- usb_quirks.c	2 Mar 2005 11:37:27 -0000	1.52
+++ usb_quirks.c	10 Sep 2005 08:42:24 -0000
@@ -110,6 +110,8 @@
  { USB_VENDOR_NEC, USB_PRODUCT_NEC_PICTY800,	    ANY,   { UQ_BROKEN_BIDIR }},
 
  { USB_VENDOR_HP, USB_PRODUCT_HP_1220C,		    ANY,   { UQ_BROKEN_BIDIR }},
+
+ { USB_VENDOR_APPLE, USB_PRODUCT_APPLE_MIGHTYMOUSE, ANY,   { UQ_WHEEL_IS_Z }},
  { 0, 0, 0, { 0 } }
 };
 
Index: usb_quirks.h
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/usb_quirks.h,v
retrieving revision 1.20
diff -u -r1.20 usb_quirks.h
--- usb_quirks.h	15 Apr 2001 09:38:01 -0000	1.20
+++ usb_quirks.h	10 Sep 2005 08:42:24 -0000
@@ -54,6 +54,7 @@
 #define UQ_AU_INP_ASYNC	0x0800	/* input is async despite claim of adaptive */
 #define UQ_ASSUME_CM_OVER_DATA 0x1000 /* modem device breaks on cm over data */
 #define UQ_BROKEN_BIDIR	0x2000	/* printer has broken bidir mode */
+#define UQ_WHEEL_IS_Z	0x4000	/* use wheel as Z-axis */
 };
 
 extern const struct usbd_quirks usbd_no_quirk;
Index: usbdevs
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/usbdevs,v
retrieving revision 1.412
diff -u -r1.412 usbdevs
--- usbdevs	7 Sep 2005 01:34:19 -0000	1.412
+++ usbdevs	10 Sep 2005 08:42:26 -0000
@@ -583,6 +583,7 @@
 
 /* Apple Computer products */
 product APPLE OPTMOUSE		0x0302	Optical mouse
+product APPLE MIGHTYMOUSE	0x0304	Mighty Mouse
 product APPLE SPEAKERS		0x1101	Speakers
 
 /* Asahi Optical products */