ohci.h 22 KB

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