blob: 2799212ab7db8525dc7121af469a9a33698896e6 [file] [log] [blame]
John Crispin8ec6d932011-03-30 09:27:48 +02001/*
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 Crispin4af92e72011-11-10 21:33:07 +010013#include <linux/export.h>
John Crispin6697c692012-04-30 11:33:09 +020014#include <linux/delay.h>
15#include <linux/of_address.h>
16#include <linux/of_platform.h>
17
John Crispin8ec6d932011-03-30 09:27:48 +020018#include <asm/reboot.h>
19
20#include <lantiq_soc.h>
21
John Crispin6697c692012-04-30 11:33:09 +020022#include "../prom.h"
23
John Crispin8ec6d932011-03-30 09:27:48 +020024#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 Crispin6697c692012-04-30 11:33:09 +020027/* reset request register */
28#define RCU_RST_REQ 0x0010
29/* reset status register */
30#define RCU_RST_STAT 0x0014
John Crispin8ec6d932011-03-30 09:27:48 +020031
John Crispin6697c692012-04-30 11:33:09 +020032/* reboot bit */
33#define RCU_RD_SRST BIT(30)
34/* reset cause */
35#define RCU_STAT_SHIFT 26
36/* boot selection */
John Crispin15753b62012-11-09 13:31:51 +010037#define RCU_BOOT_SEL(x) ((x >> 18) & 0x7)
38#define RCU_BOOT_SEL_XRX200(x) (((x >> 17) & 0xf) | ((x >> 8) & 0x10))
John Crispin8ec6d932011-03-30 09:27:48 +020039
John Crispin8ec6d932011-03-30 09:27:48 +020040/* remapped base addr of the reset control unit */
41static void __iomem *ltq_rcu_membase;
John Crispin15753b62012-11-09 13:31:51 +010042static struct device_node *ltq_rcu_np;
John Crispin8ec6d932011-03-30 09:27:48 +020043
44/* This function is used by the watchdog driver */
45int ltq_reset_cause(void)
46{
John Crispin6697c692012-04-30 11:33:09 +020047 u32 val = ltq_rcu_r32(RCU_RST_STAT);
48 return val >> RCU_STAT_SHIFT;
John Crispin8ec6d932011-03-30 09:27:48 +020049}
50EXPORT_SYMBOL_GPL(ltq_reset_cause);
51
John Crispin6697c692012-04-30 11:33:09 +020052/* allow platform code to find out what source we booted from */
53unsigned char ltq_boot_select(void)
54{
55 u32 val = ltq_rcu_r32(RCU_RST_STAT);
John Crispin15753b62012-11-09 13:31:51 +010056
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 Crispin6697c692012-04-30 11:33:09 +020061}
62
63/* reset a io domain for u micro seconds */
64void 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 Crispin8ec6d932011-03-30 09:27:48 +020071static void ltq_machine_restart(char *command)
72{
John Crispin8ec6d932011-03-30 09:27:48 +020073 local_irq_disable();
John Crispin6697c692012-04-30 11:33:09 +020074 ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | RCU_RD_SRST, RCU_RST_REQ);
John Crispin8ec6d932011-03-30 09:27:48 +020075 unreachable();
76}
77
78static void ltq_machine_halt(void)
79{
John Crispin8ec6d932011-03-30 09:27:48 +020080 local_irq_disable();
81 unreachable();
82}
83
84static void ltq_machine_power_off(void)
85{
John Crispin8ec6d932011-03-30 09:27:48 +020086 local_irq_disable();
87 unreachable();
88}
89
90static int __init mips_reboot_setup(void)
91{
John Crispina0392222012-04-13 20:56:13 +020092 struct resource res;
John Crispin15753b62012-11-09 13:31:51 +010093
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 Crispin8ec6d932011-03-30 09:27:48 +020098
John Crispina0392222012-04-13 20:56:13 +020099 /* check if all the reset register range is available */
John Crispin15753b62012-11-09 13:31:51 +0100100 if (!ltq_rcu_np)
John Crispina0392222012-04-13 20:56:13 +0200101 panic("Failed to load reset resources from devicetree");
John Crispin8ec6d932011-03-30 09:27:48 +0200102
John Crispin15753b62012-11-09 13:31:51 +0100103 if (of_address_to_resource(ltq_rcu_np, 0, &res))
John Crispina0392222012-04-13 20:56:13 +0200104 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 Crispin8ec6d932011-03-30 09:27:48 +0200110 if (!ltq_rcu_membase)
John Crispin6697c692012-04-30 11:33:09 +0200111 panic("Failed to remap core memory");
John Crispin8ec6d932011-03-30 09:27:48 +0200112
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
120arch_initcall(mips_reboot_setup);