Skip to contentSkip to conversation

usb: bcma: control VBUS via a regulator

PATCH Superseded Rosen Penev 3 participants 6 messages Sep 20 – Sep 21

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover usb: bcma: control VBUS via a regulator

bcma-hcd currently drives the USB power line by grabbing the undocumented "vcc-gpio" property from the controller node and poking it through gpiolib. Besides relying on a non-standard binding, this cannot work on boards such as the NETGEAR R7000 and R8000 where one chipcommon GPIO powers both the USB2 and USB3 cores: the two controllers each request that GPIO exclusively, so the second one fails with -EBUSY and its port stays dead.

Instead, switch the driver to the standard regulator interface and express the power rails as regulator-fixed nodes bound to the chipcommon GPIOs. The regulator core reference-counts enable/disable requests, letting both controllers share one GPIO without conflicts.

Rosen Penev (2):
usb: bcma: control VBUS via a regulator instead of a GPIO
ARM: dts: broadcom: model USB VBUS power with regulator-fixed

 .../broadcom/bcm4708-buffalo-wxr-1750dhp.dts  | 14 +++++-
 .../bcm4708-buffalo-wzr-1166dhp-common.dtsi   | 25 ++++++++++-
 .../broadcom/bcm4708-buffalo-wzr-1750dhp.dts  | 25 ++++++++++-
 .../broadcom/bcm4708-linksys-ea6300-v1.dts    | 14 +++++-
 .../broadcom/bcm4708-linksys-ea6500-v2.dts    | 14 +++++-
 .../dts/broadcom/bcm4708-netgear-r6250.dts    | 14 +++++-
 .../dts/broadcom/bcm4708-netgear-r6300-v2.dts | 14 +++++-
 .../dts/broadcom/bcm47081-luxul-xwr-1200.dts  | 14 +++++-
 .../broadcom/bcm47081-tplink-archer-c5-v2.dts | 14 +++++-
 .../dts/broadcom/bcm4709-asus-rt-ac3200.dts   | 14 +++++-
 .../broadcom/bcm4709-buffalo-wxr-1900dhp.dts  | 14 +++++-
 .../dts/broadcom/bcm4709-linksys-ea9200.dts   | 26 ++++++++++-
 .../dts/broadcom/bcm4709-netgear-r7000.dts    | 16 ++++++-
 .../dts/broadcom/bcm4709-netgear-r8000.dts    | 16 ++++++-
 .../broadcom/bcm4709-tplink-archer-c9-v1.dts  | 26 ++++++++++-
 .../dts/broadcom/bcm47094-asus-rt-ac3100.dtsi | 14 +++++-
 .../dts/broadcom/bcm47094-asus-rt-ac5300.dts  | 14 +++++-
 .../dts/broadcom/bcm47094-dlink-dir-885l.dts  | 14 +++++-
 .../dts/broadcom/bcm47094-dlink-dir-890l.dts  | 26 ++++++++++-
 .../broadcom/bcm47094-linksys-panamera.dts    | 26 ++++++++++-
 .../dts/broadcom/bcm47094-luxul-abr-4500.dts  | 14 +++++-
 .../dts/broadcom/bcm47094-luxul-xbr-4500.dts  | 14 +++++-
 .../dts/broadcom/bcm47094-luxul-xwr-3100.dts  | 14 +++++-
 .../broadcom/bcm47094-luxul-xwr-3150-v1.dts   | 14 +++++-
 .../arm/boot/dts/broadcom/bcm947189acdbmr.dts | 14 +++++-
 drivers/usb/host/bcma-hcd.c                   | 45 +++++++++++++------
 26 files changed, 422 insertions(+), 47 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/2 usb: bcma: control VBUS via a regulator instead of a GPIO

bcma-hcd drives the USB power line by grabbing the undocumented "vcc-gpio" from the controller node and poking it through gpiolib. Besides relying on a non-standard binding, this cannot work on boards such as the NETGEAR R7000 and R8000 where one chipcommon GPIO powers both the USB2 and USB3 cores: the two controllers each request that GPIO exclusively, so the second one fails with -EBUSY and its port stays dead.

