mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy
@ 2020-12-10 10:31 Jules Maselbas
  2020-12-10 10:31 ` [PATCH v2 2/4] usb: dwc2: Remove unnecessary functions declaration Jules Maselbas
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Jules Maselbas @ 2020-12-10 10:31 UTC (permalink / raw)
  To: barebox; +Cc: Jules Maselbas

Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
 drivers/usb/dwc2/core.h |  2 ++
 drivers/usb/dwc2/dwc2.c | 24 ++++++++++++++++++++++++
 drivers/usb/dwc2/dwc2.h |  1 +
 3 files changed, 27 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 090ca15fe..b9845b552 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -466,6 +466,8 @@ struct dwc2 {
 	struct dwc2_hw_params hw_params;
 	struct dwc2_core_params params;
 
+	struct phy *phy; /* optional */
+
 #ifdef CONFIG_USB_DWC2_HOST
 	struct usb_host host;
 	u8 in_data_toggle[MAX_DEVICE][MAX_ENDPOINT];
diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 282e6754b..9ab3b5b53 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -50,6 +50,20 @@ static int dwc2_probe(struct device_d *dev)
 	dwc2->regs = IOMEM(iores->start);
 	dwc2->dev = dev;
 
+	dwc2->phy = phy_optional_get(dev, "usb2-phy");
+	if (IS_ERR(dwc2->phy)) {
+		ret = PTR_ERR(dwc2->phy);
+		return ret;
+	}
+
+	if (dwc2->phy) {
+		ret = phy_power_on(dwc2->phy);
+		if (ret == 0)
+			ret = phy_init(dwc2->phy);
+		if (ret)
+			goto error;
+	}
+
 	ret = dwc2_core_snpsid(dwc2);
 	if (ret)
 		goto error;
@@ -78,15 +92,25 @@ static int dwc2_probe(struct device_d *dev)
 		ret = dwc2_set_mode(dwc2, dwc2->dr_mode);
 
 error:
+	if (dwc2->phy)
+		phy_power_off(dwc2->phy);
+
 	return ret;
 }
 
 static void dwc2_remove(struct device_d *dev)
 {
 	struct dwc2 *dwc2 = dev->priv;
+	int ret;
 
 	dwc2_host_uninit(dwc2);
 	dwc2_gadget_uninit(dwc2);
+
+	if (dwc2->phy) {
+		ret = phy_exit(dwc2->phy);
+		if (ret == 0)
+			phy_power_off(dwc2->phy);
+	}
 }
 
 static const struct of_device_id dwc2_platform_dt_ids[] = {
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index 30ad90665..196f4a07f 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -2,6 +2,7 @@
 #include <usb/usb.h>
 #include <usb/usb_defs.h>
 #include <usb/gadget.h>
+#include <linux/phy/phy.h>
 
 #include "regs.h"
 #include "core.h"
-- 
2.17.1



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v2 2/4] usb: dwc2: Remove unnecessary functions declaration
  2020-12-10 10:31 [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Jules Maselbas
@ 2020-12-10 10:31 ` Jules Maselbas
  2020-12-10 10:31 ` [PATCH v2 3/4] usb: dwc2: Fix dr_mode check in dwc2_get_dr_mode Jules Maselbas
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2020-12-10 10:31 UTC (permalink / raw)
  To: barebox; +Cc: Jules Maselbas

Theses functions are only used in dwc2/core.c make them static.

Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
 drivers/usb/dwc2/core.c | 8 ++++----
 drivers/usb/dwc2/dwc2.h | 4 ----
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index c4a3cc789..d700c3e6b 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -28,7 +28,7 @@ static bool dwc2_hw_is_device(struct dwc2 *dwc2)
 		(op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE);
 }
 
-void dwc2_set_param_otg_cap(struct dwc2 *dwc2)
+static void dwc2_set_param_otg_cap(struct dwc2 *dwc2)
 {
 	u8 val;
 
@@ -49,7 +49,7 @@ void dwc2_set_param_otg_cap(struct dwc2 *dwc2)
 	dwc2->params.otg_cap = val;
 }
 
-void dwc2_set_param_phy_type(struct dwc2 *dwc2)
+static void dwc2_set_param_phy_type(struct dwc2 *dwc2)
 {
 	u8 val;
 
@@ -69,7 +69,7 @@ void dwc2_set_param_phy_type(struct dwc2 *dwc2)
 	dwc2->params.phy_type = val;
 }
 
-void dwc2_set_param_speed(struct dwc2 *dwc2)
+static void dwc2_set_param_speed(struct dwc2 *dwc2)
 {
 	if (dwc2->params.phy_type == DWC2_PHY_TYPE_PARAM_FS)
 		dwc2->params.speed = DWC2_SPEED_PARAM_FULL;
@@ -77,7 +77,7 @@ void dwc2_set_param_speed(struct dwc2 *dwc2)
 		dwc2->params.speed = DWC2_SPEED_PARAM_HIGH;
 }
 
-void dwc2_set_param_phy_utmi_width(struct dwc2 *dwc2)
+static void dwc2_set_param_phy_utmi_width(struct dwc2 *dwc2)
 {
 	int val;
 
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index 196f4a07f..a878de85b 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -8,10 +8,6 @@
 #include "core.h"
 
 /* Core functions */
-void dwc2_set_param_otg_cap(struct dwc2 *dwc2);
-void dwc2_set_param_phy_type(struct dwc2 *dwc2);
-void dwc2_set_param_speed(struct dwc2 *dwc2);
-void dwc2_set_param_phy_utmi_width(struct dwc2 *dwc2);
 void dwc2_set_default_params(struct dwc2 *dwc2);
 int dwc2_core_snpsid(struct dwc2 *dwc2);
 void dwc2_get_hwparams(struct dwc2 *dwc2);
-- 
2.17.1



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v2 3/4] usb: dwc2: Fix dr_mode check in dwc2_get_dr_mode
  2020-12-10 10:31 [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Jules Maselbas
  2020-12-10 10:31 ` [PATCH v2 2/4] usb: dwc2: Remove unnecessary functions declaration Jules Maselbas
