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

Commit bcb8fd3a authored by Bin Liu's avatar Bin Liu Committed by Greg Kroah-Hartman
Browse files

usb: musb: break the huge isr musb_stage0_irq() into small functions



musb_stage0_irq() is 400+ lines long. Break its interrupt events
handling into each individual functions to make it easy to read.

Signed-off-by: default avatarBin Liu <b-liu@ti.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2bc2e05f
Loading
Loading
Loading
Loading
+384 −346
Original line number Diff line number Diff line
@@ -523,31 +523,8 @@ void musb_hnp_stop(struct musb *musb)

static void musb_recover_from_babble(struct musb *musb);

/*
 * Interrupt Service Routine to record USB "global" interrupts.
 * Since these do not happen often and signify things of
 * paramount importance, it seems OK to check them individually;
 * the order of the tests is specified in the manual
 *
 * @param musb instance pointer
 * @param int_usb register contents
 * @param devctl
 * @param power
 */

static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
				u8 devctl)
static void musb_handle_intr_resume(struct musb *musb, u8 devctl)
{
	irqreturn_t handled = IRQ_NONE;

	musb_dbg(musb, "<== DevCtl=%02x, int_usb=0x%x", devctl, int_usb);

	/* in host mode, the peripheral may issue remote wakeup.
	 * in peripheral mode, the host may resume the link.
	 * spurious RESUME irqs happen too, paired with SUSPEND.
	 */
	if (int_usb & MUSB_INTR_RESUME) {
		handled = IRQ_HANDLED;
	musb_dbg(musb, "RESUME (%s)",
			usb_otg_state_string(musb->xceiv->otg->state));

@@ -608,8 +585,9 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
	}
}

	/* see manual for the order of the tests */
	if (int_usb & MUSB_INTR_SESSREQ) {
/* return IRQ_HANDLED to tell the caller to return immediately */
static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl)
{
	void __iomem *mbase = musb->mregs;

	if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS
@@ -634,10 +612,11 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
	MUSB_HST_MODE(musb);
	musb_platform_set_vbus(musb, 1);

		handled = IRQ_HANDLED;
	return IRQ_NONE;
}

	if (int_usb & MUSB_INTR_VBUSERROR) {
static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl)
{
	int	ignore = 0;

	/* During connection as an A-Device, we may see a short
@@ -705,13 +684,12 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
	/* go through A_WAIT_VFALL then start a new session */
	if (!ignore)
		musb_platform_set_vbus(musb, 0);
		handled = IRQ_HANDLED;
}

	if (int_usb & MUSB_INTR_SUSPEND) {
static void musb_handle_intr_suspend(struct musb *musb, u8 devctl)
{
	musb_dbg(musb, "SUSPEND (%s) devctl %02x",
		usb_otg_state_string(musb->xceiv->otg->state), devctl);
		handled = IRQ_HANDLED;

	switch (musb->xceiv->otg->state) {
	case OTG_STATE_A_PERIPHERAL:
@@ -765,12 +743,11 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
	}
}

	if (int_usb & MUSB_INTR_CONNECT) {
static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb)
{
	struct usb_hcd *hcd = musb->hcd;

		handled = IRQ_HANDLED;
	musb->is_active = 1;

	musb->ep0_stage = MUSB_EP0_START;

	musb->intrtxe = musb->epmask;
@@ -823,11 +800,11 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
			usb_otg_state_string(musb->xceiv->otg->state), devctl);
}

	if (int_usb & MUSB_INTR_DISCONNECT) {
static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl)
{
	musb_dbg(musb, "DISCONNECT (%s) as %s, devctl %02x",
			usb_otg_state_string(musb->xceiv->otg->state),
			MUSB_MODE(musb), devctl);
		handled = IRQ_HANDLED;

	switch (musb->xceiv->otg->state) {
	case OTG_STATE_A_HOST:
@@ -868,11 +845,12 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
	}
}

	/* mentor saves a bit: bus reset and babble share the same irq.
/*
 * mentor saves a bit: bus reset and babble share the same irq.
 * only host sees babble; only peripheral sees bus reset.
 */
	if (int_usb & MUSB_INTR_RESET) {
		handled = IRQ_HANDLED;
static void musb_handle_intr_reset(struct musb *musb)
{
	if (is_host_active(musb)) {
		/*
		 * When BABBLE happens what we can depends on which
@@ -922,6 +900,66 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
	}
}

/*
 * Interrupt Service Routine to record USB "global" interrupts.
 * Since these do not happen often and signify things of
 * paramount importance, it seems OK to check them individually;
 * the order of the tests is specified in the manual
 *
 * @param musb instance pointer
 * @param int_usb register contents
 * @param devctl
 * @param power
 */

static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
				u8 devctl)
{
	irqreturn_t handled = IRQ_NONE;

	musb_dbg(musb, "<== DevCtl=%02x, int_usb=0x%x", devctl, int_usb);

	/* in host mode, the peripheral may issue remote wakeup.
	 * in peripheral mode, the host may resume the link.
	 * spurious RESUME irqs happen too, paired with SUSPEND.
	 */
	if (int_usb & MUSB_INTR_RESUME) {
		musb_handle_intr_resume(musb, devctl);
		handled = IRQ_HANDLED;
	}

	/* see manual for the order of the tests */
	if (int_usb & MUSB_INTR_SESSREQ) {
		if (musb_handle_intr_sessreq(musb, devctl))
			return IRQ_HANDLED;
		handled = IRQ_HANDLED;
	}

	if (int_usb & MUSB_INTR_VBUSERROR) {
		musb_handle_intr_vbuserr(musb, devctl);
		handled = IRQ_HANDLED;
	}

	if (int_usb & MUSB_INTR_SUSPEND) {
		musb_handle_intr_suspend(musb, devctl);
		handled = IRQ_HANDLED;
	}

	if (int_usb & MUSB_INTR_CONNECT) {
		musb_handle_intr_connect(musb, devctl, int_usb);
		handled = IRQ_HANDLED;
	}

	if (int_usb & MUSB_INTR_DISCONNECT) {
		musb_handle_intr_disconnect(musb, devctl);
		handled = IRQ_HANDLED;
	}

	if (int_usb & MUSB_INTR_RESET) {
		musb_handle_intr_reset(musb);
		handled = IRQ_HANDLED;
	}

#if 0
/* REVISIT ... this would be for multiplexing periodic endpoints, or
 * supporting transfer phasing to prevent exceeding ISO bandwidth