pxa27x_udc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /*
  2. * linux/drivers/usb/gadget/pxa27x_udc.h
  3. * Intel PXA27x on-chip full speed USB device controller
  4. *
  5. * Inspired by original driver by Frank Becker, David Brownell, and others.
  6. * Copyright (C) 2008 Robert Jarzmik
  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_PXA27X_H
  23. #define __LINUX_USB_GADGET_PXA27X_H
  24. #include <linux/types.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/io.h>
  27. /*
  28. * Register definitions
  29. */
  30. /* Offsets */
  31. #define UDCCR 0x0000 /* UDC Control Register */
  32. #define UDCICR0 0x0004 /* UDC Interrupt Control Register0 */
  33. #define UDCICR1 0x0008 /* UDC Interrupt Control Register1 */
  34. #define UDCISR0 0x000C /* UDC Interrupt Status Register 0 */
  35. #define UDCISR1 0x0010 /* UDC Interrupt Status Register 1 */
  36. #define UDCFNR 0x0014 /* UDC Frame Number Register */
  37. #define UDCOTGICR 0x0018 /* UDC On-The-Go interrupt control */
  38. #define UP2OCR 0x0020 /* USB Port 2 Output Control register */
  39. #define UP3OCR 0x0024 /* USB Port 3 Output Control register */
  40. #define UDCCSRn(x) (0x0100 + ((x)<<2)) /* UDC Control/Status register */
  41. #define UDCBCRn(x) (0x0200 + ((x)<<2)) /* UDC Byte Count Register */
  42. #define UDCDRn(x) (0x0300 + ((x)<<2)) /* UDC Data Register */
  43. #define UDCCRn(x) (0x0400 + ((x)<<2)) /* UDC Control Register */
  44. #define UDCCR_OEN (1 << 31) /* On-the-Go Enable */
  45. #define UDCCR_AALTHNP (1 << 30) /* A-device Alternate Host Negotiation
  46. Protocol Port Support */
  47. #define UDCCR_AHNP (1 << 29) /* A-device Host Negotiation Protocol
  48. Support */
  49. #define UDCCR_BHNP (1 << 28) /* B-device Host Negotiation Protocol
  50. Enable */
  51. #define UDCCR_DWRE (1 << 16) /* Device Remote Wake-up Enable */
  52. #define UDCCR_ACN (0x03 << 11) /* Active UDC configuration Number */
  53. #define UDCCR_ACN_S 11
  54. #define UDCCR_AIN (0x07 << 8) /* Active UDC interface Number */
  55. #define UDCCR_AIN_S 8
  56. #define UDCCR_AAISN (0x07 << 5) /* Active UDC Alternate Interface
  57. Setting Number */
  58. #define UDCCR_AAISN_S 5
  59. #define UDCCR_SMAC (1 << 4) /* Switch Endpoint Memory to Active
  60. Configuration */
  61. #define UDCCR_EMCE (1 << 3) /* Endpoint Memory Configuration
  62. Error */
  63. #define UDCCR_UDR (1 << 2) /* UDC Resume */
  64. #define UDCCR_UDA (1 << 1) /* UDC Active */
  65. #define UDCCR_UDE (1 << 0) /* UDC Enable */
  66. #define UDCICR_INT(n, intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
  67. #define UDCICR1_IECC (1 << 31) /* IntEn - Configuration Change */
  68. #define UDCICR1_IESOF (1 << 30) /* IntEn - Start of Frame */
  69. #define UDCICR1_IERU (1 << 29) /* IntEn - Resume */
  70. #define UDCICR1_IESU (1 << 28) /* IntEn - Suspend */
  71. #define UDCICR1_IERS (1 << 27) /* IntEn - Reset */
  72. #define UDCICR_FIFOERR (1 << 1) /* FIFO Error interrupt for EP */
  73. #define UDCICR_PKTCOMPL (1 << 0) /* Packet Complete interrupt for EP */
  74. #define UDCICR_INT_MASK (UDCICR_FIFOERR | UDCICR_PKTCOMPL)
  75. #define UDCISR_INT(n, intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
  76. #define UDCISR1_IRCC (1 << 31) /* IntReq - Configuration Change */
  77. #define UDCISR1_IRSOF (1 << 30) /* IntReq - Start of Frame */
  78. #define UDCISR1_IRRU (1 << 29) /* IntReq - Resume */
  79. #define UDCISR1_IRSU (1 << 28) /* IntReq - Suspend */
  80. #define UDCISR1_IRRS (1 << 27) /* IntReq - Reset */
  81. #define UDCISR_INT_MASK (UDCICR_FIFOERR | UDCICR_PKTCOMPL)
  82. #define UDCOTGICR_IESF (1 << 24) /* OTG SET_FEATURE command recvd */
  83. #define UDCOTGICR_IEXR (1 << 17) /* Extra Transciever Interrupt
  84. Rising Edge Interrupt Enable */
  85. #define UDCOTGICR_IEXF (1 << 16) /* Extra Transciever Interrupt
  86. Falling Edge Interrupt Enable */
  87. #define UDCOTGICR_IEVV40R (1 << 9) /* OTG Vbus Valid 4.0V Rising Edge
  88. Interrupt Enable */
  89. #define UDCOTGICR_IEVV40F (1 << 8) /* OTG Vbus Valid 4.0V Falling Edge
  90. Interrupt Enable */
  91. #define UDCOTGICR_IEVV44R (1 << 7) /* OTG Vbus Valid 4.4V Rising Edge
  92. Interrupt Enable */
  93. #define UDCOTGICR_IEVV44F (1 << 6) /* OTG Vbus Valid 4.4V Falling Edge
  94. Interrupt Enable */
  95. #define UDCOTGICR_IESVR (1 << 5) /* OTG Session Valid Rising Edge
  96. Interrupt Enable */
  97. #define UDCOTGICR_IESVF (1 << 4) /* OTG Session Valid Falling Edge
  98. Interrupt Enable */
  99. #define UDCOTGICR_IESDR (1 << 3) /* OTG A-Device SRP Detect Rising
  100. Edge Interrupt Enable */
  101. #define UDCOTGICR_IESDF (1 << 2) /* OTG A-Device SRP Detect Falling
  102. Edge Interrupt Enable */
  103. #define UDCOTGICR_IEIDR (1 << 1) /* OTG ID Change Rising Edge
  104. Interrupt Enable */
  105. #define UDCOTGICR_IEIDF (1 << 0) /* OTG ID Change Falling Edge
  106. Interrupt Enable */
  107. /* Host Port 2 field bits */
  108. #define UP2OCR_CPVEN (1 << 0) /* Charge Pump Vbus Enable */
  109. #define UP2OCR_CPVPE (1 << 1) /* Charge Pump Vbus Pulse Enable */
  110. /* Transceiver enablers */
  111. #define UP2OCR_DPPDE (1 << 2) /* D+ Pull Down Enable */
  112. #define UP2OCR_DMPDE (1 << 3) /* D- Pull Down Enable */
  113. #define UP2OCR_DPPUE (1 << 4) /* D+ Pull Up Enable */
  114. #define UP2OCR_DMPUE (1 << 5) /* D- Pull Up Enable */
  115. #define UP2OCR_DPPUBE (1 << 6) /* D+ Pull Up Bypass Enable */
  116. #define UP2OCR_DMPUBE (1 << 7) /* D- Pull Up Bypass Enable */
  117. #define UP2OCR_EXSP (1 << 8) /* External Transceiver Speed Control */
  118. #define UP2OCR_EXSUS (1 << 9) /* External Transceiver Speed Enable */
  119. #define UP2OCR_IDON (1 << 10) /* OTG ID Read Enable */
  120. #define UP2OCR_HXS (1 << 16) /* Transceiver Output Select */
  121. #define UP2OCR_HXOE (1 << 17) /* Transceiver Output Enable */
  122. #define UP2OCR_SEOS (1 << 24) /* Single-Ended Output Select */
  123. #define UDCCSR0_SA (1 << 7) /* Setup Active */
  124. #define UDCCSR0_RNE (1 << 6) /* Receive FIFO Not Empty */
  125. #define UDCCSR0_FST (1 << 5) /* Force Stall */
  126. #define UDCCSR0_SST (1 << 4) /* Sent Stall */
  127. #define UDCCSR0_DME (1 << 3) /* DMA Enable */
  128. #define UDCCSR0_FTF (1 << 2) /* Flush Transmit FIFO */
  129. #define UDCCSR0_IPR (1 << 1) /* IN Packet Ready */
  130. #define UDCCSR0_OPC (1 << 0) /* OUT Packet Complete */
  131. #define UDCCSR_DPE (1 << 9) /* Data Packet Error */
  132. #define UDCCSR_FEF (1 << 8) /* Flush Endpoint FIFO */
  133. #define UDCCSR_SP (1 << 7) /* Short Packet Control/Status */
  134. #define UDCCSR_BNE (1 << 6) /* Buffer Not Empty (IN endpoints) */
  135. #define UDCCSR_BNF (1 << 6) /* Buffer Not Full (OUT endpoints) */
  136. #define UDCCSR_FST (1 << 5) /* Force STALL */
  137. #define UDCCSR_SST (1 << 4) /* Sent STALL */
  138. #define UDCCSR_DME (1 << 3) /* DMA Enable */
  139. #define UDCCSR_TRN (1 << 2) /* Tx/Rx NAK */
  140. #define UDCCSR_PC (1 << 1) /* Packet Complete */
  141. #define UDCCSR_FS (1 << 0) /* FIFO needs service */
  142. #define UDCCONR_CN (0x03 << 25) /* Configuration Number */
  143. #define UDCCONR_CN_S 25
  144. #define UDCCONR_IN (0x07 << 22) /* Interface Number */
  145. #define UDCCONR_IN_S 22
  146. #define UDCCONR_AISN (0x07 << 19) /* Alternate Interface Number */
  147. #define UDCCONR_AISN_S 19
  148. #define UDCCONR_EN (0x0f << 15) /* Endpoint Number */
  149. #define UDCCONR_EN_S 15
  150. #define UDCCONR_ET (0x03 << 13) /* Endpoint Type: */
  151. #define UDCCONR_ET_S 13
  152. #define UDCCONR_ET_INT (0x03 << 13) /* Interrupt */
  153. #define UDCCONR_ET_BULK (0x02 << 13) /* Bulk */
  154. #define UDCCONR_ET_ISO (0x01 << 13) /* Isochronous */
  155. #define UDCCONR_ET_NU (0x00 << 13) /* Not used */
  156. #define UDCCONR_ED (1 << 12) /* Endpoint Direction */
  157. #define UDCCONR_MPS (0x3ff << 2) /* Maximum Packet Size */
  158. #define UDCCONR_MPS_S 2
  159. #define UDCCONR_DE (1 << 1) /* Double Buffering Enable */
  160. #define UDCCONR_EE (1 << 0) /* Endpoint Enable */
  161. #define UDCCR_MASK_BITS (UDCCR_OEN | UDCCR_SMAC | UDCCR_UDR | UDCCR_UDE)
  162. #define UDCCSR_WR_MASK (UDCCSR_DME | UDCCSR_FST)
  163. #define UDC_FNR_MASK (0x7ff)
  164. #define UDC_BCR_MASK (0x3ff)
  165. /*
  166. * UDCCR = UDC Endpoint Configuration Registers
  167. * UDCCSR = UDC Control/Status Register for this EP
  168. * UDCBCR = UDC Byte Count Remaining (contents of OUT fifo)
  169. * UDCDR = UDC Endpoint Data Register (the fifo)
  170. */
  171. #define ofs_UDCCR(ep) (UDCCRn(ep->idx))
  172. #define ofs_UDCCSR(ep) (UDCCSRn(ep->idx))
  173. #define ofs_UDCBCR(ep) (UDCBCRn(ep->idx))
  174. #define ofs_UDCDR(ep) (UDCDRn(ep->idx))
  175. /* Register access macros */
  176. #define udc_ep_readl(ep, reg) \
  177. __raw_readl((ep)->dev->regs + ofs_##reg(ep))
  178. #define udc_ep_writel(ep, reg, value) \
  179. __raw_writel((value), ep->dev->regs + ofs_##reg(ep))
  180. #define udc_ep_readb(ep, reg) \
  181. __raw_readb((ep)->dev->regs + ofs_##reg(ep))
  182. #define udc_ep_writeb(ep, reg, value) \
  183. __raw_writeb((value), ep->dev->regs + ofs_##reg(ep))
  184. #define udc_readl(dev, reg) \
  185. __raw_readl((dev)->regs + (reg))
  186. #define udc_writel(udc, reg, value) \
  187. __raw_writel((value), (udc)->regs + (reg))
  188. #define UDCCSR_MASK (UDCCSR_FST | UDCCSR_DME)
  189. #define UDCCISR0_EP_MASK ~0
  190. #define UDCCISR1_EP_MASK 0xffff
  191. #define UDCCSR0_CTRL_REQ_MASK (UDCCSR0_OPC | UDCCSR0_SA | UDCCSR0_RNE)
  192. #define EPIDX(ep) (ep->idx)
  193. #define EPADDR(ep) (ep->addr)
  194. #define EPXFERTYPE(ep) (ep->type)
  195. #define EPNAME(ep) (ep->name)
  196. #define is_ep0(ep) (!ep->idx)
  197. #define EPXFERTYPE_is_ISO(ep) (EPXFERTYPE(ep) == USB_ENDPOINT_XFER_ISOC)
  198. /*
  199. * Endpoint definitions
  200. *
  201. * Once enabled, pxa endpoint configuration is freezed, and cannot change
  202. * unless a reset happens or the udc is disabled.
  203. * Therefore, we must define all pxa potential endpoint definitions needed for
  204. * all gadget and set them up before the udc is enabled.
  205. *
  206. * As the architecture chosen is fully static, meaning the pxa endpoint
  207. * configurations are set up once and for all, we must provide a way to match
  208. * one usb endpoint (usb_ep) to several pxa endpoints. The reason is that gadget
  209. * layer autoconf doesn't choose the usb_ep endpoint on (config, interface, alt)
  210. * criteria, while the pxa architecture requires that.
  211. *
  212. * The solution is to define several pxa endpoints matching one usb_ep. Ex:
  213. * - "ep1-in" matches pxa endpoint EPA (which is an IN ep at addr 1, when
  214. * the udc talks on (config=3, interface=0, alt=0)
  215. * - "ep1-in" matches pxa endpoint EPB (which is an IN ep at addr 1, when
  216. * the udc talks on (config=3, interface=0, alt=1)
  217. * - "ep1-in" matches pxa endpoint EPC (which is an IN ep at addr 1, when
  218. * the udc talks on (config=2, interface=0, alt=0)
  219. *
  220. * We'll define the pxa endpoint by its index (EPA => idx=1, EPB => idx=2, ...)
  221. */
  222. /*
  223. * Endpoint definition helpers
  224. */
  225. #define USB_EP_DEF(addr, bname, dir, type, maxpkt) \
  226. { .usb_ep = { .name = bname, .ops = &pxa_ep_ops, .maxpacket = maxpkt, }, \
  227. .desc = { .bEndpointAddress = addr | (dir ? USB_DIR_IN : 0), \
  228. .bmAttributes = type, \
  229. .wMaxPacketSize = maxpkt, }, \
  230. .dev = &memory \
  231. }
  232. #define USB_EP_BULK(addr, bname, dir) \
  233. USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_BULK, BULK_FIFO_SIZE)
  234. #define USB_EP_ISO(addr, bname, dir) \
  235. USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_ISOC, ISO_FIFO_SIZE)
  236. #define USB_EP_INT(addr, bname, dir) \
  237. USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_INT, INT_FIFO_SIZE)
  238. #define USB_EP_IN_BULK(n) USB_EP_BULK(n, "ep" #n "in-bulk", 1)
  239. #define USB_EP_OUT_BULK(n) USB_EP_BULK(n, "ep" #n "out-bulk", 0)
  240. #define USB_EP_IN_ISO(n) USB_EP_ISO(n, "ep" #n "in-iso", 1)
  241. #define USB_EP_OUT_ISO(n) USB_EP_ISO(n, "ep" #n "out-iso", 0)
  242. #define USB_EP_IN_INT(n) USB_EP_INT(n, "ep" #n "in-int", 1)
  243. #define USB_EP_CTRL USB_EP_DEF(0, "ep0", 0, 0, EP0_FIFO_SIZE)
  244. #define PXA_EP_DEF(_idx, _addr, dir, _type, maxpkt, _config, iface, altset) \
  245. { \
  246. .dev = &memory, \
  247. .name = "ep" #_idx, \
  248. .idx = _idx, .enabled = 0, \
  249. .dir_in = dir, .addr = _addr, \
  250. .config = _config, .interface = iface, .alternate = altset, \
  251. .type = _type, .fifo_size = maxpkt, \
  252. }
  253. #define PXA_EP_BULK(_idx, addr, dir, config, iface, alt) \
  254. PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_BULK, BULK_FIFO_SIZE, \
  255. config, iface, alt)
  256. #define PXA_EP_ISO(_idx, addr, dir, config, iface, alt) \
  257. PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_ISOC, ISO_FIFO_SIZE, \
  258. config, iface, alt)
  259. #define PXA_EP_INT(_idx, addr, dir, config, iface, alt) \
  260. PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_INT, INT_FIFO_SIZE, \
  261. config, iface, alt)
  262. #define PXA_EP_IN_BULK(i, adr, c, f, a) PXA_EP_BULK(i, adr, 1, c, f, a)
  263. #define PXA_EP_OUT_BULK(i, adr, c, f, a) PXA_EP_BULK(i, adr, 0, c, f, a)
  264. #define PXA_EP_IN_ISO(i, adr, c, f, a) PXA_EP_ISO(i, adr, 1, c, f, a)
  265. #define PXA_EP_OUT_ISO(i, adr, c, f, a) PXA_EP_ISO(i, adr, 0, c, f, a)
  266. #define PXA_EP_IN_INT(i, adr, c, f, a) PXA_EP_INT(i, adr, 1, c, f, a)
  267. #define PXA_EP_CTRL PXA_EP_DEF(0, 0, 0, 0, EP0_FIFO_SIZE, 0, 0, 0)
  268. struct pxa27x_udc;
  269. struct stats {
  270. unsigned long in_ops;
  271. unsigned long out_ops;
  272. unsigned long in_bytes;
  273. unsigned long out_bytes;
  274. unsigned long irqs;
  275. };
  276. /**
  277. * struct udc_usb_ep - container of each usb_ep structure
  278. * @usb_ep: usb endpoint
  279. * @desc: usb descriptor, especially type and address
  280. * @dev: udc managing this endpoint
  281. * @pxa_ep: matching pxa_ep (cache of find_pxa_ep() call)
  282. */
  283. struct udc_usb_ep {
  284. struct usb_ep usb_ep;
  285. struct usb_endpoint_descriptor desc;
  286. struct pxa_udc *dev;
  287. struct pxa_ep *pxa_ep;
  288. };
  289. /**
  290. * struct pxa_ep - pxa endpoint
  291. * @dev: udc device
  292. * @queue: requests queue
  293. * @lock: lock to pxa_ep data (queues and stats)
  294. * @enabled: true when endpoint enabled (not stopped by gadget layer)
  295. * @idx: endpoint index (1 => epA, 2 => epB, ..., 24 => epX)
  296. * @name: endpoint name (for trace/debug purpose)
  297. * @dir_in: 1 if IN endpoint, 0 if OUT endpoint
  298. * @addr: usb endpoint number
  299. * @config: configuration in which this endpoint is active
  300. * @interface: interface in which this endpoint is active
  301. * @alternate: altsetting in which this endpoitn is active
  302. * @fifo_size: max packet size in the endpoint fifo
  303. * @type: endpoint type (bulk, iso, int, ...)
  304. * @udccsr_value: save register of UDCCSR0 for suspend/resume
  305. * @udccr_value: save register of UDCCR for suspend/resume
  306. * @stats: endpoint statistics
  307. *
  308. * The *PROBLEM* is that pxa's endpoint configuration scheme is both misdesigned
  309. * (cares about config/interface/altsetting, thus placing needless limits on
  310. * device capability) and full of implementation bugs forcing it to be set up
  311. * for use more or less like a pxa255.
  312. *
  313. * As we define the pxa_ep statically, we must guess all needed pxa_ep for all
  314. * gadget which may work with this udc driver.
  315. */
  316. struct pxa_ep {
  317. struct pxa_udc *dev;
  318. struct list_head queue;
  319. spinlock_t lock; /* Protects this structure */
  320. /* (queues, stats) */
  321. unsigned enabled:1;
  322. unsigned idx:5;
  323. char *name;
  324. /*
  325. * Specific pxa endpoint data, needed for hardware initialization
  326. */
  327. unsigned dir_in:1;
  328. unsigned addr:3;
  329. unsigned config:2;
  330. unsigned interface:3;
  331. unsigned alternate:3;
  332. unsigned fifo_size;
  333. unsigned type;
  334. #ifdef CONFIG_PM
  335. u32 udccsr_value;
  336. u32 udccr_value;
  337. #endif
  338. struct stats stats;
  339. };
  340. /**
  341. * struct pxa27x_request - container of each usb_request structure
  342. * @req: usb request
  343. * @udc_usb_ep: usb endpoint the request was submitted on
  344. * @in_use: sanity check if request already queued on an pxa_ep
  345. * @queue: linked list of requests, linked on pxa_ep->queue
  346. */
  347. struct pxa27x_request {
  348. struct usb_request req;
  349. struct udc_usb_ep *udc_usb_ep;
  350. unsigned in_use:1;
  351. struct list_head queue;
  352. };
  353. enum ep0_state {
  354. WAIT_FOR_SETUP,
  355. SETUP_STAGE,
  356. IN_DATA_STAGE,
  357. OUT_DATA_STAGE,
  358. IN_STATUS_STAGE,
  359. OUT_STATUS_STAGE,
  360. STALL,
  361. WAIT_ACK_SET_CONF_INTERF
  362. };
  363. static char *ep0_state_name[] = {
  364. "WAIT_FOR_SETUP", "SETUP_STAGE", "IN_DATA_STAGE", "OUT_DATA_STAGE",
  365. "IN_STATUS_STAGE", "OUT_STATUS_STAGE", "STALL",
  366. "WAIT_ACK_SET_CONF_INTERF"
  367. };
  368. #define EP0_STNAME(udc) ep0_state_name[(udc)->ep0state]
  369. #define EP0_FIFO_SIZE 16U
  370. #define BULK_FIFO_SIZE 64U
  371. #define ISO_FIFO_SIZE 256U
  372. #define INT_FIFO_SIZE 16U
  373. struct udc_stats {
  374. unsigned long irqs_reset;
  375. unsigned long irqs_suspend;
  376. unsigned long irqs_resume;
  377. unsigned long irqs_reconfig;
  378. };
  379. #define NR_USB_ENDPOINTS (1 + 5) /* ep0 + ep1in-bulk + .. + ep3in-iso */
  380. #define NR_PXA_ENDPOINTS (1 + 14) /* ep0 + epA + epB + .. + epX */
  381. /**
  382. * struct pxa_udc - udc structure
  383. * @regs: mapped IO space
  384. * @irq: udc irq
  385. * @clk: udc clock
  386. * @usb_gadget: udc gadget structure
  387. * @driver: bound gadget (zero, g_ether, g_file_storage, ...)
  388. * @dev: device
  389. * @mach: machine info, used to activate specific GPIO
  390. * @ep0state: control endpoint state machine state
  391. * @stats: statistics on udc usage
  392. * @udc_usb_ep: array of usb endpoints offered by the gadget
  393. * @pxa_ep: array of pxa available endpoints
  394. * @config: UDC active configuration
  395. * @last_interface: UDC interface of the last SET_INTERFACE host request
  396. * @last_alternate: UDC altsetting of the last SET_INTERFACE host request
  397. * @udccsr0: save of udccsr0 in case of suspend
  398. * @debugfs_root: root entry of debug filesystem
  399. * @debugfs_state: debugfs entry for "udcstate"
  400. * @debugfs_queues: debugfs entry for "queues"
  401. * @debugfs_eps: debugfs entry for "epstate"
  402. */
  403. struct pxa_udc {
  404. void __iomem *regs;
  405. int irq;
  406. struct clk *clk;
  407. struct usb_gadget gadget;
  408. struct usb_gadget_driver *driver;
  409. struct device *dev;
  410. struct pxa2xx_udc_mach_info *mach;
  411. enum ep0_state ep0state;
  412. struct udc_stats stats;
  413. struct udc_usb_ep udc_usb_ep[NR_USB_ENDPOINTS];
  414. struct pxa_ep pxa_ep[NR_PXA_ENDPOINTS];
  415. unsigned config:2;
  416. unsigned last_interface:3;
  417. unsigned last_alternate:3;
  418. #ifdef CONFIG_PM
  419. unsigned udccsr0;
  420. #endif
  421. #ifdef CONFIG_USB_GADGET_DEBUG_FS
  422. struct dentry *debugfs_root;
  423. struct dentry *debugfs_state;
  424. struct dentry *debugfs_queues;
  425. struct dentry *debugfs_eps;
  426. #endif
  427. };
  428. static inline struct pxa_udc *to_gadget_udc(struct usb_gadget *gadget)
  429. {
  430. return container_of(gadget, struct pxa_udc, gadget);
  431. }
  432. /*
  433. * Debugging/message support
  434. */
  435. #define ep_dbg(ep, fmt, arg...) \
  436. dev_dbg(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
  437. #define ep_vdbg(ep, fmt, arg...) \
  438. dev_vdbg(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
  439. #define ep_err(ep, fmt, arg...) \
  440. dev_err(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
  441. #define ep_info(ep, fmt, arg...) \
  442. dev_info(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
  443. #define ep_warn(ep, fmt, arg...) \
  444. dev_warn(ep->dev->dev, "%s:%s:" fmt, EPNAME(ep), __func__, ## arg)
  445. #endif /* __LINUX_USB_GADGET_PXA27X_H */