@ 2020-12-10 10:31 ` Jules Maselbas
  2020-12-10 10:31 ` [PATCH v2 4/4] usb: dwc2: Rename dwc2_core_snpsid to dwc2_check_core_version Jules Maselbas
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2020-12-10 10:31 UTC (permalink / raw)
  To: barebox; +Cc: Jules Maselbas

In Linux, configs CONFIG_USB_DWC2_HOST and CONFIG_USB_DWC2_GADGET
are respectively for host only and gadget only support, they are
mutually exclusive. However this is not the case in barebox, they
are independent options.

Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
 drivers/usb/dwc2/core.c | 14 ++++++--------
 drivers/usb/dwc2/dwc2.c |  2 ++
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index d700c3e6b..4e356a1df 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -649,18 +649,16 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2)
 
 	if (dwc2_hw_is_device(dwc2)) {
 		dwc2_dbg(dwc2, "Controller is device only\n");
-		if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) {
-			dwc2_err(dwc2,
-				"Controller does not support host mode.\n");
-			return -EINVAL;
+		if (!IS_ENABLED(CONFIG_USB_DWC2_GADGET)) {
+			dwc2_err(dwc2, "gadget mode support not compiled in!\n");
+			return -ENOTSUPP;
 		}
 		mode = USB_DR_MODE_PERIPHERAL;
 	} else if (dwc2_hw_is_host(dwc2)) {
 		dwc2_dbg(dwc2, "Controller is host only\n");
-		if (IS_ENABLED(CONFIG_USB_DWC2_GADGET)) {
-			dwc2_err(dwc2,
-				"Controller does not support device mode.\n");
-			return -EINVAL;
+		if (!IS_ENABLED(CONFIG_USB_DWC2_HOST)) {
+			dwc2_err(dwc2, "host mode support not compiled in!\n");
+			return -ENOTSUPP;
 		}
 		mode = USB_DR_MODE_HOST;
 	} else {
diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 9ab3b5b53..0965756f6 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -80,6 +80,8 @@ static int dwc2_probe(struct device_d *dev)
 	dwc2_get_hwparams(dwc2);
 
 	ret = dwc2_get_dr_mode(dwc2);
+	if (ret)
+		goto error;
 
 	dwc2_set_default_params(dwc2);
 
-- 
2.17.1



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v2 4/4] usb: dwc2: Rename dwc2_core_snpsid to dwc2_check_core_version
  2020-12-10 10:31 [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Jules Maselbas
  2020-12-10 10:31 ` [PATCH v2 2/4] usb: dwc2: Remove unnecessary functions declaration Jules Maselbas
  2020-12-10 10:31 ` [PATCH v2 3/4] usb: dwc2: Fix dr_mode check in dwc2_get_dr_mode Jules Maselbas
@ 2020-12-10 10:31 ` Jules Maselbas
  2020-12-11 15:36 ` [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Sascha Hauer
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2020-12-10 10:31 UTC (permalink / raw)
  To: barebox; +Cc: Jules Maselbas

The name dwc2_check_core_version is the one used on Linux, make it this
way.

Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
 drivers/usb/dwc2/core.c | 4 +---
 drivers/usb/dwc2/dwc2.c | 2 +-
 drivers/usb/dwc2/dwc2.h | 2 +-
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 4e356a1df..cc5729ed9 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -185,12 +185,10 @@ void dwc2_set_default_params(struct dwc2 *dwc2)
 	}
 }
 
-int dwc2_core_snpsid(struct dwc2 *dwc2)
+int dwc2_check_core_version(struct dwc2 *dwc2)
 {
 	struct dwc2_hw_params *hw = &dwc2->hw_params;
 
-	hw->snpsid = dwc2_readl(dwc2, GSNPSID);
-
 	/*
 	 * Attempt to ensure this device is really a DWC2 Controller.
 	 * Read and verify the GSNPSID register contents. The value should be
diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 0965756f6..e039800a5 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -64,7 +64,7 @@ static int dwc2_probe(struct device_d *dev)
 			goto error;
 	}
 
-	ret = dwc2_core_snpsid(dwc2);
+	ret = dwc2_check_core_version(dwc2);
 	if (ret)
 		goto error;
 
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index a878de85b..b9fdda850 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -9,7 +9,7 @@
 
 /* Core functions */
 void dwc2_set_default_params(struct dwc2 *dwc2);
-int dwc2_core_snpsid(struct dwc2 *dwc2);
+int dwc2_check_core_version(struct dwc2 *dwc2);
 void dwc2_get_hwparams(struct dwc2 *dwc2);
 
 void dwc2_init_fs_ls_pclk_sel(struct dwc2 *dwc2);
-- 
2.17.1



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy
  2020-12-10 10:31 [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Jules Maselbas
                   ` (2 preceding siblings ...)
  2020-12-10 10:31 ` [PATCH v2 4/4] usb: dwc2: Rename dwc2_core_snpsid to dwc2_check_core_version Jules Maselbas
@ 2020-12-11 15:36 ` Sascha Hauer
  2020-12-11 16:21   ` Jules Maselbas
  2020-12-14 11:03 ` [PATCH v2] fixup! " Jules Maselbas
  2020-12-16  8:21 ` [PATCH v2 1/4] " Sascha Hauer
  5 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2020-12-11 15:36 UTC (permalink / raw)
  To: Jules Maselbas; +Cc: barebox

On Thu, Dec 10, 2020 at 11:31:01AM +0100, Jules Maselbas wrote:
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> ---
>  drivers/usb/dwc2/core.h |  2 ++
>  drivers/usb/dwc2/dwc2.c | 24 ++++++++++++++++++++++++
>  drivers/usb/dwc2/dwc2.h |  1 +
>  3 files changed, 27 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index 090ca15fe..b9845b552 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -466,6 +466,8 @@ struct dwc2 {
>  	struct dwc2_hw_params hw_params;
>  	struct dwc2_core_params params;
>  
> +	struct phy *phy; /* optional */
> +
>  #ifdef CONFIG_USB_DWC2_HOST
>  	struct usb_host host;
>  	u8 in_data_toggle[MAX_DEVICE][MAX_ENDPOINT];
> diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
> index 282e6754b..9ab3b5b53 100644
> --- a/drivers/usb/dwc2/dwc2.c
> +++ b/drivers/usb/dwc2/dwc2.c
> @@ -50,6 +50,20 @@ static int dwc2_probe(struct device_d *dev)
>  	dwc2->regs = IOMEM(iores->start);
>  	dwc2->dev = dev;
>  
> +	dwc2->phy = phy_optional_get(dev, "usb2-phy");
> +	if (IS_ERR(dwc2->phy)) {
> +		ret = PTR_ERR(dwc2->phy);
> +		return ret;
> +	}
> +
> +	if (dwc2->phy) {
> +		ret = phy_power_on(dwc2->phy);
> +		if (ret == 0)
> +			ret = phy_init(dwc2->phy);
> +		if (ret)
> +			goto error;
> +	}

Just like with clocks a NULL pointer is handled like a dummy phy, you
can drop the if (dwc2->phy) tests here.

Shouldn't phy_init() called before phy_power_on()? At least that's the
order I find in the Kernel in several places.

>  	dwc2_gadget_uninit(dwc2);
> +
> +	if (dwc2->phy) {
> +		ret = phy_exit(dwc2->phy);
> +		if (ret == 0)
> +			phy_power_off(dwc2->phy);
> +	}

Likewise phy_power_off() before phy_exit().

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy
  2020-12-11 15:36 ` [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Sascha Hauer
@ 2020-12-11 16:21   ` Jules Maselbas
  0 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2020-12-11 16:21 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hi Sascha,

On Fri, Dec 11, 2020 at 04:36:08PM +0100, Sascha Hauer wrote:
> On Thu, Dec 10, 2020 at 11:31:01AM +0100, Jules Maselbas wrote:
> > Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> > ---
> >  drivers/usb/dwc2/core.h |  2 ++
> >  drivers/usb/dwc2/dwc2.c | 24 ++++++++++++++++++++++++
> >  drivers/usb/dwc2/dwc2.h |  1 +
> >  3 files changed, 27 insertions(+)
> > 
> > diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> > index 090ca15fe..b9845b552 100644
> > --- a/drivers/usb/dwc2/core.h
> > +++ b/drivers/usb/dwc2/core.h
> > @@ -466,6 +466,8 @@ struct dwc2 {
> >  	struct dwc2_hw_params hw_params;
> >  	struct dwc2_core_params params;
> >  
> > +	struct phy *phy; /* optional */
> > +
> >  #ifdef CONFIG_USB_DWC2_HOST
> >  	struct usb_host host;
> >  	u8 in_data_toggle[MAX_DEVICE][MAX_ENDPOINT];
> > diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
> > index 282e6754b..9ab3b5b53 100644
> > --- a/drivers/usb/dwc2/dwc2.c
> > +++ b/drivers/usb/dwc2/dwc2.c
> > @@ -50,6 +50,20 @@ static int dwc2_probe(struct device_d *dev)
> >  	dwc2->regs = IOMEM(iores->start);
> >  	dwc2->dev = dev;
> >  
> > +	dwc2->phy = phy_optional_get(dev, "usb2-phy");
> > +	if (IS_ERR(dwc2->phy)) {
> > +		ret = PTR_ERR(dwc2->phy);
> > +		return ret;
> > +	}
> > +
> > +	if (dwc2->phy) {
> > +		ret = phy_power_on(dwc2->phy);
> > +		if (ret == 0)
> > +			ret = phy_init(dwc2->phy);
> > +		if (ret)
> > +			goto error;
> > +	}
> 
> Just like with clocks a NULL pointer is handled like a dummy phy, you
> can drop the if (dwc2->phy) tests here.
Alright, I'll remove theses ifs.

> 
> Shouldn't phy_init() called before phy_power_on()? At least that's the
> order I find in the Kernel in several places.
Indeed, from what I've seen it is mostly phy_power_on and then phy_init.
However in the dwc2 driver in Linux's kernel, it is done the other way
around, see the function __dwc2_lowlevel_hw_enable in dwc2/platform.c [1]

I don't fully understand the phy api. My assumption was that phy_power_on
is used to power the phy interface, and that phy_init does initialisation
of the phy device such as toggling the reset pin as done by usb-nop-xceiv.

That's why I thought it was correct to first power on the phy and then do
initilisation. But I may have missunderstand both functions. Any insight
is more than welcome as I am new to this.

[1] https://elixir.bootlin.com/linux/latest/source/drivers/usb/dwc2/platform.c#L145

> >  	dwc2_gadget_uninit(dwc2);
> > +
> > +	if (dwc2->phy) {
> > +		ret = phy_exit(dwc2->phy);
> > +		if (ret == 0)
> > +			phy_power_off(dwc2->phy);
> > +	}
> 
> Likewise phy_power_off() before phy_exit().


---
Jules


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH v2] fixup! usb: dwc2: Add support for optional usb phy
  2020-12-10 10:31 [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Jules Maselbas
                   ` (3 preceding siblings ...)
  2020-12-11 15:36 ` [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Sascha Hauer
@ 2020-12-14 11:03 ` Jules Maselbas
  2020-12-16  8:21 ` [PATCH v2 1/4] " Sascha Hauer
  5 siblings, 0 replies; 8+ messages in thread
From: Jules Maselbas @ 2020-12-14 11:03 UTC (permalink / raw)
  To: barebox; +Cc: Jules Maselbas

In this fixup I've changed to call order for phy initialisation:
phy_init and then phy_power_on. Same for the deinitiailisation:
phy_power_off then phy_exit. Which seems to be the correct way.

Also fix the exit path.

Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
 drivers/usb/dwc2/dwc2.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 5e95e8b22..98f9b30b6 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -56,13 +56,12 @@ static int dwc2_probe(struct device_d *dev)
 		return ret;
 	}
 
-	if (dwc2->phy) {
-		ret = phy_power_on(dwc2->phy);
-		if (ret == 0)
-			ret = phy_init(dwc2->phy);
-		if (ret)
-			goto error;
-	}
+	ret = phy_init(dwc2->phy);
+	if (ret)
+		goto err_phy_init;
+	ret = phy_power_on(dwc2->phy);
+	if (ret)
+		goto err_phy_power;
 
 	ret = dwc2_check_core_version(dwc2);
 	if (ret)
@@ -93,9 +92,15 @@ static int dwc2_probe(struct device_d *dev)
 	else
 		ret = dwc2_set_mode(dwc2, dwc2->dr_mode);
 
+	if (ret)
+		goto error;
+
+	return 0;
 error:
-	if (dwc2->phy)
-		phy_power_off(dwc2->phy);
+	phy_power_off(dwc2->phy);
+err_phy_power:
+	phy_exit(dwc2->phy);
+err_phy_init:
 
 	return ret;
 }
@@ -103,16 +108,12 @@ error:
 static void dwc2_remove(struct device_d *dev)
 {
 	struct dwc2 *dwc2 = dev->priv;
-	int ret;
 
 	dwc2_host_uninit(dwc2);
 	dwc2_gadget_uninit(dwc2);
 
-	if (dwc2->phy) {
-		ret = phy_exit(dwc2->phy);
-		if (ret == 0)
-			phy_power_off(dwc2->phy);
-	}
+	phy_power_off(dwc2->phy);
+	phy_exit(dwc2->phy);
 }
 
 static const struct of_device_id dwc2_platform_dt_ids[] = {
-- 
2.17.1



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy
  2020-12-10 10:31 [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Jules Maselbas
                   ` (4 preceding siblings ...)
  2020-12-14 11:03 ` [PATCH v2] fixup! " Jules Maselbas
@ 2020-12-16  8:21 ` Sascha Hauer
  5 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2020-12-16  8:21 UTC (permalink / raw)
  To: Jules Maselbas; +Cc: barebox

On Thu, Dec 10, 2020 at 11:31:01AM +0100, Jules Maselbas wrote:
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> ---
>  drivers/usb/dwc2/core.h |  2 ++
>  drivers/usb/dwc2/dwc2.c | 24 ++++++++++++++++++++++++
>  drivers/usb/dwc2/dwc2.h |  1 +
>  3 files changed, 27 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index 090ca15fe..b9845b552 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -466,6 +466,8 @@ struct dwc2 {
>  	struct dwc2_hw_params hw_params;
>  	struct dwc2_core_params params;
>  
> +	struct phy *phy; /* optional */
> +
>  #ifdef CONFIG_USB_DWC2_HOST
>  	struct usb_host host;
>  	u8 in_data_toggle[MAX_DEVICE][MAX_ENDPOINT];
> diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
> index 282e6754b..9ab3b5b53 100644
> --- a/drivers/usb/dwc2/dwc2.c
> +++ b/drivers/usb/dwc2/dwc2.c
> @@ -50,6 +50,20 @@ static int dwc2_probe(struct device_d *dev)
>  	dwc2->regs = IOMEM(iores->start);
>  	dwc2->dev = dev;
>  
> +	dwc2->phy = phy_optional_get(dev, "usb2-phy");
> +	if (IS_ERR(dwc2->phy)) {
> +		ret = PTR_ERR(dwc2->phy);
> +		return ret;
> +	}
> +
> +	if (dwc2->phy) {
> +		ret = phy_power_on(dwc2->phy);
> +		if (ret == 0)
> +			ret = phy_init(dwc2->phy);
> +		if (ret)
> +			goto error;
> +	}
> +
>  	ret = dwc2_core_snpsid(dwc2);
>  	if (ret)
>  		goto error;
> @@ -78,15 +92,25 @@ static int dwc2_probe(struct device_d *dev)
>  		ret = dwc2_set_mode(dwc2, dwc2->dr_mode);
>  
>  error:
> +	if (dwc2->phy)
> +		phy_power_off(dwc2->phy);
> +
>  	return ret;
>  }
>  
>  static void dwc2_remove(struct device_d *dev)
>  {
>  	struct dwc2 *dwc2 = dev->priv;
> +	int ret;
>  
>  	dwc2_host_uninit(dwc2);
>  	dwc2_gadget_uninit(dwc2);
> +
> +	if (dwc2->phy) {
> +		ret = phy_exit(dwc2->phy);
> +		if (ret == 0)
> +			phy_power_off(dwc2->phy);
> +	}
>  }
>  
>  static const struct of_device_id dwc2_platform_dt_ids[] = {
> diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
> index 30ad90665..196f4a07f 100644
> --- a/drivers/usb/dwc2/dwc2.h
> +++ b/drivers/usb/dwc2/dwc2.h
> @@ -2,6 +2,7 @@
>  #include <usb/usb.h>
>  #include <usb/usb_defs.h>
>  #include <usb/gadget.h>
> +#include <linux/phy/phy.h>
>  
>  #include "regs.h"
>  #include "core.h"
> -- 
> 2.17.1
> 
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-12-16  8:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 10:31 [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Jules Maselbas
2020-12-10 10:31 ` [PATCH v2 2/4] usb: dwc2: Remove unnecessary functions declaration Jules Maselbas
2020-12-10 10:31 ` [PATCH v2 3/4] usb: dwc2: Fix dr_mode check in dwc2_get_dr_mode Jules Maselbas
2020-12-10 10:31 ` [PATCH v2 4/4] usb: dwc2: Rename dwc2_core_snpsid to dwc2_check_core_version Jules Maselbas
2020-12-11 15:36 ` [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Sascha Hauer
2020-12-11 16:21   ` Jules Maselbas
2020-12-14 11:03 ` [PATCH v2] fixup! " Jules Maselbas
2020-12-16  8:21 ` [PATCH v2 1/4] " Sascha Hauer

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