[PATCH 0/3] Add support for USB onboard HUB, used on stm32 boards

This series adds a driver to support USB onboard HUB, inspired by Linux onboard hub driver.
Purpose is to manage the power supply regulator on STM32 boards, for low power use case in Linux. U-boot driver allows to benefit of the device tree part to supply the HUB when need, instead using an always-on regulator.
It aligns the relevant DT part from emerging Linux v6.2. It also adds the relevant default configuration on stm32mp15.
Fabrice Gasnier (3): usb: onboard-hub: add driver to manage onboard hub supplies configs: stm32: enable USB onboard HUB driver ARM: dts: stm32: add support for USB2514B onboard hub on stm32mp157c-ev1
arch/arm/dts/stm32mp157c-ev1.dts | 8 ++++ common/Makefile | 1 + common/usb_onboard_hub.c | 62 +++++++++++++++++++++++++++++ configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + drivers/usb/Kconfig | 10 +++++ drivers/usb/host/usb-uclass.c | 16 +++++--- 8 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 common/usb_onboard_hub.c

The main issue the driver addresses is that a USB hub needs to be powered before it can be discovered. This is often solved by using "regulator-always-on".
This driver is inspired by the Linux v6.1 driver. It only enables (or disables) the hub vdd (3v3) supply, so it can be enumerated. Scanning of the device tree is done in a similar manner to the sandbox, by the usb-uclass. DT part looks like:
&usbh_ehci { ... #address-cells = <1>; #size-cells = <0>; hub@1 { compatible = "usb424,2514"; reg = <1>; vdd-supply = <&v3v3>; }; };
When the bus gets probed, the driver is automatically probed/removed from the bus tree, as an example on stm32: STM32MP> usb start starting USB... STM32MP> dm tree Class Index Probed Driver Name ----------------------------------------------------------- usb 0 [ + ] ehci_generic | |-- usb@5800d000 usb_hub 0 [ + ] usb_onboard_hub | | `-- hub@1 usb_hub 1 [ + ] usb_hub | | `-- usb_hub
STM32MP> usb tree USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 2mA)
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com ---
common/Makefile | 1 + common/usb_onboard_hub.c | 62 +++++++++++++++++++++++++++++++++++ drivers/usb/Kconfig | 10 ++++++ drivers/usb/host/usb-uclass.c | 16 +++++---- 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 common/usb_onboard_hub.c
diff --git a/common/Makefile b/common/Makefile index 20addfb244c2..7789aab484fd 100644 --- a/common/Makefile +++ b/common/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_PHYLIB) += miiphyutil.o obj-$(CONFIG_USB_HOST) += usb.o usb_hub.o obj-$(CONFIG_USB_GADGET) += usb.o usb_hub.o obj-$(CONFIG_USB_STORAGE) += usb_storage.o +obj-$(CONFIG_USB_ONBOARD_HUB) += usb_onboard_hub.o
# others obj-$(CONFIG_CONSOLE_MUX) += iomux.o diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c new file mode 100644 index 000000000000..89e18a2ddad6 --- /dev/null +++ b/common/usb_onboard_hub.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for onboard USB hubs + * + * Copyright (C) 2022, STMicroelectronics - All Rights Reserved + * + * Mostly inspired by Linux kernel v6.1 onboard_usb_hub driver + */ + +#include <common.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <power/regulator.h> + +struct onboard_hub { + struct udevice *vdd; +}; + +static int usb_onboard_hub_probe(struct udevice *dev) +{ + struct onboard_hub *hub = dev_get_priv(dev); + int ret; + + ret = device_get_supply_regulator(dev, "vdd-supply", &hub->vdd); + if (ret) { + dev_err(dev, "can't get vdd-supply: %d\n", ret); + return ret; + } + + ret = regulator_set_enable_if_allowed(hub->vdd, true); + if (ret) + dev_err(dev, "can't enable vdd-supply: %d\n", ret); + + return ret; +} + +static int usb_onboard_hub_remove(struct udevice *dev) +{ + struct onboard_hub *hub = dev_get_priv(dev); + int ret; + + ret = regulator_set_enable_if_allowed(hub->vdd, false); + if (ret) + dev_err(dev, "can't disable vdd-supply: %d\n", ret); + + return ret; +} + +static const struct udevice_id usb_onboard_hub_ids[] = { + /* Use generic usbVID,PID dt-bindings (usb-device.yaml) */ + { .compatible = "usb424,2514" }, /* USB2514B USB 2.0 */ + { } +}; + +U_BOOT_DRIVER(usb_onboard_hub) = { + .name = "usb_onboard_hub", + .id = UCLASS_USB_HUB, + .probe = usb_onboard_hub_probe, + .remove = usb_onboard_hub_remove, + .of_match = usb_onboard_hub_ids, + .priv_auto = sizeof(struct onboard_hub), +}; diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 3afb45d5ccb2..d10ee6853d40 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -106,6 +106,16 @@ config USB_KEYBOARD Say Y here if you want to use a USB keyboard for U-Boot command line input.
+config USB_ONBOARD_HUB + bool "Onboard USB hub support" + depends on DM_USB + ---help--- + Say Y here if you want to support discrete onboard USB hubs that + don't require an additional control bus for initialization, but + need some non-trivial form of initialization, such as enabling a + power regulator. An example for such a hub is the Microchip + USB2514B. + if USB_KEYBOARD
config USB_KEYBOARD_FN_KEYS diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 060f3441df0c..f5dc93ffee39 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -271,19 +271,23 @@ int usb_init(void) /* init low_level USB */ printf("Bus %s: ", bus->name);
-#ifdef CONFIG_SANDBOX /* * For Sandbox, we need scan the device tree each time when we * start the USB stack, in order to re-create the emulated USB * devices and bind drivers for them before we actually do the * driver probe. + * + * For USB onboard HUB, we need to do some non-trivial init + * like enabling a power regulator, before enumeration. */ - ret = dm_scan_fdt_dev(bus); - if (ret) { - printf("Sandbox USB device scan failed (%d)\n", ret); - continue; + if (IS_ENABLED(CONFIG_SANDBOX) || + IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { + ret = dm_scan_fdt_dev(bus); + if (ret) { + printf("USB device scan from fdt failed (%d)", ret); + continue; + } } -#endif
ret = device_probe(bus); if (ret == -ENODEV) { /* No such device. */

HI Fabrice
On 12/12/22 11:44, Fabrice Gasnier wrote:
The main issue the driver addresses is that a USB hub needs to be powered before it can be discovered. This is often solved by using "regulator-always-on".
This driver is inspired by the Linux v6.1 driver. It only enables (or disables) the hub vdd (3v3) supply, so it can be enumerated. Scanning of the device tree is done in a similar manner to the sandbox, by the usb-uclass. DT part looks like:
&usbh_ehci { ... #address-cells = <1>; #size-cells = <0>; hub@1 { compatible = "usb424,2514"; reg = <1>; vdd-supply = <&v3v3>; }; };
When the bus gets probed, the driver is automatically probed/removed from the bus tree, as an example on stm32: STM32MP> usb start starting USB... STM32MP> dm tree Class Index Probed Driver Name
usb 0 [ + ] ehci_generic | |-- usb@5800d000 usb_hub 0 [ + ] usb_onboard_hub | | `-- hub@1 usb_hub 1 [ + ] usb_hub | | `-- usb_hub
STM32MP> usb tree USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 2mA)
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
common/Makefile | 1 + common/usb_onboard_hub.c | 62 +++++++++++++++++++++++++++++++++++ drivers/usb/Kconfig | 10 ++++++ drivers/usb/host/usb-uclass.c | 16 +++++---- 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 common/usb_onboard_hub.c
diff --git a/common/Makefile b/common/Makefile index 20addfb244c2..7789aab484fd 100644 --- a/common/Makefile +++ b/common/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_PHYLIB) += miiphyutil.o obj-$(CONFIG_USB_HOST) += usb.o usb_hub.o obj-$(CONFIG_USB_GADGET) += usb.o usb_hub.o obj-$(CONFIG_USB_STORAGE) += usb_storage.o +obj-$(CONFIG_USB_ONBOARD_HUB) += usb_onboard_hub.o
# others obj-$(CONFIG_CONSOLE_MUX) += iomux.o diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c new file mode 100644 index 000000000000..89e18a2ddad6 --- /dev/null +++ b/common/usb_onboard_hub.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-only +/*
- Driver for onboard USB hubs
- Copyright (C) 2022, STMicroelectronics - All Rights Reserved
- Mostly inspired by Linux kernel v6.1 onboard_usb_hub driver
- */
+#include <common.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <power/regulator.h>
+struct onboard_hub {
- struct udevice *vdd;
+};
+static int usb_onboard_hub_probe(struct udevice *dev) +{
- struct onboard_hub *hub = dev_get_priv(dev);
- int ret;
- ret = device_get_supply_regulator(dev, "vdd-supply", &hub->vdd);
- if (ret) {
dev_err(dev, "can't get vdd-supply: %d\n", ret);
return ret;
- }
- ret = regulator_set_enable_if_allowed(hub->vdd, true);
- if (ret)
dev_err(dev, "can't enable vdd-supply: %d\n", ret);
- return ret;
+}
+static int usb_onboard_hub_remove(struct udevice *dev) +{
- struct onboard_hub *hub = dev_get_priv(dev);
- int ret;
- ret = regulator_set_enable_if_allowed(hub->vdd, false);
- if (ret)
dev_err(dev, "can't disable vdd-supply: %d\n", ret);
- return ret;
+}
+static const struct udevice_id usb_onboard_hub_ids[] = {
- /* Use generic usbVID,PID dt-bindings (usb-device.yaml) */
- { .compatible = "usb424,2514" }, /* USB2514B USB 2.0 */
- { }
+};
+U_BOOT_DRIVER(usb_onboard_hub) = {
- .name = "usb_onboard_hub",
- .id = UCLASS_USB_HUB,
- .probe = usb_onboard_hub_probe,
- .remove = usb_onboard_hub_remove,
- .of_match = usb_onboard_hub_ids,
- .priv_auto = sizeof(struct onboard_hub),
+}; diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 3afb45d5ccb2..d10ee6853d40 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -106,6 +106,16 @@ config USB_KEYBOARD Say Y here if you want to use a USB keyboard for U-Boot command line input.
+config USB_ONBOARD_HUB
- bool "Onboard USB hub support"
- depends on DM_USB
- ---help---
Say Y here if you want to support discrete onboard USB hubs that
don't require an additional control bus for initialization, but
need some non-trivial form of initialization, such as enabling a
power regulator. An example for such a hub is the Microchip
USB2514B.
if USB_KEYBOARD
config USB_KEYBOARD_FN_KEYS diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 060f3441df0c..f5dc93ffee39 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -271,19 +271,23 @@ int usb_init(void) /* init low_level USB */ printf("Bus %s: ", bus->name);
-#ifdef CONFIG_SANDBOX /* * For Sandbox, we need scan the device tree each time when we * start the USB stack, in order to re-create the emulated USB * devices and bind drivers for them before we actually do the * driver probe.
*
* For USB onboard HUB, we need to do some non-trivial init
*/* like enabling a power regulator, before enumeration.
ret = dm_scan_fdt_dev(bus);
if (ret) {
printf("Sandbox USB device scan failed (%d)\n", ret);
continue;
if (IS_ENABLED(CONFIG_SANDBOX) ||
IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) {
ret = dm_scan_fdt_dev(bus);
if (ret) {
printf("USB device scan from fdt failed (%d)", ret);
continue;
}}
-#endif
ret = device_probe(bus); if (ret == -ENODEV) { /* No such device. */
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Hi Fabrice
On 12/12/22 11:44, Fabrice Gasnier wrote:
The main issue the driver addresses is that a USB hub needs to be powered before it can be discovered. This is often solved by using "regulator-always-on".
This driver is inspired by the Linux v6.1 driver. It only enables (or disables) the hub vdd (3v3) supply, so it can be enumerated. Scanning of the device tree is done in a similar manner to the sandbox, by the usb-uclass. DT part looks like:
&usbh_ehci { ... #address-cells = <1>; #size-cells = <0>; hub@1 { compatible = "usb424,2514"; reg = <1>; vdd-supply = <&v3v3>; }; };
When the bus gets probed, the driver is automatically probed/removed from the bus tree, as an example on stm32: STM32MP> usb start starting USB... STM32MP> dm tree Class Index Probed Driver Name
usb 0 [ + ] ehci_generic | |-- usb@5800d000 usb_hub 0 [ + ] usb_onboard_hub | | `-- hub@1 usb_hub 1 [ + ] usb_hub | | `-- usb_hub
STM32MP> usb tree USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 2mA)
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
common/Makefile | 1 + common/usb_onboard_hub.c | 62 +++++++++++++++++++++++++++++++++++ drivers/usb/Kconfig | 10 ++++++ drivers/usb/host/usb-uclass.c | 16 +++++---- 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 common/usb_onboard_hub.c
diff --git a/common/Makefile b/common/Makefile index 20addfb244c2..7789aab484fd 100644 --- a/common/Makefile +++ b/common/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_PHYLIB) += miiphyutil.o obj-$(CONFIG_USB_HOST) += usb.o usb_hub.o obj-$(CONFIG_USB_GADGET) += usb.o usb_hub.o obj-$(CONFIG_USB_STORAGE) += usb_storage.o +obj-$(CONFIG_USB_ONBOARD_HUB) += usb_onboard_hub.o
# others obj-$(CONFIG_CONSOLE_MUX) += iomux.o diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c new file mode 100644 index 000000000000..89e18a2ddad6 --- /dev/null +++ b/common/usb_onboard_hub.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-only +/*
- Driver for onboard USB hubs
- Copyright (C) 2022, STMicroelectronics - All Rights Reserved
- Mostly inspired by Linux kernel v6.1 onboard_usb_hub driver
- */
+#include <common.h> +#include <dm.h> +#include <dm/device_compat.h> +#include <power/regulator.h>
+struct onboard_hub {
- struct udevice *vdd;
+};
+static int usb_onboard_hub_probe(struct udevice *dev) +{
- struct onboard_hub *hub = dev_get_priv(dev);
- int ret;
- ret = device_get_supply_regulator(dev, "vdd-supply", &hub->vdd);
- if (ret) {
dev_err(dev, "can't get vdd-supply: %d\n", ret);
return ret;
- }
- ret = regulator_set_enable_if_allowed(hub->vdd, true);
- if (ret)
dev_err(dev, "can't enable vdd-supply: %d\n", ret);
- return ret;
+}
+static int usb_onboard_hub_remove(struct udevice *dev) +{
- struct onboard_hub *hub = dev_get_priv(dev);
- int ret;
- ret = regulator_set_enable_if_allowed(hub->vdd, false);
- if (ret)
dev_err(dev, "can't disable vdd-supply: %d\n", ret);
- return ret;
+}
+static const struct udevice_id usb_onboard_hub_ids[] = {
- /* Use generic usbVID,PID dt-bindings (usb-device.yaml) */
- { .compatible = "usb424,2514" }, /* USB2514B USB 2.0 */
- { }
+};
+U_BOOT_DRIVER(usb_onboard_hub) = {
- .name = "usb_onboard_hub",
- .id = UCLASS_USB_HUB,
- .probe = usb_onboard_hub_probe,
- .remove = usb_onboard_hub_remove,
- .of_match = usb_onboard_hub_ids,
- .priv_auto = sizeof(struct onboard_hub),
+}; diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 3afb45d5ccb2..d10ee6853d40 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -106,6 +106,16 @@ config USB_KEYBOARD Say Y here if you want to use a USB keyboard for U-Boot command line input.
+config USB_ONBOARD_HUB
- bool "Onboard USB hub support"
- depends on DM_USB
- ---help---
Say Y here if you want to support discrete onboard USB hubs that
don't require an additional control bus for initialization, but
need some non-trivial form of initialization, such as enabling a
power regulator. An example for such a hub is the Microchip
USB2514B.
if USB_KEYBOARD
config USB_KEYBOARD_FN_KEYS diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 060f3441df0c..f5dc93ffee39 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -271,19 +271,23 @@ int usb_init(void) /* init low_level USB */ printf("Bus %s: ", bus->name);
-#ifdef CONFIG_SANDBOX /* * For Sandbox, we need scan the device tree each time when we * start the USB stack, in order to re-create the emulated USB * devices and bind drivers for them before we actually do the * driver probe.
*
* For USB onboard HUB, we need to do some non-trivial init
*/* like enabling a power regulator, before enumeration.
ret = dm_scan_fdt_dev(bus);
if (ret) {
printf("Sandbox USB device scan failed (%d)\n", ret);
continue;
if (IS_ENABLED(CONFIG_SANDBOX) ||
IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) {
ret = dm_scan_fdt_dev(bus);
if (ret) {
printf("USB device scan from fdt failed (%d)", ret);
continue;
}}
-#endif
ret = device_probe(bus); if (ret == -ENODEV) { /* No such device. */
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Hi,
On 12/12/22 11:44, Fabrice Gasnier wrote:
The main issue the driver addresses is that a USB hub needs to be powered before it can be discovered. This is often solved by using "regulator-always-on".
This driver is inspired by the Linux v6.1 driver. It only enables (or disables) the hub vdd (3v3) supply, so it can be enumerated. Scanning of the device tree is done in a similar manner to the sandbox, by the usb-uclass. DT part looks like:
&usbh_ehci { ... #address-cells = <1>; #size-cells = <0>; hub@1 { compatible = "usb424,2514"; reg = <1>; vdd-supply = <&v3v3>; }; };
When the bus gets probed, the driver is automatically probed/removed from the bus tree, as an example on stm32: STM32MP> usb start starting USB... STM32MP> dm tree Class Index Probed Driver Name
usb 0 [ + ] ehci_generic | |-- usb@5800d000 usb_hub 0 [ + ] usb_onboard_hub | | `-- hub@1 usb_hub 1 [ + ] usb_hub | | `-- usb_hub
STM32MP> usb tree USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 2mA)
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
common/Makefile | 1 + common/usb_onboard_hub.c | 62 +++++++++++++++++++++++++++++++++++ drivers/usb/Kconfig | 10 ++++++ drivers/usb/host/usb-uclass.c | 16 +++++---- 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 common/usb_onboard_hub.c
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks Patrick

