oxu210hp.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * Host interface registers
  3. */
  4. #define OXU_DEVICEID 0x00
  5. #define OXU_REV_MASK 0xffff0000
  6. #define OXU_REV_SHIFT 16
  7. #define OXU_REV_2100 0x2100
  8. #define OXU_BO_SHIFT 8
  9. #define OXU_BO_MASK (0x3 << OXU_BO_SHIFT)
  10. #define OXU_MAJ_REV_SHIFT 4
  11. #define OXU_MAJ_REV_MASK (0xf << OXU_MAJ_REV_SHIFT)
  12. #define OXU_MIN_REV_SHIFT 0
  13. #define OXU_MIN_REV_MASK (0xf << OXU_MIN_REV_SHIFT)
  14. #define OXU_HOSTIFCONFIG 0x04
  15. #define OXU_SOFTRESET 0x08
  16. #define OXU_SRESET (1 << 0)
  17. #define OXU_PIOBURSTREADCTRL 0x0C
  18. #define OXU_CHIPIRQSTATUS 0x10
  19. #define OXU_CHIPIRQEN_SET 0x14
  20. #define OXU_CHIPIRQEN_CLR 0x18
  21. #define OXU_USBSPHLPWUI 0x00000080
  22. #define OXU_USBOTGLPWUI 0x00000040
  23. #define OXU_USBSPHI 0x00000002
  24. #define OXU_USBOTGI 0x00000001
  25. #define OXU_CLKCTRL_SET 0x1C
  26. #define OXU_SYSCLKEN 0x00000008
  27. #define OXU_USBSPHCLKEN 0x00000002
  28. #define OXU_USBOTGCLKEN 0x00000001
  29. #define OXU_ASO 0x68
  30. #define OXU_SPHPOEN 0x00000100
  31. #define OXU_OVRCCURPUPDEN 0x00000800
  32. #define OXU_ASO_OP (1 << 10)
  33. #define OXU_COMPARATOR 0x000004000
  34. #define OXU_USBMODE 0x1A8
  35. #define OXU_VBPS 0x00000020
  36. #define OXU_ES_LITTLE 0x00000000
  37. #define OXU_CM_HOST_ONLY 0x00000003
  38. /*
  39. * Proper EHCI structs & defines
  40. */
  41. /* Magic numbers that can affect system performance */
  42. #define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
  43. #define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
  44. #define EHCI_TUNE_RL_TT 0
  45. #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
  46. #define EHCI_TUNE_MULT_TT 1
  47. #define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
  48. struct oxu_hcd;
  49. /* EHCI register interface, corresponds to EHCI Revision 0.95 specification */
  50. /* Section 2.2 Host Controller Capability Registers */
  51. struct ehci_caps {
  52. /* these fields are specified as 8 and 16 bit registers,
  53. * but some hosts can't perform 8 or 16 bit PCI accesses.
  54. */
  55. u32 hc_capbase;
  56. #define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */
  57. #define HC_VERSION(p) (((p)>>16)&0xffff) /* bits 31:16 */
  58. u32 hcs_params; /* HCSPARAMS - offset 0x4 */
  59. #define HCS_DEBUG_PORT(p) (((p)>>20)&0xf) /* bits 23:20, debug port? */
  60. #define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */
  61. #define HCS_N_CC(p) (((p)>>12)&0xf) /* bits 15:12, #companion HCs */
  62. #define HCS_N_PCC(p) (((p)>>8)&0xf) /* bits 11:8, ports per CC */
  63. #define HCS_PORTROUTED(p) ((p)&(1 << 7)) /* true: port routing */
  64. #define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */
  65. #define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */
  66. u32 hcc_params; /* HCCPARAMS - offset 0x8 */
  67. #define HCC_EXT_CAPS(p) (((p)>>8)&0xff) /* for pci extended caps */
  68. #define HCC_ISOC_CACHE(p) ((p)&(1 << 7)) /* true: can cache isoc frame */
  69. #define HCC_ISOC_THRES(p) (((p)>>4)&0x7) /* bits 6:4, uframes cached */
  70. #define HCC_CANPARK(p) ((p)&(1 << 2)) /* true: can park on async qh */
  71. #define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1)) /* true: periodic_size changes*/
  72. #define HCC_64BIT_ADDR(p) ((p)&(1)) /* true: can use 64-bit addr */
  73. u8 portroute[8]; /* nibbles for routing - offset 0xC */
  74. } __attribute__ ((packed));
  75. /* Section 2.3 Host Controller Operational Registers */
  76. struct ehci_regs {
  77. /* USBCMD: offset 0x00 */
  78. u32 command;
  79. /* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */
  80. #define CMD_PARK (1<<11) /* enable "park" on async qh */
  81. #define CMD_PARK_CNT(c) (((c)>>8)&3) /* how many transfers to park for */
  82. #define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */
  83. #define CMD_IAAD (1<<6) /* "doorbell" interrupt async advance */
  84. #define CMD_ASE (1<<5) /* async schedule enable */
  85. #define CMD_PSE (1<<4) /* periodic schedule enable */
  86. /* 3:2 is periodic frame list size */
  87. #define CMD_RESET (1<<1) /* reset HC not bus */
  88. #define CMD_RUN (1<<0) /* start/stop HC */
  89. /* USBSTS: offset 0x04 */
  90. u32 status;
  91. #define STS_ASS (1<<15) /* Async Schedule Status */
  92. #define STS_PSS (1<<14) /* Periodic Schedule Status */
  93. #define STS_RECL (1<<13) /* Reclamation */
  94. #define STS_HALT (1<<12) /* Not running (any reason) */
  95. /* some bits reserved */
  96. /* these STS_* flags are also intr_enable bits (USBINTR) */
  97. #define STS_IAA (1<<5) /* Interrupted on async advance */
  98. #define STS_FATAL (1<<4) /* such as some PCI access errors */
  99. #define STS_FLR (1<<3) /* frame list rolled over */
  100. #define STS_PCD (1<<2) /* port change detect */
  101. #define STS_ERR (1<<1) /* "error" completion (overflow, ...) */
  102. #define STS_INT (1<<0) /* "normal" completion (short, ...) */
  103. #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
  104. /* USBINTR: offset 0x08 */
  105. u32 intr_enable;
  106. /* FRINDEX: offset 0x0C */
  107. u32 frame_index; /* current microframe number */
  108. /* CTRLDSSEGMENT: offset 0x10 */
  109. u32 segment; /* address bits 63:32 if needed */
  110. /* PERIODICLISTBASE: offset 0x14 */
  111. u32 frame_list; /* points to periodic list */
  112. /* ASYNCLISTADDR: offset 0x18 */
  113. u32 async_next; /* address of next async queue head */
  114. u32 reserved[9];
  115. /* CONFIGFLAG: offset 0x40 */
  116. u32 configured_flag;
  117. #define FLAG_CF (1<<0) /* true: we'll support "high speed" */
  118. /* PORTSC: offset 0x44 */
  119. u32 port_status[0]; /* up to N_PORTS */
  120. /* 31:23 reserved */
  121. #define PORT_WKOC_E (1<<22) /* wake on overcurrent (enable) */
  122. #define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */
  123. #define PORT_WKCONN_E (1<<20) /* wake on connect (enable) */
  124. /* 19:16 for port testing */
  125. #define PORT_LED_OFF (0<<14)
  126. #define PORT_LED_AMBER (1<<14)
  127. #define PORT_LED_GREEN (2<<14)
  128. #define PORT_LED_MASK (3<<14)
  129. #define PORT_OWNER (1<<13) /* true: companion hc owns this port */
  130. #define PORT_POWER (1<<12) /* true: has power (see PPC) */
  131. #define PORT_USB11(x) (((x)&(3<<10)) == (1<<10)) /* USB 1.1 device */
  132. /* 11:10 for detecting lowspeed devices (reset vs release ownership) */
  133. /* 9 reserved */
  134. #define PORT_RESET (1<<8) /* reset port */
  135. #define PORT_SUSPEND (1<<7) /* suspend port */
  136. #define PORT_RESUME (1<<6) /* resume it */
  137. #define PORT_OCC (1<<5) /* over current change */
  138. #define PORT_OC (1<<4) /* over current active */
  139. #define PORT_PEC (1<<3) /* port enable change */
  140. #define PORT_PE (1<<2) /* port enable */
  141. #define PORT_CSC (1<<1) /* connect status change */
  142. #define PORT_CONNECT (1<<0) /* device connected */
  143. #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
  144. } __attribute__ ((packed));
  145. /* Appendix C, Debug port ... intended for use with special "debug devices"
  146. * that can help if there's no serial console. (nonstandard enumeration.)
  147. */
  148. struct ehci_dbg_port {
  149. u32 control;
  150. #define DBGP_OWNER (1<<30)
  151. #define DBGP_ENABLED (1<<28)
  152. #define DBGP_DONE (1<<16)
  153. #define DBGP_INUSE (1<<10)
  154. #define DBGP_ERRCODE(x) (((x)>>7)&0x07)
  155. # define DBGP_ERR_BAD 1
  156. # define DBGP_ERR_SIGNAL 2
  157. #define DBGP_ERROR (1<<6)
  158. #define DBGP_GO (1<<5)
  159. #define DBGP_OUT (1<<4)
  160. #define DBGP_LEN(x) (((x)>>0)&0x0f)
  161. u32 pids;
  162. #define DBGP_PID_GET(x) (((x)>>16)&0xff)
  163. #define DBGP_PID_SET(data, tok) (((data)<<8)|(tok))
  164. u32 data03;
  165. u32 data47;
  166. u32 address;
  167. #define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep))
  168. } __attribute__ ((packed));
  169. #define QTD_NEXT(dma) cpu_to_le32((u32)dma)
  170. /*
  171. * EHCI Specification 0.95 Section 3.5
  172. * QTD: describe data transfer components (buffer, direction, ...)
  173. * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
  174. *
  175. * These are associated only with "QH" (Queue Head) structures,
  176. * used with control, bulk, and interrupt transfers.
  177. */
  178. struct ehci_qtd {
  179. /* first part defined by EHCI spec */
  180. __le32 hw_next; /* see EHCI 3.5.1 */
  181. __le32 hw_alt_next; /* see EHCI 3.5.2 */
  182. __le32 hw_token; /* see EHCI 3.5.3 */
  183. #define QTD_TOGGLE (1 << 31) /* data toggle */
  184. #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
  185. #define QTD_IOC (1 << 15) /* interrupt on complete */
  186. #define QTD_CERR(tok) (((tok)>>10) & 0x3)
  187. #define QTD_PID(tok) (((tok)>>8) & 0x3)
  188. #define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */
  189. #define QTD_STS_HALT (1 << 6) /* halted on error */
  190. #define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */
  191. #define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */
  192. #define QTD_STS_XACT (1 << 3) /* device gave illegal response */
  193. #define QTD_STS_MMF (1 << 2) /* incomplete split transaction */
  194. #define QTD_STS_STS (1 << 1) /* split transaction state */
  195. #define QTD_STS_PING (1 << 0) /* issue PING? */
  196. __le32 hw_buf[5]; /* see EHCI 3.5.4 */
  197. __le32 hw_buf_hi[5]; /* Appendix B */
  198. /* the rest is HCD-private */
  199. dma_addr_t qtd_dma; /* qtd address */
  200. struct list_head qtd_list; /* sw qtd list */
  201. struct urb *urb; /* qtd's urb */
  202. size_t length; /* length of buffer */
  203. u32 qtd_buffer_len;
  204. void *buffer;
  205. dma_addr_t buffer_dma;
  206. void *transfer_buffer;
  207. void *transfer_dma;
  208. } __attribute__ ((aligned(32)));
  209. /* mask NakCnt+T in qh->hw_alt_next */
  210. #define QTD_MASK cpu_to_le32 (~0x1f)
  211. #define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1)
  212. /* Type tag from {qh, itd, sitd, fstn}->hw_next */
  213. #define Q_NEXT_TYPE(dma) ((dma) & cpu_to_le32 (3 << 1))
  214. /* values for that type tag */
  215. #define Q_TYPE_QH cpu_to_le32 (1 << 1)
  216. /* next async queue entry, or pointer to interrupt/periodic QH */
  217. #define QH_NEXT(dma) (cpu_to_le32(((u32)dma)&~0x01f)|Q_TYPE_QH)
  218. /* for periodic/async schedules and qtd lists, mark end of list */
  219. #define EHCI_LIST_END cpu_to_le32(1) /* "null pointer" to hw */
  220. /*
  221. * Entries in periodic shadow table are pointers to one of four kinds
  222. * of data structure. That's dictated by the hardware; a type tag is
  223. * encoded in the low bits of the hardware's periodic schedule. Use
  224. * Q_NEXT_TYPE to get the tag.
  225. *
  226. * For entries in the async schedule, the type tag always says "qh".
  227. */
  228. union ehci_shadow {
  229. struct ehci_qh *qh; /* Q_TYPE_QH */
  230. __le32 *hw_next; /* (all types) */
  231. void *ptr;
  232. };
  233. /*
  234. * EHCI Specification 0.95 Section 3.6
  235. * QH: describes control/bulk/interrupt endpoints
  236. * See Fig 3-7 "Queue Head Structure Layout".
  237. *
  238. * These appear in both the async and (for interrupt) periodic schedules.
  239. */
  240. struct ehci_qh {
  241. /* first part defined by EHCI spec */
  242. __le32 hw_next; /* see EHCI 3.6.1 */
  243. __le32 hw_info1; /* see EHCI 3.6.2 */
  244. #define QH_HEAD 0x00008000
  245. __le32 hw_info2; /* see EHCI 3.6.2 */
  246. #define QH_SMASK 0x000000ff
  247. #define QH_CMASK 0x0000ff00
  248. #define QH_HUBADDR 0x007f0000
  249. #define QH_HUBPORT 0x3f800000
  250. #define QH_MULT 0xc0000000
  251. __le32 hw_current; /* qtd list - see EHCI 3.6.4 */
  252. /* qtd overlay (hardware parts of a struct ehci_qtd) */
  253. __le32 hw_qtd_next;
  254. __le32 hw_alt_next;
  255. __le32 hw_token;
  256. __le32 hw_buf[5];
  257. __le32 hw_buf_hi[5];
  258. /* the rest is HCD-private */
  259. dma_addr_t qh_dma; /* address of qh */
  260. union ehci_shadow qh_next; /* ptr to qh; or periodic */
  261. struct list_head qtd_list; /* sw qtd list */
  262. struct ehci_qtd *dummy;
  263. struct ehci_qh *reclaim; /* next to reclaim */
  264. struct oxu_hcd *oxu;
  265. struct kref kref;
  266. unsigned stamp;
  267. u8 qh_state;
  268. #define QH_STATE_LINKED 1 /* HC sees this */
  269. #define QH_STATE_UNLINK 2 /* HC may still see this */
  270. #define QH_STATE_IDLE 3 /* HC doesn't see this */
  271. #define QH_STATE_UNLINK_WAIT 4 /* LINKED and on reclaim q */
  272. #define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
  273. /* periodic schedule info */
  274. u8 usecs; /* intr bandwidth */
  275. u8 gap_uf; /* uframes split/csplit gap */
  276. u8 c_usecs; /* ... split completion bw */
  277. u16 tt_usecs; /* tt downstream bandwidth */
  278. unsigned short period; /* polling interval */
  279. unsigned short start; /* where polling starts */
  280. #define NO_FRAME ((unsigned short)~0) /* pick new start */
  281. struct usb_device *dev; /* access to TT */
  282. } __attribute__ ((aligned(32)));
  283. /*
  284. * Proper OXU210HP structs
  285. */
  286. #define OXU_OTG_CORE_OFFSET 0x00400
  287. #define OXU_OTG_CAP_OFFSET (OXU_OTG_CORE_OFFSET + 0x100)
  288. #define OXU_SPH_CORE_OFFSET 0x00800
  289. #define OXU_SPH_CAP_OFFSET (OXU_SPH_CORE_OFFSET + 0x100)
  290. #define OXU_OTG_MEM 0xE000
  291. #define OXU_SPH_MEM 0x16000
  292. /* Only how many elements & element structure are specifies here. */
  293. /* 2 host controllers are enabled - total size <= 28 kbytes */
  294. #define DEFAULT_I_TDPS 1024
  295. #define QHEAD_NUM 16
  296. #define QTD_NUM 32
  297. #define SITD_NUM 8
  298. #define MURB_NUM 8
  299. #define BUFFER_NUM 8
  300. #define BUFFER_SIZE 512
  301. struct oxu_info {
  302. struct usb_hcd *hcd[2];
  303. };
  304. struct oxu_buf {
  305. u8 buffer[BUFFER_SIZE];
  306. } __attribute__ ((aligned(BUFFER_SIZE)));
  307. struct oxu_onchip_mem {
  308. struct oxu_buf db_pool[BUFFER_NUM];
  309. u32 frame_list[DEFAULT_I_TDPS];
  310. struct ehci_qh qh_pool[QHEAD_NUM];
  311. struct ehci_qtd qtd_pool[QTD_NUM];
  312. } __attribute__ ((aligned(4 << 10)));
  313. #define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */
  314. struct oxu_murb {
  315. struct urb urb;
  316. struct urb *main;
  317. u8 last;
  318. };
  319. struct oxu_hcd { /* one per controller */
  320. unsigned int is_otg:1;
  321. u8 qh_used[QHEAD_NUM];
  322. u8 qtd_used[QTD_NUM];
  323. u8 db_used[BUFFER_NUM];
  324. u8 murb_used[MURB_NUM];
  325. struct oxu_onchip_mem __iomem *mem;
  326. spinlock_t mem_lock;
  327. struct timer_list urb_timer;
  328. struct ehci_caps __iomem *caps;
  329. struct ehci_regs __iomem *regs;
  330. __u32 hcs_params; /* cached register copy */
  331. spinlock_t lock;
  332. /* async schedule support */
  333. struct ehci_qh *async;
  334. struct ehci_qh *reclaim;
  335. unsigned reclaim_ready:1;
  336. unsigned scanning:1;
  337. /* periodic schedule support */
  338. unsigned periodic_size;
  339. __le32 *periodic; /* hw periodic table */
  340. dma_addr_t periodic_dma;
  341. unsigned i_thresh; /* uframes HC might cache */
  342. union ehci_shadow *pshadow; /* mirror hw periodic table */
  343. int next_uframe; /* scan periodic, start here */
  344. unsigned periodic_sched; /* periodic activity count */
  345. /* per root hub port */
  346. unsigned long reset_done[EHCI_MAX_ROOT_PORTS];
  347. /* bit vectors (one bit per port) */
  348. unsigned long bus_suspended; /* which ports were
  349. * already suspended at the
  350. * start of a bus suspend
  351. */
  352. unsigned long companion_ports;/* which ports are dedicated
  353. * to the companion controller
  354. */
  355. struct timer_list watchdog;
  356. unsigned long actions;
  357. unsigned stamp;
  358. unsigned long next_statechange;
  359. u32 command;
  360. /* SILICON QUIRKS */
  361. struct list_head urb_list; /* this is the head to urb
  362. * queue that didn't get enough
  363. * resources
  364. */
  365. struct oxu_murb *murb_pool; /* murb per split big urb */
  366. unsigned urb_len;
  367. u8 sbrn; /* packed release number */
  368. };
  369. #define EHCI_IAA_JIFFIES (HZ/100) /* arbitrary; ~10 msec */
  370. #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
  371. #define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
  372. #define EHCI_SHRINK_JIFFIES (HZ/200) /* async qh unlink delay */
  373. enum ehci_timer_action {
  374. TIMER_IO_WATCHDOG,
  375. TIMER_IAA_WATCHDOG,
  376. TIMER_ASYNC_SHRINK,
  377. TIMER_ASYNC_OFF,
  378. };
  379. #include <linux/oxu210hp.h>