Skip to content

Commit 7f70c81

Browse files
mr-calgregkh
authored andcommitted
HID: magicmouse: Apple Magic Trackpad 2 USB-C driver support
[ Upstream commit 87a2f10 ] Adds driver support for the USB-C model of Apple's Magic Trackpad 2. The 2024 USB-C model is compatible with the existing Magic Trackpad 2 driver but has a different hardware ID. Link: https://bugzilla.kernel.org/show_bug.cgi?id=219470 Signed-off-by: Callahan Kovacs <[email protected]> Signed-off-by: Jiri Kosina <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent cd38a8f commit 7f70c81

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

drivers/hid/hid-ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#define USB_DEVICE_ID_APPLE_MAGICMOUSE2 0x0269
9595
#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD 0x030e
9696
#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
97+
#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC 0x0324
9798
#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e
9899
#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f
99100
#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214

drivers/hid/hid-magicmouse.c

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
227227
touch_minor = tdata[4];
228228
state = tdata[7] & TOUCH_STATE_MASK;
229229
down = state != TOUCH_STATE_NONE;
230-
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
230+
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
231+
input->id.product ==
232+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
231233
id = tdata[8] & 0xf;
232234
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
233235
y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
@@ -259,8 +261,9 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
259261
/* If requested, emulate a scroll wheel by detecting small
260262
* vertical touch motions.
261263
*/
262-
if (emulate_scroll_wheel && (input->id.product !=
263-
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)) {
264+
if (emulate_scroll_wheel &&
265+
input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
266+
input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
264267
unsigned long now = jiffies;
265268
int step_x = msc->touches[id].scroll_x - x;
266269
int step_y = msc->touches[id].scroll_y - y;
@@ -359,15 +362,19 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
359362
input_report_abs(input, ABS_MT_POSITION_X, x);
360363
input_report_abs(input, ABS_MT_POSITION_Y, y);
361364

362-
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)
365+
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
366+
input->id.product ==
367+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC)
363368
input_report_abs(input, ABS_MT_PRESSURE, pressure);
364369

365370
if (report_undeciphered) {
366371
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE ||
367372
input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2)
368373
input_event(input, EV_MSC, MSC_RAW, tdata[7]);
369374
else if (input->id.product !=
370-
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)
375+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
376+
input->id.product !=
377+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC)
371378
input_event(input, EV_MSC, MSC_RAW, tdata[8]);
372379
}
373380
}
@@ -493,7 +500,9 @@ static int magicmouse_raw_event(struct hid_device *hdev,
493500
magicmouse_emit_buttons(msc, clicks & 3);
494501
input_report_rel(input, REL_X, x);
495502
input_report_rel(input, REL_Y, y);
496-
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
503+
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
504+
input->id.product ==
505+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
497506
input_mt_sync_frame(input);
498507
input_report_key(input, BTN_MOUSE, clicks & 1);
499508
} else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
@@ -545,7 +554,9 @@ static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hd
545554
__set_bit(REL_WHEEL_HI_RES, input->relbit);
546555
__set_bit(REL_HWHEEL_HI_RES, input->relbit);
547556
}
548-
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
557+
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
558+
input->id.product ==
559+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
549560
/* If the trackpad has been connected to a Mac, the name is
550561
* automatically personalized, e.g., "José Expósito's Trackpad".
551562
* When connected through Bluetooth, the personalized name is
@@ -621,7 +632,9 @@ static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hd
621632
MOUSE_RES_X);
622633
input_abs_set_res(input, ABS_MT_POSITION_Y,
623634
MOUSE_RES_Y);
624-
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
635+
} else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
636+
input->id.product ==
637+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
625638
input_set_abs_params(input, ABS_MT_PRESSURE, 0, 253, 0, 0);
626639
input_set_abs_params(input, ABS_PRESSURE, 0, 253, 0, 0);
627640
input_set_abs_params(input, ABS_MT_ORIENTATION, -3, 4, 0, 0);
@@ -660,7 +673,8 @@ static int magicmouse_setup_input(struct input_dev *input, struct hid_device *hd
660673
input_set_events_per_packet(input, 60);
661674

662675
if (report_undeciphered &&
663-
input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
676+
input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
677+
input->id.product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
664678
__set_bit(EV_MSC, input->evbit);
665679
__set_bit(MSC_RAW, input->mscbit);
666680
}
@@ -685,7 +699,9 @@ static int magicmouse_input_mapping(struct hid_device *hdev,
685699

686700
/* Magic Trackpad does not give relative data after switching to MT */
687701
if ((hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD ||
688-
hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) &&
702+
hi->input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
703+
hi->input->id.product ==
704+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) &&
689705
field->flags & HID_MAIN_ITEM_RELATIVE)
690706
return -1;
691707

@@ -721,7 +737,8 @@ static int magicmouse_enable_multitouch(struct hid_device *hdev)
721737
int ret;
722738
int feature_size;
723739

724-
if (hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
740+
if (hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
741+
hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
725742
if (hdev->vendor == BT_VENDOR_ID_APPLE) {
726743
feature_size = sizeof(feature_mt_trackpad2_bt);
727744
feature = feature_mt_trackpad2_bt;
@@ -766,7 +783,8 @@ static int magicmouse_fetch_battery(struct hid_device *hdev)
766783

767784
if (!hdev->battery || hdev->vendor != USB_VENDOR_ID_APPLE ||
768785
(hdev->product != USB_DEVICE_ID_APPLE_MAGICMOUSE2 &&
769-
hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2))
786+
hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 &&
787+
hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC))
770788
return -1;
771789

772790
report_enum = &hdev->report_enum[hdev->battery_report_type];
@@ -835,7 +853,9 @@ static int magicmouse_probe(struct hid_device *hdev,
835853

836854
if (id->vendor == USB_VENDOR_ID_APPLE &&
837855
(id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
838-
(id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && hdev->type != HID_TYPE_USBMOUSE)))
856+
((id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
857+
id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) &&
858+
hdev->type != HID_TYPE_USBMOUSE)))
839859
return 0;
840860

841861
if (!msc->input) {
@@ -850,7 +870,8 @@ static int magicmouse_probe(struct hid_device *hdev,
850870
else if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2)
851871
report = hid_register_report(hdev, HID_INPUT_REPORT,
852872
MOUSE2_REPORT_ID, 0);
853-
else if (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
873+
else if (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
874+
id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) {
854875
if (id->vendor == BT_VENDOR_ID_APPLE)
855876
report = hid_register_report(hdev, HID_INPUT_REPORT,
856877
TRACKPAD2_BT_REPORT_ID, 0);
@@ -920,7 +941,8 @@ static const __u8 *magicmouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
920941
*/
921942
if (hdev->vendor == USB_VENDOR_ID_APPLE &&
922943
(hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 ||
923-
hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) &&
944+
hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 ||
945+
hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) &&
924946
*rsize == 83 && rdesc[46] == 0x84 && rdesc[58] == 0x85) {
925947
hid_info(hdev,
926948
"fixing up magicmouse battery report descriptor\n");
@@ -951,6 +973,10 @@ static const struct hid_device_id magic_mice[] = {
951973
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2), .driver_data = 0 },
952974
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
953975
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2), .driver_data = 0 },
976+
{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE,
977+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC), .driver_data = 0 },
978+
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE,
979+
USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC), .driver_data = 0 },
954980
{ }
955981
};
956982
MODULE_DEVICE_TABLE(hid, magic_mice);

0 commit comments

Comments
 (0)