Hi Fabrice
On 1/3/23 17:34, Patrick DELAUNAY wrote:
Hi,
On 12/12/22 11:44, Fabrice Gasnier wrote:
The main issue the driver addresses is that a USB hub needs to be powered before it can be discovered. This is often solved by using "regulator-always-on".
This driver is inspired by the Linux v6.1 driver. It only enables (or disables) the hub vdd (3v3) supply, so it can be enumerated. Scanning of the device tree is done in a similar manner to the sandbox, by the usb-uclass. DT part looks like:
&usbh_ehci { ... #address-cells = <1>; #size-cells = <0>; hub@1 { compatible = "usb424,2514"; reg = <1>; vdd-supply = <&v3v3>; }; };
When the bus gets probed, the driver is automatically probed/removed from the bus tree, as an example on stm32: STM32MP> usb start starting USB... STM32MP> dm tree Class Index Probed Driver Name
usb 0 [ + ] ehci_generic | |-- usb@5800d000 usb_hub 0 [ + ] usb_onboard_hub | | `-- hub@1 usb_hub 1 [ + ] usb_hub | | `-- usb_hub
STM32MP> usb tree USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 2mA)
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
common/Makefile | 1 + common/usb_onboard_hub.c | 62 +++++++++++++++++++++++++++++++++++ drivers/usb/Kconfig | 10 ++++++ drivers/usb/host/usb-uclass.c | 16 +++++---- 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 common/usb_onboard_hub.c
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks Patrick
Applied on u-boot-stm32/master
Thanks

