diff options
Diffstat (limited to 'arch/arm/mach-at91/setup.c')
-rw-r--r-- | arch/arm/mach-at91/setup.c | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c index 372396c2ecb6..1083739e3065 100644 --- a/arch/arm/mach-at91/setup.c +++ b/arch/arm/mach-at91/setup.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/io.h> | 9 | #include <linux/io.h> |
10 | #include <linux/mm.h> | 10 | #include <linux/mm.h> |
11 | #include <linux/pm.h> | 11 | #include <linux/pm.h> |
12 | #include <linux/of_address.h> | ||
12 | 13 | ||
13 | #include <asm/mach/map.h> | 14 | #include <asm/mach/map.h> |
14 | 15 | ||
@@ -51,6 +52,19 @@ void __init at91_init_interrupts(unsigned int *priority) | |||
51 | at91_gpio_irq_setup(); | 52 | at91_gpio_irq_setup(); |
52 | } | 53 | } |
53 | 54 | ||
55 | void __iomem *at91_ramc_base[2]; | ||
56 | |||
57 | void __init at91_ioremap_ramc(int id, u32 addr, u32 size) | ||
58 | { | ||
59 | if (id < 0 || id > 1) { | ||
60 | pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id); | ||
61 | BUG(); | ||
62 | } | ||
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); | ||
66 | } | ||
67 | |||
54 | static struct map_desc sram_desc[2] __initdata; | 68 | static struct map_desc sram_desc[2] __initdata; |
55 | 69 | ||
56 | void __init at91_init_sram(int bank, unsigned long base, unsigned int length) | 70 | void __init at91_init_sram(int bank, unsigned long base, unsigned int length) |
@@ -285,6 +299,150 @@ void __init at91_ioremap_matrix(u32 base_addr) | |||
285 | panic("Impossible to ioremap at91_matrix_base\n"); | 299 | panic("Impossible to ioremap at91_matrix_base\n"); |
286 | } | 300 | } |
287 | 301 | ||
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 }, | ||
306 | { /*sentinel*/ } | ||
307 | }; | ||
308 | |||
309 | static void at91_dt_rstc(void) | ||
310 | { | ||
311 | struct device_node *np; | ||
312 | const struct of_device_id *of_id; | ||
313 | |||
314 | np = of_find_matching_node(NULL, rstc_ids); | ||
315 | if (!np) | ||
316 | panic("unable to find compatible rstc node in dtb\n"); | ||
317 | |||
318 | at91_rstc_base = of_iomap(np, 0); | ||
319 | if (!at91_rstc_base) | ||
320 | panic("unable to map rstc cpu registers\n"); | ||
321 | |||
322 | of_id = of_match_node(rstc_ids, np); | ||
323 | if (!of_id) | ||
324 | panic("AT91: rtsc no restart function availlable\n"); | ||
325 | |||
326 | arm_pm_restart = of_id->data; | ||
327 | |||
328 | of_node_put(np); | ||
329 | } | ||
330 | |||
331 | static struct of_device_id ramc_ids[] = { | ||
332 | { .compatible = "atmel,at91sam9260-sdramc" }, | ||
333 | { .compatible = "atmel,at91sam9g45-ddramc" }, | ||
334 | { /*sentinel*/ } | ||
335 | }; | ||
336 | |||
337 | static void at91_dt_ramc(void) | ||
338 | { | ||
339 | struct device_node *np; | ||
340 | |||
341 | np = of_find_matching_node(NULL, ramc_ids); | ||
342 | if (!np) | ||
343 | panic("unable to find compatible ram conroller node in dtb\n"); | ||
344 | |||
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); | ||
350 | |||
351 | of_node_put(np); | ||
352 | } | ||
353 | |||
354 | static struct of_device_id shdwc_ids[] = { | ||
355 | { .compatible = "atmel,at91sam9260-shdwc", }, | ||
356 | { .compatible = "atmel,at91sam9rl-shdwc", }, | ||
357 | { .compatible = "atmel,at91sam9x5-shdwc", }, | ||
358 | { /*sentinel*/ } | ||
359 | }; | ||
360 | |||
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", | ||
366 | }; | ||
367 | |||
368 | const int at91_dtget_shdwc_wakeup_mode(struct device_node *np) | ||
369 | { | ||
370 | const char *pm; | ||
371 | int err, i; | ||
372 | |||
373 | err = of_property_read_string(np, "atmel,wakeup-mode", &pm); | ||
374 | if (err < 0) | ||
375 | return AT91_SHDW_WKMODE0_ANYLEVEL; | ||
376 | |||
377 | for (i = 0; i < ARRAY_SIZE(shdwc_wakeup_modes); i++) | ||
378 | if (!strcasecmp(pm, shdwc_wakeup_modes[i])) | ||
379 | return i; | ||
380 | |||
381 | return -ENODEV; | ||
382 | } | ||
383 | |||
384 | static void at91_dt_shdwc(void) | ||
385 | { | ||
386 | struct device_node *np; | ||
387 | int wakeup_mode; | ||
388 | u32 reg; | ||
389 | u32 mode = 0; | ||
390 | |||
391 | np = of_find_matching_node(NULL, shdwc_ids); | ||
392 | if (!np) { | ||
393 | pr_debug("AT91: unable to find compatible shutdown (shdwc) conroller node in dtb\n"); | ||
394 | return; | ||
395 | } | ||
396 | |||
397 | at91_shdwc_base = of_iomap(np, 0); | ||
398 | if (!at91_shdwc_base) | ||
399 | panic("AT91: unable to map shdwc cpu registers\n"); | ||
400 | |||
401 | wakeup_mode = at91_dtget_shdwc_wakeup_mode(np); | ||
402 | if (wakeup_mode < 0) { | ||
403 | pr_warn("AT91: shdwc unknown wakeup mode\n"); | ||
404 | goto end; | ||
405 | } | ||
406 | |||
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; | ||
412 | } | ||
413 | mode |= AT91_SHDW_CPTWK0_(reg); | ||
414 | } | ||
415 | |||
416 | if (of_property_read_bool(np, "atmel,wakeup-rtc-timer")) | ||
417 | mode |= AT91_SHDW_RTCWKEN; | ||
418 | |||
419 | if (of_property_read_bool(np, "atmel,wakeup-rtt-timer")) | ||
420 | mode |= AT91_SHDW_RTTWKEN; | ||
421 | |||
422 | at91_shdwc_write(AT91_SHDW_MR, wakeup_mode | mode); | ||
423 | |||
424 | end: | ||
425 | pm_power_off = at91sam9_poweroff; | ||
426 | |||
427 | of_node_put(np); | ||
428 | } | ||
429 | |||
430 | void __init at91_dt_initialize(void) | ||
431 | { | ||
432 | at91_dt_rstc(); | ||
433 | at91_dt_ramc(); | ||
434 | at91_dt_shdwc(); | ||
435 | |||
436 | /* Init clock subsystem */ | ||
437 | at91_dt_clock_init(); | ||
438 | |||
439 | /* Register the processor-specific clocks */ | ||
440 | at91_boot_soc.register_clocks(); | ||
441 | |||
442 | at91_boot_soc.init(); | ||
443 | } | ||
444 | #endif | ||
445 | |||
288 | void __init at91_initialize(unsigned long main_clock) | 446 | void __init at91_initialize(unsigned long main_clock) |
289 | { | 447 | { |
290 | at91_boot_soc.ioremap_registers(); | 448 | at91_boot_soc.ioremap_registers(); |