setup.c 7.8 KB
Newer Older
1 2 3
/*
 *  Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
 *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
M
Michael Büsch 已提交
4
 *  Copyright (C) 2006 Michael Buesch <m@bues.ch>
5
 *  Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
6
 *  Copyright (C) 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 *  This program is free software; you can redistribute  it and/or modify it
 *  under  the terms of  the GNU General  Public License as published by the
 *  Free Software Foundation;  either version 2 of the  License, or (at your
 *  option) any later version.
 *
 *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
 *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
 *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
 *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *  You should have received a copy of the  GNU General Public License along
 *  with this program; if not, write  to the Free Software Foundation, Inc.,
 *  675 Mass Ave, Cambridge, MA 02139, USA.
 */

29 30
#include "bcm47xx_private.h"

31
#include <linux/export.h>
32
#include <linux/types.h>
33 34 35
#include <linux/ethtool.h>
#include <linux/phy.h>
#include <linux/phy_fixed.h>
36
#include <linux/ssb/ssb.h>
37
#include <linux/ssb/ssb_embedded.h>
38
#include <linux/bcma/bcma_soc.h>
A
Aurelien Jarno 已提交
39
#include <asm/bootinfo.h>
40
#include <asm/idle.h>
41
#include <asm/prom.h>
42 43 44
#include <asm/reboot.h>
#include <asm/time.h>
#include <bcm47xx.h>
45
#include <bcm47xx_board.h>
46

47 48 49 50 51
union bcm47xx_bus bcm47xx_bus;
EXPORT_SYMBOL(bcm47xx_bus);

enum bcm47xx_bus_type bcm47xx_bus_type;
EXPORT_SYMBOL(bcm47xx_bus_type);
52 53 54

static void bcm47xx_machine_restart(char *command)
{
55
	pr_alert("Please stand by while rebooting the system...\n");
56 57
	local_irq_disable();
	/* Set the watchdog timer to reset immediately */
58
	switch (bcm47xx_bus_type) {
59
#ifdef CONFIG_BCM47XX_SSB
60
	case BCM47XX_BUS_TYPE_SSB:
61 62 63 64 65 66 67 68 69 70
		if (bcm47xx_bus.ssb.chip_id == 0x4785)
			write_c0_diag4(1 << 22);
		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
		if (bcm47xx_bus.ssb.chip_id == 0x4785) {
			__asm__ __volatile__(
				".set\tmips3\n\t"
				"sync\n\t"
				"wait\n\t"
				".set\tmips0");
		}
71
		break;
72 73 74
#endif
#ifdef CONFIG_BCM47XX_BCMA
	case BCM47XX_BUS_TYPE_BCMA:
75
		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
76
		break;
77
#endif
78
	}
79 80 81 82 83 84 85 86
	while (1)
		cpu_relax();
}

static void bcm47xx_machine_halt(void)
{
	/* Disable interrupts and watchdog and spin forever */
	local_irq_disable();
87
	switch (bcm47xx_bus_type) {
88
#ifdef CONFIG_BCM47XX_SSB
89 90 91
	case BCM47XX_BUS_TYPE_SSB:
		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
		break;
92 93 94 95 96
#endif
#ifdef CONFIG_BCM47XX_BCMA
	case BCM47XX_BUS_TYPE_BCMA:
		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
		break;
97
#endif
98
	}
99 100 101 102
	while (1)
		cpu_relax();
}

103
#ifdef CONFIG_BCM47XX_SSB
104
static int bcm47xx_get_invariants(struct ssb_bus *bus,
105
				  struct ssb_init_invariants *iv)
106
{
107
	char buf[20];
108
	int len, err;
A
Aurelien Jarno 已提交
109 110

	/* Fill boardinfo structure */
111
	memset(&iv->boardinfo, 0 , sizeof(struct ssb_boardinfo));
A
Aurelien Jarno 已提交
112

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
	len = bcm47xx_nvram_getenv("boardvendor", buf, sizeof(buf));
	if (len > 0) {
		err = kstrtou16(strim(buf), 0, &iv->boardinfo.vendor);
		if (err)
			pr_warn("Couldn't parse nvram board vendor entry with value \"%s\"\n",
				buf);
	}
	if (!iv->boardinfo.vendor)
		iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;

	len = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf));
	if (len > 0) {
		err = kstrtou16(strim(buf), 0, &iv->boardinfo.type);
		if (err)
			pr_warn("Couldn't parse nvram board type entry with value \"%s\"\n",
				buf);
	}
A
Aurelien Jarno 已提交
130

131
	memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
132
	bcm47xx_fill_sprom(&iv->sprom, NULL, false);
133

134
	if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
135
		iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
A
Aurelien Jarno 已提交
136

137 138 139
	return 0;
}