On 1/12/23 16:24, Patrice CHOTARD wrote:
Hi Fabrice
On 1/3/23 17:34, Patrick DELAUNAY wrote:
Hi,
On 12/12/22 11:44, Fabrice Gasnier wrote:
The main issue the driver addresses is that a USB hub needs to be powered before it can be discovered. This is often solved by using "regulator-always-on".
This driver is inspired by the Linux v6.1 driver. It only enables (or disables) the hub vdd (3v3) supply, so it can be enumerated. Scanning of the device tree is done in a similar manner to the sandbox, by the usb-uclass. DT part looks like:
&usbh_ehci { ... #address-cells = <1>; #size-cells = <0>; hub@1 { compatible = "usb424,2514"; reg = <1>; vdd-supply = <&v3v3>; }; };
When the bus gets probed, the driver is automatically probed/removed from the bus tree, as an example on stm32: STM32MP> usb start starting USB... STM32MP> dm tree Class Index Probed Driver Name
usb 0 [ + ] ehci_generic | |-- usb@5800d000 usb_hub 0 [ + ] usb_onboard_hub | | `-- hub@1 usb_hub 1 [ + ] usb_hub | | `-- usb_hub
STM32MP> usb tree USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 2mA)
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
common/Makefile | 1 + common/usb_onboard_hub.c | 62 +++++++++++++++++++++++++++++++++++ drivers/usb/Kconfig | 10 ++++++ drivers/usb/host/usb-uclass.c | 16 +++++---- 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 common/usb_onboard_hub.c
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks Patrick
Applied on u-boot-stm32/master
There is u-boot-usb tree for these patches and 1/3 should go through it.

