Skip to content

arm64: dts: apple: t8132, t8142: describe the USB-C ports as dual-role - #2511

Open
RyanTheTide wants to merge 1 commit into
integration/aurorafrom
dtfill/usb-c-dual-role
Open

RyanTheTide wants to merge 1 commit into
integration/aurorafrom
dtfill/usb-c-dual-role

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Problem. On the T8132 (M4) and T8142 (M5) Macs, every USB-C port is dual-role: a dwc3 controller behind an ATC PHY, with a role switch the port controller drives. Several board files still call these controllers host-only. The T8132 SoC .dtsi sets dr_mode = "otg" with usb-role-switch, but t8132-jxxx.dtsi (ports 0 and 1), J604 port 3, J624 ports 2 and 3 and J773g port 3 override it with dr_mode = "host". On the T8142, the J704 and J813 USB files mark every USB-C controller dr_mode = "host" and every connector data-role = "host".

Nothing depends on those values: dwc3-apple sets the controller's mode itself on every role change, and the port controller drivers don't read the connector's data-role. They only misdescribe the hardware.

Change. Drop the T8132 overrides so the SoC's otg applies. On the T8142, describe the controllers as otg and the connectors as dual, matching the T8132 boards. J773g port 2 feeds a fixed USB hub and stays host-only.

Testing. Every T8132 and T8142 DTB in the tree was built before and after and decompiled. Only these properties change:

Board Changes
J604, J623, J624, J713, J715, J773g dr_mode host -> otg on 3, 2, 4, 2, 2 and 3 controllers
J704, J813, J815 dr_mode host -> otg and data-role host -> dual on 3, 2 and 2 ports

dtc warnings are unchanged (the same pre-existing ones on J713, J813 and J815). dt-validate with the tree's schema reports 40 messages before and after, 0 new.

Still to run. One boot per family with a USB device on each USB-C port, then unplug and replug: the device enumerates as before and dmesg shows no new dwc3 or role-switch errors.

  • T8132: a J713, J715 or J773g.
  • T8142: a J813 or J704.
Why dr_mode does not change runtime behaviour

drivers/usb/dwc3/dwc3-apple.c registers its own role switch (dwc3_usb_role_switch_set). On a role change it writes dwc.dr_mode itself: host before core init on a new cable session, or host/peripheral from the switch's role. The DT dr_mode only seeds the core's first probe, and the controller starts in host (role-switch-default-mode = "host", which stays). The T8132 boards J623, J713 and J715 get their ports 0 and 1 from t8132-jxxx.dtsi through the shared laptop/desktop files, so their DTBs change too.

Assisted-by: LLM (Claude:Opus 5.5)

The USB-C ports of the T8132 and T8142 Macs are dual-role: each port's
controller is the dwc3 behind an ATC PHY, with a role switch driven by the
port controller, and the T8132 SoC .dtsi already describes these
controllers as dr_mode = "otg" with usb-role-switch. Several board files
override that with dr_mode = "host" (T8132: t8132-jxxx.dtsi ports 0 and 1,
J604 port 3, J624 ports 2 and 3, J773g port 3), and the T8142 J704 and J813
USB files describe every USB-C controller as host-only and every connector
with data-role = "host".

Nothing depends on the host-only values: dwc3-apple sets the controller's
mode itself on every role change, and the port controller drivers do not
read the connector's data-role. They only misdescribe the hardware.

Drop the T8132 overrides, so the SoC's "otg" applies, and describe the
T8142 controllers as "otg" and their connectors as "dual", as on the T8132
boards. The J773g's port 2, which feeds a fixed USB hub, stays host-only.

Every T8132 and T8142 DTB changes only in these properties.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve after one T8132 boot.

I checked the claim that dr_mode and data-role are description only, and it holds. dwc3-apple overwrites dwc->dr_mode in dwc3_apple_set_role() before xHCI or the gadget starts, skip_core_init_mode keeps dwc3_drd_init() and dwc3_core_exit_mode() out of the path, and the only first-probe check (dwc3_core_set_initial_role()) refuses host only for peripheral. host_only comes from Kconfig and the compatible. The SN201202x takes its data capability from SYSTEM_CONF through tps6598x_register_port(); only the TPS25750 path reads DT data-role. The #2434 J773g log already shows dwc3_1 taking the device role while its DT said host.

J773g port 2 staying host with its fixed hub is right.

Before merge: one boot on a J773g or J713 with a device on each changed port, unplug and replug, no new dwc3 or role-switch lines. Every enabled T8132 controller had dr_mode = "host" until now, so this is the first time any of them probes with otg. The T8142 row can come after merge.

