The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v1 1/2] usb: dwc3: Refactor usb-psy init
@ 2023-12-16  3:43 Badhri Jagan Sridharan
  2023-12-16  3:43 ` [PATCH v1 2/2] usb: gadget: Retry populating usb-psy when null Badhri Jagan Sridharan
  2023-12-22 22:40 ` [PATCH v1 1/2] usb: dwc3: Refactor usb-psy init Thinh Nguyen
  0 siblings, 2 replies; 3+ messages in thread
From: Badhri Jagan Sridharan @ 2023-12-16  3:43 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, raychi, royluo
  Cc: linux-usb, linux-kernel, Badhri Jagan Sridharan, stable

Move usb-psy init to dwc3_populate_usb_psy() so that gadget can re-use
it to retry setting up usb-psy when null.

Cc: stable@vger.kernel.org
Fixes: 6f0764b5adea ("usb: dwc3: add a power supply for current control")
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
 drivers/usb/dwc3/core.c | 24 ++++++++++++++++--------
 drivers/usb/dwc3/core.h |  1 +
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index b101dbf8c5dc..a93425b9c1c0 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1495,6 +1495,19 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
 	dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
 }
 
+void dwc3_populate_usb_psy(struct dwc3 *dwc)
+{
+	const char *usb_psy_name;
+	int ret;
+
+	if (dwc->usb_psy)
+		return;
+
+	ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name);
+	if (ret >= 0)
+		dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
+}
+
 static void dwc3_get_properties(struct dwc3 *dwc)
 {
 	struct device		*dev = dwc->dev;
@@ -1510,8 +1523,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	u8			tx_thr_num_pkt_prd = 0;
 	u8			tx_max_burst_prd = 0;
 	u8			tx_fifo_resize_max_num;
-	const char		*usb_psy_name;
-	int			ret;
 
 	/* default to highest possible threshold */
 	lpm_nyet_threshold = 0xf;
@@ -1544,12 +1555,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)
 	else
 		dwc->sysdev = dwc->dev;
 
-	ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
-	if (ret >= 0) {
-		dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
-		if (!dwc->usb_psy)
-			dev_err(dev, "couldn't get usb power supply\n");
-	}
+	dwc3_populate_usb_psy(dwc);
+	if (!dwc->usb_psy)
+		dev_err(dev, "couldn't get usb power supply\n");
 
 	dwc->has_lpm_erratum = device_property_read_bool(dev,
 				"snps,has-lpm-erratum");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index efe6caf4d0e8..6c65d76e6fe2 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1526,6 +1526,7 @@ struct dwc3_gadget_ep_cmd_params {
 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode);
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
 u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
