Skip to contentSkip to conversation

phy: Add USB3 PHY support to Google Tensor SoC USB PHY driver

PATCH Superseded RD Babiera 2 participants 2 messages Jul 9

Subsystems (3)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

RD Babiera

author
#0 lore raw

PATCH v5 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. google_usb_set_orientation can reprogram the TCA when the PHY is ready.

google_usb_set_orientation also checks pm_runtime_suspended and sets gphy->orientation while holding phy_mutex.

---
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.

Changes since v4:
* google_usb_set_orientation sets gphy->orientation while holding phy_mutex.
* google_usb_set_orientation now holds a pm_runtime reference before checking for suspend, and calls put_autosuspend prior to normal exit.

---
 drivers/phy/Kconfig          |   2 +-
 drivers/phy/phy-google-usb.c | 422 +++++++++++++++++++++++++++++++----
 2 files changed, 382 insertions(+), 42 deletions(-)
drivers/phy/Kconfig +1 -1
index 19f3b7d12b7d..d2d401129af7 100644
@@ -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 +381 -41

527 lines not on this page · raw message

base-commit: 2ace2e949979b82f82f12dd76d7c5a6145246ca3

Signature · 1 line
2.55.0.795.g602f6c329a-goog
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Race condition in `google_usb_set_orientation` due to an unsafe Runtime PM state check. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Race condition in google_usb_set_orientation due to an unsafe Runtime PM state check. --

--- Patch [1]: [PATCH v5] phy: Add USB3 PHY support to Google Tensor SoC USB PHY driver --- commit 52452ad1a696ea08726cabf09141d6fdf6a5b7a9
Author: RD Babiera <[email protected]>

phy: Add USB3 PHY support to Google Tensor SoC USB PHY driver

This commit adds USB SuperSpeed support to the Google Tensor G5 USB PHY driver. It implements USB3 phy_ops, refactors the probe sequence, and modifies google_usb_set_orientation() to reprogram the TCA when the PHY is ready while holding a pm_runtime reference.

Quoted 4 lines
drivers/phy/phy-google-usb.c +0 -0
index ab20bc20f19ea..60581ce815b27 100644

[ ... ]

Quoted 12 lines
drivers/phy/phy-google-usb.c +3 -0
@@ -46,53 +77,201 @@ struct google_usb_phy_instance {
 static int google_usb_set_orientation(struct typec_switch_dev *sw,
 				      enum typec_orientation orientation)
 {
 	struct google_usb_phy *gphy = typec_switch_get_drvdata(sw);
+	int ret = 0;
 
 	dev_dbg(gphy->dev, "set orientation %d\n", orientation);
 
+	guard(mutex)(&gphy->phy_mutex);
+
 	gphy->orientation = orientation;

drivers/phy/phy-google-usb.c struct google_usb_phy_instance { · line 94

Quoted 10 lines
drivers/phy/phy-google-usb.c +5 -3
 
-	if (pm_runtime_suspended(gphy->dev))
-		return 0;
+	pm_runtime_get_noresume(gphy->dev);
 
-	guard(mutex)(&gphy->phy_mutex);
+	if (pm_runtime_suspended(gphy->dev)) {
+		pm_runtime_put_noidle(gphy->dev);
+		return 0;
+	}

[Severity: High]
Can this result in a race condition during device suspend?

pm_runtime_get_noresume() increments the usage counter but doesn't check if a suspend is already in progress. If the device status is currently RPM_SUSPENDING, pm_runtime_suspended() will return false.

This would allow the driver to proceed to access hardware via set_vbus_valid() and program_tca_locked() concurrently with the suspend callback disabling clocks and power domains. On ARM platforms, this typically triggers an asynchronous external abort or kernel panic.

Would it be safer to use pm_runtime_get_if_active(gphy->dev) <= 0 instead, which atomically increments the counter only if the device is fully active?

Quoted 11 lines
drivers/phy/phy-google-usb.c +6 -1
 	set_vbus_valid(gphy);
 
-	return 0;
+	if (gphy->phy_state == COMBO_PHY_TCA_READY && orientation != TYPEC_ORIENTATION_NONE)
+		ret = program_tca_locked(gphy);
+
+	pm_runtime_put_autosuspend(gphy->dev);
+
+	return ret;
 }
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