On 12/12/22 11:44, Fabrice Gasnier wrote:
The main issue the driver addresses is that a USB hub needs to be powered before it can be discovered. This is often solved by using "regulator-always-on".
This driver is inspired by the Linux v6.1 driver. It only enables (or disables) the hub vdd (3v3) supply, so it can be enumerated. Scanning of the device tree is done in a similar manner to the sandbox, by the usb-uclass. DT part looks like:
&usbh_ehci { ... #address-cells = <1>; #size-cells = <0>; hub@1 { compatible = "usb424,2514"; reg = <1>; vdd-supply = <&v3v3>; }; };
When the bus gets probed, the driver is automatically probed/removed from the bus tree, as an example on stm32: STM32MP> usb start starting USB... STM32MP> dm tree Class Index Probed Driver Name
usb 0 [ + ] ehci_generic | |-- usb@5800d000 usb_hub 0 [ + ] usb_onboard_hub | | `-- hub@1 usb_hub 1 [ + ] usb_hub | | `-- usb_hub
STM32MP> usb tree USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 2mA)
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
Reviewed-by: Marek Vasut marex@denx.de

Activate the USB onboard HUB driver, that is used to enable the HUB supply on STM32MP15 EVAL, DK1 and DK2 boards. This avoids marking the 3v3 corresponding regulator as always-on.
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com ---
configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + 3 files changed, 3 insertions(+)
diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index 86ebbef0a6c8..4d2ac589931a 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -164,6 +164,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_defconfig b/configs/stm32mp15_defconfig index caa79e68834f..ccf65dd12223 100644 --- a/configs/stm32mp15_defconfig +++ b/configs/stm32mp15_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_trusted_defconfig b/configs/stm32mp15_trusted_defconfig index 3309c2e79246..a553038a42c5 100644 --- a/configs/stm32mp15_trusted_defconfig +++ b/configs/stm32mp15_trusted_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483

