Commit | Line | Data |
---|---|---|
ec9653b8 SA |
1 | /* |
2 | * Copyright (C) 2010 Broadcom | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | */ | |
14 | ||
d0f1c7ff | 15 | #include <linux/delay.h> |
ec9653b8 | 16 | #include <linux/init.h> |
89214f00 | 17 | #include <linux/irqchip/bcm2835.h> |
d0f1c7ff | 18 | #include <linux/of_address.h> |
ec9653b8 | 19 | #include <linux/of_platform.h> |
75fabc3f | 20 | #include <linux/clk/bcm2835.h> |
c1b724f6 | 21 | #include <linux/clocksource.h> |
ec9653b8 SA |
22 | |
23 | #include <asm/mach/arch.h> | |
24 | #include <asm/mach/map.h> | |
ec9653b8 | 25 | |
d0f1c7ff | 26 | #define PM_RSTC 0x1c |
45e9d77a | 27 | #define PM_RSTS 0x20 |
d0f1c7ff SW |
28 | #define PM_WDOG 0x24 |
29 | ||
30 | #define PM_PASSWORD 0x5a000000 | |
31 | #define PM_RSTC_WRCFG_MASK 0x00000030 | |
32 | #define PM_RSTC_WRCFG_FULL_RESET 0x00000020 | |
45e9d77a | 33 | #define PM_RSTS_HADWRH_SET 0x00000040 |
d0f1c7ff | 34 | |
f1ac922d SW |
35 | #define BCM2835_PERIPH_PHYS 0x20000000 |
36 | #define BCM2835_PERIPH_VIRT 0xf0000000 | |
37 | #define BCM2835_PERIPH_SIZE SZ_16M | |
38 | ||
d0f1c7ff SW |
39 | static void __iomem *wdt_regs; |
40 | ||
41 | /* | |
42 | * The machine restart method can be called from an atomic context so we won't | |
43 | * be able to ioremap the regs then. | |
44 | */ | |
45 | static void bcm2835_setup_restart(void) | |
46 | { | |
47 | struct device_node *np = of_find_compatible_node(NULL, NULL, | |
48 | "brcm,bcm2835-pm-wdt"); | |
49 | if (WARN(!np, "unable to setup watchdog restart")) | |
50 | return; | |
51 | ||
52 | wdt_regs = of_iomap(np, 0); | |
53 | WARN(!wdt_regs, "failed to remap watchdog regs"); | |
54 | } | |
55 | ||
56 | static void bcm2835_restart(char mode, const char *cmd) | |
57 | { | |
58 | u32 val; | |
59 | ||
60 | if (!wdt_regs) | |
61 | return; | |
62 | ||
63 | /* use a timeout of 10 ticks (~150us) */ | |
64 | writel_relaxed(10 | PM_PASSWORD, wdt_regs + PM_WDOG); | |
65 | val = readl_relaxed(wdt_regs + PM_RSTC); | |
66 | val &= ~PM_RSTC_WRCFG_MASK; | |
67 | val |= PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET; | |
68 | writel_relaxed(val, wdt_regs + PM_RSTC); | |
69 | ||
70 | /* No sleeping, possibly atomic. */ | |
71 | mdelay(1); | |
72 | } | |
73 | ||
45e9d77a DC |
74 | /* |
75 | * We can't really power off, but if we do the normal reset scheme, and | |
76 | * indicate to bootcode.bin not to reboot, then most of the chip will be | |
77 | * powered off. | |
78 | */ | |
79 | static void bcm2835_power_off(void) | |
80 | { | |
81 | u32 val; | |
82 | ||
83 | /* | |
84 | * We set the watchdog hard reset bit here to distinguish this reset | |
85 | * from the normal (full) reset. bootcode.bin will not reboot after a | |
86 | * hard reset. | |
87 | */ | |
88 | val = readl_relaxed(wdt_regs + PM_RSTS); | |
89 | val &= ~PM_RSTC_WRCFG_MASK; | |
90 | val |= PM_PASSWORD | PM_RSTS_HADWRH_SET; | |
91 | writel_relaxed(val, wdt_regs + PM_RSTS); | |
92 | ||
93 | /* Continue with normal reset mechanism */ | |
94 | bcm2835_restart(0, ""); | |
95 | } | |
96 | ||
ec9653b8 SA |
97 | static struct map_desc io_map __initdata = { |
98 | .virtual = BCM2835_PERIPH_VIRT, | |
99 | .pfn = __phys_to_pfn(BCM2835_PERIPH_PHYS), | |
100 | .length = BCM2835_PERIPH_SIZE, | |
101 | .type = MT_DEVICE | |
102 | }; | |
103 | ||
dd3c7548 | 104 | static void __init bcm2835_map_io(void) |
ec9653b8 SA |
105 | { |
106 | iotable_init(&io_map, 1); | |
107 | } | |
108 | ||
dd3c7548 | 109 | static void __init bcm2835_init(void) |
ec9653b8 SA |
110 | { |
111 | int ret; | |
112 | ||
d0f1c7ff | 113 | bcm2835_setup_restart(); |
45e9d77a DC |
114 | if (wdt_regs) |
115 | pm_power_off = bcm2835_power_off; | |
116 | ||
75fabc3f SA |
117 | bcm2835_init_clocks(); |
118 | ||
ec9653b8 SA |
119 | ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, |
120 | NULL); | |
121 | if (ret) { | |
122 | pr_err("of_platform_populate failed: %d\n", ret); | |
123 | BUG(); | |
124 | } | |
125 | } | |
126 | ||
ec9653b8 SA |
127 | static const char * const bcm2835_compat[] = { |
128 | "brcm,bcm2835", | |
129 | NULL | |
130 | }; | |
131 | ||
132 | DT_MACHINE_START(BCM2835, "BCM2835") | |
133 | .map_io = bcm2835_map_io, | |
134 | .init_irq = bcm2835_init_irq, | |
135 | .handle_irq = bcm2835_handle_irq, | |
136 | .init_machine = bcm2835_init, | |
c1b724f6 | 137 | .init_time = clocksource_of_init, |
d0f1c7ff | 138 | .restart = bcm2835_restart, |
ec9653b8 SA |
139 | .dt_compat = bcm2835_compat |
140 | MACHINE_END |