Skip to content

wb7: fix USB gadget high-speed enumeration (PHY TX tune)#361

Draft
evgeny-boger wants to merge 4 commits into
feature/v6.18from
feature/wb7-usb-phy-tx-tune
Draft

wb7: fix USB gadget high-speed enumeration (PHY TX tune)#361
evgeny-boger wants to merge 4 commits into
feature/v6.18from
feature/wb7-usb-phy-tx-tune

Conversation

@evgeny-boger

Copy link
Copy Markdown
Member

Problem

WB7 USB gadget reliably fails to enumerate at high speed when connected directly to some laptop root ports (no hub in between). The HS chirp handshake succeeds and host SETUP packets are decoded fine, but the host never accepts the ep0 IN data stage, so enumeration retries forever while musb floods dmesg with SetupEnd came in a wrong ep0stage. Through most hubs enumeration works, masking the issue.

This is the same marginality that #122 worked around by capping the gadget to full-speed — a cap that silently became a no-op on 6.x kernels (the 5.10-era usb_get_maximum_speed() parsing in musb sunxi glue was lost in the rebase), which is why the failure resurfaced.

Root cause

phy-sun4i-usb hardcodes the PHY TX tune field (regs 0x20-0x24) to the Allwinner BSP default 0x14 = minimum TX amplitude, slew rate 5. The resulting HS TX signal is too weak for some host receivers.

Fix

  • new optional per-PHY DT properties allwinner,usbX-tx-amplitude (0-3) and allwinner,usbX-tx-slew-rate (0-7), defaults unchanged
  • WB7 dts sets both to maximum for USB0

First two commits are upstream-shaped (bindings + driver), prepared for mainline submission as well.

Validation (WB 7.4.2, ALEPBSP3, direct connection to Latitude 9430 root port)

Deterministic A/B on live hardware via PHY tp-write:

tune value enumeration iperf host-side rx_errors per 10 s run
0x14 (stock: amp 0, slew 5) fails (state=default forever) n/a
0x15 / 0x16 (amp 1-2) fails n/a
0x17 (amp 3, slew 5) OK 1231
0x1b (amp 3, slew 6) OK 112
0x1f (amp 3, slew 7) OK, 4/4 cycles 4; then 0 over 60 s saturated duplex

Kernel built from this branch (6.18.22-wb6-usbtune, device config) — boots pending on-device deb verification.

Caveats

  • Tune values validated against a handful of hosts and via-hub paths on the bench; broader fleet/host coverage welcome before undrafting.
  • The maximum-speed = "high-speed" dts change is currently unparsed (see above) and only documents intent.

🤖 Generated with Claude Code

evgeny-boger and others added 4 commits July 10, 2026 03:24
The PHYs on Allwinner SoCs have a 5-bit TX tune field controlling the
TX amplitude (2 bits) and slew rate (3 bits) of the line driver. The
driver currently hardcodes the value inherited from the Allwinner BSP
(minimum amplitude, slew rate 5), which on some boards results in a
high-speed TX signal too weak for the link partner: on Wiren Board 7
(A40i/R40) devices the USB gadget fails to enumerate at high speed on
several tested hosts and bulk data gets corrupted under load.

Add optional per-PHY properties to tune the TX amplitude and slew rate.

Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The driver programs the PHY TX tune field (registers 0x20-0x24) with a
fixed value of 0x14, inherited from the Allwinner BSP: TX amplitude
tune 0 (the minimum) and slew rate tune 5.

The minimum TX amplitude turns out to be insufficient for some
host/device combinations at high speed. On Wiren Board 7 (A40i/R40)
devices the USB gadget reliably fails to enumerate when connected
directly to several tested laptop root ports: the HS chirp handshake
succeeds and host SETUP packets are decoded fine, but the host never
accepts the IN data stage, so enumeration retries forever while musb
logs "SetupEnd came in a wrong ep0stage". With the amplitude raised to
the maximum (3) enumeration succeeds, but bulk IN data still gets
corrupted under load (>100 packet errors per second on the host side)
until the slew rate tune is raised as well; with amplitude 3 and slew
rate 7 the link is error-free over minutes-long saturated transfers.

Add optional per-PHY devicetree properties to set the two TX tune
fields, keeping the current values as defaults.

Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
With the default TX tune (minimum amplitude, slew rate 5) the USB
gadget fails to enumerate at high speed on several tested hosts when
connected directly (without a hub): the host never receives the ep0 IN
data stage. Even when enumeration succeeds, bulk IN data gets corrupted
under load. Set both tune fields to maximum: validated error-free on
WB 7.4.2 with 60+ s of saturated bidirectional iperf traffic.

Also change the (currently unparsed) usb_otg maximum-speed cap from
full-speed to high-speed to document that the FS workaround from #122
is no longer wanted.

Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant