2 * Copyright (C) 2007 Atmel Corporation.
3 * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
8 #include <linux/module.h>
12 #include <linux/of_address.h>
13 #include <linux/pinctrl/machine.h>
14 #include <linux/clk/at91_pmc.h>
16 #include <asm/system_misc.h>
17 #include <asm/mach/map.h>
19 #include <mach/hardware.h>
21 #include <mach/at91_dbgu.h>
23 #include "at91_shdwc.h"
28 struct at91_init_soc __initdata at91_boot_soc;
30 struct at91_socinfo at91_soc_initdata;
31 EXPORT_SYMBOL(at91_soc_initdata);
33 void __init at91rm9200_set_type(int type)
35 if (type == ARCH_REVISON_9200_PQFP)
36 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
38 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
40 pr_info("AT91: filled in soc subtype: %s\n",
41 at91_get_soc_subtype(&at91_soc_initdata));
44 void __init at91_init_irq_default(void)
46 at91_init_interrupts(at91_boot_soc.default_irq_priority);
49 void __init at91_init_interrupts(unsigned int *priority)
51 /* Initialize the AIC interrupt controller */
52 at91_aic_init(priority, at91_boot_soc.extern_irq);
54 /* Enable GPIO interrupts */
55 at91_gpio_irq_setup();
58 void __iomem *at91_ramc_base[2];
59 EXPORT_SYMBOL_GPL(at91_ramc_base);
61 void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
63 if (id < 0 || id > 1) {
64 pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
67 at91_ramc_base[id] = ioremap(addr, size);
68 if (!at91_ramc_base[id])
69 panic("Impossible to ioremap ramc.%d 0x%x\n", id, addr);
72 static struct map_desc sram_desc[2] __initdata;
74 void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
76 struct map_desc *desc = &sram_desc[bank];
78 desc->virtual = (unsigned long)AT91_IO_VIRT_BASE - length;
80 desc->virtual -= sram_desc[bank - 1].length;
82 desc->pfn = __phys_to_pfn(base);
83 desc->length = length;
84 desc->type = MT_MEMORY_RWX_NONCACHED;
86 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
87 base, length, desc->virtual);
89 iotable_init(desc, 1);
92 static struct map_desc at91_io_desc __initdata __maybe_unused = {
93 .virtual = (unsigned long)AT91_VA_BASE_SYS,
94 .pfn = __phys_to_pfn(AT91_BASE_SYS),
99 static struct map_desc at91_alt_io_desc __initdata __maybe_unused = {
100 .virtual = (unsigned long)AT91_ALT_VA_BASE_SYS,
101 .pfn = __phys_to_pfn(AT91_ALT_BASE_SYS),
102 .length = 24 * SZ_1K,
106 static void __init soc_detect(u32 dbgu_base)
110 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
111 socid = cidr & ~AT91_CIDR_VERSION;
114 case ARCH_ID_AT91RM9200:
115 at91_soc_initdata.type = AT91_SOC_RM9200;
116 if (at91_soc_initdata.subtype == AT91_SOC_SUBTYPE_UNKNOWN)
117 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
118 at91_boot_soc = at91rm9200_soc;
121 case ARCH_ID_AT91SAM9260:
122 at91_soc_initdata.type = AT91_SOC_SAM9260;
123 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
124 at91_boot_soc = at91sam9260_soc;
127 case ARCH_ID_AT91SAM9261:
128 at91_soc_initdata.type = AT91_SOC_SAM9261;
129 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
130 at91_boot_soc = at91sam9261_soc;
133 case ARCH_ID_AT91SAM9263:
134 at91_soc_initdata.type = AT91_SOC_SAM9263;
135 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
136 at91_boot_soc = at91sam9263_soc;
139 case ARCH_ID_AT91SAM9G20:
140 at91_soc_initdata.type = AT91_SOC_SAM9G20;
141 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
142 at91_boot_soc = at91sam9260_soc;
145 case ARCH_ID_AT91SAM9G45:
146 at91_soc_initdata.type = AT91_SOC_SAM9G45;
147 if (cidr == ARCH_ID_AT91SAM9G45ES)
148 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
149 at91_boot_soc = at91sam9g45_soc;
152 case ARCH_ID_AT91SAM9RL64:
153 at91_soc_initdata.type = AT91_SOC_SAM9RL;
154 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
155 at91_boot_soc = at91sam9rl_soc;
158 case ARCH_ID_AT91SAM9X5:
159 at91_soc_initdata.type = AT91_SOC_SAM9X5;
160 at91_boot_soc = at91sam9x5_soc;
163 case ARCH_ID_AT91SAM9N12:
164 at91_soc_initdata.type = AT91_SOC_SAM9N12;
165 at91_boot_soc = at91sam9n12_soc;
169 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
170 if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
171 at91_soc_initdata.type = AT91_SOC_SAMA5D3;
172 at91_boot_soc = sama5d3_soc;
178 if ((socid & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
179 at91_soc_initdata.type = AT91_SOC_SAM9G10;
180 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
181 at91_boot_soc = at91sam9261_soc;
184 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
185 at91_soc_initdata.type = AT91_SOC_SAM9260;
186 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
187 at91_boot_soc = at91sam9260_soc;
190 if (!at91_soc_is_detected())
193 at91_soc_initdata.cidr = cidr;
195 /* sub version of soc */
196 if (!at91_soc_initdata.exid)
197 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
199 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
200 switch (at91_soc_initdata.exid) {
201 case ARCH_EXID_AT91SAM9M10:
202 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
204 case ARCH_EXID_AT91SAM9G46:
205 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
207 case ARCH_EXID_AT91SAM9M11:
208 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
213 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
214 switch (at91_soc_initdata.exid) {
215 case ARCH_EXID_AT91SAM9G15:
216 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
218 case ARCH_EXID_AT91SAM9G35:
219 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
221 case ARCH_EXID_AT91SAM9X35:
222 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
224 case ARCH_EXID_AT91SAM9G25:
225 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
227 case ARCH_EXID_AT91SAM9X25:
228 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
233 if (at91_soc_initdata.type == AT91_SOC_SAMA5D3) {
234 switch (at91_soc_initdata.exid) {
235 case ARCH_EXID_SAMA5D31:
236 at91_soc_initdata.subtype = AT91_SOC_SAMA5D31;
238 case ARCH_EXID_SAMA5D33:
239 at91_soc_initdata.subtype = AT91_SOC_SAMA5D33;
241 case ARCH_EXID_SAMA5D34:
242 at91_soc_initdata.subtype = AT91_SOC_SAMA5D34;
244 case ARCH_EXID_SAMA5D35:
245 at91_soc_initdata.subtype = AT91_SOC_SAMA5D35;
247 case ARCH_EXID_SAMA5D36:
248 at91_soc_initdata.subtype = AT91_SOC_SAMA5D36;
254 static void __init alt_soc_detect(u32 dbgu_base)
259 cidr = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
260 socid = cidr & ~AT91_CIDR_VERSION;
264 at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
265 if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
266 at91_soc_initdata.type = AT91_SOC_SAMA5D3;
267 at91_boot_soc = sama5d3_soc;
268 } else if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D4) {
269 at91_soc_initdata.type = AT91_SOC_SAMA5D4;
270 at91_boot_soc = sama5d4_soc;
275 if (!at91_soc_is_detected())
278 at91_soc_initdata.cidr = cidr;
280 /* sub version of soc */
281 if (!at91_soc_initdata.exid)
282 at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
284 if (at91_soc_initdata.type == AT91_SOC_SAMA5D4) {
285 switch (at91_soc_initdata.exid) {
286 case ARCH_EXID_SAMA5D41:
287 at91_soc_initdata.subtype = AT91_SOC_SAMA5D41;
289 case ARCH_EXID_SAMA5D42:
290 at91_soc_initdata.subtype = AT91_SOC_SAMA5D42;
292 case ARCH_EXID_SAMA5D43:
293 at91_soc_initdata.subtype = AT91_SOC_SAMA5D43;
295 case ARCH_EXID_SAMA5D44:
296 at91_soc_initdata.subtype = AT91_SOC_SAMA5D44;
302 static const char *soc_name[] = {
303 [AT91_SOC_RM9200] = "at91rm9200",
304 [AT91_SOC_SAM9260] = "at91sam9260",
305 [AT91_SOC_SAM9261] = "at91sam9261",
306 [AT91_SOC_SAM9263] = "at91sam9263",
307 [AT91_SOC_SAM9G10] = "at91sam9g10",
308 [AT91_SOC_SAM9G20] = "at91sam9g20",
309 [AT91_SOC_SAM9G45] = "at91sam9g45",
310 [AT91_SOC_SAM9RL] = "at91sam9rl",
311 [AT91_SOC_SAM9X5] = "at91sam9x5",
312 [AT91_SOC_SAM9N12] = "at91sam9n12",
313 [AT91_SOC_SAMA5D3] = "sama5d3",
314 [AT91_SOC_SAMA5D4] = "sama5d4",
315 [AT91_SOC_UNKNOWN] = "Unknown",
318 const char *at91_get_soc_type(struct at91_socinfo *c)
320 return soc_name[c->type];
322 EXPORT_SYMBOL(at91_get_soc_type);
324 static const char *soc_subtype_name[] = {
325 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
326 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
327 [AT91_SOC_SAM9XE] = "at91sam9xe",
328 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
329 [AT91_SOC_SAM9M10] = "at91sam9m10",
330 [AT91_SOC_SAM9G46] = "at91sam9g46",
331 [AT91_SOC_SAM9M11] = "at91sam9m11",
332 [AT91_SOC_SAM9G15] = "at91sam9g15",
333 [AT91_SOC_SAM9G35] = "at91sam9g35",
334 [AT91_SOC_SAM9X35] = "at91sam9x35",
335 [AT91_SOC_SAM9G25] = "at91sam9g25",
336 [AT91_SOC_SAM9X25] = "at91sam9x25",
337 [AT91_SOC_SAMA5D31] = "sama5d31",
338 [AT91_SOC_SAMA5D33] = "sama5d33",
339 [AT91_SOC_SAMA5D34] = "sama5d34",
340 [AT91_SOC_SAMA5D35] = "sama5d35",
341 [AT91_SOC_SAMA5D36] = "sama5d36",
342 [AT91_SOC_SAMA5D41] = "sama5d41",
343 [AT91_SOC_SAMA5D42] = "sama5d42",
344 [AT91_SOC_SAMA5D43] = "sama5d43",
345 [AT91_SOC_SAMA5D44] = "sama5d44",
346 [AT91_SOC_SUBTYPE_NONE] = "None",
347 [AT91_SOC_SUBTYPE_UNKNOWN] = "Unknown",
350 const char *at91_get_soc_subtype(struct at91_socinfo *c)
352 return soc_subtype_name[c->subtype];
354 EXPORT_SYMBOL(at91_get_soc_subtype);
356 void __init at91_map_io(void)
358 /* Map peripherals */
359 iotable_init(&at91_io_desc, 1);
361 at91_soc_initdata.type = AT91_SOC_UNKNOWN;
362 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
364 soc_detect(AT91_BASE_DBGU0);
365 if (!at91_soc_is_detected())
366 soc_detect(AT91_BASE_DBGU1);
368 if (!at91_soc_is_detected())
369 panic("AT91: Impossible to detect the SOC type");
371 pr_info("AT91: Detected soc type: %s\n",
372 at91_get_soc_type(&at91_soc_initdata));
373 if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
374 pr_info("AT91: Detected soc subtype: %s\n",
375 at91_get_soc_subtype(&at91_soc_initdata));
377 if (!at91_soc_is_enabled())
378 panic("AT91: Soc not enabled");
380 if (at91_boot_soc.map_io)
381 at91_boot_soc.map_io();
384 void __iomem *at91_shdwc_base = NULL;
386 static void at91sam9_poweroff(void)
388 at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
391 void __init at91_ioremap_shdwc(u32 base_addr)
393 at91_shdwc_base = ioremap(base_addr, 16);
394 if (!at91_shdwc_base)
395 panic("Impossible to ioremap at91_shdwc_base\n");
396 pm_power_off = at91sam9_poweroff;
399 void __iomem *at91_rstc_base;
401 void __init at91_ioremap_rstc(u32 base_addr)
403 at91_rstc_base = ioremap(base_addr, 16);
405 panic("Impossible to ioremap at91_rstc_base\n");
408 void __init at91_alt_map_io(void)
410 /* Map peripherals */
411 iotable_init(&at91_alt_io_desc, 1);
413 at91_soc_initdata.type = AT91_SOC_UNKNOWN;
414 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
416 alt_soc_detect(AT91_BASE_DBGU2);
417 if (!at91_soc_is_detected())
418 panic("AT91: Impossible to detect the SOC type");
420 pr_info("AT91: Detected soc type: %s\n",
421 at91_get_soc_type(&at91_soc_initdata));
422 if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
423 pr_info("AT91: Detected soc subtype: %s\n",
424 at91_get_soc_subtype(&at91_soc_initdata));
426 if (!at91_soc_is_enabled())
427 panic("AT91: Soc not enabled");
429 if (at91_boot_soc.map_io)
430 at91_boot_soc.map_io();
433 void __iomem *at91_matrix_base;
434 EXPORT_SYMBOL_GPL(at91_matrix_base);
436 void __init at91_ioremap_matrix(u32 base_addr)
438 at91_matrix_base = ioremap(base_addr, 512);
439 if (!at91_matrix_base)
440 panic("Impossible to ioremap at91_matrix_base\n");
443 #if defined(CONFIG_OF) && !defined(CONFIG_ARCH_AT91X40)
444 static struct of_device_id rstc_ids[] = {
445 { .compatible = "atmel,at91sam9260-rstc", .data = at91sam9_alt_restart },
446 { .compatible = "atmel,at91sam9g45-rstc", .data = at91sam9g45_restart },
450 static void at91_dt_rstc(void)
452 struct device_node *np;
453 const struct of_device_id *of_id;
455 np = of_find_matching_node(NULL, rstc_ids);
457 panic("unable to find compatible rstc node in dtb\n");
459 at91_rstc_base = of_iomap(np, 0);
461 panic("unable to map rstc cpu registers\n");
463 of_id = of_match_node(rstc_ids, np);
465 panic("AT91: rtsc no restart function available\n");
467 arm_pm_restart = of_id->data;
472 static struct of_device_id ramc_ids[] = {
473 { .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby },
474 { .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby },
475 { .compatible = "atmel,at91sam9g45-ddramc", .data = at91_ddr_standby },
479 static void at91_dt_ramc(void)
481 struct device_node *np;
482 const struct of_device_id *of_id;
484 np = of_find_matching_node(NULL, ramc_ids);
486 panic("unable to find compatible ram controller node in dtb\n");
488 at91_ramc_base[0] = of_iomap(np, 0);
489 if (!at91_ramc_base[0])
490 panic("unable to map ramc[0] cpu registers\n");
491 /* the controller may have 2 banks */
492 at91_ramc_base[1] = of_iomap(np, 1);
494 of_id = of_match_node(ramc_ids, np);
496 pr_warn("AT91: ramc no standby function available\n");
498 at91_pm_set_standby(of_id->data);
503 static struct of_device_id shdwc_ids[] = {
504 { .compatible = "atmel,at91sam9260-shdwc", },
505 { .compatible = "atmel,at91sam9rl-shdwc", },
506 { .compatible = "atmel,at91sam9x5-shdwc", },
510 static const char *shdwc_wakeup_modes[] = {
511 [AT91_SHDW_WKMODE0_NONE] = "none",
512 [AT91_SHDW_WKMODE0_HIGH] = "high",
513 [AT91_SHDW_WKMODE0_LOW] = "low",
514 [AT91_SHDW_WKMODE0_ANYLEVEL] = "any",
517 const int at91_dtget_shdwc_wakeup_mode(struct device_node *np)
522 err = of_property_read_string(np, "atmel,wakeup-mode", &pm);
524 return AT91_SHDW_WKMODE0_ANYLEVEL;
526 for (i = 0; i < ARRAY_SIZE(shdwc_wakeup_modes); i++)
527 if (!strcasecmp(pm, shdwc_wakeup_modes[i]))
533 static void at91_dt_shdwc(void)
535 struct device_node *np;
540 np = of_find_matching_node(NULL, shdwc_ids);
542 pr_debug("AT91: unable to find compatible shutdown (shdwc) controller node in dtb\n");
546 at91_shdwc_base = of_iomap(np, 0);
547 if (!at91_shdwc_base)
548 panic("AT91: unable to map shdwc cpu registers\n");
550 wakeup_mode = at91_dtget_shdwc_wakeup_mode(np);
551 if (wakeup_mode < 0) {
552 pr_warn("AT91: shdwc unknown wakeup mode\n");
556 if (!of_property_read_u32(np, "atmel,wakeup-counter", ®)) {
557 if (reg > AT91_SHDW_CPTWK0_MAX) {
558 pr_warn("AT91: shdwc wakeup counter 0x%x > 0x%x reduce it to 0x%x\n",
559 reg, AT91_SHDW_CPTWK0_MAX, AT91_SHDW_CPTWK0_MAX);
560 reg = AT91_SHDW_CPTWK0_MAX;
562 mode |= AT91_SHDW_CPTWK0_(reg);
565 if (of_property_read_bool(np, "atmel,wakeup-rtc-timer"))
566 mode |= AT91_SHDW_RTCWKEN;
568 if (of_property_read_bool(np, "atmel,wakeup-rtt-timer"))
569 mode |= AT91_SHDW_RTTWKEN;
571 at91_shdwc_write(AT91_SHDW_MR, wakeup_mode | mode);
574 pm_power_off = at91sam9_poweroff;
579 void __init at91rm9200_dt_initialize(void)
583 /* Init clock subsystem */
584 at91_dt_clock_init();
586 /* Register the processor-specific clocks */
587 if (at91_boot_soc.register_clocks)
588 at91_boot_soc.register_clocks();
590 at91_boot_soc.init();
593 void __init at91_dt_initialize(void)
599 /* Init clock subsystem */
600 at91_dt_clock_init();
602 /* Register the processor-specific clocks */
603 if (at91_boot_soc.register_clocks)
604 at91_boot_soc.register_clocks();
606 if (at91_boot_soc.init)
607 at91_boot_soc.init();
611 void __init at91_initialize(unsigned long main_clock)
613 at91_boot_soc.ioremap_registers();
615 /* Init clock subsystem */
616 at91_clock_init(main_clock);
618 /* Register the processor-specific clocks */
619 at91_boot_soc.register_clocks();
621 at91_boot_soc.init();
623 pinctrl_provide_dummies();