Skip to content

arm64: dts: mediatek: xaga: bring up USB peripheral and guarded OTG h… - #1

Open
2824799 wants to merge 1 commit into
MT6895-Mainline:7.2-mt6895-xiaomi-xagafrom
2824799:7.2-xaga-usb-fix
Open

arm64: dts: mediatek: xaga: bring up USB peripheral and guarded OTG h…#1
2824799 wants to merge 1 commit into
MT6895-Mainline:7.2-mt6895-xiaomi-xagafrom
2824799:7.2-xaga-usb-fix

Conversation

@2824799

@2824799 2824799 commented Sep 10, 2026

Copy link
Copy Markdown

Summary

This pull request resolves USB device/peripheral enumeration, Type-C PD negotiation, charger BC1.2 handoff, and safe OTG host power management on the Xiaomi Redmi Note 11T Pro / POCO X4 GT (xaga, MT6895).

Problem & Background

  1. Peripheral Enumeration Failure: On xaga, the MTU3 USB core does not have a dedicated analog VBUS sense line routed directly to the SoC. Without internal VBUS validity indication, MTU3 never initiates softconnect or pulls up the D+ line, making the device completely invisible to host PCs when plugged in via USB.
  2. Unsafe OTG VBUS Power: Previously, OTG 5V boost was uncoordinated with Type-C CC state machines, risking accidental VBUS backfeed into host ports or tailboard damage.
  3. TCPCI Alert & Packet Dropping:
    • tcpci_set_polarity previously overwrote TCPC_TCPC_CTRL via regmap_write, unintentionally clearing the connection alert notification bit.
    • tcpci_read_message lacked strict header and byte count validation, which could forward corrupted packets or 0V PDOs to the TCPM state machine.

Key Changes

  1. MTU3 Dual-Role & Peripheral Mode (drivers/usb/mtu3/):

    • VBUS Software Synchronization: Implemented ssusb_set_device_vbus() referencing the Xiaomi MT6895 vendor BSP (mediatek,force-vbus). When TCPM signals USB_ROLE_DEVICE, the driver asserts U3D_MISC_CTRL (VBUS_FRC_EN | VBUS_ON) and clears SSUSB_U2_PORT_OTG_SEL, successfully triggering high-speed device enumeration. Flags are cleanly cleared on cable disconnect or host mode.
    • Role Synchronization & Locking: Protected dr_work and recovery paths with a role_lock mutex and runtime PM references. Restricted userspace role overrides on xaga to ensure only the hardware TCPM state machine drives transitions.
    • VBUS Regulator Flexibility: Handled optional/missing local VBUS regulators in ssusb_set_vbus when power is managed externally by the charger.
  2. TCPCI & PD Robustness (drivers/usb/typec/tcpm/):

    • Modified tcpci_set_polarity to use regmap_update_bits, updating only the orientation bit while preserving connection alert flags.
    • Hardened tcpci_read_message to strictly validate message byte counts against PD header lengths and safely discard malformed packets.
  3. MT6375 Charger, PHY & Guarded OTG (drivers/power/supply/mediatek/, drivers/phy/):

    • Added coordination between BC1.2 charger detection and USB PHY data pin ownership.
    • Implemented MT6375 OTG boost 5V supply gated strictly by TCPM, ensuring 5V is only sourced when a downstream OTG partner has been safely negotiated.
    • Restricted I2C bus regulator lookup in i2c-mt65xx to controller supplies.
  4. Device Tree (arch/arm64/boot/dts/mediatek/):

    • Configured ssusb and usb_host in dr_mode = "otg" with peripheral default.
    • Included mt6895-xaga-usb-tcpm.dtsi defining the Type-C port, TCPC node, and power supplies.

Hardware Validation

  • Device Mode (ADB / RNDIS / Gadget): Verified High-Speed (480Mbps) enumeration (1d6b:0104) on PC host, stable IP communication (usb0), RDP and SSH over USB without packet drops.
  • OTG Host Mode: Verified USB keyboard, gaming mouse (Logitech G102), and 2.4G wireless receiver via powered/unpowered Type-C hubs.
  • Charging & PD: Verified PD negotiation (5V/1.5A sink) and charging while operating through a USB-C dock.

Tested-by: Silvia 2824799@users.noreply.github.com
Signed-off-by: Silvia 2824799@users.noreply.github.com

…ost support

This commit resolves USB device enumeration, Type-C PD negotiation,
charger BC1.2 handoff, and guarded OTG power sourcing on Xiaomi Redmi Note 11T
Pro / POCO X4 GT (xaga, MT6895):

1. MTU3 Dual-Role Controller & Peripheral Mode:
   - Synchronize MTU3 internal VBUS state with external TCPM data role:
     xaga lacks dedicated analog VBUS sensing routed to the MTU3 core.
     Following the Xiaomi vendor MT6895 reference driver (mediatek,force-vbus):
     when Type-C enters DEVICE mode, assert U3D_MISC_CTRL (VBUS_FRC_EN | VBUS_ON)
     and clear SSUSB_U2_PORT_OTG_SEL to enable softconnect and D+ pullup,
     allowing host computers to detect and enumerate the phone.
     Safely clear force-vbus flags upon cable disconnect or host mode switch.
   - Restrict role-switch userspace override on xaga to ensure only TCPM
     drives role transitions without power role contention.
   - Add role_lock mutex and runtime PM gating in mtu3_dr to serialize
     dual-role work and unbound device recovery.
   - Allow optional/missing local VBUS regulator in ssusb_set_vbus when
     power is handled entirely by an external charger/TCPM supply.

2. Type-C TCPCI Controller & PD Robustness:
   - In tcpci_set_polarity, use regmap_update_bits to modify the orientation
     bit while preserving connection alert flags in TCPC_TCPC_CTRL.
   - In tcpci_read_message, validate message byte count and header payload length
     strictly. Discard malformed frames to prevent forwarding invalid zero-PDOs
     to the TCPM state machine.

3. MT6375 Charger, PHY & Guarded OTG VBUS Power:
   - Coordinate MT6375 BC1.2 charger detection with USB PHY switching to release
     D+/D- data lines for USB transfer once detection concludes.
   - Implement MT6375 OTG boost 5V supply managed strictly by TCPM, ensuring
     power is sourced only after successful partner attach and role negotiation,
     preventing dangerous VBUS backfeed into host ports.
   - Restrict I2C bus regulator lookup in i2c-mt65xx to controller supplies.

4. Device Tree:
   - Enable ssusb and usb_host in dr_mode = "otg" with peripheral default.
   - Include mt6895-xaga-usb-tcpm.dtsi defining TCPC, connector, and VBUS supplies.

Tested-by: Silvia <2824799@users.noreply.github.com>
Signed-off-by: Silvia <2824799@users.noreply.github.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