@@ -73,6 +73,7 @@ MODULE_LICENSE("GPL");
7373#define MT_QUIRK_FORCE_MULTI_INPUT BIT(20)
7474#define MT_QUIRK_DISABLE_WAKEUP BIT(21)
7575#define MT_QUIRK_ORIENTATION_INVERT BIT(22)
76+ #define MT_QUIRK_APPLE_TOUCHBAR BIT(23)
7677
7778#define MT_INPUTMODE_TOUCHSCREEN 0x02
7879#define MT_INPUTMODE_TOUCHPAD 0x03
@@ -220,6 +221,7 @@ static void mt_post_parse(struct mt_device *td, struct mt_application *app);
220221#define MT_CLS_GOOGLE 0x0111
221222#define MT_CLS_RAZER_BLADE_STEALTH 0x0112
222223#define MT_CLS_SMART_TECH 0x0113
224+ #define MT_CLS_APPLE_TOUCHBAR 0x0114
223225#define MT_CLS_SIS 0x0457
224226
225227#define MT_DEFAULT_MAXCONTACT 10
@@ -405,6 +407,12 @@ static const struct mt_class mt_classes[] = {
405407 MT_QUIRK_CONTACT_CNT_ACCURATE |
406408 MT_QUIRK_SEPARATE_APP_REPORT ,
407409 },
410+ { .name = MT_CLS_APPLE_TOUCHBAR ,
411+ .quirks = MT_QUIRK_HOVERING |
412+ MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE |
413+ MT_QUIRK_APPLE_TOUCHBAR ,
414+ .maxcontacts = 11 ,
415+ },
408416 { .name = MT_CLS_SIS ,
409417 .quirks = MT_QUIRK_NOT_SEEN_MEANS_UP |
410418 MT_QUIRK_ALWAYS_VALID |
@@ -625,6 +633,7 @@ static struct mt_application *mt_find_application(struct mt_device *td,
625633static struct mt_report_data * mt_allocate_report_data (struct mt_device * td ,
626634 struct hid_report * report )
627635{
636+ struct mt_class * cls = & td -> mtclass ;
628637 struct mt_report_data * rdata ;
629638 struct hid_field * field ;
630639 int r , n ;
@@ -649,7 +658,11 @@ static struct mt_report_data *mt_allocate_report_data(struct mt_device *td,
649658
650659 if (field -> logical == HID_DG_FINGER || td -> hdev -> group != HID_GROUP_MULTITOUCH_WIN_8 ) {
651660 for (n = 0 ; n < field -> report_count ; n ++ ) {
652- if (field -> usage [n ].hid == HID_DG_CONTACTID ) {
661+ unsigned int hid = field -> usage [n ].hid ;
662+
663+ if (hid == HID_DG_CONTACTID ||
664+ (cls -> quirks & MT_QUIRK_APPLE_TOUCHBAR &&
665+ hid == HID_DG_TRANSDUCER_INDEX )) {
653666 rdata -> is_mt_collection = true;
654667 break ;
655668 }
@@ -821,12 +834,31 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
821834
822835 MT_STORE_FIELD (confidence_state );
823836 return 1 ;
837+ case HID_DG_TOUCH :
838+ /*
839+ * Legacy devices use TIPSWITCH and not TOUCH.
840+ * One special case here is of the Apple Touch Bars.
841+ * In these devices, the tip state is contained in
842+ * fields with the HID_DG_TOUCH usage.
843+ * Let's just ignore this field for other devices.
844+ */
845+ if (!(cls -> quirks & MT_QUIRK_APPLE_TOUCHBAR ))
846+ return -1 ;
847+ fallthrough ;
824848 case HID_DG_TIPSWITCH :
825849 if (field -> application != HID_GD_SYSTEM_MULTIAXIS )
826850 input_set_capability (hi -> input ,
827851 EV_KEY , BTN_TOUCH );
828852 MT_STORE_FIELD (tip_state );
829853 return 1 ;
854+ case HID_DG_TRANSDUCER_INDEX :
855+ /*
856+ * Contact ID in case of Apple Touch Bars is contained
857+ * in fields with HID_DG_TRANSDUCER_INDEX usage.
858+ */
859+ if (!(cls -> quirks & MT_QUIRK_APPLE_TOUCHBAR ))
860+ return 0 ;
861+ fallthrough ;
830862 case HID_DG_CONTACTID :
831863 MT_STORE_FIELD (contactid );
832864 app -> touches_by_report ++ ;
@@ -883,10 +915,6 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
883915 case HID_DG_CONTACTMAX :
884916 /* contact max are global to the report */
885917 return -1 ;
886- case HID_DG_TOUCH :
887- /* Legacy devices use TIPSWITCH and not TOUCH.
888- * Let's just ignore this field. */
889- return -1 ;
890918 }
891919 /* let hid-input decide for the others */
892920 return 0 ;
@@ -1314,13 +1342,27 @@ static int mt_touch_input_configured(struct hid_device *hdev,
13141342 struct input_dev * input = hi -> input ;
13151343 int ret ;
13161344
1345+ /*
1346+ * HID_DG_CONTACTMAX field is not present on Apple Touch Bars,
1347+ * but the maximum contact count is greater than the default.
1348+ */
1349+ if (cls -> quirks & MT_QUIRK_APPLE_TOUCHBAR && cls -> maxcontacts )
1350+ td -> maxcontacts = cls -> maxcontacts ;
1351+
13171352 if (!td -> maxcontacts )
13181353 td -> maxcontacts = MT_DEFAULT_MAXCONTACT ;
13191354
13201355 mt_post_parse (td , app );
13211356 if (td -> serial_maybe )
13221357 mt_post_parse_default_settings (td , app );
13231358
1359+ /*
1360+ * The application for Apple Touch Bars is HID_DG_TOUCHPAD,
1361+ * but these devices are direct.
1362+ */
1363+ if (cls -> quirks & MT_QUIRK_APPLE_TOUCHBAR )
1364+ app -> mt_flags |= INPUT_MT_DIRECT ;
1365+
13241366 if (cls -> is_indirect )
13251367 app -> mt_flags |= INPUT_MT_POINTER ;
13261368
@@ -1823,6 +1865,11 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
18231865 if (ret != 0 )
18241866 return ret ;
18251867
1868+ if (mtclass -> name == MT_CLS_APPLE_TOUCHBAR &&
1869+ !hid_find_field (hdev , HID_INPUT_REPORT ,
1870+ HID_DG_TOUCHPAD , HID_DG_TRANSDUCER_INDEX ))
1871+ return - ENODEV ;
1872+
18261873 if (mtclass -> quirks & MT_QUIRK_FIX_CONST_CONTACT_ID )
18271874 mt_fix_const_fields (hdev , HID_DG_CONTACTID );
18281875
@@ -2320,6 +2367,11 @@ static const struct hid_device_id mt_devices[] = {
23202367 MT_USB_DEVICE (USB_VENDOR_ID_XIROKU ,
23212368 USB_DEVICE_ID_XIROKU_CSR2 ) },
23222369
2370+ /* Apple Touch Bar */
2371+ { .driver_data = MT_CLS_APPLE_TOUCHBAR ,
2372+ HID_USB_DEVICE (USB_VENDOR_ID_APPLE ,
2373+ USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY ) },
2374+
23232375 /* Google MT devices */
23242376 { .driver_data = MT_CLS_GOOGLE ,
23252377 HID_DEVICE (HID_BUS_ANY , HID_GROUP_ANY , USB_VENDOR_ID_GOOGLE ,
0 commit comments