ohci.h 23 KB

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