oxu210hp.h 14 KB

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