aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/ath79/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/ath79/setup.c')
-rw-r--r--arch/mips/ath79/setup.c190
1 files changed, 190 insertions, 0 deletions
diff --git a/arch/mips/ath79/setup.c b/arch/mips/ath79/setup.c
new file mode 100644
index 000000000000..175def860165
--- /dev/null
+++ b/arch/mips/ath79/setup.c
@@ -0,0 +1,190 @@
1/*
2 * Atheros AR71XX/AR724X/AR913X specific setup
3 *
4 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * Parts of this file are based on Atheros' 2.6.15 BSP
8 *
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.
12 */
13
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/bootmem.h>
17#include <linux/err.h>
18#include <linux/clk.h>
19
20#include <asm/bootinfo.h>
21#include <asm/time.h> /* for mips_hpt_frequency */
22#include <asm/reboot.h> /* for _machine_{restart,halt} */
23
24#include <asm/mach-ath79/ath79.h>
25#include <asm/mach-ath79/ar71xx_regs.h>
26#include "common.h"
27#include "dev-common.h"
28
29#define ATH79_SYS_TYPE_LEN 64
30
31#define AR71XX_BASE_FREQ 40000000
32#define AR724X_BASE_FREQ 5000000
33#define AR913X_BASE_FREQ 5000000
34
35static char ath79_sys_type[ATH79_SYS_TYPE_LEN];
36
37static void ath79_restart(char *command)
38{
39 ath79_device_reset_set(AR71XX_RESET_FULL_CHIP);
40 for (;;)
41 if (cpu_wait)
42 cpu_wait();
43}
44
45static void ath79_halt(void)
46{
47 while (1)
48 cpu_wait();
49}
50
51static void __init ath79_detect_mem_size(void)
52{
53 unsigned long size;
54
55 for (size = ATH79_MEM_SIZE_MIN; size < ATH79_MEM_SIZE_MAX;
56 size <<= 1) {
57 if (!memcmp(ath79_detect_mem_size,
58 ath79_detect_mem_size + size, 1024))
59 break;
60 }
61
62 add_memory_region(0, size, BOOT_MEM_RAM);
63}
64
65static void __init ath79_detect_sys_type(void)
66{
67 char *chip = "????";
68 u32 id;
69 u32 major;
70 u32 minor;
71 u32 rev = 0;
72
73 id = ath79_reset_rr(AR71XX_RESET_REG_REV_ID);
74 major = id & REV_ID_MAJOR_MASK;
75
76 switch (major) {
77 case REV_ID_MAJOR_AR71XX:
78 minor = id & AR71XX_REV_ID_MINOR_MASK;
79 rev = id >> AR71XX_REV_ID_REVISION_SHIFT;
80 rev &= AR71XX_REV_ID_REVISION_MASK;
81 switch (minor) {
82 case AR71XX_REV_ID_MINOR_AR7130:
83 ath79_soc = ATH79_SOC_AR7130;
84 chip = "7130";
85 break;
86
87 case AR71XX_REV_ID_MINOR_AR7141:
88 ath79_soc = ATH79_SOC_AR7141;
89 chip = "7141";
90 break;
91
92 case AR71XX_REV_ID_MINOR_AR7161:
93 ath79_soc = ATH79_SOC_AR7161;
94 chip = "7161";
95 break;
96 }
97 break;
98
99 case REV_ID_MAJOR_AR7240:
100 ath79_soc = ATH79_SOC_AR7240;
101 chip = "7240";
102 rev = (id & AR724X_REV_ID_REVISION_MASK);
103 break;
104
105 case REV_ID_MAJOR_AR7241:
106 ath79_soc = ATH79_SOC_AR7241;
107 chip = "7241";
108 rev = (id & AR724X_REV_ID_REVISION_MASK);
109 break;
110
111 case REV_ID_MAJOR_AR7242:
112 ath79_soc = ATH79_SOC_AR7242;
113 chip = "7242";
114 rev = (id & AR724X_REV_ID_REVISION_MASK);
115 break;
116
117 case REV_ID_MAJOR_AR913X:
118 minor = id & AR913X_REV_ID_MINOR_MASK;
119 rev = id >> AR913X_REV_ID_REVISION_SHIFT;
120 rev &= AR913X_REV_ID_REVISION_MASK;
121 switch (minor) {
122 case AR913X_REV_ID_MINOR_AR9130:
123 ath79_soc = ATH79_SOC_AR9130;
124 chip = "9130";
125 break;
126
127 case AR913X_REV_ID_MINOR_AR9132:
128 ath79_soc = ATH79_SOC_AR9132;
129 chip = "9132";
130 break;
131 }
132 break;
133
134 default:
135 panic("ath79: unknown SoC, id:0x%08x\n", id);
136 }
137
138 sprintf(ath79_sys_type, "Atheros AR%s rev %u", chip, rev);
139 pr_info("SoC: %s\n", ath79_sys_type);
140}
141
142const char *get_system_type(void)
143{
144 return ath79_sys_type;
145}
146
147unsigned int __cpuinit get_c0_compare_int(void)
148{
149 return CP0_LEGACY_COMPARE_IRQ;
150}
151
152void __init plat_mem_setup(void)
153{
154 set_io_port_base(KSEG1);
155
156 ath79_reset_base = ioremap_nocache(AR71XX_RESET_BASE,
157 AR71XX_RESET_SIZE);
158 ath79_pll_base = ioremap_nocache(AR71XX_PLL_BASE,
159 AR71XX_PLL_SIZE);
160
161 ath79_ddr_base = ioremap_nocache(AR71XX_DDR_CTRL_BASE,
162 AR71XX_DDR_CTRL_SIZE);
163
164 ath79_detect_sys_type();
165 ath79_detect_mem_size();
166 ath79_clocks_init();
167
168 _machine_restart = ath79_restart;
169 _machine_halt = ath79_halt;
170 pm_power_off = ath79_halt;
171}
172
173void __init plat_time_init(void)
174{
175 struct clk *clk;
176
177 clk = clk_get(NULL, "cpu");
178 if (IS_ERR(clk))
179 panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
180
181 mips_hpt_frequency = clk_get_rate(clk) / 2;
182}
183
184static int __init ath79_setup(void)
185{
186 ath79_register_uart();
187 return 0;
188}
189
190arch_initcall(ath79_setup);