fotg210.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. #ifndef __LINUX_FOTG210_H
  2. #define __LINUX_FOTG210_H
  3. /* definitions used for the EHCI driver */
  4. /*
  5. * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to
  6. * __leXX (normally) or __beXX (given FOTG210_BIG_ENDIAN_DESC), depending on
  7. * the host controller implementation.
  8. *
  9. * To facilitate the strongest possible byte-order checking from "sparse"
  10. * and so on, we use __leXX unless that's not practical.
  11. */
  12. #define __hc32 __le32
  13. #define __hc16 __le16
  14. /* statistics can be kept for tuning/monitoring */
  15. struct fotg210_stats {
  16. /* irq usage */
  17. unsigned long normal;
  18. unsigned long error;
  19. unsigned long iaa;
  20. unsigned long lost_iaa;
  21. /* termination of urbs from core */
  22. unsigned long complete;
  23. unsigned long unlink;
  24. };
  25. /* fotg210_hcd->lock guards shared data against other CPUs:
  26. * fotg210_hcd: async, unlink, periodic (and shadow), ...
  27. * usb_host_endpoint: hcpriv
  28. * fotg210_qh: qh_next, qtd_list
  29. * fotg210_qtd: qtd_list
  30. *
  31. * Also, hold this lock when talking to HC registers or
  32. * when updating hw_* fields in shared qh/qtd/... structures.
  33. */
  34. #define FOTG210_MAX_ROOT_PORTS 1 /* see HCS_N_PORTS */
  35. /*
  36. * fotg210_rh_state values of FOTG210_RH_RUNNING or above mean that the
  37. * controller may be doing DMA. Lower values mean there's no DMA.
  38. */
  39. enum fotg210_rh_state {
  40. FOTG210_RH_HALTED,
  41. FOTG210_RH_SUSPENDED,
  42. FOTG210_RH_RUNNING,
  43. FOTG210_RH_STOPPING
  44. };
  45. /*
  46. * Timer events, ordered by increasing delay length.
  47. * Always update event_delays_ns[] and event_handlers[] (defined in
  48. * ehci-timer.c) in parallel with this list.
  49. */
  50. enum fotg210_hrtimer_event {
  51. FOTG210_HRTIMER_POLL_ASS, /* Poll for async schedule off */
  52. FOTG210_HRTIMER_POLL_PSS, /* Poll for periodic schedule off */
  53. FOTG210_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */
  54. FOTG210_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */
  55. FOTG210_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */
  56. FOTG210_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */
  57. FOTG210_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */
  58. FOTG210_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */
  59. FOTG210_HRTIMER_DISABLE_ASYNC, /* Wait to disable async sched */
  60. FOTG210_HRTIMER_IO_WATCHDOG, /* Check for missing IRQs */
  61. FOTG210_HRTIMER_NUM_EVENTS /* Must come last */
  62. };
  63. #define FOTG210_HRTIMER_NO_EVENT 99
  64. struct fotg210_hcd { /* one per controller */
  65. /* timing support */
  66. enum fotg210_hrtimer_event next_hrtimer_event;
  67. unsigned enabled_hrtimer_events;
  68. ktime_t hr_timeouts[FOTG210_HRTIMER_NUM_EVENTS];
  69. struct hrtimer hrtimer;
  70. int PSS_poll_count;
  71. int ASS_poll_count;
  72. int died_poll_count;
  73. /* glue to PCI and HCD framework */
  74. struct fotg210_caps __iomem *caps;
  75. struct fotg210_regs __iomem *regs;
  76. struct fotg210_dbg_port __iomem *debug;
  77. __u32 hcs_params; /* cached register copy */
  78. spinlock_t lock;
  79. enum fotg210_rh_state rh_state;
  80. /* general schedule support */
  81. bool scanning:1;
  82. bool need_rescan:1;
  83. bool intr_unlinking:1;
  84. bool async_unlinking:1;
  85. bool shutdown:1;
  86. struct fotg210_qh *qh_scan_next;
  87. /* async schedule support */
  88. struct fotg210_qh *async;
  89. struct fotg210_qh *dummy; /* For AMD quirk use */
  90. struct fotg210_qh *async_unlink;
  91. struct fotg210_qh *async_unlink_last;
  92. struct fotg210_qh *async_iaa;
  93. unsigned async_unlink_cycle;
  94. unsigned async_count; /* async activity count */
  95. /* periodic schedule support */
  96. #define DEFAULT_I_TDPS 1024 /* some HCs can do less */
  97. unsigned periodic_size;
  98. __hc32 *periodic; /* hw periodic table */
  99. dma_addr_t periodic_dma;
  100. struct list_head intr_qh_list;
  101. unsigned i_thresh; /* uframes HC might cache */
  102. union fotg210_shadow *pshadow; /* mirror hw periodic table */
  103. struct fotg210_qh *intr_unlink;
  104. struct fotg210_qh *intr_unlink_last;
  105. unsigned intr_unlink_cycle;
  106. unsigned now_frame; /* frame from HC hardware */
  107. unsigned next_frame; /* scan periodic, start here */
  108. unsigned intr_count; /* intr activity count */
  109. unsigned isoc_count; /* isoc activity count */
  110. unsigned periodic_count; /* periodic activity count */
  111. /* max periodic time per uframe */
  112. unsigned uframe_periodic_max;
  113. /* list of itds completed while now_frame was still active */
  114. struct list_head cached_itd_list;
  115. struct fotg210_itd *last_itd_to_free;
  116. /* per root hub port */
  117. unsigned long reset_done[FOTG210_MAX_ROOT_PORTS];
  118. /* bit vectors (one bit per port) */
  119. unsigned long bus_suspended; /* which ports were
  120. already suspended at the start of a bus suspend */
  121. unsigned long companion_ports; /* which ports are
  122. dedicated to the companion controller */
  123. unsigned long owned_ports; /* which ports are
  124. owned by the companion during a bus suspend */
  125. unsigned long port_c_suspend; /* which ports have
  126. the change-suspend feature turned on */
  127. unsigned long suspended_ports; /* which ports are
  128. suspended */
  129. unsigned long resuming_ports; /* which ports have
  130. started to resume */
  131. /* per-HC memory pools (could be per-bus, but ...) */
  132. struct dma_pool *qh_pool; /* qh per active urb */
  133. struct dma_pool *qtd_pool; /* one or more per qh */
  134. struct dma_pool *itd_pool; /* itd per iso urb */
  135. unsigned random_frame;
  136. unsigned long next_statechange;
  137. ktime_t last_periodic_enable;
  138. u32 command;
  139. /* SILICON QUIRKS */
  140. unsigned need_io_watchdog:1;
  141. unsigned fs_i_thresh:1; /* Intel iso scheduling */
  142. u8 sbrn; /* packed release number */
  143. /* irq statistics */
  144. #ifdef FOTG210_STATS
  145. struct fotg210_stats stats;
  146. # define COUNT(x) ((x)++)
  147. #else
  148. # define COUNT(x)
  149. #endif
  150. /* debug files */
  151. #ifdef DEBUG
  152. struct dentry *debug_dir;
  153. #endif
  154. };
  155. /* convert between an HCD pointer and the corresponding FOTG210_HCD */
  156. static inline struct fotg210_hcd *hcd_to_fotg210(struct usb_hcd *hcd)
  157. {
  158. return (struct fotg210_hcd *)(hcd->hcd_priv);
  159. }
  160. static inline struct usb_hcd *fotg210_to_hcd(struct fotg210_hcd *fotg210)
  161. {
  162. return container_of((void *) fotg210, struct usb_hcd, hcd_priv);
  163. }
  164. /*-------------------------------------------------------------------------*/
  165. /* EHCI register interface, corresponds to EHCI Revision 0.95 specification */
  166. /* Section 2.2 Host Controller Capability Registers */
  167. struct fotg210_caps {
  168. /* these fields are specified as 8 and 16 bit registers,
  169. * but some hosts can't perform 8 or 16 bit PCI accesses.
  170. * some hosts treat caplength and hciversion as parts of a 32-bit
  171. * register, others treat them as two separate registers, this
  172. * affects the memory map for big endian controllers.
  173. */
  174. u32 hc_capbase;
  175. #define HC_LENGTH(fotg210, p) (0x00ff&((p) >> /* bits 7:0 / offset 00h */ \
  176. (fotg210_big_endian_capbase(fotg210) ? 24 : 0)))
  177. #define HC_VERSION(fotg210, p) (0xffff&((p) >> /* bits 31:16 / offset 02h */ \
  178. (fotg210_big_endian_capbase(fotg210) ? 0 : 16)))
  179. u32 hcs_params; /* HCSPARAMS - offset 0x4 */
  180. #define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */
  181. u32 hcc_params; /* HCCPARAMS - offset 0x8 */
  182. #define HCC_CANPARK(p) ((p)&(1 << 2)) /* true: can park on async qh */
  183. #define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1)) /* true: periodic_size changes*/
  184. u8 portroute[8]; /* nibbles for routing - offset 0xC */
  185. };
  186. /* Section 2.3 Host Controller Operational Registers */
  187. struct fotg210_regs {
  188. /* USBCMD: offset 0x00 */
  189. u32 command;
  190. /* EHCI 1.1 addendum */
  191. /* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */
  192. #define CMD_PARK (1<<11) /* enable "park" on async qh */
  193. #define CMD_PARK_CNT(c) (((c)>>8)&3) /* how many transfers to park for */
  194. #define CMD_IAAD (1<<6) /* "doorbell" interrupt async advance */
  195. #define CMD_ASE (1<<5) /* async schedule enable */
  196. #define CMD_PSE (1<<4) /* periodic schedule enable */
  197. /* 3:2 is periodic frame list size */
  198. #define CMD_RESET (1<<1) /* reset HC not bus */
  199. #define CMD_RUN (1<<0) /* start/stop HC */
  200. /* USBSTS: offset 0x04 */
  201. u32 status;
  202. #define STS_ASS (1<<15) /* Async Schedule Status */
  203. #define STS_PSS (1<<14) /* Periodic Schedule Status */
  204. #define STS_RECL (1<<13) /* Reclamation */
  205. #define STS_HALT (1<<12) /* Not running (any reason) */
  206. /* some bits reserved */
  207. /* these STS_* flags are also intr_enable bits (USBINTR) */
  208. #define STS_IAA (1<<5) /* Interrupted on async advance */
  209. #define STS_FATAL (1<<4) /* such as some PCI access errors */
  210. #define STS_FLR (1<<3) /* frame list rolled over */
  211. #define STS_PCD (1<<2) /* port change detect */
  212. #define STS_ERR (1<<1) /* "error" completion (overflow, ...) */
  213. #define STS_INT (1<<0) /* "normal" completion (short, ...) */
  214. /* USBINTR: offset 0x08 */
  215. u32 intr_enable;
  216. /* FRINDEX: offset 0x0C */
  217. u32 frame_index; /* current microframe number */
  218. /* CTRLDSSEGMENT: offset 0x10 */
  219. u32 segment; /* address bits 63:32 if needed */
  220. /* PERIODICLISTBASE: offset 0x14 */
  221. u32 frame_list; /* points to periodic list */
  222. /* ASYNCLISTADDR: offset 0x18 */
  223. u32 async_next; /* address of next async queue head */
  224. u32 reserved1;
  225. /* PORTSC: offset 0x20 */
  226. u32 port_status;
  227. /* 31:23 reserved */
  228. #define PORT_USB11(x) (((x)&(3<<10)) == (1<<10)) /* USB 1.1 device */
  229. #define PORT_RESET (1<<8) /* reset port */
  230. #define PORT_SUSPEND (1<<7) /* suspend port */
  231. #define PORT_RESUME (1<<6) /* resume it */
  232. #define PORT_PEC (1<<3) /* port enable change */
  233. #define PORT_PE (1<<2) /* port enable */
  234. #define PORT_CSC (1<<1) /* connect status change */
  235. #define PORT_CONNECT (1<<0) /* device connected */
  236. #define PORT_RWC_BITS (PORT_CSC | PORT_PEC)
  237. u32 reserved2[19];
  238. /* OTGCSR: offet 0x70 */
  239. u32 otgcsr;
  240. #define OTGCSR_HOST_SPD_TYP (3 << 22)
  241. #define OTGCSR_A_BUS_DROP (1 << 5)
  242. #define OTGCSR_A_BUS_REQ (1 << 4)
  243. /* OTGISR: offset 0x74 */
  244. u32 otgisr;
  245. #define OTGISR_OVC (1 << 10)
  246. u32 reserved3[15];
  247. /* GMIR: offset 0xB4 */
  248. u32 gmir;
  249. #define GMIR_INT_POLARITY (1 << 3) /*Active High*/
  250. #define GMIR_MHC_INT (1 << 2)
  251. #define GMIR_MOTG_INT (1 << 1)
  252. #define GMIR_MDEV_INT (1 << 0)
  253. };
  254. /* Appendix C, Debug port ... intended for use with special "debug devices"
  255. * that can help if there's no serial console. (nonstandard enumeration.)
  256. */
  257. struct fotg210_dbg_port {
  258. u32 control;
  259. #define DBGP_OWNER (1<<30)
  260. #define DBGP_ENABLED (1<<28)
  261. #define DBGP_DONE (1<<16)
  262. #define DBGP_INUSE (1<<10)
  263. #define DBGP_ERRCODE(x) (((x)>>7)&0x07)
  264. # define DBGP_ERR_BAD 1
  265. # define DBGP_ERR_SIGNAL 2
  266. #define DBGP_ERROR (1<<6)
  267. #define DBGP_GO (1<<5)
  268. #define DBGP_OUT (1<<4)
  269. #define DBGP_LEN(x) (((x)>>0)&0x0f)
  270. u32 pids;
  271. #define DBGP_PID_GET(x) (((x)>>16)&0xff)
  272. #define DBGP_PID_SET(data, tok) (((data)<<8)|(tok))
  273. u32 data03;
  274. u32 data47;
  275. u32 address;
  276. #define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep))
  277. };
  278. #ifdef CONFIG_EARLY_PRINTK_DBGP
  279. #include <linux/init.h>
  280. extern int __init early_dbgp_init(char *s);
  281. extern struct console early_dbgp_console;
  282. #endif /* CONFIG_EARLY_PRINTK_DBGP */
  283. struct usb_hcd;
  284. static inline int xen_dbgp_reset_prep(struct usb_hcd *hcd)
  285. {
  286. return 1; /* Shouldn't this be 0? */
  287. }
  288. static inline int xen_dbgp_external_startup(struct usb_hcd *hcd)
  289. {
  290. return -1;
  291. }
  292. #ifdef CONFIG_EARLY_PRINTK_DBGP
  293. /* Call backs from fotg210 host driver to fotg210 debug driver */
  294. extern int dbgp_external_startup(struct usb_hcd *);
  295. extern int dbgp_reset_prep(struct usb_hcd *hcd);
  296. #else
  297. static inline int dbgp_reset_prep(struct usb_hcd *hcd)
  298. {
  299. return xen_dbgp_reset_prep(hcd);
  300. }
  301. static inline int dbgp_external_startup(struct usb_hcd *hcd)
  302. {
  303. return xen_dbgp_external_startup(hcd);
  304. }
  305. #endif
  306. /*-------------------------------------------------------------------------*/
  307. #define QTD_NEXT(fotg210, dma) cpu_to_hc32(fotg210, (u32)dma)
  308. /*
  309. * EHCI Specification 0.95 Section 3.5
  310. * QTD: describe data transfer components (buffer, direction, ...)
  311. * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
  312. *
  313. * These are associated only with "QH" (Queue Head) structures,
  314. * used with control, bulk, and interrupt transfers.
  315. */
  316. struct fotg210_qtd {
  317. /* first part defined by EHCI spec */
  318. __hc32 hw_next; /* see EHCI 3.5.1 */
  319. __hc32 hw_alt_next; /* see EHCI 3.5.2 */
  320. __hc32 hw_token; /* see EHCI 3.5.3 */
  321. #define QTD_TOGGLE (1 << 31) /* data toggle */
  322. #define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
  323. #define QTD_IOC (1 << 15) /* interrupt on complete */
  324. #define QTD_CERR(tok) (((tok)>>10) & 0x3)
  325. #define QTD_PID(tok) (((tok)>>8) & 0x3)
  326. #define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */
  327. #define QTD_STS_HALT (1 << 6) /* halted on error */
  328. #define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */
  329. #define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */
  330. #define QTD_STS_XACT (1 << 3) /* device gave illegal response */
  331. #define QTD_STS_MMF (1 << 2) /* incomplete split transaction */
  332. #define QTD_STS_STS (1 << 1) /* split transaction state */
  333. #define QTD_STS_PING (1 << 0) /* issue PING? */
  334. #define ACTIVE_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_ACTIVE)
  335. #define HALT_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_HALT)
  336. #define STATUS_BIT(fotg210) cpu_to_hc32(fotg210, QTD_STS_STS)
  337. __hc32 hw_buf[5]; /* see EHCI 3.5.4 */
  338. __hc32 hw_buf_hi[5]; /* Appendix B */
  339. /* the rest is HCD-private */
  340. dma_addr_t qtd_dma; /* qtd address */
  341. struct list_head qtd_list; /* sw qtd list */
  342. struct urb *urb; /* qtd's urb */
  343. size_t length; /* length of buffer */
  344. } __aligned(32);
  345. /* mask NakCnt+T in qh->hw_alt_next */
  346. #define QTD_MASK(fotg210) cpu_to_hc32(fotg210, ~0x1f)
  347. #define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1)
  348. /*-------------------------------------------------------------------------*/
  349. /* type tag from {qh,itd,fstn}->hw_next */
  350. #define Q_NEXT_TYPE(fotg210, dma) ((dma) & cpu_to_hc32(fotg210, 3 << 1))
  351. /*
  352. * Now the following defines are not converted using the
  353. * cpu_to_le32() macro anymore, since we have to support
  354. * "dynamic" switching between be and le support, so that the driver
  355. * can be used on one system with SoC EHCI controller using big-endian
  356. * descriptors as well as a normal little-endian PCI EHCI controller.
  357. */
  358. /* values for that type tag */
  359. #define Q_TYPE_ITD (0 << 1)
  360. #define Q_TYPE_QH (1 << 1)
  361. #define Q_TYPE_SITD (2 << 1)
  362. #define Q_TYPE_FSTN (3 << 1)
  363. /* next async queue entry, or pointer to interrupt/periodic QH */
  364. #define QH_NEXT(fotg210, dma) \
  365. (cpu_to_hc32(fotg210, (((u32)dma)&~0x01f)|Q_TYPE_QH))
  366. /* for periodic/async schedules and qtd lists, mark end of list */
  367. #define FOTG210_LIST_END(fotg210) \
  368. cpu_to_hc32(fotg210, 1) /* "null pointer" to hw */
  369. /*
  370. * Entries in periodic shadow table are pointers to one of four kinds
  371. * of data structure. That's dictated by the hardware; a type tag is
  372. * encoded in the low bits of the hardware's periodic schedule. Use
  373. * Q_NEXT_TYPE to get the tag.
  374. *
  375. * For entries in the async schedule, the type tag always says "qh".
  376. */
  377. union fotg210_shadow {
  378. struct fotg210_qh *qh; /* Q_TYPE_QH */
  379. struct fotg210_itd *itd; /* Q_TYPE_ITD */
  380. struct fotg210_fstn *fstn; /* Q_TYPE_FSTN */
  381. __hc32 *hw_next; /* (all types) */
  382. void *ptr;
  383. };
  384. /*-------------------------------------------------------------------------*/
  385. /*
  386. * EHCI Specification 0.95 Section 3.6
  387. * QH: describes control/bulk/interrupt endpoints
  388. * See Fig 3-7 "Queue Head Structure Layout".
  389. *
  390. * These appear in both the async and (for interrupt) periodic schedules.
  391. */
  392. /* first part defined by EHCI spec */
  393. struct fotg210_qh_hw {
  394. __hc32 hw_next; /* see EHCI 3.6.1 */
  395. __hc32 hw_info1; /* see EHCI 3.6.2 */
  396. #define QH_CONTROL_EP (1 << 27) /* FS/LS control endpoint */
  397. #define QH_HEAD (1 << 15) /* Head of async reclamation list */
  398. #define QH_TOGGLE_CTL (1 << 14) /* Data toggle control */
  399. #define QH_HIGH_SPEED (2 << 12) /* Endpoint speed */
  400. #define QH_LOW_SPEED (1 << 12)
  401. #define QH_FULL_SPEED (0 << 12)
  402. #define QH_INACTIVATE (1 << 7) /* Inactivate on next transaction */
  403. __hc32 hw_info2; /* see EHCI 3.6.2 */
  404. #define QH_SMASK 0x000000ff
  405. #define QH_CMASK 0x0000ff00
  406. #define QH_HUBADDR 0x007f0000
  407. #define QH_HUBPORT 0x3f800000
  408. #define QH_MULT 0xc0000000
  409. __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */
  410. /* qtd overlay (hardware parts of a struct fotg210_qtd) */
  411. __hc32 hw_qtd_next;
  412. __hc32 hw_alt_next;
  413. __hc32 hw_token;
  414. __hc32 hw_buf[5];
  415. __hc32 hw_buf_hi[5];
  416. } __aligned(32);
  417. struct fotg210_qh {
  418. struct fotg210_qh_hw *hw; /* Must come first */
  419. /* the rest is HCD-private */
  420. dma_addr_t qh_dma; /* address of qh */
  421. union fotg210_shadow qh_next; /* ptr to qh; or periodic */
  422. struct list_head qtd_list; /* sw qtd list */
  423. struct list_head intr_node; /* list of intr QHs */
  424. struct fotg210_qtd *dummy;
  425. struct fotg210_qh *unlink_next; /* next on unlink list */
  426. unsigned unlink_cycle;
  427. u8 needs_rescan; /* Dequeue during giveback */
  428. u8 qh_state;
  429. #define QH_STATE_LINKED 1 /* HC sees this */
  430. #define QH_STATE_UNLINK 2 /* HC may still see this */
  431. #define QH_STATE_IDLE 3 /* HC doesn't see this */
  432. #define QH_STATE_UNLINK_WAIT 4 /* LINKED and on unlink q */
  433. #define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
  434. u8 xacterrs; /* XactErr retry counter */
  435. #define QH_XACTERR_MAX 32 /* XactErr retry limit */
  436. /* periodic schedule info */
  437. u8 usecs; /* intr bandwidth */
  438. u8 gap_uf; /* uframes split/csplit gap */
  439. u8 c_usecs; /* ... split completion bw */
  440. u16 tt_usecs; /* tt downstream bandwidth */
  441. unsigned short period; /* polling interval */
  442. unsigned short start; /* where polling starts */
  443. #define NO_FRAME ((unsigned short)~0) /* pick new start */
  444. struct usb_device *dev; /* access to TT */
  445. unsigned is_out:1; /* bulk or intr OUT */
  446. unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
  447. };
  448. /*-------------------------------------------------------------------------*/
  449. /* description of one iso transaction (up to 3 KB data if highspeed) */
  450. struct fotg210_iso_packet {
  451. /* These will be copied to iTD when scheduling */
  452. u64 bufp; /* itd->hw_bufp{,_hi}[pg] |= */
  453. __hc32 transaction; /* itd->hw_transaction[i] |= */
  454. u8 cross; /* buf crosses pages */
  455. /* for full speed OUT splits */
  456. u32 buf1;
  457. };
  458. /* temporary schedule data for packets from iso urbs (both speeds)
  459. * each packet is one logical usb transaction to the device (not TT),
  460. * beginning at stream->next_uframe
  461. */
  462. struct fotg210_iso_sched {
  463. struct list_head td_list;
  464. unsigned span;
  465. struct fotg210_iso_packet packet[0];
  466. };
  467. /*
  468. * fotg210_iso_stream - groups all (s)itds for this endpoint.
  469. * acts like a qh would, if EHCI had them for ISO.
  470. */
  471. struct fotg210_iso_stream {
  472. /* first field matches fotg210_hq, but is NULL */
  473. struct fotg210_qh_hw *hw;
  474. u8 bEndpointAddress;
  475. u8 highspeed;
  476. struct list_head td_list; /* queued itds */
  477. struct list_head free_list; /* list of unused itds */
  478. struct usb_device *udev;
  479. struct usb_host_endpoint *ep;
  480. /* output of (re)scheduling */
  481. int next_uframe;
  482. __hc32 splits;
  483. /* the rest is derived from the endpoint descriptor,
  484. * trusting urb->interval == f(epdesc->bInterval) and
  485. * including the extra info for hw_bufp[0..2]
  486. */
  487. u8 usecs, c_usecs;
  488. u16 interval;
  489. u16 tt_usecs;
  490. u16 maxp;
  491. u16 raw_mask;
  492. unsigned bandwidth;
  493. /* This is used to initialize iTD's hw_bufp fields */
  494. __hc32 buf0;
  495. __hc32 buf1;
  496. __hc32 buf2;
  497. /* this is used to initialize sITD's tt info */
  498. __hc32 address;
  499. };
  500. /*-------------------------------------------------------------------------*/
  501. /*
  502. * EHCI Specification 0.95 Section 3.3
  503. * Fig 3-4 "Isochronous Transaction Descriptor (iTD)"
  504. *
  505. * Schedule records for high speed iso xfers
  506. */
  507. struct fotg210_itd {
  508. /* first part defined by EHCI spec */
  509. __hc32 hw_next; /* see EHCI 3.3.1 */
  510. __hc32 hw_transaction[8]; /* see EHCI 3.3.2 */
  511. #define FOTG210_ISOC_ACTIVE (1<<31) /* activate transfer this slot */
  512. #define FOTG210_ISOC_BUF_ERR (1<<30) /* Data buffer error */
  513. #define FOTG210_ISOC_BABBLE (1<<29) /* babble detected */
  514. #define FOTG210_ISOC_XACTERR (1<<28) /* XactErr - transaction error */
  515. #define FOTG210_ITD_LENGTH(tok) (((tok)>>16) & 0x0fff)
  516. #define FOTG210_ITD_IOC (1 << 15) /* interrupt on complete */
  517. #define ITD_ACTIVE(fotg210) cpu_to_hc32(fotg210, FOTG210_ISOC_ACTIVE)
  518. __hc32 hw_bufp[7]; /* see EHCI 3.3.3 */
  519. __hc32 hw_bufp_hi[7]; /* Appendix B */
  520. /* the rest is HCD-private */
  521. dma_addr_t itd_dma; /* for this itd */
  522. union fotg210_shadow itd_next; /* ptr to periodic q entry */
  523. struct urb *urb;
  524. struct fotg210_iso_stream *stream; /* endpoint's queue */
  525. struct list_head itd_list; /* list of stream's itds */
  526. /* any/all hw_transactions here may be used by that urb */
  527. unsigned frame; /* where scheduled */
  528. unsigned pg;
  529. unsigned index[8]; /* in urb->iso_frame_desc */
  530. } __aligned(32);
  531. /*-------------------------------------------------------------------------*/
  532. /*
  533. * EHCI Specification 0.96 Section 3.7
  534. * Periodic Frame Span Traversal Node (FSTN)
  535. *
  536. * Manages split interrupt transactions (using TT) that span frame boundaries
  537. * into uframes 0/1; see 4.12.2.2. In those uframes, a "save place" FSTN
  538. * makes the HC jump (back) to a QH to scan for fs/ls QH completions until
  539. * it hits a "restore" FSTN; then it returns to finish other uframe 0/1 work.
  540. */
  541. struct fotg210_fstn {
  542. __hc32 hw_next; /* any periodic q entry */
  543. __hc32 hw_prev; /* qh or FOTG210_LIST_END */
  544. /* the rest is HCD-private */
  545. dma_addr_t fstn_dma;
  546. union fotg210_shadow fstn_next; /* ptr to periodic q entry */
  547. } __aligned(32);
  548. /*-------------------------------------------------------------------------*/
  549. /* Prepare the PORTSC wakeup flags during controller suspend/resume */
  550. #define fotg210_prepare_ports_for_controller_suspend(fotg210, do_wakeup) \
  551. fotg210_adjust_port_wakeup_flags(fotg210, true, do_wakeup);
  552. #define fotg210_prepare_ports_for_controller_resume(fotg210) \
  553. fotg210_adjust_port_wakeup_flags(fotg210, false, false);
  554. /*-------------------------------------------------------------------------*/
  555. /*
  556. * Some EHCI controllers have a Transaction Translator built into the
  557. * root hub. This is a non-standard feature. Each controller will need
  558. * to add code to the following inline functions, and call them as
  559. * needed (mostly in root hub code).
  560. */
  561. static inline unsigned int
  562. fotg210_get_speed(struct fotg210_hcd *fotg210, unsigned int portsc)
  563. {
  564. return (readl(&fotg210->regs->otgcsr)
  565. & OTGCSR_HOST_SPD_TYP) >> 22;
  566. }
  567. /* Returns the speed of a device attached to a port on the root hub. */
  568. static inline unsigned int
  569. fotg210_port_speed(struct fotg210_hcd *fotg210, unsigned int portsc)
  570. {
  571. switch (fotg210_get_speed(fotg210, portsc)) {
  572. case 0:
  573. return 0;
  574. case 1:
  575. return USB_PORT_STAT_LOW_SPEED;
  576. case 2:
  577. default:
  578. return USB_PORT_STAT_HIGH_SPEED;
  579. }
  580. }
  581. /*-------------------------------------------------------------------------*/
  582. #define fotg210_has_fsl_portno_bug(e) (0)
  583. /*
  584. * While most USB host controllers implement their registers in
  585. * little-endian format, a minority (celleb companion chip) implement
  586. * them in big endian format.
  587. *
  588. * This attempts to support either format at compile time without a
  589. * runtime penalty, or both formats with the additional overhead
  590. * of checking a flag bit.
  591. *
  592. */
  593. #define fotg210_big_endian_mmio(e) 0
  594. #define fotg210_big_endian_capbase(e) 0
  595. static inline unsigned int fotg210_readl(const struct fotg210_hcd *fotg210,
  596. __u32 __iomem *regs)
  597. {
  598. return readl(regs);
  599. }
  600. static inline void fotg210_writel(const struct fotg210_hcd *fotg210,
  601. const unsigned int val, __u32 __iomem *regs)
  602. {
  603. writel(val, regs);
  604. }
  605. /* cpu to fotg210 */
  606. static inline __hc32 cpu_to_hc32(const struct fotg210_hcd *fotg210, const u32 x)
  607. {
  608. return cpu_to_le32(x);
  609. }
  610. /* fotg210 to cpu */
  611. static inline u32 hc32_to_cpu(const struct fotg210_hcd *fotg210, const __hc32 x)
  612. {
  613. return le32_to_cpu(x);
  614. }
  615. static inline u32 hc32_to_cpup(const struct fotg210_hcd *fotg210,
  616. const __hc32 *x)
  617. {
  618. return le32_to_cpup(x);
  619. }
  620. /*-------------------------------------------------------------------------*/
  621. static inline unsigned fotg210_read_frame_index(struct fotg210_hcd *fotg210)
  622. {
  623. return fotg210_readl(fotg210, &fotg210->regs->frame_index);
  624. }
  625. #define fotg210_itdlen(urb, desc, t) ({ \
  626. usb_pipein((urb)->pipe) ? \
  627. (desc)->length - FOTG210_ITD_LENGTH(t) : \
  628. FOTG210_ITD_LENGTH(t); \
  629. })
  630. /*-------------------------------------------------------------------------*/
  631. #ifndef DEBUG
  632. #define STUB_DEBUG_FILES
  633. #endif /* DEBUG */
  634. /*-------------------------------------------------------------------------*/
  635. #endif /* __LINUX_FOTG210_H */