imx21-hcd.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*
  2. * Macros and prototypes for i.MX21
  3. *
  4. * Copyright (C) 2006 Loping Dog Embedded Systems
  5. * Copyright (C) 2009 Martin Fuzzey
  6. * Originally written by Jay Monkman <jtm@lopingdog.com>
  7. * Ported to 2.6.30, debugged and enhanced by Martin Fuzzey
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. * 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 Foundation,
  21. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #ifndef __LINUX_IMX21_HCD_H__
  24. #define __LINUX_IMX21_HCD_H__
  25. #include <mach/mx21-usbhost.h>
  26. #define NUM_ISO_ETDS 2
  27. #define USB_NUM_ETD 32
  28. #define DMEM_SIZE 4096
  29. /* Register definitions */
  30. #define USBOTG_HWMODE 0x00
  31. #define USBOTG_HWMODE_ANASDBEN (1 << 14)
  32. #define USBOTG_HWMODE_OTGXCVR_SHIFT 6
  33. #define USBOTG_HWMODE_OTGXCVR_MASK (3 << 6)
  34. #define USBOTG_HWMODE_OTGXCVR_TD_RD (0 << 6)
  35. #define USBOTG_HWMODE_OTGXCVR_TS_RD (2 << 6)
  36. #define USBOTG_HWMODE_OTGXCVR_TD_RS (1 << 6)
  37. #define USBOTG_HWMODE_OTGXCVR_TS_RS (3 << 6)
  38. #define USBOTG_HWMODE_HOSTXCVR_SHIFT 4
  39. #define USBOTG_HWMODE_HOSTXCVR_MASK (3 << 4)
  40. #define USBOTG_HWMODE_HOSTXCVR_TD_RD (0 << 4)
  41. #define USBOTG_HWMODE_HOSTXCVR_TS_RD (2 << 4)
  42. #define USBOTG_HWMODE_HOSTXCVR_TD_RS (1 << 4)
  43. #define USBOTG_HWMODE_HOSTXCVR_TS_RS (3 << 4)
  44. #define USBOTG_HWMODE_CRECFG_MASK (3 << 0)
  45. #define USBOTG_HWMODE_CRECFG_HOST (1 << 0)
  46. #define USBOTG_HWMODE_CRECFG_FUNC (2 << 0)
  47. #define USBOTG_HWMODE_CRECFG_HNP (3 << 0)
  48. #define USBOTG_CINT_STAT 0x04
  49. #define USBOTG_CINT_STEN 0x08
  50. #define USBOTG_ASHNPINT (1 << 5)
  51. #define USBOTG_ASFCINT (1 << 4)
  52. #define USBOTG_ASHCINT (1 << 3)
  53. #define USBOTG_SHNPINT (1 << 2)
  54. #define USBOTG_FCINT (1 << 1)
  55. #define USBOTG_HCINT (1 << 0)
  56. #define USBOTG_CLK_CTRL 0x0c
  57. #define USBOTG_CLK_CTRL_FUNC (1 << 2)
  58. #define USBOTG_CLK_CTRL_HST (1 << 1)
  59. #define USBOTG_CLK_CTRL_MAIN (1 << 0)
  60. #define USBOTG_RST_CTRL 0x10
  61. #define USBOTG_RST_RSTI2C (1 << 15)
  62. #define USBOTG_RST_RSTCTRL (1 << 5)
  63. #define USBOTG_RST_RSTFC (1 << 4)
  64. #define USBOTG_RST_RSTFSKE (1 << 3)
  65. #define USBOTG_RST_RSTRH (1 << 2)
  66. #define USBOTG_RST_RSTHSIE (1 << 1)
  67. #define USBOTG_RST_RSTHC (1 << 0)
  68. #define USBOTG_FRM_INTVL 0x14
  69. #define USBOTG_FRM_REMAIN 0x18
  70. #define USBOTG_HNP_CSR 0x1c
  71. #define USBOTG_HNP_ISR 0x2c
  72. #define USBOTG_HNP_IEN 0x30
  73. #define USBOTG_I2C_TXCVR_REG(x) (0x100 + (x))
  74. #define USBOTG_I2C_XCVR_DEVAD 0x118
  75. #define USBOTG_I2C_SEQ_OP_REG 0x119
  76. #define USBOTG_I2C_SEQ_RD_STARTAD 0x11a
  77. #define USBOTG_I2C_OP_CTRL_REG 0x11b
  78. #define USBOTG_I2C_SCLK_TO_SCK_HPER 0x11e
  79. #define USBOTG_I2C_MASTER_INT_REG 0x11f
  80. #define USBH_HOST_CTRL 0x80
  81. #define USBH_HOST_CTRL_HCRESET (1 << 31)
  82. #define USBH_HOST_CTRL_SCHDOVR(x) ((x) << 16)
  83. #define USBH_HOST_CTRL_RMTWUEN (1 << 4)
  84. #define USBH_HOST_CTRL_HCUSBSTE_RESET (0 << 2)
  85. #define USBH_HOST_CTRL_HCUSBSTE_RESUME (1 << 2)
  86. #define USBH_HOST_CTRL_HCUSBSTE_OPERATIONAL (2 << 2)
  87. #define USBH_HOST_CTRL_HCUSBSTE_SUSPEND (3 << 2)
  88. #define USBH_HOST_CTRL_CTLBLKSR_1 (0 << 0)
  89. #define USBH_HOST_CTRL_CTLBLKSR_2 (1 << 0)
  90. #define USBH_HOST_CTRL_CTLBLKSR_3 (2 << 0)
  91. #define USBH_HOST_CTRL_CTLBLKSR_4 (3 << 0)
  92. #define USBH_SYSISR 0x88
  93. #define USBH_SYSISR_PSCINT (1 << 6)
  94. #define USBH_SYSISR_FMOFINT (1 << 5)
  95. #define USBH_SYSISR_HERRINT (1 << 4)
  96. #define USBH_SYSISR_RESDETINT (1 << 3)
  97. #define USBH_SYSISR_SOFINT (1 << 2)
  98. #define USBH_SYSISR_DONEINT (1 << 1)
  99. #define USBH_SYSISR_SORINT (1 << 0)
  100. #define USBH_SYSIEN 0x8c
  101. #define USBH_SYSIEN_PSCINT (1 << 6)
  102. #define USBH_SYSIEN_FMOFINT (1 << 5)
  103. #define USBH_SYSIEN_HERRINT (1 << 4)
  104. #define USBH_SYSIEN_RESDETINT (1 << 3)
  105. #define USBH_SYSIEN_SOFINT (1 << 2)
  106. #define USBH_SYSIEN_DONEINT (1 << 1)
  107. #define USBH_SYSIEN_SORINT (1 << 0)
  108. #define USBH_XBUFSTAT 0x98
  109. #define USBH_YBUFSTAT 0x9c
  110. #define USBH_XYINTEN 0xa0
  111. #define USBH_XFILLSTAT 0xa8
  112. #define USBH_YFILLSTAT 0xac
  113. #define USBH_ETDENSET 0xc0
  114. #define USBH_ETDENCLR 0xc4
  115. #define USBH_IMMEDINT 0xcc
  116. #define USBH_ETDDONESTAT 0xd0
  117. #define USBH_ETDDONEEN 0xd4
  118. #define USBH_FRMNUB 0xe0
  119. #define USBH_LSTHRESH 0xe4
  120. #define USBH_ROOTHUBA 0xe8
  121. #define USBH_ROOTHUBA_PWRTOGOOD_MASK (0xff)
  122. #define USBH_ROOTHUBA_PWRTOGOOD_SHIFT (24)
  123. #define USBH_ROOTHUBA_NOOVRCURP (1 << 12)
  124. #define USBH_ROOTHUBA_OVRCURPM (1 << 11)
  125. #define USBH_ROOTHUBA_DEVTYPE (1 << 10)
  126. #define USBH_ROOTHUBA_PWRSWTMD (1 << 9)
  127. #define USBH_ROOTHUBA_NOPWRSWT (1 << 8)
  128. #define USBH_ROOTHUBA_NDNSTMPRT_MASK (0xff)
  129. #define USBH_ROOTHUBB 0xec
  130. #define USBH_ROOTHUBB_PRTPWRCM(x) (1 << ((x) + 16))
  131. #define USBH_ROOTHUBB_DEVREMOVE(x) (1 << (x))
  132. #define USBH_ROOTSTAT 0xf0
  133. #define USBH_ROOTSTAT_CLRRMTWUE (1 << 31)
  134. #define USBH_ROOTSTAT_OVRCURCHG (1 << 17)
  135. #define USBH_ROOTSTAT_DEVCONWUE (1 << 15)
  136. #define USBH_ROOTSTAT_OVRCURI (1 << 1)
  137. #define USBH_ROOTSTAT_LOCPWRS (1 << 0)
  138. #define USBH_PORTSTAT(x) (0xf4 + ((x) * 4))
  139. #define USBH_PORTSTAT_PRTRSTSC (1 << 20)
  140. #define USBH_PORTSTAT_OVRCURIC (1 << 19)
  141. #define USBH_PORTSTAT_PRTSTATSC (1 << 18)
  142. #define USBH_PORTSTAT_PRTENBLSC (1 << 17)
  143. #define USBH_PORTSTAT_CONNECTSC (1 << 16)
  144. #define USBH_PORTSTAT_LSDEVCON (1 << 9)
  145. #define USBH_PORTSTAT_PRTPWRST (1 << 8)
  146. #define USBH_PORTSTAT_PRTRSTST (1 << 4)
  147. #define USBH_PORTSTAT_PRTOVRCURI (1 << 3)
  148. #define USBH_PORTSTAT_PRTSUSPST (1 << 2)
  149. #define USBH_PORTSTAT_PRTENABST (1 << 1)
  150. #define USBH_PORTSTAT_CURCONST (1 << 0)
  151. #define USB_DMAREV 0x800
  152. #define USB_DMAINTSTAT 0x804
  153. #define USB_DMAINTSTAT_EPERR (1 << 1)
  154. #define USB_DMAINTSTAT_ETDERR (1 << 0)
  155. #define USB_DMAINTEN 0x808
  156. #define USB_DMAINTEN_EPERRINTEN (1 << 1)
  157. #define USB_DMAINTEN_ETDERRINTEN (1 << 0)
  158. #define USB_ETDDMAERSTAT 0x80c
  159. #define USB_EPDMAERSTAT 0x810
  160. #define USB_ETDDMAEN 0x820
  161. #define USB_EPDMAEN 0x824
  162. #define USB_ETDDMAXTEN 0x828
  163. #define USB_EPDMAXTEN 0x82c
  164. #define USB_ETDDMAENXYT 0x830
  165. #define USB_EPDMAENXYT 0x834
  166. #define USB_ETDDMABST4EN 0x838
  167. #define USB_EPDMABST4EN 0x83c
  168. #define USB_MISCCONTROL 0x840
  169. #define USB_MISCCONTROL_ISOPREVFRM (1 << 3)
  170. #define USB_MISCCONTROL_SKPRTRY (1 << 2)
  171. #define USB_MISCCONTROL_ARBMODE (1 << 1)
  172. #define USB_MISCCONTROL_FILTCC (1 << 0)
  173. #define USB_ETDDMACHANLCLR 0x848
  174. #define USB_EPDMACHANLCLR 0x84c
  175. #define USB_ETDSMSA(x) (0x900 + ((x) * 4))
  176. #define USB_EPSMSA(x) (0x980 + ((x) * 4))
  177. #define USB_ETDDMABUFPTR(x) (0xa00 + ((x) * 4))
  178. #define USB_EPDMABUFPTR(x) (0xa80 + ((x) * 4))
  179. #define USB_ETD_DWORD(x, w) (0x200 + ((x) * 16) + ((w) * 4))
  180. #define DW0_ADDRESS 0
  181. #define DW0_ENDPNT 7
  182. #define DW0_DIRECT 11
  183. #define DW0_SPEED 13
  184. #define DW0_FORMAT 14
  185. #define DW0_MAXPKTSIZ 16
  186. #define DW0_HALTED 27
  187. #define DW0_TOGCRY 28
  188. #define DW0_SNDNAK 30
  189. #define DW1_XBUFSRTAD 0
  190. #define DW1_YBUFSRTAD 16
  191. #define DW2_RTRYDELAY 0
  192. #define DW2_POLINTERV 0
  193. #define DW2_STARTFRM 0
  194. #define DW2_RELPOLPOS 8
  195. #define DW2_DIRPID 16
  196. #define DW2_BUFROUND 18
  197. #define DW2_DELAYINT 19
  198. #define DW2_DATATOG 22
  199. #define DW2_ERRORCNT 24
  200. #define DW2_COMPCODE 28
  201. #define DW3_TOTBYECNT 0
  202. #define DW3_PKTLEN0 0
  203. #define DW3_COMPCODE0 12
  204. #define DW3_PKTLEN1 16
  205. #define DW3_BUFSIZE 21
  206. #define DW3_COMPCODE1 28
  207. #define USBCTRL 0x600
  208. #define USBCTRL_I2C_WU_INT_STAT (1 << 27)
  209. #define USBCTRL_OTG_WU_INT_STAT (1 << 26)
  210. #define USBCTRL_HOST_WU_INT_STAT (1 << 25)
  211. #define USBCTRL_FNT_WU_INT_STAT (1 << 24)
  212. #define USBCTRL_I2C_WU_INT_EN (1 << 19)
  213. #define USBCTRL_OTG_WU_INT_EN (1 << 18)
  214. #define USBCTRL_HOST_WU_INT_EN (1 << 17)
  215. #define USBCTRL_FNT_WU_INT_EN (1 << 16)
  216. #define USBCTRL_OTC_RCV_RXDP (1 << 13)
  217. #define USBCTRL_HOST1_BYP_TLL (1 << 12)
  218. #define USBCTRL_OTG_BYP_VAL(x) ((x) << 10)
  219. #define USBCTRL_HOST1_BYP_VAL(x) ((x) << 8)
  220. #define USBCTRL_OTG_PWR_MASK (1 << 6)
  221. #define USBCTRL_HOST1_PWR_MASK (1 << 5)
  222. #define USBCTRL_HOST2_PWR_MASK (1 << 4)
  223. #define USBCTRL_USB_BYP (1 << 2)
  224. #define USBCTRL_HOST1_TXEN_OE (1 << 1)
  225. #define USBOTG_DMEM 0x1000
  226. /* Values in TD blocks */
  227. #define TD_DIR_SETUP 0
  228. #define TD_DIR_OUT 1
  229. #define TD_DIR_IN 2
  230. #define TD_FORMAT_CONTROL 0
  231. #define TD_FORMAT_ISO 1
  232. #define TD_FORMAT_BULK 2
  233. #define TD_FORMAT_INT 3
  234. #define TD_TOGGLE_CARRY 0
  235. #define TD_TOGGLE_DATA0 2
  236. #define TD_TOGGLE_DATA1 3
  237. /* control transfer states */
  238. #define US_CTRL_SETUP 2
  239. #define US_CTRL_DATA 1
  240. #define US_CTRL_ACK 0
  241. /* bulk transfer main state and 0-length packet */
  242. #define US_BULK 1
  243. #define US_BULK0 0
  244. /*ETD format description*/
  245. #define IMX_FMT_CTRL 0x0
  246. #define IMX_FMT_ISO 0x1
  247. #define IMX_FMT_BULK 0x2
  248. #define IMX_FMT_INT 0x3
  249. static char fmt_urb_to_etd[4] = {
  250. /*PIPE_ISOCHRONOUS*/ IMX_FMT_ISO,
  251. /*PIPE_INTERRUPT*/ IMX_FMT_INT,
  252. /*PIPE_CONTROL*/ IMX_FMT_CTRL,
  253. /*PIPE_BULK*/ IMX_FMT_BULK
  254. };
  255. /* condition (error) CC codes and mapping (OHCI like) */
  256. #define TD_CC_NOERROR 0x00
  257. #define TD_CC_CRC 0x01
  258. #define TD_CC_BITSTUFFING 0x02
  259. #define TD_CC_DATATOGGLEM 0x03
  260. #define TD_CC_STALL 0x04
  261. #define TD_DEVNOTRESP 0x05
  262. #define TD_PIDCHECKFAIL 0x06
  263. /*#define TD_UNEXPECTEDPID 0x07 - reserved, not active on MX2*/
  264. #define TD_DATAOVERRUN 0x08
  265. #define TD_DATAUNDERRUN 0x09
  266. #define TD_BUFFEROVERRUN 0x0C
  267. #define TD_BUFFERUNDERRUN 0x0D
  268. #define TD_SCHEDULEOVERRUN 0x0E
  269. #define TD_NOTACCESSED 0x0F
  270. static const int cc_to_error[16] = {
  271. /* No Error */ 0,
  272. /* CRC Error */ -EILSEQ,
  273. /* Bit Stuff */ -EPROTO,
  274. /* Data Togg */ -EILSEQ,
  275. /* Stall */ -EPIPE,
  276. /* DevNotResp */ -ETIMEDOUT,
  277. /* PIDCheck */ -EPROTO,
  278. /* UnExpPID */ -EPROTO,
  279. /* DataOver */ -EOVERFLOW,
  280. /* DataUnder */ -EREMOTEIO,
  281. /* (for hw) */ -EIO,
  282. /* (for hw) */ -EIO,
  283. /* BufferOver */ -ECOMM,
  284. /* BuffUnder */ -ENOSR,
  285. /* (for HCD) */ -ENOSPC,
  286. /* (for HCD) */ -EALREADY
  287. };
  288. /* HCD data associated with a usb core URB */
  289. struct urb_priv {
  290. struct urb *urb;
  291. struct usb_host_endpoint *ep;
  292. int active;
  293. int state;
  294. struct td *isoc_td;
  295. int isoc_remaining;
  296. int isoc_status;
  297. };
  298. /* HCD data associated with a usb core endpoint */
  299. struct ep_priv {
  300. struct usb_host_endpoint *ep;
  301. struct list_head td_list;
  302. struct list_head queue;
  303. int etd[NUM_ISO_ETDS];
  304. int waiting_etd;
  305. };
  306. /* isoc packet */
  307. struct td {
  308. struct list_head list;
  309. struct urb *urb;
  310. struct usb_host_endpoint *ep;
  311. dma_addr_t dma_handle;
  312. void *cpu_buffer;
  313. int len;
  314. int frame;
  315. int isoc_index;
  316. };
  317. /* HCD data associated with a hardware ETD */
  318. struct etd_priv {
  319. struct usb_host_endpoint *ep;
  320. struct urb *urb;
  321. struct td *td;
  322. struct list_head queue;
  323. dma_addr_t dma_handle;
  324. void *cpu_buffer;
  325. void *bounce_buffer;
  326. int alloc;
  327. int len;
  328. int dmem_size;
  329. int dmem_offset;
  330. int active_count;
  331. #ifdef DEBUG
  332. int activated_frame;
  333. int disactivated_frame;
  334. int last_int_frame;
  335. int last_req_frame;
  336. u32 submitted_dwords[4];
  337. #endif
  338. };
  339. /* Hardware data memory info */
  340. struct imx21_dmem_area {
  341. struct usb_host_endpoint *ep;
  342. unsigned int offset;
  343. unsigned int size;
  344. struct list_head list;
  345. };
  346. #ifdef DEBUG
  347. struct debug_usage_stats {
  348. unsigned int value;
  349. unsigned int maximum;
  350. };
  351. struct debug_stats {
  352. unsigned long submitted;
  353. unsigned long completed_ok;
  354. unsigned long completed_failed;
  355. unsigned long unlinked;
  356. unsigned long queue_etd;
  357. unsigned long queue_dmem;
  358. };
  359. struct debug_isoc_trace {
  360. int schedule_frame;
  361. int submit_frame;
  362. int request_len;
  363. int done_frame;
  364. int done_len;
  365. int cc;
  366. struct td *td;
  367. };
  368. #endif
  369. /* HCD data structure */
  370. struct imx21 {
  371. spinlock_t lock;
  372. struct device *dev;
  373. struct usb_hcd *hcd;
  374. struct mx21_usbh_platform_data *pdata;
  375. struct list_head dmem_list;
  376. struct list_head queue_for_etd; /* eps queued due to etd shortage */
  377. struct list_head queue_for_dmem; /* etds queued due to dmem shortage */
  378. struct etd_priv etd[USB_NUM_ETD];
  379. struct clk *clk;
  380. void __iomem *regs;
  381. #ifdef DEBUG
  382. struct dentry *debug_root;
  383. struct debug_stats nonisoc_stats;
  384. struct debug_stats isoc_stats;
  385. struct debug_usage_stats etd_usage;
  386. struct debug_usage_stats dmem_usage;
  387. struct debug_isoc_trace isoc_trace[20];
  388. struct debug_isoc_trace isoc_trace_failed[20];
  389. unsigned long debug_unblocks;
  390. int isoc_trace_index;
  391. int isoc_trace_index_failed;
  392. #endif
  393. };
  394. #endif