From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53BFB60A3823 for ; Sun, 29 Nov 2026 09:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=3NxFhquG DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=jU6wnuZovyrBta/nVLTmXJvydMzeWfMWgbG11b19zKw=; b=3NxFhquGvXpDUpLjpMDPR8ozAP iSYDm56c7u+Y/IH4chXI34LZ8T+SQMkVfVuVctIT8jpmZtdmr7GtVuYwSAuu1J9n+ZSZMc4R0By0a LuQlF1veualMIFyTkc0YlwOA1S2udtHAIUDrfCZoH5xDkMvfryJKK/lFpTii8wZBuLCp8XH5mdMWX TtnXuaHiEdXYdKv0Wwcfr8XRyL4QS9JVbKE1BjMgWpGW8wXXCsIlm669QGi7XCYgE10EyEpMOc2Vd 9GCU/RvlTY+njwGJRHF7HgX+6TztBDGEUFuUSsX5/aCDJsceSiOmcagBYzPprSaDHVKbuzweAI6rk M6zVE/bQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXbCm-00000001jmS-36ih; Sun, 29 Nov 2026 09:28:20 +0000 Received: from mail-wm1-f51.google.com ([209.85.128.51]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXbCh-00000001jbK-0od2 for linux-phy@lists.infradead.org; Sun, 29 Nov 2026 09:28:17 +0000 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4bb9d8e8e90so65842285e9.3 for ; Sun, 29 Nov 2026 01:28:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795944493; x=1796549293; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=IQNiodbK3645v8GMP2KzIb6JQSL8JDv7xx7bgdfl12g=; b=I5fHO+FoJvlTyAEeFUgKTpazVCAFAHBE9/7D2eEH7o64B5+HVTLTisuenUxVH5S89q VW6qafpZNFTzP+u1a8Nt9uyU/AeXEyKmLNktDLghBGilGbRUMYkDgjOQOiJ8cESWdz9K rpou0P1BxNu01S4wt6v7HSGkQGeuzRierftgBnW7wt3LE0czNmmqgUfRpk2yx+QSCdV/ eUGoPFuNumXd7aEbo3eYa/kBAvgOU1tqM21Soi42MY0UVSoRyPRc7dnQ1apccRxhV/0R XeY3ng7dezwZO58xyJ2mlJDBnqnm15xqQvSVt9eYT0xcnX+twKRo3UaBvpyPosQxn7Oa sjZw== X-Forwarded-Encrypted: i=1; AL+hErE9kHYY0cpjeBbJ+DxaiEvIZRUUBxyRJZ+9eHzv8vop2V1TbDdTNk0QDLwQM2VlJ15iX9OJmOfPBnA=@lists.infradead.org X-Gm-Message-State: APuU4Z8IKWAiEWc04agSF27hl3xmFl23rpXKekdcatL9nWfOy4tzLo9U REgt9CodDFimZJCtVb2UVfgEarKVfHt1irIRrMyLBgSvde3G5oWAFk+I X-Gm-Gg: AZFdTZdLahcEeIUDBasAKANGdUzBzm/YHd2CBM1xCC1o2LtLEwqMFGaajlmloAQjXdw WuAQq6UcbQsJ9aWmA+xUqbAYEVJxJNeTmMwFXl7vCJlyA7mLrwfvq7NmJDyA+E7hGeAfEG6BYQO K5GX+B6fwe1P+hycwAqWZ1Gqt6Jmvddm7bUxYI4w2VNY2y/FHdIiVLQU5qn87Qez0M39vfiJzFc QzJu1fB0Ot1VI6T/Bmg/QVPdQRi1sNN7F4M4o+VRjDa1gue6eq2/ihZoAezS5L/20UhJrwqxjzT LIPkXfIGEeE2hNLCP2H8DsEmhvlboZWc9UHMaxzGM657h2jaEGaBmYoxIX3Gwi5PuDQxciXQKMF lngu5v66BcQCo1J5dEr7uMXLVvdiovA+vpMq8sf0RW4CQwDwKFVh3HmNbdMkIkkU6MyFAdefhpc ZPNqDCj+/oUkOtxaGLXAmOSqafQRkZjQ+PFjgYyuiguUzIG6Hiom3zXAhuxrgq5m4BsA/OLG25n tLghL1mkvQOERnLs3iPJgxPLagfI9Dzjic9ixL7pHaYd115g7mRllte9B9EuoPZncVIOTvO33I2 IuOFsBrYUsJ9zxOOtq3hMWHqLBOTeWlKgrwr6EltA9A88pVNT477d3I01FRxfqKSUP+eucWiGWc cTKp/A4R4fCf/1Q9XMinTnUYVjJvxSWZnBiPvHFX1QWgafw== X-Received: by 2002:a05:600d:8402:b0:4a3:5a91:5f61 with SMTP id 5b1f17b1804b1-4bb88806287mr477334805e9.14.1795944493048; Sun, 29 Nov 2026 01:28:13 -0800 (PST) Received: from threads.localdomain ([84.68.176.78]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab69bf61e8sm60210765f8f.11.2026.11.29.01.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 01:28:12 -0800 (PST) From: Lucas Tanure To: Neil Armstrong , Kevin Hilman , Vinod Koul , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Greg Kroah-Hartman , Mathias Nyman Cc: Jerome Brunet , Martin Blumenstingl , Manivannan Sadhasivam , 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 Message-ID: <20261129092810.146043-3-tanure@linux.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261129092810.146043-1-tanure@linux.com> References: <20261129092810.146043-1-tanure@linux.com> X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261129_012815_315940_8E2B6D36 X-CRM114-Status: GOOD ( 22.27 ) X-Spam-Score: -0.8 (/) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-phy" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- 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 #include #include +#include #include #include #include @@ -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 -- linux-phy mailing list linux-phy@lists.infradead.org https://lists.infradead.org/mailman/listinfo/linux-phy