0ff310eecdfdcfcc1ea3c695cebc76871c097877
[firefly-linux-kernel-4.4.55.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/delay.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/of_address.h>
17 #include <linux/of_irq.h>
18 #include <linux/of_platform.h>
19 #include <linux/io.h>
20 #include <linux/sunxi_timer.h>
21
22 #include <linux/irqchip/sunxi.h>
23
24 #include <asm/mach/arch.h>
25 #include <asm/mach/map.h>
26
27 #include "sunxi.h"
28
29 #define WATCHDOG_CTRL_REG       0x00
30 #define WATCHDOG_MODE_REG       0x04
31
32 static void __iomem *wdt_base;
33
34 static void sunxi_setup_restart(void)
35 {
36         struct device_node *np = of_find_compatible_node(NULL, NULL,
37                                                 "allwinner,sunxi-wdt");
38         if (WARN(!np, "unable to setup watchdog restart"))
39                 return;
40
41         wdt_base = of_iomap(np, 0);
42         WARN(!wdt_base, "failed to map watchdog base address");
43 }
44
45 static void sunxi_restart(char mode, const char *cmd)
46 {
47         if (!wdt_base)
48                 return;
49
50         /* Enable timer and set reset bit in the watchdog */
51         writel(3, wdt_base + WATCHDOG_MODE_REG);
52         writel(0xa57 << 1 | 1, wdt_base + WATCHDOG_CTRL_REG);
53         while(1) {
54                 mdelay(5);
55                 writel(3, wdt_base + WATCHDOG_MODE_REG);
56         }
57 }
58
59 static struct map_desc sunxi_io_desc[] __initdata = {
60         {
61                 .virtual        = (unsigned long) SUNXI_REGS_VIRT_BASE,
62                 .pfn            = __phys_to_pfn(SUNXI_REGS_PHYS_BASE),
63                 .length         = SUNXI_REGS_SIZE,
64                 .type           = MT_DEVICE,
65         },
66 };
67
68 void __init sunxi_map_io(void)
69 {
70         iotable_init(sunxi_io_desc, ARRAY_SIZE(sunxi_io_desc));
71 }
72
73 static void __init sunxi_dt_init(void)
74 {
75         sunxi_setup_restart();
76
77         of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
78 }
79
80 static const char * const sunxi_board_dt_compat[] = {
81         "allwinner,sun4i-a10",
82         "allwinner,sun5i-a13",
83         NULL,
84 };
85
86 DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
87         .init_machine   = sunxi_dt_init,
88         .map_io         = sunxi_map_io,
89         .init_irq       = sunxi_init_irq,
90         .handle_irq     = sunxi_handle_irq,
91         .restart        = sunxi_restart,
92         .timer          = &sunxi_timer,
93         .dt_compat      = sunxi_board_dt_compat,
94 MACHINE_END