git-svn-id: svn://svn.openwrt.org/openwrt/trunk@6516 3c298f89-4303-0410-b956-a3cf2f4a3e73
[openwrt.git] / target / linux / brcm47xx-2.6 / files / arch / mips / bcm947xx / setup.c
1 /*
2 * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
3 * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
4 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
5 * Copyright (C) 2006 Michael Buesch
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/init.h>
29 #include <linux/types.h>
30 #include <linux/tty.h>
31 #include <linux/serial.h>
32 #include <linux/serial_core.h>
33 #include <linux/serial_reg.h>
34 #include <asm/bootinfo.h>
35 #include <asm/time.h>
36 #include <asm/reboot.h>
37 #include <asm/cfe.h>
38 #include <linux/pm.h>
39 #include <linux/ssb/ssb.h>
40
41 #include <nvram.h>
42
43 extern void bcm47xx_pci_init(void);
44 extern void bcm47xx_time_init(void);
45
46 struct ssb_bus ssb;
47
48 static void bcm47xx_machine_restart(char *command)
49 {
50 printk(KERN_ALERT "Please stand by while rebooting the system...\n");
51 local_irq_disable();
52 /* CFE has a reboot callback, but that does not work.
53 * Oopses with: Reserved instruction in kernel code.
54 */
55
56 /* Set the watchdog timer to reset immediately */
57 //TODO sb_watchdog(sbh, 1);
58 while (1)
59 cpu_relax();
60 }
61
62 static void bcm47xx_machine_halt(void)
63 {
64 /* Disable interrupts and watchdog and spin forever */
65 local_irq_disable();
66 //TODO sb_watchdog(sbh, 0);
67 while (1)
68 cpu_relax();
69 }
70
71 static void e_aton(char *str, char *dest)
72 {
73 int i = 0;
74
75 if (str == NULL) {
76 memset(dest, 0, 6);
77 return;
78 }
79
80 for (;;) {
81 dest[i++] = (char) simple_strtoul(str, NULL, 16);
82 str += 2;
83 if (!*str++ || i == 6)
84 break;
85 }
86 }
87
88 static void bcm47xx_fill_sprom(struct ssb_sprom *sprom)
89 {
90 // TODO
91 }
92
93 static void bcm47xx_fill_sprom_nvram(struct ssb_sprom *sprom)
94 {
95 char *s;
96
97 memset(sprom, 0, sizeof(struct ssb_sprom));
98
99 sprom->revision = 3;
100 if ((s = nvram_get("et0macaddr")))
101 e_aton(s, sprom->r1.et0mac);
102 if ((s = nvram_get("et1macaddr")))
103 e_aton(s, sprom->r1.et1mac);
104 if ((s = nvram_get("et0phyaddr")))
105 sprom->r1.et0phyaddr = simple_strtoul(s, NULL, 10);
106 if ((s = nvram_get("et1phyaddr")))
107 sprom->r1.et1phyaddr = simple_strtoul(s, NULL, 10);
108 }
109
110 void __init plat_mem_setup(void)
111 {
112 int i, err;
113 char *s;
114 struct ssb_mipscore *mcore;
115
116 err = ssb_bus_ssbbus_register(&ssb, SSB_ENUM_BASE, bcm47xx_fill_sprom);
117 if (err) {
118 const char *msg = "Failed to initialize SSB bus (err %d)\n";
119 cfe_printk(msg, err); /* Make sure the message gets out of the box. */
120 panic(msg, err);
121 }
122 mcore = &ssb.mipscore;
123
124 /* FIXME: the nvram init depends on the ssb being fully initializes,
125 * can't use the fill_sprom callback yet! */
126 bcm47xx_fill_sprom_nvram(&ssb.sprom);
127
128 s = nvram_get("kernel_args");
129 if (s && !strncmp(s, "console=ttyS1", 13)) {
130 struct ssb_serial_port port;
131
132 cfe_printk("Swapping serial ports!\n");
133 /* swap serial ports */
134 memcpy(&port, &mcore->serial_ports[0], sizeof(port));
135 memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1], sizeof(port));
136 memcpy(&mcore->serial_ports[1], &port, sizeof(port));
137 }
138
139 for (i = 0; i < mcore->nr_serial_ports; i++) {
140 struct ssb_serial_port *port = &(mcore->serial_ports[i]);
141 struct uart_port s;
142
143 memset(&s, 0, sizeof(s));
144 s.line = i;
145 s.membase = port->regs;
146 s.irq = port->irq + 2;//FIXME?
147 s.uartclk = port->baud_base;
148 s.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
149 s.iotype = SERIAL_IO_MEM;
150 s.regshift = port->reg_shift;
151
152 early_serial_setup(&s);
153 }
154 cfe_printk("Serial init done.\n");
155
156 _machine_restart = bcm47xx_machine_restart;
157 _machine_halt = bcm47xx_machine_halt;
158 pm_power_off = bcm47xx_machine_halt;
159
160 board_time_init = bcm47xx_time_init;//FIXME move into ssb
161 }
162
163 EXPORT_SYMBOL(ssb);
This page took 0.051044 seconds and 5 git commands to generate.