imx21-hcd.h 12 KB

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