Enable USB on i.MX8ULP EVK
Subsystems (5)
cover Enable USB on i.MX8ULP EVK
This patch set is used to enable the second USB controller (base address 0x29920000) on i.MX8ULP EVK in host mode.
---
Alice Guo (2):
ehci-mx6: Update USB host driver for iMX8ULP
imx8ulp: dst: Enable USB controller at 0x29920000 in host mode
Ye Li (2):
ehci-mx6: Add powerup_fixup implementation
imx8ulp: clock: Drop CONFIG_USB_MAX_CONTROLLER_COUNT dependency
arch/arm/dts/imx8ulp-evk-u-boot.dtsi | 4 ++ arch/arm/dts/imx8ulp-evk.dts | 27 ++++++++++++++ arch/arm/dts/imx8ulp.dtsi | 30 +++++++++++++++ arch/arm/mach-imx/imx8ulp/clock.c | 12 ++---- configs/imx8ulp_evk_defconfig | 3 ++ drivers/usb/host/Kconfig | 2 +- drivers/usb/host/ehci-mx6.c | 71 ++++++++++++++++++++++++++++-------- 7 files changed, 125 insertions(+), 24 deletions(-)
---
base-commit: 610a3eb27ea1e68363fffcb3f14b7fc097ef08b6
change-id: 20251128-usb2-1511e5e3ea84
Best regards,
Signature · 1 line
Alice Guo <[email protected]>
PATCH 1/4 ehci-mx6: Add powerup_fixup implementation
From: Ye Li <[email protected]>
When doing port reset, the PR bit of PORTSC1 will be automatically cleared by our IP, but standard EHCI needs explicit clear by software. The EHCI-HCD driver follow the EHCI specification, so after 50ms wait, it clear the PR bit by writting to the PORTSC1 register with value loaded before setting PR.
This sequence is ok for our IP when the delay time is exact. But when the timer is slower, some bits like PE, PSPD have been set by controller automatically after the PR is automatically cleared. So the writing to the PORTSC1 will overwrite these bits set by controller. And eventually the driver gets wrong status.
We implement the powerup_fixup operation which delays 50ms and will check the PR until it is cleared by controller. And will update the reg value which is written to PORTSC register by EHCI-HCD driver. This is much safer than depending on the delay time to be accurate and aligining with controller's behaiver.
--- drivers/usb/host/ehci-mx6.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/usb/host/ehci-mx6.c +27 -1
@@ -265,6 +265,25 @@ int usb_phy_mode(int port) }#endif +static void ehci_mx6_powerup_fixup (struct ehci_ctrl *ctrl,uint32_t *status_reg, +uint32_t *reg) +{ +u32 result; +int usec =2000 ; + +mdelay (50 ); + +do { + result =ehci_readl (status_reg); +udelay (5 ); +if (!(result &EHCI_PS_PR )) +break ; + usec--; + }while (usec >0 ); + + *reg =ehci_readl (status_reg); +} +#if !defined(CONFIG_PHY )/* Should be done in the MXS PHY driver */ static void usb_oc_config (struct usbnc_regs *usbnc,int index)
@@ -331,6 +350,10 @@ int __weak board_ehci_power(int port, int on)return 0 ; } +static const struct ehci_ops mx6_ehci_ops = { + .powerup_fixup = ehci_mx6_powerup_fixup, +}; +int ehci_hcd_init (int index,enum usb_init_type init,struct ehci_hccr **hccr,struct ehci_hcor **hcor) {
@@ -394,6 +417,8 @@ int ehci_hcd_init(int index, enum usb_init_type init, }#endif +ehci_set_controller_priv (index,NULL , &mx6_ehci_ops); + type =board_usb_phy_mode (index);if (hccr && hcor) {
@@ -502,7 +527,8 @@ static int mx6_init_after_reset(struct ehci_ctrl *dev) }static const struct ehci_ops mx6_ehci_ops = { - .init_after_reset = mx6_init_after_reset + .powerup_fixup = ehci_mx6_powerup_fixup, + .init_after_reset = mx6_init_after_reset, };static int ehci_usb_phy_mode (struct udevice *dev)
Signature · 1 line
2.43.0
Re: [PATCH v1 1/4] ehci-mx6: Add powerup_fixup implementation
Quoted 10 lines · On 11/28/25 2:16 PM, [email protected] wrote:
From: Ye Li <[email protected]>
When doing port reset, the PR bit of PORTSC1 will be automatically cleared by our IP, but standard EHCI needs explicit clear by software. The EHCI-HCD driver follow the EHCI specification, so after 50ms wait, it clear the PR bit by writting to the PORTSC1 register with value loaded before setting PR.
This sequence is ok for our IP when the delay time is exact. But when the timer is slower
How can the timer be slower ? Maybe there is some bug somewhere else ?
Quoted 33 lines
, some bits like PE, PSPD have been set by controller automatically after the PR is automatically cleared. So the writing to the PORTSC1 will overwrite these bits set by controller. And eventually the driver gets wrong status.
We implement the
powerup_fixupoperation which delays 50ms and will check the PR until it is cleared by controller. And will update the reg value which is written to PORTSC register by EHCI-HCD driver. This is much safer than depending on the delay time to be accurate and aligining with controller's behaiver.Signed-off-by Ye Li <[email protected]>Signed-off-by Alice Guo <[email protected]>--- drivers/usb/host/ehci-mx6.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)drivers/usb/host/ehci-mx6.c +8
-0@@ -265,6 +265,25 @@ int usb_phy_mode(int port) }#endif +static void ehci_mx6_powerup_fixup (struct ehci_ctrl *ctrl,uint32_t *status_reg, +uint32_t *reg) +{ +u32 result; +int usec =2000 ; + +mdelay (50 ); +
drivers/usb/host/ehci-mx6.c int usb_phy_mode(int port) · line 285
Quoted 10 lines
drivers/usb/host/ehci-mx6.c +10
-0+do { + result =ehci_readl (status_reg); +udelay (5 ); +if (!(result &EHCI_PS_PR )) +break ; + usec--; + }while (usec >0 ); + + *reg =ehci_readl (status_reg); +}
Can't the core EHCI code simply check whether PR is cleared already and skip updating PORTSC if it is instead ?
回复: [PATCH v1 1/4] ehci-mx6: Add powerup_fixup implementation
Quoted 24 lines
-----邮件原件-----
发件人: Marek Vasut <[email protected]>
发送时间: 2025年11月30日 9:05
收件人: Alice Guo (OSS) <[email protected]>; [email protected]; dl-uboot-imx <[email protected]>
抄送: Marek Vasut <[email protected]>; Marek Vasut <[email protected]>; Tom Rini <[email protected]>; Ye Li <[email protected]>; Fabio Estevam <[email protected]>; [email protected]; Mattijs Korpershoek <[email protected]>; Patrice Chotard <[email protected]>; Stefano Babic <[email protected]>; Peng Fan <[email protected]>; Lukasz Majewski <[email protected]>; Simon Glass <[email protected]>; David Zang <[email protected]>; Alice Guo <[email protected]>
主题: Re: [PATCH v1 1/4] ehci-mx6: Addpowerup_fixupimplementationQuoted 8 lines · On 11/28/25 2:16 PM, [email protected] wrote:
From: Ye Li <[email protected]>
When doing port reset, the PR bit of PORTSC1 will be automatically cleared by our IP, but standard EHCI needs explicit clear by software. The EHCI-HCD driver follow the EHCI specification, so after 50ms wait, it clear the PR bit by writting to the PORTSC1 register with value loaded before setting PR.
Quoted 4 lines
Quoted 2 lines
This sequence is ok for our IP when the delay time is exact. But when the timer is slower
How can the timer be slower ? Maybe there is some bug somewhere else ?
On i.MX8ULP, the A35 system counter uses the internal LPO. The trimmed frequency of the LPO is not as accurate as an external oscillator.
Best regards,
Alice Guo
Re: 回复: [PATCH v1 1/4] ehci-mx6: Add powerup_fixup implementation
Quoted 6 lines · Alice Guo (OSS)
Quoted 4 lines
Quoted 2 lines
This sequence is ok for our IP when the delay time is exact. But when the timer is slower
How can the timer be slower ? Maybe there is some bug somewhere else ?
On i.MX8ULP, the A35 system counter uses the internal LPO. The trimmed frequency of the LPO is not as accurate as an external oscillator.
How much does it drift ? Details please ?
PATCH 2/4 ehci-mx6: Update USB host driver for iMX8ULP
In reply to [email protected]From: Alice Guo <[email protected]>
iMX8ULP uses same controller and PHY as iMX7ULP, but with two instances respectively. Update the driver to adapt for iMX8ULP.
When getting the phy register base from DTS node, change to use fdtdec_get_addr_size_auto_noparent(). Because the cell size in soc node is defined to 1 in dts, while fdtdec_get_addr() supposes to cell size is 2 on 64 bits platform.
--- drivers/usb/host/Kconfig | 2 +- drivers/usb/host/ehci-mx6.c | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 15 deletions(-)
drivers/usb/host/Kconfig +1 -1
@@ -202,7 +202,7 @@ config USB_EHCI_MX5 config USB_EHCI_MX6 bool "Support for i.MX6/i.MX7ULP on-chip EHCI USB controller" - depends on ARCH_MX6 || ARCH_MX7ULP || ARCH_IMXRT + depends on ARCH_MX6 || ARCH_MX7ULP || ARCH_IMXRT || ARCH_IMX8ULP select EHCI_HCD_INIT_AFTER_RESET default y ---help---
drivers/usb/host/ehci-mx6.c +29 -14
109 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v1 2/4] ehci-mx6: Update USB host driver for iMX8ULP
On 11/28/25 2:16 PM, [email protected] wrote:
[...]
drivers/usb/host/ehci-mx6.c static void __maybe_unused · line 173
Quoted 13 lines
drivers/usb/host/ehci-mx6.c +3
-2-#if defined(CONFIG_MX7ULP ) && !defined(CONFIG_PHY ) +#if (defined(CONFIG_MX7ULP ) || defined(CONFIG_IMX8ULP )) && !defined(CONFIG_PHY )static void usb_power_config_mx7ulp (struct usbphy_regs __iomem *usbphy) { -if (!is_mx7ulp ()) +if (!(is_mx7ulp () ||is_imx8ulp ()))return ;writel (ANADIG_USB2_CHRG_DETECT_EN_B |ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B , &usbphy->usb1_chrg_detect); +#if IS_ENABLED (CONFIG_IMX8ULP )
if (IS_ENABLED(...)) , but really , can we avoid the ifdeffery altogether ?
Quoted 4 lines
drivers/usb/host/ehci-mx6.c +3
-0+enable_usb_pll ((ulong )usbphy); +#else scg_enable_usb_pll (true); +#endif
[...]
drivers/usb/host/ehci-mx6.c static int mx6_parse_dt_addrs(struct udevice *dev) · line 636
Quoted 7 lines
drivers/usb/host/ehci-mx6.c +2
-1@@ -620,13 +632,15 @@ static int mx6_parse_dt_addrs(struct udevice *dev)if (misc_off <0 )return -EINVAL ; - addr = (void __iomem *)fdtdec_get_addr (blob, phy_off,"reg" ); + addr = (void __iomem *)fdtdec_get_addr_size_auto_noparent (blob, phy_off, +"reg" ,0 ,NULL , false);
Separate patch please . Also, why this change ?
PATCH 3/4 imx8ulp: clock: Drop CONFIG_USB_MAX_CONTROLLER_COUNT dependency
In reply to [email protected]From: Ye Li <[email protected]>
Remove the use of CONFIG_USB_MAX_CONTROLLER_COUNT in enable_usboh3_clk(), as this option is relevant for non-DM USB. The i.MX8ULP platform uses DM-based USB, so this dependency is unnecessary.
--- arch/arm/mach-imx/imx8ulp/clock.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
arch/arm/mach-imx/imx8ulp/clock.c +4 -8
@@ -286,14 +286,10 @@ void enable_usboh3_clk(unsigned char enable)pcc_reset_peripheral (4 ,USB0_PCC4_SLOT , false);pcc_reset_peripheral (4 ,USBPHY_PCC4_SLOT , false); -#ifdef CONFIG_USB_MAX_CONTROLLER_COUNT -if (CONFIG_USB_MAX_CONTROLLER_COUNT >1 ) { -pcc_clock_enable (4 ,USB1_PCC4_SLOT , true); -pcc_clock_enable (4 ,USB1PHY_PCC4_SLOT , true); -pcc_reset_peripheral (4 ,USB1_PCC4_SLOT , false); -pcc_reset_peripheral (4 ,USB1PHY_PCC4_SLOT , false); - } -#endif +pcc_clock_enable (4 ,USB1_PCC4_SLOT , true); +pcc_clock_enable (4 ,USB1PHY_PCC4_SLOT , true); +pcc_reset_peripheral (4 ,USB1_PCC4_SLOT , false); +pcc_reset_peripheral (4 ,USB1PHY_PCC4_SLOT , false);pcc_clock_enable (4 ,USB_XBAR_PCC4_SLOT , true); }else {
Signature · 1 line
2.43.0
PATCH 4/4 imx8ulp: dst: Enable USB controller at 0x29920000 in host mode
In reply to [email protected]From: Alice Guo <[email protected]>
Update the i.MX8ULP EVK device tree files and defconfig to enable the second USB controller (base address 0x29920000) on i.MX8ULP EVK in host mode.
--- arch/arm/dts/imx8ulp-evk-u-boot.dtsi | 4 ++++ arch/arm/dts/imx8ulp-evk.dts | 27 +++++++++++++++++++++++++++ arch/arm/dts/imx8ulp.dtsi | 30 ++++++++++++++++++++++++++++++ configs/imx8ulp_evk_defconfig | 3 +++ 4 files changed, 64 insertions(+)
arch/arm/dts/imx8ulp-evk-u-boot.dtsi +4 -0
@@ -38,6 +38,10 @@ bootph-all; }; +&usbotg2 { + compatible = "fsl,imx8ulp-usb", "fsl,imx7ulp-usb", "fsl,imx27-usb"; +}; + &usdhc0 { bootph-pre-ram; };
arch/arm/dts/imx8ulp-evk.dts +27 -0
@@ -44,6 +44,26 @@ status = "okay"; }; +&usbotg2 { + pinctrl-names = "default", "sleep"; + pinctrl-0 = <&pinctrl_otgid2>; + pinctrl-1 = <&pinctrl_otgid2>; + dr_mode = "otg"; + hnp-disable; + srp-disable; + adp-disable; + over-current-active-low; + status = "okay"; +}; + +&usbphy2 { + status = "okay"; +}; + +&usbmisc2 { + status = "okay"; +}; + &usdhc0 { pinctrl-names = "default", "sleep"; pinctrl-0 = <&pinctrl_usdhc0>;
@@ -103,6 +123,13 @@ >; }; + pinctrl_otgid2: usb2grp { + fsl,pins = < + MX8ULP_PAD_PTD23__USB1_ID 0x10003 + MX8ULP_PAD_PTF6__USB1_OC 0x10003 + >; + }; + pinctrl_usdhc0: usdhc0grp { fsl,pins = < MX8ULP_PAD_PTD1__SDHC0_CMD 0x43
arch/arm/dts/imx8ulp.dtsi +30 -0
@@ -399,6 +399,36 @@ status = "disabled"; }; + usbotg2: usb@29920000 { + compatible = "fsl,imx8ulp-usb", "fsl,imx7ulp-usb"; + reg = <0x29920000 0x200>; + interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&pcc4 IMX8ULP_CLK_USB1>; + power-domains = <&scmi_devpd IMX8ULP_PD_USDHC2_USB1>; + phys = <&usbphy2>; + fsl,usbmisc = <&usbmisc2 0>; + ahb-burst-config = <0x0>; + tx-burst-size-dword = <0x8>; + rx-burst-size-dword = <0x8>; + status = "disabled"; + }; + + usbmisc2: usbmisc@29920200 { + compatible = "fsl,imx8ulp-usbmisc", "fsl,imx7ulp-usbmisc"; + #index-cells = <1>; + reg = <0x29920200 0x200>; + status = "disabled"; + }; + + usbphy2: usb-phy@29930000 { + compatible = "fsl,imx8ulp-usbphy", "fsl,imx7ulp-usbphy"; + reg = <0x29930000 0x10000>; + interrupts = <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&pcc4 IMX8ULP_CLK_USB1_PHY>; + #phy-cells = <0>; + status = "disabled"; + }; + fec: ethernet@29950000 { compatible = "fsl,imx8ulp-fec", "fsl,imx6ul-fec", "fsl,imx6q-fec"; reg = <0x29950000 0x10000>;
configs/imx8ulp_evk_defconfig +3 -0
@@ -54,6 +54,7 @@ CONFIG_CMD_GPIO=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y CONFIG_CMD_READ=y +CONFIG_CMD_USB=y CONFIG_CMD_CACHE=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_EXT4_WRITE=y
@@ -92,4 +93,6 @@ CONFIG_FSL_LPUART=y CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_NXP_FSPI=y +CONFIG_USB=y +CONFIG_USB_EHCI_HCD=y CONFIG_ULP_WATCHDOG=y
Signature · 1 line
2.43.0
Fabio Estevam
reviewerRe: [PATCH v1 4/4] imx8ulp: dst: Enable USB controller at 0x29920000 in host mode
Hi Alice,
arch/arm/dts/imx8ulp-evk-u-boot.dtsi line 43
Quoted 3 lines · On Fri, Nov 28, 2025 at 10:18 AM <[email protected]> wrote:
+&usbotg2 {
arch/arm/dts/imx8ulp-evk-u-boot.dtsi +2
-0+ compatible = "fsl,imx8ulp-usb", "fsl,imx7ulp-usb", "fsl,imx27-usb"; +};
In imx8ulp.dtsi from Linux:
usbotg2: usb@29920000 {
compatible = "fsl,imx8ulp-usb", "fsl,imx7ulp-usb", "fsl,imx6ul-usb";
Why is U-Boot using a different compatible?
Also, what is the plan to switch imx8ulp-evk to OF_UPSTREAM?
Please explain in the commit log why you are touching U-Boot devicetrees instead of using OF_UPSTREAM.
Fabio Estevam
reviewerRe: [PATCH v1 4/4] imx8ulp: dst: Enable USB controller at 0x29920000 in host mode
In reply to [email protected]Quoted 17 lines · On Fri, Nov 28, 2025 at 10:18 AM <[email protected]> wrote:
arch/arm/dts/imx8ulp-evk.dts +9
-0@@ -44,6 +44,26 @@ status = "okay"; }; +&usbotg2 { + pinctrl-names = "default", "sleep"; + pinctrl-0 = <&pinctrl_otgid2>; + pinctrl-1 = <&pinctrl_otgid2>; + dr_mode = "otg"; + hnp-disable; + srp-disable; + adp-disable; + over-current-active-low;
arch/arm/dts/imx8ulp-evk.dts line 65
Quoted 10 lines
arch/arm/dts/imx8ulp-evk.dts +10
-0+ status = "okay"; +}; + +&usbphy2 { + status = "okay"; +}; + +&usbmisc2 { + status = "okay"; +};
These USB nodes are already present indts/upstream/src/arm64/freescale/imx8ulp.dtsidts/upstream/src/arm64/freescale/imx8ulp-evk.dts
Please send a patch to convert imx8ulp-evk to OF_UPSTREAM, then resend this series.
回复: [PATCH v1 4/4] imx8ulp: dst: Enable USB controller at 0x29920000 in host mode
Quoted 49 lines
-----邮件原件-----
发件人: Fabio Estevam <[email protected]>
发送时间: 2025年11月30日 8:07
收件人: Alice Guo (OSS) <[email protected]>
抄送: [email protected]; dl-uboot-imx <[email protected]>; Marek Vasut <[email protected]>; Marek Vasut <[email protected]>; Tom Rini <[email protected]>; Ye Li <[email protected]>; [email protected]; Mattijs Korpershoek <[email protected]>; Patrice Chotard <[email protected]>; Stefano Babic <[email protected]>; Peng Fan <[email protected]>; Lukasz Majewski <[email protected]>; Simon Glass <[email protected]>; David Zang <[email protected]>; Alice Guo <[email protected]>
主题: Re: [PATCH v1 4/4] imx8ulp: dst: Enable USB controller at0x29920000in host modeQuoted 17 lines · On Fri, Nov 28, 2025 at 10:18 AM <[email protected]> wrote:
(quoted diff) +0
-0
b/arch/arm/dts/imx8ulp-evk.dtsindex7aec1706382..fb28748ec17100644arch/arm/dts/imx8ulp-evk.dts +9
-0@@ -44,6 +44,26 @@ status = "okay"; }; +&usbotg2 { + pinctrl-names = "default", "sleep"; + pinctrl-0 = <&pinctrl_otgid2>; + pinctrl-1 = <&pinctrl_otgid2>; + dr_mode = "otg"; + hnp-disable; + srp-disable; + adp-disable; + over-current-active-low;arch/arm/dts/imx8ulp-evk.dts line 65
Quoted 10 lines
arch/arm/dts/imx8ulp-evk.dts +10
-0+ status = "okay"; +}; + +&usbphy2 { + status = "okay"; +}; + +&usbmisc2 { + status = "okay"; +};These USB nodes are already present in
dts/upstream/src/arm64/freescale/imx8ulp.dtsidts/upstream/src/arm64/freescale/imx8ulp-evk.dts
Quoted 2 lines
Please send a patch to convert imx8ulp-evk to
OF_UPSTREAM, then resend this series.
Hi Fabio,
Patch to convert imx8ulp-evk to OF_UPSTREAM is sent out. https://lore.kernel.org/u-boot/[email protected]/T/#u
Best regards
Alice Guo