1 From e410b0069ee7c318a5b556f39b8b16814330a208 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Fri, 24 Jan 2014 17:01:17 +0100
4 Subject: [PATCH 15/57] MIPS: ralink: cleanup early_printk
6 Add support for the new MT7621/8 SoC and kill ifdefs.
7 Cleanup some whitespace error while we are at it.
9 Signed-off-by: John Crispin <blogic@openwrt.org>
11 arch/mips/ralink/early_printk.c | 45 ++++++++++++++++++++++++++-------------
12 1 file changed, 30 insertions(+), 15 deletions(-)
14 --- a/arch/mips/ralink/early_printk.c
15 +++ b/arch/mips/ralink/early_printk.c
17 #include <asm/addrspace.h>
19 #ifdef CONFIG_SOC_RT288X
20 -#define EARLY_UART_BASE 0x300c00
21 +#define EARLY_UART_BASE 0x300c00
22 +#define CHIPID_BASE 0x300004
23 +#elif defined(CONFIG_SOC_MT7621)
24 +#define EARLY_UART_BASE 0x1E000c00
25 +#define CHIPID_BASE 0x1E000004
27 -#define EARLY_UART_BASE 0x10000c00
28 +#define EARLY_UART_BASE 0x10000c00
29 +#define CHIPID_BASE 0x10000004
32 -#define UART_REG_RX 0x00
33 -#define UART_REG_TX 0x04
34 -#define UART_REG_IER 0x08
35 -#define UART_REG_IIR 0x0c
36 -#define UART_REG_FCR 0x10
37 -#define UART_REG_LCR 0x14
38 -#define UART_REG_MCR 0x18
39 -#define UART_REG_LSR 0x1c
40 +#define MT7628_CHIP_NAME1 0x20203832
42 +#define UART_REG_TX 0x04
43 +#define UART_REG_LCR 0x0c
44 +#define UART_REG_LSR 0x14
45 +#define UART_REG_LSR_RT2880 0x1c
47 static __iomem void *uart_membase = (__iomem void *) KSEG1ADDR(EARLY_UART_BASE);
48 +static __iomem void *chipid_membase = (__iomem void *) KSEG1ADDR(CHIPID_BASE);
49 +static int init_complete;
51 static inline void uart_w32(u32 val, unsigned reg)
54 return __raw_readl(uart_membase + reg);
57 +static inline int soc_is_mt7628(void)
59 + return IS_ENABLED(CONFIG_SOC_MT7620) &&
60 + (__raw_readl(chipid_membase) == MT7628_CHIP_NAME1);
63 +static inline void find_uart_base(void)
67 + if (!soc_is_mt7628())
70 + for (i = 0; i < 3; i++) {
71 + u32 reg = uart_r32(UART_REG_LCR + (0x100 * i));
76 + uart_membase = (__iomem void *) KSEG1ADDR(EARLY_UART_BASE + (0x100 * i));
81 void prom_putchar(unsigned char ch)
83 - while ((uart_r32(UART_REG_LSR) & UART_LSR_THRE) == 0)
85 - uart_w32(ch, UART_REG_TX);
86 - while ((uart_r32(UART_REG_LSR) & UART_LSR_THRE) == 0)
88 + if (!init_complete) {
93 + if (IS_ENABLED(CONFIG_SOC_MT7621) || soc_is_mt7628()) {
94 + uart_w32(ch, UART_TX);
95 + while ((uart_r32(UART_REG_LSR) & UART_LSR_THRE) == 0)
98 + while ((uart_r32(UART_REG_LSR_RT2880) & UART_LSR_THRE) == 0)
100 + uart_w32(ch, UART_REG_TX);
101 + while ((uart_r32(UART_REG_LSR_RT2880) & UART_LSR_THRE) == 0)