xref: /openbmc/linux/arch/mips/bcm47xx/setup.c (revision a59da8fb3b2a1f2df5f871464e43cd5b6ca6ceb1)
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:
622727cab2SHauke Mehrtens 		if (bcm47xx_bus.ssb.chip_id == 0x4785)
632727cab2SHauke Mehrtens 			write_c0_diag4(1 << 22);
642727cab2SHauke Mehrtens 		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
652727cab2SHauke Mehrtens 		if (bcm47xx_bus.ssb.chip_id == 0x4785) {
662727cab2SHauke Mehrtens 			__asm__ __volatile__(
672727cab2SHauke Mehrtens 				".set\tmips3\n\t"
682727cab2SHauke Mehrtens 				"sync\n\t"
692727cab2SHauke Mehrtens 				"wait\n\t"
702727cab2SHauke Mehrtens 				".set\tmips0");
712727cab2SHauke Mehrtens 		}
7208ccf572SHauke Mehrtens 		break;
73a656ffcbSHauke Mehrtens #endif
74c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
75c1d1c5d4SHauke Mehrtens 	case BCM47XX_BUS_TYPE_BCMA:
762727cab2SHauke Mehrtens 		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
77c1d1c5d4SHauke Mehrtens 		break;
78c1d1c5d4SHauke Mehrtens #endif
7908ccf572SHauke Mehrtens 	}
801c0c13ebSAurelien Jarno 	while (1)
811c0c13ebSAurelien Jarno 		cpu_relax();
821c0c13ebSAurelien Jarno }
831c0c13ebSAurelien Jarno 
841c0c13ebSAurelien Jarno static void bcm47xx_machine_halt(void)
851c0c13ebSAurelien Jarno {
861c0c13ebSAurelien Jarno 	/* Disable interrupts and watchdog and spin forever */
871c0c13ebSAurelien Jarno 	local_irq_disable();
8808ccf572SHauke Mehrtens 	switch (bcm47xx_bus_type) {
89a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
9008ccf572SHauke Mehrtens 	case BCM47XX_BUS_TYPE_SSB:
9108ccf572SHauke Mehrtens 		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
9208ccf572SHauke Mehrtens 		break;
93a656ffcbSHauke Mehrtens #endif
94c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
95c1d1c5d4SHauke Mehrtens 	case BCM47XX_BUS_TYPE_BCMA:
96c1d1c5d4SHauke Mehrtens 		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
97c1d1c5d4SHauke Mehrtens 		break;
98c1d1c5d4SHauke Mehrtens #endif
9908ccf572SHauke Mehrtens 	}
1001c0c13ebSAurelien Jarno 	while (1)
1011c0c13ebSAurelien Jarno 		cpu_relax();
1021c0c13ebSAurelien Jarno }
1031c0c13ebSAurelien Jarno 
104a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
1051c0c13ebSAurelien Jarno static int bcm47xx_get_invariants(struct ssb_bus *bus,
1061c0c13ebSAurelien Jarno 				  struct ssb_init_invariants *iv)
1071c0c13ebSAurelien Jarno {
1082aa088d6SHauke Mehrtens 	char buf[20];
10925e5fb97SAurelien Jarno 
11025e5fb97SAurelien Jarno 	/* Fill boardinfo structure */
11125e5fb97SAurelien Jarno 	memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
11225e5fb97SAurelien Jarno 
113a9bba182SHauke Mehrtens 	bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL);
11425e5fb97SAurelien Jarno 
1155fe2e071SNathan Hintz 	memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
116b8ebbaffSHauke Mehrtens 	bcm47xx_fill_sprom(&iv->sprom, NULL, false);
11725e5fb97SAurelien Jarno 
118111bd981SHauke Mehrtens 	if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
1192aa088d6SHauke Mehrtens 		iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
12025e5fb97SAurelien Jarno 
1211c0c13ebSAurelien Jarno 	return 0;
1221c0c13ebSAurelien Jarno }
1231c0c13ebSAurelien Jarno 
12408ccf572SHauke Mehrtens static void __init bcm47xx_register_ssb(void)
1251c0c13ebSAurelien Jarno {
1261c0c13ebSAurelien Jarno 	int err;
1271690a7f9SHauke Mehrtens 	char buf[100];
1281690a7f9SHauke Mehrtens 	struct ssb_mipscore *mcore;
1291c0c13ebSAurelien Jarno 
13008ccf572SHauke Mehrtens 	err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
1311c0c13ebSAurelien Jarno 				      bcm47xx_get_invariants);
1321c0c13ebSAurelien Jarno 	if (err)
133ab75dc02SRalf Baechle 		panic("Failed to initialize SSB bus (err %d)", err);
1341c0c13ebSAurelien Jarno 
13508ccf572SHauke Mehrtens 	mcore = &bcm47xx_bus.ssb.mipscore;
136111bd981SHauke Mehrtens 	if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
1371690a7f9SHauke Mehrtens 		if (strstr(buf, "console=ttyS1")) {
1381690a7f9SHauke Mehrtens 			struct ssb_serial_port port;
1391690a7f9SHauke Mehrtens 
1401690a7f9SHauke Mehrtens 			printk(KERN_DEBUG "Swapping serial ports!\n");
1411690a7f9SHauke Mehrtens 			/* swap serial ports */
1421690a7f9SHauke Mehrtens 			memcpy(&port, &mcore->serial_ports[0], sizeof(port));
1431690a7f9SHauke Mehrtens 			memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
1441690a7f9SHauke Mehrtens 			       sizeof(port));
1451690a7f9SHauke Mehrtens 			memcpy(&mcore->serial_ports[1], &port, sizeof(port));
1461690a7f9SHauke Mehrtens 		}
1471690a7f9SHauke Mehrtens 	}
14808ccf572SHauke Mehrtens }
149a656ffcbSHauke Mehrtens #endif
15008ccf572SHauke Mehrtens 
151c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
152c1d1c5d4SHauke Mehrtens static void __init bcm47xx_register_bcma(void)
153c1d1c5d4SHauke Mehrtens {
154c1d1c5d4SHauke Mehrtens 	int err;
155c1d1c5d4SHauke Mehrtens 
156c1d1c5d4SHauke Mehrtens 	err = bcma_host_soc_register(&bcm47xx_bus.bcma);
157c1d1c5d4SHauke Mehrtens 	if (err)
158a395135dSRafał Miłecki 		panic("Failed to register BCMA bus (err %d)", err);
159a395135dSRafał Miłecki 
160a395135dSRafał Miłecki 	err = bcma_host_soc_init(&bcm47xx_bus.bcma);
161a395135dSRafał Miłecki 	if (err)
162ab75dc02SRalf Baechle 		panic("Failed to initialize BCMA bus (err %d)", err);
1630a2fcaa7SHauke Mehrtens 
1640a2fcaa7SHauke Mehrtens 	bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL);
165c1d1c5d4SHauke Mehrtens }
166c1d1c5d4SHauke Mehrtens #endif
167c1d1c5d4SHauke Mehrtens 
16808ccf572SHauke Mehrtens void __init plat_mem_setup(void)
16908ccf572SHauke Mehrtens {
17008ccf572SHauke Mehrtens 	struct cpuinfo_mips *c = &current_cpu_data;
17108ccf572SHauke Mehrtens 
172442e14a2SSteven J. Hill 	if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) {
173c1d1c5d4SHauke Mehrtens 		printk(KERN_INFO "bcm47xx: using bcma bus\n");
174c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
175c1d1c5d4SHauke Mehrtens 		bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
176*a59da8fbSRafał Miłecki 		bcm47xx_sprom_register_fallbacks();
177c1d1c5d4SHauke Mehrtens 		bcm47xx_register_bcma();
178dd573285SHauke Mehrtens 		bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
1796ee1d934SRafał Miłecki #ifdef CONFIG_HIGHMEM
1806ee1d934SRafał Miłecki 		bcm47xx_prom_highmem_init();
1816ee1d934SRafał Miłecki #endif
182c1d1c5d4SHauke Mehrtens #endif
183c1d1c5d4SHauke Mehrtens 	} else {
184c1d1c5d4SHauke Mehrtens 		printk(KERN_INFO "bcm47xx: using ssb bus\n");
185a656ffcbSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
18608ccf572SHauke Mehrtens 		bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
187*a59da8fbSRafał Miłecki 		bcm47xx_sprom_register_fallbacks();
18808ccf572SHauke Mehrtens 		bcm47xx_register_ssb();
189dd573285SHauke Mehrtens 		bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
190a656ffcbSHauke Mehrtens #endif
191c1d1c5d4SHauke Mehrtens 	}
1921690a7f9SHauke Mehrtens 
1931c0c13ebSAurelien Jarno 	_machine_restart = bcm47xx_machine_restart;
1941c0c13ebSAurelien Jarno 	_machine_halt = bcm47xx_machine_halt;
1951c0c13ebSAurelien Jarno 	pm_power_off = bcm47xx_machine_halt;
196786c497aSHauke Mehrtens 	bcm47xx_board_detect();
1977da4b6f8SHauke Mehrtens 	mips_set_machine_name(bcm47xx_board_get_name());
1981c0c13ebSAurelien Jarno }
199c1d1c5d4SHauke Mehrtens 
2003c06b12bSHauke Mehrtens static int __init bcm47xx_cpu_fixes(void)
2013c06b12bSHauke Mehrtens {
2023c06b12bSHauke Mehrtens 	switch (bcm47xx_bus_type) {
2033c06b12bSHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
2043c06b12bSHauke Mehrtens 	case BCM47XX_BUS_TYPE_SSB:
2053c06b12bSHauke Mehrtens 		/* Nothing to do */
2063c06b12bSHauke Mehrtens 		break;
2073c06b12bSHauke Mehrtens #endif
2083c06b12bSHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
2093c06b12bSHauke Mehrtens 	case BCM47XX_BUS_TYPE_BCMA:
2103c06b12bSHauke Mehrtens 		/* The BCM4706 has a problem with the CPU wait instruction.
2113c06b12bSHauke Mehrtens 		 * When r4k_wait or r4k_wait_irqoff is used will just hang and
2123c06b12bSHauke Mehrtens 		 * not return from a msleep(). Removing the cpu_wait
2133c06b12bSHauke Mehrtens 		 * functionality is a workaround for this problem. The BCM4716
2143c06b12bSHauke Mehrtens 		 * does not have this problem.
2153c06b12bSHauke Mehrtens 		 */
2163c06b12bSHauke Mehrtens 		if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
2173c06b12bSHauke Mehrtens 			cpu_wait = NULL;
2183c06b12bSHauke Mehrtens 		break;
2193c06b12bSHauke Mehrtens #endif
2203c06b12bSHauke Mehrtens 	}
2213c06b12bSHauke Mehrtens 	return 0;
2223c06b12bSHauke Mehrtens }
2233c06b12bSHauke Mehrtens arch_initcall(bcm47xx_cpu_fixes);
2243c06b12bSHauke Mehrtens 
225b04138b3SHauke Mehrtens static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
226b04138b3SHauke Mehrtens 	.link	= 1,
227b04138b3SHauke Mehrtens 	.speed	= SPEED_100,
228b04138b3SHauke Mehrtens 	.duplex	= DUPLEX_FULL,
229b04138b3SHauke Mehrtens };
230b04138b3SHauke Mehrtens 
231c1d1c5d4SHauke Mehrtens static int __init bcm47xx_register_bus_complete(void)
232c1d1c5d4SHauke Mehrtens {
233c1d1c5d4SHauke Mehrtens 	switch (bcm47xx_bus_type) {
234c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_SSB
235c1d1c5d4SHauke Mehrtens 	case BCM47XX_BUS_TYPE_SSB:
236c1d1c5d4SHauke Mehrtens 		/* Nothing to do */
237c1d1c5d4SHauke Mehrtens 		break;
238c1d1c5d4SHauke Mehrtens #endif
239c1d1c5d4SHauke Mehrtens #ifdef CONFIG_BCM47XX_BCMA
240c1d1c5d4SHauke Mehrtens 	case BCM47XX_BUS_TYPE_BCMA:
241c1d1c5d4SHauke Mehrtens 		bcma_bus_register(&bcm47xx_bus.bcma.bus);
242c1d1c5d4SHauke Mehrtens 		break;
243c1d1c5d4SHauke Mehrtens #endif
244c1d1c5d4SHauke Mehrtens 	}
245ef1e3e7aSRafał Miłecki 	bcm47xx_buttons_register();
246515fa75dSRafał Miłecki 	bcm47xx_leds_register();
247a2bec078SRafał Miłecki 	bcm47xx_workarounds();
248515fa75dSRafał Miłecki 
249b04138b3SHauke Mehrtens 	fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status);
250c1d1c5d4SHauke Mehrtens 	return 0;
251c1d1c5d4SHauke Mehrtens }
252c1d1c5d4SHauke Mehrtens device_initcall(bcm47xx_register_bus_complete);
253