123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425 |
- // SPDX-License-Identifier: GPL-2.0+
- /*
- * Mentor USB OTG Core host controller driver.
- *
- * Copyright (c) 2008 Texas Instruments
- *
- * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
- */
- #include <common.h>
- #include <usb.h>
- #include "musb_hcd.h"
- /* MSC control transfers */
- #define USB_MSC_BBB_RESET 0xFF
- #define USB_MSC_BBB_GET_MAX_LUN 0xFE
- /* Endpoint configuration information */
- static const struct musb_epinfo epinfo[3] = {
- {MUSB_BULK_EP, 1, 512}, /* EP1 - Bluk Out - 512 Bytes */
- {MUSB_BULK_EP, 0, 512}, /* EP1 - Bluk In - 512 Bytes */
- {MUSB_INTR_EP, 0, 64} /* EP2 - Interrupt IN - 64 Bytes */
- };
- /* --- Virtual Root Hub ---------------------------------------------------- */
- #ifdef MUSB_NO_MULTIPOINT
- static int rh_devnum;
- static u32 port_status;
- #include <usbroothubdes.h>
- #endif
- /*
- * This function writes the data toggle value.
- */
- static void write_toggle(struct usb_device *dev, u8 ep, u8 dir_out)
- {
- u16 toggle = usb_gettoggle(dev, ep, dir_out);
- u16 csr;
- if (dir_out) {
- csr = readw(&musbr->txcsr);
- if (!toggle) {
- #ifdef CONFIG_ARK_MUSB
- csr |= MUSB_TXCSR_CLRDATATOG | MUSB_TXCSR_MODE;
- #else
- if (csr & MUSB_TXCSR_MODE)
- csr = MUSB_TXCSR_CLRDATATOG;
- else
- csr = 0;
- #endif /* CONFIG_ARK_MUSB */
- writew(csr, &musbr->txcsr);
- } else {
- csr |= MUSB_TXCSR_H_WR_DATATOGGLE;
- writew(csr, &musbr->txcsr);
- csr |= (toggle << MUSB_TXCSR_H_DATATOGGLE_SHIFT);
- writew(csr, &musbr->txcsr);
- }
- } else {
- if (!toggle) {
- csr = readw(&musbr->txcsr);
- #ifdef CONFIG_ARK_MUSB
- if (csr & MUSB_TXCSR_MODE)
- csr |= MUSB_RXCSR_CLRDATATOG;
- else
- csr |= 0;
- #else
- if (csr & MUSB_TXCSR_MODE)
- csr = MUSB_RXCSR_CLRDATATOG;
- else
- csr = 0;
- #endif /* CONFIG_ARK_MUSB */
- writew(csr, &musbr->rxcsr);
- } else {
- csr = readw(&musbr->rxcsr);
- csr |= MUSB_RXCSR_H_WR_DATATOGGLE;
- writew(csr, &musbr->rxcsr);
- csr |= (toggle << MUSB_S_RXCSR_H_DATATOGGLE);
- writew(csr, &musbr->rxcsr);
- }
- }
- }
- /*
- * This function checks if RxStall has occurred on the endpoint. If a RxStall
- * has occurred, the RxStall is cleared and 1 is returned. If RxStall has
- * not occurred, 0 is returned.
- */
- static u8 check_stall(u8 ep, u8 dir_out)
- {
- u16 csr;
- /* For endpoint 0 */
- if (!ep) {
- csr = readw(&musbr->txcsr);
- if (csr & MUSB_CSR0_H_RXSTALL) {
- csr &= ~MUSB_CSR0_H_RXSTALL;
- writew(csr, &musbr->txcsr);
- return 1;
- }
- } else { /* For non-ep0 */
- if (dir_out) { /* is it tx ep */
- csr = readw(&musbr->txcsr);
- if (csr & MUSB_TXCSR_H_RXSTALL) {
- csr &= ~MUSB_TXCSR_H_RXSTALL;
- writew(csr, &musbr->txcsr);
- return 1;
- }
- } else { /* is it rx ep */
- csr = readw(&musbr->rxcsr);
- if (csr & MUSB_RXCSR_H_RXSTALL) {
- csr &= ~MUSB_RXCSR_H_RXSTALL;
- writew(csr, &musbr->rxcsr);
- return 1;
- }
- }
- }
- return 0;
- }
- /*
- * waits until ep0 is ready. Returns 0 if ep is ready, -1 for timeout
- * error and -2 for stall.
- */
- static int wait_until_ep0_ready(struct usb_device *dev, u32 bit_mask)
- {
- u16 csr;
- int result = 1;
- int timeout = CONFIG_USB_MUSB_TIMEOUT;
- while (result > 0) {
- csr = readw(&musbr->txcsr);
- if (csr & MUSB_CSR0_H_ERROR) {
- csr &= ~MUSB_CSR0_H_ERROR;
- writew(csr, &musbr->txcsr);
- dev->status = USB_ST_CRC_ERR;
- result = -1;
- break;
- }
- switch (bit_mask) {
- case MUSB_CSR0_TXPKTRDY:
- if (!(csr & MUSB_CSR0_TXPKTRDY)) {
- if (check_stall(MUSB_CONTROL_EP, 0)) {
- dev->status = USB_ST_STALLED;
- result = -2;
- } else
- result = 0;
- }
- break;
- case MUSB_CSR0_RXPKTRDY:
- if (check_stall(MUSB_CONTROL_EP, 0)) {
- dev->status = USB_ST_STALLED;
- result = -2;
- } else
- if (csr & MUSB_CSR0_RXPKTRDY)
- result = 0;
- break;
- case MUSB_CSR0_H_REQPKT:
- if (!(csr & MUSB_CSR0_H_REQPKT)) {
- if (check_stall(MUSB_CONTROL_EP, 0)) {
- dev->status = USB_ST_STALLED;
- result = -2;
- } else
- result = 0;
- }
- break;
- }
- #ifdef CONFIG_ARK_MUSB
- if(!(readb(&musbr->devctl) & (1<<2)))
- {
- result = -1;
- break;
- }
- #endif
- /* Check the timeout */
- if (--timeout)
- udelay(1);
- else {
- dev->status = USB_ST_CRC_ERR;
- result = -1;
- break;
- }
- }
- return result;
- }
- /*
- * waits until tx ep is ready. Returns 1 when ep is ready and 0 on error.
- */
- static int wait_until_txep_ready(struct usb_device *dev, u8 ep)
- {
- u16 csr;
- int timeout = CONFIG_USB_MUSB_TIMEOUT;
- do {
- if (check_stall(ep, 1)) {
- dev->status = USB_ST_STALLED;
- return 0;
- }
- csr = readw(&musbr->txcsr);
- #ifdef CONFIG_ARK_MUSB
- if (csr & MUSB_TXCSR_H_ERROR) {
- csr &= ~MUSB_TXCSR_H_ERROR;
- writew(csr, &musbr->txcsr);
-
- dev->status = USB_ST_CRC_ERR;
- return 0;
- }
- if(!(readb(&musbr->devctl) & (1<<2)))
- {
- dev->status = USB_ST_NOT_PROC;
- return 0;
- }
- /* Check the timeout */
- if (--timeout)
- udelay(1);
- else
- {
- printf("=== wait_until_txep_ready timeout ===\n");
- dev->status = USB_ST_CRC_ERR;
- return 0;
- }
- } while ((csr & MUSB_TXCSR_TXPKTRDY) || (csr & MUSB_TXCSR_FIFONOTEMPTY));
- #else
- if (csr & MUSB_TXCSR_H_ERROR) {
- dev->status = USB_ST_CRC_ERR;
- return 0;
- }
- /* Check the timeout */
- if (--timeout)
- udelay(1);
- else {
- dev->status = USB_ST_CRC_ERR;
- return 0;
- }
- } while (csr & MUSB_TXCSR_TXPKTRDY);
- #endif
- return 1;
- }
- /*
- * waits until rx ep is ready. Returns 1 when ep is ready and 0 on error.
- */
- static int wait_until_rxep_ready(struct usb_device *dev, u8 ep)
- {
- u16 csr;
- int timeout = CONFIG_USB_MUSB_TIMEOUT;
- do {
- if (check_stall(ep, 0)) {
- dev->status = USB_ST_STALLED;
- return 0;
- }
- csr = readw(&musbr->rxcsr);
- if (csr & MUSB_RXCSR_H_ERROR) {
- csr &= ~MUSB_RXCSR_H_ERROR;
- writew(csr, &musbr->rxcsr);
-
- dev->status = USB_ST_CRC_ERR;
- return 0;
- }
- //Check if usb is plug out
- if(!(readb(&musbr->devctl) & (1<<2)))
- {
- dev->status = USB_ST_NOT_PROC;
- return 0;
- }
- /* Check the timeout */
- if (--timeout)
- {
- //udelay(1);
- udelay(50);
- }
- else
- {
- printf("=== wait_until_rxep_ready timeout ===\n");
- dev->status = USB_ST_CRC_ERR;
- return 0;
- }
- } while (!(csr & MUSB_RXCSR_RXPKTRDY));
- return 1;
- }
- /*
- * This function performs the setup phase of the control transfer
- */
- static int ctrlreq_setup_phase(struct usb_device *dev, struct devrequest *setup)
- {
- int result;
- u16 csr;
- /* write the control request to ep0 fifo */
- write_fifo(MUSB_CONTROL_EP, sizeof(struct devrequest), (void *)setup);
- /* enable transfer of setup packet */
- csr = readw(&musbr->txcsr);
- udelay(100000);
- csr |= (MUSB_CSR0_TXPKTRDY|MUSB_CSR0_H_SETUPPKT);
- writew(csr, &musbr->txcsr);
- /* wait until the setup packet is transmitted */
- result = wait_until_ep0_ready(dev, MUSB_CSR0_TXPKTRDY);
- dev->act_len = 0;
- return result;
- }
- /*
- * This function handles the control transfer in data phase
- */
- static int ctrlreq_in_data_phase(struct usb_device *dev, u32 len, void *buffer)
- {
- u16 csr;
- u32 rxlen = 0;
- u32 nextlen = 0;
- u8 maxpktsize = (1 << dev->maxpacketsize) * 8;
- u8 *rxbuff = (u8 *)buffer;
- u8 rxedlength;
- int result;
- while (rxlen < len) {
- /* Determine the next read length */
- nextlen = ((len-rxlen) > maxpktsize) ? maxpktsize : (len-rxlen);
- /* Set the ReqPkt bit */
- csr = readw(&musbr->txcsr);
- writew(csr | MUSB_CSR0_H_REQPKT, &musbr->txcsr);
- result = wait_until_ep0_ready(dev, MUSB_CSR0_RXPKTRDY);
- if (result < 0)
- return result;
- /* Actual number of bytes received by usb */
- rxedlength = readb(&musbr->rxcount);
- /* Read the data from the RxFIFO */
- read_fifo(MUSB_CONTROL_EP, rxedlength, &rxbuff[rxlen]);
- /* Clear the RxPktRdy Bit */
- csr = readw(&musbr->txcsr);
- csr &= ~MUSB_CSR0_RXPKTRDY;
- writew(csr, &musbr->txcsr);
- /* short packet? */
- if (rxedlength != nextlen) {
- dev->act_len += rxedlength;
- break;
- }
- rxlen += nextlen;
- dev->act_len = rxlen;
- }
- return 0;
- }
- /*
- * This function handles the control transfer out data phase
- */
- static int ctrlreq_out_data_phase(struct usb_device *dev, u32 len, void *buffer)
- {
- u16 csr;
- u32 txlen = 0;
- u32 nextlen = 0;
- u8 maxpktsize = (1 << dev->maxpacketsize) * 8;
- u8 *txbuff = (u8 *)buffer;
- int result = 0;
- while (txlen < len) {
- /* Determine the next write length */
- nextlen = ((len-txlen) > maxpktsize) ? maxpktsize : (len-txlen);
- /* Load the data to send in FIFO */
- write_fifo(MUSB_CONTROL_EP, txlen, &txbuff[txlen]);
- /* Set TXPKTRDY bit */
- csr = readw(&musbr->txcsr);
-
- csr |= MUSB_CSR0_TXPKTRDY;
- #if !defined(CONFIG_SOC_DM365)
- csr |= MUSB_CSR0_H_DIS_PING;
- #endif
- writew(csr, &musbr->txcsr);
- result = wait_until_ep0_ready(dev, MUSB_CSR0_TXPKTRDY);
- if (result < 0)
- break;
- txlen += nextlen;
- dev->act_len = txlen;
- }
- return result;
- }
- /*
- * This function handles the control transfer out status phase
- */
- static int ctrlreq_out_status_phase(struct usb_device *dev)
- {
- u16 csr;
- int result;
- /* Set the StatusPkt bit */
- csr = readw(&musbr->txcsr);
- csr |= (MUSB_CSR0_TXPKTRDY | MUSB_CSR0_H_STATUSPKT);
- #if !defined(CONFIG_SOC_DM365)
- csr |= MUSB_CSR0_H_DIS_PING;
- #endif
- writew(csr, &musbr->txcsr);
- /* Wait until TXPKTRDY bit is cleared */
- result = wait_until_ep0_ready(dev, MUSB_CSR0_TXPKTRDY);
- return result;
- }
- /*
- * This function handles the control transfer in status phase
- */
- static int ctrlreq_in_status_phase(struct usb_device *dev)
- {
- u16 csr;
- int result;
- /* Set the StatusPkt bit and ReqPkt bit */
- csr = MUSB_CSR0_H_REQPKT | MUSB_CSR0_H_STATUSPKT;
- #if !defined(CONFIG_SOC_DM365)
- csr |= MUSB_CSR0_H_DIS_PING;
- #endif
- writew(csr, &musbr->txcsr);
- result = wait_until_ep0_ready(dev, MUSB_CSR0_H_REQPKT);
- /* clear StatusPkt bit and RxPktRdy bit */
- csr = readw(&musbr->txcsr);
- csr &= ~(MUSB_CSR0_RXPKTRDY | MUSB_CSR0_H_STATUSPKT);
- writew(csr, &musbr->txcsr);
- return result;
- }
- /*
- * determines the speed of the device (High/Full/Slow)
- */
- static u8 get_dev_speed(struct usb_device *dev)
- {
- return (dev->speed == USB_SPEED_HIGH) ? MUSB_TYPE_SPEED_HIGH :
- ((dev->speed == USB_SPEED_LOW) ? MUSB_TYPE_SPEED_LOW :
- MUSB_TYPE_SPEED_FULL);
- }
- /*
- * configure the hub address and the port address.
- */
- static void config_hub_port(struct usb_device *dev, u8 ep)
- {
- u8 chid;
- u8 hub;
- /* Find out the nearest parent which is high speed */
- while (dev->parent->parent != NULL)
- if (get_dev_speed(dev->parent) != MUSB_TYPE_SPEED_HIGH)
- dev = dev->parent;
- else
- break;
- /* determine the port address at that hub */
- hub = dev->parent->devnum;
- for (chid = 0; chid < USB_MAXCHILDREN; chid++)
- if (dev->parent->children[chid] == dev)
- break;
- #ifndef MUSB_NO_MULTIPOINT
- /* configure the hub address and the port address */
- writeb(hub, &musbr->tar[ep].txhubaddr);
- writeb((chid + 1), &musbr->tar[ep].txhubport);
- writeb(hub, &musbr->tar[ep].rxhubaddr);
- writeb((chid + 1), &musbr->tar[ep].rxhubport);
- #endif
- }
- #ifdef MUSB_NO_MULTIPOINT
- static void musb_port_reset(int do_reset)
- {
- u8 power = readb(&musbr->power);
- if (do_reset) {
- power &= 0xf0;
- writeb(power | MUSB_POWER_RESET, &musbr->power);
- port_status |= USB_PORT_STAT_RESET;
- port_status &= ~USB_PORT_STAT_ENABLE;
- udelay(500000);
- } else {
- writeb(power & ~MUSB_POWER_RESET, &musbr->power);
- power = readb(&musbr->power);
- if (power & MUSB_POWER_HSMODE)
- port_status |= USB_PORT_STAT_HIGH_SPEED;
- port_status &= ~(USB_PORT_STAT_RESET | (USB_PORT_STAT_C_CONNECTION << 16));
- port_status |= USB_PORT_STAT_ENABLE
- | (USB_PORT_STAT_C_RESET << 16)
- | (USB_PORT_STAT_C_ENABLE << 16);
- }
- }
- /*
- * root hub control
- */
- static int musb_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
- void *buffer, int transfer_len,
- struct devrequest *cmd)
- {
- int leni = transfer_len;
- int len = 0;
- int stat = 0;
- u32 datab[4];
- const u8 *data_buf = (u8 *) datab;
- u16 bmRType_bReq;
- u16 wValue;
- u16 wIndex;
- u16 wLength;
- u16 int_usb;
- if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
- debug("Root-Hub submit IRQ: NOT implemented\n");
- return 0;
- }
- bmRType_bReq = cmd->requesttype | (cmd->request << 8);
- wValue = swap_16(cmd->value);
- wIndex = swap_16(cmd->index);
- wLength = swap_16(cmd->length);
- debug("--- HUB ----------------------------------------\n");
- debug("submit rh urb, req=%x val=%#x index=%#x len=%d\n",
- bmRType_bReq, wValue, wIndex, wLength);
- debug("------------------------------------------------\n");
- switch (bmRType_bReq) {
- case RH_GET_STATUS:
- debug("RH_GET_STATUS\n");
- *(__u16 *) data_buf = swap_16(1);
- len = 2;
- break;
- case RH_GET_STATUS | RH_INTERFACE:
- debug("RH_GET_STATUS | RH_INTERFACE\n");
- *(__u16 *) data_buf = swap_16(0);
- len = 2;
- break;
- case RH_GET_STATUS | RH_ENDPOINT:
- debug("RH_GET_STATUS | RH_ENDPOINT\n");
- *(__u16 *) data_buf = swap_16(0);
- len = 2;
- break;
- case RH_GET_STATUS | RH_CLASS:
- debug("RH_GET_STATUS | RH_CLASS\n");
- *(__u32 *) data_buf = swap_32(0);
- len = 4;
- break;
- case RH_GET_STATUS | RH_OTHER | RH_CLASS:
- debug("RH_GET_STATUS | RH_OTHER | RH_CLASS\n");
- int_usb = readw(&musbr->intrusb);
- if (int_usb & MUSB_INTR_CONNECT) {
- port_status |= USB_PORT_STAT_CONNECTION
- | (USB_PORT_STAT_C_CONNECTION << 16);
- port_status |= USB_PORT_STAT_HIGH_SPEED
- | USB_PORT_STAT_ENABLE;
- }
- if (port_status & USB_PORT_STAT_RESET)
- musb_port_reset(0);
- *(__u32 *) data_buf = swap_32(port_status);
- len = 4;
- break;
- case RH_CLEAR_FEATURE | RH_ENDPOINT:
- debug("RH_CLEAR_FEATURE | RH_ENDPOINT\n");
- switch (wValue) {
- case RH_ENDPOINT_STALL:
- debug("C_HUB_ENDPOINT_STALL\n");
- len = 0;
- break;
- }
- port_status &= ~(1 << wValue);
- break;
- case RH_CLEAR_FEATURE | RH_CLASS:
- debug("RH_CLEAR_FEATURE | RH_CLASS\n");
- switch (wValue) {
- case RH_C_HUB_LOCAL_POWER:
- debug("C_HUB_LOCAL_POWER\n");
- len = 0;
- break;
- case RH_C_HUB_OVER_CURRENT:
- debug("C_HUB_OVER_CURRENT\n");
- len = 0;
- break;
- }
- port_status &= ~(1 << wValue);
- break;
- case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
- debug("RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS\n");
- switch (wValue) {
- case RH_PORT_ENABLE:
- len = 0;
- break;
- case RH_PORT_SUSPEND:
- len = 0;
- break;
- case RH_PORT_POWER:
- len = 0;
- break;
- case RH_C_PORT_CONNECTION:
- len = 0;
- break;
- case RH_C_PORT_ENABLE:
- len = 0;
- break;
- case RH_C_PORT_SUSPEND:
- len = 0;
- break;
- case RH_C_PORT_OVER_CURRENT:
- len = 0;
- break;
- case RH_C_PORT_RESET:
- len = 0;
- break;
- default:
- debug("invalid wValue\n");
- stat = USB_ST_STALLED;
- }
- port_status &= ~(1 << wValue);
- break;
- case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
- debug("RH_SET_FEATURE | RH_OTHER | RH_CLASS\n");
- switch (wValue) {
- case RH_PORT_SUSPEND:
- len = 0;
- break;
- case RH_PORT_RESET:
- musb_port_reset(1);
- len = 0;
- break;
- case RH_PORT_POWER:
- len = 0;
- break;
- case RH_PORT_ENABLE:
- len = 0;
- break;
- default:
- debug("invalid wValue\n");
- stat = USB_ST_STALLED;
- }
- port_status |= 1 << wValue;
- break;
- case RH_SET_ADDRESS:
- debug("RH_SET_ADDRESS\n");
- rh_devnum = wValue;
- len = 0;
- break;
- case RH_GET_DESCRIPTOR:
- debug("RH_GET_DESCRIPTOR: %x, %d\n", wValue, wLength);
- switch (wValue) {
- case (USB_DT_DEVICE << 8): /* device descriptor */
- len = min_t(unsigned int,
- leni, min_t(unsigned int,
- sizeof(root_hub_dev_des),
- wLength));
- data_buf = root_hub_dev_des;
- break;
- case (USB_DT_CONFIG << 8): /* configuration descriptor */
- len = min_t(unsigned int,
- leni, min_t(unsigned int,
- sizeof(root_hub_config_des),
- wLength));
- data_buf = root_hub_config_des;
- break;
- case ((USB_DT_STRING << 8) | 0x00): /* string 0 descriptors */
- len = min_t(unsigned int,
- leni, min_t(unsigned int,
- sizeof(root_hub_str_index0),
- wLength));
- data_buf = root_hub_str_index0;
- break;
- case ((USB_DT_STRING << 8) | 0x01): /* string 1 descriptors */
- len = min_t(unsigned int,
- leni, min_t(unsigned int,
- sizeof(root_hub_str_index1),
- wLength));
- data_buf = root_hub_str_index1;
- break;
- default:
- debug("invalid wValue\n");
- stat = USB_ST_STALLED;
- }
- break;
- case RH_GET_DESCRIPTOR | RH_CLASS: {
- u8 *_data_buf = (u8 *) datab;
- debug("RH_GET_DESCRIPTOR | RH_CLASS\n");
- _data_buf[0] = 0x09; /* min length; */
- _data_buf[1] = 0x29;
- _data_buf[2] = 0x1; /* 1 port */
- _data_buf[3] = 0x01; /* per-port power switching */
- _data_buf[3] |= 0x10; /* no overcurrent reporting */
- /* Corresponds to data_buf[4-7] */
- _data_buf[4] = 0;
- _data_buf[5] = 5;
- _data_buf[6] = 0;
- _data_buf[7] = 0x02;
- _data_buf[8] = 0xff;
- len = min_t(unsigned int, leni,
- min_t(unsigned int, data_buf[0], wLength));
- break;
- }
- case RH_GET_CONFIGURATION:
- debug("RH_GET_CONFIGURATION\n");
- *(__u8 *) data_buf = 0x01;
- len = 1;
- break;
- case RH_SET_CONFIGURATION:
- debug("RH_SET_CONFIGURATION\n");
- len = 0;
- break;
- default:
- debug("*** *** *** unsupported root hub command *** *** ***\n");
- stat = USB_ST_STALLED;
- }
- len = min_t(int, len, leni);
- if (buffer != data_buf)
- memcpy(buffer, data_buf, len);
- dev->act_len = len;
- dev->status = stat;
- debug("dev act_len %d, status %lu\n", dev->act_len, dev->status);
- return stat;
- }
- static void musb_rh_init(void)
- {
- rh_devnum = 0;
- port_status = 0;
- }
- #else
- static void musb_rh_init(void) {}
- #endif
- /*
- * do a control transfer
- */
- int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
- int len, struct devrequest *setup)
- {
- int devnum = usb_pipedevice(pipe);
- u8 devspeed;
-
- if(!(readb(&musbr->devctl) & (1<<2)))
- {
- return -1;
- }
- #ifdef MUSB_NO_MULTIPOINT
- /* Control message is for the HUB? */
- if (devnum == rh_devnum) {
- int stat = musb_submit_rh_msg(dev, pipe, buffer, len, setup);
- if (stat)
- return stat;
- }
- #endif
- /* select control endpoint */
- writeb(MUSB_CONTROL_EP, &musbr->index);
- readw(&musbr->txcsr);
- #ifndef MUSB_NO_MULTIPOINT
- /* target addr and (for multipoint) hub addr/port */
- writeb(devnum, &musbr->tar[MUSB_CONTROL_EP].txfuncaddr);
- writeb(devnum, &musbr->tar[MUSB_CONTROL_EP].rxfuncaddr);
- #endif
- /* configure the hub address and the port number as required */
- devspeed = get_dev_speed(dev);
- if ((musb_ishighspeed()) && (dev->parent != NULL) &&
- (devspeed != MUSB_TYPE_SPEED_HIGH)) {
- config_hub_port(dev, MUSB_CONTROL_EP);
- writeb(devspeed << 6, &musbr->txtype);
- } else {
- writeb(musb_cfg.musb_speed << 6, &musbr->txtype);
- #ifndef MUSB_NO_MULTIPOINT
- writeb(0, &musbr->tar[MUSB_CONTROL_EP].txhubaddr);
- writeb(0, &musbr->tar[MUSB_CONTROL_EP].txhubport);
- writeb(0, &musbr->tar[MUSB_CONTROL_EP].rxhubaddr);
- writeb(0, &musbr->tar[MUSB_CONTROL_EP].rxhubport);
- #endif
- }
- /* Control transfer setup phase */
- if (ctrlreq_setup_phase(dev, setup) < 0)
- return 0;
- switch (setup->request) {
- case USB_REQ_GET_DESCRIPTOR:
- case USB_REQ_GET_CONFIGURATION:
- case USB_REQ_GET_INTERFACE:
- case USB_REQ_GET_STATUS:
- case USB_MSC_BBB_GET_MAX_LUN:
- /* control transfer in-data-phase */
- if (ctrlreq_in_data_phase(dev, len, buffer) < 0)
- return 0;
- /* control transfer out-status-phase */
- if (ctrlreq_out_status_phase(dev) < 0)
- return 0;
- break;
- case USB_REQ_SET_ADDRESS:
- case USB_REQ_SET_CONFIGURATION:
- case USB_REQ_SET_FEATURE:
- case USB_REQ_SET_INTERFACE:
- case USB_REQ_CLEAR_FEATURE:
- case USB_MSC_BBB_RESET:
- /* control transfer in status phase */
- if (ctrlreq_in_status_phase(dev) < 0)
- return 0;
- break;
- case USB_REQ_SET_DESCRIPTOR:
- /* control transfer out data phase */
- if (ctrlreq_out_data_phase(dev, len, buffer) < 0)
- return 0;
- /* control transfer in status phase */
- if (ctrlreq_in_status_phase(dev) < 0)
- return 0;
- break;
- default:
- /* unhandled control transfer */
- return -1;
- }
- dev->status = 0;
- dev->act_len = len;
- #ifdef MUSB_NO_MULTIPOINT
- /* Set device address to USB_FADDR register */
- if (setup->request == USB_REQ_SET_ADDRESS)
- writeb(dev->devnum, &musbr->faddr);
- #endif
- return len;
- }
- /*
- * do a bulk transfer
- */
- int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
- void *buffer, int len)
- {
- int dir_out = usb_pipeout(pipe);
- int ep = usb_pipeendpoint(pipe);
- #ifndef MUSB_NO_MULTIPOINT
- int devnum = usb_pipedevice(pipe);
- #endif
- u8 type;
- u16 csr;
- u32 txlen = 0;
- u32 nextlen = 0;
- u8 devspeed;
- int ret = 0;
- u32 retry = 0;
- if(!(readb(&musbr->devctl) & (1<<2)))
- {
- return -1;
- }
- /* select bulk endpoint */
- writeb(MUSB_BULK_EP, &musbr->index);
- #ifndef MUSB_NO_MULTIPOINT
- /* write the address of the device */
- if (dir_out)
- writeb(devnum, &musbr->tar[MUSB_BULK_EP].txfuncaddr);
- else
- writeb(devnum, &musbr->tar[MUSB_BULK_EP].rxfuncaddr);
- #endif
- /* configure the hub address and the port number as required */
- devspeed = get_dev_speed(dev);
- if ((musb_ishighspeed()) && (dev->parent != NULL) &&
- (devspeed != MUSB_TYPE_SPEED_HIGH)) {
- /*
- * MUSB is in high speed and the destination device is full
- * speed device. So configure the hub address and port
- * address registers.
- */
- config_hub_port(dev, MUSB_BULK_EP);
- } else {
- #ifndef MUSB_NO_MULTIPOINT
- if (dir_out) {
- writeb(0, &musbr->tar[MUSB_BULK_EP].txhubaddr);
- writeb(0, &musbr->tar[MUSB_BULK_EP].txhubport);
- } else {
- writeb(0, &musbr->tar[MUSB_BULK_EP].rxhubaddr);
- writeb(0, &musbr->tar[MUSB_BULK_EP].rxhubport);
- }
- #endif
- devspeed = musb_cfg.musb_speed;
- }
- #ifdef CONFIG_ARK_MUSB
- if (dir_out) {
- csr = readw(&musbr->txcsr);
- /* flush fifo */
- while (csr & MUSB_TXCSR_FIFONOTEMPTY) {
- csr |= MUSB_TXCSR_FLUSHFIFO;
- csr |= MUSB_TXCSR_TXPKTRDY;
- writew(csr, &musbr->txcsr);
- csr = readw(&musbr->txcsr);
-
- if(!(readb(&musbr->devctl) & (1<<2)))
- {
- ret = -1;
- break;
- }
- }
-
- /*
- * We must not clear the DMAMODE bit before or in
- * the same cycle with the DMAENAB bit, so we clear
- * the latter first...
- */
- csr &= ~(MUSB_TXCSR_H_NAKTIMEOUT
- | MUSB_TXCSR_AUTOSET
- | MUSB_TXCSR_DMAENAB
- | MUSB_TXCSR_FRCDATATOG
- | MUSB_TXCSR_H_RXSTALL
- | MUSB_TXCSR_H_ERROR
- | MUSB_TXCSR_TXPKTRDY
- );
- csr |= MUSB_TXCSR_MODE;
- writew(csr, &musbr->txcsr);
- } else {
- csr = readw(&musbr->txcsr);
- /* Clear TX FIFO */
- while(csr & MUSB_TXCSR_FIFONOTEMPTY) {
- csr |= MUSB_TXCSR_FLUSHFIFO;
- csr |= MUSB_TXCSR_TXPKTRDY;
- writew(csr, &musbr->txcsr);
- csr = readw(&musbr->txcsr);
- if(!(readb(&musbr->devctl) & (1<<2)))
- {
- ret = -1;
- break;
- }
- }
-
- csr = readw(&musbr->txcsr);
- csr &= ~(MUSB_TXCSR_H_NAKTIMEOUT
- | MUSB_TXCSR_AUTOSET
- | MUSB_TXCSR_DMAENAB
- | MUSB_TXCSR_FRCDATATOG
- | MUSB_TXCSR_H_RXSTALL
- | MUSB_TXCSR_H_ERROR
- | MUSB_TXCSR_TXPKTRDY
- | MUSB_TXCSR_MODE
- );
- writew(csr, &musbr->txcsr);
- csr = readw(&musbr->txcsr);
- writew(csr | MUSB_TXCSR_FRCDATATOG, &musbr->txcsr);
- }
- #endif /* CONFIG_ARK_MUSB */
- if (dir_out) { /* bulk-out transfer */
- /* Write the saved toggle bit value */
- write_toggle(dev, ep, dir_out);
-
- /* Program the TxType register */
- type = (devspeed << MUSB_TYPE_SPEED_SHIFT) |
- (MUSB_TYPE_PROTO_BULK << MUSB_TYPE_PROTO_SHIFT) |
- (ep & MUSB_TYPE_REMOTE_END);
- writeb(type, &musbr->txtype);
- writeb(0, &musbr->txinterval);
- /* Write maximum packet size to the TxMaxp register */
- writew(dev->epmaxpacketout[ep], &musbr->txmaxp);
- while (txlen < len) {
- nextlen = ((len-txlen) < dev->epmaxpacketout[ep]) ?
- (len-txlen) : dev->epmaxpacketout[ep];
- /* Write the data to the FIFO */
- write_fifo(MUSB_BULK_EP, nextlen,
- (void *)(((u8 *)buffer) + txlen));
- /* Set the TxPktRdy bit */
- csr = readw(&musbr->txcsr);
- writew(csr | MUSB_TXCSR_TXPKTRDY, &musbr->txcsr);
- /* Wait until the TxPktRdy bit is cleared */
- if (wait_until_txep_ready(dev, MUSB_BULK_EP) != 1) {
- csr = readw(&musbr->txcsr);
- csr |= MUSB_TXCSR_FLUSHFIFO;
- //csr &= ~MUSB_TXCSR_TXPKTRDY;
- csr |= MUSB_TXCSR_TXPKTRDY; //FlushFIFO has no effect unless TXPKTRDY is set
- writew(csr, &musbr->txcsr);
-
- csr = readw(&musbr->txcsr);
- usb_settoggle(dev, ep, dir_out,
- (csr >> MUSB_TXCSR_H_DATATOGGLE_SHIFT) & 1);
- dev->act_len = txlen;
- return 0;
- }
- txlen += nextlen;
- }
- /* Keep a copy of the data toggle bit */
- csr = readw(&musbr->txcsr);
- usb_settoggle(dev, ep, dir_out,
- (csr >> MUSB_TXCSR_H_DATATOGGLE_SHIFT) & 1);
- } else { /* bulk-in transfer */
- /* Write the saved toggle bit value */
- write_toggle(dev, ep, dir_out);
- /* Program the RxType register */
- type = (devspeed << MUSB_TYPE_SPEED_SHIFT) |
- (MUSB_TYPE_PROTO_BULK << MUSB_TYPE_PROTO_SHIFT) |
- (ep & MUSB_TYPE_REMOTE_END);
- writeb(type, &musbr->rxtype);
- writeb(0, &musbr->rxinterval);
-
- /* Write the maximum packet size to the RxMaxp register */
- writew(dev->epmaxpacketin[ep], &musbr->rxmaxp);
- while (txlen < len) {
- nextlen = ((len-txlen) < dev->epmaxpacketin[ep]) ?
- (len-txlen) : dev->epmaxpacketin[ep];
-
- #if 0 /* ReqPkt failed, no retry */
- /* Set the ReqPkt bit */
- csr = readw(&musbr->rxcsr);
- writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
- /* Wait until the RxPktRdy bit is set */
- if (!wait_until_rxep_ready(dev, MUSB_BULK_EP) != 1) {
- csr = readw(&musbr->rxcsr);
- csr |= MUSB_RXCSR_FLUSHFIFO;
- //csr &= ~MUSB_RXCSR_RXPKTRDY;
- csr |= MUSB_RXCSR_RXPKTRDY;
- writew(csr, &musbr->rxcsr);
- usb_settoggle(dev, ep, dir_out,
- (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
-
- dev->act_len = txlen;
- return 0;
- }
- #else /* ReqPkt failed, then retry */
- retry = 100;
- reqpkt_again:
- /* Set the ReqPkt bit */
- csr = readw(&musbr->rxcsr);
- writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
-
- /* Wait until the RxPktRdy bit is set */
- if (!wait_until_rxep_ready(dev, MUSB_BULK_EP)) {
- //printf("###########retry:%d\n",101-retry);
- // Data err or NAK timeout
- if(dev->status == USB_ST_CRC_ERR)
- {
- udelay(1);
- if(--retry)
- goto reqpkt_again;
- }
- //Flush RxFIFO
- csr = readw(&musbr->rxcsr);
- csr |= MUSB_RXCSR_FLUSHFIFO;
- //csr &= ~MUSB_RXCSR_RXPKTRDY;
- csr |= MUSB_RXCSR_RXPKTRDY; //FlushFIFO has no effect unless rXPKTRDY is set
- writew(csr, &musbr->rxcsr);
-
- csr = readw(&musbr->rxcsr);
- usb_settoggle(dev, ep, dir_out,
- (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
-
- dev->act_len = txlen;
-
- //Check if usb is plug out
- if(!(readb(&musbr->devctl) & (1<<2)))
- {
- dev->status = USB_ST_NOT_PROC;
- return -1;
- }
-
- return 0;
- }
- #endif
- /* Read the data from the FIFO */
- read_fifo(MUSB_BULK_EP, nextlen,
- (void *)(((u8 *)buffer) + txlen));
- #if 0
- int i;
- printf("read_fifo:");
- for(i=0; i<nextlen; i++)
- printf("0x%x ", *((((u8 *)buffer) + txlen)+i));
- printf("\n");
- #endif
- /* Clear the RxPktRdy bit */
- csr = readw(&musbr->rxcsr);
- csr &= ~MUSB_RXCSR_RXPKTRDY;
- writew(csr, &musbr->rxcsr);
- txlen += nextlen;
- }
- /* Keep a copy of the data toggle bit */
- csr = readw(&musbr->rxcsr);
- usb_settoggle(dev, ep, dir_out,
- (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
- }
- /* bulk transfer is complete */
- dev->status = 0;
- dev->act_len = len;
- return ret;
- }
- /*
- * This function initializes the usb controller module.
- */
- extern int musb_platform_init(void);
- int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
- {
- u8 power;
- u32 timeout;
- musb_rh_init();
- if (musb_platform_init() == -1)
- return -1;
- /* Configure all the endpoint FIFO's and start usb controller */
- musbr = musb_cfg.regs;
- musb_configure_ep(&epinfo[0], ARRAY_SIZE(epinfo));
- musb_start();
- /*
- * Wait until musb is enabled in host mode with a timeout. There
- * should be a usb device connected.
- */
- timeout = musb_cfg.timeout;
- while (--timeout) {
- if (readb(&musbr->devctl) & MUSB_DEVCTL_HM)
- break;
- udelay(1);
- }
- if(timeout)
- printf("=============== usb_lowlevel_init time is %d us===============\r\n", musb_cfg.timeout-timeout);
- else
- printf("=============== usb_lowlevel_init %d us timeout===============\r\n", musb_cfg.timeout);
- /* if musb core is not in host mode, then return */
- if (!timeout)
- return -1;
- /* start usb bus reset */
- power = readb(&musbr->power);
- writeb(power | MUSB_POWER_RESET, &musbr->power);
- /* After initiating a usb reset, wait for about 20ms to 30ms */
- udelay(25000);
- /* stop usb bus reset */
- power = readb(&musbr->power);
- power &= ~MUSB_POWER_RESET;
- writeb(power, &musbr->power);
- /* Determine if the connected device is a high/full/low speed device */
- musb_cfg.musb_speed = (readb(&musbr->power) & MUSB_POWER_HSMODE) ?
- MUSB_TYPE_SPEED_HIGH :
- ((readb(&musbr->devctl) & MUSB_DEVCTL_FSDEV) ?
- MUSB_TYPE_SPEED_FULL : MUSB_TYPE_SPEED_LOW);
- printf("=============== usb_lowlevel_init device is %s===============\r\n",
- (readb(&musbr->power) & MUSB_POWER_HSMODE)?"high speed":"no high speed");
- return 0;
- }
- /*
- * This function stops the operation of the davinci usb module.
- */
- int usb_lowlevel_stop(int index)
- {
- /* Reset the USB module */
- musb_platform_deinit();
- writeb(0, &musbr->devctl);
- return 0;
- }
- /*
- * This function supports usb interrupt transfers. Currently, usb interrupt
- * transfers are not supported.
- */
- int submit_int_msg(struct usb_device *dev, unsigned long pipe,
- void *buffer, int len, int interval)
- {
- int dir_out = usb_pipeout(pipe);
- int ep = usb_pipeendpoint(pipe);
- #ifndef MUSB_NO_MULTIPOINT
- int devnum = usb_pipedevice(pipe);
- #endif
- u8 type;
- u16 csr;
- u32 txlen = 0;
- u32 nextlen = 0;
- u8 devspeed;
- /* select interrupt endpoint */
- writeb(MUSB_INTR_EP, &musbr->index);
- #ifndef MUSB_NO_MULTIPOINT
- /* write the address of the device */
- if (dir_out)
- writeb(devnum, &musbr->tar[MUSB_INTR_EP].txfuncaddr);
- else
- writeb(devnum, &musbr->tar[MUSB_INTR_EP].rxfuncaddr);
- #endif
- /* configure the hub address and the port number as required */
- devspeed = get_dev_speed(dev);
- if ((musb_ishighspeed()) && (dev->parent != NULL) &&
- (devspeed != MUSB_TYPE_SPEED_HIGH)) {
- /*
- * MUSB is in high speed and the destination device is full
- * speed device. So configure the hub address and port
- * address registers.
- */
- config_hub_port(dev, MUSB_INTR_EP);
- } else {
- #ifndef MUSB_NO_MULTIPOINT
- if (dir_out) {
- writeb(0, &musbr->tar[MUSB_INTR_EP].txhubaddr);
- writeb(0, &musbr->tar[MUSB_INTR_EP].txhubport);
- } else {
- writeb(0, &musbr->tar[MUSB_INTR_EP].rxhubaddr);
- writeb(0, &musbr->tar[MUSB_INTR_EP].rxhubport);
- }
- #endif
- devspeed = musb_cfg.musb_speed;
- }
- #ifdef CONFIG_ARK_MUSB
- if (dir_out) {
- csr = readw(&musbr->txcsr);
- /* flush fifo */
- while (csr & MUSB_TXCSR_FIFONOTEMPTY) {
- csr |= MUSB_TXCSR_FLUSHFIFO;
- writeb(csr, &musbr->txcsr);
- csr = readw(&musbr->txcsr);
- }
- /*
- * We must not clear the DMAMODE bit before or in
- * the same cycle with the DMAENAB bit, so we clear
- * the latter first...
- */
- csr &= ~(MUSB_TXCSR_H_NAKTIMEOUT
- | MUSB_TXCSR_AUTOSET
- | MUSB_TXCSR_DMAENAB
- | MUSB_TXCSR_FRCDATATOG
- | MUSB_TXCSR_H_RXSTALL
- | MUSB_TXCSR_H_ERROR
- | MUSB_TXCSR_TXPKTRDY
- );
- csr |= MUSB_TXCSR_MODE;
- writew(csr, &musbr->txcsr);
- } else {
- csr = readw(&musbr->txcsr);
- /* Clear TX FIFO */
- while(csr & MUSB_TXCSR_FIFONOTEMPTY) {
- csr |= MUSB_TXCSR_FLUSHFIFO;
- csr = readw(&musbr->txcsr);
- }
- csr = readw(&musbr->txcsr);
- csr &= ~(MUSB_TXCSR_H_NAKTIMEOUT
- | MUSB_TXCSR_AUTOSET
- | MUSB_TXCSR_DMAENAB
- | MUSB_TXCSR_FRCDATATOG
- | MUSB_TXCSR_H_RXSTALL
- | MUSB_TXCSR_H_ERROR
- | MUSB_TXCSR_TXPKTRDY
- | MUSB_TXCSR_MODE
- );
- writew(csr, &musbr->txcsr);
- csr = readw(&musbr->txcsr);
- writew(csr | MUSB_TXCSR_FRCDATATOG, &musbr->txcsr);
- }
- #endif /* CONFIG_ARK_MUSB */
- /* Write the saved toggle bit value */
- write_toggle(dev, ep, dir_out);
- if (!dir_out) { /* intrrupt-in transfer */
- /* Write the saved toggle bit value */
- write_toggle(dev, ep, dir_out);
- writeb(interval, &musbr->rxinterval);
- /* Program the RxType register */
- type = (devspeed << MUSB_TYPE_SPEED_SHIFT) |
- (MUSB_TYPE_PROTO_INTR << MUSB_TYPE_PROTO_SHIFT) |
- (ep & MUSB_TYPE_REMOTE_END);
- writeb(type, &musbr->rxtype);
- /* Write the maximum packet size to the RxMaxp register */
- writew(dev->epmaxpacketin[ep], &musbr->rxmaxp);
- while (txlen < len) {
- nextlen = ((len-txlen) < dev->epmaxpacketin[ep]) ?
- (len-txlen) : dev->epmaxpacketin[ep];
- /* Set the ReqPkt bit */
- csr = readw(&musbr->rxcsr);
- writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
- /* Wait until the RxPktRdy bit is set */
- if (wait_until_rxep_ready(dev, MUSB_INTR_EP) != 1) {
- csr = readw(&musbr->rxcsr);
- usb_settoggle(dev, ep, dir_out,
- (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
- csr &= ~MUSB_RXCSR_RXPKTRDY;
- writew(csr, &musbr->rxcsr);
- dev->act_len = txlen;
- return 0;
- }
- /* Read the data from the FIFO */
- read_fifo(MUSB_INTR_EP, nextlen,
- (void *)(((u8 *)buffer) + txlen));
- /* Clear the RxPktRdy bit */
- csr = readw(&musbr->rxcsr);
- csr &= ~MUSB_RXCSR_RXPKTRDY;
- writew(csr, &musbr->rxcsr);
- txlen += nextlen;
- }
- /* Keep a copy of the data toggle bit */
- csr = readw(&musbr->rxcsr);
- usb_settoggle(dev, ep, dir_out,
- (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
- }
- /* interrupt transfer is complete */
- dev->irq_status = 0;
- dev->irq_act_len = len;
- dev->irq_handle(dev);
- dev->status = 0;
- dev->act_len = len;
- return 0;
- }
|