diff mbox

[v2] phy-twl4030-usb: better handle musb_mailbox() failure

Message ID 1471893862-12459-1-git-send-email-andreas@kemnade.info (mailing list archive)
State New, archived
Headers show

Commit Message

Andreas Kemnade Aug. 22, 2016, 7:24 p.m. UTC
setting twl->linkstat = MUSB_UNKNOWN upon error in musb_mailbox as
introduced in
commit 12b7db2bf8b8 ("usb: musb: Return error value from musb_mailbox")
causes twl4030_usb_irq() to not detect a state change form cable connected
to cable disconnected after such an error so that
pm_runtime_put_autosuspend() will not be called and the usage counter
gets unbalanced. Such errors happen e.g. if the omap2430 module is not
(yet) loaded during plug/unplug events.

This patch introduces a flag instead that indicates whether there is
information for the musb_mailbox pending and calls musb_mailbox() if
that flag is set.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
changes in v2: inverted logic, renamed flag to musb_mailbox_pending
 drivers/phy/phy-twl4030-usb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Tony Lindgren Aug. 23, 2016, 10:57 p.m. UTC | #1
* Andreas Kemnade <andreas@kemnade.info> [160822 12:25]:
> setting twl->linkstat = MUSB_UNKNOWN upon error in musb_mailbox as
> introduced in
> commit 12b7db2bf8b8 ("usb: musb: Return error value from musb_mailbox")
> causes twl4030_usb_irq() to not detect a state change form cable connected
> to cable disconnected after such an error so that
> pm_runtime_put_autosuspend() will not be called and the usage counter
> gets unbalanced. Such errors happen e.g. if the omap2430 module is not
> (yet) loaded during plug/unplug events.
> 
> This patch introduces a flag instead that indicates whether there is
> information for the musb_mailbox pending and calls musb_mailbox() if
> that flag is set.

Still works for me for PM:

Tested-by: Tony Lindgren <tony@atomide.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tony Lindgren Sept. 12, 2016, 3:26 p.m. UTC | #2
Hi,

* Kishon Vijay Abraham I <kishon@a0393678ub> [160910 05:23]:
> On Tue, Aug 23, 2016 at 03:57:24PM -0700, Tony Lindgren wrote:
> > * Andreas Kemnade <andreas@kemnade.info> [160822 12:25]:
> > > setting twl->linkstat = MUSB_UNKNOWN upon error in musb_mailbox as
> > > introduced in
> > > commit 12b7db2bf8b8 ("usb: musb: Return error value from musb_mailbox")
> > > causes twl4030_usb_irq() to not detect a state change form cable connected
> > > to cable disconnected after such an error so that
> > > pm_runtime_put_autosuspend() will not be called and the usage counter
> > > gets unbalanced. Such errors happen e.g. if the omap2430 module is not
> > > (yet) loaded during plug/unplug events.
> > > 
> > > This patch introduces a flag instead that indicates whether there is
> > > information for the musb_mailbox pending and calls musb_mailbox() if
> > > that flag is set.
> > 
> > Still works for me for PM:
> > 
> > Tested-by: Tony Lindgren <tony@atomide.com>
> 
> merged, thanks.

Just to be sure we're on the same page.. Kishon, this one is needed as a
regression fix for v4.8-rc cycle in addition to the "usb: musb: Fix
unbalanced platform_disable" that I've been working on.

Regards,

Tony

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Kishon Vijay Abraham I Sept. 14, 2016, 5:23 a.m. UTC | #3
Hi,

On Monday 12 September 2016 08:56 PM, Tony Lindgren wrote:
> Hi,
> 
> * Kishon Vijay Abraham I <kishon@a0393678ub> [160910 05:23]:
>> On Tue, Aug 23, 2016 at 03:57:24PM -0700, Tony Lindgren wrote:
>>> * Andreas Kemnade <andreas@kemnade.info> [160822 12:25]:
>>>> setting twl->linkstat = MUSB_UNKNOWN upon error in musb_mailbox as
>>>> introduced in
>>>> commit 12b7db2bf8b8 ("usb: musb: Return error value from musb_mailbox")
>>>> causes twl4030_usb_irq() to not detect a state change form cable connected
>>>> to cable disconnected after such an error so that
>>>> pm_runtime_put_autosuspend() will not be called and the usage counter
>>>> gets unbalanced. Such errors happen e.g. if the omap2430 module is not
>>>> (yet) loaded during plug/unplug events.
>>>>
>>>> This patch introduces a flag instead that indicates whether there is
>>>> information for the musb_mailbox pending and calls musb_mailbox() if
>>>> that flag is set.
>>>
>>> Still works for me for PM:
>>>
>>> Tested-by: Tony Lindgren <tony@atomide.com>
>>
>> merged, thanks.
> 
> Just to be sure we're on the same page.. Kishon, this one is needed as a
> regression fix for v4.8-rc cycle in addition to the "usb: musb: Fix
> unbalanced platform_disable" that I've been working on.

Okay. Thank you for letting me know this. I see still there are discussions in
the "usb: musb: Fix unbalanced platform_disable" thread. Would it be a problem
if this patch goes without the platform_disable patch?

Thanks
Kishon
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andreas Kemnade Sept. 14, 2016, 5:45 a.m. UTC | #4
On Wed, 14 Sep 2016 10:53:10 +0530
Kishon Vijay Abraham I <kishon@ti.com> wrote:

