All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 0/7] usb: phy: twl4030-usb fixes
@ 2013-03-17 18:23 Grazvydas Ignotas
  2013-03-17 18:23 ` [PATCHv2 3/7] usb: phy: twl4030-usb: don't switch the phy on/off needlessly Grazvydas Ignotas
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-17 18:23 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-omap, Felipe Balbi, NeilBrown, kishon, Grazvydas Ignotas

I have a pandora board which has similar musb setup to beagleboard
(OMAP3530 + TWL4030) and musb never worked well on it for me in mainline.
Well it usually works if you plug the cable once, but as soon as you start
replugging cables and mixing host adapter into the game it totally breaks
and reboot is then needed. Host mode is especially broken, any replugs
after musb has been in host mode result in dead port that needs reboot
to recover.

With this series I can switch host/peripheral cables any way I like and
even suspend works with cable plugged with musb in peripheral mode!
("ARM: OMAP3: hwmod data: keep MIDLEMODE in force-standby for musb" is
needed that was sent separately). This also fixes power drain when cable
is plugged an no gadget driver is loaded.

Changed since v1:
- rebased on Felipe's testing branch
- added locking for patch 4 to take care of possible races
  between work item and IRQ
- changed patch 6 to only disable VBUS if not runtime suspended,
  otherwise we get data abort on OMAP3

Grazvydas Ignotas (7):
  usb: phy: twl4030-usb: don't enable PHY during init
  usb: phy: twl4030-usb: ignore duplicate events
  usb: phy: twl4030-usb: don't switch the phy on/off needlessly
  usb: phy: twl4030-usb: poll for ID disconnect
  usb: phy: twl4030-usb: check if vbus is driven by twl itself
  usb: musb: omap2430: turn off vbus on cable disconnect
  usb: musb: gadget: use platform callback to enable vbus

 drivers/usb/musb/musb_gadget.c    |    5 +-
 drivers/usb/musb/omap2430.c       |    1 +
 drivers/usb/phy/phy-twl4030-usb.c |  123 +++++++++++++++++++++++++++++--------
 3 files changed, 99 insertions(+), 30 deletions(-)

-- 
1.7.9.5


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

* [PATCHv2 1/7] usb: phy: twl4030-usb: don't enable PHY during init
       [not found] ` <1363544607-17634-1-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2013-03-17 18:23   ` Grazvydas Ignotas
  2013-03-17 18:23   ` [PATCHv2 2/7] usb: phy: twl4030-usb: ignore duplicate events Grazvydas Ignotas
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-17 18:23 UTC (permalink / raw)
  To: linux-usb-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA, Felipe Balbi, NeilBrown,
	kishon, Grazvydas Ignotas

There is no need to do it, otg.set_suspend(false) (which itself
comes from runtime_pm OMAP glue calls) will enable it later anyway.
This used to be the place where things were enabled if booted with
cable connected before runtime_pm conversion, but now can be dropped.

Signed-off-by: Grazvydas Ignotas <notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/usb/phy/phy-twl4030-usb.c |   20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
index a994715..9e47118 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -522,19 +522,17 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl)
 {
 	enum omap_musb_vbus_id_status status;
 
-	status = twl4030_usb_linkstat(twl);
-	if (status > 0) {
-		if (status == OMAP_MUSB_VBUS_OFF ||
-				status == OMAP_MUSB_ID_FLOAT) {
-			__twl4030_phy_power(twl, 0);
-			twl->asleep = 1;
-		} else {
-			__twl4030_phy_resume(twl);
-			twl->asleep = 0;
-		}
+	/*
+	 * Start in sleep state, we'll get called through set_suspend()
+	 * callback when musb is runtime resumed and it's time to start.
+	 */
+	__twl4030_phy_power(twl, 0);
+	twl->asleep = 1;
 
+	status = twl4030_usb_linkstat(twl);
+	if (status > 0)
 		omap_musb_mailbox(twl->linkstat);
-	}
+
 	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCHv2 2/7] usb: phy: twl4030-usb: ignore duplicate events
       [not found] ` <1363544607-17634-1-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2013-03-17 18:23   ` [PATCHv2 1/7] usb: phy: twl4030-usb: don't enable PHY during init Grazvydas Ignotas
@ 2013-03-17 18:23   ` Grazvydas Ignotas
  2013-03-17 18:23   ` [PATCHv2 4/7] usb: phy: twl4030-usb: poll for ID disconnect Grazvydas Ignotas
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-17 18:23 UTC (permalink / raw)
  To: linux-usb-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA, Felipe Balbi, NeilBrown,
	kishon, Grazvydas Ignotas

