change prefix for kernelpatchbase 2.6.26
[openwrt.git] / target / linux / brcm47xx / files-2.6.23 / 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-2008 Michael Buesch <mb@bu3sch.de>
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 <linux/serial_8250.h>
35 #include <asm/bootinfo.h>
36 #include <asm/time.h>
37 #include <asm/reboot.h>
38 #include <asm/cfe.h>
39 #include <linux/pm.h>
40 #include <linux/ssb/ssb.h>
41 #include <linux/ssb/ssb_embedded.h>
42
43 #include <nvram.h>
44
45 extern void bcm47xx_pci_init(void);
46 extern void bcm47xx_time_init(void);
47
48 struct ssb_bus ssb;
49
50
51 int pcibios_plat_dev_init(struct pci_dev *dev)
52 {
53 int err;
54
55 err = ssb_pcibios_plat_dev_init(dev);
56 if (err) {
57 printk(KERN_ALERT "PCI: Failed to init device %s\n",
58 pci_name(dev));
59 }
60
61 return err;
62 }
63
64 static void bcm47xx_machine_restart(char *command)
65 {
66 printk(KERN_ALERT "Please stand by while rebooting the system...\n");
67 local_irq_disable();
68 /* CFE has a reboot callback, but that does not work.
69 * Oopses with: Reserved instruction in kernel code.
70 */
71
72 /* Set the watchdog timer to reset immediately */
73 if (ssb_watchdog_timer_set(&ssb, 1))
74 printk(KERN_EMERG "SSB watchdog-triggered reboot failed!\n");
75 while (1)
76 cpu_relax();
77 }
78
79 static void bcm47xx_machine_halt(void)
80 {
81 /* Disable interrupts and watchdog and spin forever */
82 local_irq_disable();
83 if (ssb_watchdog_timer_set(&ssb, 0))
84 printk(KERN_EMERG "Failed to disable SSB watchdog!\n");
85 while (1)
86 cpu_relax();
87 }
88
89 static void e_aton(char *str, char *dest)
90 {
91 int i = 0;
92
93 if (str == NULL) {
94 memset(dest, 0, 6);
95 return;
96 }
97
98 for (;;) {
99 dest[i++] = (char) simple_strtoul(str, NULL, 16);
100 str += 2;
101 if (!*str++ || i == 6)
102 break;
103 }
104 }
105
106 static void bcm47xx_fill_sprom(struct ssb_sprom *sprom)
107 {
108 char *s;
109
110 memset(sprom, 0xFF, sizeof(struct ssb_sprom));
111
112 sprom->revision = 1;
113 if ((s = nvram_get("il0macaddr")))
114 e_aton(s, sprom->il0mac);
115 if ((s = nvram_get("et0macaddr")))
116 e_aton(s, sprom->et0mac);
117 if ((s = nvram_get("et1macaddr")))
118 e_aton(s, sprom->et1mac);
119 if ((s = nvram_get("et0phyaddr")))
120 sprom->et0phyaddr = simple_strtoul(s, NULL, 0);
121 if ((s = nvram_get("et1phyaddr")))
122 sprom->et1phyaddr = simple_strtoul(s, NULL, 0);
123 if ((s = nvram_get("et0mdcport")))
124 sprom->et0mdcport = !!simple_strtoul(s, NULL, 10);
125 if ((s = nvram_get("et1mdcport")))
126 sprom->et1mdcport = !!simple_strtoul(s, NULL, 10);
127 if ((s = nvram_get("pa0b0")))
128 sprom->pa0b0 = simple_strtoul(s, NULL, 0);
129 if ((s = nvram_get("pa0b1")))
130 sprom->pa0b1 = simple_strtoul(s, NULL, 0);
131 if ((s = nvram_get("pa0b2")))
132 sprom->pa0b2 = simple_strtoul(s, NULL, 0);
133 if ((s = nvram_get("pa1b0")))
134 sprom->pa1b0 = simple_strtoul(s, NULL, 0);
135 if ((s = nvram_get("pa1b1")))
136 sprom->pa1b1 = simple_strtoul(s, NULL, 0);
137 if ((s = nvram_get("pa1b2")))
138 sprom->pa1b2 = simple_strtoul(s, NULL, 0);
139 if ((s = nvram_get("wl0gpio0")))
140 sprom->gpio0 = simple_strtoul(s, NULL, 0);
141 if ((s = nvram_get("wl0gpio1")))
142 sprom->gpio1 = simple_strtoul(s, NULL, 0);
143 if ((s = nvram_get("wl0gpio2")))
144 sprom->gpio2 = simple_strtoul(s, NULL, 0);
145 if ((s = nvram_get("wl0gpio3")))
146 sprom->gpio3 = simple_strtoul(s, NULL, 0);
147 if ((s = nvram_get("pa0maxpwr")))
148 sprom->maxpwr_bg = simple_strtoul(s, NULL, 0);
149 if ((s = nvram_get("pa1maxpwr")))
150 sprom->maxpwr_a = simple_strtoul(s, NULL, 0);
151 if ((s = nvram_get("pa0itssit")))
152 sprom->itssi_bg = simple_strtoul(s, NULL, 0);
153 if ((s = nvram_get("pa1itssit")))
154 sprom->itssi_a = simple_strtoul(s, NULL, 0);
155 sprom->boardflags_lo = 0;
156 if ((s = nvram_get("boardflags")))
157 sprom->boardflags_lo = simple_strtoul(s, NULL, 0);
158 sprom->boardflags_hi = 0;
159 if ((s = nvram_get("boardflags2")))
160 sprom->boardflags_hi = simple_strtoul(s, NULL, 0);
161 }
162
163 static int bcm47xx_get_invariants(struct ssb_bus *bus, struct ssb_init_invariants *iv)
164 {
165 char *s;
166
167 iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
168 if ((s = nvram_get("boardtype")))
169 iv->boardinfo.type = (u16)simple_strtoul(s, NULL, 0);
170 if ((s = nvram_get("boardrev")))
171 iv->boardinfo.rev = (u16)simple_strtoul(s, NULL, 0);
172
173 bcm47xx_fill_sprom(&iv->sprom);
174
175 if ((s = nvram_get("cardbus")))
176 iv->has_cardbus_slot = !!simple_strtoul(s, NULL, 10);
177
178 return 0;
179 }
180
181 void __init plat_mem_setup(void)
182 {
183 int i, err;
184 char *s;
185 struct ssb_mipscore *mcore;
186
187 err = ssb_bus_ssbbus_register(&ssb, SSB_ENUM_BASE, bcm47xx_get_invariants);
188 if (err) {
189 const char *msg = "Failed to initialize SSB bus (err %d)\n";
190 cfe_printk(msg, err); /* Make sure the message gets out of the box. */
191 panic(msg, err);
192 }
193 mcore = &ssb.mipscore;
194
195 s = nvram_get("kernel_args");
196 if (s && !strncmp(s, "console=ttyS1", 13)) {
197 struct ssb_serial_port port;
198
199 cfe_printk("Swapping serial ports!\n");
200 /* swap serial ports */
201 memcpy(&port, &mcore->serial_ports[0], sizeof(port));
202 memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1], sizeof(port));
203 memcpy(&mcore->serial_ports[1], &port, sizeof(port));
204 }
205
206 for (i = 0; i < mcore->nr_serial_ports; i++) {
207 struct ssb_serial_port *port = &(mcore->serial_ports[i]);
208 struct uart_port s;
209
210 memset(&s, 0, sizeof(s));
211 s.line = i;
212 s.membase = port->regs;
213 s.irq = port->irq + 2;
214 s.uartclk = port->baud_base;
215 s.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
216 s.iotype = SERIAL_IO_MEM;
217 s.regshift = port->reg_shift;
218
219 early_serial_setup(&s);
220 }
221 cfe_printk("Serial init done.\n");
222
223 _machine_restart = bcm47xx_machine_restart;
224 _machine_halt = bcm47xx_machine_halt;
225 pm_power_off = bcm47xx_machine_halt;
226 board_time_init = bcm47xx_time_init;
227 }
228
229 static int __init bcm47xx_register_gpiodev(void)
230 {
231 static struct resource res = {
232 .start = 0xFFFFFFFF,
233 };
234 struct platform_device *pdev;
235
236 pdev = platform_device_register_simple("GPIODEV", 0, &res, 1);
237 if (!pdev) {
238 printk(KERN_ERR "bcm47xx: GPIODEV init failed\n");
239 return -ENODEV;
240 }
241
242 return 0;
243 }
244 device_initcall(bcm47xx_register_gpiodev);
245
246 EXPORT_SYMBOL(ssb);
This page took 0.053726 seconds and 5 git commands to generate.