From 751b6d509fb2f3458f3bc3b25c74cba9e1652154 Mon Sep 17 00:00:00 2001 From: Kyle Arrington Date: Mon, 16 Nov 2026 21:41:48 -0600 Subject: [PATCH 1/7] HID: magicmouse: report the J813 trackpad's palms The J813 (MacBook Air 13" M5) trackpad sends the standard MTP report and classes its contacts like the T6041 and J616s ones: low byte of a record's second word, 2 and 3 for fingers, 6 and above for palms. Most J813 palms stay below the classed tool area of 1400 that the T6041 rule needs: recorded in normal use and while typing, 221 of 370 palm-classed contacts never passed it, and fingers reached 1560, so lowering it would not separate them. The class flickers to a palm for single reports on fingers (4 of 868), so on the J813 a contact also counts as a palm once two consecutive reports class it as one. That caught all 370 palms by their second report, and one finger, classed a palm for its last reports while lifting. As on the J616s, the J813 trackpad now also advertises ABS_MT_TOOL_TYPE and the full 16-bit range of its touch and width areas. Other machines are unchanged. Signed-off-by: Kyle Arrington --- drivers/hid/hid-magicmouse.c | 40 ++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 4d8ffa36d7700..16f7f1a4643a3 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -273,9 +273,13 @@ struct effect_job { * @tp26_button: Button state of the last Trackpad26 frame. * @mtp_c1fe: Whether the MTP trackpad sends the J700 C1FE report layout. * @mtp_palms: Whether the controller's contact classes are trusted for palms - * on the standard MTP report (T6041, J616s). + * on the standard MTP report (T6041, J616s, J813). * @mtp_palm_size: Whether a tool area alone marks an MTP contact as a palm. * @mtp_palm_ids: MTP contact IDs reported as palms until they lift. + * @mtp_palm_debounce: Whether two consecutive palm classes mark an MTP contact + * as a palm whatever its tool area (J813). + * @mtp_palm_classed: MTP contact IDs the controller classed as palms in the + * previous report. * @ntouches: Number of touches in most recent touch report. * @scroll_accel: Number of consecutive scroll motions. * @scroll_jiffies: Time of last scroll motion. @@ -310,6 +314,8 @@ struct magicmouse_sc { bool mtp_palms; bool mtp_palm_size; DECLARE_BITMAP(mtp_palm_ids, U8_MAX + 1); + bool mtp_palm_debounce; + DECLARE_BITMAP(mtp_palm_classed, U8_MAX + 1); int ntouches; int scroll_accel; @@ -1008,27 +1014,46 @@ static u8 magicmouse_mtp_contact_id(const struct tp_finger *f) return le16_to_cpu(f->unknown1) & 0xff; } +/* + * The J813 (MacBook Air 13" M5) controller classes contacts the same way, but + * most of its palms stay below the classed tool area above: recorded on a J813 + * in normal use and while typing, 221 of 370 palm-classed contacts never passed + * 1400, and fingers reached 1560. Its class flickers to a palm for single + * reports on a finger (4 of 868 finger contacts), so there a contact also + * counts as a palm once two consecutive reports class it as one. That caught + * all 370 palms by their second report, and one finger, classed a palm for its + * last reports while lifting. + */ static void magicmouse_mtp_update_palms(struct magicmouse_sc *msc, const u8 *records, int count) { DECLARE_BITMAP(palms, U8_MAX + 1); + DECLARE_BITMAP(classed, U8_MAX + 1); const struct tp_finger *f; + bool palm_class; int i, tool; u8 id, class; bitmap_zero(palms, U8_MAX + 1); + bitmap_zero(classed, U8_MAX + 1); for (i = 0; i < count; i++) { f = (const struct tp_finger *)(records + i * sizeof(*f)); id = magicmouse_mtp_contact_id(f); class = le16_to_cpu(f->unknown2) & 0xff; tool = le16_to_int(f->tool_major); + palm_class = class >= MAGICMOUSE_MTP_PALM_CLASS_MIN; + if (palm_class) + __set_bit(id, classed); if ((msc->mtp_palm_size && tool > MAGICMOUSE_MTP_PALM_TOOL_MAJOR) || - (class >= MAGICMOUSE_MTP_PALM_CLASS_MIN && + (palm_class && tool > MAGICMOUSE_MTP_CLASSED_PALM_TOOL_MAJOR) || + (msc->mtp_palm_debounce && palm_class && + test_bit(id, msc->mtp_palm_classed)) || test_bit(id, msc->mtp_palm_ids)) __set_bit(id, palms); } bitmap_copy(msc->mtp_palm_ids, palms, U8_MAX + 1); + bitmap_copy(msc->mtp_palm_classed, classed, U8_MAX + 1); } static void report_finger_data(struct input_dev *input, int slot, @@ -1735,7 +1760,7 @@ static int magicmouse_setup_input_mtp(struct input_dev *input, /* * A palm's tool area on the T6041 and J616s trackpads exceeds * 5000 once scaled, so allow the full range of the record's - * 16-bit fields there. + * 16-bit fields on every trackpad whose palms are classed. */ int area_max = msc->mtp_palms ? 2 * S16_MAX : 5000; @@ -1762,7 +1787,7 @@ static int magicmouse_setup_input_mtp(struct input_dev *input, J314_TP_MAX_FINGER_ORIENTATION, 0, 0); } - /* The T6041, J616s and Trackpad26 controllers classify palms. */ + /* The T6041, J616s, J813 and Trackpad26 controllers classify palms. */ if (msc->mtp_palms || msc->mtp_tp26) input_set_abs_params(input, ABS_MT_TOOL_TYPE, 0, MT_TOOL_MAX, 0, 0); @@ -2877,12 +2902,19 @@ static int magicmouse_probe(struct hid_device *hdev, msc->mtp_c1fe = of_device_is_compatible(np, "apple,j700-multitouch"); msc->mtp_palm_size = !msc->mtp_c1fe && of_machine_is_compatible("apple,t6041"); + /* + * The J813 controller classes contacts the same way, and two + * consecutive palm classes mark its palms. + */ + msc->mtp_palm_debounce = !msc->mtp_c1fe && + of_machine_is_compatible("apple,j813"); /* * The J616s controller classes contacts the same way, but its * fingers reach a tool area of 2475, so only the class marks its * palms there. */ msc->mtp_palms = msc->mtp_palm_size || + msc->mtp_palm_debounce || (!msc->mtp_c1fe && of_machine_is_compatible("apple,j616s")); of_node_put(np); From 6bfbc9981bb54e5a7ccd8e331de0ffd8e6254308 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 17 Nov 2026 15:06:47 +0700 Subject: [PATCH 2/7] HID: magicmouse: report the J815 trackpad's palms too The J815 (MacBook Air 15" M5) has the J813's T8142 and MTP transport, and its trackpad sends the standard MTP report the previous commit reads on the J813, with the same contact classes. Take the J813's rule there as well: the controller's palm classes are trusted, and two consecutive palm classes mark a palm whatever its tool area. The pads differ: the J813 ADT's multi-touch hid-merge-personality is C1FD1,4, the J815's C1FD3,3 (a larger pad, firmware tpmtfw-j815.bin), so the rule was checked on a J815 recording (one contact line per lift): 30 s typing with both palms resting on the pad: 77 contacts the controller classed as palms, all 77 marked (36 by their second report); 15 short contacts with fewer palm classes, 11 of them marked, all with large tool areas (up to 5245) at the palms' edges. 30 s pointing, tapping and two-finger scrolling: 54 finger contacts, none marked and none with a palm class; the largest finger tool area was 1028, below the 1400 the area rule needs. (6 more contacts lifted in the first second: palms still resting from the typing phase, all classed as palms.) Signed-off-by: Nick Signed-off-by: Kyle Arrington --- drivers/hid/hid-magicmouse.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 16f7f1a4643a3..712c3ae5d78ac 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -277,7 +277,7 @@ struct effect_job { * @mtp_palm_size: Whether a tool area alone marks an MTP contact as a palm. * @mtp_palm_ids: MTP contact IDs reported as palms until they lift. * @mtp_palm_debounce: Whether two consecutive palm classes mark an MTP contact - * as a palm whatever its tool area (J813). + * as a palm whatever its tool area (J813, J815). * @mtp_palm_classed: MTP contact IDs the controller classed as palms in the * previous report. * @ntouches: Number of touches in most recent touch report. @@ -2904,10 +2904,12 @@ static int magicmouse_probe(struct hid_device *hdev, of_machine_is_compatible("apple,t6041"); /* * The J813 controller classes contacts the same way, and two - * consecutive palm classes mark its palms. + * consecutive palm classes mark its palms. The J815 (15-inch) + * sends the same standard report from its own, larger pad. */ msc->mtp_palm_debounce = !msc->mtp_c1fe && - of_machine_is_compatible("apple,j813"); + (of_machine_is_compatible("apple,j813") || + of_machine_is_compatible("apple,j815")); /* * The J616s controller classes contacts the same way, but its * fingers reach a tool area of 2475, so only the class marks its From e143d679cf6ca6e15db186767444a2cdabdcf690 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 08:05:03 +0700 Subject: [PATCH 3/7] dt-bindings: input: apple,dockchannel-hid: Describe trackpad touch states and palm rules The J813 and J815 (MacBook Air M5) trackpads send the standard MTP report, with a touch state and a firmware path ID in each contact record, and they need their own palm rules. Describe both on the multi-touch node, so the driver selects them by the trackpad and not by the machine, and another board with the same controller only needs its device tree: - apple,touch-states: the record's first word holds the touch state and the path ID; only touching contacts are reported, each in its path ID's slot. - apple,palm-debounce: two consecutive palm classes mark a palm (J813). - apple,palm-tool-area: the J815 rule, with the pad's two tool-area thresholds as values: a hand class past the first on two consecutive reports, or any contact on the surface past the second, is a palm, and its force doesn't count towards the host-derived click. The J700 report layout (compatible apple,j700-multitouch) has none of these fields, so the properties are not allowed with it. Signed-off-by: Nick --- .../bindings/input/apple,dockchannel-hid.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml b/Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml index bf82f4dc8b3ee..4f8da13249512 100644 --- a/Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml +++ b/Documentation/devicetree/bindings/input/apple,dockchannel-hid.yaml @@ -168,7 +168,59 @@ properties: power method 2 notifications without controlling an AFE GPIO. Mutually exclusive with apple,afe-reset-gpios on the parent. + apple,touch-states: + type: boolean + description: + The first word of each contact record of the trackpad's standard + report (38-byte header) holds the contact's touch state in its + high byte (start in range, hover, make touch, touching, break + touch, linger, out of range) and in its low byte the path ID under + which the firmware tracks the contact until it leaves the pad. + Only contacts that make or keep touch are then reported, each in + the slot of its path ID. + + apple,palm-debounce: + type: boolean + description: + The controller's palm classes (6 and above) flicker onto fingers + for single reports, so a contact counts as a palm once two + consecutive reports class it as one, whatever its tool area. + + apple,palm-tool-area: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: + Palm rule of a trackpad whose hand classes are 6, 7, 8 and 12, in + units of the record's contact ellipse major axis (10 um). A + contact in a hand class whose axis passes the first value on two + consecutive reports is a palm, and so is a contact on the surface + whose axis passes the second value, whatever its class. The force + of a palm, or of a contact past either value in a hand class, does + not count towards the click the host derives from the contacts' + force. The first value is below the second, and neither is above + 32767, the largest axis the record's signed 16-bit field holds. + items: + - description: Axis that marks a hand-class contact on two + consecutive reports. + maximum: 32767 + - description: Axis wider than any finger, marking a contact on + the surface at once. + maximum: 32767 + allOf: + - if: + required: + - apple,palm-tool-area + then: + properties: + apple,palm-debounce: false + - if: + required: + - compatible + then: + properties: + apple,touch-states: false + apple,palm-debounce: false + apple,palm-tool-area: false - if: required: - apple,firmware-managed-reset From 3fa72f8a794501db069c540bbdc600279b2485d6 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 08:05:14 +0700 Subject: [PATCH 4/7] arm64: dts: apple: t8142-j813, t8142-j815: Describe the trackpads' palm rules Give the multi-touch nodes the properties the driver will select the trackpad behaviour by, instead of the machine compatible: - J813: apple,palm-debounce, the rule its palms are reported with now, and apple,touch-states: gig3m's J813 recordings (MTP firmware 6310.85.7, 1,659 contacts) show the same state lifecycles and path IDs as the J815, with no path ID twice in a frame. Between a contact going out of range and the next start under its path ID come records in state 0 with zero sizes, which the on-surface test already drops. - J815: apple,touch-states (decoded on this pad against macOS's own parse of the same frames) and apple,palm-tool-area = <1200 2200>, the thresholds checked against macOS's labels for 607 contacts. Signed-off-by: Nick --- arch/arm64/boot/dts/apple/t8142-j813.dts | 4 ++++ arch/arm64/boot/dts/apple/t8142-j815.dts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index aaa635fa853fb..063e036db4f18 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -236,6 +236,10 @@ &mtp_hid { multi-touch { firmware-name = "apple/tpmtfw-j813.bin"; + /* Palm classes flicker onto fingers for single reports. */ + apple,palm-debounce; + /* The same touch states and path IDs as the J815's pad. */ + apple,touch-states; }; }; diff --git a/arch/arm64/boot/dts/apple/t8142-j815.dts b/arch/arm64/boot/dts/apple/t8142-j815.dts index 05d2e666cdb7b..3276d2082c0ef 100644 --- a/arch/arm64/boot/dts/apple/t8142-j815.dts +++ b/arch/arm64/boot/dts/apple/t8142-j815.dts @@ -136,6 +136,13 @@ multi-touch { /* ADT hid-merge-personality C1FD3,3 (J813: C1FD1,4). */ firmware-name = "apple/tpmtfw-j815.bin"; + /* Touch states and path IDs decoded on this pad against macOS. */ + apple,touch-states; + /* + * Hand classes past 12 mm on two reports, any contact past 22 mm + * at once (no finger on macOS passed 21 mm). + */ + apple,palm-tool-area = <1200 2200>; }; }; From c99a772f9bf5276af065e1fce7c7d104de13eacf Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 01:20:29 +0700 Subject: [PATCH 5/7] HID: magicmouse: report only touching MTP contacts, in path-ID slots The high byte of a standard MTP record's first word is the contact's touch state and the low byte its firmware path ID. Decoded on a J815 (MacBook Air 15" M5, MTP firmware 6300.85.6) against macOS's own parse of the same frames: MultitouchSupport's full-frame callback, matched record by record on path ID, state, finger class and hand ID over 10 minutes of use. The states are 1 start in range, 2 hover in range, 3 make touch, 4 touching, 5 break touch, 6 linger in range, 7 out of range. A finger approaching or leaving the pad (states 1, 2, 5, 6) still has a position and nonzero sizes, so the touch-size test reports it as a touch: 374 such reports in the 10 minutes, each a hovering or lifting finger seen as a touch. Report only make touch and touching there; any other state is off the surface, including the zero-size state-0 records a pad sends between a contact going out of range and the next start under its path ID. The firmware keeps a contact under its path ID until it leaves the pad, so report each contact in that ID's slot instead of matching by distance, which hands a slot over when one finger lifts as another lands nearby in the same frame (two or more contacts landed in one frame about 100 times in the 10 minutes). The slot is looked up inside the report loop, so contacts landing in the same frame get different free slots; the MTP slots are set up with INPUT_MT_DROP_UNUSED, which releases the slot of a path ID that is gone. The firmware also reuses a path ID for a new contact in the report right after the old one goes out of range (40 times in the 10 minutes), so an out-of-range record no longer keeps the palm mark of its ID. The trackpad node's apple,touch-states selects this, so it follows the trackpad's firmware rather than the machine: the J815 has it, and the J813 (the same firmware family on the same SoC, not checked yet) or a later board only needs the property. Signed-off-by: Nick --- drivers/hid/hid-magicmouse.c | 75 +++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 712c3ae5d78ac..dcb627e7bc4e8 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -280,6 +280,9 @@ struct effect_job { * as a palm whatever its tool area (J813, J815). * @mtp_palm_classed: MTP contact IDs the controller classed as palms in the * previous report. + * @mtp_states: Whether the standard MTP records' touch states are trusted: + * only contacts on the surface are reported, each in the slot + * of its firmware path ID (apple,touch-states). * @ntouches: Number of touches in most recent touch report. * @scroll_accel: Number of consecutive scroll motions. * @scroll_jiffies: Time of last scroll motion. @@ -316,6 +319,7 @@ struct magicmouse_sc { DECLARE_BITMAP(mtp_palm_ids, U8_MAX + 1); bool mtp_palm_debounce; DECLARE_BITMAP(mtp_palm_classed, U8_MAX + 1); + bool mtp_states; int ntouches; int scroll_accel; @@ -1014,6 +1018,43 @@ static u8 magicmouse_mtp_contact_id(const struct tp_finger *f) return le16_to_cpu(f->unknown1) & 0xff; } +/* + * The high byte of a standard MTP record's first word is the contact's + * touch state. Decoded on a J815 (MTP firmware 6300.85.6) against macOS's + * own parse of the same frames (MultitouchSupport's contact frames, matched + * by path ID, state, finger and hand ID on every record): 1 start in range, + * 2 hover in range, 3 make touch, 4 touching, 5 break touch, 6 linger in + * range, 7 out of range. A finger approaching or leaving the pad (1, 2, 5, + * 6) still has a position and nonzero sizes, so the touch-size test alone + * reports it as a touch; only make touch and touching are on the surface. + * Any other state, including the zero-size records in state 0 that the J813 + * sends between a contact's out of range and the next start under its path + * ID, is off the surface. + */ +#define MAGICMOUSE_MTP_STATE_MAKE_TOUCH 3 +#define MAGICMOUSE_MTP_STATE_TOUCHING 4 +#define MAGICMOUSE_MTP_STATE_OUT_OF_RANGE 7 + +static u8 magicmouse_mtp_state(const struct tp_finger *f) +{ + return le16_to_cpu(f->unknown1) >> 8; +} + +static bool magicmouse_mtp_on_surface(const struct magicmouse_sc *msc, + const struct tp_finger *f) +{ + if (msc->mtp_states) { + switch (magicmouse_mtp_state(f)) { + case MAGICMOUSE_MTP_STATE_MAKE_TOUCH: + case MAGICMOUSE_MTP_STATE_TOUCHING: + break; + default: + return false; + } + } + return le16_to_int(f->touch_major) != 0; +} + /* * The J813 (MacBook Air 13" M5) controller classes contacts the same way, but * most of its palms stay below the classed tool area above: recorded on a J813 @@ -1041,6 +1082,14 @@ static void magicmouse_mtp_update_palms(struct magicmouse_sc *msc, id = magicmouse_mtp_contact_id(f); class = le16_to_cpu(f->unknown2) & 0xff; tool = le16_to_int(f->tool_major); + /* + * Out of range ends the contact; the firmware may reuse its + * path ID for a new contact in the very next report (40 times + * in 10 minutes on a J815), which must not inherit the palm. + */ + if (msc->mtp_states && + magicmouse_mtp_state(f) == MAGICMOUSE_MTP_STATE_OUT_OF_RANGE) + continue; palm_class = class >= MAGICMOUSE_MTP_PALM_CLASS_MIN; if (palm_class) __set_bit(id, classed); @@ -1344,7 +1393,7 @@ static int magicmouse_raw_event_mtp(struct hid_device *hdev, n = 0; for (i = 0; i < tp_hdr->num_fingers; i++) { f = (struct tp_finger *)(data + hdr_sz + i * touch_sz); - if (!msc->mtp_c1fe && le16_to_int(f->touch_major) == 0) + if (!msc->mtp_c1fe && !magicmouse_mtp_on_surface(msc, f)) continue; hid_dbg(hdev, "ev x:%04x y:%04x\n", le16_to_int(f->abs_x), @@ -1355,11 +1404,27 @@ static int magicmouse_raw_event_mtp(struct hid_device *hdev, n++; } - input_mt_assign_slots(input, msc->tracking_ids, msc->pos, n, 0); + if (!msc->mtp_states) + input_mt_assign_slots(input, msc->tracking_ids, msc->pos, n, 0); for (i = 0; i < n; i++) { int idx = map_contacs[i]; + f = (struct tp_finger *)(data + hdr_sz + idx * touch_sz); + if (msc->mtp_states) { + /* + * The firmware tracks each contact under a path ID + * until it leaves the pad, so keep it in that ID's + * slot: matching by distance hands a slot over when one + * finger lifts as another lands in the same frame. Look + * the slot up just before reporting it, so contacts + * landing in the same frame get different free slots. + */ + msc->tracking_ids[i] = + input_mt_get_slot_by_key(input, magicmouse_mtp_contact_id(f)); + if (msc->tracking_ids[i] < 0) + continue; + } if (msc->mtp_c1fe) { report_c1fe_finger_data(input, msc->tracking_ids[i], &msc->pos[i]); } else { @@ -2919,6 +2984,12 @@ static int magicmouse_probe(struct hid_device *hdev, msc->mtp_palm_debounce || (!msc->mtp_c1fe && of_machine_is_compatible("apple,j616s")); + /* + * The record's touch state and path ID (decoded on a J815 + * against macOS) are a property of the trackpad's firmware. + */ + msc->mtp_states = !msc->mtp_c1fe && + of_property_read_bool(np, "apple,touch-states"); of_node_put(np); /* From a89f8bc557ef6f4deac9a8f8c21be06e58739694 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 01:20:55 +0700 Subject: [PATCH 6/7] HID: magicmouse: give the J815 trackpad its own palm rule, from its DT node The previous J815 commit took the J813's rule: two consecutive palm classes (6 and above) mark a palm whatever its tool area. Checked against macOS's own labels for the same contacts (MultitouchSupport's full-frame callback, 10 minutes of typing with resting palms, pointing, scrolling and gestures, 607 contacts, 34 of them hands), that rule marked two finger contacts as palms until they lifted, 966 finger reports lost: a finger-sized contact in the bottom-left corner whose class flickered between 10 and 12; a finger whose class flipped between 3 and 7 for up to 17 reports, with a tool area up to 1606. Class 10 is not a hand on the J815; its hand classes are 6, 7, 8 and 12. Mark a contact as a palm when a hand class comes with a tool area above 1200 on two consecutive reports: no finger contact and 33 of the 34 hands on the macOS session. 1400 missed 4 of 25 palms resting while typing on Linux (they peaked at 1325-1400); 1100 would mark one finger of the macOS session. Some resting palms are never classed as hands: in one Linux typing run two of them, 28 and 38 mm wide, stayed fingers for 0.6 s and one of them made a click. No finger or thumb contact on the surface passed a tool area of 2097 on macOS, while 21 of the 34 hands passed 2200, so a contact on the surface wider than that is a palm at once, whatever its class. Only on the surface: a thumb's start-in-range record had a tool area of 2428, and the mark would have stayed for its 35 touching reports. With both tests, the macOS session gives 33 of 34 hands, no finger, and 8 hand reports before the mark (18 with the class test alone). The 2200 margin comes from one 10-minute macOS session and Linux runs on the same machine; on Linux, fingers reached 1879 (99th percentile). Both rules are selected by the trackpad node instead of the machine compatible: apple,palm-debounce for the J813 rule, and apple,palm-tool-area for this one, whose two values are the pad's own thresholds (1200 and 2200 on the J815), so another board with the same controller gets either rule from its device tree. A swapped apple,palm-tool-area (first value not below the second), or a value above 32767, is warned about at probe and leaves the rule off. The record's tool area is a signed 16-bit field, and the thresholds are kept as int so that a raw field with bit 15 set compares as negative, not as a huge unsigned value that would mark a palm. Signed-off-by: Nick --- drivers/hid/hid-magicmouse.c | 84 ++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index dcb627e7bc4e8..c94c7e8cabf0d 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -273,13 +273,18 @@ struct effect_job { * @tp26_button: Button state of the last Trackpad26 frame. * @mtp_c1fe: Whether the MTP trackpad sends the J700 C1FE report layout. * @mtp_palms: Whether the controller's contact classes are trusted for palms - * on the standard MTP report (T6041, J616s, J813). + * on the standard MTP report (T6041, J616s, J813, J815). * @mtp_palm_size: Whether a tool area alone marks an MTP contact as a palm. * @mtp_palm_ids: MTP contact IDs reported as palms until they lift. * @mtp_palm_debounce: Whether two consecutive palm classes mark an MTP contact - * as a palm whatever its tool area (J813, J815). + * as a palm whatever its tool area (apple,palm-debounce). * @mtp_palm_classed: MTP contact IDs the controller classed as palms in the * previous report. + * @mtp_palm_large: Whether only hand classes with a palm-sized tool area, on + * two consecutive reports, or a tool area wider than any + * finger mark an MTP contact as a palm (apple,palm-tool-area). + * @mtp_palm_area: The two tool areas of apple,palm-tool-area: hand-class palm + * size, and the size wider than any finger. * @mtp_states: Whether the standard MTP records' touch states are trusted: * only contacts on the surface are reported, each in the slot * of its firmware path ID (apple,touch-states). @@ -319,6 +324,8 @@ struct magicmouse_sc { DECLARE_BITMAP(mtp_palm_ids, U8_MAX + 1); bool mtp_palm_debounce; DECLARE_BITMAP(mtp_palm_classed, U8_MAX + 1); + bool mtp_palm_large; + int mtp_palm_area[2]; bool mtp_states; int ntouches; @@ -1064,7 +1071,37 @@ static bool magicmouse_mtp_on_surface(const struct magicmouse_sc *msc, * counts as a palm once two consecutive reports class it as one. That caught * all 370 palms by their second report, and one finger, classed a palm for its * last reports while lifting. + * + * On the J815 (MacBook Air 15" M5) the controller's classes were checked + * against macOS's own labels on 607 contacts (10 minutes of typing with + * resting palms, pointing, scrolling, gestures; 34 contacts mostly classed + * 6, 7, 8 or 12, the hand classes). Two contacts that were mostly classed as + * fingers were marked as palms until they lifted by the J813 rule (966 + * finger reports lost): a finger-sized one in the bottom-left corner, + * flickering between classes 10 and 12, and one whose class flipped between + * 3 and 7 for up to 17 reports with a tool area up to 1606. Requiring a hand + * class with a tool area above 1200 on two consecutive reports marked no + * finger-classed contact and 33 of the 34 hand contacts. With 1400, palms + * resting while typing on Linux peaked at 1325-1400 and were missed (4 of 25); + * at 1100, one finger in the macOS session would be marked. + * + * Some resting palms are never classed as hands (two in one typing run on + * Linux, 28 and 38 mm wide, reported as fingers for 0.6 s). On macOS no + * finger or thumb contact passed a tool area of 2097, while 21 of the 34 + * hands passed 2200, 11 of them in their first report, so a contact wider + * than that on the surface is a palm at once, whatever its class. A finger + * coming into range can be wider: a thumb's start-in-range record had a tool + * area of 2428, and the mark would have stayed for its 35 touching reports. + * + * The two areas are the pad's own (apple,palm-tool-area = <1200 2200> on the + * J815); the hand classes are the controller's. */ + +static bool magicmouse_mtp_hand_class(u8 class) +{ + return (class >= 6 && class <= 8) || class == 12; +} + static void magicmouse_mtp_update_palms(struct magicmouse_sc *msc, const u8 *records, int count) { @@ -1090,6 +1127,18 @@ static void magicmouse_mtp_update_palms(struct magicmouse_sc *msc, if (msc->mtp_states && magicmouse_mtp_state(f) == MAGICMOUSE_MTP_STATE_OUT_OF_RANGE) continue; + if (msc->mtp_palm_large) { + palm_class = magicmouse_mtp_hand_class(class) && + tool > msc->mtp_palm_area[0]; + if (palm_class) + __set_bit(id, classed); + if ((palm_class && test_bit(id, msc->mtp_palm_classed)) || + (tool > msc->mtp_palm_area[1] && + magicmouse_mtp_on_surface(msc, f)) || + test_bit(id, msc->mtp_palm_ids)) + __set_bit(id, palms); + continue; + } palm_class = class >= MAGICMOUSE_MTP_PALM_CLASS_MIN; if (palm_class) __set_bit(id, classed); @@ -1852,7 +1901,7 @@ static int magicmouse_setup_input_mtp(struct input_dev *input, J314_TP_MAX_FINGER_ORIENTATION, 0, 0); } - /* The T6041, J616s, J813 and Trackpad26 controllers classify palms. */ + /* The T6041, J616s, J813, J815 and Trackpad26 controllers classify palms. */ if (msc->mtp_palms || msc->mtp_tp26) input_set_abs_params(input, ABS_MT_TOOL_TYPE, 0, MT_TOOL_MAX, 0, 0); @@ -2961,6 +3010,7 @@ static int magicmouse_probe(struct hid_device *hdev, // conflicts with the report ID. if (id->bus == BUS_HOST) { struct device_node *np; + u32 palm_area[2]; /* The J700 trackpad sends a different report layout. */ np = of_get_child_by_name(dev_of_node(hdev->dev.parent), "multi-touch"); @@ -2968,20 +3018,36 @@ static int magicmouse_probe(struct hid_device *hdev, msc->mtp_palm_size = !msc->mtp_c1fe && of_machine_is_compatible("apple,t6041"); /* - * The J813 controller classes contacts the same way, and two - * consecutive palm classes mark its palms. The J815 (15-inch) - * sends the same standard report from its own, larger pad. + * The J813 and J815 controllers class contacts the same way; + * the trackpad node says which palm rule its pad takes: two + * consecutive palm classes (J813), or hand classes with the + * pad's own tool areas (J815, checked against macOS's labels). */ msc->mtp_palm_debounce = !msc->mtp_c1fe && - (of_machine_is_compatible("apple,j813") || - of_machine_is_compatible("apple,j815")); + of_property_read_bool(np, "apple,palm-debounce"); + msc->mtp_palm_large = !msc->mtp_c1fe && + !of_property_read_u32_array(np, "apple,palm-tool-area", + palm_area, 2); + /* + * The record's tool area is a signed 16-bit field, compared + * as an int: a larger value could never be passed. + */ + if (msc->mtp_palm_large && + (palm_area[0] >= palm_area[1] || palm_area[1] > S16_MAX)) { + hid_warn(hdev, "apple,palm-tool-area %u %u: the first must be below the second, and both at most %d, rule off\n", + palm_area[0], palm_area[1], S16_MAX); + msc->mtp_palm_large = false; + } else if (msc->mtp_palm_large) { + msc->mtp_palm_area[0] = palm_area[0]; + msc->mtp_palm_area[1] = palm_area[1]; + } /* * The J616s controller classes contacts the same way, but its * fingers reach a tool area of 2475, so only the class marks its * palms there. */ msc->mtp_palms = msc->mtp_palm_size || - msc->mtp_palm_debounce || + msc->mtp_palm_debounce || msc->mtp_palm_large || (!msc->mtp_c1fe && of_machine_is_compatible("apple,j616s")); /* From f5b7717b40644d2d5e6e6f2878b19846739c6529 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 21 Nov 2026 03:00:23 +0700 Subject: [PATCH 7/7] HID: magicmouse: leave a resting hand's force out of the J815 click The J815's MTP click is derived on the host from the summed contact force. A palm resting while typing presses hard enough to reach the press threshold on its own: in one Linux typing run all 4 clicks came from palms (3 with only palm-marked contacts on the pad, summed force 121-139 against the press threshold of 120; 1 from a 27 mm contact in its first report, before the palm mark). On macOS a resting hand neither clicks nor moves the pointer, while a finger of the other hand still clicks and Force Clicks. Leave out the force of every hand contact, with the same tests as the palm rule and the pad's apple,palm-tool-area values: one marked as a palm, one in a hand class past the first value (1200 on the J815) already in its first report (the palm mark waits for a second one), and one on the surface wider than any finger (past the second value, 2200). On the J815, two A/B runs of pointing, typing, and pointing and clicking with the other hand while a palm rests (each click attributed from the evdev trace: a hand is a palm-marked contact or one above 2200): with this change, 59 of 59 clicks reached the press threshold on the fingers' force alone. With the previous commits' palm marking but without this change, 49 of 58 clicks did not: 10 with no finger on the pad, 39 with fingers whose own force stayed below the threshold. The two builds also differ in the 2200 test, and no palm-made click was felt with this one. Signed-off-by: Nick --- drivers/hid/hid-magicmouse.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index c94c7e8cabf0d..d1db40c539222 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -1102,6 +1102,24 @@ static bool magicmouse_mtp_hand_class(u8 class) return (class >= 6 && class <= 8) || class == 12; } +/* + * A hand on a pad with apple,palm-tool-area, for the host-derived click: a + * contact marked as a palm, or one in a hand class past the palm tool area + * already in its first report (the palm mark waits for a second one), or one + * on the surface wider than any finger. + */ +static bool magicmouse_mtp_hand(const struct magicmouse_sc *msc, + const struct tp_finger *f) +{ + int tool = le16_to_int(f->tool_major); + + /* The same tests as magicmouse_mtp_update_palms(), without the wait. */ + return test_bit(magicmouse_mtp_contact_id(f), msc->mtp_palm_ids) || + (tool > msc->mtp_palm_area[1] && magicmouse_mtp_on_surface(msc, f)) || + (magicmouse_mtp_hand_class(le16_to_cpu(f->unknown2) & 0xff) && + tool > msc->mtp_palm_area[0]); +} + static void magicmouse_mtp_update_palms(struct magicmouse_sc *msc, const u8 *records, int count) { @@ -1484,7 +1502,15 @@ static int magicmouse_raw_event_mtp(struct hid_device *hdev, tool = MT_TOOL_PALM; report_finger_data(input, msc->tracking_ids[i], &msc->pos[i], f, tool); - pressure += le16_to_int(f->pressure); + /* + * J815: a resting palm presses hard enough to reach the + * click threshold on its own. As on macOS, a resting + * hand neither clicks nor deepens a click, while a + * finger of the other hand still does: the hand's own + * force never counts. + */ + if (!(msc->mtp_palm_large && magicmouse_mtp_hand(msc, f))) + pressure += le16_to_int(f->pressure); } }