In some rare cases we may get multiple interrupts that will generate
duplicate omap_musb_mailbox() calls. This is a problem because each
VBUS/ID event generates runtime_pm call in OMAP glue code, causing
unbalanced gets or puts and breaking PM.

The same goes for initial state, glue already defaults to "no cable"
state, so only bother it if we have VBUS or ID.

Signed-off-by: Grazvydas Ignotas <notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Reviewed-by: Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>
---
 drivers/usb/phy/phy-twl4030-usb.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
index 9e47118..305463b 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -491,9 +491,10 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 {
 	struct twl4030_usb *twl = _twl;
 	enum omap_musb_vbus_id_status status;
+	enum omap_musb_vbus_id_status status_prev = twl->linkstat;
 
 	status = twl4030_usb_linkstat(twl);
-	if (status > 0) {
+	if (status > 0 && status != status_prev) {
 		/* FIXME add a set_power() method so that B-devices can
 		 * configure the charger appropriately.  It's not always
 		 * correct to consume VBUS power, and how much current to
@@ -530,7 +531,7 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl)
 	twl->asleep = 1;
 
 	status = twl4030_usb_linkstat(twl);
-	if (status > 0)
+	if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
 		omap_musb_mailbox(twl->linkstat);
 
 	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCHv2 3/7] usb: phy: twl4030-usb: don't switch the phy on/off needlessly
  2013-03-17 18:23 [PATCHv2 0/7] usb: phy: twl4030-usb fixes Grazvydas Ignotas
@ 2013-03-17 18:23 ` Grazvydas Ignotas
  2013-03-17 18:23 ` [PATCHv2 6/7] usb: musb: omap2430: turn off vbus on cable disconnect Grazvydas Ignotas
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-17 18:23 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-omap, Felipe Balbi, NeilBrown, kishon, Grazvydas Ignotas

With runtime_pm in place there is no longer need to turn the phy
on/off in OTG layer on cable connect/disconnect, OMAP glue does
this through otg.set_suspend() callback after it's called through
omap_musb_mailbox() on VBUS/ID interrupt. Not doing this will save
power when cable is connected but no gadget driver is loaded.

This will also have side effect of automatic USB charging no longer
working without twl4030_charger driver, because a regulator needed
for charging will no longer be enabled, so be sure to enable charger
driver if charging is needed.

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
---
 drivers/usb/phy/phy-twl4030-usb.c |    6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
index 305463b..b53a2a2 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -506,12 +506,6 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 		 * USB_LINK_VBUS state.  musb_hdrc won't care until it
 		 * starts to handle softconnect right.
 		 */
-		if (status == OMAP_MUSB_VBUS_OFF ||
-				status == OMAP_MUSB_ID_FLOAT)
-			twl4030_phy_suspend(twl, 0);
-		else
-			twl4030_phy_resume(twl);
-
 		omap_musb_mailbox(twl->linkstat);
 	}
 	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
-- 
1.7.9.5


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

* [PATCHv2 4/7] usb: phy: twl4030-usb: poll for ID disconnect
       [not found] ` <1363544607-17634-1-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2013-03-17 18:23   ` [PATCHv2 1/7] usb: phy: twl4030-usb: don't enable PHY during init Grazvydas Ignotas
  2013-03-17 18:23   ` [PATCHv2 2/7] usb: phy: twl4030-usb: ignore duplicate events Grazvydas Ignotas
@ 2013-03-17 18:23   ` Grazvydas Ignotas
  2013-03-17 18:23   ` [PATCHv2 5/7] usb: phy: twl4030-usb: check if vbus is driven by twl itself Grazvydas Ignotas
  2013-03-20 12:54   ` [PATCHv2 0/7] usb: phy: twl4030-usb fixes Felipe Balbi
  4 siblings, 0 replies; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-17 18:23 UTC (permalink / raw)
  To: linux-usb-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA, Felipe Balbi, NeilBrown,
	kishon, Grazvydas Ignotas

On pandora, STS_USB interrupt doesn't arrive on USB host cable disconnect
for some reason while VBUS is driven by twl itself, but STS_HW_CONDITIONS
is updated correctly. It does work fine when PHY is powered down though.
To work around that we have to poll.

This patch also moves twl->linkstat update code to callers so that
changes can be handled in thread safe way (as polling work can trigger
at the same time as real irq now).

TI PSP kernels have similar workarounds, so (many?) more boards are likely
affected.

Signed-off-by: Grazvydas Ignotas <notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/usb/phy/phy-twl4030-usb.c |   64 +++++++++++++++++++++++++++++++++----
 1 file changed, 57 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
index b53a2a2..425c18a 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -163,6 +163,8 @@ struct twl4030_usb {
 	bool			vbus_supplied;
 	u8			asleep;
 	bool			irq_enabled;
+
+	struct delayed_work	id_workaround_work;
 };
 
 /* internal define on top of container_of */
@@ -287,10 +289,6 @@ static enum omap_musb_vbus_id_status
 	 * are registered, and that both are active...
 	 */
 
-	spin_lock_irq(&twl->lock);
-	twl->linkstat = linkstat;
-	spin_unlock_irq(&twl->lock);
-
 	return linkstat;
 }
 
@@ -412,6 +410,16 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
 	__twl4030_phy_resume(twl);
 	twl->asleep = 0;
 	dev_dbg(twl->dev, "%s\n", __func__);
+
+	/*
+	 * XXX When VBUS gets driven after musb goes to A mode,
+	 * ID_PRES related interrupts no longer arrive, why?
+	 * Register itself is updated fine though, so we must poll.
+	 */
+	if (twl->linkstat == OMAP_MUSB_ID_GROUND) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+	}
 }
 
 static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
