From nobody Thu Dec 18 09:50:25 2025 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 714E91B87C9 for ; Thu, 5 Dec 2024 07:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384001; cv=none; b=rcEMjwmDV4uXNgpPWzTPOF3IgUNi9Q7JYVf5fVFmcqcE09IVsSaylEJfS+L0RNr7NenqBOnYzSFyqH99cuglG/4I3mSTDLGcUKpqrt75UPto4LL8W8CK/LlKj5KWwEWes5qAXl9VhdyXQn+tRgV3EOz8/LQIvPUels3jBD55eIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384001; c=relaxed/simple; bh=iLGQEG0MGCOTbjiK6m9v4+91pUuN3w5VUK6OiPsuNm0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gC9fd4F+tCQi0AoXuXwyXpMwqn1AHtr7kSxMPLYfEjElHtEUVPOPNDOthDNRdO+l2JESOfkc+3kG+PlD9wDLkPktGEZpWLcgBvVGJmXkoHkRlFvS6WocbbgS2HlY2l+LX5ZeM1qwGv7F5X1vbKKG/mLT9ugNS7iwZYBu6EpGKj4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=lp4VAMYt; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lp4VAMYt" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-aa549d9dffdso76968766b.2 for ; Wed, 04 Dec 2024 23:33:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733383996; x=1733988796; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rbUd4Bjv9Szr1aHrKy8wPCWITceO1kvCtngZZYvRJf0=; b=lp4VAMYtsBRIno72L++qoT2c1klfdueb24i36cH/4ws/I7OcSlCdfPYKlIe5XGRgN2 UZ6ZiWjqNrw0IG3Ba9IbTj8TGnLVFX8T25tzs5fyKTe+EutYt/HI7wJq5Yr/WQXdORLL YBTM8gvkEjb2XPHee/67U1lUuF8Rwd/pC9UoFAaohNm6ZPXs0B5kgb3mB82J1Rc2R1q9 1iVo92m9iiT1tre/88PmVtd3Zs4TyJll86hfzK3Oy5q7rtp6dAhzzqDYNqS80IH603eL EkH2T1JCUksigPAn+YmNedQY6/0y3uWY6vFMlyBQYSAogZdqCxtPwbwFzxN4e+oY1Mx4 DeZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733383996; x=1733988796; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rbUd4Bjv9Szr1aHrKy8wPCWITceO1kvCtngZZYvRJf0=; b=VYsRj4M1qvGamFH5c2vrQhOrPjiQzPrGh9eEVKVdO0quMezerdo/MvODyF1R2neRK+ BmIMXsJA2r7Nm+mzUDv8JPWjnTu9OF8Ib+nj5C3dszKz/u5dm/XOGz5K+B0gUBrc9W3F XD5mgXbeKhsF+wzCz62NZ48SHzjSBDZqjzYmfEfMyZSkcIb5YKjEHbZ+6D+/H7X1KTIQ 00pDJ4uTtbHdaI8bKMU4Di0FmNYBUHWp4jcAHCJwkWiRKkl2fc4uu1gEVpYHF1nptiY/ 4mBpG8svA/F3mFQ6Wj7qNqM42KX4WCTU77pPT+T/OpFfuId9uhAyr7RyhkQtbPSxcdv2 298A== X-Forwarded-Encrypted: i=1; AJvYcCVZY9hPgl5pwPM90HyTmXU98hlBKKPdg0gMNCjwKyqaE65Y02G6x75uXudAP8iuHYA99qD7Ffg2sB1x1uE=@vger.kernel.org X-Gm-Message-State: AOJu0YzvRLVCmjU1iXN6r8pQ0Q2lQlCWkBwDtIiRl2MReoMLizy0haiQ mgetZy1jgpVSxCgKCr05PTQICVroeZ9nNIQQN/Tk3ypD5jaqytDWVx/Ujl6uaeIdLjuYYQaVVb5 pSoM= X-Gm-Gg: ASbGnctKHd3DafIHErNxkOEvNauY1sj7A/0a52eun8Je49bIwenE2ZF8rSfb9MSCcB/ jf3DUI5hfyecI8GpP3FjX+fJUEkpEQXuxaxHDyr7yY7Yb2DRVVe7oTjRbu/Uv0cQts+2ec/QQ3k HOKlvdYZ7GLsnRpNbojJcrpLuab6xaVk7F7UN6d6Zr/ji+hDbDWuNHo6e3d2KxahSTcWs5TZBH5 YYlJ2WNtSW5gu8liGBvPzgafljKyZxkCbKKdP7K2UG6RB2MReOQlrdi72lqasZiG4pEVP+kxKTe 1GqDus9EyBKHhPx2P1+t6L0D25ACN6GV2Q== X-Google-Smtp-Source: AGHT+IHNHlztvnn2YKPTupPy7irtmhcD07q8bL0o5UzylQP2VhznMrbt8FYseED/HYM9kfIhmtmXwA== X-Received: by 2002:a17:906:23ea:b0:a99:5466:2556 with SMTP id a640c23a62f3a-aa5f7f6e957mr634121766b.61.1733383996464; Wed, 04 Dec 2024 23:33:16 -0800 (PST) Received: from puffmais.c.googlers.com (64.227.90.34.bc.googleusercontent.com. [34.90.227.64]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6260888casm53371766b.133.2024.12.04.23.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 23:33:16 -0800 (PST) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Thu, 05 Dec 2024 07:33:17 +0000 Subject: [PATCH v3 6/8] phy: exynos5-usbdrd: gs101: configure SS lanes based on orientation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241205-gs101-phy-lanes-orientation-phy-v3-6-32f721bed219@linaro.org> References: <20241205-gs101-phy-lanes-orientation-phy-v3-0-32f721bed219@linaro.org> In-Reply-To: <20241205-gs101-phy-lanes-orientation-phy-v3-0-32f721bed219@linaro.org> To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Szyprowski , Sylwester Nawrocki , Alim Akhtar Cc: Peter Griffin , Tudor Ambarus , Sam Protsenko , Will McVicker , Roy Luo , kernel-team@android.com, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Draszik?= X-Mailer: b4 0.13.0 USB SS lanes need to be configured based on the connector orientation - at most two lanes will be in use for USB (and the remaining two for alternate modes like DP). For the USB link to come up in SS, the lane configuration registers have to be programmed accordingly. While we still need a way to be notified of the actual connector orientation and then reprogram the registers accordingly (at the moment the configuration happens just once during phy_init() and never again), we can prepare the code doing the configuration to take the orientation into account. Do so. Note: the mutex is needed to synchronize this with the upcoming connector orientation callback. Reviewed-by: Peter Griffin Tested-by: Peter Griffin Signed-off-by: Andr=C3=A9 Draszik --- v2: * collect tags * replace #include typec_mux.h with typec.h, and move the former into next patch (Peter) * commit message typo (Peter) --- drivers/phy/samsung/phy-exynos5-usbdrd.c | 72 ++++++++++++++++++++++------= ---- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/drivers/phy/samsung/phy-exynos5-usbdrd.c b/drivers/phy/samsung= /phy-exynos5-usbdrd.c index c1ce6fdeef31..206483c7ca55 100644 --- a/drivers/phy/samsung/phy-exynos5-usbdrd.c +++ b/drivers/phy/samsung/phy-exynos5-usbdrd.c @@ -23,6 +23,7 @@ #include #include #include +#include =20 /* Exynos USB PHY registers */ #define EXYNOS5_FSEL_9MHZ6 0x0 @@ -209,6 +210,10 @@ =20 #define EXYNOS9_PMA_USBDP_CMN_REG00B8 0x02e0 #define CMN_REG00B8_LANE_MUX_SEL_DP GENMASK(3, 0) +#define CMN_REG00B8_LANE_MUX_SEL_DP_LANE3 BIT(3) +#define CMN_REG00B8_LANE_MUX_SEL_DP_LANE2 BIT(2) +#define CMN_REG00B8_LANE_MUX_SEL_DP_LANE1 BIT(1) +#define CMN_REG00B8_LANE_MUX_SEL_DP_LANE0 BIT(0) =20 #define EXYNOS9_PMA_USBDP_CMN_REG01C0 0x0700 #define CMN_REG01C0_ANA_LCPLL_LOCK_DONE BIT(7) @@ -383,11 +388,13 @@ struct exynos5_usbdrd_phy_drvdata { * @clks: clocks for register access * @core_clks: core clocks for phy (ref, pipe3, utmi+, ITP, etc. as requir= ed) * @drv_data: pointer to SoC level driver data structure + * @phy_mutex: mutex protecting phy_init/exit & TCPC callbacks * @phys: array for 'EXYNOS5_DRDPHYS_NUM' number of PHY * instances each with its 'phy' and 'phy_cfg'. * @extrefclk: frequency select settings when using 'separate * reference clocks' for SS and HS operations * @regulators: regulators for phy + * @orientation: TypeC connector orientation - normal or flipped */ struct exynos5_usbdrd_phy { struct device *dev; @@ -397,6 +404,7 @@ struct exynos5_usbdrd_phy { struct clk_bulk_data *clks; struct clk_bulk_data *core_clks; const struct exynos5_usbdrd_phy_drvdata *drv_data; + struct mutex phy_mutex; struct phy_usb_instance { struct phy *phy; u32 index; @@ -406,6 +414,8 @@ struct exynos5_usbdrd_phy { } phys[EXYNOS5_DRDPHYS_NUM]; u32 extrefclk; struct regulator_bulk_data *regulators; + + enum typec_orientation orientation; }; =20 static inline @@ -647,22 +657,38 @@ exynos5_usbdrd_usbdp_g2_v4_pma_lane_mux_sel(struct ex= ynos5_usbdrd_phy *phy_drd) /* lane configuration: USB on all lanes */ reg =3D readl(regs_base + EXYNOS9_PMA_USBDP_CMN_REG00B8); reg &=3D ~CMN_REG00B8_LANE_MUX_SEL_DP; - writel(reg, regs_base + EXYNOS9_PMA_USBDP_CMN_REG00B8); - /* - * FIXME: below code supports one connector orientation only. It needs - * updating once we can receive connector events. + * USB on lanes 0 & 1 in normal mode, or 2 & 3 if reversed, DP on the + * other ones. */ + reg |=3D FIELD_PREP(CMN_REG00B8_LANE_MUX_SEL_DP, + ((phy_drd->orientation =3D=3D TYPEC_ORIENTATION_NORMAL) + ? (CMN_REG00B8_LANE_MUX_SEL_DP_LANE3 + | CMN_REG00B8_LANE_MUX_SEL_DP_LANE2) + : (CMN_REG00B8_LANE_MUX_SEL_DP_LANE1 + | CMN_REG00B8_LANE_MUX_SEL_DP_LANE0))); + writel(reg, regs_base + EXYNOS9_PMA_USBDP_CMN_REG00B8); + /* override of TX receiver detector and comparator: lane 1 */ reg =3D readl(regs_base + EXYNOS9_PMA_USBDP_TRSV_REG0413); - reg &=3D ~TRSV_REG0413_OVRD_LN1_TX_RXD_COMP_EN; - reg &=3D ~TRSV_REG0413_OVRD_LN1_TX_RXD_EN; + if (phy_drd->orientation =3D=3D TYPEC_ORIENTATION_NORMAL) { + reg &=3D ~TRSV_REG0413_OVRD_LN1_TX_RXD_COMP_EN; + reg &=3D ~TRSV_REG0413_OVRD_LN1_TX_RXD_EN; + } else { + reg |=3D TRSV_REG0413_OVRD_LN1_TX_RXD_COMP_EN; + reg |=3D TRSV_REG0413_OVRD_LN1_TX_RXD_EN; + } writel(reg, regs_base + EXYNOS9_PMA_USBDP_TRSV_REG0413); =20 /* lane 3 */ reg =3D readl(regs_base + EXYNOS9_PMA_USBDP_TRSV_REG0813); - reg |=3D TRSV_REG0813_OVRD_LN3_TX_RXD_COMP_EN; - reg |=3D TRSV_REG0813_OVRD_LN3_TX_RXD_EN; + if (phy_drd->orientation =3D=3D TYPEC_ORIENTATION_NORMAL) { + reg |=3D TRSV_REG0813_OVRD_LN3_TX_RXD_COMP_EN; + reg |=3D TRSV_REG0813_OVRD_LN3_TX_RXD_EN; + } else { + reg &=3D ~TRSV_REG0813_OVRD_LN3_TX_RXD_COMP_EN; + reg &=3D ~TRSV_REG0813_OVRD_LN3_TX_RXD_EN; + } writel(reg, regs_base + EXYNOS9_PMA_USBDP_TRSV_REG0813); } =20 @@ -700,21 +726,18 @@ exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock(struct = exynos5_usbdrd_phy *phy_drd int err; =20 err =3D readl_poll_timeout( - phy_drd->reg_pma + EXYNOS9_PMA_USBDP_TRSV_REG03C3, - reg, (reg & locked) =3D=3D locked, sleep_us, timeout_us); - if (!err) - return; - - dev_err(phy_drd->dev, - "timed out waiting for CDR lock (l0): %#.8x, retrying\n", reg); - - /* based on cable orientation, this might be on the other phy port */ - err =3D readl_poll_timeout( - phy_drd->reg_pma + EXYNOS9_PMA_USBDP_TRSV_REG07C3, + /* lane depends on cable orientation */ + (phy_drd->reg_pma + + ((phy_drd->orientation =3D=3D TYPEC_ORIENTATION_NORMAL) + ? EXYNOS9_PMA_USBDP_TRSV_REG03C3 + : EXYNOS9_PMA_USBDP_TRSV_REG07C3)), reg, (reg & locked) =3D=3D locked, sleep_us, timeout_us); if (err) dev_err(phy_drd->dev, - "timed out waiting for CDR lock (l2): %#.8x\n", reg); + "timed out waiting for CDR(l%d) lock: %#.8x\n", + ((phy_drd->orientation =3D=3D TYPEC_ORIENTATION_NORMAL) + ? 0 + : 2), reg); } =20 static void exynos5_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd) @@ -1184,7 +1207,8 @@ static int exynos850_usbdrd_phy_init(struct phy *phy) return ret; =20 /* UTMI or PIPE3 specific init */ - inst->phy_cfg->phy_init(phy_drd); + scoped_guard(mutex, &phy_drd->phy_mutex) + inst->phy_cfg->phy_init(phy_drd); =20 clk_bulk_disable_unprepare(phy_drd->drv_data->n_clks, phy_drd->clks); =20 @@ -1203,6 +1227,8 @@ static int exynos850_usbdrd_phy_exit(struct phy *phy) if (ret) return ret; =20 + guard(mutex)(&phy_drd->phy_mutex); + /* Set PHY clock and control HS PHY */ reg =3D readl(regs_base + EXYNOS850_DRD_UTMI); reg &=3D ~(UTMI_DP_PULLDOWN | UTMI_DM_PULLDOWN); @@ -1701,6 +1727,10 @@ static int exynos5_usbdrd_phy_probe(struct platform_= device *pdev) return -EINVAL; phy_drd->drv_data =3D drv_data; =20 + ret =3D devm_mutex_init(dev, &phy_drd->phy_mutex); + if (ret) + return ret; + if (of_property_present(dev->of_node, "reg-names")) { void __iomem *reg; =20 --=20 2.47.0.338.g60cca15819-goog