]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
mpc85xx: use regulator for USB power main master 16842/head
authorRosen Penev <rosenp@gmail.com>
Mon, 28 Oct 2024 19:41:53 +0000 (12:41 -0700)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Wed, 15 Jul 2026 18:25:52 +0000 (20:25 +0200)
Use upstream solution for managing GPIO power for USB devices.

A small patch is needed to make the whole thing work as this is an older
USB driver that does not use the PHY framework.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16842
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
target/linux/mpc85xx/files/arch/powerpc/boot/dts/tl-wdr4900-v1.dts
target/linux/mpc85xx/p1010/config-default
target/linux/mpc85xx/patches-6.12/220-usb-fsl-mph-dr-of-add-regulator-support.patch [new file with mode: 0644]
target/linux/mpc85xx/patches-6.18/220-usb-fsl-mph-dr-of-add-regulator-support.patch [new file with mode: 0644]

index c56a3a219171a8b77d157b3d08a849af458e8489..082ea50284b17336f5e13e198b9c917e049424b6 100644 (file)
                        phy_type = "utmi";
                        dr_mode = "host";
 
+                       vbus-supply = <&reg_power_usb>;
+
                        port@1 {
                                #address-cells = <1>;
                                #size-cells = <0>;
                };
        };
 
-       gpio_export {
-                       compatible = "gpio-export";
-
-                       usb-pwr {
-                               gpio-export,name = "usb_pwr";
-                               gpio-export,output = <1>;
-                               gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
-                       };
-               };
+       reg_power_usb: regulator {
+               compatible = "regulator-fixed";
+               regulator-name = "power_usb";
+               regulator-min-microvolt = <5000000>;
+               regulator-max-microvolt = <5000000>;
+               gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>;
+               enable-active-high;
+               regulator-boot-on;
+       };
 
        buttons {
                compatible = "gpio-keys";
index a300486087ea0920cead0c7141debb0ff6ed68b4..5fcf7fd927a2b0d44ce4c7b3eaf092d7601cbfa4 100644 (file)
@@ -36,6 +36,7 @@ CONFIG_REALTEK_PHY=y
 CONFIG_RED_15W_REV1=y
 CONFIG_REGMAP=y
 CONFIG_REGULATOR=y
+CONFIG_REGULATOR_FIXED_VOLTAGE=y
 CONFIG_SGL_ALLOC=y
 CONFIG_SPI_BITBANG=y
 CONFIG_SPI_GPIO=y
diff --git a/target/linux/mpc85xx/patches-6.12/220-usb-fsl-mph-dr-of-add-regulator-support.patch b/target/linux/mpc85xx/patches-6.12/220-usb-fsl-mph-dr-of-add-regulator-support.patch
new file mode 100644 (file)
index 0000000..c1cf528
--- /dev/null
@@ -0,0 +1,48 @@
+From 04c30383e668da328ceec9f10d6437a8aa9c5b8f Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Tue, 3 Dec 2024 13:53:31 -0800
+Subject: [PATCH] usb: fsl-mph-dr-of: add regulator support
+
+Some devices have a GPIO that controls power to the USB bus. Add
+support for a vbus regulator to have the kernel control it automatically
+instead of having to rely on userspace.
+
+Acquire the regulator in the common probe path so that it works for
+all fsl-usb2-dr compatible controllers, not just MPC5121.
+
+Assisted-by: opencode:big-pickle
+Signed-off-by: Rosen Penev <rosenp@gmail.com>
+---
+ drivers/usb/host/fsl-mph-dr-of.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+--- a/drivers/usb/host/fsl-mph-dr-of.c
++++ b/drivers/usb/host/fsl-mph-dr-of.c
+@@ -15,6 +15,7 @@
+ #include <linux/clk.h>
+ #include <linux/module.h>
+ #include <linux/dma-mapping.h>
++#include <linux/regulator/consumer.h>
+ struct fsl_usb2_dev_data {
+       char *dr_mode;          /* controller mode */
+@@ -183,7 +184,7 @@ static int fsl_usb2_mph_dr_of_probe(stru
+       const struct of_device_id *match;
+       const unsigned char *prop;
+       static unsigned int idx;
+-      int i;
++      int i, err;
+       if (!of_device_is_available(np))
+               return -ENODEV;
+@@ -246,6 +247,10 @@ static int fsl_usb2_mph_dr_of_probe(stru
+               }
+       }
++      err = devm_regulator_get_enable_optional(&ofdev->dev, "vbus");
++      if (err)
++              return dev_err_probe(&ofdev->dev, err, "failed to get vbus regulator\n");
++
+       for (i = 0; i < ARRAY_SIZE(dev_data->drivers); i++) {
+               if (!dev_data->drivers[i])
+                       continue;
diff --git a/target/linux/mpc85xx/patches-6.18/220-usb-fsl-mph-dr-of-add-regulator-support.patch b/target/linux/mpc85xx/patches-6.18/220-usb-fsl-mph-dr-of-add-regulator-support.patch
new file mode 100644 (file)
index 0000000..c1cf528
--- /dev/null
@@ -0,0 +1,48 @@
+From 04c30383e668da328ceec9f10d6437a8aa9c5b8f Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Tue, 3 Dec 2024 13:53:31 -0800
+Subject: [PATCH] usb: fsl-mph-dr-of: add regulator support
+
+Some devices have a GPIO that controls power to the USB bus. Add
+support for a vbus regulator to have the kernel control it automatically
+instead of having to rely on userspace.
+
+Acquire the regulator in the common probe path so that it works for
+all fsl-usb2-dr compatible controllers, not just MPC5121.
+
+Assisted-by: opencode:big-pickle
+Signed-off-by: Rosen Penev <rosenp@gmail.com>
+---
+ drivers/usb/host/fsl-mph-dr-of.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+--- a/drivers/usb/host/fsl-mph-dr-of.c
++++ b/drivers/usb/host/fsl-mph-dr-of.c
+@@ -15,6 +15,7 @@
+ #include <linux/clk.h>
+ #include <linux/module.h>
+ #include <linux/dma-mapping.h>
++#include <linux/regulator/consumer.h>
+ struct fsl_usb2_dev_data {
+       char *dr_mode;          /* controller mode */
+@@ -183,7 +184,7 @@ static int fsl_usb2_mph_dr_of_probe(stru
+       const struct of_device_id *match;
+       const unsigned char *prop;
+       static unsigned int idx;
+-      int i;
++      int i, err;
+       if (!of_device_is_available(np))
+               return -ENODEV;
+@@ -246,6 +247,10 @@ static int fsl_usb2_mph_dr_of_probe(stru
+               }
+       }
++      err = devm_regulator_get_enable_optional(&ofdev->dev, "vbus");
++      if (err)
++              return dev_err_probe(&ofdev->dev, err, "failed to get vbus regulator\n");
++
+       for (i = 0; i < ARRAY_SIZE(dev_data->drivers); i++) {
+               if (!dev_data->drivers[i])
+                       continue;