diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c index 604db7f1780d9..cdb2c2a32cdc8 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c @@ -2575,6 +2575,8 @@ struct qmp_phy_cfg { /* true, if PHY needs delay after POWER_DOWN */ bool has_pwrdn_delay; + /* Program only the orientation-selected DP TX block for fewer than 4 lanes */ + bool dp_tx_orientation_aware; /* Offset from PCS to PCS_USB region */ unsigned int pcs_usb_offset; @@ -3381,6 +3383,7 @@ static const struct qmp_phy_cfg sm8750_usb3dpphy_cfg = { static const struct qmp_phy_cfg glymur_usb3dpphy_cfg = { .offsets = &qmp_combo_usb43dp_offsets_v8, + .dp_tx_orientation_aware = true, .serdes_tbl = glymur_usb43dp_serdes_tbl, .serdes_tbl_num = ARRAY_SIZE(glymur_usb43dp_serdes_tbl), @@ -3550,12 +3553,29 @@ static void qmp_v3_dp_aux_init(struct qmp_combo *qmp) qmp->dp_dp_phy + QSERDES_V3_DP_PHY_AUX_INTERRUPT_MASK); } +static u8 qmp_combo_dp_tx_mask(struct qmp_combo *qmp) +{ + const struct qmp_phy_cfg *cfg = qmp->cfg; + unsigned int lanes = qmp->dp_opts.lanes; + + /* Keep existing behavior for other PHYs and unsupported lane counts. */ + if (!cfg->dp_tx_orientation_aware || (lanes != 1 && lanes != 2 && lanes != 4)) + return BIT(0) | BIT(1); + + if (lanes == 4) + return BIT(0) | BIT(1); + + /* CC2/reverse uses TX0 and CC1/normal uses TX1. */ + return qmp->orientation == TYPEC_ORIENTATION_REVERSE ? BIT(0) : BIT(1); +} + static int qmp_combo_configure_dp_swing(struct qmp_combo *qmp) { const struct phy_configure_opts_dp *dp_opts = &qmp->dp_opts; const struct qmp_phy_cfg *cfg = qmp->cfg; unsigned int v_level = 0, p_level = 0; u8 voltage_swing_cfg, pre_emphasis_cfg; + u8 tx_mask; int i; for (i = 0; i < dp_opts->lanes; i++) { @@ -3579,10 +3599,18 @@ static int qmp_combo_configure_dp_swing(struct qmp_combo *qmp) voltage_swing_cfg |= DP_PHY_TXn_TX_DRV_LVL_MUX_EN; pre_emphasis_cfg |= DP_PHY_TXn_TX_EMP_POST1_LVL_MUX_EN; - writel(voltage_swing_cfg, qmp->dp_tx + cfg->regs[QPHY_TX_TX_DRV_LVL]); - writel(pre_emphasis_cfg, qmp->dp_tx + cfg->regs[QPHY_TX_TX_EMP_POST1_LVL]); - writel(voltage_swing_cfg, qmp->dp_tx2 + cfg->regs[QPHY_TX_TX_DRV_LVL]); - writel(pre_emphasis_cfg, qmp->dp_tx2 + cfg->regs[QPHY_TX_TX_EMP_POST1_LVL]); + tx_mask = qmp_combo_dp_tx_mask(qmp); + + if (tx_mask & BIT(0)) { + writel(voltage_swing_cfg, qmp->dp_tx + cfg->regs[QPHY_TX_TX_DRV_LVL]); + writel(pre_emphasis_cfg, + qmp->dp_tx + cfg->regs[QPHY_TX_TX_EMP_POST1_LVL]); + } + if (tx_mask & BIT(1)) { + writel(voltage_swing_cfg, qmp->dp_tx2 + cfg->regs[QPHY_TX_TX_DRV_LVL]); + writel(pre_emphasis_cfg, + qmp->dp_tx2 + cfg->regs[QPHY_TX_TX_EMP_POST1_LVL]); + } return 0; } @@ -3855,13 +3883,17 @@ static void qmp_v8_dp_aux_init(struct qmp_combo *qmp) static void qmp_v4_configure_dp_tx(struct qmp_combo *qmp) { const struct qmp_phy_cfg *cfg = qmp->cfg; + u8 tx_mask = qmp_combo_dp_tx_mask(qmp); /* Program default values before writing proper values */ - writel(0x27, qmp->dp_tx + cfg->regs[QPHY_TX_TX_DRV_LVL]); - writel(0x27, qmp->dp_tx2 + cfg->regs[QPHY_TX_TX_DRV_LVL]); - - writel(0x2b, qmp->dp_tx + cfg->regs[QPHY_TX_TX_EMP_POST1_LVL]); - writel(0x2b, qmp->dp_tx2 + cfg->regs[QPHY_TX_TX_EMP_POST1_LVL]); + if (tx_mask & BIT(0)) { + writel(0x27, qmp->dp_tx + cfg->regs[QPHY_TX_TX_DRV_LVL]); + writel(0x2b, qmp->dp_tx + cfg->regs[QPHY_TX_TX_EMP_POST1_LVL]); + } + if (tx_mask & BIT(1)) { + writel(0x27, qmp->dp_tx2 + cfg->regs[QPHY_TX_TX_DRV_LVL]); + writel(0x2b, qmp->dp_tx2 + cfg->regs[QPHY_TX_TX_EMP_POST1_LVL]); + } qmp_combo_configure_dp_swing(qmp); } @@ -4009,6 +4041,7 @@ static int qmp_v8_configure_dp_phy(struct qmp_combo *qmp) bool reverse = (qmp->orientation == TYPEC_ORIENTATION_REVERSE); const struct phy_configure_opts_dp *dp_opts = &qmp->dp_opts; u32 bias0_en, drvr0_en, bias1_en, drvr1_en; + u8 tx_mask; u32 status; int ret; @@ -4016,6 +4049,8 @@ static int qmp_v8_configure_dp_phy(struct qmp_combo *qmp) if (ret < 0) return ret; + tx_mask = qmp_combo_dp_tx_mask(qmp); + if (dp_opts->lanes == 1) { bias0_en = reverse ? 0x3e : 0x15; bias1_en = reverse ? 0x15 : 0x3e; @@ -4033,17 +4068,25 @@ static int qmp_v8_configure_dp_phy(struct qmp_combo *qmp) drvr1_en = 0x30; } - writel(drvr0_en, qmp->dp_tx + cfg->regs[QPHY_TX_HIGHZ_DRVR_EN]); - writel(bias0_en, qmp->dp_tx + cfg->regs[QPHY_TX_TRANSCEIVER_BIAS_EN]); - writel(drvr1_en, qmp->dp_tx2 + cfg->regs[QPHY_TX_HIGHZ_DRVR_EN]); - writel(bias1_en, qmp->dp_tx2 + cfg->regs[QPHY_TX_TRANSCEIVER_BIAS_EN]); + if (tx_mask & BIT(0)) { + writel(drvr0_en, qmp->dp_tx + cfg->regs[QPHY_TX_HIGHZ_DRVR_EN]); + writel(bias0_en, + qmp->dp_tx + cfg->regs[QPHY_TX_TRANSCEIVER_BIAS_EN]); + } + if (tx_mask & BIT(1)) { + writel(drvr1_en, qmp->dp_tx2 + cfg->regs[QPHY_TX_HIGHZ_DRVR_EN]); + writel(bias1_en, + qmp->dp_tx2 + cfg->regs[QPHY_TX_TRANSCEIVER_BIAS_EN]); + } writel(0x03, qmp->dp_dp_phy + QSERDES_V8_DP_PHY_TSYNC_OVRD); writel(0x23, qmp->dp_dp_phy + QSERDES_V8_DP_PHY_TSYNC_OVRD); writel(0x22, qmp->dp_dp_phy + QSERDES_V8_DP_PHY_TSYNC_OVRD); - writel(0x0a, qmp->dp_tx + QSERDES_V8_LALB_RESET_TSYNC_EN_CTRL); - writel(0x0a, qmp->dp_tx2 + QSERDES_V8_LALB_RESET_TSYNC_EN_CTRL); + if (tx_mask & BIT(0)) + writel(0x0a, qmp->dp_tx + QSERDES_V8_LALB_RESET_TSYNC_EN_CTRL); + if (tx_mask & BIT(1)) + writel(0x0a, qmp->dp_tx2 + QSERDES_V8_LALB_RESET_TSYNC_EN_CTRL); writel(0x3e, qmp->dp_dp_phy + QSERDES_V8_DP_PHY_TSYNC_OVRD); @@ -4286,13 +4329,20 @@ static int qmp_combo_dp_power_on(struct phy *phy) const struct qmp_phy_cfg *cfg = qmp->cfg; void __iomem *tx = qmp->dp_tx; void __iomem *tx2 = qmp->dp_tx2; + u8 tx_mask; mutex_lock(&qmp->phy_mutex); qmp_combo_dp_serdes_init(qmp); - qmp_configure_lane(qmp->dev, tx, cfg->dp_tx_tbl, cfg->dp_tx_tbl_num, 1); - qmp_configure_lane(qmp->dev, tx2, cfg->dp_tx_tbl, cfg->dp_tx_tbl_num, 2); + tx_mask = qmp_combo_dp_tx_mask(qmp); + + if (tx_mask & BIT(0)) + qmp_configure_lane(qmp->dev, tx, cfg->dp_tx_tbl, + cfg->dp_tx_tbl_num, 1); + if (tx_mask & BIT(1)) + qmp_configure_lane(qmp->dev, tx2, cfg->dp_tx_tbl, + cfg->dp_tx_tbl_num, 2); /* Configure special DP tx tunings */ cfg->configure_dp_tx(qmp);