public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1
@ 2026-03-26 10:00 Chukun Pan
  2026-03-26 10:00 ` [PATCH v3 1/1] " Chukun Pan
  0 siblings, 1 reply; 7+ messages in thread
From: Chukun Pan @ 2026-03-26 10:00 UTC (permalink / raw)
  To: Thinh Nguyen
  Cc: Yixun Lan, Ze Huang, Greg Kroah-Hartman, linux-riscv,
	linux-kernel, linux-usb, spacemit, Chukun Pan

The vbus-supply property has been declared in spacemit,k1-dwc3.yaml
https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/usb/spacemit%2Ck1-dwc3.yaml#L71

Changes in v2:
- Improve commit title and messages
- Enable regulator only in host mode
- Enable regulator when matching compatible "spacemit,k1-dwc3"
- Link to v1: https://lore.kernel.org/lkml/20260316080000.3130372-1-amadeus@jmu.edu.cn/

Changes in v3:
- Add missing properties and adjust position
- Link to v2: https://lore.kernel.org/lkml/20260320100120.1343629-1-amadeus@jmu.edu.cn/

Chukun Pan (1):
  usb: dwc3: Add optional VBUS regulator support to SpacemiT K1

 drivers/usb/dwc3/dwc3-generic-plat.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1
  2026-03-26 10:00 [PATCH v3 0/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1 Chukun Pan
@ 2026-03-26 10:00 ` Chukun Pan
  2026-03-26 23:25   ` Thinh Nguyen
                     ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Chukun Pan @ 2026-03-26 10:00 UTC (permalink / raw)
  To: Thinh Nguyen
  Cc: Yixun Lan, Ze Huang, Greg Kroah-Hartman, linux-riscv,
	linux-kernel, linux-usb, spacemit, Chukun Pan

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>
---
 drivers/usb/dwc3/dwc3-generic-plat.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-generic-plat.c b/drivers/usb/dwc3/dwc3-generic-plat.c
index e846844e0023..64f5e9f20663 100644
--- a/drivers/usb/dwc3/dwc3-generic-plat.c
+++ b/drivers/usb/dwc3/dwc3-generic-plat.c
@@ -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 = "fsl,ls1028a-dwc3", &fsl_ls1028_dwc3},
 	{ .compatible = "eswin,eic7700-dwc3", &eic7700_dwc3},
 	{ /* sentinel */ }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1
  2026-03-26 10:00 ` [PATCH v3 1/1] " Chukun Pan
@ 2026-03-26 23:25   ` Thinh Nguyen
  2026-03-30 12:15   ` Anand Moon
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Thinh Nguyen @ 2026-03-26 23:25 UTC (permalink / raw)
  To: Chukun Pan
  Cc: Thinh Nguyen, Yixun Lan, Ze Huang, Greg Kroah-Hartman,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-usb@vger.kernel.org, spacemit@lists.linux.dev

On Thu, Mar 26, 2026, Chukun Pan wrote:
> 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>
> ---
>  drivers/usb/dwc3/dwc3-generic-plat.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-generic-plat.c b/drivers/usb/dwc3/dwc3-generic-plat.c
> index e846844e0023..64f5e9f20663 100644
> --- a/drivers/usb/dwc3/dwc3-generic-plat.c
> +++ b/drivers/usb/dwc3/dwc3-generic-plat.c
> @@ -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 = "fsl,ls1028a-dwc3", &fsl_ls1028_dwc3},
>  	{ .compatible = "eswin,eic7700-dwc3", &eic7700_dwc3},
>  	{ /* sentinel */ }
> -- 
> 2.34.1
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

BR,
Thinh

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1
  2026-03-26 10:00 ` [PATCH v3 1/1] " Chukun Pan
  2026-03-26 23:25   ` Thinh Nguyen
