imx21-hcd.h 12 KB

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