[PATCH v2 1/2] phy: exynos5-usbdrd: gs101: re-init PIPE3 on orientation change
Peter Griffin
peter.griffin at linaro.org
Wed Nov 25 13:03:29 PST 2026
On Mon, 23 Nov 2026 at 14:25, André Draszik <andre.draszik at linaro.org> wrote:
>
> The SS lane mux on gs101 is programmed only when the PIPE3 phy is
> initialized, based on the Type-C orientation known at that time.
> The orientation switch callback just stores the new orientation and
> relies on the USB controller to exit and re-initialize the phy, which
> only happens if DWC3 enters runtime suspend.
>
> If a cable is connected during boot, the phy is initialized before the
> TCPC reports the orientation (e.g. ~4.0s vs. ~5.3s on Pixel 6), so the
> lanes are programmed for TYPEC_ORIENTATION_NONE, i.e. as if reversed.
> DWC3 doesn't runtime suspend while the cable stays connected (and
> runtime PM is forbidden by default anyway), so the phy is never
> re-initialized and the link comes up in high-speed only.
>
> Re-run the PIPE3 init from the orientation switch callback if the
> PIPE3 phy is initialized and its lanes are programmed for the other
> orientation. Rewriting the lane mux registers alone isn't sufficient,
> the link still comes up in high-speed only with that. Re-initialize
> before signalling VBUS valid, so that DWC3 only sees VBUS once the
> lanes are right. A failure is only logged, so that the TCPM still
> configures the USB role.
>
> Mark the PIPE3 phy as initialized in the same critical section that
> programs the lanes, so that an orientation change can't get lost in
> between.
>
> Also stop storing TYPEC_ORIENTATION_NONE on unplug, so that the stored
> orientation always describes the lanes: while the PIPE3 phy is
> initialized, they stay programmed for it, and when the phy is
> initialized again after phy_exit(), which gates its power, they are
> programmed from it. This avoids re-initializing the PIPE3 phy when a
> cable is plugged in again in the same orientation and the phy stayed
> initialized.
>
> Cc: <stable at vger.kernel.org> # 6.15.x: 2ef1e78ef722: phy: samsung: usbdrd: propagate GS101 PIPE3 lock failures
> Cc: <stable at vger.kernel.org> # 6.15.x
> Fixes: 09dc674295a3 ("phy: exynos5-usbdrd: subscribe to orientation notifier if required")
> Signed-off-by: André Draszik <andre.draszik at linaro.org>
> ---
Reviewed-by: Peter Griffin <peter.griffin at linaro.org>
> drivers/phy/samsung/phy-exynos5-usbdrd.c | 61 ++++++++++++++++++++++++++++++--
> 1 file changed, 58 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/phy/samsung/phy-exynos5-usbdrd.c b/drivers/phy/samsung/phy-exynos5-usbdrd.c
> index 2186b745d58f..ccaf0f27c4c8 100644
> --- a/drivers/phy/samsung/phy-exynos5-usbdrd.c
> +++ b/drivers/phy/samsung/phy-exynos5-usbdrd.c
> @@ -509,6 +509,7 @@ struct exynos5_usbdrd_phy_drvdata {
> * @regulators: regulators for phy
> * @sw: TypeC orientation switch handle
> * @orientation: TypeC connector orientation - normal or flipped
> + * @pipe3_initialized: gs101 PIPE3 phy is initialized (and not isolated)
> */
> struct exynos5_usbdrd_phy {
> struct device *dev;
> @@ -532,6 +533,7 @@ struct exynos5_usbdrd_phy {
>
> struct typec_switch_dev *sw;
> enum typec_orientation orientation;
> + bool pipe3_initialized;
> };
>
> static inline
> @@ -1713,6 +1715,8 @@ static int exynos5_usbdrd_gs101_pipe3_init(struct exynos5_usbdrd_phy *phy_drd)
> u32 reg;
> int ret;
>
> + lockdep_assert_held(&phy_drd->phy_mutex);
> +
> exynos5_usbdrd_usbdp_g2_v4_ctrl_pma_ready(phy_drd);
>
> /* force aux off */
> @@ -1737,7 +1741,17 @@ static int exynos5_usbdrd_gs101_pipe3_init(struct exynos5_usbdrd_phy *phy_drd)
> if (ret)
> return ret;
>
> - return exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock(phy_drd);
> + ret = exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock(phy_drd);
> + if (ret)
> + return ret;
> +
> + /*
> + * Set this while still holding phy_mutex, so that the orientation
> + * switch callback can't miss an orientation change.
> + */
> + phy_drd->pipe3_initialized = true;
> +
> + return 0;
> }
>
> static int exynos5_usbdrd_gs101_phy_init(struct phy *phy)
> @@ -1783,6 +1797,9 @@ static int exynos5_usbdrd_gs101_phy_exit(struct phy *phy)
> ret = exynos850_usbdrd_phy_exit(phy);
> if (ret)
> return ret;
> + } else {
> + scoped_guard(mutex, &phy_drd->phy_mutex)
> + phy_drd->pipe3_initialized = false;
> }
>
> exynos5_usbdrd_phy_isol(inst, true);
> @@ -1880,8 +1897,48 @@ static int exynos5_usbdrd_orien_sw_set(struct typec_switch_dev *sw,
>
> scoped_guard(mutex, &phy_drd->phy_mutex) {
> void __iomem * const regs_base = phy_drd->reg_phy;
> + bool reinit_pipe3 = false;
> unsigned int reg;
>
> + /*
> + * The SS lanes are configured during PIPE3 init, for
> + * TYPEC_ORIENTATION_NORMAL or else as reversed. If the PIPE3
> + * phy is initialized already (e.g. the orientation is only
> + * known after the USB controller probed) and the lanes have
> + * to change, initialize it again, before signalling VBUS valid
> + * to the controller. Rewriting the lane mux alone isn't enough
> + * for the SS link to come up.
> + *
> + * TYPEC_ORIENTATION_NONE (unplug) isn't stored: while the PIPE3
> + * phy is initialized, phy_drd->orientation is what the lanes are
> + * programmed for, otherwise it is what the next PIPE3 init will
> + * program.
> + *
> + * Don't return an error, so that the Type-C port manager still
> + * configures the USB role.
> + */
> + if (orientation != TYPEC_ORIENTATION_NONE) {
> + bool was_normal = (phy_drd->orientation ==
> + TYPEC_ORIENTATION_NORMAL);
> + bool is_normal = (orientation ==
> + TYPEC_ORIENTATION_NORMAL);
> +
> + reinit_pipe3 = (phy_drd->pipe3_initialized &&
> + is_normal != was_normal);
> + phy_drd->orientation = orientation;
> + }
> +
> + if (reinit_pipe3) {
> + const struct exynos5_usbdrd_phy_config *cfg =
> + phy_drd->phys[EXYNOS5_DRDPHY_PIPE3].phy_cfg;
> +
> + ret = cfg->phy_init(phy_drd);
> + if (ret)
> + dev_warn(phy_drd->dev,
> + "Failed to reconfigure SS lanes: %d\n",
> + ret);
> + }
> +
> if (orientation == TYPEC_ORIENTATION_NONE) {
> reg = readl(regs_base + EXYNOS850_DRD_UTMI);
> reg &= ~(UTMI_FORCE_VBUSVALID | UTMI_FORCE_BVALID);
> @@ -1900,8 +1957,6 @@ static int exynos5_usbdrd_orien_sw_set(struct typec_switch_dev *sw,
> reg |= HSP_VBUSVLDEXTSEL | HSP_VBUSVLDEXT;
> writel(reg, regs_base + EXYNOS850_DRD_HSP);
> }
> -
> - phy_drd->orientation = orientation;
> }
>
> clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks);
>
> --
> 2.56.1.750.gf70dc682cf-goog
>
More information about the linux-arm-kernel
mailing list