blob: dc634ae2081f2d5bb86d7806b9d040fc88497fc0 [file] [log] [blame]
Maxime Ripard3b526342012-11-08 12:40:16 +01001/*
2 * Device Tree support for Allwinner A1X SoCs
3 *
4 * Copyright (C) 2012 Maxime Ripard
5 *
6 * Maxime Ripard <maxime.ripard@free-electrons.com>
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
Maxime Ripard67bea882012-11-19 18:57:08 +010015#include <linux/of_address.h>
Maxime Ripard3b526342012-11-08 12:40:16 +010016#include <linux/of_irq.h>
17#include <linux/of_platform.h>
18#include <linux/io.h>
19#include <linux/sunxi_timer.h>
20
21#include <linux/irqchip/sunxi.h>
22
23#include <asm/hardware/vic.h>
24
25#include <asm/mach/arch.h>
26#include <asm/mach/map.h>
27
28#include "sunxi.h"
29
Maxime Ripard67bea882012-11-19 18:57:08 +010030#define WATCHDOG_CTRL_REG 0x00
31#define WATCHDOG_MODE_REG 0x04
32
33static void __iomem *wdt_base;
34
35static void sunxi_setup_restart(void)
36{
37 struct device_node *np = of_find_compatible_node(NULL, NULL,
38 "allwinner,sunxi-wdt");
39 if (WARN(!np, "unable to setup watchdog restart"))
40 return;
41
42 wdt_base = of_iomap(np, 0);
43 WARN(!wdt_base, "failed to map watchdog base address");
44}
45
46static void sunxi_restart(char mode, const char *cmd)
47{
48 if (!wdt_base)
49 return;
50
51 /* Enable timer and set reset bit in the watchdog */
52 writel(3, wdt_base + WATCHDOG_MODE_REG);
53 writel(0xa57 << 1 | 1, wdt_base + WATCHDOG_CTRL_REG);
54 while(1) {
55 mdelay(5);
56 writel(3, wdt_base + WATCHDOG_MODE_REG);
57 }
58}
59
Maxime Ripard3b526342012-11-08 12:40:16 +010060static struct map_desc sunxi_io_desc[] __initdata = {
61 {
62 .virtual = (unsigned long) SUNXI_REGS_VIRT_BASE,
63 .pfn = __phys_to_pfn(SUNXI_REGS_PHYS_BASE),
64 .length = SUNXI_REGS_SIZE,
65 .type = MT_DEVICE,
66 },
67};
68
69void __init sunxi_map_io(void)
70{
71 iotable_init(sunxi_io_desc, ARRAY_SIZE(sunxi_io_desc));
72}
73
74static void __init sunxi_dt_init(void)
75{
Maxime Ripard67bea882012-11-19 18:57:08 +010076 sunxi_setup_restart();
77
Maxime Ripard3b526342012-11-08 12:40:16 +010078 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
79}
80
81static const char * const sunxi_board_dt_compat[] = {
Stefan Roesef055f1f2012-11-19 12:09:42 +010082 "allwinner,sun4i",
Maxime Ripard3b526342012-11-08 12:40:16 +010083 "allwinner,sun5i",
84 NULL,
85};
86
87DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
88 .init_machine = sunxi_dt_init,
89 .map_io = sunxi_map_io,
90 .init_irq = sunxi_init_irq,
91 .handle_irq = sunxi_handle_irq,
Maxime Ripard67bea882012-11-19 18:57:08 +010092 .restart = sunxi_restart,
Maxime Ripard3b526342012-11-08 12:40:16 +010093 .timer = &sunxi_timer,
94 .dt_compat = sunxi_board_dt_compat,
95MACHINE_END