pxa27x_udc.h 19 KB

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