usbtty.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * (C) Copyright 2003
  3. * Gerry Hamel, geh@ti.com, Texas Instruments
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. #include <common.h>
  21. #ifdef CONFIG_USB_TTY
  22. #include <circbuf.h>
  23. #include <devices.h>
  24. #include "usbtty.h"
  25. #if 0
  26. #define TTYDBG(fmt,args...) serial_printf("[%s] %s %d: "fmt, __FILE__,__FUNCTION__,__LINE__,##args)
  27. #else
  28. #define TTYDBG(fmt,args...) do{}while(0)
  29. #endif
  30. #if 0
  31. #define TTYERR(fmt,args...) serial_printf("ERROR![%s] %s %d: "fmt, __FILE__,__FUNCTION__,__LINE__,##args)
  32. #else
  33. #define TTYERR(fmt,args...) do{}while(0)
  34. #endif
  35. /*
  36. * Buffers to hold input and output data
  37. */
  38. #define USBTTY_BUFFER_SIZE 256
  39. static circbuf_t usbtty_input;
  40. static circbuf_t usbtty_output;
  41. /*
  42. * Instance variables
  43. */
  44. static device_t usbttydev;
  45. static struct usb_device_instance device_instance[1];
  46. static struct usb_bus_instance bus_instance[1];
  47. static struct usb_configuration_instance config_instance[NUM_CONFIGS];
  48. static struct usb_interface_instance interface_instance[NUM_INTERFACES];
  49. static struct usb_alternate_instance alternate_instance[NUM_INTERFACES];
  50. static struct usb_endpoint_instance endpoint_instance[NUM_ENDPOINTS+1]; /* one extra for control endpoint */
  51. /*
  52. * Static allocation of urbs
  53. */
  54. #define RECV_ENDPOINT 1
  55. #define TX_ENDPOINT 2
  56. /*
  57. * Global flag
  58. */
  59. int usbtty_configured_flag = 0;
  60. /*
  61. * Descriptors
  62. */
  63. static u8 wstrLang[4] = {4,USB_DT_STRING,0x9,0x4};
  64. static u8 wstrManufacturer[2 + 2*(sizeof(CONFIG_USBD_MANUFACTURER)-1)];
  65. static u8 wstrProduct[2 + 2*(sizeof(CONFIG_USBD_PRODUCT_NAME)-1)];
  66. static u8 wstrSerial[2 + 2*(sizeof(CONFIG_USBD_SERIAL_NUMBER)-1)];
  67. static u8 wstrConfiguration[2 + 2*(sizeof(CONFIG_USBD_CONFIGURATION_STR)-1)];
  68. static u8 wstrInterface[2 + 2*(sizeof(CONFIG_USBD_INTERFACE_STR)-1)];
  69. static struct usb_string_descriptor *usbtty_string_table[] = {
  70. (struct usb_string_descriptor*)wstrLang,
  71. (struct usb_string_descriptor*)wstrManufacturer,
  72. (struct usb_string_descriptor*)wstrProduct,
  73. (struct usb_string_descriptor*)wstrSerial,
  74. (struct usb_string_descriptor*)wstrConfiguration,
  75. (struct usb_string_descriptor*)wstrInterface
  76. };
  77. extern struct usb_string_descriptor **usb_strings; /* defined and used by omap1510_ep0.c */
  78. static struct usb_device_descriptor device_descriptor = {
  79. bLength: sizeof(struct usb_device_descriptor),
  80. bDescriptorType: USB_DT_DEVICE,
  81. bcdUSB: USB_BCD_VERSION,
  82. bDeviceClass: USBTTY_DEVICE_CLASS,
  83. bDeviceSubClass: USBTTY_DEVICE_SUBCLASS,
  84. bDeviceProtocol: USBTTY_DEVICE_PROTOCOL,
  85. bMaxPacketSize0: EP0_MAX_PACKET_SIZE,
  86. idVendor: CONFIG_USBD_VENDORID,
  87. idProduct: CONFIG_USBD_PRODUCTID,
  88. bcdDevice: USBTTY_BCD_DEVICE,
  89. iManufacturer: STR_MANUFACTURER,
  90. iProduct: STR_PRODUCT,
  91. iSerialNumber: STR_SERIAL,
  92. bNumConfigurations: NUM_CONFIGS
  93. };
  94. static struct usb_configuration_descriptor config_descriptors[NUM_CONFIGS] = {
  95. {
  96. bLength: sizeof(struct usb_configuration_descriptor),
  97. bDescriptorType: USB_DT_CONFIG,
  98. wTotalLength: (sizeof(struct usb_configuration_descriptor)*NUM_CONFIGS) +
  99. (sizeof(struct usb_interface_descriptor)*NUM_INTERFACES) +
  100. (sizeof(struct usb_endpoint_descriptor)*NUM_ENDPOINTS),
  101. bNumInterfaces: NUM_INTERFACES,
  102. bConfigurationValue: 1,
  103. iConfiguration: STR_CONFIG,
  104. bmAttributes: BMATTRIBUTE_SELF_POWERED | BMATTRIBUTE_RESERVED,
  105. bMaxPower: USBTTY_MAXPOWER
  106. },
  107. };
  108. static struct usb_interface_descriptor interface_descriptors[NUM_INTERFACES] = {
  109. {
  110. bLength: sizeof(struct usb_interface_descriptor),
  111. bDescriptorType: USB_DT_INTERFACE,
  112. bInterfaceNumber: 0,
  113. bAlternateSetting: 0,
  114. bNumEndpoints: NUM_ENDPOINTS,
  115. bInterfaceClass: USBTTY_INTERFACE_CLASS,
  116. bInterfaceSubClass: USBTTY_INTERFACE_SUBCLASS,
  117. bInterfaceProtocol: USBTTY_INTERFACE_PROTOCOL,
  118. iInterface: STR_INTERFACE
  119. },
  120. };
  121. static struct usb_endpoint_descriptor ep_descriptors[NUM_ENDPOINTS] = {
  122. {
  123. bLength: sizeof(struct usb_endpoint_descriptor),
  124. bDescriptorType: USB_DT_ENDPOINT,
  125. bEndpointAddress: CONFIG_USBD_SERIAL_OUT_ENDPOINT | USB_DIR_OUT,
  126. bmAttributes: USB_ENDPOINT_XFER_BULK,
  127. wMaxPacketSize: CONFIG_USBD_SERIAL_OUT_PKTSIZE,
  128. bInterval: 0
  129. },
  130. {
  131. bLength: sizeof(struct usb_endpoint_descriptor),
  132. bDescriptorType: USB_DT_ENDPOINT,
  133. bEndpointAddress: CONFIG_USBD_SERIAL_IN_ENDPOINT | USB_DIR_IN,
  134. bmAttributes: USB_ENDPOINT_XFER_BULK,
  135. wMaxPacketSize: CONFIG_USBD_SERIAL_IN_PKTSIZE,
  136. bInterval: 0
  137. },
  138. {
  139. bLength: sizeof(struct usb_endpoint_descriptor),
  140. bDescriptorType: USB_DT_ENDPOINT,
  141. bEndpointAddress: CONFIG_USBD_SERIAL_INT_ENDPOINT | USB_DIR_IN,
  142. bmAttributes: USB_ENDPOINT_XFER_INT,
  143. wMaxPacketSize: CONFIG_USBD_SERIAL_INT_PKTSIZE,
  144. bInterval: 0
  145. },
  146. };
  147. static struct usb_endpoint_descriptor *ep_descriptor_ptrs[NUM_ENDPOINTS] = {
  148. &(ep_descriptors[0]),
  149. &(ep_descriptors[1]),
  150. &(ep_descriptors[2]),
  151. };
  152. /* utility function for converting char* to wide string used by USB */
  153. static void str2wide (char *str, u16 * wide)
  154. {
  155. int i;
  156. for (i = 0; i < strlen (str) && str[i]; i++)
  157. wide[i] = (u16) str[i];
  158. }
  159. /*
  160. * Prototypes
  161. */
  162. static void usbtty_init_strings (void);
  163. static void usbtty_init_instances (void);
  164. static void usbtty_init_endpoints (void);
  165. static void usbtty_event_handler (struct usb_device_instance *device,
  166. usb_device_event_t event, int data);
  167. static int usbtty_configured (void);
  168. static int write_buffer (circbuf_t * buf);
  169. static int fill_buffer (circbuf_t * buf);
  170. void usbtty_poll (void);
  171. static void pretend_interrupts (void);
  172. /*
  173. * Test whether a character is in the RX buffer
  174. */
  175. int usbtty_tstc (void)
  176. {
  177. usbtty_poll ();
  178. return (usbtty_input.size > 0);
  179. }
  180. /*
  181. * Read a single byte from the usb client port. Returns 1 on success, 0
  182. * otherwise. When the function is succesfull, the character read is
  183. * written into its argument c.
  184. */
  185. int usbtty_getc (void)
  186. {
  187. char c;
  188. while (usbtty_input.size <= 0) {
  189. usbtty_poll ();
  190. }
  191. buf_pop (&usbtty_input, &c, 1);
  192. return c;
  193. }
  194. /*
  195. * Output a single byte to the usb client port.
  196. */
  197. void usbtty_putc (const char c)
  198. {
  199. buf_push (&usbtty_output, &c, 1);
  200. /* If \n, also do \r */
  201. if (c == '\n')
  202. buf_push (&usbtty_output, "\r", 1);
  203. /* Poll at end to handle new data... */
  204. if ((usbtty_output.size + 2) >= usbtty_output.totalsize) {
  205. usbtty_poll ();
  206. }
  207. }
  208. /* usbtty_puts() helper function for finding the next '\n' in a string */
  209. static int next_nl_pos (const char *s)
  210. {
  211. int i;
  212. for (i = 0; s[i] != '\0'; i++) {
  213. if (s[i] == '\n')
  214. return i;
  215. }
  216. return i;
  217. }
  218. /*
  219. * Output a string to the usb client port.
  220. */
  221. static void __usbtty_puts (const char *str, int len)
  222. {
  223. int maxlen = usbtty_output.totalsize;
  224. int space, n;
  225. /* break str into chunks < buffer size, if needed */
  226. while (len > 0) {
  227. space = maxlen - usbtty_output.size;
  228. /* Empty buffer here, if needed, to ensure space... */
  229. if (space <= 0) {
  230. write_buffer (&usbtty_output);
  231. space = maxlen - usbtty_output.size;
  232. if (space <= 0) {
  233. space = len; /* allow old data to be overwritten. */
  234. }
  235. }
  236. n = MIN (space, MIN (len, maxlen));
  237. buf_push (&usbtty_output, str, n);
  238. str += n;
  239. len -= n;
  240. }
  241. }
  242. void usbtty_puts (const char *str)
  243. {
  244. int n;
  245. int len = strlen (str);
  246. /* add '\r' for each '\n' */
  247. while (len > 0) {
  248. n = next_nl_pos (str);
  249. if (str[n] == '\n') {
  250. __usbtty_puts (str, n + 1);
  251. __usbtty_puts ("\r", 1);
  252. str += (n + 1);
  253. len -= (n + 1);
  254. } else {
  255. /* No \n found. All done. */
  256. __usbtty_puts (str, n);
  257. break;
  258. }
  259. }
  260. /* Poll at end to handle new data... */
  261. usbtty_poll ();
  262. }
  263. /*
  264. * Initialize the usb client port.
  265. *
  266. */
  267. int drv_usbtty_init (void)
  268. {
  269. int rc;
  270. /* prepare buffers... */
  271. buf_init (&usbtty_input, USBTTY_BUFFER_SIZE);
  272. buf_init (&usbtty_output, USBTTY_BUFFER_SIZE);
  273. /* Now, set up USB controller and infrastructure */
  274. udc_init (); /* Basic USB initialization */
  275. usbtty_init_strings ();
  276. usbtty_init_instances ();
  277. udc_startup_events (device_instance); /* Enable our device, initialize udc pointers */
  278. udc_connect (); /* Enable pullup for host detection */
  279. usbtty_init_endpoints ();
  280. /* Device initialization */
  281. memset (&usbttydev, 0, sizeof (usbttydev));
  282. strcpy (usbttydev.name, "usbtty");
  283. usbttydev.ext = 0; /* No extensions */
  284. usbttydev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_OUTPUT;
  285. usbttydev.tstc = usbtty_tstc; /* 'tstc' function */
  286. usbttydev.getc = usbtty_getc; /* 'getc' function */
  287. usbttydev.putc = usbtty_putc; /* 'putc' function */
  288. usbttydev.puts = usbtty_puts; /* 'puts' function */
  289. rc = device_register (&usbttydev);
  290. return (rc == 0) ? 1 : rc;
  291. }
  292. static void usbtty_init_strings (void)
  293. {
  294. struct usb_string_descriptor *string;
  295. string = (struct usb_string_descriptor *) wstrManufacturer;
  296. string->bLength = sizeof (wstrManufacturer);
  297. string->bDescriptorType = USB_DT_STRING;
  298. str2wide (CONFIG_USBD_MANUFACTURER, string->wData);
  299. string = (struct usb_string_descriptor *) wstrProduct;
  300. string->bLength = sizeof (wstrProduct);
  301. string->bDescriptorType = USB_DT_STRING;
  302. str2wide (CONFIG_USBD_PRODUCT_NAME, string->wData);
  303. string = (struct usb_string_descriptor *) wstrSerial;
  304. string->bLength = sizeof (wstrSerial);
  305. string->bDescriptorType = USB_DT_STRING;
  306. str2wide (CONFIG_USBD_SERIAL_NUMBER, string->wData);
  307. string = (struct usb_string_descriptor *) wstrConfiguration;
  308. string->bLength = sizeof (wstrConfiguration);
  309. string->bDescriptorType = USB_DT_STRING;
  310. str2wide (CONFIG_USBD_CONFIGURATION_STR, string->wData);
  311. string = (struct usb_string_descriptor *) wstrInterface;
  312. string->bLength = sizeof (wstrInterface);
  313. string->bDescriptorType = USB_DT_STRING;
  314. str2wide (CONFIG_USBD_INTERFACE_STR, string->wData);
  315. /* Now, initialize the string table for ep0 handling */
  316. usb_strings = usbtty_string_table;
  317. }
  318. static void usbtty_init_instances (void)
  319. {
  320. int i;
  321. /* initialize device instance */
  322. memset (device_instance, 0, sizeof (struct usb_device_instance));
  323. device_instance->device_state = STATE_INIT;
  324. device_instance->device_descriptor = &device_descriptor;
  325. device_instance->event = usbtty_event_handler;
  326. device_instance->bus = bus_instance;
  327. device_instance->configurations = NUM_CONFIGS;
  328. device_instance->configuration_instance_array = config_instance;
  329. /* initialize bus instance */
  330. memset (bus_instance, 0, sizeof (struct usb_bus_instance));
  331. bus_instance->device = device_instance;
  332. bus_instance->endpoint_array = endpoint_instance;
  333. bus_instance->max_endpoints = 1;
  334. bus_instance->maxpacketsize = 64;
  335. bus_instance->serial_number_str = CONFIG_USBD_SERIAL_NUMBER;
  336. /* configuration instance */
  337. memset (config_instance, 0,
  338. sizeof (struct usb_configuration_instance));
  339. config_instance->interfaces = NUM_INTERFACES;
  340. config_instance->configuration_descriptor = config_descriptors;
  341. config_instance->interface_instance_array = interface_instance;
  342. /* interface instance */
  343. memset (interface_instance, 0,
  344. sizeof (struct usb_interface_instance));
  345. interface_instance->alternates = 1;
  346. interface_instance->alternates_instance_array = alternate_instance;
  347. /* alternates instance */
  348. memset (alternate_instance, 0,
  349. sizeof (struct usb_alternate_instance));
  350. alternate_instance->interface_descriptor = interface_descriptors;
  351. alternate_instance->endpoints = NUM_ENDPOINTS;
  352. alternate_instance->endpoints_descriptor_array = ep_descriptor_ptrs;
  353. /* endpoint instances */
  354. memset (&endpoint_instance[0], 0,
  355. sizeof (struct usb_endpoint_instance));
  356. endpoint_instance[0].endpoint_address = 0;
  357. endpoint_instance[0].rcv_packetSize = EP0_MAX_PACKET_SIZE;
  358. endpoint_instance[0].rcv_attributes = USB_ENDPOINT_XFER_CONTROL;
  359. endpoint_instance[0].tx_packetSize = EP0_MAX_PACKET_SIZE;
  360. endpoint_instance[0].tx_attributes = USB_ENDPOINT_XFER_CONTROL;
  361. udc_setup_ep (device_instance, 0, &endpoint_instance[0]);
  362. for (i = 1; i <= NUM_ENDPOINTS; i++) {
  363. memset (&endpoint_instance[i], 0,
  364. sizeof (struct usb_endpoint_instance));
  365. endpoint_instance[i].endpoint_address =
  366. ep_descriptors[i - 1].bEndpointAddress;
  367. endpoint_instance[i].rcv_packetSize =
  368. ep_descriptors[i - 1].wMaxPacketSize;
  369. endpoint_instance[i].rcv_attributes =
  370. ep_descriptors[i - 1].bmAttributes;
  371. endpoint_instance[i].tx_packetSize =
  372. ep_descriptors[i - 1].wMaxPacketSize;
  373. endpoint_instance[i].tx_attributes =
  374. ep_descriptors[i - 1].bmAttributes;
  375. urb_link_init (&endpoint_instance[i].rcv);
  376. urb_link_init (&endpoint_instance[i].rdy);
  377. urb_link_init (&endpoint_instance[i].tx);
  378. urb_link_init (&endpoint_instance[i].done);
  379. if (endpoint_instance[i].endpoint_address & USB_DIR_IN)
  380. endpoint_instance[i].tx_urb =
  381. usbd_alloc_urb (device_instance,
  382. &endpoint_instance[i]);
  383. else
  384. endpoint_instance[i].rcv_urb =
  385. usbd_alloc_urb (device_instance,
  386. &endpoint_instance[i]);
  387. }
  388. }
  389. static void usbtty_init_endpoints (void)
  390. {
  391. int i;
  392. bus_instance->max_endpoints = NUM_ENDPOINTS + 1;
  393. for (i = 0; i <= NUM_ENDPOINTS; i++) {
  394. udc_setup_ep (device_instance, i, &endpoint_instance[i]);
  395. }
  396. }
  397. /*********************************************************************************/
  398. static struct urb *next_urb (struct usb_device_instance *device,
  399. struct usb_endpoint_instance *endpoint)
  400. {
  401. struct urb *current_urb = NULL;
  402. int space;
  403. /* If there's a queue, then we should add to the last urb */
  404. if (!endpoint->tx_queue) {
  405. current_urb = endpoint->tx_urb;
  406. } else {
  407. /* Last urb from tx chain */
  408. current_urb =
  409. p2surround (struct urb, link, endpoint->tx.prev);
  410. }
  411. /* Make sure this one has enough room */
  412. space = current_urb->buffer_length - current_urb->actual_length;
  413. if (space > 0) {
  414. return current_urb;
  415. } else { /* No space here */
  416. /* First look at done list */
  417. current_urb = first_urb_detached (&endpoint->done);
  418. if (!current_urb) {
  419. current_urb = usbd_alloc_urb (device, endpoint);
  420. }
  421. urb_append (&endpoint->tx, current_urb);
  422. endpoint->tx_queue++;
  423. }
  424. return current_urb;
  425. }
  426. static int write_buffer (circbuf_t * buf)
  427. {
  428. if (!usbtty_configured ()) {
  429. return 0;
  430. }
  431. if (buf->size) {
  432. struct usb_endpoint_instance *endpoint =
  433. &endpoint_instance[TX_ENDPOINT];
  434. struct urb *current_urb = NULL;
  435. char *dest;
  436. int space_avail;
  437. int popnum, popped;
  438. int total = 0;
  439. /* Break buffer into urb sized pieces, and link each to the endpoint */
  440. while (buf->size > 0) {
  441. current_urb = next_urb (device_instance, endpoint);
  442. if (!current_urb) {
  443. TTYERR ("current_urb is NULL, buf->size %d\n",
  444. buf->size);
  445. return total;
  446. }
  447. dest = current_urb->buffer +
  448. current_urb->actual_length;
  449. space_avail =
  450. current_urb->buffer_length -
  451. current_urb->actual_length;
  452. popnum = MIN (space_avail, buf->size);
  453. if (popnum == 0)
  454. break;
  455. popped = buf_pop (buf, dest, popnum);
  456. if (popped == 0)
  457. break;
  458. current_urb->actual_length += popped;
  459. total += popped;
  460. /* If endpoint->last == 0, then transfers have not started on this endpoint */
  461. if (endpoint->last == 0) {
  462. udc_endpoint_write (endpoint);
  463. }
  464. } /* end while */
  465. return total;
  466. } /* end if tx_urb */
  467. return 0;
  468. }
  469. static int fill_buffer (circbuf_t * buf)
  470. {
  471. struct usb_endpoint_instance *endpoint =
  472. &endpoint_instance[RECV_ENDPOINT];
  473. if (endpoint->rcv_urb && endpoint->rcv_urb->actual_length) {
  474. unsigned int nb = endpoint->rcv_urb->actual_length;
  475. char *src = (char *) endpoint->rcv_urb->buffer;
  476. buf_push (buf, src, nb);
  477. endpoint->rcv_urb->actual_length = 0;
  478. return nb;
  479. }
  480. return 0;
  481. }
  482. static int usbtty_configured (void)
  483. {
  484. return usbtty_configured_flag;
  485. }
  486. /*********************************************************************************/
  487. static void usbtty_event_handler (struct usb_device_instance *device,
  488. usb_device_event_t event, int data)
  489. {
  490. switch (event) {
  491. case DEVICE_RESET:
  492. case DEVICE_BUS_INACTIVE:
  493. usbtty_configured_flag = 0;
  494. break;
  495. case DEVICE_CONFIGURED:
  496. usbtty_configured_flag = 1;
  497. break;
  498. case DEVICE_ADDRESS_ASSIGNED:
  499. usbtty_init_endpoints ();
  500. default:
  501. break;
  502. }
  503. }
  504. /*********************************************************************************/
  505. /*
  506. * Since interrupt handling has not yet been implemented, we use this function
  507. * to handle polling. This is called by the tstc,getc,putc,puts routines to
  508. * update the USB state.
  509. */
  510. void usbtty_poll (void)
  511. {
  512. /* New interrupts? */
  513. pretend_interrupts ();
  514. /* Write any output data to host buffer (do this before checking interrupts to avoid missing one) */
  515. if (usbtty_configured ()) {
  516. write_buffer (&usbtty_output);
  517. }
  518. /* New interrupts? */
  519. pretend_interrupts ();
  520. /* Check for new data from host.. (do this after checking interrupts to get latest data) */
  521. if (usbtty_configured ()) {
  522. fill_buffer (&usbtty_input);
  523. }
  524. /* New interrupts? */
  525. pretend_interrupts ();
  526. }
  527. static void pretend_interrupts (void)
  528. {
  529. /* Loop while we have interrupts.
  530. * If we don't do this, the input chain
  531. * polling delay is likely to miss
  532. * host requests.
  533. */
  534. while (inw (UDC_IRQ_SRC) & ~UDC_SOF_Flg) {
  535. /* Handle any new IRQs */
  536. omap1510_udc_irq ();
  537. omap1510_udc_noniso_irq ();
  538. }
  539. }
  540. #endif