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 2/9] phy: amlogic: phy-meson-g12a-usb2: add T7 support
Date: Sun, 29 Nov 2026 09:28:03 +0000 [thread overview]
Message-ID: <20261129092810.146043-3-tanure@linux.com> (raw)
In-Reply-To: <20261129092810.146043-1-tanure@linux.com>
USB does not work on the Amlogic T7. The chip has the G12A USB 2 PHY,
but some tuning values differ, and the port also has to be released
from reset and set to host mode in its own control registers. Without
this the port never becomes ready. The T7 values come from the vendor
kernel and are close to the S4 ones.
A warm restart also leaves the PHY stuck: USB works after power-on but
fails after a reboot with "Host took too long to start", until the
power is removed. A short reset pulse does not clear this state. The
PHY must be held in reset for a moment and then released.
Signed-off-by: Lucas Tanure <tanure@linux.com>
---
drivers/phy/amlogic/phy-meson-g12a-usb2.c | 95 ++++++++++++++++++++---
1 file changed, 83 insertions(+), 12 deletions(-)
diff --git a/drivers/phy/amlogic/phy-meson-g12a-usb2.c b/drivers/phy/amlogic/phy-meson-g12a-usb2.c
index 5fe9d484d349..d0ef75439493 100644
--- a/drivers/phy/amlogic/phy-meson-g12a-usb2.c
+++ b/drivers/phy/amlogic/phy-meson-g12a-usb2.c
@@ -13,6 +13,7 @@
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/regmap.h>
@@ -147,10 +148,21 @@
#define RESET_COMPLETE_TIME 1000
#define PLL_RESET_COMPLETE_TIME 100
+#define U2P_R0 0x0
+ #define U2P_R0_HOST_DEVICE BIT(0)
+ #define U2P_R0_POWER_ON_RESET BIT(3)
+ #define U2P_R0_ID_PULLUP BIT(4)
+ #define U2P_R0_DRV_VBUS BIT(5)
+#define U2P_R1 0x4
+ #define U2P_R1_PHY_READY BIT(0)
+
+#define PHY_READY_TIMEOUT_US 1000
+
enum meson_soc_id {
MESON_SOC_G12A = 0,
MESON_SOC_A1,
MESON_SOC_S4,
+ MESON_SOC_T7,
};
struct phy_meson_g12a_usb2_priv {
@@ -158,9 +170,31 @@ struct phy_meson_g12a_usb2_priv {
struct regmap *regmap;
struct clk *clk;
struct reset_control *reset;
+ void __iomem *port_ctrl;
int soc_id;
};
+static int phy_meson_t7_usb2_port_init(struct phy_meson_g12a_usb2_priv *priv)
+{
+ u32 val;
+
+ val = readl(priv->port_ctrl + U2P_R0);
+ val |= U2P_R0_POWER_ON_RESET;
+ writel(val, priv->port_ctrl + U2P_R0);
+
+ val |= U2P_R0_HOST_DEVICE | U2P_R0_ID_PULLUP | U2P_R0_DRV_VBUS;
+ writel(val, priv->port_ctrl + U2P_R0);
+
+ usleep_range(10, 20);
+
+ val &= ~U2P_R0_POWER_ON_RESET;
+ writel(val, priv->port_ctrl + U2P_R0);
+
+ return readl_poll_timeout(priv->port_ctrl + U2P_R1, val,
+ val & U2P_R1_PHY_READY, 10,
+ PHY_READY_TIMEOUT_US);
+}
+
static const struct regmap_config phy_meson_g12a_usb2_regmap_conf = {
.reg_bits = 8,
.val_bits = 32,
@@ -178,7 +212,15 @@ static int phy_meson_g12a_usb2_init(struct phy *phy)
if (ret)
return ret;
- ret = reset_control_reset(priv->reset);
+ if (priv->soc_id == MESON_SOC_T7) {
+ ret = reset_control_assert(priv->reset);
+ if (!ret) {
+ udelay(RESET_COMPLETE_TIME);
+ ret = reset_control_deassert(priv->reset);
+ }
+ } else {
+ ret = reset_control_reset(priv->reset);
+ }
if (ret) {
clk_disable_unprepare(priv->clk);
return ret;
@@ -224,7 +266,8 @@ static int phy_meson_g12a_usb2_init(struct phy *phy)
* (0xac5f69e5) is the G12A R18 value with MPLL_DCO_CLK_SEL (bit 13)
* set, which is exactly what the A1 path adds here.
*/
- if (priv->soc_id == MESON_SOC_A1 || priv->soc_id == MESON_SOC_S4)
+ if (priv->soc_id == MESON_SOC_A1 || priv->soc_id == MESON_SOC_S4 ||
+ priv->soc_id == MESON_SOC_T7)
value |= PHY_CTRL_R18_MPLL_DCO_CLK_SEL;
regmap_write(priv->regmap, PHY_CTRL_R18, value);
@@ -248,14 +291,14 @@ static int phy_meson_g12a_usb2_init(struct phy *phy)
FIELD_PREP(PHY_CTRL_R20_USB2_BGR_ADJ_4_0, 0) |
FIELD_PREP(PHY_CTRL_R20_USB2_BGR_VREF_4_0, 0) |
FIELD_PREP(PHY_CTRL_R20_USB2_BGR_DBG_1_0, 0);
- /* S4 uses edge-drive trim 2; other SoCs use 3 */
- if (priv->soc_id == MESON_SOC_S4)
+ /* S4 and T7 use edge-drive trim 2; other SoCs use 3 */
+ if (priv->soc_id == MESON_SOC_S4 || priv->soc_id == MESON_SOC_T7)
value |= FIELD_PREP(PHY_CTRL_R20_USB2_EDGE_DRV_TRIM_1_0, 2);
else
value |= FIELD_PREP(PHY_CTRL_R20_USB2_EDGE_DRV_TRIM_1_0, 3);
regmap_write(priv->regmap, PHY_CTRL_R20, value);
- if (priv->soc_id == MESON_SOC_G12A)
+ if (priv->soc_id == MESON_SOC_G12A || priv->soc_id == MESON_SOC_T7)
regmap_write(priv->regmap, PHY_CTRL_R4,
FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_7_0, 0xf) |
FIELD_PREP(PHY_CTRL_R4_CALIB_CODE_15_8, 0xf) |
@@ -263,13 +306,15 @@ static int phy_meson_g12a_usb2_init(struct phy *phy)
PHY_CTRL_R4_TEST_BYPASS_MODE_EN |
FIELD_PREP(PHY_CTRL_R4_I_C2L_BIAS_TRIM_1_0, 0) |
FIELD_PREP(PHY_CTRL_R4_I_C2L_BIAS_TRIM_3_2, 0));
- else if (priv->soc_id == MESON_SOC_A1 ||
- priv->soc_id == MESON_SOC_S4) {
+
+ if (priv->soc_id == MESON_SOC_A1 || priv->soc_id == MESON_SOC_S4 ||
+ priv->soc_id == MESON_SOC_T7)
regmap_write(priv->regmap, PHY_CTRL_R21,
PHY_CTRL_R21_USB2_CAL_ACK_EN |
PHY_CTRL_R21_USB2_TX_STRG_PD |
FIELD_PREP(PHY_CTRL_R21_USB2_OTG_ACA_TRIM_1_0, 2));
+ if (priv->soc_id == MESON_SOC_A1 || priv->soc_id == MESON_SOC_S4) {
/* Analog Settings */
value = FIELD_PREP(PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET, 7);
if (priv->soc_id == MESON_SOC_S4) {
@@ -287,23 +332,39 @@ static int phy_meson_g12a_usb2_init(struct phy *phy)
}
/* Tuning Disconnect Threshold */
- value = FIELD_PREP(PHY_CTRL_R3_SQUELCH_REF, 0) |
+ value = FIELD_PREP(PHY_CTRL_R3_SQUELCH_REF,
+ priv->soc_id == MESON_SOC_T7 ? 3 : 0) |
FIELD_PREP(PHY_CTRL_R3_DISC_THRESH, 3);
- /* S4 wants a higher HS disconnect reference than the other SoCs */
- if (priv->soc_id == MESON_SOC_S4)
+ /* S4 and T7 want a higher HS disconnect reference than the other SoCs */
+ if (priv->soc_id == MESON_SOC_S4 || priv->soc_id == MESON_SOC_T7)
value |= FIELD_PREP(PHY_CTRL_R3_HSDIC_REF, 3);
else
value |= FIELD_PREP(PHY_CTRL_R3_HSDIC_REF, 1);
regmap_write(priv->regmap, PHY_CTRL_R3, value);
- if (priv->soc_id == MESON_SOC_G12A) {
+ if (priv->soc_id == MESON_SOC_G12A || priv->soc_id == MESON_SOC_T7) {
/* Analog Settings */
- regmap_write(priv->regmap, PHY_CTRL_R14, 0);
+ if (priv->soc_id == MESON_SOC_T7)
+ regmap_update_bits(priv->regmap, PHY_CTRL_R14,
+ PHY_CTRL_R14_DISCONNECT_THRESHOLD_S4,
+ FIELD_PREP(PHY_CTRL_R14_DISCONNECT_THRESHOLD_S4,
+ 2));
+ else
+ regmap_write(priv->regmap, PHY_CTRL_R14, 0);
regmap_write(priv->regmap, PHY_CTRL_R13,
PHY_CTRL_R13_UPDATE_PMA_SIGNALS |
FIELD_PREP(PHY_CTRL_R13_MIN_COUNT_FOR_SYNC_DET, 7));
}
+ if (priv->soc_id == MESON_SOC_T7) {
+ ret = phy_meson_t7_usb2_port_init(priv);
+ if (ret) {
+ dev_err(priv->dev, "PHY not ready\n");
+ clk_disable_unprepare(priv->clk);
+ return ret;
+ }
+ }
+
return 0;
}
@@ -348,6 +409,12 @@ static int phy_meson_g12a_usb2_probe(struct platform_device *pdev)
priv->soc_id = (uintptr_t)of_device_get_match_data(&pdev->dev);
+ if (priv->soc_id == MESON_SOC_T7) {
+ priv->port_ctrl = devm_platform_ioremap_resource(pdev, 1);
+ if (IS_ERR(priv->port_ctrl))
+ return PTR_ERR(priv->port_ctrl);
+ }
+
priv->regmap = devm_regmap_init_mmio(dev, base,
&phy_meson_g12a_usb2_regmap_conf);
if (IS_ERR(priv->regmap))
@@ -391,6 +458,10 @@ static const struct of_device_id phy_meson_g12a_usb2_of_match[] = {
.compatible = "amlogic,s4-usb2-phy",
.data = (void *)MESON_SOC_S4,
},
+ {
+ .compatible = "amlogic,t7-usb2-phy",
+ .data = (void *)MESON_SOC_T7,
+ },
{ /* Sentinel */ }
};
MODULE_DEVICE_TABLE(of, phy_meson_g12a_usb2_of_match);
--
2.56.1
next prev 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 ` Lucas Tanure [this message]
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 ` [PATCH 8/9] phy: amlogic: phy-meson-g12a-usb3-pcie: add T7 support Lucas Tanure
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-3-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