@@ -491,10 +499,18 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 {
 	struct twl4030_usb *twl = _twl;
 	enum omap_musb_vbus_id_status status;
-	enum omap_musb_vbus_id_status status_prev = twl->linkstat;
+	bool status_changed = false;
 
 	status = twl4030_usb_linkstat(twl);
-	if (status > 0 && status != status_prev) {
+
+	spin_lock_irq(&twl->lock);
+	if (status >= 0 && status != twl->linkstat) {
+		twl->linkstat = status;
+		status_changed = true;
+	}
+	spin_unlock_irq(&twl->lock);
+
+	if (status_changed) {
 		/* FIXME add a set_power() method so that B-devices can
 		 * configure the charger appropriately.  It's not always
 		 * correct to consume VBUS power, and how much current to
@@ -506,13 +522,42 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 		 * USB_LINK_VBUS state.  musb_hdrc won't care until it
 		 * starts to handle softconnect right.
 		 */
-		omap_musb_mailbox(twl->linkstat);
+		omap_musb_mailbox(status);
 	}
 	sysfs_notify(&twl->dev->kobj, NULL, "vbus");
 
 	return IRQ_HANDLED;
 }
 
+static void twl4030_id_workaround_work(struct work_struct *work)
+{
+	struct twl4030_usb *twl = container_of(work, struct twl4030_usb,
+		id_workaround_work.work);
+	enum omap_musb_vbus_id_status status;
+	bool status_changed = false;
+
+	status = twl4030_usb_linkstat(twl);
+
+	spin_lock_irq(&twl->lock);
+	if (status >= 0 && status != twl->linkstat) {
+		twl->linkstat = status;
+		status_changed = true;
+	}
+	spin_unlock_irq(&twl->lock);
+
+	if (status_changed) {
+		dev_dbg(twl->dev, "handle missing status change to %d\n",
+			status);
+		omap_musb_mailbox(status);
+	}
+
+	/* don't schedule during sleep - irq works right then */
+	if (status == OMAP_MUSB_ID_GROUND && !twl->asleep) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+	}
+}
+
 static void twl4030_usb_phy_init(struct twl4030_usb *twl)
 {
 	enum omap_musb_vbus_id_status status;
@@ -525,6 +570,8 @@ static void twl4030_usb_phy_init(struct twl4030_usb *twl)
 	twl->asleep = 1;
 
 	status = twl4030_usb_linkstat(twl);
+	twl->linkstat = status;
+
 	if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
 		omap_musb_mailbox(twl->linkstat);
 
@@ -613,6 +660,8 @@ static int twl4030_usb_probe(struct platform_device *pdev)
 	/* init spinlock for workqueue */
 	spin_lock_init(&twl->lock);
 
+	INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work);
+
 	err = twl4030_usb_ldo_init(twl);
 	if (err) {
 		dev_err(&pdev->dev, "ldo init failed\n");
@@ -656,6 +705,7 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev)
 	struct twl4030_usb *twl = platform_get_drvdata(pdev);
 	int val;
 
