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> 6f384b3ddSHauke 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 88f384b3ddSHauke 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 112*a9bba182SHauke Mehrtens bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL); 11325e5fb97SAurelien Jarno 114a7c62f85SHauke Mehrtens bcm47xx_fill_sprom(&iv->sprom, NULL); 11525e5fb97SAurelien Jarno 1162aa088d6SHauke Mehrtens if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0) 1172aa088d6SHauke Mehrtens iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10); 11825e5fb97SAurelien Jarno 1191c0c13ebSAurelien Jarno return 0; 1201c0c13ebSAurelien Jarno } 1211c0c13ebSAurelien Jarno 12208ccf572SHauke Mehrtens static void __init bcm47xx_register_ssb(void) 1231c0c13ebSAurelien Jarno { 1241c0c13ebSAurelien Jarno int err; 1251690a7f9SHauke Mehrtens char buf[100]; 1261690a7f9SHauke Mehrtens struct ssb_mipscore *mcore; 1271c0c13ebSAurelien Jarno 128f384b3ddSHauke Mehrtens err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb); 129fe6f3642SHauke Mehrtens if (err) 130fe6f3642SHauke Mehrtens printk(KERN_WARNING "bcm47xx: someone else already registered" 131fe6f3642SHauke Mehrtens " a ssb SPROM callback handler (err %d)\n", err); 132fe6f3642SHauke Mehrtens 13308ccf572SHauke Mehrtens err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE, 1341c0c13ebSAurelien Jarno bcm47xx_get_invariants); 1351c0c13ebSAurelien Jarno if (err) 136ab75dc02SRalf Baechle panic("Failed to initialize SSB bus (err %d)", err); 1371c0c13ebSAurelien Jarno 13808ccf572SHauke Mehrtens mcore = &bcm47xx_bus.ssb.mipscore; 1391690a7f9SHauke Mehrtens if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) { 1401690a7f9SHauke Mehrtens if (strstr(buf, "console=ttyS1")) { 1411690a7f9SHauke Mehrtens struct ssb_serial_port port; 1421690a7f9SHauke Mehrtens 1431690a7f9SHauke Mehrtens printk(KERN_DEBUG "Swapping serial ports!\n"); 1441690a7f9SHauke Mehrtens /* swap serial ports */ 1451690a7f9SHauke Mehrtens memcpy(&port, &mcore->serial_ports[0], sizeof(port)); 1461690a7f9SHauke Mehrtens memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1], 1471690a7f9SHauke Mehrtens sizeof(port)); 1481690a7f9SHauke Mehrtens memcpy(&mcore->serial_ports[1], &port, sizeof(port)); 1491690a7f9SHauke Mehrtens } 1501690a7f9SHauke Mehrtens } 15108ccf572SHauke Mehrtens } 152a656ffcbSHauke Mehrtens #endif 15308ccf572SHauke Mehrtens 154c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 155f384b3ddSHauke Mehrtens static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out) 156f384b3ddSHauke Mehrtens { 157f384b3ddSHauke Mehrtens char prefix[10]; 158f384b3ddSHauke Mehrtens struct bcma_device *core; 159f384b3ddSHauke Mehrtens 160f384b3ddSHauke Mehrtens switch (bus->hosttype) { 161f384b3ddSHauke Mehrtens case BCMA_HOSTTYPE_PCI: 162f384b3ddSHauke Mehrtens snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 163f384b3ddSHauke Mehrtens bus->host_pci->bus->number + 1, 164f384b3ddSHauke Mehrtens PCI_SLOT(bus->host_pci->devfn)); 165f384b3ddSHauke Mehrtens bcm47xx_fill_sprom(out, prefix); 166f384b3ddSHauke Mehrtens return 0; 167f384b3ddSHauke Mehrtens case BCMA_HOSTTYPE_SOC: 168f384b3ddSHauke Mehrtens bcm47xx_fill_sprom_ethernet(out, NULL); 169f384b3ddSHauke Mehrtens core = bcma_find_core(bus, BCMA_CORE_80211); 170f384b3ddSHauke Mehrtens if (core) { 171f384b3ddSHauke Mehrtens snprintf(prefix, sizeof(prefix), "sb/%u/", 172f384b3ddSHauke Mehrtens core->core_index); 173f384b3ddSHauke Mehrtens bcm47xx_fill_sprom(out, prefix); 174f384b3ddSHauke Mehrtens } 175f384b3ddSHauke Mehrtens return 0; 176f384b3ddSHauke Mehrtens default: 177f384b3ddSHauke Mehrtens pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n"); 178f384b3ddSHauke Mehrtens return -EINVAL; 179f384b3ddSHauke Mehrtens } 180f384b3ddSHauke Mehrtens } 181f384b3ddSHauke Mehrtens 182c1d1c5d4SHauke Mehrtens static void __init bcm47xx_register_bcma(void) 183c1d1c5d4SHauke Mehrtens { 184c1d1c5d4SHauke Mehrtens int err; 185c1d1c5d4SHauke Mehrtens 186f384b3ddSHauke Mehrtens err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma); 187f384b3ddSHauke Mehrtens if (err) 188f384b3ddSHauke Mehrtens pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err); 189f384b3ddSHauke Mehrtens 190c1d1c5d4SHauke Mehrtens err = bcma_host_soc_register(&bcm47xx_bus.bcma); 191c1d1c5d4SHauke Mehrtens if (err) 192ab75dc02SRalf Baechle panic("Failed to initialize BCMA bus (err %d)", err); 193c1d1c5d4SHauke Mehrtens } 194c1d1c5d4SHauke Mehrtens #endif 195c1d1c5d4SHauke Mehrtens 19608ccf572SHauke Mehrtens void __init plat_mem_setup(void) 19708ccf572SHauke Mehrtens { 19808ccf572SHauke Mehrtens struct cpuinfo_mips *c = ¤t_cpu_data; 19908ccf572SHauke Mehrtens 200c1d1c5d4SHauke Mehrtens if (c->cputype == CPU_74K) { 201c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using bcma bus\n"); 202c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 203c1d1c5d4SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA; 204c1d1c5d4SHauke Mehrtens bcm47xx_register_bcma(); 205c1d1c5d4SHauke Mehrtens #endif 206c1d1c5d4SHauke Mehrtens } else { 207c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using ssb bus\n"); 208a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 20908ccf572SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB; 21008ccf572SHauke Mehrtens bcm47xx_register_ssb(); 211a656ffcbSHauke Mehrtens #endif 212c1d1c5d4SHauke Mehrtens } 2131690a7f9SHauke Mehrtens 2141c0c13ebSAurelien Jarno _machine_restart = bcm47xx_machine_restart; 2151c0c13ebSAurelien Jarno _machine_halt = bcm47xx_machine_halt; 2161c0c13ebSAurelien Jarno pm_power_off = bcm47xx_machine_halt; 2171c0c13ebSAurelien Jarno } 218c1d1c5d4SHauke Mehrtens 219c1d1c5d4SHauke Mehrtens static int __init bcm47xx_register_bus_complete(void) 220c1d1c5d4SHauke Mehrtens { 221c1d1c5d4SHauke Mehrtens switch (bcm47xx_bus_type) { 222c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 223c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 224c1d1c5d4SHauke Mehrtens /* Nothing to do */ 225c1d1c5d4SHauke Mehrtens break; 226c1d1c5d4SHauke Mehrtens #endif 227c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 228c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 229c1d1c5d4SHauke Mehrtens bcma_bus_register(&bcm47xx_bus.bcma.bus); 230c1d1c5d4SHauke Mehrtens break; 231c1d1c5d4SHauke Mehrtens #endif 232c1d1c5d4SHauke Mehrtens } 233c1d1c5d4SHauke Mehrtens return 0; 234c1d1c5d4SHauke Mehrtens } 235c1d1c5d4SHauke Mehrtens device_initcall(bcm47xx_register_bus_complete); 236