Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 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 | |
Stephen Warren | d0f1c7f | 2012-09-15 22:18:10 -0600 | [diff] [blame^] | 15 | #include <linux/delay.h> |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 16 | #include <linux/init.h> |
Simon Arlott | 89214f0 | 2012-09-12 19:57:26 -0600 | [diff] [blame] | 17 | #include <linux/irqchip/bcm2835.h> |
Stephen Warren | d0f1c7f | 2012-09-15 22:18:10 -0600 | [diff] [blame^] | 18 | #include <linux/of_address.h> |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 19 | #include <linux/of_platform.h> |
Simon Arlott | ee4af56 | 2012-09-10 22:38:35 -0600 | [diff] [blame] | 20 | #include <linux/bcm2835_timer.h> |
Simon Arlott | 75fabc3 | 2012-09-10 23:26:15 -0600 | [diff] [blame] | 21 | #include <linux/clk/bcm2835.h> |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 22 | |
| 23 | #include <asm/mach/arch.h> |
| 24 | #include <asm/mach/map.h> |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 25 | |
| 26 | #include <mach/bcm2835_soc.h> |
| 27 | |
Stephen Warren | d0f1c7f | 2012-09-15 22:18:10 -0600 | [diff] [blame^] | 28 | #define PM_RSTC 0x1c |
| 29 | #define PM_WDOG 0x24 |
| 30 | |
| 31 | #define PM_PASSWORD 0x5a000000 |
| 32 | #define PM_RSTC_WRCFG_MASK 0x00000030 |
| 33 | #define PM_RSTC_WRCFG_FULL_RESET 0x00000020 |
| 34 | |
| 35 | static void __iomem *wdt_regs; |
| 36 | |
| 37 | /* |
| 38 | * The machine restart method can be called from an atomic context so we won't |
| 39 | * be able to ioremap the regs then. |
| 40 | */ |
| 41 | static void bcm2835_setup_restart(void) |
| 42 | { |
| 43 | struct device_node *np = of_find_compatible_node(NULL, NULL, |
| 44 | "brcm,bcm2835-pm-wdt"); |
| 45 | if (WARN(!np, "unable to setup watchdog restart")) |
| 46 | return; |
| 47 | |
| 48 | wdt_regs = of_iomap(np, 0); |
| 49 | WARN(!wdt_regs, "failed to remap watchdog regs"); |
| 50 | } |
| 51 | |
| 52 | static void bcm2835_restart(char mode, const char *cmd) |
| 53 | { |
| 54 | u32 val; |
| 55 | |
| 56 | if (!wdt_regs) |
| 57 | return; |
| 58 | |
| 59 | /* use a timeout of 10 ticks (~150us) */ |
| 60 | writel_relaxed(10 | PM_PASSWORD, wdt_regs + PM_WDOG); |
| 61 | val = readl_relaxed(wdt_regs + PM_RSTC); |
| 62 | val &= ~PM_RSTC_WRCFG_MASK; |
| 63 | val |= PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET; |
| 64 | writel_relaxed(val, wdt_regs + PM_RSTC); |
| 65 | |
| 66 | /* No sleeping, possibly atomic. */ |
| 67 | mdelay(1); |
| 68 | } |
| 69 | |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 70 | static struct map_desc io_map __initdata = { |
| 71 | .virtual = BCM2835_PERIPH_VIRT, |
| 72 | .pfn = __phys_to_pfn(BCM2835_PERIPH_PHYS), |
| 73 | .length = BCM2835_PERIPH_SIZE, |
| 74 | .type = MT_DEVICE |
| 75 | }; |
| 76 | |
| 77 | void __init bcm2835_map_io(void) |
| 78 | { |
| 79 | iotable_init(&io_map, 1); |
| 80 | } |
| 81 | |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 82 | void __init bcm2835_init(void) |
| 83 | { |
| 84 | int ret; |
| 85 | |
Stephen Warren | d0f1c7f | 2012-09-15 22:18:10 -0600 | [diff] [blame^] | 86 | bcm2835_setup_restart(); |
Simon Arlott | 75fabc3 | 2012-09-10 23:26:15 -0600 | [diff] [blame] | 87 | bcm2835_init_clocks(); |
| 88 | |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 89 | ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, |
| 90 | NULL); |
| 91 | if (ret) { |
| 92 | pr_err("of_platform_populate failed: %d\n", ret); |
| 93 | BUG(); |
| 94 | } |
| 95 | } |
| 96 | |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 97 | static const char * const bcm2835_compat[] = { |
| 98 | "brcm,bcm2835", |
| 99 | NULL |
| 100 | }; |
| 101 | |
| 102 | DT_MACHINE_START(BCM2835, "BCM2835") |
| 103 | .map_io = bcm2835_map_io, |
| 104 | .init_irq = bcm2835_init_irq, |
| 105 | .handle_irq = bcm2835_handle_irq, |
| 106 | .init_machine = bcm2835_init, |
| 107 | .timer = &bcm2835_timer, |
Stephen Warren | d0f1c7f | 2012-09-15 22:18:10 -0600 | [diff] [blame^] | 108 | .restart = bcm2835_restart, |
Simon Arlott | ec9653b | 2012-05-26 01:04:43 -0600 | [diff] [blame] | 109 | .dt_compat = bcm2835_compat |
| 110 | MACHINE_END |