Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC DNM PATCH 00/15] Qualcomm USB4 host router
@ 2026-11-24 20:01 Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 01/15] phy: qualcomm: qmp-combo: Add Glymur USB4v1 PHY sequences Konrad Dybcio
                   ` (14 more replies)
  0 siblings, 15 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio, Wesley Cheng

This is an early RFC, mostly looking for acks/naks regarding the
bespoke power state machine and Type-C handling in qcom.c. This version
of the driver can power up the hardware, have it suspend/resume, but
notably not drive any tunnels (as that depends on dozens of patches to
other subsystems, many with shaky dependencies on the still-forming
usb4 dt-bindings [1]). Absolutely not intended for merging (unless you
want to take some of the intermediate tbt patches, Mika).
Speaking of dt-bindings, this posting comes with none, as it makes no
sense to waste maintainer time until that GitHub discussion is settled.

Said state machine is an attempt to tame the delicate clock setup,
which if we don't get perfectly right results in the machine hard-
crashing. More on that in the big comment at the top of the driver.

The Qualcomm USB4 host router is an in-house design, implementing a
standard NHI front-end with a lot of vendor glue. Because the USB, PCIe
and DP blocks live outside the subsystem (and are wholly disjoint), a
lot of elbow grease it required to have it all behave (similarly to the
Apple implementation, but with more manual clock control and firmware
handshakes). Native protocol controllers can only resume after the
router has re-enabled the links (which collides with today's notion of
nhi_resume re-enabling the tunnels), so that requires some
consideration (again, not included in this posting).

USB3 tunneling requires:
 * a bit in TCSR (tldr a syscon) to be toggled and the path to be
   enabled
 * a register set in DWC3 to work around an issue with the USB3 adapter
This is a fairly low-hanging fruit, but still depends on the bindings
to get the device link changes in within the USB subsystem.

PCIe tunneling requires:
 * a reset in the USB4 address space to be asserted
 * a number of additional settings on the RC side
 * standard PCIe hotplug otherwise works as expected
The link itself works without much effort. How we set up devlinks and
whether we can go forward with or dispose of the router's power state
machine will shape the suspend/resume handling there though.

DP tunneling requires:
 * handling a secondary mailbox within the USB4 subsystem (not
   included)
 * setting up the display crossbar/mux correctly (any of each routers'
   DP adapters can be muxed to any of the available DPTXes)
 * settings a couple registers in the DPTX
 * driving a secondary AUX bus from within USB4SS (the AUX controller
   in the DPTX is blissfully unaware about the existence of USB4, so
   the OS has to ping-pong between them at runtime..)
 * HPD management
Because of the muxing and runtime AUX switching, this requires
sizeable DRM changes, including Luca Ceresoli's work on bridge hotplug.

Additionally, the hardware is constructed such that the protocol
adapters need some of the native controllers' clocks and power domains
to be online, hence the odd DT references.

The uC doesn't implement a CM, it instead does some housekeeping
functions, but because it doesn't have a view directly into the SoC's
register space, it still requires a lot of OS coordination. It does
however take care of link establishment and some of the TBT-layer
chores (such as sending PERST# packets to PCIe adapters). It requires
loadable firmware which will be posted to linux-firmware soon.

This series runs as-is on a Glymur CRD board, minding its limited
usefulness given all of the above.

I know this series is not the entire feature set and that this was
promised quite some time ago now, but as I was humbled to learn,
sending 80G over a wire is no easy feat. I'm looking forward to
removing the remaining roadblocks and hopefully getting there in the
upcoming year. Please chime into the bindings discussion on GitHub if
you want to help there.

Dependencies:
 * https://lore.kernel.org/linux-arm-msm/20260409-topic-phy_fastclk-v1-1-6b4aaee56b90@oss.qualcomm.com/
 * https://lore.kernel.org/linux-arm-msm/20260928-topic-usb4phy-v6-1-815a73b063ef@oss.qualcomm.com/
 * https://lore.kernel.org/linux-arm-msm/20261123-topic-usb4_clks-v1-0-531ab5635c03@oss.qualcomm.com/
 * https://lore.kernel.org/linux-arm-msm/20261117-topic-pga_nousb4_glymur-v1-1-0ede74e620d0@oss.qualcomm.com/

The base commit (contrary to what b4 says, because of said
dependencies) is next-20261116.

[1] https://github.com/devicetree-org/dt-schema/pull/196

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
Konrad Dybcio (13):
      phy: qualcomm: qmp-combo: Add USB4 power_on/off to de/assert USB4 clamps
      soc: qcom: smem: Add and export qcom_smem_get_serial_no()
      clk: qcom: gcc-glymur: Don't poll the status bit of some USB4 clocks
      thunderbolt: nhi: Clear ring interrupts when not using MSI-X
      thunderbolt: nhi: Process ring completions in the threaded IRQ
      thunderbolt: nhi: Add pre_switch_suspend hook
      thunderbolt: nhi: Resume the domain if the NHI suspend op fails
      thunderbolt: nhi: Resume a runtime suspended NHI for system suspend
      thunderbolt: Raise TB_TIMEOUT to 500 ms
      [HACK] thunderbolt: Refuse to activate DP/USB3/PCIe tunnels
      thunderbolt: Introduce Qualcomm USB4 router driver
      arm64: dts: qcom: glymur: Add USB4 topology
      arm64: dts: qcom: glymur-crd: Enable the tertiary Type-C

Wesley Cheng (2):
      phy: qualcomm: qmp-combo: Add Glymur USB4v1 PHY sequences
      soc: qcom: pmic_glink_altmode: Enable TBT/USB4 negotiation

 arch/arm64/boot/dts/qcom/glymur-crd.dtsi         |  107 +-
 arch/arm64/boot/dts/qcom/glymur.dtsi             |  703 ++++++-
 drivers/clk/qcom/gcc-glymur.c                    |   12 +-
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c        |  321 ++-
 drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h    |    1 +
 drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h |   22 +
 drivers/soc/qcom/pmic_glink_altmode.c            |    5 +-
 drivers/soc/qcom/smem.c                          |   22 +
 drivers/thunderbolt/Kconfig                      |   13 +
 drivers/thunderbolt/Makefile                     |    3 +
 drivers/thunderbolt/eeprom.c                     |   17 -
 drivers/thunderbolt/nhi.c                        |  168 +-
 drivers/thunderbolt/nhi.h                        |    4 +-
 drivers/thunderbolt/pci.c                        |   15 +-
 drivers/thunderbolt/qcom.c                       | 2299 ++++++++++++++++++++++
 drivers/thunderbolt/qcom.h                       |  251 +++
 drivers/thunderbolt/switch.c                     |    4 +
 drivers/thunderbolt/tb.c                         |    2 +-
 drivers/thunderbolt/tb.h                         |   20 +
 drivers/thunderbolt/tb_regs.h                    |    3 +
 drivers/thunderbolt/tunnel.c                     |    2 +
 include/linux/soc/qcom/smem.h                    |    1 +
 include/linux/thunderbolt.h                      |    8 +-
 23 files changed, 3914 insertions(+), 89 deletions(-)
---
base-commit: 516d5c8f674bc07eb35c3b97fc21e79e41158dee
change-id: 20261124-topic-next-20261116-fsm-mvp-b936003bd2f2

Best regards,
-- 
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 01/15] phy: qualcomm: qmp-combo: Add Glymur USB4v1 PHY sequences
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 02/15] phy: qualcomm: qmp-combo: Add USB4 power_on/off to de/assert USB4 clamps Konrad Dybcio
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio, Wesley Cheng

From: Wesley Cheng <wesley.cheng@oss.qualcomm.com>

Introduce the programming sequences for Glymur, based on the V1.00
Hardware Settings Reference release for Glymur_R2.

Signed-off-by: Wesley Cheng <wesley.cheng@oss.qualcomm.com>
[konrad: tiny fixups, c0pll reset]
Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c        | 297 ++++++++++++++++++++++-
 drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h    |   1 +
 drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h |  22 ++
 3 files changed, 315 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
index a29f5296e900fbaf534c5de499559a768c42a33c..03fe66dae8b86837fddcc59956529ae374c1f6de 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
@@ -119,6 +119,7 @@ enum qphy_reg_layout {
 
 	QPHY_AON_TOGGLE_ENABLE,
 	QPHY_DP_AON_TOGGLE_ENABLE,
+	QPHY_USB4_AON_TOGGLE_ENABLE,
 	/* Keep last to ensure regs_layout arrays are properly initialized */
 	QPHY_LAYOUT_SIZE
 };
@@ -323,8 +324,10 @@ static const unsigned int qmp_v8_n3_usb43dpphy_regs_layout[QPHY_LAYOUT_SIZE] = {
 	[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR]	= QPHY_V8_PCS_USB_LFPS_RXTERM_IRQ_CLEAR,
 
 	[QPHY_PCS_CLAMP_ENABLE]			= QPHY_V8_PCS_AON_USB3_AON_CLAMP_ENABLE,
+	[QPHY_PCS_USB4_CLAMP_ENABLE]		= QPHY_V8_PCS_AON_USB4_AON_CLAMP_ENABLE,
 	[QPHY_AON_TOGGLE_ENABLE]		= QPHY_V8_PCS_AON_USB3_AON_TOGGLE_ENABLE,
 	[QPHY_DP_AON_TOGGLE_ENABLE]		= QPHY_V8_PCS_AON_DP_AON_TOGGLE_ENABLE,
+	[QPHY_USB4_AON_TOGGLE_ENABLE]		= QPHY_V8_PCS_AON_USB4_AON_TOGGLE_ENABLE,
 
 	[QPHY_COM_RESETSM_CNTRL]		= QSERDES_V8_COM_RESETSM_CNTRL,
 	[QPHY_COM_C_READY_STATUS]		= QSERDES_V8_COM_C_READY_STATUS,
@@ -2513,6 +2516,245 @@ static const struct qmp_phy_init_tbl hawi_usb3_pcs_usb_tbl[] = {
 	QMP_PHY_INIT_CFG(QPHY_V10_PCS_USB3_RCVR_DTCT_DLY_U3_L, 0x40),
 	QMP_PHY_INIT_CFG(QPHY_V10_PCS_USB3_RCVR_DTCT_DLY_U3_H, 0x00),
 };
+static const struct qmp_phy_init_tbl glymur_usb4_serdes_tbl[] = {
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SSC_STEP_SIZE1_MODE1, 0xcc),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SSC_STEP_SIZE2_MODE1, 0x01),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CLK_EP_DIV_MODE1, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CP_CTRL_MODE1, 0x06),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_PLL_RCTRL_MODE1, 0x16),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_PLL_CCTRL_MODE1, 0x36),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CORECLK_DIV_MODE1, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_LOCK_CMP1_MODE1, 0x24),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_LOCK_CMP2_MODE1, 0x43),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DEC_START_MODE1, 0x43),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DEC_START_MSB_MODE1, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DIV_FRAC_START1_MODE1, 0xab),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DIV_FRAC_START2_MODE1, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DIV_FRAC_START3_MODE1, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_HSCLK_SEL_1, 0x11),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_INTEGLOOP_GAIN0_MODE1, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_TUNE1_MODE1, 0x0f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_TUNE2_MODE1, 0x03),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_BIN_VCOCAL_CMP_CODE1_MODE1, 0x8c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_BIN_VCOCAL_CMP_CODE2_MODE1, 0x1f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_BIN_VCOCAL_CMP_CODE1_MODE0, 0x96),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_BIN_VCOCAL_CMP_CODE2_MODE0, 0x1e),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SSC_STEP_SIZE1_MODE0, 0x9c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SSC_STEP_SIZE2_MODE0, 0x01),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CLK_EP_DIV_MODE0, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CP_CTRL_MODE0, 0x06),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_PLL_RCTRL_MODE0, 0x16),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_PLL_CCTRL_MODE0, 0x36),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CORECLK_DIV_MODE0, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_LOCK_CMP1_MODE0, 0x1a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_LOCK_CMP2_MODE0, 0x41),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DEC_START_MODE0, 0x41),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DEC_START_MSB_MODE0, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DIV_FRAC_START1_MODE0, 0x55),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DIV_FRAC_START2_MODE0, 0x75),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DIV_FRAC_START3_MODE0, 0x01),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_HSCLK_HS_SWITCH_SEL_1, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_INTEGLOOP_GAIN0_MODE0, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_TUNE1_MODE0, 0x4d),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_TUNE2_MODE0, 0x03),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_BG_TIMER, 0x0a),
+
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SSC_EN_CENTER, 0x01),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SSC_PER1, 0x76),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SSC_PER2, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_POST_DIV_MUX, 0x60),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CLK_ENABLE1, 0x10),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SYS_CLK_CTRL, 0x82),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SYSCLK_BUF_ENABLE, 0x0a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_PLL_IVCO, 0x7f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_PLL_IVCO_MODE1, 0x7f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CMN_IETRIM, 0x0a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CMN_IPTRIM, 0x20),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SYSCLK_EN_SEL, 0x1a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_LOCK_CMP_EN, 0x04),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_LOCK_CMP_CFG, 0x04),
+
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_TUNE_CTRL, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_TUNE_MAP, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CORE_CLK_EN, 0xf0),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CMN_CONFIG_1, 0xf6),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SVS_MODE_CLK_SEL, 0x2a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CMN_MISC1, 0x88),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CMN_MODE, 0x05),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_DC_LEVEL_CTRL, 0x07),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_ADDITIONAL_MISC_2, 0x0f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_PLL_SPARE_FOR_ECO, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DCC_CAL_1, 0x40),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DCC_CAL_2, 0x03),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DCC_CAL_3, 0x60),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DCC_CAL_7, 0x20),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_DCC_CAL_9, 0x20),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_PSM_CAL_EN, 0x25),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_CLK_FWD_CONFIG_1, 0x33),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_IP_CTRL_AND_DP_SEL, 0xaf),
+};
+
+static const struct qmp_phy_init_tbl glymur_tb3_serdes_tbl[] = {
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_SSC_PER1, 0x46),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_TUNE_CTRL, 0x40),
+	QMP_PHY_INIT_CFG(QSERDES_V8_USB43_COM_VCO_TUNE_MAP, 0x54),
+};
+
+static const struct qmp_phy_init_tbl glymur_usb4_pcs_tbl[] = {
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_POWER_STATE_CONFIG3, 0xcf),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_POWER_STATE_CONFIG4, 0x0f),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G23_LOCK_DETECT_CONFIG1, 0x03),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G23_LOCK_DETECT_CONFIG2, 0xc1),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G2_TXMGN_MAIN_RS, 0x51),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G3_TXMGN_MAIN_RS, 0x51),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_RX_SIGDET_LVL, 0x55),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_EQ_CONFIG1, 0x36),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G3_EQ_CONFIG1, 0x4b),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G3_EQ_CONFIG5, 0x00),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G3_EQ_CONFIG6, 0x28),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG1, 0x83),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG2, 0xdb),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG3, 0x26),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG5, 0x18),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG1, 0x83),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG3, 0x2a),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG5, 0x18),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_LFPS_TX_ECSTART, 0x0f),
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_MBUS_CONFIG1, 0xff),
+};
+
+static const struct qmp_phy_init_tbl glymur_usb4_lalb_tbl[] = {
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CLKBUF_ENABLE, 0x85),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_TX_LVL_UPDATE_CTRL, 0x0d),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_PCIE5_TOP_LDO_CODE_CTRL1, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_PCIE5_TOP_LDO_CODE_CTRL2, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_PCIE5_TOP_LDO_CODE_CTRL3, 0x80),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_PCIE5_TOP_LDO_CODE_CTRL4, 0x8e),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_LANE_MODE_1, 0x0c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_LANE_MODE_2, 0x40),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_LANE_MODE_3, 0x41),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_LANE_MODE_4, 0x01),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_TX0_RESTRIM_CAL_CTRL, 0x20),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_TX0_RESTRIM_POST_CAL_OFFSET, 0x10),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_TX1_RESTRIM_CAL_CTRL, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_TX0_RESTRIM_VREF_SEL, 0x13),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_TX1_RESTRIM_VREF_SEL, 0x09),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_ANA_INTERFACE_SELECT2, 0x1c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_PCS_INTERFACE_SELECT1, 0x50),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_LDO_TIMER_CTRL, 0x11),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE2_B0, 0x1c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE2_B1, 0x93),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE2_B2, 0x7c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE2_B3, 0x64),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE2_B4, 0x04),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE2_B5, 0x57),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE2_B6, 0x12),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE2_B7, 0x1a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE3_B0, 0xce),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE3_B1, 0xc4),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE3_B2, 0xce),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE3_B3, 0x60),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE3_B4, 0x04),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE3_B5, 0x24),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE3_B6, 0x5b),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_MODE_RATE3_B7, 0x1b),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_TX_DCC_ANA_CTRL2, 0x0c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CMUX_DCC_POSTCAL_OFFSET, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT1_RATE2, 0x26),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT2_RATE2, 0x26),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT1_RATE3, 0x26),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT2_RATE3, 0x26),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCTRL_RATE_2_3, 0x33),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KVCO_INIT_RATE_2_3, 0x11),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KVCO_CAL_VCTRL_LOW_RATE_2_3, 0x32),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KVCO_CODE_OVRD_RATE2, 0x03),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KVCO_IDEAL_FREQ_DIFF1_RATE2, 0x19),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KVCO_IDEAL_FREQ_DIFF2_RATE2, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KVCO_IDEAL_FREQ_DIFF1_RATE3, 0x14),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KVCO_IDEAL_FREQ_DIFF2_RATE3, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KP_CODE_OVRD_RATE_2_3, 0x22),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KP_CAL_UPPER_FREQ_DIFF_BND1_RATE2, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KP_CAL_UPPER_FREQ_DIFF_BND2_RATE2, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KP_CAL_UPPER_FREQ_DIFF_BND1_RATE3, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KP_CAL_UPPER_FREQ_DIFF_BND2_RATE3, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KP_CAL_LOWER_FREQ_DIFF_BND_RATE2, 0x0a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_KP_CAL_LOWER_FREQ_DIFF_BND_RATE3, 0x10),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_SUMMER_CAL_SPD_MODE_RATE_0123, 0x2f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_IVCM_CAL_CODE_OVERRIDE_RATE2, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_IVCM_CAL_CODE_OVERRIDE_RATE3, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_IVCM_CAL_CTRL2, 0x85),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_IVCM_CAL_CTRL3, 0x55),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_IVCM_POSTCAL_OFFSET_RATE2, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_IVCM_POSTCAL_OFFSET_RATE3, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_SIGDET_ENABLES, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_SIGDET_CNTRL, 0xa3),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_SIGDET_LVL, 0x04),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_SIGDET_DEGLITCH_CNTRL, 0x0e),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_SIGDET_CAL_CTRL1, 0x14),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_SIGDET_CAL_CTRL2_AND_CDR_LOCK_EDGE, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_SIGDET_CAL_TRIM, 0x66),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_FREQ_LOCK_DET_DLY_RATE2, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_FREQ_LOCK_DET_DLY_RATE3, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_CP_CUR_FLL_RATE2, 0x0a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_CP_CUR_FLL_RATE3, 0x0a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_CP_CUR_PLL_RATE2, 0x04),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_CP_CUR_PLL_RATE3, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_FLL_DIV_RATIO_RATE_0123, 0xe5),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_LOOP_CCODE_RATE_23, 0x55),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_LOOP_RCODE_FAST_RATE_2_3, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_LOOP_RCODE_FLL_RATE_2_3, 0x43),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_LOOP_RCODE_PLL_RATE_2_3, 0x51),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CAP_CODE_RATE_0123, 0xff),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_TYPE_CONFIG, 0x17),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_EN_LOWFREQ, 0x1f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_LOOP_FUNC_CTRL, 0xd0),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_FAST_LOCK_EN_CTRL, 0x08),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_RCVR_EN, 0x09),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_GM_CAL_EN, 0x1f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_GM_CAL_RES_RATE2_3, 0xc8),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_EOM_CTRL1, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_EOM_CTRL2, 0x18),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_EOM_CTRL3, 0x28),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_EQ_OFFSET_ADAPTOR_CNTRL1, 0x44),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_OFFSET_ADAPTOR_CNTRL3, 0x68),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_EQU_ADAPTOR_CNTRL2, 0x0a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_EQU_ADAPTOR_CNTRL3, 0x0a),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_RX_EQU_ADAPTOR_CNTRL4, 0xaa),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CTLE_POST_CAL_OFFSET_RATE_0_1_2, 0x77),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CTLE_POST_CAL_OFFSET_RATE_3_4, 0x77),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_VGA_CAL_CNTRL1, 0x00),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_VGA_CAL_MAN_VAL_RATE2_3, 0x2c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_VTHRESH_CAL_MAN_VAL_RATE3, 0x78),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP3_CTRL, 0x06),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP3_MANVAL_KTAP, 0x06),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP4_CTRL, 0x06),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP4_MANVAL_KTAP, 0x06),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP5_CTRL, 0x06),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP5_MANVAL_KTAP, 0x06),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP1_DAC_ENABLE, 0x1c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP2_DAC_ENABLE, 0x1c),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP345_DAC_ENABLE, 0x18),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DFE_TAP67_DAC_ENABLE, 0x10),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_IQTUNE_CTRL, 0x58),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_IQTUNE_MAN_INDEX, 0x12), /* TODO: 0x11 for Mahua */
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_IQTUNE_DIV2_CTRL_RATE0123, 0x10),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CAP_CODE_OVRD_MUXES, 0x1f),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_LOCK_KP_OFFSET_RATE3, 0x20),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_FASTLOCK_CP_CUR_PLL_RATE3, 0x02),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_DIG_BKUP_CTRL16, 0x77),
+};
+
+static const struct qmp_phy_init_tbl glymur_tb3_pcs_tbl[] = {
+	QMP_PHY_INIT_CFG(QPHY_V8_USB4_PCS_POWER_STATE_CONFIG4, 0x1f),
+};
+
+static const struct qmp_phy_init_tbl glymur_tb3_lalb_tbl[] = {
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT1_RATE2, 0x57),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT2_RATE2, 0x27),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT1_RATE3, 0x57),
+	QMP_PHY_INIT_CFG(QSERDES_V8_LALB_CDR_VCO_CTUNE_MEAS_CNT2_RATE3, 0x27),
+};
+
 
 static const struct qmp_phy_init_tbl nord_usb3_tx_tbl[] = {
 	QMP_PHY_INIT_CFG(QSERDES_V6_TX_RES_CODE_LANE_TX, 0x00),
@@ -2729,6 +2971,12 @@ struct qmp_phy_cfg {
 	int usb4_rx_tbl_num;
 	const struct qmp_phy_init_tbl *usb4_pcs_tbl;
 	int usb4_pcs_tbl_num;
+	const struct qmp_phy_init_tbl *usb4_pcs_tb3_ovrd_tbl;
+	int usb4_pcs_tb3_ovrd_num;
+	const struct qmp_phy_init_tbl *usb4_tx_tb3_ovrd_tbl;
+	int usb4_tx_tb3_ovrd_num;
+	/* true, if the C0 PLL needs to be reset on PHY mode changes */
+	bool usb4_c0_pll_reset;
 
 	/* resets to be requested */
 	const char * const *reset_list;
@@ -2948,6 +3196,8 @@ static const struct qmp_combo_offsets qmp_combo_usb43dp_offsets_v8 = {
 	.dp_dp_phy	= 0x2400,
 	.txa		= 0x4000,
 	.txb		= 0x5000,
+	.usb4_serdes	= 0x3000,
+	.usb4_pcs	= 0x3800,
 };
 
 static const struct qmp_phy_cfg sar2130p_usb3dpphy_cfg = {
@@ -3612,6 +3862,20 @@ static const struct qmp_phy_cfg glymur_usb3dpphy_cfg = {
 	.configure_dp_clocks	= qmp_v8_configure_dp_clocks,
 	.configure_dp_phy	= qmp_v8_configure_dp_phy,
 
+	.usb4_serdes_tbl	= glymur_usb4_serdes_tbl,
+	.usb4_serdes_tbl_num	= ARRAY_SIZE(glymur_usb4_serdes_tbl),
+	.usb4_serdes_tb3_ovrd_tbl = glymur_tb3_serdes_tbl,
+	.usb4_serdes_tb3_ovrd_num = ARRAY_SIZE(glymur_tb3_serdes_tbl),
+	.usb4_tx_tbl		= glymur_usb4_lalb_tbl,
+	.usb4_tx_tbl_num	= ARRAY_SIZE(glymur_usb4_lalb_tbl),
+	.usb4_pcs_tbl		= glymur_usb4_pcs_tbl,
+	.usb4_pcs_tbl_num	= ARRAY_SIZE(glymur_usb4_pcs_tbl),
+	.usb4_pcs_tb3_ovrd_tbl	= glymur_tb3_pcs_tbl,
+	.usb4_pcs_tb3_ovrd_num	= ARRAY_SIZE(glymur_tb3_pcs_tbl),
+	.usb4_tx_tb3_ovrd_tbl	= glymur_tb3_lalb_tbl,
+	.usb4_tx_tb3_ovrd_num	= ARRAY_SIZE(glymur_tb3_lalb_tbl),
+	.usb4_c0_pll_reset	= true,
+
 	.regs			= qmp_v8_n3_usb43dpphy_regs_layout,
 	.reset_list		= msm8996_usb3phy_reset_l,
 	.num_resets		= ARRAY_SIZE(msm8996_usb3phy_reset_l),
@@ -4273,6 +4537,12 @@ static int qmp_combo_dp_calibrate(struct phy *phy)
 	return ret;
 }
 
+static void qmp_combo_toggle_c0_pll_reset(void __iomem *com)
+{
+	qphy_setbits(com, QPHY_V3_DP_COM_RESET_OVRD_CTRL2, 0x6);
+	qphy_clrbits(com, QPHY_V3_DP_COM_RESET_OVRD_CTRL2, 0x4);
+}
+
 static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)
 {
 	const struct qmp_phy_cfg *cfg = qmp->cfg;
@@ -4340,9 +4610,14 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)
 			SW_USB4PHY_RESET_MUX | SW_USB4PHY_RESET);
 
 	/* override hardware control for reset of qmp phy */
-	if (aon_toggle && cfg->regs[QPHY_AON_TOGGLE_ENABLE]) {
-		qphy_clrbits(aon_toggle, cfg->regs[QPHY_AON_TOGGLE_ENABLE], 0x1);
-		qphy_clrbits(aon_toggle, cfg->regs[QPHY_DP_AON_TOGGLE_ENABLE], 0x1);
+	if (aon_toggle) {
+		if (qmp->qmpphy_mode == QMPPHY_MODE_USB4 &&
+		    cfg->regs[QPHY_USB4_AON_TOGGLE_ENABLE]) {
+			qphy_clrbits(aon_toggle, cfg->regs[QPHY_USB4_AON_TOGGLE_ENABLE], 0x1);
+		} else if (cfg->regs[QPHY_AON_TOGGLE_ENABLE]) {
+			qphy_clrbits(aon_toggle, cfg->regs[QPHY_AON_TOGGLE_ENABLE], 0x1);
+			qphy_clrbits(aon_toggle, cfg->regs[QPHY_DP_AON_TOGGLE_ENABLE], 0x1);
+		}
 	}
 
 	/* Use software based port select and switch on typec orientation */
@@ -4362,6 +4637,8 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)
 	switch (qmp->qmpphy_mode) {
 	case QMPPHY_MODE_USB3DP:
 		writel(USB3_MODE | DP_MODE, com + QPHY_V3_DP_COM_PHY_MODE_CTRL);
+		if (cfg->usb4_c0_pll_reset)
+			qmp_combo_toggle_c0_pll_reset(com);
 
 		/* bring both QMP USB and QMP DP PHYs PCS block out of reset */
 		qphy_clrbits(com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
@@ -4379,6 +4656,8 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)
 
 	case QMPPHY_MODE_USB3_ONLY:
 		writel(USB3_MODE, com + QPHY_V3_DP_COM_PHY_MODE_CTRL);
+		if (cfg->usb4_c0_pll_reset)
+			qmp_combo_toggle_c0_pll_reset(com);
 
 		/* bring QMP USB PHY PCS block out of reset */
 		qphy_clrbits(com, QPHY_V3_DP_COM_RESET_OVRD_CTRL,
@@ -4386,6 +4665,8 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)
 		break;
 	case QMPPHY_MODE_USB4:
 		writel(USB4_MODE, com + QPHY_V3_DP_COM_PHY_MODE_CTRL);
+		if (cfg->usb4_c0_pll_reset)
+			qmp_combo_toggle_c0_pll_reset(com);
 
 		/* bring both QMP USB and QMP DP PHYs PCS block out of reset */
 		/*
@@ -4574,10 +4855,16 @@ static int qmp_combo_usb_power_on(struct phy *phy)
 	qmp_configure(qmp->dev, pcs, pcs_tbl, pcs_tbl_num);
 	qmp_configure(qmp->dev, qmp->pcs_misc, cfg->pcs_misc_tbl, cfg->pcs_misc_tbl_num);
 
-	if (qmp->qmpphy_mode == QMPPHY_MODE_USB4 && qmp->usb4_phy_submode == PHY_SUBMODE_TBT3)
+	if (qmp->qmpphy_mode == QMPPHY_MODE_USB4 && qmp->usb4_phy_submode == PHY_SUBMODE_TBT3) {
 		qmp_configure(qmp->dev, serdes, cfg->usb4_serdes_tb3_ovrd_tbl,
 			      cfg->usb4_serdes_tb3_ovrd_num);
-	else if (qmp->qmpphy_mode != QMPPHY_MODE_USB4 && pcs_usb)
+		qmp_configure_lane(qmp->dev, tx, cfg->usb4_tx_tb3_ovrd_tbl,
+				   cfg->usb4_tx_tb3_ovrd_num, 1);
+		qmp_configure_lane(qmp->dev, tx2, cfg->usb4_tx_tb3_ovrd_tbl,
+				   cfg->usb4_tx_tb3_ovrd_num, 2);
+		qmp_configure(qmp->dev, pcs, cfg->usb4_pcs_tb3_ovrd_tbl,
+			      cfg->usb4_pcs_tb3_ovrd_num);
+	} else if (qmp->qmpphy_mode != QMPPHY_MODE_USB4 && pcs_usb)
 		qmp_configure(qmp->dev, pcs_usb, cfg->pcs_usb_tbl,
 			      cfg->pcs_usb_tbl_num);
 
diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h b/drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h
index 396179ef38b0d4f0b7538c0d74b790d61139f9e2..d17571eff23bacb7045b47784930263c9ddd6964 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h
+++ b/drivers/phy/qualcomm/phy-qcom-qmp-dp-com-v3.h
@@ -14,5 +14,6 @@
 #define QPHY_V3_DP_COM_TYPEC_CTRL			0x10
 #define QPHY_V3_DP_COM_TYPEC_PWRDN_CTRL			0x14
 #define QPHY_V3_DP_COM_RESET_OVRD_CTRL			0x1c
+#define QPHY_V3_DP_COM_RESET_OVRD_CTRL2			0x20
 
 #endif
diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h b/drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h
index 4f387c8ed9e55f85ae5c124dfcd20de38454d718..faebfc854066c2d5d47640c9e92fe07fa3c929e4 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h
+++ b/drivers/phy/qualcomm/phy-qcom-qmp-usb43-pcs-v8.h
@@ -30,4 +30,26 @@
 #define QPHY_V8_USB43_PCS_EQ_CONFIG2				0x1e0
 #define QPHY_V8_USB43_PCS_EQ_CONFIG5				0x1ec
 
+/* USB4 PCS registers on QMP v8 PHYs */
+#define QPHY_V8_USB4_PCS_POWER_STATE_CONFIG3			0x0ac
+#define QPHY_V8_USB4_PCS_POWER_STATE_CONFIG4			0x0b0
+#define QPHY_V8_USB4_PCS_G23_LOCK_DETECT_CONFIG1		0x0e4
+#define QPHY_V8_USB4_PCS_G23_LOCK_DETECT_CONFIG2		0x0e8
+#define QPHY_V8_USB4_PCS_G2_TXMGN_MAIN_RS			0x118
+#define QPHY_V8_USB4_PCS_G3_TXMGN_MAIN_RS			0x144
+#define QPHY_V8_USB4_PCS_RX_SIGDET_LVL			0x29c
+#define QPHY_V8_USB4_PCS_EQ_CONFIG1				0x2e0
+#define QPHY_V8_USB4_PCS_G3_EQ_CONFIG1			0x300
+#define QPHY_V8_USB4_PCS_G3_EQ_CONFIG5			0x310
+#define QPHY_V8_USB4_PCS_G3_EQ_CONFIG6			0x314
+#define QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG1			0x340
+#define QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG2			0x344
+#define QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG3			0x348
+#define QPHY_V8_USB4_PCS_G2_FOM_EQ_CONFIG5			0x350
+#define QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG1			0x35c
+#define QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG3			0x364
+#define QPHY_V8_USB4_PCS_G3_FOM_EQ_CONFIG5			0x36c
+#define QPHY_V8_USB4_PCS_LFPS_TX_ECSTART			0x3a0
+#define QPHY_V8_USB4_PCS_MBUS_CONFIG1				0x3a8
+
 #endif

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 02/15] phy: qualcomm: qmp-combo: Add USB4 power_on/off to de/assert USB4 clamps
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 01/15] phy: qualcomm: qmp-combo: Add Glymur USB4v1 PHY sequences Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 03/15] soc: qcom: smem: Add and export qcom_smem_get_serial_no() Konrad Dybcio
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

The USB4 part of the PHY comes with its own clamps, which need to be
asserted during suspend. Use phy_power_on/off to let the router driver
do that.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
index 03fe66dae8b86837fddcc59956529ae374c1f6de..475b9a43baeeeaf18efb6e55d8151c170169c742 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
@@ -5085,6 +5085,28 @@ static int qmp_combo_usb4_exit(struct phy *phy)
 	return 0;
 }
 
+static int qmp_combo_usb4_power_on(struct phy *phy)
+{
+	struct qmp_combo *qmp = phy_get_drvdata(phy);
+
+	guard(mutex)(&qmp->phy_mutex);
+
+	qphy_setbits(qmp->pcs_aon, qmp->cfg->regs[QPHY_PCS_USB4_CLAMP_ENABLE], CLAMP_EN);
+
+	return 0;
+}
+
+static int qmp_combo_usb4_power_off(struct phy *phy)
+{
+	struct qmp_combo *qmp = phy_get_drvdata(phy);
+
+	guard(mutex)(&qmp->phy_mutex);
+
+	qphy_clrbits(qmp->pcs_aon, qmp->cfg->regs[QPHY_PCS_USB4_CLAMP_ENABLE], CLAMP_EN);
+
+	return 0;
+}
+
 static int qmp_combo_usb4_set_mode(struct phy *phy, enum phy_mode mode, int submode)
 {
 	struct qmp_combo *qmp = phy_get_drvdata(phy);
@@ -5110,6 +5132,8 @@ static const struct phy_ops qmp_combo_usb_phy_ops = {
 static const struct phy_ops qmp_combo_usb4_phy_ops = {
 	.init		= qmp_combo_usb4_init,
 	.exit		= qmp_combo_usb4_exit,
+	.power_on	= qmp_combo_usb4_power_on,
+	.power_off	= qmp_combo_usb4_power_off,
 	.set_mode	= qmp_combo_usb4_set_mode,
 	.owner		= THIS_MODULE,
 };

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 03/15] soc: qcom: smem: Add and export qcom_smem_get_serial_no()
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 01/15] phy: qualcomm: qmp-combo: Add Glymur USB4v1 PHY sequences Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 02/15] phy: qualcomm: qmp-combo: Add USB4 power_on/off to de/assert USB4 clamps Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 04/15] soc: qcom: pmic_glink_altmode: Enable TBT/USB4 negotiation Konrad Dybcio
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

The USB4 router expects that the OS programs a silicon-unique value as
part of its initialization flow. The most obvious choice for that is
the part's serial number.

Export a function to get the SN retrieved from SMEM.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/soc/qcom/smem.c       | 22 ++++++++++++++++++++++
 include/linux/soc/qcom/smem.h |  1 +
 2 files changed, 23 insertions(+)

diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index 78b9d8b9229b94524b596c79cd0dbc26f05a8dee..45b39dd34a115fa2654603cc1b547d883e89a1fa 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -912,6 +912,28 @@ int qcom_smem_get_feature_code(u32 *code)
 }
 EXPORT_SYMBOL_GPL(qcom_smem_get_feature_code);
 
+/**
+ * qcom_smem_get_serial_no() - return the unique serial number of the SoC
+ * @id: Pointer to where to store the serial number upon success.
+ *
+ * Look up serial number from HW/SW build ID and return it.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int qcom_smem_get_serial_no(u32 *id)
+{
+	struct socinfo *info;
+
+	info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, NULL);
+	if (IS_ERR(info))
+		return PTR_ERR(info);
+
+	*id = __le32_to_cpu(info->serial_num);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(qcom_smem_get_serial_no);
+
 static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
 {
 	struct smem_header *header;
diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h
index 3249cbd2016b50950842e357ae4d591dc2a1ec55..294b49a629b9a739a457773b041775716ece238d 100644
--- a/include/linux/soc/qcom/smem.h
+++ b/include/linux/soc/qcom/smem.h
@@ -14,6 +14,7 @@ phys_addr_t qcom_smem_virt_to_phys(void *p);
 
 int qcom_smem_get_soc_id(u32 *id);
 int qcom_smem_get_feature_code(u32 *code);
+int qcom_smem_get_serial_no(u32 *id);
 
 int qcom_smem_bust_hwspin_lock_by_host(unsigned int host);
 

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 04/15] soc: qcom: pmic_glink_altmode: Enable TBT/USB4 negotiation
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (2 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 03/15] soc: qcom: smem: Add and export qcom_smem_get_serial_no() Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 05/15] clk: qcom: gcc-glymur: Don't poll the status bit of some USB4 clocks Konrad Dybcio
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio, Wesley Cheng

From: Wesley Cheng <wesley.cheng@oss.qualcomm.com>

Now that USB4 is supported, stop identifying as an installer image and
report the default OS type instead. Newer versions of the Glymur SoCCP
firmware require this argument before they enable USB4 tunneling.

[missing W's s-o-b]
[konrad: commit message]
Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/soc/qcom/pmic_glink_altmode.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/qcom/pmic_glink_altmode.c b/drivers/soc/qcom/pmic_glink_altmode.c
index a8097c54a65559b48f64bfb65a1a4d0d8e033be8..f54d02994eaa96af04c673459b28edd482de37db 100644
--- a/drivers/soc/qcom/pmic_glink_altmode.c
+++ b/drivers/soc/qcom/pmic_glink_altmode.c
@@ -571,10 +571,9 @@ static void pmic_glink_altmode_enable_worker(struct work_struct *work)
 	struct pmic_glink_altmode *altmode = work_to_altmode(work);
 	int ret;
 
-	/* Set OS to installer for now to restrict USB4/TBT negotiation */
 	ret = pmic_glink_altmode_request(altmode, ALTMODE_PAN_EN,
-					 FIELD_PREP(PAN_EN_VERSION, 1) |
-					 FIELD_PREP(PAN_EN_OS_TYPE, PAN_EN_OS_INSTALLER));
+					 FIELD_PREP(PAN_EN_VERSION, 0) |
+					 FIELD_PREP(PAN_EN_OS_TYPE, PAN_EN_OS_DEFAULT));
 	if (ret)
 		dev_err(altmode->dev, "failed to request altmode notifications: %d\n", ret);
 }

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 05/15] clk: qcom: gcc-glymur: Don't poll the status bit of some USB4 clocks
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (3 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 04/15] soc: qcom: pmic_glink_altmode: Enable TBT/USB4 negotiation Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 06/15] thunderbolt: nhi: Clear ring interrupts when not using MSI-X Konrad Dybcio
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

These clocks are PHY-sourced and their halt bits seem not to update
reliably. Ignore it to prevent spurious warnings.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/clk/qcom/gcc-glymur.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/qcom/gcc-glymur.c b/drivers/clk/qcom/gcc-glymur.c
index 186c779e30846fef5fbcf66d114d58389d72efa7..3323792929d9292db0fb28b116723dd054d6deec 100644
--- a/drivers/clk/qcom/gcc-glymur.c
+++ b/drivers/clk/qcom/gcc-glymur.c
@@ -6833,7 +6833,7 @@ static struct clk_branch gcc_usb4_0_phy_pcie_pipe_clk = {
 
 static struct clk_branch gcc_usb4_0_phy_rx0_clk = {
 	.halt_reg = 0x2b0c4,
-	.halt_check = BRANCH_HALT,
+	.halt_check = BRANCH_HALT_SKIP,
 	.clkr = {
 		.enable_reg = 0x2b0c4,
 		.enable_mask = BIT(0),
@@ -6851,7 +6851,7 @@ static struct clk_branch gcc_usb4_0_phy_rx0_clk = {
 
 static struct clk_branch gcc_usb4_0_phy_rx1_clk = {
 	.halt_reg = 0x2b0d8,
-	.halt_check = BRANCH_HALT,
+	.halt_check = BRANCH_HALT_SKIP,
 	.clkr = {
 		.enable_reg = 0x2b0d8,
 		.enable_mask = BIT(0),
@@ -7068,7 +7068,7 @@ static struct clk_branch gcc_usb4_1_phy_pcie_pipe_clk = {
 
 static struct clk_branch gcc_usb4_1_phy_rx0_clk = {
 	.halt_reg = 0x2d0e8,
-	.halt_check = BRANCH_HALT,
+	.halt_check = BRANCH_HALT_SKIP,
 	.clkr = {
 		.enable_reg = 0x2d0e8,
 		.enable_mask = BIT(0),
@@ -7086,7 +7086,7 @@ static struct clk_branch gcc_usb4_1_phy_rx0_clk = {
 
 static struct clk_branch gcc_usb4_1_phy_rx1_clk = {
 	.halt_reg = 0x2d0fc,
-	.halt_check = BRANCH_HALT,
+	.halt_check = BRANCH_HALT_SKIP,
 	.clkr = {
 		.enable_reg = 0x2d0fc,
 		.enable_mask = BIT(0),
@@ -7303,7 +7303,7 @@ static struct clk_branch gcc_usb4_2_phy_pcie_pipe_clk = {
 
 static struct clk_branch gcc_usb4_2_phy_rx0_clk = {
 	.halt_reg = 0xe00c8,
-	.halt_check = BRANCH_HALT,
+	.halt_check = BRANCH_HALT_SKIP,
 	.clkr = {
 		.enable_reg = 0xe00c8,
 		.enable_mask = BIT(0),
@@ -7321,7 +7321,7 @@ static struct clk_branch gcc_usb4_2_phy_rx0_clk = {
 
 static struct clk_branch gcc_usb4_2_phy_rx1_clk = {
 	.halt_reg = 0xe00dc,
-	.halt_check = BRANCH_HALT,
+	.halt_check = BRANCH_HALT_SKIP,
 	.clkr = {
 		.enable_reg = 0xe00dc,
 		.enable_mask = BIT(0),

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 06/15] thunderbolt: nhi: Clear ring interrupts when not using MSI-X
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (4 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 05/15] clk: qcom: gcc-glymur: Don't poll the status bit of some USB4 clocks Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-12-01  7:16   ` Mika Westerberg
  2026-11-24 20:01 ` [PATCH RFC DNM 07/15] thunderbolt: nhi: Process ring completions in the threaded IRQ Konrad Dybcio
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

Commit 468c49f44759 ("thunderbolt: Disable interrupt auto clear for
rings") made the hardware stop clearing the ring interrupt status on
read for all routers except Intel ones, and added an explicit write to
REG_RING_INT_CLEAR to the MSI-X handler. The single-interrupt handler
was not updated though, so for such routers the status bits are never
cleared and the interrupt keeps firing.

Write back the bits that were found set in each notify register to
REG_RING_INT_CLEAR, before handling the rings that they belong to.

Fixes: 468c49f44759 ("thunderbolt: Disable interrupt auto clear for rings")
Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/thunderbolt/nhi.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index f54ab2189cf424d04a9ec48576efe78283a83138..e48521482c021c7f5f73349ce16519d6088d3250 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -1036,13 +1036,20 @@ void nhi_interrupt_work(struct work_struct *work)
 	/*
 	 * Starting at REG_RING_NOTIFY_BASE there are three status bitfields
 	 * (TX, RX, RX overflow). We iterate over the bits and read a new
-	 * dwords as required. The registers are cleared on read.
+	 * dwords as required. The registers are cleared on read, unless
+	 * auto-clear is disabled, in which case the bits that were set have
+	 * to be written back to REG_RING_INT_CLEAR.
 	 */
 	for (bit = 0; bit < 3 * nhi->hop_count; bit++) {
-		if (bit % 32 == 0)
+		if (bit % 32 == 0) {
 			value = ioread32(nhi->iobase
 					 + REG_RING_NOTIFY_BASE
 					 + 4 * (bit / 32));
+			if (!(nhi->quirks & QUIRK_AUTO_CLEAR_INT))
+				iowrite32(value, nhi->iobase
+					  + REG_RING_INT_CLEAR
+					  + 4 * (bit / 32));
+		}
 		if (++hop == nhi->hop_count) {
 			hop = 0;
 			type++;

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 07/15] thunderbolt: nhi: Process ring completions in the threaded IRQ
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (5 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 06/15] thunderbolt: nhi: Clear ring interrupts when not using MSI-X Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-12-01  7:33   ` Mika Westerberg
  2026-11-24 20:01 ` [PATCH RFC DNM 08/15] thunderbolt: nhi: Add pre_switch_suspend hook Konrad Dybcio
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

The Qualcomm USB4 router uses a shared IRQ for all NHI rings.
Scheduling a work item from its threaded handler adds another delay
before completed RX frames are consumed and replacement buffers are
posted.

Process completed descriptors directly from the threaded IRQ instead.
Harvest all completed frames while holding the NHI and ring locks,
replenish RX rings immediately, then invoke frame callbacks after
dropping the locks. Preserve the existing polling-ring path, which must
continue to mask the interrupt and start polling instead.

This removes the workqueue round trip from the common IRQ path without
calling ring consumers under NHI locking. Since the callbacks no longer
run only from ring->work, have tb_ring_stop() and tb_ring_free()
synchronize with the ring interrupt, so they keep returning only after
all callbacks of the ring have finished.

Switch the single MSI fallback of the PCI glue over to the same threaded
handler, which allows dropping nhi_interrupt_work() and the work item
that backed it.

Based on related work by Wesley Cheng.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/thunderbolt/nhi.c   | 133 +++++++++++++++++++++++++++++++++++---------
 drivers/thunderbolt/nhi.h   |   2 +-
 drivers/thunderbolt/pci.c   |  15 ++---
 include/linux/thunderbolt.h |   8 +--
 4 files changed, 115 insertions(+), 43 deletions(-)

diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index e48521482c021c7f5f73349ce16519d6088d3250..bcc2b959e3b1a6b014c13a4938ed6f68cb0d0fd8 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -310,6 +310,41 @@ static void ring_write_descriptors(struct tb_ring *ring, bool notify)
 		__ring_notify(ring);
 }
 
+/*
+ * ring_harvest() - collect completed frames
+ * @ring: Ring to collect the frames from
+ * @done: List to move the completed frames to
+ *
+ * Moves all completed frames from the ring buffer to @done and writes new
+ * frames to the ring buffer.
+ *
+ * ring->lock is held.
+ */
+static void ring_harvest(struct tb_ring *ring, struct list_head *done)
+{
+	struct ring_frame *frame;
+
+	lockdep_assert_held(&ring->lock);
+
+	while (!ring_empty(ring)) {
+		if (!(ring->descriptors[ring->tail].flags
+				& RING_DESC_COMPLETED))
+			break;
+		frame = list_first_entry(&ring->in_flight, typeof(*frame),
+					 list);
+		list_move_tail(&frame->list, done);
+		if (!ring->is_tx) {
+			frame->size = ring->descriptors[ring->tail].length;
+			frame->eof = ring->descriptors[ring->tail].eof;
+			frame->sof = ring->descriptors[ring->tail].sof;
+			frame->flags = ring->descriptors[ring->tail].flags;
+		}
+		frame->ring = ring;
+		ring->tail = (ring->tail + 1) % ring->size;
+	}
+	ring_write_descriptors(ring, true);
+}
+
 /*
  * ring_work() - progress completed frames
  *
@@ -337,22 +372,7 @@ static void ring_work(struct work_struct *work)
 		goto invoke_callback;
 	}
 
-	while (!ring_empty(ring)) {
-		if (!(ring->descriptors[ring->tail].flags
-				& RING_DESC_COMPLETED))
-			break;
-		frame = list_first_entry(&ring->in_flight, typeof(*frame),
-					 list);
-		list_move_tail(&frame->list, &done);
-		if (!ring->is_tx) {
-			frame->size = ring->descriptors[ring->tail].length;
-			frame->eof = ring->descriptors[ring->tail].eof;
-			frame->sof = ring->descriptors[ring->tail].sof;
-			frame->flags = ring->descriptors[ring->tail].flags;
-		}
-		ring->tail = (ring->tail + 1) % ring->size;
-	}
-	ring_write_descriptors(ring, true);
+	ring_harvest(ring, &done);
 
 invoke_callback:
 	/* allow callbacks to schedule new work */
@@ -371,6 +391,35 @@ static void ring_work(struct work_struct *work)
 	wake_up(&ring->wait);
 }
 
+/*
+ * ring_process_completions() - invoke the callbacks of completed frames
+ * @done: Frames collected by ring_harvest(), possibly from several rings
+ *
+ * The frames of each ring are contiguous in @done. Like ring_work(), wake
+ * up the waiters of a ring once the callbacks of all its frames have run.
+ */
+static void ring_process_completions(struct list_head *done)
+{
+	struct ring_frame *frame;
+	struct tb_ring *ring;
+
+	while (!list_empty(done)) {
+		frame = list_first_entry(done, typeof(*frame), list);
+		ring = frame->ring;
+		/*
+		 * The callback may reenqueue or delete frame.
+		 * Do not hold on to it.
+		 */
+		list_del_init(&frame->list);
+		if (frame->callback)
+			frame->callback(ring, frame, false);
+
+		if (list_empty(done) ||
+		    list_first_entry(done, typeof(*frame), list)->ring != ring)
+			wake_up(&ring->wait);
+	}
+}
+
 int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame, bool more)
 {
 	unsigned long flags;
@@ -819,6 +868,19 @@ static bool tb_ring_empty(struct tb_ring *ring)
 	return list_empty(&ring->in_flight);
 }
 
+/*
+ * ring_sync_irq() - wait for the interrupt handler of a ring
+ *
+ * nhi_msi_thread() invokes the callbacks of the frames it has harvested
+ * after dropping the locks, so make sure it has finished with any frames
+ * of a ring that has been stopped or dissociated from the NHI.
+ */
+static void ring_sync_irq(struct tb_ring *ring)
+{
+	if (ring->irq > 0)
+		synchronize_irq(ring->irq);
+}
+
 /**
  * tb_ring_flush() - Waits for a ring to be empty
  * @ring: Ring to wait
@@ -881,6 +943,8 @@ void tb_ring_stop(struct tb_ring *ring)
 	spin_unlock(&ring->lock);
 	spin_unlock_irq(&ring->nhi->lock);
 
+	ring_sync_irq(ring);
+
 	/*
 	 * schedule ring->work to invoke callbacks on all remaining frames.
 	 */
@@ -906,7 +970,7 @@ void tb_ring_free(struct tb_ring *ring)
 	spin_lock_irq(&ring->nhi->lock);
 	/*
 	 * Dissociate the ring from the NHI. This also ensures that
-	 * nhi_interrupt_work cannot reschedule ring->work.
+	 * nhi_msi_thread() cannot harvest its frames anymore.
 	 */
 	if (ring->is_tx)
 		ring->nhi->tx_rings[ring->hop] = NULL;
@@ -919,6 +983,8 @@ void tb_ring_free(struct tb_ring *ring)
 	}
 	spin_unlock_irq(&ring->nhi->lock);
 
+	ring_sync_irq(ring);
+
 	if (nhi->ops->release_ring_irq)
 		nhi->ops->release_ring_irq(ring);
 
@@ -935,8 +1001,8 @@ void tb_ring_free(struct tb_ring *ring)
 
 	/*
 	 * ring->work can no longer be scheduled (it is scheduled only
-	 * by nhi_interrupt_work, ring_stop and ring_msix). Wait for it
-	 * to finish before freeing the ring.
+	 * by ring_stop and ring_msix). Wait for it to finish before
+	 * freeing the ring.
 	 */
 	flush_work(&ring->work);
 	lockdep_unregister_key(&ring->lock_key);
@@ -1022,16 +1088,18 @@ enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi)
 	return (enum nhi_fw_mode)val;
 }
 
-void nhi_interrupt_work(struct work_struct *work)
+irqreturn_t nhi_msi_thread(int irq, void *data)
 {
-	struct tb_nhi *nhi = container_of(work, typeof(*nhi), interrupt_work);
+	struct tb_nhi *nhi = data;
+	LIST_HEAD(completed_frames);
+	unsigned long flags;
 	int value = 0; /* Suppress uninitialized usage warning. */
 	int bit;
 	int hop = -1;
 	int type = 0; /* current interrupt type 0: TX, 1: RX, 2: RX overflow */
 	struct tb_ring *ring;
 
-	spin_lock_irq(&nhi->lock);
+	spin_lock_irqsave(&nhi->lock, flags);
 
 	/*
 	 * Starting at REG_RING_NOTIFY_BASE there are three status bitfields
@@ -1073,17 +1141,28 @@ void nhi_interrupt_work(struct work_struct *work)
 		}
 
 		spin_lock(&ring->lock);
-		__ring_interrupt(ring);
+		/*
+		 * Harvest the completions right away instead of deferring
+		 * to ring->work, so that the RX buffers are reposted without
+		 * another scheduling delay during a burst.
+		 */
+		if (ring->start_poll)
+			__ring_interrupt(ring);
+		else if (ring->running)
+			ring_harvest(ring, &completed_frames);
 		spin_unlock(&ring->lock);
 	}
-	spin_unlock_irq(&nhi->lock);
+	spin_unlock_irqrestore(&nhi->lock, flags);
+
+	if (!list_empty(&completed_frames))
+		ring_process_completions(&completed_frames);
+
+	return IRQ_HANDLED;
 }
 
 irqreturn_t nhi_msi(int irq, void *data)
 {
-	struct tb_nhi *nhi = data;
-	schedule_work(&nhi->interrupt_work);
-	return IRQ_HANDLED;
+	return IRQ_WAKE_THREAD;
 }
 
 static int __nhi_suspend_noirq(struct device *dev, bool wakeup)
diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h
index 88af9ab9fde7afc8af6da412b668663e67380e53..71f750451aacae6ca2f8cb37bd8ae7fc5a029818 100644
--- a/drivers/thunderbolt/nhi.h
+++ b/drivers/thunderbolt/nhi.h
@@ -31,8 +31,8 @@ int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data);
 enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi);
 void nhi_enable_int_throttling(struct tb_nhi *nhi);
 void nhi_disable_interrupts(struct tb_nhi *nhi);
-void nhi_interrupt_work(struct work_struct *work);
 irqreturn_t nhi_msi(int irq, void *data);
+irqreturn_t nhi_msi_thread(int irq, void *data);
 irqreturn_t ring_msix(int irq, void *data);
 int nhi_probe(struct tb_nhi *nhi);
 void nhi_shutdown(struct tb_nhi *nhi);
diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c
index 9fe2ef43d8ac8ac867c6e37d7a77518ad2221ed9..6388f77c67ac6d51831667abbffcfb8f52881af6 100644
--- a/drivers/thunderbolt/pci.c
+++ b/drivers/thunderbolt/pci.c
@@ -206,14 +206,13 @@ static int nhi_pci_init_msi(struct tb_nhi *nhi)
 		if (nvec < 0)
 			return nvec;
 
-		INIT_WORK(&nhi->interrupt_work, nhi_interrupt_work);
-
 		irq = pci_irq_vector(pdev, 0);
 		if (irq < 0)
 			return irq;
 
-		res = devm_request_irq(&pdev->dev, irq, nhi_msi,
-				       IRQF_NO_SUSPEND, "thunderbolt", nhi);
+		res = devm_request_threaded_irq(&pdev->dev, irq, nhi_msi,
+						nhi_msi_thread,
+						IRQF_NO_SUSPEND, "thunderbolt", nhi);
 		if (res)
 			return res;
 	}
@@ -311,14 +310,8 @@ static void nhi_pci_release_irq(struct tb_nhi *nhi)
 	struct tb_nhi_pci *nhi_pci = nhi_to_pci(nhi);
 	struct pci_dev *pdev = to_pci_dev(nhi->dev);
 
-	/*
-	 * We have to release the irq before calling flush_work. Otherwise an
-	 * already executing IRQ handler could call schedule_work again.
-	 */
-	if (!pdev->msix_enabled) {
+	if (!pdev->msix_enabled)
 		devm_free_irq(nhi->dev, pdev->irq, nhi);
-		flush_work(&nhi->interrupt_work);
-	}
 	ida_destroy(&nhi_pci->msix_ida);
 }
 
diff --git a/include/linux/thunderbolt.h b/include/linux/thunderbolt.h
index 57502da290805ed6ba627578da060afe290d4137..4faec9246d175d08063b7881ed1d379b9a7bdafd 100644
--- a/include/linux/thunderbolt.h
+++ b/include/linux/thunderbolt.h
@@ -501,7 +501,8 @@ void tb_service_properties_changed(struct tb_service *svc);
 /**
  * struct tb_nhi - thunderbolt native host interface
  * @lock: Must be held during ring creation/destruction. Is acquired by
- *	  interrupt_work when dispatching interrupts to individual rings.
+ *	  the interrupt thread when dispatching interrupts to individual
+ *	  rings.
  * @dev: Device associated with this NHI instance
  * @ops: NHI specific optional ops
  * @iobase: MMIO space of the NHI
@@ -511,8 +512,6 @@ void tb_service_properties_changed(struct tb_service *svc);
  * @going_away: The host controller device is about to disappear so when
  *		this flag is set, avoid touching the hardware anymore.
  * @iommu_dma_protection: An IOMMU will isolate external-facing ports.
- * @interrupt_work: Work scheduled to handle ring interrupt when no
- *		    MSI-X is used.
  * @hop_count: Number of rings (end point hops) supported by NHI.
  * @quirks: NHI specific quirks if any
  * @domain_released: Completed when domain has been fully released
@@ -532,7 +531,6 @@ struct tb_nhi {
 	u32 *interrupt_mask;
 	bool going_away;
 	bool iommu_dma_protection;
-	struct work_struct interrupt_work;
 	u32 hop_count;
 	unsigned long quirks;
 	struct completion domain_released;
@@ -639,11 +637,13 @@ enum ring_desc_flags {
  * @flags: Flags for the frame (see &enum ring_desc_flags)
  * @eof: End of frame protocol defined field
  * @sof: Start of frame protocol defined field
+ * @ring: Ring the frame was completed on
  */
 struct ring_frame {
 	dma_addr_t buffer_phy;
 	ring_cb callback;
 	struct list_head list;
+	struct tb_ring *ring;
 	u32 size:12;
 	u32 flags:12;
 	u32 eof:4;

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 08/15] thunderbolt: nhi: Add pre_switch_suspend hook
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (6 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 07/15] thunderbolt: nhi: Process ring completions in the threaded IRQ Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-12-01  7:41   ` Mika Westerberg
  2026-11-24 20:01 ` [PATCH RFC DNM 09/15] thunderbolt: nhi: Resume the domain if the NHI suspend op fails Konrad Dybcio
                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

The Qualcomm router firmware requires a three-way handshake during its
suspend routines as the OS writes the SLP bit to a connected device.

Add a hook right beforehand to allow synchronizing right as it happens.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/thunderbolt/nhi.h    | 2 ++
 drivers/thunderbolt/switch.c | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h
index 71f750451aacae6ca2f8cb37bd8ae7fc5a029818..9bafb84cf60adbdee1f1f083732719e951b88c20 100644
--- a/drivers/thunderbolt/nhi.h
+++ b/drivers/thunderbolt/nhi.h
@@ -53,6 +53,7 @@ extern const struct dev_pm_ops nhi_pm_ops;
  * @release_ring_irq: NHI specific interrupt release hook
  * @is_present: Whether the device is currently present on the parent bus
  * @init_interrupts: NHI specific interrupt initialization hook
+ * @post_switch_suspend: NHI specific hook to call before suspending a switch
  */
 struct tb_nhi_ops {
 	int (*init)(struct tb_nhi *nhi);
@@ -68,6 +69,7 @@ struct tb_nhi_ops {
 	void (*release_ring_irq)(struct tb_ring *ring);
 	bool (*is_present)(struct tb_nhi *nhi);
 	int (*init_interrupts)(struct tb_nhi *nhi);
+	void (*pre_switch_suspend)(struct tb_nhi *nhi);
 };
 
 /*
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index d22d8db8f89064b3ed9c2b8beb8d5f0398640f11..4908c8b0e580a500acf9cac000e66a25e2102d47 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -3660,6 +3660,7 @@ int tb_switch_resume(struct tb_switch *sw, bool runtime)
  */
 void tb_switch_suspend(struct tb_switch *sw, bool runtime)
 {
+	struct tb_nhi *nhi = sw->tb->nhi;
 	unsigned int flags = 0;
 	struct tb_port *port;
 	int err;
@@ -3693,6 +3694,9 @@ void tb_switch_suspend(struct tb_switch *sw, bool runtime)
 
 	tb_switch_set_wake(sw, flags, runtime);
 
+	if (nhi->ops->pre_switch_suspend)
+		nhi->ops->pre_switch_suspend(nhi);
+
 	if (tb_switch_is_usb4(sw))
 		usb4_switch_set_sleep(sw);
 	else

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 09/15] thunderbolt: nhi: Resume the domain if the NHI suspend op fails
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (7 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 08/15] thunderbolt: nhi: Add pre_switch_suspend hook Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-12-01  7:44   ` Mika Westerberg
  2026-11-24 20:01 ` [PATCH RFC DNM 10/15] thunderbolt: nhi: Resume a runtime suspended NHI for system suspend Konrad Dybcio
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

nhi_suspend_noirq() and nhi_runtime_suspend() suspend the domain first
and then call the NHI specific suspend op. If that op fails, the error
is returned with the domain still suspended. The control channel is
stopped and the switches are marked as suspended, but the PM core
treats the device as active: it does not call resume_noirq for a device
whose suspend_noirq failed, nor runtime_resume after a failed
runtime_suspend. Nothing ever resumes the domain. Hotplug and config
space accesses stop working, and the next runtime suspend attempt
suspends an already suspended domain.

This happens on Qualcomm USB4 routers whenever the router firmware does
not acknowledge the sleep request in time. The op then returns -EBUSY
with the router still up.

Resume the domain before returning the error.
---
 drivers/thunderbolt/nhi.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index bcc2b959e3b1a6b014c13a4938ed6f68cb0d0fd8..e2578740d569a7ee1d5ab22e8effc153cb7d4632 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -1177,8 +1177,15 @@ static int __nhi_suspend_noirq(struct device *dev, bool wakeup)
 
 	if (nhi->ops->suspend_noirq) {
 		ret = nhi->ops->suspend_noirq(tb->nhi, wakeup);
-		if (ret)
+		if (ret) {
+			/*
+			 * The PM core does not call resume_noirq for a
+			 * device whose suspend_noirq failed, so resume
+			 * the domain here.
+			 */
+			tb_domain_resume_noirq(tb);
 			return ret;
+		}
 	}
 
 	return 0;
@@ -1281,8 +1288,14 @@ static int nhi_runtime_suspend(struct device *dev)
 
 	if (nhi->ops->runtime_suspend) {
 		ret = nhi->ops->runtime_suspend(tb->nhi);
-		if (ret)
+		if (ret) {
+			/*
+			 * The PM core does not call runtime_resume after a
+			 * failed runtime_suspend, so resume the domain here.
+			 */
+			tb_domain_runtime_resume(tb);
 			return ret;
+		}
 	}
 	return 0;
 }

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 10/15] thunderbolt: nhi: Resume a runtime suspended NHI for system suspend
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (8 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 09/15] thunderbolt: nhi: Resume the domain if the NHI suspend op fails Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-12-01  7:49   ` Mika Westerberg
  2026-11-24 20:01 ` [PATCH RFC DNM 11/15] thunderbolt: Raise TB_TIMEOUT to 500 ms Konrad Dybcio
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

The PCI core resumes a runtime suspended device in pci_pm_suspend()
before calling the driver's suspend callback, so nhi_suspend_noirq()
always finds the NHI active. Platform devices get no such treatment, so
these runtime suspended NHIs gets suspended a second time in the
noirq phase and resumed in nhi_resume_noirq(). nhi_complete() then still
sees it as runtime suspended and resumes it once more, which corrupts
the control channel (RX checksum mismatches, config space timeouts).

Resume the NHI at the beginning of nhi_suspend(), like the PCI core
does as a workaround.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/thunderbolt/nhi.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index e2578740d569a7ee1d5ab22e8effc153cb7d4632..56bc5748b6515b9d4799aa87ce0f72e1d673d634 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -1258,6 +1258,13 @@ static int nhi_suspend(struct device *dev)
 {
 	struct tb *tb = dev_get_drvdata(dev);
 
+	/*
+	 * The noirq callbacks expect the NHI to be active. The PCI core
+	 * resumes a runtime suspended device before calling this, do the
+	 * same for the NHIs that are not PCI devices.
+	 */
+	pm_runtime_resume(dev);
+
 	return tb_domain_suspend(tb);
 }
 

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 11/15] thunderbolt: Raise TB_TIMEOUT to 500 ms
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (9 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 10/15] thunderbolt: nhi: Resume a runtime suspended NHI for system suspend Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-24 20:01 ` [PATCH HACK RFC DNM 12/15] thunderbolt: Refuse to activate DP/USB3/PCIe tunnels Konrad Dybcio
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