+	cancel_delayed_work(&twl->id_workaround_work);
 	free_irq(twl->irq, twl);
 	device_remove_file(twl->dev, &dev_attr_vbus);
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCHv2 5/7] usb: phy: twl4030-usb: check if vbus is driven by twl itself
       [not found] ` <1363544607-17634-1-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
                     ` (2 preceding siblings ...)
  2013-03-17 18:23   ` [PATCHv2 4/7] usb: phy: twl4030-usb: poll for ID disconnect Grazvydas Ignotas
@ 2013-03-17 18:23   ` Grazvydas Ignotas
       [not found]     ` <1363544607-17634-6-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2013-03-20 12:54   ` [PATCHv2 0/7] usb: phy: twl4030-usb fixes Felipe Balbi
  4 siblings, 1 reply; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-17 18:23 UTC (permalink / raw)
  To: linux-usb-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA, Felipe Balbi, NeilBrown,
	kishon, Grazvydas Ignotas

At least on pandora, STS_VBUS gets set even when VBUS is driven by twl
itself. Reporting VBUS in this case confuses OMAP musb glue and charger
driver, so check if OTG VBUS charge pump is on before reporting VBUS
event to avoid this problem.

Signed-off-by: Grazvydas Ignotas <notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/usb/phy/phy-twl4030-usb.c |   36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
index 425c18a..87bf11d 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -248,11 +248,31 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
 
 /*-------------------------------------------------------------------------*/
 