Hi Fabrice
On 12/12/22 11:44, Fabrice Gasnier wrote:
Activate the USB onboard HUB driver, that is used to enable the HUB supply on STM32MP15 EVAL, DK1 and DK2 boards. This avoids marking the 3v3 corresponding regulator as always-on.
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + 3 files changed, 3 insertions(+)
diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index 86ebbef0a6c8..4d2ac589931a 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -164,6 +164,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_defconfig b/configs/stm32mp15_defconfig index caa79e68834f..ccf65dd12223 100644 --- a/configs/stm32mp15_defconfig +++ b/configs/stm32mp15_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_trusted_defconfig b/configs/stm32mp15_trusted_defconfig index 3309c2e79246..a553038a42c5 100644 --- a/configs/stm32mp15_trusted_defconfig +++ b/configs/stm32mp15_trusted_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Hi Fabrice
On 12/12/22 11:44, Fabrice Gasnier wrote:
Activate the USB onboard HUB driver, that is used to enable the HUB supply on STM32MP15 EVAL, DK1 and DK2 boards. This avoids marking the 3v3 corresponding regulator as always-on.
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + 3 files changed, 3 insertions(+)
diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index 86ebbef0a6c8..4d2ac589931a 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -164,6 +164,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_defconfig b/configs/stm32mp15_defconfig index caa79e68834f..ccf65dd12223 100644 --- a/configs/stm32mp15_defconfig +++ b/configs/stm32mp15_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_trusted_defconfig b/configs/stm32mp15_trusted_defconfig index 3309c2e79246..a553038a42c5 100644 --- a/configs/stm32mp15_trusted_defconfig +++ b/configs/stm32mp15_trusted_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Hi,
On 12/12/22 11:44, Fabrice Gasnier wrote:
Activate the USB onboard HUB driver, that is used to enable the HUB supply on STM32MP15 EVAL, DK1 and DK2 boards. This avoids marking the 3v3 corresponding regulator as always-on.
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + 3 files changed, 3 insertions(+)
diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index 86ebbef0a6c8..4d2ac589931a 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -164,6 +164,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_defconfig b/configs/stm32mp15_defconfig index caa79e68834f..ccf65dd12223 100644 --- a/configs/stm32mp15_defconfig +++ b/configs/stm32mp15_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_trusted_defconfig b/configs/stm32mp15_trusted_defconfig index 3309c2e79246..a553038a42c5 100644 --- a/configs/stm32mp15_trusted_defconfig +++ b/configs/stm32mp15_trusted_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks Patrick