140
static void __init bcm47xx_register_ssb(void)
141 142
{
	int err;
143 144
	char buf[100];
	struct ssb_mipscore *mcore;
145

146
	err = ssb_bus_ssbbus_register(&bcm47xx_bus.ssb, SSB_ENUM_BASE,
147 148
				      bcm47xx_get_invariants);
	if (err)
149
		panic("Failed to initialize SSB bus (err %d)", err);
150

151
	mcore = &bcm47xx_bus.ssb.mipscore;
152
	if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
153 154 155
		if (strstr(buf, "console=ttyS1")) {
			struct ssb_serial_port port;

156
			pr_debug("Swapping serial ports!\n");
157 158 159 160 161 162 163
			/* swap serial ports */
			memcpy(&port, &mcore->serial_ports[0], sizeof(port));
			memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
			       sizeof(port));
			memcpy(&mcore->serial_ports[1], &port, sizeof(port));
		}
	}
164
}
165
#endif
166

167 168 169 170 171 172
#ifdef CONFIG_BCM47XX_BCMA
static void __init bcm47xx_register_bcma(void)
{
	int err;

	err = bcma_host_soc_register(&bcm47xx_bus.bcma);
173 174
	if (err)
		panic("Failed to register BCMA bus (err %d)", err);
175 176 177
}
#endif

178 179 180 181 182
/*
 * Memory setup is done in the early part of MIPS's arch_mem_init. It's supposed
 * to detect memory and record it with add_memory_region.
 * Any extra initializaion performed here must not use kmalloc or bootmem.
 */
183 184 185 186
void __init plat_mem_setup(void)
{
	struct cpuinfo_mips *c = &current_cpu_data;

187
	if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) {
188
		pr_info("Using bcma bus\n");
189 190
#ifdef CONFIG_BCM47XX_BCMA
		bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
191
		bcm47xx_sprom_register_fallbacks();
192
		bcm47xx_register_bcma();
193
		bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
194 195 196
#ifdef CONFIG_HIGHMEM
		bcm47xx_prom_highmem_init();
#endif
197 198
#endif
	} else {
199
		pr_info("Using ssb bus\n");
200
#ifdef CONFIG_BCM47XX_SSB
201
		bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
202
		bcm47xx_sprom_register_fallbacks();
203
		bcm47xx_register_ssb();
204
		bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
205
#endif
206
	}
207

208 209 210
	_machine_restart = bcm47xx_machine_restart;
	_machine_halt = bcm47xx_machine_halt;
	pm_power_off = bcm47xx_machine_halt;
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
}

/*
 * This finishes bus initialization doing things that were not possible without
 * kmalloc. Make sure to call it late enough (after mm_init).
 */
void __init bcm47xx_bus_setup(void)
{
#ifdef CONFIG_BCM47XX_BCMA
	if (bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA) {
		int err;

		err = bcma_host_soc_init(&bcm47xx_bus.bcma);
		if (err)
			panic("Failed to initialize BCMA bus (err %d)", err);
	}
#endif

	/* With bus initialized we can access NVRAM and detect the board */
230
	bcm47xx_board_detect();
231
	mips_set_machine_name(bcm47xx_board_get_name());
232
}
233

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
static int __init bcm47xx_cpu_fixes(void)
{
	switch (bcm47xx_bus_type) {
#ifdef CONFIG_BCM47XX_SSB
	case BCM47XX_BUS_TYPE_SSB:
		/* Nothing to do */
		break;
#endif
#ifdef CONFIG_BCM47XX_BCMA
	case BCM47XX_BUS_TYPE_BCMA:
		/* The BCM4706 has a problem with the CPU wait instruction.
		 * When r4k_wait or r4k_wait_irqoff is used will just hang and
		 * not return from a msleep(). Removing the cpu_wait
		 * functionality is a workaround for this problem. The BCM4716
		 * does not have this problem.
		 */
		if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
			cpu_wait = NULL;
		break;
#endif
	}
	return 0;
}
arch_initcall(bcm47xx_cpu_fixes);

259 260 261 262 263 264
static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
	.link	= 1,
	.speed	= SPEED_100,
	.duplex	= DUPLEX_FULL,
};

265 266 267 268 269 270 271 272 273 274 275 276 277 278
static int __init bcm47xx_register_bus_complete(void)
{
	switch (bcm47xx_bus_type) {
#ifdef CONFIG_BCM47XX_SSB
	case BCM47XX_BUS_TYPE_SSB:
		/* Nothing to do */
		break;
#endif
#ifdef CONFIG_BCM47XX_BCMA
	case BCM47XX_BUS_TYPE_BCMA:
		bcma_bus_register(&bcm47xx_bus.bcma.bus);
		break;
#endif
	}
279
	bcm47xx_buttons_register();
280
	bcm47xx_leds_register();
281
	bcm47xx_workarounds();
282

283
	fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status, -1);
284 285 286
	return 0;
}
device_initcall(bcm47xx_register_bus_complete);