phy: Add USB3 PHY support to Google Tensor SoC USB PHY driver
Subsystems (3)
PATCH v4 1/1 phy: Add USB3 PHY support to Google Tensor SoC USB PHY driver
Add USB3 PHY support for the Google Tensor G5 USB PHY driver. This patch adds functionality for the usb3_tca register, usb3 clock, and usb3 reset as defined in google,lga-usb-phy.yaml. Kconfig now lists USB SuperSpeed support.
Refactor the probe sequence to initialize the USB2 and USB3 PHYs, and then initialize clocks and resets for both PHYs afterwards.
Refactor set_vbus_valid to reduce duplicated code.
Implement USB3 phy_ops for phy_init, phy_exit, and phy_power_on. combo_phy_state enum is added to track PHY bringup state across PHY API calls.
---
Changes since v1:
* Removed mix of goto-based and scope-based cleanup from usb3 phy_init
* Removed unused usb3_core resource from probe
* Added combo_phy_state enum to interally track ComboPHY bringup state to allow google_usb_set_orientation() to change TCA orientation.
* Modify Kconfig documentation to reflect SuperSpeed support
Changes since v2:
* google_usb3_phy_init now sets USBDP_TOP_CFG_REG_PMGT_REF_CLK_REQ_N to false if phy_init fails elsewhere.
* google_usb3_phy_init errors are now handled via DEFINE_FREE structures. This affects set_pmgt_ref_clk_req_n, clk_bulk_prepare_enable, and reset_control_bulk_deassert.
* google_usb2_phy_init also handles undoing clk_bulk_prepare_enable via DEFINE_FREE structure.
* google_usb3_phy_power_on allows program_tca_locked in the COMBO_PHY_TCA_READY state. Waiting for PoR=>NC is only performed once.
* Note: there are checkpatch errors for the DEFINE_FREE macros resulting in "ERROR: trailing statements should be on next line". Other cases of DEFINE_FREE where the line limit would otherwise exceed 100 columns have the indentation done the same way.
Changes since v3:
* set_pmgt_ref_clk_req_n(false) in google_usb3_phy_exit() comes after reset assertion and clock disable to match phy_init() sequence.
* program_tca_locked in usb3 power_on() now requires a valid orientation to match google_usb_set_orientation requirements.
--- drivers/phy/Kconfig | 2 +- drivers/phy/phy-google-usb.c | 407 +++++++++++++++++++++++++++++++---- 2 files changed, 371 insertions(+), 38 deletions(-)
drivers/phy/Kconfig +1 -1
@@ -100,7 +100,7 @@ config PHY_GOOGLE_USB the G5 generation (Laguna). This driver provides the PHY interfaces to interact with the SNPS eUSB2 and USB 3.2/DisplayPort Combo PHY, both of which are integrated with the DWC3 USB DRD controller. - This driver currently supports USB high-speed. + This driver currently supports USB high-speed and SuperSpeed. config USB_LGM_PHY tristate "INTEL Lightning Mountain USB PHY Driver"
drivers/phy/phy-google-usb.c +370 -37
503 lines not on this page · raw message
base-commit: 2ace2e949979b82f82f12dd76d7c5a6145246ca3
Signature · 1 line
2.55.0.rc2.803.g1fd1e6609c-goog
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Data race on gphy->orientation causes redundant hardware programming and a 2.5-second timeout.
Pre-existing issues:
- [High] TOCTOU race on pm_runtime_suspended() allows hardware access while suspended, causing a bus fault. --
--- Patch [1]: [PATCH v4] phy: Add USB3 PHY support to Google Tensor SoC USB PHY driver --- commit 1008e9b0470bdcef99e7408c0e43896673f90ba3
Author: RD Babiera <[email protected]>
phy: Add USB3 PHY support to Google Tensor SoC USB PHY driver
This patch adds USB3 PHY support for the Google Tensor G5 USB PHY driver, including the usb3_tca register, clock, and reset functionality. It also refactors the probe sequence and implements USB3 phy_ops.
Quoted 4 lines
drivers/phy/phy-google-usb.c +0
-0
[ ... ]
drivers/phy/phy-google-usb.c static int google_usb_set_orientation(struct typec_switch_dev *sw, · line 266
Quoted 7 lines
drivers/phy/phy-google-usb.c +3
-0@@ -92,6 +261,9 @@ static int google_usb_set_orientation(struct typec_switch_dev *sw,set_vbus_valid (gphy); +if (gphy->phy_state ==COMBO_PHY_TCA_READY && orientation !=TYPEC_ORIENTATION_NONE ) +return program_tca_locked (gphy); +
[Severity: High]
This is a pre-existing issue, but does this function have a race condition with power management that could cause a bus fault?
google_usb_set_orientation() checks pm_runtime_suspended(gphy->dev) without holding a PM runtime reference. If the USB core releases its PM reference immediately after this check, the device could suspend and power off the PHY.
The function would then acquire the lock and call set_vbus_valid() and program_tca_locked() on unclocked and unpowered MMIO registers, resulting in a synchronous external abort.
Would it be safer to use pm_runtime_get_sync() to ensure the hardware remains active during these accesses?
Quoted 2 lines
drivers/phy/phy-google-usb.c +0
-0return 0 ; }
[ ... ]
Quoted 12 lines
drivers/phy/phy-google-usb.c +12
-0+static int google_usb3_phy_power_on (struct phy *_phy) +{ +struct google_usb_phy_instance *inst =phy_get_drvdata (_phy); +struct google_usb_phy *gphy = inst->parent; +int ret; + +dev_dbg (gphy->dev,"power on usb3 phy\n" ); + +guard (mutex)(&gphy->phy_mutex); + +if (gphy->phy_state !=COMBO_PHY_TCA_READY ) { +/* Wait for PoR -> NC transitions*/
drivers/phy/phy-google-usb.c static const struct phy_ops google_usb2_phy_ops = { · line 439
Quoted 10 lines
drivers/phy/phy-google-usb.c +10
-0+ ret =wait_tca_xa_ack (gphy); +if (ret) { +dev_err (gphy->dev,"PoR->NC transition timeout" ); +return ret; + } + gphy->phy_state =COMBO_PHY_TCA_READY ; + } + +if (gphy->orientation !=TYPEC_ORIENTATION_NONE ) +return program_tca_locked (gphy);
[Severity: High]
Can this lead to redundant TCA programming and a 2.5-second timeout?
Looking at google_usb_set_orientation(), gphy->orientation is updated before the mutex is acquired:
google_usb_set_orientation() {
gphy->orientation = orientation;
if (pm_runtime_suspended(gphy->dev))
return 0;
guard(mutex)(&gphy->phy_mutex);
...If a Type-C plug event (Thread A) sets gphy->orientation but is preempted before taking the lock, and the USB core concurrently calls google_usb3_phy_power_on() (Thread B), Thread B will see the new orientation, program the TCA, and release the lock.
When Thread A resumes, it will acquire the mutex, see COMBO_PHY_TCA_READY, and call program_tca_locked() a second time with the identical configuration. Since writing the same configuration to the TCA hardware doesn't trigger a new XA_ACT_EVT interrupt, wait_tca_xa_ack() will stall for its full timeout.
Should the orientation update be moved inside the lock?
Quoted 3 lines
drivers/phy/phy-google-usb.c +3
-0+ +return 0 ; +}
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
Quoted 8 lines · On Mon, Jul 6, 2026 at 4:27 PM <[email protected]> wrote:
[Severity: High]
This is a pre-existing issue, but does this function have a race condition with power management that could cause a bus fault?
google_usb_set_orientation()checkspm_runtime_suspended(gphy->dev)without holding a PM runtime reference. If the USB core releases its PM reference immediately after this check, the device could suspend and power off the PHY.
Quoted 6 lines
The function would then acquire the lock and call
set_vbus_valid()andprogram_tca_locked()on unclocked and unpowered MMIO registers, resulting in a synchronous external abort.Would it be safer to use
pm_runtime_get_sync()to ensure the hardware remains active during these accesses?
I'll add a get_noresume call prior to checking runtime_suspended, and then adding a put_autosuspend at the end of the set_orientation call. If the suspended check fails, we can put_noidle here. This would cover not programming vbus_valid when unnecessary, and addressing any race condition if the runtime count drops to zero during the locked section.
Quoted 20 lines
[Severity: High]
Can this lead to redundant TCA programming and a 2.5-second timeout?Looking at
google_usb_set_orientation(),gphy->orientationis updated before the mutex is acquired:google_usb_set_orientation() { gphy->orientation = orientation; if (pm_runtime_suspended(gphy->dev)) return 0; guard(mutex)(&gphy->phy_mutex); ...If a Type-C plug event (Thread A) sets
gphy->orientationbut is preempted before taking the lock, and the USB core concurrently callsgoogle_usb3_phy_power_on()(Thread B), Thread B will see the new orientation, program the TCA, and release the lock.
Quoted 6 lines
When Thread A resumes, it will acquire the mutex, see
COMBO_PHY_TCA_READY, and callprogram_tca_locked()a second time with the identical configuration. Since writing the same configuration to the TCA hardware doesn't trigger a newXA_ACT_EVTinterrupt,wait_tca_xa_ack()will stall for its full timeout.Should the orientation update be moved inside the lock?
It should be moved inside the lock, but because if the orientation is set to none, there can be a race condition where power_on passes the orientation check and then proceeds to program the TCA when the orientation is none. Setting the valid bit on the TCA_TCPC register starts a new XA_ACT_EVT interrupt, so the stall here isn't possible.
Best,
RD