HI Fabrice
On 12/12/22 11:44, Fabrice Gasnier wrote:
Activate the USB onboard HUB driver, that is used to enable the HUB supply on STM32MP15 EVAL, DK1 and DK2 boards. This avoids marking the 3v3 corresponding regulator as always-on.
Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + 3 files changed, 3 insertions(+)
diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig index 86ebbef0a6c8..4d2ac589931a 100644 --- a/configs/stm32mp15_basic_defconfig +++ b/configs/stm32mp15_basic_defconfig @@ -164,6 +164,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_defconfig b/configs/stm32mp15_defconfig index caa79e68834f..ccf65dd12223 100644 --- a/configs/stm32mp15_defconfig +++ b/configs/stm32mp15_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483 diff --git a/configs/stm32mp15_trusted_defconfig b/configs/stm32mp15_trusted_defconfig index 3309c2e79246..a553038a42c5 100644 --- a/configs/stm32mp15_trusted_defconfig +++ b/configs/stm32mp15_trusted_defconfig @@ -140,6 +140,7 @@ CONFIG_USB=y CONFIG_DM_USB_GADGET=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y +CONFIG_USB_ONBOARD_HUB=y CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="STMicroelectronics" CONFIG_USB_GADGET_VENDOR_NUM=0x0483
Applied on u-boot-stm32/master
Thanks

