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>
14 #include <asm/mach/map.h>
16 #include <mach/hardware.h>
18 #include <mach/at91_dbgu.h>
19 #include <mach/at91_pmc.h>
20 #include <mach/at91_shdwc.h>
25 struct at91_init_soc __initdata at91_boot_soc;
27 struct at91_socinfo at91_soc_initdata;
28 EXPORT_SYMBOL(at91_soc_initdata);
30 void __init at91rm9200_set_type(int type)
32 if (type == ARCH_REVISON_9200_PQFP)
33 at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
35 at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
37 pr_info("AT91: filled in soc subtype: %s\n",
38 at91_get_soc_subtype(&at91_soc_initdata));
41 void __init at91_init_irq_default(void)
43 at91_init_interrupts(at91_boot_soc.default_irq_priority);
46 void __init at91_init_interrupts(unsigned int *priority)
48 /* Initialize the AIC interrupt controller */
49 at91_aic_init(priority);
51 /* Enable GPIO interrupts */
52 at91_gpio_irq_setup();
55 void __iomem *at91_ramc_base[2];
57 void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
59 if (id < 0 || id > 1) {
60 pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
63 at91_ramc_base[id] = ioremap(addr, size);
64 if (!at91_ramc_base[id])
65 panic("Impossible to ioremap ramc.%d 0x%x\n", id, addr);
68 static struct map_desc sram_desc[2] __initdata;
70 void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
72 struct map_desc *desc = &sram_desc[bank];
74 desc->virtual = AT91_IO_VIRT_BASE - length;
76 desc->virtual -= sram_desc[bank - 1].length;
78 desc->pfn = __phys_to_pfn(base);
79 desc->length = length;
80 desc->type = MT_DEVICE;
82 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
83 base, length, desc->virtual);
85 iotable_init(desc, 1);
88 static struct map_desc at91_io_desc __initdata = {
89 .virtual = AT91_VA_BASE_SYS,
90 .pfn = __phys_to_pfn(AT91_BASE_SYS),
95 static void __init soc_detect(u32 dbgu_base)
99 cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
100 socid = cidr & ~AT91_CIDR_VERSION;
103 case ARCH_ID_AT91RM9200:
104 at91_soc_initdata.type = AT91_SOC_RM9200;
105 at91_boot_soc = at91rm9200_soc;
108 case ARCH_ID_AT91SAM9260:
109 at91_soc_initdata.type = AT91_SOC_SAM9260;
110 at91_boot_soc = at91sam9260_soc;
113 case ARCH_ID_AT91SAM9261:
114 at91_soc_initdata.type = AT91_SOC_SAM9261;
115 at91_boot_soc = at91sam9261_soc;
118 case ARCH_ID_AT91SAM9263:
119 at91_soc_initdata.type = AT91_SOC_SAM9263;
120 at91_boot_soc = at91sam9263_soc;
123 case ARCH_ID_AT91SAM9G20:
124 at91_soc_initdata.type = AT91_SOC_SAM9G20;
125 at91_boot_soc = at91sam9260_soc;
128 case ARCH_ID_AT91SAM9G45:
129 at91_soc_initdata.type = AT91_SOC_SAM9G45;
130 if (cidr == ARCH_ID_AT91SAM9G45ES)
131 at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
132 at91_boot_soc = at91sam9g45_soc;
135 case ARCH_ID_AT91SAM9RL64:
136 at91_soc_initdata.type = AT91_SOC_SAM9RL;
137 at91_boot_soc = at91sam9rl_soc;
140 case ARCH_ID_AT91SAM9X5:
141 at91_soc_initdata.type = AT91_SOC_SAM9X5;
142 at91_boot_soc = at91sam9x5_soc;
147 if ((cidr & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
148 at91_soc_initdata.type = AT91_SOC_SAM9G10;
149 at91_boot_soc = at91sam9261_soc;
152 else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
153 at91_soc_initdata.type = AT91_SOC_SAM9260;
154 at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
155 at91_boot_soc = at91sam9260_soc;
158 if (!at91_soc_is_detected())
161 at91_soc_initdata.cidr = cidr;
163 /* sub version of soc */
164 at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
166 if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
167 switch (at91_soc_initdata.exid) {
168 case ARCH_EXID_AT91SAM9M10:
169 at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
171 case ARCH_EXID_AT91SAM9G46:
172 at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
174 case ARCH_EXID_AT91SAM9M11:
175 at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
180 if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
181 switch (at91_soc_initdata.exid) {
182 case ARCH_EXID_AT91SAM9G15:
183 at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
185 case ARCH_EXID_AT91SAM9G35:
186 at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
188 case ARCH_EXID_AT91SAM9X35:
189 at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
191 case ARCH_EXID_AT91SAM9G25:
192 at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
194 case ARCH_EXID_AT91SAM9X25:
195 at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
201 static const char *soc_name[] = {
202 [AT91_SOC_RM9200] = "at91rm9200",
203 [AT91_SOC_SAM9260] = "at91sam9260",
204 [AT91_SOC_SAM9261] = "at91sam9261",
205 [AT91_SOC_SAM9263] = "at91sam9263",
206 [AT91_SOC_SAM9G10] = "at91sam9g10",
207 [AT91_SOC_SAM9G20] = "at91sam9g20",
208 [AT91_SOC_SAM9G45] = "at91sam9g45",
209 [AT91_SOC_SAM9RL] = "at91sam9rl",
210 [AT91_SOC_SAM9X5] = "at91sam9x5",
211 [AT91_SOC_NONE] = "Unknown"
214 const char *at91_get_soc_type(struct at91_socinfo *c)
216 return soc_name[c->type];
218 EXPORT_SYMBOL(at91_get_soc_type);
220 static const char *soc_subtype_name[] = {
221 [AT91_SOC_RM9200_BGA] = "at91rm9200 BGA",
222 [AT91_SOC_RM9200_PQFP] = "at91rm9200 PQFP",
223 [AT91_SOC_SAM9XE] = "at91sam9xe",
224 [AT91_SOC_SAM9G45ES] = "at91sam9g45es",
225 [AT91_SOC_SAM9M10] = "at91sam9m10",
226 [AT91_SOC_SAM9G46] = "at91sam9g46",
227 [AT91_SOC_SAM9M11] = "at91sam9m11",
228 [AT91_SOC_SAM9G15] = "at91sam9g15",
229 [AT91_SOC_SAM9G35] = "at91sam9g35",
230 [AT91_SOC_SAM9X35] = "at91sam9x35",
231 [AT91_SOC_SAM9G25] = "at91sam9g25",
232 [AT91_SOC_SAM9X25] = "at91sam9x25",
233 [AT91_SOC_SUBTYPE_NONE] = "Unknown"
236 const char *at91_get_soc_subtype(struct at91_socinfo *c)
238 return soc_subtype_name[c->subtype];
240 EXPORT_SYMBOL(at91_get_soc_subtype);
242 void __init at91_map_io(void)
244 /* Map peripherals */
245 iotable_init(&at91_io_desc, 1);
247 at91_soc_initdata.type = AT91_SOC_NONE;
248 at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
250 soc_detect(AT91_BASE_DBGU0);
251 if (!at91_soc_is_detected())
252 soc_detect(AT91_BASE_DBGU1);
254 if (!at91_soc_is_detected())
255 panic("AT91: Impossible to detect the SOC type");
257 pr_info("AT91: Detected soc type: %s\n",
258 at91_get_soc_type(&at91_soc_initdata));
259 pr_info("AT91: Detected soc subtype: %s\n",
260 at91_get_soc_subtype(&at91_soc_initdata));
262 if (!at91_soc_is_enabled())
263 panic("AT91: Soc not enabled");
265 if (at91_boot_soc.map_io)
266 at91_boot_soc.map_io();
269 void __iomem *at91_shdwc_base = NULL;
271 static void at91sam9_poweroff(void)
273 at91_shdwc_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
276 void __init at91_ioremap_shdwc(u32 base_addr)
278 at91_shdwc_base = ioremap(base_addr, 16);
279 if (!at91_shdwc_base)
280 panic("Impossible to ioremap at91_shdwc_base\n");
281 pm_power_off = at91sam9_poweroff;
284 void __iomem *at91_rstc_base;
286 void __init at91_ioremap_rstc(u32 base_addr)
288 at91_rstc_base = ioremap(base_addr, 16);
290 panic("Impossible to ioremap at91_rstc_base\n");
293 void __iomem *at91_matrix_base;
295 void __init at91_ioremap_matrix(u32 base_addr)
297 at91_matrix_base = ioremap(base_addr, 512);
298 if (!at91_matrix_base)
299 panic("Impossible to ioremap at91_matrix_base\n");
302 #if defined(CONFIG_OF)
303 static struct of_device_id rstc_ids[] = {
304 { .compatible = "atmel,at91sam9260-rstc", .data = at91sam9_alt_restart },
305 { .compatible = "atmel,at91sam9g45-rstc", .data = at91sam9g45_restart },
309 static void at91_dt_rstc(void)
311 struct device_node *np;
312 const struct of_device_id *of_id;
314 np = of_find_matching_node(NULL, rstc_ids);
316 panic("unable to find compatible rstc node in dtb\n");
318 at91_rstc_base = of_iomap(np, 0);
320 panic("unable to map rstc cpu registers\n");
322 of_id = of_match_node(rstc_ids, np);
324 panic("AT91: rtsc no restart function availlable\n");
326 arm_pm_restart = of_id->data;
331 static struct of_device_id ramc_ids[] = {
332 { .compatible = "atmel,at91sam9260-sdramc" },
333 { .compatible = "atmel,at91sam9g45-ddramc" },
337 static void at91_dt_ramc(void)
339 struct device_node *np;
341 np = of_find_matching_node(NULL, ramc_ids);
343 panic("unable to find compatible ram conroller node in dtb\n");
345 at91_ramc_base[0] = of_iomap(np, 0);
346 if (!at91_ramc_base[0])
347 panic("unable to map ramc[0] cpu registers\n");
348 /* the controller may have 2 banks */
349 at91_ramc_base[1] = of_iomap(np, 1);
354 static struct of_device_id shdwc_ids[] = {
355 { .compatible = "atmel,at91sam9260-shdwc", },
356 { .compatible = "atmel,at91sam9rl-shdwc", },
357 { .compatible = "atmel,at91sam9x5-shdwc", },
361 static const char *shdwc_wakeup_modes[] = {
362 [AT91_SHDW_WKMODE0_NONE] = "none",
363 [AT91_SHDW_WKMODE0_HIGH] = "high",
364 [AT91_SHDW_WKMODE0_LOW] = "low",
365 [AT91_SHDW_WKMODE0_ANYLEVEL] = "any",
368 const int at91_dtget_shdwc_wakeup_mode(struct device_node *np)
373 err = of_property_read_string(np, "atmel,wakeup-mode", &pm);
375 return AT91_SHDW_WKMODE0_ANYLEVEL;
377 for (i = 0; i < ARRAY_SIZE(shdwc_wakeup_modes); i++)
378 if (!strcasecmp(pm, shdwc_wakeup_modes[i]))
384 static void at91_dt_shdwc(void)
386 struct device_node *np;
391 np = of_find_matching_node(NULL, shdwc_ids);
393 pr_debug("AT91: unable to find compatible shutdown (shdwc) conroller node in dtb\n");
397 at91_shdwc_base = of_iomap(np, 0);
398 if (!at91_shdwc_base)
399 panic("AT91: unable to map shdwc cpu registers\n");
401 wakeup_mode = at91_dtget_shdwc_wakeup_mode(np);
402 if (wakeup_mode < 0) {
403 pr_warn("AT91: shdwc unknown wakeup mode\n");
407 if (!of_property_read_u32(np, "atmel,wakeup-counter", ®)) {
408 if (reg > AT91_SHDW_CPTWK0_MAX) {
409 pr_warn("AT91: shdwc wakeup conter 0x%x > 0x%x reduce it to 0x%x\n",
410 reg, AT91_SHDW_CPTWK0_MAX, AT91_SHDW_CPTWK0_MAX);
411 reg = AT91_SHDW_CPTWK0_MAX;
413 mode |= AT91_SHDW_CPTWK0_(reg);
416 if (of_property_read_bool(np, "atmel,wakeup-rtc-timer"))
417 mode |= AT91_SHDW_RTCWKEN;
419 if (of_property_read_bool(np, "atmel,wakeup-rtt-timer"))
420 mode |= AT91_SHDW_RTTWKEN;
422 at91_shdwc_write(AT91_SHDW_MR, wakeup_mode | mode);
425 pm_power_off = at91sam9_poweroff;
430 void __init at91_dt_initialize(void)
436 /* Init clock subsystem */
437 at91_dt_clock_init();
439 /* Register the processor-specific clocks */
440 at91_boot_soc.register_clocks();
442 at91_boot_soc.init();
446 void __init at91_initialize(unsigned long main_clock)
448 at91_boot_soc.ioremap_registers();
450 /* Init clock subsystem */
451 at91_clock_init(main_clock);
453 /* Register the processor-specific clocks */
454 at91_boot_soc.register_clocks();
456 at91_boot_soc.init();