blob: 34c9c27c917e14be52d2900b4380ba772d01e035 [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-VILLARD2b11ea52012-02-28 13:57:51 +080012#include <linux/of_address.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080013
Olof Johansson86dfe442012-03-29 23:22:44 -070014#include <asm/system_misc.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080015#include <asm/mach/map.h>
16
17#include <mach/hardware.h>
18#include <mach/cpu.h>
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080019#include <mach/at91_dbgu.h>
20#include <mach/at91_pmc.h>
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +080021#include <mach/at91_shdwc.h>
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080022
23#include "soc.h"
24#include "generic.h"
25
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080026struct at91_init_soc __initdata at91_boot_soc;
27
28struct at91_socinfo at91_soc_initdata;
29EXPORT_SYMBOL(at91_soc_initdata);
30
31void __init at91rm9200_set_type(int type)
32{
33 if (type == ARCH_REVISON_9200_PQFP)
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080034 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
Nicolas Ferre3e907722011-12-28 13:10:04 +020035 else
36 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
37
38 pr_info("AT91: filled in soc subtype: %s\n",
39 at91_get_soc_subtype(&at91_soc_initdata));
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080040}
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080041
Jean-Christophe PLAGNIOL-VILLARD92100c12011-04-23 15:28:34 +080042void __init at91_init_irq_default(void)
43{
44 at91_init_interrupts(at91_boot_soc.default_irq_priority);
45}
46
47void __init at91_init_interrupts(unsigned int *priority)
48{
49 /* Initialize the AIC interrupt controller */
50 at91_aic_init(priority);
51
52 /* Enable GPIO interrupts */
53 at91_gpio_irq_setup();
54}
55
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +080056void __iomem *at91_ramc_base[2];
57
58void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
59{
60 if (id < 0 || id > 1) {
61 pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
62 BUG();
63 }
64 at91_ramc_base[id] = ioremap(addr, size);
65 if (!at91_ramc_base[id])
66 panic("Impossible to ioremap ramc.%d 0x%x\n", id, addr);
67}
68
Jean-Christophe PLAGNIOL-VILLARDf0051d82011-05-10 03:20:09 +080069static struct map_desc sram_desc[2] __initdata;
70
71void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
72{
73 struct map_desc *desc = &sram_desc[bank];
74
75 desc->virtual = AT91_IO_VIRT_BASE - length;
76 if (bank > 0)
77 desc->virtual -= sram_desc[bank - 1].length;
78
79 desc->pfn = __phys_to_pfn(base);
80 desc->length = length;
81 desc->type = MT_DEVICE;
82
83 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
84 base, length, desc->virtual);
85
86 iotable_init(desc, 1);
87}
88
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +080089static struct map_desc at91_io_desc __initdata = {
90 .virtual = AT91_VA_BASE_SYS,
91 .pfn = __phys_to_pfn(AT91_BASE_SYS),
92 .length = SZ_16K,
93 .type = MT_DEVICE,
94};
95
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +080096static void __init soc_detect(u32 dbgu_base)
97{
98 u32 cidr, socid;
99
100 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
101 socid = cidr & ~AT91_CIDR_VERSION;
102
103 switch (socid) {
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800104 case ARCH_ID_AT91RM9200:
105 at91_soc_initdata.type = AT91_SOC_RM9200;
106 at91_boot_soc = at91rm9200_soc;
107 break;
108
109 case ARCH_ID_AT91SAM9260:
110 at91_soc_initdata.type = AT91_SOC_SAM9260;
111 at91_boot_soc = at91sam9260_soc;
112 break;
113
114 case ARCH_ID_AT91SAM9261:
115 at91_soc_initdata.type = AT91_SOC_SAM9261;
116 at91_boot_soc = at91sam9261_soc;
117 break;
118
119 case ARCH_ID_AT91SAM9263:
120 at91_soc_initdata.type = AT91_SOC_SAM9263;
121 at91_boot_soc = at91sam9263_soc;
122 break;
123
124 case ARCH_ID_AT91SAM9G20:
125 at91_soc_initdata.type = AT91_SOC_SAM9G20;
126 at91_boot_soc = at91sam9260_soc;
127 break;
128
129 case ARCH_ID_AT91SAM9G45:
130 at91_soc_initdata.type = AT91_SOC_SAM9G45;
131 if (cidr == ARCH_ID_AT91SAM9G45ES)
132 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
133 at91_boot_soc = at91sam9g45_soc;
134 break;
135
136 case ARCH_ID_AT91SAM9RL64:
137 at91_soc_initdata.type = AT91_SOC_SAM9RL;
138 at91_boot_soc = at91sam9rl_soc;
139 break;
140
141 case ARCH_ID_AT91SAM9X5:
142 at91_soc_initdata.type = AT91_SOC_SAM9X5;
143 at91_boot_soc = at91sam9x5_soc;
144 break;
Hong Xu74db4fb2012-04-17 14:26:31 +0800145
146 case ARCH_ID_AT91SAM9N12:
147 at91_soc_initdata.type = AT91_SOC_SAM9N12;
148 at91_boot_soc = at91sam9n12_soc;
149 break;
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800150 }
151
152 /* at91sam9g10 */
153 if ((cidr & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
154 at91_soc_initdata.type = AT91_SOC_SAM9G10;
155 at91_boot_soc = at91sam9261_soc;
156 }
157 /* at91sam9xe */
158 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
159 at91_soc_initdata.type = AT91_SOC_SAM9260;
160 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
161 at91_boot_soc = at91sam9260_soc;
162 }
163
164 if (!at91_soc_is_detected())
165 return;
166
167 at91_soc_initdata.cidr = cidr;
168
169 /* sub version of soc */
170 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
171
172 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
173 switch (at91_soc_initdata.exid) {
174 case ARCH_EXID_AT91SAM9M10:
175 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
176 break;
177 case ARCH_EXID_AT91SAM9G46:
178 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
179 break;
180 case ARCH_EXID_AT91SAM9M11:
181 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
182 break;
183 }
184 }
185
186 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
187 switch (at91_soc_initdata.exid) {
188 case ARCH_EXID_AT91SAM9G15:
189 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
190 break;
191 case ARCH_EXID_AT91SAM9G35:
192 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
193 break;
194 case ARCH_EXID_AT91SAM9X35:
195 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
196 break;
197 case ARCH_EXID_AT91SAM9G25:
198 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
199 break;
200 case ARCH_EXID_AT91SAM9X25:
201 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
202 break;
203 }
204 }
205}
206
207static const char *soc_name[] = {
208 [AT91_SOC_RM9200] = "at91rm9200",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800209 [AT91_SOC_SAM9260] = "at91sam9260",
210 [AT91_SOC_SAM9261] = "at91sam9261",
211 [AT91_SOC_SAM9263] = "at91sam9263",
212 [AT91_SOC_SAM9G10] = "at91sam9g10",
213 [AT91_SOC_SAM9G20] = "at91sam9g20",
214 [AT91_SOC_SAM9G45] = "at91sam9g45",
215 [AT91_SOC_SAM9RL] = "at91sam9rl",
216 [AT91_SOC_SAM9X5] = "at91sam9x5",
Hong Xu74db4fb2012-04-17 14:26:31 +0800217 [AT91_SOC_SAM9N12] = "at91sam9n12",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800218 [AT91_SOC_NONE] = "Unknown"
219};
220
221const char *at91_get_soc_type(struct at91_socinfo *c)
222{
223 return soc_name[c->type];
224}
225EXPORT_SYMBOL(at91_get_soc_type);
226
227static const char *soc_subtype_name[] = {
228 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
229 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800230 [AT91_SOC_SAM9XE] = "at91sam9xe",
231 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
232 [AT91_SOC_SAM9M10] = "at91sam9m10",
233 [AT91_SOC_SAM9G46] = "at91sam9g46",
234 [AT91_SOC_SAM9M11] = "at91sam9m11",
235 [AT91_SOC_SAM9G15] = "at91sam9g15",
236 [AT91_SOC_SAM9G35] = "at91sam9g35",
237 [AT91_SOC_SAM9X35] = "at91sam9x35",
238 [AT91_SOC_SAM9G25] = "at91sam9g25",
239 [AT91_SOC_SAM9X25] = "at91sam9x25",
240 [AT91_SOC_SUBTYPE_NONE] = "Unknown"
241};
242
243const char *at91_get_soc_subtype(struct at91_socinfo *c)
244{
245 return soc_subtype_name[c->subtype];
246}
247EXPORT_SYMBOL(at91_get_soc_subtype);
248
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800249void __init at91_map_io(void)
250{
251 /* Map peripherals */
252 iotable_init(&at91_io_desc, 1);
253
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800254 at91_soc_initdata.type = AT91_SOC_NONE;
255 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
256
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800257 soc_detect(AT91_BASE_DBGU0);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800258 if (!at91_soc_is_detected())
Jean-Christophe PLAGNIOL-VILLARD13079a72011-11-02 01:43:31 +0800259 soc_detect(AT91_BASE_DBGU1);
Jean-Christophe PLAGNIOL-VILLARD8c3583b2011-04-23 22:12:57 +0800260
261 if (!at91_soc_is_detected())
262 panic("AT91: Impossible to detect the SOC type");
263
264 pr_info("AT91: Detected soc type: %s\n",
265 at91_get_soc_type(&at91_soc_initdata));
266 pr_info("AT91: Detected soc subtype: %s\n",
267 at91_get_soc_subtype(&at91_soc_initdata));
268
269 if (!at91_soc_is_enabled())
270 panic("AT91: Soc not enabled");
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800271
272 if (at91_boot_soc.map_io)
273 at91_boot_soc.map_io();
274}
275
Jean-Christophe PLAGNIOL-VILLARDf22deee2011-11-01 01:23:20 +0800276void __iomem *at91_shdwc_base = NULL;
277
278static void at91sam9_poweroff(void)
279{
280 at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
281}
282
283void __init at91_ioremap_shdwc(u32 base_addr)
284{
285 at91_shdwc_base = ioremap(base_addr, 16);
286 if (!at91_shdwc_base)
287 panic("Impossible to ioremap at91_shdwc_base\n");
288 pm_power_off = at91sam9_poweroff;
289}
290
Jean-Christophe PLAGNIOL-VILLARDe9f68b52011-11-18 01:25:52 +0800291void __iomem *at91_rstc_base;
292
293void __init at91_ioremap_rstc(u32 base_addr)
294{
295 at91_rstc_base = ioremap(base_addr, 16);
296 if (!at91_rstc_base)
297 panic("Impossible to ioremap at91_rstc_base\n");
298}
299
Jean-Christophe PLAGNIOL-VILLARD4342d642011-11-27 23:15:50 +0800300void __iomem *at91_matrix_base;
301
302void __init at91_ioremap_matrix(u32 base_addr)
303{
304 at91_matrix_base = ioremap(base_addr, 512);
305 if (!at91_matrix_base)
306 panic("Impossible to ioremap at91_matrix_base\n");
307}
308
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800309#if defined(CONFIG_OF)
Jean-Christophe PLAGNIOL-VILLARDc8082d32012-03-03 03:16:27 +0800310static struct of_device_id rstc_ids[] = {
311 { .compatible = "atmel,at91sam9260-rstc", .data = at91sam9_alt_restart },
312 { .compatible = "atmel,at91sam9g45-rstc", .data = at91sam9g45_restart },
313 { /*sentinel*/ }
314};
315
316static void at91_dt_rstc(void)
317{
318 struct device_node *np;
319 const struct of_device_id *of_id;
320
321 np = of_find_matching_node(NULL, rstc_ids);
322 if (!np)
323 panic("unable to find compatible rstc node in dtb\n");
324
325 at91_rstc_base = of_iomap(np, 0);
326 if (!at91_rstc_base)
327 panic("unable to map rstc cpu registers\n");
328
329 of_id = of_match_node(rstc_ids, np);
330 if (!of_id)
331 panic("AT91: rtsc no restart function availlable\n");
332
333 arm_pm_restart = of_id->data;
334
335 of_node_put(np);
336}
337
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800338static struct of_device_id ramc_ids[] = {
339 { .compatible = "atmel,at91sam9260-sdramc" },
340 { .compatible = "atmel,at91sam9g45-ddramc" },
341 { /*sentinel*/ }
342};
343
344static void at91_dt_ramc(void)
345{
346 struct device_node *np;
347
348 np = of_find_matching_node(NULL, ramc_ids);
349 if (!np)
350 panic("unable to find compatible ram conroller node in dtb\n");
351
352 at91_ramc_base[0] = of_iomap(np, 0);
353 if (!at91_ramc_base[0])
354 panic("unable to map ramc[0] cpu registers\n");
355 /* the controller may have 2 banks */
356 at91_ramc_base[1] = of_iomap(np, 1);
357
358 of_node_put(np);
359}
360
Jean-Christophe PLAGNIOL-VILLARD82015c42012-03-02 21:01:00 +0800361static struct of_device_id shdwc_ids[] = {
362 { .compatible = "atmel,at91sam9260-shdwc", },
363 { .compatible = "atmel,at91sam9rl-shdwc", },
364 { .compatible = "atmel,at91sam9x5-shdwc", },
365 { /*sentinel*/ }
366};
367
368static const char *shdwc_wakeup_modes[] = {
369 [AT91_SHDW_WKMODE0_NONE] = "none",
370 [AT91_SHDW_WKMODE0_HIGH] = "high",
371 [AT91_SHDW_WKMODE0_LOW] = "low",
372 [AT91_SHDW_WKMODE0_ANYLEVEL] = "any",
373};
374
375const int at91_dtget_shdwc_wakeup_mode(struct device_node *np)
376{
377 const char *pm;
378 int err, i;
379
380 err = of_property_read_string(np, "atmel,wakeup-mode", &pm);
381 if (err < 0)
382 return AT91_SHDW_WKMODE0_ANYLEVEL;
383
384 for (i = 0; i < ARRAY_SIZE(shdwc_wakeup_modes); i++)
385 if (!strcasecmp(pm, shdwc_wakeup_modes[i]))
386 return i;
387
388 return -ENODEV;
389}
390
391static void at91_dt_shdwc(void)
392{
393 struct device_node *np;
394 int wakeup_mode;
395 u32 reg;
396 u32 mode = 0;
397
398 np = of_find_matching_node(NULL, shdwc_ids);
399 if (!np) {
400 pr_debug("AT91: unable to find compatible shutdown (shdwc) conroller node in dtb\n");
401 return;
402 }
403
404 at91_shdwc_base = of_iomap(np, 0);
405 if (!at91_shdwc_base)
406 panic("AT91: unable to map shdwc cpu registers\n");
407
408 wakeup_mode = at91_dtget_shdwc_wakeup_mode(np);
409 if (wakeup_mode < 0) {
410 pr_warn("AT91: shdwc unknown wakeup mode\n");
411 goto end;
412 }
413
414 if (!of_property_read_u32(np, "atmel,wakeup-counter", &reg)) {
415 if (reg > AT91_SHDW_CPTWK0_MAX) {
416 pr_warn("AT91: shdwc wakeup conter 0x%x > 0x%x reduce it to 0x%x\n",
417 reg, AT91_SHDW_CPTWK0_MAX, AT91_SHDW_CPTWK0_MAX);
418 reg = AT91_SHDW_CPTWK0_MAX;
419 }
420 mode |= AT91_SHDW_CPTWK0_(reg);
421 }
422
423 if (of_property_read_bool(np, "atmel,wakeup-rtc-timer"))
424 mode |= AT91_SHDW_RTCWKEN;
425
426 if (of_property_read_bool(np, "atmel,wakeup-rtt-timer"))
427 mode |= AT91_SHDW_RTTWKEN;
428
429 at91_shdwc_write(AT91_SHDW_MR, wakeup_mode | mode);
430
431end:
432 pm_power_off = at91sam9_poweroff;
433
434 of_node_put(np);
435}
436
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800437void __init at91_dt_initialize(void)
438{
Jean-Christophe PLAGNIOL-VILLARDc8082d32012-03-03 03:16:27 +0800439 at91_dt_rstc();
Jean-Christophe PLAGNIOL-VILLARDa7776ec2012-03-02 20:54:37 +0800440 at91_dt_ramc();
Jean-Christophe PLAGNIOL-VILLARD82015c42012-03-02 21:01:00 +0800441 at91_dt_shdwc();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800442
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800443 /* Init clock subsystem */
Jean-Christophe PLAGNIOL-VILLARDeb5e76f2012-03-02 20:44:23 +0800444 at91_dt_clock_init();
Jean-Christophe PLAGNIOL-VILLARD2b11ea52012-02-28 13:57:51 +0800445
446 /* Register the processor-specific clocks */
447 at91_boot_soc.register_clocks();
448
449 at91_boot_soc.init();
450}
451#endif
452
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800453void __init at91_initialize(unsigned long main_clock)
454{
Jean-Christophe PLAGNIOL-VILLARDcfa5a1f2011-10-14 01:17:18 +0800455 at91_boot_soc.ioremap_registers();
456
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800457 /* Init clock subsystem */
458 at91_clock_init(main_clock);
459
Jean-Christophe PLAGNIOL-VILLARD51ddec72011-04-24 18:15:34 +0800460 /* Register the processor-specific clocks */
461 at91_boot_soc.register_clocks();
462
Jean-Christophe PLAGNIOL-VILLARD46539372011-04-24 18:20:28 +0800463 at91_boot_soc.init();
Jean-Christophe PLAGNIOL-VILLARD21d08b92011-04-23 15:28:34 +0800464}