Add USB support for the Amlogic T7
Subsystems (5)
cover Add USB support for the Amlogic T7
The Amlogic T7 (A311D2) has the G12A USB 2 PHY, the G12A USB3 + PCIe combo PHY, and two Corigine dual-role USB controllers. In the host role each controller is a plain xHCI. This series adds the host role for both controllers, both USB 2 PHYs and the USB 3 lane of the combo PHY, and enables the three USB ports of the Khadas VIM4.
Patches by tree:
- phy: 1, 2 (USB 2 PHY), 7, 8 (USB3 + PCIe combo PHY)
- usb: 3, 4 (controller binding, xhci-plat)
- amlogic: 5, 6, 9 (device tree)
The series is based on next-20261127. Patches 1 and 2 build on the S4 support in the phy tree ("phy: amlogic: meson-g12a-usb2: add S4 support"); the T7 PHY is close to the S4 one. Patch 6 only has context from the VIM4 thermal changes in the amlogic tree.
Notes for review:
- Each USB 2 port has a small block of control registers (power-on reset, host mode, PHY ready) at 0xfe03a000 + 0x20 * port. The vendor driver handles them in its PHY driver, and so does this series: they are the second register range of each USB 2 PHY node. The USB 3 registers of the same block (0xfe03a080) are the second range of the combo PHY node. No range is shared between nodes.
- The controllers can also be USB devices. Mainline has no driver for the Corigine device controller, so only the host role is supported. The binding already includes usb-drd.yaml and the board sets dr_mode = "host", so device mode can be added later without changing existing device trees.
- The controllers report 64-bit addressing but use only the lower 32 bits (patch 4, XHCI_NO_64BIT_SUPPORT, as on R-Car).
- A warm reboot left the USB 2 PHY stuck; a reset pulse does not clear it, holding the reset does (patch 2). The combo PHY gets the same treatment (patch 8).
- Patch 8 sets bits 18:17 of combo PHY register 0x18 to 2, as the vendor driver does. Neither the vendor code nor the datasheet names this field.
Tested on the Khadas VIM4, on next-20261127 after warm reboots, and with the same patches on v7.4-rc4 also after a cold boot:
- USB 3.0 socket: SuperSpeed, 101-110 MB/s read from a USB 3 flash drive
- USB 2.0 socket (on-board hub): 44 MB/s read with the same drive
- USB-C port, host role through a powered hub: flash drive (41 MB/s), network adapter (287/343 Mbit/s with iperf3), card reader
- hot plug; no errors in the log
next-20261127 does not boot on the T7 as is: since 8954a462e433 ("firmware: arm: scmi: Add centralized detection of truncated replies") every SCMI clock fails, because the T7 firmware answers CLOCK_ATTRIBUTES with 20 bytes instead of 24, and the SD and eMMC hosts then fail to probe. The tests above ran with that check reduced to a warning. This is unrelated to the series; reported here:
https://lore.kernel.org/arm-scmi/CAJX_Q+21a1UVE1CCXEGQc4-pdgu_fu32ohxspg5h=Sw7zPdKdQ@mail.gmail.com/
Lucas Tanure (9):
dt-bindings: phy: amlogic,g12a-usb2-phy: add the T7 compatible
phy: amlogic: phy-meson-g12a-usb2: add T7 support
dt-bindings: usb: add the Amlogic T7 USB controller
usb: host: xhci-plat: add Amlogic T7 support
arm64: dts: amlogic: t7: add the USB controllers
arm64: dts: amlogic: khadas-vim4: enable the USB ports
dt-bindings: phy: amlogic,g12a-usb3-pcie-phy: add the T7 compatible
phy: amlogic: phy-meson-g12a-usb3-pcie: add T7 support
arm64: dts: amlogic: t7: add the USB3 PHY
.../bindings/phy/amlogic,g12a-usb2-phy.yaml | 53 ++++++--- .../phy/amlogic,g12a-usb3-pcie-phy.yaml | 46 +++++++- .../bindings/usb/amlogic,t7-usb.yaml | 78 +++++++++++++ .../amlogic/amlogic-t7-a311d2-khadas-vim4.dts | 14 +++ arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi | 63 ++++++++++ drivers/phy/amlogic/phy-meson-g12a-usb2.c | 95 +++++++++++++-- .../phy/amlogic/phy-meson-g12a-usb3-pcie.c | 108 +++++++++++++++++- drivers/usb/host/xhci-plat.c | 7 ++ 8 files changed, 432 insertions(+), 32 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/amlogic,t7-usb.yaml
base-commit: e5aad2bdbbee783611d32599f89cea3f12f9593d
Signature · 1 line
2.56.1
PATCH 1/9 dt-bindings: phy: amlogic,g12a-usb2-phy: add the T7 compatible
The Amlogic T7 carries the G12A USB 2 PHY with different tuning values, so it needs its own compatible.
On the T7 each port also has a small block of control registers that take the port out of reset and select host mode. They are per port and sit outside the PHY register range, so the T7 PHY takes them as a second register range.
--- .../bindings/phy/amlogic,g12a-usb2-phy.yaml | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-)
Documentation/devicetree/bindings/phy/amlogic,g12a-usb2-phy.yaml +40 -13
@@ -16,9 +16,13 @@ properties: - amlogic,g12a-usb2-phy - amlogic,a1-usb2-phy - amlogic,s4-usb2-phy + - amlogic,t7-usb2-phy reg: - maxItems: 1 + minItems: 1 + items: + - description: PHY registers + - description: port control registers clocks: maxItems: 1
@@ -54,18 +58,31 @@ required: - reset-names - "#phy-cells" -if: - properties: - compatible: - enum: - - amlogic,meson-a1-usb-ctrl - -then: - properties: - power-domains: - maxItems: 1 - required: - - power-domains +allOf: + - if: + properties: + compatible: + enum: + - amlogic,meson-a1-usb-ctrl + then: + properties: + power-domains: + maxItems: 1 + required: + - power-domains + - if: + properties: + compatible: + contains: + const: amlogic,t7-usb2-phy + then: + properties: + reg: + minItems: 2 + else: + properties: + reg: + maxItems: 1 additionalProperties: false
@@ -80,3 +97,13 @@ examples: reset-names = "phy"; #phy-cells = <0>; }; + - | + phy@3c000 { + compatible = "amlogic,t7-usb2-phy"; + reg = <0x3c000 0x2000>, <0x3a000 0x20>; + clocks = <&xtal>; + clock-names = "xtal"; + resets = <&phy_reset>; + reset-names = "phy"; + #phy-cells = <0>; + };
Signature · 1 line
2.56.1
PATCH 2/9 phy: amlogic: phy-meson-g12a-usb2: add T7 support
In reply to Lucas TanureUSB 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.
--- drivers/phy/amlogic/phy-meson-g12a-usb2.c | 95 ++++++++++++++++++++--- 1 file changed, 83 insertions(+), 12 deletions(-)
drivers/phy/amlogic/phy-meson-g12a-usb2.c +83 -12
@@ -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);
Signature · 1 line
2.56.1
PATCH 3/9 dt-bindings: usb: add the Amlogic T7 USB controller
In reply to Lucas TanureThe Amlogic T7 has two USB controllers that are not described. Each one can be a USB host or a USB device. In the host role it is an xHCI that cannot use addresses above 4GB, although it reports that it can. The driver must know this, so the controller needs its own compatible.
The binding allows both roles, so that device mode can be added later without changing existing device trees.
--- .../bindings/usb/amlogic,t7-usb.yaml | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/amlogic,t7-usb.yaml
Documentation/devicetree/bindings/usb/amlogic,t7-usb.yaml new file +78 -0
@@ -0,0 +1,78 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/amlogic,t7-usb.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Amlogic T7 USB controller + +maintainers: + - Neil Armstrong <[email protected]> + +description: + Dual-role USB controller. In the host role it is an xHCI. + +allOf: + - $ref: usb-drd.yaml# + - $ref: usb-xhci.yaml# + +properties: + compatible: + const: amlogic,t7-usb + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + items: + - description: USB block reset, shared by both controllers + - description: controller reset + + phys: + minItems: 1 + maxItems: 2 + + phy-names: + minItems: 1 + items: + - const: usb2-phy + - const: usb3-phy + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + - resets + - power-domains + - phys + - phy-names + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/amlogic,t7-peripherals-clkc.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/power/amlogic,t7-pwrc.h> + + usb@fde00000 { + compatible = "amlogic,t7-usb"; + reg = <0xfde00000 0x8000>; + interrupts = <GIC_SPI 130 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc_periphs CLKID_SYS_USB>; + resets = <&reset 4>, <&reset 6>; + power-domains = <&pwrc PWRC_T7_USB_COMB_ID>; + phys = <&usb2_phy0>; + phy-names = "usb2-phy"; + dr_mode = "host"; + };
Signature · 1 line
2.56.1
PATCH 4/9 usb: host: xhci-plat: add Amlogic T7 support
In reply to Lucas TanureThe USB controller of the Amlogic T7 reports 64-bit addressing but uses only the lower 32 bits of each address. On a board with more than 4GB of RAM the command and event rings can be placed above 4GB. The controller then reads from the wrong place and never answers. A plugged device is not detected, and the only message is "Error while assigning device slot ID: Command Aborted".
Only the host role of the controller is supported.
--- drivers/usb/host/xhci-plat.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/usb/host/xhci-plat.c +7 -0
@@ -120,6 +120,10 @@ static const struct xhci_plat_priv xhci_plat_marvell_armada3700 = { .quirks = XHCI_RESET_ON_RESUME, }; +static const struct xhci_plat_priv xhci_plat_amlogic_t7 = { + .quirks =XHCI_NO_64BIT_SUPPORT , +}; +static const struct xhci_plat_priv xhci_plat_brcm = { .quirks =XHCI_RESET_ON_RESUME |XHCI_SUSPEND_RESUME_CLKS , };
@@ -147,6 +151,9 @@ static const struct of_device_id usb_xhci_of_match[] = { }, { .compatible = "brcm,bcm7445-xhci", .data = &xhci_plat_brcm, + }, { + .compatible = "amlogic,t7-usb", + .data = &xhci_plat_amlogic_t7, }, {}, };
Signature · 1 line
2.56.1
PATCH 5/9 arm64: dts: amlogic: t7: add the USB controllers
In reply to Lucas TanureThe two USB controllers of the Amlogic T7 and the USB 2 PHYs of their ports are not described, so no T7 board can use USB.
The USB 3 PHY of usb0 is not described yet, so it runs at USB 2.0 speed; usb1 has no USB 3 port. USB 2 link power management stays off, as in the vendor kernel. The nodes stay disabled because the board decides which ports are wired and how they are powered.
--- arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +48 -0
@@ -247,6 +247,32 @@ soc { #size-cells = <2>; ranges; + usb1: usb@fdd00000 { + compatible = "amlogic,t7-usb"; + reg = <0x0 0xfdd00000 0x0 0x8000>; + interrupts = <GIC_SPI 131 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc_periphs CLKID_SYS_USB>; + resets = <&reset RESET_USB>, <&reset RESET_U2DRD>; + power-domains = <&pwrc PWRC_T7_USB_COMB_ID>; + phys = <&usb2_phy1>; + phy-names = "usb2-phy"; + usb2-lpm-disable; + status = "disabled"; + }; + + usb0: usb@fde00000 { + compatible = "amlogic,t7-usb"; + reg = <0x0 0xfde00000 0x0 0x8000>; + interrupts = <GIC_SPI 130 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc_periphs CLKID_SYS_USB>; + resets = <&reset RESET_USB>, <&reset RESET_U3DRD>; + power-domains = <&pwrc PWRC_T7_USB_COMB_ID>; + phys = <&usb2_phy0>; + phy-names = "usb2-phy"; + usb2-lpm-disable; + status = "disabled"; + }; + gic: interrupt-controller@fff01000 { compatible = "arm,gic-400"; #interrupt-cells = <3>;
@@ -624,6 +650,28 @@ gpio_intc: interrupt-controller@4080 { <10 11 12 13 14 15 16 17 18 19 20 21>; }; + usb2_phy0: phy@3c000 { + compatible = "amlogic,t7-usb2-phy"; + reg = <0x0 0x3c000 0x0 0x2000>, + <0x0 0x3a000 0x0 0x20>; + clocks = <&xtal>; + clock-names = "xtal"; + resets = <&reset RESET_U2PHY20>; + reset-names = "phy"; + #phy-cells = <0>; + }; + + usb2_phy1: phy@3e000 { + compatible = "amlogic,t7-usb2-phy"; + reg = <0x0 0x3e000 0x0 0x2000>, + <0x0 0x3a020 0x0 0x20>; + clocks = <&xtal>; + clock-names = "xtal"; + resets = <&reset RESET_U2PHY21>; + reset-names = "phy"; + #phy-cells = <0>; + }; + uart_a: serial@78000 { compatible = "amlogic,t7-uart", "amlogic,meson-s4-uart"; reg = <0x0 0x78000 0x0 0x18>;
Signature · 1 line
2.56.1
PATCH 6/9 arm64: dts: amlogic: khadas-vim4: enable the USB ports
In reply to Lucas TanureNone of the USB ports of the Khadas VIM4 work. The USB controllers are not enabled on this board, and the switch that feeds 5V to the two type-A sockets is never turned on, so a plugged device gets no power.
The type-A sockets are on usb0 (USB 2 PHY 0), behind an on-board hub, and can only be host. The USB-C port is usb1 (USB 2 PHY 1). It can also be a device, which is not supported yet. The board takes its power from that port and does not supply 5V on it, so a device there needs a powered hub.
--- .../dts/amlogic/amlogic-t7-a311d2-khadas-vim4.dts | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-t7-a311d2-khadas-vim4.dts +14 -0
@@ -475,6 +475,20 @@ &uart_a { clock-names = "xtal", "pclk", "baud"; }; +&usb0 { + dr_mode = "host"; + status = "okay"; +}; + +&usb1 { + dr_mode = "host"; + status = "okay"; +}; + +&usb2_phy0 { + phy-supply = <&vcc5v0_usb>; +}; + &vpu_thermal { trips { vpu_active: vpu-active {
Signature · 1 line
2.56.1
PATCH 7/9 dt-bindings: phy: amlogic,g12a-usb3-pcie-phy: add the T7 compatible
In reply to Lucas TanureThe Amlogic T7 has the G12A USB3 + PCIe combo PHY, but it is not described, so its USB ports cannot run at SuperSpeed.
The T7 PHY needs different settings, so it needs its own compatible. It also has a second reset, for its register interface. Its USB 3 lane is tuned through USB control registers outside the PHY range, so it takes them as a second register range.
--- .../phy/amlogic,g12a-usb3-pcie-phy.yaml | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/phy/amlogic,g12a-usb3-pcie-phy.yaml +44 -2
@@ -14,9 +14,13 @@ properties: compatible: enum: - amlogic,g12a-usb3-pcie-phy + - amlogic,t7-usb3-pcie-phy reg: - maxItems: 1 + minItems: 1 + items: + - description: PHY registers + - description: USB control registers clocks: maxItems: 1
@@ -26,11 +30,16 @@ properties: - const: ref_clk resets: - maxItems: 1 + minItems: 1 + items: + - description: PHY reset + - description: PHY register interface reset reset-names: + minItems: 1 items: - const: phy + - const: apb "#phy-cells": const: 1
@@ -49,6 +58,29 @@ required: - reset-names - "#phy-cells" +allOf: + - if: + properties: + compatible: + contains: + const: amlogic,t7-usb3-pcie-phy + then: + properties: + reg: + minItems: 2 + resets: + minItems: 2 + reset-names: + minItems: 2 + else: + properties: + reg: + maxItems: 1 + resets: + maxItems: 1 + reset-names: + maxItems: 1 + additionalProperties: false examples:
@@ -62,3 +94,13 @@ examples: reset-names = "phy"; #phy-cells = <1>; }; + - | + phy@62000 { + compatible = "amlogic,t7-usb3-pcie-phy"; + reg = <0x62000 0x2000>, <0x3a080 0x20>; + clocks = <&ref_clk>; + clock-names = "ref_clk"; + resets = <&phy_reset>, <&apb_reset>; + reset-names = "phy", "apb"; + #phy-cells = <1>; + };
Signature · 1 line
2.56.1
PATCH 8/9 phy: amlogic: phy-meson-g12a-usb3-pcie: add T7 support
In reply to Lucas TanureUSB 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.
--- .../phy/amlogic/phy-meson-g12a-usb3-pcie.c | 108 +++++++++++++++++- 1 file changed, 103 insertions(+), 5 deletions(-)
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c +103 -5
@@ -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);
Signature · 1 line
2.56.1
PATCH 9/9 arm64: dts: amlogic: t7: add the USB3 PHY
In reply to Lucas TanureThe first USB controller of the Amlogic T7 has a USB 3 port, but its PHY is not described. USB 3 devices on that port connect only at high speed, and the SuperSpeed root hub stays empty.
The PHY is the USB3 + PCIe combo PHY, used here in USB 3 mode. It runs from the 100MHz PCIe reference clock.
--- arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +17 -2
@@ -4,6 +4,7 @@ */ #include <dt-bindings/interrupt-controller/arm-gic.h> +#include <dt-bindings/phy/phy.h> #include <dt-bindings/power/amlogic,t7-pwrc.h> #include "amlogic-t7-reset.h" #include <dt-bindings/clock/amlogic,t7-scmi.h>
@@ -267,8 +268,8 @@ usb0: usb@fde00000 { clocks = <&clkc_periphs CLKID_SYS_USB>; resets = <&reset RESET_USB>, <&reset RESET_U3DRD>; power-domains = <&pwrc PWRC_T7_USB_COMB_ID>; - phys = <&usb2_phy0>; - phy-names = "usb2-phy"; + phys = <&usb2_phy0>, <&usb3_pcie_phy PHY_TYPE_USB3>; + phy-names = "usb2-phy", "usb3-phy"; usb2-lpm-disable; status = "disabled"; };
@@ -672,6 +673,20 @@ usb2_phy1: phy@3e000 { #phy-cells = <0>; }; + usb3_pcie_phy: phy@62000 { + compatible = "amlogic,t7-usb3-pcie-phy"; + reg = <0x0 0x62000 0x0 0x2000>, + <0x0 0x3a080 0x0 0x20>; + clocks = <&pcie CLKID_PCIE_PLL>; + clock-names = "ref_clk"; + resets = <&reset RESET_PCIE1_PHY>, + <&reset RESET_PCIE1_APB>; + reset-names = "phy", "apb"; + assigned-clocks = <&pcie CLKID_PCIE_PLL>; + assigned-clock-rates = <100000000>; + #phy-cells = <1>; + }; + uart_a: serial@78000 { compatible = "amlogic,t7-uart", "amlogic,meson-s4-uart"; reg = <0x0 0x78000 0x0 0x18>;
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 3/9] dt-bindings: usb: add the Amlogic T7 USB controller
In reply to Lucas TanureThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dt-bindings: usb: non-canonical property ordering in amlogic,t7-usb.yaml --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dt-bindings: usb: non-canonical property ordering in amlogic,t7-usb.yaml
--
commit c22f49469c6fdecedd4c6b250862d6032d10bc2b
Author: Lucas Tanure <[email protected]>
dt-bindings: usb: add the Amlogic T7 USB controller
This commit adds the Device Tree binding schema for the dual-role USB controller on the Amlogic T7 SoC.
Quoted 6 lines
Documentation/devicetree/bindings/usb/amlogic,t7-usb.yaml new file +0
-0@@ -0,0 +1,78 @@
[ ... ]
Quoted 44 lines
Documentation/devicetree/bindings/usb/amlogic,t7-usb.yaml new file +44
-0+properties: + compatible: + const: amlogic,t7-usb + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + items: + - description: USB block reset, shared by both controllers + - description: controller reset + + phys: + minItems: 1 + maxItems: 2 + + phy-names: + minItems: 1 + items: + - const: usb2-phy + - const: usb3-phy + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + - resets + - power-domains + - phys + - phy-names + +unevaluatedProperties: false + +examples:
Documentation/devicetree/bindings/usb/amlogic,t7-usb.yaml line 72
Quoted 10 lines
Documentation/devicetree/bindings/usb/amlogic,t7-usb.yaml new file +10
-0+ - | + #include <dt-bindings/clock/amlogic,t7-peripherals-clkc.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/power/amlogic,t7-pwrc.h> + + usb@fde00000 { + compatible = "amlogic,t7-usb"; + reg = <0xfde00000 0x8000>; + interrupts = <GIC_SPI 130 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc_periphs CLKID_SYS_USB>;
[Severity: Low]
This isn't a bug, but the property order across properties, required, and the example node does not follow the canonical Device Tree sequence (compatible, reg, clocks, interrupts, power-domains). In all three sections, clocks should come before interrupts, and in properties, power-domains should follow interrupts rather than coming after phy-names.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewSashiko has finished reviewing this 9-patch series:
Sashiko has finished reviewing this 9-patch series:
- Patches 1, 2, and 4-9: no issues found.
- Patch 3 ("dt-bindings: usb: add the Amlogic T7 USB controller"): 1 potential issue (1 Low)
A detailed review has been sent as a separate reply to patch 3.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]