r8a66597.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * R8A66597 HCD (Host Controller Driver) for u-boot
  3. *
  4. * Copyright (C) 2008 Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0
  7. */
  8. #ifndef __R8A66597_H__
  9. #define __R8A66597_H__
  10. #define SYSCFG0 0x00
  11. #define SYSCFG1 0x02
  12. #define SYSSTS0 0x04
  13. #define SYSSTS1 0x06
  14. #define DVSTCTR0 0x08
  15. #define DVSTCTR1 0x0A
  16. #define TESTMODE 0x0C
  17. #define PINCFG 0x0E
  18. #define DMA0CFG 0x10
  19. #define DMA1CFG 0x12
  20. #define CFIFO 0x14
  21. #define D0FIFO 0x18
  22. #define D1FIFO 0x1C
  23. #define CFIFOSEL 0x20
  24. #define CFIFOCTR 0x22
  25. #define CFIFOSIE 0x24
  26. #define D0FIFOSEL 0x28
  27. #define D0FIFOCTR 0x2A
  28. #define D1FIFOSEL 0x2C
  29. #define D1FIFOCTR 0x2E
  30. #define INTENB0 0x30
  31. #define INTENB1 0x32
  32. #define INTENB2 0x34
  33. #define BRDYENB 0x36
  34. #define NRDYENB 0x38
  35. #define BEMPENB 0x3A
  36. #define SOFCFG 0x3C
  37. #define INTSTS0 0x40
  38. #define INTSTS1 0x42
  39. #define INTSTS2 0x44
  40. #define BRDYSTS 0x46
  41. #define NRDYSTS 0x48
  42. #define BEMPSTS 0x4A
  43. #define FRMNUM 0x4C
  44. #define UFRMNUM 0x4E
  45. #define USBADDR 0x50
  46. #define USBREQ 0x54
  47. #define USBVAL 0x56
  48. #define USBINDX 0x58
  49. #define USBLENG 0x5A
  50. #define DCPCFG 0x5C
  51. #define DCPMAXP 0x5E
  52. #define DCPCTR 0x60
  53. #define PIPESEL 0x64
  54. #define PIPECFG 0x68
  55. #define PIPEBUF 0x6A
  56. #define PIPEMAXP 0x6C
  57. #define PIPEPERI 0x6E
  58. #define PIPE1CTR 0x70
  59. #define PIPE2CTR 0x72
  60. #define PIPE3CTR 0x74
  61. #define PIPE4CTR 0x76
  62. #define PIPE5CTR 0x78
  63. #define PIPE6CTR 0x7A
  64. #define PIPE7CTR 0x7C
  65. #define PIPE8CTR 0x7E
  66. #define PIPE9CTR 0x80
  67. #define PIPE1TRE 0x90
  68. #define PIPE1TRN 0x92
  69. #define PIPE2TRE 0x94
  70. #define PIPE2TRN 0x96
  71. #define PIPE3TRE 0x98
  72. #define PIPE3TRN 0x9A
  73. #define PIPE4TRE 0x9C
  74. #define PIPE4TRN 0x9E
  75. #define PIPE5TRE 0xA0
  76. #define PIPE5TRN 0xA2
  77. #define DEVADD0 0xD0
  78. #define DEVADD1 0xD2
  79. #define DEVADD2 0xD4
  80. #define DEVADD3 0xD6
  81. #define DEVADD4 0xD8
  82. #define DEVADD5 0xDA
  83. #define DEVADD6 0xDC
  84. #define DEVADD7 0xDE
  85. #define DEVADD8 0xE0
  86. #define DEVADD9 0xE2
  87. #define DEVADDA 0xE4
  88. #define SUSPMODE0 0x102 /* RZ/A only */
  89. /* System Configuration Control Register */
  90. #if !defined(CONFIG_RZA_USB)
  91. #define XTAL 0xC000 /* b15-14: Crystal selection */
  92. #define XTAL48 0x8000 /* 48MHz */
  93. #define XTAL24 0x4000 /* 24MHz */
  94. #define XTAL12 0x0000 /* 12MHz */
  95. #define XCKE 0x2000 /* b13: External clock enable */
  96. #define PLLC 0x0800 /* b11: PLL control */
  97. #define SCKE 0x0400 /* b10: USB clock enable */
  98. #define PCSDIS 0x0200 /* b9: not CS wakeup */
  99. #define LPSME 0x0100 /* b8: Low power sleep mode */
  100. #endif
  101. #define HSE 0x0080 /* b7: Hi-speed enable */
  102. #define DCFM 0x0040 /* b6: Controller function select */
  103. #define DRPD 0x0020 /* b5: D+/- pull down control */
  104. #define DPRPU 0x0010 /* b4: D+ pull up control */
  105. #if defined(CONFIG_RZA_USB)
  106. #define XTAL 0x0004 /* b2: Crystal selection */
  107. #define XTAL12 0x0004 /* 12MHz */
  108. #define XTAL48 0x0000 /* 48MHz */
  109. #define UPLLE 0x0002 /* b1: internal PLL control */
  110. #endif
  111. #define USBE 0x0001 /* b0: USB module operation enable */
  112. /* System Configuration Status Register */
  113. #define OVCBIT 0x8000 /* b15-14: Over-current bit */
  114. #define OVCMON 0xC000 /* b15-14: Over-current monitor */
  115. #define SOFEA 0x0020 /* b5: SOF monitor */
  116. #define IDMON 0x0004 /* b3: ID-pin monitor */
  117. #define LNST 0x0003 /* b1-0: D+, D- line status */
  118. #define SE1 0x0003 /* SE1 */
  119. #define FS_KSTS 0x0002 /* Full-Speed K State */
  120. #define FS_JSTS 0x0001 /* Full-Speed J State */
  121. #define LS_JSTS 0x0002 /* Low-Speed J State */
  122. #define LS_KSTS 0x0001 /* Low-Speed K State */
  123. #define SE0 0x0000 /* SE0 */
  124. /* Device State Control Register */
  125. #define EXTLP0 0x0400 /* b10: External port */
  126. #define VBOUT 0x0200 /* b9: VBUS output */
  127. #define WKUP 0x0100 /* b8: Remote wakeup */
  128. #define RWUPE 0x0080 /* b7: Remote wakeup sense */
  129. #define USBRST 0x0040 /* b6: USB reset enable */
  130. #define RESUME 0x0020 /* b5: Resume enable */
  131. #define UACT 0x0010 /* b4: USB bus enable */
  132. #define RHST 0x0007 /* b1-0: Reset handshake status */
  133. #define HSPROC 0x0004 /* HS handshake is processing */
  134. #define HSMODE 0x0003 /* Hi-Speed mode */
  135. #define FSMODE 0x0002 /* Full-Speed mode */
  136. #define LSMODE 0x0001 /* Low-Speed mode */
  137. #define UNDECID 0x0000 /* Undecided */
  138. /* Test Mode Register */
  139. #define UTST 0x000F /* b3-0: Test select */
  140. #define H_TST_PACKET 0x000C /* HOST TEST Packet */
  141. #define H_TST_SE0_NAK 0x000B /* HOST TEST SE0 NAK */
  142. #define H_TST_K 0x000A /* HOST TEST K */
  143. #define H_TST_J 0x0009 /* HOST TEST J */
  144. #define H_TST_NORMAL 0x0000 /* HOST Normal Mode */
  145. #define P_TST_PACKET 0x0004 /* PERI TEST Packet */
  146. #define P_TST_SE0_NAK 0x0003 /* PERI TEST SE0 NAK */
  147. #define P_TST_K 0x0002 /* PERI TEST K */
  148. #define P_TST_J 0x0001 /* PERI TEST J */
  149. #define P_TST_NORMAL 0x0000 /* PERI Normal Mode */
  150. /* Data Pin Configuration Register */
  151. #define LDRV 0x8000 /* b15: Drive Current Adjust */
  152. #define VIF1 0x0000 /* VIF = 1.8V */
  153. #define VIF3 0x8000 /* VIF = 3.3V */
  154. #define INTA 0x0001 /* b1: USB INT-pin active */
  155. /* DMAx Pin Configuration Register */
  156. #define DREQA 0x4000 /* b14: Dreq active select */
  157. #define BURST 0x2000 /* b13: Burst mode */
  158. #define DACKA 0x0400 /* b10: Dack active select */
  159. #define DFORM 0x0380 /* b9-7: DMA mode select */
  160. #define CPU_ADR_RD_WR 0x0000 /* Address + RD/WR mode (CPU bus) */
  161. #define CPU_DACK_RD_WR 0x0100 /* DACK + RD/WR mode (CPU bus) */
  162. #define CPU_DACK_ONLY 0x0180 /* DACK only mode (CPU bus) */
  163. #define SPLIT_DACK_ONLY 0x0200 /* DACK only mode (SPLIT bus) */
  164. #define DENDA 0x0040 /* b6: Dend active select */
  165. #define PKTM 0x0020 /* b5: Packet mode */
  166. #define DENDE 0x0010 /* b4: Dend enable */
  167. #define OBUS 0x0004 /* b2: OUTbus mode */
  168. /* CFIFO/DxFIFO Port Select Register */
  169. #define RCNT 0x8000 /* b15: Read count mode */
  170. #define REW 0x4000 /* b14: Buffer rewind */
  171. #define DCLRM 0x2000 /* b13: DMA buffer clear mode */
  172. #define DREQE 0x1000 /* b12: DREQ output enable */
  173. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  174. #define MBW 0x0800
  175. #else
  176. #if !defined(CONFIG_RZA_USB)
  177. #define MBW 0x0400 /* b10: Maximum bit width for FIFO access */
  178. #else
  179. #define MBW 0x0800 /* b10: Maximum bit width for FIFO access */
  180. #endif
  181. #endif
  182. #define MBW_8 0x0000 /* 8bit */
  183. #define MBW_16 0x0400 /* 16bit */
  184. #define MBW_32 0x0800 /* 32bit */
  185. #define BIGEND 0x0100 /* b8: Big endian mode */
  186. #define BYTE_LITTLE 0x0000 /* little dendian */
  187. #define BYTE_BIG 0x0100 /* big endifan */
  188. #define ISEL 0x0020 /* b5: DCP FIFO port direction select */
  189. #define CURPIPE 0x000F /* b2-0: PIPE select */
  190. /* CFIFO/DxFIFO Port Control Register */
  191. #define BVAL 0x8000 /* b15: Buffer valid flag */
  192. #define BCLR 0x4000 /* b14: Buffer clear */
  193. #define FRDY 0x2000 /* b13: FIFO ready */
  194. #define DTLN 0x0FFF /* b11-0: FIFO received data length */
  195. /* Interrupt Enable Register 0 */
  196. #define VBSE 0x8000 /* b15: VBUS interrupt */
  197. #define RSME 0x4000 /* b14: Resume interrupt */
  198. #define SOFE 0x2000 /* b13: Frame update interrupt */
  199. #define DVSE 0x1000 /* b12: Device state transition interrupt */
  200. #define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */
  201. #define BEMPE 0x0400 /* b10: Buffer empty interrupt */
  202. #define NRDYE 0x0200 /* b9: Buffer not ready interrupt */
  203. #define BRDYE 0x0100 /* b8: Buffer ready interrupt */
  204. /* Interrupt Enable Register 1 */
  205. #define OVRCRE 0x8000 /* b15: Over-current interrupt */
  206. #define BCHGE 0x4000 /* b14: USB us chenge interrupt */
  207. #define DTCHE 0x1000 /* b12: Detach sense interrupt */
  208. #define ATTCHE 0x0800 /* b11: Attach sense interrupt */
  209. #define EOFERRE 0x0040 /* b6: EOF error interrupt */
  210. #define SIGNE 0x0020 /* b5: SETUP IGNORE interrupt */
  211. #define SACKE 0x0010 /* b4: SETUP ACK interrupt */
  212. /* BRDY Interrupt Enable/Status Register */
  213. #define BRDY9 0x0200 /* b9: PIPE9 */
  214. #define BRDY8 0x0100 /* b8: PIPE8 */
  215. #define BRDY7 0x0080 /* b7: PIPE7 */
  216. #define BRDY6 0x0040 /* b6: PIPE6 */
  217. #define BRDY5 0x0020 /* b5: PIPE5 */
  218. #define BRDY4 0x0010 /* b4: PIPE4 */
  219. #define BRDY3 0x0008 /* b3: PIPE3 */
  220. #define BRDY2 0x0004 /* b2: PIPE2 */
  221. #define BRDY1 0x0002 /* b1: PIPE1 */
  222. #define BRDY0 0x0001 /* b1: PIPE0 */
  223. /* NRDY Interrupt Enable/Status Register */
  224. #define NRDY9 0x0200 /* b9: PIPE9 */
  225. #define NRDY8 0x0100 /* b8: PIPE8 */
  226. #define NRDY7 0x0080 /* b7: PIPE7 */
  227. #define NRDY6 0x0040 /* b6: PIPE6 */
  228. #define NRDY5 0x0020 /* b5: PIPE5 */
  229. #define NRDY4 0x0010 /* b4: PIPE4 */
  230. #define NRDY3 0x0008 /* b3: PIPE3 */
  231. #define NRDY2 0x0004 /* b2: PIPE2 */
  232. #define NRDY1 0x0002 /* b1: PIPE1 */
  233. #define NRDY0 0x0001 /* b1: PIPE0 */
  234. /* BEMP Interrupt Enable/Status Register */
  235. #define BEMP9 0x0200 /* b9: PIPE9 */
  236. #define BEMP8 0x0100 /* b8: PIPE8 */
  237. #define BEMP7 0x0080 /* b7: PIPE7 */
  238. #define BEMP6 0x0040 /* b6: PIPE6 */
  239. #define BEMP5 0x0020 /* b5: PIPE5 */
  240. #define BEMP4 0x0010 /* b4: PIPE4 */
  241. #define BEMP3 0x0008 /* b3: PIPE3 */
  242. #define BEMP2 0x0004 /* b2: PIPE2 */
  243. #define BEMP1 0x0002 /* b1: PIPE1 */
  244. #define BEMP0 0x0001 /* b0: PIPE0 */
  245. /* SOF Pin Configuration Register */
  246. #define TRNENSEL 0x0100 /* b8: Select transaction enable period */
  247. #define BRDYM 0x0040 /* b6: BRDY clear timing */
  248. #define INTL 0x0020 /* b5: Interrupt sense select */
  249. #define EDGESTS 0x0010 /* b4: */
  250. #define SOFMODE 0x000C /* b3-2: SOF pin select */
  251. #define SOF_125US 0x0008 /* SOF OUT 125us Frame Signal */
  252. #define SOF_1MS 0x0004 /* SOF OUT 1ms Frame Signal */
  253. #define SOF_DISABLE 0x0000 /* SOF OUT Disable */
  254. /* Interrupt Status Register 0 */
  255. #define VBINT 0x8000 /* b15: VBUS interrupt */
  256. #define RESM 0x4000 /* b14: Resume interrupt */
  257. #define SOFR 0x2000 /* b13: SOF frame update interrupt */
  258. #define DVST 0x1000 /* b12: Device state transition interrupt */
  259. #define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */
  260. #define BEMP 0x0400 /* b10: Buffer empty interrupt */
  261. #define NRDY 0x0200 /* b9: Buffer not ready interrupt */
  262. #define BRDY 0x0100 /* b8: Buffer ready interrupt */
  263. #define VBSTS 0x0080 /* b7: VBUS input port */
  264. #define DVSQ 0x0070 /* b6-4: Device state */
  265. #define DS_SPD_CNFG 0x0070 /* Suspend Configured */
  266. #define DS_SPD_ADDR 0x0060 /* Suspend Address */
  267. #define DS_SPD_DFLT 0x0050 /* Suspend Default */
  268. #define DS_SPD_POWR 0x0040 /* Suspend Powered */
  269. #define DS_SUSP 0x0040 /* Suspend */
  270. #define DS_CNFG 0x0030 /* Configured */
  271. #define DS_ADDS 0x0020 /* Address */
  272. #define DS_DFLT 0x0010 /* Default */
  273. #define DS_POWR 0x0000 /* Powered */
  274. #define DVSQS 0x0030 /* b5-4: Device state */
  275. #define VALID 0x0008 /* b3: Setup packet detected flag */
  276. #define CTSQ 0x0007 /* b2-0: Control transfer stage */
  277. #define CS_SQER 0x0006 /* Sequence error */
  278. #define CS_WRND 0x0005 /* Control write nodata status stage */
  279. #define CS_WRSS 0x0004 /* Control write status stage */
  280. #define CS_WRDS 0x0003 /* Control write data stage */
  281. #define CS_RDSS 0x0002 /* Control read status stage */
  282. #define CS_RDDS 0x0001 /* Control read data stage */
  283. #define CS_IDST 0x0000 /* Idle or setup stage */
  284. /* Interrupt Status Register 1 */
  285. #define OVRCR 0x8000 /* b15: Over-current interrupt */
  286. #define BCHG 0x4000 /* b14: USB bus chenge interrupt */
  287. #define DTCH 0x1000 /* b12: Detach sense interrupt */
  288. #define ATTCH 0x0800 /* b11: Attach sense interrupt */
  289. #define EOFERR 0x0040 /* b6: EOF-error interrupt */
  290. #define SIGN 0x0020 /* b5: Setup ignore interrupt */
  291. #define SACK 0x0010 /* b4: Setup acknowledge interrupt */
  292. /* Frame Number Register */
  293. #define OVRN 0x8000 /* b15: Overrun error */
  294. #define CRCE 0x4000 /* b14: Received data error */
  295. #define FRNM 0x07FF /* b10-0: Frame number */
  296. /* Micro Frame Number Register */
  297. #define UFRNM 0x0007 /* b2-0: Micro frame number */
  298. /* Default Control Pipe Maxpacket Size Register */
  299. /* Pipe Maxpacket Size Register */
  300. #define DEVSEL 0xF000 /* b15-14: Device address select */
  301. #define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */
  302. /* Default Control Pipe Control Register */
  303. #define BSTS 0x8000 /* b15: Buffer status */
  304. #define SUREQ 0x4000 /* b14: Send USB request */
  305. #define CSCLR 0x2000 /* b13: complete-split status clear */
  306. #define CSSTS 0x1000 /* b12: complete-split status */
  307. #define SUREQCLR 0x0800 /* b11: stop setup request */
  308. #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */
  309. #define SQSET 0x0080 /* b7: Sequence toggle bit set */
  310. #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */
  311. #define PBUSY 0x0020 /* b5: pipe busy */
  312. #define PINGE 0x0010 /* b4: ping enable */
  313. #define CCPL 0x0004 /* b2: Enable control transfer complete */
  314. #define PID 0x0003 /* b1-0: Response PID */
  315. #define PID_STALL11 0x0003 /* STALL */
  316. #define PID_STALL 0x0002 /* STALL */
  317. #define PID_BUF 0x0001 /* BUF */
  318. #define PID_NAK 0x0000 /* NAK */
  319. /* Pipe Window Select Register */
  320. #define PIPENM 0x0007 /* b2-0: Pipe select */
  321. /* Pipe Configuration Register */
  322. #define R8A66597_TYP 0xC000 /* b15-14: Transfer type */
  323. #define R8A66597_ISO 0xC000 /* Isochronous */
  324. #define R8A66597_INT 0x8000 /* Interrupt */
  325. #define R8A66597_BULK 0x4000 /* Bulk */
  326. #define R8A66597_BFRE 0x0400 /* b10: Buffer ready interrupt mode select */
  327. #define R8A66597_DBLB 0x0200 /* b9: Double buffer mode select */
  328. #define R8A66597_CNTMD 0x0100 /* b8: Continuous transfer mode select */
  329. #define R8A66597_SHTNAK 0x0080 /* b7: Transfer end NAK */
  330. #define R8A66597_DIR 0x0010 /* b4: Transfer direction select */
  331. #define R8A66597_EPNUM 0x000F /* b3-0: Eendpoint number select */
  332. /* Pipe Buffer Configuration Register */
  333. #define BUFSIZE 0x7C00 /* b14-10: Pipe buffer size */
  334. #define BUFNMB 0x007F /* b6-0: Pipe buffer number */
  335. #define PIPE0BUF 256
  336. #define PIPExBUF 64
  337. /* Pipe Maxpacket Size Register */
  338. #define MXPS 0x07FF /* b10-0: Maxpacket size */
  339. /* Pipe Cycle Configuration Register */
  340. #define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */
  341. #define IITV 0x0007 /* b2-0: Isochronous interval */
  342. /* Pipex Control Register */
  343. #define BSTS 0x8000 /* b15: Buffer status */
  344. #define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */
  345. #define CSCLR 0x2000 /* b13: complete-split status clear */
  346. #define CSSTS 0x1000 /* b12: complete-split status */
  347. #define ATREPM 0x0400 /* b10: Auto repeat mode */
  348. #define ACLRM 0x0200 /* b9: Out buffer auto clear mode */
  349. #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */
  350. #define SQSET 0x0080 /* b7: Sequence toggle bit set */
  351. #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */
  352. #define PBUSY 0x0020 /* b5: pipe busy */
  353. #define PID 0x0003 /* b1-0: Response PID */
  354. /* PIPExTRE */
  355. #define TRENB 0x0200 /* b9: Transaction counter enable */
  356. #define TRCLR 0x0100 /* b8: Transaction counter clear */
  357. /* PIPExTRN */
  358. #define TRNCNT 0xFFFF /* b15-0: Transaction counter */
  359. /* DEVADDx */
  360. #define UPPHUB 0x7800
  361. #define HUBPORT 0x0700
  362. #define USBSPD 0x00C0
  363. #define RTPORT 0x0001
  364. /* Suspend Mode Register */
  365. #define SUSPM 0x4000 /* b14: Suspend */
  366. #define R8A66597_MAX_NUM_PIPE 10
  367. #define R8A66597_BUF_BSIZE 8
  368. #define R8A66597_MAX_DEVICE 10
  369. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  370. #define R8A66597_MAX_ROOT_HUB 1
  371. #else
  372. #define R8A66597_MAX_ROOT_HUB 2
  373. #endif
  374. #define R8A66597_MAX_SAMPLING 5
  375. #define R8A66597_RH_POLL_TIME 10
  376. #define BULK_IN_PIPENUM 3
  377. #define BULK_IN_BUFNUM 8
  378. #define BULK_OUT_PIPENUM 4
  379. #define BULK_OUT_BUFNUM 40
  380. #define check_bulk_or_isoc(pipenum) ((pipenum >= 1 && pipenum <= 5))
  381. #define check_interrupt(pipenum) ((pipenum >= 6 && pipenum <= 9))
  382. #define make_devsel(addr) (addr << 12)
  383. struct r8a66597 {
  384. unsigned long reg;
  385. unsigned short pipe_config; /* bit field */
  386. unsigned short port_status;
  387. unsigned short port_change;
  388. u16 speed; /* HSMODE or FSMODE or LSMODE */
  389. unsigned char rh_devnum;
  390. };
  391. static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset)
  392. {
  393. return inw(r8a66597->reg + offset);
  394. }
  395. static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597,
  396. unsigned long offset, void *buf,
  397. int len)
  398. {
  399. int i;
  400. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) || defined(CONFIG_RZA_USB)
  401. unsigned long fifoaddr = r8a66597->reg + offset;
  402. unsigned long count;
  403. unsigned long *p = buf;
  404. count = len / 4;
  405. for (i = 0; i < count; i++)
  406. p[i] = inl(r8a66597->reg + offset);
  407. if (len & 0x00000003) {
  408. unsigned long tmp = inl(fifoaddr);
  409. memcpy((unsigned char *)buf + count * 4, &tmp, len & 0x03);
  410. }
  411. #else
  412. unsigned short *p = buf;
  413. len = (len + 1) / 2;
  414. for (i = 0; i < len; i++)
  415. p[i] = inw(r8a66597->reg + offset);
  416. #endif
  417. }
  418. static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val,
  419. unsigned long offset)
  420. {
  421. outw(val, r8a66597->reg + offset);
  422. }
  423. static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
  424. unsigned long offset, void *buf,
  425. int len)
  426. {
  427. int i;
  428. unsigned long fifoaddr = r8a66597->reg + offset;
  429. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) || defined(CONFIG_RZA_USB)
  430. unsigned long count;
  431. unsigned char *pb;
  432. unsigned long *p = buf;
  433. count = len / 4;
  434. for (i = 0; i < count; i++)
  435. outl(p[i], fifoaddr);
  436. if (len & 0x00000003) {
  437. pb = (unsigned char *)buf + count * 4;
  438. for (i = 0; i < (len & 0x00000003); i++) {
  439. if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND)
  440. outb(pb[i], fifoaddr + i);
  441. else
  442. outb(pb[i], fifoaddr + 3 - i);
  443. }
  444. }
  445. #else
  446. int odd = len & 0x0001;
  447. unsigned short *p = buf;
  448. len = len / 2;
  449. for (i = 0; i < len; i++)
  450. outw(p[i], fifoaddr);
  451. if (odd) {
  452. unsigned char *pb = (unsigned char *)(buf + len);
  453. outb(*pb, fifoaddr);
  454. }
  455. #endif
  456. }
  457. static inline void r8a66597_mdfy(struct r8a66597 *r8a66597,
  458. u16 val, u16 pat, unsigned long offset)
  459. {
  460. u16 tmp;
  461. tmp = r8a66597_read(r8a66597, offset);
  462. tmp = tmp & (~pat);
  463. tmp = tmp | val;
  464. r8a66597_write(r8a66597, tmp, offset);
  465. }
  466. #define r8a66597_bclr(r8a66597, val, offset) \
  467. r8a66597_mdfy(r8a66597, 0, val, offset)
  468. #define r8a66597_bset(r8a66597, val, offset) \
  469. r8a66597_mdfy(r8a66597, val, 0, offset)
  470. static inline unsigned long get_syscfg_reg(int port)
  471. {
  472. return port == 0 ? SYSCFG0 : SYSCFG1;
  473. }
  474. static inline unsigned long get_syssts_reg(int port)
  475. {
  476. return port == 0 ? SYSSTS0 : SYSSTS1;
  477. }
  478. static inline unsigned long get_dvstctr_reg(int port)
  479. {
  480. return port == 0 ? DVSTCTR0 : DVSTCTR1;
  481. }
  482. static inline unsigned long get_dmacfg_reg(int port)
  483. {
  484. return port == 0 ? DMA0CFG : DMA1CFG;
  485. }
  486. static inline unsigned long get_intenb_reg(int port)
  487. {
  488. return port == 0 ? INTENB1 : INTENB2;
  489. }
  490. static inline unsigned long get_intsts_reg(int port)
  491. {
  492. return port == 0 ? INTSTS1 : INTSTS2;
  493. }
  494. static inline u16 get_rh_usb_speed(struct r8a66597 *r8a66597, int port)
  495. {
  496. unsigned long dvstctr_reg = get_dvstctr_reg(port);
  497. return r8a66597_read(r8a66597, dvstctr_reg) & RHST;
  498. }
  499. static inline void r8a66597_port_power(struct r8a66597 *r8a66597, int port,
  500. int power)
  501. {
  502. unsigned long dvstctr_reg = get_dvstctr_reg(port);
  503. if (power)
  504. r8a66597_bset(r8a66597, VBOUT, dvstctr_reg);
  505. else
  506. r8a66597_bclr(r8a66597, VBOUT, dvstctr_reg);
  507. }
  508. #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2)
  509. #define get_pipetre_addr(pipenum) (PIPE1TRE + (pipenum - 1) * 4)
  510. #define get_pipetrn_addr(pipenum) (PIPE1TRN + (pipenum - 1) * 4)
  511. #define get_devadd_addr(address) (DEVADD0 + address * 2)
  512. /* USB HUB CONSTANTS (not OHCI-specific; see hub.h, based on usb_ohci.h) */
  513. /* destination of request */
  514. #define RH_INTERFACE 0x01
  515. #define RH_ENDPOINT 0x02
  516. #define RH_OTHER 0x03
  517. #define RH_CLASS 0x20
  518. #define RH_VENDOR 0x40
  519. /* Requests: bRequest << 8 | bmRequestType */
  520. #define RH_GET_STATUS 0x0080
  521. #define RH_CLEAR_FEATURE 0x0100
  522. #define RH_SET_FEATURE 0x0300
  523. #define RH_SET_ADDRESS 0x0500
  524. #define RH_GET_DESCRIPTOR 0x0680
  525. #define RH_SET_DESCRIPTOR 0x0700
  526. #define RH_GET_CONFIGURATION 0x0880
  527. #define RH_SET_CONFIGURATION 0x0900
  528. #define RH_GET_STATE 0x0280
  529. #define RH_GET_INTERFACE 0x0A80
  530. #define RH_SET_INTERFACE 0x0B00
  531. #define RH_SYNC_FRAME 0x0C80
  532. /* Our Vendor Specific Request */
  533. #define RH_SET_EP 0x2000
  534. /* Hub port features */
  535. #define RH_PORT_CONNECTION 0x00
  536. #define RH_PORT_ENABLE 0x01
  537. #define RH_PORT_SUSPEND 0x02
  538. #define RH_PORT_OVER_CURRENT 0x03
  539. #define RH_PORT_RESET 0x04
  540. #define RH_PORT_POWER 0x08
  541. #define RH_PORT_LOW_SPEED 0x09
  542. #define RH_C_PORT_CONNECTION 0x10
  543. #define RH_C_PORT_ENABLE 0x11
  544. #define RH_C_PORT_SUSPEND 0x12
  545. #define RH_C_PORT_OVER_CURRENT 0x13
  546. #define RH_C_PORT_RESET 0x14
  547. /* Hub features */
  548. #define RH_C_HUB_LOCAL_POWER 0x00
  549. #define RH_C_HUB_OVER_CURRENT 0x01
  550. #define RH_DEVICE_REMOTE_WAKEUP 0x00
  551. #define RH_ENDPOINT_STALL 0x01
  552. #define RH_ACK 0x01
  553. #define RH_REQ_ERR -1
  554. #define RH_NACK 0x00
  555. /* OHCI ROOT HUB REGISTER MASKS */
  556. /* roothub.portstatus [i] bits */
  557. #define RH_PS_CCS 0x00000001 /* current connect status */
  558. #define RH_PS_PES 0x00000002 /* port enable status*/
  559. #define RH_PS_PSS 0x00000004 /* port suspend status */
  560. #define RH_PS_POCI 0x00000008 /* port over current indicator */
  561. #define RH_PS_PRS 0x00000010 /* port reset status */
  562. #define RH_PS_PPS 0x00000100 /* port power status */
  563. #define RH_PS_LSDA 0x00000200 /* low speed device attached */
  564. #define RH_PS_CSC 0x00010000 /* connect status change */
  565. #define RH_PS_PESC 0x00020000 /* port enable status change */
  566. #define RH_PS_PSSC 0x00040000 /* port suspend status change */
  567. #define RH_PS_OCIC 0x00080000 /* over current indicator change */
  568. #define RH_PS_PRSC 0x00100000 /* port reset status change */
  569. /* roothub.status bits */
  570. #define RH_HS_LPS 0x00000001 /* local power status */
  571. #define RH_HS_OCI 0x00000002 /* over current indicator */
  572. #define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
  573. #define RH_HS_LPSC 0x00010000 /* local power status change */
  574. #define RH_HS_OCIC 0x00020000 /* over current indicator change */
  575. #define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
  576. /* roothub.b masks */
  577. #define RH_B_DR 0x0000ffff /* device removable flags */
  578. #define RH_B_PPCM 0xffff0000 /* port power control mask */
  579. /* roothub.a masks */
  580. #define RH_A_NDP (0xff << 0) /* number of downstream ports */
  581. #define RH_A_PSM (1 << 8) /* power switching mode */
  582. #define RH_A_NPS (1 << 9) /* no power switching */
  583. #define RH_A_DT (1 << 10) /* device type (mbz) */
  584. #define RH_A_OCPM (1 << 11) /* over current protection mode */
  585. #define RH_A_NOCP (1 << 12) /* no over current protection */
  586. #define RH_A_POTPGT (0xff << 24) /* power on to power good time */
  587. #endif /* __R8A66597_H__ */