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> 6*f384b3ddSHauke Mehrtens * Copyright (C) 2010-2012 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 29cae39d13SPaul 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 88*f384b3ddSHauke Mehrtens static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out) 89fe6f3642SHauke Mehrtens { 90fe6f3642SHauke Mehrtens char prefix[10]; 91fe6f3642SHauke Mehrtens 92fe6f3642SHauke Mehrtens if (bus->bustype == SSB_BUSTYPE_PCI) { 93fe6f3642SHauke Mehrtens snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 94fe6f3642SHauke Mehrtens bus->host_pci->bus->number + 1, 95fe6f3642SHauke Mehrtens PCI_SLOT(bus->host_pci->devfn)); 96fe6f3642SHauke Mehrtens bcm47xx_fill_sprom(out, prefix); 97fe6f3642SHauke Mehrtens return 0; 98fe6f3642SHauke Mehrtens } else { 99fe6f3642SHauke Mehrtens printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n"); 100fe6f3642SHauke Mehrtens return -EINVAL; 101fe6f3642SHauke Mehrtens } 102fe6f3642SHauke Mehrtens } 103fe6f3642SHauke Mehrtens 1041c0c13ebSAurelien Jarno static int bcm47xx_get_invariants(struct ssb_bus *bus, 1051c0c13ebSAurelien Jarno struct ssb_init_invariants *iv) 1061c0c13ebSAurelien Jarno { 1072aa088d6SHauke Mehrtens char buf[20]; 10825e5fb97SAurelien Jarno 10925e5fb97SAurelien Jarno /* Fill boardinfo structure */ 11025e5fb97SAurelien Jarno memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo)); 11125e5fb97SAurelien Jarno 11282571084SHauke Mehrtens if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0) 1132aa088d6SHauke Mehrtens iv->boardinfo.vendor = (u16)simple_strtoul(buf, NULL, 0); 1142aa088d6SHauke Mehrtens else 1152aa088d6SHauke Mehrtens iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM; 11682571084SHauke Mehrtens if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0) 11725e5fb97SAurelien Jarno iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0); 11882571084SHauke Mehrtens if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0) 11925e5fb97SAurelien Jarno iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0); 12025e5fb97SAurelien Jarno 121a7c62f85SHauke Mehrtens bcm47xx_fill_sprom(&iv->sprom, NULL); 12225e5fb97SAurelien Jarno 1232aa088d6SHauke Mehrtens if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0) 1242aa088d6SHauke Mehrtens iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10); 12525e5fb97SAurelien Jarno 1261c0c13ebSAurelien Jarno return 0; 1271c0c13ebSAurelien Jarno } 1281c0c13ebSAurelien Jarno 12908ccf572SHauke Mehrtens static void __init bcm47xx_register_ssb(void) 1301c0c13ebSAurelien Jarno { 1311c0c13ebSAurelien Jarno int err; 1321690a7f9SHauke Mehrtens char buf[100]; 1331690a7f9SHauke Mehrtens struct ssb_mipscore *mcore; 1341c0c13ebSAurelien Jarno 135*f384b3ddSHauke Mehrtens err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb); 136fe6f3642SHauke Mehrtens if (err) 137fe6f3642SHauke Mehrtens printk(KERN_WARNING "bcm47xx: someone else already registered" 138fe6f3642SHauke Mehrtens " a ssb SPROM callback handler (err %d)\n", err); 139fe6f3642SHauke Mehrtens 14008ccf572SHauke Mehrtens err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE, 1411c0c13ebSAurelien Jarno bcm47xx_get_invariants); 1421c0c13ebSAurelien Jarno if (err) 143ab75dc02SRalf Baechle panic("Failed to initialize SSB bus (err %d)", err); 1441c0c13ebSAurelien Jarno 14508ccf572SHauke Mehrtens mcore = &bcm47xx_bus.ssb.mipscore; 1461690a7f9SHauke Mehrtens if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) { 1471690a7f9SHauke Mehrtens if (strstr(buf, "console=ttyS1")) { 1481690a7f9SHauke Mehrtens struct ssb_serial_port port; 1491690a7f9SHauke Mehrtens 1501690a7f9SHauke Mehrtens printk(KERN_DEBUG "Swapping serial ports!\n"); 1511690a7f9SHauke Mehrtens /* swap serial ports */ 1521690a7f9SHauke Mehrtens memcpy(&port, &mcore->serial_ports[0], sizeof(port)); 1531690a7f9SHauke Mehrtens memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1], 1541690a7f9SHauke Mehrtens sizeof(port)); 1551690a7f9SHauke Mehrtens memcpy(&mcore->serial_ports[1], &port, sizeof(port)); 1561690a7f9SHauke Mehrtens } 1571690a7f9SHauke Mehrtens } 15808ccf572SHauke Mehrtens } 159a656ffcbSHauke Mehrtens #endif 16008ccf572SHauke Mehrtens 161c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 162*f384b3ddSHauke Mehrtens static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out) 163*f384b3ddSHauke Mehrtens { 164*f384b3ddSHauke Mehrtens char prefix[10]; 165*f384b3ddSHauke Mehrtens struct bcma_device *core; 166*f384b3ddSHauke Mehrtens 167*f384b3ddSHauke Mehrtens switch (bus->hosttype) { 168*f384b3ddSHauke Mehrtens case BCMA_HOSTTYPE_PCI: 169*f384b3ddSHauke Mehrtens snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 170*f384b3ddSHauke Mehrtens bus->host_pci->bus->number + 1, 171*f384b3ddSHauke Mehrtens PCI_SLOT(bus->host_pci->devfn)); 172*f384b3ddSHauke Mehrtens bcm47xx_fill_sprom(out, prefix); 173*f384b3ddSHauke Mehrtens return 0; 174*f384b3ddSHauke Mehrtens case BCMA_HOSTTYPE_SOC: 175*f384b3ddSHauke Mehrtens bcm47xx_fill_sprom_ethernet(out, NULL); 176*f384b3ddSHauke Mehrtens core = bcma_find_core(bus, BCMA_CORE_80211); 177*f384b3ddSHauke Mehrtens if (core) { 178*f384b3ddSHauke Mehrtens snprintf(prefix, sizeof(prefix), "sb/%u/", 179*f384b3ddSHauke Mehrtens core->core_index); 180*f384b3ddSHauke Mehrtens bcm47xx_fill_sprom(out, prefix); 181*f384b3ddSHauke Mehrtens } 182*f384b3ddSHauke Mehrtens return 0; 183*f384b3ddSHauke Mehrtens default: 184*f384b3ddSHauke Mehrtens pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n"); 185*f384b3ddSHauke Mehrtens return -EINVAL; 186*f384b3ddSHauke Mehrtens } 187*f384b3ddSHauke Mehrtens } 188*f384b3ddSHauke Mehrtens 189c1d1c5d4SHauke Mehrtens static void __init bcm47xx_register_bcma(void) 190c1d1c5d4SHauke Mehrtens { 191c1d1c5d4SHauke Mehrtens int err; 192c1d1c5d4SHauke Mehrtens 193*f384b3ddSHauke Mehrtens err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma); 194*f384b3ddSHauke Mehrtens if (err) 195*f384b3ddSHauke Mehrtens pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err); 196*f384b3ddSHauke Mehrtens 197c1d1c5d4SHauke Mehrtens err = bcma_host_soc_register(&bcm47xx_bus.bcma); 198c1d1c5d4SHauke Mehrtens if (err) 199ab75dc02SRalf Baechle panic("Failed to initialize BCMA bus (err %d)", err); 200c1d1c5d4SHauke Mehrtens } 201c1d1c5d4SHauke Mehrtens #endif 202c1d1c5d4SHauke Mehrtens 20308ccf572SHauke Mehrtens void __init plat_mem_setup(void) 20408ccf572SHauke Mehrtens { 20508ccf572SHauke Mehrtens struct cpuinfo_mips *c = ¤t_cpu_data; 20608ccf572SHauke Mehrtens 207c1d1c5d4SHauke Mehrtens if (c->cputype == CPU_74K) { 208c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using bcma bus\n"); 209c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 210c1d1c5d4SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA; 211c1d1c5d4SHauke Mehrtens bcm47xx_register_bcma(); 212c1d1c5d4SHauke Mehrtens #endif 213c1d1c5d4SHauke Mehrtens } else { 214c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using ssb bus\n"); 215a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 21608ccf572SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB; 21708ccf572SHauke Mehrtens bcm47xx_register_ssb(); 218a656ffcbSHauke Mehrtens #endif 219c1d1c5d4SHauke Mehrtens } 2201690a7f9SHauke Mehrtens 2211c0c13ebSAurelien Jarno _machine_restart = bcm47xx_machine_restart; 2221c0c13ebSAurelien Jarno _machine_halt = bcm47xx_machine_halt; 2231c0c13ebSAurelien Jarno pm_power_off = bcm47xx_machine_halt; 2241c0c13ebSAurelien Jarno } 225c1d1c5d4SHauke Mehrtens 226c1d1c5d4SHauke Mehrtens static int __init bcm47xx_register_bus_complete(void) 227c1d1c5d4SHauke Mehrtens { 228c1d1c5d4SHauke Mehrtens switch (bcm47xx_bus_type) { 229c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 230c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 231c1d1c5d4SHauke Mehrtens /* Nothing to do */ 232c1d1c5d4SHauke Mehrtens break; 233c1d1c5d4SHauke Mehrtens #endif 234c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 235c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 236c1d1c5d4SHauke Mehrtens bcma_bus_register(&bcm47xx_bus.bcma.bus); 237c1d1c5d4SHauke Mehrtens break; 238c1d1c5d4SHauke Mehrtens #endif 239c1d1c5d4SHauke Mehrtens } 240c1d1c5d4SHauke Mehrtens return 0; 241c1d1c5d4SHauke Mehrtens } 242c1d1c5d4SHauke Mehrtens device_initcall(bcm47xx_register_bus_complete); 243