* [PATCH v1 1/7] usb: ehci-mx6: Move USB PHY register definitions to common header
2025-12-16 6:38 [PATCH 0/7] Enable USB in device mode on i.MX8ULP EVK alice.guo
@ 2025-12-16 6:38 ` alice.guo
2025-12-16 6:38 ` [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms alice.guo
` (5 subsequent siblings)
6 siblings, 0 replies; 21+ messages in thread
From: alice.guo @ 2025-12-16 6:38 UTC (permalink / raw)
To: NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
From: Alice Guo <alice.guo@nxp.com>
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.
Signed-off-by: Alice Guo <alice.guo@nxp.com>
---
arch/arm/include/asm/mach-imx/regs-usbphy.h | 3 +++
drivers/usb/host/ehci-mx6.c | 15 +--------------
2 files changed, 4 insertions(+), 14 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/regs-usbphy.h b/arch/arm/include/asm/mach-imx/regs-usbphy.h
index 2b18ec20f3f..543c825f9c3 100644
--- a/arch/arm/include/asm/mach-imx/regs-usbphy.h
+++ b/arch/arm/include/asm/mach-imx/regs-usbphy.h
@@ -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__ */
diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index 8f01b29c74e..cfaf49d67f0 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -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 */
--
2.43.0
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
2025-12-16 6:38 [PATCH 0/7] Enable USB in device mode on i.MX8ULP EVK alice.guo
2025-12-16 6:38 ` [PATCH v1 1/7] usb: ehci-mx6: Move USB PHY register definitions to common header alice.guo
@ 2025-12-16 6:38 ` alice.guo
2025-12-16 11:15 ` Marek Vasut
2025-12-16 6:38 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function alice.guo
` (4 subsequent siblings)
6 siblings, 1 reply; 21+ messages in thread
From: alice.guo @ 2025-12-16 6:38 UTC (permalink / raw)
To: NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
From: Alice Guo <alice.guo@nxp.com>
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 <alice.guo@nxp.com>
---
drivers/usb/host/ehci-mx6.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index cfaf49d67f0..03ff4ce10d5 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
2025-12-16 6:38 ` [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms alice.guo
@ 2025-12-16 11:15 ` Marek Vasut
2025-12-25 10:41 ` 回复: " Alice Guo (OSS)
0 siblings, 1 reply; 21+ messages in thread
From: Marek Vasut @ 2025-12-16 11:15 UTC (permalink / raw)
To: alice.guo, NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> From: Alice Guo <alice.guo@nxp.com>
>
> 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 <alice.guo@nxp.com>
> ---
> drivers/usb/host/ehci-mx6.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
> index cfaf49d67f0..03ff4ce10d5 100644
> --- a/drivers/usb/host/ehci-mx6.c
> +++ b/drivers/usb/host/ehci-mx6.c
> @@ -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 ?
^ permalink raw reply [flat|nested] 21+ messages in thread* 回复: [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
2025-12-16 11:15 ` Marek Vasut
@ 2025-12-25 10:41 ` Alice Guo (OSS)
2025-12-25 20:56 ` Marek Vasut
0 siblings, 1 reply; 21+ messages in thread
From: Alice Guo (OSS) @ 2025-12-25 10:41 UTC (permalink / raw)
To: Marek Vasut, Alice Guo (OSS), dl-uboot-imx, u-boot@lists.denx.de
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Ye Li,
tharvey@gateworks.com, Peng Fan, Mattijs Korpershoek,
Lukasz Majewski, Sherry Sun, Kever Yang, Jonas Karlman,
Quentin Schulz, George Chan, Simon Glass, David Zang, Alice Guo
> -----邮件原件-----
> 发件人: Marek Vasut <marek.vasut@mailbox.org>
> 发送时间: 2025年12月16日 19:16
> 收件人: Alice Guo (OSS) <alice.guo@oss.nxp.com>; dl-uboot-imx
> <uboot-imx@nxp.com>; u-boot@lists.denx.de
> 抄送: Stefano Babic <sbabic@nabladev.com>; Fabio Estevam
> <festevam@gmail.com>; Tom Rini <trini@konsulko.com>; Marek Vasut
> <marex@denx.de>; Marek Vasut <marek.vasut@mailbox.org>; Ye Li
> <ye.li@nxp.com>; tharvey@gateworks.com; Peng Fan <peng.fan@nxp.com>;
> Mattijs Korpershoek <mkorpershoek@kernel.org>; Lukasz Majewski
> <lukma@denx.de>; Sherry Sun <sherry.sun@nxp.com>; Kever Yang
> <kever.yang@rock-chips.com>; Jonas Karlman <jonas@kwiboo.se>; Quentin
> Schulz <quentin.schulz@cherry.de>; George Chan <gchan9527@gmail.com>;
> Simon Glass <sjg@chromium.org>; David Zang <davidzangcs@gmail.com>; Alice
> Guo <alice.guo@nxp.com>
> 主题: Re: [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for
> i.MX7/8M/9/7ULP/8 and 8ULP platforms
>
> On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> > From: Alice Guo <alice.guo@nxp.com>
> >
> > 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 <alice.guo@nxp.com>
> > ---
> > drivers/usb/host/ehci-mx6.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
> > index cfaf49d67f0..03ff4ce10d5 100644
> > --- a/drivers/usb/host/ehci-mx6.c
> > +++ b/drivers/usb/host/ehci-mx6.c
> > @@ -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 ?
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
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: 回复: [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms
2025-12-25 10:41 ` 回复: " Alice Guo (OSS)
@ 2025-12-25 20:56 ` Marek Vasut
0 siblings, 0 replies; 21+ messages in thread
From: Marek Vasut @ 2025-12-25 20:56 UTC (permalink / raw)
To: Alice Guo (OSS), dl-uboot-imx, u-boot@lists.denx.de
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Ye Li,
tharvey@gateworks.com, Peng Fan, Mattijs Korpershoek,
Lukasz Majewski, Sherry Sun, Kever Yang, Jonas Karlman,
Quentin Schulz, George Chan, Simon Glass, David Zang, Alice Guo
On 12/25/25 11:41 AM, Alice Guo (OSS) wrote:
Hello Alice,
>>> diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
>>> index cfaf49d67f0..03ff4ce10d5 100644
>>> --- a/drivers/usb/host/ehci-mx6.c
>>> +++ b/drivers/usb/host/ehci-mx6.c
>>> @@ -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 ?
>
> 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 ?
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function
2025-12-16 6:38 [PATCH 0/7] Enable USB in device mode on i.MX8ULP EVK alice.guo
2025-12-16 6:38 ` [PATCH v1 1/7] usb: ehci-mx6: Move USB PHY register definitions to common header alice.guo
2025-12-16 6:38 ` [PATCH v1 2/7] usb: ehci-mx6: Fix usb_oc_config() for i.MX7/8M/9/7ULP/8 and 8ULP platforms alice.guo
@ 2025-12-16 6:38 ` alice.guo
2025-12-16 9:52 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable functionr Yao Zi
2025-12-16 11:17 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function Marek Vasut
2025-12-16 6:38 ` [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET alice.guo
` (3 subsequent siblings)
6 siblings, 2 replies; 21+ messages in thread
From: alice.guo @ 2025-12-16 6:38 UTC (permalink / raw)
To: NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
From: Alice Guo <alice.guo@nxp.com>
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.
Signed-off-by: Alice Guo <alice.guo@nxp.com>
---
drivers/usb/host/ehci-mx6.c | 73 ++++++++++++++++++++++++++++++++++++++++++++-
include/usb/ci_udc.h | 9 ++++++
2 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index 03ff4ce10d5..52f14e6eca0 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -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)
/**
diff --git a/include/usb/ci_udc.h b/include/usb/ci_udc.h
index 9f15dbabe53..ccef4daf741 100644
--- a/include/usb/ci_udc.h
+++ b/include/usb/ci_udc.h
@@ -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__ */
--
2.43.0
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable functionr
2025-12-16 6:38 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function alice.guo
@ 2025-12-16 9:52 ` Yao Zi
2025-12-16 11:17 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function Marek Vasut
1 sibling, 0 replies; 21+ messages in thread
From: Yao Zi @ 2025-12-16 9:52 UTC (permalink / raw)
To: alice.guo, NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
On Tue, Dec 16, 2025 at 02:38:35PM +0800, alice.guo@oss.nxp.com wrote:
> From: Alice Guo <alice.guo@nxp.com>
>
> 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.
>
> Signed-off-by: Alice Guo <alice.guo@nxp.com>
> ---
> drivers/usb/host/ehci-mx6.c | 73 ++++++++++++++++++++++++++++++++++++++++++++-
> include/usb/ci_udc.h | 9 ++++++
> 2 files changed, 81 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
> index 03ff4ce10d5..52f14e6eca0 100644
> --- a/drivers/usb/host/ehci-mx6.c
> +++ b/drivers/usb/host/ehci-mx6.c
> @@ -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);
> + }
We have readX_poll_timeout() defined in include/linux/iopoll.h, I think
it could simplify the code here.
> + 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);
> +}
Regards,
Yao Zi
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function
2025-12-16 6:38 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function alice.guo
2025-12-16 9:52 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable functionr Yao Zi
@ 2025-12-16 11:17 ` Marek Vasut
2025-12-25 10:49 ` 回复: " Alice Guo (OSS)
1 sibling, 1 reply; 21+ messages in thread
From: Marek Vasut @ 2025-12-16 11:17 UTC (permalink / raw)
To: alice.guo, NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> From: Alice Guo <alice.guo@nxp.com>
>
> 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.
>
> Signed-off-by: Alice Guo <alice.guo@nxp.com>
> ---
> drivers/usb/host/ehci-mx6.c | 73 ++++++++++++++++++++++++++++++++++++++++++++-
> include/usb/ci_udc.h | 9 ++++++
> 2 files changed, 81 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
> index 03ff4ce10d5..52f14e6eca0 100644
> --- a/drivers/usb/host/ehci-mx6.c
> +++ b/drivers/usb/host/ehci-mx6.c
> @@ -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)
Can we avoid more ifdeffery ?
> +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);
> + }
readl_poll*() instead of hand-rolled polling.
> + 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.
> + &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
> }
[...]
^ permalink raw reply [flat|nested] 21+ messages in thread* 回复: [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function
2025-12-16 11:17 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function Marek Vasut
@ 2025-12-25 10:49 ` Alice Guo (OSS)
0 siblings, 0 replies; 21+ messages in thread
From: Alice Guo (OSS) @ 2025-12-25 10:49 UTC (permalink / raw)
To: Marek Vasut, Alice Guo (OSS), dl-uboot-imx, u-boot@lists.denx.de
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Ye Li,
tharvey@gateworks.com, Peng Fan, Mattijs Korpershoek,
Lukasz Majewski, Sherry Sun, Kever Yang, Jonas Karlman,
Quentin Schulz, George Chan, Simon Glass, David Zang, Alice Guo
> -----邮件原件-----
> 发件人: Marek Vasut <marek.vasut@mailbox.org>
> 发送时间: 2025年12月16日 19:18
> 收件人: Alice Guo (OSS) <alice.guo@oss.nxp.com>; dl-uboot-imx
> <uboot-imx@nxp.com>; u-boot@lists.denx.de
> 抄送: Stefano Babic <sbabic@nabladev.com>; Fabio Estevam
> <festevam@gmail.com>; Tom Rini <trini@konsulko.com>; Marek Vasut
> <marex@denx.de>; Marek Vasut <marek.vasut@mailbox.org>; Ye Li
> <ye.li@nxp.com>; tharvey@gateworks.com; Peng Fan <peng.fan@nxp.com>;
> Mattijs Korpershoek <mkorpershoek@kernel.org>; Lukasz Majewski
> <lukma@denx.de>; Sherry Sun <sherry.sun@nxp.com>; Kever Yang
> <kever.yang@rock-chips.com>; Jonas Karlman <jonas@kwiboo.se>; Quentin
> Schulz <quentin.schulz@cherry.de>; George Chan <gchan9527@gmail.com>;
> Simon Glass <sjg@chromium.org>; David Zang <davidzangcs@gmail.com>; Alice
> Guo <alice.guo@nxp.com>
> 主题: Re: [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable
> function
>
> On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> > From: Alice Guo <alice.guo@nxp.com>
> >
> > 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.
> >
> > Signed-off-by: Alice Guo <alice.guo@nxp.com>
> > ---
> > drivers/usb/host/ehci-mx6.c | 73
> ++++++++++++++++++++++++++++++++++++++++++++-
> > include/usb/ci_udc.h | 9 ++++++
> > 2 files changed, 81 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
> > index 03ff4ce10d5..52f14e6eca0 100644
> > --- a/drivers/usb/host/ehci-mx6.c
> > +++ b/drivers/usb/host/ehci-mx6.c
> > @@ -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)
>
> Can we avoid more ifdeffery ?
Thanks for your feedback. I will remove it in the next version.
Best Regards,
Alice Guo
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET
2025-12-16 6:38 [PATCH 0/7] Enable USB in device mode on i.MX8ULP EVK alice.guo
` (2 preceding siblings ...)
2025-12-16 6:38 ` [PATCH v1 3/7] usb: ehci-mx6: Extract PHY initialization into reusable function alice.guo
@ 2025-12-16 6:38 ` alice.guo
2025-12-16 10:00 ` Yao Zi
` (2 more replies)
2025-12-16 6:38 ` [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET alice.guo
` (2 subsequent siblings)
6 siblings, 3 replies; 21+ messages in thread
From: alice.guo @ 2025-12-16 6:38 UTC (permalink / raw)
To: NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
From: Sherry Sun <sherry.sun@nxp.com>
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.
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
Signed-off-by: Alice Guo <alice.guo@nxp.com>
Reviewed-by: Ye Li <ye.li@nxp.com>
---
drivers/usb/gadget/ci_udc.c | 352 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 348 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
index 4bff75da759..154a3ab7f22 100644
--- a/drivers/usb/gadget/ci_udc.c
+++ b/drivers/usb/gadget/ci_udc.c
@@ -7,9 +7,17 @@
* Murray.Jensen@cmst.csiro.au, 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) */
--
2.43.0
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET
2025-12-16 6:38 ` [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET alice.guo
@ 2025-12-16 10:00 ` Yao Zi
2025-12-16 11:19 ` Marek Vasut
2025-12-16 14:07 ` Tom Rini
2 siblings, 0 replies; 21+ messages in thread
From: Yao Zi @ 2025-12-16 10:00 UTC (permalink / raw)
To: alice.guo, NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
On Tue, Dec 16, 2025 at 02:38:36PM +0800, alice.guo@oss.nxp.com wrote:
> From: Sherry Sun <sherry.sun@nxp.com>
>
> 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.
>
> Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> Signed-off-by: Alice Guo <alice.guo@nxp.com>
> Reviewed-by: Ye Li <ye.li@nxp.com>
> ---
> drivers/usb/gadget/ci_udc.c | 352 +++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 348 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
> index 4bff75da759..154a3ab7f22 100644
> --- a/drivers/usb/gadget/ci_udc.c
> +++ b/drivers/usb/gadget/ci_udc.c
...
> +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
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET
2025-12-16 6:38 ` [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET alice.guo
2025-12-16 10:00 ` Yao Zi
@ 2025-12-16 11:19 ` Marek Vasut
2025-12-16 14:07 ` Tom Rini
2 siblings, 0 replies; 21+ messages in thread
From: Marek Vasut @ 2025-12-16 11:19 UTC (permalink / raw)
To: alice.guo, NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> From: Sherry Sun <sherry.sun@nxp.com>
>
> 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.
>
> Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> Signed-off-by: Alice Guo <alice.guo@nxp.com>
> Reviewed-by: Ye Li <ye.li@nxp.com>
> ---
> drivers/usb/gadget/ci_udc.c | 352 +++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 348 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
> index 4bff75da759..154a3ab7f22 100644
> --- a/drivers/usb/gadget/ci_udc.c
> +++ b/drivers/usb/gadget/ci_udc.c
> @@ -7,9 +7,17 @@
> * Murray.Jensen@cmst.csiro.au, 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"
Can we reduce the amount of headers included by this driver ?
[...]
> +#if defined(CONFIG_MX6)
Can we somehow reduce the ifdeffery ? Use if (IS_ENABLED(...)) for example ?
[...]
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET
2025-12-16 6:38 ` [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET alice.guo
2025-12-16 10:00 ` Yao Zi
2025-12-16 11:19 ` Marek Vasut
@ 2025-12-16 14:07 ` Tom Rini
2 siblings, 0 replies; 21+ messages in thread
From: Tom Rini @ 2025-12-16 14:07 UTC (permalink / raw)
To: alice.guo
Cc: NXP i.MX U-Boot Team, u-boot, Stefano Babic, Fabio Estevam,
Marek Vasut, Marek Vasut, Ye Li, Tim Harvey, Peng Fan,
Mattijs Korpershoek, Lukasz Majewski, Sherry Sun, Kever Yang,
Jonas Karlman, Quentin Schulz, George Chan, Simon Glass,
David Zang, Alice Guo
[-- Attachment #1: Type: text/plain, Size: 1344 bytes --]
On Tue, Dec 16, 2025 at 02:38:36PM +0800, alice.guo@oss.nxp.com wrote:
> From: Sherry Sun <sherry.sun@nxp.com>
>
> 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.
>
> Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> Signed-off-by: Alice Guo <alice.guo@nxp.com>
> Reviewed-by: Ye Li <ye.li@nxp.com>
> ---
> 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.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
2025-12-16 6:38 [PATCH 0/7] Enable USB in device mode on i.MX8ULP EVK alice.guo
` (3 preceding siblings ...)
2025-12-16 6:38 ` [PATCH v1 4/7] usb: ci_udc: Convert driver to DM_USB_GADGET alice.guo
@ 2025-12-16 6:38 ` alice.guo
2025-12-16 9:49 ` Quentin Schulz
2025-12-16 6:38 ` [PATCH v1 6/7] usb: gadget: ci_udc: Add i.MX8ULP support alice.guo
2025-12-16 6:38 ` [PATCH v1 7/7] imx8ulp_evk: Enable USB controller at 0x29920000 in device mode alice.guo
6 siblings, 1 reply; 21+ messages in thread
From: alice.guo @ 2025-12-16 6:38 UTC (permalink / raw)
To: NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
From: Sherry Sun <sherry.sun@nxp.com>
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.
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
Signed-off-by: Alice Guo <alice.guo@nxp.com>
Reviewed-by: Ye Li <ye.li@nxp.com>
---
drivers/usb/gadget/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 7e08aeab904..f85bf3d66b2 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -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.
--
2.43.0
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
2025-12-16 6:38 ` [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET alice.guo
@ 2025-12-16 9:49 ` Quentin Schulz
2025-12-16 10:07 ` Yao Zi
2025-12-25 10:16 ` 回复: " Alice Guo (OSS)
0 siblings, 2 replies; 21+ messages in thread
From: Quentin Schulz @ 2025-12-16 9:49 UTC (permalink / raw)
To: alice.guo, NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, George Chan, Simon Glass,
David Zang, Alice Guo
Hi Alice,
On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> From: Sherry Sun <sherry.sun@nxp.com>
>
> 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.
>
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"
> Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> Signed-off-by: Alice Guo <alice.guo@nxp.com>
> Reviewed-by: Ye Li <ye.li@nxp.com>
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
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
2025-12-16 9:49 ` Quentin Schulz
@ 2025-12-16 10:07 ` Yao Zi
2025-12-25 10:16 ` 回复: " Alice Guo (OSS)
1 sibling, 0 replies; 21+ messages in thread
From: Yao Zi @ 2025-12-16 10:07 UTC (permalink / raw)
To: Quentin Schulz, alice.guo, NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, George Chan, Simon Glass,
David Zang, Alice Guo
On Tue, Dec 16, 2025 at 10:49:47AM +0100, Quentin Schulz wrote:
> Hi Alice,
>
> On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> > From: Sherry Sun <sherry.sun@nxp.com>
> >
> > 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.
> >
>
> 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"
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.
> > Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> > Signed-off-by: Alice Guo <alice.guo@nxp.com>
> > Reviewed-by: Ye Li <ye.li@nxp.com>
>
> 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
^ permalink raw reply [flat|nested] 21+ messages in thread
* 回复: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
2025-12-16 9:49 ` Quentin Schulz
2025-12-16 10:07 ` Yao Zi
@ 2025-12-25 10:16 ` Alice Guo (OSS)
2025-12-25 15:06 ` Tom Rini
1 sibling, 1 reply; 21+ messages in thread
From: Alice Guo (OSS) @ 2025-12-25 10:16 UTC (permalink / raw)
To: Quentin Schulz, Alice Guo (OSS), dl-uboot-imx,
u-boot@lists.denx.de
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, tharvey@gateworks.com, Peng Fan, Mattijs Korpershoek,
Lukasz Majewski, Sherry Sun, Kever Yang, Jonas Karlman,
George Chan, Simon Glass, David Zang, Alice Guo
> -----邮件原件-----
> 发件人: Quentin Schulz <quentin.schulz@cherry.de>
> 发送时间: 2025年12月16日 17:50
> 收件人: Alice Guo (OSS) <alice.guo@oss.nxp.com>; dl-uboot-imx
> <uboot-imx@nxp.com>; u-boot@lists.denx.de
> 抄送: Stefano Babic <sbabic@nabladev.com>; Fabio Estevam
> <festevam@gmail.com>; Tom Rini <trini@konsulko.com>; Marek Vasut
> <marex@denx.de>; Marek Vasut <marek.vasut@mailbox.org>; Ye Li
> <ye.li@nxp.com>; tharvey@gateworks.com; Peng Fan <peng.fan@nxp.com>;
> Mattijs Korpershoek <mkorpershoek@kernel.org>; Lukasz Majewski
> <lukma@denx.de>; Sherry Sun <sherry.sun@nxp.com>; Kever Yang
> <kever.yang@rock-chips.com>; Jonas Karlman <jonas@kwiboo.se>; George
> Chan <gchan9527@gmail.com>; Simon Glass <sjg@chromium.org>; David Zang
> <davidzangcs@gmail.com>; Alice Guo <alice.guo@nxp.com>
> 主题: Re: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
>
> Hi Alice,
>
> On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> > From: Sherry Sun <sherry.sun@nxp.com>
> >
> > 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.
> >
>
> 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"
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.
> > Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> > Signed-off-by: Alice Guo <alice.guo@nxp.com>
> > Reviewed-by: Ye Li <ye.li@nxp.com>
>
> 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
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: 回复: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
2025-12-25 10:16 ` 回复: " Alice Guo (OSS)
@ 2025-12-25 15:06 ` Tom Rini
0 siblings, 0 replies; 21+ messages in thread
From: Tom Rini @ 2025-12-25 15:06 UTC (permalink / raw)
To: Alice Guo (OSS)
Cc: Quentin Schulz, dl-uboot-imx, u-boot@lists.denx.de, Stefano Babic,
Fabio Estevam, Marek Vasut, Marek Vasut, Ye Li,
tharvey@gateworks.com, Peng Fan, Mattijs Korpershoek,
Lukasz Majewski, Sherry Sun, Kever Yang, Jonas Karlman,
George Chan, Simon Glass, David Zang, Alice Guo
[-- Attachment #1: Type: text/plain, Size: 1987 bytes --]
On Thu, Dec 25, 2025 at 10:16:29AM +0000, Alice Guo (OSS) wrote:
> > -----邮件原件-----
> > 发件人: Quentin Schulz <quentin.schulz@cherry.de>
> > 发送时间: 2025年12月16日 17:50
> > 收件人: Alice Guo (OSS) <alice.guo@oss.nxp.com>; dl-uboot-imx
> > <uboot-imx@nxp.com>; u-boot@lists.denx.de
> > 抄送: Stefano Babic <sbabic@nabladev.com>; Fabio Estevam
> > <festevam@gmail.com>; Tom Rini <trini@konsulko.com>; Marek Vasut
> > <marex@denx.de>; Marek Vasut <marek.vasut@mailbox.org>; Ye Li
> > <ye.li@nxp.com>; tharvey@gateworks.com; Peng Fan <peng.fan@nxp.com>;
> > Mattijs Korpershoek <mkorpershoek@kernel.org>; Lukasz Majewski
> > <lukma@denx.de>; Sherry Sun <sherry.sun@nxp.com>; Kever Yang
> > <kever.yang@rock-chips.com>; Jonas Karlman <jonas@kwiboo.se>; George
> > Chan <gchan9527@gmail.com>; Simon Glass <sjg@chromium.org>; David Zang
> > <davidzangcs@gmail.com>; Alice Guo <alice.guo@nxp.com>
> > 主题: Re: [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET
> >
> > Hi Alice,
> >
> > On 12/16/25 7:38 AM, alice.guo@oss.nxp.com wrote:
> > > From: Sherry Sun <sherry.sun@nxp.com>
> > >
> > > 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.
> > >
> >
> > 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"
>
> 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.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v1 6/7] usb: gadget: ci_udc: Add i.MX8ULP support
2025-12-16 6:38 [PATCH 0/7] Enable USB in device mode on i.MX8ULP EVK alice.guo
` (4 preceding siblings ...)
2025-12-16 6:38 ` [PATCH v1 5/7] usb: Kconfig: imply DM_USB_GADGET alice.guo
@ 2025-12-16 6:38 ` alice.guo
2025-12-16 6:38 ` [PATCH v1 7/7] imx8ulp_evk: Enable USB controller at 0x29920000 in device mode alice.guo
6 siblings, 0 replies; 21+ messages in thread
From: alice.guo @ 2025-12-16 6:38 UTC (permalink / raw)
To: NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
From: Alice Guo <alice.guo@nxp.com>
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.
Signed-off-by: Alice Guo <alice.guo@nxp.com>
---
drivers/usb/gadget/ci_udc.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
index 154a3ab7f22..98d6dd99055 100644
--- a/drivers/usb/gadget/ci_udc.c
+++ b/drivers/usb/gadget/ci_udc.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH v1 7/7] imx8ulp_evk: Enable USB controller at 0x29920000 in device mode
2025-12-16 6:38 [PATCH 0/7] Enable USB in device mode on i.MX8ULP EVK alice.guo
` (5 preceding siblings ...)
2025-12-16 6:38 ` [PATCH v1 6/7] usb: gadget: ci_udc: Add i.MX8ULP support alice.guo
@ 2025-12-16 6:38 ` alice.guo
6 siblings, 0 replies; 21+ messages in thread
From: alice.guo @ 2025-12-16 6:38 UTC (permalink / raw)
To: NXP i.MX U-Boot Team, u-boot
Cc: Stefano Babic, Fabio Estevam, Tom Rini, Marek Vasut, Marek Vasut,
Ye Li, Tim Harvey, Peng Fan, Mattijs Korpershoek, Lukasz Majewski,
Sherry Sun, Kever Yang, Jonas Karlman, Quentin Schulz,
George Chan, Simon Glass, David Zang, Alice Guo
From: Alice Guo <alice.guo@nxp.com>
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.
Signed-off-by: Alice Guo <alice.guo@nxp.com>
---
arch/arm/dts/imx8ulp-evk-u-boot.dtsi | 17 +++++++++++++++++
configs/imx8ulp_evk_defconfig | 7 +++++++
2 files changed, 24 insertions(+)
diff --git a/arch/arm/dts/imx8ulp-evk-u-boot.dtsi b/arch/arm/dts/imx8ulp-evk-u-boot.dtsi
index e35653edc29..e4f47bb1dcb 100644
--- a/arch/arm/dts/imx8ulp-evk-u-boot.dtsi
+++ b/arch/arm/dts/imx8ulp-evk-u-boot.dtsi
@@ -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;
};
diff --git a/configs/imx8ulp_evk_defconfig b/configs/imx8ulp_evk_defconfig
index 5fd73ce4ae9..52994e4f785 100644
--- a/configs/imx8ulp_evk_defconfig
+++ b/configs/imx8ulp_evk_defconfig
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 21+ messages in thread