xref: /openbmc/linux/arch/mips/bcm47xx/setup.c (revision e1f7c9ee)
1 /*
2  *  Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
3  *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
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  *  This program is free software; you can redistribute  it and/or modify it
9  *  under  the terms of  the GNU General  Public License as published by the
10  *  Free Software Foundation;  either version 2 of the  License, or (at your
11  *  option) any later version.
12  *
13  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
14  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
15  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
16  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
17  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
19  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
21  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  *  You should have received a copy of the  GNU General Public License along
25  *  with this program; if not, write  to the Free Software Foundation, Inc.,
26  *  675 Mass Ave, Cambridge, MA 02139, USA.
27  */
28 
29 #include "bcm47xx_private.h"
30 
31 #include <linux/export.h>
32 #include <linux/types.h>
33 #include <linux/ethtool.h>
34 #include <linux/phy.h>
35 #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>
39 #include <asm/bootinfo.h>
40 #include <asm/idle.h>
41 #include <asm/prom.h>
42 #include <asm/reboot.h>
43 #include <asm/time.h>
44 #include <bcm47xx.h>
45 #include <bcm47xx_nvram.h>
46 #include <bcm47xx_board.h>
47 
48 union bcm47xx_bus bcm47xx_bus;
49 EXPORT_SYMBOL(bcm47xx_bus);
50 
51 enum bcm47xx_bus_type bcm47xx_bus_type;
52 EXPORT_SYMBOL(bcm47xx_bus_type);
53 
54 static void bcm47xx_machine_restart(char *command)
55 {
56 	printk(KERN_ALERT "Please stand by while rebooting the system...\n");
57 	local_irq_disable();
58 	/* Set the watchdog timer to reset immediately */
59 	switch (bcm47xx_bus_type) {
60 #ifdef CONFIG_BCM47XX_SSB
61 	case BCM47XX_BUS_TYPE_SSB:
62 		if (bcm47xx_bus.ssb.chip_id == 0x4785)
63 			write_c0_diag4(1 << 22);
64 		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
65 		if (bcm47xx_bus.ssb.chip_id == 0x4785) {
66 			__asm__ __volatile__(
67 				".set\tmips3\n\t"
68 				"sync\n\t"
69 				"wait\n\t"
70 				".set\tmips0");
71 		}
72 		break;
73 #endif
74 #ifdef CONFIG_BCM47XX_BCMA
75 	case BCM47XX_BUS_TYPE_BCMA:
76 		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
77 		break;
78 #endif
79 	}
80 	while (1)
81 		cpu_relax();
82 }
83 
84 static void bcm47xx_machine_halt(void)
85 {
86 	/* Disable interrupts and watchdog and spin forever */
87 	local_irq_disable();
88 	switch (bcm47xx_bus_type) {
89 #ifdef CONFIG_BCM47XX_SSB
90 	case BCM47XX_BUS_TYPE_SSB:
91 		ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
92 		break;
93 #endif
94 #ifdef CONFIG_BCM47XX_BCMA
95 	case BCM47XX_BUS_TYPE_BCMA:
96 		bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
97 		break;
98 #endif
99 	}
100 	while (1)
101 		cpu_relax();
102 }
103 
104 #ifdef CONFIG_BCM47XX_SSB
105 static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
106 {
107 	char prefix[10];
108 
109 	if (bus->bustype == SSB_BUSTYPE_PCI) {
110 		memset(out, 0, sizeof(struct ssb_sprom));
111 		snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
112 			 bus->host_pci->bus->number + 1,
113 			 PCI_SLOT(bus->host_pci->devfn));
114 		bcm47xx_fill_sprom(out, prefix, false);
115 		return 0;
116 	} else {
117 		printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n");
118 		return -EINVAL;
119 	}
120 }
121 
122 static int bcm47xx_get_invariants(struct ssb_bus *bus,
123 				  struct ssb_init_invariants *iv)
124 {
125 	char buf[20];
126 
127 	/* Fill boardinfo structure */
128 	memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
129 
130 	bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL);
131 
132 	memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
133 	bcm47xx_fill_sprom(&iv->sprom, NULL, false);
134 
135 	if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
136 		iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
137 
138 	return 0;
139 }
140 
141 static void __init bcm47xx_register_ssb(void)
142 {
143 	int err;
144 	char buf[100];
145 	struct ssb_mipscore *mcore;
146 
147 	err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb);
148 	if (err)
149 		printk(KERN_WARNING "bcm47xx: someone else already registered"
150 			" a ssb SPROM callback handler (err %d)\n", err);
151 
152 	err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
153 				      bcm47xx_get_invariants);
154 	if (err)
155 		panic("Failed to initialize SSB bus (err %d)", err);
156 
157 	mcore = &bcm47xx_bus.ssb.mipscore;
158 	if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
159 		if (strstr(buf, "console=ttyS1")) {
160 			struct ssb_serial_port port;
161 
162 			printk(KERN_DEBUG "Swapping serial ports!\n");
163 			/* swap serial ports */
164 			memcpy(&port, &mcore->serial_ports[0], sizeof(port));
165 			memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
166 			       sizeof(port));
167 			memcpy(&mcore->serial_ports[1], &port, sizeof(port));
168 		}
169 	}
170 }
171 #endif
172 
173 #ifdef CONFIG_BCM47XX_BCMA
174 static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
175 {
176 	char prefix[10];
177 	struct bcma_device *core;
178 
179 	switch (bus->hosttype) {
180 	case BCMA_HOSTTYPE_PCI:
181 		memset(out, 0, sizeof(struct ssb_sprom));
182 		snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
183 			 bus->host_pci->bus->number + 1,
184 			 PCI_SLOT(bus->host_pci->devfn));
185 		bcm47xx_fill_sprom(out, prefix, false);
186 		return 0;
187 	case BCMA_HOSTTYPE_SOC:
188 		memset(out, 0, sizeof(struct ssb_sprom));
189 		core = bcma_find_core(bus, BCMA_CORE_80211);
190 		if (core) {
191 			snprintf(prefix, sizeof(prefix), "sb/%u/",
192 				 core->core_index);
193 			bcm47xx_fill_sprom(out, prefix, true);
194 		} else {
195 			bcm47xx_fill_sprom(out, NULL, false);
196 		}
197 		return 0;
198 	default:
199 		pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n");
200 		return -EINVAL;
201 	}
202 }
203 
204 static void __init bcm47xx_register_bcma(void)
205 {
206 	int err;
207 
208 	err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma);
209 	if (err)
210 		pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err);
211 
212 	err = bcma_host_soc_register(&bcm47xx_bus.bcma);
213 	if (err)
214 		panic("Failed to register BCMA bus (err %d)", err);
215 
216 	err = bcma_host_soc_init(&bcm47xx_bus.bcma);
217 	if (err)
218 		panic("Failed to initialize BCMA bus (err %d)", err);
219 
220 	bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL);
221 }
222 #endif
223 
224 void __init plat_mem_setup(void)
225 {
226 	struct cpuinfo_mips *c = &current_cpu_data;
227 
228 	if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) {
229 		printk(KERN_INFO "bcm47xx: using bcma bus\n");
230 #ifdef CONFIG_BCM47XX_BCMA
231 		bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
232 		bcm47xx_register_bcma();
233 		bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
234 #ifdef CONFIG_HIGHMEM
235 		bcm47xx_prom_highmem_init();
236 #endif
237 #endif
238 	} else {
239 		printk(KERN_INFO "bcm47xx: using ssb bus\n");
240 #ifdef CONFIG_BCM47XX_SSB
241 		bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
242 		bcm47xx_register_ssb();
243 		bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
244 #endif
245 	}
246 
247 	_machine_restart = bcm47xx_machine_restart;
248 	_machine_halt = bcm47xx_machine_halt;
249 	pm_power_off = bcm47xx_machine_halt;
250 	bcm47xx_board_detect();
251 	mips_set_machine_name(bcm47xx_board_get_name());
252 }
253 
254 static int __init bcm47xx_cpu_fixes(void)
255 {
256 	switch (bcm47xx_bus_type) {
257 #ifdef CONFIG_BCM47XX_SSB
258 	case BCM47XX_BUS_TYPE_SSB:
259 		/* Nothing to do */
260 		break;
261 #endif
262 #ifdef CONFIG_BCM47XX_BCMA
263 	case BCM47XX_BUS_TYPE_BCMA:
264 		/* The BCM4706 has a problem with the CPU wait instruction.
265 		 * When r4k_wait or r4k_wait_irqoff is used will just hang and
266 		 * not return from a msleep(). Removing the cpu_wait
267 		 * functionality is a workaround for this problem. The BCM4716
268 		 * does not have this problem.
269 		 */
270 		if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
271 			cpu_wait = NULL;
272 		break;
273 #endif
274 	}
275 	return 0;
276 }
277 arch_initcall(bcm47xx_cpu_fixes);
278 
279 static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
280 	.link	= 1,
281 	.speed	= SPEED_100,
282 	.duplex	= DUPLEX_FULL,
283 };
284 
285 static int __init bcm47xx_register_bus_complete(void)
286 {
287 	switch (bcm47xx_bus_type) {
288 #ifdef CONFIG_BCM47XX_SSB
289 	case BCM47XX_BUS_TYPE_SSB:
290 		/* Nothing to do */
291 		break;
292 #endif
293 #ifdef CONFIG_BCM47XX_BCMA
294 	case BCM47XX_BUS_TYPE_BCMA:
295 		bcma_bus_register(&bcm47xx_bus.bcma.bus);
296 		break;
297 #endif
298 	}
299 	bcm47xx_buttons_register();
300 	bcm47xx_leds_register();
301 	bcm47xx_workarounds();
302 
303 	fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status);
304 	return 0;
305 }
306 device_initcall(bcm47xx_register_bus_complete);
307