pxa25x_udc.h 7.0 KB

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