Routers with firmware-managed link training (e.g. Qualcomm) can take
well over 100 ms to answer config requests while a link is coming up.
Increase the timeout to facilitate that.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/thunderbolt/tb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 418ad0a61a5de84717d7653c3516faca2a3db2ec..7594bc24c443fc27af651dd22c2db4b6e5acd696 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -16,7 +16,7 @@
 #include "tb_regs.h"
 #include "tunnel.h"
 
-#define TB_TIMEOUT		100	/* ms */
+#define TB_TIMEOUT		500	/* ms */
 #define TB_RELEASE_BW_TIMEOUT	10000	/* ms */
 
 /*

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH HACK RFC DNM 12/15] thunderbolt: Refuse to activate DP/USB3/PCIe tunnels
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (10 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 11/15] thunderbolt: Raise TB_TIMEOUT to 500 ms Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 13/15] thunderbolt: Introduce Qualcomm USB4 router driver Konrad Dybcio
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

This is for demonstration purposes for anyone wanting to try out the
series on real hw, keeping in mind the constraints detailed in the
cover letter.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/thunderbolt/tunnel.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c
index 8145657835c5bb060812770a303cbf2649082a55..8b497da596b99d7f9d2e04636caa9896617af2e4 100644
--- a/drivers/thunderbolt/tunnel.c
+++ b/drivers/thunderbolt/tunnel.c
@@ -2430,6 +2430,8 @@ int tb_tunnel_activate(struct tb_tunnel *tunnel)
 	int res, i;
 
 	tb_tunnel_dbg(tunnel, "activating\n");
+	if (!tb_tunnel_is_dma(tunnel))
+		return -EOPNOTSUPP;
 
 	/*
 	 * Make sure all paths are properly disabled before enabling

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 13/15] thunderbolt: Introduce Qualcomm USB4 router driver
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (11 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH HACK RFC DNM 12/15] thunderbolt: Refuse to activate DP/USB3/PCIe tunnels Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-28 13:54   ` Troels Vognbjerg
  2026-11-24 20:01 ` [PATCH RFC DNM 14/15] arm64: dts: qcom: glymur: Add USB4 topology Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 15/15] arm64: dts: qcom: glymur-crd: Enable the tertiary Type-C Konrad Dybcio
  14 siblings, 1 reply; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

Introduce a driver for the in-house Qualcomm USB4 router driver.
It consists of resource enablement, uC firmware loading and
communication, Type-C infrastructure and power state handling.

Unlike many other implementations, the power state of both the router
and the native protocol controllers has to be manually coordinated,
which much of this driver ends up doing.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 drivers/thunderbolt/Kconfig   |   13 +
 drivers/thunderbolt/Makefile  |    3 +
 drivers/thunderbolt/eeprom.c  |   17 -
 drivers/thunderbolt/qcom.c    | 2299 +++++++++++++++++++++++++++++++++++++++++
 drivers/thunderbolt/qcom.h    |  251 +++++
 drivers/thunderbolt/tb.h      |   20 +
 drivers/thunderbolt/tb_regs.h |    3 +
 7 files changed, 2589 insertions(+), 17 deletions(-)

diff --git a/drivers/thunderbolt/Kconfig b/drivers/thunderbolt/Kconfig
index 294b3227a54582536433cbb391057b99bb9df352..94654d3e41137b630fc4723adc4949d8df8b0617 100644
--- a/drivers/thunderbolt/Kconfig
+++ b/drivers/thunderbolt/Kconfig
@@ -64,6 +64,19 @@ config USB4_DMA_TEST
 	  To compile this driver a module, choose M here. The module will be
 	  called thunderbolt_dma_test.
 
+config USB4_QCOM
+	tristate "Qualcomm USB4/Thunderbolt Support"
+	depends on USB4
+	depends on OF
+	depends on ARCH_QCOM || COMPILE_TEST
+	depends on COMMON_CLK && PM
+	help
+	  Say Y here to add support for the USB4 and Thunderbolt host
+	  routers found on Qualcomm SoCs.
+
+	  To compile the driver as a module, choose M here. The module
+	  will be called thunderbolt_qcom.
+
 config USB4_STREAM
 	tristate "Stream data over Thunderbolt/USB4 cable"
 	depends on USB4_CONFIGFS
diff --git a/drivers/thunderbolt/Makefile b/drivers/thunderbolt/Makefile
index beb054c3126b1445d26b4c14de039d23367a5100..8f56afd7d6b47e95324adbd95f50692ca7b3582d 100644
--- a/drivers/thunderbolt/Makefile
+++ b/drivers/thunderbolt/Makefile
@@ -11,6 +11,9 @@ thunderbolt-$(CONFIG_USB4_CONFIGFS) += configfs.o
 thunderbolt-${CONFIG_USB4_KUNIT_TEST} += test.o
 CFLAGS_test.o += $(DISABLE_STRUCTLEAK_PLUGIN)
 
+thunderbolt_qcom-objs := qcom.o
+obj-${CONFIG_USB4_QCOM} += thunderbolt_qcom.o
+
 thunderbolt_dma_test-${CONFIG_USB4_DMA_TEST} += dma_test.o
 obj-$(CONFIG_USB4_DMA_TEST) += thunderbolt_dma_test.o
 
diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c
index 2acfe83928b6d8cc95520479f90b595d7137b829..74be3295a0a241f17c833d143d0674e18ffb9bb0 100644
--- a/drivers/thunderbolt/eeprom.c
+++ b/drivers/thunderbolt/eeprom.c
@@ -197,23 +197,6 @@ static int tb_eeprom_read_n(struct tb_switch *sw, u16 offset, u8 *val,
 	return tb_eeprom_active(sw, false);
 }
 
-static u8 tb_crc8(u8 *data, int len)
-{
-	int i, j;
-	u8 val = 0xff;
-	for (i = 0; i < len; i++) {
-		val ^= data[i];
-		for (j = 0; j < 8; j++)
-			val = (val << 1) ^ ((val & 0x80) ? 7 : 0);
-	}
-	return val;
-}
-
-static u32 tb_crc32(void *data, size_t len)
-{
-	return ~crc32c(~0, data, len);
-}
-
 #define TB_DROM_DATA_START		13
 #define TB_DROM_HEADER_SIZE		22
 #define USB4_DROM_HEADER_SIZE		16
diff --git a/drivers/thunderbolt/qcom.c b/drivers/thunderbolt/qcom.c
new file mode 100644
index 0000000000000000000000000000000000000000..721feeccd7364e21bb1e2ecb2d97967bee5bc5cf
--- /dev/null
+++ b/drivers/thunderbolt/qcom.c
@@ -0,0 +1,2299 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#include <linux/align.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/devm-helpers.h>
+#include <linux/errno.h>
+#include <linux/firmware.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/overflow.h>
+#include <linux/phy/phy.h>
+#include <linux/pinctrl/consumer.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <linux/pm_opp.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/slab.h>
+#include <linux/soc/qcom/smem.h>
+#include <linux/unaligned.h>
+#include <linux/units.h>
+#include <linux/usb/pd.h>
+#include <linux/usb/typec_altmode.h>
+#include <linux/usb/typec_mux.h>
+#include <linux/usb/typec_tbt.h>
+#include <linux/usb/typec.h>
+#include <linux/workqueue.h>
+
+#include "nhi.h"
+#include "nhi_regs.h"
+#include "qcom.h"
+#include "tb.h"
+
+/*
+ * The router's operational ability is directly tied to the mode and power state of the QMPPHY
+ * (and thus to cable presence). The router (transitively) sources its clocks from the PHY,
+ * although it may operate in reduced capacity even when it's off (by muxing its inputs to the
+ * 19.2 MHz XO clock source). That 'reduced mode' allows for register access, but not TBT linkup.
+ *
+ * At probe time, that mechanism is used to bootstrap the router regardless of the plug state
+ * (since forcefully switching the PHY to USB4 mode would disrupt a USB3/DP link on that port).
+ * Then, upon a USB4/TBT3 typec_mux event the PHY is reconfigured, the clocks are reconfigured to
+ * follow, the uC is brought online and a BEGIN_HSE command is sent to the router, which can take
+ * a couple seconds to complete.
+ *
+ * Upon unplug, the router has to be immediately torn down (including the clocks scaffolding and
+ * the PHY) to unblock the port for a potentially soon-to-be-plugged USB3/DP device.
+ *
+ * Suspend/resume sequences require a handshake with the uC, as that influences the state of some
+ * clocks and failing to follow that ends up in a hard crash of the entire platform.
+ *
+ * This is modeled as an explicit state machine (enum qcusb4_hw_state), with all transitions
+ * serialized by state_lock:
+ *
+ *   OFF --probe--> IDLE <--reconcile--> LINK
+ *                    \                   /
+ *                     +---> ASLEEP <----+   (runtime/system sleep, uC handshake)
+ *
+ * The Type-C callbacks record what state they want (->desired_state) and kick the reconcile work,
+ * which runs the IDLE <-> LINK transitions. Cable removal is LINK -> IDLE, which cycles the domain
+ * and the router through a full sleep (TBT layer _SLP first, then the uC handshake) to hand the PHY
+ * back, then cold-restarts the router on XO (a sleep exit would have the FW go for the PHY it no
+ * longer has), so the TBT core sees a regular unplug. The PHY must never be taken away outside of
+ * that handshake. For the same reason, sleep entered from IDLE is exited through a cold restart, as
+ * the cable may have been plugged in meanwhile. Two gates protect against unclocked access from
+ * outside the state machine: uc_online for FW commands and mmio_ok for the PCIe reset controller.
+ */
+
+/* ROUTER_CS registers */
+#define ROUTER_CS_CS_1			0x4
+#define ROUTER_CS_CS_5			0x14
+
+#define is_usb4v2(q)			((q)->match_data->entries[(q)->instance_idx].usb4v2_capable)
+
+/* LANEn_CS registers */
+#define UC_RAM_DROM_OFFSET_V1		0xdf20
+#define UC_RAM_DROM_OFFSET_V2		0xff20
+#define UC_RAM_DROM_OFFSET(q)		(is_usb4v2((q)) ? \
+					 UC_RAM_DROM_OFFSET_V2 : UC_RAM_DROM_OFFSET_V1)
+
+#define LANEn_CS_CS_1(q)		(is_usb4v2(q) ? 0x58 : 0x50)
+#define LANEn_CS_CS_1_ADAPTER_STATE	GENMASK(29, 26)
+#define LANEn_CS_CS_18(q)		(is_usb4v2(q) ? 0xac : 0xa4)
+#define LANEn_CS_CS_19(q)		(is_usb4v2(q) ? 0xb0 : 0xa8)
+
+/* PORT_GROUP registers */
+#define PORT_GROUP_LANE_CFG		0x0
+#define LANE_CFG_CLx_SUPPORT(q)		(is_usb4v2(q) ? GENMASK(21, 19) : GENMASK(23, 21))
+#define PORT_GROUP_FCM_2_CFG		0x64
+ #define FCM_2_CFG_DIS_ANY_HOPID	BIT(6)
+
+/* SIDEBAND registers */
+#define SIDEBAND_TX_CTRL		0xc
+ #define SB_TX_CTRL_TX_ENABLE		BIT(31)
+
+/* UC_PER registers */
+#define UC_PER_CONTROL			0x1000
+ #define PER_CONTROL_UC_ENABLE		BIT(0)
+#define UC_PER_SW_TRIGGERS_UC_IRQ	0x100c
+#define UC_PER_FW_INT_STATUS_SET	0x1010
+#define UC_PER_FW_INT_CLR		0x1018
+ #define PER_FW_INT_CLR_CLR		BIT(0)
+#define UC_PER_FW_INT_MASK		0x101c
+ #define PER_FW_INT_MASK_FW_INT		BIT(0)
+
+/* CFG registers */
+#define CFG_SYS_CLK_CGC			0x0
+ #define SYS_CLK_CGC_SYS_CLK_EN_USBAP	BIT(7)
+
+/* USBAP_CONFIG registers */
+#define USBAP_CFG_SYNC_RST_USB3		0x0
+ #define RST_USB3_RST			BIT(0)
+#define USBAP_CFG_USB4_MODE		0x4
+ #define USB4_MODE_USB4_MODE		BIT(0)
+#define USBAP_CFG_RXTERM_BACKDOOR_CTRL	0x10
+#define USBAP_CFG_RXTERM_BACKDOOR_STS	0x14
+ #define RXTERM_RX_TERM			BIT(0)
+#define USBAP_CFG_PHYSTATUS_EN		0x18
+ #define PHYSTATUS_EN_EN		BIT(0)
+
+/* PCIEAP_CONFIG registers */
+#define PCIEAP_CONFIG_SYNC_RST		0x0
+ #define PCIEAP_SYNC_RST_PCIE		BIT(0)
+#define PCIEAP_CONFIG_IRQ_STATUS	0x0c
+ #define PCIEAP_IRQ_PE_DEASSERT		BIT(3)
+ #define PCIEAP_IRQ_PE_ASSERT		BIT(2)
+#define PCIEAP_CONFIG_IRQ_MASK		0x10
+#define PCIEAP_CONFIG_IRQ_CLEAR		0x14
+
+/* PCIEAP (USB4 v2 router) registers */
+#define PCIEAP_TX_CFG			0x0
+ #define PCIEAP_TX_CFG_EN_FLUSH_MISSING_SOP	BIT(22)
+
+/* ROUTER_CONFIG registers */
+#define ROUTER_CONFIG_CS_6		0x18
+ #define CS_6_ROUTER_READY		BIT(24)
+#define ROUTER_CONFIG_CS_7		0x1c
+#define ROUTER_CONFIG_CS_8		0x20
+
+struct qcom_usb4_fw_event {
+	u8 opcode;
+	u8 params[];
+} __packed;
+
+struct qcom_usb4_fw_events {
+	__le16 num_entries;
+	__le16 entry_size;
+	__le32 next_entry_index;
+	__le16 num_unread_entries; /* This only guarantees num_unread >= num_entries */
+	u8 res[6];
+	struct qcom_usb4_fw_event entries[];
+} __packed;
+
+#define FW_EV_BUF_SIZE			SZ_8K
+
+enum qcom_usb4_fw_cmd {
+	FW_CMD_BEGIN_HSE = 0x1,
+
+	FW_CMD_ENABLE_PHY_PRESETS = 0x2,
+#define PHY_PRESETS_DEFAULT (BIT(0) | BIT(1) | BIT(5) | BIT(6) | BIT(10) | BIT(11))
+
+	FW_CMD_LIMIT_LOGLEVEL = 0x3,
+#define LOG_LEVEL_ALL			0
+#define LOG_LEVEL_WARN			1
+#define LOG_LEVEL_ERR			2
+#define LOG_LEVEL_NONE			3
+
+	/* Only makes sense to call this after FW_MSG_SLEEP_READY */
+	FW_CMD_COMPLETE_SLEEP = 0x4,
+
+	/* Reconfigure the internals to restore the link (or handle an in-sleep disconnect) */
+	FW_CMD_WAKEUP = 0x5,
+#define WAKEUP_REASON_DEVICE		0
+#define WAKEUP_REASON_CBL_DIS		1
+#define WAKEUP_REASON_CBL_CON		2
+#define WAKEUP_REASON_SYSTEM		3
+
+	/* The router alone can't differentiate between physical and logical disconnects */
+	FW_CMD_PHYS_DISCONNECT = 0x6,
+
+	FW_CMD_DEPRECATED	= 0x7,
+
+	/* USB4v2 introduced more tuning presets */
+	FW_CMD_ENABLE_PHY_PRESETS_MSB = 0x8,
+
+	/* Notify the uC that we're done with the Host Router Reset */
+	FW_CMD_HRR_DONE = 0x9,
+
+	FW_CMD_WA_DONE = 0xa,
+#define WA_DONE_USBAP_RXTERM		1
+};
+
+/* Must be called with the mux clocks enabled */
+static int qcusb4_select_rx_clock_source(struct qcom_usb4 *qcusb4,
+					 bool fast_clock)
+{
+	struct clk *rx0 = qcusb4->mux_clks[MUX_CLK_PHY_RX0].clk;
+	struct clk *rx1 = qcusb4->mux_clks[MUX_CLK_PHY_RX1].clk;
+	unsigned long rate = fast_clock ? ULONG_MAX : 19200000;
+	int ret;
+
+	clk_disable_unprepare(rx0);
+	clk_disable_unprepare(rx1);
+
+	/* No error unwinding on purpose, failure here is borderline impossible and catastrophic */
+	ret = clk_set_rate(rx0, rate);
+	if (ret) {
+		dev_err(qcusb4->nhi.dev, "Failed to select RX0 clock source: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_set_rate(rx1, rate);
+	if (ret) {
+		dev_err(qcusb4->nhi.dev, "Failed to select RX1 clock source: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_prepare_enable(rx0);
+	if (ret) {
+		dev_err(qcusb4->nhi.dev, "Failed to re-enable the RX0 clock: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_prepare_enable(rx1);
+	if (ret)
+		dev_err(qcusb4->nhi.dev, "Failed to re-enable the RX1 clock: %d\n", ret);
+
+	return ret;
+}
+
+static int __qcusb4_fw_cmd(struct qcom_usb4 *qcusb4, enum qcom_usb4_fw_cmd msg, u32 args)
+{
+	u32 cmd;
+	u32 val;
+
+	lockdep_assert_held(&qcusb4->uc_cmd_lock);
+
+	/* The uC is either down, or about to be */
+	if (!qcusb4->uc_online) {
+		dev_warn_ratelimited(qcusb4->nhi.dev,
+				     "Dropping cmd=0x%x arg=0x%x, the uC is not running\n",
+				     msg, args);
+		return -EAGAIN;
+	}
+
+	pm_runtime_mark_last_busy(qcusb4->nhi.dev);
+
+	cmd = FIELD_PREP(GENMASK(31, 8), args) |
+	      FIELD_PREP(GENMASK(7, 0), msg);
+
+	writel(cmd, qcusb4->uc_per + UC_PER_SW_TRIGGERS_UC_IRQ);
+
+	if (readl_poll_timeout(qcusb4->uc_per + UC_PER_SW_TRIGGERS_UC_IRQ,
+			       val, !val, 10, 10 * USEC_PER_MSEC)) {
+		dev_err(qcusb4->nhi.dev, "Firmware failed to clear cmd 0x%08x\n", cmd);
+		return -ETIMEDOUT;
+	}
+
+	return 0;
+}
+
+static int qcusb4_fw_cmd(struct qcom_usb4 *qcusb4, enum qcom_usb4_fw_cmd msg, u32 args)
+{
+	guard(mutex)(&qcusb4->uc_cmd_lock);
+
+	return __qcusb4_fw_cmd(qcusb4, msg, args);
+}
+
+/*
+ * Send a command that the FW acks with an event. The completion is re-armed under uc_cmd_lock,
+ * so that a stale ack from an earlier command can't satisfy the wait.
+ */
+static int qcusb4_fw_cmd_wait(struct qcom_usb4 *qcusb4, enum qcom_usb4_fw_cmd msg, u32 args,
+			      struct completion *done, unsigned int timeout_ms)
+{
+	int ret;
+
+	scoped_guard(mutex, &qcusb4->uc_cmd_lock) {
+		reinit_completion(done);
+
+		ret = __qcusb4_fw_cmd(qcusb4, msg, args);
+		if (ret)
+			return ret;
+	}
+
+	if (!wait_for_completion_timeout(done, msecs_to_jiffies(timeout_ms)))
+		return -ETIMEDOUT;
+
+	return 0;
+}
+
+enum qcom_usb4_fw_msg {
+	FW_MSG_MESSAGE = 0x1,
+	FW_MSG_ERR = 0x2,
+	FW_MSG_TEST_RES = 0x3,
+	/* Fires after a successful handling of FW_CMD_COMPLETE_SLEEP */
+	FW_MSG_SLEEP_DONE = 0x4,
+	/* Fires after a packet with opcode = USB4_SB_OPCODE_ROUTER_OFFLINE is handled */
+	FW_MSG_EXIT_OFFLINE = 0x5,
+	/* Fires after any sort of (incl. logical) disconnect has been detected */
+	FW_MSG_DISCONNECT = 0x6,
+	/* Fires after a successful handling of ROUTER_CS_5.SLP becoming set */
+	FW_MSG_SLEEP_READY = 0x7,
+	/* "A specific software workaround must be applied immediately" */
+	FW_MSG_TRIGGER = 0x8,
+#define WA_TRIGGER_USBAP_RXTERM		3
+
+	/* "found hotplug with HopId > 1" */
+	FW_MSG_CHAINED_HOTPLUG = 0x9,
+	/* Fires after a HRR request arrives, needs to be acked with FW_CMD_HRR_DONE */
+	FW_MSG_HOST_RESET = 0xa,
+	FW_MSG_HSE_STATS = 0xb,
+	FW_MSG_FOM_STATS = 0xc,
+};
+
+static void qcom_usb4_fw_clear_irq(struct qcom_usb4 *qcusb4)
+{
+	/* Clear the irq - this resets the unread message counter on the FW side */
+	writel(PER_FW_INT_CLR_CLR, qcusb4->uc_per + UC_PER_FW_INT_CLR);
+	readl(qcusb4->uc_per + UC_PER_FW_INT_CLR);
+}
+
+static bool qcom_usb4_fw_event_ring_valid(struct qcom_usb4 *qcusb4, u32 data_off,
+					  u16 total_entries, u16 entry_size, u32 *ring_size)
+{
+	u32 entries_size;
+
+	if (!total_entries || entry_size < sizeof(struct qcom_usb4_fw_event))
+		return false;
+
+	if (check_mul_overflow((u32)total_entries, (u32)entry_size, &entries_size))
+		return false;
+
+	if (check_add_overflow((u32)sizeof(struct qcom_usb4_fw_events),
+			       entries_size, ring_size))
+		return false;
+
+	if (*ring_size > FW_EV_BUF_SIZE)
+		return false;
+
+	if (data_off > qcusb4->uc_ram_size - *ring_size)
+		return false;
+
+	return true;
+}
+
+/*
+ * The FW exposes a ring buffer with no 'event processing done' acking (i.e. the event may be gone
+ * before we process it).
+ *
+ * Accessing that data happens by directly reading the uC's RAM at a given offset.
+ * The uC is clocked by the SYS clock (part of qcusb4->mux_clks), so care must be taken to disable
+ * this IRQ, to prevent system crashes.
+ */
+static irqreturn_t qcom_usb4_fw_irq_handler(int irq, void *data)
+{
+	struct qcom_usb4 *qcusb4 = data;
+	u16 total_entries;
+	u16 entry_size;
+	u32 ring_size;
+	u32 data_off;
+
+	if (unlikely(!qcusb4->fw_ev_rb_base)) {
+		data_off = readl(qcusb4->uc_per + UC_PER_FW_INT_STATUS_SET);
+		if (!IS_ALIGNED(data_off, sizeof(u32)) ||
+		    data_off > qcusb4->uc_ram_size - sizeof(struct qcom_usb4_fw_events)) {
+			dev_err_ratelimited(qcusb4->nhi.dev,
+					    "Invalid FW event ring offset 0x%x\n",
+					    data_off);
+			qcom_usb4_fw_clear_irq(qcusb4);
+			return IRQ_HANDLED;
+		}
+
+		total_entries = lower_16_bits(readl(qcusb4->uc_ram + data_off));
+		entry_size = upper_16_bits(readl(qcusb4->uc_ram + data_off));
+
+		if (!qcom_usb4_fw_event_ring_valid(qcusb4, data_off, total_entries,
+						   entry_size, &ring_size)) {
+			dev_err_ratelimited(qcusb4->nhi.dev,
+					    "Invalid FW event ring: off=0x%x entries=%u size=%u\n",
+					    data_off, total_entries, entry_size);
+			qcom_usb4_fw_clear_irq(qcusb4);
+			return IRQ_HANDLED;
+		}
+
+		qcusb4->fw_ev_rb_base = qcusb4->uc_ram + data_off;
+		qcusb4->fw_ev_total_entry_num = total_entries;
+		qcusb4->fw_ev_entry_size = entry_size;
+		qcusb4->fw_ev_ring_size = ring_size;
+		qcusb4->next_fw_ev_idx = 0;
+	}
+
+	return IRQ_WAKE_THREAD;
+}
+
+static int qcusb4_usbap_rxterm_wa(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	u32 val;
+	int ret;
+
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+	writel(val & ~PHYSTATUS_EN_EN, qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_SYNC_RST_USB3);
+	writel(val | RST_USB3_RST, qcusb4->usb_cfg + USBAP_CFG_SYNC_RST_USB3);
+
+	ret = reset_control_assert(qcusb4->usb_pipe_reset);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't assert usb_pipe reset\n");
+
+	usleep_range(100, 150);
+
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+	writel(val | PHYSTATUS_EN_EN, qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+
+	val = readl(qcusb4->cfg + CFG_SYS_CLK_CGC);
+	writel(val & ~SYS_CLK_CGC_SYS_CLK_EN_USBAP, qcusb4->cfg + CFG_SYS_CLK_CGC);
+
+	ret = reset_control_deassert(qcusb4->usb_pipe_reset);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't deassert usb_pipe reset\n");
+
+	usleep_range(100, 150);
+
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_SYNC_RST_USB3);
+	writel(val & ~RST_USB3_RST, qcusb4->usb_cfg + USBAP_CFG_SYNC_RST_USB3);
+
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_RXTERM_BACKDOOR_CTRL);
+	writel(val | RXTERM_RX_TERM, qcusb4->usb_cfg + USBAP_CFG_RXTERM_BACKDOOR_CTRL);
+
+	return qcusb4_fw_cmd(qcusb4, FW_CMD_WA_DONE, WA_DONE_USBAP_RXTERM);
+}
+
+static irqreturn_t qcom_usb4_fw_irq_thread(int irq, void *data)
+{
+	struct qcom_usb4 *qcusb4 = data;
+	struct qcom_usb4_fw_events *fw_events = qcusb4->fw_events_buf;
+	struct device *dev = qcusb4->nhi.dev;
+	u32 entry_size = qcusb4->fw_ev_entry_size;
+	u16 num_new_entries, num_to_end;
+	void __iomem *entries;
+	u32 next_entry_index;
+
+	if (!qcusb4->fw_ev_rb_base || !qcusb4->fw_ev_ring_size) {
+		qcom_usb4_fw_clear_irq(qcusb4);
+		return IRQ_HANDLED;
+	}
+
+	/*
+	 * Clear before reading the write index. Otherwise an event written in between gets its IRQ
+	 * cleared, but not read, and sits in the ring until something else fires the IRQ.
+	 */
+	qcom_usb4_fw_clear_irq(qcusb4);
+
+	next_entry_index = readl(qcusb4->fw_ev_rb_base +
+				 offsetof(struct qcom_usb4_fw_events, next_entry_index));
+	if (next_entry_index >= qcusb4->fw_ev_total_entry_num) {
+		dev_err_ratelimited(dev, "Invalid FW event index %u/%u\n",
+				    next_entry_index, qcusb4->fw_ev_total_entry_num);
+		return IRQ_HANDLED;
+	}
+
+	/* Check for ringbuffer rollover */
+	if (next_entry_index < qcusb4->next_fw_ev_idx)
+		num_new_entries = qcusb4->fw_ev_total_entry_num - qcusb4->next_fw_ev_idx
+				  + next_entry_index;
+	else
+		num_new_entries = next_entry_index - qcusb4->next_fw_ev_idx;
+
+	/* Grab the header and the new entries (wrapping around) from the uC's RAM */
+	memcpy_fromio(fw_events, qcusb4->fw_ev_rb_base, sizeof(*fw_events));
+	entries = qcusb4->fw_ev_rb_base + offsetof(struct qcom_usb4_fw_events, entries);
+	num_to_end = min_t(u16, num_new_entries,
+			   qcusb4->fw_ev_total_entry_num - qcusb4->next_fw_ev_idx);
+	memcpy_fromio((void *)fw_events->entries + entry_size * qcusb4->next_fw_ev_idx,
+		      entries + entry_size * qcusb4->next_fw_ev_idx, entry_size * num_to_end);
+	memcpy_fromio(fw_events->entries, entries, entry_size * (num_new_entries - num_to_end));
+	/* Make sure we get the events before proceeding */
+	mb();
+
+	if (le16_to_cpu(fw_events->num_unread_entries) >= qcusb4->fw_ev_total_entry_num)
+		dev_warn_ratelimited(dev, "FW event ring overflowed, events were lost\n");
+
+	for (int i = 0; i < num_new_entries; i++) {
+		struct qcom_usb4_fw_event *ev;
+		u16 payload_size = qcusb4->fw_ev_entry_size - sizeof(*ev);
+
+		ev = (void *)fw_events->entries +
+		     (qcusb4->fw_ev_entry_size * qcusb4->next_fw_ev_idx++);
+
+		switch (ev->opcode) {
+		case FW_MSG_MESSAGE:
+			dev_warn(qcusb4->nhi.dev, "FW MSG: %.*s\n", payload_size, ev->params);
+			break;
+		case FW_MSG_ERR:
+			if (payload_size < 3) {
+				dev_err(dev, "Malformed FW error event\n");
+				break;
+			}
+
+			u8 error = ev->params[0];
+			u16 extradata = (ev->params[2] << 8) | ev->params[1];
+
+			dev_err(qcusb4->nhi.dev, "Received FW error: %u (data: 0x%x)\n",
+				error, extradata);
+			break;
+		case FW_MSG_SLEEP_DONE:
+			complete(&qcusb4->sleep_acked);
+			dev_err(qcusb4->nhi.dev, "FW Sleep done\n");
+			break;
+		case FW_MSG_EXIT_OFFLINE:
+			dev_err(qcusb4->nhi.dev, "FW exit offline\n");
+			break;
+		case FW_MSG_DISCONNECT:
+			if (!payload_size) {
+				dev_err(dev, "Malformed FW disconnect event\n");
+				break;
+			}
+
+			complete(&qcusb4->disconnect_acked);
+			dev_err(qcusb4->nhi.dev, "FW disconnect event: %u\n", *ev->params);
+			break;
+		case FW_MSG_SLEEP_READY:
+			complete(&qcusb4->sleep_ready);
+			dev_err(qcusb4->nhi.dev, "FW Sleep ready\n");
+			break;
+		case FW_MSG_TRIGGER:
+			if (!payload_size) {
+				dev_err(dev, "Malformed FW trigger event\n");
+				break;
+			}
+
+			unsigned int type = *ev->params;
+
+			switch (type) {
+			case WA_TRIGGER_USBAP_RXTERM:
+				int ret = qcusb4_usbap_rxterm_wa(qcusb4);
+
+				if (ret)
+					dev_err(dev, "Failed to execute RXTERM workaround\n");
+				break;
+			default:
+				dev_err(qcusb4->nhi.dev, "unknown firmware workaround %u\n",
+					*ev->params);
+				break;
+			}
+			break;
+		case FW_MSG_HOST_RESET:
+			if (!is_usb4v2(qcusb4))
+				break;
+
+			/* TODO: assert GCC_USB4_HRR_BCR for 100 us */
+			qcusb4_fw_cmd(qcusb4, FW_CMD_HRR_DONE, 0);
+			break;
+		case FW_MSG_CHAINED_HOTPLUG:
+		case FW_MSG_HSE_STATS:
+		case FW_MSG_FOM_STATS:
+			/* Ignore */
+			break;
+		default:
+			dev_notice(qcusb4->nhi.dev, "Unknown firmware message opcode 0x%x\n",
+				   ev->opcode);
+			break;
+		}
+
+		if (qcusb4->next_fw_ev_idx >= qcusb4->fw_ev_total_entry_num)
+			qcusb4->next_fw_ev_idx -= qcusb4->fw_ev_total_entry_num;
+	}
+
+	return IRQ_HANDLED;
+}
+
+#define rcdev_to_qcusb4(rcdev)	container_of(rcdev, struct qcom_usb4, rcdev)
+static void qcusb4_pcie_sync_rst_apply(struct qcom_usb4 *qcusb4)
+{
+	u32 val;
+
+	lockdep_assert_held(&qcusb4->rst_lock);
+
+	val = readl(qcusb4->pcie_cfg + PCIEAP_CONFIG_SYNC_RST);
+	if (qcusb4->pcie_rst_asserted)
+		val |= PCIEAP_SYNC_RST_PCIE;
+	else
+		val &= ~PCIEAP_SYNC_RST_PCIE;
+	writel(val, qcusb4->pcie_cfg + PCIEAP_CONFIG_SYNC_RST);
+
+	udelay(5);
+
+	if (is_usb4v2(qcusb4)) {
+		val = readl(qcusb4->pcie_ap + PCIEAP_TX_CFG);
+		val |= PCIEAP_TX_CFG_EN_FLUSH_MISSING_SOP;
+		writel(val, qcusb4->pcie_ap + PCIEAP_TX_CFG);
+	}
+}
+
+static int __qcusb4_pcie_sync_rst_set(struct qcom_usb4 *qcusb4, bool assert)
+{
+	guard(mutex)(&qcusb4->rst_lock);
+
+	qcusb4->pcie_rst_asserted = assert;
+
+	/*
+	 * The AP registers are unclocked while the router sleeps, and accessing them then
+	 * hard-resets the SoC. In that case the request is only recorded, and applied by
+	 * qcusb4_power_up() before the router is handed back.
+	 */
+	if (qcusb4->mmio_ok)
+		qcusb4_pcie_sync_rst_apply(qcusb4);
+
+	return 0;
+}
+
+static int qcusb4_pcie_sync_rst_assert(struct reset_controller_dev *rcdev,
+				       unsigned long id)
+{
+	return __qcusb4_pcie_sync_rst_set(rcdev_to_qcusb4(rcdev), true);
+}
+
+static int qcusb4_pcie_sync_rst_deassert(struct reset_controller_dev *rcdev,
+					 unsigned long id)
+{
+	return __qcusb4_pcie_sync_rst_set(rcdev_to_qcusb4(rcdev), false);
+}
+
+static const struct reset_control_ops qcusb4_pcie_sync_rst_ops = {
+	.assert = qcusb4_pcie_sync_rst_assert,
+	.deassert = qcusb4_pcie_sync_rst_deassert,
+};
+
+static irqreturn_t qcom_usb4_pcie_ap_irq_handler(int irq, void *data)
+{
+	struct qcom_usb4 *qcusb4 = data;
+	u32 val;
+
+	val = readl(qcusb4->pcie_cfg + PCIEAP_CONFIG_IRQ_STATUS);
+	writel(val, qcusb4->pcie_cfg + PCIEAP_CONFIG_IRQ_CLEAR);
+
+	return IRQ_HANDLED;
+}
+
+static int qcom_usb4_get_mmio_regions(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	struct platform_device *pdev = to_platform_device(dev);
+	struct resource *res;
+
+	qcusb4->router_cs = devm_platform_ioremap_resource_byname(pdev, "router_cs");
+	if (IS_ERR(qcusb4->router_cs))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->router_cs),
+				     "Couldn't get router_cs region\n");
+
+	qcusb4->port_group = devm_platform_ioremap_resource_byname(pdev, "port_group");
+	if (IS_ERR(qcusb4->port_group))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->port_group),
+				     "Couldn't get port_group region\n");
+
+	qcusb4->pcie_cfg = devm_platform_ioremap_resource_byname(pdev, "pcie_cfg");
+	if (IS_ERR(qcusb4->pcie_cfg))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->pcie_cfg),
+				     "Couldn't get pcie_cfg region\n");
+
+	qcusb4->pcie_ap = devm_platform_ioremap_resource_byname(pdev, "pcie");
+	if (IS_ERR(qcusb4->pcie_ap))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->pcie_ap),
+				     "Couldn't get pcie region\n");
+
+	qcusb4->sideband = devm_platform_ioremap_resource_byname(pdev, "sideband");
+	if (IS_ERR(qcusb4->sideband))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->sideband),
+				     "Couldn't get sideband region\n");
+
+	qcusb4->usb_cfg = devm_platform_ioremap_resource_byname(pdev, "usb_cfg");
+	if (IS_ERR(qcusb4->usb_cfg))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->usb_cfg),
+				     "Couldn't get usb_cfg region\n");
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uc_ram");
+	if (!res)
+		return dev_err_probe(dev, -EINVAL, "Couldn't get uc_ram region\n");
+
+	qcusb4->uc_ram = devm_ioremap_resource(dev, res);
+	if (IS_ERR(qcusb4->uc_ram))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->uc_ram),
+				     "Couldn't get uc_ram region\n");
+	qcusb4->uc_ram_size = resource_size(res);
+
+	qcusb4->router_cfg = devm_platform_ioremap_resource_byname(pdev, "router_cfg");
+	if (IS_ERR(qcusb4->router_cfg))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->router_cfg),
+				     "Couldn't get router_cfg region\n");
+
+	qcusb4->uc_per = devm_platform_ioremap_resource_byname(pdev, "uc_per");
+	if (IS_ERR(qcusb4->uc_per))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->uc_per),
+				     "Couldn't get uc_per region\n");
+
+	qcusb4->lane0_cs = devm_platform_ioremap_resource_byname(pdev, "lane0_cs");
+	if (IS_ERR(qcusb4->lane0_cs))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->lane0_cs),
+				     "Couldn't get lane0_cs region\n");
+
+	qcusb4->cfg = devm_platform_ioremap_resource_byname(pdev, "cfg");
+	if (IS_ERR(qcusb4->cfg))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->cfg),
+				     "Couldn't get cfg region\n");
+
+	qcusb4->tcsr_usb4_mode = syscon_regmap_lookup_by_phandle_args(dev->of_node,
+								      "qcom,usb4-mode-sel",
+								      ARRAY_SIZE(qcusb4->tcsr_args),
+								      qcusb4->tcsr_args);
+	if (IS_ERR(qcusb4->tcsr_usb4_mode)) {
+		int ret = PTR_ERR(qcusb4->tcsr_usb4_mode);
+
+		dev_err(dev, "failed to lookup TCSR handle: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+#define USB_VID_QCOM		0x05c6
+static int qcom_usb4_setup_drom(struct qcom_usb4 *qcusb4)
+{
+	struct qcom_usb4_drom drom = { };
+	u32 uuid_hi, uuid_lo;
+
+	uuid_hi = FIELD_PREP(GENMASK(31, 16), USB_VID_QCOM) |
+		  FIELD_PREP(GENMASK(15, 0), (FIELD_GET(GENMASK(31, 28), qcusb4->chip_serial_no)));
+	uuid_lo = FIELD_PREP(GENMASK(31, 4), FIELD_GET(GENMASK(27, 0), qcusb4->chip_serial_no)) |
+		  FIELD_PREP(GENMASK(3, 0), qcusb4->instance_idx);
+
+	/* Set up the controller UUID */
+	writel(uuid_hi, qcusb4->router_cfg + ROUTER_CONFIG_CS_7);
+	writel(uuid_lo, qcusb4->router_cfg + ROUTER_CONFIG_CS_8);
+
+	/* Fill out the DROM */
+	drom.uuid = FIELD_PREP(GENMASK(63, 32), uuid_hi) |
+		    FIELD_PREP(GENMASK(31, 0), uuid_lo);
+
+	drom.tbt3.len = 0x67;
+	drom.tbt3.ver = 1;
+	drom.tbt3.vendor_id = 0x0328;
+
+	drom.dp0.len = 5;
+	drom.dp0.details.adapter_number = 6;
+	drom.dp0.details.disabled = 0;
+	drom.dp0.details.entry = 1;
+	drom.dp0.lane_adapter = 0;
+
+	drom.dp1.len = 5;
+	drom.dp1.details.adapter_number = 7;
+	drom.dp1.details.disabled = 0;
+	drom.dp1.details.entry = 1;
+	drom.dp1.lane_adapter = 0;
+
+	drom.lane0.len = 8;
+	drom.lane0.details.adapter_number = 2;
+	drom.lane0.details.disabled = 0;
+	drom.lane0.details.entry = 1;
+	drom.lane0.dual_lane = 0x80;
+	drom.lane0.secondary_adapter = 3;
+
+	drom.lane1.len = 8;
+	drom.lane1.details.adapter_number = 3;
+	drom.lane1.details.disabled = 0;
+	drom.lane1.details.entry = 1;
+	drom.lane1.dual_lane = 0x90;
+	drom.lane1.secondary_adapter = 2;
+
+	drom.pcie.len = 3;
+	drom.pcie.details.adapter_number = 4;
+	drom.pcie.details.disabled = 0;
+	drom.pcie.details.entry = 1;
+	drom.pcie.bus_func = 0;
+
+	drom.vendor.len = 0x1e;
+	drom.vendor.details.type = 1;
+	strscpy(drom.vendor.name, "Qualcomm Technologies, Inc.", sizeof(drom.vendor.name));
+
+	drom.model.len = 0x11;
+	drom.model.details.type = 2;
+	strscpy(drom.model.name, "Snapdragon 01A", sizeof(drom.model.name));
+
+	drom.tmu.len = 3;
+	drom.tmu.details.type = 8;
+	drom.tmu.mode = 6;
+
+	drom.product_descriptor.len = 0x0f;
+	drom.product_descriptor.details.type = 9;
+	drom.product_descriptor.usb_spec_ver = 0x410; /* USB4 v1.0 */
+	drom.product_descriptor.vendor_id = USB_VID_QCOM;
+	drom.product_descriptor.product_id = 0x0938;
+	drom.product_descriptor.tid = qcusb4->match_data->drom_tid;
+
+	/* Calculate some checksums */
+	drom.tbt3.crc32 = tb_crc32(&drom.tbt3.ver,
+				   sizeof(drom) - offsetof(struct qcom_usb4_drom, tbt3.ver));
+	drom.crc8 = tb_crc8((unsigned char *)&drom.uuid, 8);
+
+	/* Push it to the uC */
+	memcpy_toio(qcusb4->uc_ram + UC_RAM_DROM_OFFSET(qcusb4), &drom, sizeof(drom));
+
+	return 0;
+}
+
+static int qcom_usb4_load_firmware(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	const struct firmware *fw __free(firmware) = NULL;
+	const u8 *data, *end;
+	const char *firmware_name;
+	int ret;
+
+	ret = device_property_read_string(dev, "firmware-name", &firmware_name);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't read firmware-name\n");
+
+	ret = request_firmware_direct(&fw, firmware_name, dev);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't get firmware\n");
+
+	/*
+	 * The image is a sequence of { u32 offset; u32 size; u32 data[size]; } segments, with
+	 * the offset in bytes into the uC RAM and the size in dwords.
+	 */
+	data = fw->data;
+	end = fw->data + fw->size;
+
+	while (data < end) {
+		size_t seg_bytes, seg_end;
+		u32 offset, seg_size;
+
+		if (end - data < 2 * sizeof(u32))
+			return dev_err_probe(dev, -EINVAL, "Truncated firmware segment header\n");
+
+		offset = get_unaligned_le32(data);
+		seg_size = get_unaligned_le32(data + sizeof(u32));
+		data += 2 * sizeof(u32);
+
+		if (offset % sizeof(u32))
+			return dev_err_probe(dev, -EINVAL,
+					     "Firmware has a non-aligned segment, bailing out\n");
+
+		if (check_mul_overflow((size_t)seg_size, sizeof(u32), &seg_bytes) ||
+		    seg_bytes > end - data)
+			return dev_err_probe(dev, -EINVAL, "Segment references OOB data\n");
+
+		if (check_add_overflow((size_t)offset, seg_bytes, &seg_end) ||
+		    seg_end > qcusb4->uc_ram_size)
+			return dev_err_probe(dev, -EINVAL,
+					     "Firmware contains data outside uC RAM boundaries\n");
+
+		memcpy_toio(qcusb4->uc_ram + offset, data, seg_bytes);
+
+		data += seg_bytes;
+	}
+
+	return qcom_usb4_setup_drom(qcusb4);
+}
+
+static int qcusb4_tcsr_config(struct qcom_usb4 *qcusb4, bool usb4_mode)
+{
+	int ret;
+
+	ret = regmap_assign_bits(qcusb4->tcsr_usb4_mode,
+				 qcusb4->tcsr_args[0],
+				 BIT(qcusb4->tcsr_args[1]),
+				 usb4_mode);
+	if (ret < 0)
+		dev_err(qcusb4->nhi.dev, "failed to set USB4_MODE: %d\n", ret);
+
+	return ret;
+}
+
+static int qcusb4_clks_enable(struct qcom_usb4 *qcusb4)
+{
+	int ret;
+
+	ret = clk_bulk_prepare_enable(NUM_CLKS, qcusb4->clks);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(qcusb4->hrr_clk);
+	if (ret)
+		clk_bulk_disable_unprepare(NUM_CLKS, qcusb4->clks);
+
+	return ret;
+}
+
+static void qcusb4_clks_disable(struct qcom_usb4 *qcusb4)
+{
+	clk_disable_unprepare(qcusb4->hrr_clk);
+	clk_bulk_disable_unprepare(NUM_CLKS, qcusb4->clks);
+}
+
+static void qcusb4_restore_router_state(struct qcom_usb4 *qcusb4)
+{
+	/* Spec 4.5.2 - Restore the non-persistent registers */
+	u32 router_cs_1 = readl(qcusb4->router_cs + ROUTER_CS_CS_1);
+	u32 router_cs_5 = readl(qcusb4->router_cs + ROUTER_CS_CS_5);
+	u32 lane0_cs_19 = readl(qcusb4->lane0_cs + LANEn_CS_CS_19(qcusb4));
+	u32 val;
+
+	FIELD_MODIFY(ROUTER_CS_1_UA, &router_cs_1,
+		     FIELD_GET(ROUTER_CS_1_UA, qcusb4->router_cs_1_val));
+
+	FIELD_MODIFY(ROUTER_CS_5_WOU, &router_cs_5,
+		     FIELD_GET(ROUTER_CS_5_WOU, qcusb4->router_cs_5_val));
+	FIELD_MODIFY(ROUTER_CS_5_WOP, &router_cs_5,
+		     FIELD_GET(ROUTER_CS_5_WOP, qcusb4->router_cs_5_val));
+
+	FIELD_MODIFY(PORT_CS_19_WOID, &lane0_cs_19,
+		     FIELD_GET(PORT_CS_19_WOID, qcusb4->lane0_cs_19_val));
+	FIELD_MODIFY(PORT_CS_19_WOD, &lane0_cs_19,
+		     FIELD_GET(PORT_CS_19_WOD, qcusb4->lane0_cs_19_val));
+	FIELD_MODIFY(PORT_CS_19_WOC, &lane0_cs_19,
+		     FIELD_GET(PORT_CS_19_WOC, qcusb4->lane0_cs_19_val));
+	FIELD_MODIFY(PORT_CS_19_PID, &lane0_cs_19,
+		     FIELD_GET(PORT_CS_19_PID, qcusb4->lane0_cs_19_val));
+	FIELD_MODIFY(PORT_CS_19_PC, &lane0_cs_19,
+		     FIELD_GET(PORT_CS_19_PC, qcusb4->lane0_cs_19_val));
+
+	writel(router_cs_1, qcusb4->router_cs + ROUTER_CS_CS_1);
+	writel(router_cs_5, qcusb4->router_cs + ROUTER_CS_CS_5);
+	writel(lane0_cs_19, qcusb4->lane0_cs + LANEn_CS_CS_19(qcusb4));
+
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_RXTERM_BACKDOOR_CTRL);
+	FIELD_MODIFY(RXTERM_RX_TERM, &val, qcusb4->last_lfps_state);
+	writel(val, qcusb4->usb_cfg + USBAP_CFG_RXTERM_BACKDOOR_CTRL);
+}
+
+static int qcusb4_prepare_phy(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	int ret;
+
+	ret = qcusb4_tcsr_config(qcusb4, true);
+	if (ret)
+		return ret;
+
+	/* Instruct the USB3 adapter to enter USB4 mode */
+	writel(BIT(0), qcusb4->usb_cfg + USBAP_CFG_USB4_MODE);
+
+	ret = phy_init(qcusb4->phy);
+	if (ret) {
+		dev_err(dev, "PHY init failed: %d\n", ret);
+		goto err_tcsr;
+	}
+
+	ret = phy_power_on(qcusb4->phy);
+	if (ret) {
+		dev_err(dev, "PHY power on failed: %d\n", ret);
+		goto err_phy_exit;
+	}
+
+	ret = qcusb4_select_rx_clock_source(qcusb4, true);
+	if (ret)
+		goto err_phy_off;
+
+	return 0;
+
+err_phy_off:
+	phy_power_off(qcusb4->phy);
+err_phy_exit:
+	phy_exit(qcusb4->phy);
+err_tcsr:
+	qcusb4_tcsr_config(qcusb4, false);
+
+	return ret;
+}
+
+/* Take the PHY over from USB3/DP. The router must be up (IDLE or waking up) */
+static int qcusb4_acquire_phy(struct qcom_usb4 *qcusb4, const struct qcusb4_link_req *req)
+{
+	int ret;
+
+	ret = phy_set_mode_ext(qcusb4->phy, PHY_MODE_TBT, req->phy_submode);
+	if (ret) {
+		dev_err(qcusb4->nhi.dev, "PHY set_mode failed: %d\n", ret);
+		return ret;
+	}
+
+	return qcusb4_prepare_phy(qcusb4);
+}
+
+/* Hand the PHY back, allowing a USB3(+DP)-native mode switch. The router stays up on XO */
+static void qcusb4_release_phy(struct qcom_usb4 *qcusb4)
+{
+	qcusb4_select_rx_clock_source(qcusb4, false);
+
+	phy_power_off(qcusb4->phy);
+
+	/*
+	 * phy_exit() brings the PHY up in USB3 mode, which times out with the TCSR still routing
+	 * it to the router. Switch it over the same way qcusb4_enter_sleep() does.
+	 */
+	qcusb4_tcsr_config(qcusb4, false);
+
+	phy_exit(qcusb4->phy);
+}
+
+static void qcusb4_clear_router_ready(struct qcom_usb4 *qcusb4)
+{
+	u32 val;
+
+	val = readl(qcusb4->router_cfg + ROUTER_CONFIG_CS_6);
+	writel(val & ~CS_6_ROUTER_READY, qcusb4->router_cfg + ROUTER_CONFIG_CS_6);
+	/* Ensure we don't lose the race against the actual "ready" write from uC FW.. */
+	readl(qcusb4->router_cfg + ROUTER_CONFIG_CS_6);
+}
+
+static int qcusb4_usb3_adapter_reset(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	int ret;
+
+	writel(RST_USB3_RST, qcusb4->usb_cfg + USBAP_CFG_SYNC_RST_USB3);
+	usleep_range(1000, 1100);
+
+	ret = reset_control_assert(qcusb4->usb_pipe_reset);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't assert usb_pipe reset\n");
+	usleep_range(1000, 1100);
+
+	/* Ensure the USB3 controller receives phyStatus from the adapter */
+	writel(PHYSTATUS_EN_EN, qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+
+	ret = reset_control_deassert(qcusb4->usb_pipe_reset);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't deassert usb_pipe reset\n");
+
+	writel(0, qcusb4->usb_cfg + USBAP_CFG_SYNC_RST_USB3);
+	usleep_range(1000, 1100);
+
+	return 0;
+}
+
+/* Cold-boot-only configuration, the uC RAM and these registers are retained across sleep */
+static int qcusb4_router_cold_init(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	u32 val;
+	int ret;
+
+	/* Disable sideband TX (may take some attempts..) */
+	for (int i = 10; i > 0; i--) {
+		val = readl(qcusb4->sideband + SIDEBAND_TX_CTRL);
+		writel(val & ~SB_TX_CTRL_TX_ENABLE, qcusb4->sideband + SIDEBAND_TX_CTRL);
+
+		val = readl(qcusb4->sideband + SIDEBAND_TX_CTRL);
+		if (!(val & SB_TX_CTRL_TX_ENABLE))
+			break;
+
+		udelay(1);
+	}
+	fsleep(10 * USEC_PER_MSEC);
+
+	/* This also sets up the UUID and the DROM */
+	ret = qcom_usb4_load_firmware(qcusb4);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't load USB4 firmware\n");
+
+	/* Disable all CLx low power states */
+	val = readl(qcusb4->port_group + PORT_GROUP_LANE_CFG);
+	val &= ~LANE_CFG_CLx_SUPPORT(qcusb4);
+	writel(val, qcusb4->port_group + PORT_GROUP_LANE_CFG);
+
+	/* Credit allocation fixup */
+	val = readl(qcusb4->port_group + PORT_GROUP_FCM_2_CFG);
+	writel(val & ~FCM_2_CFG_DIS_ANY_HOPID, qcusb4->port_group + PORT_GROUP_FCM_2_CFG);
+
+	return 0;
+}
+
+/*
+ * The one bring-up sequence, shared between probe (@cold, from OFF) and sleep exit (from ASLEEP).
+ * @link: whether the PHY is ours, i.e. ASLEEP was entered from LINK. Leaves the router running
+ * with the uC accepting commands, the caller sets the resulting state.
+ */
+static int qcusb4_power_up(struct qcom_usb4 *qcusb4, bool cold, bool link)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	u32 val;
+	int ret;
+
+	if (cold) {
+		/* The master clock runs at 19.2 MHz OOTB, give it some more. */
+		ret = dev_pm_opp_set_level(dev, 3);
+		if (ret)
+			return ret;
+
+		/* Make sure the misc resets are released before the clocks come up */
+		ret = reset_control_bulk_deassert(NUM_MISC_RESETS, qcusb4->misc_resets);
+		if (ret) {
+			dev_err_probe(dev, ret, "Couldn't deassert misc resets\n");
+			goto err_drop_opp;
+		}
+	}
+
+	if (link) {
+		ret = qcusb4_tcsr_config(qcusb4, true);
+		if (ret)
+			goto err_drop_opp;
+	}
+
+	ret = qcusb4_clks_enable(qcusb4);
+	if (ret) {
+		dev_err_probe(dev, ret, "Couldn't enable clocks\n");
+		goto err_tcsr;
+	}
+
+	if (cold) {
+		ret = clk_bulk_prepare_enable(NUM_MUX_CLKS, qcusb4->mux_clks);
+		if (ret) {
+			dev_err_probe(dev, ret, "Couldn't enable mux clocks\n");
+			goto err_clks;
+		}
+
+		/* The PHY isn't running yet */
+		ret = qcusb4_select_rx_clock_source(qcusb4, false);
+		if (ret)
+			goto err_mux_clks;
+	}
+
+	/*
+	 * Un-clamp the PHY I/Os first. The PHY itself keeps its configuration across sleep
+	 * and is not reprogrammed.
+	 */
+	if (link) {
+		ret = phy_power_on(qcusb4->phy);
+		if (ret) {
+			dev_err_probe(dev, ret, "Couldn't power on the PHY\n");
+			goto err_mux_clks;
+		}
+	}
+
+	if (cold) {
+		ret = reset_control_assert(qcusb4->core_reset);
+		if (ret) {
+			dev_err_probe(dev, ret, "Couldn't assert core reset\n");
+			goto err_phy;
+		}
+
+		usleep_range(100, 200);
+
+		ret = reset_control_deassert(qcusb4->core_reset);
+		if (ret) {
+			dev_err_probe(dev, ret, "Couldn't deassert core reset\n");
+			goto err_phy;
+		}
+
+		ret = pinctrl_select_state(qcusb4->pinctrl, qcusb4->pinctrl_active);
+		if (ret) {
+			dev_err_probe(dev, ret, "Couldn't set pinctrl active state\n");
+			goto err_phy;
+		}
+	} else {
+		ret = reset_control_bulk_assert(NUM_MISC_RESETS, qcusb4->misc_resets);
+		if (ret) {
+			dev_err_probe(dev, ret, "Couldn't assert misc resets\n");
+			goto err_phy;
+		}
+
+		usleep_range(100, 200);
+
+		ret = reset_control_bulk_deassert(NUM_MISC_RESETS, qcusb4->misc_resets);
+		if (ret) {
+			dev_err_probe(dev, ret, "Couldn't deassert misc resets\n");
+			goto err_phy;
+		}
+
+		if (link) {
+			ret = qcusb4_select_rx_clock_source(qcusb4, true);
+			if (ret)
+				goto err_phy;
+		}
+	}
+
+	ret = qcusb4_usb3_adapter_reset(qcusb4);
+	if (ret)
+		goto err_pinctrl;
+
+	scoped_guard(mutex, &qcusb4->rst_lock) {
+		qcusb4->mmio_ok = true;
+
+		/* Apply whatever the PCIe controller asked for while the router was asleep */
+		if (!cold)
+			qcusb4_pcie_sync_rst_apply(qcusb4);
+	}
+
+	if (cold) {
+		ret = qcusb4_router_cold_init(qcusb4);
+		if (ret)
+			goto err_mmio;
+	}
+
+	qcusb4_clear_router_ready(qcusb4);
+
+	/* Enable the uC */
+	val = readl(qcusb4->uc_per + UC_PER_CONTROL);
+	writel(val | PER_CONTROL_UC_ENABLE, qcusb4->uc_per + UC_PER_CONTROL);
+
+	ret = readl_poll_timeout(qcusb4->uc_per, val, (val & BIT(3)), 100, 100 * USEC_PER_MSEC);
+	if (ret) {
+		val = readl(qcusb4->uc_per);
+		dev_err_probe(dev, ret, "USB4 uC failed to initialize: 0x%08x\n", val);
+		goto err_uc;
+	}
+
+	ret = readl_poll_timeout(qcusb4->router_cfg + ROUTER_CONFIG_CS_6, val,
+				 val & CS_6_ROUTER_READY, 5 * USEC_PER_MSEC,
+				 USEC_PER_SEC);
+	if (ret) {
+		val = readl(qcusb4->router_cfg + ROUTER_CONFIG_CS_6);
+		dev_err_probe(dev, ret, "USB4 router failed to initialize: 0x%08x\n", val);
+		goto err_uc;
+	}
+
+	enable_irq(qcusb4->fw_ev_irq);
+
+	/* Unmask the firmware interrupt */
+	val = readl(qcusb4->uc_per + UC_PER_FW_INT_MASK);
+	writel(val | PER_FW_INT_MASK_FW_INT, qcusb4->uc_per + UC_PER_FW_INT_MASK);
+
+	/* Unmask PCIe AP interrupts */
+	val = readl(qcusb4->pcie_cfg + PCIEAP_CONFIG_IRQ_MASK);
+	writel(val | PCIEAP_IRQ_PE_DEASSERT | PCIEAP_IRQ_PE_ASSERT,
+	       qcusb4->pcie_cfg + PCIEAP_CONFIG_IRQ_MASK);
+
+	enable_irq(qcusb4->pcieap_irq);
+
+	scoped_guard(mutex, &qcusb4->uc_cmd_lock)
+		qcusb4->uc_online = true;
+
+	qcusb4_fw_cmd(qcusb4, FW_CMD_LIMIT_LOGLEVEL, LOG_LEVEL_WARN);
+
+	return 0;
+
+err_uc:
+	val = readl(qcusb4->uc_per + UC_PER_CONTROL);
+	writel(val & ~PER_CONTROL_UC_ENABLE, qcusb4->uc_per + UC_PER_CONTROL);
+err_mmio:
+	scoped_guard(mutex, &qcusb4->rst_lock)
+		qcusb4->mmio_ok = false;
+err_pinctrl:
+	if (cold)
+		pinctrl_select_state(qcusb4->pinctrl, qcusb4->pinctrl_inactive);
+err_phy:
+	/* Keep the PHY refcounts balanced for the next resume attempt or remove */
+	if (link)
+		phy_power_off(qcusb4->phy);
+err_mux_clks:
+	if (cold)
+		clk_bulk_disable_unprepare(NUM_MUX_CLKS, qcusb4->mux_clks);
+err_clks:
+	qcusb4_clks_disable(qcusb4);
+err_tcsr:
+	if (link)
+		qcusb4_tcsr_config(qcusb4, false);
+err_drop_opp:
+	if (cold)
+		dev_pm_opp_set_opp(dev, NULL);
+
+	return ret;
+}
+
+/* Stop the uC and the IRQs that talk to it, the router stays clocked */
+static void qcusb4_halt_uc(struct qcom_usb4 *qcusb4)
+{
+	u32 val;
+
+	disable_irq(qcusb4->pcieap_irq);
+	disable_irq(qcusb4->fw_ev_irq);
+
+	/* Mask the firmware interrupt */
+	val = readl(qcusb4->uc_per + UC_PER_FW_INT_MASK);
+	writel(val & ~PER_FW_INT_MASK_FW_INT, qcusb4->uc_per + UC_PER_FW_INT_MASK);
+
+	/* Disable the uC */
+	val = readl(qcusb4->uc_per + UC_PER_CONTROL);
+	writel(val & ~PER_CONTROL_UC_ENABLE, qcusb4->uc_per + UC_PER_CONTROL);
+}
+
+/* IDLE/LINK -> OFF, for remove and the probe error path */
+static void qcusb4_power_off(struct qcom_usb4 *qcusb4)
+{
+	lockdep_assert_held(&qcusb4->state_lock);
+
+	if (WARN_ON(qcusb4->current_state != QCUSB4_IDLE && qcusb4->current_state != QCUSB4_LINK))
+		return;
+
+	scoped_guard(mutex, &qcusb4->uc_cmd_lock)
+		qcusb4->uc_online = false;
+
+	scoped_guard(mutex, &qcusb4->rst_lock)
+		qcusb4->mmio_ok = false;
+
+	qcusb4_halt_uc(qcusb4);
+
+	if (qcusb4->current_state == QCUSB4_LINK) {
+		qcusb4_select_rx_clock_source(qcusb4, false);
+		phy_power_off(qcusb4->phy);
+	}
+
+	/*
+	 * The SYS, DP and HRR clocks are sourced from the PHY, so they can only halt as long as it
+	 * hasn't been handed back. phy_exit() in turn needs the TCSR switched over, see
+	 * qcusb4_release_phy().
+	 */
+	clk_disable_unprepare(qcusb4->hrr_clk);
+	clk_bulk_disable_unprepare(NUM_MUX_CLKS, qcusb4->mux_clks);
+
+	if (qcusb4->current_state == QCUSB4_LINK) {
+		qcusb4_tcsr_config(qcusb4, false);
+		phy_exit(qcusb4->phy);
+	}
+
+	clk_bulk_disable_unprepare(NUM_CLKS, qcusb4->clks);
+
+	pinctrl_select_state(qcusb4->pinctrl, qcusb4->pinctrl_inactive);
+
+	dev_pm_opp_set_opp(qcusb4->nhi.dev, NULL);
+
+	qcusb4->current_state = QCUSB4_OFF;
+}
+
+static u32 qcusb4_begin_hse_args(struct qcom_usb4 *qcusb4, const struct qcusb4_link_req *req)
+{
+	u32 args = 0;
+
+	if (req->phy_submode == PHY_SUBMODE_USB4)
+		args |= BIT(0);
+
+	if (req->orientation == TYPEC_ORIENTATION_REVERSE)
+		args |= BIT(1);
+
+	/* TODO: do not set this bit if an onboard retimer (such as PS883x) is absent */
+	args |= BIT(2);
+
+	if (req->active_cable)
+		args |= BIT(3);
+
+	if (req->cable_legacy_tbt3)
+		args |= BIT(4);
+
+	if (req->cable_max_gen >= EUDO_CABLE_SPEED_USB4_GEN3)
+		args |= FIELD_PREP(GENMASK(6, 5), req->cable_max_gen - EUDO_CABLE_SPEED_USB4_GEN2);
+
+	return args;
+}
+
+/* Kick off link establishment, the PHY must already be ours */
+static int qcusb4_begin_hse(struct qcom_usb4 *qcusb4, const struct qcusb4_link_req *req)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	u64 tx_eq_presets;
+	int ret;
+
+	/* Choose which PHY presets to offer during link establishment */
+	if (device_property_read_u64(dev, "tx-equalization-presets", &tx_eq_presets))
+		tx_eq_presets = PHY_PRESETS_DEFAULT;
+
+	ret = qcusb4_fw_cmd(qcusb4, FW_CMD_ENABLE_PHY_PRESETS,
+			    FIELD_GET(GENMASK(23, 0), tx_eq_presets));
+	if (ret)
+		return ret;
+
+	if (is_usb4v2(qcusb4)) {
+		ret = qcusb4_fw_cmd(qcusb4, FW_CMD_ENABLE_PHY_PRESETS_MSB,
+				    FIELD_GET(GENMASK(41, 24), tx_eq_presets));
+		if (ret)
+			return ret;
+	}
+
+	return qcusb4_fw_cmd(qcusb4, FW_CMD_BEGIN_HSE, qcusb4_begin_hse_args(qcusb4, req));
+}
+
+static int qcusb4_idle_to_link(struct qcom_usb4 *qcusb4, const struct qcusb4_link_req *req)
+{
+	int ret;
+
+	lockdep_assert_held(&qcusb4->state_lock);
+
+	ret = qcusb4_acquire_phy(qcusb4, req);
+	if (ret)
+		return ret;
+
+	ret = qcusb4_begin_hse(qcusb4, req);
+	if (ret) {
+		qcusb4_release_phy(qcusb4);
+		return ret;
+	}
+
+	qcusb4->link = *req;
+	qcusb4->link_fw_gone = false;
+	qcusb4->current_state = QCUSB4_LINK;
+
+	return 0;
+}
+
+/* IDLE/LINK -> ASLEEP. Returns -EBUSY with the router still up if the FW won't go to sleep */
+static int qcusb4_enter_sleep(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	bool acked;
+	int ret;
+	u32 val;
+
+	lockdep_assert_held(&qcusb4->state_lock);
+
+	if (qcusb4->current_state == QCUSB4_ASLEEP)
+		return 0;
+
+	if (WARN_ON(qcusb4->current_state == QCUSB4_OFF))
+		return -EINVAL;
+
+	if (!wait_for_completion_timeout(&qcusb4->sleep_ready, msecs_to_jiffies(500))) {
+		dev_err(dev, "Router firmware didn't ack sleep readiness in time\n");
+		return -EBUSY;
+	}
+
+	/* Spec 4.5.2 - Save some non-persistent registers */
+	qcusb4->router_cs_1_val = readl(qcusb4->router_cs + ROUTER_CS_CS_1);
+	qcusb4->router_cs_5_val = readl(qcusb4->router_cs + ROUTER_CS_CS_5);
+	qcusb4->lane0_cs_19_val = readl(qcusb4->lane0_cs + LANEn_CS_CS_19(qcusb4));
+
+	/* Qualcomm-specific */
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_RXTERM_BACKDOOR_STS);
+	qcusb4->last_lfps_state = FIELD_GET(RXTERM_RX_TERM, val);
+
+	/* Mask phyStatus coming from USB3AP to the USB3 controller */
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+	writel(val & ~PHYSTATUS_EN_EN, qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+
+	scoped_guard(mutex, &qcusb4->uc_cmd_lock) {
+		reinit_completion(&qcusb4->sleep_acked);
+
+		ret = __qcusb4_fw_cmd(qcusb4, FW_CMD_COMPLETE_SLEEP, 0);
+		/* With a lot of printing, this may seemingly time out */
+		if (ret != -EAGAIN)
+			qcusb4->uc_online = false;
+	}
+	if (ret == -EAGAIN)
+		goto err_unmask;
+
+	acked = wait_for_completion_timeout(&qcusb4->sleep_acked, msecs_to_jiffies(3000));
+	if (!acked) {
+		/* The ack may still be queued up behind other FW events in the IRQ thread */
+		synchronize_irq(qcusb4->fw_ev_irq);
+		acked = try_wait_for_completion(&qcusb4->sleep_acked);
+	}
+
+	if (!acked) {
+		dev_err(dev, "Router firmware didn't ack sleep entry in time, STATUS=0x%08x\n",
+			readl(qcusb4->uc_per));
+
+		/*
+		 * Powering anything off now is what takes the platform down. Nothing has been
+		 * yet, so ask the FW to resume and fail the suspend instead.
+		 */
+		scoped_guard(mutex, &qcusb4->uc_cmd_lock) {
+			qcusb4->uc_online = true;
+			__qcusb4_fw_cmd(qcusb4, FW_CMD_WAKEUP, WAKEUP_REASON_SYSTEM);
+		}
+
+		ret = -EBUSY;
+		goto err_unmask;
+	}
+
+	scoped_guard(mutex, &qcusb4->rst_lock)
+		qcusb4->mmio_ok = false;
+
+	/*
+	 * Also keeps events from arriving after the clocks are disabled. The PCIe AP IRQ is
+	 * NO_SUSPEND and could otherwise fire on wake.
+	 */
+	qcusb4_halt_uc(qcusb4);
+
+	/*
+	 * The router is already down at this point and can't be brought back without a full
+	 * power_up, so carry on with the teardown even if the below fails.
+	 */
+	ret = qcusb4_select_rx_clock_source(qcusb4, false);
+	if (ret)
+		dev_warn(dev, "Couldn't move the RX clocks to XO: %d\n", ret);
+
+	/* The PHY stays initialized (and ours) across sleep, only its I/Os get clamped */
+	if (qcusb4->current_state == QCUSB4_LINK)
+		phy_power_off(qcusb4->phy);
+
+	ret = qcusb4_tcsr_config(qcusb4, false);
+	if (ret)
+		dev_warn(dev, "Couldn't switch the TCSR to sleep config: %d\n", ret);
+
+	qcusb4_clks_disable(qcusb4);
+
+	qcusb4->sleep_from = qcusb4->current_state;
+	qcusb4->current_state = QCUSB4_ASLEEP;
+
+	return 0;
+
+err_unmask:
+	val = readl(qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+	writel(val | PHYSTATUS_EN_EN, qcusb4->usb_cfg + USBAP_CFG_PHYSTATUS_EN);
+
+	return ret;
+}
+
+static struct qcusb4_link_req qcusb4_get_desired_state(struct qcom_usb4 *qcusb4)
+{
+	guard(mutex)(&qcusb4->typec_lock);
+
+	return qcusb4->desired_state;
+}
+
+/*
+ * ASLEEP/OFF -> IDLE. A FW woken up from sleep goes for the PHY it had, or for a cable plugged in
+ * meanwhile, and doing so without a PHY set up for it takes the SoC down. Have it start over
+ * without a PHY instead, same as on probe.
+ */
+static int qcusb4_restart_cold(struct qcom_usb4 *qcusb4)
+{
+	int ret;
+
+	if (qcusb4->current_state == QCUSB4_ASLEEP) {
+		clk_bulk_disable_unprepare(NUM_MUX_CLKS, qcusb4->mux_clks);
+		pinctrl_select_state(qcusb4->pinctrl, qcusb4->pinctrl_inactive);
+		qcusb4->current_state = QCUSB4_OFF;
+	}
+
+	/* The reloaded FW sets its event ring up from scratch */
+	qcusb4->fw_ev_rb_base = NULL;
+
+	ret = qcusb4_power_up(qcusb4, true, false);
+	if (ret)
+		return ret;
+
+	qcusb4->current_state = QCUSB4_IDLE;
+
+	return 0;
+}
+
+#define SLEEP_EXIT_CL0_MAX_RETRIES	500
+/* ASLEEP/OFF -> IDLE/LINK, the router is register-accessible afterwards unless this fails */
+static int qcusb4_exit_sleep(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	struct qcusb4_link_req req;
+	u8 wakeup_reason;
+	int ret;
+	u32 val;
+
+	lockdep_assert_held(&qcusb4->state_lock);
+
+	if (qcusb4->current_state != QCUSB4_ASLEEP && qcusb4->current_state != QCUSB4_OFF)
+		return 0;
+
+	/*
+	 * Without a PHY, a cable plugged in during sleep can't be woken up into: the Type-C side
+	 * may not even have reported it yet (it resumes later). Leave the link to the reconcile
+	 * work instead. A previously failed restart (OFF) is retried here as well.
+	 */
+	if (qcusb4->current_state == QCUSB4_OFF || qcusb4->sleep_from == QCUSB4_IDLE)
+		return qcusb4_restart_cold(qcusb4);
+
+	req = qcusb4_get_desired_state(qcusb4);
+
+	ret = qcusb4_power_up(qcusb4, false, true);
+	if (ret)
+		return ret;
+
+	val = readl(qcusb4->lane0_cs + LANEn_CS_CS_18(qcusb4));
+
+	if (val & PORT_CS_18_WOCS)
+		wakeup_reason = WAKEUP_REASON_CBL_CON;
+	else if (val & PORT_CS_18_WODS)
+		wakeup_reason = WAKEUP_REASON_CBL_DIS;
+	else if (val & (PORT_CS_18_WOU4S | PORT_CS_18_WOIDS))
+		wakeup_reason = WAKEUP_REASON_DEVICE;
+	else
+		wakeup_reason = WAKEUP_REASON_SYSTEM;
+
+	/* Unplugged while asleep, don't have the FW run a handshake on a dead link */
+	if (!req.usb4)
+		wakeup_reason = WAKEUP_REASON_CBL_DIS;
+
+	qcusb4_restore_router_state(qcusb4);
+
+	ret = qcusb4_fw_cmd(qcusb4, FW_CMD_WAKEUP, wakeup_reason);
+	if (ret)
+		dev_warn(dev, "Couldn't send WAKEUP: %d\n", ret);
+
+	if (wakeup_reason != WAKEUP_REASON_CBL_DIS) {
+		/* Poll for CL0 entry as the uC carries out its resume */
+		for (int retries = 1; retries <= SLEEP_EXIT_CL0_MAX_RETRIES; retries++) {
+			val = readl(qcusb4->lane0_cs + LANEn_CS_CS_1(qcusb4));
+
+			if (FIELD_GET(LANEn_CS_CS_1_ADAPTER_STATE, val) == TB_PORT_UP)
+				break;
+
+			/* The cable might be unplugged unexpectedly */
+			if (!qcusb4_get_desired_state(qcusb4).usb4)
+				break;
+
+			fsleep(10 * USEC_PER_MSEC);
+
+			if (retries == SLEEP_EXIT_CL0_MAX_RETRIES)
+				dev_warn(dev, "Device hasn't re-entered CL0 after 5 seconds\n");
+		}
+	}
+
+	qcusb4->link_fw_gone = wakeup_reason == WAKEUP_REASON_CBL_DIS;
+	qcusb4->current_state = QCUSB4_LINK;
+
+	return 0;
+}
+
+static void qcusb4_link_to_idle(struct qcom_usb4 *qcusb4)
+{
+	struct device *dev = qcusb4->nhi.dev;
+	struct tb *tb = dev_get_drvdata(dev);
+	int ret;
+
+	lockdep_assert_held(&qcusb4->state_lock);
+
+	/* A sleep exit that found the cable gone has already sent WAKEUP(CBL_DIS) */
+	if (!qcusb4->link_fw_gone) {
+		ret = qcusb4_fw_cmd_wait(qcusb4, FW_CMD_PHYS_DISCONNECT, 0,
+					 &qcusb4->disconnect_acked, 500);
+		/* Carry on regardless, the PHY is about to be repurposed anyway */
+		if (ret)
+			dev_warn(dev, "Router firmware didn't ack cable disconnect: %d\n", ret);
+	}
+
+	/*
+	 * The FW keeps going for a while after acking the disconnect, and the PHY can only be
+	 * taken away from it through a full sleep handshake. COMPLETE_SLEEP in turn requires the
+	 * TBT layer to have put the host router to sleep (_SLP) first, so cycle the domain through
+	 * runtime sleep around handing the PHY back.
+	 */
+	ret = tb_domain_runtime_suspend(tb);
+	if (ret) {
+		dev_err(dev, "Couldn't suspend the domain after cable removal: %d\n", ret);
+		goto out_fw_gone;
+	}
+
+	ret = qcusb4_enter_sleep(qcusb4);
+	if (ret) {
+		/*
+		 * Having been asked to wake back up mid-sleep, the FW won't go through another
+		 * sleep handshake, so retrying from here only ever times out again. With the cable
+		 * gone there's nothing to preserve, so power the router off and start over.
+		 */
+		dev_err(dev, "Couldn't put the router to sleep after cable removal: %d, forcing a restart\n",
+			ret);
+		qcusb4_power_off(qcusb4);
+	} else {
+		phy_exit(qcusb4->phy);
+	}
+
+	qcusb4->link_fw_gone = false;
+
+	/* The PHY is in USB3 mode now, it mustn't be woken up into */
+	ret = qcusb4_restart_cold(qcusb4);
+	if (ret) {
+		dev_err(dev, "Couldn't restart the router after cable removal: %d\n", ret);
+		return;
+	}
+
+	/* The router has been reset, the TBT core finds the topology gone */
+	tb_domain_runtime_resume(tb);
+	return;
+
+out_fw_gone:
+	/*
+	 * Still in LINK, but the FW has already been told the cable is gone. The next reconcile
+	 * retries from the domain suspend, without another PHYS_DISCONNECT.
+	 */
+	qcusb4->link_fw_gone = true;
+}
+
+static int qcusb4_router_runtime_suspend(struct tb_nhi *nhi)
+{
+	struct qcom_usb4 *qcusb4 = container_of(nhi, struct qcom_usb4, nhi);
+
+	guard(mutex)(&qcusb4->state_lock);
+
+	return qcusb4_enter_sleep(qcusb4);
+}
+
+static int qcusb4_router_suspend_noirq(struct tb_nhi *nhi, bool wakeup)
+{
+	return qcusb4_router_runtime_suspend(nhi);
+}
+
+static int qcusb4_router_resume(struct tb_nhi *nhi)
+{
+	struct qcom_usb4 *qcusb4 = container_of(nhi, struct qcom_usb4, nhi);
+
+	guard(mutex)(&qcusb4->state_lock);
+
+	return qcusb4_exit_sleep(qcusb4);
+}
+
+/* Brings the hardware in line with what the Type-C side asked for */
+static void qcusb4_reconcile_work(struct work_struct *work)
+{
+	struct qcom_usb4 *qcusb4 = container_of(work, struct qcom_usb4, reconcile_work);
+	struct device *dev = qcusb4->nhi.dev;
+	struct qcusb4_link_req req;
+	int ret;
+
+	req = qcusb4_get_desired_state(qcusb4);
+
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret) {
+		dev_err(dev, "Couldn't resume the host router: %d\n", ret);
+		return;
+	}
+
+	scoped_guard(mutex, &qcusb4->state_lock) {
+		if (qcusb4->current_state == QCUSB4_IDLE && req.usb4) {
+			ret = qcusb4_idle_to_link(qcusb4, &req);
+			if (ret)
+				dev_err(dev, "Couldn't bring up the USB4 link: %d\n", ret);
+		} else if (qcusb4->current_state == QCUSB4_LINK && !req.usb4) {
+			qcusb4_link_to_idle(qcusb4);
+		}
+	}
+
+	pm_runtime_mark_last_busy(dev);
+	pm_runtime_put_autosuspend(dev);
+}
+
+static int qcom_usb4_sw_set(struct typec_switch_dev *sw,
+			    enum typec_orientation orientation)
+{
+	struct qcom_usb4 *qcusb4 = typec_switch_get_drvdata(sw);
+
+	guard(mutex)(&qcusb4->typec_lock);
+
+	qcusb4->desired_state.orientation = orientation;
+
+	return 0;
+}
+
+static int qcom_usb4_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state)
+{
+	struct qcom_usb4 *qcusb4 = typec_mux_get_drvdata(mux);
+	struct qcusb4_link_req req = { .usb4 = true };
+	struct typec_thunderbolt_data *tbt_data;
+	struct enter_usb_data *usb4_data;
+
+	guard(mutex)(&qcusb4->typec_lock);
+
+	if (state->alt && state->alt->svid == USB_TYPEC_TBT_SID) {
+		req.phy_submode = PHY_SUBMODE_TBT3;
+
+		tbt_data = state->data;
+
+		req.cable_max_gen = TBT_CABLE_SPEED(tbt_data->cable_mode);
+
+		if (FIELD_GET(TBT_CABLE_ACTIVE_PASSIVE, tbt_data->cable_mode)) {
+			req.active_cable = true;
+			req.cable_legacy_tbt3 = true;
+		}
+	} else if (state->mode == TYPEC_MODE_USB4) {
+		req.phy_submode = PHY_SUBMODE_USB4;
+
+		usb4_data = state->data;
+
+		req.cable_max_gen = FIELD_GET(EUDO_CABLE_SPEED_MASK, usb4_data->eudo);
+
+		/* Routers that aren't USB4 v2 can't go beyond Gen 3 regardless of the cable */
+		if (!is_usb4v2(qcusb4))
+			req.cable_max_gen = min(req.cable_max_gen, EUDO_CABLE_SPEED_USB4_GEN3);
+
+		if (FIELD_GET(EUDO_CABLE_TYPE_MASK, usb4_data->eudo) == EUDO_CABLE_TYPE_RE_TIMER)
+			req.active_cable = true;
+	} else if (state->mode == TYPEC_STATE_SAFE) {
+		/* SAFE may be transient, e.g. during DP altmode entry */
+		if (qcusb4->desired_state.orientation != TYPEC_ORIENTATION_NONE)
+			return 0;
+
+		/* The USB4 router still receives Type-C events even after it's disengaged */
+		if (!qcusb4->desired_state.usb4)
+			return 0;
+
+		req.usb4 = false;
+	} else {
+		/* Do nothing for e.g. DP altmode */
+		return 0;
+	}
+
+	req.orientation = qcusb4->desired_state.orientation;
+	qcusb4->desired_state = req;
+
+	/*
+	 * Only record the request here. Acting on it talks to the FW and reconfigures the PHY,
+	 * which must not interleave with a system suspend/resume, so it runs from a freezable
+	 * workqueue. That also keeps the long chain of typec_mux() calls short, as otherwise
+	 * the PAN_ACK will arrive too late and the FW will get confused (with the visible result
+	 * of that being repeated UCSI messages).
+	 */
+	if (qcusb4->reconcile_enabled)
+		queue_work(qcusb4->wq, &qcusb4->reconcile_work);
+
+	return 0;
+}
+
+static int qcusb4_ring_request_irq(struct tb_ring *ring, bool no_suspend)
+{
+	struct tb_nhi *nhi = ring->nhi;
+	struct qcom_usb4 *qcusb4 = container_of(nhi, struct qcom_usb4, nhi);
+
+	ring->irq = qcusb4->ring_irq;
+	ring->vector = 0;
+
+	return 0;
+}
+
+static void qcusb4_ring_release_irq(struct tb_ring *ring)
+{
+	ring->irq = 0;
+}
+
+static int qcusb4_init_interrupts(struct tb_nhi *nhi)
+{
+	struct qcom_usb4 *qcusb4 = container_of(nhi, struct qcom_usb4, nhi);
+	struct device *dev = qcusb4->nhi.dev;
+	int ret;
+
+	ret = devm_request_threaded_irq(dev, qcusb4->ring_irq, nhi_msi, nhi_msi_thread,
+					IRQF_ONESHOT | IRQF_NO_SUSPEND, "thunderbolt",
+					&qcusb4->nhi);
+	if (ret)
+		dev_err(dev, "failed to request IRQ: %d\n", ret);
+
+	return ret;
+}
+
+static void qcusb4_pre_switch_suspend(struct tb_nhi *nhi)
+{
+	struct qcom_usb4 *qcusb4 = container_of(nhi, struct qcom_usb4, nhi);
+
+	reinit_completion(&qcusb4->sleep_ready);
+}
+
+const struct tb_nhi_ops qcom_nhi_ops = {
+	.suspend_noirq = qcusb4_router_suspend_noirq,
+	.resume_noirq = qcusb4_router_resume,
+	.runtime_suspend = qcusb4_router_runtime_suspend,
+	.runtime_resume = qcusb4_router_resume,
+	.request_ring_irq = qcusb4_ring_request_irq,
+	.release_ring_irq = qcusb4_ring_release_irq,
+	.init_interrupts = qcusb4_init_interrupts,
+	.pre_switch_suspend = qcusb4_pre_switch_suspend,
+};
+
+static void qcom_usb4_clear_wake(void *data)
+{
+	struct device *dev = data;
+
+	dev_pm_clear_wake_irq(dev);
+}
+
+static void qcom_usb4_unregister_typec_mux(void *data)
+{
+	typec_mux_unregister(data);
+}
+
+static void qcom_usb4_unregister_typec_switch(void *data)
+{
+	typec_switch_unregister(data);
+}
+
+static void qcom_usb4_del_device_link(void *data)
+{
+	device_link_del(data);
+}
+
+static int qcom_usb4_attach_power_domains(struct qcom_usb4 *qcusb4)
+{
+	static const char * const usb4_pd_name[] = { "usb4" };
+	static const char * const pcie_pd_name[] = { "pcie" };
+	struct device *dev = qcusb4->nhi.dev;
+	const struct dev_pm_domain_attach_data usb4_pd_data = {
+		.pd_names = usb4_pd_name,
+		.num_pd_names = ARRAY_SIZE(usb4_pd_name),
+		.pd_flags = PD_FLAG_DEV_LINK_ON | PD_FLAG_REQUIRED_OPP,
+	};
+	const struct dev_pm_domain_attach_data pcie_pd_data = {
+		.pd_names = pcie_pd_name,
+		.num_pd_names = ARRAY_SIZE(pcie_pd_name),
+		.pd_flags = PD_FLAG_NO_DEV_LINK,
+	};
+	int ret;
+
+	if (dev->pm_domain)
+		return 0;
+
+	ret = devm_pm_domain_attach_list(dev, &usb4_pd_data,
+					 &qcusb4->usb4_pd);
+	if (ret < 0)
+		return dev_err_probe(dev, ret,
+				     "Couldn't attach USB4 power domain\n");
+	if (!ret)
+		return 0;
+
+	ret = devm_pm_domain_attach_list(dev, &pcie_pd_data,
+					 &qcusb4->pcie_pd);
+	if (ret < 0)
+		return dev_err_probe(dev, ret,
+				     "Couldn't attach PCIe power domain\n");
+	if (!ret)
+		return dev_err_probe(dev, -ENODEV,
+				     "PCIe power domain is missing\n");
+
+	qcusb4->pcie_pd_link = device_link_add(dev,
+					       qcusb4->pcie_pd->pd_devs[0],
+					       DL_FLAG_STATELESS);
+	if (!qcusb4->pcie_pd_link)
+		return dev_err_probe(dev, -EINVAL,
+				     "Couldn't link PCIe power domain\n");
+
+	return devm_add_action_or_reset(dev, qcom_usb4_del_device_link,
+					qcusb4->pcie_pd_link);
+}
+
+static int qcom_usb4_probe(struct platform_device *pdev)
+{
+	const struct qcom_usb4_match_data *match_data;
+	struct typec_switch_desc sw_desc = { };
+	struct typec_mux_desc mux_desc = { };
+	struct device *dev = &pdev->dev;
+	struct qcom_usb4 *qcusb4;
+	struct resource *res;
+	int wakeirq;
+	int ret;
+	int i;
+
+	/* SMEM is required to fetch the SoC serial number.. this shouldn't really ever fail */
+	if (!qcom_smem_is_available())
+		return -EPROBE_DEFER;
+
+	qcusb4 = devm_kzalloc(dev, sizeof(*qcusb4), GFP_KERNEL);
+	if (!qcusb4)
+		return -ENOMEM;
+
+	qcusb4->fw_events_buf = devm_kzalloc(dev, FW_EV_BUF_SIZE, GFP_KERNEL);
+	if (!qcusb4->fw_events_buf)
+		return -ENOMEM;
+
+	mutex_init(&qcusb4->rst_lock);
+	mutex_init(&qcusb4->state_lock);
+	mutex_init(&qcusb4->typec_lock);
+	mutex_init(&qcusb4->uc_cmd_lock);
+
+	qcusb4->current_state = QCUSB4_OFF;
+	qcusb4->desired_state.orientation = TYPEC_ORIENTATION_NONE;
+
+	init_completion(&qcusb4->disconnect_acked);
+	init_completion(&qcusb4->sleep_acked);
+	init_completion(&qcusb4->sleep_ready);
+
+	qcusb4->wq = devm_alloc_ordered_workqueue(dev, "qcusb4", WQ_FREEZABLE);
+	if (!qcusb4->wq)
+		return -ENOMEM;
+
+	ret = devm_work_autocancel(dev, &qcusb4->reconcile_work, qcusb4_reconcile_work);
+	if (ret)
+		return ret;
+
+	/* Everything sits behind an SMMU instance, always */
+	qcusb4->nhi.iommu_dma_protection = true;
+	qcusb4->nhi.dev = dev;
+
+	ret = qcom_usb4_attach_power_domains(qcusb4);
+	if (ret)
+		return ret;
+
+	qcusb4->nhi.iobase = devm_platform_ioremap_resource_byname(pdev, "nhi");
+	ret = PTR_ERR_OR_ZERO(qcusb4->nhi.iobase);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't get NHI region\n");
+
+	ret = qcom_usb4_get_mmio_regions(qcusb4);
+	if (ret)
+		return ret;
+
+	qcusb4->pinctrl = devm_pinctrl_get(dev);
+	if (IS_ERR(qcusb4->pinctrl))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->pinctrl),
+				     "Couldn't get pinctrl entries\n");
+
+	qcusb4->pinctrl_active = pinctrl_lookup_state(qcusb4->pinctrl, "default");
+	if (IS_ERR(qcusb4->pinctrl_active))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->pinctrl_active),
+				     "Couldn't get default pin state\n");
+
+	qcusb4->pinctrl_inactive = pinctrl_lookup_state(qcusb4->pinctrl, "reset");
+	if (IS_ERR(qcusb4->pinctrl_inactive))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->pinctrl_inactive),
+				     "Couldn't get reset pin state\n");
+
+	ret = pinctrl_select_state(qcusb4->pinctrl, qcusb4->pinctrl_inactive);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't set pinctrl reset state\n");
+
+	qcusb4->phy = devm_phy_get(dev, "usb4");
+	if (IS_ERR(qcusb4->phy))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->phy), "Couldn't get the USB4 phy\n");
+
+	/* NoC clocks ought to be enabled first */
+	qcusb4->clks[0].id = "noc_aggr_south";
+	qcusb4->clks[1].id = "noc_sys";
+	qcusb4->clks[2].id = "master";
+	qcusb4->clks[3].id = "tmu";
+	qcusb4->clks[4].id = "ahb";
+	qcusb4->clks[5].id = "axi";
+	qcusb4->clks[6].id = "sb";
+	qcusb4->clks[7].id = "pcie_pipe";
+	qcusb4->clks[8].id = "usb_pipe";
+	ret = devm_clk_bulk_get(dev, NUM_CLKS, qcusb4->clks);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Couldn't get clocks\n");
+
+	qcusb4->hrr_clk = devm_clk_get_optional(dev, "hrr");
+	if (IS_ERR(qcusb4->hrr_clk))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->hrr_clk),
+				     "Couldn't get the HRR clock\n");
+
+	qcusb4->mux_clks[0].id = "sys";
+	qcusb4->mux_clks[MUX_CLK_PHY_RX0].id = "phy_rx0";
+	qcusb4->mux_clks[MUX_CLK_PHY_RX1].id = "phy_rx1";
+	qcusb4->mux_clks[MUX_CLK_DP0].id = "dp0";
+	qcusb4->mux_clks[MUX_CLK_DP1].id = "dp1";
+	ret = devm_clk_bulk_get(dev, NUM_MUX_CLKS, qcusb4->mux_clks);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Couldn't get clocks\n");
+
+	qcusb4->core_reset = devm_reset_control_get_optional_exclusive(dev, "core");
+	if (IS_ERR(qcusb4->core_reset))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->core_reset),
+				     "Couldn't get core reset\n");
+
+	qcusb4->usb_pipe_reset = devm_reset_control_get_optional_exclusive(dev, "usb_pipe");
+	if (IS_ERR(qcusb4->usb_pipe_reset))
+		return dev_err_probe(dev, PTR_ERR(qcusb4->usb_pipe_reset),
+				     "Couldn't get usb_pipe reset\n");
+
+	qcusb4->misc_resets[0].id = "sys";
+	qcusb4->misc_resets[1].id = "rx0";
+	qcusb4->misc_resets[2].id = "rx1";
+	qcusb4->misc_resets[3].id = "pcie_pipe";
+	qcusb4->misc_resets[4].id = "tmu";
+	qcusb4->misc_resets[5].id = "hia_master";
+	qcusb4->misc_resets[6].id = "dp0";
+	qcusb4->misc_resets[7].id = "dp1";
+	ret = devm_reset_control_bulk_get_exclusive(dev, NUM_MISC_RESETS, qcusb4->misc_resets);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't get misc resets\n");
+
+	ret = dev_pm_opp_of_find_icc_paths(dev, NULL);
+	if (ret)
+		return ret;
+
+	ret = devm_pm_opp_set_clkname(dev, "master");
+	if (ret)
+		return ret;
+
+	ret = devm_pm_opp_of_add_table(dev);
+	if (ret)
+		return dev_err_probe(dev, ret, "Invalid OPP table\n");
+
+	qcusb4->nhi.ops = &qcom_nhi_ops;
+
+	/* All three rings share a single interrupt */
+	qcusb4->ring_irq = platform_get_irq_byname(pdev, "ring_data");
+	if (qcusb4->ring_irq < 0)
+		return qcusb4->ring_irq;
+
+	wakeirq = platform_get_irq_byname(pdev, "wake");
+	if (wakeirq < 0)
+		return wakeirq;
+
+	ret = dev_pm_set_dedicated_wake_irq(dev, wakeirq);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't set the wake interrupt\n");
+
+	ret = devm_add_action_or_reset(dev, qcom_usb4_clear_wake, dev);
+	if (ret)
+		return ret;
+
+	qcusb4->fw_ev_irq = platform_get_irq_byname(pdev, "fw");
+	if (qcusb4->fw_ev_irq < 0)
+		return dev_err_probe(dev, qcusb4->fw_ev_irq, "Couldn't get firmware interrupt");
+
+	ret = devm_request_threaded_irq(dev, qcusb4->fw_ev_irq, qcom_usb4_fw_irq_handler,
+					qcom_usb4_fw_irq_thread,
+					IRQF_NO_AUTOEN | IRQF_ONESHOT | IRQF_NO_SUSPEND,
+					"qcom_usb4_fw", qcusb4);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't request the firmware interrupt\n");
+
+	qcusb4->pcieap_irq = platform_get_irq_byname(pdev, "pcieap");
+	if (qcusb4->pcieap_irq < 0)
+		return qcusb4->pcieap_irq;
+
+	ret = devm_request_irq(dev, qcusb4->pcieap_irq, qcom_usb4_pcie_ap_irq_handler,
+			       IRQF_NO_AUTOEN | IRQF_NO_SUSPEND, "pcie_ap", qcusb4);
+	if (ret)
+		return ret;
+
+	/* For UUID setup */
+	ret = qcom_smem_get_serial_no(&qcusb4->chip_serial_no);
+	if (ret)
+		return dev_err_probe(dev, ret, "Couldn't get SoC serial number\n");
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
+	match_data = device_get_match_data(dev);
+	if (!match_data)
+		return dev_err_probe(dev, -EINVAL, "Missing match data for this compatible\n");
+
+	for (i = 0; i < match_data->num_entries; i++) {
+		if (match_data->entries[i].mmio_base == res->start) {
+			qcusb4->instance_idx = i;
+			qcusb4->match_data = match_data;
+			break;
+		}
+	}
+
+	if (i == match_data->num_entries)
+		return dev_err_probe(dev, -EINVAL, "Router not described in match data\n");
+
+	sw_desc.drvdata = qcusb4;
+	sw_desc.fwnode = dev_fwnode(dev);
+	sw_desc.set = qcom_usb4_sw_set;
+
+	qcusb4->typec_sw = typec_switch_register(dev, &sw_desc);
+	if (IS_ERR(qcusb4->typec_sw)) {
+		return dev_err_probe(dev, PTR_ERR(qcusb4->typec_sw),
+				     "Failed to register Type-C switch\n");
+	}
+
+	ret = devm_add_action_or_reset(dev, qcom_usb4_unregister_typec_switch,
+				       qcusb4->typec_sw);
+	if (ret)
+		return ret;
+
+	mux_desc.drvdata = qcusb4;
+	mux_desc.fwnode = dev_fwnode(dev);
+	mux_desc.set = qcom_usb4_mux_set;
+
+	qcusb4->typec_mux = typec_mux_register(dev, &mux_desc);
+	if (IS_ERR(qcusb4->typec_mux)) {
+		return dev_err_probe(dev, PTR_ERR(qcusb4->typec_mux),
+				     "Failed to register Type-C mux\n");
+	}
+
+	ret = devm_add_action_or_reset(dev, qcom_usb4_unregister_typec_mux,
+				       qcusb4->typec_mux);
+	if (ret)
+		return ret;
+
+	scoped_guard(mutex, &qcusb4->state_lock) {
+		ret = qcusb4_power_up(qcusb4, true, false);
+		if (!ret)
+			qcusb4->current_state = QCUSB4_IDLE;
+	}
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to initialize the USB4 host router\n");
+
+	/* pci.c copypasta */
+	pm_runtime_forbid(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	pm_runtime_get_noresume(dev);
+
+	ret = nhi_probe(&qcusb4->nhi);
+	if (ret) {
+		pm_runtime_put_noidle(dev);
+		pm_runtime_disable(dev);
+		pm_runtime_set_suspended(dev);
+
+		scoped_guard(mutex, &qcusb4->state_lock)
+			qcusb4_power_off(qcusb4);
+
+		return dev_err_probe(dev, ret, "NHI common probe failed\n");
+	}
+
+	qcusb4->rcdev.owner = THIS_MODULE;
+	qcusb4->rcdev.ops = &qcusb4_pcie_sync_rst_ops;
+	qcusb4->rcdev.of_node = dev->of_node;
+	qcusb4->rcdev.nr_resets = 1;
+	ret = devm_reset_controller_register(dev, &qcusb4->rcdev);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to register reset controller\n");
+
+	/* Act on whatever Type-C reported so far */
+	scoped_guard(mutex, &qcusb4->typec_lock) {
+		qcusb4->reconcile_enabled = true;
+		queue_work(qcusb4->wq, &qcusb4->reconcile_work);
+	}
+
+	return 0;
+}
+
+static void qcom_usb4_remove(struct platform_device *pdev)
+{
+	struct tb *tb = platform_get_drvdata(pdev);
+	struct device *dev = &pdev->dev;
+	struct qcom_usb4 *qcusb4;
+	struct tb_nhi *nhi;
+
+	if (!tb)
+		return;
+
+	nhi = tb->nhi;
+	qcusb4 = container_of(nhi, struct qcom_usb4, nhi);
+
+	devm_release_action(dev, qcom_usb4_unregister_typec_mux, qcusb4->typec_mux);
+	devm_release_action(dev, qcom_usb4_unregister_typec_switch, qcusb4->typec_sw);
+	devm_release_action(dev, devm_work_drop, &qcusb4->reconcile_work);
+
+	pm_runtime_get_sync(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
+	pm_runtime_forbid(&pdev->dev);
+
+	tb_domain_remove(tb);
+	nhi_shutdown(nhi);
+
+	guard(mutex)(&qcusb4->state_lock);
+
+	/* Only stays ASLEEP if the runtime resume above failed, nothing to do then */
+	if (qcusb4->current_state == QCUSB4_IDLE || qcusb4->current_state == QCUSB4_LINK)
+		qcusb4_power_off(qcusb4);
+}
+
+static const struct qcom_usb4_router_instance_data x1e80100_instances[] = {
+	[0] = { .mmio_base = 0x15600000, .usb4v2_capable = false },
+	[1] = { .mmio_base = 0x15700000, .usb4v2_capable = false },
+	[2] = { .mmio_base = 0x15500000, .usb4v2_capable = false },
+};
+
+static const struct qcom_usb4_router_instance_data glymur_instances[] = {
+	[0] = { .mmio_base = 0x15600000, .usb4v2_capable = false },
+	[1] = { .mmio_base = 0x15800000, .usb4v2_capable = true },
+	[2] = { .mmio_base = 0x15700000, .usb4v2_capable = false },
+};
+
+static const struct qcom_usb4_match_data x1e80100_data = {
+	.entries = x1e80100_instances,
+	.num_entries = ARRAY_SIZE(x1e80100_instances),
+	.drom_tid = 0x2833,
+};
+
+static const struct qcom_usb4_match_data glymur_data = {
+	.entries = glymur_instances,
+	.num_entries = ARRAY_SIZE(glymur_instances),
+	.drom_tid = 0x34eb,
+};
+
+static const struct of_device_id qcom_usb4_of_match_table[] = {
+	{ .compatible = "qcom,x1e80100-usb4-hr", .data = &x1e80100_data },
+	{ .compatible = "qcom,glymur-usb4-hr", .data = &glymur_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, qcom_usb4_of_match_table);
+
+static struct platform_driver qcom_usb4_driver = {
+	.probe = qcom_usb4_probe,
+	.remove = qcom_usb4_remove,
+	.shutdown = qcom_usb4_remove,
+	.driver = {
+		.name = "qcom_usb4",
+		.of_match_table = qcom_usb4_of_match_table,
+		.pm = &nhi_pm_ops,
+	},
+};
+MODULE_DESCRIPTION("Qualcomm USB4 driver");
+MODULE_LICENSE("GPL");
+
+module_platform_driver(qcom_usb4_driver);
diff --git a/drivers/thunderbolt/qcom.h b/drivers/thunderbolt/qcom.h
new file mode 100644
index 0000000000000000000000000000000000000000..7665ddb7f0c95c129740364674d1371844c70831
--- /dev/null
+++ b/drivers/thunderbolt/qcom.h
@@ -0,0 +1,251 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#ifndef __USB4_QCOM_H__
+#define __USB4_QCOM_H__
+
+#include <linux/reset-controller.h>
+
+#define NUM_CLKS			9
+#define NUM_MUX_CLKS			5
+#define MUX_CLK_PHY_RX0			1
+#define MUX_CLK_PHY_RX1			2
+#define MUX_CLK_DP0			3
+#define MUX_CLK_DP1			4
+
+#define NUM_MISC_RESETS			8
+
+/*
+ * Each state implies what may be touched:
+ * OFF:    nothing is clocked
+ * IDLE:   router clocked off XO, uC running
+ * LINK:   PHY in USB4/TBT mode and owned by us, RX clocks sourced from it
+ * ASLEEP: COMPLETE_SLEEP acked, uC and clocks off
+ */
+enum qcusb4_hw_state {
+	QCUSB4_OFF,
+	QCUSB4_IDLE,
+	QCUSB4_LINK,
+	QCUSB4_ASLEEP,
+};
+
+/* What the Type-C side last asked for, consumed by the reconcile work */
+struct qcusb4_link_req {
+	bool usb4;
+	enum typec_orientation orientation;
+	enum tbt_phy_submode phy_submode;
+	bool active_cable;
+	bool cable_legacy_tbt3;
+	unsigned int cable_max_gen;
+};
+
+struct qcom_usb4 {
+	struct tb_nhi nhi;
+
+	/*
+	 * The USB4 PHY acts as a clocksource to parts of the router - it may only be disabled
+	 * after we receive FW_MSG_DISCONNECT or FW_MSG_SLEEP_DONE and must be re-enabled prior
+	 * to attempting any link establishment or maintenance operations.
+	 */
+	struct phy *phy;
+	struct typec_mux_dev *typec_mux;
+	struct typec_switch_dev *typec_sw;
+	u32 chip_serial_no;
+	u8 instance_idx;
+	const struct qcom_usb4_match_data *match_data;
+
+	int fw_ev_irq;
+	int ring_irq;
+	int pcieap_irq;
+
+	/* Shadowed standard registers */
+	void __iomem *router_cs;
+
+	/* Implementation-specific registers */
+	void __iomem *lane0_cs;
+	void __iomem *pcie_cfg;
+	void __iomem *port_group;
+	void __iomem *router_cfg;
+	void __iomem *sideband;
+	void __iomem *uc_per;
+	void __iomem *uc_ram;
+	size_t uc_ram_size;
+	void __iomem *usb_cfg;
+	void __iomem *cfg;
+	void __iomem *pcie_ap;
+	struct dev_pm_domain_list *usb4_pd;
+	struct dev_pm_domain_list *pcie_pd;
+	struct device_link *pcie_pd_link;
+
+	/* USB4_MODE toggle in TCSR */
+	struct regmap *tcsr_usb4_mode;
+	unsigned int tcsr_args[2];
+
+	struct clk_bulk_data clks[NUM_CLKS];
+	struct clk_bulk_data mux_clks[NUM_MUX_CLKS];
+	struct clk *hrr_clk;
+
+	struct reset_control *core_reset;
+	struct reset_control *usb_pipe_reset;
+	struct reset_control_bulk_data misc_resets[NUM_MISC_RESETS];
+	struct reset_controller_dev rcdev;
+	/* Protects mmio_ok and pcie_rst_asserted */
+	struct mutex rst_lock;
+	/* Set while the registers backing rcdev are clocked */
+	bool mmio_ok;
+	/* Last level requested through rcdev, replayed when the router comes back */
+	bool pcie_rst_asserted;
+
+	struct pinctrl *pinctrl;
+	struct pinctrl_state *pinctrl_active;
+	struct pinctrl_state *pinctrl_inactive;
+
+	u32 next_fw_ev_idx;
+	struct qcom_usb4_fw_events *fw_events_buf;
+	u16 fw_ev_total_entry_num;
+	u16 fw_ev_entry_size;
+	u32 fw_ev_ring_size;
+	void __iomem *fw_ev_rb_base;
+
+	/* Serializes all state transitions, protects current_state and sleep_from */
+	struct mutex state_lock;
+	enum qcusb4_hw_state current_state;
+	/* The state ASLEEP was entered from, i.e. whether the PHY is still ours */
+	enum qcusb4_hw_state sleep_from;
+
+	/* Protects desired_state and reconcile_enabled */
+	struct mutex typec_lock;
+	struct qcusb4_link_req desired_state;
+	bool reconcile_enabled;
+
+	/* Protects uc_online and serializes FW commands */
+	struct mutex uc_cmd_lock;
+	/* Set while the uC accepts commands */
+	bool uc_online;
+
+	struct completion disconnect_acked;
+	struct completion sleep_acked;
+	struct completion sleep_ready;
+
+	struct workqueue_struct *wq;
+	struct work_struct reconcile_work;
+	/* Cable properties of the current link, valid in LINK (and ASLEEP from LINK) */
+	struct qcusb4_link_req link;
+	/* In LINK: the FW was already told about the disconnect by WAKEUP(CBL_DIS) */
+	bool link_fw_gone;
+
+	/* Registers that need manual save-restore */
+	u32 router_cs_1_val;
+	u32 router_cs_5_val;
+	u32 lane0_cs_19_val;
+	u32 last_lfps_state;
+};
+
+struct qcom_usb4_router_instance_data {
+	u32 mmio_base;
+	bool usb4v2_capable;
+};
+
+struct qcom_usb4_match_data {
+	const struct qcom_usb4_router_instance_data * const entries;
+	const unsigned int num_entries;
+	u16 drom_tid;
+};
+
+struct drom_tbt3_hdr {
+	u32 crc32;
+	u8 ver;
+	/* Bits [15:12] are reserved */
+	u16 len;
+	u16 vendor_id;
+	u16 model_id;
+	u8 model_rev;
+	u8 nvm_rev;
+} __packed;
+
+struct drom_adp_details {
+	u8 adapter_number : 6;
+	u8 disabled : 1;
+	u8 entry : 1;
+} __packed;
+
+struct drom_entry_details {
+	u8 type : 6;
+	u8 res : 1;
+	u8 adp_entry : 1;
+} __packed;
+
+struct drom_dp_adp_hdr {
+	u8 len;
+	struct drom_adp_details details;
+	u16 res;
+	u8 lane_adapter;
+} __packed;
+
+struct drom_vendor_hdr {
+	u8 len;
+	struct drom_entry_details details;
+	char name[28];
+	// fn: 0-2
+	// 3-4 dev hi
+	// 5-7 dev_low
+} __packed;
+
+struct drom_model_hdr {
+	u8 len;
+	struct drom_entry_details details;
+	char name[15];
+	// fn: 0-2
+	// 3-4 dev hi
+	// 5-7 dev_low
+} __packed;
+
+struct drom_product_hdr {
+	u8 len;
+	struct drom_entry_details details;
+	u16 usb_spec_ver;
+	u16 vendor_id;
+	u16 product_id;
+	u16 product_fw_rev;
+	u32 tid;
+	u8 product_hw_rev;
+} __packed;
+
+struct drom_lane_adp_hdr {
+	u8 len;
+	struct drom_adp_details details;
+	u8 dual_lane;
+	u8 secondary_adapter;
+	u8 res[4];
+} __packed;
+
+struct drom_pcie_adp_hdr {
+	u8 len;
+	struct drom_adp_details details;
+	u8 bus_func;
+} __packed;
+
+struct drom_tmu_hdr {
+	u8 len;
+	struct drom_entry_details details;
+	u8 mode;
+} __packed;
+
+struct qcom_usb4_drom {
+	u8 crc8;
+	u64 uuid;
+	struct drom_tbt3_hdr tbt3;
+	struct drom_dp_adp_hdr dp0;
+	struct drom_dp_adp_hdr dp1;
+	struct drom_vendor_hdr vendor;
+	struct drom_model_hdr model;
+	struct drom_product_hdr product_descriptor;
+	struct drom_lane_adp_hdr lane0;
+	struct drom_lane_adp_hdr lane1;
+	struct drom_pcie_adp_hdr pcie;
+	struct drom_tmu_hdr tmu;
+} __packed;
+
+#endif
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index 8ed373e94b652f460c5fa553410c6ad5d3787989..374e4b7ef3c7e8886a8008b094bc11b9b1580c5a 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -9,6 +9,7 @@
 #ifndef TB_H_
 #define TB_H_
 
+#include <linux/crc32.h>
 #include <linux/debugfs.h>
 #include <linux/nvmem-provider.h>
 #include <linux/pci.h>
@@ -1330,6 +1331,25 @@ static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
 	return usb4_switch_version(sw) > 0;
 }
 
+static inline u8 tb_crc8(u8 *data, int len)
+{
+	int i, j;
+	u8 val = 0xff;
+
+	for (i = 0; i < len; i++) {
+		val ^= data[i];
+		for (j = 0; j < 8; j++)
+			val = (val << 1) ^ ((val & 0x80) ? 7 : 0);
+	}
+
+	return val;
+}
+
+static inline u32 tb_crc32(void *data, size_t len)
+{
+	return ~crc32c(~0, data, len);
+}
+
 void usb4_switch_check_wakes(struct tb_switch *sw);
 int usb4_switch_setup(struct tb_switch *sw);
 int usb4_switch_configuration_valid(struct tb_switch *sw);
diff --git a/drivers/thunderbolt/tb_regs.h b/drivers/thunderbolt/tb_regs.h
index 92d893634d2bc66b365b29ed42a8248659617b82..6149fcabad8b959502fb59fb94eec2d408f24474 100644
--- a/drivers/thunderbolt/tb_regs.h
+++ b/drivers/thunderbolt/tb_regs.h
@@ -193,6 +193,7 @@ struct tb_regs_switch_header {
 #define USB4_VERSION_MAJOR_MASK			GENMASK(7, 5)
 
 #define ROUTER_CS_1				0x01
+#define ROUTER_CS_1_UA				GENMASK(13, 8)
 #define ROUTER_CS_3				0x03
 #define ROUTER_CS_3_V				BIT(31)
 #define ROUTER_CS_4				0x04
@@ -388,6 +389,7 @@ struct tb_regs_port_header {
 #define PORT_CS_18_WOCS				BIT(16)
 #define PORT_CS_18_WODS				BIT(17)
 #define PORT_CS_18_WOU4S			BIT(18)
+#define PORT_CS_18_WOIDS			BIT(19)
 #define PORT_CS_18_CSA				BIT(22)
 #define PORT_CS_18_TIP				BIT(24)
 #define PORT_CS_19				0x13
@@ -397,6 +399,7 @@ struct tb_regs_port_header {
 #define PORT_CS_19_WOC				BIT(16)
 #define PORT_CS_19_WOD				BIT(17)
 #define PORT_CS_19_WOU4				BIT(18)
+#define PORT_CS_19_WOID				BIT(19)
 #define PORT_CS_19_START_ASYM			BIT(24)
 
 /* Display Port adapter registers */

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 14/15] arm64: dts: qcom: glymur: Add USB4 topology
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (12 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 13/15] thunderbolt: Introduce Qualcomm USB4 router driver Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  2026-11-24 20:01 ` [PATCH RFC DNM 15/15] arm64: dts: qcom: glymur-crd: Enable the tertiary Type-C Konrad Dybcio
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

Describe the USB4 PHY clocks, router, Type-C endpoints, PCIe tunnel
host interface, and tunneled DisplayPort resources on Glymur and the CRD.

Includes some work by Wesley Cheng.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 arch/arm64/boot/dts/qcom/glymur-crd.dtsi |  29 +-
 arch/arm64/boot/dts/qcom/glymur.dtsi     | 703 ++++++++++++++++++++++++++++++-
 2 files changed, 724 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
index 3a9cd5f3ec2b8629cba176f7beb1efce4aa9507d..53f134878b1934e8627678dd1d3b8b73ec91f308 100644
--- a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
+++ b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
@@ -87,13 +87,21 @@ pmic_glink_hs_in: endpoint {
 					};
 				};
 
-				port@1 {
-					reg = <1>;
+				port@2 {
+					reg = <2>;
 
 					pmic_glink_ss_in: endpoint {
 						remote-endpoint = <&usb_0_qmpphy_out>;
 					};
 				};
+
+				port@1 {
+					reg = <1>;
+
+					pmic_glink_usb4_in: endpoint {
+						remote-endpoint = <&usb4_0_mode_in>;
+					};
+				};
 			};
 		};
 
@@ -122,6 +130,14 @@ pmic_glink_ss_in1: endpoint {
 						remote-endpoint = <&usb_1_qmpphy_out>;
 					};
 				};
+
+				port@2 {
+					reg = <2>;
+
+					pmic_glink_usb4_in1: endpoint {
+						remote-endpoint = <&usb4_1_mode_in>;
+					};
+				};
 			};
 		};
 	};
@@ -974,6 +990,7 @@ wwan_reg_en: wwan-reg-en-state {
 		drive-strength = <2>;
 		bias-disable;
 	};
+
 };
 
 &uart14 {
@@ -993,6 +1010,14 @@ bluetooth {
 	};
 };
 
+&usb4_0_mode_in {
+	remote-endpoint = <&pmic_glink_usb4_in>;
+};
+
+&usb4_1_mode_in {
+	remote-endpoint = <&pmic_glink_usb4_in1>;
+};
+
 &usb_0 {
 	status = "okay";
 };
diff --git a/arch/arm64/boot/dts/qcom/glymur.dtsi b/arch/arm64/boot/dts/qcom/glymur.dtsi
index 419d57171b56a7f21c68481c53cabd6a609bac93..e8f5a3132487e9e4e187bca8fdc7fc039beb4d42 100644
--- a/arch/arm64/boot/dts/qcom/glymur.dtsi
+++ b/arch/arm64/boot/dts/qcom/glymur.dtsi
@@ -2572,11 +2572,13 @@ usb_0_qmpphy: phy@fd5000 {
 			clocks = <&gcc GCC_USB3_PRIM_PHY_AUX_CLK>,
 				 <&rpmhcc RPMH_CXO_CLK>,
 				 <&gcc GCC_USB3_PRIM_PHY_COM_AUX_CLK>,
-				 <&gcc GCC_USB3_PRIM_PHY_PIPE_CLK>;
+				 <&gcc GCC_USB3_PRIM_PHY_PIPE_CLK>,
+				 <&gcc GCC_USB4_0_PHY_P2RR2P_PIPE_CLK>;
 			clock-names = "aux",
 				      "ref",
 				      "com_aux",
-				      "usb3_pipe";
+				      "usb3_pipe",
+				      "p2rr2p_pipe";
 
 			resets = <&gcc GCC_USB3_PHY_PRIM_BCR>,
 				 <&gcc GCC_USB3PHY_PHY_PRIM_BCR>;
@@ -2645,11 +2647,13 @@ usb_1_qmpphy: phy@fde000 {
 			clocks = <&gcc GCC_USB3_SEC_PHY_AUX_CLK>,
 				 <&tcsr TCSR_USB4_1_CLKREF_EN>,
 				 <&gcc GCC_USB3_SEC_PHY_COM_AUX_CLK>,
-				 <&gcc GCC_USB3_SEC_PHY_PIPE_CLK>;
+				 <&gcc GCC_USB3_SEC_PHY_PIPE_CLK>,
+				 <&gcc GCC_USB4_1_PHY_P2RR2P_PIPE_CLK>;
 			clock-names = "aux",
 				      "ref",
 				      "com_aux",
-				      "usb3_pipe";
+				      "usb3_pipe",
+				      "p2rr2p_pipe";
 
 			power-domains = <&gcc GCC_USB_1_PHY_GDSC>;
 
@@ -4882,11 +4886,13 @@ usb_2_qmpphy: phy@88e1000 {
 			clocks = <&gcc GCC_USB3_TERT_PHY_AUX_CLK>,
 				 <&tcsr TCSR_USB4_2_CLKREF_EN>,
 				 <&gcc GCC_USB3_TERT_PHY_COM_AUX_CLK>,
-				 <&gcc GCC_USB3_TERT_PHY_PIPE_CLK>;
+				 <&gcc GCC_USB3_TERT_PHY_PIPE_CLK>,
+				 <&gcc GCC_USB4_2_PHY_P2RR2P_PIPE_CLK>;
 			clock-names = "aux",
 				      "ref",
 				      "com_aux",
-				      "usb3_pipe";
+				      "usb3_pipe",
+				      "p2rr2p_pipe";
 
 			power-domains = <&gcc GCC_USB_2_PHY_GDSC>;
 
@@ -4984,6 +4990,8 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>,
 			phy-names = "usb2-phy",
 				    "usb3-phy";
 
+			usb4-host-interface = <&usb4_router0>;
+
 			snps,hird-threshold = /bits/ 8 <0x0>;
 			snps,dis-u1-entry-quirk;
 			snps,dis-u2-entry-quirk;
@@ -5075,6 +5083,8 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>,
 			phy-names = "usb2-phy",
 				    "usb3-phy";
 
+			usb4-host-interface = <&usb4_router1>;
+
 			snps,hird-threshold = /bits/ 8 <0x0>;
 			snps,dis-u1-entry-quirk;
 			snps,dis-u2-entry-quirk;
@@ -5166,6 +5176,8 @@ &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>,
 			phy-names = "usb2-phy",
 				    "usb3-phy";
 
+			usb4-host-interface = <&usb4_router2>;
+
 			snps,hird-threshold = /bits/ 8 <0x0>;
 			snps,dis-u1-entry-quirk;
 			snps,dis-u2-entry-quirk;
@@ -6755,6 +6767,102 @@ rx-pins {
 				};
 			};
 
+			usb4_0_sbrx_active: usb4-0-sbrx-active-state {
+				pins = "gpio163";
+				function = "usb0_sbrx";
+				drive-strength = <10>;
+				output-disable;
+				input-enable;
+				bias-disable;
+			};
+
+			usb4_0_sbrx_reset: usb4-0-sbrx-reset-state {
+				pins = "gpio163";
+				function = "gpio";
+				drive-strength = <10>;
+				bias-pull-down;
+				output-disable;
+			};
+
+			usb4_0_sbtx_active: usb4-0-sbtx-active-state {
+				pins = "gpio164";
+				function = "usb0_sbtx";
+				drive-strength = <10>;
+				bias-pull-up;
+				output-disable;
+			};
+
+			usb4_0_sbtx_reset: usb4-0-sbtx-reset-state {
+				pins = "gpio164";
+				function = "gpio";
+				drive-strength = <10>;
+				output-low;
+			};
+
+			usb4_1_sbrx_active: usb4-1-sbrx-active-state {
+				pins = "gpio172";
+				function = "usb1_sbrx";
+				drive-strength = <10>;
+				output-disable;
+				input-enable;
+				bias-disable;
+			};
+
+			usb4_1_sbrx_reset: usb4-1-sbrx-reset-state {
+				pins = "gpio172";
+				function = "gpio";
+				drive-strength = <10>;
+				bias-pull-down;
+				output-disable;
+			};
+
+			usb4_1_sbtx_active: usb4-1-sbtx-active-state {
+				pins = "gpio173";
+				function = "usb1_sbtx";
+				drive-strength = <10>;
+				bias-pull-up;
+				output-disable;
+			};
+
+			usb4_1_sbtx_reset: usb4-1-sbtx-reset-state {
+				pins = "gpio173";
+				function = "gpio";
+				drive-strength = <10>;
+				output-low;
+			};
+
+			usb4_2_sbrx_active: usb4-2-sbrx-active-state {
+				pins = "gpio181";
+				function = "usb2_sbrx";
+				drive-strength = <10>;
+				output-disable;
+				input-enable;
+				bias-disable;
+			};
+
+			usb4_2_sbrx_reset: usb4-2-sbrx-reset-state {
+				pins = "gpio181";
+				function = "gpio";
+				drive-strength = <10>;
+				bias-pull-down;
+				output-disable;
+			};
+
+			usb4_2_sbtx_active: usb4-2-sbtx-active-state {
+				pins = "gpio182";
+				function = "usb2_sbtx";
+				drive-strength = <10>;
+				bias-pull-up;
+				output-disable;
+			};
+
+			usb4_2_sbtx_reset: usb4-2-sbtx-reset-state {
+				pins = "gpio182";
+				function = "gpio";
+				drive-strength = <10>;
+				output-low;
+			};
+
 			sdc2_default_state: sdc2-default-state {
 				clk-pins {
 					pins = "sdc2_clk";
@@ -8650,6 +8758,589 @@ cpu_scp_lpri1: scp-sram-section@180 {
 				reg = <0x180 0x180>;
 			};
 		};
+
+		usb4_router0: usb4-router@15600000 {
+			compatible = "qcom,glymur-usb4-hr";
+			reg = <0x0 0x15600000 0x0 0x70>,
+			      <0x0 0x15600070 0x0 0x500>,
+			      <0x0 0x15601000 0x0 0x1000>,
+			      <0x0 0x15602000 0x0 0x1000>,
+			      <0x0 0x15603000 0x0 0x1000>,
+			      <0x0 0x15604000 0x0 0x1000>,
+			      <0x0 0x15605000 0x0 0x1000>,
+			      <0x0 0x15606000 0x0 0x400>,
+			      <0x0 0x15606400 0x0 0xc00>,
+			      <0x0 0x15607000 0x0 0x400>,
+			      <0x0 0x15607400 0x0 0xc00>,
+			      <0x0 0x15608000 0x0 0x70>,
+			      <0x0 0x15608070 0x0 0x500>,
+			      <0x0 0x15609000 0x0 0x4000>,
+			      <0x0 0x1560d000 0x0 0x1000>,
+			      <0x0 0x1560e000 0x0 0x1000>,
+			      <0x0 0x1560f000 0x0 0x1000>,
+			      <0x0 0x15610000 0x0 0x800>,
+			      <0x0 0x15610800 0x0 0x800>,
+			      <0x0 0x15611000 0x0 0x1000>,
+			      <0x0 0x15612000 0x0 0x1000>,
+			      <0x0 0x15613000 0x0 0xe000>,
+			      <0x0 0x15621000 0x0 0x2000>,
+			      <0x0 0x15623000 0x0 0x2000>,
+			      <0x0 0x1563f000 0x0 0x40000>,
+			      <0x0 0x1567f000 0x0 0x1000>,
+			      <0x0 0x15680000 0x0 0x1000>,
+			      <0x0 0x15681000 0x0 0x1000>,
+			      <0x0 0x15682000 0x0 0x1000>;
+			reg-names = "router_cs",
+				    "tmu_cs",
+				    "hia_cs",
+				    "lane0_cs",
+				    "lane1_cs",
+				    "pcie_cs",
+				    "usb_cs",
+				    "dpin0_cs",
+				    "dpin0_path_cs",
+				    "dpin1_cs",
+				    "dpin1_path_cs",
+				    "router_cfg",
+				    "tmu_cfg",
+				    "hia",
+				    "port_group",
+				    "pcie",
+				    "usb",
+				    "cp",
+				    "cp_ram",
+				    "msgbus",
+				    "sideband",
+				    "uc_ram",
+				    "uc_per",
+				    "uc_mbox",
+				    "nhi",
+				    "cfg",
+				    "debug",
+				    "usb_cfg",
+				    "pcie_cfg";
+
+			interrupts-extended = <&intc GIC_SPI 70 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 450 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 121 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 71 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 142 IRQ_TYPE_LEVEL_HIGH>,
+					      <&pdc 91 IRQ_TYPE_EDGE_RISING>;
+			interrupt-names = "ring_data",
+					  "ring_ctrl",
+					  "fw",
+					  "pcieap",
+					  "clx_exit",
+					  "wake";
+
+			clocks = <&gcc GCC_USB4_0_MASTER_CLK>,
+				 <&gcc GCC_USB4_0_TMU_CLK>,
+				 <&gcc GCC_USB4_0_CFG_AHB_CLK>,
+				 <&gcc GCC_AGGRE_USB4_0_AXI_CLK>,
+				 <&gcc GCC_USB4_0_SB_IF_CLK>,
+				 <&gcc GCC_USB4_0_SYS_CLK>,
+				 <&gcc GCC_USB4_0_PHY_RX0_CLK>,
+				 <&gcc GCC_USB4_0_PHY_RX1_CLK>,
+				 <&gcc GCC_USB4_0_DP0_CLK>,
+				 <&gcc GCC_USB4_0_DP1_CLK>,
+				 <&gcc GCC_USB4_0_PHY_PCIE_PIPE_CLK>,
+				 <&gcc GCC_USB4_0_PHY_USB_PIPE_CLK>,
+				 <&gcc GCC_CFG_NOC_USB_ANOC_SOUTH_AHB_CLK>,
+				 <&gcc GCC_CFG_NOC_USB_ANOC_AHB_CLK>,
+				 <&gcc GCC_USB4_0_UC_HRR_CLK>;
+			clock-names = "master",
+				      "tmu",
+				      "ahb",
+				      "axi",
+				      "sb",
+				      "sys",
+				      "phy_rx0",
+				      "phy_rx1",
+				      "dp0",
+				      "dp1",
+				      "pcie_pipe",
+				      "usb_pipe",
+				      "noc_aggr_south",
+				      "noc_sys",
+				      "hrr";
+
+			assigned-clocks = <&gcc GCC_USB4_0_TMU_CLK>;
+			assigned-clock-rates = <250000000>;
+
+			resets = <&gcc GCC_USB4_0_BCR>,
+				 <&gcc GCC_USB4_0_MISC_USB4_SYS_BCR>,
+				 <&gcc GCC_USB4_0_MISC_RX_CLK_0_BCR>,
+				 <&gcc GCC_USB4_0_MISC_RX_CLK_1_BCR>,
+				 <&gcc GCC_USB4_0_MISC_USB_PIPE_BCR>,
+				 <&gcc GCC_USB4_0_MISC_PCIE_PIPE_BCR>,
+				 <&gcc GCC_USB4_0_MISC_TMU_BCR>,
+				 <&gcc GCC_USB4_0_MISC_SB_IF_BCR>,
+				 <&gcc GCC_USB4_0_MISC_HIA_MSTR_BCR>,
+				 <&gcc GCC_USB4_0_MISC_AHB_BCR>,
+				 <&gcc GCC_USB4_0_MISC_DP0_MAX_PCLK_BCR>,
+				 <&gcc GCC_USB4_0_MISC_DP1_MAX_PCLK_BCR>,
+				 <&gcc GCC_USB4_0_MISC_HRR_BCR>;
+			reset-names = "core",
+				      "sys",
+				      "rx0",
+				      "rx1",
+				      "usb_pipe",
+				      "pcie_pipe",
+				      "tmu",
+				      "sideband_iface",
+				      "hia_master",
+				      "ahb",
+				      "dp0",
+				      "dp1",
+				      "hrr";
+
+			power-domains = <&gcc GCC_USB4_0_GDSC>,
+					<&gcc GCC_PCIE_0_TUNNEL_GDSC>;
+			power-domain-names = "usb4",
+					     "pcie";
+
+			phys = <&usb_0_qmpphy QMP_USB43DP_USB4_PHY>;
+			phy-names = "usb4";
+			iommus = <&apps_smmu 0x1440 0x0>;
+			pinctrl-0 = <&usb4_0_sbrx_active>, <&usb4_0_sbtx_active>;
+			pinctrl-1 = <&usb4_0_sbrx_reset>, <&usb4_0_sbtx_reset>;
+			pinctrl-names = "default", "reset";
+			#reset-cells = <1>;
+
+			interconnects = <&aggre4_noc MASTER_USB4_0 QCOM_ICC_TAG_ALWAYS
+					 &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>,
+					<&system_noc MASTER_APPSS_PROC QCOM_ICC_TAG_ACTIVE_ONLY
+					 &config_noc SLAVE_USB4_0 QCOM_ICC_TAG_ACTIVE_ONLY>;
+			interconnect-names = "usb4-ddr",
+					     "apps-usb4";
+
+			operating-points-v2 = <&usb4_opp_table>;
+			orientation-switch;
+			mode-switch;
+
+			firmware-name = "qcom/glymur/usb4.bin";
+
+			tx-equalization-presets = /bits/ 64 <0x5ce7>;
+
+			qcom,usb4-mode-sel = <&tcsr 0xb004 0>;
+
+			ports {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				port@0 {
+					reg = <0>;
+
+					usb4_0_mode_in: endpoint {
+					};
+				};
+
+			};
+
+			usb4_opp_table: opp-table {
+				compatible = "operating-points-v2";
+
+				/* Gen3 */
+				opp-355333500 {
+					opp-hz = /bits/ 64 <355333500>;
+					required-opps = <&rpmhpd_opp_nom>;
+					opp-peak-kBps = <5000000 1>;
+					opp-level = <3>;
+				};
+
+				/* Gen2 */
+				opp-177666750 {
+					opp-hz = /bits/ 64 <177666750>;
+					required-opps = <&rpmhpd_opp_svs>;
+					opp-peak-kBps = <2500000 1>;
+					opp-level = <2>;
+				};
+			};
+		};
+
+		usb4_router1: usb4-router@15800000 {
+			compatible = "qcom,glymur-usb4-hr";
+			reg = <0x0 0x15800000 0x0 0x70>,
+			      <0x0 0x15800070 0x0 0x500>,
+			      <0x0 0x15801000 0x0 0x1000>,
+			      <0x0 0x15802000 0x0 0x1000>,
+			      <0x0 0x15803000 0x0 0x1000>,
+			      <0x0 0x15804000 0x0 0x1000>,
+			      <0x0 0x15805000 0x0 0x1000>,
+			      <0x0 0x15806000 0x0 0x400>,
+			      <0x0 0x15806400 0x0 0xc00>,
+			      <0x0 0x15807000 0x0 0x400>,
+			      <0x0 0x15807400 0x0 0xc00>,
+			      <0x0 0x15808000 0x0 0x70>,
+			      <0x0 0x15808070 0x0 0x500>,
+			      <0x0 0x15809000 0x0 0x4000>,
+			      <0x0 0x1580d000 0x0 0x1000>,
+			      <0x0 0x1580e000 0x0 0x1000>,
+			      <0x0 0x1580f000 0x0 0x1000>,
+			      <0x0 0x15810000 0x0 0x800>,
+			      <0x0 0x15810800 0x0 0x800>,
+			      <0x0 0x15811000 0x0 0x1000>,
+			      <0x0 0x15812000 0x0 0x1000>,
+			      <0x0 0x1581e000 0x0 0x10000>,
+			      <0x0 0x15813000 0x0 0x2000>,
+			      <0x0 0x15815000 0x0 0x1000>,
+			      <0x0 0x1583f000 0x0 0x39898>,
+			      <0x0 0x1587f000 0x0 0x1000>,
+			      <0x0 0x15880000 0x0 0x1000>,
+			      <0x0 0x15881000 0x0 0x1000>,
+			      <0x0 0x15882000 0x0 0x1000>;
+			reg-names = "router_cs",
+				    "tmu_cs",
+				    "hia_cs",
+				    "lane0_cs",
+				    "lane1_cs",
+				    "pcie_cs",
+				    "usb_cs",
+				    "dpin0_cs",
+				    "dpin0_path_cs",
+				    "dpin1_cs",
+				    "dpin1_path_cs",
+				    "router_cfg",
+				    "tmu_cfg",
+				    "hia",
+				    "port_group",
+				    "pcie",
+				    "usb",
+				    "cp",
+				    "cp_ram",
+				    "msgbus",
+				    "sideband",
+				    "uc_ram",
+				    "uc_per",
+				    "uc_mbox",
+				    "nhi",
+				    "cfg",
+				    "debug",
+				    "usb_cfg",
+				    "pcie_cfg";
+
+			interrupts-extended = <&intc GIC_SPI 736 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 735 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 941 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 853 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 427 IRQ_TYPE_LEVEL_HIGH>,
+					      <&pdc 80 IRQ_TYPE_EDGE_RISING>;
+			interrupt-names = "ring_data",
+					  "ring_ctrl",
+					  "fw",
+					  "pcieap",
+					  "clx_exit",
+					  "wake";
+
+			clocks = <&gcc GCC_USB4_1_MASTER_CLK>,
+				 <&gcc GCC_USB4_1_TMU_CLK>,
+				 <&gcc GCC_USB4_1_CFG_AHB_CLK>,
+				 <&gcc GCC_AGGRE_USB4_1_AXI_CLK>,
+				 <&gcc GCC_USB4_1_SB_IF_CLK>,
+				 <&gcc GCC_USB4_1_SYS_CLK>,
+				 <&gcc GCC_USB4_1_PHY_RX0_CLK>,
+				 <&gcc GCC_USB4_1_PHY_RX1_CLK>,
+				 <&gcc GCC_USB4_1_DP0_CLK>,
+				 <&gcc GCC_USB4_1_DP1_CLK>,
+				 <&gcc GCC_USB4_1_PHY_PCIE_PIPE_CLK>,
+				 <&gcc GCC_USB4_1_PHY_USB_PIPE_CLK>,
+				 <&gcc GCC_CFG_NOC_USB_ANOC_SOUTH_AHB_CLK>,
+				 <&gcc GCC_CFG_NOC_USB_ANOC_AHB_CLK>,
+				 <&gcc GCC_USB4_1_UC_HRR_CLK>;
+			clock-names = "master",
+				      "tmu",
+				      "ahb",
+				      "axi",
+				      "sb",
+				      "sys",
+				      "phy_rx0",
+				      "phy_rx1",
+				      "dp0",
+				      "dp1",
+				      "pcie_pipe",
+				      "usb_pipe",
+				      "noc_aggr_south",
+				      "noc_sys",
+				      "hrr";
+
+			assigned-clocks = <&gcc GCC_USB4_1_TMU_CLK>;
+			assigned-clock-rates = <250000000>;
+
+			resets = <&gcc GCC_USB4_1_BCR>,
+				 <&gcc GCC_USB4_1_MISC_USB4_SYS_BCR>,
+				 <&gcc GCC_USB4_1_MISC_RX_CLK_0_BCR>,
+				 <&gcc GCC_USB4_1_MISC_RX_CLK_1_BCR>,
+				 <&gcc GCC_USB4_1_MISC_USB_PIPE_BCR>,
+				 <&gcc GCC_USB4_1_MISC_PCIE_PIPE_BCR>,
+				 <&gcc GCC_USB4_1_MISC_TMU_BCR>,
+				 <&gcc GCC_USB4_1_MISC_SB_IF_BCR>,
+				 <&gcc GCC_USB4_1_MISC_HIA_MSTR_BCR>,
+				 <&gcc GCC_USB4_1_MISC_AHB_BCR>,
+				 <&gcc GCC_USB4_1_MISC_DP0_MAX_PCLK_BCR>,
+				 <&gcc GCC_USB4_1_MISC_DP1_MAX_PCLK_BCR>,
+				 <&gcc GCC_USB4_1_MISC_HRR_BCR>;
+			reset-names = "core",
+				      "sys",
+				      "rx0",
+				      "rx1",
+				      "usb_pipe",
+				      "pcie_pipe",
+				      "tmu",
+				      "sideband_iface",
+				      "hia_master",
+				      "ahb",
+				      "dp0",
+				      "dp1",
+				      "hrr";
+
+			power-domains = <&gcc GCC_USB4_1_GDSC>,
+					<&gcc GCC_PCIE_1_TUNNEL_GDSC>;
+			power-domain-names = "usb4",
+					     "pcie";
+
+			phys = <&usb_1_qmpphy QMP_USB43DP_USB4_PHY>;
+			phy-names = "usb4";
+			iommus = <&apps_smmu 0x1600 0x0>;
+			pinctrl-0 = <&usb4_1_sbrx_active>, <&usb4_1_sbtx_active>;
+			pinctrl-1 = <&usb4_1_sbrx_reset>, <&usb4_1_sbtx_reset>;
+			pinctrl-names = "default", "reset";
+			#reset-cells = <1>;
+
+			interconnects = <&aggre4_noc MASTER_USB4_1 QCOM_ICC_TAG_ALWAYS
+					 &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>,
+					<&system_noc MASTER_APPSS_PROC QCOM_ICC_TAG_ACTIVE_ONLY
+					 &config_noc SLAVE_USB4_1 QCOM_ICC_TAG_ACTIVE_ONLY>;
+			interconnect-names = "usb4-ddr",
+					     "apps-usb4";
+
+			operating-points-v2 = <&usb4_v2_opp_table>;
+			orientation-switch;
+			mode-switch;
+
+			firmware-name = "qcom/glymur/usb4_v2.bin";
+
+			tx-equalization-presets = /bits/ 64 <0x5ce7>;
+
+			qcom,usb4-mode-sel = <&tcsr 0xb004 1>;
+
+			ports {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				port@0 {
+					reg = <0>;
+
+					usb4_1_mode_in: endpoint {
+					};
+				};
+			};
+
+			usb4_v2_opp_table: opp-table {
+				compatible = "operating-points-v2";
+
+				/* Gen4 */
+				opp-355333500-gen4 {
+					opp-hz = /bits/ 64 <355333500>;
+					required-opps = <&rpmhpd_opp_nom>;
+					opp-peak-kBps = <10000000 1>;
+					opp-level = <4>;
+				};
+
+				/* Gen3 */
+				opp-355333500 {
+					opp-hz = /bits/ 64 <355333500>;
+					required-opps = <&rpmhpd_opp_nom>;
+					opp-peak-kBps = <5000000 1>;
+					opp-level = <3>;
+				};
+
+				/* Gen2 */
+				opp-177666750 {
+					opp-hz = /bits/ 64 <177666750>;
+					required-opps = <&rpmhpd_opp_svs>;
+					opp-peak-kBps = <2500000 1>;
+					opp-level = <2>;
+				};
+			};
+		};
+
+		usb4_router2: usb4-router@15700000 {
+			compatible = "qcom,glymur-usb4-hr";
+			reg = <0x0 0x15700000 0x0 0x70>,
+			      <0x0 0x15700070 0x0 0x500>,
+			      <0x0 0x15701000 0x0 0x1000>,
+			      <0x0 0x15702000 0x0 0x1000>,
+			      <0x0 0x15703000 0x0 0x1000>,
+			      <0x0 0x15704000 0x0 0x1000>,
+			      <0x0 0x15705000 0x0 0x1000>,
+			      <0x0 0x15706000 0x0 0x400>,
+			      <0x0 0x15706400 0x0 0xc00>,
+			      <0x0 0x15707000 0x0 0x400>,
+			      <0x0 0x15707400 0x0 0xc00>,
+			      <0x0 0x15708000 0x0 0x70>,
+			      <0x0 0x15708070 0x0 0x500>,
+			      <0x0 0x15709000 0x0 0x4000>,
+			      <0x0 0x1570d000 0x0 0x1000>,
+			      <0x0 0x1570e000 0x0 0x1000>,
+			      <0x0 0x1570f000 0x0 0x1000>,
+			      <0x0 0x15710000 0x0 0x800>,
+			      <0x0 0x15710800 0x0 0x800>,
+			      <0x0 0x15711000 0x0 0x1000>,
+			      <0x0 0x15712000 0x0 0x1000>,
+			      <0x0 0x15713000 0x0 0xe000>,
+			      <0x0 0x15721000 0x0 0x2000>,
+			      <0x0 0x15723000 0x0 0x2000>,
+			      <0x0 0x1573f000 0x0 0x40000>,
+			      <0x0 0x1577f000 0x0 0x1000>,
+			      <0x0 0x15780000 0x0 0x1000>,
+			      <0x0 0x15781000 0x0 0x1000>,
+			      <0x0 0x15782000 0x0 0x1000>;
+			reg-names = "router_cs",
+				    "tmu_cs",
+				    "hia_cs",
+				    "lane0_cs",
+				    "lane1_cs",
+				    "pcie_cs",
+				    "usb_cs",
+				    "dpin0_cs",
+				    "dpin0_path_cs",
+				    "dpin1_cs",
+				    "dpin1_path_cs",
+				    "router_cfg",
+				    "tmu_cfg",
+				    "hia",
+				    "port_group",
+				    "pcie",
+				    "usb",
+				    "cp",
+				    "cp_ram",
+				    "msgbus",
+				    "sideband",
+				    "uc_ram",
+				    "uc_per",
+				    "uc_mbox",
+				    "nhi",
+				    "cfg",
+				    "debug",
+				    "usb_cfg",
+				    "pcie_cfg";
+
+			interrupts-extended = <&intc GIC_SPI 452 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 453 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 940 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 854 IRQ_TYPE_LEVEL_HIGH>,
+					      <&intc GIC_SPI 417 IRQ_TYPE_LEVEL_HIGH>,
+					      <&pdc 79 IRQ_TYPE_EDGE_RISING>;
+			interrupt-names = "ring_data",
+					  "ring_ctrl",
+					  "fw",
+					  "pcieap",
+					  "clx_exit",
+					  "wake";
+
+			clocks = <&gcc GCC_USB4_2_MASTER_CLK>,
+				 <&gcc GCC_USB4_2_TMU_CLK>,
+				 <&gcc GCC_USB4_2_CFG_AHB_CLK>,
+				 <&gcc GCC_AGGRE_USB4_2_AXI_CLK>,
+				 <&gcc GCC_USB4_2_SB_IF_CLK>,
+				 <&gcc GCC_USB4_2_SYS_CLK>,
+				 <&gcc GCC_USB4_2_PHY_RX0_CLK>,
+				 <&gcc GCC_USB4_2_PHY_RX1_CLK>,
+				 <&gcc GCC_USB4_2_DP0_CLK>,
+				 <&gcc GCC_USB4_2_DP1_CLK>,
+				 <&gcc GCC_USB4_2_PHY_PCIE_PIPE_CLK>,
+				 <&gcc GCC_USB4_2_PHY_USB_PIPE_CLK>,
+				 <&gcc GCC_CFG_NOC_USB_ANOC_SOUTH_AHB_CLK>,
+				 <&gcc GCC_CFG_NOC_USB_ANOC_AHB_CLK>,
+				 <&gcc GCC_USB4_2_UC_HRR_CLK>;
+			clock-names = "master",
+				      "tmu",
+				      "ahb",
+				      "axi",
+				      "sb",
+				      "sys",
+				      "phy_rx0",
+				      "phy_rx1",
+				      "dp0",
+				      "dp1",
+				      "pcie_pipe",
+				      "usb_pipe",
+				      "noc_aggr_south",
+				      "noc_sys",
+				      "hrr";
+
+			assigned-clocks = <&gcc GCC_USB4_2_TMU_CLK>;
+			assigned-clock-rates = <250000000>;
+
+			resets = <&gcc GCC_USB4_2_BCR>,
+				 <&gcc GCC_USB4_2_MISC_USB4_SYS_BCR>,
+				 <&gcc GCC_USB4_2_MISC_RX_CLK_0_BCR>,
+				 <&gcc GCC_USB4_2_MISC_RX_CLK_1_BCR>,
+				 <&gcc GCC_USB4_2_MISC_USB_PIPE_BCR>,
+				 <&gcc GCC_USB4_2_MISC_PCIE_PIPE_BCR>,
+				 <&gcc GCC_USB4_2_MISC_TMU_BCR>,
+				 <&gcc GCC_USB4_2_MISC_SB_IF_BCR>,
+				 <&gcc GCC_USB4_2_MISC_HIA_MSTR_BCR>,
+				 <&gcc GCC_USB4_2_MISC_AHB_BCR>,
+				 <&gcc GCC_USB4_2_MISC_DP0_MAX_PCLK_BCR>,
+				 <&gcc GCC_USB4_2_MISC_DP1_MAX_PCLK_BCR>,
+				 <&gcc GCC_USB4_2_MISC_HRR_BCR>;
+			reset-names = "core",
+				      "sys",
+				      "rx0",
+				      "rx1",
+				      "usb_pipe",
+				      "pcie_pipe",
+				      "tmu",
+				      "sideband_iface",
+				      "hia_master",
+				      "ahb",
+				      "dp0",
+				      "dp1",
+				      "hrr";
+
+			power-domains = <&gcc GCC_USB4_2_GDSC>,
+					<&gcc GCC_PCIE_2_TUNNEL_GDSC>;
+			power-domain-names = "usb4",
+					     "pcie";
+
+			phys = <&usb_2_qmpphy QMP_USB43DP_USB4_PHY>;
+			phy-names = "usb4";
+			iommus = <&apps_smmu 0x440 0x0>;
+			pinctrl-0 = <&usb4_2_sbrx_active>, <&usb4_2_sbtx_active>;
+			pinctrl-1 = <&usb4_2_sbrx_reset>, <&usb4_2_sbtx_reset>;
+			pinctrl-names = "default", "reset";
+			#reset-cells = <1>;
+
+			interconnects = <&aggre2_noc MASTER_USB4_2 QCOM_ICC_TAG_ALWAYS
+					 &mc_virt SLAVE_EBI1 QCOM_ICC_TAG_ALWAYS>,
+					<&system_noc MASTER_APPSS_PROC QCOM_ICC_TAG_ACTIVE_ONLY
+					 &config_noc SLAVE_USB4_2 QCOM_ICC_TAG_ACTIVE_ONLY>;
+			interconnect-names = "usb4-ddr",
+					     "apps-usb4";
+
+			operating-points-v2 = <&usb4_opp_table>;
+			orientation-switch;
+			mode-switch;
+
+			firmware-name = "qcom/glymur/usb4.bin";
+
+			tx-equalization-presets = /bits/ 64 <0x5ce7>;
+
+			qcom,usb4-mode-sel = <&tcsr 0xb004 2>;
+
+			ports {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				port@0 {
+					reg = <0>;
+
+					usb4_2_mode_in: endpoint {
+					};
+				};
+			};
+		};
 	};
 
 	timer {

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH RFC DNM 15/15] arm64: dts: qcom: glymur-crd: Enable the tertiary Type-C
  2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
                   ` (13 preceding siblings ...)
  2026-11-24 20:01 ` [PATCH RFC DNM 14/15] arm64: dts: qcom: glymur: Add USB4 topology Konrad Dybcio
@ 2026-11-24 20:01 ` Konrad Dybcio
  14 siblings, 0 replies; 22+ messages in thread
From: Konrad Dybcio @ 2026-11-24 20:01 UTC (permalink / raw)
  To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-arm-msm, linux-phy, linux-clk, linux-usb, linux-kernel,
	devicetree, usb4-upstream, Konrad Dybcio

This is just for demonstration purposes for the series, a cleaner patch
handling 2xType-C + HDMI variants will come separately.

Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
 arch/arm64/boot/dts/qcom/glymur-crd.dtsi | 82 ++++++++++++++++++++++++++++++--
 1 file changed, 78 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
index 53f134878b1934e8627678dd1d3b8b73ec91f308..5d557d17ca29c4b379209815b2ffd426aaa0b093 100644
--- a/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
+++ b/arch/arm64/boot/dts/qcom/glymur-crd.dtsi
@@ -123,16 +123,16 @@ pmic_glink_hs_in1: endpoint {
 					};
 				};
 
-				port@1 {
-					reg = <1>;
+				port@2 {
+					reg = <2>;
 
 					pmic_glink_ss_in1: endpoint {
 						remote-endpoint = <&usb_1_qmpphy_out>;
 					};
 				};
 
-				port@2 {
-					reg = <2>;
+				port@1 {
+					reg = <1>;
 
 					pmic_glink_usb4_in1: endpoint {
 						remote-endpoint = <&usb4_1_mode_in>;
@@ -140,6 +140,42 @@ pmic_glink_usb4_in1: endpoint {
 				};
 			};
 		};
+
+		connector@2 {
+			compatible = "usb-c-connector";
+			reg = <2>;
+			power-role = "dual";
+			data-role = "dual";
+
+			ports {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				port@0 {
+					reg = <0>;
+
+					pmic_glink_hs_in2: endpoint {
+						remote-endpoint = <&usb_2_dwc3_hs>;
+					};
+				};
+
+				port@2 {
+					reg = <2>;
+
+					pmic_glink_ss_in2: endpoint {
+						remote-endpoint = <&usb_2_qmpphy_out>;
+					};
+				};
+
+				port@1 {
+					reg = <1>;
+
+					pmic_glink_usb4_in2: endpoint {
+						remote-endpoint = <&usb4_2_mode_in>;
+					};
+				};
+			};
+		};
 	};
 
 	vreg_edp_3p3: regulator-edp-3p3 {
@@ -563,6 +599,14 @@ &mdss_dp1_out {
 	link-frequencies = /bits/ 64 <1620000000 2700000000 5400000000 8100000000>;
 };
 
+&mdss_dp2 {
+	status = "okay";
+};
+
+&mdss_dp2_out {
+	link-frequencies = /bits/ 64 <1620000000 2700000000 5400000000 8100000000>;
+};
+
 &mdss_dp3 {
 	/delete-property/ #sound-dai-cells;
 
@@ -735,6 +779,10 @@ &remoteproc_cdsp {
 	status = "okay";
 };
 
+&smb2370_l_e2 {
+	status = "okay";
+};
+
 &sdhc_2 {
 	vmmc-supply = <&vreg_l9b0>;
 	vqmmc-supply = <&vreg_l2b0>;
@@ -1018,6 +1066,10 @@ &usb4_1_mode_in {
 	remote-endpoint = <&pmic_glink_usb4_in1>;
 };
 
+&usb4_2_mode_in {
+	remote-endpoint = <&pmic_glink_usb4_in2>;
+};
+
 &usb_0 {
 	status = "okay";
 };
@@ -1062,6 +1114,28 @@ &usb_1_qmpphy_out {
 	remote-endpoint = <&pmic_glink_ss_in1>;
 };
 
+&usb_2 {
+	status = "okay";
+};
+
+&usb_2_dwc3_hs {
+	remote-endpoint = <&pmic_glink_hs_in2>;
+};
+
+&usb_2_hsphy {
+	phys = <&smb2370_l_e2_eusb2_repeater>;
+
+	status = "okay";
+};
+
+&usb_2_qmpphy {
+	status = "okay";
+};
+
+&usb_2_qmpphy_out {
+	remote-endpoint = <&pmic_glink_ss_in2>;
+};
+
 &usb_hs {
 	dr_mode = "host";
 

-- 
2.55.0


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC DNM 13/15] thunderbolt: Introduce Qualcomm USB4 router driver
  2026-11-24 20:01 ` [PATCH RFC DNM 13/15] thunderbolt: Introduce Qualcomm USB4 router driver Konrad Dybcio
@ 2026-11-28 13:54   ` Troels Vognbjerg
  0 siblings, 0 replies; 22+ messages in thread
From: Troels Vognbjerg @ 2026-11-28 13:54 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-phy,
	linux-clk, linux-usb, linux-kernel, devicetree, usb4-upstream

On Tue, Nov 24, 2026 at 21:01:42 +0100, Konrad Dybcio wrote:
[..]
> +static int qcom_usb4_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state)
> +{
> +	struct qcom_usb4 *qcusb4 = typec_mux_get_drvdata(mux);
> +	struct qcusb4_link_req req = { .usb4 = true };
> +	struct typec_thunderbolt_data *tbt_data;
> +	struct enter_usb_data *usb4_data;
> +
> +	guard(mutex)(&qcusb4->typec_lock);
> +
> +	if (state->alt && state->alt->svid == USB_TYPEC_TBT_SID) {
> +		req.phy_submode = PHY_SUBMODE_TBT3;
> +
> +		tbt_data = state->data;
> +
> +		req.cable_max_gen = TBT_CABLE_SPEED(tbt_data->cable_mode);
> +
> +		if (FIELD_GET(TBT_CABLE_ACTIVE_PASSIVE, tbt_data->cable_mode)) {
> +			req.active_cable = true;
> +			req.cable_legacy_tbt3 = true;
> +		}
> +	} else if (state->mode == TYPEC_MODE_USB4) {

While testing this series on an ASUS Zenbook A16 (UX3607OA), I ran
into an issue with a USB type-c display using DP Alt Mode.

TYPEC_MODE_USB4 and TYPEC_DP_STATE_C share the same integer value,
causing a DP Alt Mode request to be interpreted as a USB4 request.

Changing the above condition to

	} else if (!state->alt && state->mode == TYPEC_MODE_USB4) {

fixes the issue. The display works again with both USB-C ports.


> +	} else {
> +		/* Do nothing for e.g. DP altmode */
> +		return 0;
> +	}

Regards,
Troels

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC DNM 06/15] thunderbolt: nhi: Clear ring interrupts when not using MSI-X
  2026-11-24 20:01 ` [PATCH RFC DNM 06/15] thunderbolt: nhi: Clear ring interrupts when not using MSI-X Konrad Dybcio
@ 2026-12-01  7:16   ` Mika Westerberg
  0 siblings, 0 replies; 22+ messages in thread
From: Mika Westerberg @ 2026-12-01  7:16 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-phy,
	linux-clk, linux-usb, linux-kernel, devicetree, usb4-upstream

Hi,

On Tue, Nov 24, 2026 at 09:01:35PM +0100, Konrad Dybcio wrote:
> Commit 468c49f44759 ("thunderbolt: Disable interrupt auto clear for
> rings") made the hardware stop clearing the ring interrupt status on
> read for all routers except Intel ones, and added an explicit write to
> REG_RING_INT_CLEAR to the MSI-X handler. The single-interrupt handler
> was not updated though, so for such routers the status bits are never
> cleared and the interrupt keeps firing.
> 
> Write back the bits that were found set in each notify register to
> REG_RING_INT_CLEAR, before handling the rings that they belong to.
> 
> Fixes: 468c49f44759 ("thunderbolt: Disable interrupt auto clear for rings")
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Applied to thunderbolt.git/next.

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC DNM 07/15] thunderbolt: nhi: Process ring completions in the threaded IRQ
  2026-11-24 20:01 ` [PATCH RFC DNM 07/15] thunderbolt: nhi: Process ring completions in the threaded IRQ Konrad Dybcio
@ 2026-12-01  7:33   ` Mika Westerberg
  0 siblings, 0 replies; 22+ messages in thread
From: Mika Westerberg @ 2026-12-01  7:33 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-phy,
	linux-clk, linux-usb, linux-kernel, devicetree, usb4-upstream

Hi,

On Tue, Nov 24, 2026 at 09:01:36PM +0100, Konrad Dybcio wrote:
> The Qualcomm USB4 router uses a shared IRQ for all NHI rings.
> Scheduling a work item from its threaded handler adds another delay
> before completed RX frames are consumed and replacement buffers are
> posted.
> 
> Process completed descriptors directly from the threaded IRQ instead.
> Harvest all completed frames while holding the NHI and ring locks,
> replenish RX rings immediately, then invoke frame callbacks after
> dropping the locks. Preserve the existing polling-ring path, which must
> continue to mask the interrupt and start polling instead.
> 
> This removes the workqueue round trip from the common IRQ path without
> calling ring consumers under NHI locking. Since the callbacks no longer
> run only from ring->work, have tb_ring_stop() and tb_ring_free()
> synchronize with the ring interrupt, so they keep returning only after
> all callbacks of the ring have finished.
> 
> Switch the single MSI fallback of the PCI glue over to the same threaded
> handler, which allows dropping nhi_interrupt_work() and the work item
> that backed it.

The MSI code can go. All the hardware supports MSI-X so that code path is
really not needed. I think the MediaTek folks are doing that already
though.

> Based on related work by Wesley Cheng.
> 
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> ---
>  drivers/thunderbolt/nhi.c   | 133 +++++++++++++++++++++++++++++++++++---------
>  drivers/thunderbolt/nhi.h   |   2 +-
>  drivers/thunderbolt/pci.c   |  15 ++---
>  include/linux/thunderbolt.h |   8 +--
>  4 files changed, 115 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
> index e48521482c021c7f5f73349ce16519d6088d3250..bcc2b959e3b1a6b014c13a4938ed6f68cb0d0fd8 100644
> --- a/drivers/thunderbolt/nhi.c
> +++ b/drivers/thunderbolt/nhi.c
> @@ -310,6 +310,41 @@ static void ring_write_descriptors(struct tb_ring *ring, bool notify)
>  		__ring_notify(ring);
>  }
>  
> +/*

Use /** for kernel doc

> + * ring_harvest() - collect completed frames
> + * @ring: Ring to collect the frames from
> + * @done: List to move the completed frames to
> + *
> + * Moves all completed frames from the ring buffer to @done and writes new
> + * frames to the ring buffer.
> + *
> + * ring->lock is held.

You can drop this comment if you have the lockdep_assert below.

> + */
> +static void ring_harvest(struct tb_ring *ring, struct list_head *done)
> +{
> +	struct ring_frame *frame;
> +
> +	lockdep_assert_held(&ring->lock);
> +
> +	while (!ring_empty(ring)) {
> +		if (!(ring->descriptors[ring->tail].flags
> +				& RING_DESC_COMPLETED))
> +			break;
> +		frame = list_first_entry(&ring->in_flight, typeof(*frame),
> +					 list);
> +		list_move_tail(&frame->list, done);
> +		if (!ring->is_tx) {
> +			frame->size = ring->descriptors[ring->tail].length;
> +			frame->eof = ring->descriptors[ring->tail].eof;
> +			frame->sof = ring->descriptors[ring->tail].sof;
> +			frame->flags = ring->descriptors[ring->tail].flags;
> +		}
> +		frame->ring = ring;
> +		ring->tail = (ring->tail + 1) % ring->size;
> +	}
> +	ring_write_descriptors(ring, true);

Please check if tb_ring_poll() can be made to use this as well.

> +}
> +
>  /*
>   * ring_work() - progress completed frames
>   *
> @@ -337,22 +372,7 @@ static void ring_work(struct work_struct *work)
>  		goto invoke_callback;
>  	}
>  
> -	while (!ring_empty(ring)) {
> -		if (!(ring->descriptors[ring->tail].flags
> -				& RING_DESC_COMPLETED))
> -			break;
> -		frame = list_first_entry(&ring->in_flight, typeof(*frame),
> -					 list);
> -		list_move_tail(&frame->list, &done);
> -		if (!ring->is_tx) {
> -			frame->size = ring->descriptors[ring->tail].length;
> -			frame->eof = ring->descriptors[ring->tail].eof;
> -			frame->sof = ring->descriptors[ring->tail].sof;
> -			frame->flags = ring->descriptors[ring->tail].flags;
> -		}
> -		ring->tail = (ring->tail + 1) % ring->size;
> -	}
> -	ring_write_descriptors(ring, true);
> +	ring_harvest(ring, &done);
>  
>  invoke_callback:
>  	/* allow callbacks to schedule new work */
> @@ -371,6 +391,35 @@ static void ring_work(struct work_struct *work)
>  	wake_up(&ring->wait);
>  }
>  
> +/*

Here too /**

> + * ring_process_completions() - invoke the callbacks of completed frames
> + * @done: Frames collected by ring_harvest(), possibly from several rings
> + *
> + * The frames of each ring are contiguous in @done. Like ring_work(), wake
> + * up the waiters of a ring once the callbacks of all its frames have run.
> + */
> +static void ring_process_completions(struct list_head *done)
> +{
> +	struct ring_frame *frame;
> +	struct tb_ring *ring;
> +
> +	while (!list_empty(done)) {

		struct ring_frame *frame;
		struct tb_ring *ring;


> +		frame = list_first_entry(done, typeof(*frame), list);
> +		ring = frame->ring;
> +		/*
> +		 * The callback may reenqueue or delete frame.

re-enqueue?

> +		 * Do not hold on to it.
> +		 */
> +		list_del_init(&frame->list);
> +		if (frame->callback)
> +			frame->callback(ring, frame, false);
> +

This could use a comment. I think we can do the wake_up() outside of the
loop except when ring is changed. Whichever looks more readable.

> +		if (list_empty(done) ||
> +		    list_first_entry(done, typeof(*frame), list)->ring != ring)
> +			wake_up(&ring->wait);
> +	}
> +}
> +
>  int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame, bool more)
>  {
>  	unsigned long flags;
> @@ -819,6 +868,19 @@ static bool tb_ring_empty(struct tb_ring *ring)
>  	return list_empty(&ring->in_flight);
>  }
>  
> +/*

Same here /**

ditto everywhere.

> + * ring_sync_irq() - wait for the interrupt handler of a ring
> + *
> + * nhi_msi_thread() invokes the callbacks of the frames it has harvested
> + * after dropping the locks, so make sure it has finished with any frames
> + * of a ring that has been stopped or dissociated from the NHI.
> + */
> +static void ring_sync_irq(struct tb_ring *ring)
> +{
> +	if (ring->irq > 0)
> +		synchronize_irq(ring->irq);
> +}
> +
>  /**
>   * tb_ring_flush() - Waits for a ring to be empty
>   * @ring: Ring to wait
> @@ -881,6 +943,8 @@ void tb_ring_stop(struct tb_ring *ring)
>  	spin_unlock(&ring->lock);
>  	spin_unlock_irq(&ring->nhi->lock);
>  
> +	ring_sync_irq(ring);
> +
>  	/*
>  	 * schedule ring->work to invoke callbacks on all remaining frames.
>  	 */
> @@ -906,7 +970,7 @@ void tb_ring_free(struct tb_ring *ring)
>  	spin_lock_irq(&ring->nhi->lock);
>  	/*
>  	 * Dissociate the ring from the NHI. This also ensures that
> -	 * nhi_interrupt_work cannot reschedule ring->work.
> +	 * nhi_msi_thread() cannot harvest its frames anymore.
>  	 */
>  	if (ring->is_tx)
>  		ring->nhi->tx_rings[ring->hop] = NULL;
> @@ -919,6 +983,8 @@ void tb_ring_free(struct tb_ring *ring)
>  	}
>  	spin_unlock_irq(&ring->nhi->lock);
>  
> +	ring_sync_irq(ring);
> +
>  	if (nhi->ops->release_ring_irq)
>  		nhi->ops->release_ring_irq(ring);
>  
> @@ -935,8 +1001,8 @@ void tb_ring_free(struct tb_ring *ring)
>  
>  	/*
>  	 * ring->work can no longer be scheduled (it is scheduled only
> -	 * by nhi_interrupt_work, ring_stop and ring_msix). Wait for it
> -	 * to finish before freeing the ring.
> +	 * by ring_stop and ring_msix). Wait for it to finish before
> +	 * freeing the ring.
>  	 */
>  	flush_work(&ring->work);
>  	lockdep_unregister_key(&ring->lock_key);
> @@ -1022,16 +1088,18 @@ enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi)
>  	return (enum nhi_fw_mode)val;
>  }
>  
> -void nhi_interrupt_work(struct work_struct *work)
> +irqreturn_t nhi_msi_thread(int irq, void *data)
>  {
> -	struct tb_nhi *nhi = container_of(work, typeof(*nhi), interrupt_work);
> +	struct tb_nhi *nhi = data;
> +	LIST_HEAD(completed_frames);
> +	unsigned long flags;
>  	int value = 0; /* Suppress uninitialized usage warning. */
>  	int bit;
>  	int hop = -1;
>  	int type = 0; /* current interrupt type 0: TX, 1: RX, 2: RX overflow */
>  	struct tb_ring *ring;
>  
> -	spin_lock_irq(&nhi->lock);
> +	spin_lock_irqsave(&nhi->lock, flags);
>  
>  	/*
>  	 * Starting at REG_RING_NOTIFY_BASE there are three status bitfields
> @@ -1073,17 +1141,28 @@ void nhi_interrupt_work(struct work_struct *work)
>  		}
>  
>  		spin_lock(&ring->lock);
> -		__ring_interrupt(ring);
> +		/*
> +		 * Harvest the completions right away instead of deferring
> +		 * to ring->work, so that the RX buffers are reposted without
> +		 * another scheduling delay during a burst.
> +		 */
> +		if (ring->start_poll)
> +			__ring_interrupt(ring);
> +		else if (ring->running)
> +			ring_harvest(ring, &completed_frames);
>  		spin_unlock(&ring->lock);
>  	}
> -	spin_unlock_irq(&nhi->lock);
> +	spin_unlock_irqrestore(&nhi->lock, flags);
> +
> +	if (!list_empty(&completed_frames))
> +		ring_process_completions(&completed_frames);
> +
> +	return IRQ_HANDLED;
>  }
>  
>  irqreturn_t nhi_msi(int irq, void *data)
>  {
> -	struct tb_nhi *nhi = data;
> -	schedule_work(&nhi->interrupt_work);
> -	return IRQ_HANDLED;
> +	return IRQ_WAKE_THREAD;
>  }
>  
>  static int __nhi_suspend_noirq(struct device *dev, bool wakeup)
> diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h
> index 88af9ab9fde7afc8af6da412b668663e67380e53..71f750451aacae6ca2f8cb37bd8ae7fc5a029818 100644
> --- a/drivers/thunderbolt/nhi.h
> +++ b/drivers/thunderbolt/nhi.h
> @@ -31,8 +31,8 @@ int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data);
>  enum nhi_fw_mode nhi_mailbox_mode(struct tb_nhi *nhi);
>  void nhi_enable_int_throttling(struct tb_nhi *nhi);
>  void nhi_disable_interrupts(struct tb_nhi *nhi);
> -void nhi_interrupt_work(struct work_struct *work);
>  irqreturn_t nhi_msi(int irq, void *data);
> +irqreturn_t nhi_msi_thread(int irq, void *data);
>  irqreturn_t ring_msix(int irq, void *data);
>  int nhi_probe(struct tb_nhi *nhi);
>  void nhi_shutdown(struct tb_nhi *nhi);
> diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c
> index 9fe2ef43d8ac8ac867c6e37d7a77518ad2221ed9..6388f77c67ac6d51831667abbffcfb8f52881af6 100644
> --- a/drivers/thunderbolt/pci.c
> +++ b/drivers/thunderbolt/pci.c
> @@ -206,14 +206,13 @@ static int nhi_pci_init_msi(struct tb_nhi *nhi)
>  		if (nvec < 0)
>  			return nvec;
>  
> -		INIT_WORK(&nhi->interrupt_work, nhi_interrupt_work);
> -
>  		irq = pci_irq_vector(pdev, 0);
>  		if (irq < 0)
>  			return irq;
>  
> -		res = devm_request_irq(&pdev->dev, irq, nhi_msi,
> -				       IRQF_NO_SUSPEND, "thunderbolt", nhi);
> +		res = devm_request_threaded_irq(&pdev->dev, irq, nhi_msi,
> +						nhi_msi_thread,
> +						IRQF_NO_SUSPEND, "thunderbolt", nhi);
>  		if (res)
>  			return res;
>  	}
> @@ -311,14 +310,8 @@ static void nhi_pci_release_irq(struct tb_nhi *nhi)
>  	struct tb_nhi_pci *nhi_pci = nhi_to_pci(nhi);
>  	struct pci_dev *pdev = to_pci_dev(nhi->dev);
>  
> -	/*
> -	 * We have to release the irq before calling flush_work. Otherwise an
> -	 * already executing IRQ handler could call schedule_work again.
> -	 */
> -	if (!pdev->msix_enabled) {
> +	if (!pdev->msix_enabled)
>  		devm_free_irq(nhi->dev, pdev->irq, nhi);
> -		flush_work(&nhi->interrupt_work);
> -	}
>  	ida_destroy(&nhi_pci->msix_ida);
>  }
>  
> diff --git a/include/linux/thunderbolt.h b/include/linux/thunderbolt.h
> index 57502da290805ed6ba627578da060afe290d4137..4faec9246d175d08063b7881ed1d379b9a7bdafd 100644
> --- a/include/linux/thunderbolt.h
> +++ b/include/linux/thunderbolt.h
> @@ -501,7 +501,8 @@ void tb_service_properties_changed(struct tb_service *svc);
>  /**
>   * struct tb_nhi - thunderbolt native host interface
>   * @lock: Must be held during ring creation/destruction. Is acquired by
> - *	  interrupt_work when dispatching interrupts to individual rings.
> + *	  the interrupt thread when dispatching interrupts to individual
> + *	  rings.
>   * @dev: Device associated with this NHI instance
>   * @ops: NHI specific optional ops
>   * @iobase: MMIO space of the NHI
> @@ -511,8 +512,6 @@ void tb_service_properties_changed(struct tb_service *svc);
>   * @going_away: The host controller device is about to disappear so when
>   *		this flag is set, avoid touching the hardware anymore.
>   * @iommu_dma_protection: An IOMMU will isolate external-facing ports.
> - * @interrupt_work: Work scheduled to handle ring interrupt when no
> - *		    MSI-X is used.
>   * @hop_count: Number of rings (end point hops) supported by NHI.
>   * @quirks: NHI specific quirks if any
>   * @domain_released: Completed when domain has been fully released
> @@ -532,7 +531,6 @@ struct tb_nhi {
>  	u32 *interrupt_mask;
>  	bool going_away;
>  	bool iommu_dma_protection;
> -	struct work_struct interrupt_work;
>  	u32 hop_count;
>  	unsigned long quirks;
>  	struct completion domain_released;
> @@ -639,11 +637,13 @@ enum ring_desc_flags {
>   * @flags: Flags for the frame (see &enum ring_desc_flags)
>   * @eof: End of frame protocol defined field
>   * @sof: Start of frame protocol defined field
> + * @ring: Ring the frame was completed on
>   */
>  struct ring_frame {
>  	dma_addr_t buffer_phy;
>  	ring_cb callback;
>  	struct list_head list;
> +	struct tb_ring *ring;
>  	u32 size:12;
>  	u32 flags:12;
>  	u32 eof:4;
> 
> -- 
> 2.55.0

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC DNM 08/15] thunderbolt: nhi: Add pre_switch_suspend hook
  2026-11-24 20:01 ` [PATCH RFC DNM 08/15] thunderbolt: nhi: Add pre_switch_suspend hook Konrad Dybcio
@ 2026-12-01  7:41   ` Mika Westerberg
  0 siblings, 0 replies; 22+ messages in thread