Two notes:

  • #2434 and #2334 are still open. On this base a calibrated T8132 port in the device role still fails in atcphy_usb3_set_mode(). This PR is consistent with #2334 (device capability from the PHY, not DT) and does not depend on it, but "dual-role" on T8132 only works for USB2 until #2334 lands.
  • j813.config builds CONFIG_USB_DWC3_HOST=y, so with otg in DT each J813/J815 controller now logs "Configuration mismatch. dr_mode forced to host" at first probe. Please switch that config to DUAL_ROLE in a follow-up, or mention the line in the row.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

T8132 row on a J713 (M4 MacBook Air, 13"): PASS.

The J713's DTB with this PR's change applied (dr_mode deleted from both dwc3 nodes; its connectors already have data-role = "dual"). Everything else was the J713's default: kernel 7.3.0 (stock cmdline), and the same aura/U-Boot bytes as its configured Stage 2. One aura-try boot. Before that, a baseline on the default boot (dr_mode = "host").

  • Host (port 0, USB-C monitor with a USB 2.0 hub and two devices): the hub and both devices enumerate at boot. I unplugged and replugged twice by unbinding and rebinding that port's PD controller: the hub went away and came back each time, with data role host.
  • Device (port 1, a Linux host on the other end): an NCM+ACM gadget reaches configured at high speed. The host binds cdc_ncm and cdc_acm on both binds, with no can't set config / -110.
  • dmesg: no dwc3, typec, tps6598x, atcphy or xhci errors on either boot (0 lines each).

Not covered: SuperSpeed host (the hub is USB 2.0 only), a physical unplug (software PD rebind instead), and T8142.

Details
  • DT check on the trial boot: /proc/device-tree/soc/usb@402280000/dr_mode and .../usb@40a280000/dr_mode absent (both host on the default boot).
  • The gadget needs ~15 s from bind to configured on this port (the M3 Air needs about the same). A check at 8 s still reads not attached.
  • On the same Air with today's dr_mode = "host", the controller also enters device role and its UDC works (earlier rows). That fits the PR's point that dr_mode has no runtime effect here.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge-train adversarial review (MERGETRAIN-LINUX2) at f8c5e27: NO BLOCKERS.

Code read only, nothing built here. Before the merge it still needs Dj's verdict at this head; the missing rows are listed below.

Full review

#2511 arm64: dts: apple: t8132, t8142: describe the USB-C ports as dual-role @f8c5e279

VERDICT: NO BLOCKERS

I verified the PR's claim that "nothing depends on the value":

  • dwc3-apple probes the core with skip_core_init_mode and sets dwc.dr_mode itself on every role (dwc3-apple.c:724, 932).
  • dwc3_core_remove_no_shutdown() skips dwc3_core_exit_mode(), so dr_mode == OTG never reaches dwc3_drd_exit() on an uninitialised DRD.
  • dwc3_get_dr_mode() keeps OTG because USB_DWC3_APPLE selects USB_ROLE_SWITCH and the nodes have usb-role-switch. So the host-first initial_role = HOST check (core.c:2300) cannot hit -EINVAL.
  • The host-only rx/tx_thr branch (core.c:1258) changes nothing: no Apple DT sets those properties.
  • The tipd/cd321x/sn201202x drivers take their data capability from the PD controller (tipd/core.c:2491-2508). Only tps25750 reads data-role.
  • M1/M2/M3/T8140 already run dr_mode = "otg" on the same glue.
  • The J773g fixed-hub port (dwc3_2, j773g.dts:213) stays host.

Nits:

  1. With dr_mode OTG, the first dwc3_core_init() runs before any role has written dwc.dr_mode, whereas before it ran with HOST (if the first cable is a device role). This is harmless on this IP version (the clock-gating quirk at core.c:1058 covers OTG and HOST alike), but the claim of "no runtime effect" is slightly overstated.
  2. This interacts with phy: apple: atc: serve a T8132 device role on USB2 #2434: with both merged, T8132 ports are described as dual-role and actually serve a device role over USB2. Merge phy: apple: atc: serve a T8132 device role on USB2 #2434 first, or say so in one place.

Missing rows (the PR lists them as still to run; none are done):

  • One T8132 (J713/J715/J773g) and one T8142 (J813/J704) boot: a device on every USB-C port, unplug/replug, no new dwc3 or role-switch errors.
  • J604/J624 have the most ports changed (3 and 4) and get no row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants