Enable USB on i.MX8ULP EVK
Subsystems (5)
v2 cover Enable USB on i.MX8ULP EVK
Changes for v1:
- Enable the second USB controller (base address 0x29920000) on i.MX8ULP EVK in host mode.
Changes for v2:
- Split the part that replaces fdtdec_get_addr with fdtdec_get_addr_size_auto_noparent from v1 patch 2/4 into a separate patch.
- Use the USB node from the dts/upstream.
CI: https://github.com/u-boot/u-boot/pull/839/checks
---
Alice Guo (3):
usb: ehci-mx6: Replace fdtdec_get_addr() with fdtdec_get_addr_size_auto_noparent()
usb: ehci-mx6: Add support for i.MX8ULP
imx8ulp_evk: 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/mach-imx/imx8ulp/clock.c | 12 ++---- configs/imx8ulp_evk_defconfig | 3 ++ drivers/usb/host/Kconfig | 2 +- drivers/usb/host/ehci-mx6.c | 73 ++++++++++++++++++++++++++++-------- 5 files changed, 70 insertions(+), 24 deletions(-)
---
base-commit: 819a82c35354fee6680c4ccf1edc91a50802e4e9
change-id: 20251209-imx8ulp-fc888d404545
Best regards,
Signature · 1 line
Alice Guo <[email protected]>
PATCH v2 1/5 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 + .init_after_reset = mx6_init_after_reset, + .powerup_fixup = ehci_mx6_powerup_fixup, };static int ehci_usb_phy_mode (struct udevice *dev)
Signature · 1 line
2.43.0
PATCH v2 2/5 usb: ehci-mx6: Replace fdtdec_get_addr() with fdtdec_get_addr_size_auto_noparent()
In reply to [email protected]From: Alice Guo <[email protected]>
Replace fdtdec_get_addr() with fdtdec_get_addr_size_auto_noparent() so that address and size are decoded according to the device tree’s actual #address-cells and #size-cells.
--- drivers/usb/host/ehci-mx6.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/host/ehci-mx6.c +8 -5
@@ -551,8 +551,8 @@ static int ehci_usb_phy_mode(struct udevice *dev)if (phy_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);if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE )return -EINVAL ;
@@ -620,13 +620,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);if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE ) addr =NULL ; priv->phy_addr = addr; - addr = (void __iomem *)fdtdec_get_addr (blob, misc_off,"reg" ); + addr = (void __iomem *)fdtdec_get_addr_size_auto_noparent (blob, misc_off, +"reg" ,0 ,NULL , false);if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE )return -EINVAL ;
@@ -646,7 +648,8 @@ static int mx6_parse_dt_addrs(struct udevice *dev)if (anatop_off <0 )return -EINVAL ; - addr = (void __iomem *)fdtdec_get_addr (blob, anatop_off,"reg" ); + addr = (void __iomem *)fdtdec_get_addr_size_auto_noparent (blob, anatop_off, +"reg" ,0 ,NULL , false);if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE )return -EINVAL ;
Signature · 1 line
2.43.0
PATCH v2 3/5 usb: ehci-mx6: Add support for i.MX8ULP
In reply to [email protected]From: Alice Guo <[email protected]>
The i.MX8ULP shares the same USB OTG and PHY controllers as the i.MX7ULP. Update the driver to support i.MX8ULP.
i.MX8ULP uses the property phys for the phandle of the USB PHY connected to the port.
--- drivers/usb/host/Kconfig | 2 +- drivers/usb/host/ehci-mx6.c | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 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 +23 -9
@@ -160,25 +160,30 @@ static void __maybe_unused usb_power_config_mx7(void *usbnc) { }#endif -#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 ) +enable_usb_pll ((ulong )usbphy); +#else scg_enable_usb_pll (true); +#endif }#else static void __maybe_unused usb_power_config_mx7ulp (void *usbphy) { }#endif -#if defined(CONFIG_MX6 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMXRT ) -static const unsigned phy_bases[] = { +#if defined(CONFIG_MX6 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMXRT ) || \ + defined(CONFIG_IMX8ULP ) +static const ulong phy_bases[] = {USB_PHY0_BASE_ADDR , #if defined(USB_PHY1_BASE_ADDR) USB_PHY1_BASE_ADDR,
@@ -374,6 +379,11 @@ int ehci_hcd_init(int index, enum usb_init_type init, (struct usbphy_regs __iomem *)USB_PHY0_BASE_ADDR ;struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + (0x10000 * index) +USBNC_OFFSET ); +#elif defined(CONFIG_IMX8ULP ) +u32 controller_spacing =0x20000 ; +struct usbphy_regs __iomem *usbphy = (struct usbphy_regs __iomem *)(ulong )phy_bases[index]; +struct usbnc_regs *usbnc = (struct usbnc_regs *)(USB_BASE_ADDR + + (controller_spacing * index) +USBNC_OFFSET );#endif struct usb_ehci *ehci = (struct usb_ehci *)(USB_BASE_ADDR + (controller_spacing * index));
@@ -404,7 +414,7 @@ int ehci_hcd_init(int index, enum usb_init_type init,usb_power_config_mx6 (anatop, index);#elif defined (CONFIG_MX7 )usb_power_config_mx7 (usbnc); -#elif defined (CONFIG_MX7ULP ) +#elif defined(CONFIG_MX7ULP ) || defined(CONFIG_IMX8ULP )usb_power_config_mx7ulp (usbphy);#endif
@@ -544,12 +554,15 @@ static int ehci_usb_phy_mode(struct udevice *dev)* About fsl,usbphy, Refer to * Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt. */ -if (is_mx6 () ||is_mx7ulp () ||is_imxrt ()) { +if (is_mx6 () ||is_mx7ulp () ||is_imxrt () ||is_imx8ulp ()) { phy_off =fdtdec_lookup_phandle (blob, offset,"fsl,usbphy" ); -if (phy_off <0 ) -return -EINVAL ; +if (phy_off <0 ) { + phy_off =fdtdec_lookup_phandle (blob, offset,"phys" ); +if (phy_off <0 ) +return -EINVAL ; + } addr = (void __iomem *)fdtdec_get_addr_size_auto_noparent (blob, phy_off,"reg" ,0 ,NULL , false);
@@ -727,7 +740,8 @@ static int ehci_usb_probe(struct udevice *dev)usb_oc_config (priv->misc_addr, priv->portnr); -#if defined(CONFIG_MX6 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMXRT ) +#if defined(CONFIG_MX6 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMXRT ) || \ + defined(CONFIG_IMX8ULP )usb_internal_phy_clock_gate (priv->phy_addr,1 );usb_phy_enable (ehci, priv->phy_addr);#endif
Signature · 1 line
2.43.0
PATCH v2 4/5 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 v2 5/5 imx8ulp_evk: 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 ++++ configs/imx8ulp_evk_defconfig | 3 +++ 2 files changed, 7 insertions(+)
arch/arm/dts/imx8ulp-evk-u-boot.dtsi +4 -0
@@ -34,6 +34,10 @@ bootph-pre-ram; }; +&usbotg2 { + compatible = "fsl,imx8ulp-usb", "fsl,imx7ulp-usb", "fsl,imx27-usb"; +}; + &iomuxc1 { bootph-all; };
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