Skip to contentSkip to conversation

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

PATCH Superseded RD Babiera 2 participants 3 messages Jul 10 – Sep 8

Subsystems (3)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

RD Babiera

author
#0 lore raw

PATCH v6 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 now calls pm_runtime_get_if_active to guarantee register access. Setting orientation and pm_runtime management are now handled within 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.

Changes since v5:
* google_usb_set_orientation replaces pm_runtime_suspended check with pm_runtime_get_if_active call.

---
 drivers/phy/Kconfig          |   2 +-
 drivers/phy/phy-google-usb.c | 422 +++++++++++++++++++++++++++++++----
 2 files changed, 381 insertions(+), 43 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 +380 -42

526 lines not on this page · raw message

base-commit: 2ace2e949979b82f82f12dd76d7c5a6145246ca3

Signature · 1 line
2.55.0.795.g602f6c329a-goog
#1 lore raw

Hi RD, some minor comments below.

drivers/phy/phy-google-usb.c line 62

Quoted 2 lines · RD Babiera
drivers/phy/phy-google-usb.c +2 -0
+#define GPHY_TCA_DELAY_US 10
+#define GPHY_TCA_TIMEOUT_US 2500000

Do we really need a 2.5s timeout?

...

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

Quoted 11 lines
drivers/phy/phy-google-usb.c +11 -0
+
+static int wait_tca_xa_ack(struct google_usb_phy *gphy)
+{
+	int ret;
+	u32 reg;
+
+	ret = readl_poll_timeout(gphy->usb3_tca_base + TCA_INTR_STS_OFFSET,
+				 reg, !!(reg & TCA_INTR_STS_XA_ACT_EVT),
+				 GPHY_TCA_DELAY_US, GPHY_TCA_TIMEOUT_US);
+	if (ret)
+		dev_err(gphy->dev, "tca xa_ack timeout, ret=%d", ret);

The dev_* calls throughout this patch should have trailing newline characters.

Quoted 3 lines
drivers/phy/phy-google-usb.c +3 -0
+
+	return ret;
+}

...

Quoted 18 lines

static int google_usb_set_orientation(struct typec_switch_dev *sw,

drivers/phy/phy-google-usb.c +5 -4
 				      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);
 
-	gphy->orientation = orientation;
+	guard(mutex)(&gphy->phy_mutex);
 
-	if (pm_runtime_suspended(gphy->dev))
-		return 0;
+	gphy->orientation = orientation;
 
-	guard(mutex)(&gphy->phy_mutex);
+	if (IS_ENABLED(CONFIG_PM)) {
+		if (pm_runtime_get_if_active(gphy->dev) <= 0)

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

Quoted 10 lines
drivers/phy/phy-google-usb.c +6 -1
+			return 0;
+	}
 
 	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);

Here you are using the _autosuspend variant, but autosuspend is never configured in probe(). Should this be changed to the plain pm_runtime_put(), or actually enable autosuspend in the probe function?

Quoted 3 lines
drivers/phy/phy-google-usb.c +2 -0
+
+	return ret;
 }

...

drivers/phy/phy-google-usb.c static const struct phy_ops google_usb2_phy_ops = { · line 433

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) {

I think prior to this we should add a check if phy_state is COMBO_PHY_IDLE, return an error and change this check to phy_state == COMBO_PHY_INIT_DONE to make sure we are explicit in our state handling to prevent issues with any potential refactoring.

Quoted 4 lines
drivers/phy/phy-google-usb.c +4 -0
+		/* Wait for PoR -> NC transitions*/
+		ret = wait_tca_xa_ack(gphy);
+		if (ret) {
+			dev_err(gphy->dev, "PoR->NC transition timeout");

drivers/phy/phy-google-usb.c static const struct phy_ops google_usb2_phy_ops = { · line 447

Quoted 10 lines
drivers/phy/phy-google-usb.c +10 -0
+			return ret;
+		}
+		gphy->phy_state = COMBO_PHY_TCA_READY;
+	}
+
+	if (gphy->orientation != TYPEC_ORIENTATION_NONE)
+		return program_tca_locked(gphy);
+
+	return 0;
+}

...

Thanks,
Neill

author
#2 lore raw

Hi Neill, thanks for taking a look. Sorry for the delay here, the feedback arrived right before I had left for vacation so I wanted to make sure I had proper time to look at it:

Quoted 1 line · Neill Kapron

Do we really need a 2.5s timeout?

2.5s is actually the hardware default for this transaction, which I agree is unnecessarily long—I set it here for correctness. We use software polling instead of the hardware interrupt, and in the product's lifetime 100ms is more than enough time for the ACK signal to arrive. I'll update the next patch version to use this value. I'll also program TCA_CTRLSYNCMODE_CFG1.xa_timeout_val to match the SW
poll timeout so we don't let the operation hang on the PHY when SW finishes its poll.

Quoted 2 lines

The dev_* calls throughout this patch should have trailing newline characters.

Thanks for the heads-up, I will add them.

Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+     pm_runtime_put_autosuspend(gphy->dev);

Here you are using the _autosuspend variant, but autosuspend is never configured in probe(). Should this be changed to the plain pm_runtime_put(), or actually enable autosuspend in the probe function?

Quoted 3 lines
drivers/phy/phy-google-usb.c +2 -0
+
+     return ret;
 }

That's fair, I'll commit to pm_runtime_put() here given we don't implement suspend/resume on the PHY itself.

Quoted 4 lines

I think prior to this we should add a check if phy_state is COMBO_PHY_IDLE, return an error and change this check to phy_state == COMBO_PHY_INIT_DONE to make sure we are explicit in our state handling to prevent issues with any potential refactoring.

Makes sense to me, this will also allow power_on to only run once in the PHY init/exit lifetime as well.

Best,
RD