blob: c867d0e8cf7cc85522e23c4acafbb2c60b19ec27 [file] [log] [blame]
Simon Arlottec9653b2012-05-26 01:04:43 -06001/*
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
Stephen Warrend0f1c7f2012-09-15 22:18:10 -060015#include <linux/delay.h>
Simon Arlottec9653b2012-05-26 01:04:43 -060016#include <linux/init.h>
Simon Arlott89214f02012-09-12 19:57:26 -060017#include <linux/irqchip/bcm2835.h>
Stephen Warrend0f1c7f2012-09-15 22:18:10 -060018#include <linux/of_address.h>
Simon Arlottec9653b2012-05-26 01:04:43 -060019#include <linux/of_platform.h>
Simon Arlottee4af562012-09-10 22:38:35 -060020#include <linux/bcm2835_timer.h>
Simon Arlott75fabc32012-09-10 23:26:15 -060021#include <linux/clk/bcm2835.h>
Simon Arlottec9653b2012-05-26 01:04:43 -060022
23#include <asm/mach/arch.h>
24#include <asm/mach/map.h>
Simon Arlottec9653b2012-05-26 01:04:43 -060025
26#include <mach/bcm2835_soc.h>
27
Stephen Warrend0f1c7f2012-09-15 22:18:10 -060028#define PM_RSTC 0x1c
Dom Cobley45e9d772012-10-27 21:14:50 -060029#define PM_RSTS 0x20
Stephen Warrend0f1c7f2012-09-15 22:18:10 -060030#define PM_WDOG 0x24
31
32#define PM_PASSWORD 0x5a000000
33#define PM_RSTC_WRCFG_MASK 0x00000030
34#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
Dom Cobley45e9d772012-10-27 21:14:50 -060035#define PM_RSTS_HADWRH_SET 0x00000040
Stephen Warrend0f1c7f2012-09-15 22:18:10 -060036
37static void __iomem *wdt_regs;
38
39/*
40 * The machine restart method can be called from an atomic context so we won't
41 * be able to ioremap the regs then.
42 */
43static void bcm2835_setup_restart(void)
44{
45 struct device_node *np = of_find_compatible_node(NULL, NULL,
46 "brcm,bcm2835-pm-wdt");
47 if (WARN(!np, "unable to setup watchdog restart"))
48 return;
49
50 wdt_regs = of_iomap(np, 0);
51 WARN(!wdt_regs, "failed to remap watchdog regs");
52}
53
54static void bcm2835_restart(char mode, const char *cmd)
55{
56 u32 val;
57
58 if (!wdt_regs)
59 return;
60
61 /* use a timeout of 10 ticks (~150us) */
62 writel_relaxed(10 | PM_PASSWORD, wdt_regs + PM_WDOG);
63 val = readl_relaxed(wdt_regs + PM_RSTC);
64 val &= ~PM_RSTC_WRCFG_MASK;
65 val |= PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET;
66 writel_relaxed(val, wdt_regs + PM_RSTC);
67
68 /* No sleeping, possibly atomic. */
69 mdelay(1);
70}
71
Dom Cobley45e9d772012-10-27 21:14:50 -060072/*
73 * We can't really power off, but if we do the normal reset scheme, and
74 * indicate to bootcode.bin not to reboot, then most of the chip will be
75 * powered off.
76 */
77static void bcm2835_power_off(void)
78{
79 u32 val;
80
81 /*
82 * We set the watchdog hard reset bit here to distinguish this reset
83 * from the normal (full) reset. bootcode.bin will not reboot after a
84 * hard reset.
85 */
86 val = readl_relaxed(wdt_regs + PM_RSTS);
87 val &= ~PM_RSTC_WRCFG_MASK;
88 val |= PM_PASSWORD | PM_RSTS_HADWRH_SET;
89 writel_relaxed(val, wdt_regs + PM_RSTS);
90
91 /* Continue with normal reset mechanism */
92 bcm2835_restart(0, "");
93}
94
Simon Arlottec9653b2012-05-26 01:04:43 -060095static struct map_desc io_map __initdata = {
96 .virtual = BCM2835_PERIPH_VIRT,
97 .pfn = __phys_to_pfn(BCM2835_PERIPH_PHYS),
98 .length = BCM2835_PERIPH_SIZE,
99 .type = MT_DEVICE
100};
101
Domenico Andreolidd3c7542012-10-20 03:35:27 +0200102static void __init bcm2835_map_io(void)
Simon Arlottec9653b2012-05-26 01:04:43 -0600103{
104 iotable_init(&io_map, 1);
105}
106
Domenico Andreolidd3c7542012-10-20 03:35:27 +0200107static void __init bcm2835_init(void)
Simon Arlottec9653b2012-05-26 01:04:43 -0600108{
109 int ret;
110
Stephen Warrend0f1c7f2012-09-15 22:18:10 -0600111 bcm2835_setup_restart();
Dom Cobley45e9d772012-10-27 21:14:50 -0600112 if (wdt_regs)
113 pm_power_off = bcm2835_power_off;
114
Simon Arlott75fabc32012-09-10 23:26:15 -0600115 bcm2835_init_clocks();
116
Simon Arlottec9653b2012-05-26 01:04:43 -0600117 ret = of_platform_populate(NULL, of_default_bus_match_table, NULL,
118 NULL);
119 if (ret) {
120 pr_err("of_platform_populate failed: %d\n", ret);
121 BUG();
122 }
123}
124
Simon Arlottec9653b2012-05-26 01:04:43 -0600125static const char * const bcm2835_compat[] = {
126 "brcm,bcm2835",
127 NULL
128};
129
130DT_MACHINE_START(BCM2835, "BCM2835")
131 .map_io = bcm2835_map_io,
132 .init_irq = bcm2835_init_irq,
133 .handle_irq = bcm2835_handle_irq,
134 .init_machine = bcm2835_init,
135 .timer = &bcm2835_timer,
Stephen Warrend0f1c7f2012-09-15 22:18:10 -0600136 .restart = bcm2835_restart,
Simon Arlottec9653b2012-05-26 01:04:43 -0600137 .dt_compat = bcm2835_compat
138MACHINE_END