ARM: sunxi: irqchip: Update the documentation
[deliverable/linux.git] / arch / arm / mach-sunxi / sunxi.c
CommitLineData
3b52634f
MR
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
ea71d9a6 13#include <linux/clocksource.h>
5e51651d 14#include <linux/delay.h>
3b52634f
MR
15#include <linux/kernel.h>
16#include <linux/init.h>
67bea88d 17#include <linux/of_address.h>
3b52634f
MR
18#include <linux/of_irq.h>
19#include <linux/of_platform.h>
20#include <linux/io.h>
3b52634f 21
ea71d9a6 22#include <linux/clk/sunxi.h>
3b52634f 23
3b52634f
MR
24#include <asm/mach/arch.h>
25#include <asm/mach/map.h>
bc34b5f2 26#include <asm/system_misc.h>
3b52634f
MR
27
28#include "sunxi.h"
29
bc34b5f2
MR
30#define SUN4I_WATCHDOG_CTRL_REG 0x00
31#define SUN4I_WATCHDOG_CTRL_RESTART (1 << 0)
32#define SUN4I_WATCHDOG_MODE_REG 0x04
33#define SUN4I_WATCHDOG_MODE_ENABLE (1 << 0)
34#define SUN4I_WATCHDOG_MODE_RESET_ENABLE (1 << 1)
67bea88d
MR
35
36static void __iomem *wdt_base;
37
bc34b5f2 38static void sun4i_restart(char mode, const char *cmd)
67bea88d
MR
39{
40 if (!wdt_base)
41 return;
42
43 /* Enable timer and set reset bit in the watchdog */
bc34b5f2
MR
44 writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
45 wdt_base + SUN4I_WATCHDOG_MODE_REG);
b60decad
MR
46
47 /*
48 * Restart the watchdog. The default (and lowest) interval
49 * value for the watchdog is 0.5s.
50 */
bc34b5f2 51 writel(SUN4I_WATCHDOG_CTRL_RESTART, wdt_base + SUN4I_WATCHDOG_CTRL_REG);
b60decad
MR
52
53 while (1) {
67bea88d 54 mdelay(5);
bc34b5f2
MR
55 writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
56 wdt_base + SUN4I_WATCHDOG_MODE_REG);
67bea88d
MR
57 }
58}
59
bc34b5f2
MR
60static struct of_device_id sunxi_restart_ids[] = {
61 { .compatible = "allwinner,sun4i-wdt", .data = sun4i_restart },
62 { /*sentinel*/ }
63};
64
65static void sunxi_setup_restart(void)
66{
67 const struct of_device_id *of_id;
68 struct device_node *np;
69
70 np = of_find_matching_node(NULL, sunxi_restart_ids);
71 if (WARN(!np, "unable to setup watchdog restart"))
72 return;
73
74 wdt_base = of_iomap(np, 0);
75 WARN(!wdt_base, "failed to map watchdog base address");
76
77 of_id = of_match_node(sunxi_restart_ids, np);
78 WARN(!of_id, "restart function not available");
79
80 arm_pm_restart = of_id->data;
81}
82
3b52634f
MR
83static struct map_desc sunxi_io_desc[] __initdata = {
84 {
85 .virtual = (unsigned long) SUNXI_REGS_VIRT_BASE,
86 .pfn = __phys_to_pfn(SUNXI_REGS_PHYS_BASE),
87 .length = SUNXI_REGS_SIZE,
88 .type = MT_DEVICE,
89 },
90};
91
92void __init sunxi_map_io(void)
93{
94 iotable_init(sunxi_io_desc, ARRAY_SIZE(sunxi_io_desc));
95}
96
ea71d9a6
MR
97static void __init sunxi_timer_init(void)
98{
99 sunxi_init_clocks();
100 clocksource_of_init();
101}
102
3b52634f
MR
103static void __init sunxi_dt_init(void)
104{
67bea88d
MR
105 sunxi_setup_restart();
106
3b52634f
MR
107 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
108}
109
110static const char * const sunxi_board_dt_compat[] = {
43880f70
MR
111 "allwinner,sun4i-a10",
112 "allwinner,sun5i-a13",
3b52634f
MR
113 NULL,
114};
115
116DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
117 .init_machine = sunxi_dt_init,
118 .map_io = sunxi_map_io,
ea71d9a6 119 .init_time = sunxi_timer_init,
3b52634f
MR
120 .dt_compat = sunxi_board_dt_compat,
121MACHINE_END
This page took 0.04706 seconds and 5 git commands to generate.