+void dwc3_populate_usb_psy(struct dwc3 *dwc);
 
 #define DWC3_IP_IS(_ip)							\
 	(dwc->ip == _ip##_IP)

base-commit: 51920207674e9e3475a91d2091583889792df99a
-- 
2.43.0.472.g3155946c3a-goog


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

* [PATCH v1 2/2] usb: gadget: Retry populating usb-psy when null
  2023-12-16  3:43 [PATCH v1 1/2] usb: dwc3: Refactor usb-psy init Badhri Jagan Sridharan
@ 2023-12-16  3:43 ` Badhri Jagan Sridharan
  2023-12-22 22:40 ` [PATCH v1 1/2] usb: dwc3: Refactor usb-psy init Thinh Nguyen
  1 sibling, 0 replies; 3+ messages in thread
From: Badhri Jagan Sridharan @ 2023-12-16  3:43 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh, raychi, royluo
  Cc: linux-usb, linux-kernel, Badhri Jagan Sridharan, stable

This patch allows populating usb-psy where usb-psy comes up
after dwc3 is probed. Retry populating usb-psy when dwc->usb_psy
is null while dwc3_gadget_vbus_draw() is executed.

Cc: stable@vger.kernel.org
Fixes: 99288de36020 ("usb: dwc3: add an alternate path in vbus_draw callback")
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
---
 drivers/usb/dwc3/gadget.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 858fe4c299b7..b3470a5e5e26 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -3049,8 +3049,11 @@ static int dwc3_gadget_vbus_draw(struct usb_gadget *g, unsigned int mA)
 	if (dwc->usb2_phy)
 		return usb_phy_set_power(dwc->usb2_phy, mA);
 
-	if (!dwc->usb_psy)
-		return -EOPNOTSUPP;
+	if (!dwc->usb_psy) {
+		dwc3_populate_usb_psy(dwc);
+		if (!dwc->usb_psy)
+			return -EOPNOTSUPP;
+	}
 
 	val.intval = 1000 * mA;
 	ret = power_supply_set_property(dwc->usb_psy, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val);
-- 
2.43.0.472.g3155946c3a-goog


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

* Re: [PATCH v1 1/2] usb: dwc3: Refactor usb-psy init
  2023-12-16  3:43 [PATCH v1 1/2] usb: dwc3: Refactor usb-psy init Badhri Jagan Sridharan
  2023-12-16  3:43 ` [PATCH v1 2/2] usb: gadget: Retry populating usb-psy when null Badhri Jagan Sridharan
@ 2023-12-22 22:40 ` Thinh Nguyen
  1 sibling, 0 replies; 3+ messages in thread
From: Thinh Nguyen @ 2023-12-22 22:40 UTC (permalink / raw)
  To: Badhri Jagan Sridharan
  Cc: Thinh Nguyen, gregkh@linuxfoundation.org, raychi@google.com,
	royluo@google.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org

On Sat, Dec 16, 2023, Badhri Jagan Sridharan wrote:
> Move usb-psy init to dwc3_populate_usb_psy() so that gadget can re-use
> it to retry setting up usb-psy when null.
> 
> Cc: stable@vger.kernel.org
> Fixes: 6f0764b5adea ("usb: dwc3: add a power supply for current control")

This is not a fix. It shouldn't go to stable.

> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
> ---
>  drivers/usb/dwc3/core.c | 24 ++++++++++++++++--------
>  drivers/usb/dwc3/core.h |  1 +
>  2 files changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index b101dbf8c5dc..a93425b9c1c0 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1495,6 +1495,19 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
>  	dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
>  }
>  
> +void dwc3_populate_usb_psy(struct dwc3 *dwc)
> +{
> +	const char *usb_psy_name;
> +	int ret;
> +
> +	if (dwc->usb_psy)
> +		return;
> +
> +	ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name);
> +	if (ret >= 0)
> +		dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
> +}
> +
>  static void dwc3_get_properties(struct dwc3 *dwc)
>  {
>  	struct device		*dev = dwc->dev;
> @@ -1510,8 +1523,6 @@ static void dwc3_get_properties(struct dwc3 *dwc)
>  	u8			tx_thr_num_pkt_prd = 0;
>  	u8			tx_max_burst_prd = 0;
>  	u8			tx_fifo_resize_max_num;
> -	const char		*usb_psy_name;
> -	int			ret;
>  
>  	/* default to highest possible threshold */
>  	lpm_nyet_threshold = 0xf;
> @@ -1544,12 +1555,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)
>  	else
>  		dwc->sysdev = dwc->dev;
>  
> -	ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
> -	if (ret >= 0) {
> -		dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
> -		if (!dwc->usb_psy)
> -			dev_err(dev, "couldn't get usb power supply\n");
> -	}
> +	dwc3_populate_usb_psy(dwc);
> +	if (!dwc->usb_psy)
> +		dev_err(dev, "couldn't get usb power supply\n");
>  
>  	dwc->has_lpm_erratum = device_property_read_bool(dev,
>  				"snps,has-lpm-erratum");
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index efe6caf4d0e8..6c65d76e6fe2 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1526,6 +1526,7 @@ struct dwc3_gadget_ep_cmd_params {
>  void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode);
>  void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
>  u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
> +void dwc3_populate_usb_psy(struct dwc3 *dwc);
>  
>  #define DWC3_IP_IS(_ip)							\
>  	(dwc->ip == _ip##_IP)
> 
> base-commit: 51920207674e9e3475a91d2091583889792df99a
> -- 
> 2.43.0.472.g3155946c3a-goog
> 

Why do we want to retry again? Perhaps the dwc3 needs to wait for the
power supply available by using -EPROBE_DEFERRED?

BR,
Thinh

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

end of thread, other threads:[~2023-12-22 22:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-16  3:43 [PATCH v1 1/2] usb: dwc3: Refactor usb-psy init Badhri Jagan Sridharan
2023-12-16  3:43 ` [PATCH v1 2/2] usb: gadget: Retry populating usb-psy when null Badhri Jagan Sridharan
2023-12-22 22:40 ` [PATCH v1 1/2] usb: dwc3: Refactor usb-psy init Thinh Nguyen

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