Skip to contentSkip to conversation

usb: musb: da8xx: Fix few issues

PATCH Superseded Alexandre Bailon 2 participants 7 messages Oct 25, 2016 – Oct 26, 2016

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover usb: musb: da8xx: Fix few issues

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

Alexandre Bailon (3):
usb: musb: da8xx: Only execute the OTG workaround when phy in OTG mode
usb: musb: da8xx: Fixup the OTG workaround
usb: musb: da8xx: Call earlier clk_prepare_enable()

 drivers/phy/phy-da8xx-usb.c | 17 ++++++++++++-----
 drivers/usb/musb/da8xx.c    | 23 +++++++++++++++++------
 2 files changed, 29 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.3
#1 lore raw

PATCH 1/3 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.

---
 drivers/usb/musb/da8xx.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/musb/da8xx.c +6 -6
index 210b7e4..ec93602 100644
@@ -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");
+		goto fail;
+	}
+
 	/* 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 */
Signature · 1 line
2.7.3
#2 lore raw

Re: [PATCH 1/3] usb: musb: da8xx: Call earlier clk_prepare_enable()

Quoted 14 lines · Alexandre Bailon

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.

---
 drivers/usb/musb/da8xx.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/musb/da8xx.c +0 -0
index 210b7e4..ec93602 100644

drivers/usb/musb/da8xx.c static int da8xx_musb_init(struct musb *musb) · line 372

Quoted 7 lines
drivers/usb/musb/da8xx.c +4 -0
@@ -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");
+		goto fail;

You can simply return ret; here instead of goto fail;

drivers/usb/musb/da8xx.c static int da8xx_musb_init(struct musb *musb) · line 383

Quoted 7 lines
drivers/usb/musb/da8xx.c +2 -0
+	}
+
 	/* 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;

The unwinding on error needs to be updated so that clk_disable_unprepare() is called at this point and subsequently. Currently, all goto fail; will return without disabling the clock.

Quoted 12 lines
drivers/usb/musb/da8xx.c +0 -6
 	}
 
-	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 */
#3 lore raw

PATCH 2/3 phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround

In reply to Alexandre Bailon

If we configure the da8xx OTG phy in OTG mode, neither device or host mode will work. That is because the PHY is not able to detect and notify the driver that value of ID pin changed.
To work despite this hardware limitation, the da8xx glue implement a workaround.
But to work, the workaround require the VBUS sense and the session end comparator to enabled.
Enable them if the phy is configured in OTG mode.

---
 drivers/phy/phy-da8xx-usb.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/phy/phy-da8xx-usb.c +12 -5
index 32ae78c..fd39292 100644
@@ -93,24 +93,31 @@ static int da8xx_usb20_phy_power_off(struct phy *phy)
 static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
 {
 	struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+	int ret;
 	u32 val;
 
+	ret = regmap_read(d_phy->regmap, CFGCHIP(2), &val);
+	if (ret)
+		return ret;
+
+	val &= ~CFGCHIP2_OTGMODE_MASK;
+
 	switch (mode) {
 	case PHY_MODE_USB_HOST:		/* Force VBUS valid, ID = 0 */
-		val = CFGCHIP2_OTGMODE_FORCE_HOST;
+		val |= CFGCHIP2_OTGMODE_FORCE_HOST;
 		break;
 	case PHY_MODE_USB_DEVICE:	/* Force VBUS valid, ID = 1 */
-		val = CFGCHIP2_OTGMODE_FORCE_DEVICE;
+		val |= CFGCHIP2_OTGMODE_FORCE_DEVICE;
 		break;
 	case PHY_MODE_USB_OTG:	/* Don't override the VBUS/ID comparators */
-		val = CFGCHIP2_OTGMODE_NO_OVERRIDE;
+		val |= CFGCHIP2_OTGMODE_NO_OVERRIDE |
+			CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGMODE_MASK,
-			  val);
+	regmap_write(d_phy->regmap, CFGCHIP(2), val);
 
 	return 0;
 }
Signature · 1 line
2.7.3
#4 lore raw

Re: [PATCH 2/3] phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround

Quoted 34 lines · Alexandre Bailon

If we configure the da8xx OTG phy in OTG mode, neither device or host mode will work. That is because the PHY is not able to detect and notify the driver that value of ID pin changed.
To work despite this hardware limitation, the da8xx glue implement a workaround.
But to work, the workaround require the VBUS sense and the session end comparator to enabled.
Enable them if the phy is configured in OTG mode.

---
 drivers/phy/phy-da8xx-usb.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/phy/phy-da8xx-usb.c +7 -1
