musb_hcd.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. /*
  2. * Mentor USB OTG Core host controller driver.
  3. *
  4. * Copyright (c) 2008 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. *
  21. * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
  22. */
  23. #include <common.h>
  24. #include "musb_hcd.h"
  25. /* MSC control transfers */
  26. #define USB_MSC_BBB_RESET 0xFF
  27. #define USB_MSC_BBB_GET_MAX_LUN 0xFE
  28. /* Endpoint configuration information */
  29. static const struct musb_epinfo epinfo[3] = {
  30. {MUSB_BULK_EP, 1, 512}, /* EP1 - Bluk Out - 512 Bytes */
  31. {MUSB_BULK_EP, 0, 512}, /* EP1 - Bluk In - 512 Bytes */
  32. {MUSB_INTR_EP, 0, 64} /* EP2 - Interrupt IN - 64 Bytes */
  33. };
  34. /* --- Virtual Root Hub ---------------------------------------------------- */
  35. #ifdef MUSB_NO_MULTIPOINT
  36. static int rh_devnum;
  37. static u32 port_status;
  38. /* Device descriptor */
  39. static const u8 root_hub_dev_des[] = {
  40. 0x12, /* __u8 bLength; */
  41. 0x01, /* __u8 bDescriptorType; Device */
  42. 0x00, /* __u16 bcdUSB; v1.1 */
  43. 0x02,
  44. 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
  45. 0x00, /* __u8 bDeviceSubClass; */
  46. 0x00, /* __u8 bDeviceProtocol; */
  47. 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
  48. 0x00, /* __u16 idVendor; */
  49. 0x00,
  50. 0x00, /* __u16 idProduct; */
  51. 0x00,
  52. 0x00, /* __u16 bcdDevice; */
  53. 0x00,
  54. 0x00, /* __u8 iManufacturer; */
  55. 0x01, /* __u8 iProduct; */
  56. 0x00, /* __u8 iSerialNumber; */
  57. 0x01 /* __u8 bNumConfigurations; */
  58. };
  59. /* Configuration descriptor */
  60. static const u8 root_hub_config_des[] = {
  61. 0x09, /* __u8 bLength; */
  62. 0x02, /* __u8 bDescriptorType; Configuration */
  63. 0x19, /* __u16 wTotalLength; */
  64. 0x00,
  65. 0x01, /* __u8 bNumInterfaces; */
  66. 0x01, /* __u8 bConfigurationValue; */
  67. 0x00, /* __u8 iConfiguration; */
  68. 0x40, /* __u8 bmAttributes;
  69. Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
  70. 0x00, /* __u8 MaxPower; */
  71. /* interface */
  72. 0x09, /* __u8 if_bLength; */
  73. 0x04, /* __u8 if_bDescriptorType; Interface */
  74. 0x00, /* __u8 if_bInterfaceNumber; */
  75. 0x00, /* __u8 if_bAlternateSetting; */
  76. 0x01, /* __u8 if_bNumEndpoints; */
  77. 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
  78. 0x00, /* __u8 if_bInterfaceSubClass; */
  79. 0x00, /* __u8 if_bInterfaceProtocol; */
  80. 0x00, /* __u8 if_iInterface; */
  81. /* endpoint */
  82. 0x07, /* __u8 ep_bLength; */
  83. 0x05, /* __u8 ep_bDescriptorType; Endpoint */
  84. 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
  85. 0x03, /* __u8 ep_bmAttributes; Interrupt */
  86. 0x00, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
  87. 0x02,
  88. 0xff /* __u8 ep_bInterval; 255 ms */
  89. };
  90. static const unsigned char root_hub_str_index0[] = {
  91. 0x04, /* __u8 bLength; */
  92. 0x03, /* __u8 bDescriptorType; String-descriptor */
  93. 0x09, /* __u8 lang ID */
  94. 0x04, /* __u8 lang ID */
  95. };
  96. static const unsigned char root_hub_str_index1[] = {
  97. 0x1c, /* __u8 bLength; */
  98. 0x03, /* __u8 bDescriptorType; String-descriptor */
  99. 'M', /* __u8 Unicode */
  100. 0, /* __u8 Unicode */
  101. 'U', /* __u8 Unicode */
  102. 0, /* __u8 Unicode */
  103. 'S', /* __u8 Unicode */
  104. 0, /* __u8 Unicode */
  105. 'B', /* __u8 Unicode */
  106. 0, /* __u8 Unicode */
  107. ' ', /* __u8 Unicode */
  108. 0, /* __u8 Unicode */
  109. 'R', /* __u8 Unicode */
  110. 0, /* __u8 Unicode */
  111. 'o', /* __u8 Unicode */
  112. 0, /* __u8 Unicode */
  113. 'o', /* __u8 Unicode */
  114. 0, /* __u8 Unicode */
  115. 't', /* __u8 Unicode */
  116. 0, /* __u8 Unicode */
  117. ' ', /* __u8 Unicode */
  118. 0, /* __u8 Unicode */
  119. 'H', /* __u8 Unicode */
  120. 0, /* __u8 Unicode */
  121. 'u', /* __u8 Unicode */
  122. 0, /* __u8 Unicode */
  123. 'b', /* __u8 Unicode */
  124. 0, /* __u8 Unicode */
  125. };
  126. #endif
  127. /*
  128. * This function writes the data toggle value.
  129. */
  130. static void write_toggle(struct usb_device *dev, u8 ep, u8 dir_out)
  131. {
  132. u16 toggle = usb_gettoggle(dev, ep, dir_out);
  133. u16 csr;
  134. if (dir_out) {
  135. csr = readw(&musbr->txcsr);
  136. if (!toggle) {
  137. if (csr & MUSB_TXCSR_MODE)
  138. csr = MUSB_TXCSR_CLRDATATOG;
  139. else
  140. csr = 0;
  141. writew(csr, &musbr->txcsr);
  142. } else {
  143. csr |= MUSB_TXCSR_H_WR_DATATOGGLE;
  144. writew(csr, &musbr->txcsr);
  145. csr |= (toggle << MUSB_TXCSR_H_DATATOGGLE_SHIFT);
  146. writew(csr, &musbr->txcsr);
  147. }
  148. } else {
  149. if (!toggle) {
  150. csr = readw(&musbr->txcsr);
  151. if (csr & MUSB_TXCSR_MODE)
  152. csr = MUSB_RXCSR_CLRDATATOG;
  153. else
  154. csr = 0;
  155. writew(csr, &musbr->rxcsr);
  156. } else {
  157. csr = readw(&musbr->rxcsr);
  158. csr |= MUSB_RXCSR_H_WR_DATATOGGLE;
  159. writew(csr, &musbr->rxcsr);
  160. csr |= (toggle << MUSB_S_RXCSR_H_DATATOGGLE);
  161. writew(csr, &musbr->rxcsr);
  162. }
  163. }
  164. }
  165. /*
  166. * This function checks if RxStall has occured on the endpoint. If a RxStall
  167. * has occured, the RxStall is cleared and 1 is returned. If RxStall has
  168. * not occured, 0 is returned.
  169. */
  170. static u8 check_stall(u8 ep, u8 dir_out)
  171. {
  172. u16 csr;
  173. /* For endpoint 0 */
  174. if (!ep) {
  175. csr = readw(&musbr->txcsr);
  176. if (csr & MUSB_CSR0_H_RXSTALL) {
  177. csr &= ~MUSB_CSR0_H_RXSTALL;
  178. writew(csr, &musbr->txcsr);
  179. return 1;
  180. }
  181. } else { /* For non-ep0 */
  182. if (dir_out) { /* is it tx ep */
  183. csr = readw(&musbr->txcsr);
  184. if (csr & MUSB_TXCSR_H_RXSTALL) {
  185. csr &= ~MUSB_TXCSR_H_RXSTALL;
  186. writew(csr, &musbr->txcsr);
  187. return 1;
  188. }
  189. } else { /* is it rx ep */
  190. csr = readw(&musbr->rxcsr);
  191. if (csr & MUSB_RXCSR_H_RXSTALL) {
  192. csr &= ~MUSB_RXCSR_H_RXSTALL;
  193. writew(csr, &musbr->rxcsr);
  194. return 1;
  195. }
  196. }
  197. }
  198. return 0;
  199. }
  200. /*
  201. * waits until ep0 is ready. Returns 0 if ep is ready, -1 for timeout
  202. * error and -2 for stall.
  203. */
  204. static int wait_until_ep0_ready(struct usb_device *dev, u32 bit_mask)
  205. {
  206. u16 csr;
  207. int result = 1;
  208. int timeout = CONFIG_MUSB_TIMEOUT;
  209. while (result > 0) {
  210. csr = readw(&musbr->txcsr);
  211. if (csr & MUSB_CSR0_H_ERROR) {
  212. csr &= ~MUSB_CSR0_H_ERROR;
  213. writew(csr, &musbr->txcsr);
  214. dev->status = USB_ST_CRC_ERR;
  215. result = -1;
  216. break;
  217. }
  218. switch (bit_mask) {
  219. case MUSB_CSR0_TXPKTRDY:
  220. if (!(csr & MUSB_CSR0_TXPKTRDY)) {
  221. if (check_stall(MUSB_CONTROL_EP, 0)) {
  222. dev->status = USB_ST_STALLED;
  223. result = -2;
  224. } else
  225. result = 0;
  226. }
  227. break;
  228. case MUSB_CSR0_RXPKTRDY:
  229. if (check_stall(MUSB_CONTROL_EP, 0)) {
  230. dev->status = USB_ST_STALLED;
  231. result = -2;
  232. } else
  233. if (csr & MUSB_CSR0_RXPKTRDY)
  234. result = 0;
  235. break;
  236. case MUSB_CSR0_H_REQPKT:
  237. if (!(csr & MUSB_CSR0_H_REQPKT)) {
  238. if (check_stall(MUSB_CONTROL_EP, 0)) {
  239. dev->status = USB_ST_STALLED;
  240. result = -2;
  241. } else
  242. result = 0;
  243. }
  244. break;
  245. }
  246. /* Check the timeout */
  247. if (--timeout)
  248. udelay(1);
  249. else {
  250. dev->status = USB_ST_CRC_ERR;
  251. result = -1;
  252. break;
  253. }
  254. }
  255. return result;
  256. }
  257. /*
  258. * waits until tx ep is ready. Returns 1 when ep is ready and 0 on error.
  259. */
  260. static u8 wait_until_txep_ready(struct usb_device *dev, u8 ep)
  261. {
  262. u16 csr;
  263. int timeout = CONFIG_MUSB_TIMEOUT;
  264. do {
  265. if (check_stall(ep, 1)) {
  266. dev->status = USB_ST_STALLED;
  267. return 0;
  268. }
  269. csr = readw(&musbr->txcsr);
  270. if (csr & MUSB_TXCSR_H_ERROR) {
  271. dev->status = USB_ST_CRC_ERR;
  272. return 0;
  273. }
  274. /* Check the timeout */
  275. if (--timeout)
  276. udelay(1);
  277. else {
  278. dev->status = USB_ST_CRC_ERR;
  279. return -1;
  280. }
  281. } while (csr & MUSB_TXCSR_TXPKTRDY);
  282. return 1;
  283. }
  284. /*
  285. * waits until rx ep is ready. Returns 1 when ep is ready and 0 on error.
  286. */
  287. static u8 wait_until_rxep_ready(struct usb_device *dev, u8 ep)
  288. {
  289. u16 csr;
  290. int timeout = CONFIG_MUSB_TIMEOUT;
  291. do {
  292. if (check_stall(ep, 0)) {
  293. dev->status = USB_ST_STALLED;
  294. return 0;
  295. }
  296. csr = readw(&musbr->rxcsr);
  297. if (csr & MUSB_RXCSR_H_ERROR) {
  298. dev->status = USB_ST_CRC_ERR;
  299. return 0;
  300. }
  301. /* Check the timeout */
  302. if (--timeout)
  303. udelay(1);
  304. else {
  305. dev->status = USB_ST_CRC_ERR;
  306. return -1;
  307. }
  308. } while (!(csr & MUSB_RXCSR_RXPKTRDY));
  309. return 1;
  310. }
  311. /*
  312. * This function performs the setup phase of the control transfer
  313. */
  314. static int ctrlreq_setup_phase(struct usb_device *dev, struct devrequest *setup)
  315. {
  316. int result;
  317. u16 csr;
  318. /* write the control request to ep0 fifo */
  319. write_fifo(MUSB_CONTROL_EP, sizeof(struct devrequest), (void *)setup);
  320. /* enable transfer of setup packet */
  321. csr = readw(&musbr->txcsr);
  322. csr |= (MUSB_CSR0_TXPKTRDY|MUSB_CSR0_H_SETUPPKT);
  323. writew(csr, &musbr->txcsr);
  324. /* wait until the setup packet is transmitted */
  325. result = wait_until_ep0_ready(dev, MUSB_CSR0_TXPKTRDY);
  326. dev->act_len = 0;
  327. return result;
  328. }
  329. /*
  330. * This function handles the control transfer in data phase
  331. */
  332. static int ctrlreq_in_data_phase(struct usb_device *dev, u32 len, void *buffer)
  333. {
  334. u16 csr;
  335. u32 rxlen = 0;
  336. u32 nextlen = 0;
  337. u8 maxpktsize = (1 << dev->maxpacketsize) * 8;
  338. u8 *rxbuff = (u8 *)buffer;
  339. u8 rxedlength;
  340. int result;
  341. while (rxlen < len) {
  342. /* Determine the next read length */
  343. nextlen = ((len-rxlen) > maxpktsize) ? maxpktsize : (len-rxlen);
  344. /* Set the ReqPkt bit */
  345. csr = readw(&musbr->txcsr);
  346. writew(csr | MUSB_CSR0_H_REQPKT, &musbr->txcsr);
  347. result = wait_until_ep0_ready(dev, MUSB_CSR0_RXPKTRDY);
  348. if (result < 0)
  349. return result;
  350. /* Actual number of bytes received by usb */
  351. rxedlength = readb(&musbr->rxcount);
  352. /* Read the data from the RxFIFO */
  353. read_fifo(MUSB_CONTROL_EP, rxedlength, &rxbuff[rxlen]);
  354. /* Clear the RxPktRdy Bit */
  355. csr = readw(&musbr->txcsr);
  356. csr &= ~MUSB_CSR0_RXPKTRDY;
  357. writew(csr, &musbr->txcsr);
  358. /* short packet? */
  359. if (rxedlength != nextlen) {
  360. dev->act_len += rxedlength;
  361. break;
  362. }
  363. rxlen += nextlen;
  364. dev->act_len = rxlen;
  365. }
  366. return 0;
  367. }
  368. /*
  369. * This function handles the control transfer out data phase
  370. */
  371. static int ctrlreq_out_data_phase(struct usb_device *dev, u32 len, void *buffer)
  372. {
  373. u16 csr;
  374. u32 txlen = 0;
  375. u32 nextlen = 0;
  376. u8 maxpktsize = (1 << dev->maxpacketsize) * 8;
  377. u8 *txbuff = (u8 *)buffer;
  378. int result = 0;
  379. while (txlen < len) {
  380. /* Determine the next write length */
  381. nextlen = ((len-txlen) > maxpktsize) ? maxpktsize : (len-txlen);
  382. /* Load the data to send in FIFO */
  383. write_fifo(MUSB_CONTROL_EP, txlen, &txbuff[txlen]);
  384. /* Set TXPKTRDY bit */
  385. csr = readw(&musbr->txcsr);
  386. writew(csr | MUSB_CSR0_H_DIS_PING | MUSB_CSR0_TXPKTRDY,
  387. &musbr->txcsr);
  388. result = wait_until_ep0_ready(dev, MUSB_CSR0_TXPKTRDY);
  389. if (result < 0)
  390. break;
  391. txlen += nextlen;
  392. dev->act_len = txlen;
  393. }
  394. return result;
  395. }
  396. /*
  397. * This function handles the control transfer out status phase
  398. */
  399. static int ctrlreq_out_status_phase(struct usb_device *dev)
  400. {
  401. u16 csr;
  402. int result;
  403. /* Set the StatusPkt bit */
  404. csr = readw(&musbr->txcsr);
  405. csr |= (MUSB_CSR0_H_DIS_PING | MUSB_CSR0_TXPKTRDY |
  406. MUSB_CSR0_H_STATUSPKT);
  407. writew(csr, &musbr->txcsr);
  408. /* Wait until TXPKTRDY bit is cleared */
  409. result = wait_until_ep0_ready(dev, MUSB_CSR0_TXPKTRDY);
  410. return result;
  411. }
  412. /*
  413. * This function handles the control transfer in status phase
  414. */
  415. static int ctrlreq_in_status_phase(struct usb_device *dev)
  416. {
  417. u16 csr;
  418. int result;
  419. /* Set the StatusPkt bit and ReqPkt bit */
  420. csr = MUSB_CSR0_H_DIS_PING | MUSB_CSR0_H_REQPKT | MUSB_CSR0_H_STATUSPKT;
  421. writew(csr, &musbr->txcsr);
  422. result = wait_until_ep0_ready(dev, MUSB_CSR0_H_REQPKT);
  423. /* clear StatusPkt bit and RxPktRdy bit */
  424. csr = readw(&musbr->txcsr);
  425. csr &= ~(MUSB_CSR0_RXPKTRDY | MUSB_CSR0_H_STATUSPKT);
  426. writew(csr, &musbr->txcsr);
  427. return result;
  428. }
  429. /*
  430. * determines the speed of the device (High/Full/Slow)
  431. */
  432. static u8 get_dev_speed(struct usb_device *dev)
  433. {
  434. return (dev->speed & USB_SPEED_HIGH) ? MUSB_TYPE_SPEED_HIGH :
  435. ((dev->speed & USB_SPEED_LOW) ? MUSB_TYPE_SPEED_LOW :
  436. MUSB_TYPE_SPEED_FULL);
  437. }
  438. /*
  439. * configure the hub address and the port address.
  440. */
  441. static void config_hub_port(struct usb_device *dev, u8 ep)
  442. {
  443. u8 chid;
  444. u8 hub;
  445. /* Find out the nearest parent which is high speed */
  446. while (dev->parent->parent != NULL)
  447. if (get_dev_speed(dev->parent) != MUSB_TYPE_SPEED_HIGH)
  448. dev = dev->parent;
  449. else
  450. break;
  451. /* determine the port address at that hub */
  452. hub = dev->parent->devnum;
  453. for (chid = 0; chid < USB_MAXCHILDREN; chid++)
  454. if (dev->parent->children[chid] == dev)
  455. break;
  456. #ifndef MUSB_NO_MULTIPOINT
  457. /* configure the hub address and the port address */
  458. writeb(hub, &musbr->tar[ep].txhubaddr);
  459. writeb((chid + 1), &musbr->tar[ep].txhubport);
  460. writeb(hub, &musbr->tar[ep].rxhubaddr);
  461. writeb((chid + 1), &musbr->tar[ep].rxhubport);
  462. #endif
  463. }
  464. #ifdef MUSB_NO_MULTIPOINT
  465. static void musb_port_reset(int do_reset)
  466. {
  467. u8 power = readb(&musbr->power);
  468. if (do_reset) {
  469. power &= 0xf0;
  470. writeb(power | MUSB_POWER_RESET, &musbr->power);
  471. port_status |= USB_PORT_STAT_RESET;
  472. port_status &= ~USB_PORT_STAT_ENABLE;
  473. udelay(30000);
  474. } else {
  475. writeb(power & ~MUSB_POWER_RESET, &musbr->power);
  476. power = readb(&musbr->power);
  477. if (power & MUSB_POWER_HSMODE)
  478. port_status |= USB_PORT_STAT_HIGH_SPEED;
  479. port_status &= ~(USB_PORT_STAT_RESET | (USB_PORT_STAT_C_CONNECTION << 16));
  480. port_status |= USB_PORT_STAT_ENABLE
  481. | (USB_PORT_STAT_C_RESET << 16)
  482. | (USB_PORT_STAT_C_ENABLE << 16);
  483. }
  484. }
  485. /*
  486. * root hub control
  487. */
  488. static int musb_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
  489. void *buffer, int transfer_len,
  490. struct devrequest *cmd)
  491. {
  492. int leni = transfer_len;
  493. int len = 0;
  494. int stat = 0;
  495. u32 datab[4];
  496. const u8 *data_buf = (u8 *) datab;
  497. u16 bmRType_bReq;
  498. u16 wValue;
  499. u16 wIndex;
  500. u16 wLength;
  501. u16 int_usb;
  502. if ((pipe & PIPE_INTERRUPT) == PIPE_INTERRUPT) {
  503. debug("Root-Hub submit IRQ: NOT implemented\n");
  504. return 0;
  505. }
  506. bmRType_bReq = cmd->requesttype | (cmd->request << 8);
  507. wValue = swap_16(cmd->value);
  508. wIndex = swap_16(cmd->index);
  509. wLength = swap_16(cmd->length);
  510. debug("--- HUB ----------------------------------------\n");
  511. debug("submit rh urb, req=%x val=%#x index=%#x len=%d\n",
  512. bmRType_bReq, wValue, wIndex, wLength);
  513. debug("------------------------------------------------\n");
  514. switch (bmRType_bReq) {
  515. case RH_GET_STATUS:
  516. debug("RH_GET_STATUS\n");
  517. *(__u16 *) data_buf = swap_16(1);
  518. len = 2;
  519. break;
  520. case RH_GET_STATUS | RH_INTERFACE:
  521. debug("RH_GET_STATUS | RH_INTERFACE\n");
  522. *(__u16 *) data_buf = swap_16(0);
  523. len = 2;
  524. break;
  525. case RH_GET_STATUS | RH_ENDPOINT:
  526. debug("RH_GET_STATUS | RH_ENDPOINT\n");
  527. *(__u16 *) data_buf = swap_16(0);
  528. len = 2;
  529. break;
  530. case RH_GET_STATUS | RH_CLASS:
  531. debug("RH_GET_STATUS | RH_CLASS\n");
  532. *(__u32 *) data_buf = swap_32(0);
  533. len = 4;
  534. break;
  535. case RH_GET_STATUS | RH_OTHER | RH_CLASS:
  536. debug("RH_GET_STATUS | RH_OTHER | RH_CLASS\n");
  537. int_usb = readw(&musbr->intrusb);
  538. if (int_usb & MUSB_INTR_CONNECT) {
  539. port_status |= USB_PORT_STAT_CONNECTION
  540. | (USB_PORT_STAT_C_CONNECTION << 16);
  541. port_status |= USB_PORT_STAT_HIGH_SPEED
  542. | USB_PORT_STAT_ENABLE;
  543. }
  544. if (port_status & USB_PORT_STAT_RESET)
  545. musb_port_reset(0);
  546. *(__u32 *) data_buf = swap_32(port_status);
  547. len = 4;
  548. break;
  549. case RH_CLEAR_FEATURE | RH_ENDPOINT:
  550. debug("RH_CLEAR_FEATURE | RH_ENDPOINT\n");
  551. switch (wValue) {
  552. case RH_ENDPOINT_STALL:
  553. debug("C_HUB_ENDPOINT_STALL\n");
  554. len = 0;
  555. break;
  556. }
  557. port_status &= ~(1 << wValue);
  558. break;
  559. case RH_CLEAR_FEATURE | RH_CLASS:
  560. debug("RH_CLEAR_FEATURE | RH_CLASS\n");
  561. switch (wValue) {
  562. case RH_C_HUB_LOCAL_POWER:
  563. debug("C_HUB_LOCAL_POWER\n");
  564. len = 0;
  565. break;
  566. case RH_C_HUB_OVER_CURRENT:
  567. debug("C_HUB_OVER_CURRENT\n");
  568. len = 0;
  569. break;
  570. }
  571. port_status &= ~(1 << wValue);
  572. break;
  573. case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
  574. debug("RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS\n");
  575. switch (wValue) {
  576. case RH_PORT_ENABLE:
  577. len = 0;
  578. break;
  579. case RH_PORT_SUSPEND:
  580. len = 0;
  581. break;
  582. case RH_PORT_POWER:
  583. len = 0;
  584. break;
  585. case RH_C_PORT_CONNECTION:
  586. len = 0;
  587. break;
  588. case RH_C_PORT_ENABLE:
  589. len = 0;
  590. break;
  591. case RH_C_PORT_SUSPEND:
  592. len = 0;
  593. break;
  594. case RH_C_PORT_OVER_CURRENT:
  595. len = 0;
  596. break;
  597. case RH_C_PORT_RESET:
  598. len = 0;
  599. break;
  600. default:
  601. debug("invalid wValue\n");
  602. stat = USB_ST_STALLED;
  603. }
  604. port_status &= ~(1 << wValue);
  605. break;
  606. case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
  607. debug("RH_SET_FEATURE | RH_OTHER | RH_CLASS\n");
  608. switch (wValue) {
  609. case RH_PORT_SUSPEND:
  610. len = 0;
  611. break;
  612. case RH_PORT_RESET:
  613. musb_port_reset(1);
  614. len = 0;
  615. break;
  616. case RH_PORT_POWER:
  617. len = 0;
  618. break;
  619. case RH_PORT_ENABLE:
  620. len = 0;
  621. break;
  622. default:
  623. debug("invalid wValue\n");
  624. stat = USB_ST_STALLED;
  625. }
  626. port_status |= 1 << wValue;
  627. break;
  628. case RH_SET_ADDRESS:
  629. debug("RH_SET_ADDRESS\n");
  630. rh_devnum = wValue;
  631. len = 0;
  632. break;
  633. case RH_GET_DESCRIPTOR:
  634. debug("RH_GET_DESCRIPTOR: %x, %d\n", wValue, wLength);
  635. switch (wValue) {
  636. case (USB_DT_DEVICE << 8): /* device descriptor */
  637. len = min_t(unsigned int,
  638. leni, min_t(unsigned int,
  639. sizeof(root_hub_dev_des),
  640. wLength));
  641. data_buf = root_hub_dev_des;
  642. break;
  643. case (USB_DT_CONFIG << 8): /* configuration descriptor */
  644. len = min_t(unsigned int,
  645. leni, min_t(unsigned int,
  646. sizeof(root_hub_config_des),
  647. wLength));
  648. data_buf = root_hub_config_des;
  649. break;
  650. case ((USB_DT_STRING << 8) | 0x00): /* string 0 descriptors */
  651. len = min_t(unsigned int,
  652. leni, min_t(unsigned int,
  653. sizeof(root_hub_str_index0),
  654. wLength));
  655. data_buf = root_hub_str_index0;
  656. break;
  657. case ((USB_DT_STRING << 8) | 0x01): /* string 1 descriptors */
  658. len = min_t(unsigned int,
  659. leni, min_t(unsigned int,
  660. sizeof(root_hub_str_index1),
  661. wLength));
  662. data_buf = root_hub_str_index1;
  663. break;
  664. default:
  665. debug("invalid wValue\n");
  666. stat = USB_ST_STALLED;
  667. }
  668. break;
  669. case RH_GET_DESCRIPTOR | RH_CLASS: {
  670. u8 *_data_buf = (u8 *) datab;
  671. debug("RH_GET_DESCRIPTOR | RH_CLASS\n");
  672. _data_buf[0] = 0x09; /* min length; */
  673. _data_buf[1] = 0x29;
  674. _data_buf[2] = 0x1; /* 1 port */
  675. _data_buf[3] = 0x01; /* per-port power switching */
  676. _data_buf[3] |= 0x10; /* no overcurrent reporting */
  677. /* Corresponds to data_buf[4-7] */
  678. _data_buf[4] = 0;
  679. _data_buf[5] = 5;
  680. _data_buf[6] = 0;
  681. _data_buf[7] = 0x02;
  682. _data_buf[8] = 0xff;
  683. len = min_t(unsigned int, leni,
  684. min_t(unsigned int, data_buf[0], wLength));
  685. break;
  686. }
  687. case RH_GET_CONFIGURATION:
  688. debug("RH_GET_CONFIGURATION\n");
  689. *(__u8 *) data_buf = 0x01;
  690. len = 1;
  691. break;
  692. case RH_SET_CONFIGURATION:
  693. debug("RH_SET_CONFIGURATION\n");
  694. len = 0;
  695. break;
  696. default:
  697. debug("*** *** *** unsupported root hub command *** *** ***\n");
  698. stat = USB_ST_STALLED;
  699. }
  700. len = min_t(int, len, leni);
  701. if (buffer != data_buf)
  702. memcpy(buffer, data_buf, len);
  703. dev->act_len = len;
  704. dev->status = stat;
  705. debug("dev act_len %d, status %d\n", dev->act_len, dev->status);
  706. return stat;
  707. }
  708. static void musb_rh_init(void)
  709. {
  710. rh_devnum = 0;
  711. port_status = 0;
  712. }
  713. #else
  714. static void musb_rh_init(void) {}
  715. #endif
  716. /*
  717. * do a control transfer
  718. */
  719. int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  720. int len, struct devrequest *setup)
  721. {
  722. int devnum = usb_pipedevice(pipe);
  723. u16 csr;
  724. u8 devspeed;
  725. #ifdef MUSB_NO_MULTIPOINT
  726. /* Control message is for the HUB? */
  727. if (devnum == rh_devnum)
  728. return musb_submit_rh_msg(dev, pipe, buffer, len, setup);
  729. #endif
  730. /* select control endpoint */
  731. writeb(MUSB_CONTROL_EP, &musbr->index);
  732. csr = readw(&musbr->txcsr);
  733. #ifndef MUSB_NO_MULTIPOINT
  734. /* target addr and (for multipoint) hub addr/port */
  735. writeb(devnum, &musbr->tar[MUSB_CONTROL_EP].txfuncaddr);
  736. writeb(devnum, &musbr->tar[MUSB_CONTROL_EP].rxfuncaddr);
  737. #endif
  738. /* configure the hub address and the port number as required */
  739. devspeed = get_dev_speed(dev);
  740. if ((musb_ishighspeed()) && (dev->parent != NULL) &&
  741. (devspeed != MUSB_TYPE_SPEED_HIGH)) {
  742. config_hub_port(dev, MUSB_CONTROL_EP);
  743. writeb(devspeed << 6, &musbr->txtype);
  744. } else {
  745. writeb(musb_cfg.musb_speed << 6, &musbr->txtype);
  746. #ifndef MUSB_NO_MULTIPOINT
  747. writeb(0, &musbr->tar[MUSB_CONTROL_EP].txhubaddr);
  748. writeb(0, &musbr->tar[MUSB_CONTROL_EP].txhubport);
  749. writeb(0, &musbr->tar[MUSB_CONTROL_EP].rxhubaddr);
  750. writeb(0, &musbr->tar[MUSB_CONTROL_EP].rxhubport);
  751. #endif
  752. }
  753. /* Control transfer setup phase */
  754. if (ctrlreq_setup_phase(dev, setup) < 0)
  755. return 0;
  756. switch (setup->request) {
  757. case USB_REQ_GET_DESCRIPTOR:
  758. case USB_REQ_GET_CONFIGURATION:
  759. case USB_REQ_GET_INTERFACE:
  760. case USB_REQ_GET_STATUS:
  761. case USB_MSC_BBB_GET_MAX_LUN:
  762. /* control transfer in-data-phase */
  763. if (ctrlreq_in_data_phase(dev, len, buffer) < 0)
  764. return 0;
  765. /* control transfer out-status-phase */
  766. if (ctrlreq_out_status_phase(dev) < 0)
  767. return 0;
  768. break;
  769. case USB_REQ_SET_ADDRESS:
  770. case USB_REQ_SET_CONFIGURATION:
  771. case USB_REQ_SET_FEATURE:
  772. case USB_REQ_SET_INTERFACE:
  773. case USB_REQ_CLEAR_FEATURE:
  774. case USB_MSC_BBB_RESET:
  775. /* control transfer in status phase */
  776. if (ctrlreq_in_status_phase(dev) < 0)
  777. return 0;
  778. break;
  779. case USB_REQ_SET_DESCRIPTOR:
  780. /* control transfer out data phase */
  781. if (ctrlreq_out_data_phase(dev, len, buffer) < 0)
  782. return 0;
  783. /* control transfer in status phase */
  784. if (ctrlreq_in_status_phase(dev) < 0)
  785. return 0;
  786. break;
  787. default:
  788. /* unhandled control transfer */
  789. return -1;
  790. }
  791. dev->status = 0;
  792. dev->act_len = len;
  793. #ifdef MUSB_NO_MULTIPOINT
  794. /* Set device address to USB_FADDR register */
  795. if (setup->request == USB_REQ_SET_ADDRESS)
  796. writeb(dev->devnum, &musbr->faddr);
  797. #endif
  798. return len;
  799. }
  800. /*
  801. * do a bulk transfer
  802. */
  803. int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
  804. void *buffer, int len)
  805. {
  806. int dir_out = usb_pipeout(pipe);
  807. int ep = usb_pipeendpoint(pipe);
  808. #ifndef MUSB_NO_MULTIPOINT
  809. int devnum = usb_pipedevice(pipe);
  810. #endif
  811. u8 type;
  812. u16 csr;
  813. u32 txlen = 0;
  814. u32 nextlen = 0;
  815. u8 devspeed;
  816. /* select bulk endpoint */
  817. writeb(MUSB_BULK_EP, &musbr->index);
  818. #ifndef MUSB_NO_MULTIPOINT
  819. /* write the address of the device */
  820. if (dir_out)
  821. writeb(devnum, &musbr->tar[MUSB_BULK_EP].txfuncaddr);
  822. else
  823. writeb(devnum, &musbr->tar[MUSB_BULK_EP].rxfuncaddr);
  824. #endif
  825. /* configure the hub address and the port number as required */
  826. devspeed = get_dev_speed(dev);
  827. if ((musb_ishighspeed()) && (dev->parent != NULL) &&
  828. (devspeed != MUSB_TYPE_SPEED_HIGH)) {
  829. /*
  830. * MUSB is in high speed and the destination device is full
  831. * speed device. So configure the hub address and port
  832. * address registers.
  833. */
  834. config_hub_port(dev, MUSB_BULK_EP);
  835. } else {
  836. #ifndef MUSB_NO_MULTIPOINT
  837. if (dir_out) {
  838. writeb(0, &musbr->tar[MUSB_BULK_EP].txhubaddr);
  839. writeb(0, &musbr->tar[MUSB_BULK_EP].txhubport);
  840. } else {
  841. writeb(0, &musbr->tar[MUSB_BULK_EP].rxhubaddr);
  842. writeb(0, &musbr->tar[MUSB_BULK_EP].rxhubport);
  843. }
  844. #endif
  845. devspeed = musb_cfg.musb_speed;
  846. }
  847. /* Write the saved toggle bit value */
  848. write_toggle(dev, ep, dir_out);
  849. if (dir_out) { /* bulk-out transfer */
  850. /* Program the TxType register */
  851. type = (devspeed << MUSB_TYPE_SPEED_SHIFT) |
  852. (MUSB_TYPE_PROTO_BULK << MUSB_TYPE_PROTO_SHIFT) |
  853. (ep & MUSB_TYPE_REMOTE_END);
  854. writeb(type, &musbr->txtype);
  855. /* Write maximum packet size to the TxMaxp register */
  856. writew(dev->epmaxpacketout[ep], &musbr->txmaxp);
  857. while (txlen < len) {
  858. nextlen = ((len-txlen) < dev->epmaxpacketout[ep]) ?
  859. (len-txlen) : dev->epmaxpacketout[ep];
  860. #ifdef CONFIG_USB_BLACKFIN
  861. /* Set the transfer data size */
  862. writew(nextlen, &musbr->txcount);
  863. #endif
  864. /* Write the data to the FIFO */
  865. write_fifo(MUSB_BULK_EP, nextlen,
  866. (void *)(((u8 *)buffer) + txlen));
  867. /* Set the TxPktRdy bit */
  868. csr = readw(&musbr->txcsr);
  869. writew(csr | MUSB_TXCSR_TXPKTRDY, &musbr->txcsr);
  870. /* Wait until the TxPktRdy bit is cleared */
  871. if (!wait_until_txep_ready(dev, MUSB_BULK_EP)) {
  872. readw(&musbr->txcsr);
  873. usb_settoggle(dev, ep, dir_out,
  874. (csr >> MUSB_TXCSR_H_DATATOGGLE_SHIFT) & 1);
  875. dev->act_len = txlen;
  876. return 0;
  877. }
  878. txlen += nextlen;
  879. }
  880. /* Keep a copy of the data toggle bit */
  881. csr = readw(&musbr->txcsr);
  882. usb_settoggle(dev, ep, dir_out,
  883. (csr >> MUSB_TXCSR_H_DATATOGGLE_SHIFT) & 1);
  884. } else { /* bulk-in transfer */
  885. /* Write the saved toggle bit value */
  886. write_toggle(dev, ep, dir_out);
  887. /* Program the RxType register */
  888. type = (devspeed << MUSB_TYPE_SPEED_SHIFT) |
  889. (MUSB_TYPE_PROTO_BULK << MUSB_TYPE_PROTO_SHIFT) |
  890. (ep & MUSB_TYPE_REMOTE_END);
  891. writeb(type, &musbr->rxtype);
  892. /* Write the maximum packet size to the RxMaxp register */
  893. writew(dev->epmaxpacketin[ep], &musbr->rxmaxp);
  894. while (txlen < len) {
  895. nextlen = ((len-txlen) < dev->epmaxpacketin[ep]) ?
  896. (len-txlen) : dev->epmaxpacketin[ep];
  897. /* Set the ReqPkt bit */
  898. csr = readw(&musbr->rxcsr);
  899. writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
  900. /* Wait until the RxPktRdy bit is set */
  901. if (!wait_until_rxep_ready(dev, MUSB_BULK_EP)) {
  902. csr = readw(&musbr->rxcsr);
  903. usb_settoggle(dev, ep, dir_out,
  904. (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
  905. csr &= ~MUSB_RXCSR_RXPKTRDY;
  906. writew(csr, &musbr->rxcsr);
  907. dev->act_len = txlen;
  908. return 0;
  909. }
  910. /* Read the data from the FIFO */
  911. read_fifo(MUSB_BULK_EP, nextlen,
  912. (void *)(((u8 *)buffer) + txlen));
  913. /* Clear the RxPktRdy bit */
  914. csr = readw(&musbr->rxcsr);
  915. csr &= ~MUSB_RXCSR_RXPKTRDY;
  916. writew(csr, &musbr->rxcsr);
  917. txlen += nextlen;
  918. }
  919. /* Keep a copy of the data toggle bit */
  920. csr = readw(&musbr->rxcsr);
  921. usb_settoggle(dev, ep, dir_out,
  922. (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
  923. }
  924. /* bulk transfer is complete */
  925. dev->status = 0;
  926. dev->act_len = len;
  927. return 0;
  928. }
  929. /*
  930. * This function initializes the usb controller module.
  931. */
  932. int usb_lowlevel_init(void)
  933. {
  934. u8 power;
  935. u32 timeout;
  936. musb_rh_init();
  937. if (musb_platform_init() == -1)
  938. return -1;
  939. /* Configure all the endpoint FIFO's and start usb controller */
  940. musbr = musb_cfg.regs;
  941. musb_configure_ep(&epinfo[0],
  942. sizeof(epinfo) / sizeof(struct musb_epinfo));
  943. musb_start();
  944. /*
  945. * Wait until musb is enabled in host mode with a timeout. There
  946. * should be a usb device connected.
  947. */
  948. timeout = musb_cfg.timeout;
  949. while (timeout--)
  950. if (readb(&musbr->devctl) & MUSB_DEVCTL_HM)
  951. break;
  952. /* if musb core is not in host mode, then return */
  953. if (!timeout)
  954. return -1;
  955. /* start usb bus reset */
  956. power = readb(&musbr->power);
  957. writeb(power | MUSB_POWER_RESET, &musbr->power);
  958. /* After initiating a usb reset, wait for about 20ms to 30ms */
  959. udelay(30000);
  960. /* stop usb bus reset */
  961. power = readb(&musbr->power);
  962. power &= ~MUSB_POWER_RESET;
  963. writeb(power, &musbr->power);
  964. /* Determine if the connected device is a high/full/low speed device */
  965. musb_cfg.musb_speed = (readb(&musbr->power) & MUSB_POWER_HSMODE) ?
  966. MUSB_TYPE_SPEED_HIGH :
  967. ((readb(&musbr->devctl) & MUSB_DEVCTL_FSDEV) ?
  968. MUSB_TYPE_SPEED_FULL : MUSB_TYPE_SPEED_LOW);
  969. return 0;
  970. }
  971. /*
  972. * This function stops the operation of the davinci usb module.
  973. */
  974. int usb_lowlevel_stop(void)
  975. {
  976. /* Reset the USB module */
  977. musb_platform_deinit();
  978. writeb(0, &musbr->devctl);
  979. return 0;
  980. }
  981. /*
  982. * This function supports usb interrupt transfers. Currently, usb interrupt
  983. * transfers are not supported.
  984. */
  985. int submit_int_msg(struct usb_device *dev, unsigned long pipe,
  986. void *buffer, int len, int interval)
  987. {
  988. int dir_out = usb_pipeout(pipe);
  989. int ep = usb_pipeendpoint(pipe);
  990. #ifndef MUSB_NO_MULTIPOINT
  991. int devnum = usb_pipedevice(pipe);
  992. #endif
  993. u8 type;
  994. u16 csr;
  995. u32 txlen = 0;
  996. u32 nextlen = 0;
  997. u8 devspeed;
  998. /* select interrupt endpoint */
  999. writeb(MUSB_INTR_EP, &musbr->index);
  1000. #ifndef MUSB_NO_MULTIPOINT
  1001. /* write the address of the device */
  1002. if (dir_out)
  1003. writeb(devnum, &musbr->tar[MUSB_INTR_EP].txfuncaddr);
  1004. else
  1005. writeb(devnum, &musbr->tar[MUSB_INTR_EP].rxfuncaddr);
  1006. #endif
  1007. /* configure the hub address and the port number as required */
  1008. devspeed = get_dev_speed(dev);
  1009. if ((musb_ishighspeed()) && (dev->parent != NULL) &&
  1010. (devspeed != MUSB_TYPE_SPEED_HIGH)) {
  1011. /*
  1012. * MUSB is in high speed and the destination device is full
  1013. * speed device. So configure the hub address and port
  1014. * address registers.
  1015. */
  1016. config_hub_port(dev, MUSB_INTR_EP);
  1017. } else {
  1018. #ifndef MUSB_NO_MULTIPOINT
  1019. if (dir_out) {
  1020. writeb(0, &musbr->tar[MUSB_INTR_EP].txhubaddr);
  1021. writeb(0, &musbr->tar[MUSB_INTR_EP].txhubport);
  1022. } else {
  1023. writeb(0, &musbr->tar[MUSB_INTR_EP].rxhubaddr);
  1024. writeb(0, &musbr->tar[MUSB_INTR_EP].rxhubport);
  1025. }
  1026. #endif
  1027. devspeed = musb_cfg.musb_speed;
  1028. }
  1029. /* Write the saved toggle bit value */
  1030. write_toggle(dev, ep, dir_out);
  1031. if (!dir_out) { /* intrrupt-in transfer */
  1032. /* Write the saved toggle bit value */
  1033. write_toggle(dev, ep, dir_out);
  1034. writeb(interval, &musbr->rxinterval);
  1035. /* Program the RxType register */
  1036. type = (devspeed << MUSB_TYPE_SPEED_SHIFT) |
  1037. (MUSB_TYPE_PROTO_INTR << MUSB_TYPE_PROTO_SHIFT) |
  1038. (ep & MUSB_TYPE_REMOTE_END);
  1039. writeb(type, &musbr->rxtype);
  1040. /* Write the maximum packet size to the RxMaxp register */
  1041. writew(dev->epmaxpacketin[ep], &musbr->rxmaxp);
  1042. while (txlen < len) {
  1043. nextlen = ((len-txlen) < dev->epmaxpacketin[ep]) ?
  1044. (len-txlen) : dev->epmaxpacketin[ep];
  1045. /* Set the ReqPkt bit */
  1046. csr = readw(&musbr->rxcsr);
  1047. writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
  1048. /* Wait until the RxPktRdy bit is set */
  1049. if (!wait_until_rxep_ready(dev, MUSB_INTR_EP)) {
  1050. csr = readw(&musbr->rxcsr);
  1051. usb_settoggle(dev, ep, dir_out,
  1052. (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
  1053. csr &= ~MUSB_RXCSR_RXPKTRDY;
  1054. writew(csr, &musbr->rxcsr);
  1055. dev->act_len = txlen;
  1056. return 0;
  1057. }
  1058. /* Read the data from the FIFO */
  1059. read_fifo(MUSB_INTR_EP, nextlen,
  1060. (void *)(((u8 *)buffer) + txlen));
  1061. /* Clear the RxPktRdy bit */
  1062. csr = readw(&musbr->rxcsr);
  1063. csr &= ~MUSB_RXCSR_RXPKTRDY;
  1064. writew(csr, &musbr->rxcsr);
  1065. txlen += nextlen;
  1066. }
  1067. /* Keep a copy of the data toggle bit */
  1068. csr = readw(&musbr->rxcsr);
  1069. usb_settoggle(dev, ep, dir_out,
  1070. (csr >> MUSB_S_RXCSR_H_DATATOGGLE) & 1);
  1071. }
  1072. /* interrupt transfer is complete */
  1073. dev->irq_status = 0;
  1074. dev->irq_act_len = len;
  1075. dev->irq_handle(dev);
  1076. dev->status = 0;
  1077. dev->act_len = len;
  1078. return 0;
  1079. }
  1080. #ifdef CONFIG_SYS_USB_EVENT_POLL
  1081. /*
  1082. * This function polls for USB keyboard data.
  1083. */
  1084. void usb_event_poll()
  1085. {
  1086. struct stdio_dev *dev;
  1087. struct usb_device *usb_kbd_dev;
  1088. struct usb_interface *iface;
  1089. struct usb_endpoint_descriptor *ep;
  1090. int pipe;
  1091. int maxp;
  1092. /* Get the pointer to USB Keyboard device pointer */
  1093. dev = stdio_get_by_name("usbkbd");
  1094. usb_kbd_dev = (struct usb_device *)dev->priv;
  1095. iface = &usb_kbd_dev->config.if_desc[0];
  1096. ep = &iface->ep_desc[0];
  1097. pipe = usb_rcvintpipe(usb_kbd_dev, ep->bEndpointAddress);
  1098. /* Submit a interrupt transfer request */
  1099. maxp = usb_maxpacket(usb_kbd_dev, pipe);
  1100. usb_submit_int_msg(usb_kbd_dev, pipe, &new[0],
  1101. maxp > 8 ? 8 : maxp, ep->bInterval);
  1102. }
  1103. #endif /* CONFIG_SYS_USB_EVENT_POLL */