linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
To: Bin Liu <b-liu-l0cyMroinI0@public.gmane.org>
Cc: Boris Brezillon
	<boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	Andreas Kemnade <andreas-cLv4Z9ELZ06ZuzBka8ofvg@public.gmane.org>,
	Felipe Balbi <balbi-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	George Cherian <george.cherian-l0cyMroinI0@public.gmane.org>,
	Kishon Vijay Abraham I <kishon-l0cyMroinI0@public.gmane.org>,
	Ivaylo Dimitrov
	<ivo.g.dimitrov.75-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Johan Hovold <johan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Ladislav Michl <ladis-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org>,
	Laurent Pinchart
	<laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>,
	Sergei Shtylyov
	<sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 3/4] usb: musb: Fix PM for hub disconnect
Date: Mon,  7 Nov 2016 14:50:19 -0700	[thread overview]
Message-ID: <20161107215020.31399-4-tony@atomide.com> (raw)
In-Reply-To: <20161107215020.31399-1-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>

With a USB hub disconnected, devctl can be 0x19 for about a second
on am335x and will stay forever on at least omap3. And we get no
further interrupts when devctl session bit clears. This keeps
PM runtime active.

Let's fix the issue by polling devctl until the session bit clears
or times out. We can do this by making musb->irq_work into
delayed_work.

And with the polling implemented, we can now also have the quirk
for invalid VBUS it to avoid disconnecting too early while VBUS
is ramping up.

Fixes: 467d5c980709 ("usb: musb: Implement session bit based runtime
PM for musb-core")
Fixes: 65b3f50ed6fa ("usb: musb: Add PM runtime support for MUSB DSPS
Signed-off-by: Tony Lindgren <tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
---
 drivers/usb/musb/musb_core.c   | 29 +++++++++++++++++++----------
 drivers/usb/musb/musb_core.h   |  4 ++--
 drivers/usb/musb/musb_gadget.c |  6 +++---
 drivers/usb/musb/tusb6010.c    |  6 +++---
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -986,7 +986,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
 	}
 #endif
 
-	schedule_work(&musb->irq_work);
+	schedule_delayed_work(&musb->irq_work, 0);
 
 	return handled;
 }
@@ -1855,14 +1855,23 @@ static void musb_pm_runtime_check_session(struct musb *musb)
 		MUSB_DEVCTL_HR;
 	switch (devctl & ~s) {
 	case MUSB_QUIRK_B_INVALID_VBUS_91:
-		if (!musb->session && !musb->quirk_invalid_vbus) {
-			musb->quirk_invalid_vbus = true;
+		if (musb->quirk_retries--) {
 			musb_dbg(musb,
-				 "First invalid vbus, assume no session");
+				 "Poll devctl on invalid vbus, assume no session");
+			schedule_delayed_work(&musb->irq_work,
+					      msecs_to_jiffies(1000));
+
 			return;
 		}
-		break;
 	case MUSB_QUIRK_A_DISCONNECT_19:
+		if (musb->quirk_retries--) {
+			musb_dbg(musb,
+				 "Poll devctl on possible host mode disconnect");
+			schedule_delayed_work(&musb->irq_work,
+					      msecs_to_jiffies(1000));
+
+			return;
+		}
 		if (!musb->session)
 			break;
 		musb_dbg(musb, "Allow PM on possible host mode disconnect");
@@ -1886,9 +1895,9 @@ static void musb_pm_runtime_check_session(struct musb *musb)
 		if (error < 0)
 			dev_err(musb->controller, "Could not enable: %i\n",
 				error);
+		musb->quirk_retries = 3;
 	} else {
 		musb_dbg(musb, "Allow PM with no session: %02x", devctl);
-		musb->quirk_invalid_vbus = false;
 		pm_runtime_mark_last_busy(musb->controller);
 		pm_runtime_put_autosuspend(musb->controller);
 	}
@@ -1899,7 +1908,7 @@ static void musb_pm_runtime_check_session(struct musb *musb)
 /* Only used to provide driver mode change events */
 static void musb_irq_work(struct work_struct *data)
 {
-	struct musb *musb = container_of(data, struct musb, irq_work);
+	struct musb *musb = container_of(data, struct musb, irq_work.work);
 
 	musb_pm_runtime_check_session(musb);
 
@@ -2275,7 +2284,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
 	musb_generic_disable(musb);
 
 	/* Init IRQ workqueue before request_irq */
-	INIT_WORK(&musb->irq_work, musb_irq_work);
+	INIT_DELAYED_WORK(&musb->irq_work, musb_irq_work);
 	INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset);
 	INIT_DELAYED_WORK(&musb->pending_resume_work, musb_pending_work);
 	INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume);
@@ -2373,7 +2382,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
 	musb_host_cleanup(musb);
 
 fail3:
-	cancel_work_sync(&musb->irq_work);
+	cancel_delayed_work_sync(&musb->irq_work);
 	cancel_delayed_work_sync(&musb->finish_resume_work);
 	cancel_delayed_work_sync(&musb->pending_resume_work);
 	cancel_delayed_work_sync(&musb->deassert_reset_work);
