2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
6 * Parts of this file are based on Ralink's 2.6.21 BSP
8 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
9 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
10 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
17 #include <asm/mipsregs.h>
18 #include <asm/mach-ralink/ralink_regs.h>
19 #include <asm/mach-ralink/rt305x.h>
23 enum rt305x_soc_type rt305x_soc
;
25 static struct ralink_pinmux_grp mode_mux
[] = {
28 .mask
= RT305X_GPIO_MODE_I2C
,
29 .gpio_first
= RT305X_GPIO_I2C_SD
,
30 .gpio_last
= RT305X_GPIO_I2C_SCLK
,
33 .mask
= RT305X_GPIO_MODE_SPI
,
34 .gpio_first
= RT305X_GPIO_SPI_EN
,
35 .gpio_last
= RT305X_GPIO_SPI_CLK
,
38 .mask
= RT305X_GPIO_MODE_UART1
,
39 .gpio_first
= RT305X_GPIO_UART1_TXD
,
40 .gpio_last
= RT305X_GPIO_UART1_RXD
,
43 .mask
= RT305X_GPIO_MODE_JTAG
,
44 .gpio_first
= RT305X_GPIO_JTAG_TDO
,
45 .gpio_last
= RT305X_GPIO_JTAG_TDI
,
48 .mask
= RT305X_GPIO_MODE_MDIO
,
49 .gpio_first
= RT305X_GPIO_MDIO_MDC
,
50 .gpio_last
= RT305X_GPIO_MDIO_MDIO
,
53 .mask
= RT305X_GPIO_MODE_SDRAM
,
54 .gpio_first
= RT305X_GPIO_SDRAM_MD16
,
55 .gpio_last
= RT305X_GPIO_SDRAM_MD31
,
58 .mask
= RT305X_GPIO_MODE_RGMII
,
59 .gpio_first
= RT305X_GPIO_GE0_TXD0
,
60 .gpio_last
= RT305X_GPIO_GE0_RXCLK
,
64 static struct ralink_pinmux_grp uart_mux
[] = {
67 .mask
= RT305X_GPIO_MODE_UARTF
,
68 .gpio_first
= RT305X_GPIO_7
,
69 .gpio_last
= RT305X_GPIO_14
,
72 .mask
= RT305X_GPIO_MODE_PCM_UARTF
,
73 .gpio_first
= RT305X_GPIO_7
,
74 .gpio_last
= RT305X_GPIO_14
,
77 .mask
= RT305X_GPIO_MODE_PCM_I2S
,
78 .gpio_first
= RT305X_GPIO_7
,
79 .gpio_last
= RT305X_GPIO_14
,
82 .mask
= RT305X_GPIO_MODE_I2S_UARTF
,
83 .gpio_first
= RT305X_GPIO_7
,
84 .gpio_last
= RT305X_GPIO_14
,
87 .mask
= RT305X_GPIO_MODE_PCM_GPIO
,
88 .gpio_first
= RT305X_GPIO_10
,
89 .gpio_last
= RT305X_GPIO_14
,
92 .mask
= RT305X_GPIO_MODE_GPIO_UARTF
,
93 .gpio_first
= RT305X_GPIO_7
,
94 .gpio_last
= RT305X_GPIO_10
,
97 .mask
= RT305X_GPIO_MODE_GPIO_I2S
,
98 .gpio_first
= RT305X_GPIO_7
,
99 .gpio_last
= RT305X_GPIO_10
,
102 .mask
= RT305X_GPIO_MODE_GPIO
,
106 static void rt305x_wdt_reset(void)
110 /* enable WDT reset output on pin SRAM_CS_N */
111 t
= rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG
);
112 t
|= RT305X_SYSCFG_SRAM_CS0_MODE_WDT
<<
113 RT305X_SYSCFG_SRAM_CS0_MODE_SHIFT
;
114 rt_sysc_w32(t
, SYSC_REG_SYSTEM_CONFIG
);
117 struct ralink_pinmux rt_gpio_pinmux
= {
120 .uart_shift
= RT305X_GPIO_MODE_UART0_SHIFT
,
121 .uart_mask
= RT305X_GPIO_MODE_UART0_MASK
,
122 .wdt_reset
= rt305x_wdt_reset
,
125 static unsigned long rt5350_get_mem_size(void)
127 void __iomem
*sysc
= (void __iomem
*) KSEG1ADDR(RT305X_SYSC_BASE
);
131 t
= __raw_readl(sysc
+ SYSC_REG_SYSTEM_CONFIG
);
132 t
= (t
>> RT5350_SYSCFG0_DRAM_SIZE_SHIFT
) &
133 RT5350_SYSCFG0_DRAM_SIZE_MASK
;
136 case RT5350_SYSCFG0_DRAM_SIZE_2M
:
139 case RT5350_SYSCFG0_DRAM_SIZE_8M
:
142 case RT5350_SYSCFG0_DRAM_SIZE_16M
:
145 case RT5350_SYSCFG0_DRAM_SIZE_32M
:
148 case RT5350_SYSCFG0_DRAM_SIZE_64M
:
152 panic("rt5350: invalid DRAM size: %u", t
);
159 void __init
ralink_clk_init(void)
161 unsigned long cpu_rate
, sys_rate
, wdt_rate
, uart_rate
;
162 unsigned long wmac_rate
= 40000000;
164 u32 t
= rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG
);
166 if (soc_is_rt305x() || soc_is_rt3350()) {
167 t
= (t
>> RT305X_SYSCFG_CPUCLK_SHIFT
) &
168 RT305X_SYSCFG_CPUCLK_MASK
;
170 case RT305X_SYSCFG_CPUCLK_LOW
:
171 cpu_rate
= 320000000;
173 case RT305X_SYSCFG_CPUCLK_HIGH
:
174 cpu_rate
= 384000000;
177 sys_rate
= uart_rate
= wdt_rate
= cpu_rate
/ 3;
178 } else if (soc_is_rt3352()) {
179 t
= (t
>> RT3352_SYSCFG0_CPUCLK_SHIFT
) &
180 RT3352_SYSCFG0_CPUCLK_MASK
;
182 case RT3352_SYSCFG0_CPUCLK_LOW
:
183 cpu_rate
= 384000000;
185 case RT3352_SYSCFG0_CPUCLK_HIGH
:
186 cpu_rate
= 400000000;
189 sys_rate
= wdt_rate
= cpu_rate
/ 3;
190 uart_rate
= 40000000;
191 } else if (soc_is_rt5350()) {
192 t
= (t
>> RT5350_SYSCFG0_CPUCLK_SHIFT
) &
193 RT5350_SYSCFG0_CPUCLK_MASK
;
195 case RT5350_SYSCFG0_CPUCLK_360
:
196 cpu_rate
= 360000000;
197 sys_rate
= cpu_rate
/ 3;
199 case RT5350_SYSCFG0_CPUCLK_320
:
200 cpu_rate
= 320000000;
201 sys_rate
= cpu_rate
/ 4;
203 case RT5350_SYSCFG0_CPUCLK_300
:
204 cpu_rate
= 300000000;
205 sys_rate
= cpu_rate
/ 3;
210 uart_rate
= 40000000;
216 if (soc_is_rt3352() || soc_is_rt5350()) {
217 u32 val
= rt_sysc_r32(RT3352_SYSC_REG_SYSCFG0
);
219 if (!(val
& RT3352_CLKCFG0_XTAL_SEL
))
220 wmac_rate
= 20000000;
223 ralink_clk_add("cpu", cpu_rate
);
224 ralink_clk_add("10000b00.spi", sys_rate
);
225 ralink_clk_add("10000100.timer", wdt_rate
);
226 ralink_clk_add("10000120.watchdog", wdt_rate
);
227 ralink_clk_add("10000500.uart", uart_rate
);
228 ralink_clk_add("10000c00.uartlite", uart_rate
);
229 ralink_clk_add("10100000.ethernet", sys_rate
);
230 ralink_clk_add("10180000.wmac", wmac_rate
);
233 void __init
ralink_of_remap(void)
235 rt_sysc_membase
= plat_of_remap_node("ralink,rt3050-sysc");
236 rt_memc_membase
= plat_of_remap_node("ralink,rt3050-memc");
238 if (!rt_sysc_membase
|| !rt_memc_membase
)
239 panic("Failed to remap core resources");
242 void prom_soc_init(struct ralink_soc_info
*soc_info
)
244 void __iomem
*sysc
= (void __iomem
*) KSEG1ADDR(RT305X_SYSC_BASE
);
250 n0
= __raw_readl(sysc
+ SYSC_REG_CHIP_NAME0
);
251 n1
= __raw_readl(sysc
+ SYSC_REG_CHIP_NAME1
);
253 if (n0
== RT3052_CHIP_NAME0
&& n1
== RT3052_CHIP_NAME1
) {
254 unsigned long icache_sets
;
256 icache_sets
= (read_c0_config1() >> 22) & 7;
257 if (icache_sets
== 1) {
258 rt305x_soc
= RT305X_SOC_RT3050
;
260 soc_info
->compatible
= "ralink,rt3050-soc";
262 rt305x_soc
= RT305X_SOC_RT3052
;
264 soc_info
->compatible
= "ralink,rt3052-soc";
266 } else if (n0
== RT3350_CHIP_NAME0
&& n1
== RT3350_CHIP_NAME1
) {
267 rt305x_soc
= RT305X_SOC_RT3350
;
269 soc_info
->compatible
= "ralink,rt3350-soc";
270 } else if (n0
== RT3352_CHIP_NAME0
&& n1
== RT3352_CHIP_NAME1
) {
271 rt305x_soc
= RT305X_SOC_RT3352
;
273 soc_info
->compatible
= "ralink,rt3352-soc";
274 } else if (n0
== RT5350_CHIP_NAME0
&& n1
== RT5350_CHIP_NAME1
) {
275 rt305x_soc
= RT305X_SOC_RT5350
;
277 soc_info
->compatible
= "ralink,rt5350-soc";
279 panic("rt305x: unknown SoC, n0:%08x n1:%08x", n0
, n1
);
282 id
= __raw_readl(sysc
+ SYSC_REG_CHIP_ID
);
284 snprintf(soc_info
->sys_type
, RAMIPS_SYS_TYPE_LEN
,
285 "Ralink %s id:%u rev:%u",
287 (id
>> CHIP_ID_ID_SHIFT
) & CHIP_ID_ID_MASK
,
288 (id
& CHIP_ID_REV_MASK
));
290 soc_info
->mem_base
= RT305X_SDRAM_BASE
;
291 if (soc_is_rt5350()) {
292 soc_info
->mem_size
= rt5350_get_mem_size();
293 } else if (soc_is_rt305x() || soc_is_rt3350()) {
294 soc_info
->mem_size_min
= RT305X_MEM_SIZE_MIN
;
295 soc_info
->mem_size_max
= RT305X_MEM_SIZE_MAX
;
296 } else if (soc_is_rt3352()) {
297 soc_info
->mem_size_min
= RT3352_MEM_SIZE_MIN
;
298 soc_info
->mem_size_max
= RT3352_MEM_SIZE_MAX
;