Merge tag 'soc-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[cascardo/linux.git] / arch / arm / mach-sunxi / sunxi.c
1 /*
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/clocksource.h>
14 #include <linux/delay.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/of_address.h>
18 #include <linux/of_irq.h>
19 #include <linux/of_platform.h>
20 #include <linux/io.h>
21
22 #include <linux/clk/sunxi.h>
23
24 #include <asm/mach/arch.h>
25 #include <asm/mach/map.h>
26 #include <asm/system_misc.h>
27
28 #define SUN4I_WATCHDOG_CTRL_REG         0x00
29 #define SUN4I_WATCHDOG_CTRL_RESTART             (1 << 0)
30 #define SUN4I_WATCHDOG_MODE_REG         0x04
31 #define SUN4I_WATCHDOG_MODE_ENABLE              (1 << 0)
32 #define SUN4I_WATCHDOG_MODE_RESET_ENABLE        (1 << 1)
33
34 static void __iomem *wdt_base;
35
36 static void sun4i_restart(char mode, const char *cmd)
37 {
38         if (!wdt_base)
39                 return;
40
41         /* Enable timer and set reset bit in the watchdog */
42         writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
43                wdt_base + SUN4I_WATCHDOG_MODE_REG);
44
45         /*
46          * Restart the watchdog. The default (and lowest) interval
47          * value for the watchdog is 0.5s.
48          */
49         writel(SUN4I_WATCHDOG_CTRL_RESTART, wdt_base + SUN4I_WATCHDOG_CTRL_REG);
50
51         while (1) {
52                 mdelay(5);
53                 writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
54                        wdt_base + SUN4I_WATCHDOG_MODE_REG);
55         }
56 }
57
58 static struct of_device_id sunxi_restart_ids[] = {
59         { .compatible = "allwinner,sun4i-wdt", .data = sun4i_restart },
60         { /*sentinel*/ }
61 };
62
63 static void sunxi_setup_restart(void)
64 {
65         const struct of_device_id *of_id;
66         struct device_node *np;
67
68         np = of_find_matching_node(NULL, sunxi_restart_ids);
69         if (WARN(!np, "unable to setup watchdog restart"))
70                 return;
71
72         wdt_base = of_iomap(np, 0);
73         WARN(!wdt_base, "failed to map watchdog base address");
74
75         of_id = of_match_node(sunxi_restart_ids, np);
76         WARN(!of_id, "restart function not available");
77
78         arm_pm_restart = of_id->data;
79 }
80
81 static void __init sunxi_timer_init(void)
82 {
83         sunxi_init_clocks();
84         clocksource_of_init();
85 }
86
87 static void __init sunxi_dt_init(void)
88 {
89         sunxi_setup_restart();
90
91         of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
92 }
93
94 static const char * const sunxi_board_dt_compat[] = {
95         "allwinner,sun4i-a10",
96         "allwinner,sun5i-a10s",
97         "allwinner,sun5i-a13",
98         NULL,
99 };
100
101 DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
102         .init_machine   = sunxi_dt_init,
103         .init_time      = sunxi_timer_init,
104         .dt_compat      = sunxi_board_dt_compat,
105 MACHINE_END