spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / arch / mips / bcm47xx / setup.c
blobaab6b0c40a7569b54767c5e473e75da5ba5b8563
1 /*
2 * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
3 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
4 * Copyright (C) 2006 Michael Buesch <m@bues.ch>
5 * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
6 * Copyright (C) 2010-2011 Hauke Mehrtens <hauke@hauke-m.de>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <linux/export.h>
30 #include <linux/types.h>
31 #include <linux/ssb/ssb.h>
32 #include <linux/ssb/ssb_embedded.h>
33 #include <linux/bcma/bcma_soc.h>
34 #include <asm/bootinfo.h>
35 #include <asm/reboot.h>
36 #include <asm/time.h>
37 #include <bcm47xx.h>
38 #include <asm/mach-bcm47xx/nvram.h>
40 union bcm47xx_bus bcm47xx_bus;
41 EXPORT_SYMBOL(bcm47xx_bus);
43 enum bcm47xx_bus_type bcm47xx_bus_type;
44 EXPORT_SYMBOL(bcm47xx_bus_type);
46 static void bcm47xx_machine_restart(char *command)
48 printk(KERN_ALERT "Please stand by while rebooting the system...\n");
49 local_irq_disable();
50 /* Set the watchdog timer to reset immediately */
51 switch (bcm47xx_bus_type) {
52 #ifdef CONFIG_BCM47XX_SSB
53 case BCM47XX_BUS_TYPE_SSB:
54 ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
55 break;
56 #endif
57 #ifdef CONFIG_BCM47XX_BCMA
58 case BCM47XX_BUS_TYPE_BCMA:
59 bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
60 break;
61 #endif
63 while (1)
64 cpu_relax();
67 static void bcm47xx_machine_halt(void)
69 /* Disable interrupts and watchdog and spin forever */
70 local_irq_disable();
71 switch (bcm47xx_bus_type) {
72 #ifdef CONFIG_BCM47XX_SSB
73 case BCM47XX_BUS_TYPE_SSB:
74 ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
75 break;
76 #endif
77 #ifdef CONFIG_BCM47XX_BCMA
78 case BCM47XX_BUS_TYPE_BCMA:
79 bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
80 break;
81 #endif
83 while (1)
84 cpu_relax();
87 #ifdef CONFIG_BCM47XX_SSB
88 #define READ_FROM_NVRAM(_outvar, name, buf) \
89 if (nvram_getprefix(prefix, name, buf, sizeof(buf)) >= 0)\
90 sprom->_outvar = simple_strtoul(buf, NULL, 0);
92 #define READ_FROM_NVRAM2(_outvar, name1, name2, buf) \
93 if (nvram_getprefix(prefix, name1, buf, sizeof(buf)) >= 0 || \
94 nvram_getprefix(prefix, name2, buf, sizeof(buf)) >= 0)\
95 sprom->_outvar = simple_strtoul(buf, NULL, 0);
97 static inline int nvram_getprefix(const char *prefix, char *name,
98 char *buf, int len)
100 if (prefix) {
101 char key[100];
103 snprintf(key, sizeof(key), "%s%s", prefix, name);
104 return nvram_getenv(key, buf, len);
107 return nvram_getenv(name, buf, len);
110 static u32 nvram_getu32(const char *name, char *buf, int len)
112 int rv;
113 char key[100];
114 u16 var0, var1;
116 snprintf(key, sizeof(key), "%s0", name);
117 rv = nvram_getenv(key, buf, len);
118 /* return 0 here so this looks like unset */
119 if (rv < 0)
120 return 0;
121 var0 = simple_strtoul(buf, NULL, 0);
123 snprintf(key, sizeof(key), "%s1", name);
124 rv = nvram_getenv(key, buf, len);
125 if (rv < 0)
126 return 0;
127 var1 = simple_strtoul(buf, NULL, 0);
128 return var1 << 16 | var0;
131 static void bcm47xx_fill_sprom(struct ssb_sprom *sprom, const char *prefix)
133 char buf[100];
134 u32 boardflags;
136 memset(sprom, 0, sizeof(struct ssb_sprom));
138 sprom->revision = 1; /* Fallback: Old hardware does not define this. */
139 READ_FROM_NVRAM(revision, "sromrev", buf);
140 if (nvram_getprefix(prefix, "il0macaddr", buf, sizeof(buf)) >= 0 ||
141 nvram_getprefix(prefix, "macaddr", buf, sizeof(buf)) >= 0)
142 nvram_parse_macaddr(buf, sprom->il0mac);
143 if (nvram_getprefix(prefix, "et0macaddr", buf, sizeof(buf)) >= 0)
144 nvram_parse_macaddr(buf, sprom->et0mac);
145 if (nvram_getprefix(prefix, "et1macaddr", buf, sizeof(buf)) >= 0)
146 nvram_parse_macaddr(buf, sprom->et1mac);
147 READ_FROM_NVRAM(et0phyaddr, "et0phyaddr", buf);
148 READ_FROM_NVRAM(et1phyaddr, "et1phyaddr", buf);
149 READ_FROM_NVRAM(et0mdcport, "et0mdcport", buf);
150 READ_FROM_NVRAM(et1mdcport, "et1mdcport", buf);
151 READ_FROM_NVRAM(board_rev, "boardrev", buf);
152 READ_FROM_NVRAM(country_code, "ccode", buf);
153 READ_FROM_NVRAM(ant_available_a, "aa5g", buf);
154 READ_FROM_NVRAM(ant_available_bg, "aa2g", buf);
155 READ_FROM_NVRAM(pa0b0, "pa0b0", buf);
156 READ_FROM_NVRAM(pa0b1, "pa0b1", buf);
157 READ_FROM_NVRAM(pa0b2, "pa0b2", buf);
158 READ_FROM_NVRAM(pa1b0, "pa1b0", buf);
159 READ_FROM_NVRAM(pa1b1, "pa1b1", buf);
160 READ_FROM_NVRAM(pa1b2, "pa1b2", buf);
161 READ_FROM_NVRAM(pa1lob0, "pa1lob0", buf);
162 READ_FROM_NVRAM(pa1lob2, "pa1lob1", buf);
163 READ_FROM_NVRAM(pa1lob1, "pa1lob2", buf);
164 READ_FROM_NVRAM(pa1hib0, "pa1hib0", buf);
165 READ_FROM_NVRAM(pa1hib2, "pa1hib1", buf);
166 READ_FROM_NVRAM(pa1hib1, "pa1hib2", buf);
167 READ_FROM_NVRAM2(gpio0, "ledbh0", "wl0gpio0", buf);
168 READ_FROM_NVRAM2(gpio1, "ledbh1", "wl0gpio1", buf);
169 READ_FROM_NVRAM2(gpio2, "ledbh2", "wl0gpio2", buf);
170 READ_FROM_NVRAM2(gpio3, "ledbh3", "wl0gpio3", buf);
171 READ_FROM_NVRAM2(maxpwr_bg, "maxp2ga0", "pa0maxpwr", buf);
172 READ_FROM_NVRAM2(maxpwr_al, "maxp5gla0", "pa1lomaxpwr", buf);
173 READ_FROM_NVRAM2(maxpwr_a, "maxp5ga0", "pa1maxpwr", buf);
174 READ_FROM_NVRAM2(maxpwr_ah, "maxp5gha0", "pa1himaxpwr", buf);
175 READ_FROM_NVRAM2(itssi_bg, "itt5ga0", "pa0itssit", buf);
176 READ_FROM_NVRAM2(itssi_a, "itt2ga0", "pa1itssit", buf);
177 READ_FROM_NVRAM(tri2g, "tri2g", buf);
178 READ_FROM_NVRAM(tri5gl, "tri5gl", buf);
179 READ_FROM_NVRAM(tri5g, "tri5g", buf);
180 READ_FROM_NVRAM(tri5gh, "tri5gh", buf);
181 READ_FROM_NVRAM(txpid2g[0], "txpid2ga0", buf);
182 READ_FROM_NVRAM(txpid2g[1], "txpid2ga1", buf);
183 READ_FROM_NVRAM(txpid2g[2], "txpid2ga2", buf);
184 READ_FROM_NVRAM(txpid2g[3], "txpid2ga3", buf);
185 READ_FROM_NVRAM(txpid5g[0], "txpid5ga0", buf);
186 READ_FROM_NVRAM(txpid5g[1], "txpid5ga1", buf);
187 READ_FROM_NVRAM(txpid5g[2], "txpid5ga2", buf);
188 READ_FROM_NVRAM(txpid5g[3], "txpid5ga3", buf);
189 READ_FROM_NVRAM(txpid5gl[0], "txpid5gla0", buf);
190 READ_FROM_NVRAM(txpid5gl[1], "txpid5gla1", buf);
191 READ_FROM_NVRAM(txpid5gl[2], "txpid5gla2", buf);
192 READ_FROM_NVRAM(txpid5gl[3], "txpid5gla3", buf);
193 READ_FROM_NVRAM(txpid5gh[0], "txpid5gha0", buf);
194 READ_FROM_NVRAM(txpid5gh[1], "txpid5gha1", buf);
195 READ_FROM_NVRAM(txpid5gh[2], "txpid5gha2", buf);
196 READ_FROM_NVRAM(txpid5gh[3], "txpid5gha3", buf);
197 READ_FROM_NVRAM(rxpo2g, "rxpo2g", buf);
198 READ_FROM_NVRAM(rxpo5g, "rxpo5g", buf);
199 READ_FROM_NVRAM(rssisav2g, "rssisav2g", buf);
200 READ_FROM_NVRAM(rssismc2g, "rssismc2g", buf);
201 READ_FROM_NVRAM(rssismf2g, "rssismf2g", buf);
202 READ_FROM_NVRAM(bxa2g, "bxa2g", buf);
203 READ_FROM_NVRAM(rssisav5g, "rssisav5g", buf);
204 READ_FROM_NVRAM(rssismc5g, "rssismc5g", buf);
205 READ_FROM_NVRAM(rssismf5g, "rssismf5g", buf);
206 READ_FROM_NVRAM(bxa5g, "bxa5g", buf);
207 READ_FROM_NVRAM(cck2gpo, "cck2gpo", buf);
209 sprom->ofdm2gpo = nvram_getu32("ofdm2gpo", buf, sizeof(buf));
210 sprom->ofdm5glpo = nvram_getu32("ofdm5glpo", buf, sizeof(buf));
211 sprom->ofdm5gpo = nvram_getu32("ofdm5gpo", buf, sizeof(buf));
212 sprom->ofdm5ghpo = nvram_getu32("ofdm5ghpo", buf, sizeof(buf));
214 READ_FROM_NVRAM(antenna_gain.ghz24.a0, "ag0", buf);
215 READ_FROM_NVRAM(antenna_gain.ghz24.a1, "ag1", buf);
216 READ_FROM_NVRAM(antenna_gain.ghz24.a2, "ag2", buf);
217 READ_FROM_NVRAM(antenna_gain.ghz24.a3, "ag3", buf);
218 memcpy(&sprom->antenna_gain.ghz5, &sprom->antenna_gain.ghz24,
219 sizeof(sprom->antenna_gain.ghz5));
221 if (nvram_getprefix(prefix, "boardflags", buf, sizeof(buf)) >= 0) {
222 boardflags = simple_strtoul(buf, NULL, 0);
223 if (boardflags) {
224 sprom->boardflags_lo = (boardflags & 0x0000FFFFU);
225 sprom->boardflags_hi = (boardflags & 0xFFFF0000U) >> 16;
228 if (nvram_getprefix(prefix, "boardflags2", buf, sizeof(buf)) >= 0) {
229 boardflags = simple_strtoul(buf, NULL, 0);
230 if (boardflags) {
231 sprom->boardflags2_lo = (boardflags & 0x0000FFFFU);
232 sprom->boardflags2_hi = (boardflags & 0xFFFF0000U) >> 16;
237 int bcm47xx_get_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
239 char prefix[10];
241 if (bus->bustype == SSB_BUSTYPE_PCI) {
242 snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
243 bus->host_pci->bus->number + 1,
244 PCI_SLOT(bus->host_pci->devfn));
245 bcm47xx_fill_sprom(out, prefix);
246 return 0;
247 } else {
248 printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n");
249 return -EINVAL;
253 static int bcm47xx_get_invariants(struct ssb_bus *bus,
254 struct ssb_init_invariants *iv)
256 char buf[20];
258 /* Fill boardinfo structure */
259 memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
261 if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0)
262 iv->boardinfo.vendor = (u16)simple_strtoul(buf, NULL, 0);
263 else
264 iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
265 if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
266 iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
267 if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
268 iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);
270 bcm47xx_fill_sprom(&iv->sprom, NULL);
272 if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
273 iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
275 return 0;
278 static void __init bcm47xx_register_ssb(void)
280 int err;
281 char buf[100];
282 struct ssb_mipscore *mcore;
284 err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom);
285 if (err)
286 printk(KERN_WARNING "bcm47xx: someone else already registered"
287 " a ssb SPROM callback handler (err %d)\n", err);
289 err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
290 bcm47xx_get_invariants);
291 if (err)
292 panic("Failed to initialize SSB bus (err %d)", err);
294 mcore = &bcm47xx_bus.ssb.mipscore;
295 if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
296 if (strstr(buf, "console=ttyS1")) {
297 struct ssb_serial_port port;
299 printk(KERN_DEBUG "Swapping serial ports!\n");
300 /* swap serial ports */
301 memcpy(&port, &mcore->serial_ports[0], sizeof(port));
302 memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
303 sizeof(port));
304 memcpy(&mcore->serial_ports[1], &port, sizeof(port));
308 #endif
310 #ifdef CONFIG_BCM47XX_BCMA
311 static void __init bcm47xx_register_bcma(void)
313 int err;
315 err = bcma_host_soc_register(&bcm47xx_bus.bcma);
316 if (err)
317 panic("Failed to initialize BCMA bus (err %d)", err);
319 #endif
321 void __init plat_mem_setup(void)
323 struct cpuinfo_mips *c = &current_cpu_data;
325 if (c->cputype == CPU_74K) {
326 printk(KERN_INFO "bcm47xx: using bcma bus\n");
327 #ifdef CONFIG_BCM47XX_BCMA
328 bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
329 bcm47xx_register_bcma();
330 #endif
331 } else {
332 printk(KERN_INFO "bcm47xx: using ssb bus\n");
333 #ifdef CONFIG_BCM47XX_SSB
334 bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
335 bcm47xx_register_ssb();
336 #endif
339 _machine_restart = bcm47xx_machine_restart;
340 _machine_halt = bcm47xx_machine_halt;
341 pm_power_off = bcm47xx_machine_halt;
344 static int __init bcm47xx_register_bus_complete(void)
346 switch (bcm47xx_bus_type) {
347 #ifdef CONFIG_BCM47XX_SSB
348 case BCM47XX_BUS_TYPE_SSB:
349 /* Nothing to do */
350 break;
351 #endif
352 #ifdef CONFIG_BCM47XX_BCMA
353 case BCM47XX_BUS_TYPE_BCMA:
354 bcma_bus_register(&bcm47xx_bus.bcma.bus);
355 break;
356 #endif
358 return 0;
360 device_initcall(bcm47xx_register_bus_complete);