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 29*cae39d13SPaul Gortmaker #include <linux/export.h> 301c0c13ebSAurelien Jarno #include <linux/types.h> 311c0c13ebSAurelien Jarno #include <linux/ssb/ssb.h> 32b06f3e19SAurelien Jarno #include <linux/ssb/ssb_embedded.h> 33c1d1c5d4SHauke Mehrtens #include <linux/bcma/bcma_soc.h> 3425e5fb97SAurelien Jarno #include <asm/bootinfo.h> 351c0c13ebSAurelien Jarno #include <asm/reboot.h> 361c0c13ebSAurelien Jarno #include <asm/time.h> 371c0c13ebSAurelien Jarno #include <bcm47xx.h> 38121915c4SWaldemar Brodkorb #include <asm/mach-bcm47xx/nvram.h> 391c0c13ebSAurelien Jarno 4008ccf572SHauke Mehrtens union bcm47xx_bus bcm47xx_bus; 4108ccf572SHauke Mehrtens EXPORT_SYMBOL(bcm47xx_bus); 4208ccf572SHauke Mehrtens 4308ccf572SHauke Mehrtens enum bcm47xx_bus_type bcm47xx_bus_type; 4408ccf572SHauke Mehrtens EXPORT_SYMBOL(bcm47xx_bus_type); 451c0c13ebSAurelien Jarno 461c0c13ebSAurelien Jarno static void bcm47xx_machine_restart(char *command) 471c0c13ebSAurelien Jarno { 481c0c13ebSAurelien Jarno printk(KERN_ALERT "Please stand by while rebooting the system...\n"); 491c0c13ebSAurelien Jarno local_irq_disable(); 501c0c13ebSAurelien Jarno /* Set the watchdog timer to reset immediately */ 5108ccf572SHauke Mehrtens switch (bcm47xx_bus_type) { 52a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 5308ccf572SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 5408ccf572SHauke Mehrtens ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1); 5508ccf572SHauke Mehrtens break; 56a656ffcbSHauke Mehrtens #endif 57c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 58c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 59c1d1c5d4SHauke Mehrtens bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1); 60c1d1c5d4SHauke Mehrtens break; 61c1d1c5d4SHauke Mehrtens #endif 6208ccf572SHauke Mehrtens } 631c0c13ebSAurelien Jarno while (1) 641c0c13ebSAurelien Jarno cpu_relax(); 651c0c13ebSAurelien Jarno } 661c0c13ebSAurelien Jarno 671c0c13ebSAurelien Jarno static void bcm47xx_machine_halt(void) 681c0c13ebSAurelien Jarno { 691c0c13ebSAurelien Jarno /* Disable interrupts and watchdog and spin forever */ 701c0c13ebSAurelien Jarno local_irq_disable(); 7108ccf572SHauke Mehrtens switch (bcm47xx_bus_type) { 72a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 7308ccf572SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 7408ccf572SHauke Mehrtens ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0); 7508ccf572SHauke Mehrtens break; 76a656ffcbSHauke Mehrtens #endif 77c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 78c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 79c1d1c5d4SHauke Mehrtens bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0); 80c1d1c5d4SHauke Mehrtens break; 81c1d1c5d4SHauke Mehrtens #endif 8208ccf572SHauke Mehrtens } 831c0c13ebSAurelien Jarno while (1) 841c0c13ebSAurelien Jarno cpu_relax(); 851c0c13ebSAurelien Jarno } 861c0c13ebSAurelien Jarno 87a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 882aa088d6SHauke Mehrtens #define READ_FROM_NVRAM(_outvar, name, buf) \ 89a7c62f85SHauke Mehrtens if (nvram_getprefix(prefix, name, buf, sizeof(buf)) >= 0)\ 902aa088d6SHauke Mehrtens sprom->_outvar = simple_strtoul(buf, NULL, 0); 912aa088d6SHauke Mehrtens 9241790fd5SHauke Mehrtens #define READ_FROM_NVRAM2(_outvar, name1, name2, buf) \ 9341790fd5SHauke Mehrtens if (nvram_getprefix(prefix, name1, buf, sizeof(buf)) >= 0 || \ 9441790fd5SHauke Mehrtens nvram_getprefix(prefix, name2, buf, sizeof(buf)) >= 0)\ 9541790fd5SHauke Mehrtens sprom->_outvar = simple_strtoul(buf, NULL, 0); 9641790fd5SHauke Mehrtens 97a7c62f85SHauke Mehrtens static inline int nvram_getprefix(const char *prefix, char *name, 98a7c62f85SHauke Mehrtens char *buf, int len) 99a7c62f85SHauke Mehrtens { 100a7c62f85SHauke Mehrtens if (prefix) { 101a7c62f85SHauke Mehrtens char key[100]; 102a7c62f85SHauke Mehrtens 103a7c62f85SHauke Mehrtens snprintf(key, sizeof(key), "%s%s", prefix, name); 104a7c62f85SHauke Mehrtens return nvram_getenv(key, buf, len); 105a7c62f85SHauke Mehrtens } 106a7c62f85SHauke Mehrtens 107a7c62f85SHauke Mehrtens return nvram_getenv(name, buf, len); 108a7c62f85SHauke Mehrtens } 109a7c62f85SHauke Mehrtens 11041790fd5SHauke Mehrtens static u32 nvram_getu32(const char *name, char *buf, int len) 11141790fd5SHauke Mehrtens { 11241790fd5SHauke Mehrtens int rv; 11341790fd5SHauke Mehrtens char key[100]; 11441790fd5SHauke Mehrtens u16 var0, var1; 11541790fd5SHauke Mehrtens 11641790fd5SHauke Mehrtens snprintf(key, sizeof(key), "%s0", name); 11741790fd5SHauke Mehrtens rv = nvram_getenv(key, buf, len); 11841790fd5SHauke Mehrtens /* return 0 here so this looks like unset */ 11941790fd5SHauke Mehrtens if (rv < 0) 12041790fd5SHauke Mehrtens return 0; 12141790fd5SHauke Mehrtens var0 = simple_strtoul(buf, NULL, 0); 12241790fd5SHauke Mehrtens 12341790fd5SHauke Mehrtens snprintf(key, sizeof(key), "%s1", name); 12441790fd5SHauke Mehrtens rv = nvram_getenv(key, buf, len); 12541790fd5SHauke Mehrtens if (rv < 0) 12641790fd5SHauke Mehrtens return 0; 12741790fd5SHauke Mehrtens var1 = simple_strtoul(buf, NULL, 0); 12841790fd5SHauke Mehrtens return var1 << 16 | var0; 12941790fd5SHauke Mehrtens } 13041790fd5SHauke Mehrtens 131a7c62f85SHauke Mehrtens static void bcm47xx_fill_sprom(struct ssb_sprom *sprom, const char *prefix) 1322aa088d6SHauke Mehrtens { 1332aa088d6SHauke Mehrtens char buf[100]; 1342aa088d6SHauke Mehrtens u32 boardflags; 1352aa088d6SHauke Mehrtens 1362aa088d6SHauke Mehrtens memset(sprom, 0, sizeof(struct ssb_sprom)); 1372aa088d6SHauke Mehrtens 1382aa088d6SHauke Mehrtens sprom->revision = 1; /* Fallback: Old hardware does not define this. */ 1392aa088d6SHauke Mehrtens READ_FROM_NVRAM(revision, "sromrev", buf); 14041790fd5SHauke Mehrtens if (nvram_getprefix(prefix, "il0macaddr", buf, sizeof(buf)) >= 0 || 14141790fd5SHauke Mehrtens nvram_getprefix(prefix, "macaddr", buf, sizeof(buf)) >= 0) 14259833fcfSHauke Mehrtens nvram_parse_macaddr(buf, sprom->il0mac); 143a7c62f85SHauke Mehrtens if (nvram_getprefix(prefix, "et0macaddr", buf, sizeof(buf)) >= 0) 14459833fcfSHauke Mehrtens nvram_parse_macaddr(buf, sprom->et0mac); 145a7c62f85SHauke Mehrtens if (nvram_getprefix(prefix, "et1macaddr", buf, sizeof(buf)) >= 0) 14659833fcfSHauke Mehrtens nvram_parse_macaddr(buf, sprom->et1mac); 1472aa088d6SHauke Mehrtens READ_FROM_NVRAM(et0phyaddr, "et0phyaddr", buf); 1482aa088d6SHauke Mehrtens READ_FROM_NVRAM(et1phyaddr, "et1phyaddr", buf); 1492aa088d6SHauke Mehrtens READ_FROM_NVRAM(et0mdcport, "et0mdcport", buf); 1502aa088d6SHauke Mehrtens READ_FROM_NVRAM(et1mdcport, "et1mdcport", buf); 1512aa088d6SHauke Mehrtens READ_FROM_NVRAM(board_rev, "boardrev", buf); 1522aa088d6SHauke Mehrtens READ_FROM_NVRAM(country_code, "ccode", buf); 1532aa088d6SHauke Mehrtens READ_FROM_NVRAM(ant_available_a, "aa5g", buf); 1542aa088d6SHauke Mehrtens READ_FROM_NVRAM(ant_available_bg, "aa2g", buf); 1552aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa0b0, "pa0b0", buf); 1562aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa0b1, "pa0b1", buf); 1572aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa0b2, "pa0b2", buf); 1582aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1b0, "pa1b0", buf); 1592aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1b1, "pa1b1", buf); 1602aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1b2, "pa1b2", buf); 1612aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1lob0, "pa1lob0", buf); 1622aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1lob2, "pa1lob1", buf); 1632aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1lob1, "pa1lob2", buf); 1642aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1hib0, "pa1hib0", buf); 1652aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1hib2, "pa1hib1", buf); 1662aa088d6SHauke Mehrtens READ_FROM_NVRAM(pa1hib1, "pa1hib2", buf); 16741790fd5SHauke Mehrtens READ_FROM_NVRAM2(gpio0, "ledbh0", "wl0gpio0", buf); 16841790fd5SHauke Mehrtens READ_FROM_NVRAM2(gpio1, "ledbh1", "wl0gpio1", buf); 16941790fd5SHauke Mehrtens READ_FROM_NVRAM2(gpio2, "ledbh2", "wl0gpio2", buf); 17041790fd5SHauke Mehrtens READ_FROM_NVRAM2(gpio3, "ledbh3", "wl0gpio3", buf); 17141790fd5SHauke Mehrtens READ_FROM_NVRAM2(maxpwr_bg, "maxp2ga0", "pa0maxpwr", buf); 17241790fd5SHauke Mehrtens READ_FROM_NVRAM2(maxpwr_al, "maxp5gla0", "pa1lomaxpwr", buf); 17341790fd5SHauke Mehrtens READ_FROM_NVRAM2(maxpwr_a, "maxp5ga0", "pa1maxpwr", buf); 17441790fd5SHauke Mehrtens READ_FROM_NVRAM2(maxpwr_ah, "maxp5gha0", "pa1himaxpwr", buf); 17541790fd5SHauke Mehrtens READ_FROM_NVRAM2(itssi_bg, "itt5ga0", "pa0itssit", buf); 17641790fd5SHauke Mehrtens READ_FROM_NVRAM2(itssi_a, "itt2ga0", "pa1itssit", buf); 1772aa088d6SHauke Mehrtens READ_FROM_NVRAM(tri2g, "tri2g", buf); 1782aa088d6SHauke Mehrtens READ_FROM_NVRAM(tri5gl, "tri5gl", buf); 1792aa088d6SHauke Mehrtens READ_FROM_NVRAM(tri5g, "tri5g", buf); 1802aa088d6SHauke Mehrtens READ_FROM_NVRAM(tri5gh, "tri5gh", buf); 18141790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid2g[0], "txpid2ga0", buf); 18241790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid2g[1], "txpid2ga1", buf); 18341790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid2g[2], "txpid2ga2", buf); 18441790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid2g[3], "txpid2ga3", buf); 18541790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5g[0], "txpid5ga0", buf); 18641790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5g[1], "txpid5ga1", buf); 18741790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5g[2], "txpid5ga2", buf); 18841790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5g[3], "txpid5ga3", buf); 18941790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5gl[0], "txpid5gla0", buf); 19041790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5gl[1], "txpid5gla1", buf); 19141790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5gl[2], "txpid5gla2", buf); 19241790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5gl[3], "txpid5gla3", buf); 19341790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5gh[0], "txpid5gha0", buf); 19441790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5gh[1], "txpid5gha1", buf); 19541790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5gh[2], "txpid5gha2", buf); 19641790fd5SHauke Mehrtens READ_FROM_NVRAM(txpid5gh[3], "txpid5gha3", buf); 1972aa088d6SHauke Mehrtens READ_FROM_NVRAM(rxpo2g, "rxpo2g", buf); 1982aa088d6SHauke Mehrtens READ_FROM_NVRAM(rxpo5g, "rxpo5g", buf); 1992aa088d6SHauke Mehrtens READ_FROM_NVRAM(rssisav2g, "rssisav2g", buf); 2002aa088d6SHauke Mehrtens READ_FROM_NVRAM(rssismc2g, "rssismc2g", buf); 2012aa088d6SHauke Mehrtens READ_FROM_NVRAM(rssismf2g, "rssismf2g", buf); 2022aa088d6SHauke Mehrtens READ_FROM_NVRAM(bxa2g, "bxa2g", buf); 2032aa088d6SHauke Mehrtens READ_FROM_NVRAM(rssisav5g, "rssisav5g", buf); 2042aa088d6SHauke Mehrtens READ_FROM_NVRAM(rssismc5g, "rssismc5g", buf); 2052aa088d6SHauke Mehrtens READ_FROM_NVRAM(rssismf5g, "rssismf5g", buf); 2062aa088d6SHauke Mehrtens READ_FROM_NVRAM(bxa5g, "bxa5g", buf); 2072aa088d6SHauke Mehrtens READ_FROM_NVRAM(cck2gpo, "cck2gpo", buf); 20841790fd5SHauke Mehrtens 20941790fd5SHauke Mehrtens sprom->ofdm2gpo = nvram_getu32("ofdm2gpo", buf, sizeof(buf)); 21041790fd5SHauke Mehrtens sprom->ofdm5glpo = nvram_getu32("ofdm5glpo", buf, sizeof(buf)); 21141790fd5SHauke Mehrtens sprom->ofdm5gpo = nvram_getu32("ofdm5gpo", buf, sizeof(buf)); 21241790fd5SHauke Mehrtens sprom->ofdm5ghpo = nvram_getu32("ofdm5ghpo", buf, sizeof(buf)); 21341790fd5SHauke Mehrtens 21441790fd5SHauke Mehrtens READ_FROM_NVRAM(antenna_gain.ghz24.a0, "ag0", buf); 21541790fd5SHauke Mehrtens READ_FROM_NVRAM(antenna_gain.ghz24.a1, "ag1", buf); 21641790fd5SHauke Mehrtens READ_FROM_NVRAM(antenna_gain.ghz24.a2, "ag2", buf); 21741790fd5SHauke Mehrtens READ_FROM_NVRAM(antenna_gain.ghz24.a3, "ag3", buf); 21841790fd5SHauke Mehrtens memcpy(&sprom->antenna_gain.ghz5, &sprom->antenna_gain.ghz24, 21941790fd5SHauke Mehrtens sizeof(sprom->antenna_gain.ghz5)); 2202aa088d6SHauke Mehrtens 221a7c62f85SHauke Mehrtens if (nvram_getprefix(prefix, "boardflags", buf, sizeof(buf)) >= 0) { 2222aa088d6SHauke Mehrtens boardflags = simple_strtoul(buf, NULL, 0); 2232aa088d6SHauke Mehrtens if (boardflags) { 2242aa088d6SHauke Mehrtens sprom->boardflags_lo = (boardflags & 0x0000FFFFU); 2252aa088d6SHauke Mehrtens sprom->boardflags_hi = (boardflags & 0xFFFF0000U) >> 16; 2262aa088d6SHauke Mehrtens } 2272aa088d6SHauke Mehrtens } 228a7c62f85SHauke Mehrtens if (nvram_getprefix(prefix, "boardflags2", buf, sizeof(buf)) >= 0) { 2292aa088d6SHauke Mehrtens boardflags = simple_strtoul(buf, NULL, 0); 2302aa088d6SHauke Mehrtens if (boardflags) { 2312aa088d6SHauke Mehrtens sprom->boardflags2_lo = (boardflags & 0x0000FFFFU); 2322aa088d6SHauke Mehrtens sprom->boardflags2_hi = (boardflags & 0xFFFF0000U) >> 16; 2332aa088d6SHauke Mehrtens } 2342aa088d6SHauke Mehrtens } 2352aa088d6SHauke Mehrtens } 2362aa088d6SHauke Mehrtens 237fe6f3642SHauke Mehrtens int bcm47xx_get_sprom(struct ssb_bus *bus, struct ssb_sprom *out) 238fe6f3642SHauke Mehrtens { 239fe6f3642SHauke Mehrtens char prefix[10]; 240fe6f3642SHauke Mehrtens 241fe6f3642SHauke Mehrtens if (bus->bustype == SSB_BUSTYPE_PCI) { 242fe6f3642SHauke Mehrtens snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 243fe6f3642SHauke Mehrtens bus->host_pci->bus->number + 1, 244fe6f3642SHauke Mehrtens PCI_SLOT(bus->host_pci->devfn)); 245fe6f3642SHauke Mehrtens bcm47xx_fill_sprom(out, prefix); 246fe6f3642SHauke Mehrtens return 0; 247fe6f3642SHauke Mehrtens } else { 248fe6f3642SHauke Mehrtens printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n"); 249fe6f3642SHauke Mehrtens return -EINVAL; 250fe6f3642SHauke Mehrtens } 251fe6f3642SHauke Mehrtens } 252fe6f3642SHauke Mehrtens 2531c0c13ebSAurelien Jarno static int bcm47xx_get_invariants(struct ssb_bus *bus, 2541c0c13ebSAurelien Jarno struct ssb_init_invariants *iv) 2551c0c13ebSAurelien Jarno { 2562aa088d6SHauke Mehrtens char buf[20]; 25725e5fb97SAurelien Jarno 25825e5fb97SAurelien Jarno /* Fill boardinfo structure */ 25925e5fb97SAurelien Jarno memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo)); 26025e5fb97SAurelien Jarno 26182571084SHauke Mehrtens if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0) 2622aa088d6SHauke Mehrtens iv->boardinfo.vendor = (u16)simple_strtoul(buf, NULL, 0); 2632aa088d6SHauke Mehrtens else 2642aa088d6SHauke Mehrtens iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM; 26582571084SHauke Mehrtens if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0) 26625e5fb97SAurelien Jarno iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0); 26782571084SHauke Mehrtens if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0) 26825e5fb97SAurelien Jarno iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0); 26925e5fb97SAurelien Jarno 270a7c62f85SHauke Mehrtens bcm47xx_fill_sprom(&iv->sprom, NULL); 27125e5fb97SAurelien Jarno 2722aa088d6SHauke Mehrtens if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0) 2732aa088d6SHauke Mehrtens iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10); 27425e5fb97SAurelien Jarno 2751c0c13ebSAurelien Jarno return 0; 2761c0c13ebSAurelien Jarno } 2771c0c13ebSAurelien Jarno 27808ccf572SHauke Mehrtens static void __init bcm47xx_register_ssb(void) 2791c0c13ebSAurelien Jarno { 2801c0c13ebSAurelien Jarno int err; 2811690a7f9SHauke Mehrtens char buf[100]; 2821690a7f9SHauke Mehrtens struct ssb_mipscore *mcore; 2831c0c13ebSAurelien Jarno 284fe6f3642SHauke Mehrtens err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom); 285fe6f3642SHauke Mehrtens if (err) 286fe6f3642SHauke Mehrtens printk(KERN_WARNING "bcm47xx: someone else already registered" 287fe6f3642SHauke Mehrtens " a ssb SPROM callback handler (err %d)\n", err); 288fe6f3642SHauke Mehrtens 28908ccf572SHauke Mehrtens err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE, 2901c0c13ebSAurelien Jarno bcm47xx_get_invariants); 2911c0c13ebSAurelien Jarno if (err) 2921c0c13ebSAurelien Jarno panic("Failed to initialize SSB bus (err %d)\n", err); 2931c0c13ebSAurelien Jarno 29408ccf572SHauke Mehrtens mcore = &bcm47xx_bus.ssb.mipscore; 2951690a7f9SHauke Mehrtens if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) { 2961690a7f9SHauke Mehrtens if (strstr(buf, "console=ttyS1")) { 2971690a7f9SHauke Mehrtens struct ssb_serial_port port; 2981690a7f9SHauke Mehrtens 2991690a7f9SHauke Mehrtens printk(KERN_DEBUG "Swapping serial ports!\n"); 3001690a7f9SHauke Mehrtens /* swap serial ports */ 3011690a7f9SHauke Mehrtens memcpy(&port, &mcore->serial_ports[0], sizeof(port)); 3021690a7f9SHauke Mehrtens memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1], 3031690a7f9SHauke Mehrtens sizeof(port)); 3041690a7f9SHauke Mehrtens memcpy(&mcore->serial_ports[1], &port, sizeof(port)); 3051690a7f9SHauke Mehrtens } 3061690a7f9SHauke Mehrtens } 30708ccf572SHauke Mehrtens } 308a656ffcbSHauke Mehrtens #endif 30908ccf572SHauke Mehrtens 310c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 311c1d1c5d4SHauke Mehrtens static void __init bcm47xx_register_bcma(void) 312c1d1c5d4SHauke Mehrtens { 313c1d1c5d4SHauke Mehrtens int err; 314c1d1c5d4SHauke Mehrtens 315c1d1c5d4SHauke Mehrtens err = bcma_host_soc_register(&bcm47xx_bus.bcma); 316c1d1c5d4SHauke Mehrtens if (err) 317c1d1c5d4SHauke Mehrtens panic("Failed to initialize BCMA bus (err %d)\n", err); 318c1d1c5d4SHauke Mehrtens } 319c1d1c5d4SHauke Mehrtens #endif 320c1d1c5d4SHauke Mehrtens 32108ccf572SHauke Mehrtens void __init plat_mem_setup(void) 32208ccf572SHauke Mehrtens { 32308ccf572SHauke Mehrtens struct cpuinfo_mips *c = ¤t_cpu_data; 32408ccf572SHauke Mehrtens 325c1d1c5d4SHauke Mehrtens if (c->cputype == CPU_74K) { 326c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using bcma bus\n"); 327c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 328c1d1c5d4SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA; 329c1d1c5d4SHauke Mehrtens bcm47xx_register_bcma(); 330c1d1c5d4SHauke Mehrtens #endif 331c1d1c5d4SHauke Mehrtens } else { 332c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using ssb bus\n"); 333a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 33408ccf572SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB; 33508ccf572SHauke Mehrtens bcm47xx_register_ssb(); 336a656ffcbSHauke Mehrtens #endif 337c1d1c5d4SHauke Mehrtens } 3381690a7f9SHauke Mehrtens 3391c0c13ebSAurelien Jarno _machine_restart = bcm47xx_machine_restart; 3401c0c13ebSAurelien Jarno _machine_halt = bcm47xx_machine_halt; 3411c0c13ebSAurelien Jarno pm_power_off = bcm47xx_machine_halt; 3421c0c13ebSAurelien Jarno } 343c1d1c5d4SHauke Mehrtens 344c1d1c5d4SHauke Mehrtens static int __init bcm47xx_register_bus_complete(void) 345c1d1c5d4SHauke Mehrtens { 346c1d1c5d4SHauke Mehrtens switch (bcm47xx_bus_type) { 347c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 348c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 349c1d1c5d4SHauke Mehrtens /* Nothing to do */ 350c1d1c5d4SHauke Mehrtens break; 351c1d1c5d4SHauke Mehrtens #endif 352c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 353c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 354c1d1c5d4SHauke Mehrtens bcma_bus_register(&bcm47xx_bus.bcma.bus); 355c1d1c5d4SHauke Mehrtens break; 356c1d1c5d4SHauke Mehrtens #endif 357c1d1c5d4SHauke Mehrtens } 358c1d1c5d4SHauke Mehrtens return 0; 359c1d1c5d4SHauke Mehrtens } 360c1d1c5d4SHauke Mehrtens device_initcall(bcm47xx_register_bus_complete); 361