@@ -54,6 +54,7 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie
54
54
#define TRACKPAD2_USB_REPORT_ID 0x02
55
55
#define TRACKPAD2_BT_REPORT_ID 0x31
56
56
#define MOUSE_REPORT_ID 0x29
57
+ #define MOUSE2_REPORT_ID 0x12
57
58
#define DOUBLE_REPORT_ID 0xf7
58
59
/* These definitions are not precise, but they're close enough. (Bits
59
60
* 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem
@@ -195,7 +196,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
195
196
int id , x , y , size , orientation , touch_major , touch_minor , state , down ;
196
197
int pressure = 0 ;
197
198
198
- if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ) {
199
+ if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
200
+ input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ) {
199
201
id = (tdata [6 ] << 2 | tdata [5 ] >> 6 ) & 0xf ;
200
202
x = (tdata [1 ] << 28 | tdata [0 ] << 20 ) >> 20 ;
201
203
y = - ((tdata [2 ] << 24 | tdata [1 ] << 16 ) >> 20 );
@@ -296,7 +298,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
296
298
input_report_abs (input , ABS_MT_PRESSURE , pressure );
297
299
298
300
if (report_undeciphered ) {
299
- if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE )
301
+ if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
302
+ input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 )
300
303
input_event (input , EV_MSC , MSC_RAW , tdata [7 ]);
301
304
else if (input -> id .product !=
302
305
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 )
@@ -380,6 +383,34 @@ static int magicmouse_raw_event(struct hid_device *hdev,
380
383
* ts = data[3] >> 6 | data[4] << 2 | data[5] << 10;
381
384
*/
382
385
break ;
386
+ case MOUSE2_REPORT_ID :
387
+ /* Size is either 8 or (14 + 8 * N) */
388
+ if (size != 8 && (size < 14 || (size - 14 ) % 8 != 0 ))
389
+ return 0 ;
390
+ npoints = (size - 14 ) / 8 ;
391
+ if (npoints > 15 ) {
392
+ hid_warn (hdev , "invalid size value (%d) for MOUSE2_REPORT_ID\n" ,
393
+ size );
394
+ return 0 ;
395
+ }
396
+ msc -> ntouches = 0 ;
397
+ for (ii = 0 ; ii < npoints ; ii ++ )
398
+ magicmouse_emit_touch (msc , ii , data + ii * 8 + 14 );
399
+
400
+ /* When emulating three-button mode, it is important
401
+ * to have the current touch information before
402
+ * generating a click event.
403
+ */
404
+ x = (int )((data [3 ] << 24 ) | (data [2 ] << 16 )) >> 16 ;
405
+ y = (int )((data [5 ] << 24 ) | (data [4 ] << 16 )) >> 16 ;
406
+ clicks = data [1 ];
407
+
408
+ /* The following bits provide a device specific timestamp. They
409
+ * are unused here.
410
+ *
411
+ * ts = data[11] >> 6 | data[12] << 2 | data[13] << 10;
412
+ */
413
+ break ;
383
414
case DOUBLE_REPORT_ID :
384
415
/* Sometimes the trackpad sends two touch reports in one
385
416
* packet.
@@ -392,7 +423,8 @@ static int magicmouse_raw_event(struct hid_device *hdev,
392
423
return 0 ;
393
424
}
394
425
395
- if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ) {
426
+ if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
427
+ input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ) {
396
428
magicmouse_emit_buttons (msc , clicks & 3 );
397
429
input_report_rel (input , REL_X , x );
398
430
input_report_rel (input , REL_Y , y );
@@ -415,7 +447,8 @@ static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hd
415
447
416
448
__set_bit (EV_KEY , input -> evbit );
417
449
418
- if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ) {
450
+ if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
451
+ input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ) {
419
452
__set_bit (BTN_LEFT , input -> keybit );
420
453
__set_bit (BTN_RIGHT , input -> keybit );
421
454
if (emulate_3button )
@@ -480,7 +513,8 @@ static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hd
480
513
* the origin at the same position, and just uses the additive
481
514
* inverse of the reported Y.
482
515
*/
483
- if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ) {
516
+ if (input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
517
+ input -> id .product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ) {
484
518
input_set_abs_params (input , ABS_MT_ORIENTATION , -31 , 32 , 1 , 0 );
485
519
input_set_abs_params (input , ABS_MT_POSITION_X ,
486
520
MOUSE_MIN_X , MOUSE_MAX_X , 4 , 0 );
@@ -586,6 +620,7 @@ static int magicmouse_probe(struct hid_device *hdev,
586
620
{
587
621
const u8 * feature ;
588
622
const u8 feature_mt [] = { 0xD7 , 0x01 };
623
+ const u8 feature_mt_mouse2 [] = { 0xF1 , 0x02 , 0x01 };
589
624
const u8 feature_mt_trackpad2_usb [] = { 0x02 , 0x01 };
590
625
const u8 feature_mt_trackpad2_bt [] = { 0xF1 , 0x02 , 0x01 };
591
626
u8 * buf ;
@@ -631,6 +666,9 @@ static int magicmouse_probe(struct hid_device *hdev,
631
666
if (id -> product == USB_DEVICE_ID_APPLE_MAGICMOUSE )
632
667
report = hid_register_report (hdev , HID_INPUT_REPORT ,
633
668
MOUSE_REPORT_ID , 0 );
669
+ else if (id -> product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 )
670
+ report = hid_register_report (hdev , HID_INPUT_REPORT ,
671
+ MOUSE2_REPORT_ID , 0 );
634
672
else if (id -> product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ) {
635
673
if (id -> vendor == BT_VENDOR_ID_APPLE )
636
674
report = hid_register_report (hdev , HID_INPUT_REPORT ,
@@ -660,6 +698,9 @@ static int magicmouse_probe(struct hid_device *hdev,
660
698
feature_size = sizeof (feature_mt_trackpad2_usb );
661
699
feature = feature_mt_trackpad2_usb ;
662
700
}
701
+ } else if (id -> product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ) {
702
+ feature_size = sizeof (feature_mt_mouse2 );
703
+ feature = feature_mt_mouse2 ;
663
704
} else {
664
705
feature_size = sizeof (feature_mt );
665
706
feature = feature_mt ;
@@ -696,6 +737,8 @@ static int magicmouse_probe(struct hid_device *hdev,
696
737
static const struct hid_device_id magic_mice [] = {
697
738
{ HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE ,
698
739
USB_DEVICE_ID_APPLE_MAGICMOUSE ), .driver_data = 0 },
740
+ { HID_BLUETOOTH_DEVICE (BT_VENDOR_ID_APPLE ,
741
+ USB_DEVICE_ID_APPLE_MAGICMOUSE2 ), .driver_data = 0 },
699
742
{ HID_BLUETOOTH_DEVICE (USB_VENDOR_ID_APPLE ,
700
743
USB_DEVICE_ID_APPLE_MAGICTRACKPAD ), .driver_data = 0 },
701
744
{ HID_BLUETOOTH_DEVICE (BT_VENDOR_ID_APPLE ,
0 commit comments