2 * Atheros AR71xx SoC specific setup
4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 * Parts of this file are based on Atheros' 2.6.15 BSP
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/serial_8250.h>
17 #include <linux/bootmem.h>
19 #include <asm/bootinfo.h>
20 #include <asm/time.h> /* for mips_hpt_frequency */
21 #include <asm/reboot.h> /* for _machine_{restart,halt} */
22 #include <asm/mips_machine.h>
24 #include <asm/mach-ar71xx/ar71xx.h>
25 #include <asm/mach-ar71xx/pci.h>
30 #define AR71XX_SYS_TYPE_LEN 64
31 #define AR71XX_BASE_FREQ 40000000
32 #define AR91XX_BASE_FREQ 5000000
33 #define AR724X_BASE_FREQ 5000000
35 enum ar71xx_mach_type ar71xx_mach
;
38 EXPORT_SYMBOL_GPL(ar71xx_cpu_freq
);
41 EXPORT_SYMBOL_GPL(ar71xx_ahb_freq
);
44 EXPORT_SYMBOL_GPL(ar71xx_ddr_freq
);
46 enum ar71xx_soc_type ar71xx_soc
;
47 EXPORT_SYMBOL_GPL(ar71xx_soc
);
49 static char ar71xx_sys_type
[AR71XX_SYS_TYPE_LEN
];
51 static void ar71xx_restart(char *command
)
53 ar71xx_device_stop(RESET_MODULE_FULL_CHIP
);
59 static void ar71xx_halt(void)
65 static void __init
ar71xx_detect_mem_size(void)
69 for (size
= AR71XX_MEM_SIZE_MIN
; size
< AR71XX_MEM_SIZE_MAX
;
71 if (!memcmp(ar71xx_detect_mem_size
,
72 ar71xx_detect_mem_size
+ size
, 1024))
76 add_memory_region(0, size
, BOOT_MEM_RAM
);
79 static void __init
ar71xx_detect_sys_type(void)
87 id
= ar71xx_reset_rr(AR71XX_RESET_REG_REV_ID
);
88 major
= id
& REV_ID_MAJOR_MASK
;
91 case REV_ID_MAJOR_AR71XX
:
92 minor
= id
& AR71XX_REV_ID_MINOR_MASK
;
93 rev
= id
>> AR71XX_REV_ID_REVISION_SHIFT
;
94 rev
&= AR71XX_REV_ID_REVISION_MASK
;
96 case AR71XX_REV_ID_MINOR_AR7130
:
97 ar71xx_soc
= AR71XX_SOC_AR7130
;
101 case AR71XX_REV_ID_MINOR_AR7141
:
102 ar71xx_soc
= AR71XX_SOC_AR7141
;
106 case AR71XX_REV_ID_MINOR_AR7161
:
107 ar71xx_soc
= AR71XX_SOC_AR7161
;
113 case REV_ID_MAJOR_AR724X
:
114 ar71xx_soc
= AR71XX_SOC_AR7240
;
116 rev
= (id
& AR724X_REV_ID_REVISION_MASK
);
119 case REV_ID_MAJOR_AR913X
:
120 minor
= id
& AR91XX_REV_ID_MINOR_MASK
;
121 rev
= id
>> AR91XX_REV_ID_REVISION_SHIFT
;
122 rev
&= AR91XX_REV_ID_REVISION_MASK
;
124 case AR91XX_REV_ID_MINOR_AR9130
:
125 ar71xx_soc
= AR71XX_SOC_AR9130
;
129 case AR91XX_REV_ID_MINOR_AR9132
:
130 ar71xx_soc
= AR71XX_SOC_AR9132
;
137 panic("ar71xx: unknown chip id:0x%08x\n", id
);
140 sprintf(ar71xx_sys_type
, "Atheros AR%s rev %u", chip
, rev
);
143 static void __init
ar91xx_detect_sys_frequency(void)
149 pll
= ar71xx_pll_rr(AR91XX_PLL_REG_CPU_CONFIG
);
151 div
= ((pll
>> AR91XX_PLL_DIV_SHIFT
) & AR91XX_PLL_DIV_MASK
);
152 freq
= div
* AR91XX_BASE_FREQ
;
154 ar71xx_cpu_freq
= freq
;
156 div
= ((pll
>> AR91XX_DDR_DIV_SHIFT
) & AR91XX_DDR_DIV_MASK
) + 1;
157 ar71xx_ddr_freq
= freq
/ div
;
159 div
= (((pll
>> AR91XX_AHB_DIV_SHIFT
) & AR91XX_AHB_DIV_MASK
) + 1) * 2;
160 ar71xx_ahb_freq
= ar71xx_cpu_freq
/ div
;
163 static void __init
ar71xx_detect_sys_frequency(void)
169 pll
= ar71xx_pll_rr(AR71XX_PLL_REG_CPU_CONFIG
);
171 div
= ((pll
>> AR71XX_PLL_DIV_SHIFT
) & AR71XX_PLL_DIV_MASK
) + 1;
172 freq
= div
* AR71XX_BASE_FREQ
;
174 div
= ((pll
>> AR71XX_CPU_DIV_SHIFT
) & AR71XX_CPU_DIV_MASK
) + 1;
175 ar71xx_cpu_freq
= freq
/ div
;
177 div
= ((pll
>> AR71XX_DDR_DIV_SHIFT
) & AR71XX_DDR_DIV_MASK
) + 1;
178 ar71xx_ddr_freq
= freq
/ div
;
180 div
= (((pll
>> AR71XX_AHB_DIV_SHIFT
) & AR71XX_AHB_DIV_MASK
) + 1) * 2;
181 ar71xx_ahb_freq
= ar71xx_cpu_freq
/ div
;
184 static void __init
ar724x_detect_sys_frequency(void)
190 pll
= ar71xx_pll_rr(AR724X_PLL_REG_CPU_CONFIG
);
192 div
= ((pll
>> AR724X_PLL_DIV_SHIFT
) & AR724X_PLL_DIV_MASK
);
193 freq
= div
* AR724X_BASE_FREQ
;
195 div
= ((pll
>> AR724X_PLL_REF_DIV_SHIFT
) & AR724X_PLL_REF_DIV_MASK
);
198 ar71xx_cpu_freq
= freq
;
200 div
= ((pll
>> AR724X_DDR_DIV_SHIFT
) & AR724X_DDR_DIV_MASK
) + 1;
201 ar71xx_ddr_freq
= freq
/ div
;
203 div
= (((pll
>> AR724X_AHB_DIV_SHIFT
) & AR724X_AHB_DIV_MASK
) + 1) * 2;
204 ar71xx_ahb_freq
= ar71xx_cpu_freq
/ div
;
207 static void __init
detect_sys_frequency(void)
209 switch (ar71xx_soc
) {
210 case AR71XX_SOC_AR7130
:
211 case AR71XX_SOC_AR7141
:
212 case AR71XX_SOC_AR7161
:
213 ar71xx_detect_sys_frequency();
216 case AR71XX_SOC_AR7240
:
217 ar724x_detect_sys_frequency();
220 case AR71XX_SOC_AR9130
:
221 case AR71XX_SOC_AR9132
:
222 ar91xx_detect_sys_frequency();
230 const char *get_system_type(void)
232 return ar71xx_sys_type
;
235 unsigned int __cpuinit
get_c0_compare_irq(void)
237 return CP0_LEGACY_COMPARE_IRQ
;
240 void __init
plat_mem_setup(void)
242 set_io_port_base(KSEG1
);
244 ar71xx_ddr_base
= ioremap_nocache(AR71XX_DDR_CTRL_BASE
,
245 AR71XX_DDR_CTRL_SIZE
);
247 ar71xx_pll_base
= ioremap_nocache(AR71XX_PLL_BASE
,
250 ar71xx_reset_base
= ioremap_nocache(AR71XX_RESET_BASE
,
253 ar71xx_gpio_base
= ioremap_nocache(AR71XX_GPIO_BASE
, AR71XX_GPIO_SIZE
);
255 ar71xx_usb_ctrl_base
= ioremap_nocache(AR71XX_USB_CTRL_BASE
,
256 AR71XX_USB_CTRL_SIZE
);
258 ar71xx_detect_mem_size();
259 ar71xx_detect_sys_type();
260 detect_sys_frequency();
263 "%s, CPU:%u.%03u MHz, AHB:%u.%03u MHz, DDR:%u.%03u MHz\n",
265 ar71xx_cpu_freq
/ 1000000, (ar71xx_cpu_freq
/ 1000) % 1000,
266 ar71xx_ahb_freq
/ 1000000, (ar71xx_ahb_freq
/ 1000) % 1000,
267 ar71xx_ddr_freq
/ 1000000, (ar71xx_ddr_freq
/ 1000) % 1000);
269 _machine_restart
= ar71xx_restart
;
270 _machine_halt
= ar71xx_halt
;
271 pm_power_off
= ar71xx_halt
;
274 void __init
plat_time_init(void)
276 mips_hpt_frequency
= ar71xx_cpu_freq
/ 2;
279 static int __init
ar71xx_machine_setup(void)
283 ar71xx_add_device_uart();
284 ar71xx_add_device_wdt();
286 mips_machine_setup(ar71xx_mach
);
290 arch_initcall(ar71xx_machine_setup
);