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> 33b04138b3SHauke Mehrtens #include <linux/ethtool.h> 34b04138b3SHauke Mehrtens #include <linux/phy.h> 35b04138b3SHauke Mehrtens #include <linux/phy_fixed.h> 361c0c13ebSAurelien Jarno #include <linux/ssb/ssb.h> 37b06f3e19SAurelien Jarno #include <linux/ssb/ssb_embedded.h> 38c1d1c5d4SHauke Mehrtens #include <linux/bcma/bcma_soc.h> 3925e5fb97SAurelien Jarno #include <asm/bootinfo.h> 4076b573e4SHauke Mehrtens #include <asm/idle.h> 417da4b6f8SHauke Mehrtens #include <asm/prom.h> 421c0c13ebSAurelien Jarno #include <asm/reboot.h> 431c0c13ebSAurelien Jarno #include <asm/time.h> 441c0c13ebSAurelien Jarno #include <bcm47xx.h> 45111bd981SHauke Mehrtens #include <bcm47xx_nvram.h> 46786c497aSHauke Mehrtens #include <bcm47xx_board.h> 471c0c13ebSAurelien Jarno 4808ccf572SHauke Mehrtens union bcm47xx_bus bcm47xx_bus; 4908ccf572SHauke Mehrtens EXPORT_SYMBOL(bcm47xx_bus); 5008ccf572SHauke Mehrtens 5108ccf572SHauke Mehrtens enum bcm47xx_bus_type bcm47xx_bus_type; 5208ccf572SHauke Mehrtens EXPORT_SYMBOL(bcm47xx_bus_type); 531c0c13ebSAurelien Jarno 541c0c13ebSAurelien Jarno static void bcm47xx_machine_restart(char *command) 551c0c13ebSAurelien Jarno { 561c0c13ebSAurelien Jarno printk(KERN_ALERT "Please stand by while rebooting the system...\n"); 571c0c13ebSAurelien Jarno local_irq_disable(); 581c0c13ebSAurelien Jarno /* Set the watchdog timer to reset immediately */ 5908ccf572SHauke Mehrtens switch (bcm47xx_bus_type) { 60a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 6108ccf572SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 6208ccf572SHauke Mehrtens ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1); 6308ccf572SHauke Mehrtens break; 64a656ffcbSHauke Mehrtens #endif 65c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 66c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 67c1d1c5d4SHauke Mehrtens bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1); 68c1d1c5d4SHauke Mehrtens break; 69c1d1c5d4SHauke Mehrtens #endif 7008ccf572SHauke Mehrtens } 711c0c13ebSAurelien Jarno while (1) 721c0c13ebSAurelien Jarno cpu_relax(); 731c0c13ebSAurelien Jarno } 741c0c13ebSAurelien Jarno 751c0c13ebSAurelien Jarno static void bcm47xx_machine_halt(void) 761c0c13ebSAurelien Jarno { 771c0c13ebSAurelien Jarno /* Disable interrupts and watchdog and spin forever */ 781c0c13ebSAurelien Jarno local_irq_disable(); 7908ccf572SHauke Mehrtens switch (bcm47xx_bus_type) { 80a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 8108ccf572SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 8208ccf572SHauke Mehrtens ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0); 8308ccf572SHauke Mehrtens break; 84a656ffcbSHauke Mehrtens #endif 85c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 86c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 87c1d1c5d4SHauke Mehrtens bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0); 88c1d1c5d4SHauke Mehrtens break; 89c1d1c5d4SHauke Mehrtens #endif 9008ccf572SHauke Mehrtens } 911c0c13ebSAurelien Jarno while (1) 921c0c13ebSAurelien Jarno cpu_relax(); 931c0c13ebSAurelien Jarno } 941c0c13ebSAurelien Jarno 95a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 96f384b3ddSHauke Mehrtens static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out) 97fe6f3642SHauke Mehrtens { 98fe6f3642SHauke Mehrtens char prefix[10]; 99fe6f3642SHauke Mehrtens 100fe6f3642SHauke Mehrtens if (bus->bustype == SSB_BUSTYPE_PCI) { 1015fe2e071SNathan Hintz memset(out, 0, sizeof(struct ssb_sprom)); 102fe6f3642SHauke Mehrtens snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 103fe6f3642SHauke Mehrtens bus->host_pci->bus->number + 1, 104fe6f3642SHauke Mehrtens PCI_SLOT(bus->host_pci->devfn)); 105b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(out, prefix, false); 106fe6f3642SHauke Mehrtens return 0; 107fe6f3642SHauke Mehrtens } else { 108fe6f3642SHauke Mehrtens printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n"); 109fe6f3642SHauke Mehrtens return -EINVAL; 110fe6f3642SHauke Mehrtens } 111fe6f3642SHauke Mehrtens } 112fe6f3642SHauke Mehrtens 1131c0c13ebSAurelien Jarno static int bcm47xx_get_invariants(struct ssb_bus *bus, 1141c0c13ebSAurelien Jarno struct ssb_init_invariants *iv) 1151c0c13ebSAurelien Jarno { 1162aa088d6SHauke Mehrtens char buf[20]; 11725e5fb97SAurelien Jarno 11825e5fb97SAurelien Jarno /* Fill boardinfo structure */ 11925e5fb97SAurelien Jarno memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo)); 12025e5fb97SAurelien Jarno 121a9bba182SHauke Mehrtens bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL); 12225e5fb97SAurelien Jarno 1235fe2e071SNathan Hintz memset(&iv->sprom, 0, sizeof(struct ssb_sprom)); 124b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(&iv->sprom, NULL, false); 12525e5fb97SAurelien Jarno 126111bd981SHauke Mehrtens if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0) 1272aa088d6SHauke Mehrtens iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10); 12825e5fb97SAurelien Jarno 1291c0c13ebSAurelien Jarno return 0; 1301c0c13ebSAurelien Jarno } 1311c0c13ebSAurelien Jarno 13208ccf572SHauke Mehrtens static void __init bcm47xx_register_ssb(void) 1331c0c13ebSAurelien Jarno { 1341c0c13ebSAurelien Jarno int err; 1351690a7f9SHauke Mehrtens char buf[100]; 1361690a7f9SHauke Mehrtens struct ssb_mipscore *mcore; 1371c0c13ebSAurelien Jarno 138f384b3ddSHauke Mehrtens err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb); 139fe6f3642SHauke Mehrtens if (err) 140fe6f3642SHauke Mehrtens printk(KERN_WARNING "bcm47xx: someone else already registered" 141fe6f3642SHauke Mehrtens " a ssb SPROM callback handler (err %d)\n", err); 142fe6f3642SHauke Mehrtens 14308ccf572SHauke Mehrtens err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE, 1441c0c13ebSAurelien Jarno bcm47xx_get_invariants); 1451c0c13ebSAurelien Jarno if (err) 146ab75dc02SRalf Baechle panic("Failed to initialize SSB bus (err %d)", err); 1471c0c13ebSAurelien Jarno 14808ccf572SHauke Mehrtens mcore = &bcm47xx_bus.ssb.mipscore; 149111bd981SHauke Mehrtens if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) { 1501690a7f9SHauke Mehrtens if (strstr(buf, "console=ttyS1")) { 1511690a7f9SHauke Mehrtens struct ssb_serial_port port; 1521690a7f9SHauke Mehrtens 1531690a7f9SHauke Mehrtens printk(KERN_DEBUG "Swapping serial ports!\n"); 1541690a7f9SHauke Mehrtens /* swap serial ports */ 1551690a7f9SHauke Mehrtens memcpy(&port, &mcore->serial_ports[0], sizeof(port)); 1561690a7f9SHauke Mehrtens memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1], 1571690a7f9SHauke Mehrtens sizeof(port)); 1581690a7f9SHauke Mehrtens memcpy(&mcore->serial_ports[1], &port, sizeof(port)); 1591690a7f9SHauke Mehrtens } 1601690a7f9SHauke Mehrtens } 16108ccf572SHauke Mehrtens } 162a656ffcbSHauke Mehrtens #endif 16308ccf572SHauke Mehrtens 164c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 165f384b3ddSHauke Mehrtens static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out) 166f384b3ddSHauke Mehrtens { 167f384b3ddSHauke Mehrtens char prefix[10]; 168f384b3ddSHauke Mehrtens struct bcma_device *core; 169f384b3ddSHauke Mehrtens 170f384b3ddSHauke Mehrtens switch (bus->hosttype) { 171f384b3ddSHauke Mehrtens case BCMA_HOSTTYPE_PCI: 1725fe2e071SNathan Hintz memset(out, 0, sizeof(struct ssb_sprom)); 173f384b3ddSHauke Mehrtens snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 174f384b3ddSHauke Mehrtens bus->host_pci->bus->number + 1, 175f384b3ddSHauke Mehrtens PCI_SLOT(bus->host_pci->devfn)); 176b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(out, prefix, false); 177f384b3ddSHauke Mehrtens return 0; 178f384b3ddSHauke Mehrtens case BCMA_HOSTTYPE_SOC: 1795fe2e071SNathan Hintz memset(out, 0, sizeof(struct ssb_sprom)); 180f384b3ddSHauke Mehrtens core = bcma_find_core(bus, BCMA_CORE_80211); 181f384b3ddSHauke Mehrtens if (core) { 182f384b3ddSHauke Mehrtens snprintf(prefix, sizeof(prefix), "sb/%u/", 183f384b3ddSHauke Mehrtens core->core_index); 184b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(out, prefix, true); 1852c376311SHauke Mehrtens } else { 186b8ebbaffSHauke Mehrtens bcm47xx_fill_sprom(out, NULL, false); 187f384b3ddSHauke Mehrtens } 188f384b3ddSHauke Mehrtens return 0; 189f384b3ddSHauke Mehrtens default: 190f384b3ddSHauke Mehrtens pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n"); 191f384b3ddSHauke Mehrtens return -EINVAL; 192f384b3ddSHauke Mehrtens } 193f384b3ddSHauke Mehrtens } 194f384b3ddSHauke Mehrtens 195c1d1c5d4SHauke Mehrtens static void __init bcm47xx_register_bcma(void) 196c1d1c5d4SHauke Mehrtens { 197c1d1c5d4SHauke Mehrtens int err; 198c1d1c5d4SHauke Mehrtens 199f384b3ddSHauke Mehrtens err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma); 200f384b3ddSHauke Mehrtens if (err) 201f384b3ddSHauke Mehrtens pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err); 202f384b3ddSHauke Mehrtens 203c1d1c5d4SHauke Mehrtens err = bcma_host_soc_register(&bcm47xx_bus.bcma); 204c1d1c5d4SHauke Mehrtens if (err) 205ab75dc02SRalf Baechle panic("Failed to initialize BCMA bus (err %d)", err); 2060a2fcaa7SHauke Mehrtens 2070a2fcaa7SHauke Mehrtens bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL); 208c1d1c5d4SHauke Mehrtens } 209c1d1c5d4SHauke Mehrtens #endif 210c1d1c5d4SHauke Mehrtens 21108ccf572SHauke Mehrtens void __init plat_mem_setup(void) 21208ccf572SHauke Mehrtens { 21308ccf572SHauke Mehrtens struct cpuinfo_mips *c = ¤t_cpu_data; 21408ccf572SHauke Mehrtens 215442e14a2SSteven J. Hill if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) { 216c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using bcma bus\n"); 217c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 218c1d1c5d4SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA; 219c1d1c5d4SHauke Mehrtens bcm47xx_register_bcma(); 220dd573285SHauke Mehrtens bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id); 221c1d1c5d4SHauke Mehrtens #endif 222c1d1c5d4SHauke Mehrtens } else { 223c1d1c5d4SHauke Mehrtens printk(KERN_INFO "bcm47xx: using ssb bus\n"); 224a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 22508ccf572SHauke Mehrtens bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB; 22608ccf572SHauke Mehrtens bcm47xx_register_ssb(); 227dd573285SHauke Mehrtens bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id); 228a656ffcbSHauke Mehrtens #endif 229c1d1c5d4SHauke Mehrtens } 2301690a7f9SHauke Mehrtens 2311c0c13ebSAurelien Jarno _machine_restart = bcm47xx_machine_restart; 2321c0c13ebSAurelien Jarno _machine_halt = bcm47xx_machine_halt; 2331c0c13ebSAurelien Jarno pm_power_off = bcm47xx_machine_halt; 234786c497aSHauke Mehrtens bcm47xx_board_detect(); 2357da4b6f8SHauke Mehrtens mips_set_machine_name(bcm47xx_board_get_name()); 2361c0c13ebSAurelien Jarno } 237c1d1c5d4SHauke Mehrtens 2383c06b12bSHauke Mehrtens static int __init bcm47xx_cpu_fixes(void) 2393c06b12bSHauke Mehrtens { 2403c06b12bSHauke Mehrtens switch (bcm47xx_bus_type) { 2413c06b12bSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 2423c06b12bSHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 2433c06b12bSHauke Mehrtens /* Nothing to do */ 2443c06b12bSHauke Mehrtens break; 2453c06b12bSHauke Mehrtens #endif 2463c06b12bSHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 2473c06b12bSHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 2483c06b12bSHauke Mehrtens /* The BCM4706 has a problem with the CPU wait instruction. 2493c06b12bSHauke Mehrtens * When r4k_wait or r4k_wait_irqoff is used will just hang and 2503c06b12bSHauke Mehrtens * not return from a msleep(). Removing the cpu_wait 2513c06b12bSHauke Mehrtens * functionality is a workaround for this problem. The BCM4716 2523c06b12bSHauke Mehrtens * does not have this problem. 2533c06b12bSHauke Mehrtens */ 2543c06b12bSHauke Mehrtens if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706) 2553c06b12bSHauke Mehrtens cpu_wait = NULL; 2563c06b12bSHauke Mehrtens break; 2573c06b12bSHauke Mehrtens #endif 2583c06b12bSHauke Mehrtens } 2593c06b12bSHauke Mehrtens return 0; 2603c06b12bSHauke Mehrtens } 2613c06b12bSHauke Mehrtens arch_initcall(bcm47xx_cpu_fixes); 2623c06b12bSHauke Mehrtens 263b04138b3SHauke Mehrtens static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = { 264b04138b3SHauke Mehrtens .link = 1, 265b04138b3SHauke Mehrtens .speed = SPEED_100, 266b04138b3SHauke Mehrtens .duplex = DUPLEX_FULL, 267b04138b3SHauke Mehrtens }; 268b04138b3SHauke Mehrtens 269c1d1c5d4SHauke Mehrtens static int __init bcm47xx_register_bus_complete(void) 270c1d1c5d4SHauke Mehrtens { 271c1d1c5d4SHauke Mehrtens switch (bcm47xx_bus_type) { 272c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB 273c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_SSB: 274c1d1c5d4SHauke Mehrtens /* Nothing to do */ 275c1d1c5d4SHauke Mehrtens break; 276c1d1c5d4SHauke Mehrtens #endif 277c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA 278c1d1c5d4SHauke Mehrtens case BCM47XX_BUS_TYPE_BCMA: 279c1d1c5d4SHauke Mehrtens bcma_bus_register(&bcm47xx_bus.bcma.bus); 280c1d1c5d4SHauke Mehrtens break; 281c1d1c5d4SHauke Mehrtens #endif 282c1d1c5d4SHauke Mehrtens } 283ef1e3e7aSRafał Miłecki bcm47xx_buttons_register(); 284515fa75dSRafał Miłecki bcm47xx_leds_register(); 285*a2bec078SRafał Miłecki bcm47xx_workarounds(); 286515fa75dSRafał Miłecki 287b04138b3SHauke Mehrtens fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status); 288c1d1c5d4SHauke Mehrtens return 0; 289c1d1c5d4SHauke Mehrtens } 290c1d1c5d4SHauke Mehrtens device_initcall(bcm47xx_register_bus_complete); 291