setup.c 6.0 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-2011 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
#include <linux/export.h>
30 31
#include <linux/types.h>
#include <linux/ssb/ssb.h>
32
#include <linux/ssb/ssb_embedded.h>
33
#include <linux/bcma/bcma_soc.h>
A
Aurelien Jarno 已提交
34
#include <asm/bootinfo.h>
35 36 37
#include <asm/reboot.h>
#include <asm/time.h>
#include <bcm47xx.h>
38
#include <asm/mach-bcm47xx/nvram.h>
39

40 41 42 43 44
union bcm47xx_bus bcm47xx_bus;
EXPORT_SYMBOL(bcm47xx_bus);

enum bcm47xx_bus_type bcm47xx_bus_type;
EXPORT_SYMBOL(bcm47xx_bus_type);
45 46 47 48 49 50

static void bcm47xx_machine_restart(char *command)
{
	printk(KERN_ALERT "Please stand by while rebooting the system...\n");
	local_irq_disable();
	/* Set the watchdog timer to reset immediately */
51
	switch (bcm47xx_bus_type) {
52
#ifdef CONFIG_BCM47XX_SSB
53 54 55
	case BCM47XX_BUS_TYPE_SSB:
		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
		break;
56 57 58 59 60
#endif
#ifdef CONFIG_BCM47XX_BCMA
	case BCM47XX_BUS_TYPE_BCMA:
		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
		break;
61
#endif
62
	}
63 64 65 66 67 68 69 70
	while (1)
		cpu_relax();
}

static void bcm47xx_machine_halt(void)
{
	/* Disable interrupts and watchdog and spin forever */
	local_irq_disable();
71
	switch (bcm47xx_bus_type) {
72
#ifdef CONFIG_BCM47XX_SSB
73 74 75
	case BCM47XX_BUS_TYPE_SSB:
		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
		break;
76 77 78 79 80
#endif
#ifdef CONFIG_BCM47XX_BCMA
	case BCM47XX_BUS_TYPE_BCMA:
		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
		break;
81
#endif
82
	}
83 84 85 86
	while (1)
		cpu_relax();
}

87
#ifdef CONFIG_BCM47XX_SSB
88
static int bcm47xx_get_sprom(struct ssb_bus *bus, struct ssb_sprom *out)
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
{
	char prefix[10];

	if (bus->bustype == SSB_BUSTYPE_PCI) {
		snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
			 bus->host_pci->bus->number + 1,
			 PCI_SLOT(bus->host_pci->devfn));
		bcm47xx_fill_sprom(out, prefix);
		return 0;
	} else {
		printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n");
		return -EINVAL;
	}
}

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

	/* Fill boardinfo structure */
	memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));

112
	if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0)
113 114 115
		iv->boardinfo.vendor = (u16)simple_strtoul(buf, NULL, 0);
	else
		iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
116
	if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
A
Aurelien Jarno 已提交
117
		iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
118
	if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
A
Aurelien Jarno 已提交
119 120
		iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);

121
	bcm47xx_fill_sprom(&iv->sprom, NULL);
122

123 124
	if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
		iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
A
Aurelien Jarno 已提交
125

126 127 128
	return 0;
}

129
static void __init bcm47xx_register_ssb(void)
130 131
{
	int err;
132 133
	char buf[100];
	struct ssb_mipscore *mcore;
134

135 136 137 138 139
	err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom);
	if (err)
		printk(KERN_WARNING "bcm47xx: someone else already registered"
			" a ssb SPROM callback handler (err %d)\n", err);

140
	err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
141 142
				      bcm47xx_get_invariants);
	if (err)
143
		panic("Failed to initialize SSB bus (err %d)", err);
144

145
	mcore = &bcm47xx_bus.ssb.mipscore;
146 147 148 149 150 151 152 153 154 155 156 157
	if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
		if (strstr(buf, "console=ttyS1")) {
			struct ssb_serial_port port;

			printk(KERN_DEBUG "Swapping serial ports!\n");
			/* 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));
		}
	}
158
}
159
#endif
160

161 162 163 164 165 166 167
#ifdef CONFIG_BCM47XX_BCMA
static void __init bcm47xx_register_bcma(void)
{
	int err;

	err = bcma_host_soc_register(&bcm47xx_bus.bcma);
	if (err)
168
		panic("Failed to initialize BCMA bus (err %d)", err);
169 170 171
}
#endif

172 173 174 175
void __init plat_mem_setup(void)
{
	struct cpuinfo_mips *c = &current_cpu_data;

176 177 178 179 180 181 182 183
	if (c->cputype == CPU_74K) {
		printk(KERN_INFO "bcm47xx: using bcma bus\n");
#ifdef CONFIG_BCM47XX_BCMA
		bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
		bcm47xx_register_bcma();
#endif
	} else {
		printk(KERN_INFO "bcm47xx: using ssb bus\n");
184
#ifdef CONFIG_BCM47XX_SSB
185 186
		bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
		bcm47xx_register_ssb();
187
#endif
188
	}
189

190 191 192 193
	_machine_restart = bcm47xx_machine_restart;
	_machine_halt = bcm47xx_machine_halt;
	pm_power_off = bcm47xx_machine_halt;
}
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

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
	}
	return 0;
}
device_initcall(bcm47xx_register_bus_complete);