127dab59232ceea918f8097543fbf1c1300cd670
[openwrt.git] / target / linux / brcm47xx / patches-2.6.28 / 400-arch-bcm47xx.patch
1 Index: linux-2.6.28.7/arch/mips/Kconfig
2 ===================================================================
3 --- linux-2.6.28.7.orig/arch/mips/Kconfig       2009-03-17 17:26:23.000000000 +0100
4 +++ linux-2.6.28.7/arch/mips/Kconfig    2009-03-17 17:27:33.000000000 +0100
5 @@ -53,6 +53,7 @@ config BCM47XX
6         select SSB_DRIVER_MIPS
7         select SSB_DRIVER_EXTIF
8         select SSB_EMBEDDED
9 +       select SSB_B43_PCI_BRIDGE if PCI
10         select SSB_PCICORE_HOSTMODE if PCI
11         select GENERIC_GPIO
12         select SYS_HAS_EARLY_PRINTK
13 Index: linux-2.6.28.7/arch/mips/bcm47xx/Makefile
14 ===================================================================
15 --- linux-2.6.28.7.orig/arch/mips/bcm47xx/Makefile      2009-03-17 17:26:19.000000000 +0100
16 +++ linux-2.6.28.7/arch/mips/bcm47xx/Makefile   2009-03-17 17:26:56.000000000 +0100
17 @@ -3,4 +3,4 @@
18  # under Linux.
19  #
20  
21 -obj-y := gpio.o irq.o prom.o serial.o setup.o time.o wgt634u.o
22 +obj-y := cfe_env.o gpio.o irq.o nvram.o prom.o serial.o setup.o time.o wgt634u.o
23 Index: linux-2.6.28.7/arch/mips/bcm47xx/irq.c
24 ===================================================================
25 --- linux-2.6.28.7.orig/arch/mips/bcm47xx/irq.c 2009-03-17 17:26:19.000000000 +0100
26 +++ linux-2.6.28.7/arch/mips/bcm47xx/irq.c      2009-03-17 17:26:23.000000000 +0100
27 @@ -1,5 +1,6 @@
28  /*
29   *  Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
30 + *  Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>
31   *
32   *  This program is free software; you can redistribute  it and/or modify it
33   *  under  the terms of  the GNU General  Public License as published by the
34 @@ -23,10 +24,19 @@
35   */
36  
37  #include <linux/types.h>
38 +#include <linux/errno.h>
39 +#include <linux/init.h>
40  #include <linux/interrupt.h>
41  #include <linux/irq.h>
42 +#include <linux/pci.h>
43 +#include <linux/ssb/ssb.h>
44 +
45  #include <asm/irq_cpu.h>
46  
47 +
48 +extern struct ssb_bus ssb_bcm47xx;
49 +
50 +
51  void plat_irq_dispatch(void)
52  {
53         u32 cause;
54 Index: linux-2.6.28.7/arch/mips/bcm47xx/nvram.c
55 ===================================================================
56 --- linux-2.6.28.7.orig/arch/mips/bcm47xx/nvram.c       2009-03-17 17:26:19.000000000 +0100
57 +++ linux-2.6.28.7/arch/mips/bcm47xx/nvram.c    2009-03-17 17:26:23.000000000 +0100
58 @@ -24,10 +24,10 @@
59  #include <asm/io.h>
60  #include <asm/uaccess.h>
61  
62 -#include <nvram.h>
63 +#include "include/nvram.h"
64  
65  #define MB * 1048576
66 -extern struct ssb_bus ssb;
67 +extern struct ssb_bus ssb_bcm47xx;
68  
69  static char nvram_buf[NVRAM_SPACE];
70  static int cfe_env;
71 @@ -36,7 +36,7 @@ extern char *cfe_env_get(char *nv_buf, c
72  /* Probe for NVRAM header */
73  static void __init early_nvram_init(void)
74  {
75 -       struct ssb_mipscore *mcore = &ssb.mipscore;
76 +       struct ssb_mipscore *mcore = &ssb_bcm47xx.mipscore;
77         struct nvram_header *header;
78         int i;
79         u32 base, lim, off;
80 Index: linux-2.6.28.7/arch/mips/bcm47xx/setup.c
81 ===================================================================
82 --- linux-2.6.28.7.orig/arch/mips/bcm47xx/setup.c       2009-03-17 17:26:19.000000000 +0100
83 +++ linux-2.6.28.7/arch/mips/bcm47xx/setup.c    2009-03-17 17:26:23.000000000 +0100
84 @@ -2,7 +2,7 @@
85   *  Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
86   *  Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
87   *  Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
88 - *  Copyright (C) 2006 Michael Buesch <mb@bu3sch.de>
89 + *  Copyright (C) 2006-2008 Michael Buesch <mb@bu3sch.de>
90   *
91   *  This program is free software; you can redistribute  it and/or modify it
92   *  under  the terms of  the GNU General  Public License as published by the
93 @@ -25,18 +25,28 @@
94   *  675 Mass Ave, Cambridge, MA 02139, USA.
95   */
96  
97 +#include <linux/init.h>
98  #include <linux/types.h>
99  #include <linux/ssb/ssb.h>
100  #include <linux/ssb/ssb_embedded.h>
101 +#include <linux/tty.h>
102 +#include <linux/serial.h>
103 +#include <linux/serial_core.h>
104 +#include <linux/serial_reg.h>
105 +#include <linux/serial_8250.h>
106  #include <asm/bootinfo.h>
107  #include <asm/reboot.h>
108  #include <asm/time.h>
109 -#include <bcm47xx.h>
110  #include <asm/fw/cfe/cfe_api.h>
111 +#include <linux/pm.h>
112 +
113 +#include "include/nvram.h"
114  
115  struct ssb_bus ssb_bcm47xx;
116  EXPORT_SYMBOL(ssb_bcm47xx);
117  
118 +extern void bcm47xx_pci_init(void);
119 +
120  static void bcm47xx_machine_restart(char *command)
121  {
122         printk(KERN_ALERT "Please stand by while rebooting the system...\n");
123 @@ -56,7 +66,7 @@ static void bcm47xx_machine_halt(void)
124                 cpu_relax();
125  }
126  
127 -static void str2eaddr(char *str, char *dest)
128 +static void e_aton(char *str, char *dest)
129  {
130         int i = 0;
131  
132 @@ -73,52 +83,141 @@ static void str2eaddr(char *str, char *d
133         }
134  }
135  
136 -static int bcm47xx_get_invariants(struct ssb_bus *bus,
137 -                                  struct ssb_init_invariants *iv)
138 +static void bcm47xx_fill_sprom(struct ssb_sprom *sprom)
139  {
140 -       char buf[100];
141 +       char *s;
142  
143 -       /* Fill boardinfo structure */
144 -       memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
145 +       memset(sprom, 0xFF, sizeof(struct ssb_sprom));
146  
147 -       if (cfe_getenv("boardvendor", buf, sizeof(buf)) >= 0)
148 -               iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
149 -       if (cfe_getenv("boardtype", buf, sizeof(buf)) >= 0)
150 -               iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
151 -       if (cfe_getenv("boardrev", buf, sizeof(buf)) >= 0)
152 -               iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);
153 -
154 -       /* Fill sprom structure */
155 -       memset(&(iv->sprom), 0, sizeof(struct ssb_sprom));
156 -       iv->sprom.revision = 3;
157 -
158 -       if (cfe_getenv("et0macaddr", buf, sizeof(buf)) >= 0)
159 -               str2eaddr(buf, iv->sprom.et0mac);
160 -       if (cfe_getenv("et1macaddr", buf, sizeof(buf)) >= 0)
161 -               str2eaddr(buf, iv->sprom.et1mac);
162 -       if (cfe_getenv("et0phyaddr", buf, sizeof(buf)) >= 0)
163 -               iv->sprom.et0phyaddr = simple_strtoul(buf, NULL, 10);
164 -       if (cfe_getenv("et1phyaddr", buf, sizeof(buf)) >= 0)
165 -               iv->sprom.et1phyaddr = simple_strtoul(buf, NULL, 10);
166 -       if (cfe_getenv("et0mdcport", buf, sizeof(buf)) >= 0)
167 -               iv->sprom.et0mdcport = simple_strtoul(buf, NULL, 10);
168 -       if (cfe_getenv("et1mdcport", buf, sizeof(buf)) >= 0)
169 -               iv->sprom.et1mdcport = simple_strtoul(buf, NULL, 10);
170 +       sprom->revision = 1;
171 +       if ((s = nvram_get("il0macaddr")))
172 +               e_aton(s, sprom->il0mac);
173 +       if ((s = nvram_get("et0macaddr")))
174 +               e_aton(s, sprom->et0mac);
175 +       if ((s = nvram_get("et1macaddr")))
176 +               e_aton(s, sprom->et1mac);
177 +       if ((s = nvram_get("et0phyaddr")))
178 +               sprom->et0phyaddr = simple_strtoul(s, NULL, 0);
179 +       if ((s = nvram_get("et1phyaddr")))
180 +               sprom->et1phyaddr = simple_strtoul(s, NULL, 0);
181 +       if ((s = nvram_get("et0mdcport")))
182 +               sprom->et0mdcport = !!simple_strtoul(s, NULL, 10);
183 +       if ((s = nvram_get("et1mdcport")))
184 +               sprom->et1mdcport = !!simple_strtoul(s, NULL, 10);
185 +       if ((s = nvram_get("pa0b0")))
186 +               sprom->pa0b0 = simple_strtoul(s, NULL, 0);
187 +       if ((s = nvram_get("pa0b1")))
188 +               sprom->pa0b1 = simple_strtoul(s, NULL, 0);
189 +       if ((s = nvram_get("pa0b2")))
190 +               sprom->pa0b2 = simple_strtoul(s, NULL, 0);
191 +       if ((s = nvram_get("pa1b0")))
192 +               sprom->pa1b0 = simple_strtoul(s, NULL, 0);
193 +       if ((s = nvram_get("pa1b1")))
194 +               sprom->pa1b1 = simple_strtoul(s, NULL, 0);
195 +       if ((s = nvram_get("pa1b2")))
196 +               sprom->pa1b2 = simple_strtoul(s, NULL, 0);
197 +       if ((s = nvram_get("wl0gpio0")))
198 +               sprom->gpio0 = simple_strtoul(s, NULL, 0);
199 +       if ((s = nvram_get("wl0gpio1")))
200 +               sprom->gpio1 = simple_strtoul(s, NULL, 0);
201 +       if ((s = nvram_get("wl0gpio2")))
202 +               sprom->gpio2 = simple_strtoul(s, NULL, 0);
203 +       if ((s = nvram_get("wl0gpio3")))
204 +               sprom->gpio3 = simple_strtoul(s, NULL, 0);
205 +       if ((s = nvram_get("pa0maxpwr")))
206 +               sprom->maxpwr_bg = simple_strtoul(s, NULL, 0);
207 +       if ((s = nvram_get("pa1maxpwr")))
208 +               sprom->maxpwr_a = simple_strtoul(s, NULL, 0);
209 +       if ((s = nvram_get("pa0itssit")))
210 +               sprom->itssi_bg = simple_strtoul(s, NULL, 0);
211 +       if ((s = nvram_get("pa1itssit")))
212 +               sprom->itssi_a = simple_strtoul(s, NULL, 0);
213 +       sprom->boardflags_lo = 0;
214 +       if ((s = nvram_get("boardflags")))
215 +               sprom->boardflags_lo = simple_strtoul(s, NULL, 0);
216 +       sprom->boardflags_hi = 0;
217 +       if ((s = nvram_get("boardflags2")))
218 +               sprom->boardflags_hi = simple_strtoul(s, NULL, 0);
219 +}
220 +
221 +static int bcm47xx_get_invariants(struct ssb_bus *bus, struct ssb_init_invariants *iv)
222 +{
223 +       char *s;
224 +
225 +       iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
226 +       if ((s = nvram_get("boardtype")))
227 +               iv->boardinfo.type = (u16)simple_strtoul(s, NULL, 0);
228 +       if ((s = nvram_get("boardrev")))
229 +               iv->boardinfo.rev = (u16)simple_strtoul(s, NULL, 0);
230 +
231 +       bcm47xx_fill_sprom(&iv->sprom);
232 +
233 +       if ((s = nvram_get("cardbus")))
234 +               iv->has_cardbus_slot = !!simple_strtoul(s, NULL, 10);
235  
236         return 0;
237  }
238  
239  void __init plat_mem_setup(void)
240  {
241 -       int err;
242 +       int i, err;
243 +       char *s;
244 +       struct ssb_mipscore *mcore;
245 +
246 +       err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE, bcm47xx_get_invariants);
247 +       if (err) {
248 +               const char *msg = "Failed to initialize SSB bus (err %d)\n";
249 +               printk(msg, err); /* Make sure the message gets out of the box. */
250 +               panic(msg, err);
251 +       }
252 +       mcore = &ssb_bcm47xx.mipscore;
253  
254 -       err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE,
255 -                                     bcm47xx_get_invariants);
256 -       if (err)
257 -               panic("Failed to initialize SSB bus (err %d)\n", err);
258 +       s = nvram_get("kernel_args");
259 +       if (s && !strncmp(s, "console=ttyS1", 13)) {
260 +               struct ssb_serial_port port;
261 +
262 +               printk("Swapping serial ports!\n");
263 +               /* swap serial ports */
264 +               memcpy(&port, &mcore->serial_ports[0], sizeof(port));
265 +               memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1], sizeof(port));
266 +               memcpy(&mcore->serial_ports[1], &port, sizeof(port));
267 +       }
268 +
269 +       for (i = 0; i < mcore->nr_serial_ports; i++) {
270 +               struct ssb_serial_port *port = &(mcore->serial_ports[i]);
271 +               struct uart_port s;
272 +
273 +               memset(&s, 0, sizeof(s));
274 +               s.line = i;
275 +               s.membase = port->regs;
276 +               s.irq = port->irq + 2;
277 +               s.uartclk = port->baud_base;
278 +               s.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
279 +               s.iotype = SERIAL_IO_MEM;
280 +               s.regshift = port->reg_shift;
281 +
282 +               early_serial_setup(&s);
283 +       }
284 +       printk("Serial init done.\n");
285  
286         _machine_restart = bcm47xx_machine_restart;
287         _machine_halt = bcm47xx_machine_halt;
288         pm_power_off = bcm47xx_machine_halt;
289  }
290  
291 +static int __init bcm47xx_register_gpiodev(void)
292 +{
293 +       static struct resource res = {
294 +               .start = 0xFFFFFFFF,
295 +       };
296 +       struct platform_device *pdev;
297 +
298 +       pdev = platform_device_register_simple("GPIODEV", 0, &res, 1);
299 +       if (!pdev) {
300 +               printk(KERN_ERR "bcm47xx: GPIODEV init failed\n");
301 +               return -ENODEV;
302 +       }
303 +
304 +       return 0;
305 +}
306 +device_initcall(bcm47xx_register_gpiodev);
307 Index: linux-2.6.28.7/arch/mips/bcm47xx/time.c
308 ===================================================================
309 --- linux-2.6.28.7.orig/arch/mips/bcm47xx/time.c        2009-03-17 17:26:19.000000000 +0100
310 +++ linux-2.6.28.7/arch/mips/bcm47xx/time.c     2009-03-17 17:26:23.000000000 +0100
311 @@ -22,11 +22,17 @@
312   *  675 Mass Ave, Cambridge, MA 02139, USA.
313   */
314  
315 -
316  #include <linux/init.h>
317 +#include <linux/kernel.h>
318 +#include <linux/sched.h>
319 +#include <linux/serial_reg.h>
320 +#include <linux/interrupt.h>
321  #include <linux/ssb/ssb.h>
322 +#include <asm/addrspace.h>
323 +#include <asm/io.h>
324  #include <asm/time.h>
325 -#include <bcm47xx.h>
326 +
327 +extern struct ssb_bus ssb_bcm47xx;
328  
329  void __init plat_time_init(void)
330  {