xref: /openbmc/linux/arch/mips/bcm47xx/setup.c (revision c1d1c5d4213ee96e054c4d195117368972a4c01f)
11c0c13ebSAurelien Jarno /*
21c0c13ebSAurelien Jarno  *  Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
31c0c13ebSAurelien Jarno  *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
4eb032b98SMichael Büsch  *  Copyright (C) 2006 Michael Buesch <m@bues.ch>
5121915c4SWaldemar Brodkorb  *  Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
6fe6f3642SHauke Mehrtens  *  Copyright (C) 2010-2011 Hauke Mehrtens <hauke@hauke-m.de>
71c0c13ebSAurelien Jarno  *
81c0c13ebSAurelien Jarno  *  This program is free software; you can redistribute  it and/or modify it
91c0c13ebSAurelien Jarno  *  under  the terms of  the GNU General  Public License as published by the
101c0c13ebSAurelien Jarno  *  Free Software Foundation;  either version 2 of the  License, or (at your
111c0c13ebSAurelien Jarno  *  option) any later version.
121c0c13ebSAurelien Jarno  *
131c0c13ebSAurelien Jarno  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
141c0c13ebSAurelien Jarno  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
151c0c13ebSAurelien Jarno  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
161c0c13ebSAurelien Jarno  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
171c0c13ebSAurelien Jarno  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
181c0c13ebSAurelien Jarno  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
191c0c13ebSAurelien Jarno  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
201c0c13ebSAurelien Jarno  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
211c0c13ebSAurelien Jarno  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
221c0c13ebSAurelien Jarno  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
231c0c13ebSAurelien Jarno  *
241c0c13ebSAurelien Jarno  *  You should have received a copy of the  GNU General Public License along
251c0c13ebSAurelien Jarno  *  with this program; if not, write  to the Free Software Foundation, Inc.,
261c0c13ebSAurelien Jarno  *  675 Mass Ave, Cambridge, MA 02139, USA.
271c0c13ebSAurelien Jarno  */
281c0c13ebSAurelien Jarno 
291c0c13ebSAurelien Jarno #include <linux/types.h>
301c0c13ebSAurelien Jarno #include <linux/ssb/ssb.h>
31b06f3e19SAurelien Jarno #include <linux/ssb/ssb_embedded.h>
32*c1d1c5d4SHauke Mehrtens #include <linux/bcma/bcma_soc.h>
3325e5fb97SAurelien Jarno #include <asm/bootinfo.h>
341c0c13ebSAurelien Jarno #include <asm/reboot.h>
351c0c13ebSAurelien Jarno #include <asm/time.h>
361c0c13ebSAurelien Jarno #include <bcm47xx.h>
37121915c4SWaldemar Brodkorb #include <asm/mach-bcm47xx/nvram.h>
381c0c13ebSAurelien Jarno 
3908ccf572SHauke Mehrtens union bcm47xx_bus bcm47xx_bus;
4008ccf572SHauke Mehrtens EXPORT_SYMBOL(bcm47xx_bus);
4108ccf572SHauke Mehrtens 
4208ccf572SHauke Mehrtens enum bcm47xx_bus_type bcm47xx_bus_type;
4308ccf572SHauke Mehrtens EXPORT_SYMBOL(bcm47xx_bus_type);
441c0c13ebSAurelien Jarno 
451c0c13ebSAurelien Jarno static void bcm47xx_machine_restart(char *command)
461c0c13ebSAurelien Jarno {
471c0c13ebSAurelien Jarno 	printk(KERN_ALERT "Please stand by while rebooting the system...\n");
481c0c13ebSAurelien Jarno 	local_irq_disable();
491c0c13ebSAurelien Jarno 	/* Set the watchdog timer to reset immediately */
5008ccf572SHauke Mehrtens 	switch (bcm47xx_bus_type) {
51a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
5208ccf572SHauke Mehrtens 	case BCM47XX_BUS_TYPE_SSB:
5308ccf572SHauke Mehrtens 		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
5408ccf572SHauke Mehrtens 		break;
55a656ffcbSHauke Mehrtens #endif
56*c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
57*c1d1c5d4SHauke Mehrtens 	case BCM47XX_BUS_TYPE_BCMA:
58*c1d1c5d4SHauke Mehrtens 		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
59*c1d1c5d4SHauke Mehrtens 		break;
60*c1d1c5d4SHauke Mehrtens #endif
6108ccf572SHauke Mehrtens 	}
621c0c13ebSAurelien Jarno 	while (1)
631c0c13ebSAurelien Jarno 		cpu_relax();
641c0c13ebSAurelien Jarno }
651c0c13ebSAurelien Jarno 
661c0c13ebSAurelien Jarno static void bcm47xx_machine_halt(void)
671c0c13ebSAurelien Jarno {
681c0c13ebSAurelien Jarno 	/* Disable interrupts and watchdog and spin forever */
691c0c13ebSAurelien Jarno 	local_irq_disable();
7008ccf572SHauke Mehrtens 	switch (bcm47xx_bus_type) {
71a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
7208ccf572SHauke Mehrtens 	case BCM47XX_BUS_TYPE_SSB:
7308ccf572SHauke Mehrtens 		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
7408ccf572SHauke Mehrtens 		break;
75a656ffcbSHauke Mehrtens #endif
76*c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
77*c1d1c5d4SHauke Mehrtens 	case BCM47XX_BUS_TYPE_BCMA:
78*c1d1c5d4SHauke Mehrtens 		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
79*c1d1c5d4SHauke Mehrtens 		break;
80*c1d1c5d4SHauke Mehrtens #endif
8108ccf572SHauke Mehrtens 	}
821c0c13ebSAurelien Jarno 	while (1)
831c0c13ebSAurelien Jarno 		cpu_relax();
841c0c13ebSAurelien Jarno }
851c0c13ebSAurelien Jarno 
86a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
872aa088d6SHauke Mehrtens #define READ_FROM_NVRAM(_outvar, name, buf) \
88a7c62f85SHauke Mehrtens 	if (nvram_getprefix(prefix, name, buf, sizeof(buf)) >= 0)\
892aa088d6SHauke Mehrtens 		sprom->_outvar = simple_strtoul(buf, NULL, 0);
902aa088d6SHauke Mehrtens 
9141790fd5SHauke Mehrtens #define READ_FROM_NVRAM2(_outvar, name1, name2, buf) \
9241790fd5SHauke Mehrtens 	if (nvram_getprefix(prefix, name1, buf, sizeof(buf)) >= 0 || \
9341790fd5SHauke Mehrtens 	    nvram_getprefix(prefix, name2, buf, sizeof(buf)) >= 0)\
9441790fd5SHauke Mehrtens 		sprom->_outvar = simple_strtoul(buf, NULL, 0);
9541790fd5SHauke Mehrtens 
96a7c62f85SHauke Mehrtens static inline int nvram_getprefix(const char *prefix, char *name,
97a7c62f85SHauke Mehrtens 				  char *buf, int len)
98a7c62f85SHauke Mehrtens {
99a7c62f85SHauke Mehrtens 	if (prefix) {
100a7c62f85SHauke Mehrtens 		char key[100];
101a7c62f85SHauke Mehrtens 
102a7c62f85SHauke Mehrtens 		snprintf(key, sizeof(key), "%s%s", prefix, name);
103a7c62f85SHauke Mehrtens 		return nvram_getenv(key, buf, len);
104a7c62f85SHauke Mehrtens 	}
105a7c62f85SHauke Mehrtens 
106a7c62f85SHauke Mehrtens 	return nvram_getenv(name, buf, len);
107a7c62f85SHauke Mehrtens }
108a7c62f85SHauke Mehrtens 
10941790fd5SHauke Mehrtens static u32 nvram_getu32(const char *name, char *buf, int len)
11041790fd5SHauke Mehrtens {
11141790fd5SHauke Mehrtens 	int rv;
11241790fd5SHauke Mehrtens 	char key[100];
11341790fd5SHauke Mehrtens 	u16 var0, var1;
11441790fd5SHauke Mehrtens 
11541790fd5SHauke Mehrtens 	snprintf(key, sizeof(key), "%s0", name);
11641790fd5SHauke Mehrtens 	rv = nvram_getenv(key, buf, len);
11741790fd5SHauke Mehrtens 	/* return 0 here so this looks like unset */
11841790fd5SHauke Mehrtens 	if (rv < 0)
11941790fd5SHauke Mehrtens 		return 0;
12041790fd5SHauke Mehrtens 	var0 = simple_strtoul(buf, NULL, 0);
12141790fd5SHauke Mehrtens 
12241790fd5SHauke Mehrtens 	snprintf(key, sizeof(key), "%s1", name);
12341790fd5SHauke Mehrtens 	rv = nvram_getenv(key, buf, len);
12441790fd5SHauke Mehrtens 	if (rv < 0)
12541790fd5SHauke Mehrtens 		return 0;
12641790fd5SHauke Mehrtens 	var1 = simple_strtoul(buf, NULL, 0);
12741790fd5SHauke Mehrtens 	return var1 << 16 | var0;
12841790fd5SHauke Mehrtens }
12941790fd5SHauke Mehrtens 
130a7c62f85SHauke Mehrtens static void bcm47xx_fill_sprom(struct ssb_sprom *sprom, const char *prefix)
1312aa088d6SHauke Mehrtens {
1322aa088d6SHauke Mehrtens 	char buf[100];
1332aa088d6SHauke Mehrtens 	u32 boardflags;
1342aa088d6SHauke Mehrtens 
1352aa088d6SHauke Mehrtens 	memset(sprom, 0, sizeof(struct ssb_sprom));
1362aa088d6SHauke Mehrtens 
1372aa088d6SHauke Mehrtens 	sprom->revision = 1; /* Fallback: Old hardware does not define this. */
1382aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(revision, "sromrev", buf);
13941790fd5SHauke Mehrtens 	if (nvram_getprefix(prefix, "il0macaddr", buf, sizeof(buf)) >= 0 ||
14041790fd5SHauke Mehrtens 	    nvram_getprefix(prefix, "macaddr", buf, sizeof(buf)) >= 0)
14159833fcfSHauke Mehrtens 		nvram_parse_macaddr(buf, sprom->il0mac);
142a7c62f85SHauke Mehrtens 	if (nvram_getprefix(prefix, "et0macaddr", buf, sizeof(buf)) >= 0)
14359833fcfSHauke Mehrtens 		nvram_parse_macaddr(buf, sprom->et0mac);
144a7c62f85SHauke Mehrtens 	if (nvram_getprefix(prefix, "et1macaddr", buf, sizeof(buf)) >= 0)
14559833fcfSHauke Mehrtens 		nvram_parse_macaddr(buf, sprom->et1mac);
1462aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(et0phyaddr, "et0phyaddr", buf);
1472aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(et1phyaddr, "et1phyaddr", buf);
1482aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(et0mdcport, "et0mdcport", buf);
1492aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(et1mdcport, "et1mdcport", buf);
1502aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(board_rev, "boardrev", buf);
1512aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(country_code, "ccode", buf);
1522aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(ant_available_a, "aa5g", buf);
1532aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(ant_available_bg, "aa2g", buf);
1542aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa0b0, "pa0b0", buf);
1552aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa0b1, "pa0b1", buf);
1562aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa0b2, "pa0b2", buf);
1572aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1b0, "pa1b0", buf);
1582aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1b1, "pa1b1", buf);
1592aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1b2, "pa1b2", buf);
1602aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1lob0, "pa1lob0", buf);
1612aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1lob2, "pa1lob1", buf);
1622aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1lob1, "pa1lob2", buf);
1632aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1hib0, "pa1hib0", buf);
1642aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1hib2, "pa1hib1", buf);
1652aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(pa1hib1, "pa1hib2", buf);
16641790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(gpio0, "ledbh0", "wl0gpio0", buf);
16741790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(gpio1, "ledbh1", "wl0gpio1", buf);
16841790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(gpio2, "ledbh2", "wl0gpio2", buf);
16941790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(gpio3, "ledbh3", "wl0gpio3", buf);
17041790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(maxpwr_bg, "maxp2ga0", "pa0maxpwr", buf);
17141790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(maxpwr_al, "maxp5gla0", "pa1lomaxpwr", buf);
17241790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(maxpwr_a, "maxp5ga0", "pa1maxpwr", buf);
17341790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(maxpwr_ah, "maxp5gha0", "pa1himaxpwr", buf);
17441790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(itssi_bg, "itt5ga0", "pa0itssit", buf);
17541790fd5SHauke Mehrtens 	READ_FROM_NVRAM2(itssi_a, "itt2ga0", "pa1itssit", buf);
1762aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(tri2g, "tri2g", buf);
1772aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(tri5gl, "tri5gl", buf);
1782aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(tri5g, "tri5g", buf);
1792aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(tri5gh, "tri5gh", buf);
18041790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid2g[0], "txpid2ga0", buf);
18141790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid2g[1], "txpid2ga1", buf);
18241790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid2g[2], "txpid2ga2", buf);
18341790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid2g[3], "txpid2ga3", buf);
18441790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5g[0], "txpid5ga0", buf);
18541790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5g[1], "txpid5ga1", buf);
18641790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5g[2], "txpid5ga2", buf);
18741790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5g[3], "txpid5ga3", buf);
18841790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5gl[0], "txpid5gla0", buf);
18941790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5gl[1], "txpid5gla1", buf);
19041790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5gl[2], "txpid5gla2", buf);
19141790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5gl[3], "txpid5gla3", buf);
19241790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5gh[0], "txpid5gha0", buf);
19341790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5gh[1], "txpid5gha1", buf);
19441790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5gh[2], "txpid5gha2", buf);
19541790fd5SHauke Mehrtens 	READ_FROM_NVRAM(txpid5gh[3], "txpid5gha3", buf);
1962aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(rxpo2g, "rxpo2g", buf);
1972aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(rxpo5g, "rxpo5g", buf);
1982aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(rssisav2g, "rssisav2g", buf);
1992aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(rssismc2g, "rssismc2g", buf);
2002aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(rssismf2g, "rssismf2g", buf);
2012aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(bxa2g, "bxa2g", buf);
2022aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(rssisav5g, "rssisav5g", buf);
2032aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(rssismc5g, "rssismc5g", buf);
2042aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(rssismf5g, "rssismf5g", buf);
2052aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(bxa5g, "bxa5g", buf);
2062aa088d6SHauke Mehrtens 	READ_FROM_NVRAM(cck2gpo, "cck2gpo", buf);
20741790fd5SHauke Mehrtens 
20841790fd5SHauke Mehrtens 	sprom->ofdm2gpo = nvram_getu32("ofdm2gpo", buf, sizeof(buf));
20941790fd5SHauke Mehrtens 	sprom->ofdm5glpo = nvram_getu32("ofdm5glpo", buf, sizeof(buf));
21041790fd5SHauke Mehrtens 	sprom->ofdm5gpo = nvram_getu32("ofdm5gpo", buf, sizeof(buf));
21141790fd5SHauke Mehrtens 	sprom->ofdm5ghpo = nvram_getu32("ofdm5ghpo", buf, sizeof(buf));
21241790fd5SHauke Mehrtens 
21341790fd5SHauke Mehrtens 	READ_FROM_NVRAM(antenna_gain.ghz24.a0, "ag0", buf);
21441790fd5SHauke Mehrtens 	READ_FROM_NVRAM(antenna_gain.ghz24.a1, "ag1", buf);
21541790fd5SHauke Mehrtens 	READ_FROM_NVRAM(antenna_gain.ghz24.a2, "ag2", buf);
21641790fd5SHauke Mehrtens 	READ_FROM_NVRAM(antenna_gain.ghz24.a3, "ag3", buf);
21741790fd5SHauke Mehrtens 	memcpy(&sprom->antenna_gain.ghz5, &sprom->antenna_gain.ghz24,
21841790fd5SHauke Mehrtens 	       sizeof(sprom->antenna_gain.ghz5));
2192aa088d6SHauke Mehrtens 
220a7c62f85SHauke Mehrtens 	if (nvram_getprefix(prefix, "boardflags", buf, sizeof(buf)) >= 0) {
2212aa088d6SHauke Mehrtens 		boardflags = simple_strtoul(buf, NULL, 0);
2222aa088d6SHauke Mehrtens 		if (boardflags) {
2232aa088d6SHauke Mehrtens 			sprom->boardflags_lo = (boardflags & 0x0000FFFFU);
2242aa088d6SHauke Mehrtens 			sprom->boardflags_hi = (boardflags & 0xFFFF0000U) >> 16;
2252aa088d6SHauke Mehrtens 		}
2262aa088d6SHauke Mehrtens 	}
227a7c62f85SHauke Mehrtens 	if (nvram_getprefix(prefix, "boardflags2", buf, sizeof(buf)) >= 0) {
2282aa088d6SHauke Mehrtens 		boardflags = simple_strtoul(buf, NULL, 0);
2292aa088d6SHauke Mehrtens 		if (boardflags) {
2302aa088d6SHauke Mehrtens 			sprom->boardflags2_lo = (boardflags & 0x0000FFFFU);
2312aa088d6SHauke Mehrtens 			sprom->boardflags2_hi = (boardflags & 0xFFFF0000U) >> 16;
2322aa088d6SHauke Mehrtens 		}
2332aa088d6SHauke Mehrtens 	}
2342aa088d6SHauke Mehrtens }
2352aa088d6SHauke Mehrtens 
236fe6f3642SHauke Mehrtens int bcm47xx_get_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
237fe6f3642SHauke Mehrtens {
238fe6f3642SHauke Mehrtens 	char prefix[10];
239fe6f3642SHauke Mehrtens 
240fe6f3642SHauke Mehrtens 	if (bus->bustype == SSB_BUSTYPE_PCI) {
241fe6f3642SHauke Mehrtens 		snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
242fe6f3642SHauke Mehrtens 			 bus->host_pci->bus->number + 1,
243fe6f3642SHauke Mehrtens 			 PCI_SLOT(bus->host_pci->devfn));
244fe6f3642SHauke Mehrtens 		bcm47xx_fill_sprom(out, prefix);
245fe6f3642SHauke Mehrtens 		return 0;
246fe6f3642SHauke Mehrtens 	} else {
247fe6f3642SHauke Mehrtens 		printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n");
248fe6f3642SHauke Mehrtens 		return -EINVAL;
249fe6f3642SHauke Mehrtens 	}
250fe6f3642SHauke Mehrtens }
251fe6f3642SHauke Mehrtens 
2521c0c13ebSAurelien Jarno static int bcm47xx_get_invariants(struct ssb_bus *bus,
2531c0c13ebSAurelien Jarno 				   struct ssb_init_invariants *iv)
2541c0c13ebSAurelien Jarno {
2552aa088d6SHauke Mehrtens 	char buf[20];
25625e5fb97SAurelien Jarno 
25725e5fb97SAurelien Jarno 	/* Fill boardinfo structure */
25825e5fb97SAurelien Jarno 	memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
25925e5fb97SAurelien Jarno 
26082571084SHauke Mehrtens 	if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0)
2612aa088d6SHauke Mehrtens 		iv->boardinfo.vendor = (u16)simple_strtoul(buf, NULL, 0);
2622aa088d6SHauke Mehrtens 	else
2632aa088d6SHauke Mehrtens 		iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
26482571084SHauke Mehrtens 	if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
26525e5fb97SAurelien Jarno 		iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
26682571084SHauke Mehrtens 	if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
26725e5fb97SAurelien Jarno 		iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);
26825e5fb97SAurelien Jarno 
269a7c62f85SHauke Mehrtens 	bcm47xx_fill_sprom(&iv->sprom, NULL);
27025e5fb97SAurelien Jarno 
2712aa088d6SHauke Mehrtens 	if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
2722aa088d6SHauke Mehrtens 		iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
27325e5fb97SAurelien Jarno 
2741c0c13ebSAurelien Jarno 	return 0;
2751c0c13ebSAurelien Jarno }
2761c0c13ebSAurelien Jarno 
27708ccf572SHauke Mehrtens static void __init bcm47xx_register_ssb(void)
2781c0c13ebSAurelien Jarno {
2791c0c13ebSAurelien Jarno 	int err;
2801690a7f9SHauke Mehrtens 	char buf[100];
2811690a7f9SHauke Mehrtens 	struct ssb_mipscore *mcore;
2821c0c13ebSAurelien Jarno 
283fe6f3642SHauke Mehrtens 	err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom);
284fe6f3642SHauke Mehrtens 	if (err)
285fe6f3642SHauke Mehrtens 		printk(KERN_WARNING "bcm47xx: someone else already registered"
286fe6f3642SHauke Mehrtens 			" a ssb SPROM callback handler (err %d)\n", err);
287fe6f3642SHauke Mehrtens 
28808ccf572SHauke Mehrtens 	err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
2891c0c13ebSAurelien Jarno 				      bcm47xx_get_invariants);
2901c0c13ebSAurelien Jarno 	if (err)
2911c0c13ebSAurelien Jarno 		panic("Failed to initialize SSB bus (err %d)\n", err);
2921c0c13ebSAurelien Jarno 
29308ccf572SHauke Mehrtens 	mcore = &bcm47xx_bus.ssb.mipscore;
2941690a7f9SHauke Mehrtens 	if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
2951690a7f9SHauke Mehrtens 		if (strstr(buf, "console=ttyS1")) {
2961690a7f9SHauke Mehrtens 			struct ssb_serial_port port;
2971690a7f9SHauke Mehrtens 
2981690a7f9SHauke Mehrtens 			printk(KERN_DEBUG "Swapping serial ports!\n");
2991690a7f9SHauke Mehrtens 			/* swap serial ports */
3001690a7f9SHauke Mehrtens 			memcpy(&port, &mcore->serial_ports[0], sizeof(port));
3011690a7f9SHauke Mehrtens 			memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
3021690a7f9SHauke Mehrtens 			       sizeof(port));
3031690a7f9SHauke Mehrtens 			memcpy(&mcore->serial_ports[1], &port, sizeof(port));
3041690a7f9SHauke Mehrtens 		}
3051690a7f9SHauke Mehrtens 	}
30608ccf572SHauke Mehrtens }
307a656ffcbSHauke Mehrtens #endif
30808ccf572SHauke Mehrtens 
309*c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
310*c1d1c5d4SHauke Mehrtens static void __init bcm47xx_register_bcma(void)
311*c1d1c5d4SHauke Mehrtens {
312*c1d1c5d4SHauke Mehrtens 	int err;
313*c1d1c5d4SHauke Mehrtens 
314*c1d1c5d4SHauke Mehrtens 	err = bcma_host_soc_register(&bcm47xx_bus.bcma);
315*c1d1c5d4SHauke Mehrtens 	if (err)
316*c1d1c5d4SHauke Mehrtens 		panic("Failed to initialize BCMA bus (err %d)\n", err);
317*c1d1c5d4SHauke Mehrtens }
318*c1d1c5d4SHauke Mehrtens #endif
319*c1d1c5d4SHauke Mehrtens 
32008ccf572SHauke Mehrtens void __init plat_mem_setup(void)
32108ccf572SHauke Mehrtens {
32208ccf572SHauke Mehrtens 	struct cpuinfo_mips *c = &current_cpu_data;
32308ccf572SHauke Mehrtens 
324*c1d1c5d4SHauke Mehrtens 	if (c->cputype == CPU_74K) {
325*c1d1c5d4SHauke Mehrtens 		printk(KERN_INFO "bcm47xx: using bcma bus\n");
326*c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
327*c1d1c5d4SHauke Mehrtens 		bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
328*c1d1c5d4SHauke Mehrtens 		bcm47xx_register_bcma();
329*c1d1c5d4SHauke Mehrtens #endif
330*c1d1c5d4SHauke Mehrtens 	} else {
331*c1d1c5d4SHauke Mehrtens 		printk(KERN_INFO "bcm47xx: using ssb bus\n");
332a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
33308ccf572SHauke Mehrtens 		bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
33408ccf572SHauke Mehrtens 		bcm47xx_register_ssb();
335a656ffcbSHauke Mehrtens #endif
336*c1d1c5d4SHauke Mehrtens 	}
3371690a7f9SHauke Mehrtens 
3381c0c13ebSAurelien Jarno 	_machine_restart = bcm47xx_machine_restart;
3391c0c13ebSAurelien Jarno 	_machine_halt = bcm47xx_machine_halt;
3401c0c13ebSAurelien Jarno 	pm_power_off = bcm47xx_machine_halt;
3411c0c13ebSAurelien Jarno }
342*c1d1c5d4SHauke Mehrtens 
343*c1d1c5d4SHauke Mehrtens static int __init bcm47xx_register_bus_complete(void)
344*c1d1c5d4SHauke Mehrtens {
345*c1d1c5d4SHauke Mehrtens 	switch (bcm47xx_bus_type) {
346*c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
347*c1d1c5d4SHauke Mehrtens 	case BCM47XX_BUS_TYPE_SSB:
348*c1d1c5d4SHauke Mehrtens 		/* Nothing to do */
349*c1d1c5d4SHauke Mehrtens 		break;
350*c1d1c5d4SHauke Mehrtens #endif
351*c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
352*c1d1c5d4SHauke Mehrtens 	case BCM47XX_BUS_TYPE_BCMA:
353*c1d1c5d4SHauke Mehrtens 		bcma_bus_register(&bcm47xx_bus.bcma.bus);
354*c1d1c5d4SHauke Mehrtens 		break;
355*c1d1c5d4SHauke Mehrtens #endif
356*c1d1c5d4SHauke Mehrtens 	}
357*c1d1c5d4SHauke Mehrtens 	return 0;
358*c1d1c5d4SHauke Mehrtens }
359*c1d1c5d4SHauke Mehrtens device_initcall(bcm47xx_register_bus_complete);
360