usb: ehci-vf: make the USB host port usable
Subsystems (3)
v9 cover usb: ehci-vf: make the USB host port usable
From: Mehmet Fide <[email protected]>
"usb start" on a Colibri VF50 or VF61 kills U-Boot with a data abort, and even with that fixed the host port stays unpowered:
- patch 1 makes the flat-tree alias lookups match a stem exactly, as the live tree does; their prefix match is what gave the two USB controllers of the Vybrid the sequence numbers 2 and 3
- patch 2 fixes the data abort: the controller index came from that sequence number and indexed past the driver's tables
- patches 3 to 7 drop the dead non-DM path and the empty bind hook, take dr_mode through usb_get_dr_mode() and the ID detect gpio through the device, and the PHY, usbmisc and anatop bases from the device tree instead of the tables
- patch 8 sorts the includes
- patch 9 enables the vbus-supply of the port
Patches 3 to 7 are the follow-up Marek asked for in his review of the data abort fix: the PHY and usbmisc tables are gone, and the port index that is left, for board_ehci_hcd_init() and the anatop registers, comes from the clock of the PHY.
v9:
- Krzysztof's review of v8: patch 7 takes the port index from the clock of the PHY, VF610_CLK_USBPHY0 or VF610_CLK_USBPHY1, instead of the usbphy alias, which is not documented ABI; the ofnode_get_alias_seq() patch of v8 is dropped, so patches 6 to 10 of v8 are now 5 to 9
- patch 9 puts dev before vbus_supply in the private data (Marek)
- patches 5 and 9 carry Marek's Reviewed-by; patch 7 drops his v8 one, its code changed, and so does patch 8 for the one include it now sorts
- rebased on main
v8:
- Marek's review of v7: patch 6 reads dr_mode through usb_get_dr_mode() alone and takes USB_DR_MODE_UNKNOWN as host, for legacy device trees without the property; an unknown value now means host as well, as in v6, instead of the -EINVAL of v7
- new patch 9 sorts the includes; patch 10 adds its two in order and leaves the argument of the reset hook named dev
- patches 7 and 8 carry Marek's Reviewed-by
- rebased on main
v7:
- Marek's review of v6: the dr_mode patch is split in two, patch 6 only replaces the private enum and the strcmp() chain, the new patch 7 moves the ID detect gpio request to the device and into the probe, checks the results of gpio_request_by_name() and dm_gpio_get_value(), and frees the gpio in a new remove hook and on the failing probe paths, so the probe that follows a "usb stop" can request it again
- a dr_mode value the driver does not know fails the probe with -EINVAL again, as it did before the series; v6 made it host
- patch 8 keeps the u32 portnr, the alias lookup writes a local int
- the tags sit above the Signed-off-by; patch 3 carries Marek's Reviewed-by
- Simon's Reviewed-by on v6 carried to patches 1 to 5, whose code is unchanged; patches 6 and 8 changed after his review and patch 7 is new
- patch 9 drops the Reviewed-by of Marek and Simon on v6: its VBUS code is unchanged, but it now adds its line to the remove hook of patch 7
- rebased on main
v6:
- Marek's review of v5: patch 3 names USB_HOST as the option that selects DM_USB, patch 4 loses its two Fixes tags, patches 2 and 4 carry his Reviewed-by
- new patch 6: the driver's own dr_mode enum and parsing go, it uses usb_get_dr_mode() and USB_DR_MODE_* as ehci-mx6 does
- patch 7 reads the phandles of the controller node with dev_read_phandle_with_args() and passes the private data to the helpers instead of single addresses
- patch 8 reports through dev_err() and dev_dbg()
v5:
- Simon's review of patch 4 (now 5): the live and the flat lookup treated the stem differently, exact against prefix, and the register base patch relied on the prefix to find usbphy0 with the "usb" stem. New patch 1 makes the flat lookup exact, ofnode_get_alias_seq() documents it and its test checks a prefix stem; the PHY node is looked up with the "usbphy" stem
- ofnode_get_alias_seq() now works on a node of any tree, on the live tree as well: of_alias_get_id() looks a node outside the control tree up in the /aliases node of its own tree; a test uses the other tree of the sandbox tests
- the checkpatch note of patch 4 (now 5) moved below the --- line
- rebased on main after the v2026.10 release
v4:
- rebased on next; the dm core change that moved of_to_plat() after pinctrl is gone, the regulator GPIO is now claimed at probe time upstream, which is what the vbus patch needed
- the data abort fix joins the series, the register base patch depends on it
- the vbus patch enables VBUS in the reset hook only, as ehci-mx6 does; v3 enabled it there and in the shared init, so the regulator counted two enables per probe and "usb stop" never switched VBUS off
- the dm core patch gains a test and no longer documents -ENOENT for a missing alias, the live tree returns -ENODEV
v8 of this series:
https://lore.kernel.org/u-boot/[email protected]/
v7 of this series:
https://lore.kernel.org/u-boot/[email protected]/
v6 of this series:
https://lore.kernel.org/u-boot/[email protected]/
v5 of this series:
https://lore.kernel.org/u-boot/[email protected]/
v4 of this series:
https://lore.kernel.org/u-boot/[email protected]/
v2 of the register base series:
https://lore.kernel.org/u-boot/[email protected]/
v3 of the vbus series:
https://lore.kernel.org/u-boot/[email protected]/
the data abort fix on its own:
https://lore.kernel.org/u-boot/[email protected]/
Tested on a Colibri VF50 V1.2A on the Iris carrier, colibri_vf_defconfig on main (903c9578eeb): "usb start" finds a USB stick behind the host port at usb@400b4000 and reads the same data before and after "usb reset", VBUS goes on at "usb start" and off at "usb stop", also after repeated resets, and Linux takes the port over when U-Boot boots it without "usb stop". The code of patches 1 to 4 is the one tested on a VF61 V1.2B for v6; patches 5 to 9 changed only in the driver and were tested on the VF50 as above, usb0 on PLL3 and usb1 on PLL7. With local device trees that make usb0 an OTG port with the fsl,cdet-gpio colibri_vf had before its device tree sync, both ID states went through "usb start", "usb reset" and "usb stop" cycles: read as device, the port is not available on every start and the gpio stays free; read as host (GPIO_ACTIVE_LOW), the port holds the gpio while it runs and gives it back at "usb stop". Without the frees, every probe after the first fails with -EBUSY. An unknown dr_mode and a missing one both give a host port. The gadget side goes through the same probe: "dfu" and "ums" on usb0, the latter with the stick behind usb1 as its storage, enumerate on a Windows host, which reads the first MiB of the stick through usb0 with the same CRC32 as "usb read" in U-Boot, and "usb start" works after both; on the host state of the OTG device trees, and with an unknown or a missing dr_mode, "dfu" fails with -ENODEV instead. v2026.07, whose ehci-vf driver is the one on main, hangs in "dfu".
The five ARCH_VF610 boards build at every patch, and "ut dm" on sandbox gives the same result as on main, plus the test of patch 1 on the live and the flat tree.
Mehmet Fide (9):
fdtdec: match an alias to its stem only when the number follows it
usb: ehci-vf: take the controller index from the device tree
usb: ehci-vf: remove the code path for a build without DM_USB
usb: ehci-vf: drop the empty bind hook
usb: ehci-vf: use usb_get_dr_mode()
usb: ehci-vf: request the ID detect gpio through the device
usb: ehci-vf: take the register bases from the device tree
usb: ehci-vf: sort the includes
usb: ehci-vf: enable the vbus supply of the port
drivers/usb/host/ehci-vf.c | 322 +++++++++++++++++++------------------ lib/fdtdec.c | 43 +++-- test/dm/fdtdec.c | 35 ++++ 3 files changed, 229 insertions(+), 171 deletions(-)
base-commit: 903c9578eeb36d72f087082da494c605ddaed3b2
Signature · 1 line
2.55.0
PATCH v9 1/9 fdtdec: match an alias to its stem only when the number follows it
From: Mehmet Fide <[email protected]>
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.
---
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(-)
lib/fdtdec.c +30 -13
@@ -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;
test/dm/fdtdec.c +35 -0
@@ -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 );
Signature · 1 line
2.55.0
Re: [REGRESSION] [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it
Hello Mehmet, Marek,
Quoted 11 lines · Mehmet Fide
From: Mehmet Fide <[email protected]>
fdtdec_get_alias_seq()andfdtdec_get_alias_highest_id()compare the alias name with the stem bystrncmp()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: thereof_alias_scan()splits an alias into the stem and the number andof_alias_get_id()compares the stem exactly.
Quoted 6 lines
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 <[email protected]>Signed-off-by Mehmet Fide <[email protected]>
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(-)
drivers/usb/host/ehci-mx6.c +1 -2
@@ -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;
PATCH 1/1 usb: ehci-mx6: look up the port number with the usbphy alias
From: Mehmet Fide <[email protected]>
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.
--- drivers/usb/host/ehci-mx6.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/host/ehci-mx6.c +1 -2
@@ -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;
Signature · 1 line
2.56.0
Re: [REGRESSION] [PATCH v9 1/9] fdtdec: match an alias to its stem only when the number follows it
In reply to Francesco DolciniHi Francesco,
Quoted 9 lines · Francesco Dolcini
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
-ENOENTand 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
PATCH v9 2/9 usb: ehci-vf: take the controller index from the device tree
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
"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.
---
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(-)
drivers/usb/host/ehci-vf.c +16 -1
@@ -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 );
Signature · 1 line
2.55.0
PATCH v9 3/9 usb: ehci-vf: remove the code path for a build without DM_USB
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
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.
---
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(-)
drivers/usb/host/ehci-vf.c +0 -49
@@ -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
Signature · 1 line
2.55.0
PATCH v9 4/9 usb: ehci-vf: drop the empty bind hook
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
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.
---
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(-)
drivers/usb/host/ehci-vf.c +0 -15
@@ -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,
Signature · 1 line
2.55.0
PATCH v9 5/9 usb: ehci-vf: use usb_get_dr_mode()
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
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.
---
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(-)
drivers/usb/host/ehci-vf.c +25 -37
@@ -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 );
Signature · 1 line
2.55.0
PATCH v9 6/9 usb: ehci-vf: request the ID detect gpio through the device
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
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.
---
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(-)
drivers/usb/host/ehci-vf.c +40 -21
@@ -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 ),
Signature · 1 line
2.55.0
PATCH v9 7/9 usb: ehci-vf: take the register bases from the device tree
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
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.
---
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(-)
drivers/usb/host/ehci-vf.c +85 -60
@@ -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;
Signature · 1 line
2.55.0
Re: [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree
On 10/23/26 1:15 PM, Mehmet Fide wrote:
[...]
Quoted 5 lines
drivers/usb/host/ehci-vf.c +5
-0+ ret =ofnode_parse_phandle_with_args (phy.node,"clocks" ,"#clock-cells" , +0 ,0 , &clk); +if (ret) +return ret; +
drivers/usb/host/ehci-vf.c int __weak board_ehci_hcd_init(int port) · line 176
Quoted 10 lines
drivers/usb/host/ehci-vf.c +9
-0+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 ?
Re: [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree
Hi Marek,
Quoted 2 lines · Marek Vasut
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
Re: [PATCH v9 7/9] usb: ehci-vf: take the register bases from the device tree
Quoted 8 lines · Mehmet Fide
Hi Marek,
Quoted 2 lines · Marek Vasut
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 !
PATCH v9 8/9 usb: ehci-vf: sort the includes
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
Put the includes in the order the coding style asks for: the top-level headers, then the ones in subdirectories, each in alphabetical order.
---
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(-)
drivers/usb/host/ehci-vf.c +6 -6
@@ -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"
Signature · 1 line
2.55.0
Re: [PATCH v9 8/9] usb: ehci-vf: sort the includes
Quoted 6 lines · Mehmet Fide
From: Mehmet Fide <[email protected]>
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 <[email protected]>
PATCH v9 9/9 usb: ehci-vf: enable the vbus supply of the port
In reply to Mehmet FideFrom: Mehmet Fide <[email protected]>
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.
---
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(+)
drivers/usb/host/ehci-vf.c +23 -0
@@ -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);
Signature · 1 line
2.55.0
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
On 11/14/26 4:24 PM, Mehmet Fide wrote:
Hello Mehmet,
Quoted 4 lines
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.
Signature · 2 lines
Best regards, Marek Vasut