Repository navigation
usb: typec: ucsi: Add Surface UCSI-over-HID driver & charger Artg support - #184
JValdivia23 wants to merge 4 commits into
Conversation
Microsoft Surface devices whose System Aggregator Module (SSAM) exposes a USB Type-C UCSI Platform Policy Manager over HID advertise a vendor application collection (Usage Page 0xFF00, Usage 0xF900; matched on Windows by SurfaceUcmUcsiHidClient.inf via HID\VID_045E&UP:FF00_U:F900). Because multiple unrelated SSAM HID functions can share the same VID:PID (for example, Surface Book 3 Base 045E:09A6 exposes both UCSI PPM collection 0xFF00:0xF900 and CFU firmware update collection 0xFF0B:0x0101), and hid-generic yields devices based solely on hid_device_id table matches without consulting .match(), assign HID_GROUP_SURFACE_UCSI during report descriptor scanning so a dedicated UCSI HID transport driver can bind cleanly across all Surface models without disturbing sibling collections. Signed-off-by: Jairo Valdivia <valdiviaprado.ing@gmail.com> Patchset: surface-ucsi-hid
|
Thanks for this! I've tested it on the Surface Pro X (details in linux-surface/surface-pro-x#35). Required some fixes/quirks, but then the driver works there as well: ports, partners, PD contracts, PDOs, and connector-change notifications. Note that the SPX also needed some additional work outside the scope of this PR (registry node, event registry selection in Here are the issues I've found. Would be good if you could address those and check on the SB3: 1.
|
|
A small follow-up on the
So the report layout in your driver matches Windows exactly. Always sending Neither of the two PPM quirks from my previous comment ( |
Several Microsoft Surface devices (including Surface Book 3 and Surface Pro X) do not expose an ACPI UCSI device (PNP0CA0 / USBC000). Instead, their Surface System Aggregator Module (SSAM) exposes a UCSI v1.x Platform Policy Manager over HID application collection 0xFF00:0xF900 (matched by HID_GROUP_SURFACE_UCSI), using: - Feature Report 0x32 (49 bytes): standard 48-byte UCSI v1.x data block (VERSION, RESERVED/seq, CCI, CONTROL, 16-byte MESSAGE_IN, 16-byte MESSAGE_OUT) prefixed by report ID 0x32. - Input Report 0x32: asynchronous notification signalling a CCI update, after which the updated UCSI state is read via Feature Report 0x32. - Feature Report 0x33 (3 bytes): PPM capability summary (connector count and UDC support flag). Add ucsi_surface_hid to bridge this HID transport to the Linux UCSI core, exposing /sys/class/typec/port* and ucsi-source-psy-* power_supply telemetry, with workarounds for SAM UCSI firmware quirks: - Report UCSI v1.1 unconditionally, as SAM does not populate the version field in Feature Report 0x32. - Synthesize UCSI_CCI_COMMAND_COMPLETE when SAM sets UCSI_CCI_NOT_SUPPORTED or UCSI_CCI_ERROR without command completion. - Strip the leading 1-byte entry length (0x06) prepended by SAM to UCSI_GET_ALTERNATE_MODES responses. - Ensure UCSI_ENABLE_NTFY_CMD_COMPLETE is set on empty-mask UCSI_SET_NOTIFICATION_ENABLE commands so SAM clears RESET_COMPLETE. Tested on Surface Book 3 (0019:045E:09A6) and Surface Pro X (0019:045E:0922). Closes: linux-surface/surface-pro-x#35 Signed-off-by: Jairo Valdivia <valdiviaprado.ing@gmail.com> Patchset: surface-ucsi-hid
…get_property() spwr_ac_update_unlocked() returns 1 when ac->state changes, 0 when unchanged, and a negative errno on failure. Checking if (status) in spwr_ac_get_property() causes the first property read observing a state transition (such as initial registration when AC is connected) to abort without populating val->intval and return +1 to power_supply_sysfs. Check for status < 0 and normalize status to 0 before reading the requested property. Fixes: e61ffb3 ("power: supply: Add AC driver for Surface Aggregator Module") Signed-off-by: Jairo Valdivia <valdiviaprado.ing@gmail.com> Patchset: surface-sam
SSAM target category SSAM_SSH_TC_BAT command 0x0f (Artg) reports the rated power of the currently connected AC / USB-C PD adapter in mW when external power is online (_PSR != 0). Query CID 0x0f whenever ac->state is non-zero (gracefully falling back to 0 if unsupported by older firmware), emit power_supply_changed() if the adapter rating changes, and expose the value in microwatts through POWER_SUPPLY_PROP_INPUT_POWER_LIMIT. Verified on Surface Book 3 (reports 60000 mW -> 60000000 uW with a 60 W USB-C PD adapter and 0 when unplugged). Closes: linux-surface/linux-surface#1069 Signed-off-by: Jairo Valdivia <valdiviaprado.ing@gmail.com> Patchset: surface-sam
e504c62 to
aa4c309
Compare
|
Thanks @qzed for the thorough review and for testing on Surface Pro X! I have updated the branch (and tested on Surface Book 3 running
|
|
Just for my understanding regarding 3: Does the SB3 actually return a valid version there or not? |
|
@qzed It does not return a valid version in Report To be 100% sure why, I disassembled the Surface Book 3 Keyboard Base (
(As a nice bonus, the disassembly also confirmed our other quirks: at Since the KIP firmware actually writes |
|
Tested on a second Surface Book 3 (13.5", SAM-over-SSH, Bazzite, kernel 7.3.3), built as an out-of-tree module. It works, and it let me fix a long-standing charging fault. Two things that may be useful for the PR. 1. Product ID differs on this unit The UCSI collection shows up as The sibling interface on 2. USB-C charging stops after a clipboard reattach, and a soft CONNECTOR_RESET fixes it This is the fault reported in linux-surface/linux-surface#623 in 2021 ("USB-C charging is not working anymore after detaching and reattaching. The USB-C cable needs to be removed and plugged in again"). It reproduces every time here with a USB-C charger left in the base. State after the reattach, with this driver loaded (it re-probes and resets the PPM when the base HID devices come back):
So the PD contract survives, but the system does not draw from it, and the PPM reset on probe does not change that. Through the UCSI debugfs
I now send that soft reset from the surface-dtx-daemon attach handler when a partner is present and I have not tested whether Windows sends the same command; the 2021 reporter said Windows showed the fault too on their unit, and the owner of this one does not recall it there. If it would help, I can capture SAM events (tc 0x02 and 0x11) across a detach and reattach, or test a version of the driver that issues the reset itself. Side note for anyone reading old logs: the |
Summary
Several Microsoft Surface models whose Embedded Controller uses the Surface System Aggregator Module (SSAM) — including Surface Book 3 and Surface Pro X — do not expose an ACPI UCSI device (
PNP0CA0/USBC000). Instead, SAM exposes a standard UCSI v1.x Platform Policy Manager (PPM) over HID (HID\VID_045E&UP:FF00_U:F900, handled on Windows bySurfaceUcmUcsiHidClient.sys), leaving/sys/class/typecempty on Linux.In addition,
surface_chargercurrently only queries SSAMTC=0x02, CID=0x0d(_PSRonline status) and does not exposeTC=0x02, CID=0x0f(Artg, connected AC / USB-C PD adapter wattage rating inmW).This series adds both pieces cleanly (
checkpatch.pl: 0 errors, 0 warnings across all 4 commits):HID: Assign HID_GROUP_SURFACE_UCSI to Microsoft Surface UCSI collections(Patchset: surface-ucsi-hid)HID_GROUP_SURFACE_UCSI(0x0106) inhid_scan_collection()whenvendor == USB_VENDOR_ID_MICROSOFT,type == HID_COLLECTION_APPLICATION, and usage is0xFF00:0xF900.VID:PID(e.g. Surface Book 3 Base045E:09A6exposes both0xFF00:0xF900UCSI PPM and0xFF0B:0x0101Base CFU firmware update) andhid-genericyields based solely onid_tablewithout consulting.match(), grouping at scan time (analogous toHID_GROUP_VIVALDI) letsucsi_surface_hidbind across all Surface models (09A6,0922, etc.) without disturbing sibling collections.usb: typec: ucsi: Add Microsoft Surface HID transport driver(Patchset: surface-ucsi-hid)0x32(49-byte report:report_id+ standard 48-byte UCSI v1.x data block) and Feature Report0x33(3-byte PPM capability summary:num_connectors,udc_supported) to the Linuxtypec_ucsicore (CONFIG_UCSI_SURFACE_HID).0x32VERSIONbytes (e.g.0x7628observed on Surface Book 3 prior toUCSI_PPM_RESET) toUCSI_VERSION_1_1(0x0110).0x32feature report reads to a workqueue outside the SSAM event notifier callback.power: supply: surface_charger: Fix positive return value in spwr_ac_get_property()(Patchset: surface-sam)spwr_ac_update_unlocked()returns1whenstatechanges;spwr_ac_get_property()previously checkedif (status)instead ofif (status < 0), returning+1without populatingval->intvalon transitions.power: supply: surface_charger: Expose connected adapter power rating(Patchset: surface-sam)TC=0x02, CID=0x0f(Artg, rated PSU power inmW) when external power is online (_PSR != 0), gracefully falling back to0if unsupported, and exposesPOWER_SUPPLY_PROP_INPUT_POWER_LIMIT(inuW, matchingmacsmc-power).Closes: linux-surface/surface-pro-x#35
Closes: linux-surface/linux-surface#1069
Related: linux-surface/linux-surface#2195
Hardware Verification (Surface Book 3, Linux 7.3)
dmesgon module load (zero warnings/errors):/sys/class/typec/port0:usb_typec_revision:1.3,usb_power_delivery_revision:3.0data_role:host [device],power_role:source [sink],usb_capability:usb2 [usb3],supported_accessory_modes:debug/sys/class/power_supply/ucsi-source-psy-0019:045E:09A6.00021:POWER_SUPPLY_USB_TYPE=[C] PD PD_PPS,POWER_SUPPLY_SCOPE=SystemGET_PDOS+GET_CURRENT_CAM/GET_CONNECTOR_STATUSRDO20V@3A= 60 W) and SSAMCID=0x0fArtgreporting60000mW (60000000uW) when attached and0when unplugged, with all sibling SSAM HID devices (09A6.0004Base CFU,09AEkeyboard,09AFtouchpad) completely unaffected.