pxa2xx_udc.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * linux/drivers/usb/gadget/pxa2xx_udc.h
  3. * Intel PXA2xx on-chip full speed USB device controller
  4. *
  5. * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
  6. * Copyright (C) 2003 David Brownell
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #ifndef __LINUX_USB_GADGET_PXA2XX_H
  24. #define __LINUX_USB_GADGET_PXA2XX_H
  25. #include <linux/types.h>
  26. /*-------------------------------------------------------------------------*/
  27. /* pxa2xx has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */
  28. #define UFNRH_SIR (1 << 7) /* SOF interrupt request */
  29. #define UFNRH_SIM (1 << 6) /* SOF interrupt mask */
  30. #define UFNRH_IPE14 (1 << 5) /* ISO packet error, ep14 */
  31. #define UFNRH_IPE9 (1 << 4) /* ISO packet error, ep9 */
  32. #define UFNRH_IPE4 (1 << 3) /* ISO packet error, ep4 */
  33. /* pxa255 has this (move to include/asm-arm/arch-pxa/pxa-regs.h) */
  34. #define UDCCFR UDC_RES2 /* UDC Control Function Register */
  35. #define UDCCFR_AREN (1 << 7) /* ACK response enable (now) */
  36. #define UDCCFR_ACM (1 << 2) /* ACK control mode (wait for AREN) */
  37. /* latest pxa255 errata define new "must be one" bits in UDCCFR */
  38. #define UDCCFR_MB1 (0xff & ~(UDCCFR_AREN|UDCCFR_ACM))
  39. /*-------------------------------------------------------------------------*/
  40. struct pxa2xx_udc;
  41. struct pxa2xx_ep {
  42. struct usb_ep ep;
  43. struct pxa2xx_udc *dev;
  44. const struct usb_endpoint_descriptor *desc;
  45. struct list_head queue;
  46. unsigned long pio_irqs;
  47. unsigned short fifo_size;
  48. u8 bEndpointAddress;
  49. u8 bmAttributes;
  50. unsigned stopped : 1;
  51. unsigned dma_fixup : 1;
  52. /* UDCCS = UDC Control/Status for this EP
  53. * UBCR = UDC Byte Count Remaining (contents of OUT fifo)
  54. * UDDR = UDC Endpoint Data Register (the fifo)
  55. * DRCM = DMA Request Channel Map
  56. */
  57. volatile u32 *reg_udccs;
  58. volatile u32 *reg_ubcr;
  59. volatile u32 *reg_uddr;
  60. };
  61. struct pxa2xx_request {
  62. struct usb_request req;
  63. struct list_head queue;
  64. };
  65. enum ep0_state {
  66. EP0_IDLE,
  67. EP0_IN_DATA_PHASE,
  68. EP0_OUT_DATA_PHASE,
  69. EP0_END_XFER,
  70. EP0_STALL,
  71. };
  72. #define EP0_FIFO_SIZE ((unsigned)16)
  73. #define BULK_FIFO_SIZE ((unsigned)64)
  74. #define ISO_FIFO_SIZE ((unsigned)256)
  75. #define INT_FIFO_SIZE ((unsigned)8)
  76. struct udc_stats {
  77. struct ep0stats {
  78. unsigned long ops;
  79. unsigned long bytes;
  80. } read, write;
  81. unsigned long irqs;
  82. };
  83. #ifdef CONFIG_USB_PXA2XX_SMALL
  84. /* when memory's tight, SMALL config saves code+data. */
  85. #define PXA_UDC_NUM_ENDPOINTS 3
  86. #endif
  87. #ifndef PXA_UDC_NUM_ENDPOINTS
  88. #define PXA_UDC_NUM_ENDPOINTS 16
  89. #endif
  90. struct pxa2xx_udc {
  91. struct usb_gadget gadget;
  92. struct usb_gadget_driver *driver;
  93. enum ep0_state ep0state;
  94. struct udc_stats stats;
  95. unsigned got_irq : 1,
  96. vbus : 1,
  97. pullup : 1,
  98. has_cfr : 1,
  99. req_pending : 1,
  100. req_std : 1,
  101. req_config : 1;
  102. #define start_watchdog(dev) mod_timer(&dev->timer, jiffies + (HZ/200))
  103. struct timer_list timer;
  104. struct device *dev;
  105. struct clk *clk;
  106. struct pxa2xx_udc_mach_info *mach;
  107. u64 dma_mask;
  108. struct pxa2xx_ep ep [PXA_UDC_NUM_ENDPOINTS];
  109. };
  110. /*-------------------------------------------------------------------------*/
  111. #ifdef CONFIG_ARCH_LUBBOCK
  112. #include <asm/arch/lubbock.h>
  113. /* lubbock can also report usb connect/disconnect irqs */
  114. #endif
  115. static struct pxa2xx_udc *the_controller;
  116. /*-------------------------------------------------------------------------*/
  117. /*
  118. * Debugging support vanishes in non-debug builds. DBG_NORMAL should be
  119. * mostly silent during normal use/testing, with no timing side-effects.
  120. */
  121. #define DBG_NORMAL 1 /* error paths, device state transitions */
  122. #define DBG_VERBOSE 2 /* add some success path trace info */
  123. #define DBG_NOISY 3 /* ... even more: request level */
  124. #define DBG_VERY_NOISY 4 /* ... even more: packet level */
  125. #ifdef DEBUG
  126. static const char *state_name[] = {
  127. "EP0_IDLE",
  128. "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE",
  129. "EP0_END_XFER", "EP0_STALL"
  130. };
  131. #define DMSG(stuff...) printk(KERN_DEBUG "udc: " stuff)
  132. #ifdef VERBOSE
  133. # define UDC_DEBUG DBG_VERBOSE
  134. #else
  135. # define UDC_DEBUG DBG_NORMAL
  136. #endif
  137. static void __maybe_unused
  138. dump_udccr(const char *label)
  139. {
  140. u32 udccr = UDCCR;
  141. DMSG("%s %02X =%s%s%s%s%s%s%s%s\n",
  142. label, udccr,
  143. (udccr & UDCCR_REM) ? " rem" : "",
  144. (udccr & UDCCR_RSTIR) ? " rstir" : "",
  145. (udccr & UDCCR_SRM) ? " srm" : "",
  146. (udccr & UDCCR_SUSIR) ? " susir" : "",
  147. (udccr & UDCCR_RESIR) ? " resir" : "",
  148. (udccr & UDCCR_RSM) ? " rsm" : "",
  149. (udccr & UDCCR_UDA) ? " uda" : "",
  150. (udccr & UDCCR_UDE) ? " ude" : "");
  151. }
  152. static void __maybe_unused
  153. dump_udccs0(const char *label)
  154. {
  155. u32 udccs0 = UDCCS0;
  156. DMSG("%s %s %02X =%s%s%s%s%s%s%s%s\n",
  157. label, state_name[the_controller->ep0state], udccs0,
  158. (udccs0 & UDCCS0_SA) ? " sa" : "",
  159. (udccs0 & UDCCS0_RNE) ? " rne" : "",
  160. (udccs0 & UDCCS0_FST) ? " fst" : "",
  161. (udccs0 & UDCCS0_SST) ? " sst" : "",
  162. (udccs0 & UDCCS0_DRWF) ? " dwrf" : "",
  163. (udccs0 & UDCCS0_FTF) ? " ftf" : "",
  164. (udccs0 & UDCCS0_IPR) ? " ipr" : "",
  165. (udccs0 & UDCCS0_OPR) ? " opr" : "");
  166. }
  167. static void __maybe_unused
  168. dump_state(struct pxa2xx_udc *dev)
  169. {
  170. u32 tmp;
  171. unsigned i;
  172. DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
  173. is_usb_connected() ? "host " : "disconnected",
  174. state_name[dev->ep0state],
  175. UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
  176. dump_udccr("udccr");
  177. if (dev->has_cfr) {
  178. tmp = UDCCFR;
  179. DMSG("udccfr %02X =%s%s\n", tmp,
  180. (tmp & UDCCFR_AREN) ? " aren" : "",
  181. (tmp & UDCCFR_ACM) ? " acm" : "");
  182. }
  183. if (!dev->driver) {
  184. DMSG("no gadget driver bound\n");
  185. return;
  186. } else
  187. DMSG("ep0 driver '%s'\n", dev->driver->driver.name);
  188. if (!is_usb_connected())
  189. return;
  190. dump_udccs0 ("udccs0");
  191. DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n",
  192. dev->stats.write.bytes, dev->stats.write.ops,
  193. dev->stats.read.bytes, dev->stats.read.ops);
  194. for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) {
  195. if (dev->ep [i].desc == 0)
  196. continue;
  197. DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs);
  198. }
  199. }
  200. #else
  201. #define DMSG(stuff...) do{}while(0)
  202. #define dump_udccr(x) do{}while(0)
  203. #define dump_udccs0(x) do{}while(0)
  204. #define dump_state(x) do{}while(0)
  205. #define UDC_DEBUG ((unsigned)0)
  206. #endif
  207. #define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0)
  208. #define WARN(stuff...) printk(KERN_WARNING "udc: " stuff)
  209. #define INFO(stuff...) printk(KERN_INFO "udc: " stuff)
  210. #endif /* __LINUX_USB_GADGET_PXA2XX_H */