Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas Tanure <tanure@linux.com>
To: Neil Armstrong <neil.armstrong@linaro.org>,
	Kevin Hilman <khilman@baylibre.com>,
	Vinod Koul <vkoul@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mathias Nyman <mathias.nyman@intel.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>,
	Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	Manivannan Sadhasivam <mani@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org, linux-phy@lists.infradead.org,
	devicetree@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 8/9] phy: amlogic: phy-meson-g12a-usb3-pcie: add T7 support
Date: Sun, 29 Nov 2026 09:28:09 +0000	[thread overview]
Message-ID: <20261129092810.146043-9-tanure@linux.com> (raw)
In-Reply-To: <20261129092810.146043-1-tanure@linux.com>

USB 3 devices on the Amlogic T7 only connect at high speed. The chip
has the G12A USB3 + PCIe combo PHY, but nothing sets it up.

The G12A sequence alone is not enough on the T7. The PHY must be held
in reset and released, the way the vendor driver does. The USB 3 lane
also needs its reference clock, spread spectrum and transmit levels set
in the USB control registers, and two analog settings differ from the
G12A.

Signed-off-by: Lucas Tanure <tanure@linux.com>
---
 .../phy/amlogic/phy-meson-g12a-usb3-pcie.c    | 108 +++++++++++++++++-
 1 file changed, 103 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c b/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c
index f94c08b17267..de65c9b2d2b6 100644
--- a/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c
+++ b/drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c
@@ -10,6 +10,7 @@
 #include <linux/bitfield.h>
 #include <linux/bitops.h>
 #include <linux/clk.h>
+#include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/phy/phy.h>
@@ -50,22 +51,50 @@
 	#define PHY_R5_PHY_CR_ACK				BIT(16)
 	#define PHY_R5_PHY_BS_OUT				BIT(17)
 
+#define PHY_R6							0x18
+	#define PHY_R6_SEL					GENMASK(18, 17)
+
+#define USB_R3							0x0c
+	#define USB_R3_P30_REF_SSP_EN				BIT(13)
+	#define USB_R3_P31_PCS_TX_DEEMPH_3P5DB			GENMASK(25, 20)
+
+#define USB_R7							0x1c
+	#define USB_R7_P31_SSC_EN				BIT(0)
+	#define USB_R7_P31_SSC_RANGE				GENMASK(3, 1)
+	#define USB_R7_P31_PCS_TX_DEEMPH_6DB			GENMASK(21, 16)
+	#define USB_R7_P31_PCS_TX_SWING_FULL			GENMASK(31, 25)
+
 #define PCIE_RESET_DELAY					500
 
