mach-rtl838x.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2006-2012 Tony Wu ([email protected])
  4. * Copyright (C) 2020 B. Koblitz
  5. */
  6. #ifndef _MACH_RTL838X_H_
  7. #define _MACH_RTL838X_H_
  8. /*
  9. * Register access macros
  10. */
  11. #define RTL838X_SW_BASE ((volatile void *) 0xBB000000)
  12. #define rtl838x_r32(reg) __raw_readl(reg)
  13. #define rtl838x_w32(val, reg) __raw_writel(val, reg)
  14. #define rtl838x_w32_mask(clear, set, reg) rtl838x_w32((rtl838x_r32(reg) & ~(clear)) | (set), reg)
  15. #define rtl838x_r8(reg) __raw_readb(reg)
  16. #define rtl838x_w8(val, reg) __raw_writeb(val, reg)
  17. #define sw_r32(reg) __raw_readl(RTL838X_SW_BASE + reg)
  18. #define sw_w32(val, reg) __raw_writel(val, RTL838X_SW_BASE + reg)
  19. #define sw_w32_mask(clear, set, reg) \
  20. sw_w32((sw_r32(reg) & ~(clear)) | (set), reg)
  21. #define sw_r64(reg) ((((u64)__raw_readl(RTL838X_SW_BASE + reg)) << 32) | \
  22. __raw_readl(RTL838X_SW_BASE + reg + 4))
  23. #define sw_w64(val, reg) do { \
  24. __raw_writel((u32)((val) >> 32), RTL838X_SW_BASE + reg); \
  25. __raw_writel((u32)((val) & 0xffffffff), \
  26. RTL838X_SW_BASE + reg + 4); \
  27. } while (0)
  28. /*
  29. * SPRAM
  30. */
  31. #define RTL838X_ISPRAM_BASE 0x0
  32. #define RTL838X_DSPRAM_BASE 0x0
  33. /*
  34. * IRQ Controller
  35. */
  36. #define RTL838X_IRQ_CPU_BASE 0
  37. #define RTL838X_IRQ_CPU_NUM 8
  38. #define RTL838X_IRQ_ICTL_BASE (RTL838X_IRQ_CPU_BASE + RTL838X_IRQ_CPU_NUM)
  39. #define RTL838X_IRQ_ICTL_NUM 32
  40. /*
  41. * MIPS32R2 counter
  42. */
  43. #define RTL838X_COMPARE_IRQ (RTL838X_IRQ_CPU_BASE + 7)
  44. /*
  45. * ICTL
  46. * Base address 0xb8003000UL
  47. */
  48. #define RTL838X_ICTL1_IRQ (RTL838X_IRQ_CPU_BASE + 2)
  49. #define RTL838X_ICTL2_IRQ (RTL838X_IRQ_CPU_BASE + 3)
  50. #define RTL838X_ICTL3_IRQ (RTL838X_IRQ_CPU_BASE + 4)
  51. #define RTL838X_ICTL4_IRQ (RTL838X_IRQ_CPU_BASE + 5)
  52. #define RTL838X_ICTL5_IRQ (RTL838X_IRQ_CPU_BASE + 6)
  53. #define GIMR (0x00)
  54. #define UART0_IE (1 << 31)
  55. #define UART1_IE (1 << 30)
  56. #define TC0_IE (1 << 29)
  57. #define TC1_IE (1 << 28)
  58. #define OCPTO_IE (1 << 27)
  59. #define HLXTO_IE (1 << 26)
  60. #define SLXTO_IE (1 << 25)
  61. #define NIC_IE (1 << 24)
  62. #define GPIO_ABCD_IE (1 << 23)
  63. #define GPIO_EFGH_IE (1 << 22)
  64. #define RTC_IE (1 << 21)
  65. #define WDT_IP1_IE (1 << 19)
  66. #define WDT_IP2_IE (1 << 18)
  67. #define GISR (0x04)
  68. #define UART0_IP (1 << 31)
  69. #define UART1_IP (1 << 30)
  70. #define TC0_IP (1 << 29)
  71. #define TC1_IP (1 << 28)
  72. #define OCPTO_IP (1 << 27)
  73. #define HLXTO_IP (1 << 26)
  74. #define SLXTO_IP (1 << 25)
  75. #define NIC_IP (1 << 24)
  76. #define GPIO_ABCD_IP (1 << 23)
  77. #define GPIO_EFGH_IP (1 << 22)
  78. #define RTC_IP (1 << 21)
  79. #define WDT_IP1_IP (1 << 19)
  80. #define WDT_IP2_IP (1 << 18)
  81. #define IRR0 (0x08)
  82. #define IRR0_SETTING ((UART0_RS << 28) | \
  83. (UART1_RS << 24) | \
  84. (TC0_RS << 20) | \
  85. (TC1_RS << 16) | \
  86. (OCPTO_RS << 12) | \
  87. (HLXTO_RS << 8) | \
  88. (SLXTO_RS << 4) | \
  89. (NIC_RS << 0) \
  90. )
  91. #define IRR1 (0x0c)
  92. #define IRR1_SETTING_RTL838X ((GPIO_ABCD_RS << 28) | \
  93. (GPIO_EFGH_RS << 24) | \
  94. (RTC_RS << 20) | \
  95. (SWCORE_RS << 16) \
  96. )
  97. #define IRR1_SETTING_RTL839X ((GPIO_ABCD_RS << 28) | \
  98. (SWCORE_RS << 16) \
  99. )
  100. #define IRR2 (0x10)
  101. #define IRR2_SETTING 0
  102. #define IRR3 (0x14)
  103. #define IRR3_SETTING 0
  104. /* Interrupt Routing Selection */
  105. #define UART0_RS 2
  106. #define UART1_RS 1
  107. #define TC0_RS 5
  108. #define TC1_RS 1
  109. #define OCPTO_RS 1
  110. #define HLXTO_RS 1
  111. #define SLXTO_RS 1
  112. #define NIC_RS 4
  113. #define GPIO_ABCD_RS 4
  114. #define GPIO_EFGH_RS 4
  115. #define RTC_RS 4
  116. #define SWCORE_RS 3
  117. #define WDT_IP1_RS 4
  118. #define WDT_IP2_RS 5
  119. /* Interrupt IRQ Assignments */
  120. #define UART0_IRQ 31
  121. #define UART1_IRQ 30
  122. #define TC0_IRQ 29
  123. #define TC1_IRQ 28
  124. #define OCPTO_IRQ 27
  125. #define HLXTO_IRQ 26
  126. #define SLXTO_IRQ 25
  127. #define NIC_IRQ 24
  128. #define GPIO_ABCD_IRQ 23
  129. #define GPIO_EFGH_IRQ 22
  130. #define RTC_IRQ 21
  131. #define SWCORE_IRQ 20
  132. #define WDT_IP1_IRQ 19
  133. #define WDT_IP2_IRQ 18
  134. #define SYSTEM_FREQ 200000000
  135. #define RTL838X_UART0_BASE ((volatile void *)(0xb8002000UL))
  136. #define RTL838X_UART0_BAUD 38400 /* ex. 19200 or 38400 or 57600 or 115200 */
  137. #define RTL838X_UART0_FREQ (SYSTEM_FREQ - RTL838X_UART0_BAUD * 24)
  138. #define RTL838X_UART0_MAPBASE 0x18002000UL
  139. #define RTL838X_UART0_MAPSIZE 0x100
  140. #define RTL838X_UART0_IRQ UART0_IRQ
  141. #define RTL838X_UART1_BASE ((volatile void *)(0xb8002100UL))
  142. #define RTL838X_UART1_BAUD 38400 /* ex. 19200 or 38400 or 57600 or 115200 */
  143. #define RTL838X_UART1_FREQ (SYSTEM_FREQ - RTL838X_UART1_BAUD * 24)
  144. #define RTL838X_UART1_MAPBASE 0x18002100UL
  145. #define RTL838X_UART1_MAPSIZE 0x100
  146. #define RTL838X_UART1_IRQ UART1_IRQ
  147. #define UART0_RBR (RTL838X_UART0_BASE + 0x000)
  148. #define UART0_THR (RTL838X_UART0_BASE + 0x000)
  149. #define UART0_DLL (RTL838X_UART0_BASE + 0x000)
  150. #define UART0_IER (RTL838X_UART0_BASE + 0x004)
  151. #define UART0_DLM (RTL838X_UART0_BASE + 0x004)
  152. #define UART0_IIR (RTL838X_UART0_BASE + 0x008)
  153. #define UART0_FCR (RTL838X_UART0_BASE + 0x008)
  154. #define UART0_LCR (RTL838X_UART0_BASE + 0x00C)
  155. #define UART0_MCR (RTL838X_UART0_BASE + 0x010)
  156. #define UART0_LSR (RTL838X_UART0_BASE + 0x014)
  157. #define UART1_RBR (RTL838X_UART1_BASE + 0x000)
  158. #define UART1_THR (RTL838X_UART1_BASE + 0x000)
  159. #define UART1_DLL (RTL838X_UART1_BASE + 0x000)
  160. #define UART1_IER (RTL838X_UART1_BASE + 0x004)
  161. #define UART1_DLM (RTL838X_UART1_BASE + 0x004)
  162. #define UART1_IIR (RTL838X_UART1_BASE + 0x008)
  163. #define UART1_FCR (RTL838X_UART1_BASE + 0x008)
  164. #define FCR_EN 0x01
  165. #define FCR_RXRST 0x02
  166. #define XRST 0x02
  167. #define FCR_TXRST 0x04
  168. #define TXRST 0x04
  169. #define FCR_DMA 0x08
  170. #define FCR_RTRG 0xC0
  171. #define CHAR_TRIGGER_01 0x00
  172. #define CHAR_TRIGGER_04 0x40
  173. #define CHAR_TRIGGER_08 0x80
  174. #define CHAR_TRIGGER_14 0xC0
  175. #define UART1_LCR (RTL838X_UART1_BASE + 0x00C)
  176. #define LCR_WLN 0x03
  177. #define CHAR_LEN_5 0x00
  178. #define CHAR_LEN_6 0x01
  179. #define CHAR_LEN_7 0x02
  180. #define CHAR_LEN_8 0x03
  181. #define LCR_STB 0x04
  182. #define ONE_STOP 0x00
  183. #define TWO_STOP 0x04
  184. #define LCR_PEN 0x08
  185. #define PARITY_ENABLE 0x01
  186. #define PARITY_DISABLE 0x00
  187. #define LCR_EPS 0x30
  188. #define PARITY_ODD 0x00
  189. #define PARITY_EVEN 0x10
  190. #define PARITY_MARK 0x20
  191. #define PARITY_SPACE 0x30
  192. #define LCR_BRK 0x40
  193. #define LCR_DLAB 0x80
  194. #define DLAB 0x80
  195. #define UART1_MCR (RTL838X_UART1_BASE + 0x010)
  196. #define UART1_LSR (RTL838X_UART1_BASE + 0x014)
  197. #define LSR_DR 0x01
  198. #define RxCHAR_AVAIL 0x01
  199. #define LSR_OE 0x02
  200. #define LSR_PE 0x04
  201. #define LSR_FE 0x08
  202. #define LSR_BI 0x10
  203. #define LSR_THRE 0x20
  204. #define TxCHAR_AVAIL 0x00
  205. #define TxCHAR_EMPTY 0x20
  206. #define LSR_TEMT 0x40
  207. #define LSR_RFE 0x80
  208. /*
  209. * Timer/counter for 8390/80/28 TC & MP chip
  210. */
  211. #define RTL838X_TIMER0_BASE ((volatile void *)(0xb8003100UL))
  212. #define RTL838X_TIMER0_IRQ RTL838X_TC0_EXT_IRQ
  213. #define RTL8390TC_TC1DATA (RTL838X_TIMER0_BASE + 0x04)
  214. #define RTL8390TC_TCD_OFFSET 8
  215. #define RTL8390TC_TC0CNT (RTL838X_TIMER0_BASE + 0x08)
  216. #define RTL8390TC_TC1CNT (RTL838X_TIMER0_BASE + 0x0C)
  217. #define RTL8390TC_TCCNR (RTL838X_TIMER0_BASE + 0x10)
  218. #define RTL8390TC_TC0EN (1 << 31)
  219. #define RTL8390TC_TC0MODE_TIMER (1 << 30)
  220. #define RTL8390TC_TC1EN (1 << 29)
  221. #define RTL8390TC_TC1MODE_TIMER (1 << 28)
  222. #define RTL8390TC_TCIR (RTL838X_TIMER0_BASE + 0x14)
  223. #define RTL8390TC_TC0IE (1 << 31)
  224. #define RTL8390TC_TC1IE (1 << 30)
  225. #define RTL8390TC_TC0IP (1 << 29)
  226. #define RTL8390TC_TC1IP (1 << 28)
  227. #define RTL8390TC_CDBR (RTL838X_TIMER0_BASE + 0x18)
  228. #define RTL8390TC_DIVF_OFFSET 16
  229. #define RTL8390TC_WDTCNR (RTL838X_TIMER0_BASE + 0x1C)
  230. #define RTL8390MP_TC1DATA (RTL838X_TIMER0_BASE + 0x10)
  231. #define RTL8390MP_TC0CNT (RTL838X_TIMER0_BASE + 0x04)
  232. #define RTL8390MP_TC1CNT (RTL838X_TIMER0_BASE + 0x14)
  233. #define RTL8390MP_TC0CTL (RTL838X_TIMER0_BASE + 0x08)
  234. #define RTL8390MP_TC1CTL (RTL838X_TIMER0_BASE + 0x18)
  235. #define RTL8390MP_TCEN (1 << 28)
  236. #define RTL8390MP_TCMODE_TIMER (1 << 24)
  237. #define RTL8390MP_TCDIV_FACTOR (0xFFFF << 0)
  238. #define RTL8390MP_TC0INT (RTL838X_TIMER0_BASE + 0xC)
  239. #define RTL8390MP_TC1INT (RTL838X_TIMER0_BASE + 0x1C)
  240. #define RTL8390MP_TCIE (1 << 20)
  241. #define RTL8390MP_TCIP (1 << 16)
  242. #define RTL8390MP_WDTCNR (RTL838X_TIMER0_BASE + 0x50)
  243. #define RTL8380MP_TC0DATA (RTL838X_TIMER0_BASE + 0x00)
  244. #define RTL8380MP_TC1DATA (RTL838X_TIMER0_BASE + 0x10)
  245. #define RTL8380MP_TC0CNT (RTL838X_TIMER0_BASE + 0x04)
  246. #define RTL8380MP_TC1CNT (RTL838X_TIMER0_BASE + 0x14)
  247. #define RTL8380MP_TC0CTL (RTL838X_TIMER0_BASE + 0x08)
  248. #define RTL8380MP_TC1CTL (RTL838X_TIMER0_BASE + 0x18)
  249. #define RTL8380MP_TCEN (1 << 28)
  250. #define RTL8380MP_TCMODE_TIMER (1 << 24)
  251. #define RTL8380MP_TCDIV_FACTOR (0xFFFF << 0)
  252. #define RTL8380MP_TC0INT (RTL838X_TIMER0_BASE + 0xC)
  253. #define RTL8380MP_TC1INT (RTL838X_TIMER0_BASE + 0x1C)
  254. #define RTL8380MP_TCIE (1 << 20)
  255. #define RTL8380MP_TCIP (1 << 16)
  256. #define RTL8380MP_WDTCNR (RTL838X_TIMER0_BASE + 0x50)
  257. #define DIVISOR_RTL8390 55
  258. #define DIVISOR_RTL8380 2500
  259. #define DIVISOR_MAX 16834
  260. /*
  261. * Memory Controller
  262. */
  263. #define MC_MCR 0xB8001000
  264. #define MC_MCR_VAL 0x00000000
  265. #define MC_DCR 0xB8001004
  266. #define MC_DCR0_VAL 0x54480000
  267. #define MC_DTCR 0xB8001008
  268. #define MC_DTCR_VAL 0xFFFF05C0
  269. /*
  270. * GPIO
  271. */
  272. #define GPIO_CTRL_REG_BASE ((volatile void *) 0xb8003500)
  273. #define RTL838X_GPIO_PABC_CNR (GPIO_CTRL_REG_BASE + 0x0)
  274. #define RTL838X_GPIO_PABC_TYPE (GPIO_CTRL_REG_BASE + 0x04)
  275. #define RTL838X_GPIO_PABC_DIR (GPIO_CTRL_REG_BASE + 0x8)
  276. #define RTL838X_GPIO_PABC_DATA (GPIO_CTRL_REG_BASE + 0xc)
  277. #define RTL838X_GPIO_PABC_ISR (GPIO_CTRL_REG_BASE + 0x10)
  278. #define RTL838X_GPIO_PAB_IMR (GPIO_CTRL_REG_BASE + 0x14)
  279. #define RTL838X_GPIO_PC_IMR (GPIO_CTRL_REG_BASE + 0x18)
  280. #define RTL838X_MODEL_NAME_INFO (0x00D4)
  281. #define RTL839X_MODEL_NAME_INFO (0x0FF0)
  282. #define RTL838X_LED_GLB_CTRL (0xA000)
  283. #define RTL839X_LED_GLB_CTRL (0x00E4)
  284. #define RTL838X_EXT_GPIO_DIR_0 (0xA08C)
  285. #define RTL838X_EXT_GPIO_DIR_1 (0xA090)
  286. #define RTL838X_EXT_GPIO_DATA_0 (0xA094)
  287. #define RTL838X_EXT_GPIO_DATA_1 (0xA098)
  288. #define RTL838X_EXT_GPIO_INDRT_ACCESS (0xA09C)
  289. #define RTL838X_EXTRA_GPIO_CTRL (0xA0E0)
  290. #define RTL838X_EXTRA_GPIO_DIR_0 (0xA0E4)
  291. #define RTL838X_EXTRA_GPIO_DIR_1 (0xA0E8)
  292. #define RTL838X_EXTRA_GPIO_DATA_0 (0xA0EC)
  293. #define RTL838X_EXTRA_GPIO_DATA_1 (0xA0F0)
  294. #define RTL838X_DMY_REG5 (0x0144)
  295. #define RTL838X_EXTRA_GPIO_CTRL (0xA0E0)
  296. #define RTL838X_GMII_INTF_SEL (0x1000)
  297. #define RTL838X_IO_DRIVING_ABILITY_CTRL (0x1010)
  298. #define RTL838X_GPIO_A7 31
  299. #define RTL838X_GPIO_A6 30
  300. #define RTL838X_GPIO_A5 29
  301. #define RTL838X_GPIO_A4 28
  302. #define RTL838X_GPIO_A3 27
  303. #define RTL838X_GPIO_A2 26
  304. #define RTL838X_GPIO_A1 25
  305. #define RTL838X_GPIO_A0 24
  306. #define RTL838X_GPIO_B7 23
  307. #define RTL838X_GPIO_B6 22
  308. #define RTL838X_GPIO_B5 21
  309. #define RTL838X_GPIO_B4 20
  310. #define RTL838X_GPIO_B3 19
  311. #define RTL838X_GPIO_B2 18
  312. #define RTL838X_GPIO_B1 17
  313. #define RTL838X_GPIO_B0 16
  314. #define RTL838X_GPIO_C7 15
  315. #define RTL838X_GPIO_C6 14
  316. #define RTL838X_GPIO_C5 13
  317. #define RTL838X_GPIO_C4 12
  318. #define RTL838X_GPIO_C3 11
  319. #define RTL838X_GPIO_C2 10
  320. #define RTL838X_GPIO_C1 9
  321. #define RTL838X_GPIO_C0 8
  322. #define RTL838X_INT_RW_CTRL (0x0058)
  323. #define RTL838X_EXT_VERSION (0x00D0)
  324. #define RTL838X_PLL_CML_CTRL (0x0FF8)
  325. #define RTL838X_STRAP_DBG (0x100C)
  326. /*
  327. * Reset
  328. */
  329. #define RGCR (0x1E70)
  330. #define RTL839X_RST_GLB_CTRL (0x0014)
  331. #define RTL838X_RST_GLB_CTRL_1 (0x0040)
  332. /* LED control by switch */
  333. #define RTL838X_LED_MODE_SEL (0x1004)
  334. #define RTL838X_LED_MODE_CTRL (0xA004)
  335. #define RTL838X_LED_P_EN_CTRL (0xA008)
  336. /* LED control by software */
  337. #define RTL838X_LED_SW_CTRL (0xA00C)
  338. #define RTL838X_LED0_SW_P_EN_CTRL (0xA010)
  339. #define RTL838X_LED1_SW_P_EN_CTRL (0xA014)
  340. #define RTL838X_LED2_SW_P_EN_CTRL (0xA018)
  341. #define RTL838X_LED_SW_P_CTRL(p) (0xA01C + ((p) << 2))
  342. #define RTL839X_MAC_EFUSE_CTRL (0x02ac)
  343. /*
  344. * MDIO via Realtek's SMI interface
  345. */
  346. #define RTL838X_SMI_GLB_CTRL (0xa100)
  347. #define RTL838X_SMI_ACCESS_PHY_CTRL_0 (0xa1b8)
  348. #define RTL838X_SMI_ACCESS_PHY_CTRL_1 (0xa1bc)
  349. #define RTL838X_SMI_ACCESS_PHY_CTRL_2 (0xa1c0)
  350. #define RTL838X_SMI_ACCESS_PHY_CTRL_3 (0xa1c4)
  351. #define RTL838X_SMI_PORT0_5_ADDR_CTRL (0xa1c8)
  352. #define RTL838X_SMI_POLL_CTRL (0xa17c)
  353. #define RTL839X_SMI_GLB_CTRL (0x03f8)
  354. #define RTL839X_SMI_PORT_POLLING_CTRL (0x03fc)
  355. #define RTL839X_PHYREG_ACCESS_CTRL (0x03DC)
  356. #define RTL839X_PHYREG_CTRL (0x03E0)
  357. #define RTL839X_PHYREG_PORT_CTRL(p) (0x03E4 + ((p >> 5) << 2))
  358. #define RTL839X_PHYREG_DATA_CTRL (0x03F0)
  359. /*
  360. * Switch interrupts
  361. */
  362. #define RTL838X_IMR_GLB (0x1100)
  363. #define RTL838X_IMR_PORT_LINK_STS_CHG (0x1104)
  364. #define RTL838X_ISR_GLB_SRC (0x1148)
  365. #define RTL838X_ISR_PORT_LINK_STS_CHG (0x114C)
  366. #define RTL839X_IMR_GLB (0x0064)
  367. #define RTL839X_IMR_PORT_LINK_STS_CHG (0x0068)
  368. #define RTL839X_ISR_GLB_SRC (0x009c)
  369. #define RTL839X_ISR_PORT_LINK_STS_CHG (0x00a0)
  370. /* Definition of family IDs */
  371. #define RTL8389_FAMILY_ID (0x8389)
  372. #define RTL8328_FAMILY_ID (0x8328)
  373. #define RTL8390_FAMILY_ID (0x8390)
  374. #define RTL8350_FAMILY_ID (0x8350)
  375. #define RTL8380_FAMILY_ID (0x8380)
  376. #define RTL8330_FAMILY_ID (0x8330)
  377. struct rtl838x_soc_info {
  378. unsigned char *name;
  379. unsigned int id;
  380. unsigned int family;
  381. unsigned char *compatible;
  382. volatile void *sw_base;
  383. volatile void *icu_base;
  384. };
  385. extern struct rtl838x_soc_info soc_info;
  386. extern struct mutex smi_lock;
  387. void rtl838x_soc_detect(struct rtl838x_soc_info *i);
  388. #endif /* _MACH_RTL838X_H_ */