Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab983f2a authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman
Browse files

musb: support disconnect after HNP roleswitch



Adjust HNP state machines in MUSB driver so that they handle the
case where the cable is disconnected.  The A-side machine was
very wrong (unrecoverable); the B-Side was much less so.

 - A_PERIPHERAL ... as usual, the non-observability of the ID
   pin through Mentor's registers makes trouble.  We can't go
   directly to A_WAIT_VFALL to end the session and start the
   disconnect processing.  We can however sense link suspending,
   go to A_WAIT_BCON, and from there use OTG timeouts to finally
   trigger that A_WAIT_VFALL transition.  (Hoping that nobody
   reconnects quickly to that port and notices the wrong state.)

 - B_HOST ... actually clear the Host Request (HR) bit as the
   messages say, disconnect the peripheral from the root hub,
   and don't detour through a suspend state.  (In some cases
   this would eventually have cleaned up.)

Also adjust the A_SUSPEND transition to respect the A_AIDL_BDIS
timeout, so if HNP doesn't trigger quickly enough the A_WAIT_VFALL
transition happens as it should.

Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1de00dae
Loading
Loading
Loading
Loading
+29 −12
Original line number Original line Diff line number Diff line
@@ -304,9 +304,11 @@ void musb_otg_timer_func(unsigned long data)
		musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
		musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
		musb->is_active = 0;
		musb->is_active = 0;
		break;
		break;
	case OTG_STATE_A_SUSPEND:
	case OTG_STATE_A_WAIT_BCON:
	case OTG_STATE_A_WAIT_BCON:
		DBG(1, "HNP: a_wait_bcon timeout; back to a_host\n");
		DBG(1, "HNP: %s timeout\n", otg_state_string(musb));
		musb_hnp_stop(musb);
		musb_set_vbus(musb, 0);
		musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
		break;
		break;
	default:
	default:
		DBG(1, "HNP: Unhandled mode %s\n", otg_state_string(musb));
		DBG(1, "HNP: Unhandled mode %s\n", otg_state_string(musb));
@@ -324,15 +326,12 @@ void musb_hnp_stop(struct musb *musb)
	void __iomem	*mbase = musb->mregs;
	void __iomem	*mbase = musb->mregs;
	u8	reg;
	u8	reg;


	DBG(1, "HNP: stop from %s\n", otg_state_string(musb));

	switch (musb->xceiv->state) {
	switch (musb->xceiv->state) {
	case OTG_STATE_A_PERIPHERAL:
	case OTG_STATE_A_PERIPHERAL:
	case OTG_STATE_A_WAIT_VFALL:
	case OTG_STATE_A_WAIT_BCON:
		DBG(1, "HNP: Switching back to A-host\n");
		musb_g_disconnect(musb);
		musb_g_disconnect(musb);
		musb->xceiv->state = OTG_STATE_A_IDLE;
		DBG(1, "HNP: back to %s\n", otg_state_string(musb));
		MUSB_HST_MODE(musb);
		musb->is_active = 0;
		break;
		break;
	case OTG_STATE_B_HOST:
	case OTG_STATE_B_HOST:
		DBG(1, "HNP: Disabling HR\n");
		DBG(1, "HNP: Disabling HR\n");
@@ -775,7 +774,16 @@ static irqreturn_t musb_stage2_irq(struct musb *musb, u8 int_usb,
#endif	/* HOST */
#endif	/* HOST */
#ifdef CONFIG_USB_MUSB_OTG
#ifdef CONFIG_USB_MUSB_OTG
		case OTG_STATE_B_HOST:
		case OTG_STATE_B_HOST:
			musb_hnp_stop(musb);
			/* REVISIT this behaves for "real disconnect"
			 * cases; make sure the other transitions from
			 * from B_HOST act right too.  The B_HOST code
			 * in hnp_stop() is currently not used...
			 */
			musb_root_disconnect(musb);
			musb_to_hcd(musb)->self.is_b_host = 0;
			musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
			MUSB_DEV_MODE(musb);
			musb_g_disconnect(musb);
			break;
			break;
		case OTG_STATE_A_PERIPHERAL:
		case OTG_STATE_A_PERIPHERAL:
			musb_hnp_stop(musb);
			musb_hnp_stop(musb);
@@ -807,10 +815,19 @@ static irqreturn_t musb_stage2_irq(struct musb *musb, u8 int_usb,
		switch (musb->xceiv->state) {
		switch (musb->xceiv->state) {
#ifdef	CONFIG_USB_MUSB_OTG
#ifdef	CONFIG_USB_MUSB_OTG
		case OTG_STATE_A_PERIPHERAL:
		case OTG_STATE_A_PERIPHERAL:
			/*
			/* We also come here if the cable is removed, since
			 * We cannot stop HNP here, devctl BDEVICE might be
			 * this silicon doesn't report ID-no-longer-grounded.
			 * still set.
			 *
			 * We depend on T(a_wait_bcon) to shut us down, and
			 * hope users don't do anything dicey during this
			 * undesired detour through A_WAIT_BCON.
			 */
			 */
			musb_hnp_stop(musb);
			usb_hcd_resume_root_hub(musb_to_hcd(musb));
			musb_root_disconnect(musb);
			musb_platform_try_idle(musb, jiffies
					+ msecs_to_jiffies(musb->a_wait_bcon
						? : OTG_TIME_A_WAIT_BCON));
			break;
			break;
#endif
#endif
		case OTG_STATE_B_PERIPHERAL:
		case OTG_STATE_B_PERIPHERAL:
+2 −0
Original line number Original line Diff line number Diff line
@@ -1962,9 +1962,11 @@ void musb_g_disconnect(struct musb *musb)
		DBG(2, "Unhandled disconnect %s, setting a_idle\n",
		DBG(2, "Unhandled disconnect %s, setting a_idle\n",
			otg_state_string(musb));
			otg_state_string(musb));
		musb->xceiv->state = OTG_STATE_A_IDLE;
		musb->xceiv->state = OTG_STATE_A_IDLE;
		MUSB_HST_MODE(musb);
		break;
		break;
	case OTG_STATE_A_PERIPHERAL:
	case OTG_STATE_A_PERIPHERAL:
		musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
		musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
		MUSB_HST_MODE(musb);
		break;
		break;
	case OTG_STATE_B_WAIT_ACON:
	case OTG_STATE_B_WAIT_ACON:
	case OTG_STATE_B_HOST:
	case OTG_STATE_B_HOST:
+4 −0
Original line number Original line Diff line number Diff line
@@ -83,6 +83,10 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
			musb->xceiv->state = OTG_STATE_A_SUSPEND;
			musb->xceiv->state = OTG_STATE_A_SUSPEND;
			musb->is_active = is_otg_enabled(musb)
			musb->is_active = is_otg_enabled(musb)
					&& musb->xceiv->host->b_hnp_enable;
					&& musb->xceiv->host->b_hnp_enable;
			if (musb->is_active)
				mod_timer(&musb->otg_timer, jiffies
					+ msecs_to_jiffies(
						OTG_TIME_A_AIDL_BDIS));
			musb_platform_try_idle(musb, 0);
			musb_platform_try_idle(musb, 0);
			break;
			break;
#ifdef	CONFIG_USB_MUSB_OTG
#ifdef	CONFIG_USB_MUSB_OTG