index 32ae78c..fd39292 100644
@@ -93,24 +93,31 @@ static int da8xx_usb20_phy_power_off(struct phy *phy)
 static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
 {
 	struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+	int ret;
 	u32 val;
 
+	ret = regmap_read(d_phy->regmap, CFGCHIP(2), &val);
+	if (ret)
+		return ret;
+
+	val &= ~CFGCHIP2_OTGMODE_MASK;
+
 	switch (mode) {
 	case PHY_MODE_USB_HOST:		/* Force VBUS valid, ID = 0 */
-		val = CFGCHIP2_OTGMODE_FORCE_HOST;

drivers/phy/phy-da8xx-usb.c static int da8xx_usb20_phy_power_off(struct phy *phy) · line 114

Quoted 10 lines
drivers/phy/phy-da8xx-usb.c +4 -2
+		val |= CFGCHIP2_OTGMODE_FORCE_HOST;
 		break;
 	case PHY_MODE_USB_DEVICE:	/* Force VBUS valid, ID = 1 */
-		val = CFGCHIP2_OTGMODE_FORCE_DEVICE;
+		val |= CFGCHIP2_OTGMODE_FORCE_DEVICE;
 		break;
 	case PHY_MODE_USB_OTG:	/* Don't override the VBUS/ID comparators */
-		val = CFGCHIP2_OTGMODE_NO_OVERRIDE;
+		val |= CFGCHIP2_OTGMODE_NO_OVERRIDE |
+			CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;

Do we need to clear CFGCHIP2_SESENDEN and/or CFGCHIP2_VBDTCTEN in case PHY_MODE_USB_HOST: or case PHY_MODE_USB_DEVICE:? Or are they ignored in those modes?

Quoted 12 lines
drivers/phy/phy-da8xx-usb.c +1 -2
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGMODE_MASK,
-			  val);
+	regmap_write(d_phy->regmap, CFGCHIP(2), val);
 
 	return 0;
 }
#5 lore raw

Re: [PATCH 2/3] phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround

Quoted 42 lines · David Lechner
Quoted 41 lines · Alexandre Bailon

If we configure the da8xx OTG phy in OTG mode, neither device or host mode will work. That is because the PHY is not able to detect and notify the driver that value of ID pin changed.
To work despite this hardware limitation, the da8xx glue implement a workaround.
But to work, the workaround require the VBUS sense and the session end comparator to enabled.
Enable them if the phy is configured in OTG mode.

---
 drivers/phy/phy-da8xx-usb.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/phy/phy-da8xx-usb.c +9 -2
index 32ae78c..fd39292 100644
@@ -93,24 +93,31 @@ static int da8xx_usb20_phy_power_off(struct phy *phy)
 static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
 {
     struct da8xx_usb_phy *d_phy = phy_get_drvdata(phy);
+    int ret;
     u32 val;
 
+    ret = regmap_read(d_phy->regmap, CFGCHIP(2), &val);
+    if (ret)
+        return ret;
+
+    val &= ~CFGCHIP2_OTGMODE_MASK;
+
     switch (mode) {
     case PHY_MODE_USB_HOST:        /* Force VBUS valid, ID = 0 */
-        val = CFGCHIP2_OTGMODE_FORCE_HOST;
+        val |= CFGCHIP2_OTGMODE_FORCE_HOST;
         break;
     case PHY_MODE_USB_DEVICE:    /* Force VBUS valid, ID = 1 */
-        val = CFGCHIP2_OTGMODE_FORCE_DEVICE;
+        val |= CFGCHIP2_OTGMODE_FORCE_DEVICE;
         break;
     case PHY_MODE_USB_OTG:    /* Don't override the VBUS/ID
Quoted 8 lines

drivers/phy/phy-da8xx-usb.c static int da8xx_usb20_phy_power_off(struct phy *phy) · line 114

Quoted 4 lines

comparators */

drivers/phy/phy-da8xx-usb.c +2 -1
-        val = CFGCHIP2_OTGMODE_NO_OVERRIDE;
+        val |= CFGCHIP2_OTGMODE_NO_OVERRIDE |
+            CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;

Do we need to clear CFGCHIP2_SESENDEN and/or CFGCHIP2_VBDTCTEN in case
PHY_MODE_USB_HOST: or case PHY_MODE_USB_DEVICE:? Or are they ignored in those modes?

Actually, I don't know. The datasheet is quite confusing. The "USB PHY Initialization" section seems to speak only about OTG mode. But my observation let me think they are ignored when the phy is forced in device or host mode.

Quoted 14 lines
Quoted 13 lines
         break;
     default:
         return -EINVAL;
     }
drivers/phy/phy-da8xx-usb.c +1 -2
-    regmap_write_bits(d_phy->regmap, CFGCHIP(2), CFGCHIP2_OTGMODE_MASK,
-              val);
+    regmap_write(d_phy->regmap, CFGCHIP(2), val);
 
     return 0;
 }
#6 lore raw

PATCH 3/3 usb: musb: da8xx: Only execute the OTG workaround when phy in OTG mode

In reply to Alexandre Bailon

When the phy is forced in host mode, only the first hot plug and hot remove works. That is actually because the driver execute the OTG workaround, whereas it is not applicable in host or device mode. Indeed, to work correctly, the VBUS sense and session end comparator must be enabled, what is only possible when the phy is in OTG mode. Only execute the workaround if the phy is in OTG mode.

---
 drivers/usb/musb/da8xx.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/usb/musb/da8xx.c +11 -0
index ec93602..be10c51 100644
@@ -145,6 +145,17 @@ static void otg_timer(unsigned long _musb)
 	unsigned long		flags;
 
 	/*
+	 * We should only execute the OTG workaround when the phy is in OTG
+	 * mode. The workaround require the VBUS sense and the session end
+	 * comparator to be enabled, what is only possible if the phy is in
+	 * OTG mode. As the workaround is only required to detect if the
+	 * controller must act as host or device, we can safely exit OTG is
+	 * not in use.
+	 */
+	if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE)
+		return;
+
+	/*
 	 * We poll because DaVinci's won't expose several OTG-critical
 	 * status change events (from the transceiver) otherwise.
 	 */
Signature · 1 line
2.7.3