2 * Copyright (C) 2007 Atmel Corporation.
3 * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
8 #define pr_fmt(fmt) "AT91: " fmt
10 #include <linux/module.h>
14 #include <linux/of_address.h>
15 #include <linux/pinctrl/machine.h>
16 #include <linux/clk/at91_pmc.h>
18 #include <asm/system_misc.h>
19 #include <asm/mach/map.h>
21 #include <mach/hardware.h>
23 #include <mach/at91_dbgu.h>
29 struct at91_init_soc __initdata at91_boot_soc;
31 struct at91_socinfo at91_soc_initdata;
32 EXPORT_SYMBOL(at91_soc_initdata);
34 void __init at91rm9200_set_type(int type)
36 if (type == ARCH_REVISON_9200_PQFP)
37 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
39 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
41 pr_info("filled in soc subtype: %s\n",
42 at91_get_soc_subtype(&at91_soc_initdata));
45 void __init at91_init_irq_default(void)
47 at91_init_interrupts(at91_boot_soc.default_irq_priority);
50 void __init at91_init_interrupts(unsigned int *priority)
52 /* Enable GPIO interrupts */
53 at91_gpio_irq_setup();
56 void __iomem *at91_ramc_base[2];
57 EXPORT_SYMBOL_GPL(at91_ramc_base);
59 void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
61 if (id < 0 || id > 1) {
62 pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
65 at91_ramc_base[id] = ioremap(addr, size);
66 if (!at91_ramc_base[id])
67 panic(pr_fmt("Impossible to ioremap ramc.%d 0x%x\n"), id, addr);
70 static struct map_desc sram_desc[2] __initdata;
72 void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
74 struct map_desc *desc = &sram_desc[bank];
76 desc->virtual = (unsigned long)AT91_IO_VIRT_BASE - length;
78 desc->virtual -= sram_desc[bank - 1].length;
80 desc->pfn = __phys_to_pfn(base);
81 desc->length = length;
82 desc->type = MT_MEMORY_RWX_NONCACHED;
84 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
85 base, length, desc->virtual);
87 iotable_init(desc, 1);
90 static struct map_desc at91_io_desc __initdata __maybe_unused = {
91 .virtual = (unsigned long)AT91_VA_BASE_SYS,
92 .pfn = __phys_to_pfn(AT91_BASE_SYS),
97 static struct map_desc at91_alt_io_desc __initdata __maybe_unused = {
98 .virtual = (unsigned long)AT91_ALT_VA_BASE_SYS,
99 .pfn = __phys_to_pfn(AT91_ALT_BASE_SYS),
100 .length = 24 * SZ_1K,
104 static void __init soc_detect(u32 dbgu_base)
108 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
109 socid = cidr & ~AT91_CIDR_VERSION;
112 case ARCH_ID_AT91RM9200:
113 at91_soc_initdata.type = AT91_SOC_RM9200;
114 if (at91_soc_initdata.subtype == AT91_SOC_SUBTYPE_UNKNOWN)
115 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
116 at91_boot_soc = at91rm9200_soc;
119 case ARCH_ID_AT91SAM9260:
120 at91_soc_initdata.type = AT91_SOC_SAM9260;
121 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
122 at91_boot_soc = at91sam9260_soc;
125 case ARCH_ID_AT91SAM9261:
126 at91_soc_initdata.type = AT91_SOC_SAM9261;
127 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
128 at91_boot_soc = at91sam9261_soc;
131 case ARCH_ID_AT91SAM9263:
132 at91_soc_initdata.type = AT91_SOC_SAM9263;
133 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
134 at91_boot_soc = at91sam9263_soc;
137 case ARCH_ID_AT91SAM9G20:
138 at91_soc_initdata.type = AT91_SOC_SAM9G20;
139 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
140 at91_boot_soc = at91sam9260_soc;
143 case ARCH_ID_AT91SAM9G45:
144 at91_soc_initdata.type = AT91_SOC_SAM9G45;
145 if (cidr == ARCH_ID_AT91SAM9G45ES)
146 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
147 at91_boot_soc = at91sam9g45_soc;
150 case ARCH_ID_AT91SAM9RL64:
151 at91_soc_initdata.type = AT91_SOC_SAM9RL;
152 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
153 at91_boot_soc = at91sam9rl_soc;
156 case ARCH_ID_AT91SAM9X5:
157 at91_soc_initdata.type = AT91_SOC_SAM9X5;
158 at91_boot_soc = at91sam9x5_soc;
161 case ARCH_ID_AT91SAM9N12:
162 at91_soc_initdata.type = AT91_SOC_SAM9N12;
163 at91_boot_soc = at91sam9n12_soc;
167 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
168 if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
169 at91_soc_initdata.type = AT91_SOC_SAMA5D3;
170 at91_boot_soc = sama5d3_soc;
176 if ((socid & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
177 at91_soc_initdata.type = AT91_SOC_SAM9G10;
178 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
179 at91_boot_soc = at91sam9261_soc;
182 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
183 at91_soc_initdata.type = AT91_SOC_SAM9260;
184 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
185 at91_boot_soc = at91sam9260_soc;
188 if (!at91_soc_is_detected())
191 at91_soc_initdata.cidr = cidr;
193 /* sub version of soc */
194 if (!at91_soc_initdata.exid)
195 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
197 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
198 switch (at91_soc_initdata.exid) {
199 case ARCH_EXID_AT91SAM9M10:
200 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
202 case ARCH_EXID_AT91SAM9G46:
203 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
205 case ARCH_EXID_AT91SAM9M11:
206 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
211 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
212 switch (at91_soc_initdata.exid) {
213 case ARCH_EXID_AT91SAM9G15:
214 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
216 case ARCH_EXID_AT91SAM9G35:
217 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
219 case ARCH_EXID_AT91SAM9X35:
220 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
222 case ARCH_EXID_AT91SAM9G25:
223 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
225 case ARCH_EXID_AT91SAM9X25:
226 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
231 if (at91_soc_initdata.type == AT91_SOC_SAMA5D3) {
232 switch (at91_soc_initdata.exid) {
233 case ARCH_EXID_SAMA5D31:
234 at91_soc_initdata.subtype = AT91_SOC_SAMA5D31;
236 case ARCH_EXID_SAMA5D33:
237 at91_soc_initdata.subtype = AT91_SOC_SAMA5D33;
239 case ARCH_EXID_SAMA5D34:
240 at91_soc_initdata.subtype = AT91_SOC_SAMA5D34;
242 case ARCH_EXID_SAMA5D35:
243 at91_soc_initdata.subtype = AT91_SOC_SAMA5D35;
245 case ARCH_EXID_SAMA5D36:
246 at91_soc_initdata.subtype = AT91_SOC_SAMA5D36;
252 static void __init alt_soc_detect(u32 dbgu_base)
257 cidr = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
258 socid = cidr & ~AT91_CIDR_VERSION;
262 at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
263 if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
264 at91_soc_initdata.type = AT91_SOC_SAMA5D3;
265 at91_boot_soc = sama5d3_soc;
266 } else if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D4) {
267 at91_soc_initdata.type = AT91_SOC_SAMA5D4;
268 at91_boot_soc = sama5d4_soc;
273 if (!at91_soc_is_detected())
276 at91_soc_initdata.cidr = cidr;
278 /* sub version of soc */
279 if (!at91_soc_initdata.exid)
280 at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
282 if (at91_soc_initdata.type == AT91_SOC_SAMA5D4) {
283 switch (at91_soc_initdata.exid) {
284 case ARCH_EXID_SAMA5D41:
285 at91_soc_initdata.subtype = AT91_SOC_SAMA5D41;
287 case ARCH_EXID_SAMA5D42:
288 at91_soc_initdata.subtype = AT91_SOC_SAMA5D42;
290 case ARCH_EXID_SAMA5D43:
291 at91_soc_initdata.subtype = AT91_SOC_SAMA5D43;
293 case ARCH_EXID_SAMA5D44:
294 at91_soc_initdata.subtype = AT91_SOC_SAMA5D44;
300 static const char *soc_name[] = {
301 [AT91_SOC_RM9200] = "at91rm9200",
302 [AT91_SOC_SAM9260] = "at91sam9260",
303 [AT91_SOC_SAM9261] = "at91sam9261",
304 [AT91_SOC_SAM9263] = "at91sam9263",
305 [AT91_SOC_SAM9G10] = "at91sam9g10",
306 [AT91_SOC_SAM9G20] = "at91sam9g20",
307 [AT91_SOC_SAM9G45] = "at91sam9g45",
308 [AT91_SOC_SAM9RL] = "at91sam9rl",
309 [AT91_SOC_SAM9X5] = "at91sam9x5",
310 [AT91_SOC_SAM9N12] = "at91sam9n12",
311 [AT91_SOC_SAMA5D3] = "sama5d3",
312 [AT91_SOC_SAMA5D4] = "sama5d4",
313 [AT91_SOC_UNKNOWN] = "Unknown",
316 const char *at91_get_soc_type(struct at91_socinfo *c)
318 return soc_name[c->type];
320 EXPORT_SYMBOL(at91_get_soc_type);
322 static const char *soc_subtype_name[] = {
323 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
324 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
325 [AT91_SOC_SAM9XE] = "at91sam9xe",
326 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
327 [AT91_SOC_SAM9M10] = "at91sam9m10",
328 [AT91_SOC_SAM9G46] = "at91sam9g46",
329 [AT91_SOC_SAM9M11] = "at91sam9m11",
330 [AT91_SOC_SAM9G15] = "at91sam9g15",
331 [AT91_SOC_SAM9G35] = "at91sam9g35",
332 [AT91_SOC_SAM9X35] = "at91sam9x35",
333 [AT91_SOC_SAM9G25] = "at91sam9g25",
334 [AT91_SOC_SAM9X25] = "at91sam9x25",
335 [AT91_SOC_SAMA5D31] = "sama5d31",
336 [AT91_SOC_SAMA5D33] = "sama5d33",
337 [AT91_SOC_SAMA5D34] = "sama5d34",
338 [AT91_SOC_SAMA5D35] = "sama5d35",
339 [AT91_SOC_SAMA5D36] = "sama5d36",
340 [AT91_SOC_SAMA5D41] = "sama5d41",
341 [AT91_SOC_SAMA5D42] = "sama5d42",
342 [AT91_SOC_SAMA5D43] = "sama5d43",
343 [AT91_SOC_SAMA5D44] = "sama5d44",
344 [AT91_SOC_SUBTYPE_NONE] = "None",
345 [AT91_SOC_SUBTYPE_UNKNOWN] = "Unknown",
348 const char *at91_get_soc_subtype(struct at91_socinfo *c)
350 return soc_subtype_name[c->subtype];
352 EXPORT_SYMBOL(at91_get_soc_subtype);
354 void __init at91_map_io(void)
356 /* Map peripherals */
357 iotable_init(&at91_io_desc, 1);
359 at91_soc_initdata.type = AT91_SOC_UNKNOWN;
360 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
362 soc_detect(AT91_BASE_DBGU0);
363 if (!at91_soc_is_detected())
364 soc_detect(AT91_BASE_DBGU1);
366 if (!at91_soc_is_detected())
367 panic(pr_fmt("Impossible to detect the SOC type"));
369 pr_info("Detected soc type: %s\n",
370 at91_get_soc_type(&at91_soc_initdata));
371 if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
372 pr_info("Detected soc subtype: %s\n",
373 at91_get_soc_subtype(&at91_soc_initdata));
375 if (!at91_soc_is_enabled())
376 panic(pr_fmt("Soc not enabled"));
378 if (at91_boot_soc.map_io)
379 at91_boot_soc.map_io();
382 void __init at91_alt_map_io(void)
384 /* Map peripherals */
385 iotable_init(&at91_alt_io_desc, 1);
387 at91_soc_initdata.type = AT91_SOC_UNKNOWN;
388 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
390 alt_soc_detect(AT91_BASE_DBGU2);
391 if (!at91_soc_is_detected())
392 panic("AT91: Impossible to detect the SOC type");
394 pr_info("AT91: Detected soc type: %s\n",
395 at91_get_soc_type(&at91_soc_initdata));
396 if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
397 pr_info("AT91: Detected soc subtype: %s\n",
398 at91_get_soc_subtype(&at91_soc_initdata));
400 if (!at91_soc_is_enabled())
401 panic("AT91: Soc not enabled");
403 if (at91_boot_soc.map_io)
404 at91_boot_soc.map_io();
407 void __iomem *at91_matrix_base;
408 EXPORT_SYMBOL_GPL(at91_matrix_base);
410 void __init at91_ioremap_matrix(u32 base_addr)
412 at91_matrix_base = ioremap(base_addr, 512);
413 if (!at91_matrix_base)
414 panic(pr_fmt("Impossible to ioremap at91_matrix_base\n"));
417 #if defined(CONFIG_OF)
418 static struct of_device_id ramc_ids[] = {
419 { .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby },
420 { .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby },
421 { .compatible = "atmel,at91sam9g45-ddramc", .data = at91_ddr_standby },
422 { .compatible = "atmel,sama5d3-ddramc", .data = at91_ddr_standby },
426 static void at91_dt_ramc(void)
428 struct device_node *np;
429 const struct of_device_id *of_id;
431 const void *standby = NULL;
433 for_each_matching_node_and_match(np, ramc_ids, &of_id) {
434 at91_ramc_base[idx] = of_iomap(np, 0);
435 if (!at91_ramc_base[idx])
436 panic(pr_fmt("unable to map ramc[%d] cpu registers\n"), idx);
439 standby = of_id->data;
445 panic(pr_fmt("unable to find compatible ram controller node in dtb\n"));
448 pr_warn("ramc no standby function available\n");
452 at91_pm_set_standby(standby);
455 void __init at91rm9200_dt_initialize(void)
459 /* Register the processor-specific clocks */
460 if (at91_boot_soc.register_clocks)
461 at91_boot_soc.register_clocks();
463 at91_boot_soc.init();
466 void __init at91_dt_initialize(void)
470 /* Register the processor-specific clocks */
471 if (at91_boot_soc.register_clocks)
472 at91_boot_soc.register_clocks();
474 if (at91_boot_soc.init)
475 at91_boot_soc.init();
479 void __init at91_initialize(unsigned long main_clock)
481 at91_boot_soc.ioremap_registers();
483 /* Register the processor-specific clocks */
484 at91_boot_soc.register_clocks();
486 at91_boot_soc.init();
488 pinctrl_provide_dummies();
491 void __init at91_register_devices(void)
493 at91_boot_soc.register_devices();
496 void __init at91_init_time(void)
498 at91_boot_soc.init_time();