MIPS: BCM47xx: Use sscanf for parsing mac address
[deliverable/linux.git] / arch / mips / bcm47xx / setup.c
CommitLineData
1c0c13eb
AJ
1/*
2 * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
1c0c13eb
AJ
3 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
4 * Copyright (C) 2006 Michael Buesch <mb@bu3sch.de>
121915c4 5 * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
1c0c13eb
AJ
6 *
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>
b06f3e19 30#include <linux/ssb/ssb_embedded.h>
25e5fb97 31#include <asm/bootinfo.h>
1c0c13eb
AJ
32#include <asm/reboot.h>
33#include <asm/time.h>
34#include <bcm47xx.h>
121915c4 35#include <asm/mach-bcm47xx/nvram.h>
1c0c13eb
AJ
36
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 */
b06f3e19 45 ssb_watchdog_timer_set(&ssb_bcm47xx, 1);
1c0c13eb
AJ
46 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();
b06f3e19 54 ssb_watchdog_timer_set(&ssb_bcm47xx, 0);
1c0c13eb
AJ
55 while (1)
56 cpu_relax();
57}
58
2aa088d6
HM
59#define READ_FROM_NVRAM(_outvar, name, buf) \
60 if (nvram_getenv(name, buf, sizeof(buf)) >= 0)\
61 sprom->_outvar = simple_strtoul(buf, NULL, 0);
62
63static void bcm47xx_fill_sprom(struct ssb_sprom *sprom)
64{
65 char buf[100];
66 u32 boardflags;
67
68 memset(sprom, 0, sizeof(struct ssb_sprom));
69
70 sprom->revision = 1; /* Fallback: Old hardware does not define this. */
71 READ_FROM_NVRAM(revision, "sromrev", buf);
72 if (nvram_getenv("il0macaddr", buf, sizeof(buf)) >= 0)
59833fcf 73 nvram_parse_macaddr(buf, sprom->il0mac);
2aa088d6 74 if (nvram_getenv("et0macaddr", buf, sizeof(buf)) >= 0)
59833fcf 75 nvram_parse_macaddr(buf, sprom->et0mac);
2aa088d6 76 if (nvram_getenv("et1macaddr", buf, sizeof(buf)) >= 0)
59833fcf 77 nvram_parse_macaddr(buf, sprom->et1mac);
2aa088d6
HM
78 READ_FROM_NVRAM(et0phyaddr, "et0phyaddr", buf);
79 READ_FROM_NVRAM(et1phyaddr, "et1phyaddr", buf);
80 READ_FROM_NVRAM(et0mdcport, "et0mdcport", buf);
81 READ_FROM_NVRAM(et1mdcport, "et1mdcport", buf);
82 READ_FROM_NVRAM(board_rev, "boardrev", buf);
83 READ_FROM_NVRAM(country_code, "ccode", buf);
84 READ_FROM_NVRAM(ant_available_a, "aa5g", buf);
85 READ_FROM_NVRAM(ant_available_bg, "aa2g", buf);
86 READ_FROM_NVRAM(pa0b0, "pa0b0", buf);
87 READ_FROM_NVRAM(pa0b1, "pa0b1", buf);
88 READ_FROM_NVRAM(pa0b2, "pa0b2", buf);
89 READ_FROM_NVRAM(pa1b0, "pa1b0", buf);
90 READ_FROM_NVRAM(pa1b1, "pa1b1", buf);
91 READ_FROM_NVRAM(pa1b2, "pa1b2", buf);
92 READ_FROM_NVRAM(pa1lob0, "pa1lob0", buf);
93 READ_FROM_NVRAM(pa1lob2, "pa1lob1", buf);
94 READ_FROM_NVRAM(pa1lob1, "pa1lob2", buf);
95 READ_FROM_NVRAM(pa1hib0, "pa1hib0", buf);
96 READ_FROM_NVRAM(pa1hib2, "pa1hib1", buf);
97 READ_FROM_NVRAM(pa1hib1, "pa1hib2", buf);
98 READ_FROM_NVRAM(gpio0, "wl0gpio0", buf);
99 READ_FROM_NVRAM(gpio1, "wl0gpio1", buf);
100 READ_FROM_NVRAM(gpio2, "wl0gpio2", buf);
101 READ_FROM_NVRAM(gpio3, "wl0gpio3", buf);
102 READ_FROM_NVRAM(maxpwr_bg, "pa0maxpwr", buf);
103 READ_FROM_NVRAM(maxpwr_al, "pa1lomaxpwr", buf);
104 READ_FROM_NVRAM(maxpwr_a, "pa1maxpwr", buf);
105 READ_FROM_NVRAM(maxpwr_ah, "pa1himaxpwr", buf);
106 READ_FROM_NVRAM(itssi_a, "pa1itssit", buf);
107 READ_FROM_NVRAM(itssi_bg, "pa0itssit", buf);
108 READ_FROM_NVRAM(tri2g, "tri2g", buf);
109 READ_FROM_NVRAM(tri5gl, "tri5gl", buf);
110 READ_FROM_NVRAM(tri5g, "tri5g", buf);
111 READ_FROM_NVRAM(tri5gh, "tri5gh", buf);
112 READ_FROM_NVRAM(rxpo2g, "rxpo2g", buf);
113 READ_FROM_NVRAM(rxpo5g, "rxpo5g", buf);
114 READ_FROM_NVRAM(rssisav2g, "rssisav2g", buf);
115 READ_FROM_NVRAM(rssismc2g, "rssismc2g", buf);
116 READ_FROM_NVRAM(rssismf2g, "rssismf2g", buf);
117 READ_FROM_NVRAM(bxa2g, "bxa2g", buf);
118 READ_FROM_NVRAM(rssisav5g, "rssisav5g", buf);
119 READ_FROM_NVRAM(rssismc5g, "rssismc5g", buf);
120 READ_FROM_NVRAM(rssismf5g, "rssismf5g", buf);
121 READ_FROM_NVRAM(bxa5g, "bxa5g", buf);
122 READ_FROM_NVRAM(cck2gpo, "cck2gpo", buf);
123 READ_FROM_NVRAM(ofdm2gpo, "ofdm2gpo", buf);
124 READ_FROM_NVRAM(ofdm5glpo, "ofdm5glpo", buf);
125 READ_FROM_NVRAM(ofdm5gpo, "ofdm5gpo", buf);
126 READ_FROM_NVRAM(ofdm5ghpo, "ofdm5ghpo", buf);
127
128 if (nvram_getenv("boardflags", buf, sizeof(buf)) >= 0) {
129 boardflags = simple_strtoul(buf, NULL, 0);
130 if (boardflags) {
131 sprom->boardflags_lo = (boardflags & 0x0000FFFFU);
132 sprom->boardflags_hi = (boardflags & 0xFFFF0000U) >> 16;
133 }
134 }
135 if (nvram_getenv("boardflags2", buf, sizeof(buf)) >= 0) {
136 boardflags = simple_strtoul(buf, NULL, 0);
137 if (boardflags) {
138 sprom->boardflags2_lo = (boardflags & 0x0000FFFFU);
139 sprom->boardflags2_hi = (boardflags & 0xFFFF0000U) >> 16;
140 }
141 }
142}
143
1c0c13eb
AJ
144static int bcm47xx_get_invariants(struct ssb_bus *bus,
145 struct ssb_init_invariants *iv)
146{
2aa088d6 147 char buf[20];
25e5fb97
AJ
148
149 /* Fill boardinfo structure */
150 memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
151
82571084 152 if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0)
2aa088d6
HM
153 iv->boardinfo.vendor = (u16)simple_strtoul(buf, NULL, 0);
154 else
155 iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
82571084 156 if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
25e5fb97 157 iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
82571084 158 if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
25e5fb97
AJ
159 iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);
160
2aa088d6 161 bcm47xx_fill_sprom(&iv->sprom);
121915c4 162
2aa088d6
HM
163 if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
164 iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
25e5fb97 165
1c0c13eb
AJ
166 return 0;
167}
168
169void __init plat_mem_setup(void)
170{
171 int err;
172
173 err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE,
174 bcm47xx_get_invariants);
175 if (err)
176 panic("Failed to initialize SSB bus (err %d)\n", err);
177
178 _machine_restart = bcm47xx_machine_restart;
179 _machine_halt = bcm47xx_machine_halt;
180 pm_power_off = bcm47xx_machine_halt;
1c0c13eb 181}
This page took 0.271247 seconds and 5 git commands to generate.