adm5120.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. /*
  2. * ADM5120 HCD (Host Controller Driver) for USB
  3. *
  4. * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
  5. *
  6. * This file was derived from: drivers/usb/host/ohci.h
  7. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  8. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. *
  14. */
  15. /*
  16. * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to
  17. * __leXX (normally) or __beXX (given OHCI_BIG_ENDIAN), depending on the
  18. * host controller implementation.
  19. */
  20. typedef __u32 __bitwise __hc32;
  21. typedef __u16 __bitwise __hc16;
  22. /*
  23. * OHCI Endpoint Descriptor (ED) ... holds TD queue
  24. * See OHCI spec, section 4.2
  25. *
  26. * This is a "Queue Head" for those transfers, which is why
  27. * both EHCI and UHCI call similar structures a "QH".
  28. */
  29. #define TD_DATALEN_MAX 4096
  30. #define ED_ALIGN 16
  31. #define ED_MASK ((u32)~(ED_ALIGN-1)) /* strip hw status in low addr bits */
  32. struct ed {
  33. /* first fields are hardware-specified */
  34. __hc32 hwINFO; /* endpoint config bitmap */
  35. /* info bits defined by hcd */
  36. #define ED_DEQUEUE (1 << 27)
  37. /* info bits defined by the hardware */
  38. #define ED_MPS_SHIFT 16
  39. #define ED_MPS_MASK ((1 << 11)-1)
  40. #define ED_MPS_GET(x) (((x) >> ED_MPS_SHIFT) & ED_MPS_MASK)
  41. #define ED_ISO (1 << 15) /* isochronous endpoint */
  42. #define ED_SKIP (1 << 14)
  43. #define ED_SPEED_FULL (1 << 13) /* fullspeed device */
  44. #define ED_INT (1 << 11) /* interrupt endpoint */
  45. #define ED_EN_SHIFT 7 /* endpoint shift */
  46. #define ED_EN_MASK ((1 << 4)-1) /* endpoint mask */
  47. #define ED_EN_GET(x) (((x) >> ED_EN_SHIFT) & ED_EN_MASK)
  48. #define ED_FA_MASK ((1 << 7)-1) /* function address mask */
  49. #define ED_FA_GET(x) ((x) & ED_FA_MASK)
  50. __hc32 hwTailP; /* tail of TD list */
  51. __hc32 hwHeadP; /* head of TD list (hc r/w) */
  52. #define ED_C (0x02) /* toggle carry */
  53. #define ED_H (0x01) /* halted */
  54. __hc32 hwNextED; /* next ED in list */
  55. /* rest are purely for the driver's use */
  56. dma_addr_t dma; /* addr of ED */
  57. struct td *dummy; /* next TD to activate */
  58. struct list_head urb_list; /* list of our URBs */
  59. /* host's view of schedule */
  60. struct ed *ed_next; /* on schedule list */
  61. struct ed *ed_prev; /* for non-interrupt EDs */
  62. struct ed *ed_rm_next; /* on rm list */
  63. struct list_head td_list; /* "shadow list" of our TDs */
  64. /* create --> IDLE --> OPER --> ... --> IDLE --> destroy
  65. * usually: OPER --> UNLINK --> (IDLE | OPER) --> ...
  66. */
  67. u8 state; /* ED_{IDLE,UNLINK,OPER} */
  68. #define ED_IDLE 0x00 /* NOT linked to HC */
  69. #define ED_UNLINK 0x01 /* being unlinked from hc */
  70. #define ED_OPER 0x02 /* IS linked to hc */
  71. u8 type; /* PIPE_{BULK,...} */
  72. /* periodic scheduling params (for intr and iso) */
  73. u8 branch;
  74. u16 interval;
  75. u16 load;
  76. u16 last_iso; /* iso only */
  77. /* HC may see EDs on rm_list until next frame (frame_no == tick) */
  78. u16 tick;
  79. } __attribute__ ((aligned(ED_ALIGN)));
  80. /*
  81. * OHCI Transfer Descriptor (TD) ... one per transfer segment
  82. * See OHCI spec, sections 4.3.1 (general = control/bulk/interrupt)
  83. * and 4.3.2 (iso)
  84. */
  85. #define TD_ALIGN 32
  86. #define TD_MASK ((u32)~(TD_ALIGN-1)) /* strip hw status in low addr bits */
  87. struct td {
  88. /* first fields are hardware-specified */
  89. __hc32 hwINFO; /* transfer info bitmask */
  90. /* hwINFO bits */
  91. #define TD_OWN (1 << 31) /* owner of the descriptor */
  92. #define TD_CC_SHIFT 27 /* condition code */
  93. #define TD_CC_MASK 0xf
  94. #define TD_CC (TD_CC_MASK << TD_CC_SHIFT)
  95. #define TD_CC_GET(x) (((x) >> TD_CC_SHIFT) & TD_CC_MASK)
  96. #define TD_EC_SHIFT 25 /* error count */
  97. #define TD_EC_MASK 0x3
  98. #define TD_EC (TD_EC_MASK << TD_EC_SHIFT)
  99. #define TD_EC_GET(x) ((x >> TD_EC_SHIFT) & TD_EC_MASK)
  100. #define TD_T_SHIFT 23 /* data toggle state */
  101. #define TD_T_MASK 0x3
  102. #define TD_T (TD_T_MASK << TD_T_SHIFT)
  103. #define TD_T_DATA0 (0x2 << TD_T_SHIFT) /* DATA0 */
  104. #define TD_T_DATA1 (0x3 << TD_T_SHIFT) /* DATA1 */
  105. #define TD_T_CARRY (0x0 << TD_T_SHIFT) /* uses ED_C */
  106. #define TD_T_GET(x) (((x) >> TD_T_SHIFT) & TD_T_MASK)
  107. #define TD_DP_SHIFT 21 /* direction/pid */
  108. #define TD_DP_MASK 0x3
  109. #define TD_DP (TD_DP_MASK << TD_DP_SHIFT)
  110. #define TD_DP_GET (((x) >> TD_DP_SHIFT) & TD_DP_MASK)
  111. #define TD_DP_SETUP (0x0 << TD_DP_SHIFT) /* SETUP pid */
  112. #define TD_DP_OUT (0x1 << TD_DP_SHIFT) /* OUT pid */
  113. #define TD_DP_IN (0x2 << TD_DP_SHIFT) /* IN pid */
  114. #define TD_ISI_SHIFT 8 /* Interrupt Service Interval */
  115. #define TD_ISI_MASK 0x3f
  116. #define TD_ISI_GET(x) (((x) >> TD_ISI_SHIFT) & TD_ISI_MASK)
  117. #define TD_FN_MASK 0x3f /* frame number */
  118. #define TD_FN_GET(x) ((x) & TD_FN_MASK)
  119. __hc32 hwDBP; /* Data Buffer Pointer (or 0) */
  120. __hc32 hwCBL; /* Controller/Buffer Length */
  121. /* hwCBL bits */
  122. #define TD_BL_MASK 0xffff /* buffer length */
  123. #define TD_BL_GET(x) ((x) & TD_BL_MASK)
  124. #define TD_IE (1 << 16) /* interrupt enable */
  125. __hc32 hwNextTD; /* Next TD Pointer */
  126. /* rest are purely for the driver's use */
  127. __u8 index;
  128. struct ed *ed;
  129. struct td *td_hash; /* dma-->td hashtable */
  130. struct td *next_dl_td;
  131. struct urb *urb;
  132. dma_addr_t td_dma; /* addr of this TD */
  133. dma_addr_t data_dma; /* addr of data it points to */
  134. struct list_head td_list; /* "shadow list", TDs on same ED */
  135. u32 flags;
  136. #define TD_FLAG_DONE (1 << 17) /* retired to done list */
  137. #define TD_FLAG_ISO (1 << 16) /* copy of ED_ISO */
  138. } __attribute__ ((aligned(TD_ALIGN))); /* c/b/i need 16; only iso needs 32 */
  139. /*
  140. * Hardware transfer status codes -- CC from td->hwINFO
  141. */
  142. #define TD_CC_NOERROR 0x00
  143. #define TD_CC_CRC 0x01
  144. #define TD_CC_BITSTUFFING 0x02
  145. #define TD_CC_DATATOGGLEM 0x03
  146. #define TD_CC_STALL 0x04
  147. #define TD_CC_DEVNOTRESP 0x05
  148. #define TD_CC_PIDCHECKFAIL 0x06
  149. #define TD_CC_UNEXPECTEDPID 0x07
  150. #define TD_CC_DATAOVERRUN 0x08
  151. #define TD_CC_DATAUNDERRUN 0x09
  152. /* 0x0A, 0x0B reserved for hardware */
  153. #define TD_CC_BUFFEROVERRUN 0x0C
  154. #define TD_CC_BUFFERUNDERRUN 0x0D
  155. /* 0x0E, 0x0F reserved for HCD */
  156. #define TD_CC_HCD0 0x0E
  157. #define TD_CC_NOTACCESSED 0x0F
  158. /*
  159. * preshifted status codes
  160. */
  161. #define TD_SCC_NOTACCESSED (TD_CC_NOTACCESSED << TD_CC_SHIFT)
  162. /* map OHCI TD status codes (CC) to errno values */
  163. static const int cc_to_error[16] = {
  164. /* No Error */ 0,
  165. /* CRC Error */ -EILSEQ,
  166. /* Bit Stuff */ -EPROTO,
  167. /* Data Togg */ -EILSEQ,
  168. /* Stall */ -EPIPE,
  169. /* DevNotResp */ -ETIME,
  170. /* PIDCheck */ -EPROTO,
  171. /* UnExpPID */ -EPROTO,
  172. /* DataOver */ -EOVERFLOW,
  173. /* DataUnder */ -EREMOTEIO,
  174. /* (for hw) */ -EIO,
  175. /* (for hw) */ -EIO,
  176. /* BufferOver */ -ECOMM,
  177. /* BuffUnder */ -ENOSR,
  178. /* (for HCD) */ -EALREADY,
  179. /* (for HCD) */ -EALREADY
  180. };
  181. #define NUM_INTS 32
  182. /*
  183. * This is the structure of the OHCI controller's memory mapped I/O region.
  184. * You must use readl() and writel() (in <asm/io.h>) to access these fields!!
  185. * Layout is in section 7 (and appendix B) of the spec.
  186. */
  187. struct admhcd_regs {
  188. __hc32 gencontrol; /* General Control */
  189. __hc32 int_status; /* Interrupt Status */
  190. __hc32 int_enable; /* Interrupt Enable */
  191. __hc32 reserved00;
  192. __hc32 host_control; /* Host General Control */
  193. __hc32 reserved01;
  194. __hc32 fminterval; /* Frame Interval */
  195. __hc32 fmnumber; /* Frame Number */
  196. __hc32 reserved02;
  197. __hc32 reserved03;
  198. __hc32 reserved04;
  199. __hc32 reserved05;
  200. __hc32 reserved06;
  201. __hc32 reserved07;
  202. __hc32 reserved08;
  203. __hc32 reserved09;
  204. __hc32 reserved10;
  205. __hc32 reserved11;
  206. __hc32 reserved12;
  207. __hc32 reserved13;
  208. __hc32 reserved14;
  209. __hc32 reserved15;
  210. __hc32 reserved16;
  211. __hc32 reserved17;
  212. __hc32 reserved18;
  213. __hc32 reserved19;
  214. __hc32 reserved20;
  215. __hc32 reserved21;
  216. __hc32 lsthresh; /* Low Speed Threshold */
  217. __hc32 rhdesc; /* Root Hub Descriptor */
  218. #define MAX_ROOT_PORTS 2
  219. __hc32 portstatus[MAX_ROOT_PORTS]; /* Port Status */
  220. __hc32 hosthead; /* Host Descriptor Head */
  221. } __attribute__ ((aligned(32)));
  222. /*
  223. * General Control register bits
  224. */
  225. #define ADMHC_CTRL_UHFE (1 << 0) /* USB Host Function Enable */
  226. #define ADMHC_CTRL_SIR (1 << 1) /* Software Interrupt request */
  227. #define ADMHC_CTRL_DMAA (1 << 2) /* DMA Arbitration Control */
  228. #define ADMHC_CTRL_SR (1 << 3) /* Software Reset */
  229. /*
  230. * Host General Control register bits
  231. */
  232. #define ADMHC_HC_BUSS 0x3 /* USB bus state */
  233. #define ADMHC_BUSS_RESET 0x0
  234. #define ADMHC_BUSS_RESUME 0x1
  235. #define ADMHC_BUSS_OPER 0x2
  236. #define ADMHC_BUSS_SUSPEND 0x3
  237. #define ADMHC_HC_DMAE (1 << 2) /* DMA enable */
  238. /*
  239. * Interrupt Status/Enable register bits
  240. */
  241. #define ADMHC_INTR_SOFI (1 << 4) /* start of frame */
  242. #define ADMHC_INTR_RESI (1 << 5) /* resume detected */
  243. #define ADMHC_INTR_6 (1 << 6) /* unknown */
  244. #define ADMHC_INTR_7 (1 << 7) /* unknown */
  245. #define ADMHC_INTR_BABI (1 << 8) /* babble detected */
  246. #define ADMHC_INTR_INSM (1 << 9) /* root hub status change */
  247. #define ADMHC_INTR_SO (1 << 10) /* scheduling overrun */
  248. #define ADMHC_INTR_FNO (1 << 11) /* frame number overflow */
  249. #define ADMHC_INTR_TDC (1 << 20) /* transfer descriptor completed */
  250. #define ADMHC_INTR_SWI (1 << 29) /* software interrupt */
  251. #define ADMHC_INTR_FATI (1 << 30) /* fatal error */
  252. #define ADMHC_INTR_INTA (1 << 31) /* interrupt active */
  253. #define ADMHC_INTR_MIE (1 << 31) /* master interrupt enable */
  254. /*
  255. * SOF Frame Interval register bits
  256. */
  257. #define ADMHC_SFI_FI_MASK ((1 << 14)-1) /* Frame Interval value */
  258. #define ADMHC_SFI_FSLDP_SHIFT 16
  259. #define ADMHC_SFI_FSLDP_MASK ((1 << 15)-1)
  260. #define ADMHC_SFI_FIT (1 << 31) /* Frame Interval Toggle */
  261. /*
  262. * SOF Frame Number register bits
  263. */
  264. #define ADMHC_SFN_FN_MASK ((1 << 16)-1) /* Frame Number Mask */
  265. #define ADMHC_SFN_FR_SHIFT 16 /* Frame Remaining Shift */
  266. #define ADMHC_SFN_FR_MASK ((1 << 14)-1) /* Frame Remaining Mask */
  267. #define ADMHC_SFN_FRT (1 << 31) /* Frame Remaining Toggle */
  268. /*
  269. * Root Hub Descriptor register bits
  270. */
  271. #define ADMHC_RH_NUMP 0xff /* number of ports */
  272. #define ADMHC_RH_PSM (1 << 8) /* power switching mode */
  273. #define ADMHC_RH_NPS (1 << 9) /* no power switching */
  274. #define ADMHC_RH_OCPM (1 << 10) /* over current protection mode */
  275. #define ADMHC_RH_NOCP (1 << 11) /* no over current protection */
  276. #define ADMHC_RH_PPCM (0xff << 16) /* port power control */
  277. #define ADMHC_RH_LPS (1 << 24) /* local power switch */
  278. #define ADMHC_RH_OCI (1 << 25) /* over current indicator */
  279. /* status change bits */
  280. #define ADMHC_RH_LPSC (1 << 26) /* local power switch change */
  281. #define ADMHC_RH_OCIC (1 << 27) /* over current indicator change */
  282. #define ADMHC_RH_DRWE (1 << 28) /* device remote wakeup enable */
  283. #define ADMHC_RH_CRWE (1 << 29) /* clear remote wakeup enable */
  284. #define ADMHC_RH_CGP (1 << 24) /* clear global power */
  285. #define ADMHC_RH_SGP (1 << 26) /* set global power */
  286. /*
  287. * Port Status register bits
  288. */
  289. #define ADMHC_PS_CCS (1 << 0) /* current connect status */
  290. #define ADMHC_PS_PES (1 << 1) /* port enable status */
  291. #define ADMHC_PS_PSS (1 << 2) /* port suspend status */
  292. #define ADMHC_PS_POCI (1 << 3) /* port over current indicator */
  293. #define ADMHC_PS_PRS (1 << 4) /* port reset status */
  294. #define ADMHC_PS_PPS (1 << 8) /* port power status */
  295. #define ADMHC_PS_LSDA (1 << 9) /* low speed device attached */
  296. /* status change bits */
  297. #define ADMHC_PS_CSC (1 << 16) /* connect status change */
  298. #define ADMHC_PS_PESC (1 << 17) /* port enable status change */
  299. #define ADMHC_PS_PSSC (1 << 18) /* port suspend status change */
  300. #define ADMHC_PS_OCIC (1 << 19) /* over current indicator change */
  301. #define ADMHC_PS_PRSC (1 << 20) /* port reset status change */
  302. /* port feature bits */
  303. #define ADMHC_PS_CPE (1 << 0) /* clear port enable */
  304. #define ADMHC_PS_SPE (1 << 1) /* set port enable */
  305. #define ADMHC_PS_SPS (1 << 2) /* set port suspend */
  306. #define ADMHC_PS_CPS (1 << 3) /* clear suspend status */
  307. #define ADMHC_PS_SPR (1 << 4) /* set port reset */
  308. #define ADMHC_PS_SPP (1 << 8) /* set port power */
  309. #define ADMHC_PS_CPP (1 << 9) /* clear port power */
  310. /*
  311. * the POTPGT value is not defined in the ADMHC, so define a dummy value
  312. */
  313. #define ADMHC_POTPGT 2 /* in ms */
  314. /* hcd-private per-urb state */
  315. struct urb_priv {
  316. struct ed *ed;
  317. struct list_head pending; /* URBs on the same ED */
  318. u32 td_cnt; /* # tds in this request */
  319. u32 td_idx; /* index of the current td */
  320. struct td *td[0]; /* all TDs in this request */
  321. };
  322. #define TD_HASH_SIZE 64 /* power'o'two */
  323. /* sizeof (struct td) ~= 64 == 2^6 ... */
  324. #define TD_HASH_FUNC(td_dma) ((td_dma ^ (td_dma >> 6)) % TD_HASH_SIZE)
  325. /*
  326. * This is the full ADMHCD controller description
  327. *
  328. * Note how the "proper" USB information is just
  329. * a subset of what the full implementation needs. (Linus)
  330. */
  331. struct admhcd {
  332. spinlock_t lock;
  333. /*
  334. * I/O memory used to communicate with the HC (dma-consistent)
  335. */
  336. struct admhcd_regs __iomem *regs;
  337. /*
  338. * hcd adds to schedule for a live hc any time, but removals finish
  339. * only at the start of the next frame.
  340. */
  341. struct ed *ed_head;
  342. struct ed *ed_tails[4];
  343. struct ed *ed_rm_list; /* to be removed */
  344. struct ed *periodic[NUM_INTS]; /* shadow int_table */
  345. #if 0 /* TODO: remove? */
  346. /*
  347. * OTG controllers and transceivers need software interaction;
  348. * other external transceivers should be software-transparent
  349. */
  350. struct otg_transceiver *transceiver;
  351. void (*start_hnp)(struct admhcd *ahcd);
  352. #endif
  353. /*
  354. * memory management for queue data structures
  355. */
  356. struct dma_pool *td_cache;
  357. struct dma_pool *ed_cache;
  358. struct td *td_hash[TD_HASH_SIZE];
  359. struct list_head pending;
  360. /*
  361. * driver state
  362. */
  363. int num_ports;
  364. int load[NUM_INTS];
  365. u32 host_control; /* copy of the host_control reg */
  366. unsigned long next_statechange; /* suspend/resume */
  367. u32 fminterval; /* saved register */
  368. unsigned autostop:1; /* rh auto stopping/stopped */
  369. unsigned long flags; /* for HC bugs */
  370. #define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
  371. #define OHCI_QUIRK_SUPERIO 0x02 /* natsemi */
  372. #define OHCI_QUIRK_INITRESET 0x04 /* SiS, OPTi, ... */
  373. #define OHCI_QUIRK_BE_DESC 0x08 /* BE descriptors */
  374. #define OHCI_QUIRK_BE_MMIO 0x10 /* BE registers */
  375. #define OHCI_QUIRK_ZFMICRO 0x20 /* Compaq ZFMicro chipset*/
  376. /* there are also chip quirks/bugs in init logic */
  377. #ifdef DEBUG
  378. struct dentry *debug_dir;
  379. struct dentry *debug_async;
  380. struct dentry *debug_periodic;
  381. struct dentry *debug_registers;
  382. #endif
  383. };
  384. /* convert between an hcd pointer and the corresponding ahcd_hcd */
  385. static inline struct admhcd *hcd_to_admhcd(struct usb_hcd *hcd)
  386. {
  387. return (struct admhcd *)(hcd->hcd_priv);
  388. }
  389. static inline struct usb_hcd *admhcd_to_hcd(const struct admhcd *ahcd)
  390. {
  391. return container_of((void *)ahcd, struct usb_hcd, hcd_priv);
  392. }
  393. /*-------------------------------------------------------------------------*/
  394. #ifndef DEBUG
  395. #define STUB_DEBUG_FILES
  396. #endif /* DEBUG */
  397. #ifdef DEBUG
  398. # define admhc_dbg(ahcd, fmt, args...) \
  399. printk(KERN_DEBUG "adm5120-hcd: " fmt, ## args)
  400. #else
  401. # define admhc_dbg(ahcd, fmt, args...) do { } while (0)
  402. #endif
  403. #define admhc_err(ahcd, fmt, args...) \
  404. printk(KERN_ERR "adm5120-hcd: " fmt, ## args)
  405. #define admhc_info(ahcd, fmt, args...) \
  406. printk(KERN_INFO "adm5120-hcd: " fmt, ## args)
  407. #define admhc_warn(ahcd, fmt, args...) \
  408. printk(KERN_WARNING "adm5120-hcd: " fmt, ## args)
  409. #ifdef ADMHC_VERBOSE_DEBUG
  410. # define admhc_vdbg admhc_dbg
  411. #else
  412. # define admhc_vdbg(ahcd, fmt, args...) do { } while (0)
  413. #endif
  414. /*-------------------------------------------------------------------------*/
  415. /*
  416. * While most USB host controllers implement their registers and
  417. * in-memory communication descriptors in little-endian format,
  418. * a minority (notably the IBM STB04XXX and the Motorola MPC5200
  419. * processors) implement them in big endian format.
  420. *
  421. * In addition some more exotic implementations like the Toshiba
  422. * Spider (aka SCC) cell southbridge are "mixed" endian, that is,
  423. * they have a different endianness for registers vs. in-memory
  424. * descriptors.
  425. *
  426. * This attempts to support either format at compile time without a
  427. * runtime penalty, or both formats with the additional overhead
  428. * of checking a flag bit.
  429. *
  430. * That leads to some tricky Kconfig rules howevber. There are
  431. * different defaults based on some arch/ppc platforms, though
  432. * the basic rules are:
  433. *
  434. * Controller type Kconfig options needed
  435. * --------------- ----------------------
  436. * little endian CONFIG_USB_ADMHC_LITTLE_ENDIAN
  437. *
  438. * fully big endian CONFIG_USB_ADMHC_BIG_ENDIAN_DESC _and_
  439. * CONFIG_USB_ADMHC_BIG_ENDIAN_MMIO
  440. *
  441. * mixed endian CONFIG_USB_ADMHC_LITTLE_ENDIAN _and_
  442. * CONFIG_USB_OHCI_BIG_ENDIAN_{MMIO,DESC}
  443. *
  444. * (If you have a mixed endian controller, you -must- also define
  445. * CONFIG_USB_ADMHC_LITTLE_ENDIAN or things will not work when building
  446. * both your mixed endian and a fully big endian controller support in
  447. * the same kernel image).
  448. */
  449. #ifdef CONFIG_USB_ADMHC_BIG_ENDIAN_DESC
  450. #ifdef CONFIG_USB_ADMHC_LITTLE_ENDIAN
  451. #define big_endian_desc(ahcd) (ahcd->flags & OHCI_QUIRK_BE_DESC)
  452. #else
  453. #define big_endian_desc(ahcd) 1 /* only big endian */
  454. #endif
  455. #else
  456. #define big_endian_desc(ahcd) 0 /* only little endian */
  457. #endif
  458. #ifdef CONFIG_USB_ADMHC_BIG_ENDIAN_MMIO
  459. #ifdef CONFIG_USB_ADMHC_LITTLE_ENDIAN
  460. #define big_endian_mmio(ahcd) (ahcd->flags & OHCI_QUIRK_BE_MMIO)
  461. #else
  462. #define big_endian_mmio(ahcd) 1 /* only big endian */
  463. #endif
  464. #else
  465. #define big_endian_mmio(ahcd) 0 /* only little endian */
  466. #endif
  467. /*
  468. * Big-endian read/write functions are arch-specific.
  469. * Other arches can be added if/when they're needed.
  470. *
  471. */
  472. static inline unsigned int admhc_readl(const struct admhcd *ahcd,
  473. __hc32 __iomem *regs)
  474. {
  475. #ifdef CONFIG_USB_ADMHC_BIG_ENDIAN_MMIO
  476. return big_endian_mmio(ahcd) ?
  477. readl_be(regs) :
  478. readl(regs);
  479. #else
  480. return readl(regs);
  481. #endif
  482. }
  483. static inline void admhc_writel(const struct admhcd *ahcd,
  484. const unsigned int val, __hc32 __iomem *regs)
  485. {
  486. #ifdef CONFIG_USB_ADMHC_BIG_ENDIAN_MMIO
  487. big_endian_mmio(ahcd) ?
  488. writel_be(val, regs) :
  489. writel(val, regs);
  490. #else
  491. writel(val, regs);
  492. #endif
  493. }
  494. static inline void admhc_writel_flush(const struct admhcd *ahcd)
  495. {
  496. #if 0
  497. /* TODO: remove? */
  498. (void) admhc_readl(ahcd, &ahcd->regs->gencontrol);
  499. #endif
  500. }
  501. /*-------------------------------------------------------------------------*/
  502. /* cpu to ahcd */
  503. static inline __hc16 cpu_to_hc16(const struct admhcd *ahcd, const u16 x)
  504. {
  505. return big_endian_desc(ahcd) ?
  506. (__force __hc16)cpu_to_be16(x) :
  507. (__force __hc16)cpu_to_le16(x);
  508. }
  509. static inline __hc16 cpu_to_hc16p(const struct admhcd *ahcd, const u16 *x)
  510. {
  511. return big_endian_desc(ahcd) ?
  512. cpu_to_be16p(x) :
  513. cpu_to_le16p(x);
  514. }
  515. static inline __hc32 cpu_to_hc32(const struct admhcd *ahcd, const u32 x)
  516. {
  517. return big_endian_desc(ahcd) ?
  518. (__force __hc32)cpu_to_be32(x) :
  519. (__force __hc32)cpu_to_le32(x);
  520. }
  521. static inline __hc32 cpu_to_hc32p(const struct admhcd *ahcd, const u32 *x)
  522. {
  523. return big_endian_desc(ahcd) ?
  524. cpu_to_be32p(x) :
  525. cpu_to_le32p(x);
  526. }
  527. /* ahcd to cpu */
  528. static inline u16 hc16_to_cpu(const struct admhcd *ahcd, const __hc16 x)
  529. {
  530. return big_endian_desc(ahcd) ?
  531. be16_to_cpu((__force __be16)x) :
  532. le16_to_cpu((__force __le16)x);
  533. }
  534. static inline u16 hc16_to_cpup(const struct admhcd *ahcd, const __hc16 *x)
  535. {
  536. return big_endian_desc(ahcd) ?
  537. be16_to_cpup((__force __be16 *)x) :
  538. le16_to_cpup((__force __le16 *)x);
  539. }
  540. static inline u32 hc32_to_cpu(const struct admhcd *ahcd, const __hc32 x)
  541. {
  542. return big_endian_desc(ahcd) ?
  543. be32_to_cpu((__force __be32)x) :
  544. le32_to_cpu((__force __le32)x);
  545. }
  546. static inline u32 hc32_to_cpup(const struct admhcd *ahcd, const __hc32 *x)
  547. {
  548. return big_endian_desc(ahcd) ?
  549. be32_to_cpup((__force __be32 *)x) :
  550. le32_to_cpup((__force __le32 *)x);
  551. }
  552. /*-------------------------------------------------------------------------*/
  553. static inline u16 admhc_frame_no(const struct admhcd *ahcd)
  554. {
  555. u32 t;
  556. t = admhc_readl(ahcd, &ahcd->regs->fmnumber) & ADMHC_SFN_FN_MASK;
  557. return (u16)t;
  558. }
  559. static inline u16 admhc_frame_remain(const struct admhcd *ahcd)
  560. {
  561. u32 t;
  562. t = admhc_readl(ahcd, &ahcd->regs->fmnumber) >> ADMHC_SFN_FR_SHIFT;
  563. t &= ADMHC_SFN_FR_MASK;
  564. return (u16)t;
  565. }
  566. /*-------------------------------------------------------------------------*/
  567. static inline void admhc_disable(struct admhcd *ahcd)
  568. {
  569. admhcd_to_hcd(ahcd)->state = HC_STATE_HALT;
  570. }
  571. #define FI 0x2edf /* 12000 bits per frame (-1) */
  572. #define FSLDP(fi) (0x7fff & ((6 * ((fi) - 1200)) / 7))
  573. #define FIT ADMHC_SFI_FIT
  574. #define LSTHRESH 0x628 /* lowspeed bit threshold */
  575. static inline void periodic_reinit(struct admhcd *ahcd)
  576. {
  577. #if 0
  578. u32 fi = ahcd->fminterval & ADMHC_SFI_FI_MASK;
  579. u32 fit = admhc_readl(ahcd, &ahcd->regs->fminterval) & FIT;
  580. /* TODO: adjust FSLargestDataPacket value too? */
  581. admhc_writel(ahcd, (fit ^ FIT) | ahcd->fminterval,
  582. &ahcd->regs->fminterval);
  583. #else
  584. u32 fit = admhc_readl(ahcd, &ahcd->regs->fminterval) & FIT;
  585. /* TODO: adjust FSLargestDataPacket value too? */
  586. admhc_writel(ahcd, (fit ^ FIT) | ahcd->fminterval,
  587. &ahcd->regs->fminterval);
  588. #endif
  589. }
  590. static inline u32 admhc_read_rhdesc(struct admhcd *ahcd)
  591. {
  592. return admhc_readl(ahcd, &ahcd->regs->rhdesc);
  593. }
  594. static inline u32 admhc_read_portstatus(struct admhcd *ahcd, int port)
  595. {
  596. return admhc_readl(ahcd, &ahcd->regs->portstatus[port]);
  597. }
  598. static inline void admhc_write_portstatus(struct admhcd *ahcd, int port,
  599. u32 value)
  600. {
  601. admhc_writel(ahcd, value, &ahcd->regs->portstatus[port]);
  602. }
  603. static inline void roothub_write_status(struct admhcd *ahcd, u32 value)
  604. {
  605. /* FIXME: read-only bits must be masked out */
  606. admhc_writel(ahcd, value, &ahcd->regs->rhdesc);
  607. }
  608. static inline void admhc_intr_disable(struct admhcd *ahcd, u32 ints)
  609. {
  610. u32 t;
  611. t = admhc_readl(ahcd, &ahcd->regs->int_enable);
  612. t &= ~(ints);
  613. admhc_writel(ahcd, t, &ahcd->regs->int_enable);
  614. /* TODO: flush writes ?*/
  615. }
  616. static inline void admhc_intr_enable(struct admhcd *ahcd, u32 ints)
  617. {
  618. u32 t;
  619. t = admhc_readl(ahcd, &ahcd->regs->int_enable);
  620. t |= ints;
  621. admhc_writel(ahcd, t, &ahcd->regs->int_enable);
  622. /* TODO: flush writes ?*/
  623. }
  624. static inline void admhc_intr_ack(struct admhcd *ahcd, u32 ints)
  625. {
  626. admhc_writel(ahcd, ints, &ahcd->regs->int_status);
  627. }
  628. static inline void admhc_dma_enable(struct admhcd *ahcd)
  629. {
  630. u32 t;
  631. t = admhc_readl(ahcd, &ahcd->regs->host_control);
  632. if (t & ADMHC_HC_DMAE)
  633. return;
  634. t |= ADMHC_HC_DMAE;
  635. admhc_writel(ahcd, t, &ahcd->regs->host_control);
  636. admhc_vdbg(ahcd, "DMA enabled\n");
  637. }
  638. static inline void admhc_dma_disable(struct admhcd *ahcd)
  639. {
  640. u32 t;
  641. t = admhc_readl(ahcd, &ahcd->regs->host_control);
  642. if (!(t & ADMHC_HC_DMAE))
  643. return;
  644. t &= ~ADMHC_HC_DMAE;
  645. admhc_writel(ahcd, t, &ahcd->regs->host_control);
  646. admhc_vdbg(ahcd, "DMA disabled\n");
  647. }