+enum phy_g12a_usb3_pcie_soc {
+	PHY_G12A_USB3_PCIE_G12A,
+	PHY_G12A_USB3_PCIE_T7,
+};
+
 struct phy_g12a_usb3_pcie_priv {
 	struct regmap		*regmap;
 	struct regmap		*regmap_cr;
+	struct regmap		*regmap_usb;
 	struct clk		*clk_ref;
 	struct reset_control	*reset;
 	struct phy		*phy;
 	unsigned int		mode;
+	enum phy_g12a_usb3_pcie_soc soc;
 };
 
 static const struct regmap_config phy_g12a_usb3_pcie_regmap_conf = {
 	.reg_bits = 8,
 	.val_bits = 32,
 	.reg_stride = 4,
-	.max_register = PHY_R5,
+	.max_register = PHY_R6,
+};
+
+static const struct regmap_config phy_t7_usb3_regmap_conf = {
+	.name = "usb",
+	.reg_bits = 8,
+	.val_bits = 32,
+	.reg_stride = 4,
+	.max_register = USB_R7,
 };
 
 static int phy_g12a_usb3_pcie_cr_bus_addr(struct phy_g12a_usb3_pcie_priv *priv,
@@ -193,12 +222,57 @@ static const struct regmap_config phy_g12a_usb3_pcie_cr_regmap_conf = {
 	.disable_locking = true,
 };
 
+static int phy_t7_usb3_reset(struct phy_g12a_usb3_pcie_priv *priv)
+{
+	int ret;
+
+	ret = reset_control_assert(priv->reset);
+	if (ret)
+		return ret;
+
+	usleep_range(100, 200);
+
+	ret = reset_control_deassert(priv->reset);
+	if (ret)
+		return ret;
+
+	usleep_range(100, 200);
+
+	return 0;
+}
+
+static void phy_t7_usb3_setup(struct phy_g12a_usb3_pcie_priv *priv)
+{
+	regmap_update_bits(priv->regmap, PHY_R6, PHY_R6_SEL,
+			   FIELD_PREP(PHY_R6_SEL, 2));
+
+	regmap_update_bits(priv->regmap_usb, USB_R3, USB_R3_P30_REF_SSP_EN,
+			   USB_R3_P30_REF_SSP_EN);
+
+	regmap_update_bits(priv->regmap_usb, USB_R7,
+			   USB_R7_P31_SSC_EN | USB_R7_P31_SSC_RANGE |
+			   USB_R7_P31_PCS_TX_DEEMPH_6DB |
+			   USB_R7_P31_PCS_TX_SWING_FULL,
+			   USB_R7_P31_SSC_EN |
+			   FIELD_PREP(USB_R7_P31_SSC_RANGE, 2) |
+			   FIELD_PREP(USB_R7_P31_PCS_TX_DEEMPH_6DB, 0x20) |
+			   FIELD_PREP(USB_R7_P31_PCS_TX_SWING_FULL, 127));
+
+	regmap_update_bits(priv->regmap_usb, USB_R3,
+			   USB_R3_P31_PCS_TX_DEEMPH_3P5DB,
+			   FIELD_PREP(USB_R3_P31_PCS_TX_DEEMPH_3P5DB, 0x15));
+}
+
 static int phy_g12a_usb3_init(struct phy *phy)
 {
 	struct phy_g12a_usb3_pcie_priv *priv = phy_get_drvdata(phy);
+	bool t7 = priv->soc == PHY_G12A_USB3_PCIE_T7;
 	int data, ret;
 
-	ret = reset_control_reset(priv->reset);
+	if (t7)
+		ret = phy_t7_usb3_reset(priv);
+	else
+		ret = reset_control_reset(priv->reset);
 	if (ret)
 		return ret;
 
@@ -208,6 +282,9 @@ static int phy_g12a_usb3_init(struct phy *phy)
 			   PHY_R0_PCIE_USB3_SWITCH,
 			   PHY_R0_PCIE_USB3_SWITCH);
 
+	if (t7)
+		phy_t7_usb3_setup(priv);
+
 	/*
 	 * WORKAROUND: There is SSPHY suspend bug due to
 	 * which USB enumerates
@@ -219,7 +296,8 @@ static int phy_g12a_usb3_init(struct phy *phy)
 	if (ret)
 		return ret;
 
-	ret = regmap_update_bits(priv->regmap_cr, 0x1010, 0xff0, 20);
+	ret = regmap_update_bits(priv->regmap_cr, 0x1010, 0xff0,
+				 t7 ? 0x20 : 20);
 	if (ret)
 		return ret;
 
@@ -272,7 +350,7 @@ static int phy_g12a_usb3_init(struct phy *phy)
 
 	regmap_update_bits(priv->regmap, PHY_R1,
 			PHY_R1_PHY_LOS_BIAS | PHY_R1_PHY_LOS_LEVEL,
-			FIELD_PREP(PHY_R1_PHY_LOS_BIAS, 4) |
+			FIELD_PREP(PHY_R1_PHY_LOS_BIAS, t7 ? 5 : 4) |
 			FIELD_PREP(PHY_R1_PHY_LOS_LEVEL, 9));
 
 	return 0;
@@ -402,6 +480,19 @@ static int phy_g12a_usb3_pcie_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->regmap))
 		return PTR_ERR(priv->regmap);
 
+	priv->soc = (uintptr_t)of_device_get_match_data(dev);
+
+	if (priv->soc == PHY_G12A_USB3_PCIE_T7) {
+		base = devm_platform_ioremap_resource(pdev, 1);
+		if (IS_ERR(base))
+			return PTR_ERR(base);
+
+		priv->regmap_usb = devm_regmap_init_mmio(dev, base,
+							 &phy_t7_usb3_regmap_conf);
+		if (IS_ERR(priv->regmap_usb))
+			return PTR_ERR(priv->regmap_usb);
+	}
+
 	priv->regmap_cr = devm_regmap_init(dev, NULL, priv,
 					   &phy_g12a_usb3_pcie_cr_regmap_conf);
 	if (IS_ERR(priv->regmap_cr))
@@ -428,7 +519,14 @@ static int phy_g12a_usb3_pcie_probe(struct platform_device *pdev)
 }
 
 static const struct of_device_id phy_g12a_usb3_pcie_of_match[] = {
-	{ .compatible = "amlogic,g12a-usb3-pcie-phy", },
+	{
+		.compatible = "amlogic,g12a-usb3-pcie-phy",
+		.data = (void *)PHY_G12A_USB3_PCIE_G12A,
+	},
+	{
+		.compatible = "amlogic,t7-usb3-pcie-phy",
+		.data = (void *)PHY_G12A_USB3_PCIE_T7,
+	},
 	{ },
 };
 MODULE_DEVICE_TABLE(of, phy_g12a_usb3_pcie_of_match);
-- 
2.56.1



  parent reply	other threads:[~2026-11-29  9:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  9:28 [PATCH 0/9] Add USB support for the Amlogic T7 Lucas Tanure
2026-11-29  9:28 ` [PATCH 2/9] phy: amlogic: phy-meson-g12a-usb2: add T7 support Lucas Tanure
2026-11-29  9:28 ` [PATCH 3/9] dt-bindings: usb: add the Amlogic T7 USB controller Lucas Tanure
2026-11-29  9:28 ` [PATCH 4/9] usb: host: xhci-plat: add Amlogic T7 support Lucas Tanure
2026-11-29  9:28 ` [PATCH 5/9] arm64: dts: amlogic: t7: add the USB controllers Lucas Tanure
2026-11-29  9:28 ` [PATCH 6/9] arm64: dts: amlogic: khadas-vim4: enable the USB ports Lucas Tanure
2026-11-29  9:28 ` [PATCH 7/9] dt-bindings: phy: amlogic,g12a-usb3-pcie-phy: add the T7 compatible Lucas Tanure
2026-11-29  9:28 ` Lucas Tanure [this message]
2026-11-29  9:28 ` [PATCH 9/9] arm64: dts: amlogic: t7: add the USB3 PHY Lucas Tanure

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129092810.146043-9-tanure@linux.com \
    --to=tanure@linux.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbrunet@baylibre.com \
    --cc=khilman@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=mathias.nyman@intel.com \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox