]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: dwc3: Add optional VBUS regulator support to SpacemiT K1
authorChukun Pan <amadeus@jmu.edu.cn>
Thu, 26 Mar 2026 10:00:10 +0000 (18:00 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 30 Mar 2026 14:51:21 +0000 (16:51 +0200)
Some SpacemiT K1 boards (like OrangePi R2S) provide USB VBUS
through a controllable regulator. Add support for the optional
vbus-supply property so the regulator can be properly managed
in host mode instead of left always-on. Note that this doesn't
apply to USB Hub downstream ports with different VBUS supplies.

The enabled and disabled actions of the regulator are handled
automatically by devm_regulator_get_enable_optional().

Signed-off-by: Chukun Pan <amadeus@jmu.edu.cn>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Reviewed-by: Anand Moon <linux.amoon@gmail.com>
Link: https://patch.msgid.link/20260326100010.3588454-2-amadeus@jmu.edu.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/dwc3-generic-plat.c

index 28219968b8b09600a28157f8690634c40b920a01..69b7e6227b3ba28ee43a73116e2a20913bb1ac8a 100644 (file)
@@ -12,6 +12,8 @@
 #include <linux/reset.h>
 #include <linux/regmap.h>
 #include <linux/mfd/syscon.h>
+#include <linux/regulator/consumer.h>
+#include <linux/usb/otg.h>
 #include "glue.h"
 
 #define EIC7700_HSP_BUS_FILTER_EN      BIT(0)
@@ -69,6 +71,20 @@ static int dwc3_eic7700_init(struct dwc3_generic *dwc3g)
        return 0;
 }
 
+static int dwc3_spacemit_k1_init(struct dwc3_generic *dwc3g)
+{
+       struct device *dev = dwc3g->dev;
+
+       if (usb_get_dr_mode(dev) == USB_DR_MODE_HOST) {
+               int ret = devm_regulator_get_enable_optional(dev, "vbus");
+
+               if (ret && ret != -ENODEV)
+                       return dev_err_probe(dev, ret, "failed to enable VBUS\n");
+       }
+
+       return 0;
+}
+
 static int dwc3_generic_probe(struct platform_device *pdev)
 {
        const struct dwc3_generic_config *plat_config;
@@ -201,6 +217,11 @@ static const struct dev_pm_ops dwc3_generic_dev_pm_ops = {
                       dwc3_generic_runtime_idle)
 };
 
+static const struct dwc3_generic_config spacemit_k1_dwc3 = {
+       .init = dwc3_spacemit_k1_init,
+       .properties = DWC3_DEFAULT_PROPERTIES,
+};
+
 static const struct dwc3_generic_config fsl_ls1028_dwc3 = {
        .properties.gsbuscfg0_reqinfo = 0x2222,
 };
@@ -211,7 +232,7 @@ static const struct dwc3_generic_config eic7700_dwc3 =  {
 };
 
 static const struct of_device_id dwc3_generic_of_match[] = {
-       { .compatible = "spacemit,k1-dwc3", },
+       { .compatible = "spacemit,k1-dwc3", &spacemit_k1_dwc3},
        { .compatible = "spacemit,k3-dwc3", },
        { .compatible = "fsl,ls1028a-dwc3", &fsl_ls1028_dwc3},
        { .compatible = "eswin,eic7700-dwc3", &eic7700_dwc3},