Repository navigation
HID: magicmouse: J813/J815 trackpad touch states, palm rules and palm-free click - #2613
m0d16l14n1 wants to merge 7 commits into
Conversation
|
The path-ID slots look right to me: each contact's slot is looked up just before it is reported, so
Assisted-by: LLM (Claude:Opus 5.5) |
|
In magicmouse_probe(), mtp_palm_debounce, mtp_palm_large and mtp_states are set from of_machine_is_compatible("apple,j813") / ("apple,j815"), so the palm rules and touch-state decoding follow the board name rather than the trackpad. The multitouch node np is already in hand here; key these on its compatible (e.g. a per-controller compatible) or on a DT property of that node, the same way mtp_c1fe is selected. That way another board with the same controller gets the behaviour without a code change. Until then this should stay a draft. |
a36e1f4 to
17f519c
Compare
|
@RyanTheTide thanks. All three code points are in the new head Selected by the trackpad node.
The series is now:
Another board with the same controller only needs its DT. The binding rejects
Force Click with the other hand resting: not run yet. I'll do it on the J815 together with the surface-only 2200 change and this DT-selected build, and post the row before taking it out of draft. The T6041 and J616s selections in the same block still use the machine compatible. I left them out of this series; they could move to the node in a follow-up if you want. Checks:
Assisted-by: Claude Opus 5.5 |
|
Checked 17f519c. The three rules now come from the Assisted-by: LLM (Claude:Opus 5.5) |
|
J813 (MacBook Air 13" M5, macOS 27.2 stub, MTP firmware Raw records (HID debugfs: a recording from 11-16 of normal use and typing, 85,862 frames and 1,300 contacts, plus today's 25,093 frames and 359 contacts):
Without the states, the size test in today's driver, on the 11-16 recording:
With this series' driver commits (
So 🤖 Generated with Claude Code |
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 <kyle@arrington.co>
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 <nekreshen@yandex.ru> Signed-off-by: Kyle Arrington <kyle@arrington.co>
17f519c to
f2c267c
Compare
|
@RyanTheTide added both:
@gig3m thanks for the J813 run. Rebased onto cc14570; #2116's two commits are carried, since it's closed. Assisted-by: LLM (Claude:Opus 5.5) |
|
Re-review of f2c267c: No blockers. From the last comments:
Since then the series also puts
HW row: J815 on this head and its DTB, default command line. (a) A Force Click with one palm resting and the other hand clicking. (b) A thumb landing that starts above the second threshold, still reported as a finger. Plus one J813 run with a palm resting while typing. Pass: no palm click, Force Click registers, palms marked with no finger lost, and the regression line shows 0 failed units, 0 AVC denials and 0 new kernel errors. Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Pre-PR checklist review at f2c267cba17c (CI: dt-checks and host-tests passing).
The DT-driven architecture is clean (§1): board gating is replaced by per-pad multi-touch properties (apple,touch-states, apple,palm-debounce, apple,palm-tool-area) with binding mutual-exclusion rules, path-ID slot assignment (input_mt_get_slot_by_key() inside the report loop with INPUT_MT_DROP_UNUSED) and out-of-range palm clearing are sound, and §4 attribution is clean (#2116 commits carried unchanged, human Signed-off-by: only across all 7 commits, Assisted-by: in PR body).
Blockers:
- Signed/unsigned comparison bug (
drivers/hid/hid-magicmouse.c:1114, 1118, 1120, 1139, 1150, 1154):int tool = le16_to_int(f->tool_major)sign-extends the 16-bit LE field (-32768..32767), whilemsc->mtp_palm_area[2]isu32. Intool > msc->mtp_palm_area[0]andtool > msc->mtp_palm_area[1], C usual arithmetic conversions promoteint tooltou32, so any rawtool_majorwith bit 15 set (tool < 0) becomes>= 0x80000000Uand falsely triggers both the immediate palm mark (> area[1]) and hand-force click suppression. Additionally,apple,palm-tool-areainDocumentation/devicetree/bindings/input/apple,dockchannel-hid.yamlhas nomaximum: 32767, andmagicmouse_probe()does not reject values> S16_MAX(which would silently disable the rule). Please addmaximum: 32767to the binding, validate<= S16_MAXat probe, and store/comparemtp_palm_areaasint. - PR readiness & missing §5 hardware evidence on live head: The PR is out of draft, yet the PR body still lists three hardware checks "before this leaves draft" (surface-only
>2200thumb approach test, this DT-selected build onf2c267cb, and Force Click with a resting palm). Please post the live-head HW rows (J815 on this head + DTB covering Force Click with resting palm and>2200thumb approach; J813 with a resting palm underapple,touch-states) along with the §5 regression line (0 SELinux denials, 0 failed units, 0 new kernel errors), and update the PR body.
Minor hardening / nits (non-blocking):
magicmouse_mtp_on_surface()(drivers/hid/hid-magicmouse.c:1052-1062) states that only make-touch (3) and touching (4) are on the surface, but uses a denylist (1, 2, 5, 6, 7) instead of allowlisting3, 4— leaving state0(observed 2,555 times on J813) reliant ontouch_major == 0and not cleared inmagicmouse_mtp_update_palms().drivers/hid/hid-magicmouse.c:1930comment (/* The T6041, J616s, J813 and Trackpad26 controllers classify palms. */) omits J815.
Assisted-by: LLM (Gemini 4 Neon)
…ates 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 <nekreshen@yandex.ru>
…lm 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 <nekreshen@yandex.ru>
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 <nekreshen@yandex.ru>
…T 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 <nekreshen@yandex.ru>
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 <nekreshen@yandex.ru>
f2c267c to
f5b7717
Compare
|
Re-review of f5b7717: no blockers.
Optional: the comment at hid-magicmouse.c:1030-1033 and the messages of c99a772 and a89f8bc name the macOS component used as the reference. "Checked against macOS's own contact labels" says the same without naming it. HW row (still owed, at f5b7717 and its DTB, default command line): J815 Force Click with one palm resting and the other hand clicking; J815 thumb landing that starts above the second threshold and is still reported as a finger; J813 palm resting while typing under Assisted-by: LLM (Claude:Opus 5.5) |
|
@DjDeveloperr @RyanTheTide fixed in
Checks: each changed commit builds Still owed on
Assisted-by: LLM (Claude:Opus 5.5) |
Carries #2116, which gig3m closed in favour of this PR. The first two commits are its J813 palm commit (
751b6d50, Kyle's) and the J815 follow-up (6bfbc998), rebased but otherwise unchanged. The five after them:e143d679dt-bindings: input: apple,dockchannel-hid: Describe trackpad touch states and palm rules3fa72f8aarm64: dts: apple: t8142-j813, t8142-j815: Describe the trackpads' palm rulesc99a772fHID: magicmouse: report only touching MTP contacts, in path-ID slotsa89f8bc5HID: magicmouse: give the J815 trackpad its own palm rule, from its DT nodef5b7717bHID: magicmouse: leave a resting hand's force out of the J815 clickThe palm-rule commit replaces the J815 rule from the second commit, which turned out to mark some fingers as palms (details below).
Changed on this head (
f5b7717b), from DjDeveloperr's and Ryan's last reviews:mtp_palm_area[]is nowint, so a rawtool_majorwith bit 15 set (sign-extended byle16_to_int()) compares as negative instead of as a huge unsigned value that would mark a palm. The binding gives bothapple,palm-tool-areavaluesmaximum: 32767, and probe warns and leaves the rule off for a value aboveS16_MAX(a89f8bc5,e143d679).apple,touch-states, only make touch (3) and touching (4) can be on the surface. Every other state, including the J813's zero-size state-0 records, is off it (c99a772f). For states 0-7 that is the same result as before, because state 0 already failed the size test.ABS_MT_TOOL_TYPEcomment and themtp_palmskernel-doc name the J815 as well.f2c267cb. The two carried HID: magicmouse: report the J813 trackpad's palms #2116 commits are byte-identical.Changed on the previous head:
apple,touch-states(3fa72f8a). gig3m's J813 recordings (MTP firmware 6310.85.7: 85,862 + 25,093 frames, 1,659 contacts) show the same lifecycles and path IDs as the J815, with no path ID twice in a frame. The records in state 0 between a contact's out of range and its path ID's next start have zero sizes, so the on-surface test already drops them. With the driver commits and both J813 properties, over 8 minutes: 358 make-touch records gave 358 touches, the one hovering contact and 1,252 off-surface records started none, and 22 simultaneous landings each got their own touch.apple,palm-tool-area: the binding says the first value is below the second. The driver warns at probe and leaves the rule off if they are swapped.integration/auroracc14570. My commits carry only mySigned-off-by.Selected by the trackpad node, not the machine
The trackpad's behaviour is now described by three properties on the
multi-touchnode, in the same wayapple,j700-multitouchselects the C1FE layout:apple,touch-statesapple,palm-debounceapple,palm-tool-area = <a b>aon two consecutive reports, or any contact on the surface pastb. Its force is left out of the click.<1200 2200>The binding allows neither
apple,palm-debouncetogether withapple,palm-tool-area, nor any of the three withapple,j700-multitouch.dt_binding_checkpasses, and the J813/J815 DTBs passdtbs_check. A J815 DTS with an unknown property, or with both palm rules, is rejected. The T6041 and J616s selections already in the driver still use the machine compatible. I left them as they are; they can move to the node in a follow-up.How the data was collected
The J815's standard MTP record was decoded against macOS's own parse of the same frames. A small tool registered
MTRegisterFullFrameCallbackfrom MultitouchSupport. For each frame it logged the raw 0x75 report next to macOS's parsed contacts (path ID, state, finger class, hand ID, ellipse, pressure) and the cursor and button state. The session ran 10 minutes on macOS 27.2 (MTP firmware 6300.85.6) and covered typing with resting palms, pointing, scrolling and gestures: 607 contacts, 34 of them hands. Every claim below was checked record by record against those labels. The Linux numbers come from evdev traces of A/B runs on the same machine.1. Touch states and path-ID slots
The low byte of the record's first word is the firmware path ID. The high byte is the touch state:
A finger approaching or leaving the pad still has a position and nonzero sizes, so the touch-size test reported it as a touch: 374 such reports in 10 minutes. These states are now dropped.
Contacts now stay in their path ID's slot (
input_mt_get_slot_by_key) instead of being matched by distance. Distance matching swaps slots when one finger lifts as another lands in the same frame, which happened in about 100 frames in 10 minutes. The slot is looked up inside the report loop, so contacts that land together get different free slots.INPUT_MT_DROP_UNUSEDreleases the slots of path IDs that are gone.The firmware also reuses a path ID in the report right after the old contact goes out of range (40 times in 10 minutes). An out-of-range record no longer keeps its ID's palm mark, so the new contact doesn't inherit it.
2. J815 palm rule
Two consecutive palm classes (≥ 6) mark a palm in the J813 rule, which #2116 currently applies to the J815 too. Against the macOS labels, it marked two finger contacts as palms until they lifted, losing 966 finger reports:
On the J815 the hand classes are 6, 7, 8 and 12; class 10 isn't a hand. The new rule:
1400 also missed 4 of 25 palms that rested while typing on Linux (they peaked at 1325-1400). 1100 would mark one finger from the macOS session.
3. A resting hand never clicks
The host derives the click from the summed contact force, and a resting palm reaches the press threshold of 120 on its own. On macOS a resting hand neither clicks nor moves the pointer, while a finger of the other hand still clicks and Force Clicks. This commit leaves out the force of every hand contact:
I ran pointing, typing, and pointing with one palm resting while the other hand clicked 5 times, in two passes. Each click was attributed from the evdev trace; a hand is a palm-marked contact or one wider than 2200.
Testing
integration/aurora+ this stack), KDE Plasma 6.8, libinput 1.32. The palm, click and touch-state behaviour was tested with the board-matched form of these commits. With the DT above, the code paths are the same: the diff against that form is the property reads and the surface check inmagicmouse_mtp_hand().f5b7717b) and its DTB, default command line:apple,touch-states;apple,palm-debounce, and getsapple,touch-states, so it needs this series' DTB. No palm landed in gig3m's run with the states on, so the J813 palm rule under the states is still to be exercised.W=1and no warnings,checkpatch --strictis clean on all seven, anddt_binding_check(apple,dockchannel-hid.yaml) andCHECK_DTBSpass on the J813/J815 DTBs.Not in this PR:
touch_major/minorcarry the controller's signal total and density, not sizes. Changing that needs a libinput quirk too.Assisted-by: LLM (Claude:Opus 5.5)