Add support for USB2514B onboard hub on stm32mp157c EV1 board. The HUB is supplied by a 3v3 PMIC regulator.
[backport from linux ad9591b01d24] Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com ---
arch/arm/dts/stm32mp157c-ev1.dts | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/arm/dts/stm32mp157c-ev1.dts b/arch/arm/dts/stm32mp157c-ev1.dts index d142dd30e16b..07bcd7c50672 100644 --- a/arch/arm/dts/stm32mp157c-ev1.dts +++ b/arch/arm/dts/stm32mp157c-ev1.dts @@ -362,6 +362,14 @@ &usbh_ehci { phys = <&usbphyc_port0>; status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + /* onboard HUB */ + hub@1 { + compatible = "usb424,2514"; + reg = <1>; + vdd-supply = <&v3v3>; + }; };
&usbotg_hs {

Hi Fabrice
On 12/12/22 11:44, Fabrice Gasnier wrote:
Add support for USB2514B onboard hub on stm32mp157c EV1 board. The HUB is supplied by a 3v3 PMIC regulator.
[backport from linux ad9591b01d24] Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
arch/arm/dts/stm32mp157c-ev1.dts | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/arm/dts/stm32mp157c-ev1.dts b/arch/arm/dts/stm32mp157c-ev1.dts index d142dd30e16b..07bcd7c50672 100644 --- a/arch/arm/dts/stm32mp157c-ev1.dts +++ b/arch/arm/dts/stm32mp157c-ev1.dts @@ -362,6 +362,14 @@ &usbh_ehci { phys = <&usbphyc_port0>; status = "okay";
- #address-cells = <1>;
- #size-cells = <0>;
- /* onboard HUB */
- hub@1 {
compatible = "usb424,2514";
reg = <1>;
vdd-supply = <&v3v3>;
- };
};
&usbotg_hs {
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Hi Fabrice
On 12/12/22 11:44, Fabrice Gasnier wrote:
Add support for USB2514B onboard hub on stm32mp157c EV1 board. The HUB is supplied by a 3v3 PMIC regulator.
[backport from linux ad9591b01d24] Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
arch/arm/dts/stm32mp157c-ev1.dts | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/arm/dts/stm32mp157c-ev1.dts b/arch/arm/dts/stm32mp157c-ev1.dts index d142dd30e16b..07bcd7c50672 100644 --- a/arch/arm/dts/stm32mp157c-ev1.dts +++ b/arch/arm/dts/stm32mp157c-ev1.dts @@ -362,6 +362,14 @@ &usbh_ehci { phys = <&usbphyc_port0>; status = "okay";
- #address-cells = <1>;
- #size-cells = <0>;
- /* onboard HUB */
- hub@1 {
compatible = "usb424,2514";
reg = <1>;
vdd-supply = <&v3v3>;
- };
};
&usbotg_hs {
Reviewed-by: Patrice Chotard patrice.chotard@foss.st.com
Thanks Patrice

Hi,
On 12/12/22 11:44, Fabrice Gasnier wrote:
Add support for USB2514B onboard hub on stm32mp157c EV1 board. The HUB is supplied by a 3v3 PMIC regulator.
[backport from linux ad9591b01d24] Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
arch/arm/dts/stm32mp157c-ev1.dts | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/arm/dts/stm32mp157c-ev1.dts b/arch/arm/dts/stm32mp157c-ev1.dts index d142dd30e16b..07bcd7c50672 100644 --- a/arch/arm/dts/stm32mp157c-ev1.dts +++ b/arch/arm/dts/stm32mp157c-ev1.dts @@ -362,6 +362,14 @@ &usbh_ehci { phys = <&usbphyc_port0>; status = "okay";
#address-cells = <1>;
#size-cells = <0>;
/* onboard HUB */
hub@1 {
compatible = "usb424,2514";
reg = <1>;
vdd-supply = <&v3v3>;
}; };
&usbotg_hs {
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com Tested-by: Patrick Delaunay patrick.delaunay@foss.st.com
I just test the supply regulator support on EV1 when the port is used
and the regulator is no more always-on.
with modification in ./arch/arm/dts/stm32mp157c-ed1.dts:224
v3v3: buck4 { regulator-name = "v3v3"; - regulator-always-on;
Thanks Patrick

Hi Fabrice
On 12/12/22 11:44, Fabrice Gasnier wrote:
Add support for USB2514B onboard hub on stm32mp157c EV1 board. The HUB is supplied by a 3v3 PMIC regulator.
[backport from linux ad9591b01d24] Signed-off-by: Fabrice Gasnier fabrice.gasnier@foss.st.com
arch/arm/dts/stm32mp157c-ev1.dts | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/arm/dts/stm32mp157c-ev1.dts b/arch/arm/dts/stm32mp157c-ev1.dts index d142dd30e16b..07bcd7c50672 100644 --- a/arch/arm/dts/stm32mp157c-ev1.dts +++ b/arch/arm/dts/stm32mp157c-ev1.dts @@ -362,6 +362,14 @@ &usbh_ehci { phys = <&usbphyc_port0>; status = "okay";
- #address-cells = <1>;
- #size-cells = <0>;
- /* onboard HUB */
- hub@1 {
compatible = "usb424,2514";
reg = <1>;
vdd-supply = <&v3v3>;
- };
};
&usbotg_hs {
Applied on u-boot-stm32/master
Thanks

On 12/12/22 11:44, Fabrice Gasnier wrote:
This series adds a driver to support USB onboard HUB, inspired by Linux onboard hub driver.
Purpose is to manage the power supply regulator on STM32 boards, for low power use case in Linux. U-boot driver allows to benefit of the device tree part to supply the HUB when need, instead using an always-on regulator.
It aligns the relevant DT part from emerging Linux v6.2. It also adds the relevant default configuration on stm32mp15.
Fabrice Gasnier (3): usb: onboard-hub: add driver to manage onboard hub supplies configs: stm32: enable USB onboard HUB driver ARM: dts: stm32: add support for USB2514B onboard hub on stm32mp157c-ev1
arch/arm/dts/stm32mp157c-ev1.dts | 8 ++++ common/Makefile | 1 + common/usb_onboard_hub.c | 62 +++++++++++++++++++++++++++++ configs/stm32mp15_basic_defconfig | 1 + configs/stm32mp15_defconfig | 1 + configs/stm32mp15_trusted_defconfig | 1 + drivers/usb/Kconfig | 10 +++++ drivers/usb/host/usb-uclass.c | 16 +++++--- 8 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 common/usb_onboard_hub.c
+CC Michal

On 12/12/22 14:19, Marek Vasut wrote:
CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
On 12/12/22 11:44, Fabrice Gasnier wrote:
This series adds a driver to support USB onboard HUB, inspired by Linux onboard hub driver.
Purpose is to manage the power supply regulator on STM32 boards, for low power use case in Linux. U-boot driver allows to benefit of the device tree part to supply the HUB when need, instead using an always-on regulator.
It aligns the relevant DT part from emerging Linux v6.2. It also adds the relevant default configuration on stm32mp15.
Not sure why v6.2 is relevant. That changes in connection to usb hubs/companion hubs/peer hubs have been merged some time ago.
It would be lovely to see also peer hubs part in u-boot too but nothing wrong with this part.
Acked-by: Michal Simek michal.simek@amd.com
Thanks, Michal
participants (5)
-
Fabrice Gasnier
-
Marek Vasut
-
Michal Simek
-
Patrice CHOTARD
-
Patrick DELAUNAY