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