From: Mika Westerberg @ 2026-12-01  7:41 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-phy,
	linux-clk, linux-usb, linux-kernel, devicetree, usb4-upstream

On Tue, Nov 24, 2026 at 09:01:37PM +0100, Konrad Dybcio wrote:
> The Qualcomm router firmware requires a three-way handshake during its
> suspend routines as the OS writes the SLP bit to a connected device.
> 
> Add a hook right beforehand to allow synchronizing right as it happens.
> 
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> ---
>  drivers/thunderbolt/nhi.h    | 2 ++
>  drivers/thunderbolt/switch.c | 4 ++++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h
> index 71f750451aacae6ca2f8cb37bd8ae7fc5a029818..9bafb84cf60adbdee1f1f083732719e951b88c20 100644
> --- a/drivers/thunderbolt/nhi.h
> +++ b/drivers/thunderbolt/nhi.h
> @@ -53,6 +53,7 @@ extern const struct dev_pm_ops nhi_pm_ops;
>   * @release_ring_irq: NHI specific interrupt release hook
>   * @is_present: Whether the device is currently present on the parent bus
>   * @init_interrupts: NHI specific interrupt initialization hook
> + * @post_switch_suspend: NHI specific hook to call before suspending a switch

pre?

Also the tb_nhi_ops starts to look like a collection of random hooks. I
would really like there to be some logic in it rather that let's put there
everything.

