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 29515fa75dSRafał Miłecki #include "bcm47xx_private.h" 30515fa75dSRafał Miłecki 31cae39d13SPaul Gortmaker #include <linux/export.h> 321c0c13ebSAurelien Jarno #include <linux/types.h> 331c0c13ebSAurelien Jarno #include <linux/ssb/ssb.h> 34b06f3e19SAurelien Jarno #include <linux/ssb/ssb_embedded.h> 35c1d1c5d4SHauke Mehrtens #include <linux/bcma/bcma_soc.h> 3625e5fb97SAurelien Jarno #include <asm/bootinfo.h> 3776b573e4SHauke Mehrtens #include <asm/idle.h> 387da4b6f8SHauke Mehrtens #include <asm/prom.h> 391c0c13ebSAurelien Jarno #include <asm/reboot.h> 401c0c13ebSAurelien Jarno #include <asm/time.h> 411c0c13ebSAurelien Jarno #include <bcm47xx.h> 42111bd981SHauke Mehrtens #include <bcm47xx_nvram.h> 43786c497aSHauke Mehrtens #include <bcm47xx_board.h> 441c0c13ebSAurelien Jarno 4508ccf572SHauke Mehrtens union bcm47xx_bus bcm47xx_bus; 4608ccf572SHauke Mehrtens EXPORT_SYMBOL(bcm47xx_bus); 4708ccf572SHauke Mehrtens 4808ccf572SHauke Mehrtens enum bcm47xx_bus_type bcm47xx_bus_type; 4908ccf572SHauke Mehrtens EXPORT_SYMBOL(bcm47xx_bus_type); 501c0c13ebSAurelien Jarno 511c0c13ebSAurelien Jarno static void bcm47xx_machine_restart(char *command) 521c0c13ebSAurelien Jarno { 531c0c13ebSAurelien Jarno printk(KERN_ALERT "Please stand by while rebooting the system...\n"); 541c0c13ebSAurelien Jarno local_irq_disable(); 551c0c13ebSAurelien Jarno /* Set the watchdog timer to reset immediately */ 5608ccf572SHauke Mehrtens switch (bcm47xx_bus_type) { 57a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 5808ccf572SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 5908ccf572SHauke Mehrtens ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1); 6008ccf572SHauke Mehrtens break; 61a656ffcbSHauke Mehrtens #endif 62c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 63c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 64c1d1c5d4SHauke Mehrtens bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1); 65c1d1c5d4SHauke Mehrtens break; 66c1d1c5d4SHauke Mehrtens #endif 6708ccf572SHauke Mehrtens } 681c0c13ebSAurelien Jarno while (1) 691c0c13ebSAurelien Jarno cpu_relax(); 701c0c13ebSAurelien Jarno } 711c0c13ebSAurelien Jarno 721c0c13ebSAurelien Jarno static void bcm47xx_machine_halt(void) 731c0c13ebSAurelien Jarno { 741c0c13ebSAurelien Jarno /* Disable interrupts and watchdog and spin forever */ 751c0c13ebSAurelien Jarno local_irq_disable(); 7608ccf572SHauke Mehrtens switch (bcm47xx_bus_type) { 77a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 7808ccf572SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 7908ccf572SHauke Mehrtens ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0); 8008ccf572SHauke Mehrtens break; 81a656ffcbSHauke Mehrtens #endif 82c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 83c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 84c1d1c5d4SHauke Mehrtens bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0); 85c1d1c5d4SHauke Mehrtens break; 86c1d1c5d4SHauke Mehrtens #endif 8708ccf572SHauke Mehrtens } 881c0c13ebSAurelien Jarno while (1) 891c0c13ebSAurelien Jarno cpu_relax(); 901c0c13ebSAurelien Jarno } 911c0c13ebSAurelien Jarno 92a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 93f384b3ddSHauke Mehrtens static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out) 94fe6f3642SHauke Mehrtens { 95fe6f3642SHauke Mehrtens char prefix[10]; 96fe6f3642SHauke Mehrtens 97fe6f3642SHauke Mehrtens if (bus->bustype == SSB_BUSTYPE_PCI) { 985fe2e071SNathan Hintz memset(out, 0, sizeof(struct ssb_sprom)); 99fe6f3642SHauke Mehrtens snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 100fe6f3642SHauke Mehrtens bus->host_pci->bus->number + 1, 101fe6f3642SHauke Mehrtens PCI_SLOT(bus->host_pci->devfn)); 102b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(out, prefix, false); 103fe6f3642SHauke Mehrtens return 0; 104fe6f3642SHauke Mehrtens } else { 105fe6f3642SHauke Mehrtens printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n"); 106fe6f3642SHauke Mehrtens return -EINVAL; 107fe6f3642SHauke Mehrtens } 108fe6f3642SHauke Mehrtens } 109fe6f3642SHauke Mehrtens 1101c0c13ebSAurelien Jarno static int bcm47xx_get_invariants(struct ssb_bus *bus, 1111c0c13ebSAurelien Jarno struct ssb_init_invariants *iv) 1121c0c13ebSAurelien Jarno { 1132aa088d6SHauke Mehrtens char buf[20]; 11425e5fb97SAurelien Jarno 11525e5fb97SAurelien Jarno /* Fill boardinfo structure */ 11625e5fb97SAurelien Jarno memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo)); 11725e5fb97SAurelien Jarno 118a9bba182SHauke Mehrtens bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL); 11925e5fb97SAurelien Jarno 1205fe2e071SNathan Hintz memset(&iv->sprom, 0, sizeof(struct ssb_sprom)); 121b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(&iv->sprom, NULL, false); 12225e5fb97SAurelien Jarno 123111bd981SHauke Mehrtens if (bcm47xx_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 135f384b3ddSHauke 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; 146111bd981SHauke Mehrtens if (bcm47xx_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 162f384b3ddSHauke Mehrtens static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out) 163f384b3ddSHauke Mehrtens { 164f384b3ddSHauke Mehrtens char prefix[10]; 165f384b3ddSHauke Mehrtens struct bcma_device *core; 166f384b3ddSHauke Mehrtens 167f384b3ddSHauke Mehrtens switch (bus->hosttype) { 168f384b3ddSHauke Mehrtens case BCMA_HOSTTYPE_PCI: 1695fe2e071SNathan Hintz memset(out, 0, sizeof(struct ssb_sprom)); 170f384b3ddSHauke Mehrtens snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 171f384b3ddSHauke Mehrtens bus->host_pci->bus->number + 1, 172f384b3ddSHauke Mehrtens PCI_SLOT(bus->host_pci->devfn)); 173b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(out, prefix, false); 174f384b3ddSHauke Mehrtens return 0; 175f384b3ddSHauke Mehrtens case BCMA_HOSTTYPE_SOC: 1765fe2e071SNathan Hintz memset(out, 0, sizeof(struct ssb_sprom)); 177f384b3ddSHauke Mehrtens core = bcma_find_core(bus, BCMA_CORE_80211); 178f384b3ddSHauke Mehrtens if (core) { 179f384b3ddSHauke Mehrtens snprintf(prefix, sizeof(prefix), "sb/%u/", 180f384b3ddSHauke Mehrtens core->core_index); 181b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(out, prefix, true); 1822c376311SHauke Mehrtens } else { 183b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(out, NULL, false); 184f384b3ddSHauke Mehrtens } 185f384b3ddSHauke Mehrtens return 0; 186f384b3ddSHauke Mehrtens default: 187f384b3ddSHauke Mehrtens pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n"); 188f384b3ddSHauke Mehrtens return -EINVAL; 189f384b3ddSHauke Mehrtens } 190f384b3ddSHauke Mehrtens } 191f384b3ddSHauke Mehrtens 192c1d1c5d4SHauke Mehrtens static void __init bcm47xx_register_bcma(void) 193c1d1c5d4SHauke Mehrtens { 194c1d1c5d4SHauke Mehrtens int err; 195c1d1c5d4SHauke Mehrtens 196f384b3ddSHauke Mehrtens err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma); 197f384b3ddSHauke Mehrtens if (err) 198f384b3ddSHauke Mehrtens pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err); 199f384b3ddSHauke Mehrtens 200c1d1c5d4SHauke Mehrtens err = bcma_host_soc_register(&bcm47xx_bus.bcma); 201c1d1c5d4SHauke Mehrtens if (err) 202ab75dc02SRalf Baechle panic("Failed to initialize BCMA bus (err %d)", err); 2030a2fcaa7SHauke Mehrtens 2040a2fcaa7SHauke Mehrtens bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL); 205c1d1c5d4SHauke Mehrtens } 206c1d1c5d4SHauke Mehrtens #endif 207c1d1c5d4SHauke Mehrtens 20808ccf572SHauke Mehrtens void __init plat_mem_setup(void) 20908ccf572SHauke Mehrtens { 21008ccf572SHauke Mehrtens struct cpuinfo_mips *c = ¤t_cpu_data; 21108ccf572SHauke Mehrtens 212c1d1c5d4SHauke Mehrtens if (c->cputype == CPU_74K) { 213c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using bcma bus\n"); 214c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 215c1d1c5d4SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA; 216c1d1c5d4SHauke Mehrtens bcm47xx_register_bcma(); 217dd573285SHauke Mehrtens bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id); 218c1d1c5d4SHauke Mehrtens #endif 219c1d1c5d4SHauke Mehrtens } else { 220c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using ssb bus\n"); 221a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 22208ccf572SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB; 22308ccf572SHauke Mehrtens bcm47xx_register_ssb(); 224dd573285SHauke Mehrtens bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id); 225a656ffcbSHauke Mehrtens #endif 226c1d1c5d4SHauke Mehrtens } 2271690a7f9SHauke Mehrtens 2281c0c13ebSAurelien Jarno _machine_restart = bcm47xx_machine_restart; 2291c0c13ebSAurelien Jarno _machine_halt = bcm47xx_machine_halt; 2301c0c13ebSAurelien Jarno pm_power_off = bcm47xx_machine_halt; 231786c497aSHauke Mehrtens bcm47xx_board_detect(); 2327da4b6f8SHauke Mehrtens mips_set_machine_name(bcm47xx_board_get_name()); 2331c0c13ebSAurelien Jarno } 234c1d1c5d4SHauke Mehrtens 235*3c06b12bSHauke Mehrtens static int __init bcm47xx_cpu_fixes(void) 236*3c06b12bSHauke Mehrtens { 237*3c06b12bSHauke Mehrtens switch (bcm47xx_bus_type) { 238*3c06b12bSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 239*3c06b12bSHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 240*3c06b12bSHauke Mehrtens /* Nothing to do */ 241*3c06b12bSHauke Mehrtens break; 242*3c06b12bSHauke Mehrtens #endif 243*3c06b12bSHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 244*3c06b12bSHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 245*3c06b12bSHauke Mehrtens /* The BCM4706 has a problem with the CPU wait instruction. 246*3c06b12bSHauke Mehrtens * When r4k_wait or r4k_wait_irqoff is used will just hang and 247*3c06b12bSHauke Mehrtens * not return from a msleep(). Removing the cpu_wait 248*3c06b12bSHauke Mehrtens * functionality is a workaround for this problem. The BCM4716 249*3c06b12bSHauke Mehrtens * does not have this problem. 250*3c06b12bSHauke Mehrtens */ 251*3c06b12bSHauke Mehrtens if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706) 252*3c06b12bSHauke Mehrtens cpu_wait = NULL; 253*3c06b12bSHauke Mehrtens break; 254*3c06b12bSHauke Mehrtens #endif 255*3c06b12bSHauke Mehrtens } 256*3c06b12bSHauke Mehrtens return 0; 257*3c06b12bSHauke Mehrtens } 258*3c06b12bSHauke Mehrtens arch_initcall(bcm47xx_cpu_fixes); 259*3c06b12bSHauke Mehrtens 260c1d1c5d4SHauke Mehrtens static int __init bcm47xx_register_bus_complete(void) 261c1d1c5d4SHauke Mehrtens { 262c1d1c5d4SHauke Mehrtens switch (bcm47xx_bus_type) { 263c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 264c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 265c1d1c5d4SHauke Mehrtens /* Nothing to do */ 266c1d1c5d4SHauke Mehrtens break; 267c1d1c5d4SHauke Mehrtens #endif 268c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 269c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 270c1d1c5d4SHauke Mehrtens bcma_bus_register(&bcm47xx_bus.bcma.bus); 271c1d1c5d4SHauke Mehrtens break; 272c1d1c5d4SHauke Mehrtens #endif 273c1d1c5d4SHauke Mehrtens } 274ef1e3e7aSRafał Miłecki bcm47xx_buttons_register(); 275515fa75dSRafał Miłecki bcm47xx_leds_register(); 276515fa75dSRafał Miłecki 277c1d1c5d4SHauke Mehrtens return 0; 278c1d1c5d4SHauke Mehrtens } 279c1d1c5d4SHauke Mehrtens device_initcall(bcm47xx_register_bus_complete); 280