Enable USB in device mode on i.MX8ULP EVK
Subsystems (4)
cover Enable USB in device mode on i.MX8ULP EVK
Changes for v1:
- Refactor USB PHY register definitions to a common header file to enable code sharing between ehci-mx6.c and ci_udc.c.
- Fix the usb_oc_config() function to correctly handle overcurrent configuration on i.MX7/8M/9/7ULP/8/8ULP platforms, where the register layout differs from i.MX6.
- Extract PHY initialization code into a reusable function that can be shared between ehci-mx6.c and ci_udc.c.
- Convert the ci_udc driver to use driver model.
- Updating Kconfig to automatically select DM_USB_GADGET when CI_UDC is enabled.
- Add i.MX8ULP platform support.
Tested on i.MX8ULP EVK board with USB mass storage functionality.
---
Alice Guo (5):
usb: ehci-mx6: Move USB PHY register definitions to common header
usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
usb: ehci-mx6: Extract PHY initialization into reusable function
usb: gadget: ci_udc: Add i.MX8ULP support
imx8ulp_evk: Enable USB controller at 0x29920000 in device mode
Sherry Sun (2):
usb: ci_udc: Convert driver to DM_USB_GADGET
usb: Kconfig: imply DM_USB_GADGET
arch/arm/dts/imx8ulp-evk-u-boot.dtsi | 17 ++ arch/arm/include/asm/mach-imx/regs-usbphy.h | 3 + configs/imx8ulp_evk_defconfig | 7 + drivers/usb/gadget/Kconfig | 2 +- drivers/usb/gadget/ci_udc.c | 354 +++++++++++++++++++++++++++- drivers/usb/host/ehci-mx6.c | 93 ++++++-- include/usb/ci_udc.h | 9 + 7 files changed, 465 insertions(+), 20 deletions(-)
---
base-commit: d21fcfb29ec2871976de8d21ea0e60fb13ce032f
change-id: 20251216-imx8ulp-129e9fdc1128
Best regards,
Signature · 1 line
Alice Guo <[email protected]>
PATCH 1/7 usb: ehci-mx6: Move USB PHY register definitions to common header
From: Alice Guo <[email protected]>
Move USB PHY related register definitions from ehci-mx6.c to the common regs-usbphy.h header file to enable sharing across different USB drivers.
--- arch/arm/include/asm/mach-imx/regs-usbphy.h | 3 +++ drivers/usb/host/ehci-mx6.c | 15 +-------------- 2 files changed, 4 insertions(+), 14 deletions(-)
arch/arm/include/asm/mach-imx/regs-usbphy.h +3 -0
@@ -22,4 +22,7 @@#define USBPHY_CTRL_CLKGATE (1 << 30)#define USBPHY_CTRL_SFTRST (1 << 31) +#define USBNC_PHY_STATUS_OFFSET 0x23C +#define USBNC_PHYSTATUS_ID_DIG BIT(4)/* otg_id status */ +#endif /* __REGS_USBPHY_H__ */
drivers/usb/host/ehci-mx6.c +1 -14
@@ -17,6 +17,7 @@#include <asm/arch/imx-regs.h> #include <asm/arch/clock.h> #include <asm/mach-imx/iomux-v3.h> +#include <asm/mach-imx/regs-usbphy.h> #include <asm/mach-imx/sys_proto.h> #include <dm.h> #include <asm/mach-types.h>
@@ -36,18 +37,6 @@ DECLARE_GLOBAL_DATA_PTR;#define USB_H1_CTRL_OFFSET 0x04 -#define USBPHY_CTRL 0x00000030 -#define USBPHY_CTRL_SET 0x00000034 -#define USBPHY_CTRL_CLR 0x00000038 -#define USBPHY_CTRL_TOG 0x0000003c - -#define USBPHY_PWD 0x00000000 -#define USBPHY_CTRL_SFTRST 0x80000000 -#define USBPHY_CTRL_CLKGATE 0x40000000 -#define USBPHY_CTRL_ENUTMILEVEL3 0x00008000 -#define USBPHY_CTRL_ENUTMILEVEL2 0x00004000 -#define USBPHY_CTRL_OTG_ID 0x08000000 -#define ANADIG_USB2_CHRG_DETECT_EN_B 0x00100000#define ANADIG_USB2_CHRG_DETECT_CHK_CHRG_B 0x00080000
@@ -57,8 +46,6 @@ DECLARE_GLOBAL_DATA_PTR;#define ANADIG_USB2_PLL_480_CTRL_EN_USB_CLKS 0x00000040#define USBNC_OFFSET 0x200 -#define USBNC_PHY_STATUS_OFFSET 0x23C -#define USBNC_PHYSTATUS_ID_DIG (1 << 4)/* otg_id status */ #define USBNC_PHYCFG2_ACAENB (1 << 4)/* otg_id detection enable */ #define UCTRL_PWR_POL (1 << 9)/* OTG Polarity of Power Pin */ #define UCTRL_OVER_CUR_POL (1 << 8)/* OTG Polarity of Overcurrent */
Signature · 1 line
2.43.0
PATCH 2/7 usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
In reply to [email protected]From: Alice Guo <[email protected]>
The usb_oc_config() function previously assumed that the overcurrent control register index always matches the USB controller index, which is true for i.MX6 but not for i.MX7/8M/9/7ULP/8/8ULP. On these platforms, the overcurrent control is located in the USB OTG Control 1 register, which is always at index 0.
--- drivers/usb/host/ehci-mx6.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/host/ehci-mx6.c +5 -0
@@ -280,7 +280,12 @@ static void ehci_mx6_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg,/* Should be done in the MXS PHY driver */ static void usb_oc_config (struct usbnc_regs *usbnc,int index) { +#if defined(CONFIG_MX6 )void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[index]); +#elif defined(CONFIG_USB_EHCI_MX7 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMX8 ) || \ + defined(CONFIG_IMX8ULP ) +void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[0 ]); +#endif setbits_le32 (ctrl,UCTRL_OVER_CUR_POL );
Signature · 1 line
2.43.0
Re: [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
Quoted 18 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Alice Guo <[email protected]>
The
usb_oc_config()function previously assumed that the overcurrent control register index always matches the USB controller index, which is true for i.MX6 but not for i.MX7/8M/9/7ULP/8/8ULP. On these platforms, the overcurrent control is located in the USB OTG Control 1 register, which is always at index 0.Signed-off-by Alice Guo <[email protected]>--- drivers/usb/host/ehci-mx6.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/host/ehci-mx6.c +0
-0
drivers/usb/host/ehci-mx6.c static void ehci_mx6_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg, · line 288
Quoted 9 lines
drivers/usb/host/ehci-mx6.c +5
-0@@ -280,7 +280,12 @@ static void ehci_mx6_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg,/* Should be done in the MXS PHY driver */ static void usb_oc_config (struct usbnc_regs *usbnc,int index) { +#if defined(CONFIG_MX6 )void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[index]); +#elif defined(CONFIG_USB_EHCI_MX7 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMX8 ) || \ + defined(CONFIG_IMX8ULP ) +void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[0 ]); +#endif
Can we simply pass 0 to this function as index for non-MX6 instead of this ifdeffery ?
回复: [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
Quoted 45 lines
-----邮件原件-----
发件人: Marek Vasut <[email protected]>
发送时间: 2025年12月16日 19:16
收件人: Alice Guo (OSS) <[email protected]>; dl-uboot-imx <[email protected]>; [email protected]
抄送: Stefano Babic <[email protected]>; Fabio Estevam <[email protected]>; Tom Rini <[email protected]>; Marek Vasut <[email protected]>; Marek Vasut <[email protected]>; Ye Li <[email protected]>; [email protected]; Peng Fan <[email protected]>; Mattijs Korpershoek <[email protected]>; Lukasz Majewski <[email protected]>; Sherry Sun <[email protected]>; Kever Yang <[email protected]>; Jonas Karlman <[email protected]>; Quentin Schulz <[email protected]>; George Chan <[email protected]>; Simon Glass <[email protected]>; David Zang <[email protected]>; Alice Guo <[email protected]>
主题: Re: [PATCH v1 2/7] usb: ehci-mx6: Fixusb_oc_config()for i.MX7/8M/9/7ULP/8 and 8ULP platformsdrivers/usb/host/ehci-mx6.c static void ehci_mx6_powerup_fixup(struct ehci_ctrl
Quoted 18 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Alice Guo <[email protected]>
The
usb_oc_config()function previously assumed that the overcurrent control register index always matches the USB controller index, which is true for i.MX6 but not for i.MX7/8M/9/7ULP/8/8ULP. On these platforms, the overcurrent control is located in the USB OTG Control 1 register, which is always at index 0.Signed-off-by Alice Guo <[email protected]>--- drivers/usb/host/ehci-mx6.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/host/ehci-mx6.c +0
-0@@ -280,7 +280,12 @@ static void ehci_mx6_powerup_fixup(struct ehci_ctrl*ctrl,
uint32_t*status_reg,drivers/usb/host/ehci-mx6.c static void ehci_mx6_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg,
Quoted 6 lines
drivers/usb/host/ehci-mx6.c +2
-0/* Should be done in the MXS PHY driver */ static void usb_oc_config (struct usbnc_regs *usbnc,int index) { +#if defined(CONFIG_MX6 )void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[index]); +#elif defined(CONFIG_USB_EHCI_MX7) || defined(CONFIG_MX7ULP) ||
defined(CONFIG_IMX8)|| \
Quoted 4 lines
drivers/usb/host/ehci-mx6.c static void ehci_mx6_powerup_fixup(struct ehci_ctrl · line 287
Quoted 2 lines
drivers/usb/host/ehci-mx6.c +2
-0+defined (CONFIG_IMX8ULP) + void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[0]); #endifCan we simply pass 0 to this function as index for non-MX6 instead of this ifdeffery ?
Even if I move the condition from inside the usb_oc_config() to the call site, I still cannot avoid conditional compilation because the logic is platform-specific. Given this, is it acceptable to keep the current change as it is?
Best Regards,
Alice Guo
Re: 回复: [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
On 12/25/25 11:41 AM, Alice Guo (OSS) wrote:
Hello Alice,
Quoted 13 lines
Quoted 13 lines
drivers/usb/host/ehci-mx6.c static void ehci_mx6_powerup_fixup(struct ehci_ctrl
Quoted 5 lines
drivers/usb/host/ehci-mx6.c +0
-0@@ -280,7 +280,12 @@ static void ehci_mx6_powerup_fixup(struct ehci_ctrl*ctrl,
uint32_t*status_reg,drivers/usb/host/ehci-mx6.c static void ehci_mx6_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg,
Quoted 6 lines
drivers/usb/host/ehci-mx6.c +2
-0/* Should be done in the MXS PHY driver */ static void usb_oc_config (struct usbnc_regs *usbnc,int index) { +#if defined(CONFIG_MX6 )void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[index]); +#elif defined(CONFIG_USB_EHCI_MX7) || defined(CONFIG_MX7ULP) ||
defined(CONFIG_IMX8)|| \
Quoted 7 lines
Quoted 4 lines
drivers/usb/host/ehci-mx6.c static void ehci_mx6_powerup_fixup(struct ehci_ctrl · line 287
Quoted 2 lines
drivers/usb/host/ehci-mx6.c +2
-0+defined (CONFIG_IMX8ULP) + void __iomem *ctrl = (void __iomem *)(&usbnc->ctrl[0]); #endifCan we simply pass 0 to this function as index for non-MX6 instead of this ifdeffery ?
Even if I move the condition from inside the
usb_oc_config()to the call site, I still cannot avoid conditional compilation because the logic is platform-specific. Given this, is it acceptable to keep the current change as it is?
Can we please somehow weed out the ifdeffery ?
PATCH 3/7 usb: ehci-mx6: Extract PHY initialization into reusable function
In reply to [email protected]From: Alice Guo <[email protected]>
Extract USB PHY initialization code from ehci-mx6.c into a new function ehci_mx6_phy_init() that can be shared with the ChipIdea UDC driver.
--- drivers/usb/host/ehci-mx6.c | 73 ++++++++++++++++++++++++++++++++++++++++++++- include/usb/ci_udc.h | 9 ++++++ 2 files changed, 81 insertions(+), 1 deletion(-)
drivers/usb/host/ehci-mx6.c +72 -1
@@ -12,6 +12,7 @@#include <asm/global_data.h> #include <linux/compiler.h> #include <linux/delay.h> +#include <usb/ci_udc.h> #include <usb/ehci-ci.h> #include <asm/io.h> #include <asm/arch/imx-regs.h>
@@ -168,6 +169,54 @@ static void __maybe_unused usb_power_config_mx7ulp(void *usbphy) { }#endif +#if defined(CONFIG_IMX8 ) +static void usb_power_config_imx8 (void __iomem *usbphy_base) +{ +struct usbphy_regs __iomem *usbphy = (struct usbphy_regs __iomem *)usbphy_base; + +if (!is_imx8 ()) +return ; + +int timeout =1000000 ; + +if (!(readl (&usbphy->usb1_pll_480_ctrl) &PLL_USB_LOCK_MASK )) { +/* Enable the regulator first */ +writel (PLL_USB_REG_ENABLE_MASK , + &usbphy->usb1_pll_480_ctrl_set); + +/* Wait at least 25us */ +udelay (25 ); + +/* Enable the power */ +writel (PLL_USB_PWR_MASK , &usbphy->usb1_pll_480_ctrl_set); + +/* Wait lock */ +while (timeout--) { +if (readl (&usbphy->usb1_pll_480_ctrl) & +PLL_USB_LOCK_MASK ) +break ; +udelay (10 ); + } + +if (timeout <=0 ) { +/* If timeout, we power down the pll */ +writel (PLL_USB_PWR_MASK , + &usbphy->usb1_pll_480_ctrl_clr); +return ; + } + } + +/* Clear the bypass */ +writel (PLL_USB_BYPASS_MASK , &usbphy->usb1_pll_480_ctrl_clr); + +/* Enable the PLL clock out to USB */ +writel ((PLL_USB_EN_USB_CLKS_MASK |PLL_USB_ENABLE_MASK ), + &usbphy->usb1_pll_480_ctrl_set); +} +#else +static void __maybe_unused usb_power_config_imx8 (void __iomem *usbphy_base) { } +#endif +#if defined(CONFIG_MX6 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMXRT ) || \ defined(CONFIG_IMX8ULP ) static const ulong phy_bases[] = {
@@ -276,7 +325,6 @@ static void ehci_mx6_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg, *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) {
@@ -298,7 +346,30 @@ static void usb_oc_config(struct usbnc_regs *usbnc, int index)clrbits_le32 (ctrl,UCTRL_PWR_POL );#endif } + +void ehci_mx6_phy_init (struct usb_ehci *ehci,struct ehci_mx6_phy_data *phy_data,int index) +{ +u32 portsc; + + portsc =readl (&ehci->portsc); +if (portsc &PORT_PTS_PHCD ) { +debug ("suspended: portsc %x, enabled it.\n" , portsc); +clrbits_le32 (&ehci->portsc,PORT_PTS_PHCD ); + } + +usb_power_config_mx6 (phy_data->anatop_addr, index); +usb_power_config_mx7 (phy_data->misc_addr); +usb_power_config_mx7ulp (phy_data->phy_addr); +usb_power_config_imx8 (phy_data->phy_addr); + +usb_oc_config (phy_data->misc_addr, index); + +#if defined(CONFIG_MX6 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMXRT ) || \ + defined(CONFIG_IMX8 ) || defined(CONFIG_IMX8ULP ) +usb_internal_phy_clock_gate (phy_data->phy_addr,1 ); +usb_phy_enable (ehci, phy_data->phy_addr);#endif +}#if !CONFIG_IS_ENABLED (DM_USB )/**
include/usb/ci_udc.h +9 -0
@@ -6,7 +6,16 @@#ifndef __CI_UDC_H__#define __CI_UDC_H__ +#include <usb/ehci-ci.h> #define EP_MAX_PACKET_SIZE 0x200#define EP0_MAX_PACKET_SIZE 64 + +struct ehci_mx6_phy_data { +void __iomem *phy_addr; +void __iomem *misc_addr; +void __iomem *anatop_addr; +}; + +void ehci_mx6_phy_init (struct usb_ehci *ehci,struct ehci_mx6_phy_data *phy_data,int index);#endif /* __CI_UDC_H__ */
Signature · 1 line
2.43.0
Re: [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable functionr
Quoted 45 lines · On Tue, Dec 16, 2025 at 02:38:35PM +0800, [email protected] wrote:
From: Alice Guo <[email protected]>
Extract USB PHY initialization code from
ehci-mx6.cinto a new functionehci_mx6_phy_init()that can be shared with the ChipIdea UDC driver.Signed-off-by Alice Guo <[email protected]>--- drivers/usb/host/ehci-mx6.c | 73 ++++++++++++++++++++++++++++++++++++++++++++- include/usb/ci_udc.h | 9 ++++++ 2 files changed, 81 insertions(+), 1 deletion(-)drivers/usb/host/ehci-mx6.c +19
-0@@ -12,6 +12,7 @@#include <asm/global_data.h> #include <linux/compiler.h> #include <linux/delay.h> +#include <usb/ci_udc.h> #include <usb/ehci-ci.h> #include <asm/io.h> #include <asm/arch/imx-regs.h> @@ -168,6 +169,54 @@ static void __maybe_unused usb_power_config_mx7ulp(void *usbphy) { }#endif +#if defined(CONFIG_IMX8 ) +static void usb_power_config_imx8 (void __iomem *usbphy_base) +{ +struct usbphy_regs __iomem *usbphy = (struct usbphy_regs __iomem *)usbphy_base; + +if (!is_imx8 ()) +return ; + +int timeout =1000000 ; + +if (!(readl (&usbphy->usb1_pll_480_ctrl) &PLL_USB_LOCK_MASK )) { +/* Enable the regulator first */ +writel (PLL_USB_REG_ENABLE_MASK , + &usbphy->usb1_pll_480_ctrl_set); + +/* Wait at least 25us */ +udelay (25 ); +
drivers/usb/host/ehci-mx6.c static void __maybe_unused · line 199
Quoted 10 lines
drivers/usb/host/ehci-mx6.c +10
-0+/* Enable the power */ +writel (PLL_USB_PWR_MASK , &usbphy->usb1_pll_480_ctrl_set); + +/* Wait lock */ +while (timeout--) { +if (readl (&usbphy->usb1_pll_480_ctrl) & +PLL_USB_LOCK_MASK ) +break ; +udelay (10 ); + }
We have readX_poll_timeout() defined in include/linux/iopoll.h, I think it could simplify the code here.
Quoted 5 lines
drivers/usb/host/ehci-mx6.c +5
-0+if (timeout <=0 ) { +/* If timeout, we power down the pll */ +writel (PLL_USB_PWR_MASK , + &usbphy->usb1_pll_480_ctrl_clr); +return ;
drivers/usb/host/ehci-mx6.c static void __maybe_unused · line 215
Quoted 10 lines
drivers/usb/host/ehci-mx6.c +10
-0+ } + } + +/* Clear the bypass */ +writel (PLL_USB_BYPASS_MASK , &usbphy->usb1_pll_480_ctrl_clr); + +/* Enable the PLL clock out to USB */ +writel ((PLL_USB_EN_USB_CLKS_MASK |PLL_USB_ENABLE_MASK ), + &usbphy->usb1_pll_480_ctrl_set); +}
Regards,
Yao Zi
Re: [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function
In reply to [email protected]Quoted 24 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Alice Guo <[email protected]>
Extract USB PHY initialization code from
ehci-mx6.cinto a new functionehci_mx6_phy_init()that can be shared with the ChipIdea UDC driver.Signed-off-by Alice Guo <[email protected]>--- drivers/usb/host/ehci-mx6.c | 73 ++++++++++++++++++++++++++++++++++++++++++++- include/usb/ci_udc.h | 9 ++++++ 2 files changed, 81 insertions(+), 1 deletion(-)drivers/usb/host/ehci-mx6.c +1
-0@@ -12,6 +12,7 @@#include <asm/global_data.h> #include <linux/compiler.h> #include <linux/delay.h> +#include <usb/ci_udc.h> #include <usb/ehci-ci.h> #include <asm/io.h> #include <asm/arch/imx-regs.h>
drivers/usb/host/ehci-mx6.c static void __maybe_unused · line 172
Quoted 4 lines
drivers/usb/host/ehci-mx6.c +1
-0@@ -168,6 +169,54 @@ static void __maybe_unused usb_power_config_mx7ulp(void *usbphy) { }#endif +#if defined(CONFIG_IMX8 )
Can we avoid more ifdeffery ?
Quoted 17 lines
drivers/usb/host/ehci-mx6.c +17
-0+static void usb_power_config_imx8 (void __iomem *usbphy_base) +{ +struct usbphy_regs __iomem *usbphy = (struct usbphy_regs __iomem *)usbphy_base; + +if (!is_imx8 ()) +return ; + +int timeout =1000000 ; + +if (!(readl (&usbphy->usb1_pll_480_ctrl) &PLL_USB_LOCK_MASK )) { +/* Enable the regulator first */ +writel (PLL_USB_REG_ENABLE_MASK , + &usbphy->usb1_pll_480_ctrl_set); + +/* Wait at least 25us */ +udelay (25 ); +
drivers/usb/host/ehci-mx6.c static void __maybe_unused · line 199
Quoted 10 lines
drivers/usb/host/ehci-mx6.c +10
-0+/* Enable the power */ +writel (PLL_USB_PWR_MASK , &usbphy->usb1_pll_480_ctrl_set); + +/* Wait lock */ +while (timeout--) { +if (readl (&usbphy->usb1_pll_480_ctrl) & +PLL_USB_LOCK_MASK ) +break ; +udelay (10 ); + }
readl_poll*() instead of hand-rolled polling.
drivers/usb/host/ehci-mx6.c static void __maybe_unused · line 213
Quoted 13 lines
drivers/usb/host/ehci-mx6.c +13
-0+if (timeout <=0 ) { +/* If timeout, we power down the pll */ +writel (PLL_USB_PWR_MASK , + &usbphy->usb1_pll_480_ctrl_clr); +return ; + } + } + +/* Clear the bypass */ +writel (PLL_USB_BYPASS_MASK , &usbphy->usb1_pll_480_ctrl_clr); + +/* Enable the PLL clock out to USB */ + writel((PLL_USB_EN_USB_CLKS_MASK | PLL_USB_ENABLE_MASK),
Parenthesis () not needed.
Quoted 21 lines
drivers/usb/host/ehci-mx6.c +6
-1+ &usbphy->usb1_pll_480_ctrl_set); +} +#else +static void __maybe_unused usb_power_config_imx8 (void __iomem *usbphy_base) { } +#endif +#if defined(CONFIG_MX6 ) || defined(CONFIG_MX7ULP ) || defined(CONFIG_IMXRT ) || \ defined(CONFIG_IMX8ULP ) static const ulong phy_bases[] = {@@ -276,7 +325,6 @@ static void ehci_mx6_powerup_fixup(struct ehci_ctrl *ctrl, uint32_t *status_reg, *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) {@@ -298,7 +346,30 @@ static void usb_oc_config(struct usbnc_regs *usbnc, int index)clrbits_le32 (ctrl,UCTRL_PWR_POL );#endif }
[...]
回复: [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function
Quoted 48 lines
-----邮件原件-----
发件人: Marek Vasut <[email protected]>
发送时间: 2025年12月16日 19:18
收件人: Alice Guo (OSS) <[email protected]>; dl-uboot-imx <[email protected]>; [email protected]
抄送: Stefano Babic <[email protected]>; Fabio Estevam <[email protected]>; Tom Rini <[email protected]>; Marek Vasut <[email protected]>; Marek Vasut <[email protected]>; Ye Li <[email protected]>; [email protected]; Peng Fan <[email protected]>; Mattijs Korpershoek <[email protected]>; Lukasz Majewski <[email protected]>; Sherry Sun <[email protected]>; Kever Yang <[email protected]>; Jonas Karlman <[email protected]>; Quentin Schulz <[email protected]>; George Chan <[email protected]>; Simon Glass <[email protected]>; David Zang <[email protected]>; Alice Guo <[email protected]>
主题: Re: [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable functionQuoted 9 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Alice Guo <[email protected]>
Extract USB PHY initialization code from
ehci-mx6.cinto a new functionehci_mx6_phy_init()that can be shared with the ChipIdea UDC driver.Signed-off-by Alice Guo <[email protected]>--- drivers/usb/host/ehci-mx6.c | 73++++++++++++++++++++++++++++++++++++++++++++-
Quoted 19 lines
include/usb/ci_udc.h | 9 ++++++ 2 files changed, 81 insertions(+), 1 deletion(-)drivers/usb/host/ehci-mx6.c +1
-0@@ -12,6 +12,7 @@#include <asm/global_data.h> #include <linux/compiler.h> #include <linux/delay.h> +#include <usb/ci_udc.h> #include <usb/ehci-ci.h> #include <asm/io.h> #include <asm/arch/imx-regs.h> @@ -168,6 +169,54 @@ static void __maybe_unused usb_power_config_mx7ulp(void *usbphy) { }#endif
Quoted 3 lines
drivers/usb/host/ehci-mx6.c static void __maybe_unused · line 172
Quoted 1 line
drivers/usb/host/ehci-mx6.c +1
-0+#if defined(CONFIG_IMX8 )Can we avoid more ifdeffery ?
Thanks for your feedback. I will remove it in the next version.
Best Regards,
Alice Guo
PATCH 4/7 usb: ci_udc: Convert driver to DM_USB_GADGET
In reply to [email protected]From: Sherry Sun <[email protected]>
Convert the ci_udc driver to driver model by using the uclass UCLASS_USB_GADGET_GENERIC. The clk and power of USB controller and USB PHY both are initialized by parsing the device tree nodes.
If CONFIG_DM_USB_GADGET is defined, we use the ci_udc driver in DM way, if it does not defined, we can use ci_udc driver in its original Non-DM way.
--- drivers/usb/gadget/ci_udc.c | 352 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 348 insertions(+), 4 deletions(-)
drivers/usb/gadget/ci_udc.c +348 -4
@@ -7,9 +7,17 @@* [email protected], 27-Jan-01. */ +#include <asm/arch/sys_proto.h> +#include <asm/arch/clock.h> +#include <asm/mach-imx/regs-usbphy.h> +#include <clk.h> #include <command.h> #include <config.h> #include <cpu_func.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <dm/pinctrl.h> +#include <power-domain.h> #include <net.h> #include <malloc.h> #include <wait_bit.h>
@@ -22,6 +30,8 @@#include <linux/types.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> +#include <linux/usb/otg.h> +#include <usb/ehci-ci.h> #include <usb/ci_udc.h> #include "../host/ehci.h" #include "ci_udc.h"
@@ -93,9 +103,18 @@ static int ci_ep_dequeue(struct usb_ep *ep, struct usb_request *req);static struct usb_request *ci_ep_alloc_request (struct usb_ep *ep,unsigned int gfp_flags);static void ci_ep_free_request (struct usb_ep *ep,struct usb_request *_req); +#if CONFIG_IS_ENABLED (DM_USB_GADGET ) +static int ci_udc_gadget_start (struct usb_gadget *g, +struct usb_gadget_driver *driver); +static int ci_udc_gadget_stop (struct usb_gadget *g); +#endif static const struct usb_gadget_ops ci_udc_ops = { .pullup = ci_pullup, +#if CONFIG_IS_ENABLED(DM_USB_GADGET) + .udc_start = ci_udc_gadget_start, + .udc_stop = ci_udc_gadget_stop, +#endif };static const struct usb_ep_ops ci_ep_ops = {
@@ -927,7 +946,7 @@ void udc_irq(void) } } -int dm_usb_gadget_handle_interrupts (struct udevice *dev) +int ci_udc_handle_interrupts (void ) {struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;u32 value;
@@ -1072,6 +1091,19 @@ static int ci_udc_probe(void)return 0 ; } +bool dfu_usb_get_reset (void ) +{ +struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor; + +return !!(readl (&udc->usbsts) &STS_URI ); +} + +#if !CONFIG_IS_ENABLED (DM_USB_GADGET ) +int dm_usb_gadget_handle_interrupts (struct udevice *dev) +{ +return ci_udc_handle_interrupts (); +} +int usb_gadget_register_driver (struct usb_gadget_driver *driver) {int ret;
@@ -1125,10 +1157,322 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)return 0 ; } +#else /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */ -bool dfu_usb_get_reset (void ) +static int ci_udc_gadget_start (struct usb_gadget *g, +struct usb_gadget_driver *driver) { -struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor; +if (!driver) +return -EINVAL ; +if (!driver->bind || !driver->setup || !driver->disconnect) +return -EINVAL ; -return !!(readl (&udc->usbsts) &STS_URI ); + controller.driver = driver; +return 0 ; +} + +static int ci_udc_gadget_stop (struct usb_gadget *g) +{ + controller.driver =NULL ; + +ci_ep_free_request (&controller.ep[0 ].ep, &controller.ep0_req->req); +free (controller.items_mem); +free (controller.epts); +return 0 ; +} + +struct ci_udc_priv_data { +struct ehci_ctrl ctrl; +struct udevice otgdev; +struct clk_bulk clks; +int phy_off; +struct power_domain otg_pd; +struct clk phy_clk; +struct power_domain phy_pd; +struct ehci_mx6_phy_data phy_data; +}; + +static int ci_udc_gadget_handle_interrupts (struct udevice *dev) +{ +return ci_udc_handle_interrupts (); +} + +static int ci_udc_phy_setup (struct udevice *dev,struct ci_udc_priv_data *priv) +{ +void *__iomem addr; +int misc_off; +struct udevice __maybe_unused phy_dev; + + priv->phy_off =fdtdec_lookup_phandle (gd->fdt_blob, +dev_of_offset (dev), +"fsl,usbphy" ); +if (priv->phy_off <0 ) { + priv->phy_off =fdtdec_lookup_phandle (gd->fdt_blob, +dev_of_offset (dev),"phys" ); +if (priv->phy_off <0 ) +return -EINVAL ; + } + + addr = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, priv->phy_off,"reg" ); +if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE ) + addr =NULL ; + + priv->phy_data.phy_addr = addr; + + misc_off =fdtdec_lookup_phandle (gd->fdt_blob,dev_of_offset (dev),"fsl,usbmisc" ); +if (misc_off <0 ) +return -EINVAL ; + + addr = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, misc_off,"reg" ); +if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->phy_data.misc_addr = addr; + +#if defined(CONFIG_MX6 ) +int anatop_off; + +/* Resolve ANATOP offset through USB PHY node */ + anatop_off =fdtdec_lookup_phandle (gd->fdt_blob, priv->phy_off,"fsl,anatop" ); +if (anatop_off <0 ) +return -EINVAL ; + + addr = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, anatop_off,"reg" ); +if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + priv->phy_data.anatop_addr = addr; +#endif + +dev_set_ofnode (&phy_dev,offset_to_ofnode (priv->phy_off)); + +#if CONFIG_IS_ENABLED (POWER_DOMAIN ) +/* Need to power on the PHY before access it */ +if (!power_domain_get (&phy_dev, &priv->phy_pd)) { +if (power_domain_on (&priv->phy_pd)) +return -EINVAL ; + } +#endif + +#if CONFIG_IS_ENABLED (CLK ) +int ret; + + ret =clk_get_by_index (&phy_dev,0 , &priv->phy_clk); +if (ret) { +printf ("Failed to get phy_clk\n" ); +return ret; + } + + ret =clk_enable (&priv->phy_clk); +if (ret) { +printf ("Failed to enable phy_clk\n" ); +return ret; + } +#endif + +return 0 ; } + +static int ci_udc_phy_shutdown (struct ci_udc_priv_data *priv) +{ +int ret =0 ; + +#if CONFIG_IS_ENABLED (CLK ) +if (priv->phy_clk.dev) { + ret =clk_disable (&priv->phy_clk); +if (ret) +return ret; + } +#endif + +#if CONFIG_IS_ENABLED (POWER_DOMAIN ) + ret =power_domain_off (&priv->phy_pd); +if (ret) +printf ("Power down USB PHY failed! (error = %d)\n" , ret); +#endif +return ret; +} + +static int ci_udc_otg_clk_init (struct udevice *dev, +struct clk_bulk *clks) +{ +#if CONFIG_IS_ENABLED (CLK ) +int ret; + + ret =clk_get_bulk (dev, clks); +if (ret == -ENOSYS ) +return 0 ; + +if (ret) +return ret; + + ret =clk_enable_bulk (clks); +if (ret) { +clk_release_bulk (clks); +return ret; + } +#else +enable_usboh3_clk (1 ); +#endif + +return 0 ; +} + +static int ci_udc_otg_phy_mode (struct udevice *dev) +{ +struct ci_udc_priv_data *priv =dev_get_priv (dev); + +void *__iomem phy_ctrl, *__iomem phy_status; +void *__iomem phy_base = (void *__iomem )devfdt_get_addr (&priv->otgdev); +u32 val; + +if (is_mx6 () ||is_mx7ulp () ||is_imx8 ()) { + phy_base = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, + priv->phy_off, +"reg" ); +if ((fdt_addr_t )phy_base ==FDT_ADDR_T_NONE ) +return -EINVAL ; + + phy_ctrl = (void __iomem *)(phy_base +USBPHY_CTRL ); + val =readl (phy_ctrl); +if (val &USBPHY_CTRL_OTG_ID ) +return USB_INIT_DEVICE ; +else +return USB_INIT_HOST ; + }else if (is_mx7 () ||is_imx8mm () ||is_imx8mn ()) { + phy_status = (void __iomem *)(phy_base + +USBNC_PHY_STATUS_OFFSET ); + val =readl (phy_status); +if (val &USBNC_PHYSTATUS_ID_DIG ) +return USB_INIT_DEVICE ; +else +return USB_INIT_HOST ; + }else { +return -EINVAL ; + } +} + +static int ci_udc_otg_ofdata_to_platdata (struct udevice *dev) +{ +struct ci_udc_priv_data *priv =dev_get_priv (dev); +int node =dev_of_offset (dev); +int usbotg_off; + +if (usb_get_dr_mode (dev_ofnode (dev)) !=USB_DR_MODE_PERIPHERAL ) { +dev_dbg (dev,"Invalid mode\n" ); +return -ENODEV ; + } + + usbotg_off =fdtdec_lookup_phandle (gd->fdt_blob, + node, +"chipidea,usb" ); +if (usbotg_off <0 ) +return -EINVAL ; +dev_set_ofnode (&priv->otgdev,offset_to_ofnode (usbotg_off)); + priv->otgdev.parent = dev->parent; + +return 0 ; +} + +static int ci_udc_otg_probe (struct udevice *dev) +{ +struct ci_udc_priv_data *priv =dev_get_priv (dev); +struct usb_ehci *ehci; +int ret; + + ehci = (struct usb_ehci *)devfdt_get_addr (&priv->otgdev); + +pinctrl_select_state (&priv->otgdev,"default" ); + +#if defined(CONFIG_MX6 ) +if (usb_fused ((u32 )ehci)) { +printf ("USB@0x%x is fused, disable it\n" , (u32 )ehci); +return -ENODEV ; + } +#endif + + ret =board_usb_init (dev_seq (dev),USB_INIT_DEVICE ); +if (ret) { +printf ("Failed to initialize board for USB\n" ); +return ret; + } + +#if CONFIG_IS_ENABLED (POWER_DOMAIN ) +if (!power_domain_get (&priv->otgdev, &priv->otg_pd)) { +if (power_domain_on (&priv->otg_pd)) +return -EINVAL ; + } +#endif + + ret =ci_udc_phy_setup (&priv->otgdev, priv); +if (ret) +return ret; + + ret =ci_udc_otg_clk_init (&priv->otgdev, &priv->clks); +if (ret) +return ret; + +ehci_mx6_phy_init (ehci, &priv->phy_data,dev_seq (dev)); + +if (ci_udc_otg_phy_mode (dev) !=USB_INIT_DEVICE ) +return -ENODEV ; + + priv->ctrl.hccr = (struct ehci_hccr *)((ulong)&ehci->caplength); + priv->ctrl.hcor = (struct ehci_hcor *)((ulong )priv->ctrl.hccr + +HC_LENGTH (ehci_readl (&(priv->ctrl.hccr)->cr_capbase))); + controller.ctrl = &priv->ctrl; + + ret =ci_udc_probe (); +if (ret) { +DBG ("udc probe failed, returned %d\n" , ret); +return ret; + } + + ret =usb_add_gadget_udc ((struct device *)dev, &controller.gadget); + +return ret; +} + +static int ci_udc_otg_remove (struct udevice *dev) +{ +struct ci_udc_priv_data *priv =dev_get_priv (dev); + +usb_del_gadget_udc (&controller.gadget); + +#if CONFIG_IS_ENABLED (CLK ) +clk_release_bulk (&priv->clks); +#endif +ci_udc_phy_shutdown (priv); +#if CONFIG_IS_ENABLED (POWER_DOMAIN ) +if (power_domain_off (&priv->otg_pd)) { +printf ("Power down USB controller failed!\n" ); +return -EINVAL ; + } +#endif +board_usb_cleanup (dev_seq (dev),USB_INIT_DEVICE ); + + controller.ctrl =NULL ; +return 0 ; +} + +static const struct udevice_id ci_udc_otg_ids[] = { + { .compatible ="fsl,imx27-usb-gadget" }, + { } +}; + +static const struct usb_gadget_generic_ops ci_udc_gadget_ops = { + .handle_interrupts = ci_udc_gadget_handle_interrupts, +}; + +U_BOOT_DRIVER (ci_udc_otg) = { + .name ="ci-udc-otg" , + .id =UCLASS_USB_GADGET_GENERIC , + .of_match = ci_udc_otg_ids, + .of_to_plat = ci_udc_otg_ofdata_to_platdata, + .probe = ci_udc_otg_probe, + .remove = ci_udc_otg_remove, + .ops = &ci_udc_gadget_ops, + .priv_auto =sizeof (struct ci_udc_priv_data ), +}; + +#endif /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */
Signature · 1 line
2.43.0
Re: [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET
Quoted 21 lines · On Tue, Dec 16, 2025 at 02:38:36PM +0800, [email protected] wrote:
From: Sherry Sun <[email protected]>
Convert the
ci_udcdriver to driver model by using the uclassUCLASS_USB_GADGET_GENERIC. The clk and power of USB controller and USB PHY both are initialized by parsing the device tree nodes.If
CONFIG_DM_USB_GADGETis defined, we use theci_udcdriver in DM way, if it does not defined, we can useci_udcdriver in its original Non-DM way.Signed-off-by Sherry Sun <[email protected]>Signed-off-by Alice Guo <[email protected]>Reviewed-by Ye Li <[email protected]>--- drivers/usb/gadget/ci_udc.c | 352 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 348 insertions(+), 4 deletions(-)drivers/usb/gadget/ci_udc.c +0
-0
...
drivers/usb/gadget/ci_udc.c int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) · line 1385
Quoted 9 lines
drivers/usb/gadget/ci_udc.c +9
-0+static int ci_udc_otg_probe (struct udevice *dev) +{ +struct ci_udc_priv_data *priv =dev_get_priv (dev); +struct usb_ehci *ehci; +int ret; + + ehci = (struct usb_ehci *)devfdt_get_addr (&priv->otgdev); + +pinctrl_select_state (&priv->otgdev,"default" );
I think device core would take care of pinctrl and set it to "default" state before probing the driver if possible, is this call to pinctrl_select_state really necessary? See device_probe() in drivers/core/device.c.
Regards,
Yao Zi
Re: [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET
In reply to [email protected]Quoted 10 lines · On Tue, Dec 16, 2025 at 02:38:36PM +0800, [email protected] wrote:
From: Sherry Sun <[email protected]>
Convert the
ci_udcdriver to driver model by using the uclassUCLASS_USB_GADGET_GENERIC. The clk and power of USB controller and USB PHY both are initialized by parsing the device tree nodes.If
CONFIG_DM_USB_GADGETis defined, we use theci_udcdriver in DM way, if it does not defined, we can useci_udcdriver in its original Non-DM way.
Quoted 6 lines
Signed-off-by Sherry Sun <[email protected]>Signed-off-by Alice Guo <[email protected]>Reviewed-by Ye Li <[email protected]>--- drivers/usb/gadget/ci_udc.c | 352 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 348 insertions(+), 4 deletions(-)
Good to get this converted. However, and this addresses some of the questions in the Kconfig patch (which should be part of this patch too), the end result should be supporting:
- Full U-Boot is DM only.
- SPL works with SPL_DM and (SPL_CI_UDC && SPL_DM).
- SPL works with SPL_CI_UDC and !SPL_DM.
This does mean adding a new symbol, for SPL, and migrating existing configs to SPL_CI_UDC. It would also be real nice to know if all of the imx6 and imx7 platforms that don't use SPL_DM could use SPL_DM, so we could drop that last case I mentioned above.
Signature · 1 line
Tom
Re: [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET
In reply to [email protected]Quoted 40 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Sherry Sun <[email protected]>
Convert the
ci_udcdriver to driver model by using the uclassUCLASS_USB_GADGET_GENERIC. The clk and power of USB controller and USB PHY both are initialized by parsing the device tree nodes.If
CONFIG_DM_USB_GADGETis defined, we use theci_udcdriver in DM way, if it does not defined, we can useci_udcdriver in its original Non-DM way.Signed-off-by Sherry Sun <[email protected]>Signed-off-by Alice Guo <[email protected]>Reviewed-by Ye Li <[email protected]>--- drivers/usb/gadget/ci_udc.c | 352 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 348 insertions(+), 4 deletions(-)drivers/usb/gadget/ci_udc.c +8
-0@@ -7,9 +7,17 @@* [email protected], 27-Jan-01. */ +#include <asm/arch/sys_proto.h> +#include <asm/arch/clock.h> +#include <asm/mach-imx/regs-usbphy.h> +#include <clk.h> #include <command.h> #include <config.h> #include <cpu_func.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <dm/pinctrl.h> +#include <power-domain.h> #include <net.h> #include <malloc.h> #include <wait_bit.h>
drivers/usb/gadget/ci_udc.c line 37
Quoted 8 lines
drivers/usb/gadget/ci_udc.c +2
-0@@ -22,6 +30,8 @@#include <linux/types.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> +#include <linux/usb/otg.h> +#include <usb/ehci-ci.h> #include <usb/ci_udc.h> #include "../host/ehci.h" #include "ci_udc.h"
Can we reduce the amount of headers included by this driver ?
[...]
Quoted 1 line
+#if
defined(CONFIG_MX6)
Can we somehow reduce the ifdeffery ? Use if (IS_ENABLED(...)) for example ?
[...]
PATCH 5/7 usb: Kconfig: imply DM_USB_GADGET
In reply to [email protected]From: Sherry Sun <[email protected]>
Since the ci_udc driver has been converted to DM driver, the CONFIG_DM_USB_GADGET should also be selected when CONFIG_CI_UDC is enabled, then we can use DM ci_udc driver.
--- drivers/usb/gadget/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/Kconfig +1 -1
@@ -151,8 +151,8 @@ config USB_GADGET_OS_DESCRIPTORS config CI_UDC bool "ChipIdea device controller" - depends on !DM_USB_GADGET select USB_GADGET_DUALSPEED + imply DM_USB_GADGET help Say Y here to enable device controller functionality of the ChipIdea driver.
Signature · 1 line
2.43.0
Re: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
Hi Alice,
Quoted 6 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Sherry Sun <[email protected]>
Since the
ci_udcdriver has been converted to DM driver, theCONFIG_DM_USB_GADGETshould also be selected whenCONFIG_CI_UDCis enabled, then we can use DMci_udcdriver.
Is DM_USB_GADGET *required* for CI_UDC to work? "imply" allows to have DM_USB_GADGET=y AND CI_UDC=n, which is probably not what you want. You probably simply want "depends on DM_USB_GADGET"
Quoted 3 lines
Signed-off-by Sherry Sun <[email protected]>Signed-off-by Alice Guo <[email protected]>Reviewed-by Ye Li <[email protected]>
Please do not provide Reviewed-by on the first version of a patch, Reviewed-by, Acked-by, Tested-by, etc.... should be given publicly on the mailing list. We don't know if Ye Li actually reviewed it or if you unilaterally decided they reviewed it. We don't know if we can trust it... which we shouldn't have to figure out.
Cheers,
Quentin
Re: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
Quoted 5 lines · Quentin Schulz
Hi Alice,
Quoted 2 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Sherry Sun <[email protected]>
Quoted 8 lines
Quoted 4 lines
Since the
ci_udcdriver has been converted to DM driver, theCONFIG_DM_USB_GADGETshould also be selected whenCONFIG_CI_UDCis enabled, then we can use DMci_udcdriver.Is
DM_USB_GADGET*required* forCI_UDCto work? "imply" allows to have DM_USB_GADGET=y AND CI_UDC=n, which is probably not what you want. You probably simply want "depends onDM_USB_GADGET"
And if DM_USB_GADGET is required for CI_UDC to work after PATCH 4 which does the convert, this patch should probably be merged with PATCH 4, or we will have unfunctional commits, affecting bisectibility.
Quoted 4 lines
Quoted 3 lines
Signed-off-by Sherry Sun <[email protected]>Signed-off-by Alice Guo <[email protected]>Reviewed-by Ye Li <[email protected]>
Quoted 8 lines
Please do not provide Reviewed-by on the first version of a patch, Reviewed-by, Acked-by, Tested-by, etc.... should be given publicly on the mailing list. We don't know if Ye Li actually reviewed it or if you unilaterally decided they reviewed it. We don't know if we can trust it... which we shouldn't have to figure out.
Cheers,
Quentin
Best regards,
Yao Zi
回复: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
In reply to Quentin SchulzQuoted 21 lines
-----邮件原件-----
发件人: Quentin Schulz <[email protected]>
发送时间: 2025年12月16日 17:50
收件人: Alice Guo (OSS) <[email protected]>; dl-uboot-imx <[email protected]>; [email protected]
抄送: Stefano Babic <[email protected]>; Fabio Estevam <[email protected]>; Tom Rini <[email protected]>; Marek Vasut <[email protected]>; Marek Vasut <[email protected]>; Ye Li <[email protected]>; [email protected]; Peng Fan <[email protected]>; Mattijs Korpershoek <[email protected]>; Lukasz Majewski <[email protected]>; Sherry Sun <[email protected]>; Kever Yang <[email protected]>; Jonas Karlman <[email protected]>; George Chan <[email protected]>; Simon Glass <[email protected]>; David Zang <[email protected]>; Alice Guo <[email protected]>
主题: Re: [PATCH v1 5/7] usb:Kconfig: implyDM_USB_GADGETHi Alice,
Quoted 2 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Sherry Sun <[email protected]>
Quoted 8 lines
Quoted 4 lines
Since the
ci_udcdriver has been converted to DM driver, theCONFIG_DM_USB_GADGETshould also be selected whenCONFIG_CI_UDCis enabled, then we can use DMci_udcdriver.Is
DM_USB_GADGET*required* forCI_UDCto work? "imply" allows to have DM_USB_GADGET=y AND CI_UDC=n, which is probably not what you want. You probably simply want "depends onDM_USB_GADGET"
There are 2 implementations supported in drivers/usb/gadget/ci_udc.c: a non-DM path and a DM-based path. The current commit log wording might be ambiguous.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Sherry Sun <[email protected]>Signed-off-by Alice Guo <[email protected]>Reviewed-by Ye Li <[email protected]>Please do not provide Reviewed-by on the first version of a patch, Reviewed-by, Acked-by, Tested-by, etc.... should be given publicly on the mailing list. We don't know if Ye Li actually reviewed it or if you unilaterally decided they reviewed it. We don't know if we can trust it... which we shouldn't have to figure out.
The Reviewed-by tag was added during our internal review process. I will remove it in the next version.
Best Regards,
Alice Guo
Re: 回复: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
Quoted 26 lines · Alice Guo (OSS)
Quoted 26 lines
-----邮件原件-----
发件人: Quentin Schulz <[email protected]>
发送时间: 2025年12月16日 17:50
收件人: Alice Guo (OSS) <[email protected]>; dl-uboot-imx <[email protected]>; [email protected]
抄送: Stefano Babic <[email protected]>; Fabio Estevam <[email protected]>; Tom Rini <[email protected]>; Marek Vasut <[email protected]>; Marek Vasut <[email protected]>; Ye Li <[email protected]>; [email protected]; Peng Fan <[email protected]>; Mattijs Korpershoek <[email protected]>; Lukasz Majewski <[email protected]>; Sherry Sun <[email protected]>; Kever Yang <[email protected]>; Jonas Karlman <[email protected]>; George Chan <[email protected]>; Simon Glass <[email protected]>; David Zang <[email protected]>; Alice Guo <[email protected]>
主题: Re: [PATCH v1 5/7] usb:Kconfig: implyDM_USB_GADGETHi Alice,
Quoted 6 lines · On 12/16/25 7:38 AM, [email protected] wrote:
From: Sherry Sun <[email protected]>
Since the
ci_udcdriver has been converted to DM driver, theCONFIG_DM_USB_GADGETshould also be selected whenCONFIG_CI_UDCis enabled, then we can use DMci_udcdriver.
Quoted 5 lines
Quoted 3 lines
Is
DM_USB_GADGET*required* forCI_UDCto work? "imply" allows to have DM_USB_GADGET=y AND CI_UDC=n, which is probably not what you want. You probably simply want "depends onDM_USB_GADGET"There are 2 implementations supported in
drivers/usb/gadget/ci_udc.c: a non-DM path and a DM-based path. The current commit log wording might be ambiguous.
OK. But the key here is that we shouldn't keep code around for the case of both non-DM and full U-Boot. It's valid to have non-DM and xPL, or DM and xPL or DM and full U-Boot. We just need to be clear and sure that we're doing this in both code and commit message.
Signature · 1 line
Tom
PATCH 6/7 usb: gadget: ci_udc: Add i.MX8ULP support
In reply to [email protected]From: Alice Guo <[email protected]>
Replace fdtdec_get_addr() with fdtdec_get_addr_size_auto_noparent() to properly handle device tree address translation with different #address-cells and #size-cells values.
Add i.MX8ULP platform support in ci_udc_otg_phy_mode() function to ensure correct PHY base address is used.
--- drivers/usb/gadget/ci_udc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/usb/gadget/ci_udc.c +8 -6
@@ -1213,7 +1213,8 @@ static int ci_udc_phy_setup(struct udevice *dev, struct ci_udc_priv_data *priv)return -EINVAL ; } - addr = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, priv->phy_off,"reg" ); + addr = (void __iomem *)fdtdec_get_addr_size_auto_noparent (gd->fdt_blob, priv->phy_off, +"reg" ,0 ,NULL , false);if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE ) addr =NULL ;
@@ -1223,7 +1224,8 @@ static int ci_udc_phy_setup(struct udevice *dev, struct ci_udc_priv_data *priv)if (misc_off <0 )return -EINVAL ; - addr = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, misc_off,"reg" ); + addr = (void __iomem *)fdtdec_get_addr_size_auto_noparent (gd->fdt_blob, misc_off, +"reg" ,0 ,NULL , false);if ((fdt_addr_t )addr ==FDT_ADDR_T_NONE )return -EINVAL ;
@@ -1326,10 +1328,10 @@ static int ci_udc_otg_phy_mode(struct udevice *dev)void *__iomem phy_base = (void *__iomem )devfdt_get_addr (&priv->otgdev);u32 val; -if (is_mx6 () ||is_mx7ulp () ||is_imx8 ()) { - phy_base = (void __iomem *)fdtdec_get_addr (gd->fdt_blob, - priv->phy_off, -"reg" ); +if (is_mx6 () ||is_mx7ulp () ||is_imx8 () ||is_imx8ulp ()) { + phy_base = (void __iomem *)fdtdec_get_addr_size_auto_noparent (gd->fdt_blob, + priv->phy_off,"reg" , +0 ,NULL , false);if ((fdt_addr_t )phy_base ==FDT_ADDR_T_NONE )return -EINVAL ;
Signature · 1 line
2.43.0
PATCH 7/7 imx8ulp_evk: Enable USB controller at 0x29920000 in device 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 device mode, allowing the board to operate as a USB mass storage gadget.
--- arch/arm/dts/imx8ulp-evk-u-boot.dtsi | 17 +++++++++++++++++ configs/imx8ulp_evk_defconfig | 7 +++++++ 2 files changed, 24 insertions(+)
arch/arm/dts/imx8ulp-evk-u-boot.dtsi +17 -0
@@ -12,6 +12,19 @@ status = "okay"; bootph-all; }; + + aliases { + usb_gadget1 = &usbg2; + usb1 = &usbotg2; + }; + + usbg2: usbg2 { + compatible = "fsl,imx27-usb-gadget"; + dr_mode = "peripheral"; + chipidea,usb = <&usbotg2>; + status = "okay"; + bootph-all; + }; }; &soc {
@@ -38,6 +51,10 @@ compatible = "fsl,imx8ulp-usb", "fsl,imx7ulp-usb", "fsl,imx27-usb"; }; +&pinctrl_usb2 { + bootph-all; +}; + &iomuxc1 { bootph-all; };
configs/imx8ulp_evk_defconfig +7 -0
@@ -55,6 +55,7 @@ CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y CONFIG_CMD_READ=y CONFIG_CMD_USB=y +CONFIG_CMD_USB_MASS_STORAGE=y CONFIG_CMD_CACHE=y CONFIG_CMD_REGULATOR=y CONFIG_CMD_EXT4_WRITE=y
@@ -95,4 +96,10 @@ CONFIG_DM_SPI=y CONFIG_NXP_FSPI=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y +CONFIG_USB_GADGET=y +CONFIG_USB_GADGET_MANUFACTURER="FSL" +CONFIG_USB_GADGET_VENDOR_NUM=0x0525 +CONFIG_USB_GADGET_PRODUCT_NUM=0xa4a5 +CONFIG_CI_UDC=y +CONFIG_USB_GADGET_DOWNLOAD=y CONFIG_ULP_WATCHDOG=y
Signature · 1 line
2.43.0