John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify it |
| 3 | * under the terms of the GNU General Public License version 2 as published |
| 4 | * by the Free Software Foundation. |
| 5 | * |
| 6 | * Copyright (C) 2010 John Crispin <blogic@openwrt.org> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/io.h> |
| 11 | #include <linux/ioport.h> |
| 12 | #include <linux/pm.h> |
John Crispin | 4af92e7 | 2011-11-10 21:33:07 +0100 | [diff] [blame] | 13 | #include <linux/export.h> |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 14 | #include <linux/delay.h> |
| 15 | #include <linux/of_address.h> |
| 16 | #include <linux/of_platform.h> |
| 17 | |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 18 | #include <asm/reboot.h> |
| 19 | |
| 20 | #include <lantiq_soc.h> |
| 21 | |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 22 | #include "../prom.h" |
| 23 | |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 24 | #define ltq_rcu_w32(x, y) ltq_w32((x), ltq_rcu_membase + (y)) |
| 25 | #define ltq_rcu_r32(x) ltq_r32(ltq_rcu_membase + (x)) |
| 26 | |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 27 | /* reset request register */ |
| 28 | #define RCU_RST_REQ 0x0010 |
| 29 | /* reset status register */ |
| 30 | #define RCU_RST_STAT 0x0014 |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 31 | |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 32 | /* reboot bit */ |
| 33 | #define RCU_RD_SRST BIT(30) |
| 34 | /* reset cause */ |
| 35 | #define RCU_STAT_SHIFT 26 |
| 36 | /* boot selection */ |
John Crispin | 15753b6 | 2012-11-09 13:31:51 +0100 | [diff] [blame^] | 37 | #define RCU_BOOT_SEL(x) ((x >> 18) & 0x7) |
| 38 | #define RCU_BOOT_SEL_XRX200(x) (((x >> 17) & 0xf) | ((x >> 8) & 0x10)) |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 39 | |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 40 | /* remapped base addr of the reset control unit */ |
| 41 | static void __iomem *ltq_rcu_membase; |
John Crispin | 15753b6 | 2012-11-09 13:31:51 +0100 | [diff] [blame^] | 42 | static struct device_node *ltq_rcu_np; |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 43 | |
| 44 | /* This function is used by the watchdog driver */ |
| 45 | int ltq_reset_cause(void) |
| 46 | { |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 47 | u32 val = ltq_rcu_r32(RCU_RST_STAT); |
| 48 | return val >> RCU_STAT_SHIFT; |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 49 | } |
| 50 | EXPORT_SYMBOL_GPL(ltq_reset_cause); |
| 51 | |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 52 | /* allow platform code to find out what source we booted from */ |
| 53 | unsigned char ltq_boot_select(void) |
| 54 | { |
| 55 | u32 val = ltq_rcu_r32(RCU_RST_STAT); |
John Crispin | 15753b6 | 2012-11-09 13:31:51 +0100 | [diff] [blame^] | 56 | |
| 57 | if (of_device_is_compatible(ltq_rcu_np, "lantiq,rcu-xrx200")) |
| 58 | return RCU_BOOT_SEL_XRX200(val); |
| 59 | |
| 60 | return RCU_BOOT_SEL(val); |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /* reset a io domain for u micro seconds */ |
| 64 | void ltq_reset_once(unsigned int module, ulong u) |
| 65 | { |
| 66 | ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | module, RCU_RST_REQ); |
| 67 | udelay(u); |
| 68 | ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~module, RCU_RST_REQ); |
| 69 | } |
| 70 | |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 71 | static void ltq_machine_restart(char *command) |
| 72 | { |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 73 | local_irq_disable(); |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 74 | ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | RCU_RD_SRST, RCU_RST_REQ); |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 75 | unreachable(); |
| 76 | } |
| 77 | |
| 78 | static void ltq_machine_halt(void) |
| 79 | { |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 80 | local_irq_disable(); |
| 81 | unreachable(); |
| 82 | } |
| 83 | |
| 84 | static void ltq_machine_power_off(void) |
| 85 | { |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 86 | local_irq_disable(); |
| 87 | unreachable(); |
| 88 | } |
| 89 | |
| 90 | static int __init mips_reboot_setup(void) |
| 91 | { |
John Crispin | a039222 | 2012-04-13 20:56:13 +0200 | [diff] [blame] | 92 | struct resource res; |
John Crispin | 15753b6 | 2012-11-09 13:31:51 +0100 | [diff] [blame^] | 93 | |
| 94 | ltq_rcu_np = of_find_compatible_node(NULL, NULL, "lantiq,rcu-xway"); |
| 95 | if (!ltq_rcu_np) |
| 96 | ltq_rcu_np = of_find_compatible_node(NULL, NULL, |
| 97 | "lantiq,rcu-xrx200"); |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 98 | |
John Crispin | a039222 | 2012-04-13 20:56:13 +0200 | [diff] [blame] | 99 | /* check if all the reset register range is available */ |
John Crispin | 15753b6 | 2012-11-09 13:31:51 +0100 | [diff] [blame^] | 100 | if (!ltq_rcu_np) |
John Crispin | a039222 | 2012-04-13 20:56:13 +0200 | [diff] [blame] | 101 | panic("Failed to load reset resources from devicetree"); |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 102 | |
John Crispin | 15753b6 | 2012-11-09 13:31:51 +0100 | [diff] [blame^] | 103 | if (of_address_to_resource(ltq_rcu_np, 0, &res)) |
John Crispin | a039222 | 2012-04-13 20:56:13 +0200 | [diff] [blame] | 104 | panic("Failed to get rcu memory range"); |
| 105 | |
| 106 | if (request_mem_region(res.start, resource_size(&res), res.name) < 0) |
| 107 | pr_err("Failed to request rcu memory"); |
| 108 | |
| 109 | ltq_rcu_membase = ioremap_nocache(res.start, resource_size(&res)); |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 110 | if (!ltq_rcu_membase) |
John Crispin | 6697c69 | 2012-04-30 11:33:09 +0200 | [diff] [blame] | 111 | panic("Failed to remap core memory"); |
John Crispin | 8ec6d93 | 2011-03-30 09:27:48 +0200 | [diff] [blame] | 112 | |
| 113 | _machine_restart = ltq_machine_restart; |
| 114 | _machine_halt = ltq_machine_halt; |
| 115 | pm_power_off = ltq_machine_power_off; |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | arch_initcall(mips_reboot_setup); |