1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2006-2012 Tony Wu (tonywu@realtek.com)
4 * Copyright (C) 2020 B. Koblitz
6 #ifndef _MACH_RTL838X_H_
7 #define _MACH_RTL838X_H_
11 * Register access macros
14 #define RTL838X_SW_BASE ((volatile void *) 0xBB000000)
16 #define rtl83xx_r32(reg) readl(reg)
17 #define rtl83xx_w32(val, reg) writel(val, reg)
18 #define rtl83xx_w32_mask(clear, set, reg) rtl83xx_w32((rtl83xx_r32(reg) & ~(clear)) | (set), reg)
20 #define rtl83xx_r8(reg) readb(reg)
21 #define rtl83xx_w8(val, reg) writeb(val, reg)
23 #define sw_r32(reg) readl(RTL838X_SW_BASE + reg)
24 #define sw_w32(val, reg) writel(val, RTL838X_SW_BASE + reg)
25 #define sw_w32_mask(clear, set, reg) \
26 sw_w32((sw_r32(reg) & ~(clear)) | (set), reg)
27 #define sw_r64(reg) ((((u64)readl(RTL838X_SW_BASE + reg)) << 32) | \
28 readl(RTL838X_SW_BASE + reg + 4))
30 #define sw_w64(val, reg) do { \
31 writel((u32)((val) >> 32), RTL838X_SW_BASE + reg); \
32 writel((u32)((val) & 0xffffffff), \
33 RTL838X_SW_BASE + reg + 4); \
39 #define RTL838X_ISPRAM_BASE 0x0
40 #define RTL838X_DSPRAM_BASE 0x0
45 #define RTL838X_IRQ_CPU_BASE 0
46 #define RTL838X_IRQ_CPU_NUM 8
47 #define RTL838X_IRQ_ICTL_BASE (RTL838X_IRQ_CPU_BASE + RTL838X_IRQ_CPU_NUM)
48 #define RTL838X_IRQ_ICTL_NUM 32
50 #define RTL83XX_IRQ_UART0 31
51 #define RTL83XX_IRQ_UART1 30
52 #define RTL83XX_IRQ_TC0 29
53 #define RTL83XX_IRQ_TC1 28
54 #define RTL83XX_IRQ_OCPTO 27
55 #define RTL83XX_IRQ_HLXTO 26
56 #define RTL83XX_IRQ_SLXTO 25
57 #define RTL83XX_IRQ_NIC 24
58 #define RTL83XX_IRQ_GPIO_ABCD 23
59 #define RTL83XX_IRQ_GPIO_EFGH 22
60 #define RTL83XX_IRQ_RTC 21
61 #define RTL83XX_IRQ_SWCORE 20
62 #define RTL83XX_IRQ_WDT_IP1 19
63 #define RTL83XX_IRQ_WDT_IP2 18
69 #define RTL838X_COMPARE_IRQ (RTL838X_IRQ_CPU_BASE + 7)
73 * Base address 0xb8003000UL
75 #define RTL838X_ICTL1_IRQ (RTL838X_IRQ_CPU_BASE + 2)
76 #define RTL838X_ICTL2_IRQ (RTL838X_IRQ_CPU_BASE + 3)
77 #define RTL838X_ICTL3_IRQ (RTL838X_IRQ_CPU_BASE + 4)
78 #define RTL838X_ICTL4_IRQ (RTL838X_IRQ_CPU_BASE + 5)
79 #define RTL838X_ICTL5_IRQ (RTL838X_IRQ_CPU_BASE + 6)
82 #define UART0_IE (1 << 31)
83 #define UART1_IE (1 << 30)
84 #define TC0_IE (1 << 29)
85 #define TC1_IE (1 << 28)
86 #define OCPTO_IE (1 << 27)
87 #define HLXTO_IE (1 << 26)
88 #define SLXTO_IE (1 << 25)
89 #define NIC_IE (1 << 24)
90 #define GPIO_ABCD_IE (1 << 23)
91 #define GPIO_EFGH_IE (1 << 22)
92 #define RTC_IE (1 << 21)
93 #define WDT_IP1_IE (1 << 19)
94 #define WDT_IP2_IE (1 << 18)
97 #define UART0_IP (1 << 31)
98 #define UART1_IP (1 << 30)
99 #define TC0_IP (1 << 29)
100 #define TC1_IP (1 << 28)
101 #define OCPTO_IP (1 << 27)
102 #define HLXTO_IP (1 << 26)
103 #define SLXTO_IP (1 << 25)
104 #define NIC_IP (1 << 24)
105 #define GPIO_ABCD_IP (1 << 23)
106 #define GPIO_EFGH_IP (1 << 22)
107 #define RTC_IP (1 << 21)
108 #define WDT_IP1_IP (1 << 19)
109 #define WDT_IP2_IP (1 << 18)
112 #define IRR0_SETTING ((UART0_RS << 28) | \
123 #define IRR1_SETTING_RTL838X ((GPIO_ABCD_RS << 28) | \
124 (GPIO_EFGH_RS << 24) | \
128 #define IRR1_SETTING_RTL839X ((GPIO_ABCD_RS << 28) | \
133 #define IRR2_SETTING 0
136 #define IRR3_SETTING 0
138 /* Interrupt Routing Selection */
147 #define GPIO_ABCD_RS 4
148 #define GPIO_EFGH_RS 4
154 /* Interrupt IRQ Assignments */
163 #define GPIO_ABCD_IRQ 23
164 #define GPIO_EFGH_IRQ 22
166 #define SWCORE_IRQ 20
167 #define WDT_IP1_IRQ 19
168 #define WDT_IP2_IRQ 18
170 #define SYSTEM_FREQ 200000000
171 #define RTL838X_UART0_BASE ((volatile void *)(0xb8002000UL))
172 #define RTL838X_UART0_BAUD 38400 /* ex. 19200 or 38400 or 57600 or 115200 */
173 #define RTL838X_UART0_FREQ (SYSTEM_FREQ - RTL838X_UART0_BAUD * 24)
174 #define RTL838X_UART0_MAPBASE 0x18002000UL
175 #define RTL838X_UART0_MAPSIZE 0x100
176 #define RTL838X_UART0_IRQ UART0_IRQ
178 #define RTL838X_UART1_BASE ((volatile void *)(0xb8002100UL))
179 #define RTL838X_UART1_BAUD 38400 /* ex. 19200 or 38400 or 57600 or 115200 */
180 #define RTL838X_UART1_FREQ (SYSTEM_FREQ - RTL838X_UART1_BAUD * 24)
181 #define RTL838X_UART1_MAPBASE 0x18002100UL
182 #define RTL838X_UART1_MAPSIZE 0x100
183 #define RTL838X_UART1_IRQ UART1_IRQ
185 #define UART0_RBR (RTL838X_UART0_BASE + 0x000)
186 #define UART0_THR (RTL838X_UART0_BASE + 0x000)
187 #define UART0_DLL (RTL838X_UART0_BASE + 0x000)
188 #define UART0_IER (RTL838X_UART0_BASE + 0x004)
189 #define UART0_DLM (RTL838X_UART0_BASE + 0x004)
190 #define UART0_IIR (RTL838X_UART0_BASE + 0x008)
191 #define UART0_FCR (RTL838X_UART0_BASE + 0x008)
192 #define UART0_LCR (RTL838X_UART0_BASE + 0x00C)
193 #define UART0_MCR (RTL838X_UART0_BASE + 0x010)
194 #define UART0_LSR (RTL838X_UART0_BASE + 0x014)
196 #define UART1_RBR (RTL838X_UART1_BASE + 0x000)
197 #define UART1_THR (RTL838X_UART1_BASE + 0x000)
198 #define UART1_DLL (RTL838X_UART1_BASE + 0x000)
199 #define UART1_IER (RTL838X_UART1_BASE + 0x004)
200 #define UART1_DLM (RTL838X_UART1_BASE + 0x004)
201 #define UART1_IIR (RTL838X_UART1_BASE + 0x008)
202 #define UART1_FCR (RTL838X_UART1_BASE + 0x008)
204 #define FCR_RXRST 0x02
206 #define FCR_TXRST 0x04
209 #define FCR_RTRG 0xC0
210 #define CHAR_TRIGGER_01 0x00
211 #define CHAR_TRIGGER_04 0x40
212 #define CHAR_TRIGGER_08 0x80
213 #define CHAR_TRIGGER_14 0xC0
214 #define UART1_LCR (RTL838X_UART1_BASE + 0x00C)
216 #define CHAR_LEN_5 0x00
217 #define CHAR_LEN_6 0x01
218 #define CHAR_LEN_7 0x02
219 #define CHAR_LEN_8 0x03
221 #define ONE_STOP 0x00
222 #define TWO_STOP 0x04
224 #define PARITY_ENABLE 0x01
225 #define PARITY_DISABLE 0x00
227 #define PARITY_ODD 0x00
228 #define PARITY_EVEN 0x10
229 #define PARITY_MARK 0x20
230 #define PARITY_SPACE 0x30
232 #define LCR_DLAB 0x80
234 #define UART1_MCR (RTL838X_UART1_BASE + 0x010)
235 #define UART1_LSR (RTL838X_UART1_BASE + 0x014)
237 #define RxCHAR_AVAIL 0x01
242 #define LSR_THRE 0x20
243 #define TxCHAR_AVAIL 0x00
244 #define TxCHAR_EMPTY 0x20
245 #define LSR_TEMT 0x40
249 * Timer/counter for 8390/80/28 TC & MP chip
251 #define RTL838X_TIMER0_BASE ((volatile void *)(0xb8003100UL))
252 #define RTL838X_TIMER0_IRQ RTL838X_TC0_EXT_IRQ
254 #define RTL8390TC_TC1DATA (RTL838X_TIMER0_BASE + 0x04)
255 #define RTL8390TC_TCD_OFFSET 8
256 #define RTL8390TC_TC0CNT (RTL838X_TIMER0_BASE + 0x08)
257 #define RTL8390TC_TC1CNT (RTL838X_TIMER0_BASE + 0x0C)
258 #define RTL8390TC_TCCNR (RTL838X_TIMER0_BASE + 0x10)
259 #define RTL8390TC_TC0EN (1 << 31)
260 #define RTL8390TC_TC0MODE_TIMER (1 << 30)
261 #define RTL8390TC_TC1EN (1 << 29)
262 #define RTL8390TC_TC1MODE_TIMER (1 << 28)
263 #define RTL8390TC_TCIR (RTL838X_TIMER0_BASE + 0x14)
264 #define RTL8390TC_TC0IE (1 << 31)
265 #define RTL8390TC_TC1IE (1 << 30)
266 #define RTL8390TC_TC0IP (1 << 29)
267 #define RTL8390TC_TC1IP (1 << 28)
268 #define RTL8390TC_CDBR (RTL838X_TIMER0_BASE + 0x18)
269 #define RTL8390TC_DIVF_OFFSET 16
270 #define RTL8390TC_WDTCNR (RTL838X_TIMER0_BASE + 0x1C)
272 #define RTL8390MP_TC1DATA (RTL838X_TIMER0_BASE + 0x10)
273 #define RTL8390MP_TC0CNT (RTL838X_TIMER0_BASE + 0x04)
274 #define RTL8390MP_TC1CNT (RTL838X_TIMER0_BASE + 0x14)
275 #define RTL8390MP_TC0CTL (RTL838X_TIMER0_BASE + 0x08)
276 #define RTL8390MP_TC1CTL (RTL838X_TIMER0_BASE + 0x18)
277 #define RTL8390MP_TCEN (1 << 28)
278 #define RTL8390MP_TCMODE_TIMER (1 << 24)
279 #define RTL8390MP_TCDIV_FACTOR (0xFFFF << 0)
280 #define RTL8390MP_TC0INT (RTL838X_TIMER0_BASE + 0xC)
281 #define RTL8390MP_TC1INT (RTL838X_TIMER0_BASE + 0x1C)
282 #define RTL8390MP_TCIE (1 << 20)
283 #define RTL8390MP_TCIP (1 << 16)
284 #define RTL8390MP_WDTCNR (RTL838X_TIMER0_BASE + 0x50)
286 #define RTL8380MP_TC0DATA (RTL838X_TIMER0_BASE + 0x00)
287 #define RTL8380MP_TC1DATA (RTL838X_TIMER0_BASE + 0x10)
288 #define RTL8380MP_TC0CNT (RTL838X_TIMER0_BASE + 0x04)
289 #define RTL8380MP_TC1CNT (RTL838X_TIMER0_BASE + 0x14)
290 #define RTL8380MP_TC0CTL (RTL838X_TIMER0_BASE + 0x08)
291 #define RTL8380MP_TC1CTL (RTL838X_TIMER0_BASE + 0x18)
292 #define RTL8380MP_TCEN (1 << 28)
293 #define RTL8380MP_TCMODE_TIMER (1 << 24)
294 #define RTL8380MP_TCDIV_FACTOR (0xFFFF << 0)
295 #define RTL8380MP_TC0INT (RTL838X_TIMER0_BASE + 0xC)
296 #define RTL8380MP_TC1INT (RTL838X_TIMER0_BASE + 0x1C)
297 #define RTL8380MP_TCIE (1 << 20)
298 #define RTL8380MP_TCIP (1 << 16)
299 #define RTL8380MP_WDTCNR (RTL838X_TIMER0_BASE + 0x50)
301 #define DIVISOR_RTL8390 55
302 #define DIVISOR_RTL8380 2500
303 #define DIVISOR_MAX 16834
308 #define MC_MCR 0xB8001000
309 #define MC_MCR_VAL 0x00000000
311 #define MC_DCR 0xB8001004
312 #define MC_DCR0_VAL 0x54480000
314 #define MC_DTCR 0xB8001008
315 #define MC_DTCR_VAL 0xFFFF05C0
320 #define GPIO_CTRL_REG_BASE ((volatile void *) 0xb8003500)
321 #define RTL838X_GPIO_PABC_CNR (GPIO_CTRL_REG_BASE + 0x0)
322 #define RTL838X_GPIO_PABC_TYPE (GPIO_CTRL_REG_BASE + 0x04)
323 #define RTL838X_GPIO_PABC_DIR (GPIO_CTRL_REG_BASE + 0x8)
324 #define RTL838X_GPIO_PABC_DATA (GPIO_CTRL_REG_BASE + 0xc)
325 #define RTL838X_GPIO_PABC_ISR (GPIO_CTRL_REG_BASE + 0x10)
326 #define RTL838X_GPIO_PAB_IMR (GPIO_CTRL_REG_BASE + 0x14)
327 #define RTL838X_GPIO_PC_IMR (GPIO_CTRL_REG_BASE + 0x18)
329 #define RTL838X_MODEL_NAME_INFO (0x00D4)
330 #define RTL839X_MODEL_NAME_INFO (0x0FF0)
331 #define RTL838X_LED_GLB_CTRL (0xA000)
332 #define RTL839X_LED_GLB_CTRL (0x00E4)
333 #define RTL838X_EXT_GPIO_DIR (0xA08C)
334 #define RTL839X_EXT_GPIO_DIR (0x0214)
335 #define RTL838X_EXT_GPIO_DATA (0xA094)
336 #define RTL839X_EXT_GPIO_DATA (0x021c)
337 #define RTL838X_EXT_GPIO_INDRT_ACCESS (0xA09C)
338 #define RTL839X_EXT_GPIO_INDRT_ACCESS (0x0224)
339 #define RTL838X_EXTRA_GPIO_CTRL (0xA0E0)
340 #define RTL838X_DMY_REG5 (0x0144)
341 #define RTL838X_EXTRA_GPIO_CTRL (0xA0E0)
343 #define RTL838X_GMII_INTF_SEL (0x1000)
344 #define RTL838X_IO_DRIVING_ABILITY_CTRL (0x1010)
346 #define RTL838X_GPIO_A7 31
347 #define RTL838X_GPIO_A6 30
348 #define RTL838X_GPIO_A5 29
349 #define RTL838X_GPIO_A4 28
350 #define RTL838X_GPIO_A3 27
351 #define RTL838X_GPIO_A2 26
352 #define RTL838X_GPIO_A1 25
353 #define RTL838X_GPIO_A0 24
354 #define RTL838X_GPIO_B7 23
355 #define RTL838X_GPIO_B6 22
356 #define RTL838X_GPIO_B5 21
357 #define RTL838X_GPIO_B4 20
358 #define RTL838X_GPIO_B3 19
359 #define RTL838X_GPIO_B2 18
360 #define RTL838X_GPIO_B1 17
361 #define RTL838X_GPIO_B0 16
362 #define RTL838X_GPIO_C7 15
363 #define RTL838X_GPIO_C6 14
364 #define RTL838X_GPIO_C5 13
365 #define RTL838X_GPIO_C4 12
366 #define RTL838X_GPIO_C3 11
367 #define RTL838X_GPIO_C2 10
368 #define RTL838X_GPIO_C1 9
369 #define RTL838X_GPIO_C0 8
371 #define RTL838X_INT_RW_CTRL (0x0058)
372 #define RTL838X_EXT_VERSION (0x00D0)
373 #define RTL838X_PLL_CML_CTRL (0x0FF8)
374 #define RTL838X_STRAP_DBG (0x100C)
379 #define RGCR (0x1E70)
380 #define RTL839X_RST_GLB_CTRL (0x0014)
381 #define RTL838X_RST_GLB_CTRL_1 (0x0040)
383 /* LED control by switch */
384 #define RTL838X_LED_MODE_SEL (0x1004)
385 #define RTL838X_LED_MODE_CTRL (0xA004)
386 #define RTL838X_LED_P_EN_CTRL (0xA008)
388 /* LED control by software */
389 #define RTL838X_LED_SW_CTRL (0x0128)
390 #define RTL839X_LED_SW_CTRL (0xA00C)
391 #define RTL838X_LED_SW_P_EN_CTRL (0xA010)
392 #define RTL839X_LED_SW_P_EN_CTRL (0x012C)
393 #define RTL838X_LED0_SW_P_EN_CTRL (0xA010)
394 #define RTL839X_LED0_SW_P_EN_CTRL (0x012C)
395 #define RTL838X_LED1_SW_P_EN_CTRL (0xA014)
396 #define RTL839X_LED1_SW_P_EN_CTRL (0x0130)
397 #define RTL838X_LED2_SW_P_EN_CTRL (0xA018)
398 #define RTL839X_LED2_SW_P_EN_CTRL (0x0134)
399 #define RTL838X_LED_SW_P_CTRL (0xA01C)
400 #define RTL839X_LED_SW_P_CTRL (0x0144)
402 #define RTL839X_MAC_EFUSE_CTRL (0x02ac)
405 * MDIO via Realtek's SMI interface
407 #define RTL838X_SMI_GLB_CTRL (0xa100)
408 #define RTL838X_SMI_ACCESS_PHY_CTRL_0 (0xa1b8)
409 #define RTL838X_SMI_ACCESS_PHY_CTRL_1 (0xa1bc)
410 #define RTL838X_SMI_ACCESS_PHY_CTRL_2 (0xa1c0)
411 #define RTL838X_SMI_ACCESS_PHY_CTRL_3 (0xa1c4)
412 #define RTL838X_SMI_PORT0_5_ADDR_CTRL (0xa1c8)
413 #define RTL838X_SMI_POLL_CTRL (0xa17c)
415 #define RTL839X_SMI_GLB_CTRL (0x03f8)
416 #define RTL839X_SMI_PORT_POLLING_CTRL (0x03fc)
417 #define RTL839X_PHYREG_ACCESS_CTRL (0x03DC)
418 #define RTL839X_PHYREG_CTRL (0x03E0)
419 #define RTL839X_PHYREG_PORT_CTRL(p) (0x03E4 + ((p >> 5) << 2))
420 #define RTL839X_PHYREG_DATA_CTRL (0x03F0)
425 #define RTL838X_IMR_GLB (0x1100)
426 #define RTL838X_IMR_PORT_LINK_STS_CHG (0x1104)
427 #define RTL838X_ISR_GLB_SRC (0x1148)
428 #define RTL838X_ISR_PORT_LINK_STS_CHG (0x114C)
429 #define RTL839X_IMR_GLB (0x0064)
430 #define RTL839X_IMR_PORT_LINK_STS_CHG (0x0068)
431 #define RTL839X_ISR_GLB_SRC (0x009c)
432 #define RTL839X_ISR_PORT_LINK_STS_CHG (0x00a0)
434 /* Definition of family IDs */
435 #define RTL8389_FAMILY_ID (0x8389)
436 #define RTL8328_FAMILY_ID (0x8328)
437 #define RTL8390_FAMILY_ID (0x8390)
438 #define RTL8350_FAMILY_ID (0x8350)
439 #define RTL8380_FAMILY_ID (0x8380)
440 #define RTL8330_FAMILY_ID (0x8330)
442 struct rtl83xx_soc_info
{
446 unsigned char *compatible
;
447 volatile void *sw_base
;
448 volatile void *icu_base
;
451 /* rtl83xx-related functions used across subsystems */
452 int rtl838x_smi_wait_op(int timeout
);
453 int rtl838x_read_phy(u32 port
, u32 page
, u32 reg
, u32
*val
);
454 int rtl838x_write_phy(u32 port
, u32 page
, u32 reg
, u32 val
);
455 int rtl839x_read_phy(u32 port
, u32 page
, u32 reg
, u32
*val
);
456 int rtl839x_write_phy(u32 port
, u32 page
, u32 reg
, u32 val
);
458 #endif /* _MACH_RTL838X_H_ */