Support Apple Magic Mouse
cover Support Apple Magic Mouse
he Magic Mouse uses a vendor-specific code page to turn on its multi-touch support, and then reports that with an "unlisted" input report. The first two patches in this series allow the driver to (respectively) register for and enable those reports.
The third patch is the driver itself. The major and minor axis lengths use what the device sends, and the units for those are larger than for the touch resolution. I'm not sure how hard a rule it is that those be in surface units.
drivers/hid/Kconfig | 10 + drivers/hid/Makefile | 1 + drivers/hid/hid-core.c | 4 +- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-magicmouse.c | 395 +++++++++++++++++++++++++++++++++++++++++ drivers/hid/usbhid/hid-core.c | 23 +++ include/linux/hid.h | 5 + net/bluetooth/hidp/core.c | 25 +++ 8 files changed, 463 insertions(+), 1 deletions(-)
RFC PATCH 1/3 Export hid_register_report().
The Apple Magic Mouse (and probably other devices) publish reports that are not called out in their HID report descriptors -- they only send them when enabled through other writes to the device. This allows a driver to handle these unlisted reports.
--- drivers/hid/hid-core.c | 3 ++- include/linux/hid.h | 1 + 2 files changed, 3 insertions(+), 1 deletions(-)
drivers/hid/hid-core.c +2 -1
@@ -51,7 +51,7 @@ EXPORT_SYMBOL_GPL(hid_debug);* Register a new report for a device. */ -static struct hid_report *hid_register_report (struct hid_device *device,unsigned type,unsigned id) +struct hid_report *hid_register_report (struct hid_device *device,unsigned type,unsigned id) {struct hid_report_enum *report_enum = device->report_enum + type;struct hid_report *report;
@@ -75,6 +75,7 @@ static struct hid_report *hid_register_report(struct hid_device *device, unsignereturn report; } +EXPORT_SYMBOL_GPL (hid_register_report);/* * Register a new field for this report.
include/linux/hid.h +1 -0
@@ -690,6 +690,7 @@ int hid_input_report(struct hid_device *, int type, u8 *, int, int);int hidinput_find_field (struct hid_device *hid,unsigned int type,unsigned int code,struct hid_field **field);void hid_output_report (struct hid_report *report,__u8 *data);struct hid_device *hid_allocate_device (void ); +struct hid_report *hid_register_report (struct hid_device *device,unsigned type,unsigned id);int hid_parse_report (struct hid_device *hid,__u8 *start,unsigned size);int hid_check_keys_pressed (struct hid_device *hid);int hid_connect (struct hid_device *hid,unsigned int connect_mask);
Signature · 1 line
1.6.5.6
RFC PATCH 2/3 Add a hid_ll_driver.hid_set_report() function.
This allows a HID device driver to send a Set_Report(Output) or Set_Report(Feature) message to its device.
--- drivers/hid/usbhid/hid-core.c | 23 +++++++++++++++++++++++ include/linux/hid.h | 4 ++++ net/bluetooth/hidp/core.c | 25 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 0 deletions(-)
drivers/hid/usbhid/hid-core.c +23 -0
@@ -1067,6 +1067,28 @@ static int usbhid_power(struct hid_device *hid, int lvl)return r; } +static int usbhid_set_report (struct hid_device *hid,int type, +__u8 *buf,int count) +{ +struct usb_device *dev =hid_to_usb_dev (hid); +struct usbhid_device *usbhid = hid->driver_data; +struct usb_interface *intf = usbhid->intf; +struct usb_host_interface *interface = intf->cur_altsetting; +int ret; + + ret =usb_control_msg (dev,usb_sndctrlpipe (dev,0 ), +HID_REQ_SET_REPORT , +USB_DIR_OUT |USB_TYPE_CLASS |USB_RECIP_INTERFACE , + ((type +1 ) <<8 ) | *buf, + interface->desc.bInterfaceNumber, buf +1 , count -1 , +USB_CTRL_SET_TIMEOUT ); + +if (ret >0 ) + ret++; + +return ret; +} +static struct hid_ll_driver usb_hid_driver = { .parse = usbhid_parse, .start = usbhid_start,
@@ -1075,6 +1097,7 @@ static struct hid_ll_driver usb_hid_driver = { .close = usbhid_close, .power = usbhid_power, .hidinput_input_event = usb_hidinput_input_event, + .hid_set_report = usbhid_set_report, };static int usbhid_probe (struct usb_interface *intf,const struct usb_device_id *id)
include/linux/hid.h +4 -0
@@ -642,6 +642,7 @@ struct hid_driver {* @hidinput_input_event: event input event (e.g. ff or leds) * @parse: this method is called only once to parse the device data, * shouldn't allocate anything to not leak memory +* @hid_set_report: sends a SET_REPORT request to the device */ struct hid_ll_driver {int (*start)(struct hid_device *hdev);
@@ -656,6 +657,9 @@ struct hid_ll_driver { unsigned int code, int value);int (*parse)(struct hid_device *hdev); + +int (*hid_set_report) (struct hid_device *hdev,int type, +__u8 *buf,int count); };#define PM_HINT_FULLON 1<<5
net/bluetooth/hidp/core.c +25 -0
@@ -752,6 +752,30 @@ static void hidp_stop(struct hid_device *hid) hid->claimed =0 ; } +static int hidp_set_report (struct hid_device *hid,int type, +__u8 *data,int size) +{ +struct hidp_session *session = hid->driver_data; +struct sk_buff *skb; + +BT_DBG ("session %p hid %p data %p size %d" , session, hid, data, size); + +if (!(skb =alloc_skb (size +1 ,GFP_ATOMIC ))) { +BT_ERR ("Can't allocate memory for new frame" ); +return -ENOMEM ; + } + + *skb_put (skb,1 ) =0xa0 | (type +1 ); +if (size >0 ) +memcpy (skb_put (skb, size), data, size); + +skb_queue_tail (&session->intr_transmit, skb); + +hidp_schedule (session); + +return 0 ; +} +static struct hid_ll_driver hidp_hid_driver = { .parse = hidp_parse, .start = hidp_start,
@@ -759,6 +783,7 @@ static struct hid_ll_driver hidp_hid_driver = { .open = hidp_open, .close = hidp_close, .hidinput_input_event = hidp_hidinput_event, + .hid_set_report = hidp_set_report, }; static int hidp_setup_hid(struct hidp_session *session,
Signature · 1 line
1.6.5.6
RFC PATCH 3/3 Add a device driver for the Apple Magic Mouse.
--- drivers/hid/Kconfig | 10 + drivers/hid/Makefile | 1 + drivers/hid/hid-core.c | 1 + drivers/hid/hid-ids.h | 1 + drivers/hid/hid-magicmouse.c | 395 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 408 insertions(+), 0 deletions(-) create mode 100644 drivers/hid/hid-magicmouse.c
drivers/hid/Kconfig +10 -0
@@ -183,6 +183,16 @@ config LOGIRUMBLEPAD2_FF Say Y here if you want to enable force feedback support for Logitech Rumblepad 2 devices. +config HID_MAGICMOUSE + tristate "Apple" if EMBEDDED + depends on (USB_HID || BT_HIDP) + default !EMBEDDED + ---help--- + Support for the Apple Magic Mouse. + + Say Y here if you want support for the multi-touch features of the + Apple Wireless "Magic" Mouse. + config HID_MICROSOFT tristate "Microsoft" if EMBEDDED depends on USB_HID
drivers/hid/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_HID_GYRATION) += hid-gyration.o obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o obj-$(CONFIG_HID_KYE) += hid-kye.o obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o +obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o
drivers/hid/hid-core.c +1 -0
@@ -1254,6 +1254,7 @@ static const struct hid_device_id hid_blacklist[] = { { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
drivers/hid/hid-ids.h +1 -0
@@ -56,6 +56,7 @@#define USB_VENDOR_ID_APPLE 0x05ac#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 +#define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
drivers/hid/hid-magicmouse.c new file +395 -0
395 lines not on this page · raw message
Signature · 1 line
1.6.5.6