@ 2026-03-30 12:15   ` Anand Moon
  2026-03-31  1:57   ` Troy Mitchell
  2026-03-31  8:42   ` Troy Mitchell
  3 siblings, 0 replies; 7+ messages in thread
From: Anand Moon @ 2026-03-30 12:15 UTC (permalink / raw)
  To: Chukun Pan
  Cc: Thinh Nguyen, Yixun Lan, Ze Huang, Greg Kroah-Hartman,
	linux-riscv, linux-kernel, linux-usb, spacemit

hi Chukun,

On Thu, 26 Mar 2026 at 15:32, Chukun Pan <amadeus@jmu.edu.cn> wrote:
>
> 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>
> ---
Reviewed-by: Anand Moon <linux.amoon@gmail.com>

Thanks
-Anand

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1
  2026-03-26 10:00 ` [PATCH v3 1/1] " Chukun Pan
  2026-03-26 23:25   ` Thinh Nguyen
  2026-03-30 12:15   ` Anand Moon
@ 2026-03-31  1:57   ` Troy Mitchell
  2026-03-31  8:42   ` Troy Mitchell
  3 siblings, 0 replies; 7+ messages in thread
From: Troy Mitchell @ 2026-03-31  1:57 UTC (permalink / raw)
  To: Chukun Pan, Thinh Nguyen
  Cc: Yixun Lan, Ze Huang, Greg Kroah-Hartman, linux-riscv,
	linux-kernel, linux-usb, spacemit, Troy Mitchell

On Thu, Mar 26, 2026 at 18:00:10 CST, Chukun Pan wrote:
> 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>
Thanks for the patch.

Reviewed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1
  2026-03-26 10:00 ` [PATCH v3 1/1] " Chukun Pan
                     ` (2 preceding siblings ...)
  2026-03-31  1:57   ` Troy Mitchell
@ 2026-03-31  8:42   ` Troy Mitchell
  2026-03-31 13:02     ` Chukun Pan
  3 siblings, 1 reply; 7+ messages in thread
From: Troy Mitchell @ 2026-03-31  8:42 UTC (permalink / raw)
  To: Chukun Pan, Thinh Nguyen
  Cc: Yixun Lan, Ze Huang, Greg Kroah-Hartman, linux-riscv,
	linux-kernel, linux-usb, spacemit, Troy Mitchell

On Thu, Mar 26, 2026 at 18:00:10 CST, Chukun Pan wrote:
> 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>
> ---
>  drivers/usb/dwc3/dwc3-generic-plat.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-generic-plat.c b/drivers/usb/dwc3/dwc3-generic-plat.c
> index e846844e0023..64f5e9f20663 100644
> --- a/drivers/usb/dwc3/dwc3-generic-plat.c
> +++ b/drivers/usb/dwc3/dwc3-generic-plat.c
> @@ -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) {
The logic looks good, but the structure can be further improved to better align with
standard kernel coding style:

if (usb_get_dr_mode(dev) != USB_DR_MODE_HOST)
  return 0;
> +		int ret = devm_regulator_get_enable_optional(dev, "vbus");
Could you please move the declaration of ret to the top of the function?

Otherwise, LGTM.
Reviewed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1
  2026-03-31  8:42   ` Troy Mitchell
@ 2026-03-31 13:02     ` Chukun Pan
  0 siblings, 0 replies; 7+ messages in thread
From: Chukun Pan @ 2026-03-31 13:02 UTC (permalink / raw)
  To: troy.mitchell
  Cc: Thinh.Nguyen, amadeus, dlan, gregkh, huang.ze, linux-kernel,
	linux-riscv, linux-usb, spacemit

Hi,

> > +	if (usb_get_dr_mode(dev) == USB_DR_MODE_HOST) {
> The logic looks good, but the structure can be further improved to better align with
> standard kernel coding style:
>
> if (usb_get_dr_mode(dev) != USB_DR_MODE_HOST)
>   return 0;

I initially thought of writing it this way too.

> > +		int ret = devm_regulator_get_enable_optional(dev, "vbus");
> Could you please move the declaration of ret to the top of the function?

Thank you for your suggestion. This patch has been merged.
Perhaps it can be revised in the future.

Thanks,
Chukun

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-03-31 13:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26 10:00 [PATCH v3 0/1] usb: dwc3: Add optional VBUS regulator support to SpacemiT K1 Chukun Pan
2026-03-26 10:00 ` [PATCH v3 1/1] " Chukun Pan
2026-03-26 23:25   ` Thinh Nguyen
2026-03-30 12:15   ` Anand Moon
2026-03-31  1:57   ` Troy Mitchell
2026-03-31  8:42   ` Troy Mitchell
2026-03-31 13:02     ` Chukun Pan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox