blob: 544dbb7fb421e03ac01200e226255390f26499f7 [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 Crispinaf14a452012-11-09 13:43:30 +010031/* vr9 gphy registers */
32#define RCU_GFS_ADD0_XRX200 0x0020
33#define RCU_GFS_ADD1_XRX200 0x0068
John Crispin8ec6d932011-03-30 09:27:48 +020034
John Crispin6697c692012-04-30 11:33:09 +020035/* reboot bit */
John Crispinaf14a452012-11-09 13:43:30 +010036#define RCU_RD_GPHY0_XRX200 BIT(31)
John Crispin6697c692012-04-30 11:33:09 +020037#define RCU_RD_SRST BIT(30)
John Crispinaf14a452012-11-09 13:43:30 +010038#define RCU_RD_GPHY1_XRX200 BIT(29)
39
John Crispin6697c692012-04-30 11:33:09 +020040/* reset cause */
41#define RCU_STAT_SHIFT 26
42/* boot selection */
John Crispin15753b62012-11-09 13:31:51 +010043#define RCU_BOOT_SEL(x) ((x >> 18) & 0x7)
44#define RCU_BOOT_SEL_XRX200(x) (((x >> 17) & 0xf) | ((x >> 8) & 0x10))
John Crispin8ec6d932011-03-30 09:27:48 +020045
John Crispin8ec6d932011-03-30 09:27:48 +020046/* remapped base addr of the reset control unit */
47static void __iomem *ltq_rcu_membase;
John Crispin15753b62012-11-09 13:31:51 +010048static struct device_node *ltq_rcu_np;
John Crispin8ec6d932011-03-30 09:27:48 +020049
50/* This function is used by the watchdog driver */
51int ltq_reset_cause(void)
52{
John Crispin6697c692012-04-30 11:33:09 +020053 u32 val = ltq_rcu_r32(RCU_RST_STAT);
54 return val >> RCU_STAT_SHIFT;
John Crispin8ec6d932011-03-30 09:27:48 +020055}
56EXPORT_SYMBOL_GPL(ltq_reset_cause);
57
John Crispin6697c692012-04-30 11:33:09 +020058/* allow platform code to find out what source we booted from */
59unsigned char ltq_boot_select(void)
60{
61 u32 val = ltq_rcu_r32(RCU_RST_STAT);
John Crispin15753b62012-11-09 13:31:51 +010062
63 if (of_device_is_compatible(ltq_rcu_np, "lantiq,rcu-xrx200"))
64 return RCU_BOOT_SEL_XRX200(val);
65
66 return RCU_BOOT_SEL(val);
John Crispin6697c692012-04-30 11:33:09 +020067}
68
John Crispinaf14a452012-11-09 13:43:30 +010069/* reset / boot a gphy */
70static struct ltq_xrx200_gphy_reset {
71 u32 rd;
72 u32 addr;
73} xrx200_gphy[] = {
74 {RCU_RD_GPHY0_XRX200, RCU_GFS_ADD0_XRX200},
75 {RCU_RD_GPHY1_XRX200, RCU_GFS_ADD1_XRX200},
76};
77
78/* reset and boot a gphy. these phys only exist on xrx200 SoC */
79int xrx200_gphy_boot(struct device *dev, unsigned int id, dma_addr_t dev_addr)
80{
81 if (!of_device_is_compatible(ltq_rcu_np, "lantiq,rcu-xrx200")) {
82 dev_err(dev, "this SoC has no GPHY\n");
83 return -EINVAL;
84 }
85 if (id > 1) {
86 dev_err(dev, "%u is an invalid gphy id\n", id);
87 return -EINVAL;
88 }
89 dev_info(dev, "booting GPHY%u firmware at %X\n", id, dev_addr);
90
91 ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | xrx200_gphy[id].rd,
92 RCU_RST_REQ);
93 ltq_rcu_w32(dev_addr, xrx200_gphy[id].addr);
94 ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~xrx200_gphy[id].rd,
95 RCU_RST_REQ);
96 return 0;
97}
98
John Crispin6697c692012-04-30 11:33:09 +020099/* reset a io domain for u micro seconds */
100void ltq_reset_once(unsigned int module, ulong u)
101{
102 ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | module, RCU_RST_REQ);
103 udelay(u);
104 ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~module, RCU_RST_REQ);
105}
106
John Crispin8ec6d932011-03-30 09:27:48 +0200107static void ltq_machine_restart(char *command)
108{
John Crispin8ec6d932011-03-30 09:27:48 +0200109 local_irq_disable();
John Crispin6697c692012-04-30 11:33:09 +0200110 ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | RCU_RD_SRST, RCU_RST_REQ);
John Crispin8ec6d932011-03-30 09:27:48 +0200111 unreachable();
112}
113
114static void ltq_machine_halt(void)
115{
John Crispin8ec6d932011-03-30 09:27:48 +0200116 local_irq_disable();
117 unreachable();
118}
119
120static void ltq_machine_power_off(void)
121{
John Crispin8ec6d932011-03-30 09:27:48 +0200122 local_irq_disable();
123 unreachable();
124}
125
126static int __init mips_reboot_setup(void)
127{
John Crispina0392222012-04-13 20:56:13 +0200128 struct resource res;
John Crispin15753b62012-11-09 13:31:51 +0100129
130 ltq_rcu_np = of_find_compatible_node(NULL, NULL, "lantiq,rcu-xway");
131 if (!ltq_rcu_np)
132 ltq_rcu_np = of_find_compatible_node(NULL, NULL,
133 "lantiq,rcu-xrx200");
John Crispin8ec6d932011-03-30 09:27:48 +0200134
John Crispina0392222012-04-13 20:56:13 +0200135 /* check if all the reset register range is available */
John Crispin15753b62012-11-09 13:31:51 +0100136 if (!ltq_rcu_np)
John Crispina0392222012-04-13 20:56:13 +0200137 panic("Failed to load reset resources from devicetree");
John Crispin8ec6d932011-03-30 09:27:48 +0200138
John Crispin15753b62012-11-09 13:31:51 +0100139 if (of_address_to_resource(ltq_rcu_np, 0, &res))
John Crispina0392222012-04-13 20:56:13 +0200140 panic("Failed to get rcu memory range");
141
142 if (request_mem_region(res.start, resource_size(&res), res.name) < 0)
143 pr_err("Failed to request rcu memory");
144
145 ltq_rcu_membase = ioremap_nocache(res.start, resource_size(&res));
John Crispin8ec6d932011-03-30 09:27:48 +0200146 if (!ltq_rcu_membase)
John Crispin6697c692012-04-30 11:33:09 +0200147 panic("Failed to remap core memory");
John Crispin8ec6d932011-03-30 09:27:48 +0200148
149 _machine_restart = ltq_machine_restart;
150 _machine_halt = ltq_machine_halt;
151 pm_power_off = ltq_machine_power_off;
152
153 return 0;
154}
155
156arch_initcall(mips_reboot_setup);