>   */
>  struct tb_nhi_ops {
>  	int (*init)(struct tb_nhi *nhi);
> @@ -68,6 +69,7 @@ struct tb_nhi_ops {
>  	void (*release_ring_irq)(struct tb_ring *ring);
>  	bool (*is_present)(struct tb_nhi *nhi);
>  	int (*init_interrupts)(struct tb_nhi *nhi);
> +	void (*pre_switch_suspend)(struct tb_nhi *nhi);
>  };
>  
>  /*
> diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
> index d22d8db8f89064b3ed9c2b8beb8d5f0398640f11..4908c8b0e580a500acf9cac000e66a25e2102d47 100644
> --- a/drivers/thunderbolt/switch.c
> +++ b/drivers/thunderbolt/switch.c
> @@ -3660,6 +3660,7 @@ int tb_switch_resume(struct tb_switch *sw, bool runtime)
>   */
>  void tb_switch_suspend(struct tb_switch *sw, bool runtime)
>  {
> +	struct tb_nhi *nhi = sw->tb->nhi;

USB4 side should not call into the NHI like this.

>  	unsigned int flags = 0;
>  	struct tb_port *port;
>  	int err;
> @@ -3693,6 +3694,9 @@ void tb_switch_suspend(struct tb_switch *sw, bool runtime)
>  
>  	tb_switch_set_wake(sw, flags, runtime);
>  
> +	if (nhi->ops->pre_switch_suspend)
> +		nhi->ops->pre_switch_suspend(nhi);
> +
>  	if (tb_switch_is_usb4(sw))
>  		usb4_switch_set_sleep(sw);
>  	else
> 
> -- 
> 2.55.0

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC DNM 09/15] thunderbolt: nhi: Resume the domain if the NHI suspend op fails
  2026-11-24 20:01 ` [PATCH RFC DNM 09/15] thunderbolt: nhi: Resume the domain if the NHI suspend op fails Konrad Dybcio
@ 2026-12-01  7:44   ` Mika Westerberg
  0 siblings, 0 replies; 22+ messages in thread
From: Mika Westerberg @ 2026-12-01  7:44 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-phy,
	linux-clk, linux-usb, linux-kernel, devicetree, usb4-upstream

Hi,

On Tue, Nov 24, 2026 at 09:01:38PM +0100, Konrad Dybcio wrote:
> nhi_suspend_noirq() and nhi_runtime_suspend() suspend the domain first
> and then call the NHI specific suspend op. If that op fails, the error
> is returned with the domain still suspended. The control channel is
> stopped and the switches are marked as suspended, but the PM core

routers

Note once the domain sleep is started, there is no way going back until it
enters sleep.

> treats the device as active: it does not call resume_noirq for a device
> whose suspend_noirq failed, nor runtime_resume after a failed
> runtime_suspend. Nothing ever resumes the domain. Hotplug and config
> space accesses stop working, and the next runtime suspend attempt
> suspends an already suspended domain.
> 
> This happens on Qualcomm USB4 routers whenever the router firmware does
> not acknowledge the sleep request in time. The op then returns -EBUSY
> with the router still up.

Is there a reason why the firmware does not ack it in time?

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH RFC DNM 10/15] thunderbolt: nhi: Resume a runtime suspended NHI for system suspend
  2026-11-24 20:01 ` [PATCH RFC DNM 10/15] thunderbolt: nhi: Resume a runtime suspended NHI for system suspend Konrad Dybcio
@ 2026-12-01  7:49   ` Mika Westerberg
  0 siblings, 0 replies; 22+ messages in thread