+static bool twl4030_is_driving_vbus(struct twl4030_usb *twl)
+{
+	int ret;
+
+	ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS);
+	if (ret < 0 || !(ret & PHY_DPLL_CLK))
+		/*
+		 * if clocks are off, registers are not updated,
+		 * but we can assume we don't drive VBUS in this case
+		 */
+		return false;
+
+	ret = twl4030_usb_read(twl, ULPI_OTG_CTRL);
+	if (ret < 0)
+		return false;
+
+	return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false;
+}
+
 static enum omap_musb_vbus_id_status
 	twl4030_usb_linkstat(struct twl4030_usb *twl)
 {
 	int	status;
 	enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN;
+	bool	driving_vbus = false;
 
 	twl->vbus_supplied = false;
 
@@ -270,20 +290,26 @@ static enum omap_musb_vbus_id_status
 	if (status < 0)
 		dev_err(twl->dev, "USB link status err %d\n", status);
 	else if (status & (BIT(7) | BIT(2))) {
-		if (status & (BIT(7)))
-                        twl->vbus_supplied = true;
+		if (status & BIT(7)) {
+			driving_vbus = twl4030_is_driving_vbus(twl);
+			if (driving_vbus)
+				status &= ~BIT(7);
+		}
 
 		if (status & BIT(2))
 			linkstat = OMAP_MUSB_ID_GROUND;
-		else
+		else if (status & BIT(7)) {
 			linkstat = OMAP_MUSB_VBUS_VALID;
+			twl->vbus_supplied = true;
+		} else
+			linkstat = OMAP_MUSB_VBUS_OFF;
 	} else {
 		if (twl->linkstat != OMAP_MUSB_UNKNOWN)
 			linkstat = OMAP_MUSB_VBUS_OFF;
 	}
 
-	dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
-			status, status, linkstat);
+	dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x; link %d, driving_vbus %d\n",
+		status, linkstat, driving_vbus);
 
 	/* REVISIT this assumes host and peripheral controllers
 	 * are registered, and that both are active...
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCHv2 6/7] usb: musb: omap2430: turn off vbus on cable disconnect
  2013-03-17 18:23 [PATCHv2 0/7] usb: phy: twl4030-usb fixes Grazvydas Ignotas
  2013-03-17 18:23 ` [PATCHv2 3/7] usb: phy: twl4030-usb: don't switch the phy on/off needlessly Grazvydas Ignotas
@ 2013-03-17 18:23 ` Grazvydas Ignotas
  2013-03-17 18:23 ` [PATCHv2 7/7] usb: musb: gadget: use platform callback to enable vbus Grazvydas Ignotas
       [not found] ` <1363544607-17634-1-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  3 siblings, 0 replies; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-17 18:23 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-omap, Felipe Balbi, NeilBrown, kishon, Grazvydas Ignotas

On USB_EVENT_ID event the musb glue enables VBUS by calling
omap2430_musb_set_vbus(musb, 1) that sets the session bit, but on
USB_EVENT_NONE reverse action is never made, and that breaks PM.

Disable VBUS on USB_EVENT_NONE to be sure musb session is ended
on cable unplug so that PM works.

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
---
 drivers/usb/musb/omap2430.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index ec460ea..780a750 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -291,6 +291,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 
 		musb->xceiv->last_event = USB_EVENT_NONE;
 		if (musb->gadget_driver) {
+			omap2430_musb_set_vbus(musb, 0);
 			pm_runtime_mark_last_busy(dev);
 			pm_runtime_put_autosuspend(dev);
 		}
-- 
1.7.9.5


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

* [PATCHv2 7/7] usb: musb: gadget: use platform callback to enable vbus
  2013-03-17 18:23 [PATCHv2 0/7] usb: phy: twl4030-usb fixes Grazvydas Ignotas
  2013-03-17 18:23 ` [PATCHv2 3/7] usb: phy: twl4030-usb: don't switch the phy on/off needlessly Grazvydas Ignotas
  2013-03-17 18:23 ` [PATCHv2 6/7] usb: musb: omap2430: turn off vbus on cable disconnect Grazvydas Ignotas
@ 2013-03-17 18:23 ` Grazvydas Ignotas
       [not found] ` <1363544607-17634-1-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  3 siblings, 0 replies; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-17 18:23 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-omap, Felipe Balbi, NeilBrown, kishon, Grazvydas Ignotas

On some platform configurations (like OMAP3+twl4030) it's the platform
code that enables VBUS, not OTG transceiver, so call vbus platform
callback instead, it will then call the transceiver if needed.

This fixes a use case where USB cable is plugged first and gadget
driver is loaded later after that.

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
---
 drivers/usb/musb/musb_gadget.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index ae59ee6..60eef20 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1799,9 +1799,8 @@ static int musb_gadget_start(struct usb_gadget *g,
 		goto err;
 	}
 
-	if ((musb->xceiv->last_event == USB_EVENT_ID)
-				&& otg->set_vbus)
-		otg_set_vbus(otg, 1);
+	if (musb->xceiv->last_event == USB_EVENT_ID)
+		musb_platform_set_vbus(musb, 1);
 
 	hcd->self.uses_pio_for_control = 1;
 
-- 
1.7.9.5


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

* Re: [PATCHv2 0/7] usb: phy: twl4030-usb fixes
       [not found] ` <1363544607-17634-1-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
                     ` (3 preceding siblings ...)
  2013-03-17 18:23   ` [PATCHv2 5/7] usb: phy: twl4030-usb: check if vbus is driven by twl itself Grazvydas Ignotas
@ 2013-03-20 12:54   ` Felipe Balbi
       [not found]     ` <20130320125425.GQ29659-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
  4 siblings, 1 reply; 13+ messages in thread
From: Felipe Balbi @ 2013-03-20 12:54 UTC (permalink / raw)
  To: Grazvydas Ignotas
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, Felipe Balbi, NeilBrown,
	kishon

[-- Attachment #1: Type: text/plain, Size: 1726 bytes --]

On Sun, Mar 17, 2013 at 08:23:20PM +0200, Grazvydas Ignotas wrote:
> I have a pandora board which has similar musb setup to beagleboard
> (OMAP3530 + TWL4030) and musb never worked well on it for me in mainline.
> Well it usually works if you plug the cable once, but as soon as you start
> replugging cables and mixing host adapter into the game it totally breaks
> and reboot is then needed. Host mode is especially broken, any replugs
> after musb has been in host mode result in dead port that needs reboot
> to recover.
> 
> With this series I can switch host/peripheral cables any way I like and
> even suspend works with cable plugged with musb in peripheral mode!
> ("ARM: OMAP3: hwmod data: keep MIDLEMODE in force-standby for musb" is
> needed that was sent separately). This also fixes power drain when cable
> is plugged an no gadget driver is loaded.
> 
> Changed since v1:
> - rebased on Felipe's testing branch
> - added locking for patch 4 to take care of possible races
>   between work item and IRQ
> - changed patch 6 to only disable VBUS if not runtime suspended,
>   otherwise we get data abort on OMAP3
> 
> Grazvydas Ignotas (7):
>   usb: phy: twl4030-usb: don't enable PHY during init
>   usb: phy: twl4030-usb: ignore duplicate events
>   usb: phy: twl4030-usb: don't switch the phy on/off needlessly
>   usb: phy: twl4030-usb: poll for ID disconnect
>   usb: phy: twl4030-usb: check if vbus is driven by twl itself
>   usb: musb: omap2430: turn off vbus on cable disconnect
>   usb: musb: gadget: use platform callback to enable vbus

since this falls into "has never worked before" I will apply them for
v3.10. If you have any objections, let me know.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCHv2 5/7] usb: phy: twl4030-usb: check if vbus is driven by twl itself
       [not found]     ` <1363544607-17634-6-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2013-03-20 13:07       ` Felipe Balbi
       [not found]         ` <20130320130750.GR29659-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Felipe Balbi @ 2013-03-20 13:07 UTC (permalink / raw)
  To: Grazvydas Ignotas
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, Felipe Balbi, NeilBrown,
	kishon

[-- Attachment #1: Type: text/plain, Size: 2198 bytes --]

On Sun, Mar 17, 2013 at 08:23:25PM +0200, Grazvydas Ignotas wrote:
> At least on pandora, STS_VBUS gets set even when VBUS is driven by twl
> itself. Reporting VBUS in this case confuses OMAP musb glue and charger
> driver, so check if OTG VBUS charge pump is on before reporting VBUS
> event to avoid this problem.
> 
> Signed-off-by: Grazvydas Ignotas <notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/usb/phy/phy-twl4030-usb.c |   36 +++++++++++++++++++++++++++++++-----
>  1 file changed, 31 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
> index 425c18a..87bf11d 100644
> --- a/drivers/usb/phy/phy-twl4030-usb.c
> +++ b/drivers/usb/phy/phy-twl4030-usb.c
> @@ -248,11 +248,31 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
>  
>  /*-------------------------------------------------------------------------*/
>  
> +static bool twl4030_is_driving_vbus(struct twl4030_usb *twl)
> +{
> +	int ret;
> +
> +	ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS);
> +	if (ret < 0 || !(ret & PHY_DPLL_CLK))
> +		/*
> +		 * if clocks are off, registers are not updated,
> +		 * but we can assume we don't drive VBUS in this case
> +		 */
> +		return false;
> +
> +	ret = twl4030_usb_read(twl, ULPI_OTG_CTRL);
> +	if (ret < 0)
> +		return false;
> +
> +	return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false;
> +}
> +
>  static enum omap_musb_vbus_id_status
>  	twl4030_usb_linkstat(struct twl4030_usb *twl)
>  {
>  	int	status;
>  	enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN;
> +	bool	driving_vbus = false;
>  
>  	twl->vbus_supplied = false;
>  
> @@ -270,20 +290,26 @@ static enum omap_musb_vbus_id_status
>  	if (status < 0)
>  		dev_err(twl->dev, "USB link status err %d\n", status);
>  	else if (status & (BIT(7) | BIT(2))) {
> -		if (status & (BIT(7)))
> -                        twl->vbus_supplied = true;
> +		if (status & BIT(7)) {
> +			driving_vbus = twl4030_is_driving_vbus(twl);
> +			if (driving_vbus)

how about just:

if (twl4030_is_driving_vbus(twl))
	status &= ~BIT(7);

????

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCHv2 0/7] usb: phy: twl4030-usb fixes
       [not found]     ` <20130320125425.GQ29659-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
@ 2013-03-20 13:08       ` Felipe Balbi
  0 siblings, 0 replies; 13+ messages in thread
From: Felipe Balbi @ 2013-03-20 13:08 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Grazvydas Ignotas, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, NeilBrown, kishon

[-- Attachment #1: Type: text/plain, Size: 1997 bytes --]

On Wed, Mar 20, 2013 at 02:54:25PM +0200, Felipe Balbi wrote:
> On Sun, Mar 17, 2013 at 08:23:20PM +0200, Grazvydas Ignotas wrote:
> > I have a pandora board which has similar musb setup to beagleboard
> > (OMAP3530 + TWL4030) and musb never worked well on it for me in mainline.
> > Well it usually works if you plug the cable once, but as soon as you start
> > replugging cables and mixing host adapter into the game it totally breaks
> > and reboot is then needed. Host mode is especially broken, any replugs
> > after musb has been in host mode result in dead port that needs reboot
> > to recover.
> > 
> > With this series I can switch host/peripheral cables any way I like and
> > even suspend works with cable plugged with musb in peripheral mode!
> > ("ARM: OMAP3: hwmod data: keep MIDLEMODE in force-standby for musb" is
> > needed that was sent separately). This also fixes power drain when cable
> > is plugged an no gadget driver is loaded.
> > 
> > Changed since v1:
> > - rebased on Felipe's testing branch
> > - added locking for patch 4 to take care of possible races
> >   between work item and IRQ
> > - changed patch 6 to only disable VBUS if not runtime suspended,
> >   otherwise we get data abort on OMAP3
> > 
> > Grazvydas Ignotas (7):
> >   usb: phy: twl4030-usb: don't enable PHY during init
> >   usb: phy: twl4030-usb: ignore duplicate events
> >   usb: phy: twl4030-usb: don't switch the phy on/off needlessly
> >   usb: phy: twl4030-usb: poll for ID disconnect
> >   usb: phy: twl4030-usb: check if vbus is driven by twl itself
> >   usb: musb: omap2430: turn off vbus on cable disconnect
> >   usb: musb: gadget: use platform callback to enable vbus
> 
> since this falls into "has never worked before" I will apply them for
> v3.10. If you have any objections, let me know.

I have applied up to 'poll for ID disconnect'. Please rebase the others
against my 'testing' branch once you update based on my comments.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCHv2 5/7] usb: phy: twl4030-usb: check if vbus is driven by twl itself
       [not found]         ` <20130320130750.GR29659-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
@ 2013-03-21 13:42           ` Grazvydas Ignotas
       [not found]             ` <CANOLnOOS6X95ijodL903zqLn3emNZ-rDX0xrxYQUXFJ1PR-PZw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Grazvydas Ignotas @ 2013-03-21 13:42 UTC (permalink / raw)
  To: balbi-l0cyMroinI0
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, NeilBrown, kishon

On Wed, Mar 20, 2013 at 3:07 PM, Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org> wrote:
> On Sun, Mar 17, 2013 at 08:23:25PM +0200, Grazvydas Ignotas wrote:
>> At least on pandora, STS_VBUS gets set even when VBUS is driven by twl
>> itself. Reporting VBUS in this case confuses OMAP musb glue and charger
>> driver, so check if OTG VBUS charge pump is on before reporting VBUS
>> event to avoid this problem.
>>
>> Signed-off-by: Grazvydas Ignotas <notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> ---
>>  drivers/usb/phy/phy-twl4030-usb.c |   36 +++++++++++++++++++++++++++++++-----
>>  1 file changed, 31 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
>> index 425c18a..87bf11d 100644
>> --- a/drivers/usb/phy/phy-twl4030-usb.c
>> +++ b/drivers/usb/phy/phy-twl4030-usb.c
>> @@ -248,11 +248,31 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
>>
>>  /*-------------------------------------------------------------------------*/
>>
>> +static bool twl4030_is_driving_vbus(struct twl4030_usb *twl)
>> +{
>> +     int ret;
>> +
>> +     ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS);
>> +     if (ret < 0 || !(ret & PHY_DPLL_CLK))
>> +             /*
>> +              * if clocks are off, registers are not updated,
>> +              * but we can assume we don't drive VBUS in this case
>> +              */
>> +             return false;
>> +
>> +     ret = twl4030_usb_read(twl, ULPI_OTG_CTRL);
>> +     if (ret < 0)
>> +             return false;
>> +
>> +     return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false;
>> +}
>> +
>>  static enum omap_musb_vbus_id_status
>>       twl4030_usb_linkstat(struct twl4030_usb *twl)
>>  {
>>       int     status;
>>       enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN;
>> +     bool    driving_vbus = false;
>>
>>       twl->vbus_supplied = false;
>>
>> @@ -270,20 +290,26 @@ static enum omap_musb_vbus_id_status
>>       if (status < 0)
>>               dev_err(twl->dev, "USB link status err %d\n", status);
>>       else if (status & (BIT(7) | BIT(2))) {
>> -             if (status & (BIT(7)))
>> -                        twl->vbus_supplied = true;
>> +             if (status & BIT(7)) {
>> +                     driving_vbus = twl4030_is_driving_vbus(twl);
>> +                     if (driving_vbus)
>
> how about just:
>
> if (twl4030_is_driving_vbus(twl))
>         status &= ~BIT(7);
>
> ????

I'm logging driving_vbus below with dev_dbg(), so that it's easier to
see what going on..

>
> --
> balbi

-- 
Gražvydas
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCHv2 5/7] usb: phy: twl4030-usb: check if vbus is driven by twl itself
       [not found]             ` <CANOLnOOS6X95ijodL903zqLn3emNZ-rDX0xrxYQUXFJ1PR-PZw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2013-03-21 16:43               ` Felipe Balbi
  0 siblings, 0 replies; 13+ messages in thread
From: Felipe Balbi @ 2013-03-21 16:43 UTC (permalink / raw)
  To: Grazvydas Ignotas
  Cc: balbi-l0cyMroinI0, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, NeilBrown, kishon

[-- Attachment #1: Type: text/plain, Size: 2759 bytes --]

Hi,

On Thu, Mar 21, 2013 at 03:42:46PM +0200, Grazvydas Ignotas wrote:
> >> At least on pandora, STS_VBUS gets set even when VBUS is driven by twl
> >> itself. Reporting VBUS in this case confuses OMAP musb glue and charger
> >> driver, so check if OTG VBUS charge pump is on before reporting VBUS
> >> event to avoid this problem.
> >>
> >> Signed-off-by: Grazvydas Ignotas <notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> >> ---
> >>  drivers/usb/phy/phy-twl4030-usb.c |   36 +++++++++++++++++++++++++++++++-----
> >>  1 file changed, 31 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
> >> index 425c18a..87bf11d 100644
> >> --- a/drivers/usb/phy/phy-twl4030-usb.c
> >> +++ b/drivers/usb/phy/phy-twl4030-usb.c
> >> @@ -248,11 +248,31 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
> >>
> >>  /*-------------------------------------------------------------------------*/
> >>
> >> +static bool twl4030_is_driving_vbus(struct twl4030_usb *twl)
> >> +{
> >> +     int ret;
> >> +
> >> +     ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS);
> >> +     if (ret < 0 || !(ret & PHY_DPLL_CLK))
> >> +             /*
> >> +              * if clocks are off, registers are not updated,
> >> +              * but we can assume we don't drive VBUS in this case
> >> +              */
> >> +             return false;
> >> +
> >> +     ret = twl4030_usb_read(twl, ULPI_OTG_CTRL);
> >> +     if (ret < 0)
> >> +             return false;
> >> +
> >> +     return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false;
> >> +}
> >> +
> >>  static enum omap_musb_vbus_id_status
> >>       twl4030_usb_linkstat(struct twl4030_usb *twl)
> >>  {
> >>       int     status;
> >>       enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN;
> >> +     bool    driving_vbus = false;
> >>
> >>       twl->vbus_supplied = false;
> >>
> >> @@ -270,20 +290,26 @@ static enum omap_musb_vbus_id_status
> >>       if (status < 0)
> >>               dev_err(twl->dev, "USB link status err %d\n", status);
> >>       else if (status & (BIT(7) | BIT(2))) {
> >> -             if (status & (BIT(7)))
> >> -                        twl->vbus_supplied = true;
> >> +             if (status & BIT(7)) {
> >> +                     driving_vbus = twl4030_is_driving_vbus(twl);
> >> +                     if (driving_vbus)
> >
> > how about just:
> >
> > if (twl4030_is_driving_vbus(twl))
> >         status &= ~BIT(7);
> >
> > ????
> 
> I'm logging driving_vbus below with dev_dbg(), so that it's easier to
> see what going on..

is that really necessary ? Don't we expose it through sysfs already ?

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2013-03-21 16:43 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-17 18:23 [PATCHv2 0/7] usb: phy: twl4030-usb fixes Grazvydas Ignotas
2013-03-17 18:23 ` [PATCHv2 3/7] usb: phy: twl4030-usb: don't switch the phy on/off needlessly Grazvydas Ignotas
2013-03-17 18:23 ` [PATCHv2 6/7] usb: musb: omap2430: turn off vbus on cable disconnect Grazvydas Ignotas
2013-03-17 18:23 ` [PATCHv2 7/7] usb: musb: gadget: use platform callback to enable vbus Grazvydas Ignotas
     [not found] ` <1363544607-17634-1-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-03-17 18:23   ` [PATCHv2 1/7] usb: phy: twl4030-usb: don't enable PHY during init Grazvydas Ignotas
2013-03-17 18:23   ` [PATCHv2 2/7] usb: phy: twl4030-usb: ignore duplicate events Grazvydas Ignotas
2013-03-17 18:23   ` [PATCHv2 4/7] usb: phy: twl4030-usb: poll for ID disconnect Grazvydas Ignotas
2013-03-17 18:23   ` [PATCHv2 5/7] usb: phy: twl4030-usb: check if vbus is driven by twl itself Grazvydas Ignotas
     [not found]     ` <1363544607-17634-6-git-send-email-notasas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-03-20 13:07       ` Felipe Balbi
     [not found]         ` <20130320130750.GR29659-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2013-03-21 13:42           ` Grazvydas Ignotas
     [not found]             ` <CANOLnOOS6X95ijodL903zqLn3emNZ-rDX0xrxYQUXFJ1PR-PZw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-03-21 16:43               ` Felipe Balbi
2013-03-20 12:54   ` [PATCHv2 0/7] usb: phy: twl4030-usb fixes Felipe Balbi
     [not found]     ` <20130320125425.GQ29659-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2013-03-20 13:08       ` Felipe Balbi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.