* [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-11-22 19:53 ` [REGRESSION] " Francesco Dolcini
2026-10-23 11:15 ` [PATCH v9 2/9] usb: ehci-vf: take the controller index from the device tree Mehmet Fide
` (8 subsequent siblings)
9 siblings, 1 reply; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
fdtdec_get_alias_seq() and fdtdec_get_alias_highest_id() compare the
alias name with the stem by strncmp() over the length of the stem, so
every alias that starts with the stem counts. On a Colibri VF50 the
aliases usbphy0 and usbphy1 matched the "usb" stem, the two USB
controllers were given the sequence numbers 2 and 3, and ehci-vf
indexed its two-entry tables with them. The live tree disagrees: there
of_alias_scan() splits an alias into the stem and the number and
of_alias_get_id() compares the stem exactly.
Match an alias only when the stem is followed by its number, as the
live tree does. A test covers both lookups with the sandbox aliases,
where "test" is a prefix of testbus3 and of the testfdt aliases.
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- none, rebased on main
Changes in v8:
- none, rebased on main
Changes in v7:
- Reviewed-by from Simon
- rebased on main
Changes in v6:
- none
Changes in v5:
- new patch, from the review of the alias lookup in v4: the live and the
flat implementation disagreed on a stem that is a prefix of an alias
- the test calls fdtdec directly, which checkpatch warns about; the two
lookups under test have no livetree form
lib/fdtdec.c | 43 ++++++++++++++++++++++++++++++-------------
test/dm/fdtdec.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index d25535bf36c..5fe7e85a943 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -508,10 +508,29 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name,
return num_found;
}
+/**
+ * alias_seq_of() - get the number an alias gives a stem
+ *
+ * @name: Alias name, e.g. "serial2"
+ * @base: Stem to match, e.g. "serial"
+ * Return: the number that follows the stem, -1 if @name is not @base
+ * followed by a number (usbphy0 is not a "usb" alias)
+ */
+static int alias_seq_of(const char *name, const char *base)
+{
+ int base_len = strlen(base);
+ const char *num = name + base_len;
+
+ if (strncmp(name, base, base_len) || !*num ||
+ strspn(num, "0123456789") != strlen(num))
+ return -1;
+
+ return dectoul(num, NULL);
+}
+
int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
int *seqp)
{
- int base_len = strlen(base);
const char *find_name;
int find_namelen;
int prop_offset;
@@ -531,8 +550,11 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
debug(" - %s, %s\n", name, prop);
- if (len < find_namelen || *prop != '/' || prop[len - 1] ||
- strncmp(name, base, base_len))
+ if (len < find_namelen || *prop != '/' || prop[len - 1])
+ continue;
+
+ val = alias_seq_of(name, base);
+ if (val < 0)
continue;
slash = strrchr(prop, '/');
@@ -549,12 +571,9 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
continue;
}
- val = trailing_strtol(name);
- if (val != -1) {
- *seqp = val;
- debug("Found seq %d\n", *seqp);
- return 0;
- }
+ *seqp = val;
+ debug("Found seq %d\n", *seqp);
+ return 0;
}
debug("Not found\n");
@@ -563,7 +582,6 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
int fdtdec_get_alias_highest_id(const void *blob, const char *base)
{
- int base_len = strlen(base);
int prop_offset;
int aliases;
int max = -1;
@@ -580,11 +598,10 @@ int fdtdec_get_alias_highest_id(const void *blob, const char *base)
prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
debug(" - %s, %s\n", name, prop);
- if (*prop != '/' || prop[len - 1] ||
- strncmp(name, base, base_len))
+ if (*prop != '/' || prop[len - 1])
continue;
- val = trailing_strtol(name);
+ val = alias_seq_of(name, base);
if (val > max) {
debug("Found seq %d\n", val);
max = val;
diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c
index 495f57234a4..075f7e5471f 100644
--- a/test/dm/fdtdec.c
+++ b/test/dm/fdtdec.c
@@ -8,6 +8,7 @@
#include <dm/of_extra.h>
#include <dm/test.h>
#include <fdt_support.h>
+#include <fdtdec.h>
#include <mapmem.h>
#include <smbios.h>
#include <test/ut.h>
@@ -188,3 +189,37 @@ static int dm_test_fdt_chosen_smbios(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_fdt_chosen_smbios, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* test fdtdec_get_alias_seq() and fdtdec_get_alias_highest_id() */
+static int dm_test_fdtdec_alias_seq(struct unit_test_state *uts)
+{
+ const void *blob = gd->fdt_blob;
+ int seq;
+
+ ut_assertok(fdtdec_get_alias_seq(blob, "testfdt",
+ fdt_path_offset(blob,
+ "/some-bus/c-test@1"),
+ &seq));
+ ut_asserteq(12, seq);
+ ut_assertok(fdtdec_get_alias_seq(blob, "testbus",
+ fdt_path_offset(blob, "/some-bus"),
+ &seq));
+ ut_asserteq(3, seq);
+
+ /* the stem must be followed by the number: testbus3 is no "test" */
+ ut_asserteq(-ENOENT,
+ fdtdec_get_alias_seq(blob, "test",
+ fdt_path_offset(blob, "/some-bus"),
+ &seq));
+ ut_asserteq(-ENOENT,
+ fdtdec_get_alias_seq(blob, "spi",
+ fdt_path_offset(blob, "/i2c@0"),
+ &seq));
+
+ ut_asserteq(12, fdtdec_get_alias_highest_id(blob, "testfdt"));
+ ut_asserteq(3, fdtdec_get_alias_highest_id(blob, "testbus"));
+ ut_asserteq(-1, fdtdec_get_alias_highest_id(blob, "test"));
+
+ return 0;
+}
+DM_TEST(dm_test_fdtdec_alias_seq, UTF_SCAN_PDATA | UTF_SCAN_FDT);
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [REGRESSION] [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it
2026-10-23 11:15 ` [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it Mehmet Fide
@ 2026-11-22 19:53 ` Francesco Dolcini
2026-11-22 20:51 ` [PATCH] usb: ehci-mx6: look up the port number with the usbphy alias Mehmet Fide
2026-11-22 20:52 ` [REGRESSION] [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it Mehmet Fide
0 siblings, 2 replies; 20+ messages in thread
From: Francesco Dolcini @ 2026-11-22 19:53 UTC (permalink / raw)
To: Mehmet Fide, Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
Hello Mehmet, Marek,
On Fri, Oct 23, 2026 at 01:15:51PM +0200, Mehmet Fide wrote:
> From: Mehmet Fide <mehmet.fide@screeningeagle.com>
>
> fdtdec_get_alias_seq() and fdtdec_get_alias_highest_id() compare the
> alias name with the stem by strncmp() over the length of the stem, so
> every alias that starts with the stem counts. On a Colibri VF50 the
> aliases usbphy0 and usbphy1 matched the "usb" stem, the two USB
> controllers were given the sequence numbers 2 and 3, and ehci-vf
> indexed its two-entry tables with them. The live tree disagrees: there
> of_alias_scan() splits an alias into the stem and the number and
> of_alias_get_id() compares the stem exactly.
>
> Match an alias only when the stem is followed by its number, as the
> live tree does. A test covers both lookups with the sandbox aliases,
> where "test" is a prefix of testbus3 and of the testfdt aliases.
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
This commit seems (74b14db48a8e in main) to break USB on all i.MX6Q/DL/UL/ULL
boards without CONFIG_PHY, USB gadget included, so fastboot and SDP from
U-Boot do not work anymore. We noticed it because uuu recovery stopped
working on Apalis iMX6, Colibri iMX6 and Colibri iMX6ULL, while Colibri
iMX7 with the same U-Boot is fine.
ehci-mx6 takes the port number from the alias of the USB PHY node, but
looks it up with the "usb" stem:
ret = fdtdec_get_alias_seq(blob, dev->uclass->uc_drv->name,
phy_off, &devnump);
The only aliases pointing to the PHY nodes are usbphy0/usbphy1, so this
worked only thanks to the prefix match you removed. Now it returns
-ENOENT and the EHCI probe fails.
Following patch diff is compile-tested only. And the analysis is from
claude, so take it with the appropriate caution.
Francesco
-- >8 --
drivers/usb/host/ehci-mx6.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index 25907f22612f..93b0d75633f6 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -609,8 +609,7 @@ static int mx6_parse_dt_addrs(struct udevice *dev)
#if defined(CONFIG_MX6)
int anatop_off, ret, devnump;
- ret = fdtdec_get_alias_seq(blob, dev->uclass->uc_drv->name,
- phy_off, &devnump);
+ ret = fdtdec_get_alias_seq(blob, "usbphy", phy_off, &devnump);
if (ret < 0)
return ret;
priv->portnr = devnump;
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH] usb: ehci-mx6: look up the port number with the usbphy alias
2026-11-22 19:53 ` [REGRESSION] " Francesco Dolcini
@ 2026-11-22 20:51 ` Mehmet Fide
2026-11-23 9:31 ` Emanuele Ghidoli
2026-11-22 20:52 ` [REGRESSION] [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it Mehmet Fide
1 sibling, 1 reply; 20+ messages in thread
From: Mehmet Fide @ 2026-11-22 20:51 UTC (permalink / raw)
To: Marek Vasut
Cc: Tom Rini, Francesco Dolcini, Fabio Estevam, Simon Glass, u-boot,
mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
mx6_parse_dt_addrs() takes the port number from the alias of the USB
PHY node, but looks it up with the uclass name "usb" as the stem. The
PHY nodes only have the aliases usbphy0 and usbphy1, which matched
only while fdtdec_get_alias_seq() accepted any alias starting with the
stem. Since that was fixed, the lookup returns -ENOENT and the probe
fails on i.MX6 without CONFIG_PHY, host and gadget alike.
Look the alias up with the "usbphy" stem.
Fixes: 74b14db48a8e ("fdtdec: match an alias to its stem only when the number follows it")
Reported-by: Francesco Dolcini <francesco@dolcini.it>
Closes: https://lore.kernel.org/u-boot/20261122195302.GA432275@francesco-nb/
Suggested-by: Francesco Dolcini <francesco@dolcini.it>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
drivers/usb/host/ehci-mx6.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
index 25907f22612..93b0d75633f 100644
--- a/drivers/usb/host/ehci-mx6.c
+++ b/drivers/usb/host/ehci-mx6.c
@@ -609,8 +609,7 @@ static int mx6_parse_dt_addrs(struct udevice *dev)
#if defined(CONFIG_MX6)
int anatop_off, ret, devnump;
- ret = fdtdec_get_alias_seq(blob, dev->uclass->uc_drv->name,
- phy_off, &devnump);
+ ret = fdtdec_get_alias_seq(blob, "usbphy", phy_off, &devnump);
if (ret < 0)
return ret;
priv->portnr = devnump;
--
2.56.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH] usb: ehci-mx6: look up the port number with the usbphy alias
2026-11-22 20:51 ` [PATCH] usb: ehci-mx6: look up the port number with the usbphy alias Mehmet Fide
@ 2026-11-23 9:31 ` Emanuele Ghidoli
0 siblings, 0 replies; 20+ messages in thread
From: Emanuele Ghidoli @ 2026-11-23 9:31 UTC (permalink / raw)
To: Mehmet Fide, Marek Vasut
Cc: Tom Rini, Francesco Dolcini, Fabio Estevam, Simon Glass, u-boot,
mehmet.fide, Emanuele Ghidoli
On 11/22/26 21:51, Mehmet Fide wrote:
> From: Mehmet Fide <mehmet.fide@screeningeagle.com>
>
> mx6_parse_dt_addrs() takes the port number from the alias of the USB
> PHY node, but looks it up with the uclass name "usb" as the stem. The
> PHY nodes only have the aliases usbphy0 and usbphy1, which matched
> only while fdtdec_get_alias_seq() accepted any alias starting with the
> stem. Since that was fixed, the lookup returns -ENOENT and the probe
> fails on i.MX6 without CONFIG_PHY, host and gadget alike.
>
> Look the alias up with the "usbphy" stem.
>
> Fixes: 74b14db48a8e ("fdtdec: match an alias to its stem only when the number follows it")
> Reported-by: Francesco Dolcini <francesco@dolcini.it>
> Closes: https://lore.kernel.org/u-boot/20261122195302.GA432275@francesco-nb/
> Suggested-by: Francesco Dolcini <francesco@dolcini.it>
> Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
> ---
> drivers/usb/host/ehci-mx6.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c
> index 25907f22612..93b0d75633f 100644
> --- a/drivers/usb/host/ehci-mx6.c
> +++ b/drivers/usb/host/ehci-mx6.c
> @@ -609,8 +609,7 @@ static int mx6_parse_dt_addrs(struct udevice *dev)
> #if defined(CONFIG_MX6)
> int anatop_off, ret, devnump;
>
> - ret = fdtdec_get_alias_seq(blob, dev->uclass->uc_drv->name,
> - phy_off, &devnump);
> + ret = fdtdec_get_alias_seq(blob, "usbphy", phy_off, &devnump);
> if (ret < 0)
> return ret;
> priv->portnr = devnump;
Tested on Apalis iMX6Q 1GB with the configuration we normally use to load
U-Boot over USB:
CONFIG_BOOTCOMMAND="fastboot usb 0"
# CONFIG_CMD_USB_SDP is not set
CONFIG_DEVICE_TREE_INCLUDES="toradex-recovery-u-boot.dtsi"
CONFIG_ENV_IMPORT_FDT=y
# CONFIG_ENV_IS_IN_MMC is not set
# CONFIG_ENV_IS_IN_NAND is not set
CONFIG_ENV_IS_NOWHERE=y
# CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID is not set
Without the patch, fastboot fails to start:
Hit any key to stop autoboot: 0
g_dnl_register: failed!, error: -2
Apalis iMX6 #
With the patch applied, it works as expected.
Base: e578056c766d ("Merge branch 'main' of
https://git.u-boot-project.org/u-boot/custodians/u-boot-sh")
Tested-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [REGRESSION] [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it
2026-11-22 19:53 ` [REGRESSION] " Francesco Dolcini
2026-11-22 20:51 ` [PATCH] usb: ehci-mx6: look up the port number with the usbphy alias Mehmet Fide
@ 2026-11-22 20:52 ` Mehmet Fide
1 sibling, 0 replies; 20+ messages in thread
From: Mehmet Fide @ 2026-11-22 20:52 UTC (permalink / raw)
To: Francesco Dolcini, Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Krzysztof Kozlowski, u-boot, mehmet.fide
Hi Francesco,
On Sun, Nov 22, 2026 at 08:53:02PM +0100, Francesco Dolcini wrote:
> ehci-mx6 takes the port number from the alias of the USB PHY node, but
> looks it up with the "usb" stem:
>
> ret = fdtdec_get_alias_seq(blob, dev->uclass->uc_drv->name,
> phy_off, &devnump);
>
> The only aliases pointing to the PHY nodes are usbphy0/usbphy1, so this
> worked only thanks to the prefix match you removed. Now it returns
> -ENOENT and the EHCI probe fails.
Right, I missed this caller. It is the only one that looks up the alias
of another node by the uclass name. I sent your diff as a patch in reply
to your mail, built for seven i.MX6 configurations. I have no i.MX6
board to run it on; could you test it on yours?
Our CI has test rigs with a Verdin iMX8M Plus, a Verdin AM62 Solo, a
Verdin AM62 Dual, a Colibri VF50 and a Colibri VF61. If you can send us
a Colibri iMX6ULL with raw NAND and an Iris, I will add it to the CI, so
that changes like this one are tested on i.MX6ULL too.
Mehmet
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v9 2/9] usb: ehci-vf: take the controller index from the device tree
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
2026-10-23 11:15 ` [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-10-23 11:15 ` [PATCH v9 3/9] usb: ehci-vf: remove the code path for a build without DM_USB Mehmet Fide
` (7 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
"usb start" on a Colibri VF50 or VF61 ends in a data abort and a
watchdog reset.
vf_usb_of_to_plat() takes the controller index from dev_seq(), but the
usbphy0 and usbphy1 aliases count as "usb" aliases when the uclass
numbers its devices, so the two controllers get 2 and 3 and index past
the two entries of phy_bases[] and nc_reg_bases[]. usb_oc_config() then
writes through an address read from beyond the table.
Follow the fsl,usbphy phandle, as ehci-mx6 does, and map the PHY node to
the index of the table instead of trusting the sequence number.
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- none, rebased on main
Changes in v8:
- none, rebased on main
Changes in v7:
- the Reviewed-by moved above the Signed-off-by
Changes in v6:
- Reviewed-by from Marek and Simon
Changes in v5:
- none
Changes in v4:
- sent alone before, now patch 1 of the series
- reworded the commit message, no code change
- the test note moved here: on a Colibri VF50 V1.2A on an Iris carrier,
"usb start" brings up the controller instead of resetting the board
drivers/usb/host/ehci-vf.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 96d1363a76e..32fe05920d0 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -221,8 +221,23 @@ static int vf_usb_of_to_plat(struct udevice *dev)
const void *dt_blob = gd->fdt_blob;
int node = dev_of_offset(dev);
const char *mode;
+ fdt_addr_t phy_addr;
+ ofnode phy_node;
+ int i;
- priv->portnr = dev_seq(dev);
+ phy_node = ofnode_parse_phandle(dev_ofnode(dev), "fsl,usbphy", 0);
+ if (!ofnode_valid(phy_node))
+ return -EINVAL;
+
+ phy_addr = ofnode_get_addr(phy_node);
+ for (i = 0; i < ARRAY_SIZE(phy_bases); i++) {
+ if (phy_addr == phy_bases[i])
+ break;
+ }
+ if (i == ARRAY_SIZE(phy_bases))
+ return -EINVAL;
+
+ priv->portnr = i;
priv->ehci = dev_read_addr_ptr(dev);
mode = fdt_getprop(dt_blob, node, "dr_mode", NULL);
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v9 3/9] usb: ehci-vf: remove the code path for a build without DM_USB
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
2026-10-23 11:15 ` [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it Mehmet Fide
2026-10-23 11:15 ` [PATCH v9 2/9] usb: ehci-vf: take the controller index from the device tree Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-10-23 11:15 ` [PATCH v9 4/9] usb: ehci-vf: drop the empty bind hook Mehmet Fide
` (6 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
USB_EHCI_HCD selects USB_HOST, and USB_HOST selects DM_USB, so the
!CONFIG_IS_ENABLED(DM_USB) branch of this driver can never be selected.
It also cannot compile: ehci_hcd_init() calls ehci_vf_common_init() with
one argument while the function takes two, so the branch has been dead
since the controller was added as a second parameter.
Remove it, together with the board_usb_phy_mode() hook that no board
implements and nothing else calls.
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- none, rebased on main
Changes in v8:
- none, rebased on main
Changes in v7:
- Reviewed-by from Marek and Simon
Changes in v6:
- the commit message names USB_HOST as the option that selects DM_USB
Changes in v5:
- none
Changes in v4:
- none, rebased on next
drivers/usb/host/ehci-vf.c | 49 --------------------------------------
1 file changed, 49 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 32fe05920d0..5d27318de62 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -128,11 +128,6 @@ static void usb_oc_config(int index)
setbits_le32(ctrl, UCTRL_OVER_CUR_DIS);
}
-int __weak board_usb_phy_mode(int port)
-{
- return 0;
-}
-
int __weak board_ehci_hcd_init(int port)
{
return 0;
@@ -155,49 +150,6 @@ int ehci_vf_common_init(struct usb_ehci *ehci, int index)
return 0;
}
-#if !CONFIG_IS_ENABLED(DM_USB)
-int ehci_hcd_init(int index, enum usb_init_type init,
- struct ehci_hccr **hccr, struct ehci_hcor **hcor)
-{
- struct usb_ehci *ehci;
- enum usb_init_type type;
- int ret;
-
- if (index >= ARRAY_SIZE(nc_reg_bases))
- return -EINVAL;
-
- ehci = (struct usb_ehci *)nc_reg_bases[index];
-
- ret = ehci_vf_common_init(index);
- if (ret)
- return ret;
-
- *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
- *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
- HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
-
- type = board_usb_phy_mode(index);
- if (type != init)
- return -ENODEV;
-
- if (init == USB_INIT_DEVICE) {
- setbits_le32(&ehci->usbmode, CM_DEVICE);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- } else if (init == USB_INIT_HOST) {
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- }
-
- return 0;
-}
-
-int ehci_hcd_stop(int index)
-{
- return 0;
-}
-#else
/* Possible port types (dual role mode) */
enum dr_mode {
DR_MODE_NONE = 0,
@@ -372,4 +324,3 @@ U_BOOT_DRIVER(ehci_vf) = {
.priv_auto = sizeof(struct ehci_vf_priv_data),
.flags = DM_FLAG_ALLOC_PRIV_DMA,
};
-#endif
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v9 4/9] usb: ehci-vf: drop the empty bind hook
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
` (2 preceding siblings ...)
2026-10-23 11:15 ` [PATCH v9 3/9] usb: ehci-vf: remove the code path for a build without DM_USB Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-10-23 11:15 ` [PATCH v9 5/9] usb: ehci-vf: use usb_get_dr_mode() Mehmet Fide
` (5 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
vf_usb_bind() only returns 0. Its comment describes a hack that keeps
the second controller from taking sequence number 0, but no such code
is there, and an empty .bind cannot influence the numbering the uclass
does. Remove it.
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- none, rebased on main
Changes in v8:
- none, rebased on main
Changes in v7:
- the Reviewed-by moved above the Signed-off-by
Changes in v6:
- dropped the two Fixes tags, the hook was not empty at those commits
- Reviewed-by from Marek and Simon
Changes in v5:
- none
Changes in v4:
- none, rebased on next
drivers/usb/host/ehci-vf.c | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 5d27318de62..e5f9ec0fdbb 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -261,20 +261,6 @@ static const struct ehci_ops vf_ehci_ops = {
.init_after_reset = vf_init_after_reset
};
-static int vf_usb_bind(struct udevice *dev)
-{
- /*
- * Without this hack, if we return ENODEV for USB Controller 0, on
- * probe for the next controller, USB Controller 1 will be given a
- * sequence number of 0. This conflicts with our requirement of
- * sequence numbers while initialising the peripherals.
- *
- * FIXME: Check that this still works OK with the new sequence numbers
- */
-
- return 0;
-}
-
static int ehci_usb_probe(struct udevice *dev)
{
struct usb_plat *plat = dev_get_plat(dev);
@@ -315,7 +301,6 @@ U_BOOT_DRIVER(ehci_vf) = {
.name = "ehci_vf",
.id = UCLASS_USB,
.of_match = vf_usb_ids,
- .bind = vf_usb_bind,
.probe = ehci_usb_probe,
.remove = ehci_deregister,
.ops = &ehci_usb_ops,
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v9 5/9] usb: ehci-vf: use usb_get_dr_mode()
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
` (3 preceding siblings ...)
2026-10-23 11:15 ` [PATCH v9 4/9] usb: ehci-vf: drop the empty bind hook Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-10-23 11:15 ` [PATCH v9 6/9] usb: ehci-vf: request the ID detect gpio through the device Mehmet Fide
` (4 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
The driver parses the dr_mode property itself, through the flat tree,
into an enum of its own that mirrors enum usb_dr_mode. Use
usb_get_dr_mode() and USB_DR_MODE_* instead, as ehci-mx6 does. A
missing property still means host, for legacy device trees.
usb_get_dr_mode() does not tell it from a value it does not know, so
such a value now means host as well instead of failing the probe.
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- Reviewed-by from Marek
Changes in v8:
- usb_get_dr_mode() is read once and USB_DR_MODE_UNKNOWN falls back to
host, as Marek proposed; an unknown value now means host too, as in
v6, instead of failing with -EINVAL as in v7
Changes in v7:
- Marek's review: this patch only replaces the private enum and the
strcmp() chain; the ID detect gpio moves to the next patch
- a missing dr_mode property means host and an unknown value fails with
-EINVAL again, as before the series; v6 made an unknown value host
Changes in v6:
- new patch, from the review of the register base patch in v5: the
private enum duplicated USB_DR_MODE_*
drivers/usb/host/ehci-vf.c | 62 +++++++++++++++-----------------------
1 file changed, 25 insertions(+), 37 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index e5f9ec0fdbb..90840cea92d 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -21,8 +21,8 @@
#include <asm/mach-imx/regs-usbphy.h>
#include <linux/delay.h>
#include <usb/ehci-ci.h>
-#include <linux/libfdt.h>
#include <fdtdec.h>
+#include <linux/usb/otg.h>
#include "ehci.h"
@@ -150,29 +150,19 @@ int ehci_vf_common_init(struct usb_ehci *ehci, int index)
return 0;
}
-/* Possible port types (dual role mode) */
-enum dr_mode {
- DR_MODE_NONE = 0,
- DR_MODE_HOST, /* supports host operation */
- DR_MODE_DEVICE, /* supports device operation */
- DR_MODE_OTG, /* supports both */
-};
-
struct ehci_vf_priv_data {
struct ehci_ctrl ctrl;
struct usb_ehci *ehci;
struct gpio_desc cdet_gpio;
enum usb_init_type init_type;
- enum dr_mode dr_mode;
+ enum usb_dr_mode dr_mode;
u32 portnr;
};
static int vf_usb_of_to_plat(struct udevice *dev)
{
struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- const void *dt_blob = gd->fdt_blob;
int node = dev_of_offset(dev);
- const char *mode;
fdt_addr_t phy_addr;
ofnode phy_node;
int i;
@@ -192,34 +182,32 @@ static int vf_usb_of_to_plat(struct udevice *dev)
priv->portnr = i;
priv->ehci = dev_read_addr_ptr(dev);
- mode = fdt_getprop(dt_blob, node, "dr_mode", NULL);
- if (mode) {
- if (0 == strcmp(mode, "host")) {
- priv->dr_mode = DR_MODE_HOST;
- priv->init_type = USB_INIT_HOST;
- } else if (0 == strcmp(mode, "peripheral")) {
- priv->dr_mode = DR_MODE_DEVICE;
- priv->init_type = USB_INIT_DEVICE;
- } else if (0 == strcmp(mode, "otg")) {
- priv->dr_mode = DR_MODE_OTG;
- /*
- * We set init_type to device by default when OTG
- * mode is requested. If a valid gpio is provided
- * we will switch the init_type based on the state
- * of the gpio pin.
- */
- priv->init_type = USB_INIT_DEVICE;
- } else {
- debug("%s: Cannot decode dr_mode '%s'\n",
- __func__, mode);
- return -EINVAL;
- }
- } else {
- priv->dr_mode = DR_MODE_HOST;
+ priv->dr_mode = usb_get_dr_mode(dev_ofnode(dev));
+ /* Handle legacy DTs without dr_mode property, fall back to host */
+ if (priv->dr_mode == USB_DR_MODE_UNKNOWN)
+ priv->dr_mode = USB_DR_MODE_HOST;
+
+ switch (priv->dr_mode) {
+ case USB_DR_MODE_HOST:
priv->init_type = USB_INIT_HOST;
+ break;
+ case USB_DR_MODE_PERIPHERAL:
+ priv->init_type = USB_INIT_DEVICE;
+ break;
+ case USB_DR_MODE_OTG:
+ /*
+ * We set init_type to device by default when OTG
+ * mode is requested. If a valid gpio is provided
+ * we will switch the init_type based on the state
+ * of the gpio pin.
+ */
+ priv->init_type = USB_INIT_DEVICE;
+ break;
+ default:
+ return -EINVAL;
}
- if (priv->dr_mode == DR_MODE_OTG) {
+ if (priv->dr_mode == USB_DR_MODE_OTG) {
gpio_request_by_name_nodev(offset_to_ofnode(node),
"fsl,cdet-gpio", 0, &priv->cdet_gpio,
GPIOD_IS_IN);
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v9 6/9] usb: ehci-vf: request the ID detect gpio through the device
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
` (4 preceding siblings ...)
2026-10-23 11:15 ` [PATCH v9 5/9] usb: ehci-vf: use usb_get_dr_mode() Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-10-23 11:15 ` [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree Mehmet Fide
` (3 subsequent siblings)
9 siblings, 0 replies; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
The ID detect gpio of an OTG port is requested through the flat node,
the result is never checked and the gpio is never freed: a bad gpio
description or a failing read silently leaves the port in device mode,
and every probe after a "usb stop" fails to request the pin again and
reads it only because the failed request left the descriptor pointing
at it.
Request it through the device in the probe and fail the probe on any
error but a missing property, which keeps the port in device mode as
before. Free it in a remove hook and on the failing probe paths, so
that the probe after a "usb stop" can request it again.
The flat tree access was the last user of the global data pointer:
drop it.
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- none, rebased on main
Changes in v8:
- Reviewed-by from Marek
Changes in v7:
- new patch, split out of the previous one on Marek's review
- gpio_request_by_name() and dm_gpio_get_value() are checked; only a
missing property is tolerated
- the gpio is requested in the probe and freed in a new remove hook and
on the failing probe paths, so the probe after a "usb stop" can
request it again
drivers/usb/host/ehci-vf.c | 61 +++++++++++++++++++++++++-------------
1 file changed, 40 insertions(+), 21 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 90840cea92d..52ec83fc485 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -10,7 +10,6 @@
#include <log.h>
#include <usb.h>
#include <errno.h>
-#include <asm/global_data.h>
#include <linux/compiler.h>
#include <asm/io.h>
#include <asm-generic/gpio.h>
@@ -37,8 +36,6 @@
#define UCMD_RUN_STOP (1 << 0) /* controller run/stop */
#define UCMD_RESET (1 << 1) /* controller reset */
-DECLARE_GLOBAL_DATA_PTR;
-
static const unsigned phy_bases[] = {
USB_PHY0_BASE_ADDR,
USB_PHY1_BASE_ADDR,
@@ -162,7 +159,6 @@ struct ehci_vf_priv_data {
static int vf_usb_of_to_plat(struct udevice *dev)
{
struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- int node = dev_of_offset(dev);
fdt_addr_t phy_addr;
ofnode phy_node;
int i;
@@ -207,18 +203,6 @@ static int vf_usb_of_to_plat(struct udevice *dev)
return -EINVAL;
}
- if (priv->dr_mode == USB_DR_MODE_OTG) {
- gpio_request_by_name_nodev(offset_to_ofnode(node),
- "fsl,cdet-gpio", 0, &priv->cdet_gpio,
- GPIOD_IS_IN);
- if (dm_gpio_is_valid(&priv->cdet_gpio)) {
- if (dm_gpio_get_value(&priv->cdet_gpio))
- priv->init_type = USB_INIT_DEVICE;
- else
- priv->init_type = USB_INIT_HOST;
- }
- }
-
return 0;
}
@@ -258,12 +242,27 @@ static int ehci_usb_probe(struct udevice *dev)
struct ehci_hcor *hcor;
int ret;
+ if (priv->dr_mode == USB_DR_MODE_OTG) {
+ ret = gpio_request_by_name(dev, "fsl,cdet-gpio", 0,
+ &priv->cdet_gpio, GPIOD_IS_IN);
+ if (ret && ret != -ENOENT)
+ return ret;
+ if (!ret) {
+ ret = dm_gpio_get_value(&priv->cdet_gpio);
+ if (ret < 0)
+ goto err_gpio;
+ priv->init_type = ret ? USB_INIT_DEVICE : USB_INIT_HOST;
+ }
+ }
+
ret = ehci_vf_common_init(ehci, priv->portnr);
if (ret)
- return ret;
+ goto err_gpio;
- if (priv->init_type != plat->init_type)
- return -ENODEV;
+ if (priv->init_type != plat->init_type) {
+ ret = -ENODEV;
+ goto err_gpio;
+ }
if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
@@ -277,7 +276,17 @@ static int ehci_usb_probe(struct udevice *dev)
hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, priv->init_type);
+ ret = ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, priv->init_type);
+ if (ret)
+ goto err_gpio;
+
+ return 0;
+
+err_gpio:
+ if (dm_gpio_is_valid(&priv->cdet_gpio))
+ dm_gpio_free(dev, &priv->cdet_gpio);
+
+ return ret;
}
static const struct udevice_id vf_usb_ids[] = {
@@ -285,12 +294,22 @@ static const struct udevice_id vf_usb_ids[] = {
{ }
};
+static int ehci_usb_remove(struct udevice *dev)
+{
+ struct ehci_vf_priv_data *priv = dev_get_priv(dev);
+
+ if (dm_gpio_is_valid(&priv->cdet_gpio))
+ dm_gpio_free(dev, &priv->cdet_gpio);
+
+ return ehci_deregister(dev);
+}
+
U_BOOT_DRIVER(ehci_vf) = {
.name = "ehci_vf",
.id = UCLASS_USB,
.of_match = vf_usb_ids,
.probe = ehci_usb_probe,
- .remove = ehci_deregister,
+ .remove = ehci_usb_remove,
.ops = &ehci_usb_ops,
.of_to_plat = vf_usb_of_to_plat,
.plat_auto = sizeof(struct usb_plat),
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
` (5 preceding siblings ...)
2026-10-23 11:15 ` [PATCH v9 6/9] usb: ehci-vf: request the ID detect gpio through the device Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-10-23 14:23 ` Marek Vasut
2026-10-23 11:15 ` [PATCH v9 8/9] usb: ehci-vf: sort the includes Mehmet Fide
` (2 subsequent siblings)
9 siblings, 1 reply; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
The driver keeps its own tables of PHY and controller base addresses
and reaches the anatop block through a hardcoded address, although the
device tree describes all three: the controller points at its PHY and
usbmisc nodes, and the PHY at its anatop.
Read them from there and drop the tables: the two phandles of the
controller node through dev_read_phandle_with_args(), the anatop one
from the PHY node. The helpers take the private data instead of single
addresses. The port number stays only for the choice between PLL3 and
PLL7 and now comes from the clock of the PHY: VF610_CLK_USBPHY0 and
VF610_CLK_USBPHY1 are the USB clock gates of the two PLLs.
The usbmisc node already starts at the non-core registers, so the
driver no longer adds an offset to reach them.
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- the port number comes from the clock of the PHY, VF610_CLK_USBPHY0
or VF610_CLK_USBPHY1, instead of its usbphy alias, which is not
documented ABI (Krzysztof); the ofnode_get_alias_seq() patch is gone
- the Reviewed-by of Marek on v8 is dropped, the code changed
Changes in v8:
- Reviewed-by from Marek
Changes in v7:
- portnr keeps its u32 type, Marek's review; the alias lookup writes a
local int
- adapted to the split of the previous patch, no other code change
Changes in v6:
- the phandles of the controller node are read with
dev_read_phandle_with_args()
- the helpers take the private data, not single addresses
- the dr_mode enum this patch used to move is gone, see the new patch
before this one
Changes in v5:
- the PHY node is looked up with the "usbphy" stem: the uclass name
"usb" found usbphy0 only through the prefix match of the flat lookup
Changes in v4:
- rebased on next
- dropped two comments that repeated the commit message
- reworded the commit message and took the note on the previous version
out of it
drivers/usb/host/ehci-vf.c | 145 ++++++++++++++++++++++---------------
1 file changed, 85 insertions(+), 60 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 52ec83fc485..46d8f6b4461 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -20,13 +20,11 @@
#include <asm/mach-imx/regs-usbphy.h>
#include <linux/delay.h>
#include <usb/ehci-ci.h>
-#include <fdtdec.h>
#include <linux/usb/otg.h>
+#include <dt-bindings/clock/vf610-clock.h>
#include "ehci.h"
-#define USB_NC_REG_OFFSET 0x00000800
-
#define ANADIG_PLL_CTRL_EN_USB_CLKS (1 << 6)
#define UCTRL_OVER_CUR_POL (1 << 8) /* OTG Polarity of Overcurrent */
@@ -36,31 +34,29 @@
#define UCMD_RUN_STOP (1 << 0) /* controller run/stop */
#define UCMD_RESET (1 << 1) /* controller reset */
-static const unsigned phy_bases[] = {
- USB_PHY0_BASE_ADDR,
- USB_PHY1_BASE_ADDR,
-};
-
-static const unsigned nc_reg_bases[] = {
- USBC0_BASE_ADDR,
- USBC1_BASE_ADDR,
+struct ehci_vf_priv_data {
+ struct ehci_ctrl ctrl;
+ struct usb_ehci *ehci;
+ struct gpio_desc cdet_gpio;
+ enum usb_init_type init_type;
+ enum usb_dr_mode dr_mode;
+ struct anadig_reg __iomem *anatop_addr;
+ void __iomem *phy_addr;
+ void __iomem *misc_addr;
+ u32 portnr;
};
-static void usb_internal_phy_clock_gate(int index)
+static void usb_internal_phy_clock_gate(struct ehci_vf_priv_data *priv)
{
- void __iomem *phy_reg;
-
- phy_reg = (void __iomem *)phy_bases[index];
- clrbits_le32(phy_reg + USBPHY_CTRL, USBPHY_CTRL_CLKGATE);
+ clrbits_le32(priv->phy_addr + USBPHY_CTRL, USBPHY_CTRL_CLKGATE);
}
-static void usb_power_config(int index)
+static void usb_power_config(struct ehci_vf_priv_data *priv)
{
- struct anadig_reg __iomem *anadig =
- (struct anadig_reg __iomem *)ANADIG_BASE_ADDR;
+ struct anadig_reg __iomem *anadig = priv->anatop_addr;
void __iomem *pll_ctrl;
- switch (index) {
+ switch (priv->portnr) {
case 0:
pll_ctrl = &anadig->pll3_ctrl;
clrbits_le32(pll_ctrl, ANADIG_PLL3_CTRL_BYPASS);
@@ -80,15 +76,14 @@ static void usb_power_config(int index)
}
}
-static void usb_phy_enable(int index, struct usb_ehci *ehci)
+static void usb_phy_enable(struct ehci_vf_priv_data *priv)
{
- void __iomem *phy_reg;
+ void __iomem *phy_reg = priv->phy_addr;
void __iomem *phy_ctrl;
void __iomem *usb_cmd;
- phy_reg = (void __iomem *)phy_bases[index];
phy_ctrl = (void __iomem *)(phy_reg + USBPHY_CTRL);
- usb_cmd = (void __iomem *)&ehci->usbcmd;
+ usb_cmd = (void __iomem *)&priv->ehci->usbcmd;
/* Stop then Reset */
clrbits_le32(usb_cmd, UCMD_RUN_STOP);
@@ -115,14 +110,10 @@ static void usb_phy_enable(int index, struct usb_ehci *ehci)
USBPHY_CTRL_ENUTMILEVEL3);
}
-static void usb_oc_config(int index)
+static void usb_oc_config(struct ehci_vf_priv_data *priv)
{
- void __iomem *ctrl;
-
- ctrl = (void __iomem *)(nc_reg_bases[index] + USB_NC_REG_OFFSET);
-
- setbits_le32(ctrl, UCTRL_OVER_CUR_POL);
- setbits_le32(ctrl, UCTRL_OVER_CUR_DIS);
+ setbits_le32(priv->misc_addr, UCTRL_OVER_CUR_POL);
+ setbits_le32(priv->misc_addr, UCTRL_OVER_CUR_DIS);
}
int __weak board_ehci_hcd_init(int port)
@@ -130,52 +121,86 @@ int __weak board_ehci_hcd_init(int port)
return 0;
}
-int ehci_vf_common_init(struct usb_ehci *ehci, int index)
+static int ehci_vf_common_init(struct ehci_vf_priv_data *priv)
{
int ret;
/* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
+ ret = board_ehci_hcd_init(priv->portnr);
if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
+ usb_power_config(priv);
+ usb_oc_config(priv);
+ usb_internal_phy_clock_gate(priv);
+ usb_phy_enable(priv);
return 0;
}
-struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- struct gpio_desc cdet_gpio;
- enum usb_init_type init_type;
- enum usb_dr_mode dr_mode;
- u32 portnr;
-};
-
-static int vf_usb_of_to_plat(struct udevice *dev)
+static int vf_parse_dt_addrs(struct udevice *dev)
{
struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- fdt_addr_t phy_addr;
- ofnode phy_node;
- int i;
+ struct ofnode_phandle_args phy, misc, clk;
+ ofnode anatop_node;
+ fdt_addr_t addr;
+ int ret;
+
+ ret = dev_read_phandle_with_args(dev, "fsl,usbphy", NULL, 0, 0, &phy);
+ if (ret)
+ return ret;
+
+ ret = dev_read_phandle_with_args(dev, "fsl,usbmisc", NULL, 0, 0,
+ &misc);
+ if (ret)
+ return ret;
- phy_node = ofnode_parse_phandle(dev_ofnode(dev), "fsl,usbphy", 0);
- if (!ofnode_valid(phy_node))
+ anatop_node = ofnode_parse_phandle(phy.node, "fsl,anatop", 0);
+ if (!ofnode_valid(anatop_node))
return -EINVAL;
- phy_addr = ofnode_get_addr(phy_node);
- for (i = 0; i < ARRAY_SIZE(phy_bases); i++) {
- if (phy_addr == phy_bases[i])
- break;
+ ret = ofnode_parse_phandle_with_args(phy.node, "clocks", "#clock-cells",
+ 0, 0, &clk);
+ if (ret)
+ return ret;
+
+ switch (clk.args[0]) {
+ case VF610_CLK_USBPHY0:
+ priv->portnr = 0;
+ break;
+ case VF610_CLK_USBPHY1:
+ priv->portnr = 1;
+ break;
+ default:
+ return -EINVAL;
}
- if (i == ARRAY_SIZE(phy_bases))
+
+ addr = ofnode_get_addr(phy.node);
+ if (addr == FDT_ADDR_T_NONE)
+ return -EINVAL;
+ priv->phy_addr = (void __iomem *)addr;
+
+ addr = ofnode_get_addr(misc.node);
+ if (addr == FDT_ADDR_T_NONE)
+ return -EINVAL;
+ priv->misc_addr = (void __iomem *)addr;
+
+ addr = ofnode_get_addr(anatop_node);
+ if (addr == FDT_ADDR_T_NONE)
return -EINVAL;
+ priv->anatop_addr = (struct anadig_reg __iomem *)addr;
- priv->portnr = i;
+ return 0;
+}
+
+static int vf_usb_of_to_plat(struct udevice *dev)
+{
+ struct ehci_vf_priv_data *priv = dev_get_priv(dev);
+ int ret;
+
+ ret = vf_parse_dt_addrs(dev);
+ if (ret)
+ return ret;
priv->ehci = dev_read_addr_ptr(dev);
priv->dr_mode = usb_get_dr_mode(dev_ofnode(dev));
@@ -213,7 +238,7 @@ static int vf_init_after_reset(struct ehci_ctrl *dev)
struct usb_ehci *ehci = priv->ehci;
int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
+ ret = ehci_vf_common_init(priv);
if (ret)
return ret;
@@ -255,7 +280,7 @@ static int ehci_usb_probe(struct udevice *dev)
}
}
- ret = ehci_vf_common_init(ehci, priv->portnr);
+ ret = ehci_vf_common_init(priv);
if (ret)
goto err_gpio;
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree
2026-10-23 11:15 ` [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree Mehmet Fide
@ 2026-10-23 14:23 ` Marek Vasut
2026-10-23 14:35 ` Mehmet Fide
0 siblings, 1 reply; 20+ messages in thread
From: Marek Vasut @ 2026-10-23 14:23 UTC (permalink / raw)
To: Mehmet Fide, Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
On 10/23/26 1:15 PM, Mehmet Fide wrote:
[...]
> + ret = ofnode_parse_phandle_with_args(phy.node, "clocks", "#clock-cells",
> + 0, 0, &clk);
> + if (ret)
> + return ret;
> +
> + switch (clk.args[0]) {
> + case VF610_CLK_USBPHY0:
> + priv->portnr = 0;
> + break;
> + case VF610_CLK_USBPHY1:
> + priv->portnr = 1;
> + break;
> + default:
> + return -EINVAL;
> }
This is admittedly a bit icky, please at least add a code comment. But I
think this will get removed in some follow up series ?
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree
2026-10-23 14:23 ` Marek Vasut
@ 2026-10-23 14:35 ` Mehmet Fide
2026-10-23 19:34 ` Marek Vasut
0 siblings, 1 reply; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 14:35 UTC (permalink / raw)
To: Marek Vasut
Cc: Krzysztof Kozlowski, Simon Glass, Tom Rini, Fabio Estevam,
Stefan Agner, Francesco Dolcini, u-boot, mehmet.fide
Hi Marek,
On 10/23/26 4:23 PM, Marek Vasut wrote:
> This is admittedly a bit icky, please at least add a code comment. But I
> think this will get removed in some follow up series ?
Yes, the follow-up with a VF610 clock driver removes this switch and
portnr altogether. If that is fine with you, I would keep v9 as it is.
Thanks,
Mehmet
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree
2026-10-23 14:35 ` Mehmet Fide
@ 2026-10-23 19:34 ` Marek Vasut
0 siblings, 0 replies; 20+ messages in thread
From: Marek Vasut @ 2026-10-23 19:34 UTC (permalink / raw)
To: Mehmet Fide, Marek Vasut
Cc: Krzysztof Kozlowski, Simon Glass, Tom Rini, Fabio Estevam,
Stefan Agner, Francesco Dolcini, u-boot, mehmet.fide
On 10/23/26 4:35 PM, Mehmet Fide wrote:
> Hi Marek,
>
> On 10/23/26 4:23 PM, Marek Vasut wrote:
>> This is admittedly a bit icky, please at least add a code comment. But I
>> think this will get removed in some follow up series ?
>
> Yes, the follow-up with a VF610 clock driver removes this switch and
> portnr altogether. If that is fine with you, I would keep v9 as it is.
I can live with that, thanks !
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v9 8/9] usb: ehci-vf: sort the includes
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
` (6 preceding siblings ...)
2026-10-23 11:15 ` [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-10-23 13:49 ` Marek Vasut
2026-10-23 11:15 ` [PATCH v9 9/9] usb: ehci-vf: enable the vbus supply of the port Mehmet Fide
2026-11-14 15:24 ` [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
9 siblings, 1 reply; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
Put the includes in the order the coding style asks for: the top-level
headers, then the ones in subdirectories, each in alphabetical order.
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- the include the previous patch adds is sorted with the others; the
Reviewed-by of Marek on v8 is dropped for that line
Changes in v8:
- new patch, from Marek's review of the vbus patch in v7
drivers/usb/host/ehci-vf.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 46d8f6b4461..364ac5b831d 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -7,21 +7,21 @@
*/
#include <dm.h>
+#include <errno.h>
#include <log.h>
#include <usb.h>
-#include <errno.h>
-#include <linux/compiler.h>
-#include <asm/io.h>
#include <asm-generic/gpio.h>
#include <asm/arch/clock.h>
-#include <asm/arch/imx-regs.h>
#include <asm/arch/crm_regs.h>
+#include <asm/arch/imx-regs.h>
+#include <asm/io.h>
#include <asm/mach-imx/iomux-v3.h>
#include <asm/mach-imx/regs-usbphy.h>
+#include <dt-bindings/clock/vf610-clock.h>
+#include <linux/compiler.h>
#include <linux/delay.h>
-#include <usb/ehci-ci.h>
#include <linux/usb/otg.h>
-#include <dt-bindings/clock/vf610-clock.h>
+#include <usb/ehci-ci.h>
#include "ehci.h"
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v9 8/9] usb: ehci-vf: sort the includes
2026-10-23 11:15 ` [PATCH v9 8/9] usb: ehci-vf: sort the includes Mehmet Fide
@ 2026-10-23 13:49 ` Marek Vasut
0 siblings, 0 replies; 20+ messages in thread
From: Marek Vasut @ 2026-10-23 13:49 UTC (permalink / raw)
To: Mehmet Fide, Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
On 10/23/26 1:15 PM, Mehmet Fide wrote:
> From: Mehmet Fide <mehmet.fide@screeningeagle.com>
>
> Put the includes in the order the coding style asks for: the top-level
> headers, then the ones in subdirectories, each in alphabetical order.
>
> Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v9 9/9] usb: ehci-vf: enable the vbus supply of the port
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
` (7 preceding siblings ...)
2026-10-23 11:15 ` [PATCH v9 8/9] usb: ehci-vf: sort the includes Mehmet Fide
@ 2026-10-23 11:15 ` Mehmet Fide
2026-11-14 15:24 ` [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
9 siblings, 0 replies; 20+ messages in thread
From: Mehmet Fide @ 2026-10-23 11:15 UTC (permalink / raw)
To: Marek Vasut
Cc: Simon Glass, Tom Rini, Fabio Estevam, Stefan Agner,
Francesco Dolcini, Krzysztof Kozlowski, u-boot, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
The driver never enables the vbus-supply of its port, so on boards that
switch VBUS through a regulator, such as the Colibri VF50 and VF61
carriers, the port stays unpowered and no device is found.
Do what ehci-mx6 does: look the regulator up in probe, enable it in
host mode, disable it in device mode, and turn it off on remove. A
missing vbus-supply or a build without DM_REGULATOR is fine; any other
lookup error fails the probe instead of leaving the port dead.
Reviewed-by: Marek Vasut <marek.vasut+usb@mailbox.org>
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v9:
- dev goes before vbus_supply in the private data (Marek)
- Reviewed-by from Marek
Changes in v8:
- the two includes go in sorted, and the reset hook keeps its argument
name dev (Marek)
Changes in v7:
- the Reviewed-by of Marek and Simon on v6 is dropped: the VBUS code is
unchanged, but the remove hook now comes from patch 7 and this patch
adds its VBUS line to it
Changes in v6:
- dev_err() and dev_dbg() for the two messages; the reset hook reaches
the device through the private data
Changes in v5:
- none
Changes in v4:
- enable VBUS in the reset hook only, as ehci-mx6 does: enabling it in
the shared init as well counted two enables per probe, so "usb stop"
never switched it off
- the dm core patch it needed is dropped, next claims the regulator
GPIO at probe time
- reworded the commit message
drivers/usb/host/ehci-vf.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c
index 364ac5b831d..f7809a98c88 100644
--- a/drivers/usb/host/ehci-vf.c
+++ b/drivers/usb/host/ehci-vf.c
@@ -17,10 +17,12 @@
#include <asm/io.h>
#include <asm/mach-imx/iomux-v3.h>
#include <asm/mach-imx/regs-usbphy.h>
+#include <dm/device_compat.h>
#include <dt-bindings/clock/vf610-clock.h>
#include <linux/compiler.h>
#include <linux/delay.h>
#include <linux/usb/otg.h>
+#include <power/regulator.h>
#include <usb/ehci-ci.h>
#include "ehci.h"
@@ -43,6 +45,8 @@ struct ehci_vf_priv_data {
struct anadig_reg __iomem *anatop_addr;
void __iomem *phy_addr;
void __iomem *misc_addr;
+ struct udevice *dev;
+ struct udevice *vbus_supply;
u32 portnr;
};
@@ -242,6 +246,13 @@ static int vf_init_after_reset(struct ehci_ctrl *dev)
if (ret)
return ret;
+ ret = regulator_set_enable_if_allowed(priv->vbus_supply,
+ type != USB_INIT_DEVICE);
+ if (ret && ret != -ENOSYS) {
+ dev_err(priv->dev, "cannot enable the VBUS supply: %d\n", ret);
+ return ret;
+ }
+
if (type == USB_INIT_DEVICE)
return 0;
@@ -267,6 +278,16 @@ static int ehci_usb_probe(struct udevice *dev)
struct ehci_hcor *hcor;
int ret;
+ priv->dev = dev;
+ ret = device_get_supply_regulator(dev, "vbus-supply",
+ &priv->vbus_supply);
+ if (ret == -ENOENT || ret == -ENOSYS) {
+ dev_dbg(dev, "no VBUS supply\n");
+ } else if (ret) {
+ dev_err(dev, "cannot get the VBUS supply: %d\n", ret);
+ return ret;
+ }
+
if (priv->dr_mode == USB_DR_MODE_OTG) {
ret = gpio_request_by_name(dev, "fsl,cdet-gpio", 0,
&priv->cdet_gpio, GPIOD_IS_IN);
@@ -323,6 +344,8 @@ static int ehci_usb_remove(struct udevice *dev)
{
struct ehci_vf_priv_data *priv = dev_get_priv(dev);
+ regulator_set_enable_if_allowed(priv->vbus_supply, false);
+
if (dm_gpio_is_valid(&priv->cdet_gpio))
dm_gpio_free(dev, &priv->cdet_gpio);
--
2.55.0
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable
2026-10-23 11:15 [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
` (8 preceding siblings ...)
2026-10-23 11:15 ` [PATCH v9 9/9] usb: ehci-vf: enable the vbus supply of the port Mehmet Fide
@ 2026-11-14 15:24 ` Mehmet Fide
2026-11-15 14:21 ` Marek Vasut
9 siblings, 1 reply; 20+ messages in thread
From: Mehmet Fide @ 2026-11-14 15:24 UTC (permalink / raw)
To: Marek Vasut
Cc: Krzysztof Kozlowski, Simon Glass, Tom Rini, Fabio Estevam,
Stefan Agner, Francesco Dolcini, u-boot, mehmet.fide
Hi Marek,
A gentle ping on this series. It still applies to today's main and next
without changes.
Is there anything else you need from me for it?
Thanks,
Mehmet
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable
2026-11-14 15:24 ` [PATCH v9 0/9] usb: ehci-vf: make the USB host port usable Mehmet Fide
@ 2026-11-15 14:21 ` Marek Vasut
0 siblings, 0 replies; 20+ messages in thread
From: Marek Vasut @ 2026-11-15 14:21 UTC (permalink / raw)
To: Mehmet Fide, Marek Vasut
Cc: Krzysztof Kozlowski, Simon Glass, Tom Rini, Fabio Estevam,
Stefan Agner, Francesco Dolcini, u-boot, mehmet.fide
On 11/14/26 4:24 PM, Mehmet Fide wrote:
Hello Mehmet,
> A gentle ping on this series. It still applies to today's main and next
> without changes.
>
> Is there anything else you need from me for it?
No, I applied it now, thank you for the reminder, this helped.
I'll get it into 2027.01 once the CI gets fixed.
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 20+ messages in thread