From: Mika Westerberg @ 2026-12-01  7:49 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam,
	Bjorn Andersson, Konrad Dybcio, Abel Vesa, Stephen Boyd,
	Brian Masney, Jerome Brunet, Andreas Noever, Mika Westerberg,
	Yehezkel Bernat, Mario Limonciello, Philipp Zabel, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, linux-arm-msm, linux-phy,
	linux-clk, linux-usb, linux-kernel, devicetree, usb4-upstream

Hi,

On Tue, Nov 24, 2026 at 09:01:39PM +0100, Konrad Dybcio wrote:
> The PCI core resumes a runtime suspended device in pci_pm_suspend()
> before calling the driver's suspend callback, so nhi_suspend_noirq()
> always finds the NHI active. Platform devices get no such treatment, so
> these runtime suspended NHIs gets suspended a second time in the
> noirq phase and resumed in nhi_resume_noirq(). nhi_complete() then still
> sees it as runtime suspended and resumes it once more, which corrupts
> the control channel (RX checksum mismatches, config space timeouts).
> 
> Resume the NHI at the beginning of nhi_suspend(), like the PCI core
> does as a workaround.

Okay but I would rather keep it suspended over the system sleep. There
is no difference from USB4 perspective so there is really no point waking
it up. IIRC we do that now because USB stack needs to re-configure wakes
for S3 but for s2idle (which is what the modern Intel systems at least do)
that should not be necessary - it should wake the same way as runtime
suspended.

> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> ---
>  drivers/thunderbolt/nhi.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
> index e2578740d569a7ee1d5ab22e8effc153cb7d4632..56bc5748b6515b9d4799aa87ce0f72e1d673d634 100644
> --- a/drivers/thunderbolt/nhi.c
> +++ b/drivers/thunderbolt/nhi.c
> @@ -1258,6 +1258,13 @@ static int nhi_suspend(struct device *dev)
>  {
>  	struct tb *tb = dev_get_drvdata(dev);
>  
> +	/*
> +	 * The noirq callbacks expect the NHI to be active. The PCI core
> +	 * resumes a runtime suspended device before calling this, do the
> +	 * same for the NHIs that are not PCI devices.
> +	 */
> +	pm_runtime_resume(dev);
> +
>  	return tb_domain_suspend(tb);
>  }
>  
> 
> -- 
> 2.55.0

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2026-12-01  7:49 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 20:01 [RFC DNM PATCH 00/15] Qualcomm USB4 host router Konrad Dybcio
2026-11-24 20:01 ` [PATCH RFC DNM 01/15] phy: qualcomm: qmp-combo: Add Glymur USB4v1 PHY sequences Konrad Dybcio
2026-11-24 20:01 ` [PATCH RFC DNM 02/15] phy: qualcomm: qmp-combo: Add USB4 power_on/off to de/assert USB4 clamps Konrad Dybcio
2026-11-24 20:01 ` [PATCH RFC DNM 03/15] soc: qcom: smem: Add and export qcom_smem_get_serial_no() Konrad Dybcio
2026-11-24 20:01 ` [PATCH RFC DNM 04/15] soc: qcom: pmic_glink_altmode: Enable TBT/USB4 negotiation Konrad Dybcio
2026-11-24 20:01 ` [PATCH RFC DNM 05/15] clk: qcom: gcc-glymur: Don't poll the status bit of some USB4 clocks Konrad Dybcio
2026-11-24 20:01 ` [PATCH RFC DNM 06/15] thunderbolt: nhi: Clear ring interrupts when not using MSI-X Konrad Dybcio
2026-12-01  7:16   ` Mika Westerberg
2026-11-24 20:01 ` [PATCH RFC DNM 07/15] thunderbolt: nhi: Process ring completions in the threaded IRQ Konrad Dybcio
2026-12-01  7:33   ` Mika Westerberg
2026-11-24 20:01 ` [PATCH RFC DNM 08/15] thunderbolt: nhi: Add pre_switch_suspend hook Konrad Dybcio
2026-12-01  7:41   ` Mika Westerberg
2026-11-24 20:01 ` [PATCH RFC DNM 09/15] thunderbolt: nhi: Resume the domain if the NHI suspend op fails Konrad Dybcio
2026-12-01  7:44   ` Mika Westerberg
2026-11-24 20:01 ` [PATCH RFC DNM 10/15] thunderbolt: nhi: Resume a runtime suspended NHI for system suspend Konrad Dybcio
2026-12-01  7:49   ` Mika Westerberg
2026-11-24 20:01 ` [PATCH RFC DNM 11/15] thunderbolt: Raise TB_TIMEOUT to 500 ms Konrad Dybcio
2026-11-24 20:01 ` [PATCH HACK RFC DNM 12/15] thunderbolt: Refuse to activate DP/USB3/PCIe tunnels Konrad Dybcio
2026-11-24 20:01 ` [PATCH RFC DNM 13/15] thunderbolt: Introduce Qualcomm USB4 router driver Konrad Dybcio
2026-11-28 13:54   ` Troels Vognbjerg
2026-11-24 20:01 ` [PATCH RFC DNM 14/15] arm64: dts: qcom: glymur: Add USB4 topology Konrad Dybcio
2026-11-24 20:01 ` [PATCH RFC DNM 15/15] arm64: dts: qcom: glymur-crd: Enable the tertiary Type-C Konrad Dybcio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox