Commit 8b63229c authored by David Brownell's avatar David Brownell Committed by Tony Lindgren

musb_hdrc: Minor cleanups involving name changes

Minor cleanups involving name changes, primarily on the peripheral side:

 - musb->bMayWakeup becomes may_wakeup (camelcase bad)
 - musb->bIsSelfPowered becomes is_self_powered (camelcase bad)
 - pThis (as parameter or variable) becomes musb (camelcase bad)
 - tusb_set_power becomes tusb_draw_power (more meaningful name)
 - tusb_set_vbus becomes tusb_source_power (more meaningful name)

Also, add a flag to track if a B-Peripheral device draws any VBUS power
(currently only tusb6010 can set that).
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
parent fceaff4d
...@@ -71,10 +71,10 @@ static char *decode_ep0stage(u8 stage) ...@@ -71,10 +71,10 @@ static char *decode_ep0stage(u8 stage)
* Context: caller holds controller lock * Context: caller holds controller lock
*/ */
static int service_tx_status_request( static int service_tx_status_request(
struct musb *pThis, struct musb *musb,
const struct usb_ctrlrequest *pControlRequest) const struct usb_ctrlrequest *pControlRequest)
{ {
void __iomem *pBase = pThis->pRegs; void __iomem *pBase = musb->pRegs;
int handled = 1; int handled = 1;
u8 bResult[2], bEnd = 0; u8 bResult[2], bEnd = 0;
const u8 bRecip = pControlRequest->bRequestType & USB_RECIP_MASK; const u8 bRecip = pControlRequest->bRequestType & USB_RECIP_MASK;
...@@ -83,15 +83,15 @@ static int service_tx_status_request( ...@@ -83,15 +83,15 @@ static int service_tx_status_request(
switch (bRecip) { switch (bRecip) {
case USB_RECIP_DEVICE: case USB_RECIP_DEVICE:
bResult[0] = pThis->bIsSelfPowered << USB_DEVICE_SELF_POWERED; bResult[0] = musb->is_self_powered << USB_DEVICE_SELF_POWERED;
bResult[0] |= pThis->bMayWakeup << USB_DEVICE_REMOTE_WAKEUP; bResult[0] |= musb->may_wakeup << USB_DEVICE_REMOTE_WAKEUP;
#ifdef CONFIG_USB_MUSB_OTG #ifdef CONFIG_USB_MUSB_OTG
if (pThis->g.is_otg) { if (musb->g.is_otg) {
bResult[0] |= pThis->g.b_hnp_enable bResult[0] |= musb->g.b_hnp_enable
<< USB_DEVICE_B_HNP_ENABLE; << USB_DEVICE_B_HNP_ENABLE;
bResult[0] |= pThis->g.a_alt_hnp_support bResult[0] |= musb->g.a_alt_hnp_support
<< USB_DEVICE_A_ALT_HNP_SUPPORT; << USB_DEVICE_A_ALT_HNP_SUPPORT;
bResult[0] |= pThis->g.a_hnp_support bResult[0] |= musb->g.a_hnp_support
<< USB_DEVICE_A_HNP_SUPPORT; << USB_DEVICE_A_HNP_SUPPORT;
} }
#endif #endif
...@@ -116,11 +116,11 @@ static int service_tx_status_request( ...@@ -116,11 +116,11 @@ static int service_tx_status_request(
is_in = bEnd & USB_DIR_IN; is_in = bEnd & USB_DIR_IN;
if (is_in) { if (is_in) {
bEnd &= 0x0f; bEnd &= 0x0f;
ep = &pThis->aLocalEnd[bEnd].ep_in; ep = &musb->aLocalEnd[bEnd].ep_in;
} else { } else {
ep = &pThis->aLocalEnd[bEnd].ep_out; ep = &musb->aLocalEnd[bEnd].ep_out;
} }
regs = pThis->aLocalEnd[bEnd].regs; regs = musb->aLocalEnd[bEnd].regs;
if (bEnd >= MUSB_C_NUM_EPS || !ep->desc) { if (bEnd >= MUSB_C_NUM_EPS || !ep->desc) {
handled = -EINVAL; handled = -EINVAL;
...@@ -151,7 +151,7 @@ static int service_tx_status_request( ...@@ -151,7 +151,7 @@ static int service_tx_status_request(
if (len > 2) if (len > 2)
len = 2; len = 2;
musb_write_fifo(&pThis->aLocalEnd[0], len, bResult); musb_write_fifo(&musb->aLocalEnd[0], len, bResult);
} }
return handled; return handled;
...@@ -169,7 +169,7 @@ static int service_tx_status_request( ...@@ -169,7 +169,7 @@ static int service_tx_status_request(
* Context: caller holds controller lock * Context: caller holds controller lock
*/ */
static int static int
service_in_request(struct musb *pThis, service_in_request(struct musb *musb,
const struct usb_ctrlrequest *pControlRequest) const struct usb_ctrlrequest *pControlRequest)
{ {
int handled = 0; /* not handled */ int handled = 0; /* not handled */
...@@ -178,7 +178,7 @@ service_in_request(struct musb *pThis, ...@@ -178,7 +178,7 @@ service_in_request(struct musb *pThis,
== USB_TYPE_STANDARD) { == USB_TYPE_STANDARD) {
switch (pControlRequest->bRequest) { switch (pControlRequest->bRequest) {
case USB_REQ_GET_STATUS: case USB_REQ_GET_STATUS:
handled = service_tx_status_request(pThis, handled = service_tx_status_request(musb,
pControlRequest); pControlRequest);
break; break;
...@@ -194,10 +194,10 @@ service_in_request(struct musb *pThis, ...@@ -194,10 +194,10 @@ service_in_request(struct musb *pThis,
/* /*
* Context: caller holds controller lock * Context: caller holds controller lock
*/ */
static void musb_g_ep0_giveback(struct musb *pThis, struct usb_request *req) static void musb_g_ep0_giveback(struct musb *musb, struct usb_request *req)
{ {
pThis->ep0_state = MGC_END0_STAGE_SETUP; musb->ep0_state = MGC_END0_STAGE_SETUP;
musb_g_giveback(&pThis->aLocalEnd[0].ep_in, req, 0); musb_g_giveback(&musb->aLocalEnd[0].ep_in, req, 0);
} }
/* /*
...@@ -211,13 +211,13 @@ static void musb_g_ep0_giveback(struct musb *pThis, struct usb_request *req) ...@@ -211,13 +211,13 @@ static void musb_g_ep0_giveback(struct musb *pThis, struct usb_request *req)
* Context: caller holds controller lock * Context: caller holds controller lock
*/ */
static int static int
service_zero_data_request(struct musb *pThis, service_zero_data_request(struct musb *musb,
struct usb_ctrlrequest *pControlRequest) struct usb_ctrlrequest *pControlRequest)
__releases(pThis->Lock) __releases(musb->Lock)
__acquires(pThis->Lock) __acquires(musb->Lock)
{ {
int handled = -EINVAL; int handled = -EINVAL;
void __iomem *pBase = pThis->pRegs; void __iomem *pBase = musb->pRegs;
const u8 bRecip = pControlRequest->bRequestType & USB_RECIP_MASK; const u8 bRecip = pControlRequest->bRequestType & USB_RECIP_MASK;
/* the gadget driver handles everything except what we MUST handle */ /* the gadget driver handles everything except what we MUST handle */
...@@ -226,8 +226,8 @@ __acquires(pThis->Lock) ...@@ -226,8 +226,8 @@ __acquires(pThis->Lock)
switch (pControlRequest->bRequest) { switch (pControlRequest->bRequest) {
case USB_REQ_SET_ADDRESS: case USB_REQ_SET_ADDRESS:
/* change it after the status stage */ /* change it after the status stage */
pThis->bSetAddress = TRUE; musb->bSetAddress = TRUE;
pThis->bAddress = (u8) (pControlRequest->wValue & 0x7f); musb->bAddress = (u8) (pControlRequest->wValue & 0x7f);
handled = 1; handled = 1;
break; break;
...@@ -237,7 +237,7 @@ __acquires(pThis->Lock) ...@@ -237,7 +237,7 @@ __acquires(pThis->Lock)
if (pControlRequest->wValue if (pControlRequest->wValue
!= USB_DEVICE_REMOTE_WAKEUP) != USB_DEVICE_REMOTE_WAKEUP)
break; break;
pThis->bMayWakeup = 0; musb->may_wakeup = 0;
handled = 1; handled = 1;
break; break;
case USB_RECIP_INTERFACE: case USB_RECIP_INTERFACE:
...@@ -253,16 +253,16 @@ __acquires(pThis->Lock) ...@@ -253,16 +253,16 @@ __acquires(pThis->Lock)
break; break;
if (pControlRequest->wIndex & USB_DIR_IN) if (pControlRequest->wIndex & USB_DIR_IN)
pEnd = &pThis->aLocalEnd[bEnd].ep_in; pEnd = &musb->aLocalEnd[bEnd].ep_in;
else else
pEnd = &pThis->aLocalEnd[bEnd].ep_out; pEnd = &musb->aLocalEnd[bEnd].ep_out;
if (!pEnd->desc) if (!pEnd->desc)
break; break;
/* REVISIT do it directly, no locking games */ /* REVISIT do it directly, no locking games */
spin_unlock(&pThis->Lock); spin_unlock(&musb->Lock);
musb_gadget_set_halt(&pEnd->end_point, 0); musb_gadget_set_halt(&pEnd->end_point, 0);
spin_lock(&pThis->Lock); spin_lock(&musb->Lock);
/* select ep0 again */ /* select ep0 again */
MGC_SelectEnd(pBase, 0); MGC_SelectEnd(pBase, 0);
...@@ -281,10 +281,10 @@ __acquires(pThis->Lock) ...@@ -281,10 +281,10 @@ __acquires(pThis->Lock)
handled = 1; handled = 1;
switch (pControlRequest->wValue) { switch (pControlRequest->wValue) {
case USB_DEVICE_REMOTE_WAKEUP: case USB_DEVICE_REMOTE_WAKEUP:
pThis->bMayWakeup = 1; musb->may_wakeup = 1;
break; break;
case USB_DEVICE_TEST_MODE: case USB_DEVICE_TEST_MODE:
if (pThis->g.speed != USB_SPEED_HIGH) if (musb->g.speed != USB_SPEED_HIGH)
goto stall; goto stall;
if (pControlRequest->wIndex & 0xff) if (pControlRequest->wIndex & 0xff)
goto stall; goto stall;
...@@ -293,25 +293,25 @@ __acquires(pThis->Lock) ...@@ -293,25 +293,25 @@ __acquires(pThis->Lock)
case 1: case 1:
pr_debug("TEST_J\n"); pr_debug("TEST_J\n");
/* TEST_J */ /* TEST_J */
pThis->bTestModeValue = musb->bTestModeValue =
MGC_M_TEST_J; MGC_M_TEST_J;
break; break;
case 2: case 2:
/* TEST_K */ /* TEST_K */
pr_debug("TEST_K\n"); pr_debug("TEST_K\n");
pThis->bTestModeValue = musb->bTestModeValue =
MGC_M_TEST_K; MGC_M_TEST_K;
break; break;
case 3: case 3:
/* TEST_SE0_NAK */ /* TEST_SE0_NAK */
pr_debug("TEST_SE0_NAK\n"); pr_debug("TEST_SE0_NAK\n");
pThis->bTestModeValue = musb->bTestModeValue =
MGC_M_TEST_SE0_NAK; MGC_M_TEST_SE0_NAK;
break; break;
case 4: case 4:
/* TEST_PACKET */ /* TEST_PACKET */
pr_debug("TEST_PACKET\n"); pr_debug("TEST_PACKET\n");
pThis->bTestModeValue = musb->bTestModeValue =
MGC_M_TEST_PACKET; MGC_M_TEST_PACKET;
break; break;
default: default:
...@@ -320,14 +320,14 @@ __acquires(pThis->Lock) ...@@ -320,14 +320,14 @@ __acquires(pThis->Lock)
/* enter test mode after irq */ /* enter test mode after irq */
if (handled > 0) if (handled > 0)
pThis->bTestMode = TRUE; musb->bTestMode = TRUE;
break; break;
#ifdef CONFIG_USB_MUSB_OTG #ifdef CONFIG_USB_MUSB_OTG
case USB_DEVICE_B_HNP_ENABLE: case USB_DEVICE_B_HNP_ENABLE:
if (!pThis->g.is_otg) if (!musb->g.is_otg)
goto stall; goto stall;
{ u8 devctl; { u8 devctl;
pThis->g.b_hnp_enable = 1; musb->g.b_hnp_enable = 1;
devctl = musb_readb(pBase, devctl = musb_readb(pBase,
MGC_O_HDRC_DEVCTL); MGC_O_HDRC_DEVCTL);
musb_writeb(pBase, MGC_O_HDRC_DEVCTL, musb_writeb(pBase, MGC_O_HDRC_DEVCTL,
...@@ -335,14 +335,14 @@ __acquires(pThis->Lock) ...@@ -335,14 +335,14 @@ __acquires(pThis->Lock)
} }
break; break;
case USB_DEVICE_A_HNP_SUPPORT: case USB_DEVICE_A_HNP_SUPPORT:
if (!pThis->g.is_otg) if (!musb->g.is_otg)
goto stall; goto stall;
pThis->g.a_hnp_support = 1; musb->g.a_hnp_support = 1;
break; break;
case USB_DEVICE_A_ALT_HNP_SUPPORT: case USB_DEVICE_A_ALT_HNP_SUPPORT:
if (!pThis->g.is_otg) if (!musb->g.is_otg)
goto stall; goto stall;
pThis->g.a_alt_hnp_support = 1; musb->g.a_alt_hnp_support = 1;
break; break;
#endif #endif
stall: stall:
...@@ -370,7 +370,7 @@ stall: ...@@ -370,7 +370,7 @@ stall:
!= USB_ENDPOINT_HALT) != USB_ENDPOINT_HALT)
break; break;
ep = pThis->aLocalEnd + bEnd; ep = musb->aLocalEnd + bEnd;
regs = ep->regs; regs = ep->regs;
is_in = pControlRequest->wIndex & USB_DIR_IN; is_in = pControlRequest->wIndex & USB_DIR_IN;
if (is_in) if (is_in)
...@@ -473,10 +473,10 @@ static void ep0_rxstate(struct musb *this) ...@@ -473,10 +473,10 @@ static void ep0_rxstate(struct musb *this)
* *
* Context: caller holds controller lock * Context: caller holds controller lock
*/ */
static void ep0_txstate(struct musb *pThis) static void ep0_txstate(struct musb *musb)
{ {
void __iomem *regs = pThis->control_ep->regs; void __iomem *regs = musb->control_ep->regs;
struct usb_request *pRequest = next_ep0_request(pThis); struct usb_request *pRequest = next_ep0_request(musb);
u16 wCsrVal = MGC_M_CSR0_TXPKTRDY; u16 wCsrVal = MGC_M_CSR0_TXPKTRDY;
u8 *pFifoSource; u8 *pFifoSource;
u8 wFifoCount; u8 wFifoCount;
...@@ -491,13 +491,13 @@ static void ep0_txstate(struct musb *pThis) ...@@ -491,13 +491,13 @@ static void ep0_txstate(struct musb *pThis)
pFifoSource = (u8 *) pRequest->buf + pRequest->actual; pFifoSource = (u8 *) pRequest->buf + pRequest->actual;
wFifoCount = min((unsigned) MGC_END0_FIFOSIZE, wFifoCount = min((unsigned) MGC_END0_FIFOSIZE,
pRequest->length - pRequest->actual); pRequest->length - pRequest->actual);
musb_write_fifo(&pThis->aLocalEnd[0], wFifoCount, pFifoSource); musb_write_fifo(&musb->aLocalEnd[0], wFifoCount, pFifoSource);
pRequest->actual += wFifoCount; pRequest->actual += wFifoCount;
/* update the flags */ /* update the flags */
if (wFifoCount < MUSB_MAX_END0_PACKET if (wFifoCount < MUSB_MAX_END0_PACKET
|| pRequest->actual == pRequest->length) { || pRequest->actual == pRequest->length) {
pThis->ep0_state = MGC_END0_STAGE_STATUSOUT; musb->ep0_state = MGC_END0_STAGE_STATUSOUT;
wCsrVal |= MGC_M_CSR0_P_DATAEND; wCsrVal |= MGC_M_CSR0_P_DATAEND;
} else } else
pRequest = NULL; pRequest = NULL;
...@@ -511,7 +511,7 @@ static void ep0_txstate(struct musb *pThis) ...@@ -511,7 +511,7 @@ static void ep0_txstate(struct musb *pThis)
* this hardware, but not usable from portable gadget drivers.) * this hardware, but not usable from portable gadget drivers.)
*/ */
if (pRequest) if (pRequest)
musb_g_ep0_giveback(pThis, pRequest); musb_g_ep0_giveback(musb, pRequest);
} }
/* /*
...@@ -521,12 +521,12 @@ static void ep0_txstate(struct musb *pThis) ...@@ -521,12 +521,12 @@ static void ep0_txstate(struct musb *pThis)
* Context: caller holds controller lock. * Context: caller holds controller lock.
*/ */
static void static void
musb_read_setup(struct musb *pThis, struct usb_ctrlrequest *req) musb_read_setup(struct musb *musb, struct usb_ctrlrequest *req)
{ {
struct usb_request *r; struct usb_request *r;
void __iomem *regs = pThis->control_ep->regs; void __iomem *regs = musb->control_ep->regs;
musb_read_fifo(&pThis->aLocalEnd[0], sizeof *req, (u8 *)req); musb_read_fifo(&musb->aLocalEnd[0], sizeof *req, (u8 *)req);
/* NOTE: earlier 2.6 versions changed setup packets to host /* NOTE: earlier 2.6 versions changed setup packets to host
* order, but now USB packets always stay in USB byte order. * order, but now USB packets always stay in USB byte order.
...@@ -539,9 +539,9 @@ musb_read_setup(struct musb *pThis, struct usb_ctrlrequest *req) ...@@ -539,9 +539,9 @@ musb_read_setup(struct musb *pThis, struct usb_ctrlrequest *req)
le16_to_cpu(req->wLength)); le16_to_cpu(req->wLength));
/* clean up any leftover transfers */ /* clean up any leftover transfers */
r = next_ep0_request(pThis); r = next_ep0_request(musb);
if (r) if (r)
musb_g_ep0_giveback(pThis, r); musb_g_ep0_giveback(musb, r);
/* For zero-data requests we want to delay the STATUS stage to /* For zero-data requests we want to delay the STATUS stage to
* avoid SETUPEND errors. If we read data (OUT), delay accepting * avoid SETUPEND errors. If we read data (OUT), delay accepting
...@@ -551,21 +551,21 @@ musb_read_setup(struct musb *pThis, struct usb_ctrlrequest *req) ...@@ -551,21 +551,21 @@ musb_read_setup(struct musb *pThis, struct usb_ctrlrequest *req)
* the TX FIFO right away, and give the controller a moment * the TX FIFO right away, and give the controller a moment
* to switch modes... * to switch modes...
*/ */
pThis->bSetAddress = FALSE; musb->bSetAddress = FALSE;
pThis->ackpend = MGC_M_CSR0_P_SVDRXPKTRDY; musb->ackpend = MGC_M_CSR0_P_SVDRXPKTRDY;
if (req->wLength == 0) { if (req->wLength == 0) {
if (req->bRequestType & USB_DIR_IN) if (req->bRequestType & USB_DIR_IN)
pThis->ackpend |= MGC_M_CSR0_TXPKTRDY; musb->ackpend |= MGC_M_CSR0_TXPKTRDY;
pThis->ep0_state = MGC_END0_STAGE_ACKWAIT; musb->ep0_state = MGC_END0_STAGE_ACKWAIT;
} else if (req->bRequestType & USB_DIR_IN) { } else if (req->bRequestType & USB_DIR_IN) {
pThis->ep0_state = MGC_END0_STAGE_TX; musb->ep0_state = MGC_END0_STAGE_TX;
musb_writew(regs, MGC_O_HDRC_CSR0, MGC_M_CSR0_P_SVDRXPKTRDY); musb_writew(regs, MGC_O_HDRC_CSR0, MGC_M_CSR0_P_SVDRXPKTRDY);
while ((musb_readw(regs, MGC_O_HDRC_CSR0) while ((musb_readw(regs, MGC_O_HDRC_CSR0)
& MGC_M_CSR0_RXPKTRDY) != 0) & MGC_M_CSR0_RXPKTRDY) != 0)
cpu_relax(); cpu_relax();
pThis->ackpend = 0; musb->ackpend = 0;
} else } else
pThis->ep0_state = MGC_END0_STAGE_RX; musb->ep0_state = MGC_END0_STAGE_RX;
} }
static int static int
...@@ -585,16 +585,15 @@ __acquires(musb->Lock) ...@@ -585,16 +585,15 @@ __acquires(musb->Lock)
/* /*
* Handle peripheral ep0 interrupt * Handle peripheral ep0 interrupt
* @param pThis this
* *
* Context: irq handler; we won't re-enter the driver that way. * Context: irq handler; we won't re-enter the driver that way.
*/ */
irqreturn_t musb_g_ep0_irq(struct musb *pThis) irqreturn_t musb_g_ep0_irq(struct musb *musb)
{ {
u16 wCsrVal; u16 wCsrVal;
u16 wCount; u16 wCount;
void __iomem *pBase = pThis->pRegs; void __iomem *pBase = musb->pRegs;
void __iomem *regs = pThis->aLocalEnd[0].regs; void __iomem *regs = musb->aLocalEnd[0].regs;
irqreturn_t retval = IRQ_NONE; irqreturn_t retval = IRQ_NONE;
MGC_SelectEnd(pBase, 0); /* select ep0 */ MGC_SelectEnd(pBase, 0); /* select ep0 */
...@@ -604,14 +603,14 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -604,14 +603,14 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
DBG(4, "csr %04x, count %d, myaddr %d, ep0stage %s\n", DBG(4, "csr %04x, count %d, myaddr %d, ep0stage %s\n",
wCsrVal, wCount, wCsrVal, wCount,
musb_readb(pBase, MGC_O_HDRC_FADDR), musb_readb(pBase, MGC_O_HDRC_FADDR),
decode_ep0stage(pThis->ep0_state)); decode_ep0stage(musb->ep0_state));
/* I sent a stall.. need to acknowledge it now.. */ /* I sent a stall.. need to acknowledge it now.. */
if (wCsrVal & MGC_M_CSR0_P_SENTSTALL) { if (wCsrVal & MGC_M_CSR0_P_SENTSTALL) {
musb_writew(regs, MGC_O_HDRC_CSR0, musb_writew(regs, MGC_O_HDRC_CSR0,
wCsrVal & ~MGC_M_CSR0_P_SENTSTALL); wCsrVal & ~MGC_M_CSR0_P_SENTSTALL);
retval = IRQ_HANDLED; retval = IRQ_HANDLED;
pThis->ep0_state = MGC_END0_STAGE_SETUP; musb->ep0_state = MGC_END0_STAGE_SETUP;
wCsrVal = musb_readw(regs, MGC_O_HDRC_CSR0); wCsrVal = musb_readw(regs, MGC_O_HDRC_CSR0);
} }
...@@ -619,7 +618,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -619,7 +618,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
if (wCsrVal & MGC_M_CSR0_P_SETUPEND) { if (wCsrVal & MGC_M_CSR0_P_SETUPEND) {
musb_writew(regs, MGC_O_HDRC_CSR0, MGC_M_CSR0_P_SVDSETUPEND); musb_writew(regs, MGC_O_HDRC_CSR0, MGC_M_CSR0_P_SVDSETUPEND);
retval = IRQ_HANDLED; retval = IRQ_HANDLED;
pThis->ep0_state = MGC_END0_STAGE_SETUP; musb->ep0_state = MGC_END0_STAGE_SETUP;
wCsrVal = musb_readw(regs, MGC_O_HDRC_CSR0); wCsrVal = musb_readw(regs, MGC_O_HDRC_CSR0);
/* NOTE: request may need completion */ /* NOTE: request may need completion */
} }
...@@ -628,12 +627,12 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -628,12 +627,12 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
* we need to handle nuances around status stages, and also the * we need to handle nuances around status stages, and also the
* case where status and setup stages come back-to-back ... * case where status and setup stages come back-to-back ...
*/ */
switch (pThis->ep0_state) { switch (musb->ep0_state) {
case MGC_END0_STAGE_TX: case MGC_END0_STAGE_TX:
/* irq on clearing txpktrdy */ /* irq on clearing txpktrdy */
if ((wCsrVal & MGC_M_CSR0_TXPKTRDY) == 0) { if ((wCsrVal & MGC_M_CSR0_TXPKTRDY) == 0) {
ep0_txstate(pThis); ep0_txstate(musb);
retval = IRQ_HANDLED; retval = IRQ_HANDLED;
} }
break; break;
...@@ -641,7 +640,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -641,7 +640,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
case MGC_END0_STAGE_RX: case MGC_END0_STAGE_RX:
/* irq on set rxpktrdy */ /* irq on set rxpktrdy */
if (wCsrVal & MGC_M_CSR0_RXPKTRDY) { if (wCsrVal & MGC_M_CSR0_RXPKTRDY) {
ep0_rxstate(pThis); ep0_rxstate(musb);
retval = IRQ_HANDLED; retval = IRQ_HANDLED;
} }
break; break;
...@@ -654,20 +653,20 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -654,20 +653,20 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
* we get 10 msec to receive this irq... until this * we get 10 msec to receive this irq... until this
* is done we won't see the next packet. * is done we won't see the next packet.
*/ */
if (pThis->bSetAddress) { if (musb->bSetAddress) {
pThis->bSetAddress = FALSE; musb->bSetAddress = FALSE;
musb_writeb(pBase, MGC_O_HDRC_FADDR, pThis->bAddress); musb_writeb(pBase, MGC_O_HDRC_FADDR, musb->bAddress);
} }
/* enter test mode if needed (exit by reset) */ /* enter test mode if needed (exit by reset) */
else if (pThis->bTestMode) { else if (musb->bTestMode) {
DBG(1, "entering TESTMODE\n"); DBG(1, "entering TESTMODE\n");
if (MGC_M_TEST_PACKET == pThis->bTestModeValue) if (MGC_M_TEST_PACKET == musb->bTestModeValue)
musb_load_testpacket(pThis); musb_load_testpacket(musb);
musb_writeb(pBase, MGC_O_HDRC_TESTMODE, musb_writeb(pBase, MGC_O_HDRC_TESTMODE,
pThis->bTestModeValue); musb->bTestModeValue);
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
...@@ -676,12 +675,12 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -676,12 +675,12 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
{ {
struct usb_request *req; struct usb_request *req;
req = next_ep0_request(pThis); req = next_ep0_request(musb);
if (req) if (req)
musb_g_ep0_giveback(pThis, req); musb_g_ep0_giveback(musb, req);
} }
retval = IRQ_HANDLED; retval = IRQ_HANDLED;
pThis->ep0_state = MGC_END0_STAGE_SETUP; musb->ep0_state = MGC_END0_STAGE_SETUP;
/* FALLTHROUGH */ /* FALLTHROUGH */
case MGC_END0_STAGE_SETUP: case MGC_END0_STAGE_SETUP:
...@@ -693,23 +692,23 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -693,23 +692,23 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
ERR("SETUP packet len %d != 8 ?\n", wCount); ERR("SETUP packet len %d != 8 ?\n", wCount);
break; break;
} }
musb_read_setup(pThis, &setup); musb_read_setup(musb, &setup);
retval = IRQ_HANDLED; retval = IRQ_HANDLED;
/* sometimes the RESET won't be reported */ /* sometimes the RESET won't be reported */
if (unlikely(pThis->g.speed == USB_SPEED_UNKNOWN)) { if (unlikely(musb->g.speed == USB_SPEED_UNKNOWN)) {
u8 power; u8 power;
printk(KERN_NOTICE "%s: peripheral reset " printk(KERN_NOTICE "%s: peripheral reset "
"irq lost!\n", "irq lost!\n",
musb_driver_name); musb_driver_name);
power = musb_readb(pBase, MGC_O_HDRC_POWER); power = musb_readb(pBase, MGC_O_HDRC_POWER);
pThis->g.speed = (power & MGC_M_POWER_HSMODE) musb->g.speed = (power & MGC_M_POWER_HSMODE)
? USB_SPEED_HIGH : USB_SPEED_FULL; ? USB_SPEED_HIGH : USB_SPEED_FULL;
} }
switch (pThis->ep0_state) { switch (musb->ep0_state) {
/* sequence #3 (no data stage), includes requests /* sequence #3 (no data stage), includes requests
* we can't forward (notably SET_ADDRESS and the * we can't forward (notably SET_ADDRESS and the
...@@ -718,12 +717,12 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -718,12 +717,12 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
*/ */
case MGC_END0_STAGE_ACKWAIT: case MGC_END0_STAGE_ACKWAIT:
handled = service_zero_data_request( handled = service_zero_data_request(
pThis, &setup); musb, &setup);
/* status stage might be immediate */ /* status stage might be immediate */
if (handled > 0) { if (handled > 0) {
pThis->ackpend |= MGC_M_CSR0_P_DATAEND; musb->ackpend |= MGC_M_CSR0_P_DATAEND;
pThis->ep0_state = musb->ep0_state =
MGC_END0_STAGE_STATUSIN; MGC_END0_STAGE_STATUSIN;
} }
break; break;
...@@ -733,11 +732,11 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -733,11 +732,11 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
* and others that we must * and others that we must
*/ */
case MGC_END0_STAGE_TX: case MGC_END0_STAGE_TX:
handled = service_in_request(pThis, &setup); handled = service_in_request(musb, &setup);
if (handled > 0) { if (handled > 0) {
pThis->ackpend = MGC_M_CSR0_TXPKTRDY musb->ackpend = MGC_M_CSR0_TXPKTRDY
| MGC_M_CSR0_P_DATAEND; | MGC_M_CSR0_P_DATAEND;
pThis->ep0_state = musb->ep0_state =
MGC_END0_STAGE_STATUSOUT; MGC_END0_STAGE_STATUSOUT;
} }
break; break;
...@@ -749,7 +748,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -749,7 +748,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
DBG(3, "handled %d, csr %04x, ep0stage %s\n", DBG(3, "handled %d, csr %04x, ep0stage %s\n",
handled, wCsrVal, handled, wCsrVal,
decode_ep0stage(pThis->ep0_state)); decode_ep0stage(musb->ep0_state));
/* unless we need to delegate this to the gadget /* unless we need to delegate this to the gadget
* driver, we know how to wrap this up: csr0 has * driver, we know how to wrap this up: csr0 has
...@@ -760,17 +759,17 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis) ...@@ -760,17 +759,17 @@ irqreturn_t musb_g_ep0_irq(struct musb *pThis)
else if (handled > 0) else if (handled > 0)
goto finish; goto finish;
handled = forward_to_driver(pThis, &setup); handled = forward_to_driver(musb, &setup);
if (handled < 0) { if (handled < 0) {
MGC_SelectEnd(pBase, 0); MGC_SelectEnd(pBase, 0);
stall: stall:
DBG(3, "stall (%d)\n", handled); DBG(3, "stall (%d)\n", handled);
pThis->ackpend |= MGC_M_CSR0_P_SENDSTALL; musb->ackpend |= MGC_M_CSR0_P_SENDSTALL;
pThis->ep0_state = MGC_END0_STAGE_SETUP; musb->ep0_state = MGC_END0_STAGE_SETUP;
finish: finish:
musb_writew(regs, MGC_O_HDRC_CSR0, musb_writew(regs, MGC_O_HDRC_CSR0,
pThis->ackpend); musb->ackpend);
pThis->ackpend = 0; musb->ackpend = 0;
} }
} }
break; break;
...@@ -786,7 +785,7 @@ finish: ...@@ -786,7 +785,7 @@ finish:
/* "can't happen" */ /* "can't happen" */
WARN_ON(1); WARN_ON(1);
musb_writew(regs, MGC_O_HDRC_CSR0, MGC_M_CSR0_P_SENDSTALL); musb_writew(regs, MGC_O_HDRC_CSR0, MGC_M_CSR0_P_SENDSTALL);
pThis->ep0_state = MGC_END0_STAGE_SETUP; musb->ep0_state = MGC_END0_STAGE_SETUP;
break; break;
} }
......
...@@ -188,9 +188,9 @@ static void nuke(struct musb_ep *ep, const int status) ...@@ -188,9 +188,9 @@ static void nuke(struct musb_ep *ep, const int status)
* from the usb core ... sequenced a bit differently from mentor dma. * from the usb core ... sequenced a bit differently from mentor dma.
*/ */
static inline int max_ep_writesize(struct musb *pThis, struct musb_ep *ep) static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep)
{ {
if (can_bulk_split(pThis, ep->type)) if (can_bulk_split(musb, ep->type))
return ep->hw_ep->wMaxPacketSizeTx; return ep->hw_ep->wMaxPacketSizeTx;
else else
return ep->wPacketSize; return ep->wPacketSize;
...@@ -238,11 +238,11 @@ static inline int max_ep_writesize(struct musb *pThis, struct musb_ep *ep) ...@@ -238,11 +238,11 @@ static inline int max_ep_writesize(struct musb *pThis, struct musb_ep *ep)
* *
* Context: controller locked, IRQs blocked, endpoint selected * Context: controller locked, IRQs blocked, endpoint selected
*/ */
static void txstate(struct musb *pThis, struct musb_request *req) static void txstate(struct musb *musb, struct musb_request *req)
{ {
u8 bEnd = req->bEnd; u8 bEnd = req->bEnd;
struct musb_ep *pEnd; struct musb_ep *pEnd;
void __iomem *epio = pThis->aLocalEnd[bEnd].regs; void __iomem *epio = musb->aLocalEnd[bEnd].regs;
struct usb_request *pRequest; struct usb_request *pRequest;
u16 wFifoCount = 0, wCsrVal; u16 wFifoCount = 0, wCsrVal;
int use_dma = 0; int use_dma = 0;
...@@ -259,7 +259,7 @@ static void txstate(struct musb *pThis, struct musb_request *req) ...@@ -259,7 +259,7 @@ static void txstate(struct musb *pThis, struct musb_request *req)
wCsrVal = musb_readw(epio, MGC_O_HDRC_TXCSR); wCsrVal = musb_readw(epio, MGC_O_HDRC_TXCSR);
pRequest = &req->request; pRequest = &req->request;
wFifoCount = min(max_ep_writesize(pThis, pEnd), wFifoCount = min(max_ep_writesize(musb, pEnd),
(int)(pRequest->length - pRequest->actual)); (int)(pRequest->length - pRequest->actual));
if (wCsrVal & MGC_M_TXCSR_TXPKTRDY) { if (wCsrVal & MGC_M_TXCSR_TXPKTRDY) {
...@@ -280,7 +280,7 @@ static void txstate(struct musb *pThis, struct musb_request *req) ...@@ -280,7 +280,7 @@ static void txstate(struct musb *pThis, struct musb_request *req)
#ifndef CONFIG_USB_INVENTRA_FIFO #ifndef CONFIG_USB_INVENTRA_FIFO
if (is_dma_capable() && pEnd->dma) { if (is_dma_capable() && pEnd->dma) {
struct dma_controller *c = pThis->pDmaController; struct dma_controller *c = musb->pDmaController;
use_dma = (pRequest->dma != DMA_ADDR_INVALID); use_dma = (pRequest->dma != DMA_ADDR_INVALID);
...@@ -390,13 +390,13 @@ static void txstate(struct musb *pThis, struct musb_request *req) ...@@ -390,13 +390,13 @@ static void txstate(struct musb *pThis, struct musb_request *req)
* FIFO state update (e.g. data ready). * FIFO state update (e.g. data ready).
* Called from IRQ, with controller locked. * Called from IRQ, with controller locked.
*/ */
void musb_g_tx(struct musb *pThis, u8 bEnd) void musb_g_tx(struct musb *musb, u8 bEnd)
{ {
u16 wCsrVal; u16 wCsrVal;
struct usb_request *pRequest; struct usb_request *pRequest;
u8 __iomem *pBase = pThis->pRegs; u8 __iomem *pBase = musb->pRegs;
struct musb_ep *pEnd = &pThis->aLocalEnd[bEnd].ep_in; struct musb_ep *pEnd = &musb->aLocalEnd[bEnd].ep_in;
void __iomem *epio = pThis->aLocalEnd[bEnd].regs; void __iomem *epio = musb->aLocalEnd[bEnd].regs;
struct dma_channel *dma; struct dma_channel *dma;
MGC_SelectEnd(pBase, bEnd); MGC_SelectEnd(pBase, bEnd);
...@@ -416,7 +416,7 @@ void musb_g_tx(struct musb *pThis, u8 bEnd) ...@@ -416,7 +416,7 @@ void musb_g_tx(struct musb *pThis, u8 bEnd)
musb_writew(epio, MGC_O_HDRC_TXCSR, wCsrVal); musb_writew(epio, MGC_O_HDRC_TXCSR, wCsrVal);
if (dma_channel_status(dma) == MGC_DMA_STATUS_BUSY) { if (dma_channel_status(dma) == MGC_DMA_STATUS_BUSY) {
dma->bStatus = MGC_DMA_STATUS_CORE_ABORT; dma->bStatus = MGC_DMA_STATUS_CORE_ABORT;
pThis->pDmaController->channel_abort(dma); musb->pDmaController->channel_abort(dma);
} }
if (pRequest) if (pRequest)
...@@ -514,7 +514,7 @@ void musb_g_tx(struct musb *pThis, u8 bEnd) ...@@ -514,7 +514,7 @@ void musb_g_tx(struct musb *pThis, u8 bEnd)
} }
} }
txstate(pThis, to_musb_request(pRequest)); txstate(musb, to_musb_request(pRequest));
} }
} while (0); } while (0);
...@@ -556,20 +556,20 @@ void musb_g_tx(struct musb *pThis, u8 bEnd) ...@@ -556,20 +556,20 @@ void musb_g_tx(struct musb *pThis, u8 bEnd)
/* /*
* Context: controller locked, IRQs blocked, endpoint selected * Context: controller locked, IRQs blocked, endpoint selected
*/ */
static void rxstate(struct musb *pThis, struct musb_request *req) static void rxstate(struct musb *musb, struct musb_request *req)
{ {
u16 wCsrVal = 0; u16 wCsrVal = 0;
const u8 bEnd = req->bEnd; const u8 bEnd = req->bEnd;
struct usb_request *pRequest = &req->request; struct usb_request *pRequest = &req->request;
struct musb_ep *pEnd = &pThis->aLocalEnd[bEnd].ep_out; struct musb_ep *pEnd = &musb->aLocalEnd[bEnd].ep_out;
void __iomem *epio = pThis->aLocalEnd[bEnd].regs; void __iomem *epio = musb->aLocalEnd[bEnd].regs;
u16 wFifoCount = 0; u16 wFifoCount = 0;
u16 wCount = pEnd->wPacketSize; u16 wCount = pEnd->wPacketSize;
wCsrVal = musb_readw(epio, MGC_O_HDRC_RXCSR); wCsrVal = musb_readw(epio, MGC_O_HDRC_RXCSR);
if (is_cppi_enabled() && pEnd->dma) { if (is_cppi_enabled() && pEnd->dma) {
struct dma_controller *c = pThis->pDmaController; struct dma_controller *c = musb->pDmaController;
struct dma_channel *channel = pEnd->dma; struct dma_channel *channel = pEnd->dma;
/* NOTE: CPPI won't actually stop advancing the DMA /* NOTE: CPPI won't actually stop advancing the DMA
...@@ -604,7 +604,7 @@ static void rxstate(struct musb *pThis, struct musb_request *req) ...@@ -604,7 +604,7 @@ static void rxstate(struct musb *pThis, struct musb_request *req)
struct dma_channel *channel; struct dma_channel *channel;
int use_dma = 0; int use_dma = 0;
c = pThis->pDmaController; c = musb->pDmaController;
channel = pEnd->dma; channel = pEnd->dma;
/* We use DMA Req mode 0 in RxCsr, and DMA controller operates in /* We use DMA Req mode 0 in RxCsr, and DMA controller operates in
...@@ -680,7 +680,7 @@ static void rxstate(struct musb *pThis, struct musb_request *req) ...@@ -680,7 +680,7 @@ static void rxstate(struct musb *pThis, struct musb_request *req)
#ifdef CONFIG_USB_TUSB_OMAP_DMA #ifdef CONFIG_USB_TUSB_OMAP_DMA
if (tusb_dma_omap() && pEnd->dma) { if (tusb_dma_omap() && pEnd->dma) {
struct dma_controller *c = pThis->pDmaController; struct dma_controller *c = musb->pDmaController;
struct dma_channel *channel = pEnd->dma; struct dma_channel *channel = pEnd->dma;
u32 dma_addr = pRequest->dma + pRequest->actual; u32 dma_addr = pRequest->dma + pRequest->actual;
int ret; int ret;
...@@ -717,16 +717,14 @@ static void rxstate(struct musb *pThis, struct musb_request *req) ...@@ -717,16 +717,14 @@ static void rxstate(struct musb *pThis, struct musb_request *req)
/* /*
* Data ready for a request; called from IRQ * Data ready for a request; called from IRQ
* @param pThis the controller
* @param req the request
*/ */
void musb_g_rx(struct musb *pThis, u8 bEnd) void musb_g_rx(struct musb *musb, u8 bEnd)
{ {
u16 wCsrVal; u16 wCsrVal;
struct usb_request *pRequest; struct usb_request *pRequest;
void __iomem *pBase = pThis->pRegs; void __iomem *pBase = musb->pRegs;
struct musb_ep *pEnd = &pThis->aLocalEnd[bEnd].ep_out; struct musb_ep *pEnd = &musb->aLocalEnd[bEnd].ep_out;
void __iomem *epio = pThis->aLocalEnd[bEnd].regs; void __iomem *epio = musb->aLocalEnd[bEnd].regs;
struct dma_channel *dma; struct dma_channel *dma;
MGC_SelectEnd(pBase, bEnd); MGC_SelectEnd(pBase, bEnd);
...@@ -742,7 +740,7 @@ void musb_g_rx(struct musb *pThis, u8 bEnd) ...@@ -742,7 +740,7 @@ void musb_g_rx(struct musb *pThis, u8 bEnd)
if (wCsrVal & MGC_M_RXCSR_P_SENTSTALL) { if (wCsrVal & MGC_M_RXCSR_P_SENTSTALL) {
if (dma_channel_status(dma) == MGC_DMA_STATUS_BUSY) { if (dma_channel_status(dma) == MGC_DMA_STATUS_BUSY) {
dma->bStatus = MGC_DMA_STATUS_CORE_ABORT; dma->bStatus = MGC_DMA_STATUS_CORE_ABORT;
(void) pThis->pDmaController->channel_abort(dma); (void) musb->pDmaController->channel_abort(dma);
pRequest->actual += pEnd->dma->dwActualLength; pRequest->actual += pEnd->dma->dwActualLength;
} }
...@@ -823,7 +821,7 @@ void musb_g_rx(struct musb *pThis, u8 bEnd) ...@@ -823,7 +821,7 @@ void musb_g_rx(struct musb *pThis, u8 bEnd)
/* analyze request if the ep is hot */ /* analyze request if the ep is hot */
if (pRequest) if (pRequest)
rxstate(pThis, to_musb_request(pRequest)); rxstate(musb, to_musb_request(pRequest));
else else
DBG(3, "packet waiting for %s%s request\n", DBG(3, "packet waiting for %s%s request\n",
pEnd->desc ? "" : "inactive ", pEnd->desc ? "" : "inactive ",
...@@ -842,7 +840,7 @@ static int musb_gadget_enable(struct usb_ep *ep, ...@@ -842,7 +840,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
struct musb_ep *pEnd; struct musb_ep *pEnd;
struct musb_hw_ep *hw_ep; struct musb_hw_ep *hw_ep;
void __iomem *regs; void __iomem *regs;
struct musb *pThis; struct musb *musb;
void __iomem *pBase; void __iomem *pBase;
u8 bEnd; u8 bEnd;
u16 csr; u16 csr;
...@@ -855,11 +853,11 @@ static int musb_gadget_enable(struct usb_ep *ep, ...@@ -855,11 +853,11 @@ static int musb_gadget_enable(struct usb_ep *ep,
pEnd = to_musb_ep(ep); pEnd = to_musb_ep(ep);
hw_ep = pEnd->hw_ep; hw_ep = pEnd->hw_ep;
regs = hw_ep->regs; regs = hw_ep->regs;
pThis = pEnd->pThis; musb = pEnd->pThis;
pBase = pThis->pRegs; pBase = musb->pRegs;
bEnd = pEnd->bEndNumber; bEnd = pEnd->bEndNumber;
spin_lock_irqsave(&pThis->Lock, flags); spin_lock_irqsave(&musb->Lock, flags);
if (pEnd->desc) { if (pEnd->desc) {
status = -EBUSY; status = -EBUSY;
...@@ -950,8 +948,8 @@ static int musb_gadget_enable(struct usb_ep *ep, ...@@ -950,8 +948,8 @@ static int musb_gadget_enable(struct usb_ep *ep,
/* NOTE: all the I/O code _should_ work fine without DMA, in case /* NOTE: all the I/O code _should_ work fine without DMA, in case
* for some reason you run out of channels here. * for some reason you run out of channels here.
*/ */
if (is_dma_capable() && pThis->pDmaController) { if (is_dma_capable() && musb->pDmaController) {
struct dma_controller *c = pThis->pDmaController; struct dma_controller *c = musb->pDmaController;
pEnd->dma = c->channel_alloc(c, hw_ep, pEnd->dma = c->channel_alloc(c, hw_ep,
(desc->bEndpointAddress & USB_DIR_IN)); (desc->bEndpointAddress & USB_DIR_IN));
...@@ -973,10 +971,10 @@ static int musb_gadget_enable(struct usb_ep *ep, ...@@ -973,10 +971,10 @@ static int musb_gadget_enable(struct usb_ep *ep,
pEnd->dma ? "dma, " : "", pEnd->dma ? "dma, " : "",
pEnd->wPacketSize); pEnd->wPacketSize);
schedule_work(&pThis->irq_work); schedule_work(&musb->irq_work);
fail: fail:
spin_unlock_irqrestore(&pThis->Lock, flags); spin_unlock_irqrestore(&musb->Lock, flags);
return status; return status;
} }
...@@ -986,30 +984,30 @@ fail: ...@@ -986,30 +984,30 @@ fail:
static int musb_gadget_disable(struct usb_ep *ep) static int musb_gadget_disable(struct usb_ep *ep)
{ {
unsigned long flags; unsigned long flags;
struct musb *pThis; struct musb *musb;
u8 bEnd; u8 bEnd;
struct musb_ep *pEnd; struct musb_ep *pEnd;
void __iomem *epio; void __iomem *epio;
int status = 0; int status = 0;
pEnd = to_musb_ep(ep); pEnd = to_musb_ep(ep);
pThis = pEnd->pThis; musb = pEnd->pThis;
bEnd = pEnd->bEndNumber; bEnd = pEnd->bEndNumber;
epio = pThis->aLocalEnd[bEnd].regs; epio = musb->aLocalEnd[bEnd].regs;
spin_lock_irqsave(&pThis->Lock, flags); spin_lock_irqsave(&musb->Lock, flags);
MGC_SelectEnd(pThis->pRegs, bEnd); MGC_SelectEnd(musb->pRegs, bEnd);
/* zero the endpoint sizes */ /* zero the endpoint sizes */
if (pEnd->is_in) { if (pEnd->is_in) {
u16 wIntrTxE = musb_readw(pThis->pRegs, MGC_O_HDRC_INTRTXE); u16 wIntrTxE = musb_readw(musb->pRegs, MGC_O_HDRC_INTRTXE);
wIntrTxE &= ~(1 << bEnd); wIntrTxE &= ~(1 << bEnd);
musb_writew(pThis->pRegs, MGC_O_HDRC_INTRTXE, wIntrTxE); musb_writew(musb->pRegs, MGC_O_HDRC_INTRTXE, wIntrTxE);
musb_writew(epio, MGC_O_HDRC_TXMAXP, 0); musb_writew(epio, MGC_O_HDRC_TXMAXP, 0);
} else { } else {
u16 wIntrRxE = musb_readw(pThis->pRegs, MGC_O_HDRC_INTRRXE); u16 wIntrRxE = musb_readw(musb->pRegs, MGC_O_HDRC_INTRRXE);
wIntrRxE &= ~(1 << bEnd); wIntrRxE &= ~(1 << bEnd);
musb_writew(pThis->pRegs, MGC_O_HDRC_INTRRXE, wIntrRxE); musb_writew(musb->pRegs, MGC_O_HDRC_INTRRXE, wIntrRxE);
musb_writew(epio, MGC_O_HDRC_RXMAXP, 0); musb_writew(epio, MGC_O_HDRC_RXMAXP, 0);
} }
...@@ -1018,9 +1016,9 @@ static int musb_gadget_disable(struct usb_ep *ep) ...@@ -1018,9 +1016,9 @@ static int musb_gadget_disable(struct usb_ep *ep)
/* abort all pending DMA and requests */ /* abort all pending DMA and requests */
nuke(pEnd, -ESHUTDOWN); nuke(pEnd, -ESHUTDOWN);
schedule_work(&pThis->irq_work); schedule_work(&musb->irq_work);
spin_unlock_irqrestore(&(pThis->Lock), flags); spin_unlock_irqrestore(&(musb->Lock), flags);
DBG(2, "%s\n", pEnd->end_point.name); DBG(2, "%s\n", pEnd->end_point.name);
...@@ -1121,17 +1119,17 @@ static void musb_gadget_free_buffer(struct usb_ep *ep, ...@@ -1121,17 +1119,17 @@ static void musb_gadget_free_buffer(struct usb_ep *ep,
/* /*
* Context: controller locked, IRQs blocked. * Context: controller locked, IRQs blocked.
*/ */
static void musb_ep_restart(struct musb *pThis, struct musb_request *req) static void musb_ep_restart(struct musb *musb, struct musb_request *req)
{ {
DBG(3, "<== %s request %p len %u on hw_ep%d\n", DBG(3, "<== %s request %p len %u on hw_ep%d\n",
req->bTx ? "TX/IN" : "RX/OUT", req->bTx ? "TX/IN" : "RX/OUT",
&req->request, req->request.length, req->bEnd); &req->request, req->request.length, req->bEnd);
MGC_SelectEnd(pThis->pRegs, req->bEnd); MGC_SelectEnd(musb->pRegs, req->bEnd);
if (req->bTx) if (req->bTx)
txstate(pThis, req); txstate(musb, req);
else else
rxstate(pThis, req); rxstate(musb, req);
} }
static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req, static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
...@@ -1215,11 +1213,12 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *pRequest) ...@@ -1215,11 +1213,12 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *pRequest)
struct usb_request *r; struct usb_request *r;
unsigned long flags; unsigned long flags;
int status = 0; int status = 0;
struct musb *musb = pEnd->pThis;
if (!ep || !pRequest || to_musb_request(pRequest)->ep != pEnd) if (!ep || !pRequest || to_musb_request(pRequest)->ep != pEnd)
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&pEnd->pThis->Lock, flags); spin_lock_irqsave(&musb->Lock, flags);
list_for_each_entry(r, &pEnd->req_list, list) { list_for_each_entry(r, &pEnd->req_list, list) {
if (r == pRequest) if (r == pRequest)
...@@ -1237,9 +1236,9 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *pRequest) ...@@ -1237,9 +1236,9 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *pRequest)
/* ... else abort the dma transfer ... */ /* ... else abort the dma transfer ... */
else if (is_dma_capable() && pEnd->dma) { else if (is_dma_capable() && pEnd->dma) {
struct dma_controller *c = pEnd->pThis->pDmaController; struct dma_controller *c = musb->pDmaController;
MGC_SelectEnd(pEnd->pThis->pRegs, pEnd->bEndNumber); MGC_SelectEnd(musb->pRegs, pEnd->bEndNumber);
if (c->channel_abort) if (c->channel_abort)
status = c->channel_abort(pEnd->dma); status = c->channel_abort(pEnd->dma);
else else
...@@ -1254,7 +1253,7 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *pRequest) ...@@ -1254,7 +1253,7 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *pRequest)
} }
done: done:
spin_unlock_irqrestore(&pEnd->pThis->Lock, flags); spin_unlock_irqrestore(&musb->Lock, flags);
return status; return status;
} }
...@@ -1268,17 +1267,17 @@ int musb_gadget_set_halt(struct usb_ep *ep, int value) ...@@ -1268,17 +1267,17 @@ int musb_gadget_set_halt(struct usb_ep *ep, int value)
{ {
struct musb_ep *pEnd = to_musb_ep(ep); struct musb_ep *pEnd = to_musb_ep(ep);
u8 bEnd = pEnd->bEndNumber; u8 bEnd = pEnd->bEndNumber;
struct musb *pThis = pEnd->pThis; struct musb *musb = pEnd->pThis;
void __iomem *epio = pThis->aLocalEnd[bEnd].regs; void __iomem *epio = musb->aLocalEnd[bEnd].regs;
void __iomem *pBase; void __iomem *pBase;
unsigned long flags; unsigned long flags;
u16 wCsr; u16 wCsr;
struct musb_request *pRequest = NULL; struct musb_request *pRequest = NULL;
int status = 0; int status = 0;
pBase = pThis->pRegs; pBase = musb->pRegs;
spin_lock_irqsave(&pThis->Lock, flags); spin_lock_irqsave(&musb->Lock, flags);
if ((USB_ENDPOINT_XFER_ISOC == pEnd->type)) { if ((USB_ENDPOINT_XFER_ISOC == pEnd->type)) {
status = -EINVAL; status = -EINVAL;
...@@ -1293,7 +1292,7 @@ int musb_gadget_set_halt(struct usb_ep *ep, int value) ...@@ -1293,7 +1292,7 @@ int musb_gadget_set_halt(struct usb_ep *ep, int value)
wCsr = musb_readw(epio, MGC_O_HDRC_TXCSR); wCsr = musb_readw(epio, MGC_O_HDRC_TXCSR);
if (wCsr & MGC_M_TXCSR_FIFONOTEMPTY) { if (wCsr & MGC_M_TXCSR_FIFONOTEMPTY) {
DBG(3, "%s fifo busy, cannot halt\n", ep->name); DBG(3, "%s fifo busy, cannot halt\n", ep->name);
spin_unlock_irqrestore(&pThis->Lock, flags); spin_unlock_irqrestore(&musb->Lock, flags);
return -EAGAIN; return -EAGAIN;
} }
...@@ -1332,10 +1331,10 @@ done: ...@@ -1332,10 +1331,10 @@ done:
/* maybe start the first request in the queue */ /* maybe start the first request in the queue */
if (!pEnd->busy && !value && pRequest) { if (!pEnd->busy && !value && pRequest) {
DBG(3, "restarting the request\n"); DBG(3, "restarting the request\n");
musb_ep_restart(pThis, pRequest); musb_ep_restart(musb, pRequest);
} }
spin_unlock_irqrestore(&pThis->Lock, flags); spin_unlock_irqrestore(&musb->Lock, flags);
return status; return status;
} }
...@@ -1419,9 +1418,9 @@ static const struct usb_ep_ops musb_ep_ops = { ...@@ -1419,9 +1418,9 @@ static const struct usb_ep_ops musb_ep_ops = {
static int musb_gadget_get_frame(struct usb_gadget *gadget) static int musb_gadget_get_frame(struct usb_gadget *gadget)
{ {
struct musb *pThis = gadget_to_musb(gadget); struct musb *musb = gadget_to_musb(gadget);
return (int)musb_readw(pThis->pRegs, MGC_O_HDRC_FRAME); return (int)musb_readw(musb->pRegs, MGC_O_HDRC_FRAME);
} }
static int musb_gadget_wakeup(struct usb_gadget *gadget) static int musb_gadget_wakeup(struct usb_gadget *gadget)
...@@ -1444,7 +1443,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget) ...@@ -1444,7 +1443,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
* that's part of the standard usb 1.1 state machine, and * that's part of the standard usb 1.1 state machine, and
* doesn't affect OTG transitions. * doesn't affect OTG transitions.
*/ */
if (musb->bMayWakeup) if (musb->may_wakeup)
break; break;
goto done; goto done;
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
...@@ -1483,9 +1482,9 @@ done: ...@@ -1483,9 +1482,9 @@ done:
static int static int
musb_gadget_set_self_powered(struct usb_gadget *gadget, int is_selfpowered) musb_gadget_set_self_powered(struct usb_gadget *gadget, int is_selfpowered)
{ {
struct musb *pThis = gadget_to_musb(gadget); struct musb *musb = gadget_to_musb(gadget);
pThis->bIsSelfPowered = !!is_selfpowered; musb->is_self_powered = !!is_selfpowered;
return 0; return 0;
} }
...@@ -1617,29 +1616,29 @@ init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 bEnd, int is_in) ...@@ -1617,29 +1616,29 @@ init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 bEnd, int is_in)
* Initialize the endpoints exposed to peripheral drivers, with backlinks * Initialize the endpoints exposed to peripheral drivers, with backlinks
* to the rest of the driver state. * to the rest of the driver state.
*/ */
static inline void __init musb_g_init_endpoints(struct musb *pThis) static inline void __init musb_g_init_endpoints(struct musb *musb)
{ {
u8 bEnd; u8 bEnd;
struct musb_hw_ep *hw_ep; struct musb_hw_ep *hw_ep;
unsigned count = 0; unsigned count = 0;
/* intialize endpoint list just once */ /* intialize endpoint list just once */
INIT_LIST_HEAD(&(pThis->g.ep_list)); INIT_LIST_HEAD(&(musb->g.ep_list));
for (bEnd = 0, hw_ep = pThis->aLocalEnd; for (bEnd = 0, hw_ep = musb->aLocalEnd;
bEnd < pThis->bEndCount; bEnd < musb->bEndCount;
bEnd++, hw_ep++) { bEnd++, hw_ep++) {
if (hw_ep->bIsSharedFifo /* || !bEnd */) { if (hw_ep->bIsSharedFifo /* || !bEnd */) {
init_peripheral_ep(pThis, &hw_ep->ep_in, bEnd, 0); init_peripheral_ep(musb, &hw_ep->ep_in, bEnd, 0);
count++; count++;
} else { } else {
if (hw_ep->wMaxPacketSizeTx) { if (hw_ep->wMaxPacketSizeTx) {
init_peripheral_ep(pThis, &hw_ep->ep_in, init_peripheral_ep(musb, &hw_ep->ep_in,
bEnd, 1); bEnd, 1);
count++; count++;
} }
if (hw_ep->wMaxPacketSizeRx) { if (hw_ep->wMaxPacketSizeRx) {
init_peripheral_ep(pThis, &hw_ep->ep_out, init_peripheral_ep(musb, &hw_ep->ep_out,
bEnd, 0); bEnd, 0);
count++; count++;
} }
...@@ -1711,7 +1710,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) ...@@ -1711,7 +1710,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
{ {
int retval; int retval;
unsigned long flags; unsigned long flags;
struct musb *pThis = the_gadget; struct musb *musb = the_gadget;
if (!driver if (!driver
|| driver->speed != USB_SPEED_HIGH || driver->speed != USB_SPEED_HIGH
...@@ -1720,49 +1719,49 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) ...@@ -1720,49 +1719,49 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
return -EINVAL; return -EINVAL;
/* driver must be initialized to support peripheral mode */ /* driver must be initialized to support peripheral mode */
if (!pThis || !(pThis->board_mode == MUSB_OTG if (!musb || !(musb->board_mode == MUSB_OTG
|| pThis->board_mode != MUSB_OTG)) { || musb->board_mode != MUSB_OTG)) {
DBG(1,"%s, no dev??\n", __FUNCTION__); DBG(1,"%s, no dev??\n", __FUNCTION__);
return -ENODEV; return -ENODEV;
} }
DBG(3, "registering driver %s\n", driver->function); DBG(3, "registering driver %s\n", driver->function);
spin_lock_irqsave(&pThis->Lock, flags); spin_lock_irqsave(&musb->Lock, flags);
if (pThis->pGadgetDriver) { if (musb->pGadgetDriver) {
DBG(1, "%s is already bound to %s\n", DBG(1, "%s is already bound to %s\n",
musb_driver_name, musb_driver_name,
pThis->pGadgetDriver->driver.name); musb->pGadgetDriver->driver.name);
retval = -EBUSY; retval = -EBUSY;
} else { } else {
pThis->pGadgetDriver = driver; musb->pGadgetDriver = driver;
pThis->g.dev.driver = &driver->driver; musb->g.dev.driver = &driver->driver;
driver->driver.bus = NULL; driver->driver.bus = NULL;
pThis->softconnect = 1; musb->softconnect = 1;
retval = 0; retval = 0;
} }
spin_unlock_irqrestore(&pThis->Lock, flags); spin_unlock_irqrestore(&musb->Lock, flags);
if (retval == 0) if (retval == 0)
retval = driver->bind(&pThis->g); retval = driver->bind(&musb->g);
if (retval != 0) { if (retval != 0) {
DBG(3, "bind to driver %s failed --> %d\n", DBG(3, "bind to driver %s failed --> %d\n",
driver->driver.name, retval); driver->driver.name, retval);
pThis->pGadgetDriver = NULL; musb->pGadgetDriver = NULL;
pThis->g.dev.driver = NULL; musb->g.dev.driver = NULL;
} }
/* start peripheral and/or OTG engines */ /* start peripheral and/or OTG engines */
if (retval == 0) { if (retval == 0) {
spin_lock_irqsave(&pThis->Lock, flags); spin_lock_irqsave(&musb->Lock, flags);
/* REVISIT always use otg_set_peripheral(), handling /* REVISIT always use otg_set_peripheral(), handling
* issues including the root hub one below ... * issues including the root hub one below ...
*/ */
pThis->xceiv.gadget = &pThis->g; musb->xceiv.gadget = &musb->g;
pThis->xceiv.state = OTG_STATE_B_IDLE; musb->xceiv.state = OTG_STATE_B_IDLE;
pThis->is_active = 1; musb->is_active = 1;
/* FIXME this ignores the softconnect flag. Drivers are /* FIXME this ignores the softconnect flag. Drivers are
* allowed hold the peripheral inactive until for example * allowed hold the peripheral inactive until for example
...@@ -1770,27 +1769,27 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) ...@@ -1770,27 +1769,27 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
* hosts only see fully functional devices. * hosts only see fully functional devices.
*/ */
if (!is_otg_enabled(pThis)) if (!is_otg_enabled(musb))
musb_start(pThis); musb_start(musb);
spin_unlock_irqrestore(&pThis->Lock, flags); spin_unlock_irqrestore(&musb->Lock, flags);
if (is_otg_enabled(pThis)) { if (is_otg_enabled(musb)) {
DBG(3, "OTG startup...\n"); DBG(3, "OTG startup...\n");
/* REVISIT: funcall to other code, which also /* REVISIT: funcall to other code, which also
* handles power budgeting ... this way also * handles power budgeting ... this way also
* ensures HdrcStart is indirectly called. * ensures HdrcStart is indirectly called.
*/ */
retval = usb_add_hcd(musb_to_hcd(pThis), -1, 0); retval = usb_add_hcd(musb_to_hcd(musb), -1, 0);
if (retval < 0) { if (retval < 0) {
DBG(1, "add_hcd failed, %d\n", retval); DBG(1, "add_hcd failed, %d\n", retval);
spin_lock_irqsave(&pThis->Lock, flags); spin_lock_irqsave(&musb->Lock, flags);
pThis->xceiv.gadget = NULL; musb->xceiv.gadget = NULL;
pThis->xceiv.state = OTG_STATE_UNDEFINED; musb->xceiv.state = OTG_STATE_UNDEFINED;
pThis->pGadgetDriver = NULL; musb->pGadgetDriver = NULL;
pThis->g.dev.driver = NULL; musb->g.dev.driver = NULL;
spin_unlock_irqrestore(&pThis->Lock, flags); spin_unlock_irqrestore(&musb->Lock, flags);
} }
} }
} }
...@@ -1897,44 +1896,44 @@ EXPORT_SYMBOL(usb_gadget_unregister_driver); ...@@ -1897,44 +1896,44 @@ EXPORT_SYMBOL(usb_gadget_unregister_driver);
/* lifecycle operations called through plat_uds.c */ /* lifecycle operations called through plat_uds.c */
void musb_g_resume(struct musb *pThis) void musb_g_resume(struct musb *musb)
{ {
switch (pThis->xceiv.state) { switch (musb->xceiv.state) {
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
break; break;
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
pThis->is_active = 1; musb->is_active = 1;
if (pThis->pGadgetDriver && pThis->pGadgetDriver->resume) { if (musb->pGadgetDriver && musb->pGadgetDriver->resume) {
spin_unlock(&pThis->Lock); spin_unlock(&musb->Lock);
pThis->pGadgetDriver->resume(&pThis->g); musb->pGadgetDriver->resume(&musb->g);
spin_lock(&pThis->Lock); spin_lock(&musb->Lock);
} }
break; break;
default: default:
WARN("unhandled RESUME transition (%s)\n", WARN("unhandled RESUME transition (%s)\n",
otg_state_string(pThis)); otg_state_string(musb));
} }
} }
/* called when SOF packets stop for 3+ msec */ /* called when SOF packets stop for 3+ msec */
void musb_g_suspend(struct musb *pThis) void musb_g_suspend(struct musb *musb)
{ {
u8 devctl; u8 devctl;
devctl = musb_readb(pThis->pRegs, MGC_O_HDRC_DEVCTL); devctl = musb_readb(musb->pRegs, MGC_O_HDRC_DEVCTL);
DBG(3, "devctl %02x\n", devctl); DBG(3, "devctl %02x\n", devctl);
switch (pThis->xceiv.state) { switch (musb->xceiv.state) {
case OTG_STATE_B_IDLE: case OTG_STATE_B_IDLE:
if ((devctl & MGC_M_DEVCTL_VBUS) == MGC_M_DEVCTL_VBUS) if ((devctl & MGC_M_DEVCTL_VBUS) == MGC_M_DEVCTL_VBUS)
pThis->xceiv.state = OTG_STATE_B_PERIPHERAL; musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
break; break;
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
if (pThis->pGadgetDriver && pThis->pGadgetDriver->suspend) { if (musb->pGadgetDriver && musb->pGadgetDriver->suspend) {
spin_unlock(&pThis->Lock); spin_unlock(&musb->Lock);
pThis->pGadgetDriver->suspend(&pThis->g); musb->pGadgetDriver->suspend(&musb->g);
spin_lock(&pThis->Lock); spin_lock(&musb->Lock);
} }
break; break;
default: default:
...@@ -1942,14 +1941,14 @@ void musb_g_suspend(struct musb *pThis) ...@@ -1942,14 +1941,14 @@ void musb_g_suspend(struct musb *pThis)
* A_PERIPHERAL may need care too * A_PERIPHERAL may need care too
*/ */
WARN("unhandled SUSPEND transition (%s)\n", WARN("unhandled SUSPEND transition (%s)\n",
otg_state_string(pThis)); otg_state_string(musb));
} }
} }
/* called when VBUS drops below session threshold, and in other cases */ /* called when VBUS drops below session threshold, and in other cases */
void musb_g_disconnect(struct musb *pThis) void musb_g_disconnect(struct musb *musb)
{ {
void __iomem *mregs = pThis->pRegs; void __iomem *mregs = musb->pRegs;
u8 devctl = musb_readb(mregs, MGC_O_HDRC_DEVCTL); u8 devctl = musb_readb(mregs, MGC_O_HDRC_DEVCTL);
DBG(3, "devctl %02x\n", devctl); DBG(3, "devctl %02x\n", devctl);
...@@ -1958,38 +1957,38 @@ void musb_g_disconnect(struct musb *pThis) ...@@ -1958,38 +1957,38 @@ void musb_g_disconnect(struct musb *pThis)
musb_writeb(mregs, MGC_O_HDRC_DEVCTL, devctl & MGC_M_DEVCTL_SESSION); musb_writeb(mregs, MGC_O_HDRC_DEVCTL, devctl & MGC_M_DEVCTL_SESSION);
/* don't draw vbus until new b-default session */ /* don't draw vbus until new b-default session */
(void) musb_gadget_vbus_draw(&pThis->g, 0); (void) musb_gadget_vbus_draw(&musb->g, 0);
pThis->g.speed = USB_SPEED_UNKNOWN; musb->g.speed = USB_SPEED_UNKNOWN;
if (pThis->pGadgetDriver && pThis->pGadgetDriver->disconnect) { if (musb->pGadgetDriver && musb->pGadgetDriver->disconnect) {
spin_unlock(&pThis->Lock); spin_unlock(&musb->Lock);
pThis->pGadgetDriver->disconnect(&pThis->g); musb->pGadgetDriver->disconnect(&musb->g);
spin_lock(&pThis->Lock); spin_lock(&musb->Lock);
} }
switch (pThis->xceiv.state) { switch (musb->xceiv.state) {
default: default:
#ifdef CONFIG_USB_MUSB_OTG #ifdef CONFIG_USB_MUSB_OTG
pThis->xceiv.state = OTG_STATE_A_IDLE; musb->xceiv.state = OTG_STATE_A_IDLE;
break; break;
case OTG_STATE_B_WAIT_ACON: case OTG_STATE_B_WAIT_ACON:
case OTG_STATE_B_HOST: case OTG_STATE_B_HOST:
#endif #endif
case OTG_STATE_B_PERIPHERAL: case OTG_STATE_B_PERIPHERAL:
pThis->xceiv.state = OTG_STATE_B_IDLE; musb->xceiv.state = OTG_STATE_B_IDLE;
break; break;
case OTG_STATE_B_SRP_INIT: case OTG_STATE_B_SRP_INIT:
break; break;
} }
pThis->is_active = 0; musb->is_active = 0;
} }
void musb_g_reset(struct musb *pThis) void musb_g_reset(struct musb *musb)
__releases(pThis->Lock) __releases(musb->Lock)
__acquires(pThis->Lock) __acquires(musb->Lock)
{ {
void __iomem *pBase = pThis->pRegs; void __iomem *pBase = musb->pRegs;
u8 devctl = musb_readb(pBase, MGC_O_HDRC_DEVCTL); u8 devctl = musb_readb(pBase, MGC_O_HDRC_DEVCTL);
u8 power; u8 power;
...@@ -1997,14 +1996,14 @@ __acquires(pThis->Lock) ...@@ -1997,14 +1996,14 @@ __acquires(pThis->Lock)
(devctl & MGC_M_DEVCTL_BDEVICE) (devctl & MGC_M_DEVCTL_BDEVICE)
? "B-Device" : "A-Device", ? "B-Device" : "A-Device",
musb_readb(pBase, MGC_O_HDRC_FADDR), musb_readb(pBase, MGC_O_HDRC_FADDR),
pThis->pGadgetDriver musb->pGadgetDriver
? pThis->pGadgetDriver->driver.name ? musb->pGadgetDriver->driver.name
: NULL : NULL
); );
/* report disconnect, if we didn't already (flushing EP state) */ /* report disconnect, if we didn't already (flushing EP state) */
if (pThis->g.speed != USB_SPEED_UNKNOWN) if (musb->g.speed != USB_SPEED_UNKNOWN)
musb_g_disconnect(pThis); musb_g_disconnect(musb);
/* clear HR */ /* clear HR */
else if (devctl & MGC_M_DEVCTL_HR) else if (devctl & MGC_M_DEVCTL_HR)
...@@ -2013,33 +2012,33 @@ __acquires(pThis->Lock) ...@@ -2013,33 +2012,33 @@ __acquires(pThis->Lock)
/* what speed did we negotiate? */ /* what speed did we negotiate? */
power = musb_readb(pBase, MGC_O_HDRC_POWER); power = musb_readb(pBase, MGC_O_HDRC_POWER);
pThis->g.speed = (power & MGC_M_POWER_HSMODE) musb->g.speed = (power & MGC_M_POWER_HSMODE)
? USB_SPEED_HIGH : USB_SPEED_FULL; ? USB_SPEED_HIGH : USB_SPEED_FULL;
/* start in USB_STATE_DEFAULT */ /* start in USB_STATE_DEFAULT */
pThis->is_active = 1; musb->is_active = 1;
MUSB_DEV_MODE(pThis); MUSB_DEV_MODE(musb);
pThis->bAddress = 0; musb->bAddress = 0;
pThis->ep0_state = MGC_END0_STAGE_SETUP; musb->ep0_state = MGC_END0_STAGE_SETUP;
pThis->bMayWakeup = 0; musb->may_wakeup = 0;
pThis->g.b_hnp_enable = 0; musb->g.b_hnp_enable = 0;
pThis->g.a_alt_hnp_support = 0; musb->g.a_alt_hnp_support = 0;
pThis->g.a_hnp_support = 0; musb->g.a_hnp_support = 0;
/* Normal reset, as B-Device; /* Normal reset, as B-Device;
* or else after HNP, as A-Device * or else after HNP, as A-Device
*/ */
if (devctl & MGC_M_DEVCTL_BDEVICE) { if (devctl & MGC_M_DEVCTL_BDEVICE) {
pThis->xceiv.state = OTG_STATE_B_PERIPHERAL; musb->xceiv.state = OTG_STATE_B_PERIPHERAL;
pThis->g.is_a_peripheral = 0; musb->g.is_a_peripheral = 0;
} else if (is_otg_enabled(pThis)) { } else if (is_otg_enabled(musb)) {
pThis->xceiv.state = OTG_STATE_A_PERIPHERAL; musb->xceiv.state = OTG_STATE_A_PERIPHERAL;
pThis->g.is_a_peripheral = 1; musb->g.is_a_peripheral = 1;
} else } else
WARN_ON(1); WARN_ON(1);
/* start with default limits on VBUS power draw */ /* start with default limits on VBUS power draw */
(void) musb_gadget_vbus_draw(&pThis->g, (void) musb_gadget_vbus_draw(&musb->g,
is_otg_enabled(pThis) ? 8 : 100); is_otg_enabled(musb) ? 8 : 100);
} }
...@@ -402,7 +402,7 @@ struct musb { ...@@ -402,7 +402,7 @@ struct musb {
u8 min_power; /* vbus for periph, in mA/2 */ u8 min_power; /* vbus for periph, in mA/2 */
/* active means connected and not suspended */ /* active means connected and not suspended */
unsigned is_active:1; unsigned is_active:1;
unsigned bIsMultipoint:1; unsigned bIsMultipoint:1;
unsigned bIsHost:1; unsigned bIsHost:1;
...@@ -430,8 +430,16 @@ struct musb { ...@@ -430,8 +430,16 @@ struct musb {
#endif #endif
#ifdef CONFIG_USB_GADGET_MUSB_HDRC #ifdef CONFIG_USB_GADGET_MUSB_HDRC
unsigned bIsSelfPowered:1; /* may_wakeup means remote wakeup is enabled */
unsigned bMayWakeup:1; unsigned may_wakeup:1;
/* is_self_powered is reported in device status and the
* config descriptor. is_bus_powered means B_PERIPHERAL
* draws some VBUS current; both can be true.
*/
unsigned is_self_powered:1;
unsigned is_bus_powered:1;
unsigned bSetAddress:1; unsigned bSetAddress:1;
unsigned bTestMode:1; unsigned bTestMode:1;
unsigned softconnect:1; unsigned softconnect:1;
......
...@@ -142,13 +142,15 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf) ...@@ -142,13 +142,15 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf)
} }
} }
#ifdef CONFIG_USB_GADGET_MUSB_HDRC
/* This is used by gadget drivers, and OTG transceiver logic, allowing /* This is used by gadget drivers, and OTG transceiver logic, allowing
* at most mA current to be drawn from VBUS during a Default-B session * at most mA current to be drawn from VBUS during a Default-B session
* (that is, while VBUS exceeds 4.4V). In Default-A (including pure host * (that is, while VBUS exceeds 4.4V). In Default-A (including pure host
* mode), or low power Default-B sessions, something else supplies power. * mode), or low power Default-B sessions, something else supplies power.
* Caller must take care of locking. * Caller must take care of locking.
*/ */
static int tusb_set_power(struct otg_transceiver *x, unsigned mA) static int tusb_draw_power(struct otg_transceiver *x, unsigned mA)
{ {
struct musb *musb = container_of(x, struct musb, xceiv); struct musb *musb = container_of(x, struct musb, xceiv);
void __iomem *base = musb->ctrl_base; void __iomem *base = musb->ctrl_base;
...@@ -165,16 +167,23 @@ static int tusb_set_power(struct otg_transceiver *x, unsigned mA) ...@@ -165,16 +167,23 @@ static int tusb_set_power(struct otg_transceiver *x, unsigned mA)
mA = 0; mA = 0;
reg = musb_readl(base, TUSB_PRCM_MNGMT); reg = musb_readl(base, TUSB_PRCM_MNGMT);
if (mA) if (mA) {
musb->is_bus_powered = 1;
reg |= TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN; reg |= TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN;
else } else {
musb->is_bus_powered = 0;
reg &= ~(TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN); reg &= ~(TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN);
}
musb_writel(base, TUSB_PRCM_MNGMT, reg); musb_writel(base, TUSB_PRCM_MNGMT, reg);
DBG(2, "draw max %d mA VBUS\n", mA); DBG(2, "draw max %d mA VBUS\n", mA);
return 0; return 0;
} }
#else
#define tusb_draw_power NULL
#endif
/* workaround for issue 13: change clock during chip idle /* workaround for issue 13: change clock during chip idle
* (to be fixed in rev3 silicon) ... symptoms include disconnect * (to be fixed in rev3 silicon) ... symptoms include disconnect
* or looping suspend/resume cycles * or looping suspend/resume cycles
...@@ -330,7 +339,7 @@ void musb_platform_try_idle(struct musb *musb) ...@@ -330,7 +339,7 @@ void musb_platform_try_idle(struct musb *musb)
| TUSB_DEV_OTG_TIMER_ENABLE) \ | TUSB_DEV_OTG_TIMER_ENABLE) \
: 0) : 0)
static void tusb_set_vbus(struct musb *musb, int is_on) static void tusb_source_power(struct musb *musb, int is_on)
{ {
void __iomem *base = musb->ctrl_base; void __iomem *base = musb->ctrl_base;
u32 conf, prcm, timer; u32 conf, prcm, timer;
...@@ -399,7 +408,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *base) ...@@ -399,7 +408,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *base)
default_a = is_host_enabled(musb); default_a = is_host_enabled(musb);
DBG(2, "Default-%c\n", default_a ? 'A' : 'B'); DBG(2, "Default-%c\n", default_a ? 'A' : 'B');
musb->xceiv.default_a = default_a; musb->xceiv.default_a = default_a;
tusb_set_vbus(musb, default_a); tusb_source_power(musb, default_a);
} }
/* VBUS state change */ /* VBUS state change */
...@@ -447,7 +456,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *base) ...@@ -447,7 +456,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *base)
*/ */
if (musb->vbuserr_retry) { if (musb->vbuserr_retry) {
musb->vbuserr_retry--; musb->vbuserr_retry--;
tusb_set_vbus(musb, 1); tusb_source_power(musb, 1);
} }
break; break;
default: default:
...@@ -491,12 +500,12 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *base) ...@@ -491,12 +500,12 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *base)
} else { } else {
/* REVISIT report overcurrent to hub? */ /* REVISIT report overcurrent to hub? */
ERR("vbus too slow, devctl %02x\n", devctl); ERR("vbus too slow, devctl %02x\n", devctl);
tusb_set_vbus(musb, 0); tusb_source_power(musb, 0);
} }
break; break;
case OTG_STATE_A_WAIT_BCON: case OTG_STATE_A_WAIT_BCON:
if (OTG_TIME_A_WAIT_BCON) if (OTG_TIME_A_WAIT_BCON)
tusb_set_vbus(musb, 0); tusb_source_power(musb, 0);
break; break;
case OTG_STATE_A_SUSPEND: case OTG_STATE_A_SUSPEND:
break; break;
...@@ -832,9 +841,9 @@ int __init musb_platform_init(struct musb *musb) ...@@ -832,9 +841,9 @@ int __init musb_platform_init(struct musb *musb)
musb->isr = tusb_interrupt; musb->isr = tusb_interrupt;
if (is_host_enabled(musb)) if (is_host_enabled(musb))
musb->board_set_vbus = tusb_set_vbus; musb->board_set_vbus = tusb_source_power;
if (is_peripheral_enabled(musb)) if (is_peripheral_enabled(musb))
musb->xceiv.set_power = tusb_set_power; musb->xceiv.set_power = tusb_draw_power;
setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment