2016-11-15 17:42:56

by Alexandre Bailon

[permalink] [raw]
Subject: [PATCH v6 0/2] usb: musb: da8xx: Fix few issues

This series require the following patch to build:
[PATCH 1/6] usb: musb: Fix broken use of static variable for multiple instances

Currently, the USB OTG of the da8xx doesn't work.
This series intend to fix them.

Change in v2:
* Fix the error path da8xx_musb_init()

Changes in v3:
* Remove the host workaround that was not working on every platform
* Add a property to the devicetree node of phy to force the phy in a specific
mode (host or device).
* Only use dr_mode to configure the controller mode and let the phy in OTG mode.
The main goal of this change is to prevent the phy to be set in host or
device mode because these modes have some issues.

Changes in v4:
* Enable VBUS sense and session end comparator during probe of phy.
* Add a quirk flag to skip the phy set mode made during the init of musb.
In that way, we can still can configure the phy mode by using mode file in
sysfs and configure the controller mode by using dr_mode or platform_data.
* Init the phy in otg mode in da8xx glue driver.

Changes in v5:
* Add the init argument to musb_platform_set_mode() and set_mode() callback.
* Remove the quirk
* Configure the DA8xx phy in OTG mode if da8xx_musb_set_mode() is called from
init.

Changes in v6:
* Remove the patch that was adding a new parametter to musb_platform_set_mode().
Instead, use the variable is_initialized.
* The patch fixing the phy has been merged to phy-next, so I removed it from
this series.

Alexandre Bailon (2):
usb: musb: da8xx: Call earlier clk_prepare_enable()
usb: musb: da8xx: Set phy in OTG mode by default

drivers/usb/musb/da8xx.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)

--
2.7.3


2016-11-15 17:42:59

by Alexandre Bailon

[permalink] [raw]
Subject: [PATCH v6 1/2] usb: musb: da8xx: Call earlier clk_prepare_enable()

The first attempt to read a register may fail because the clock may not
be enabled, and then the probe of musb driver will fail.
Call clk_prepare_enable() before the first register read.

Signed-off-by: Alexandre Bailon <[email protected]>
---
drivers/usb/musb/da8xx.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 2440f88..4fc226c 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -366,6 +366,12 @@ static int da8xx_musb_init(struct musb *musb)

musb->mregs += DA8XX_MENTOR_CORE_OFFSET;

+ ret = clk_prepare_enable(glue->clk);
+ if (ret) {
+ dev_err(glue->dev, "failed to enable clock\n");
+ return ret;
+ }
+
/* Returns zero if e.g. not clocked */
rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG);
if (!rev)
@@ -377,12 +383,6 @@ static int da8xx_musb_init(struct musb *musb)
goto fail;
}

- ret = clk_prepare_enable(glue->clk);
- if (ret) {
- dev_err(glue->dev, "failed to enable clock\n");
- goto fail;
- }
-
setup_timer(&otg_workaround, otg_timer, (unsigned long)musb);

/* Reset the controller */
@@ -392,7 +392,7 @@ static int da8xx_musb_init(struct musb *musb)
ret = phy_init(glue->phy);
if (ret) {
dev_err(glue->dev, "Failed to init phy.\n");
- goto err_phy_init;
+ goto fail;
}

ret = phy_power_on(glue->phy);
@@ -412,9 +412,8 @@ static int da8xx_musb_init(struct musb *musb)

err_phy_power_on:
phy_exit(glue->phy);
-err_phy_init:
- clk_disable_unprepare(glue->clk);
fail:
+ clk_disable_unprepare(glue->clk);
return ret;
}

--
2.7.3

2016-11-15 17:43:33

by Alexandre Bailon

[permalink] [raw]
Subject: [PATCH v6 2/2] usb: musb: da8xx: Set phy in OTG mode by default

The DA8xx OTG PHY has some issues when it is forced in host or
peripheral mode. Actually, most of the time, OTG is the best mode
because host or peripheral mode are only required for hardware that
miss some circuitry.
Init the PHY mode OTG mode by default.

Signed-off-by: Alexandre Bailon <[email protected]>
---
drivers/usb/musb/da8xx.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 4fc226c..e0dbe14 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -340,6 +340,13 @@ static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode)
struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
enum phy_mode phy_mode;

+ /*
+ * The PHY has some issues when it is forced in device or host mode.
+ * Unless the user request another mode, configure the PHY in OTG mode.
+ */
+ if (!musb->is_initialized)
+ return phy_set_mode(glue->phy, PHY_MODE_USB_OTG);
+
switch (musb_mode) {
case MUSB_HOST: /* Force VBUS valid, ID = 0 */
phy_mode = PHY_MODE_USB_HOST;
--
2.7.3

2016-11-18 18:12:52

by Bin Liu

[permalink] [raw]
Subject: Re: [PATCH v6 0/2] usb: musb: da8xx: Fix few issues

On Tue, Nov 15, 2016 at 06:42:45PM +0100, Alexandre Bailon wrote:
> This series require the following patch to build:
> [PATCH 1/6] usb: musb: Fix broken use of static variable for multiple instances
>
> Currently, the USB OTG of the da8xx doesn't work.
> This series intend to fix them.
>
> Change in v2:
> * Fix the error path da8xx_musb_init()
>
> Changes in v3:
> * Remove the host workaround that was not working on every platform
> * Add a property to the devicetree node of phy to force the phy in a specific
> mode (host or device).
> * Only use dr_mode to configure the controller mode and let the phy in OTG mode.
> The main goal of this change is to prevent the phy to be set in host or
> device mode because these modes have some issues.
>
> Changes in v4:
> * Enable VBUS sense and session end comparator during probe of phy.
> * Add a quirk flag to skip the phy set mode made during the init of musb.
> In that way, we can still can configure the phy mode by using mode file in
> sysfs and configure the controller mode by using dr_mode or platform_data.
> * Init the phy in otg mode in da8xx glue driver.
>
> Changes in v5:
> * Add the init argument to musb_platform_set_mode() and set_mode() callback.
> * Remove the quirk
> * Configure the DA8xx phy in OTG mode if da8xx_musb_set_mode() is called from
> init.
>
> Changes in v6:
> * Remove the patch that was adding a new parametter to musb_platform_set_mode().
> Instead, use the variable is_initialized.
> * The patch fixing the phy has been merged to phy-next, so I removed it from
> this series.
>
> Alexandre Bailon (2):
> usb: musb: da8xx: Call earlier clk_prepare_enable()
> usb: musb: da8xx: Set phy in OTG mode by default

Applied. Thanks.
-Bin.

>
> drivers/usb/musb/da8xx.c | 24 +++++++++++++++---------
> 1 file changed, 15 insertions(+), 9 deletions(-)
>
> --
> 2.7.3
>