Use the standard regulator interface instead. Each core obtains its (shared) VBUS supply through devm_regulator_get_optional() and the regulator core reference-counts the enable/disable requests, allowing both controllers to drive one GPIO without conflicts.

Assisted-by LLM
---
 drivers/usb/host/bcma-hcd.c | 45 +++++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 14 deletions(-)
drivers/usb/host/bcma-hcd.c +31 -14
index 519386255886..394ba9e5a7f7 100644
@@ -20,12 +20,12 @@
  */
 #include <linux/bcma/bcma.h>
 #include <linux/delay.h>
-#include <linux/gpio/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/of.h>
 #include <linux/of_platform.h>
+#include <linux/regulator/consumer.h>
 #include <linux/usb/ehci_pdriver.h>
 #include <linux/usb/ohci_pdriver.h>
 
@@ -40,7 +40,7 @@ struct bcma_hcd_device {
 	struct bcma_device *core;
 	struct platform_device *ehci_dev;
 	struct platform_device *ohci_dev;
-	struct gpio_desc *gpio_desc;
+	struct regulator *regulator;
 };
 
 /* Wait for bitmask in a register to get set or cleared.
@@ -280,14 +280,20 @@ static int bcma_hcd_usb20_ns_init(struct bcma_hcd_device *bcma_hcd)
 	return 0;
 }
 
-static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val)
+static int bcma_hci_platform_power(struct bcma_device *dev, bool on)
 {
 	struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
+	int err;
+
+	if (!usb_dev->regulator)
+		return 0;
 
-	if (!usb_dev->gpio_desc)
-		return;
+	if (on)
+		err = regulator_enable(usb_dev->regulator);
+	else
+		err = regulator_disable(usb_dev->regulator);
 
-	gpiod_set_value(usb_dev->gpio_desc, val);
+	return err;
 }
 
 static const struct usb_ehci_pdata ehci_pdata = {
@@ -405,11 +411,14 @@ static int bcma_hcd_probe(struct bcma_device *core)
 		return -ENOMEM;
 	usb_dev->core = core;
 
-	usb_dev->gpio_desc = devm_gpiod_get_optional(&core->dev, "vcc",
-						     GPIOD_OUT_HIGH);
-	if (IS_ERR(usb_dev->gpio_desc))
-		return dev_err_probe(&core->dev, PTR_ERR(usb_dev->gpio_desc),
-				     "error obtaining VCC GPIO");
+	usb_dev->regulator = devm_regulator_get_optional(&core->dev, "vbus");
+	if (IS_ERR(usb_dev->regulator)) {
+		return PTR_ERR(usb_dev->regulator);
+
+	err = regulator_enable(usb_dev->regulator);
+	if (err)
+		return dev_err_probe(&core->dev, err,
+				     "error enabling VCC regulator");
 
 	switch (core->id.id) {
 	case BCMA_CORE_USB20_HOST:
@@ -452,7 +461,7 @@ static void bcma_hcd_remove(struct bcma_device *dev)
 
 static void bcma_hcd_shutdown(struct bcma_device *dev)
 {
-	bcma_hci_platform_power_gpio(dev, false);
+	bcma_hci_platform_power(dev, false);
 	bcma_core_disable(dev, 0);
 }
 
@@ -460,7 +469,11 @@ static void bcma_hcd_shutdown(struct bcma_device *dev)
 
 static int bcma_hcd_suspend(struct bcma_device *dev)
 {
-	bcma_hci_platform_power_gpio(dev, false);
+	int err;
+
+	err = bcma_hci_platform_power(dev, false);
+	if (err)
+		return err;
 	bcma_core_disable(dev, 0);
 
 	return 0;
@@ -468,7 +481,11 @@ static int bcma_hcd_suspend(struct bcma_device *dev)
 
 static int bcma_hcd_resume(struct bcma_device *dev)
 {
-	bcma_hci_platform_power_gpio(dev, true);
+	int err;
+
+	err = bcma_hci_platform_power(dev, true);
+	if (err)
+		return err;
 	bcma_core_enable(dev, 0);
 
 	return 0;
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH 1/2] usb: bcma: control VBUS via a regulator instead of a GPIO

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Critical] usb: bcma: ABI breakage by removing vcc-gpio DT backward compatibility - [High] usb: bcma…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] usb: bcma: ABI breakage by removing vcc-gpio DT backward compatibility
- [High] usb: bcma: fatal probe failure on missing optional regulator
- [High] usb: bcma: regulator enable count leak on error and remove
- [Low] build: syntax error due to missing closing brace
--

commit 2da0c63e158c66b33d97e363d8f72cf580a7db29
Author: Rosen Penev <[email protected]>

usb: bcma: control VBUS via a regulator instead of a GPIO

This commit replaces the custom vcc-gpio GPIO driving in bcma-hcd with the standard regulator framework. It uses devm_regulator_get_optional so shared regulators are properly reference-counted, avoiding conflicts on boards where multiple controllers share the same GPIO.

Quoted 4 lines
drivers/usb/host/bcma-hcd.c +0 -0
index 519386255886c..394ba9e5a7f77 100644

[ ... ]

drivers/usb/host/bcma-hcd.c static int bcma_hcd_probe(struct bcma_device *core) · line 414

Quoted 10 lines
drivers/usb/host/bcma-hcd.c +1 -5
@@ -405,11 +411,14 @@ static int bcma_hcd_probe(struct bcma_device *core)
 		return -ENOMEM;
 	usb_dev->core = core;
 
-	usb_dev->gpio_desc = devm_gpiod_get_optional(&core->dev, "vcc",
-						     GPIOD_OUT_HIGH);
-	if (IS_ERR(usb_dev->gpio_desc))
-		return dev_err_probe(&core->dev, PTR_ERR(usb_dev->gpio_desc),
-				     "error obtaining VCC GPIO");
+	usb_dev->regulator = devm_regulator_get_optional(&core->dev, "vbus");

[Severity: Critical]
Does replacing the vcc property with vbus drop support for existing devices using older Device Trees? It seems like this might break backward compatibility for any board still relying on the legacy vcc-gpio binding.

drivers/usb/host/bcma-hcd.c static int bcma_hcd_probe(struct bcma_device *core) · line 416

Quoted 2 lines
drivers/usb/host/bcma-hcd.c +2 -0
+	if (IS_ERR(usb_dev->regulator)) {
+		return PTR_ERR(usb_dev->regulator);

[Severity: High]
Does this unconditionally fail the probe when an optional regulator is not present? devm_regulator_get_optional() returns -ENODEV when no supply is defined in the Device Tree, which seems like it would cause this to return early instead of treating the regulator as optional.

If -ENODEV is handled to allow the probe to continue, does usb_dev->regulator need to be set to NULL so an error pointer is not passed to regulator_enable() below?

[Severity: Low]
Is there a missing closing brace here? It looks like this will cause a compilation error.

Quoted 8 lines
drivers/usb/host/bcma-hcd.c +5 -0
+
+	err = regulator_enable(usb_dev->regulator);
+	if (err)
+		return dev_err_probe(&core->dev, err,
+				     "error enabling VCC regulator");
 
 	switch (core->id.id) {
 	case BCMA_CORE_USB20_HOST:

[ ... ]

drivers/usb/host/bcma-hcd.c static void bcma_hcd_remove(struct bcma_device *dev)

Quoted 1 line
drivers/usb/host/bcma-hcd.c +0 -0
@@ -452,7 +461,7 @@ static void bcma_hcd_remove(struct bcma_device *dev)

[Severity: High]
If the probe fails later, or when the device is unbound via bcma_hcd_remove(), does this leak the regulator enable count? It appears regulator_disable() is not called in the probe error paths or during removal.

Quoted 7 lines
drivers/usb/host/bcma-hcd.c +1 -1
 static void bcma_hcd_shutdown(struct bcma_device *dev)
 {
-	bcma_hci_platform_power_gpio(dev, false);
+	bcma_hci_platform_power(dev, false);
 	bcma_core_disable(dev, 0);
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw

Re: [PATCH 1/2] usb: bcma: control VBUS via a regulator instead of a GPIO

In reply to Rosen Penev

niedz., 20 wrz 2026 o 23:14 Rosen Penev <[email protected]> napisał(a):

Quoted 8 lines

bcma-hcd drives the USB power line by grabbing the undocumented "vcc-gpio" from the controller node and poking it through gpiolib. Besides relying on a non-standard binding, this cannot work on boards such as the NETGEAR R7000 and R8000 where one chipcommon GPIO powers both the USB2 and USB3 cores: the two controllers each request that GPIO exclusively, so the second one fails with -EBUSY and its port stays dead.

Quoted 4 lines

Use the standard regulator interface instead. Each core obtains its (shared) VBUS supply through devm_regulator_get_optional() and the regulator core reference-counts the enable/disable requests, allowing both controllers to drive one GPIO without conflicts.

You should add support for VBUS without dropping "vcc-gpio" for now. Deprecate it. Give it some time and then submit a patch to drop it.

This patch as it stands also breaks bisectability (because it drops "vcc-gpio" before switching to VBUS.

Signature · 1 line
Rafał
#4 lore raw

PATCH 2/2 ARM: dts: broadcom: model USB VBUS power with regulator-fixed

In reply to Rosen Penev

Replace the undocumented "vcc-gpio" property on the usb2/usb3 controller nodes with the standard vbus-supply/regulator-fixed model. Boards now declare a regulator bound to the chipcommon GPIO that bcma-hcd used to poke directly, one per power rail.

Polarity is preserved: rails that used a GPIO_ACTIVE_HIGH are marked enable-active-high, while the Buffalo usb3 rails keep GPIO_ACTIVE_LOW and rely on the binding's active-low default. regulator-boot-on mirrors the rail being left enabled by CFE so the power line is never toggled during probe.

Assisted-by LLM
---
 .../broadcom/bcm4708-buffalo-wxr-1750dhp.dts  | 14 +++++++++-
 .../bcm4708-buffalo-wzr-1166dhp-common.dtsi   | 25 ++++++++++++++++--
 .../broadcom/bcm4708-buffalo-wzr-1750dhp.dts  | 25 ++++++++++++++++--
 .../broadcom/bcm4708-linksys-ea6300-v1.dts    | 14 +++++++++-
 .../broadcom/bcm4708-linksys-ea6500-v2.dts    | 14 +++++++++-
 .../dts/broadcom/bcm4708-netgear-r6250.dts    | 14 +++++++++-
 .../dts/broadcom/bcm4708-netgear-r6300-v2.dts | 14 +++++++++-
 .../dts/broadcom/bcm47081-luxul-xwr-1200.dts  | 14 +++++++++-
 .../broadcom/bcm47081-tplink-archer-c5-v2.dts | 14 +++++++++-
 .../dts/broadcom/bcm4709-asus-rt-ac3200.dts   | 14 +++++++++-
 .../broadcom/bcm4709-buffalo-wxr-1900dhp.dts  | 14 +++++++++-
 .../dts/broadcom/bcm4709-linksys-ea9200.dts   | 26 +++++++++++++++++--
 .../dts/broadcom/bcm4709-netgear-r7000.dts    | 16 ++++++++++--
 .../dts/broadcom/bcm4709-netgear-r8000.dts    | 16 ++++++++++--
 .../broadcom/bcm4709-tplink-archer-c9-v1.dts  | 26 +++++++++++++++++--
 .../dts/broadcom/bcm47094-asus-rt-ac3100.dtsi | 14 +++++++++-
 .../dts/broadcom/bcm47094-asus-rt-ac5300.dts  | 14 +++++++++-
 .../dts/broadcom/bcm47094-dlink-dir-885l.dts  | 14 +++++++++-
 .../dts/broadcom/bcm47094-dlink-dir-890l.dts  | 26 +++++++++++++++++--
 .../broadcom/bcm47094-linksys-panamera.dts    | 26 +++++++++++++++++--
 .../dts/broadcom/bcm47094-luxul-abr-4500.dts  | 14 +++++++++-
 .../dts/broadcom/bcm47094-luxul-xbr-4500.dts  | 14 +++++++++-
 .../dts/broadcom/bcm47094-luxul-xwr-3100.dts  | 14 +++++++++-
 .../broadcom/bcm47094-luxul-xwr-3150-v1.dts   | 14 +++++++++-
 .../arm/boot/dts/broadcom/bcm947189acdbmr.dts | 14 +++++++++-
 25 files changed, 391 insertions(+), 33 deletions(-)
arch/arm/boot/dts/broadcom/bcm4708-buffalo-wxr-1750dhp.dts +13 -1
index f5c95c9a712e..1bedd74e40d0 100644
@@ -129,8 +129,20 @@ port@4 {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 10 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 10 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3_phy {
arch/arm/boot/dts/broadcom/bcm4708-buffalo-wzr-1166dhp-common.dtsi +23 -2
index 9f9084269ef5..faed5e0895c6 100644
@@ -138,12 +138,33 @@ button-eject {
 	};
 };
 
+/ {
+	usb2_power: regulator-usb2 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb2-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+
+	usb3_power: regulator-usb3 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb3-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 10 GPIO_ACTIVE_LOW>;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb2_power>;
 };
 
 &usb3 {
-	vcc-gpio = <&chipcommon 10 GPIO_ACTIVE_LOW>;
+	vbus-supply = <&usb3_power>;
 };
 
 &spi_nor {
arch/arm/boot/dts/broadcom/bcm4708-buffalo-wzr-1750dhp.dts +23 -2
index 95ef6ca7210b..6dcfb273329d 100644
@@ -134,12 +134,33 @@ button-eject {
 	};
 };
 
+/ {
+	usb2_power: regulator-usb2 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb2-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+
+	usb3_power: regulator-usb3 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb3-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 10 GPIO_ACTIVE_LOW>;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb2_power>;
 };
 
 &usb3 {
-	vcc-gpio = <&chipcommon 10 GPIO_ACTIVE_LOW>;
+	vbus-supply = <&usb3_power>;
 };
 
 &spi_nor {
arch/arm/boot/dts/broadcom/bcm4708-linksys-ea6300-v1.dts +13 -1
index 03d5546a147c..41a02961763e 100644
@@ -47,6 +47,18 @@ &usb3_phy {
 	status = "okay";
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 10 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 10 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
arch/arm/boot/dts/broadcom/bcm4708-linksys-ea6500-v2.dts +13 -1
index ad246f9a734a..31aa34288d18 100644
@@ -44,6 +44,18 @@ &usb3_phy {
 	status = "okay";
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 10 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 10 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
arch/arm/boot/dts/broadcom/bcm4708-netgear-r6250.dts +13 -1
index 2bdbc7d18b0e..f8c8bb9e9661 100644
@@ -83,8 +83,20 @@ button-restart {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &spi_nor {
arch/arm/boot/dts/broadcom/bcm4708-netgear-r6300-v2.dts +13 -1
index 55f0d9e90d5f..4c9b11c798bc 100644
@@ -88,5 +88,17 @@ &usb3_phy {
 };
 
 &usb3 {
-	vcc-gpio = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
+};
+
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
 };
arch/arm/boot/dts/broadcom/bcm47081-luxul-xwr-1200.dts +13 -1
index 73ff1694a4a0..87c4766d181c 100644
@@ -106,8 +106,20 @@ button-restart {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &gmac0 {
arch/arm/boot/dts/broadcom/bcm47081-tplink-archer-c5-v2.dts +13 -1
index b6a5886698b2..3673d4b3c2b6 100644
@@ -108,6 +108,18 @@ partition-file-system {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
arch/arm/boot/dts/broadcom/bcm4709-asus-rt-ac3200.dts +13 -1
index 3da2daee0c84..e97a41d1a400 100644
@@ -141,8 +141,20 @@ port@4 {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3_phy {
arch/arm/boot/dts/broadcom/bcm4709-buffalo-wxr-1900dhp.dts +13 -1
index b7cd2faa30ce..66c141ef9f6d 100644
@@ -119,8 +119,20 @@ button-eject {
 };
 
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 13 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 13 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &spi_nor {
arch/arm/boot/dts/broadcom/bcm4709-linksys-ea9200.dts +24 -2
index 37593e7582ba..4d2663627d08 100644
@@ -154,12 +154,34 @@ &usb3_phy {
 	status = "okay";
 };
 
+/ {
+	usb2_power: regulator-usb2 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb2-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 13 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+
+	usb3_power: regulator-usb3 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb3-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 14 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpios = <&chipcommon 13 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb2_power>;
 };
 
 &usb3 {
-	vcc-gpios = <&chipcommon 14 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb3_power>;
 };
 
 &gmac2 {
arch/arm/boot/dts/broadcom/bcm4709-netgear-r7000.dts +14 -2
index 24ba8f8f9bf3..1911daa84b08 100644
@@ -93,12 +93,24 @@ button-restart {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3 {
-	vcc-gpio = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3_phy {
arch/arm/boot/dts/broadcom/bcm4709-netgear-r8000.dts +14 -2
index a4b135d37659..5940f052b77f 100644
@@ -186,12 +186,24 @@ wifi@0,0 {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3 {
-	vcc-gpio = <&chipcommon 0 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3_phy {
arch/arm/boot/dts/broadcom/bcm4709-tplink-archer-c9-v1.dts +24 -2
index 5a8b2b1567e6..69ff4f14b89e 100644
@@ -92,12 +92,34 @@ button-restart {
 	};
 };
 
+/ {
+	usb2_power: regulator-usb2 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb2-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 13 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+
+	usb3_power: regulator-usb3 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb3-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 12 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 13 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb2_power>;
 };
 
 &usb3 {
-	vcc-gpio = <&chipcommon 12 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb3_power>;
 };
 
 &spi_nor {
arch/arm/boot/dts/broadcom/bcm47094-asus-rt-ac3100.dtsi +13 -1
index 2d2e7e581291..29f54169d072 100644
@@ -166,8 +166,20 @@ port@8 {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3_phy {
arch/arm/boot/dts/broadcom/bcm47094-asus-rt-ac5300.dts +13 -1
index 8bf623c67de0..0906c0ef8182 100644
@@ -150,8 +150,20 @@ port@4 {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 9 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3_phy {
arch/arm/boot/dts/broadcom/bcm47094-dlink-dir-885l.dts +13 -1
index c5099defe9f9..046bca843e29 100644
@@ -117,8 +117,20 @@ button-restart {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &gmac0 {
arch/arm/boot/dts/broadcom/bcm47094-dlink-dir-890l.dts +24 -2
index 944d592dee2c..1816f636b293 100644
@@ -157,12 +157,34 @@ firmware@0 {
 	};
 };
 
+/ {
+	usb2_power: regulator-usb2 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb2-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 21 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+
+	usb3_power: regulator-usb3 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb3-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpios = <&chipcommon 21 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb2_power>;
 };
 
 &usb3 {
-	vcc-gpios = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb3_power>;
 };
 
 &usb3_phy {
arch/arm/boot/dts/broadcom/bcm47094-linksys-panamera.dts +24 -2
index bdbd0f097925..b62ac448fe2d 100644
@@ -197,12 +197,34 @@ fixed-link {
 	};
 };
 
+/ {
+	usb2_power: regulator-usb2 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb2-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 13 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+
+	usb3_power: regulator-usb3 {
+		compatible = "regulator-fixed";
+		regulator-name = "usb3-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 14 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 13 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb2_power>;
 };
 
 &usb3 {
-	vcc-gpio = <&chipcommon 14 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb3_power>;
 };
 
 &srab {
arch/arm/boot/dts/broadcom/bcm47094-luxul-abr-4500.dts +13 -1
index e374062eb5b7..fbd362991e43 100644
@@ -61,8 +61,20 @@ button-restart {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &gmac0 {
arch/arm/boot/dts/broadcom/bcm47094-luxul-xbr-4500.dts +13 -1
index cf95af9db1e6..f1f099a90997 100644
@@ -61,8 +61,20 @@ button-restart {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &gmac0 {
arch/arm/boot/dts/broadcom/bcm47094-luxul-xwr-3100.dts +13 -1
index 4d0ba315a204..9420ae1367d8 100644
@@ -101,8 +101,20 @@ button-restart {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &gmac0 {
arch/arm/boot/dts/broadcom/bcm47094-luxul-xwr-3150-v1.dts +13 -1
index 8e487f60a2cc..f4f718b52c6f 100644
@@ -97,8 +97,20 @@ wifi@0,0 {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb3 {
-	vcc-gpio = <&chipcommon 18 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
 
 &usb3_phy {
arch/arm/boot/dts/broadcom/bcm947189acdbmr.dts +13 -1
index 0b8727ae6f16..fcb0bb9f3942 100644
@@ -91,6 +91,18 @@ wifi@0,1,0 {
 	};
 };
 
+/ {
+	usb_power: regulator-usb {
+		compatible = "regulator-fixed";
+		regulator-name = "usb-vcc";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-boot-on;
+		gpios = <&chipcommon 8 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
 &usb2 {
-	vcc-gpio = <&chipcommon 8 GPIO_ACTIVE_HIGH>;
+	vbus-supply = <&usb_power>;
 };
Signature · 1 line
2.55.0
#5 lore raw

Re: [PATCH 2/2] ARM: dts: broadcom: model USB VBUS power with regulator-fixed

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] usb: bcma: ABI breakage on older Device Trees due to missing regulator - [High] usb: bcma…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] usb: bcma: ABI breakage on older Device Trees due to missing regulator
- [High] usb: bcma: regulator enable count leaked on error paths and remove
- [Low] build: missing closing brace in bcma_hcd_probe() causes compilation failure --

commit 2da0c63e158c66b33d97e363d8f72cf580a7db29
Author: Rosen Penev <[email protected]>

usb: bcma: control VBUS via a regulator instead of a GPIO

This commit replaces the undocumented "vcc-gpio" property handling with the standard regulator interface. Each core obtains its VBUS supply via devm_regulator_get_optional() and the regulator core reference-counts the enable/disable requests to avoid conflicts.

Quoted 4 lines
drivers/usb/host/bcma-hcd.c +0 -0
index 519386255886c..394ba9e5a7f77 100644

[ ... ]

drivers/usb/host/bcma-hcd.c static int bcma_hcd_probe(struct bcma_device *core) · line 416

Quoted 12 lines
drivers/usb/host/bcma-hcd.c +3 -5
@@ -405,11 +411,14 @@ static int bcma_hcd_probe(struct bcma_device *core)
 		return -ENOMEM;
 	usb_dev->core = core;
 
-	usb_dev->gpio_desc = devm_gpiod_get_optional(&core->dev, "vcc",
-						     GPIOD_OUT_HIGH);
-	if (IS_ERR(usb_dev->gpio_desc))
-		return dev_err_probe(&core->dev, PTR_ERR(usb_dev->gpio_desc),
-				     "error obtaining VCC GPIO");
+	usb_dev->regulator = devm_regulator_get_optional(&core->dev, "vbus");
+	if (IS_ERR(usb_dev->regulator)) {
+		return PTR_ERR(usb_dev->regulator);

[Severity: Critical]
Is it possible this unconditional return breaks backward compatibility with older device trees?

Since devm_regulator_get_optional() returns -ENODEV when the regulator is absent, returning this error will fail probe entirely on older setups rather than proceeding without it.

[Severity: Low]
Does this code have a missing closing brace?

The if block is opened here but the closing brace is missing, incorrectly scoping the rest of the function and breaking compilation.

drivers/usb/host/bcma-hcd.c static int bcma_hcd_probe(struct bcma_device *core) · line 418

Quoted 2 lines
drivers/usb/host/bcma-hcd.c +2 -0
+
+	err = regulator_enable(usb_dev->regulator);

[Severity: High]
Does this code leak the regulator enable count?

If bcma_hcd_probe() encounters an error later in the initialization sequence after regulator_enable() has succeeded:

drivers/usb/host/bcma-hcd.c:bcma_hcd_probe() {
    ...
	switch (core->id.id) {
    ...
	}
	if (err)
		return err;
    ...
}

It returns without calling regulator_disable().

Similarly, does bcma_hcd_remove() also leak the regulator enable count?

When the module is unbound, it fails to invoke regulator_disable(), which would leave the regulator active and trigger core warnings.

Quoted 6 lines
drivers/usb/host/bcma-hcd.c +3 -0
+	if (err)
+		return dev_err_probe(&core->dev, err,
+				     "error enabling VCC regulator");
 
 	switch (core->id.id) {
 	case BCMA_CORE_USB20_HOST:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2