Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org> |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 3 | * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org> |
| 4 | * Copyright (C) 2006 Michael Buesch <mb@bu3sch.de> |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 5 | * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org> |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 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> |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 30 | #include <linux/ssb/ssb_embedded.h> |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 31 | #include <asm/bootinfo.h> |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 32 | #include <asm/reboot.h> |
| 33 | #include <asm/time.h> |
| 34 | #include <bcm47xx.h> |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 35 | #include <asm/mach-bcm47xx/nvram.h> |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 36 | |
| 37 | struct ssb_bus ssb_bcm47xx; |
| 38 | EXPORT_SYMBOL(ssb_bcm47xx); |
| 39 | |
| 40 | static 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 Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 45 | ssb_watchdog_timer_set(&ssb_bcm47xx, 1); |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 46 | while (1) |
| 47 | cpu_relax(); |
| 48 | } |
| 49 | |
| 50 | static void bcm47xx_machine_halt(void) |
| 51 | { |
| 52 | /* Disable interrupts and watchdog and spin forever */ |
| 53 | local_irq_disable(); |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 54 | ssb_watchdog_timer_set(&ssb_bcm47xx, 0); |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 55 | while (1) |
| 56 | cpu_relax(); |
| 57 | } |
| 58 | |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 59 | static 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 | |
Hauke Mehrtens | 2aa088d6 | 2010-11-27 17:45:59 +0100 | [diff] [blame^] | 76 | #define READ_FROM_NVRAM(_outvar, name, buf) \ |
| 77 | if (nvram_getenv(name, buf, sizeof(buf)) >= 0)\ |
| 78 | sprom->_outvar = simple_strtoul(buf, NULL, 0); |
| 79 | |
| 80 | static void bcm47xx_fill_sprom(struct ssb_sprom *sprom) |
| 81 | { |
| 82 | char buf[100]; |
| 83 | u32 boardflags; |
| 84 | |
| 85 | memset(sprom, 0, sizeof(struct ssb_sprom)); |
| 86 | |
| 87 | sprom->revision = 1; /* Fallback: Old hardware does not define this. */ |
| 88 | READ_FROM_NVRAM(revision, "sromrev", buf); |
| 89 | if (nvram_getenv("il0macaddr", buf, sizeof(buf)) >= 0) |
| 90 | str2eaddr(buf, sprom->il0mac); |
| 91 | if (nvram_getenv("et0macaddr", buf, sizeof(buf)) >= 0) |
| 92 | str2eaddr(buf, sprom->et0mac); |
| 93 | if (nvram_getenv("et1macaddr", buf, sizeof(buf)) >= 0) |
| 94 | str2eaddr(buf, sprom->et1mac); |
| 95 | READ_FROM_NVRAM(et0phyaddr, "et0phyaddr", buf); |
| 96 | READ_FROM_NVRAM(et1phyaddr, "et1phyaddr", buf); |
| 97 | READ_FROM_NVRAM(et0mdcport, "et0mdcport", buf); |
| 98 | READ_FROM_NVRAM(et1mdcport, "et1mdcport", buf); |
| 99 | READ_FROM_NVRAM(board_rev, "boardrev", buf); |
| 100 | READ_FROM_NVRAM(country_code, "ccode", buf); |
| 101 | READ_FROM_NVRAM(ant_available_a, "aa5g", buf); |
| 102 | READ_FROM_NVRAM(ant_available_bg, "aa2g", buf); |
| 103 | READ_FROM_NVRAM(pa0b0, "pa0b0", buf); |
| 104 | READ_FROM_NVRAM(pa0b1, "pa0b1", buf); |
| 105 | READ_FROM_NVRAM(pa0b2, "pa0b2", buf); |
| 106 | READ_FROM_NVRAM(pa1b0, "pa1b0", buf); |
| 107 | READ_FROM_NVRAM(pa1b1, "pa1b1", buf); |
| 108 | READ_FROM_NVRAM(pa1b2, "pa1b2", buf); |
| 109 | READ_FROM_NVRAM(pa1lob0, "pa1lob0", buf); |
| 110 | READ_FROM_NVRAM(pa1lob2, "pa1lob1", buf); |
| 111 | READ_FROM_NVRAM(pa1lob1, "pa1lob2", buf); |
| 112 | READ_FROM_NVRAM(pa1hib0, "pa1hib0", buf); |
| 113 | READ_FROM_NVRAM(pa1hib2, "pa1hib1", buf); |
| 114 | READ_FROM_NVRAM(pa1hib1, "pa1hib2", buf); |
| 115 | READ_FROM_NVRAM(gpio0, "wl0gpio0", buf); |
| 116 | READ_FROM_NVRAM(gpio1, "wl0gpio1", buf); |
| 117 | READ_FROM_NVRAM(gpio2, "wl0gpio2", buf); |
| 118 | READ_FROM_NVRAM(gpio3, "wl0gpio3", buf); |
| 119 | READ_FROM_NVRAM(maxpwr_bg, "pa0maxpwr", buf); |
| 120 | READ_FROM_NVRAM(maxpwr_al, "pa1lomaxpwr", buf); |
| 121 | READ_FROM_NVRAM(maxpwr_a, "pa1maxpwr", buf); |
| 122 | READ_FROM_NVRAM(maxpwr_ah, "pa1himaxpwr", buf); |
| 123 | READ_FROM_NVRAM(itssi_a, "pa1itssit", buf); |
| 124 | READ_FROM_NVRAM(itssi_bg, "pa0itssit", buf); |
| 125 | READ_FROM_NVRAM(tri2g, "tri2g", buf); |
| 126 | READ_FROM_NVRAM(tri5gl, "tri5gl", buf); |
| 127 | READ_FROM_NVRAM(tri5g, "tri5g", buf); |
| 128 | READ_FROM_NVRAM(tri5gh, "tri5gh", buf); |
| 129 | READ_FROM_NVRAM(rxpo2g, "rxpo2g", buf); |
| 130 | READ_FROM_NVRAM(rxpo5g, "rxpo5g", buf); |
| 131 | READ_FROM_NVRAM(rssisav2g, "rssisav2g", buf); |
| 132 | READ_FROM_NVRAM(rssismc2g, "rssismc2g", buf); |
| 133 | READ_FROM_NVRAM(rssismf2g, "rssismf2g", buf); |
| 134 | READ_FROM_NVRAM(bxa2g, "bxa2g", buf); |
| 135 | READ_FROM_NVRAM(rssisav5g, "rssisav5g", buf); |
| 136 | READ_FROM_NVRAM(rssismc5g, "rssismc5g", buf); |
| 137 | READ_FROM_NVRAM(rssismf5g, "rssismf5g", buf); |
| 138 | READ_FROM_NVRAM(bxa5g, "bxa5g", buf); |
| 139 | READ_FROM_NVRAM(cck2gpo, "cck2gpo", buf); |
| 140 | READ_FROM_NVRAM(ofdm2gpo, "ofdm2gpo", buf); |
| 141 | READ_FROM_NVRAM(ofdm5glpo, "ofdm5glpo", buf); |
| 142 | READ_FROM_NVRAM(ofdm5gpo, "ofdm5gpo", buf); |
| 143 | READ_FROM_NVRAM(ofdm5ghpo, "ofdm5ghpo", buf); |
| 144 | |
| 145 | if (nvram_getenv("boardflags", buf, sizeof(buf)) >= 0) { |
| 146 | boardflags = simple_strtoul(buf, NULL, 0); |
| 147 | if (boardflags) { |
| 148 | sprom->boardflags_lo = (boardflags & 0x0000FFFFU); |
| 149 | sprom->boardflags_hi = (boardflags & 0xFFFF0000U) >> 16; |
| 150 | } |
| 151 | } |
| 152 | if (nvram_getenv("boardflags2", buf, sizeof(buf)) >= 0) { |
| 153 | boardflags = simple_strtoul(buf, NULL, 0); |
| 154 | if (boardflags) { |
| 155 | sprom->boardflags2_lo = (boardflags & 0x0000FFFFU); |
| 156 | sprom->boardflags2_hi = (boardflags & 0xFFFF0000U) >> 16; |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 161 | static int bcm47xx_get_invariants(struct ssb_bus *bus, |
| 162 | struct ssb_init_invariants *iv) |
| 163 | { |
Hauke Mehrtens | 2aa088d6 | 2010-11-27 17:45:59 +0100 | [diff] [blame^] | 164 | char buf[20]; |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 165 | |
| 166 | /* Fill boardinfo structure */ |
| 167 | memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo)); |
| 168 | |
Hauke Mehrtens | 8257108 | 2010-11-27 17:45:58 +0100 | [diff] [blame] | 169 | if (nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0) |
Hauke Mehrtens | 2aa088d6 | 2010-11-27 17:45:59 +0100 | [diff] [blame^] | 170 | iv->boardinfo.vendor = (u16)simple_strtoul(buf, NULL, 0); |
| 171 | else |
| 172 | iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM; |
Hauke Mehrtens | 8257108 | 2010-11-27 17:45:58 +0100 | [diff] [blame] | 173 | if (nvram_getenv("boardtype", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 174 | iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0); |
Hauke Mehrtens | 8257108 | 2010-11-27 17:45:58 +0100 | [diff] [blame] | 175 | if (nvram_getenv("boardrev", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 176 | iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0); |
| 177 | |
Hauke Mehrtens | 2aa088d6 | 2010-11-27 17:45:59 +0100 | [diff] [blame^] | 178 | bcm47xx_fill_sprom(&iv->sprom); |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 179 | |
Hauke Mehrtens | 2aa088d6 | 2010-11-27 17:45:59 +0100 | [diff] [blame^] | 180 | if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0) |
| 181 | iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10); |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 182 | |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | void __init plat_mem_setup(void) |
| 187 | { |
| 188 | int err; |
| 189 | |
| 190 | err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE, |
| 191 | bcm47xx_get_invariants); |
| 192 | if (err) |
| 193 | panic("Failed to initialize SSB bus (err %d)\n", err); |
| 194 | |
| 195 | _machine_restart = bcm47xx_machine_restart; |
| 196 | _machine_halt = bcm47xx_machine_halt; |
| 197 | pm_power_off = bcm47xx_machine_halt; |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 198 | } |