blob: 12d77e9c2cb49233500e3398e226b949095e2720 [file] [log] [blame]
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +02001/*
2 * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +02003 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
Michael Büscheb032b92011-07-04 20:50:05 +02004 * Copyright (C) 2006 Michael Buesch <m@bues.ch>
Waldemar Brodkorb121915c2010-06-08 19:06:01 +02005 * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +01006 * Copyright (C) 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +02007 *
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
Rafał Miłecki515fa752014-01-14 12:14:41 +010029#include "bcm47xx_private.h"
30
Paul Gortmakercae39d12011-07-28 18:46:31 -040031#include <linux/export.h>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020032#include <linux/types.h>
33#include <linux/ssb/ssb.h>
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020034#include <linux/ssb/ssb_embedded.h>
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020035#include <linux/bcma/bcma_soc.h>
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020036#include <asm/bootinfo.h>
Hauke Mehrtens76b573e2013-12-22 14:36:30 +010037#include <asm/idle.h>
Hauke Mehrtens7da4b6f2014-01-14 12:06:08 +010038#include <asm/prom.h>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020039#include <asm/reboot.h>
40#include <asm/time.h>
41#include <bcm47xx.h>
Hauke Mehrtens111bd982012-12-26 19:51:14 +000042#include <bcm47xx_nvram.h>
Hauke Mehrtens786c4972013-09-18 13:29:57 +020043#include <bcm47xx_board.h>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020044
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020045union bcm47xx_bus bcm47xx_bus;
46EXPORT_SYMBOL(bcm47xx_bus);
47
48enum bcm47xx_bus_type bcm47xx_bus_type;
49EXPORT_SYMBOL(bcm47xx_bus_type);
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020050
51static void bcm47xx_machine_restart(char *command)
52{
53 printk(KERN_ALERT "Please stand by while rebooting the system...\n");
54 local_irq_disable();
55 /* Set the watchdog timer to reset immediately */
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020056 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020057#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020058 case BCM47XX_BUS_TYPE_SSB:
59 ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
60 break;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020061#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020062#ifdef CONFIG_BCM47XX_BCMA
63 case BCM47XX_BUS_TYPE_BCMA:
64 bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
65 break;
66#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020067 }
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020068 while (1)
69 cpu_relax();
70}
71
72static void bcm47xx_machine_halt(void)
73{
74 /* Disable interrupts and watchdog and spin forever */
75 local_irq_disable();
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020076 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020077#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020078 case BCM47XX_BUS_TYPE_SSB:
79 ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
80 break;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020081#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020082#ifdef CONFIG_BCM47XX_BCMA
83 case BCM47XX_BUS_TYPE_BCMA:
84 bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
85 break;
86#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020087 }
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020088 while (1)
89 cpu_relax();
90}
91
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020092#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +010093static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
Hauke Mehrtensfe6f3642011-05-10 23:31:32 +020094{
95 char prefix[10];
96
97 if (bus->bustype == SSB_BUSTYPE_PCI) {
Nathan Hintz5fe2e072012-05-04 21:56:32 -070098 memset(out, 0, sizeof(struct ssb_sprom));
Hauke Mehrtensfe6f3642011-05-10 23:31:32 +020099 snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
100 bus->host_pci->bus->number + 1,
101 PCI_SLOT(bus->host_pci->devfn));
Hauke Mehrtensb8ebbaf2012-10-03 11:34:20 +0000102 bcm47xx_fill_sprom(out, prefix, false);
Hauke Mehrtensfe6f3642011-05-10 23:31:32 +0200103 return 0;
104 } else {
105 printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n");
106 return -EINVAL;
107 }
108}
109
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200110static int bcm47xx_get_invariants(struct ssb_bus *bus,
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +0100111 struct ssb_init_invariants *iv)
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200112{
Hauke Mehrtens2aa088d2010-11-27 17:45:59 +0100113 char buf[20];
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200114
115 /* Fill boardinfo structure */
116 memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
117
Hauke Mehrtensa9bba182012-04-29 02:04:07 +0200118 bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL);
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200119
Nathan Hintz5fe2e072012-05-04 21:56:32 -0700120 memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
Hauke Mehrtensb8ebbaf2012-10-03 11:34:20 +0000121 bcm47xx_fill_sprom(&iv->sprom, NULL, false);
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200122
Hauke Mehrtens111bd982012-12-26 19:51:14 +0000123 if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
Hauke Mehrtens2aa088d2010-11-27 17:45:59 +0100124 iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200125
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200126 return 0;
127}
128
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200129static void __init bcm47xx_register_ssb(void)
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200130{
131 int err;
Hauke Mehrtens1690a7f2010-11-27 17:46:01 +0100132 char buf[100];
133 struct ssb_mipscore *mcore;
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200134
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +0100135 err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb);
Hauke Mehrtensfe6f3642011-05-10 23:31:32 +0200136 if (err)
137 printk(KERN_WARNING "bcm47xx: someone else already registered"
138 " a ssb SPROM callback handler (err %d)\n", err);
139
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200140 err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200141 bcm47xx_get_invariants);
142 if (err)
Ralf Baechleab75dc02011-11-17 15:07:31 +0000143 panic("Failed to initialize SSB bus (err %d)", err);
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200144
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200145 mcore = &bcm47xx_bus.ssb.mipscore;
Hauke Mehrtens111bd982012-12-26 19:51:14 +0000146 if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
Hauke Mehrtens1690a7f2010-11-27 17:46:01 +0100147 if (strstr(buf, "console=ttyS1")) {
148 struct ssb_serial_port port;
149
150 printk(KERN_DEBUG "Swapping serial ports!\n");
151 /* swap serial ports */
152 memcpy(&port, &mcore->serial_ports[0], sizeof(port));
153 memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
154 sizeof(port));
155 memcpy(&mcore->serial_ports[1], &port, sizeof(port));
156 }
157 }
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200158}
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200159#endif
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200160
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200161#ifdef CONFIG_BCM47XX_BCMA
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +0100162static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
163{
164 char prefix[10];
165 struct bcma_device *core;
166
167 switch (bus->hosttype) {
168 case BCMA_HOSTTYPE_PCI:
Nathan Hintz5fe2e072012-05-04 21:56:32 -0700169 memset(out, 0, sizeof(struct ssb_sprom));
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +0100170 snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
171 bus->host_pci->bus->number + 1,
172 PCI_SLOT(bus->host_pci->devfn));
Hauke Mehrtensb8ebbaf2012-10-03 11:34:20 +0000173 bcm47xx_fill_sprom(out, prefix, false);
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +0100174 return 0;
175 case BCMA_HOSTTYPE_SOC:
Nathan Hintz5fe2e072012-05-04 21:56:32 -0700176 memset(out, 0, sizeof(struct ssb_sprom));
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +0100177 core = bcma_find_core(bus, BCMA_CORE_80211);
178 if (core) {
179 snprintf(prefix, sizeof(prefix), "sb/%u/",
180 core->core_index);
Hauke Mehrtensb8ebbaf2012-10-03 11:34:20 +0000181 bcm47xx_fill_sprom(out, prefix, true);
Hauke Mehrtens2c376312012-10-03 11:34:19 +0000182 } else {
Hauke Mehrtensb8ebbaf2012-10-03 11:34:20 +0000183 bcm47xx_fill_sprom(out, NULL, false);
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +0100184 }
185 return 0;
186 default:
187 pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n");
188 return -EINVAL;
189 }
190}
191
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200192static void __init bcm47xx_register_bcma(void)
193{
194 int err;
195
Hauke Mehrtensf384b3d2012-02-28 00:56:14 +0100196 err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma);
197 if (err)
198 pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err);
199
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200200 err = bcma_host_soc_register(&bcm47xx_bus.bcma);
201 if (err)
Ralf Baechleab75dc02011-11-17 15:07:31 +0000202 panic("Failed to initialize BCMA bus (err %d)", err);
Hauke Mehrtens0a2fcaa2012-04-29 02:04:08 +0200203
204 bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL);
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200205}
206#endif
207
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +0200208void __init plat_mem_setup(void)
209{
210 struct cpuinfo_mips *c = &current_cpu_data;
211
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200212 if (c->cputype == CPU_74K) {
213 printk(KERN_INFO "bcm47xx: using bcma bus\n");
214#ifdef CONFIG_BCM47XX_BCMA
215 bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
216 bcm47xx_register_bcma();
Hauke Mehrtensdd573282013-09-19 23:40:09 +0200217 bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +0200218#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200219 } else {
220 printk(KERN_INFO "bcm47xx: using ssb bus\n");
221#ifdef CONFIG_BCM47XX_SSB
222 bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
223 bcm47xx_register_ssb();
Hauke Mehrtensdd573282013-09-19 23:40:09 +0200224 bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200225#endif
226 }
Hauke Mehrtens1690a7f2010-11-27 17:46:01 +0100227
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200228 _machine_restart = bcm47xx_machine_restart;
229 _machine_halt = bcm47xx_machine_halt;
230 pm_power_off = bcm47xx_machine_halt;
Hauke Mehrtens786c4972013-09-18 13:29:57 +0200231 bcm47xx_board_detect();
Hauke Mehrtens7da4b6f2014-01-14 12:06:08 +0100232 mips_set_machine_name(bcm47xx_board_get_name());
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200233}
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200234
Hauke Mehrtens3c06b122014-01-14 19:36:55 +0100235static int __init bcm47xx_cpu_fixes(void)
236{
237 switch (bcm47xx_bus_type) {
238#ifdef CONFIG_BCM47XX_SSB
239 case BCM47XX_BUS_TYPE_SSB:
240 /* Nothing to do */
241 break;
242#endif
243#ifdef CONFIG_BCM47XX_BCMA
244 case BCM47XX_BUS_TYPE_BCMA:
245 /* The BCM4706 has a problem with the CPU wait instruction.
246 * When r4k_wait or r4k_wait_irqoff is used will just hang and
247 * not return from a msleep(). Removing the cpu_wait
248 * functionality is a workaround for this problem. The BCM4716
249 * does not have this problem.
250 */
251 if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
252 cpu_wait = NULL;
253 break;
254#endif
255 }
256 return 0;
257}
258arch_initcall(bcm47xx_cpu_fixes);
259
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200260static int __init bcm47xx_register_bus_complete(void)
261{
262 switch (bcm47xx_bus_type) {
263#ifdef CONFIG_BCM47XX_SSB
264 case BCM47XX_BUS_TYPE_SSB:
265 /* Nothing to do */
266 break;
267#endif
268#ifdef CONFIG_BCM47XX_BCMA
269 case BCM47XX_BUS_TYPE_BCMA:
270 bcma_bus_register(&bcm47xx_bus.bcma.bus);
271 break;
272#endif
273 }
Rafał Miłeckief1e3e72014-01-14 12:36:29 +0100274 bcm47xx_buttons_register();
Rafał Miłecki515fa752014-01-14 12:14:41 +0100275 bcm47xx_leds_register();
276
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +0200277 return 0;
278}
279device_initcall(bcm47xx_register_bus_complete);