@@ -60,7 +60,7 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state fie
60
60
#define MOUSE_REPORT_ID 0x29
61
61
#define MOUSE2_REPORT_ID 0x12
62
62
#define DOUBLE_REPORT_ID 0xf7
63
- #define USB_BATTERY_TIMEOUT_MS 60000
63
+ #define USB_BATTERY_TIMEOUT_SEC 60
64
64
65
65
/* These definitions are not precise, but they're close enough. (Bits
66
66
* 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem
@@ -791,17 +791,31 @@ static void magicmouse_enable_mt_work(struct work_struct *work)
791
791
hid_err (msc -> hdev , "unable to request touch data (%d)\n" , ret );
792
792
}
793
793
794
+ static bool is_usb_magicmouse2 (__u32 vendor , __u32 product )
795
+ {
796
+ if (vendor != USB_VENDOR_ID_APPLE )
797
+ return false;
798
+ return product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
799
+ product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC ;
800
+ }
801
+
802
+ static bool is_usb_magictrackpad2 (__u32 vendor , __u32 product )
803
+ {
804
+ if (vendor != USB_VENDOR_ID_APPLE )
805
+ return false;
806
+ return product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
807
+ product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ;
808
+ }
809
+
794
810
static int magicmouse_fetch_battery (struct hid_device * hdev )
795
811
{
796
812
#ifdef CONFIG_HID_BATTERY_STRENGTH
797
813
struct hid_report_enum * report_enum ;
798
814
struct hid_report * report ;
799
815
800
- if (!hdev -> battery || hdev -> vendor != USB_VENDOR_ID_APPLE ||
801
- (hdev -> product != USB_DEVICE_ID_APPLE_MAGICMOUSE2 &&
802
- hdev -> product != USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC &&
803
- hdev -> product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
804
- hdev -> product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ))
816
+ if (!hdev -> battery ||
817
+ (!is_usb_magicmouse2 (hdev -> vendor , hdev -> product ) &&
818
+ !is_usb_magictrackpad2 (hdev -> vendor , hdev -> product )))
805
819
return -1 ;
806
820
807
821
report_enum = & hdev -> report_enum [hdev -> battery_report_type ];
@@ -827,7 +841,7 @@ static void magicmouse_battery_timer_tick(struct timer_list *t)
827
841
828
842
if (magicmouse_fetch_battery (hdev ) == 0 ) {
829
843
mod_timer (& msc -> battery_timer ,
830
- jiffies + msecs_to_jiffies ( USB_BATTERY_TIMEOUT_MS ));
844
+ jiffies + secs_to_jiffies ( USB_BATTERY_TIMEOUT_SEC ));
831
845
}
832
846
}
833
847
@@ -863,17 +877,17 @@ static int magicmouse_probe(struct hid_device *hdev,
863
877
return ret ;
864
878
}
865
879
866
- timer_setup ( & msc -> battery_timer , magicmouse_battery_timer_tick , 0 );
867
- mod_timer ( & msc -> battery_timer ,
868
- jiffies + msecs_to_jiffies ( USB_BATTERY_TIMEOUT_MS ) );
869
- magicmouse_fetch_battery ( hdev );
870
-
871
- if ( id -> vendor == USB_VENDOR_ID_APPLE &&
872
- ( id -> product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
873
- id -> product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC ||
874
- ( (id -> product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
875
- id -> product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ) &&
876
- hdev -> type != HID_TYPE_USBMOUSE ) ))
880
+ if ( is_usb_magicmouse2 ( id -> vendor , id -> product ) ||
881
+ is_usb_magictrackpad2 ( id -> vendor , id -> product )) {
882
+ timer_setup ( & msc -> battery_timer , magicmouse_battery_timer_tick , 0 );
883
+ mod_timer ( & msc -> battery_timer ,
884
+ jiffies + secs_to_jiffies ( USB_BATTERY_TIMEOUT_SEC ));
885
+ magicmouse_fetch_battery ( hdev );
886
+ }
887
+
888
+ if ( is_usb_magicmouse2 (id -> vendor , id -> product ) ||
889
+ ( is_usb_magictrackpad2 ( id -> vendor , id -> product ) &&
890
+ hdev -> type != HID_TYPE_USBMOUSE ))
877
891
return 0 ;
878
892
879
893
if (!msc -> input ) {
@@ -936,7 +950,10 @@ static int magicmouse_probe(struct hid_device *hdev,
936
950
937
951
return 0 ;
938
952
err_stop_hw :
939
- timer_delete_sync (& msc -> battery_timer );
953
+ if (is_usb_magicmouse2 (id -> vendor , id -> product ) ||
954
+ is_usb_magictrackpad2 (id -> vendor , id -> product ))
955
+ timer_delete_sync (& msc -> battery_timer );
956
+
940
957
hid_hw_stop (hdev );
941
958
return ret ;
942
959
}
@@ -947,7 +964,9 @@ static void magicmouse_remove(struct hid_device *hdev)
947
964
948
965
if (msc ) {
949
966
cancel_delayed_work_sync (& msc -> work );
950
- timer_delete_sync (& msc -> battery_timer );
967
+ if (is_usb_magicmouse2 (hdev -> vendor , hdev -> product ) ||
968
+ is_usb_magictrackpad2 (hdev -> vendor , hdev -> product ))
969
+ timer_delete_sync (& msc -> battery_timer );
951
970
}
952
971
953
972
hid_hw_stop (hdev );
@@ -964,11 +983,8 @@ static const __u8 *magicmouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
964
983
* 0x05, 0x01, // Usage Page (Generic Desktop) 0
965
984
* 0x09, 0x02, // Usage (Mouse) 2
966
985
*/
967
- if (hdev -> vendor == USB_VENDOR_ID_APPLE &&
968
- (hdev -> product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
969
- hdev -> product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC ||
970
- hdev -> product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
971
- hdev -> product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ) &&
986
+ if ((is_usb_magicmouse2 (hdev -> vendor , hdev -> product ) ||
987
+ is_usb_magictrackpad2 (hdev -> vendor , hdev -> product )) &&
972
988
* rsize == 83 && rdesc [46 ] == 0x84 && rdesc [58 ] == 0x85 ) {
973
989
hid_info (hdev ,
974
990
"fixing up magicmouse battery report descriptor\n" );
0 commit comments