pxa2xx_udc.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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 long dma_irqs;
  48. short dma;
  49. unsigned short fifo_size;
  50. u8 bEndpointAddress;
  51. u8 bmAttributes;
  52. unsigned stopped : 1;
  53. unsigned dma_fixup : 1;
  54. /* UDCCS = UDC Control/Status for this EP
  55. * UBCR = UDC Byte Count Remaining (contents of OUT fifo)
  56. * UDDR = UDC Endpoint Data Register (the fifo)
  57. * DRCM = DMA Request Channel Map
  58. */
  59. volatile u32 *reg_udccs;
  60. volatile u32 *reg_ubcr;
  61. volatile u32 *reg_uddr;
  62. #ifdef USE_DMA
  63. volatile u32 *reg_drcmr;
  64. #define drcmr(n) .reg_drcmr = & DRCMR ## n ,
  65. #else
  66. #define drcmr(n)
  67. #endif
  68. };
  69. struct pxa2xx_request {
  70. struct usb_request req;
  71. struct list_head queue;
  72. };
  73. enum ep0_state {
  74. EP0_IDLE,
  75. EP0_IN_DATA_PHASE,
  76. EP0_OUT_DATA_PHASE,
  77. EP0_END_XFER,
  78. EP0_STALL,
  79. };
  80. #define EP0_FIFO_SIZE ((unsigned)16)
  81. #define BULK_FIFO_SIZE ((unsigned)64)
  82. #define ISO_FIFO_SIZE ((unsigned)256)
  83. #define INT_FIFO_SIZE ((unsigned)8)
  84. struct udc_stats {
  85. struct ep0stats {
  86. unsigned long ops;
  87. unsigned long bytes;
  88. } read, write;
  89. unsigned long irqs;
  90. };
  91. #ifdef CONFIG_USB_PXA2XX_SMALL
  92. /* when memory's tight, SMALL config saves code+data. */
  93. #undef USE_DMA
  94. #define PXA_UDC_NUM_ENDPOINTS 3
  95. #endif
  96. #ifndef PXA_UDC_NUM_ENDPOINTS
  97. #define PXA_UDC_NUM_ENDPOINTS 16
  98. #endif
  99. struct pxa2xx_udc {
  100. struct usb_gadget gadget;
  101. struct usb_gadget_driver *driver;
  102. enum ep0_state ep0state;
  103. struct udc_stats stats;
  104. unsigned got_irq : 1,
  105. vbus : 1,
  106. pullup : 1,
  107. has_cfr : 1,
  108. req_pending : 1,
  109. req_std : 1,
  110. req_config : 1;
  111. #define start_watchdog(dev) mod_timer(&dev->timer, jiffies + (HZ/200))
  112. struct timer_list timer;
  113. struct device *dev;
  114. struct pxa2xx_udc_mach_info *mach;
  115. u64 dma_mask;
  116. struct pxa2xx_ep ep [PXA_UDC_NUM_ENDPOINTS];
  117. };
  118. /*-------------------------------------------------------------------------*/
  119. #ifdef CONFIG_ARCH_LUBBOCK
  120. #include <asm/arch/lubbock.h>
  121. /* lubbock can also report usb connect/disconnect irqs */
  122. #ifdef DEBUG
  123. #define HEX_DISPLAY(n) if (machine_is_lubbock()) { LUB_HEXLED = (n); }
  124. #endif
  125. #endif
  126. /*-------------------------------------------------------------------------*/
  127. /* LEDs are only for debug */
  128. #ifndef HEX_DISPLAY
  129. #define HEX_DISPLAY(n) do {} while(0)
  130. #endif
  131. #ifdef DEBUG
  132. #include <asm/leds.h>
  133. #define LED_CONNECTED_ON leds_event(led_green_on)
  134. #define LED_CONNECTED_OFF do { \
  135. leds_event(led_green_off); \
  136. HEX_DISPLAY(0); \
  137. } while(0)
  138. #endif
  139. #ifndef LED_CONNECTED_ON
  140. #define LED_CONNECTED_ON do {} while(0)
  141. #define LED_CONNECTED_OFF do {} while(0)
  142. #endif
  143. /*-------------------------------------------------------------------------*/
  144. static struct pxa2xx_udc *the_controller;
  145. static inline int pxa_gpio_get(unsigned gpio)
  146. {
  147. return (GPLR(gpio) & GPIO_bit(gpio)) != 0;
  148. }
  149. static inline void pxa_gpio_set(unsigned gpio, int is_on)
  150. {
  151. int mask = GPIO_bit(gpio);
  152. if (is_on)
  153. GPSR(gpio) = mask;
  154. else
  155. GPCR(gpio) = mask;
  156. }
  157. /*-------------------------------------------------------------------------*/
  158. /*
  159. * Debugging support vanishes in non-debug builds. DBG_NORMAL should be
  160. * mostly silent during normal use/testing, with no timing side-effects.
  161. */
  162. #define DBG_NORMAL 1 /* error paths, device state transitions */
  163. #define DBG_VERBOSE 2 /* add some success path trace info */
  164. #define DBG_NOISY 3 /* ... even more: request level */
  165. #define DBG_VERY_NOISY 4 /* ... even more: packet level */
  166. #ifdef DEBUG
  167. static const char *state_name[] = {
  168. "EP0_IDLE",
  169. "EP0_IN_DATA_PHASE", "EP0_OUT_DATA_PHASE",
  170. "EP0_END_XFER", "EP0_STALL"
  171. };
  172. #define DMSG(stuff...) printk(KERN_DEBUG "udc: " stuff)
  173. #ifdef VERBOSE
  174. # define UDC_DEBUG DBG_VERBOSE
  175. #else
  176. # define UDC_DEBUG DBG_NORMAL
  177. #endif
  178. static void __attribute__ ((__unused__))
  179. dump_udccr(const char *label)
  180. {
  181. u32 udccr = UDCCR;
  182. DMSG("%s %02X =%s%s%s%s%s%s%s%s\n",
  183. label, udccr,
  184. (udccr & UDCCR_REM) ? " rem" : "",
  185. (udccr & UDCCR_RSTIR) ? " rstir" : "",
  186. (udccr & UDCCR_SRM) ? " srm" : "",
  187. (udccr & UDCCR_SUSIR) ? " susir" : "",
  188. (udccr & UDCCR_RESIR) ? " resir" : "",
  189. (udccr & UDCCR_RSM) ? " rsm" : "",
  190. (udccr & UDCCR_UDA) ? " uda" : "",
  191. (udccr & UDCCR_UDE) ? " ude" : "");
  192. }
  193. static void __attribute__ ((__unused__))
  194. dump_udccs0(const char *label)
  195. {
  196. u32 udccs0 = UDCCS0;
  197. DMSG("%s %s %02X =%s%s%s%s%s%s%s%s\n",
  198. label, state_name[the_controller->ep0state], udccs0,
  199. (udccs0 & UDCCS0_SA) ? " sa" : "",
  200. (udccs0 & UDCCS0_RNE) ? " rne" : "",
  201. (udccs0 & UDCCS0_FST) ? " fst" : "",
  202. (udccs0 & UDCCS0_SST) ? " sst" : "",
  203. (udccs0 & UDCCS0_DRWF) ? " dwrf" : "",
  204. (udccs0 & UDCCS0_FTF) ? " ftf" : "",
  205. (udccs0 & UDCCS0_IPR) ? " ipr" : "",
  206. (udccs0 & UDCCS0_OPR) ? " opr" : "");
  207. }
  208. static void __attribute__ ((__unused__))
  209. dump_state(struct pxa2xx_udc *dev)
  210. {
  211. u32 tmp;
  212. unsigned i;
  213. DMSG("%s %s, uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
  214. is_usb_connected() ? "host " : "disconnected",
  215. state_name[dev->ep0state],
  216. UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
  217. dump_udccr("udccr");
  218. if (dev->has_cfr) {
  219. tmp = UDCCFR;
  220. DMSG("udccfr %02X =%s%s\n", tmp,
  221. (tmp & UDCCFR_AREN) ? " aren" : "",
  222. (tmp & UDCCFR_ACM) ? " acm" : "");
  223. }
  224. if (!dev->driver) {
  225. DMSG("no gadget driver bound\n");
  226. return;
  227. } else
  228. DMSG("ep0 driver '%s'\n", dev->driver->driver.name);
  229. if (!is_usb_connected())
  230. return;
  231. dump_udccs0 ("udccs0");
  232. DMSG("ep0 IN %lu/%lu, OUT %lu/%lu\n",
  233. dev->stats.write.bytes, dev->stats.write.ops,
  234. dev->stats.read.bytes, dev->stats.read.ops);
  235. for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) {
  236. if (dev->ep [i].desc == 0)
  237. continue;
  238. DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs);
  239. }
  240. }
  241. #else
  242. #define DMSG(stuff...) do{}while(0)
  243. #define dump_udccr(x) do{}while(0)
  244. #define dump_udccs0(x) do{}while(0)
  245. #define dump_state(x) do{}while(0)
  246. #define UDC_DEBUG ((unsigned)0)
  247. #endif
  248. #define DBG(lvl, stuff...) do{if ((lvl) <= UDC_DEBUG) DMSG(stuff);}while(0)
  249. #define WARN(stuff...) printk(KERN_WARNING "udc: " stuff)
  250. #define INFO(stuff...) printk(KERN_INFO "udc: " stuff)
  251. #endif /* __LINUX_USB_GADGET_PXA2XX_H */