ohci.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. *
  7. * This file is licenced under the GPL.
  8. */
  9. /*
  10. * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to
  11. * __leXX (normally) or __beXX (given OHCI_BIG_ENDIAN), depending on the
  12. * host controller implementation.
  13. */
  14. typedef __u32 __bitwise __hc32;
  15. typedef __u16 __bitwise __hc16;
  16. /*
  17. * OHCI Endpoint Descriptor (ED) ... holds TD queue
  18. * See OHCI spec, section 4.2
  19. *
  20. * This is a "Queue Head" for those transfers, which is why
  21. * both EHCI and UHCI call similar structures a "QH".
  22. */
  23. struct ed {
  24. /* first fields are hardware-specified */
  25. __hc32 hwINFO; /* endpoint config bitmap */
  26. /* info bits defined by hcd */
  27. #define ED_DEQUEUE (1 << 27)
  28. /* info bits defined by the hardware */
  29. #define ED_ISO (1 << 15)
  30. #define ED_SKIP (1 << 14)
  31. #define ED_LOWSPEED (1 << 13)
  32. #define ED_OUT (0x01 << 11)
  33. #define ED_IN (0x02 << 11)
  34. __hc32 hwTailP; /* tail of TD list */
  35. __hc32 hwHeadP; /* head of TD list (hc r/w) */
  36. #define ED_C (0x02) /* toggle carry */
  37. #define ED_H (0x01) /* halted */
  38. __hc32 hwNextED; /* next ED in list */
  39. /* rest are purely for the driver's use */
  40. dma_addr_t dma; /* addr of ED */
  41. struct td *dummy; /* next TD to activate */
  42. /* host's view of schedule */
  43. struct ed *ed_next; /* on schedule or rm_list */
  44. struct ed *ed_prev; /* for non-interrupt EDs */
  45. struct list_head td_list; /* "shadow list" of our TDs */
  46. struct list_head in_use_list;
  47. /* create --> IDLE --> OPER --> ... --> IDLE --> destroy
  48. * usually: OPER --> UNLINK --> (IDLE | OPER) --> ...
  49. */
  50. u8 state; /* ED_{IDLE,UNLINK,OPER} */
  51. #define ED_IDLE 0x00 /* NOT linked to HC */
  52. #define ED_UNLINK 0x01 /* being unlinked from hc */
  53. #define ED_OPER 0x02 /* IS linked to hc */
  54. u8 type; /* PIPE_{BULK,...} */
  55. /* periodic scheduling params (for intr and iso) */
  56. u8 branch;
  57. u16 interval;
  58. u16 load;
  59. u16 last_iso; /* iso only */
  60. /* HC may see EDs on rm_list until next frame (frame_no == tick) */
  61. u16 tick;
  62. /* Detect TDs not added to the done queue */
  63. unsigned takeback_wdh_cnt;
  64. struct td *pending_td;
  65. #define OKAY_TO_TAKEBACK(ohci, ed) \
  66. ((int) (ohci->wdh_cnt - ed->takeback_wdh_cnt) >= 0)
  67. } __attribute__ ((aligned(16)));
  68. #define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */
  69. /*
  70. * OHCI Transfer Descriptor (TD) ... one per transfer segment
  71. * See OHCI spec, sections 4.3.1 (general = control/bulk/interrupt)
  72. * and 4.3.2 (iso)
  73. */
  74. struct td {
  75. /* first fields are hardware-specified */
  76. __hc32 hwINFO; /* transfer info bitmask */
  77. /* hwINFO bits for both general and iso tds: */
  78. #define TD_CC 0xf0000000 /* condition code */
  79. #define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
  80. //#define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
  81. #define TD_DI 0x00E00000 /* frames before interrupt */
  82. #define TD_DI_SET(X) (((X) & 0x07)<< 21)
  83. /* these two bits are available for definition/use by HCDs in both
  84. * general and iso tds ... others are available for only one type
  85. */
  86. #define TD_DONE 0x00020000 /* retired to donelist */
  87. #define TD_ISO 0x00010000 /* copy of ED_ISO */
  88. /* hwINFO bits for general tds: */
  89. #define TD_EC 0x0C000000 /* error count */
  90. #define TD_T 0x03000000 /* data toggle state */
  91. #define TD_T_DATA0 0x02000000 /* DATA0 */
  92. #define TD_T_DATA1 0x03000000 /* DATA1 */
  93. #define TD_T_TOGGLE 0x00000000 /* uses ED_C */
  94. #define TD_DP 0x00180000 /* direction/pid */
  95. #define TD_DP_SETUP 0x00000000 /* SETUP pid */
  96. #define TD_DP_IN 0x00100000 /* IN pid */
  97. #define TD_DP_OUT 0x00080000 /* OUT pid */
  98. /* 0x00180000 rsvd */
  99. #define TD_R 0x00040000 /* round: short packets OK? */
  100. /* (no hwINFO #defines yet for iso tds) */
  101. __hc32 hwCBP; /* Current Buffer Pointer (or 0) */
  102. __hc32 hwNextTD; /* Next TD Pointer */
  103. __hc32 hwBE; /* Memory Buffer End Pointer */
  104. /* PSW is only for ISO. Only 1 PSW entry is used, but on
  105. * big-endian PPC hardware that's the second entry.
  106. */
  107. #define MAXPSW 2
  108. __hc16 hwPSW [MAXPSW];
  109. /* rest are purely for the driver's use */
  110. __u8 index;
  111. struct ed *ed;
  112. struct td *td_hash; /* dma-->td hashtable */
  113. struct td *next_dl_td;
  114. struct urb *urb;
  115. dma_addr_t td_dma; /* addr of this TD */
  116. dma_addr_t data_dma; /* addr of data it points to */
  117. struct list_head td_list; /* "shadow list", TDs on same ED */
  118. } __attribute__ ((aligned(32))); /* c/b/i need 16; only iso needs 32 */
  119. #define TD_MASK ((u32)~0x1f) /* strip hw status in low addr bits */
  120. /*
  121. * Hardware transfer status codes -- CC from td->hwINFO or td->hwPSW
  122. */
  123. #define TD_CC_NOERROR 0x00
  124. #define TD_CC_CRC 0x01
  125. #define TD_CC_BITSTUFFING 0x02
  126. #define TD_CC_DATATOGGLEM 0x03
  127. #define TD_CC_STALL 0x04
  128. #define TD_DEVNOTRESP 0x05
  129. #define TD_PIDCHECKFAIL 0x06
  130. #define TD_UNEXPECTEDPID 0x07
  131. #define TD_DATAOVERRUN 0x08
  132. #define TD_DATAUNDERRUN 0x09
  133. /* 0x0A, 0x0B reserved for hardware */
  134. #define TD_BUFFEROVERRUN 0x0C
  135. #define TD_BUFFERUNDERRUN 0x0D
  136. /* 0x0E, 0x0F reserved for HCD */
  137. #define TD_NOTACCESSED 0x0F
  138. /* map OHCI TD status codes (CC) to errno values */
  139. static const int cc_to_error [16] = {
  140. /* No Error */ 0,
  141. /* CRC Error */ -EILSEQ,
  142. /* Bit Stuff */ -EPROTO,
  143. /* Data Togg */ -EILSEQ,
  144. /* Stall */ -EPIPE,
  145. /* DevNotResp */ -ETIME,
  146. /* PIDCheck */ -EPROTO,
  147. /* UnExpPID */ -EPROTO,
  148. /* DataOver */ -EOVERFLOW,
  149. /* DataUnder */ -EREMOTEIO,
  150. /* (for hw) */ -EIO,
  151. /* (for hw) */ -EIO,
  152. /* BufferOver */ -ECOMM,
  153. /* BuffUnder */ -ENOSR,
  154. /* (for HCD) */ -EALREADY,
  155. /* (for HCD) */ -EALREADY
  156. };
  157. /*
  158. * The HCCA (Host Controller Communications Area) is a 256 byte
  159. * structure defined section 4.4.1 of the OHCI spec. The HC is
  160. * told the base address of it. It must be 256-byte aligned.
  161. */
  162. struct ohci_hcca {
  163. #define NUM_INTS 32
  164. __hc32 int_table [NUM_INTS]; /* periodic schedule */
  165. /*
  166. * OHCI defines u16 frame_no, followed by u16 zero pad.
  167. * Since some processors can't do 16 bit bus accesses,
  168. * portable access must be a 32 bits wide.
  169. */
  170. __hc32 frame_no; /* current frame number */
  171. __hc32 done_head; /* info returned for an interrupt */
  172. u8 reserved_for_hc [116];
  173. u8 what [4]; /* spec only identifies 252 bytes :) */
  174. } __attribute__ ((aligned(256)));
  175. /*
  176. * This is the structure of the OHCI controller's memory mapped I/O region.
  177. * You must use readl() and writel() (in <asm/io.h>) to access these fields!!
  178. * Layout is in section 7 (and appendix B) of the spec.
  179. */
  180. struct ohci_regs {
  181. /* control and status registers (section 7.1) */
  182. __hc32 revision;
  183. __hc32 control;
  184. __hc32 cmdstatus;
  185. __hc32 intrstatus;
  186. __hc32 intrenable;
  187. __hc32 intrdisable;
  188. /* memory pointers (section 7.2) */
  189. __hc32 hcca;
  190. __hc32 ed_periodcurrent;
  191. __hc32 ed_controlhead;
  192. __hc32 ed_controlcurrent;
  193. __hc32 ed_bulkhead;
  194. __hc32 ed_bulkcurrent;
  195. __hc32 donehead;
  196. /* frame counters (section 7.3) */
  197. __hc32 fminterval;
  198. __hc32 fmremaining;
  199. __hc32 fmnumber;
  200. __hc32 periodicstart;
  201. __hc32 lsthresh;
  202. /* Root hub ports (section 7.4) */
  203. struct ohci_roothub_regs {
  204. __hc32 a;
  205. __hc32 b;
  206. __hc32 status;
  207. #define MAX_ROOT_PORTS 15 /* maximum OHCI root hub ports (RH_A_NDP) */
  208. __hc32 portstatus [MAX_ROOT_PORTS];
  209. } roothub;
  210. /* and optional "legacy support" registers (appendix B) at 0x0100 */
  211. } __attribute__ ((aligned(32)));
  212. /* OHCI CONTROL AND STATUS REGISTER MASKS */
  213. /*
  214. * HcControl (control) register masks
  215. */
  216. #define OHCI_CTRL_CBSR (3 << 0) /* control/bulk service ratio */
  217. #define OHCI_CTRL_PLE (1 << 2) /* periodic list enable */
  218. #define OHCI_CTRL_IE (1 << 3) /* isochronous enable */
  219. #define OHCI_CTRL_CLE (1 << 4) /* control list enable */
  220. #define OHCI_CTRL_BLE (1 << 5) /* bulk list enable */
  221. #define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */
  222. #define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
  223. #define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
  224. #define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
  225. /* pre-shifted values for HCFS */
  226. # define OHCI_USB_RESET (0 << 6)
  227. # define OHCI_USB_RESUME (1 << 6)
  228. # define OHCI_USB_OPER (2 << 6)
  229. # define OHCI_USB_SUSPEND (3 << 6)
  230. /*
  231. * HcCommandStatus (cmdstatus) register masks
  232. */
  233. #define OHCI_HCR (1 << 0) /* host controller reset */
  234. #define OHCI_CLF (1 << 1) /* control list filled */
  235. #define OHCI_BLF (1 << 2) /* bulk list filled */
  236. #define OHCI_OCR (1 << 3) /* ownership change request */
  237. #define OHCI_SOC (3 << 16) /* scheduling overrun count */
  238. /*
  239. * masks used with interrupt registers:
  240. * HcInterruptStatus (intrstatus)
  241. * HcInterruptEnable (intrenable)
  242. * HcInterruptDisable (intrdisable)
  243. */
  244. #define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
  245. #define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */
  246. #define OHCI_INTR_SF (1 << 2) /* start frame */
  247. #define OHCI_INTR_RD (1 << 3) /* resume detect */
  248. #define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
  249. #define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
  250. #define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
  251. #define OHCI_INTR_OC (1 << 30) /* ownership change */
  252. #define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
  253. /* OHCI ROOT HUB REGISTER MASKS */
  254. /* roothub.portstatus [i] bits */
  255. #define RH_PS_CCS 0x00000001 /* current connect status */
  256. #define RH_PS_PES 0x00000002 /* port enable status*/
  257. #define RH_PS_PSS 0x00000004 /* port suspend status */
  258. #define RH_PS_POCI 0x00000008 /* port over current indicator */
  259. #define RH_PS_PRS 0x00000010 /* port reset status */
  260. #define RH_PS_PPS 0x00000100 /* port power status */
  261. #define RH_PS_LSDA 0x00000200 /* low speed device attached */
  262. #define RH_PS_CSC 0x00010000 /* connect status change */
  263. #define RH_PS_PESC 0x00020000 /* port enable status change */
  264. #define RH_PS_PSSC 0x00040000 /* port suspend status change */
  265. #define RH_PS_OCIC 0x00080000 /* over current indicator change */
  266. #define RH_PS_PRSC 0x00100000 /* port reset status change */
  267. /* roothub.status bits */
  268. #define RH_HS_LPS 0x00000001 /* local power status */
  269. #define RH_HS_OCI 0x00000002 /* over current indicator */
  270. #define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
  271. #define RH_HS_LPSC 0x00010000 /* local power status change */
  272. #define RH_HS_OCIC 0x00020000 /* over current indicator change */
  273. #define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
  274. /* roothub.b masks */
  275. #define RH_B_DR 0x0000ffff /* device removable flags */
  276. #define RH_B_PPCM 0xffff0000 /* port power control mask */
  277. /* roothub.a masks */
  278. #define RH_A_NDP (0xff << 0) /* number of downstream ports */
  279. #define RH_A_PSM (1 << 8) /* power switching mode */
  280. #define RH_A_NPS (1 << 9) /* no power switching */
  281. #define RH_A_DT (1 << 10) /* device type (mbz) */
  282. #define RH_A_OCPM (1 << 11) /* over current protection mode */
  283. #define RH_A_NOCP (1 << 12) /* no over current protection */
  284. #define RH_A_POTPGT (0xff << 24) /* power on to power good time */
  285. /* hcd-private per-urb state */
  286. typedef struct urb_priv {
  287. struct ed *ed;
  288. u16 length; // # tds in this request
  289. u16 td_cnt; // tds already serviced
  290. struct list_head pending;
  291. struct td *td [0]; // all TDs in this request
  292. } urb_priv_t;
  293. #define TD_HASH_SIZE 64 /* power'o'two */
  294. // sizeof (struct td) ~= 64 == 2^6 ...
  295. #define TD_HASH_FUNC(td_dma) ((td_dma ^ (td_dma >> 6)) % TD_HASH_SIZE)
  296. /*
  297. * This is the full ohci controller description
  298. *
  299. * Note how the "proper" USB information is just
  300. * a subset of what the full implementation needs. (Linus)
  301. */
  302. enum ohci_rh_state {
  303. OHCI_RH_HALTED,
  304. OHCI_RH_SUSPENDED,
  305. OHCI_RH_RUNNING
  306. };
  307. struct ohci_hcd {
  308. spinlock_t lock;
  309. /*
  310. * I/O memory used to communicate with the HC (dma-consistent)
  311. */
  312. struct ohci_regs __iomem *regs;
  313. /*
  314. * main memory used to communicate with the HC (dma-consistent).
  315. * hcd adds to schedule for a live hc any time, but removals finish
  316. * only at the start of the next frame.
  317. */
  318. struct ohci_hcca *hcca;
  319. dma_addr_t hcca_dma;
  320. struct ed *ed_rm_list; /* to be removed */
  321. struct ed *ed_bulktail; /* last in bulk list */
  322. struct ed *ed_controltail; /* last in ctrl list */
  323. struct ed *periodic [NUM_INTS]; /* shadow int_table */
  324. void (*start_hnp)(struct ohci_hcd *ohci);
  325. /*
  326. * memory management for queue data structures
  327. */
  328. struct dma_pool *td_cache;
  329. struct dma_pool *ed_cache;
  330. struct td *td_hash [TD_HASH_SIZE];
  331. struct td *dl_start, *dl_end; /* the done list */
  332. struct list_head pending;
  333. struct list_head eds_in_use; /* all EDs with at least 1 TD */
  334. /*
  335. * driver state
  336. */
  337. enum ohci_rh_state rh_state;
  338. int num_ports;
  339. int load [NUM_INTS];
  340. u32 hc_control; /* copy of hc control reg */
  341. unsigned long next_statechange; /* suspend/resume */
  342. u32 fminterval; /* saved register */
  343. unsigned autostop:1; /* rh auto stopping/stopped */
  344. unsigned working:1;
  345. unsigned restart_work:1;
  346. unsigned long flags; /* for HC bugs */
  347. #define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
  348. #define OHCI_QUIRK_SUPERIO 0x02 /* natsemi */
  349. #define OHCI_QUIRK_INITRESET 0x04 /* SiS, OPTi, ... */
  350. #define OHCI_QUIRK_BE_DESC 0x08 /* BE descriptors */
  351. #define OHCI_QUIRK_BE_MMIO 0x10 /* BE registers */
  352. #define OHCI_QUIRK_ZFMICRO 0x20 /* Compaq ZFMicro chipset*/
  353. #define OHCI_QUIRK_NEC 0x40 /* lost interrupts */
  354. #define OHCI_QUIRK_FRAME_NO 0x80 /* no big endian frame_no shift */
  355. #define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */
  356. #define OHCI_QUIRK_AMD_PLL 0x200 /* AMD PLL quirk*/
  357. #define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */
  358. #define OHCI_QUIRK_GLOBAL_SUSPEND 0x800 /* must suspend ports */
  359. // there are also chip quirks/bugs in init logic
  360. unsigned prev_frame_no;
  361. unsigned wdh_cnt, prev_wdh_cnt;
  362. u32 prev_donehead;
  363. struct timer_list io_watchdog;
  364. struct work_struct nec_work; /* Worker for NEC quirk */
  365. struct dentry *debug_dir;
  366. struct dentry *debug_async;
  367. struct dentry *debug_periodic;
  368. struct dentry *debug_registers;
  369. /* platform-specific data -- must come last */
  370. unsigned long priv[0] __aligned(sizeof(s64));
  371. };
  372. #ifdef CONFIG_PCI
  373. static inline int quirk_nec(struct ohci_hcd *ohci)
  374. {
  375. return ohci->flags & OHCI_QUIRK_NEC;
  376. }
  377. static inline int quirk_zfmicro(struct ohci_hcd *ohci)
  378. {
  379. return ohci->flags & OHCI_QUIRK_ZFMICRO;
  380. }
  381. static inline int quirk_amdiso(struct ohci_hcd *ohci)
  382. {
  383. return ohci->flags & OHCI_QUIRK_AMD_PLL;
  384. }
  385. static inline int quirk_amdprefetch(struct ohci_hcd *ohci)
  386. {
  387. return ohci->flags & OHCI_QUIRK_AMD_PREFETCH;
  388. }
  389. #else
  390. static inline int quirk_nec(struct ohci_hcd *ohci)
  391. {
  392. return 0;
  393. }
  394. static inline int quirk_zfmicro(struct ohci_hcd *ohci)
  395. {
  396. return 0;
  397. }
  398. static inline int quirk_amdiso(struct ohci_hcd *ohci)
  399. {
  400. return 0;
  401. }
  402. static inline int quirk_amdprefetch(struct ohci_hcd *ohci)
  403. {
  404. return 0;
  405. }
  406. #endif
  407. /* convert between an hcd pointer and the corresponding ohci_hcd */
  408. static inline struct ohci_hcd *hcd_to_ohci (struct usb_hcd *hcd)
  409. {
  410. return (struct ohci_hcd *) (hcd->hcd_priv);
  411. }
  412. static inline struct usb_hcd *ohci_to_hcd (const struct ohci_hcd *ohci)
  413. {
  414. return container_of ((void *) ohci, struct usb_hcd, hcd_priv);
  415. }
  416. /*-------------------------------------------------------------------------*/
  417. #define ohci_dbg(ohci, fmt, args...) \
  418. dev_dbg (ohci_to_hcd(ohci)->self.controller , fmt , ## args )
  419. #define ohci_err(ohci, fmt, args...) \
  420. dev_err (ohci_to_hcd(ohci)->self.controller , fmt , ## args )
  421. #define ohci_info(ohci, fmt, args...) \
  422. dev_info (ohci_to_hcd(ohci)->self.controller , fmt , ## args )
  423. #define ohci_warn(ohci, fmt, args...) \
  424. dev_warn (ohci_to_hcd(ohci)->self.controller , fmt , ## args )
  425. /*-------------------------------------------------------------------------*/
  426. /*
  427. * While most USB host controllers implement their registers and
  428. * in-memory communication descriptors in little-endian format,
  429. * a minority (notably the IBM STB04XXX and the Motorola MPC5200
  430. * processors) implement them in big endian format.
  431. *
  432. * In addition some more exotic implementations like the Toshiba
  433. * Spider (aka SCC) cell southbridge are "mixed" endian, that is,
  434. * they have a different endianness for registers vs. in-memory
  435. * descriptors.
  436. *
  437. * This attempts to support either format at compile time without a
  438. * runtime penalty, or both formats with the additional overhead
  439. * of checking a flag bit.
  440. *
  441. * That leads to some tricky Kconfig rules howevber. There are
  442. * different defaults based on some arch/ppc platforms, though
  443. * the basic rules are:
  444. *
  445. * Controller type Kconfig options needed
  446. * --------------- ----------------------
  447. * little endian CONFIG_USB_OHCI_LITTLE_ENDIAN
  448. *
  449. * fully big endian CONFIG_USB_OHCI_BIG_ENDIAN_DESC _and_
  450. * CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
  451. *
  452. * mixed endian CONFIG_USB_OHCI_LITTLE_ENDIAN _and_
  453. * CONFIG_USB_OHCI_BIG_ENDIAN_{MMIO,DESC}
  454. *
  455. * (If you have a mixed endian controller, you -must- also define
  456. * CONFIG_USB_OHCI_LITTLE_ENDIAN or things will not work when building
  457. * both your mixed endian and a fully big endian controller support in
  458. * the same kernel image).
  459. */
  460. #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_DESC
  461. #ifdef CONFIG_USB_OHCI_LITTLE_ENDIAN
  462. #define big_endian_desc(ohci) (ohci->flags & OHCI_QUIRK_BE_DESC)
  463. #else
  464. #define big_endian_desc(ohci) 1 /* only big endian */
  465. #endif
  466. #else
  467. #define big_endian_desc(ohci) 0 /* only little endian */
  468. #endif
  469. #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
  470. #ifdef CONFIG_USB_OHCI_LITTLE_ENDIAN
  471. #define big_endian_mmio(ohci) (ohci->flags & OHCI_QUIRK_BE_MMIO)
  472. #else
  473. #define big_endian_mmio(ohci) 1 /* only big endian */
  474. #endif
  475. #else
  476. #define big_endian_mmio(ohci) 0 /* only little endian */
  477. #endif
  478. /*
  479. * Big-endian read/write functions are arch-specific.
  480. * Other arches can be added if/when they're needed.
  481. *
  482. */
  483. static inline unsigned int _ohci_readl (const struct ohci_hcd *ohci,
  484. __hc32 __iomem * regs)
  485. {
  486. #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
  487. return big_endian_mmio(ohci) ?
  488. readl_be (regs) :
  489. readl (regs);
  490. #else
  491. return readl (regs);
  492. #endif
  493. }
  494. static inline void _ohci_writel (const struct ohci_hcd *ohci,
  495. const unsigned int val, __hc32 __iomem *regs)
  496. {
  497. #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
  498. big_endian_mmio(ohci) ?
  499. writel_be (val, regs) :
  500. writel (val, regs);
  501. #else
  502. writel (val, regs);
  503. #endif
  504. }
  505. #define ohci_readl(o,r) _ohci_readl(o,r)
  506. #define ohci_writel(o,v,r) _ohci_writel(o,v,r)
  507. /*-------------------------------------------------------------------------*/
  508. /* cpu to ohci */
  509. static inline __hc16 cpu_to_hc16 (const struct ohci_hcd *ohci, const u16 x)
  510. {
  511. return big_endian_desc(ohci) ?
  512. (__force __hc16)cpu_to_be16(x) :
  513. (__force __hc16)cpu_to_le16(x);
  514. }
  515. static inline __hc16 cpu_to_hc16p (const struct ohci_hcd *ohci, const u16 *x)
  516. {
  517. return big_endian_desc(ohci) ?
  518. cpu_to_be16p(x) :
  519. cpu_to_le16p(x);
  520. }
  521. static inline __hc32 cpu_to_hc32 (const struct ohci_hcd *ohci, const u32 x)
  522. {
  523. return big_endian_desc(ohci) ?
  524. (__force __hc32)cpu_to_be32(x) :
  525. (__force __hc32)cpu_to_le32(x);
  526. }
  527. static inline __hc32 cpu_to_hc32p (const struct ohci_hcd *ohci, const u32 *x)
  528. {
  529. return big_endian_desc(ohci) ?
  530. cpu_to_be32p(x) :
  531. cpu_to_le32p(x);
  532. }
  533. /* ohci to cpu */
  534. static inline u16 hc16_to_cpu (const struct ohci_hcd *ohci, const __hc16 x)
  535. {
  536. return big_endian_desc(ohci) ?
  537. be16_to_cpu((__force __be16)x) :
  538. le16_to_cpu((__force __le16)x);
  539. }
  540. static inline u16 hc16_to_cpup (const struct ohci_hcd *ohci, const __hc16 *x)
  541. {
  542. return big_endian_desc(ohci) ?
  543. be16_to_cpup((__force __be16 *)x) :
  544. le16_to_cpup((__force __le16 *)x);
  545. }
  546. static inline u32 hc32_to_cpu (const struct ohci_hcd *ohci, const __hc32 x)
  547. {
  548. return big_endian_desc(ohci) ?
  549. be32_to_cpu((__force __be32)x) :
  550. le32_to_cpu((__force __le32)x);
  551. }
  552. static inline u32 hc32_to_cpup (const struct ohci_hcd *ohci, const __hc32 *x)
  553. {
  554. return big_endian_desc(ohci) ?
  555. be32_to_cpup((__force __be32 *)x) :
  556. le32_to_cpup((__force __le32 *)x);
  557. }
  558. /*-------------------------------------------------------------------------*/
  559. /*
  560. * The HCCA frame number is 16 bits, but is accessed as 32 bits since not all
  561. * hardware handles 16 bit reads. Depending on the SoC implementation, the
  562. * frame number can wind up in either bits [31:16] (default) or
  563. * [15:0] (OHCI_QUIRK_FRAME_NO) on big endian hosts.
  564. *
  565. * Somewhat similarly, the 16-bit PSW fields in a transfer descriptor are
  566. * reordered on BE.
  567. */
  568. static inline u16 ohci_frame_no(const struct ohci_hcd *ohci)
  569. {
  570. u32 tmp;
  571. if (big_endian_desc(ohci)) {
  572. tmp = be32_to_cpup((__force __be32 *)&ohci->hcca->frame_no);
  573. if (!(ohci->flags & OHCI_QUIRK_FRAME_NO))
  574. tmp >>= 16;
  575. } else
  576. tmp = le32_to_cpup((__force __le32 *)&ohci->hcca->frame_no);
  577. return (u16)tmp;
  578. }
  579. static inline __hc16 *ohci_hwPSWp(const struct ohci_hcd *ohci,
  580. const struct td *td, int index)
  581. {
  582. return (__hc16 *)(big_endian_desc(ohci) ?
  583. &td->hwPSW[index ^ 1] : &td->hwPSW[index]);
  584. }
  585. static inline u16 ohci_hwPSW(const struct ohci_hcd *ohci,
  586. const struct td *td, int index)
  587. {
  588. return hc16_to_cpup(ohci, ohci_hwPSWp(ohci, td, index));
  589. }
  590. /*-------------------------------------------------------------------------*/
  591. #define FI 0x2edf /* 12000 bits per frame (-1) */
  592. #define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7))
  593. #define FIT (1 << 31)
  594. #define LSTHRESH 0x628 /* lowspeed bit threshold */
  595. static inline void periodic_reinit (struct ohci_hcd *ohci)
  596. {
  597. u32 fi = ohci->fminterval & 0x03fff;
  598. u32 fit = ohci_readl(ohci, &ohci->regs->fminterval) & FIT;
  599. ohci_writel (ohci, (fit ^ FIT) | ohci->fminterval,
  600. &ohci->regs->fminterval);
  601. ohci_writel (ohci, ((9 * fi) / 10) & 0x3fff,
  602. &ohci->regs->periodicstart);
  603. }
  604. /* AMD-756 (D2 rev) reports corrupt register contents in some cases.
  605. * The erratum (#4) description is incorrect. AMD's workaround waits
  606. * till some bits (mostly reserved) are clear; ok for all revs.
  607. */
  608. #define read_roothub(hc, register, mask) ({ \
  609. u32 temp = ohci_readl (hc, &hc->regs->roothub.register); \
  610. if (temp == -1) \
  611. hc->rh_state = OHCI_RH_HALTED; \
  612. else if (hc->flags & OHCI_QUIRK_AMD756) \
  613. while (temp & mask) \
  614. temp = ohci_readl (hc, &hc->regs->roothub.register); \
  615. temp; })
  616. static inline u32 roothub_a (struct ohci_hcd *hc)
  617. { return read_roothub (hc, a, 0xfc0fe000); }
  618. static inline u32 roothub_b (struct ohci_hcd *hc)
  619. { return ohci_readl (hc, &hc->regs->roothub.b); }
  620. static inline u32 roothub_status (struct ohci_hcd *hc)
  621. { return ohci_readl (hc, &hc->regs->roothub.status); }
  622. static inline u32 roothub_portstatus (struct ohci_hcd *hc, int i)
  623. { return read_roothub (hc, portstatus [i], 0xffe0fce0); }
  624. /* Declarations of things exported for use by ohci platform drivers */
  625. struct ohci_driver_overrides {
  626. const char *product_desc;
  627. size_t extra_priv_size;
  628. int (*reset)(struct usb_hcd *hcd);
  629. };
  630. extern void ohci_init_driver(struct hc_driver *drv,
  631. const struct ohci_driver_overrides *over);
  632. extern int ohci_restart(struct ohci_hcd *ohci);
  633. extern int ohci_setup(struct usb_hcd *hcd);
  634. #ifdef CONFIG_PM
  635. extern int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup);
  636. extern int ohci_resume(struct usb_hcd *hcd, bool hibernated);
  637. #endif
  638. extern int ohci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
  639. u16 wIndex, char *buf, u16 wLength);
  640. extern int ohci_hub_status_data(struct usb_hcd *hcd, char *buf);