r8a66597.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * R8A66597 HCD (Host Controller Driver)
  3. *
  4. * Copyright (C) 2006-2007 Renesas Solutions Corp.
  5. * Portions Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
  6. * Portions Copyright (C) 2004-2005 David Brownell
  7. * Portions Copyright (C) 1999 Roman Weissgaerber
  8. *
  9. * Author : Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; version 2 of the License.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. */
  25. #ifndef __R8A66597_H__
  26. #define __R8A66597_H__
  27. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
  28. #include <linux/clk.h>
  29. #endif
  30. #define SYSCFG0 0x00
  31. #define SYSCFG1 0x02
  32. #define SYSSTS0 0x04
  33. #define SYSSTS1 0x06
  34. #define DVSTCTR0 0x08
  35. #define DVSTCTR1 0x0A
  36. #define TESTMODE 0x0C
  37. #define PINCFG 0x0E
  38. #define DMA0CFG 0x10
  39. #define DMA1CFG 0x12
  40. #define CFIFO 0x14
  41. #define D0FIFO 0x18
  42. #define D1FIFO 0x1C
  43. #define CFIFOSEL 0x20
  44. #define CFIFOCTR 0x22
  45. #define CFIFOSIE 0x24
  46. #define D0FIFOSEL 0x28
  47. #define D0FIFOCTR 0x2A
  48. #define D1FIFOSEL 0x2C
  49. #define D1FIFOCTR 0x2E
  50. #define INTENB0 0x30
  51. #define INTENB1 0x32
  52. #define INTENB2 0x34
  53. #define BRDYENB 0x36
  54. #define NRDYENB 0x38
  55. #define BEMPENB 0x3A
  56. #define SOFCFG 0x3C
  57. #define INTSTS0 0x40
  58. #define INTSTS1 0x42
  59. #define INTSTS2 0x44
  60. #define BRDYSTS 0x46
  61. #define NRDYSTS 0x48
  62. #define BEMPSTS 0x4A
  63. #define FRMNUM 0x4C
  64. #define UFRMNUM 0x4E
  65. #define USBADDR 0x50
  66. #define USBREQ 0x54
  67. #define USBVAL 0x56
  68. #define USBINDX 0x58
  69. #define USBLENG 0x5A
  70. #define DCPCFG 0x5C
  71. #define DCPMAXP 0x5E
  72. #define DCPCTR 0x60
  73. #define PIPESEL 0x64
  74. #define PIPECFG 0x68
  75. #define PIPEBUF 0x6A
  76. #define PIPEMAXP 0x6C
  77. #define PIPEPERI 0x6E
  78. #define PIPE1CTR 0x70
  79. #define PIPE2CTR 0x72
  80. #define PIPE3CTR 0x74
  81. #define PIPE4CTR 0x76
  82. #define PIPE5CTR 0x78
  83. #define PIPE6CTR 0x7A
  84. #define PIPE7CTR 0x7C
  85. #define PIPE8CTR 0x7E
  86. #define PIPE9CTR 0x80
  87. #define PIPE1TRE 0x90
  88. #define PIPE1TRN 0x92
  89. #define PIPE2TRE 0x94
  90. #define PIPE2TRN 0x96
  91. #define PIPE3TRE 0x98
  92. #define PIPE3TRN 0x9A
  93. #define PIPE4TRE 0x9C
  94. #define PIPE4TRN 0x9E
  95. #define PIPE5TRE 0xA0
  96. #define PIPE5TRN 0xA2
  97. #define DEVADD0 0xD0
  98. #define DEVADD1 0xD2
  99. #define DEVADD2 0xD4
  100. #define DEVADD3 0xD6
  101. #define DEVADD4 0xD8
  102. #define DEVADD5 0xDA
  103. #define DEVADD6 0xDC
  104. #define DEVADD7 0xDE
  105. #define DEVADD8 0xE0
  106. #define DEVADD9 0xE2
  107. #define DEVADDA 0xE4
  108. /* System Configuration Control Register */
  109. #define XTAL 0xC000 /* b15-14: Crystal selection */
  110. #define XTAL48 0x8000 /* 48MHz */
  111. #define XTAL24 0x4000 /* 24MHz */
  112. #define XTAL12 0x0000 /* 12MHz */
  113. #define XCKE 0x2000 /* b13: External clock enable */
  114. #define PLLC 0x0800 /* b11: PLL control */
  115. #define SCKE 0x0400 /* b10: USB clock enable */
  116. #define PCSDIS 0x0200 /* b9: not CS wakeup */
  117. #define LPSME 0x0100 /* b8: Low power sleep mode */
  118. #define HSE 0x0080 /* b7: Hi-speed enable */
  119. #define DCFM 0x0040 /* b6: Controller function select */
  120. #define DRPD 0x0020 /* b5: D+/- pull down control */
  121. #define DPRPU 0x0010 /* b4: D+ pull up control */
  122. #define USBE 0x0001 /* b0: USB module operation enable */
  123. /* System Configuration Status Register */
  124. #define OVCBIT 0x8000 /* b15-14: Over-current bit */
  125. #define OVCMON 0xC000 /* b15-14: Over-current monitor */
  126. #define SOFEA 0x0020 /* b5: SOF monitor */
  127. #define IDMON 0x0004 /* b3: ID-pin monitor */
  128. #define LNST 0x0003 /* b1-0: D+, D- line status */
  129. #define SE1 0x0003 /* SE1 */
  130. #define FS_KSTS 0x0002 /* Full-Speed K State */
  131. #define FS_JSTS 0x0001 /* Full-Speed J State */
  132. #define LS_JSTS 0x0002 /* Low-Speed J State */
  133. #define LS_KSTS 0x0001 /* Low-Speed K State */
  134. #define SE0 0x0000 /* SE0 */
  135. /* Device State Control Register */
  136. #define EXTLP0 0x0400 /* b10: External port */
  137. #define VBOUT 0x0200 /* b9: VBUS output */
  138. #define WKUP 0x0100 /* b8: Remote wakeup */
  139. #define RWUPE 0x0080 /* b7: Remote wakeup sense */
  140. #define USBRST 0x0040 /* b6: USB reset enable */
  141. #define RESUME 0x0020 /* b5: Resume enable */
  142. #define UACT 0x0010 /* b4: USB bus enable */
  143. #define RHST 0x0007 /* b1-0: Reset handshake status */
  144. #define HSPROC 0x0004 /* HS handshake is processing */
  145. #define HSMODE 0x0003 /* Hi-Speed mode */
  146. #define FSMODE 0x0002 /* Full-Speed mode */
  147. #define LSMODE 0x0001 /* Low-Speed mode */
  148. #define UNDECID 0x0000 /* Undecided */
  149. /* Test Mode Register */
  150. #define UTST 0x000F /* b3-0: Test select */
  151. #define H_TST_PACKET 0x000C /* HOST TEST Packet */
  152. #define H_TST_SE0_NAK 0x000B /* HOST TEST SE0 NAK */
  153. #define H_TST_K 0x000A /* HOST TEST K */
  154. #define H_TST_J 0x0009 /* HOST TEST J */
  155. #define H_TST_NORMAL 0x0000 /* HOST Normal Mode */
  156. #define P_TST_PACKET 0x0004 /* PERI TEST Packet */
  157. #define P_TST_SE0_NAK 0x0003 /* PERI TEST SE0 NAK */
  158. #define P_TST_K 0x0002 /* PERI TEST K */
  159. #define P_TST_J 0x0001 /* PERI TEST J */
  160. #define P_TST_NORMAL 0x0000 /* PERI Normal Mode */
  161. /* Data Pin Configuration Register */
  162. #define LDRV 0x8000 /* b15: Drive Current Adjust */
  163. #define VIF1 0x0000 /* VIF = 1.8V */
  164. #define VIF3 0x8000 /* VIF = 3.3V */
  165. #define INTA 0x0001 /* b1: USB INT-pin active */
  166. /* DMAx Pin Configuration Register */
  167. #define DREQA 0x4000 /* b14: Dreq active select */
  168. #define BURST 0x2000 /* b13: Burst mode */
  169. #define DACKA 0x0400 /* b10: Dack active select */
  170. #define DFORM 0x0380 /* b9-7: DMA mode select */
  171. #define CPU_ADR_RD_WR 0x0000 /* Address + RD/WR mode (CPU bus) */
  172. #define CPU_DACK_RD_WR 0x0100 /* DACK + RD/WR mode (CPU bus) */
  173. #define CPU_DACK_ONLY 0x0180 /* DACK only mode (CPU bus) */
  174. #define SPLIT_DACK_ONLY 0x0200 /* DACK only mode (SPLIT bus) */
  175. #define DENDA 0x0040 /* b6: Dend active select */
  176. #define PKTM 0x0020 /* b5: Packet mode */
  177. #define DENDE 0x0010 /* b4: Dend enable */
  178. #define OBUS 0x0004 /* b2: OUTbus mode */
  179. /* CFIFO/DxFIFO Port Select Register */
  180. #define RCNT 0x8000 /* b15: Read count mode */
  181. #define REW 0x4000 /* b14: Buffer rewind */
  182. #define DCLRM 0x2000 /* b13: DMA buffer clear mode */
  183. #define DREQE 0x1000 /* b12: DREQ output enable */
  184. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  185. #define MBW 0x0800
  186. #else
  187. #define MBW 0x0400 /* b10: Maximum bit width for FIFO access */
  188. #endif
  189. #define MBW_8 0x0000 /* 8bit */
  190. #define MBW_16 0x0400 /* 16bit */
  191. #define BIGEND 0x0100 /* b8: Big endian mode */
  192. #define BYTE_LITTLE 0x0000 /* little dendian */
  193. #define BYTE_BIG 0x0100 /* big endifan */
  194. #define ISEL 0x0020 /* b5: DCP FIFO port direction select */
  195. #define CURPIPE 0x000F /* b2-0: PIPE select */
  196. /* CFIFO/DxFIFO Port Control Register */
  197. #define BVAL 0x8000 /* b15: Buffer valid flag */
  198. #define BCLR 0x4000 /* b14: Buffer clear */
  199. #define FRDY 0x2000 /* b13: FIFO ready */
  200. #define DTLN 0x0FFF /* b11-0: FIFO received data length */
  201. /* Interrupt Enable Register 0 */
  202. #define VBSE 0x8000 /* b15: VBUS interrupt */
  203. #define RSME 0x4000 /* b14: Resume interrupt */
  204. #define SOFE 0x2000 /* b13: Frame update interrupt */
  205. #define DVSE 0x1000 /* b12: Device state transition interrupt */
  206. #define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */
  207. #define BEMPE 0x0400 /* b10: Buffer empty interrupt */
  208. #define NRDYE 0x0200 /* b9: Buffer not ready interrupt */
  209. #define BRDYE 0x0100 /* b8: Buffer ready interrupt */
  210. /* Interrupt Enable Register 1 */
  211. #define OVRCRE 0x8000 /* b15: Over-current interrupt */
  212. #define BCHGE 0x4000 /* b14: USB us chenge interrupt */
  213. #define DTCHE 0x1000 /* b12: Detach sense interrupt */
  214. #define ATTCHE 0x0800 /* b11: Attach sense interrupt */
  215. #define EOFERRE 0x0040 /* b6: EOF error interrupt */
  216. #define SIGNE 0x0020 /* b5: SETUP IGNORE interrupt */
  217. #define SACKE 0x0010 /* b4: SETUP ACK interrupt */
  218. /* BRDY Interrupt Enable/Status Register */
  219. #define BRDY9 0x0200 /* b9: PIPE9 */
  220. #define BRDY8 0x0100 /* b8: PIPE8 */
  221. #define BRDY7 0x0080 /* b7: PIPE7 */
  222. #define BRDY6 0x0040 /* b6: PIPE6 */
  223. #define BRDY5 0x0020 /* b5: PIPE5 */
  224. #define BRDY4 0x0010 /* b4: PIPE4 */
  225. #define BRDY3 0x0008 /* b3: PIPE3 */
  226. #define BRDY2 0x0004 /* b2: PIPE2 */
  227. #define BRDY1 0x0002 /* b1: PIPE1 */
  228. #define BRDY0 0x0001 /* b1: PIPE0 */
  229. /* NRDY Interrupt Enable/Status Register */
  230. #define NRDY9 0x0200 /* b9: PIPE9 */
  231. #define NRDY8 0x0100 /* b8: PIPE8 */
  232. #define NRDY7 0x0080 /* b7: PIPE7 */
  233. #define NRDY6 0x0040 /* b6: PIPE6 */
  234. #define NRDY5 0x0020 /* b5: PIPE5 */
  235. #define NRDY4 0x0010 /* b4: PIPE4 */
  236. #define NRDY3 0x0008 /* b3: PIPE3 */
  237. #define NRDY2 0x0004 /* b2: PIPE2 */
  238. #define NRDY1 0x0002 /* b1: PIPE1 */
  239. #define NRDY0 0x0001 /* b1: PIPE0 */
  240. /* BEMP Interrupt Enable/Status Register */
  241. #define BEMP9 0x0200 /* b9: PIPE9 */
  242. #define BEMP8 0x0100 /* b8: PIPE8 */
  243. #define BEMP7 0x0080 /* b7: PIPE7 */
  244. #define BEMP6 0x0040 /* b6: PIPE6 */
  245. #define BEMP5 0x0020 /* b5: PIPE5 */
  246. #define BEMP4 0x0010 /* b4: PIPE4 */
  247. #define BEMP3 0x0008 /* b3: PIPE3 */
  248. #define BEMP2 0x0004 /* b2: PIPE2 */
  249. #define BEMP1 0x0002 /* b1: PIPE1 */
  250. #define BEMP0 0x0001 /* b0: PIPE0 */
  251. /* SOF Pin Configuration Register */
  252. #define TRNENSEL 0x0100 /* b8: Select transaction enable period */
  253. #define BRDYM 0x0040 /* b6: BRDY clear timing */
  254. #define INTL 0x0020 /* b5: Interrupt sense select */
  255. #define EDGESTS 0x0010 /* b4: */
  256. #define SOFMODE 0x000C /* b3-2: SOF pin select */
  257. #define SOF_125US 0x0008 /* SOF OUT 125us Frame Signal */
  258. #define SOF_1MS 0x0004 /* SOF OUT 1ms Frame Signal */
  259. #define SOF_DISABLE 0x0000 /* SOF OUT Disable */
  260. /* Interrupt Status Register 0 */
  261. #define VBINT 0x8000 /* b15: VBUS interrupt */
  262. #define RESM 0x4000 /* b14: Resume interrupt */
  263. #define SOFR 0x2000 /* b13: SOF frame update interrupt */
  264. #define DVST 0x1000 /* b12: Device state transition interrupt */
  265. #define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */
  266. #define BEMP 0x0400 /* b10: Buffer empty interrupt */
  267. #define NRDY 0x0200 /* b9: Buffer not ready interrupt */
  268. #define BRDY 0x0100 /* b8: Buffer ready interrupt */
  269. #define VBSTS 0x0080 /* b7: VBUS input port */
  270. #define DVSQ 0x0070 /* b6-4: Device state */
  271. #define DS_SPD_CNFG 0x0070 /* Suspend Configured */
  272. #define DS_SPD_ADDR 0x0060 /* Suspend Address */
  273. #define DS_SPD_DFLT 0x0050 /* Suspend Default */
  274. #define DS_SPD_POWR 0x0040 /* Suspend Powered */
  275. #define DS_SUSP 0x0040 /* Suspend */
  276. #define DS_CNFG 0x0030 /* Configured */
  277. #define DS_ADDS 0x0020 /* Address */
  278. #define DS_DFLT 0x0010 /* Default */
  279. #define DS_POWR 0x0000 /* Powered */
  280. #define DVSQS 0x0030 /* b5-4: Device state */
  281. #define VALID 0x0008 /* b3: Setup packet detected flag */
  282. #define CTSQ 0x0007 /* b2-0: Control transfer stage */
  283. #define CS_SQER 0x0006 /* Sequence error */
  284. #define CS_WRND 0x0005 /* Control write nodata status stage */
  285. #define CS_WRSS 0x0004 /* Control write status stage */
  286. #define CS_WRDS 0x0003 /* Control write data stage */
  287. #define CS_RDSS 0x0002 /* Control read status stage */
  288. #define CS_RDDS 0x0001 /* Control read data stage */
  289. #define CS_IDST 0x0000 /* Idle or setup stage */
  290. /* Interrupt Status Register 1 */
  291. #define OVRCR 0x8000 /* b15: Over-current interrupt */
  292. #define BCHG 0x4000 /* b14: USB bus chenge interrupt */
  293. #define DTCH 0x1000 /* b12: Detach sense interrupt */
  294. #define ATTCH 0x0800 /* b11: Attach sense interrupt */
  295. #define EOFERR 0x0040 /* b6: EOF-error interrupt */
  296. #define SIGN 0x0020 /* b5: Setup ignore interrupt */
  297. #define SACK 0x0010 /* b4: Setup acknowledge interrupt */
  298. /* Frame Number Register */
  299. #define OVRN 0x8000 /* b15: Overrun error */
  300. #define CRCE 0x4000 /* b14: Received data error */
  301. #define FRNM 0x07FF /* b10-0: Frame number */
  302. /* Micro Frame Number Register */
  303. #define UFRNM 0x0007 /* b2-0: Micro frame number */
  304. /* Default Control Pipe Maxpacket Size Register */
  305. /* Pipe Maxpacket Size Register */
  306. #define DEVSEL 0xF000 /* b15-14: Device address select */
  307. #define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */
  308. /* Default Control Pipe Control Register */
  309. #define BSTS 0x8000 /* b15: Buffer status */
  310. #define SUREQ 0x4000 /* b14: Send USB request */
  311. #define CSCLR 0x2000 /* b13: complete-split status clear */
  312. #define CSSTS 0x1000 /* b12: complete-split status */
  313. #define SUREQCLR 0x0800 /* b11: stop setup request */
  314. #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */
  315. #define SQSET 0x0080 /* b7: Sequence toggle bit set */
  316. #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */
  317. #define PBUSY 0x0020 /* b5: pipe busy */
  318. #define PINGE 0x0010 /* b4: ping enable */
  319. #define CCPL 0x0004 /* b2: Enable control transfer complete */
  320. #define PID 0x0003 /* b1-0: Response PID */
  321. #define PID_STALL11 0x0003 /* STALL */
  322. #define PID_STALL 0x0002 /* STALL */
  323. #define PID_BUF 0x0001 /* BUF */
  324. #define PID_NAK 0x0000 /* NAK */
  325. /* Pipe Window Select Register */
  326. #define PIPENM 0x0007 /* b2-0: Pipe select */
  327. /* Pipe Configuration Register */
  328. #define R8A66597_TYP 0xC000 /* b15-14: Transfer type */
  329. #define R8A66597_ISO 0xC000 /* Isochronous */
  330. #define R8A66597_INT 0x8000 /* Interrupt */
  331. #define R8A66597_BULK 0x4000 /* Bulk */
  332. #define R8A66597_BFRE 0x0400 /* b10: Buffer ready interrupt mode select */
  333. #define R8A66597_DBLB 0x0200 /* b9: Double buffer mode select */
  334. #define R8A66597_CNTMD 0x0100 /* b8: Continuous transfer mode select */
  335. #define R8A66597_SHTNAK 0x0080 /* b7: Transfer end NAK */
  336. #define R8A66597_DIR 0x0010 /* b4: Transfer direction select */
  337. #define R8A66597_EPNUM 0x000F /* b3-0: Eendpoint number select */
  338. /* Pipe Buffer Configuration Register */
  339. #define BUFSIZE 0x7C00 /* b14-10: Pipe buffer size */
  340. #define BUFNMB 0x007F /* b6-0: Pipe buffer number */
  341. #define PIPE0BUF 256
  342. #define PIPExBUF 64
  343. /* Pipe Maxpacket Size Register */
  344. #define MXPS 0x07FF /* b10-0: Maxpacket size */
  345. /* Pipe Cycle Configuration Register */
  346. #define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */
  347. #define IITV 0x0007 /* b2-0: Isochronous interval */
  348. /* Pipex Control Register */
  349. #define BSTS 0x8000 /* b15: Buffer status */
  350. #define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */
  351. #define CSCLR 0x2000 /* b13: complete-split status clear */
  352. #define CSSTS 0x1000 /* b12: complete-split status */
  353. #define ATREPM 0x0400 /* b10: Auto repeat mode */
  354. #define ACLRM 0x0200 /* b9: Out buffer auto clear mode */
  355. #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */
  356. #define SQSET 0x0080 /* b7: Sequence toggle bit set */
  357. #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */
  358. #define PBUSY 0x0020 /* b5: pipe busy */
  359. #define PID 0x0003 /* b1-0: Response PID */
  360. /* PIPExTRE */
  361. #define TRENB 0x0200 /* b9: Transaction counter enable */
  362. #define TRCLR 0x0100 /* b8: Transaction counter clear */
  363. /* PIPExTRN */
  364. #define TRNCNT 0xFFFF /* b15-0: Transaction counter */
  365. /* DEVADDx */
  366. #define UPPHUB 0x7800
  367. #define HUBPORT 0x0700
  368. #define USBSPD 0x00C0
  369. #define RTPORT 0x0001
  370. #define R8A66597_MAX_NUM_PIPE 10
  371. #define R8A66597_BUF_BSIZE 8
  372. #define R8A66597_MAX_DEVICE 10
  373. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  374. #define R8A66597_MAX_ROOT_HUB 1
  375. #else
  376. #define R8A66597_MAX_ROOT_HUB 2
  377. #endif
  378. #define R8A66597_MAX_SAMPLING 5
  379. #define R8A66597_RH_POLL_TIME 10
  380. #define R8A66597_MAX_DMA_CHANNEL 2
  381. #define R8A66597_PIPE_NO_DMA R8A66597_MAX_DMA_CHANNEL
  382. #define check_bulk_or_isoc(pipenum) ((pipenum >= 1 && pipenum <= 5))
  383. #define check_interrupt(pipenum) ((pipenum >= 6 && pipenum <= 9))
  384. #define make_devsel(addr) (addr << 12)
  385. struct r8a66597_pipe_info {
  386. unsigned long timer_interval;
  387. u16 pipenum;
  388. u16 address; /* R8A66597 HCD usb address */
  389. u16 epnum;
  390. u16 maxpacket;
  391. u16 type;
  392. u16 bufnum;
  393. u16 buf_bsize;
  394. u16 interval;
  395. u16 dir_in;
  396. };
  397. struct r8a66597_pipe {
  398. struct r8a66597_pipe_info info;
  399. unsigned long fifoaddr;
  400. unsigned long fifosel;
  401. unsigned long fifoctr;
  402. unsigned long pipectr;
  403. unsigned long pipetre;
  404. unsigned long pipetrn;
  405. };
  406. struct r8a66597_td {
  407. struct r8a66597_pipe *pipe;
  408. struct urb *urb;
  409. struct list_head queue;
  410. u16 type;
  411. u16 pipenum;
  412. int iso_cnt;
  413. u16 address; /* R8A66597's USB address */
  414. u16 maxpacket;
  415. unsigned zero_packet:1;
  416. unsigned short_packet:1;
  417. unsigned set_address:1;
  418. };
  419. struct r8a66597_device {
  420. u16 address; /* R8A66597's USB address */
  421. u16 hub_port;
  422. u16 root_port;
  423. unsigned short ep_in_toggle;
  424. unsigned short ep_out_toggle;
  425. unsigned char pipe_cnt[R8A66597_MAX_NUM_PIPE];
  426. unsigned char dma_map;
  427. enum usb_device_state state;
  428. struct usb_device *udev;
  429. int usb_address;
  430. struct list_head device_list;
  431. };
  432. struct r8a66597_root_hub {
  433. u32 port;
  434. u16 old_syssts;
  435. int scount;
  436. struct r8a66597_device *dev;
  437. };
  438. struct r8a66597 {
  439. spinlock_t lock;
  440. unsigned long reg;
  441. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597) && defined(CONFIG_HAVE_CLK)
  442. struct clk *clk;
  443. #endif
  444. struct r8a66597_device device0;
  445. struct r8a66597_root_hub root_hub[R8A66597_MAX_ROOT_HUB];
  446. struct list_head pipe_queue[R8A66597_MAX_NUM_PIPE];
  447. struct timer_list rh_timer;
  448. struct timer_list td_timer[R8A66597_MAX_NUM_PIPE];
  449. struct timer_list interval_timer[R8A66597_MAX_NUM_PIPE];
  450. unsigned short address_map;
  451. unsigned short timeout_map;
  452. unsigned short interval_map;
  453. unsigned char pipe_cnt[R8A66597_MAX_NUM_PIPE];
  454. unsigned char dma_map;
  455. struct list_head child_device;
  456. unsigned long child_connect_map[4];
  457. unsigned bus_suspended:1;
  458. };
  459. static inline struct r8a66597 *hcd_to_r8a66597(struct usb_hcd *hcd)
  460. {
  461. return (struct r8a66597 *)(hcd->hcd_priv);
  462. }
  463. static inline struct usb_hcd *r8a66597_to_hcd(struct r8a66597 *r8a66597)
  464. {
  465. return container_of((void *)r8a66597, struct usb_hcd, hcd_priv);
  466. }
  467. static inline struct r8a66597_td *r8a66597_get_td(struct r8a66597 *r8a66597,
  468. u16 pipenum)
  469. {
  470. if (unlikely(list_empty(&r8a66597->pipe_queue[pipenum])))
  471. return NULL;
  472. return list_entry(r8a66597->pipe_queue[pipenum].next,
  473. struct r8a66597_td, queue);
  474. }
  475. static inline struct urb *r8a66597_get_urb(struct r8a66597 *r8a66597,
  476. u16 pipenum)
  477. {
  478. struct r8a66597_td *td;
  479. td = r8a66597_get_td(r8a66597, pipenum);
  480. return (td ? td->urb : NULL);
  481. }
  482. static inline u16 r8a66597_read(struct r8a66597 *r8a66597, unsigned long offset)
  483. {
  484. return inw(r8a66597->reg + offset);
  485. }
  486. static inline void r8a66597_read_fifo(struct r8a66597 *r8a66597,
  487. unsigned long offset, u16 *buf,
  488. int len)
  489. {
  490. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  491. unsigned long fifoaddr = r8a66597->reg + offset;
  492. unsigned long count;
  493. count = len / 4;
  494. insl(fifoaddr, buf, count);
  495. if (len & 0x00000003) {
  496. unsigned long tmp = inl(fifoaddr);
  497. memcpy((unsigned char *)buf + count * 4, &tmp, len & 0x03);
  498. }
  499. #else
  500. len = (len + 1) / 2;
  501. insw(r8a66597->reg + offset, buf, len);
  502. #endif
  503. }
  504. static inline void r8a66597_write(struct r8a66597 *r8a66597, u16 val,
  505. unsigned long offset)
  506. {
  507. outw(val, r8a66597->reg + offset);
  508. }
  509. static inline void r8a66597_write_fifo(struct r8a66597 *r8a66597,
  510. unsigned long offset, u16 *buf,
  511. int len)
  512. {
  513. unsigned long fifoaddr = r8a66597->reg + offset;
  514. #if defined(CONFIG_SUPERH_ON_CHIP_R8A66597)
  515. unsigned long count;
  516. unsigned char *pb;
  517. int i;
  518. count = len / 4;
  519. outsl(fifoaddr, buf, count);
  520. if (len & 0x00000003) {
  521. pb = (unsigned char *)buf + count * 4;
  522. for (i = 0; i < (len & 0x00000003); i++) {
  523. if (r8a66597_read(r8a66597, CFIFOSEL) & BIGEND)
  524. outb(pb[i], fifoaddr + i);
  525. else
  526. outb(pb[i], fifoaddr + 3 - i);
  527. }
  528. }
  529. #else
  530. int odd = len & 0x0001;
  531. len = len / 2;
  532. outsw(fifoaddr, buf, len);
  533. if (unlikely(odd)) {
  534. buf = &buf[len];
  535. outb((unsigned char)*buf, fifoaddr);
  536. }
  537. #endif
  538. }
  539. static inline void r8a66597_mdfy(struct r8a66597 *r8a66597,
  540. u16 val, u16 pat, unsigned long offset)
  541. {
  542. u16 tmp;
  543. tmp = r8a66597_read(r8a66597, offset);
  544. tmp = tmp & (~pat);
  545. tmp = tmp | val;
  546. r8a66597_write(r8a66597, tmp, offset);
  547. }
  548. #define r8a66597_bclr(r8a66597, val, offset) \
  549. r8a66597_mdfy(r8a66597, 0, val, offset)
  550. #define r8a66597_bset(r8a66597, val, offset) \
  551. r8a66597_mdfy(r8a66597, val, 0, offset)
  552. static inline unsigned long get_syscfg_reg(int port)
  553. {
  554. return port == 0 ? SYSCFG0 : SYSCFG1;
  555. }
  556. static inline unsigned long get_syssts_reg(int port)
  557. {
  558. return port == 0 ? SYSSTS0 : SYSSTS1;
  559. }
  560. static inline unsigned long get_dvstctr_reg(int port)
  561. {
  562. return port == 0 ? DVSTCTR0 : DVSTCTR1;
  563. }
  564. static inline unsigned long get_dmacfg_reg(int port)
  565. {
  566. return port == 0 ? DMA0CFG : DMA1CFG;
  567. }
  568. static inline unsigned long get_intenb_reg(int port)
  569. {
  570. return port == 0 ? INTENB1 : INTENB2;
  571. }
  572. static inline unsigned long get_intsts_reg(int port)
  573. {
  574. return port == 0 ? INTSTS1 : INTSTS2;
  575. }
  576. static inline u16 get_rh_usb_speed(struct r8a66597 *r8a66597, int port)
  577. {
  578. unsigned long dvstctr_reg = get_dvstctr_reg(port);
  579. return r8a66597_read(r8a66597, dvstctr_reg) & RHST;
  580. }
  581. static inline void r8a66597_port_power(struct r8a66597 *r8a66597, int port,
  582. int power)
  583. {
  584. unsigned long dvstctr_reg = get_dvstctr_reg(port);
  585. if (power)
  586. r8a66597_bset(r8a66597, VBOUT, dvstctr_reg);
  587. else
  588. r8a66597_bclr(r8a66597, VBOUT, dvstctr_reg);
  589. }
  590. #define get_pipectr_addr(pipenum) (PIPE1CTR + (pipenum - 1) * 2)
  591. #define get_pipetre_addr(pipenum) (PIPE1TRE + (pipenum - 1) * 4)
  592. #define get_pipetrn_addr(pipenum) (PIPE1TRN + (pipenum - 1) * 4)
  593. #define get_devadd_addr(address) (DEVADD0 + address * 2)
  594. #define enable_irq_ready(r8a66597, pipenum) \
  595. enable_pipe_irq(r8a66597, pipenum, BRDYENB)
  596. #define disable_irq_ready(r8a66597, pipenum) \
  597. disable_pipe_irq(r8a66597, pipenum, BRDYENB)
  598. #define enable_irq_empty(r8a66597, pipenum) \
  599. enable_pipe_irq(r8a66597, pipenum, BEMPENB)
  600. #define disable_irq_empty(r8a66597, pipenum) \
  601. disable_pipe_irq(r8a66597, pipenum, BEMPENB)
  602. #define enable_irq_nrdy(r8a66597, pipenum) \
  603. enable_pipe_irq(r8a66597, pipenum, NRDYENB)
  604. #define disable_irq_nrdy(r8a66597, pipenum) \
  605. disable_pipe_irq(r8a66597, pipenum, NRDYENB)
  606. #endif /* __R8A66597_H__ */