> Hi,
> 
> On Monday 12 September 2016 08:56 PM, Tony Lindgren wrote:
> > Hi,
> > 
> > * Kishon Vijay Abraham I <kishon@a0393678ub> [160910 05:23]:
> >> On Tue, Aug 23, 2016 at 03:57:24PM -0700, Tony Lindgren wrote:
> >>> * Andreas Kemnade <andreas@kemnade.info> [160822 12:25]:
> >>>> setting twl->linkstat = MUSB_UNKNOWN upon error in musb_mailbox
> >>>> as introduced in
> >>>> commit 12b7db2bf8b8 ("usb: musb: Return error value from
> >>>> musb_mailbox") causes twl4030_usb_irq() to not detect a state
> >>>> change form cable connected to cable disconnected after such an
> >>>> error so that pm_runtime_put_autosuspend() will not be called
> >>>> and the usage counter gets unbalanced. Such errors happen e.g.
> >>>> if the omap2430 module is not (yet) loaded during plug/unplug
> >>>> events.
> >>>>
> >>>> This patch introduces a flag instead that indicates whether
> >>>> there is information for the musb_mailbox pending and calls
> >>>> musb_mailbox() if that flag is set.
> >>>
> >>> Still works for me for PM:
> >>>
> >>> Tested-by: Tony Lindgren <tony@atomide.com>
> >>
> >> merged, thanks.
> > 
> > Just to be sure we're on the same page.. Kishon, this one is needed
> > as a regression fix for v4.8-rc cycle in addition to the "usb:
> > musb: Fix unbalanced platform_disable" that I've been working on.
> 
> Okay. Thank you for letting me know this. I see still there are
> discussions in the "usb: musb: Fix unbalanced platform_disable"
> thread. Would it be a problem if this patch goes without the
> platform_disable patch?

No problem. It can go without it (and my other phy patch can also
without it). 

Regards,
Andreas
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tony Lindgren Sept. 14, 2016, 4:58 p.m. UTC | #5
* Andreas Kemnade <andreas@kemnade.info> [160913 22:46]:
> On Wed, 14 Sep 2016 10:53:10 +0530
> Kishon Vijay Abraham I <kishon@ti.com> wrote:
> 
> > Hi,
> > 
> > On Monday 12 September 2016 08:56 PM, Tony Lindgren wrote:
> > > Hi,
> > > 
> > > * Kishon Vijay Abraham I <kishon@a0393678ub> [160910 05:23]:
> > >> On Tue, Aug 23, 2016 at 03:57:24PM -0700, Tony Lindgren wrote:
> > >>> * Andreas Kemnade <andreas@kemnade.info> [160822 12:25]:
> > >>>> setting twl->linkstat = MUSB_UNKNOWN upon error in musb_mailbox
> > >>>> as introduced in
> > >>>> commit 12b7db2bf8b8 ("usb: musb: Return error value from
> > >>>> musb_mailbox") causes twl4030_usb_irq() to not detect a state
> > >>>> change form cable connected to cable disconnected after such an
> > >>>> error so that pm_runtime_put_autosuspend() will not be called
> > >>>> and the usage counter gets unbalanced. Such errors happen e.g.
> > >>>> if the omap2430 module is not (yet) loaded during plug/unplug
> > >>>> events.
> > >>>>
> > >>>> This patch introduces a flag instead that indicates whether
> > >>>> there is information for the musb_mailbox pending and calls
> > >>>> musb_mailbox() if that flag is set.
> > >>>
> > >>> Still works for me for PM:
> > >>>
> > >>> Tested-by: Tony Lindgren <tony@atomide.com>
> > >>
> > >> merged, thanks.
> > > 
> > > Just to be sure we're on the same page.. Kishon, this one is needed
> > > as a regression fix for v4.8-rc cycle in addition to the "usb:
> > > musb: Fix unbalanced platform_disable" that I've been working on.
> > 
> > Okay. Thank you for letting me know this. I see still there are
> > discussions in the "usb: musb: Fix unbalanced platform_disable"
> > thread. Would it be a problem if this patch goes without the
> > platform_disable patch?
> 
> No problem. It can go without it (and my other phy patch can also
> without it). 

Yes it can go separately. I will send v3 of the musb fix with
the glue layer changes Bin suggested so Bin can take it.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index adf6b7e..4acec3c 100644
--- a/drivers/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -173,6 +173,7 @@  struct twl4030_usb {
 	int			irq;
 	enum musb_vbus_id_status linkstat;
 	bool			vbus_supplied;
+	bool			musb_mailbox_pending;
 
 	struct delayed_work	id_workaround_work;
 };
@@ -711,9 +712,12 @@  static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 			pm_runtime_mark_last_busy(twl->dev);
 			pm_runtime_put_autosuspend(twl->dev);
 		}
+		twl->musb_mailbox_pending = true;
+	}
+	if (twl->musb_mailbox_pending) {
 		err = musb_mailbox(status);
-		if (err)
-			twl->linkstat = MUSB_UNKNOWN;
+		if (!err)
+			twl->musb_mailbox_pending = false;
 	}
 
 	/* don't schedule during sleep - irq works right then */
@@ -826,6 +830,7 @@  printk("twl4030_usb_probe: otg = %p\n", otg);
 	twl->irq		= platform_get_irq(pdev, 0);
 	twl->vbus_supplied	= false;
 	twl->linkstat		= MUSB_UNKNOWN;
+	twl->musb_mailbox_pending = false;
 
 	twl->phy.dev		= twl->dev;
 	twl->phy.label		= "twl4030";