blob: 2c6bdade3f13f34b8ff4908ec686da8158c81272 [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>
4 * Copyright (C) 2006 Michael Buesch <mb@bu3sch.de>
Waldemar Brodkorb121915c2010-06-08 19:06:01 +02005 * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +02006 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#include <linux/types.h>
29#include <linux/ssb/ssb.h>
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020030#include <linux/ssb/ssb_embedded.h>
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020031#include <asm/bootinfo.h>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020032#include <asm/reboot.h>
33#include <asm/time.h>
34#include <bcm47xx.h>
Waldemar Brodkorb121915c2010-06-08 19:06:01 +020035#include <asm/mach-bcm47xx/nvram.h>
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020036
37struct ssb_bus ssb_bcm47xx;
38EXPORT_SYMBOL(ssb_bcm47xx);
39
40static void bcm47xx_machine_restart(char *command)
41{
42 printk(KERN_ALERT "Please stand by while rebooting the system...\n");
43 local_irq_disable();
44 /* Set the watchdog timer to reset immediately */
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020045 ssb_watchdog_timer_set(&ssb_bcm47xx, 1);
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020046 while (1)
47 cpu_relax();
48}
49
50static void bcm47xx_machine_halt(void)
51{
52 /* Disable interrupts and watchdog and spin forever */
53 local_irq_disable();
Aurelien Jarnob06f3e12008-10-14 11:44:26 +020054 ssb_watchdog_timer_set(&ssb_bcm47xx, 0);
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020055 while (1)
56 cpu_relax();
57}
58
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020059static void str2eaddr(char *str, char *dest)
60{
61 int i = 0;
62
63 if (str == NULL) {
64 memset(dest, 0, 6);
65 return;
66 }
67
68 for (;;) {
69 dest[i++] = (char) simple_strtoul(str, NULL, 16);
70 str += 2;
71 if (!*str++ || i == 6)
72 break;
73 }
74}
75
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +020076static int bcm47xx_get_invariants(struct ssb_bus *bus,
77 struct ssb_init_invariants *iv)
78{
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020079 char buf[100];
80
81 /* Fill boardinfo structure */
82 memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
83
Hauke Mehrtens82571082010-11-27 17:45:58 +010084 if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0)
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020085 iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
Hauke Mehrtens82571082010-11-27 17:45:58 +010086 if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020087 iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
Hauke Mehrtens82571082010-11-27 17:45:58 +010088 if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
Aurelien Jarno25e5fb92007-09-25 15:41:24 +020089 iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);
90
91 /* Fill sprom structure */
92 memset(&(iv->sprom), 0, sizeof(struct ssb_sprom));
93 iv->sprom.revision = 3;
94
Hauke Mehrtens82571082010-11-27 17:45:58 +010095 if (nvram_getenv("et0macaddr", buf, sizeof(buf)) >= 0)
Aurelien Jarnocc2d6f72008-02-18 11:04:31 +010096 str2eaddr(buf, iv->sprom.et0mac);
Waldemar Brodkorb121915c2010-06-08 19:06:01 +020097
Hauke Mehrtens82571082010-11-27 17:45:58 +010098 if (nvram_getenv("et1macaddr", buf, sizeof(buf)) >= 0)
Aurelien Jarnocc2d6f72008-02-18 11:04:31 +010099 str2eaddr(buf, iv->sprom.et1mac);
Waldemar Brodkorb121915c2010-06-08 19:06:01 +0200100
Hauke Mehrtens82571082010-11-27 17:45:58 +0100101 if (nvram_getenv("et0phyaddr", buf, sizeof(buf)) >= 0)
Waldemar Brodkorb121915c2010-06-08 19:06:01 +0200102 iv->sprom.et0phyaddr = simple_strtoul(buf, NULL, 0);
103
Hauke Mehrtens82571082010-11-27 17:45:58 +0100104 if (nvram_getenv("et1phyaddr", buf, sizeof(buf)) >= 0)
Waldemar Brodkorb121915c2010-06-08 19:06:01 +0200105 iv->sprom.et1phyaddr = simple_strtoul(buf, NULL, 0);
106
Hauke Mehrtens82571082010-11-27 17:45:58 +0100107 if (nvram_getenv("et0mdcport", buf, sizeof(buf)) >= 0)
Aurelien Jarnocc2d6f72008-02-18 11:04:31 +0100108 iv->sprom.et0mdcport = simple_strtoul(buf, NULL, 10);
Waldemar Brodkorb121915c2010-06-08 19:06:01 +0200109
Hauke Mehrtens82571082010-11-27 17:45:58 +0100110 if (nvram_getenv("et1mdcport", buf, sizeof(buf)) >= 0)
Aurelien Jarnocc2d6f72008-02-18 11:04:31 +0100111 iv->sprom.et1mdcport = simple_strtoul(buf, NULL, 10);
Aurelien Jarno25e5fb92007-09-25 15:41:24 +0200112
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200113 return 0;
114}
115
116void __init plat_mem_setup(void)
117{
118 int err;
119
120 err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE,
121 bcm47xx_get_invariants);
122 if (err)
123 panic("Failed to initialize SSB bus (err %d)\n", err);
124
125 _machine_restart = bcm47xx_machine_restart;
126 _machine_halt = bcm47xx_machine_halt;
127 pm_power_off = bcm47xx_machine_halt;
Aurelien Jarno1c0c13e2007-09-25 15:40:12 +0200128}