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> |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 35 | #include <asm/fw/cfe/cfe_api.h> |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 36 | #include <asm/mach-bcm47xx/nvram.h> |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 37 | |
| 38 | struct ssb_bus ssb_bcm47xx; |
| 39 | EXPORT_SYMBOL(ssb_bcm47xx); |
| 40 | |
| 41 | static void bcm47xx_machine_restart(char *command) |
| 42 | { |
| 43 | printk(KERN_ALERT "Please stand by while rebooting the system...\n"); |
| 44 | local_irq_disable(); |
| 45 | /* Set the watchdog timer to reset immediately */ |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 46 | ssb_watchdog_timer_set(&ssb_bcm47xx, 1); |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 47 | while (1) |
| 48 | cpu_relax(); |
| 49 | } |
| 50 | |
| 51 | static void bcm47xx_machine_halt(void) |
| 52 | { |
| 53 | /* Disable interrupts and watchdog and spin forever */ |
| 54 | local_irq_disable(); |
Aurelien Jarno | b06f3e1 | 2008-10-14 11:44:26 +0200 | [diff] [blame] | 55 | ssb_watchdog_timer_set(&ssb_bcm47xx, 0); |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 56 | while (1) |
| 57 | cpu_relax(); |
| 58 | } |
| 59 | |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 60 | static void str2eaddr(char *str, char *dest) |
| 61 | { |
| 62 | int i = 0; |
| 63 | |
| 64 | if (str == NULL) { |
| 65 | memset(dest, 0, 6); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | for (;;) { |
| 70 | dest[i++] = (char) simple_strtoul(str, NULL, 16); |
| 71 | str += 2; |
| 72 | if (!*str++ || i == 6) |
| 73 | break; |
| 74 | } |
| 75 | } |
| 76 | |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 77 | static int bcm47xx_get_invariants(struct ssb_bus *bus, |
| 78 | struct ssb_init_invariants *iv) |
| 79 | { |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 80 | char buf[100]; |
| 81 | |
| 82 | /* Fill boardinfo structure */ |
| 83 | memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo)); |
| 84 | |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 85 | if (cfe_getenv("boardvendor", buf, sizeof(buf)) >= 0 || |
| 86 | nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 87 | iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0); |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 88 | if (cfe_getenv("boardtype", buf, sizeof(buf)) >= 0 || |
| 89 | nvram_getenv("boardtype", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 90 | iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0); |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 91 | if (cfe_getenv("boardrev", buf, sizeof(buf)) >= 0 || |
| 92 | nvram_getenv("boardrev", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 93 | iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0); |
| 94 | |
| 95 | /* Fill sprom structure */ |
| 96 | memset(&(iv->sprom), 0, sizeof(struct ssb_sprom)); |
| 97 | iv->sprom.revision = 3; |
| 98 | |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 99 | if (cfe_getenv("et0macaddr", buf, sizeof(buf)) >= 0 || |
| 100 | nvram_getenv("et0macaddr", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | cc2d6f7 | 2008-02-18 11:04:31 +0100 | [diff] [blame] | 101 | str2eaddr(buf, iv->sprom.et0mac); |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 102 | |
| 103 | if (cfe_getenv("et1macaddr", buf, sizeof(buf)) >= 0 || |
| 104 | nvram_getenv("et1macaddr", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | cc2d6f7 | 2008-02-18 11:04:31 +0100 | [diff] [blame] | 105 | str2eaddr(buf, iv->sprom.et1mac); |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 106 | |
| 107 | if (cfe_getenv("et0phyaddr", buf, sizeof(buf)) >= 0 || |
| 108 | nvram_getenv("et0phyaddr", buf, sizeof(buf)) >= 0) |
| 109 | iv->sprom.et0phyaddr = simple_strtoul(buf, NULL, 0); |
| 110 | |
| 111 | if (cfe_getenv("et1phyaddr", buf, sizeof(buf)) >= 0 || |
| 112 | nvram_getenv("et1phyaddr", buf, sizeof(buf)) >= 0) |
| 113 | iv->sprom.et1phyaddr = simple_strtoul(buf, NULL, 0); |
| 114 | |
| 115 | if (cfe_getenv("et0mdcport", buf, sizeof(buf)) >= 0 || |
| 116 | nvram_getenv("et0mdcport", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | cc2d6f7 | 2008-02-18 11:04:31 +0100 | [diff] [blame] | 117 | iv->sprom.et0mdcport = simple_strtoul(buf, NULL, 10); |
Waldemar Brodkorb | 121915c | 2010-06-08 19:06:01 +0200 | [diff] [blame] | 118 | |
| 119 | if (cfe_getenv("et1mdcport", buf, sizeof(buf)) >= 0 || |
| 120 | nvram_getenv("et1mdcport", buf, sizeof(buf)) >= 0) |
Aurelien Jarno | cc2d6f7 | 2008-02-18 11:04:31 +0100 | [diff] [blame] | 121 | iv->sprom.et1mdcport = simple_strtoul(buf, NULL, 10); |
Aurelien Jarno | 25e5fb9 | 2007-09-25 15:41:24 +0200 | [diff] [blame] | 122 | |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | void __init plat_mem_setup(void) |
| 127 | { |
| 128 | int err; |
| 129 | |
| 130 | err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE, |
| 131 | bcm47xx_get_invariants); |
| 132 | if (err) |
| 133 | panic("Failed to initialize SSB bus (err %d)\n", err); |
| 134 | |
| 135 | _machine_restart = bcm47xx_machine_restart; |
| 136 | _machine_halt = bcm47xx_machine_halt; |
| 137 | pm_power_off = bcm47xx_machine_halt; |
Aurelien Jarno | 1c0c13e | 2007-09-25 15:40:12 +0200 | [diff] [blame] | 138 | } |