blob: 053c36993154e82d4fbcafb8e71eec8dea12a871 [file] [log] [blame]
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +08001/*
2 * Copyright (C) 2007 Atmel Corporation.
3 * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
4 *
5 * Under GPLv2
6 */
7
8#include <linux/module.h>
9#include <linux/io.h>
Jean-Christophe PLAGNIOL-VILLARDfb149f92011-05-07 11:16:00 +080010#include <linux/mm.h>
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +080011#include <linux/pm.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080012
13#include <asm/mach/map.h>
14
15#include <mach/hardware.h>
16#include <mach/cpu.h>
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080017#include <mach/at91_dbgu.h>
18#include <mach/at91_pmc.h>
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +080019#include <mach/at91_shdwc.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080020
21#include "soc.h"
22#include "generic.h"
23
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080024struct at91_init_soc __initdata at91_boot_soc;
25
26struct at91_socinfo at91_soc_initdata;
27EXPORT_SYMBOL(at91_soc_initdata);
28
29void __init at91rm9200_set_type(int type)
30{
31 if (type == ARCH_REVISON_9200_PQFP)
32 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
33 else
34 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
35}
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080036
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +080037void __init at91_init_irq_default(void)
38{
39 at91_init_interrupts(at91_boot_soc.default_irq_priority);
40}
41
42void __init at91_init_interrupts(unsigned int *priority)
43{
44 /* Initialize the AIC interrupt controller */
45 at91_aic_init(priority);
46
47 /* Enable GPIO interrupts */
48 at91_gpio_irq_setup();
49}
50
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080051static struct map_desc sram_desc[2] __initdata;
52
53void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
54{
55 struct map_desc *desc = &sram_desc[bank];
56
57 desc->virtual = AT91_IO_VIRT_BASE - length;
58 if (bank > 0)
59 desc->virtual -= sram_desc[bank - 1].length;
60
61 desc->pfn = __phys_to_pfn(base);
62 desc->length = length;
63 desc->type = MT_DEVICE;
64
65 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
66 base, length, desc->virtual);
67
68 iotable_init(desc, 1);
69}
70
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080071static struct map_desc at91_io_desc __initdata = {
72 .virtual = AT91_VA_BASE_SYS,
73 .pfn = __phys_to_pfn(AT91_BASE_SYS),
74 .length = SZ_16K,
75 .type = MT_DEVICE,
76};
77
Jean-Christophe PLAGNIOL-VILLARDfb149f92011-05-07 11:16:00 +080078void __iomem *at91_ioremap(unsigned long p, size_t size, unsigned int type)
79{
80 if (p >= AT91_BASE_SYS && p <= (AT91_BASE_SYS + SZ_16K - 1))
81 return (void __iomem *)AT91_IO_P2V(p);
82
83 return __arm_ioremap_caller(p, size, type, __builtin_return_address(0));
84}
85EXPORT_SYMBOL(at91_ioremap);
86
87void at91_iounmap(volatile void __iomem *addr)
88{
89 unsigned long virt = (unsigned long)addr;
90
91 if (virt >= VMALLOC_START && virt < VMALLOC_END)
92 __iounmap(addr);
93}
94EXPORT_SYMBOL(at91_iounmap);
95
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080096#define AT91_DBGU0 0xfffff200
97#define AT91_DBGU1 0xffffee00
98
99static void __init soc_detect(u32 dbgu_base)
100{
101 u32 cidr, socid;
102
103 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
104 socid = cidr & ~AT91_CIDR_VERSION;
105
106 switch (socid) {
107 case ARCH_ID_AT91CAP9: {
108#ifdef CONFIG_AT91_PMC_UNIT
109 u32 pmc_ver = at91_sys_read(AT91_PMC_VER);
110
111 if (pmc_ver == ARCH_REVISION_CAP9_B)
112 at91_soc_initdata.subtype = AT91_SOC_CAP9_REV_B;
113 else if (pmc_ver == ARCH_REVISION_CAP9_C)
114 at91_soc_initdata.subtype = AT91_SOC_CAP9_REV_C;
115#endif
116 at91_soc_initdata.type = AT91_SOC_CAP9;
117 at91_boot_soc = at91cap9_soc;
118 break;
119 }
120
121 case ARCH_ID_AT91RM9200:
122 at91_soc_initdata.type = AT91_SOC_RM9200;
123 at91_boot_soc = at91rm9200_soc;
124 break;
125
126 case ARCH_ID_AT91SAM9260:
127 at91_soc_initdata.type = AT91_SOC_SAM9260;
128 at91_boot_soc = at91sam9260_soc;
129 break;
130
131 case ARCH_ID_AT91SAM9261:
132 at91_soc_initdata.type = AT91_SOC_SAM9261;
133 at91_boot_soc = at91sam9261_soc;
134 break;
135
136 case ARCH_ID_AT91SAM9263:
137 at91_soc_initdata.type = AT91_SOC_SAM9263;
138 at91_boot_soc = at91sam9263_soc;
139 break;
140
141 case ARCH_ID_AT91SAM9G20:
142 at91_soc_initdata.type = AT91_SOC_SAM9G20;
143 at91_boot_soc = at91sam9260_soc;
144 break;
145
146 case ARCH_ID_AT91SAM9G45:
147 at91_soc_initdata.type = AT91_SOC_SAM9G45;
148 if (cidr == ARCH_ID_AT91SAM9G45ES)
149 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
150 at91_boot_soc = at91sam9g45_soc;
151 break;
152
153 case ARCH_ID_AT91SAM9RL64:
154 at91_soc_initdata.type = AT91_SOC_SAM9RL;
155 at91_boot_soc = at91sam9rl_soc;
156 break;
157
158 case ARCH_ID_AT91SAM9X5:
159 at91_soc_initdata.type = AT91_SOC_SAM9X5;
160 at91_boot_soc = at91sam9x5_soc;
161 break;
162 }
163
164 /* at91sam9g10 */
165 if ((cidr & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
166 at91_soc_initdata.type = AT91_SOC_SAM9G10;
167 at91_boot_soc = at91sam9261_soc;
168 }
169 /* at91sam9xe */
170 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
171 at91_soc_initdata.type = AT91_SOC_SAM9260;
172 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
173 at91_boot_soc = at91sam9260_soc;
174 }
175
176 if (!at91_soc_is_detected())
177 return;
178
179 at91_soc_initdata.cidr = cidr;
180
181 /* sub version of soc */
182 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
183
184 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
185 switch (at91_soc_initdata.exid) {
186 case ARCH_EXID_AT91SAM9M10:
187 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
188 break;
189 case ARCH_EXID_AT91SAM9G46:
190 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
191 break;
192 case ARCH_EXID_AT91SAM9M11:
193 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
194 break;
195 }
196 }
197
198 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
199 switch (at91_soc_initdata.exid) {
200 case ARCH_EXID_AT91SAM9G15:
201 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
202 break;
203 case ARCH_EXID_AT91SAM9G35:
204 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
205 break;
206 case ARCH_EXID_AT91SAM9X35:
207 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
208 break;
209 case ARCH_EXID_AT91SAM9G25:
210 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
211 break;
212 case ARCH_EXID_AT91SAM9X25:
213 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
214 break;
215 }
216 }
217}
218
219static const char *soc_name[] = {
220 [AT91_SOC_RM9200] = "at91rm9200",
221 [AT91_SOC_CAP9] = "at91cap9",
222 [AT91_SOC_SAM9260] = "at91sam9260",
223 [AT91_SOC_SAM9261] = "at91sam9261",
224 [AT91_SOC_SAM9263] = "at91sam9263",
225 [AT91_SOC_SAM9G10] = "at91sam9g10",
226 [AT91_SOC_SAM9G20] = "at91sam9g20",
227 [AT91_SOC_SAM9G45] = "at91sam9g45",
228 [AT91_SOC_SAM9RL] = "at91sam9rl",
229 [AT91_SOC_SAM9X5] = "at91sam9x5",
230 [AT91_SOC_NONE] = "Unknown"
231};
232
233const char *at91_get_soc_type(struct at91_socinfo *c)
234{
235 return soc_name[c->type];
236}
237EXPORT_SYMBOL(at91_get_soc_type);
238
239static const char *soc_subtype_name[] = {
240 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
241 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
242 [AT91_SOC_CAP9_REV_B] = "at91cap9 revB",
243 [AT91_SOC_CAP9_REV_C] = "at91cap9 revC",
244 [AT91_SOC_SAM9XE] = "at91sam9xe",
245 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
246 [AT91_SOC_SAM9M10] = "at91sam9m10",
247 [AT91_SOC_SAM9G46] = "at91sam9g46",
248 [AT91_SOC_SAM9M11] = "at91sam9m11",
249 [AT91_SOC_SAM9G15] = "at91sam9g15",
250 [AT91_SOC_SAM9G35] = "at91sam9g35",
251 [AT91_SOC_SAM9X35] = "at91sam9x35",
252 [AT91_SOC_SAM9G25] = "at91sam9g25",
253 [AT91_SOC_SAM9X25] = "at91sam9x25",
254 [AT91_SOC_SUBTYPE_NONE] = "Unknown"
255};
256
257const char *at91_get_soc_subtype(struct at91_socinfo *c)
258{
259 return soc_subtype_name[c->subtype];
260}
261EXPORT_SYMBOL(at91_get_soc_subtype);
262
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800263void __init at91_map_io(void)
264{
265 /* Map peripherals */
266 iotable_init(&at91_io_desc, 1);
267
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800268 at91_soc_initdata.type = AT91_SOC_NONE;
269 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
270
271 soc_detect(AT91_DBGU0);
272 if (!at91_soc_is_detected())
273 soc_detect(AT91_DBGU1);
274
275 if (!at91_soc_is_detected())
276 panic("AT91: Impossible to detect the SOC type");
277
278 pr_info("AT91: Detected soc type: %s\n",
279 at91_get_soc_type(&at91_soc_initdata));
280 pr_info("AT91: Detected soc subtype: %s\n",
281 at91_get_soc_subtype(&at91_soc_initdata));
282
283 if (!at91_soc_is_enabled())
284 panic("AT91: Soc not enabled");
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800285
286 if (at91_boot_soc.map_io)
287 at91_boot_soc.map_io();
288}
289
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +0800290void __iomem *at91_shdwc_base = NULL;
291
292static void at91sam9_poweroff(void)
293{
294 at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
295}
296
297void __init at91_ioremap_shdwc(u32 base_addr)
298{
299 at91_shdwc_base = ioremap(base_addr, 16);
300 if (!at91_shdwc_base)
301 panic("Impossible to ioremap at91_shdwc_base\n");
302 pm_power_off = at91sam9_poweroff;
303}
304
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800305void __init at91_initialize(unsigned long main_clock)
306{
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800307 at91_boot_soc.ioremap_registers();
308
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800309 /* Init clock subsystem */
310 at91_clock_init(main_clock);
311
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800312 /* Register the processor-specific clocks */
313 at91_boot_soc.register_clocks();
314
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800315 at91_boot_soc.init();
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800316}