USB4 mode programming for QMMPHY on X1E
Subsystems (4)
Konrad Dybcio
maintainerv5 cover USB4 mode programming for QMMPHY on X1E
The USB43DP QMP PHY, as the name suggests, supports USB4 in addition to DP/USB. This series provides the necessary plumbing to switch to that mode of operation on hamoa/purwa.
This is achieved by exposing a third struct phy * for the USB4 sub- PHY, which will be toggled by the USB4 router driver, living within the Thunderbolt framework, which will be posted separately.
Find more details in the individual commit messages. Tested on a X1E80100 CRD.
No external dependencies.
---
Changes in v5:
- Reabse on next-20260907 (NOP)
- By popular demand, wrap a comment at 80 lines
- Link to v4: https://patch.msgid.link/[email protected]
Changes in v4:
- Rebase on next-20260820
- Rename phy-tbt.h to phy-thunderbolt.h
- Add missing error unrolling in usb4 phy_init()
- Rename usb4phy_init_count to usb4_init_count
- Refactor the submode acceptance logic in usb4 phy_set_mode()
- Pick up tags
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Fix up assisted-by tag
- Pick up tags
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Massage the bindings to only allow the p2rr2p clock on Hamoa
- Pick up tags
- Rebase (nop)
- Link to v1: https://patch.msgid.link/[email protected]
To: Vinod Koul <[email protected]>
To: Neil Armstrong <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Bjorn Andersson <[email protected]>
To: Konrad Dybcio <[email protected]>
To: Manivannan Sadhasivam <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Konrad Dybcio (5):
dt-bindings: phy: qcom,qmp-usb3-dp: Extend X1E description for USB4
phy: core: Define TBT phy_mode
phy: qualcomm: qmp-combo: Add preliminary USB4 support
phy: qualcomm: qmp-combo: Add USB4/TBT3 configuration data for Hamoa
arm64: dts: qcom: hamoa: Extend QMPPHY description for USB4
.../phy/qcom,sc8280xp-qmp-usb43dp-phy.yaml | 55 +- arch/arm64/boot/dts/qcom/hamoa.dtsi | 18 +- drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 602 ++++++++++++++++++--- drivers/phy/qualcomm/phy-qcom-qmp-pcs-aon-v6.h | 2 + drivers/phy/qualcomm/phy-qcom-qmp-pcs-usb-v6.h | 15 + .../phy/qualcomm/phy-qcom-qmp-qserdes-txrx-v6_n4.h | 45 ++ include/dt-bindings/phy/phy-qcom-qmp.h | 1 + include/linux/phy/phy-thunderbolt.h | 14 + include/linux/phy/phy.h | 2 + 9 files changed, 661 insertions(+), 93 deletions(-)
---
base-commit: 944a035ecca915ae947905dcfb03f2b9dc6d032c
change-id: 20260518-topic-usb4phy-e9612f5ba008
Best regards,
Signature · 1 line
Konrad Dybcio <[email protected]>
Konrad Dybcio
maintainerPATCH v5 1/5 dt-bindings: phy: qcom,qmp-usb3-dp: Extend X1E description for USB4
From: Konrad Dybcio <[email protected]>
Some instances of the QMP combo PHY (called USB43DP) feature a third functional sub-block, responsible for USB4/Thunderbolt 3 communication.
Compared to the today's state of the binding, one more clock (P2RR2P - PHY-to-Router, Router-to-PHY) needs to be enabled for the PHY to be able to switch to USB4 mode. Allow that for X1E.
Also, add a bindings define to let consumers access it.
--- .../phy/qcom,sc8280xp-qmp-usb43dp-phy.yaml | 55 +++++++++++++++++----- include/dt-bindings/phy/phy-qcom-qmp.h | 1 + 2 files changed, 45 insertions(+), 11 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb43dp-phy.yaml +44 -11
@@ -53,12 +53,7 @@ properties: clock-names: minItems: 4 - items: - - const: aux - - const: ref - - const: com_aux - - const: usb3_pipe - - const: cfg_ahb + maxItems: 5 power-domains: maxItems: 1
@@ -189,21 +184,59 @@ allOf: - if: properties: compatible: - enum: - - qcom,sc7180-qmp-usb3-dp-phy - - qcom,sdm845-qmp-usb3-dp-phy + contains: + enum: + - qcom,x1e80100-qmp-usb3-dp-phy then: properties: clocks: maxItems: 5 clock-names: + items: + - const: aux + - const: ref + - const: com_aux + - const: usb3_pipe + - const: p2rr2p_pipe + + - if: + properties: + compatible: + contains: + enum: + - qcom,sc7180-qmp-usb3-dp-phy + - qcom,sdm845-qmp-usb3-dp-phy + then: + properties: + clocks: maxItems: 5 - else: + clock-names: + items: + - const: aux + - const: ref + - const: com_aux + - const: usb3_pipe + - const: cfg_ahb + + - if: + not: + properties: + compatible: + contains: + enum: + - qcom,x1e80100-qmp-usb3-dp-phy + - qcom,sc7180-qmp-usb3-dp-phy + - qcom,sdm845-qmp-usb3-dp-phy + then: properties: clocks: maxItems: 4 clock-names: - maxItems: 4 + items: + - const: aux + - const: ref + - const: com_aux + - const: usb3_pipe - if: properties:
include/dt-bindings/phy/phy-qcom-qmp.h +1 -0
@@ -16,6 +16,7 @@/* QMP USB4-USB3-DP PHYs */ #define QMP_USB43DP_USB3_PHY 0#define QMP_USB43DP_DP_PHY 1 +#define QMP_USB43DP_USB4_PHY 2/* QMP PCIE PHYs */ #define QMP_PCIE_PIPE_CLK 0
Signature · 1 line
2.55.0
Konrad Dybcio
maintainerPATCH v5 2/5 phy: core: Define TBT phy_mode
In reply to Konrad DybcioFrom: Konrad Dybcio <[email protected]>
There exist OS-accessible USB4 and Thunderbolt PHYs that need specific configuration. Define a new phy_mode for them.
Currently, USB4 and TBT3 are defined as submodes, because they're quite distinct, most visibly in the electrical/analog aspects (slightly different frequencies, timings, etc.). This results in a need to make the PHY aware of the actual mode needed (at least in the Qualcomm implementation, but I believe that'll be a general need).
Newer versions of TBT are basically supersets of USB4 with higher host-side requirements, so these are not defined. This can always be changed as necessary.
--- include/linux/phy/phy-thunderbolt.h | 14 ++++++++++++++ include/linux/phy/phy.h | 2 ++ 2 files changed, 16 insertions(+)
include/linux/phy/phy-thunderbolt.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +*/ + +#ifndef __PHY_TBT_H_ +#define __PHY_TBT_H_ + +enum tbt_phy_submode { +PHY_SUBMODE_TBT3 , +PHY_SUBMODE_USB4 , +}; + +#endif
include/linux/phy/phy.h +2 -0
@@ -20,6 +20,7 @@#include <linux/phy/phy-hdmi.h> #include <linux/phy/phy-lvds.h> #include <linux/phy/phy-mipi-dphy.h> +#include <linux/phy/phy-thunderbolt.h> struct phy ;
@@ -45,6 +46,7 @@ enum phy_mode {PHY_MODE_LVDS ,PHY_MODE_DP ,PHY_MODE_HDMI , + PHY_MODE_TBT, }; enum phy_media {
Signature · 1 line
2.55.0
Konrad Dybcio
maintainerPATCH v5 3/5 phy: qualcomm: qmp-combo: Add preliminary USB4 support
In reply to Konrad DybcioFrom: Konrad Dybcio <[email protected]>
Some Combo PHYs (so far only on SC8280XP, X1E80100 and Glymur), come in a flavor called USB43DP, which as the name implies, features USB4, USB3 and DP signal processing capabilities. In that architecture, USB3 and USB4 PHYs share the same USB_PLL while featuring separate logic spaces. The DP part is roughly the same as on the instances without USB4.
The USB4 and USB3/DP operation modes of the PHY are mutually exclusive. Only one USB protocol (and flavor of pipe clock) can be active at a given moment (not to be confused with USB3 not being able to be tunneled as USB4 packets - that of course remains possible). The DP PLL is still used for clocking tunneled DP links. It may be turned off to save power when no tunnels are active, but that's left as a TODO item for now.
Due to the nature of USB4, the Type-C handling happens entirely inside the Host Router, and as such the QMPPHY's mux_set() function is nullified for the period when USB4 PHY remains active. This is strictly necessary, as the Host Router driver is going to excercise manual control over the USB4 PHY's power state, which is needed by the suspend and resume flows. Failure to control that synchronously with other parts of the code results in a SoC crash by unlocked access.
Because of that, a new struct phy is spawned to expose the USB4 mode, along with a .set_mode callback to allow toggling between USB4 and TBT3 submodes.
Thunderbolt 3, having a number of differences vs USB4, requires a couple specific overrides, pertaining to electrical characteristics, which are easily accommodated for.
--- drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 402 ++++++++++++++++++++++++------ 1 file changed, 332 insertions(+), 70 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +332 -70
@@ -22,6 +22,7 @@#include <linux/usb/typec.h> #include <linux/usb/typec_dp.h> #include <linux/usb/typec_mux.h> +#include <linux/usb/typec_tbt.h> #include <drm/bridge/aux-bridge.h>
@@ -66,10 +67,14 @@#define SW_USB3PHY_RESET BIT(2)/* mux to select USB3 PHY reset control, 0:HW control, 1: software reset */ #define SW_USB3PHY_RESET_MUX BIT(3) +#define SW_USB4PHY_RESET BIT(4) +#define SW_USB4PHY_RESET_MUX BIT(5)/* QPHY_V3_DP_COM_PHY_MODE_CTRL register bits */ #define USB3_MODE BIT(0)/* enables USB3 mode */ #define DP_MODE BIT(1)/* enables DP mode */ +#define USB4_MODE BIT(2)/* mutually exclusive with the above */ +#define DP_TUNNELING_CLOCK_GEN_EN BIT(3)/* QPHY_V3_DP_COM_TYPEC_CTRL register bits */ #define SW_PORTSELECT_VAL BIT(0)
@@ -82,6 +87,8 @@ enum qmpphy_mode {QMPPHY_MODE_USB3DP =0 ,QMPPHY_MODE_DP_ONLY ,QMPPHY_MODE_USB3_ONLY , +/* USB4 QMPPHY mode refers to both USB4 and TBT3 */ + QMPPHY_MODE_USB4, };/* set of registers with offsets different per-PHY */
@@ -94,6 +101,7 @@ enum qphy_reg_layout {QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR ,QPHY_PCS_POWER_DOWN_CONTROL ,QPHY_PCS_CLAMP_ENABLE , +QPHY_PCS_USB4_CLAMP_ENABLE ,QPHY_COM_RESETSM_CNTRL , QPHY_COM_C_READY_STATUS,
@@ -2489,6 +2497,8 @@ struct qmp_combo_offsets {u16 dp_txb;u16 dp_dp_phy;u16 aon_toggle; +u16 usb4_serdes; +u16 usb4_pcs; };struct qmp_phy_cfg {
@@ -2536,6 +2546,18 @@ struct qmp_phy_cfg {int (*calibrate_dp_phy)(struct qmp_combo *qmp);void (*dp_aux_init)(struct qmp_combo *qmp); +/* USB4 specifics */ +const struct qmp_phy_init_tbl *usb4_serdes_tbl; +int usb4_serdes_tbl_num; +const struct qmp_phy_init_tbl *usb4_serdes_tb3_ovrd_tbl; +int usb4_serdes_tb3_ovrd_num; +const struct qmp_phy_init_tbl *usb4_tx_tbl; +int usb4_tx_tbl_num; +const struct qmp_phy_init_tbl *usb4_rx_tbl; +int usb4_rx_tbl_num; +const struct qmp_phy_init_tbl *usb4_pcs_tbl; +int usb4_pcs_tbl_num; +/* resets to be requested */ const char *const *reset_list;int num_resets;
@@ -2578,8 +2600,12 @@ struct qmp_combo {void __iomem *dp_tx2;void __iomem *dp_dp_phy; +void __iomem *usb4_serdes; +void __iomem *usb4_pcs; +struct clk *pipe_clk;struct clk_bulk_data *clks; +struct clk *p2rr2p_pipe_clk;int num_clks;struct reset_control_bulk_data *resets;struct regulator_bulk_data *vregs;
@@ -2598,6 +2624,10 @@ struct qmp_combo {unsigned int dp_init_count;bool dp_powered_on; +struct phy *usb4_phy; +enum tbt_phy_submode usb4_phy_submode; +unsigned int usb4_init_count; +struct clk_fixed_rate pipe_clk_fixed;struct clk_hw dp_link_hw;struct clk_hw dp_pixel_hw;
@@ -4006,6 +4036,9 @@ static int qmp_combo_dp_calibrate(struct phy *phy)static int qmp_combo_com_init (struct qmp_combo *qmp,bool force) {const struct qmp_phy_cfg *cfg = qmp->cfg; +u32 dp_reset_val =SW_DPPHY_RESET_MUX |SW_DPPHY_RESET ; +void __iomem *pcs_aon = qmp->pcs_aon; +void __iomem *pcs = qmp->pcs;void __iomem *com = qmp->com;void __iomem *aon_toggle;int ret;
@@ -4019,6 +4052,16 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)else aon_toggle = qmp->pcs_aon; +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 ) { + pcs = qmp->usb4_pcs; + +qphy_setbits (pcs_aon, cfg->regs[QPHY_PCS_USB4_CLAMP_ENABLE ],CLAMP_EN ); + +/* Do not disturb the DP PLL in case there's an active DP tunnel */ +if (readl (com +QPHY_V3_DP_COM_RESET_OVRD_CTRL ) &DP_TUNNELING_CLOCK_GEN_EN ) + dp_reset_val &= ~SW_DPPHY_RESET_MUX ; + } + ret =regulator_bulk_enable (cfg->num_vregs, qmp->vregs);if (ret) {dev_err (qmp->dev,"failed to enable regulators, err=%d\n" , ret);
@@ -4052,8 +4095,9 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)/* override hardware control for reset of qmp phy */ qphy_setbits (com,QPHY_V3_DP_COM_RESET_OVRD_CTRL , -SW_DPPHY_RESET_MUX |SW_DPPHY_RESET | -SW_USB3PHY_RESET_MUX |SW_USB3PHY_RESET ); + dp_reset_val | +SW_USB3PHY_RESET_MUX |SW_USB3PHY_RESET | +SW_USB4PHY_RESET_MUX |SW_USB4PHY_RESET );/* override hardware control for reset of qmp phy */ if (aon_toggle && cfg->regs[QPHY_AON_TOGGLE_ENABLE ]) {
@@ -4069,6 +4113,10 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)if (cfg->invert_cc_polarity) val |=INVERT_CC_POLARITY ; +/* +* Note that in USB4 mode, the router controls pin assignments instead +* and the values of the PORTSELECT registers are ignored. +*/ writel (val, com +QPHY_V3_DP_COM_TYPEC_CTRL );switch (qmp->qmpphy_mode) {
@@ -4096,12 +4144,24 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)qphy_clrbits (com,QPHY_V3_DP_COM_RESET_OVRD_CTRL ,SW_USB3PHY_RESET_MUX |SW_USB3PHY_RESET );break ; +case QMPPHY_MODE_USB4 : +writel (USB4_MODE , com +QPHY_V3_DP_COM_PHY_MODE_CTRL ); + +/* bring both QMP USB and QMP DP PHYs PCS block out of reset */ +/* +* TODO: disable the DP PLL to save power if there are no +* active DP tunnels after router setup has concluded +*/ +qphy_clrbits (com,QPHY_V3_DP_COM_RESET_OVRD_CTRL , +SW_USB4PHY_RESET_MUX |SW_USB4PHY_RESET | +SW_DPPHY_RESET_MUX |SW_DPPHY_RESET ); +break ; }qphy_clrbits (com,QPHY_V3_DP_COM_SWI_CTRL ,0x03 );qphy_clrbits (com,QPHY_V3_DP_COM_SW_RESET ,SW_RESET ); -qphy_setbits (qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL ], +qphy_setbits (pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL ],SW_PWRDN );return 0 ;
@@ -4219,6 +4279,10 @@ static int qmp_combo_usb_power_on(struct phy *phy)struct qmp_combo *qmp =phy_get_drvdata (phy);const struct qmp_phy_cfg *cfg = qmp->cfg;void __iomem *serdes = qmp->serdes; +const struct qmp_phy_init_tbl *pcs_tbl; +const struct qmp_phy_init_tbl *rx_tbl; +const struct qmp_phy_init_tbl *serdes_tbl; +const struct qmp_phy_init_tbl *tx_tbl;void __iomem *tx = qmp->tx;void __iomem *rx = qmp->rx;void __iomem *tx2 = qmp->tx2;
@@ -4226,23 +4290,54 @@ static int qmp_combo_usb_power_on(struct phy *phy)void __iomem *pcs = qmp->pcs;void __iomem *pcs_usb = qmp->pcs_usb;void __iomem *status; +int pcs_tbl_num, rx_tbl_num, serdes_tbl_num, tx_tbl_num;unsigned int val;int ret; -qmp_configure (qmp->dev, serdes, cfg->serdes_tbl, cfg->serdes_tbl_num); +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 ) { + pcs = qmp->usb4_pcs; + serdes = qmp->usb4_serdes; + pcs_tbl = cfg->usb4_pcs_tbl; + pcs_tbl_num = cfg->usb4_pcs_tbl_num; + + serdes_tbl = cfg->usb4_serdes_tbl; + serdes_tbl_num = cfg->usb4_serdes_tbl_num; + + rx_tbl = cfg->usb4_rx_tbl; + rx_tbl_num = cfg->usb4_rx_tbl_num; + + tx_tbl = cfg->usb4_tx_tbl; + tx_tbl_num = cfg->usb4_tx_tbl_num; + }else { + pcs_tbl = cfg->pcs_tbl; + pcs_tbl_num = cfg->pcs_tbl_num; + + serdes_tbl = cfg->serdes_tbl; + serdes_tbl_num = cfg->serdes_tbl_num; + + rx_tbl = cfg->rx_tbl; + rx_tbl_num = cfg->rx_tbl_num; + + tx_tbl = cfg->tx_tbl; + tx_tbl_num = cfg->tx_tbl_num; + } + +qmp_configure (qmp->dev, serdes, serdes_tbl, serdes_tbl_num);/* Tx, Rx, and PCS configurations */ -qmp_configure_lane (qmp->dev, tx, cfg->tx_tbl, cfg->tx_tbl_num,1 ); -qmp_configure_lane (qmp->dev, tx2, cfg->tx_tbl, cfg->tx_tbl_num,2 ); +qmp_configure_lane (qmp->dev, tx, tx_tbl, tx_tbl_num,1 ); +qmp_configure_lane (qmp->dev, tx2, tx_tbl, tx_tbl_num,2 ); -qmp_configure_lane (qmp->dev, rx, cfg->rx_tbl, cfg->rx_tbl_num,1 ); -qmp_configure_lane (qmp->dev, rx2, cfg->rx_tbl, cfg->rx_tbl_num,2 ); +qmp_configure_lane (qmp->dev, rx, rx_tbl, rx_tbl_num,1 ); +qmp_configure_lane (qmp->dev, rx2, rx_tbl, rx_tbl_num,2 ); -qmp_configure (qmp->dev, pcs, cfg->pcs_tbl, cfg->pcs_tbl_num); +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 (pcs_usb) +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 (qmp->dev, pcs_usb, cfg->pcs_usb_tbl, cfg->pcs_usb_tbl_num);
@@ -4275,16 +4370,20 @@ static int qmp_combo_usb_power_off(struct phy *phy) {struct qmp_combo *qmp =phy_get_drvdata (phy);const struct qmp_phy_cfg *cfg = qmp->cfg; +void __iomem *pcs = qmp->pcs; + +if (qmp->usb4_init_count) + pcs = qmp->usb4_pcs;/* PHY reset */ -qphy_setbits (qmp->pcs, cfg->regs[QPHY_SW_RESET ],SW_RESET ); +qphy_setbits (pcs, cfg->regs[QPHY_SW_RESET ],SW_RESET );/* stop SerDes and Phy-Coding-Sublayer */ -qphy_clrbits (qmp->pcs, cfg->regs[QPHY_START_CTRL ], +qphy_clrbits (pcs, cfg->regs[QPHY_START_CTRL ],SERDES_START |PCS_START );/* Put PHY into POWER DOWN state: active low */ -qphy_clrbits (qmp->pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL ], +qphy_clrbits (pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL ],SW_PWRDN );return 0 ;
@@ -4295,21 +4394,27 @@ static int qmp_combo_usb_init(struct phy *phy)struct qmp_combo *qmp =phy_get_drvdata (phy);int ret; -mutex_lock (&qmp->phy_mutex); +guard (mutex)(&qmp->phy_mutex); + +/* USB4 mode takes precedence, do not reprogram the PHY in that case */ +if (qmp->usb4_init_count) { + qmp->init_count++; + qmp->usb_init_count++; +return 0 ; + } + ret =qmp_combo_com_init (qmp, false);if (ret) - goto out_unlock; +return ret; ret =qmp_combo_usb_power_on (phy);if (ret) {qmp_combo_com_exit (qmp, false); - goto out_unlock; +return ret; } qmp->usb_init_count++; -out_unlock: -mutex_unlock (&qmp->phy_mutex);return ret; }
@@ -4318,20 +4423,26 @@ static int qmp_combo_usb_exit(struct phy *phy)struct qmp_combo *qmp =phy_get_drvdata (phy);int ret; -mutex_lock (&qmp->phy_mutex); +guard (mutex)(&qmp->phy_mutex); + +/* USB4 mode takes precedence, do not reprogram the PHY in that case */ +if (qmp->usb4_init_count) { + qmp->init_count--; + qmp->usb_init_count--; +return 0 ; + } + ret =qmp_combo_usb_power_off (phy);if (ret) - goto out_unlock; +return ret; ret =qmp_combo_com_exit (qmp, false);if (ret) - goto out_unlock; +return ret; qmp->usb_init_count--; -out_unlock: -mutex_unlock (&qmp->phy_mutex); -return ret; +return 0 ; }static int qmp_combo_usb_set_mode (struct phy *phy,enum phy_mode mode,int submode)
@@ -4343,6 +4454,125 @@ static int qmp_combo_usb_set_mode(struct phy *phy, enum phy_mode mode, int submoreturn 0 ; } +static int qmp_combo_reconfigure_phy (struct qmp_combo *qmp,enum qmpphy_mode new_mode) +{ +dev_dbg (qmp->dev,"qmp_combo_reconfigure_phy: switching from qmpphy mode %d to %d\n" , + qmp->qmpphy_mode, new_mode); + +if (qmp->usb_init_count || qmp->usb4_init_count) +qmp_combo_usb_power_off (qmp->usb_phy); + +if (qmp->dp_init_count) +writel (DP_PHY_PD_CTL_PSR_PWRDN , qmp->dp_dp_phy +QSERDES_DP_PHY_PD_CTL ); + +qmp_combo_com_exit (qmp, true); + + qmp->qmpphy_mode = new_mode; + +/* Now everything's powered down, power up the right PHYs */ +qmp_combo_com_init (qmp, true); + +if ((qmp->usb_init_count || qmp->usb4_init_count) && + new_mode !=QMPPHY_MODE_DP_ONLY ) +qmp_combo_usb_power_on (qmp->usb_phy); + +if ((new_mode ==QMPPHY_MODE_USB3DP || new_mode ==QMPPHY_MODE_DP_ONLY ) && + qmp->dp_init_count) + qmp->cfg->dp_aux_init (qmp); + +return 0 ; +} + +static int qmp_combo_usb4_init (struct phy *phy) +{ +struct qmp_combo *qmp =phy_get_drvdata (phy); +int ret; + +guard (mutex)(&qmp->phy_mutex); + +if (!qmp->p2rr2p_pipe_clk) { +dev_err (qmp->dev,"missing p2rr2p_pipe clock handle. Update your Device Tree.\n" ); +return -EINVAL ; + } + + ret =clk_prepare_enable (qmp->p2rr2p_pipe_clk); +if (ret) { +dev_err (qmp->dev,"p2rr2p_pipe enable failed: %d\n" , ret); +return ret; + } + + ret =qmp_combo_com_init (qmp, false); +if (ret) { +clk_disable_unprepare (qmp->p2rr2p_pipe_clk); +return ret; + } + +/* USB4 mode takes precedence to USB3(+DP), force reconfigure the PHY */ + ret =qmp_combo_reconfigure_phy (qmp,QMPPHY_MODE_USB4 ); +if (ret) { +clk_disable_unprepare (qmp->p2rr2p_pipe_clk); +qmp_combo_com_exit (qmp, false); +return ret; + } + + ret =qmp_combo_usb_power_on (phy); +if (ret) { +clk_disable_unprepare (qmp->p2rr2p_pipe_clk); +qmp_combo_com_exit (qmp, false); +return ret; + } + +/* +* Due to the SoC design, the PHY only has a single valid consumer and +* preventing it from having sole ownership of the PHY's power state +* makes suspending/resuming the router impossible. +*/ +WARN_ON (qmp->usb4_init_count++); + +return 0 ; +} + +static int qmp_combo_usb4_exit (struct phy *phy) +{ +struct qmp_combo *qmp =phy_get_drvdata (phy); +int ret; + +guard (mutex)(&qmp->phy_mutex); + + ret =qmp_combo_usb_power_off (qmp->usb_phy); +if (ret) +return ret; + + ret =qmp_combo_com_exit (qmp, false); +if (ret) +return ret; + +/* +* Mark the USB4 PHY uninitialized and wait for a mux_set event to determine the correct +* setting. This will always be possible because USB4 requires Type-C. +*/ + qmp->usb4_init_count--; + +clk_disable_unprepare (qmp->p2rr2p_pipe_clk); + +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); + +if (mode !=PHY_MODE_TBT ) +return -EINVAL ; + +if (submode !=PHY_SUBMODE_USB4 && submode !=PHY_SUBMODE_TBT3 ) +return -EINVAL ; + + qmp->usb4_phy_submode = submode; + +return 0 ; +} +static const struct phy_ops qmp_combo_usb_phy_ops = { .init = qmp_combo_usb_init, .exit = qmp_combo_usb_exit,
@@ -4350,6 +4580,13 @@ static const struct phy_ops qmp_combo_usb_phy_ops = { .owner = THIS_MODULE, }; +static const struct phy_ops qmp_combo_usb4_phy_ops = { + .init = qmp_combo_usb4_init, + .exit = qmp_combo_usb4_exit, + .set_mode = qmp_combo_usb4_set_mode, + .owner =THIS_MODULE , +}; +static const struct phy_ops qmp_combo_dp_phy_ops = { .init = qmp_combo_dp_init, .configure = qmp_combo_dp_configure,
@@ -4389,9 +4626,12 @@ static void qmp_combo_enable_autonomous_mode(struct qmp_combo *qmp)* Enable i/o clamp_n for autonomous mode * V6 and later versions use pcs aon clamp register */ -if (pcs_aon) -qphy_clrbits (pcs_aon, cfg->regs[QPHY_PCS_CLAMP_ENABLE ],CLAMP_EN ); -else if (pcs_misc) +if (pcs_aon) { +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 ) +qphy_clrbits (pcs_aon, cfg->regs[QPHY_PCS_USB4_CLAMP_ENABLE ],CLAMP_EN ); +else +qphy_clrbits (pcs_aon, cfg->regs[QPHY_PCS_CLAMP_ENABLE ],CLAMP_EN ); + }else if (pcs_misc)qphy_clrbits (pcs_misc, cfg->regs[QPHY_PCS_CLAMP_ENABLE ],CLAMP_EN ); }
@@ -4403,9 +4643,12 @@ static void qmp_combo_disable_autonomous_mode(struct qmp_combo *qmp)void __iomem *pcs_aon = qmp->pcs_aon;/* Disable i/o clamp_n on resume for normal mode */ -if (pcs_aon) -qphy_setbits (pcs_aon, cfg->regs[QPHY_PCS_CLAMP_ENABLE ],CLAMP_EN ); -else if (pcs_misc) +if (pcs_aon) { +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 ) +qphy_setbits (pcs_aon, cfg->regs[QPHY_PCS_USB4_CLAMP_ENABLE ],CLAMP_EN ); +else +qphy_setbits (pcs_aon, cfg->regs[QPHY_PCS_CLAMP_ENABLE ],CLAMP_EN ); + }else if (pcs_misc)qphy_setbits (pcs_misc, cfg->regs[QPHY_PCS_CLAMP_ENABLE ],CLAMP_EN ); qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_AUTONOMOUS_MODE_CTRL],
@@ -4779,24 +5022,29 @@ static int qmp_combo_typec_switch_set(struct typec_switch_dev *sw,struct qmp_combo *qmp =typec_switch_get_drvdata (sw);const struct qmp_phy_cfg *cfg = qmp->cfg; +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 ) { +/* QMPPHY has no orientation handling in USB4 mode, don't cache the setting */ + qmp->orientation =TYPEC_ORIENTATION_NONE ; +return 0 ; + } +if (orientation == qmp->orientation || orientation ==TYPEC_ORIENTATION_NONE )return 0 ; -mutex_lock (&qmp->phy_mutex); +guard (mutex)(&qmp->phy_mutex); qmp->orientation = orientation;if (qmp->init_count) { -if (qmp->usb_init_count) +if (qmp->usb_init_count || qmp->usb4_init_count)qmp_combo_usb_power_off (qmp->usb_phy);qmp_combo_com_exit (qmp, true);qmp_combo_com_init (qmp, true); -if (qmp->usb_init_count) +if (qmp->usb_init_count || qmp->usb4_init_count)qmp_combo_usb_power_on (qmp->usb_phy);if (qmp->dp_init_count) cfg->dp_aux_init (qmp); } -mutex_unlock (&qmp->phy_mutex);return 0 ; }
@@ -4804,7 +5052,6 @@ static int qmp_combo_typec_switch_set(struct typec_switch_dev *sw,static int qmp_combo_typec_mux_set (struct typec_mux_dev *mux,struct typec_mux_state *state) {struct qmp_combo *qmp =typec_mux_get_drvdata (mux); -const struct qmp_phy_cfg *cfg = qmp->cfg;enum qmpphy_mode new_mode;unsigned int svid;
@@ -4815,6 +5062,29 @@ static int qmp_combo_typec_mux_set(struct typec_mux_dev *mux, struct typec_mux_selse svid =0 ; +/* +* The USB4 router driver must excercise fine-grained control over the timing of +* USB4 QMPPHY mode entry/exit, which is difficult to otherwise ensure within Linux's +* Type-C framework if the PHY acts as a self-decisive mode mux in parallel. +* +* Keep the hardware in QMPPHY_MODE_USB4 at all times between .init and .exit of the +* (Linux) USB4 PHY and wait for the router driver to turn it off at its discretion. +* Once that happens, fall back to the usual USB3/DP/Combo mode logic. +* +* After the QMPPHY has been turned off through phy_exit(usb4_phy), the next mux_set +* will initialize it in the right mode. +*/ +if (qmp->usb4_init_count) +return 0 ; + +/* +* Explicitly ignore TBT/USB4 mode requests that may come if the USB4 PHY hasn't been +* initialized, either due to the USB4 drivers being disabled or due to this PHY instance +* lacking USB4 support. +*/ +if (svid ==USB_TYPEC_TBT_SID || (!state->alt && state->mode ==TYPEC_MODE_USB4 )) +return 0 ; +if (svid ==USB_TYPEC_DP_SID ) {switch (state->mode) {/* DP Only */
@@ -4847,41 +5117,11 @@ static int qmp_combo_typec_mux_set(struct typec_mux_dev *mux, struct typec_mux_sreturn 0 ; } -dev_dbg (qmp->dev,"typec_mux_set: switching from qmpphy mode %d to %d\n" , - qmp->qmpphy_mode, new_mode); +/* The mux still receives Type-C events, even if all PHYs are uninitialized */ +if (!qmp->init_count) +return 0 ; - qmp->qmpphy_mode = new_mode; - -if (qmp->init_count) { -if (qmp->usb_init_count) -qmp_combo_usb_power_off (qmp->usb_phy); - -if (qmp->dp_init_count) -writel (DP_PHY_PD_CTL_PSR_PWRDN , qmp->dp_dp_phy +QSERDES_DP_PHY_PD_CTL ); - -qmp_combo_com_exit (qmp, true); - -/* Now everything's powered down, power up the right PHYs */ -qmp_combo_com_init (qmp, true); - -if (new_mode ==QMPPHY_MODE_DP_ONLY ) { -if (qmp->usb_init_count) - qmp->usb_init_count--; - } - -if (new_mode ==QMPPHY_MODE_USB3DP || new_mode ==QMPPHY_MODE_USB3_ONLY ) { -qmp_combo_usb_power_on (qmp->usb_phy); -if (!qmp->usb_init_count) - qmp->usb_init_count++; - } - -if (new_mode ==QMPPHY_MODE_DP_ONLY || new_mode ==QMPPHY_MODE_USB3DP ) { -if (qmp->dp_init_count) - cfg->dp_aux_init (qmp); - } - } - -return 0 ; +return qmp_combo_reconfigure_phy (qmp, new_mode); }static void qmp_combo_typec_switch_unregister (void *data)
@@ -5088,6 +5328,9 @@ static int qmp_combo_parse_dt(struct qmp_combo *qmp)if (offs->aon_toggle) qmp->aon_toggle = base + offs->aon_toggle; + qmp->usb4_serdes = base + offs->usb4_serdes; + qmp->usb4_pcs = base + offs->usb4_pcs; + ret =qmp_combo_clk_init (qmp);if (ret)return ret;
@@ -5098,6 +5341,12 @@ static int qmp_combo_parse_dt(struct qmp_combo *qmp) "failed to get usb3_pipe clock\n"); } + qmp->p2rr2p_pipe_clk =devm_clk_get_optional (dev,"p2rr2p_pipe" ); +if (IS_ERR (qmp->p2rr2p_pipe_clk)) { +return dev_err_probe (dev,PTR_ERR (qmp->p2rr2p_pipe_clk), +"failed to get p2rr2p_pipe clock\n" ); + } +return 0 ; }
@@ -5113,6 +5362,8 @@ static struct phy *qmp_combo_phy_xlate(struct device *dev, const struct of_phandreturn qmp->usb_phy;case QMP_USB43DP_DP_PHY :return qmp->dp_phy; +case QMP_USB43DP_USB4_PHY : +return qmp->usb4_phy ?:ERR_PTR (-EINVAL ); }return ERR_PTR (-EINVAL );
@@ -5325,6 +5576,17 @@ static int qmp_combo_probe(struct platform_device *pdev)phy_set_drvdata (qmp->dp_phy, qmp); +if (qmp->cfg->usb4_serdes_tbl) { + qmp->usb4_phy =devm_phy_create (dev, dev->of_node, &qmp_combo_usb4_phy_ops); +if (IS_ERR (qmp->usb4_phy)) { + ret =PTR_ERR (qmp->usb4_phy); +dev_err (dev,"failed to create USB4 PHY: %d\n" , ret); + goto err_node_put; + } + +phy_set_drvdata (qmp->usb4_phy, qmp); + } +if (usb_np == dev->of_node) phy_provider =devm_of_phy_provider_register (dev, qmp_combo_phy_xlate);else
Signature · 1 line
2.55.0
Konrad Dybcio
maintainerPATCH v5 4/5 phy: qualcomm: qmp-combo: Add USB4/TBT3 configuration data for Hamoa
In reply to Konrad DybcioFrom: Konrad Dybcio <[email protected]>
Add the offsets and configuration tables to support USB4 and Thunderbolt 3 operation on the USB4-capable PHYs found on Hamoa chips.
--- drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 200 ++++++++++++++++++++- drivers/phy/qualcomm/phy-qcom-qmp-pcs-aon-v6.h | 2 + drivers/phy/qualcomm/phy-qcom-qmp-pcs-usb-v6.h | 15 ++ .../phy/qualcomm/phy-qcom-qmp-qserdes-txrx-v6_n4.h | 45 +++++ 4 files changed, 256 insertions(+), 6 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +194 -6
@@ -240,6 +240,7 @@ static const unsigned int qmp_v6_n4_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = { [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = QPHY_V6_PCS_USB3_LFPS_RXTERM_IRQ_CLEAR, [QPHY_PCS_CLAMP_ENABLE] = QPHY_V6_PCS_AON_CLAMP_ENABLE, + [QPHY_PCS_USB4_CLAMP_ENABLE] = QPHY_V6_PCS_AON_USB4_CLAMP_ENABLE, [QPHY_COM_RESETSM_CNTRL] = QSERDES_V6_COM_RESETSM_CNTRL, [QPHY_COM_C_READY_STATUS] = QSERDES_V6_COM_C_READY_STATUS,
@@ -1967,7 +1968,85 @@ static const struct qmp_phy_init_tbl sc8280xp_usb43dp_pcs_tbl[] = { QMP_PHY_INIT_CFG(QPHY_V5_PCS_USB3_RXEQTRAINING_DFE_TIME_S2, 0x07), }; -static const struct qmp_phy_init_tbl x1e80100_usb43dp_serdes_tbl[] = { +static const struct qmp_phy_init_tbl x1e80100_usb4_serdes_tbl[] = { +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_EN_CENTER ,0x01 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_PER1 ,0x62 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_PER2 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_STEP_SIZE1_MODE0 ,0xd9 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_STEP_SIZE2_MODE0 ,0x03 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_STEP_SIZE1_MODE1 ,0xb2 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_STEP_SIZE2_MODE1 ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SYSCLK_BUF_ENABLE ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_CP_CTRL_MODE0 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_CP_CTRL_MODE1 ,0x02 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_RCTRL_MODE0 ,0x18 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_RCTRL_MODE1 ,0x18 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_CCTRL_MODE0 ,0x36 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_CCTRL_MODE1 ,0x36 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SYSCLK_EN_SEL ,0x1a ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_LOCK_CMP_EN ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_LOCK_CMP_CFG ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_LOCK_CMP1_MODE0 ,0x1a ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_LOCK_CMP2_MODE0 ,0x41 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_LOCK_CMP1_MODE1 ,0x24 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_LOCK_CMP2_MODE1 ,0x43 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DEC_START_MODE0 ,0x82 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DEC_START_MSB_MODE0 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DEC_START_MODE1 ,0x86 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DEC_START_MSB_MODE1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DIV_FRAC_START1_MODE0 ,0x55 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DIV_FRAC_START2_MODE0 ,0x55 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DIV_FRAC_START3_MODE0 ,0x03 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DIV_FRAC_START1_MODE1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DIV_FRAC_START2_MODE1 ,0xa7 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_DIV_FRAC_START3_MODE1 ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_VCO_TUNE_MAP ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_VCO_TUNE1_MODE0 ,0xba ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_VCO_TUNE2_MODE0 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_VCO_TUNE1_MODE1 ,0x3c ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_VCO_TUNE2_MODE1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_HSCLK_SEL_1 ,0x11 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_HSCLK_HS_SWITCH_SEL_1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_CORE_CLK_DIV_MODE0 ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_CORECLK_DIV_MODE1 ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_CMN_CONFIG_1 ,0x76 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_CORE_CLK_EN ,0xb0 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_IVCO ,0x7f ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_IVCO_MODE1 ,0x7f ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_INTEGLOOP_GAIN0_MODE0 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_INTEGLOOP_GAIN0_MODE1 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_CMN_IPTRIM ,0x17 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SVS_MODE_CLK_SEL ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_CMN_MODE ,0x05 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_VCO_DC_LEVEL_CTRL ,0x07 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_ADDITIONAL_MISC_2 ,0x0f ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_VCO_TUNE_INITVAL2 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_VCO_TUNE_MAXVAL2 ,0x01 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_PLL_POST_DIV_MUX ,0x60 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_BG_TIMER ,0x0a ), +}; + +static const struct qmp_phy_init_tbl x1e80100_usb4_tb3_serdes_tbl[] = { +QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_PER1 ,0x15 ), +QMP_PHY_INIT_CFG (QSERDES_V6_COM_VCO_TUNE_MAP ,0x54 ), +}; + +static const struct qmp_phy_init_tbl x1e80100_usb4_tx_tbl[] = { +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_LANE_MODE_1 ,0x05 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_LANE_MODE_2 ,0x50 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_LANE_MODE_3 ,0x40 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_RES_CODE_LANE_OFFSET_TX ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_RES_CODE_LANE_OFFSET_RX ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_RX_MARG_COARSE_THRESH1_RATE210 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_RX_MARG_COARSE_THRESH1_RATE3 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_RX_MARG_COARSE_THRESH2_RATE210 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_RX_MARG_COARSE_THRESH2_RATE3 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_RX_MARG_COARSE_THRESH3_RATE210 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_RX_MARG_COARSE_THRESH3_RATE3 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_TX_LDO_TIMER_CTRL ,0x03 ), +}; + +static const struct qmp_phy_init_tbl x1e80100_usb3dp_serdes_tbl[] = {QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_EN_CENTER ,0x01 ),QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_PER1 ,0x62 ),QMP_PHY_INIT_CFG (QSERDES_V6_COM_SSC_PER2 ,0x02 ),
@@ -2028,6 +2107,68 @@ static const struct qmp_phy_init_tbl x1e80100_usb43dp_tx_tbl[] = { QMP_PHY_INIT_CFG(QSERDES_V6_N4_TX_RES_CODE_LANE_OFFSET_RX, 0x0a), }; +static const struct qmp_phy_init_tbl x1e80100_usb4_rx_tbl[] = { +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_SIGDET_CNTRL ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_SIGDET_DEGLITCH_CNTRL ,0x0e ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_SIGDET_ENABLES ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE2_B0 ,0xd3 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE2_B1 ,0xee ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE2_B2 ,0x58 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE2_B4 ,0x24 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE3_B0 ,0xbf ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE3_B1 ,0x7f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE3_B2 ,0xa2 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE3_B3 ,0xdd ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE3_B4 ,0x6a ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE3_B5 ,0xdb ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_MODE_RATE3_B6 ,0xe3 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_UCDR_FASTLOCK_COUNTER_LOW_RATE2 ,0x30 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_UCDR_FASTLOCK_COUNTER_HIGH_RATE2 ,0x14 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_UCDR_FASTLOCK_COUNTER_LOW_RATE3 ,0xff ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_UCDR_FASTLOCK_COUNTER_HIGH_RATE3 ,0x3f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_PI_CTRL1 ,0xd0 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_PI_CTRL2 ,0x48 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_SB2_THRESH1_RATE3 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_SB2_GAIN2_RATE2 ,0x0a ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_SB2_GAIN1_RATE3 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_SB2_GAIN2_RATE3 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_IVCM_CAL_CODE_OVERRIDE ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_RX_IVCM_CAL_CTRL2 ,0x80 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_RX_SUMMER_CAL_SPD_MODE ,0x2f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_CTLE_POST_CAL_OFFSET ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DCC_CMUX_POSTCAL_OFFSET ,0x1d ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_FO_GAIN_RATE2 ,0x09 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_FO_GAIN_RATE3 ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_SO_GAIN_RATE2 ,0x05 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_SO_GAIN_RATE3 ,0x05 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_PI_CONTROLS ,0x15 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_FASTLOCK_FO_GAIN_RATE3 ,0x1f ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_FASTLOCK_SO_GAIN_RATE3 ,0x08 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_UCDR_SO_SATURATION ,0x36 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_RX_IVCM_POSTCAL_OFFSET ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_VGA_CAL_CNTRL1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_VGA_CAL_MAN_VAL ,0x08 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_DAC_ENABLE1 ,0x88 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_DAC_ENABLE2 ,0x08 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_1 ,0x00 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_2 ,0x04 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_3 ,0x45 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_TAP3_CTRL ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_TAP4_CTRL ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_TAP5_CTRL ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_GM_CAL ,0x0d ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_RX_EQ_OFFSET_ADAPTOR_CNTRL1 ,0x24 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_RX_OFFSET_ADAPTOR_CNTRL3 ,0x08 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_EOM_CTRL1 ,0x10 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_EOM_CTRL2 ,0x21 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_TAP3_MANVAL_KTAP ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_TAP4_MANVAL_KTAP ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_DFE_TAP5_MANVAL_KTAP ,0x06 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_VTHRESH_CAL_MAN_VAL_RATE3 ,0x78 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_Q_PI_INTRINSIC_BIAS_RATE32 ,0x27 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_RX_BKUP_CTRL1 ,0x14 ), +}; +static const struct qmp_phy_init_tbl x1e80100_usb43dp_rx_tbl[] = {QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_SIGDET_CNTRL ,0x04 ),QMP_PHY_INIT_CFG (QSERDES_V6_N4_RX_SIGDET_DEGLITCH_CNTRL ,0x0e ),
@@ -2066,6 +2207,23 @@ static const struct qmp_phy_init_tbl x1e80100_usb43dp_rx_tbl[] = { QMP_PHY_INIT_CFG(QSERDES_V6_N4_RX_RX_BKUP_CTRL1, 0x14), }; +static const struct qmp_phy_init_tbl x1e80100_usb4_pcs_tbl[] = { +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_POWER_STATE_CONFIG3 ,0x4f ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_LOCK_DETECT_CONFIG1 ,0x03 ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_LOCK_DETECT_CONFIG2 ,0xc0 ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_RX_SIGDET_LVL ,0x55 ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_PCS_PCS_TX_RX_CONFIG1 ,0x51 ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_EQ_CONFIG1 ,0x2e ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_G3_EQ_CONFIG1 ,0x4b ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_G3_EQ_CONFIG5 ,0x1e ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_G2_FOM_EQ_CONFIG1 ,0x83 ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_G2_FOM_EQ_CONFIG3 ,0x2e ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_G2_FOM_EQ_CONFIG5 ,0x10 ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_G3_FOM_EQ_CONFIG3 ,0x25 ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_G3_FOM_EQ_CONFIG5 ,0x22 ), +QMP_PHY_INIT_CFG (QPHY_V6_PCS_USB4_LPFS_TX_ECSTART ,0x0f ), +}; +static const struct qmp_phy_init_tbl x1e80100_usb43dp_pcs_tbl[] = {QMP_PHY_INIT_CFG (QPHY_V6_N4_PCS_RCVR_DTCT_DLY_P1U2_L ,0xe7 ),QMP_PHY_INIT_CFG (QPHY_V6_N4_PCS_RCVR_DTCT_DLY_P1U2_H ,0x03 ),
@@ -2720,6 +2878,23 @@ static const struct qmp_combo_offsets qmp_combo_offsets_v5 = { .dp_dp_phy = 0x2200, }; +static const struct qmp_combo_offsets qmp_combo_offsets_v6_n4 = { + .com =0x0000 , + .usb3_pcs_aon =0x0100 , + .txa =0x0400 , + .rxa =0x0600 , + .txb =0x0a00 , + .rxb =0x0c00 , + .usb3_serdes =0x1000 , + .usb3_pcs_misc =0x1200 , + .usb3_pcs =0x1400 , + .usb3_pcs_usb =0x1700 , + .dp_serdes =0x2000 , + .dp_dp_phy =0x2200 , + .usb4_serdes =0x3000 , + .usb4_pcs =0x3400 , +}; +static const struct qmp_combo_offsets qmp_combo_offsets_v8 = { .com =0x0000 , .txa =0x1400 ,
@@ -2995,11 +3170,11 @@ static const struct qmp_phy_cfg sc8280xp_usb43dpphy_cfg = { .regs = qmp_v5_5nm_usb3phy_regs_layout, }; -static const struct qmp_phy_cfg x1e80100_usb3dpphy_cfg = { - .offsets = &qmp_combo_offsets_v5, +static const struct qmp_phy_cfg x1e80100_usb43dpphy_cfg = { + .offsets = &qmp_combo_offsets_v6_n4, - .serdes_tbl = x1e80100_usb43dp_serdes_tbl, - .serdes_tbl_num =ARRAY_SIZE (x1e80100_usb43dp_serdes_tbl), + .serdes_tbl = x1e80100_usb3dp_serdes_tbl, + .serdes_tbl_num =ARRAY_SIZE (x1e80100_usb3dp_serdes_tbl), .tx_tbl = x1e80100_usb43dp_tx_tbl, .tx_tbl_num =ARRAY_SIZE (x1e80100_usb43dp_tx_tbl), .rx_tbl = x1e80100_usb43dp_rx_tbl,
@@ -3033,6 +3208,19 @@ static const struct qmp_phy_cfg x1e80100_usb3dpphy_cfg = { .configure_dp_clocks = qmp_v3_configure_dp_clocks, .configure_dp_phy = qmp_v4_configure_dp_phy, + .usb4_serdes_tbl = x1e80100_usb4_serdes_tbl, + .usb4_serdes_tbl_num = ARRAY_SIZE(x1e80100_usb4_serdes_tbl), + .usb4_serdes_tb3_ovrd_tbl = x1e80100_usb4_tb3_serdes_tbl, + .usb4_serdes_tb3_ovrd_num = ARRAY_SIZE(x1e80100_usb4_tb3_serdes_tbl), + + .usb4_tx_tbl = x1e80100_usb4_tx_tbl, + .usb4_tx_tbl_num = ARRAY_SIZE(x1e80100_usb4_tx_tbl), + .usb4_rx_tbl = x1e80100_usb4_rx_tbl, + .usb4_rx_tbl_num = ARRAY_SIZE(x1e80100_usb4_rx_tbl), + + .usb4_pcs_tbl = x1e80100_usb4_pcs_tbl, + .usb4_pcs_tbl_num = ARRAY_SIZE(x1e80100_usb4_pcs_tbl), + .reset_list = msm8996_usb3phy_reset_l, .num_resets = ARRAY_SIZE(msm8996_usb3phy_reset_l), .vreg_list = qmp_phy_vreg_l,
@@ -5683,7 +5871,7 @@ static const struct of_device_id qmp_combo_of_match_table[] = { }, { .compatible = "qcom,x1e80100-qmp-usb3-dp-phy", - .data = &x1e80100_usb3dpphy_cfg, + .data = &x1e80100_usb43dpphy_cfg, }, { } };
drivers/phy/qualcomm/phy-qcom-qmp-pcs-aon-v6.h +2 -0
@@ -8,5 +8,7 @@/* Only for QMP V6 PHY - PCS_AON registers */ #define QPHY_V6_PCS_AON_CLAMP_ENABLE 0x00 +/* Valid only for USB43DP variants */ +#define QPHY_V6_PCS_AON_USB4_CLAMP_ENABLE 0x04#endif
drivers/phy/qualcomm/phy-qcom-qmp-pcs-usb-v6.h +15 -0
@@ -14,4 +14,19 @@#define QPHY_V6_PCS_USB3_RCVR_DTCT_DLY_U3_L 0x40#define QPHY_V6_PCS_USB3_RCVR_DTCT_DLY_U3_H 0x44 +#define QPHY_V6_PCS_USB4_POWER_STATE_CONFIG3 0x98 +#define QPHY_V6_PCS_USB4_LOCK_DETECT_CONFIG1 0xd0 +#define QPHY_V6_PCS_USB4_LOCK_DETECT_CONFIG2 0xd4 +#define QPHY_V6_PCS_USB4_RX_SIGDET_LVL 0x17c +#define QPHY_V6_PCS_USB4_PCS_PCS_TX_RX_CONFIG1 0x1a8 +#define QPHY_V6_PCS_USB4_EQ_CONFIG1 0x1b8 +#define QPHY_V6_PCS_USB4_G3_EQ_CONFIG1 0x1d8 +#define QPHY_V6_PCS_USB4_G3_EQ_CONFIG5 0x1e8 +#define QPHY_V6_PCS_USB4_G2_FOM_EQ_CONFIG1 0x1f4 +#define QPHY_V6_PCS_USB4_G2_FOM_EQ_CONFIG3 0x1fc +#define QPHY_V6_PCS_USB4_G2_FOM_EQ_CONFIG5 0x204 +#define QPHY_V6_PCS_USB4_G3_FOM_EQ_CONFIG3 0x210 +#define QPHY_V6_PCS_USB4_G3_FOM_EQ_CONFIG5 0x218 +#define QPHY_V6_PCS_USB4_LPFS_TX_ECSTART 0x220 +#endif
drivers/phy/qualcomm/phy-qcom-qmp-qserdes-txrx-v6_n4.h +45 -0
78 lines not on this page · raw message
Signature · 1 line
2.55.0
Konrad Dybcio
maintainerPATCH v5 5/5 arm64: dts: qcom: hamoa: Extend QMPPHY description for USB4
In reply to Konrad DybcioFrom: Konrad Dybcio <[email protected]>
The USB4 part of the QMPPHY requires that one more GCC clock (P2RR2P - PHY-to-Router, Router-to-PHY) is enabled for the PHY to initialize successfully. Describe that.
--- arch/arm64/boot/dts/qcom/hamoa.dtsi | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
arch/arm64/boot/dts/qcom/hamoa.dtsi +12 -6
@@ -2838,11 +2838,13 @@ usb_1_ss0_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"; power-domains = <&gcc GCC_USB_0_PHY_GDSC>;
@@ -2909,11 +2911,13 @@ usb_1_ss1_qmpphy: phy@fda000 { 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>;
@@ -2980,11 +2984,13 @@ usb_1_ss2_qmpphy: phy@fdf000 { 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>;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v5 4/5] phy: qualcomm: qmp-combo: Add USB4/TBT3 configuration data for Hamoa
In reply to Konrad DybcioThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [Low] Incorrect prefix for RX UCDR FASTLOCK_COUNTER registers.
- [Low] Typo in USB4 LFPS register name (written as LPFS).
- [Low] Register sort order violation in header file.
Pre-existing issues:
- [Critical] Unclocked and unpowered register access in qmp_combo_com_init when in USB4 mode. --
commit dbef849ad62b34a45390169ec84b4136bf981184
Author: Konrad Dybcio <[email protected]>
phy: qualcomm: qmp-combo: Add USB4/TBT3 configuration data for Hamoa
Add the offsets and configuration tables to support USB4 and Thunderbolt 3 operation on the USB4-capable PHYs found on Hamoa chips.
drivers/phy/qualcomm/phy-qcom-qmp-combo.c static const unsigned int qmp_v6_n4_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = { · line 243
Quoted 9 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +1
-0@@ -240,6 +240,7 @@ static const unsigned int qmp_v6_n4_usb3phy_regs_layout[QPHY_LAYOUT_SIZE] = { [QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR] = QPHY_V6_PCS_USB3_LFPS_RXTERM_IRQ_CLEAR, [QPHY_PCS_CLAMP_ENABLE] = QPHY_V6_PCS_AON_CLAMP_ENABLE, + [QPHY_PCS_USB4_CLAMP_ENABLE] = QPHY_V6_PCS_AON_USB4_CLAMP_ENABLE,
[Severity: Critical]
This is a pre-existing issue, but providing this layout entry exposes qmp_combo_com_init() to an unclocked and unpowered register access in USB4 mode.
When qmp->qmpphy_mode == QMPPHY_MODE_USB4, qmp_combo_com_init() immediately executes qphy_setbits() using QPHY_PCS_USB4_CLAMP_ENABLE. This occurs before regulator_bulk_enable() and clk_bulk_prepare_enable() are called later in the function.
Accessing unclocked and unpowered APB/AHB mapped registers can cause a synchronous external abort (bus hang). Could this access be deferred until after the clocks and regulators are enabled?
[ ... ]
Quoted 1 line
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +0
-0@@ -2028,6 +2107,68 @@ static const struct qmp_phy_init_tbl x1e80100_usb43dp_tx_tbl[] = {
[ ... ]
Quoted 1 line
+static const struct
qmp_phy_init_tblx1e80100_usb4_rx_tbl[] = {
[ ... ]
drivers/phy/qualcomm/phy-qcom-qmp-combo.c static const struct qmp_phy_init_tbl x1e80100_usb43dp_tx_tbl[] = { · line 2128
Quoted 4 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +4
-0+QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_UCDR_FASTLOCK_COUNTER_LOW_RATE2 ,0x30 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_UCDR_FASTLOCK_COUNTER_HIGH_RATE2 ,0x14 ), +QMP_PHY_INIT_CFG (QSERDES_V6_N4_TX_UCDR_FASTLOCK_COUNTER_LOW_RATE3 ,0xff ), + QMP_PHY_INIT_CFG(QSERDES_V6_N4_TX_UCDR_FASTLOCK_COUNTER_HIGH_RATE3, 0x3f),
[Severity: Low]
Are these TX macros intentionally placed in the rx_tbl, or do they refer to RX UCDR FASTLOCK_COUNTER registers?
If they are UCDR registers mapping into the RX hardware block, should they have the QSERDES_V6_N4_RX_ prefix instead to prevent confusion?
Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-pcs-usb-v6.h +0
-0@@ -14,4 +14,19 @@
[ ... ]
drivers/phy/qualcomm/phy-qcom-qmp-pcs-usb-v6.h line 30
Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-qmp-pcs-usb-v6.h +3
-0+#define QPHY_V6_PCS_USB4_G3_FOM_EQ_CONFIG3 0x210 +#define QPHY_V6_PCS_USB4_G3_FOM_EQ_CONFIG5 0x218 +#define QPHY_V6_PCS_USB4_LPFS_TX_ECSTART 0x220
[Severity: Low]
Is this intended to be LFPS (Low Frequency Periodic Signaling) instead of LPFS? It might be clearer to name it QPHY_V6_PCS_USB4_LFPS_TX_ECSTART to match standard USB protocol terminology.
Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-qserdes-txrx-v6_n4.h +0
-0@@ -23,27 +23,63 @@
[ ... ]
drivers/phy/qualcomm/phy-qcom-qmp-qserdes-txrx-v6_n4.h line 38
Quoted 4 lines
#define
QSERDES_V6_N4_RX_UCDR_FO_GAIN_RATE20x8drivers/phy/qualcomm/phy-qcom-qmp-qserdes-txrx-v6_n4.h +2
-0+#define QSERDES_V6_N4_RX_UCDR_FO_GAIN_RATE3 0xc +#define QSERDES_V6_N4_RX_UCDR_SO_GAIN_RATE3 0x1c#define QSERDES_V6_N4_RX_UCDR_SO_GAIN_RATE2 0x18
[Severity: Low]
Does this break the numerical sort order of the register offsets? Offset 0x1c is defined here before 0x18.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v5 3/5] phy: qualcomm: qmp-combo: Add preliminary USB4 support
In reply to Konrad DybcioThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
New issues:
- [Critical] Accessing PHY registers before enabling clocks in qmp_combo_com_init causes a synchronous external abort.
- [High] Type-C mux events fail to update qmpphy_mode when the PHY is uninitialized, leading to stale state and broken subsequent connections.
- [High] Double initialization of the USB4 PHY when transitioning from an active USB3 state clobbers the active hardware state.
- [High] PHY mode and power state are not restored if USB4 power-on fails.
- [Medium] Data race on shared state qmp->orientation due to unprotected access in qmp_combo_typec_switch_set.
Pre-existing issues:
- [High] Preexisting race condition: qmp_combo_typec_mux_set modifies shared PHY state and hardware without holding phy_mutex. --
commit e68a240bfd6571e7ac31565bbc5b1911cba807e3
Author: Konrad Dybcio <[email protected]>
Subject: phy: qualcomm: qmp-combo: Add preliminary USB4 support
This commit introduces preliminary USB4 support for Combo PHYs on certain Qualcomm platforms (SC8280XP, X1E80100, Glymur). It adds a new struct phy to expose the USB4 mode and modifies the PHY mode management to support mutually exclusive toggling between USB4/TBT3 and USB3/DP operation.
Quoted 4 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +0
-0
[ ... ]
Quoted 17 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +6
-0@@ -4006,6 +4036,9 @@ static int qmp_combo_dp_calibrate(struct phy *phy)static int qmp_combo_com_init (struct qmp_combo *qmp,bool force) {const struct qmp_phy_cfg *cfg = qmp->cfg; +u32 dp_reset_val =SW_DPPHY_RESET_MUX |SW_DPPHY_RESET ; +void __iomem *pcs_aon = qmp->pcs_aon; +void __iomem *pcs = qmp->pcs;void __iomem *com = qmp->com;void __iomem *aon_toggle;int ret;@@ -4019,6 +4052,16 @@ static int qmp_combo_com_init(struct qmp_combo *qmp, bool force)else aon_toggle = qmp->pcs_aon; +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 ) { + pcs = qmp->usb4_pcs; +
drivers/phy/qualcomm/phy-qcom-qmp-combo.c static int qmp_combo_com_init(struct qmp_combo *qmp, bool force) · line 4067
Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +7
-0+qphy_setbits (pcs_aon, cfg->regs[QPHY_PCS_USB4_CLAMP_ENABLE ],CLAMP_EN ); + +/* Do not disturb the DP PLL in case there's an active DP tunnel */ +if (readl (com +QPHY_V3_DP_COM_RESET_OVRD_CTRL ) &DP_TUNNELING_CLOCK_GEN_EN ) + dp_reset_val &= ~SW_DPPHY_RESET_MUX ; + } + ret =regulator_bulk_enable (cfg->num_vregs, qmp->vregs);if (ret) {dev_err (qmp->dev,"failed to enable regulators, err=%d\n" , ret);
[Severity: Critical]
Does accessing these memory-mapped registers before enabling clocks cause a synchronous external abort?
When transitioning to USB4 mode, qmp_combo_reconfigure_phy() calls qmp_combo_com_exit(qmp, true) which disables all PHY clocks. Immediately after, it calls qmp_combo_com_init(qmp, true), executing this block where it reads from and writes to the PHY registers before regulator_bulk_enable() and clk_bulk_prepare_enable() are called below.
[ ... ]
Quoted 61 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +57
-0@@ -4343,6 +4454,125 @@ static int qmp_combo_usb_set_mode(struct phy *phy, enum phy_mode mode, int submoreturn 0 ; } +static int qmp_combo_reconfigure_phy (struct qmp_combo *qmp,enum qmpphy_mode new_mode) +{ +dev_dbg (qmp->dev,"qmp_combo_reconfigure_phy: switching from qmpphy mode %d to %d\n" , + qmp->qmpphy_mode, new_mode); + +if (qmp->usb_init_count || qmp->usb4_init_count) +qmp_combo_usb_power_off (qmp->usb_phy); + +if (qmp->dp_init_count) +writel (DP_PHY_PD_CTL_PSR_PWRDN , qmp->dp_dp_phy +QSERDES_DP_PHY_PD_CTL ); + +qmp_combo_com_exit (qmp, true); + + qmp->qmpphy_mode = new_mode; + +/* Now everything's powered down, power up the right PHYs */ +qmp_combo_com_init (qmp, true); + +if ((qmp->usb_init_count || qmp->usb4_init_count) && + new_mode !=QMPPHY_MODE_DP_ONLY ) +qmp_combo_usb_power_on (qmp->usb_phy); + +if ((new_mode ==QMPPHY_MODE_USB3DP || new_mode ==QMPPHY_MODE_DP_ONLY ) && + qmp->dp_init_count) + qmp->cfg->dp_aux_init (qmp); + +return 0 ; +} + +static int qmp_combo_usb4_init (struct phy *phy) +{ +struct qmp_combo *qmp =phy_get_drvdata (phy); +int ret; + +guard (mutex)(&qmp->phy_mutex); + +if (!qmp->p2rr2p_pipe_clk) { +dev_err (qmp->dev,"missing p2rr2p_pipe clock handle. Update your Device Tree.\n" ); +return -EINVAL ; + } + + ret =clk_prepare_enable (qmp->p2rr2p_pipe_clk); +if (ret) { +dev_err (qmp->dev,"p2rr2p_pipe enable failed: %d\n" , ret); +return ret; + } + + ret =qmp_combo_com_init (qmp, false); +if (ret) { +clk_disable_unprepare (qmp->p2rr2p_pipe_clk); +return ret; + } + +/* USB4 mode takes precedence to USB3(+DP), force reconfigure the PHY */ + ret =qmp_combo_reconfigure_phy (qmp,QMPPHY_MODE_USB4 ); +if (ret) { +clk_disable_unprepare (qmp->p2rr2p_pipe_clk);
drivers/phy/qualcomm/phy-qcom-qmp-combo.c static int qmp_combo_usb_set_mode(struct phy *phy, enum phy_mode mode, int submo · line 4523
Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +10
-0+qmp_combo_com_exit (qmp, false); +return ret; + } + + ret =qmp_combo_usb_power_on (phy); +if (ret) { +clk_disable_unprepare (qmp->p2rr2p_pipe_clk); +qmp_combo_com_exit (qmp, false); +return ret; + }
[Severity: High]
Does this execute a double initialization of the USB4 PHY?
When qmp_combo_reconfigure_phy() is called and the USB3 PHY is already active (qmp->usb_init_count > 0), it tears down the connection and calls qmp_combo_usb_power_on() to start the hardware in the new USB4 mode. Since it has already started the PHY hardware state machine, does calling qmp_combo_usb_power_on() again immediately after clobber the active hardware state?
[Severity: High]
If this second call to qmp_combo_usb_power_on() fails (for example due to a PHY status poll timeout), does the error path fail to restore the PHY mode and power state?
qmp_combo_reconfigure_phy() modifies qmp->qmpphy_mode and shuts down the active USB3/DP PHYs. If power-on fails here, qmp->qmpphy_mode is not restored and the previously active PHYs are left powered off, leaving the USB3/DP drivers believing the PHY is initialized.
[ ... ]
Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +2
-0@@ -4779,24 +5022,29 @@ static int qmp_combo_typec_switch_set(struct typec_switch_dev *sw,struct qmp_combo *qmp =typec_switch_get_drvdata (sw);const struct qmp_phy_cfg *cfg = qmp->cfg; +if (qmp->qmpphy_mode ==QMPPHY_MODE_USB4 ) { +/* QMPPHY has no orientation handling in USB4 mode, don't cache the setting */
drivers/phy/qualcomm/phy-qcom-qmp-combo.c static int qmp_combo_typec_switch_set(struct typec_switch_dev *sw, · line 5035
Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +5
-1+ qmp->orientation =TYPEC_ORIENTATION_NONE ; +return 0 ; + } +if (orientation == qmp->orientation || orientation ==TYPEC_ORIENTATION_NONE )return 0 ; -mutex_lock (&qmp->phy_mutex); +guard (mutex)(&qmp->phy_mutex); qmp->orientation = orientation;
[Severity: Medium]
Does writing to qmp->orientation here without holding qmp->phy_mutex introduce a data race?
This write bypasses the subsequent guard(mutex)(&qmp->phy_mutex) used for normal orientation caching, creating a concurrent memory access violation if PHY initialization (such as qmp_combo_com_init) is running in parallel during Type-C switch events.
[ ... ]
Quoted 34 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +0
-30@@ -4847,41 +5117,11 @@ static int qmp_combo_typec_mux_set(struct typec_mux_dev *mux, struct typec_mux_sreturn 0 ; } -dev_dbg (qmp->dev,"typec_mux_set: switching from qmpphy mode %d to %d\n" , - qmp->qmpphy_mode, new_mode); - - qmp->qmpphy_mode = new_mode; - -if (qmp->init_count) { -if (qmp->usb_init_count) -qmp_combo_usb_power_off (qmp->usb_phy); - -if (qmp->dp_init_count) -writel (DP_PHY_PD_CTL_PSR_PWRDN , qmp->dp_dp_phy +QSERDES_DP_PHY_PD_CTL ); - -qmp_combo_com_exit (qmp, true); - -/* Now everything's powered down, power up the right PHYs */ -qmp_combo_com_init (qmp, true); - -if (new_mode ==QMPPHY_MODE_DP_ONLY ) { -if (qmp->usb_init_count) - qmp->usb_init_count--; - } - -if (new_mode ==QMPPHY_MODE_USB3DP || new_mode ==QMPPHY_MODE_USB3_ONLY ) { -qmp_combo_usb_power_on (qmp->usb_phy); -if (!qmp->usb_init_count) - qmp->usb_init_count++; - } - -if (new_mode ==QMPPHY_MODE_DP_ONLY || new_mode ==QMPPHY_MODE_USB3DP ) { -if (qmp->dp_init_count)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c static int qmp_combo_typec_mux_set(struct typec_mux_dev *mux, struct typec_mux_s · line 5125
Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +4
-4- cfg->dp_aux_init (qmp); - } - } +/* The mux still receives Type-C events, even if all PHYs are uninitialized */ +if (!qmp->init_count) +return 0 ; -return 0 ; +return qmp_combo_reconfigure_phy (qmp, new_mode); }
[Severity: High]
Does this early return prevent qmp->qmpphy_mode from tracking the actual Type-C mux state while the PHY is powered down?
If a USB4 device is unplugged, init_count drops to 0 and qmpphy_mode remains QMPPHY_MODE_USB4. If a USB3 device is then plugged in, this check returns early and fails to update qmp->qmpphy_mode. Later, when the USB controller calls phy_init(), the PHY is programmed using the stale USB4 mode without orientation, which can break the SuperSpeed link.
[Severity: High]
This is a pre-existing issue, but does calling qmp_combo_reconfigure_phy() from qmp_combo_typec_mux_set() modify shared PHY state and hardware without holding qmp->phy_mutex?
qmp_combo_typec_mux_set() is called by the Type-C workqueue without holding the mutex. It calls qmp_combo_reconfigure_phy(), which updates qmp->qmpphy_mode and programs PHY hardware registers. This seems to race with PHY lifecycle operations running in the USB controller thread, which do acquire phy_mutex to protect these exact same variables and registers.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: (subset) [PATCH v5 0/5] USB4 mode programming for QMMPHY on X1E
In reply to Konrad DybcioQuoted 9 lines · Konrad Dybcio
The USB43DP QMP PHY, as the name suggests, supports USB4 in addition to DP/USB. This series provides the necessary plumbing to switch to that mode of operation on hamoa/purwa.
This is achieved by exposing a third
struct phy *for the USB4 sub- PHY, which will be toggled by the USB4 router driver, living within the Thunderbolt framework, which will be posted separately.[...]
Applied, thanks!
[1/5] dt-bindings: phy: qcom,qmp-usb3-dp: Extend X1E description for USB4
commit: 1b8595f4cc9f4029d11ea1957a4c9b4bce3f6872
[2/5] phy: core: Define TBT phy_mode
commit: bc70554e6294d71fde45895223881a4ac3769630
[3/5] phy: qualcomm: qmp-combo: Add preliminary USB4 support
commit: bb8955305318217526e6f9e93ee150888d91d4ea
[4/5] phy: qualcomm: qmp-combo: Add USB4/TBT3 configuration data for Hamoa
commit: 0e1288af882068dbaf6e64808ba23c95a80dc916Best regards,
Signature · 1 line
~Vinod
Re: (subset) [PATCH v5 0/5] USB4 mode programming for QMMPHY on X1E
Quoted 14 lines · Vinod Koul
Quoted 9 lines · Konrad Dybcio
The USB43DP QMP PHY, as the name suggests, supports USB4 in addition to DP/USB. This series provides the necessary plumbing to switch to that mode of operation on hamoa/purwa.
This is achieved by exposing a third
struct phy *for the USB4 sub- PHY, which will be toggled by the USB4 router driver, living within the Thunderbolt framework, which will be posted separately.[...]
Applied, thanks!
Quoted 8 lines
[1/5] dt-bindings: phy: qcom,qmp-usb3-dp: Extend X1E description for USB4
commit: 1b8595f4cc9f4029d11ea1957a4c9b4bce3f6872 [2/5] phy: core: Define TBT phy_mode commit: bc70554e6294d71fde45895223881a4ac3769630 [3/5] phy: qualcomm: qmp-combo: Add preliminary USB4 support commit: bb8955305318217526e6f9e93ee150888d91d4ea [4/5] phy: qualcomm: qmp-combo: Add USB4/TBT3 configuration data for Hamoa commit: 0e1288af882068dbaf6e64808ba23c95a80dc916
Patch 4 is missing from your branch and consequently from next, other patches are there
Konrad
Re: (subset) [PATCH v5 0/5] USB4 mode programming for QMMPHY on X1E
In reply to Konrad DybcioQuoted 9 lines · Konrad Dybcio
The USB43DP QMP PHY, as the name suggests, supports USB4 in addition to DP/USB. This series provides the necessary plumbing to switch to that mode of operation on hamoa/purwa.
This is achieved by exposing a third
struct phy *for the USB4 sub- PHY, which will be toggled by the USB4 router driver, living within the Thunderbolt framework, which will be posted separately.[...]
Applied, thanks!
[5/5] arm64: dts: qcom: hamoa: Extend QMPPHY description for USB4
commit: 1360126eeb38872b68f5b89d793bd28e328224fd
Best regards,
Signature · 1 line
Bjorn Andersson <[email protected]>