@@ -2441,7 +2450,7 @@ static int musb_remove(struct platform_device *pdev)
 	 */
 	musb_exit_debugfs(musb);
 
-	cancel_work_sync(&musb->irq_work);
+	cancel_delayed_work_sync(&musb->irq_work);
 	cancel_delayed_work_sync(&musb->finish_resume_work);
 	cancel_delayed_work_sync(&musb->pending_resume_work);
 	cancel_delayed_work_sync(&musb->deassert_reset_work);
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -310,7 +310,7 @@ struct musb {
 	struct musb_context_registers context;
 
 	irqreturn_t		(*isr)(int, void *);
-	struct work_struct	irq_work;
+	struct delayed_work	irq_work;
 	struct delayed_work	deassert_reset_work;
 	struct delayed_work	pending_resume_work;
 	struct delayed_work	finish_resume_work;
@@ -382,7 +382,7 @@ struct musb {
 
 	int			port_mode;	/* MUSB_PORT_MODE_* */
 	bool			session;
-	bool			quirk_invalid_vbus;
+	unsigned long		quirk_retries;
 	bool			is_host;
 
 	int			a_wait_bcon;	/* VBUS timeout in msecs */
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1114,7 +1114,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
 			musb_ep->dma ? "dma, " : "",
 			musb_ep->packet_sz);
 
-	schedule_work(&musb->irq_work);
+	schedule_delayed_work(&musb->irq_work, 0);
 
 fail:
 	spin_unlock_irqrestore(&musb->lock, flags);
@@ -1158,7 +1158,7 @@ static int musb_gadget_disable(struct usb_ep *ep)
 	musb_ep->desc = NULL;
 	musb_ep->end_point.desc = NULL;
 
-	schedule_work(&musb->irq_work);
+	schedule_delayed_work(&musb->irq_work, 0);
 
 	spin_unlock_irqrestore(&(musb->lock), flags);
 
@@ -1985,7 +1985,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
 	 */
 
 	/* Force check of devctl register for PM runtime */
-	schedule_work(&musb->irq_work);
+	schedule_delayed_work(&musb->irq_work, 0);
 
 	pm_runtime_mark_last_busy(musb->controller);
 	pm_runtime_put_autosuspend(musb->controller);
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -724,7 +724,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
 			dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
 				usb_otg_state_string(musb->xceiv->otg->state), otg_stat);
 			idle_timeout = jiffies + (1 * HZ);
-			schedule_work(&musb->irq_work);
+			schedule_delayed_work(&musb->irq_work, 0);
 
 		} else /* A-dev state machine */ {
 			dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
@@ -814,7 +814,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
 			break;
 		}
 	}
-	schedule_work(&musb->irq_work);
+	schedule_delayed_work(&musb->irq_work, 0);
 
 	return idle_timeout;
 }
@@ -864,7 +864,7 @@ static irqreturn_t tusb_musb_interrupt(int irq, void *__hci)
 		musb_writel(tbase, TUSB_PRCM_WAKEUP_CLEAR, reg);
 		if (reg & ~TUSB_PRCM_WNORCS) {
 			musb->is_active = 1;
-			schedule_work(&musb->irq_work);
+			schedule_delayed_work(&musb->irq_work, 0);
 		}
 		dev_dbg(musb->controller, "wake %sactive %02x\n",
 				musb->is_active ? "" : "in", reg);
-- 
2.10.2
--
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

  parent reply	other threads:[~2016-11-07 21:50 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-07 21:50 [PATCH 0/4] musb fixes for v4.9-rc cycle Tony Lindgren
     [not found] ` <20161107215020.31399-1-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-07 21:50   ` [PATCH 1/4] usb: musb: Fix broken use of static variable for multiple instances Tony Lindgren
     [not found]     ` <20161107215020.31399-2-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-08 17:10       ` Johan Hovold
2016-11-07 21:50   ` [PATCH 2/4] usb: musb: Fix sleeping function called from invalid context for hdrc glue Tony Lindgren
     [not found]     ` <20161107215020.31399-3-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-08 17:09       ` Johan Hovold
2016-11-08 17:34         ` Tony Lindgren
     [not found]           ` <20161108173413.GM2428-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-08 19:03             ` Johan Hovold
2016-11-09  1:26               ` Tony Lindgren
     [not found]                 ` <20161109012606.GR2428-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-09 15:34                   ` Tony Lindgren
     [not found]                     ` <20161109153409.GU2428-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-09 15:50                       ` Johan Hovold
2016-11-09 15:39                   ` Johan Hovold
2016-11-09 16:04                     ` Johan Hovold
2016-11-09 17:54                     ` Tony Lindgren
     [not found]                       ` <20161109175437.GZ2428-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-10 16:04                         ` Johan Hovold
2016-11-10 17:41                           ` Tony Lindgren
     [not found]                             ` <20161110174150.GC27724-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-10 18:02                               ` Tony Lindgren
     [not found]                                 ` <20161110180234.GH27724-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-10 18:04                                   ` Johan Hovold
2016-11-10 18:42                               ` Johan Hovold
2016-11-10 19:40                                 ` Tony Lindgren
     [not found]                                   ` <20161110194003.GI27724-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-11 12:03                                     ` Johan Hovold
2016-11-11 15:42                                       ` Tony Lindgren
     [not found]                                         ` <20161111154250.GB7138-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-11 16:40                                           ` Johan Hovold
2016-11-11 16:50                                             ` Tony Lindgren
2016-11-07 21:50   ` Tony Lindgren [this message]
2016-11-07 21:50   ` [PATCH 4/4] phy: twl4030-usb: Fix for musb session bit based PM Tony Lindgren
2016-11-08 13:38   ` [PATCH 0/4] musb fixes for v4.9-rc cycle Ladislav Michl
     [not found]     ` <20161108133821.GA1855-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2016-11-08 14:49       ` Tony Lindgren
     [not found]         ` <20161108144934.GK2428-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-08 14:55           ` Tony Lindgren
     [not found]             ` <20161108145550.GL2428-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-08 17:19               ` Ladislav Michl
     [not found]                 ` <20161108171951.GA27533-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2016-11-08 22:05                   ` Tony Lindgren
     [not found]                     ` <20161108220530.GO2428-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-08 22:52                       ` Ladislav Michl
     [not found]                         ` <20161108225206.GA14049-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2016-11-08 23:16                           ` Tony Lindgren
     [not found]                             ` <20161108231637.GP2428-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-08 23:39                               ` Ladislav Michl
     [not found]                                 ` <20161108233934.GA25005-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2016-11-08 23:47                                   ` Tony Lindgren
2016-11-10 12:46   ` Laurent Pinchart
2016-11-10 15:01     ` Tony Lindgren
     [not found]       ` <20161110150152.GA27724-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-10 17:18         ` Laurent Pinchart
2016-11-10 17:25           ` Laurent Pinchart
2016-11-10 17:43           ` Laurent Pinchart
2016-11-10 17:50           ` Tony Lindgren
     [not found]             ` <20161110175033.GD27724-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-10 20:29               ` Laurent Pinchart
2016-11-10 20:42                 ` Tony Lindgren
     [not found]                   ` <20161110204233.GJ27724-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-10 22:27                     ` Laurent Pinchart
2016-11-10 23:39                       ` Laurent Pinchart
2016-11-11 16:24                         ` Bin Liu
2016-11-11 16:53                           ` Tony Lindgren
     [not found]                             ` <20161111165321.GF7138-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-11 22:11                               ` Laurent Pinchart
2016-11-11 23:06                                 ` Bin Liu
2016-11-12  1:21                                   ` Laurent Pinchart
2016-12-20 18:40                                     ` Ladislav Michl
2016-12-20 20:59                                       ` Tony Lindgren
2016-11-10 21:25                 ` Laurent Pinchart
2016-11-10 21:56                   ` Tony Lindgren
2016-11-23 10:14                   ` Tomi Valkeinen
     [not found]                     ` <839f0f26-3bb0-d368-8cff-dbccaffa7244-l0cyMroinI0@public.gmane.org>
2016-11-23 15:49                       ` Laurent Pinchart
2016-11-23 15:54                         ` Tomi Valkeinen
     [not found]                           ` <47c6e11e-3725-8955-5cc4-654df4d1c3bc-l0cyMroinI0@public.gmane.org>
2016-11-23 15:57                             ` Tony Lindgren
     [not found]                               ` <20161123155747.GF4082-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-23 16:13                                 ` Tomi Valkeinen
     [not found]                                   ` <c76fd922-9ac8-3b32-902a-7839a4817109-l0cyMroinI0@public.gmane.org>
2016-11-23 16:34                                     ` Tony Lindgren
     [not found]                                       ` <20161123163448.GJ4082-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-11-23 16:40                                         ` Tomi Valkeinen
     [not found]                                           ` <19526c30-5f18-337a-1e73-7f8965a778c1-l0cyMroinI0@public.gmane.org>
2016-11-23 16:44                                             ` Tony Lindgren
2016-11-23 16:44                                             ` Laurent Pinchart
2016-12-08  5:51                                               ` Tony Lindgren
     [not found]                                                 ` <20161208055122.GC4264-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2016-12-08 12:03                                                   ` Laurent Pinchart
2016-12-08 18:47                                                     ` Tony Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161107215020.31399-4-tony@atomide.com \
    --to=tony-4v6ys6ai5vpbdgjk7y7tuq@public.gmane.org \
    --cc=andreas-cLv4Z9ELZ06ZuzBka8ofvg@public.gmane.org \
    --cc=b-liu-l0cyMroinI0@public.gmane.org \
    --cc=balbi-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=george.cherian-l0cyMroinI0@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=ivo.g.dimitrov.75-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=johan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=kishon-l0cyMroinI0@public.gmane.org \
    --cc=ladis-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org \
    --cc=laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org \
    --cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).