kernel: update 3.18 to 3.18.1
[openwrt.git] / target / linux / generic / patches-3.3 / 025-bcma_backport.patch
1 --- a/arch/mips/bcm47xx/serial.c
2 +++ b/arch/mips/bcm47xx/serial.c
3 @@ -62,7 +62,7 @@ static int __init uart8250_init_bcma(voi
4  
5                 p->mapbase = (unsigned int) bcma_port->regs;
6                 p->membase = (void *) bcma_port->regs;
7 -               p->irq = bcma_port->irq + 2;
8 +               p->irq = bcma_port->irq;
9                 p->uartclk = bcma_port->baud_base;
10                 p->regshift = bcma_port->reg_shift;
11                 p->iotype = UPIO_MEM;
12 --- a/drivers/bcma/Kconfig
13 +++ b/drivers/bcma/Kconfig
14 @@ -26,16 +26,23 @@ config BCMA_HOST_PCI_POSSIBLE
15  config BCMA_HOST_PCI
16         bool "Support for BCMA on PCI-host bus"
17         depends on BCMA_HOST_PCI_POSSIBLE
18 +       default y
19  
20  config BCMA_DRIVER_PCI_HOSTMODE
21         bool "Driver for PCI core working in hostmode"
22 -       depends on BCMA && MIPS
23 +       depends on BCMA && MIPS && BCMA_HOST_PCI
24         help
25           PCI core hostmode operation (external PCI bus).
26  
27  config BCMA_HOST_SOC
28 -       bool
29 -       depends on BCMA_DRIVER_MIPS
30 +       bool "Support for BCMA in a SoC"
31 +       depends on BCMA
32 +       help
33 +         Host interface for a Broadcom AIX bus directly mapped into
34 +         the memory. This only works with the Broadcom SoCs from the
35 +         BCM47XX line.
36 +
37 +         If unsure, say N
38  
39  config BCMA_DRIVER_MIPS
40         bool "BCMA Broadcom MIPS core driver"
41 @@ -46,6 +53,33 @@ config BCMA_DRIVER_MIPS
42  
43           If unsure, say N
44  
45 +config BCMA_SFLASH
46 +       bool
47 +       depends on BCMA_DRIVER_MIPS
48 +       default y
49 +
50 +config BCMA_NFLASH
51 +       bool
52 +       depends on BCMA_DRIVER_MIPS
53 +       default y
54 +
55 +config BCMA_DRIVER_GMAC_CMN
56 +       bool "BCMA Broadcom GBIT MAC COMMON core driver"
57 +       depends on BCMA
58 +       help
59 +         Driver for the Broadcom GBIT MAC COMMON core attached to Broadcom
60 +         specific Advanced Microcontroller Bus.
61 +
62 +         If unsure, say N
63 +
64 +config BCMA_DRIVER_GPIO
65 +       bool "BCMA GPIO driver"
66 +       depends on BCMA && GPIOLIB
67 +       help
68 +         Driver to provide access to the GPIO pins of the bcma bus.
69 +
70 +         If unsure, say N
71 +
72  config BCMA_DEBUG
73         bool "BCMA debugging"
74         depends on BCMA
75 --- a/drivers/bcma/Makefile
76 +++ b/drivers/bcma/Makefile
77 @@ -1,8 +1,12 @@
78  bcma-y                                 += main.o scan.o core.o sprom.o
79  bcma-y                                 += driver_chipcommon.o driver_chipcommon_pmu.o
80 +bcma-$(CONFIG_BCMA_SFLASH)             += driver_chipcommon_sflash.o
81 +bcma-$(CONFIG_BCMA_NFLASH)             += driver_chipcommon_nflash.o
82  bcma-y                                 += driver_pci.o
83  bcma-$(CONFIG_BCMA_DRIVER_PCI_HOSTMODE)        += driver_pci_host.o
84  bcma-$(CONFIG_BCMA_DRIVER_MIPS)                += driver_mips.o
85 +bcma-$(CONFIG_BCMA_DRIVER_GMAC_CMN)    += driver_gmac_cmn.o
86 +bcma-$(CONFIG_BCMA_DRIVER_GPIO)                += driver_gpio.o
87  bcma-$(CONFIG_BCMA_HOST_PCI)           += host_pci.o
88  bcma-$(CONFIG_BCMA_HOST_SOC)           += host_soc.o
89  obj-$(CONFIG_BCMA)                     += bcma.o
90 --- a/drivers/bcma/bcma_private.h
91 +++ b/drivers/bcma/bcma_private.h
92 @@ -10,10 +10,21 @@
93  
94  #define BCMA_CORE_SIZE         0x1000
95  
96 +#define bcma_err(bus, fmt, ...) \
97 +       pr_err("bus%d: " fmt, (bus)->num, ##__VA_ARGS__)
98 +#define bcma_warn(bus, fmt, ...) \
99 +       pr_warn("bus%d: " fmt, (bus)->num, ##__VA_ARGS__)
100 +#define bcma_info(bus, fmt, ...) \
101 +       pr_info("bus%d: " fmt, (bus)->num, ##__VA_ARGS__)
102 +#define bcma_debug(bus, fmt, ...) \
103 +       pr_debug("bus%d: " fmt, (bus)->num, ##__VA_ARGS__)
104 +
105  struct bcma_bus;
106  
107  /* main.c */
108 -int bcma_bus_register(struct bcma_bus *bus);
109 +bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
110 +                    int timeout);
111 +int __devinit bcma_bus_register(struct bcma_bus *bus);
112  void bcma_bus_unregister(struct bcma_bus *bus);
113  int __init bcma_bus_early_register(struct bcma_bus *bus,
114                                    struct bcma_device *core_cc,
115 @@ -22,6 +33,8 @@ int __init bcma_bus_early_register(struc
116  int bcma_bus_suspend(struct bcma_bus *bus);
117  int bcma_bus_resume(struct bcma_bus *bus);
118  #endif
119 +struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
120 +                                       u8 unit);
121  
122  /* scan.c */
123  int bcma_bus_scan(struct bcma_bus *bus);
124 @@ -36,11 +49,36 @@ int bcma_sprom_get(struct bcma_bus *bus)
125  /* driver_chipcommon.c */
126  #ifdef CONFIG_BCMA_DRIVER_MIPS
127  void bcma_chipco_serial_init(struct bcma_drv_cc *cc);
128 +extern struct platform_device bcma_pflash_dev;
129  #endif /* CONFIG_BCMA_DRIVER_MIPS */
130  
131  /* driver_chipcommon_pmu.c */
132 -u32 bcma_pmu_alp_clock(struct bcma_drv_cc *cc);
133 -u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc);
134 +u32 bcma_pmu_get_alp_clock(struct bcma_drv_cc *cc);
135 +u32 bcma_pmu_get_cpu_clock(struct bcma_drv_cc *cc);
136 +
137 +#ifdef CONFIG_BCMA_SFLASH
138 +/* driver_chipcommon_sflash.c */
139 +int bcma_sflash_init(struct bcma_drv_cc *cc);
140 +extern struct platform_device bcma_sflash_dev;
141 +#else
142 +static inline int bcma_sflash_init(struct bcma_drv_cc *cc)
143 +{
144 +       bcma_err(cc->core->bus, "Serial flash not supported\n");
145 +       return 0;
146 +}
147 +#endif /* CONFIG_BCMA_SFLASH */
148 +
149 +#ifdef CONFIG_BCMA_NFLASH
150 +/* driver_chipcommon_nflash.c */
151 +int bcma_nflash_init(struct bcma_drv_cc *cc);
152 +extern struct platform_device bcma_nflash_dev;
153 +#else
154 +static inline int bcma_nflash_init(struct bcma_drv_cc *cc)
155 +{
156 +       bcma_err(cc->core->bus, "NAND flash not supported\n");
157 +       return 0;
158 +}
159 +#endif /* CONFIG_BCMA_NFLASH */
160  
161  #ifdef CONFIG_BCMA_HOST_PCI
162  /* host_pci.c */
163 @@ -48,8 +86,29 @@ extern int __init bcma_host_pci_init(voi
164  extern void __exit bcma_host_pci_exit(void);
165  #endif /* CONFIG_BCMA_HOST_PCI */
166  
167 +/* driver_pci.c */
168 +u32 bcma_pcie_read(struct bcma_drv_pci *pc, u32 address);
169 +
170 +extern int bcma_chipco_watchdog_register(struct bcma_drv_cc *cc);
171 +
172  #ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE
173 -void bcma_core_pci_hostmode_init(struct bcma_drv_pci *pc);
174 +bool __devinit bcma_core_pci_is_in_hostmode(struct bcma_drv_pci *pc);
175 +void __devinit bcma_core_pci_hostmode_init(struct bcma_drv_pci *pc);
176  #endif /* CONFIG_BCMA_DRIVER_PCI_HOSTMODE */
177  
178 +#ifdef CONFIG_BCMA_DRIVER_GPIO
179 +/* driver_gpio.c */
180 +int bcma_gpio_init(struct bcma_drv_cc *cc);
181 +int bcma_gpio_unregister(struct bcma_drv_cc *cc);
182 +#else
183 +static inline int bcma_gpio_init(struct bcma_drv_cc *cc)
184 +{
185 +       return -ENOTSUPP;
186 +}
187 +static inline int bcma_gpio_unregister(struct bcma_drv_cc *cc)
188 +{
189 +       return 0;
190 +}
191 +#endif /* CONFIG_BCMA_DRIVER_GPIO */
192 +
193  #endif
194 --- a/drivers/bcma/core.c
195 +++ b/drivers/bcma/core.c
196 @@ -9,6 +9,25 @@
197  #include <linux/export.h>
198  #include <linux/bcma/bcma.h>
199  
200 +static bool bcma_core_wait_value(struct bcma_device *core, u16 reg, u32 mask,
201 +                                u32 value, int timeout)
202 +{
203 +       unsigned long deadline = jiffies + timeout;
204 +       u32 val;
205 +
206 +       do {
207 +               val = bcma_aread32(core, reg);
208 +               if ((val & mask) == value)
209 +                       return true;
210 +               cpu_relax();
211 +               udelay(10);
212 +       } while (!time_after_eq(jiffies, deadline));
213 +
214 +       bcma_warn(core->bus, "Timeout waiting for register 0x%04X!\n", reg);
215 +
216 +       return false;
217 +}
218 +
219  bool bcma_core_is_enabled(struct bcma_device *core)
220  {
221         if ((bcma_aread32(core, BCMA_IOCTL) & (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC))
222 @@ -25,12 +44,15 @@ void bcma_core_disable(struct bcma_devic
223         if (bcma_aread32(core, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
224                 return;
225  
226 -       bcma_awrite32(core, BCMA_IOCTL, flags);
227 -       bcma_aread32(core, BCMA_IOCTL);
228 -       udelay(10);
229 +       bcma_core_wait_value(core, BCMA_RESET_ST, ~0, 0, 300);
230  
231         bcma_awrite32(core, BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);
232 +       bcma_aread32(core, BCMA_RESET_CTL);
233         udelay(1);
234 +
235 +       bcma_awrite32(core, BCMA_IOCTL, flags);
236 +       bcma_aread32(core, BCMA_IOCTL);
237 +       udelay(10);
238  }
239  EXPORT_SYMBOL_GPL(bcma_core_disable);
240  
241 @@ -42,6 +64,7 @@ int bcma_core_enable(struct bcma_device
242         bcma_aread32(core, BCMA_IOCTL);
243  
244         bcma_awrite32(core, BCMA_RESET_CTL, 0);
245 +       bcma_aread32(core, BCMA_RESET_CTL);
246         udelay(1);
247  
248         bcma_awrite32(core, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
249 @@ -64,7 +87,7 @@ void bcma_core_set_clockmode(struct bcma
250         switch (clkmode) {
251         case BCMA_CLKMODE_FAST:
252                 bcma_set32(core, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT);
253 -               udelay(64);
254 +               usleep_range(64, 300);
255                 for (i = 0; i < 1500; i++) {
256                         if (bcma_read32(core, BCMA_CLKCTLST) &
257                             BCMA_CLKCTLST_HAVEHT) {
258 @@ -74,10 +97,10 @@ void bcma_core_set_clockmode(struct bcma
259                         udelay(10);
260                 }
261                 if (i)
262 -                       pr_err("HT force timeout\n");
263 +                       bcma_err(core->bus, "HT force timeout\n");
264                 break;
265         case BCMA_CLKMODE_DYNAMIC:
266 -               pr_warn("Dynamic clockmode not supported yet!\n");
267 +               bcma_set32(core, BCMA_CLKCTLST, ~BCMA_CLKCTLST_FORCEHT);
268                 break;
269         }
270  }
271 @@ -101,9 +124,15 @@ void bcma_core_pll_ctl(struct bcma_devic
272                         udelay(10);
273                 }
274                 if (i)
275 -                       pr_err("PLL enable timeout\n");
276 +                       bcma_err(core->bus, "PLL enable timeout\n");
277         } else {
278 -               pr_warn("Disabling PLL not supported yet!\n");
279 +               /*
280 +                * Mask the PLL but don't wait for it to be disabled. PLL may be
281 +                * shared between cores and will be still up if there is another
282 +                * core using it.
283 +                */
284 +               bcma_mask32(core, BCMA_CLKCTLST, ~req);
285 +               bcma_read32(core, BCMA_CLKCTLST);
286         }
287  }
288  EXPORT_SYMBOL_GPL(bcma_core_pll_ctl);
289 @@ -119,8 +148,8 @@ u32 bcma_core_dma_translation(struct bcm
290                 else
291                         return BCMA_DMA_TRANSLATION_DMA32_CMT;
292         default:
293 -               pr_err("DMA translation unknown for host %d\n",
294 -                      core->bus->hosttype);
295 +               bcma_err(core->bus, "DMA translation unknown for host %d\n",
296 +                        core->bus->hosttype);
297         }
298         return BCMA_DMA_TRANSLATION_NONE;
299  }
300 --- a/drivers/bcma/driver_chipcommon.c
301 +++ b/drivers/bcma/driver_chipcommon.c
302 @@ -4,12 +4,15 @@
303   *
304   * Copyright 2005, Broadcom Corporation
305   * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
306 + * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
307   *
308   * Licensed under the GNU/GPL. See COPYING for details.
309   */
310  
311  #include "bcma_private.h"
312 +#include <linux/bcm47xx_wdt.h>
313  #include <linux/export.h>
314 +#include <linux/platform_device.h>
315  #include <linux/bcma/bcma.h>
316  
317  static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset,
318 @@ -22,29 +25,136 @@ static inline u32 bcma_cc_write32_masked
319         return value;
320  }
321  
322 -void bcma_core_chipcommon_init(struct bcma_drv_cc *cc)
323 +u32 bcma_chipco_get_alp_clock(struct bcma_drv_cc *cc)
324  {
325 -       u32 leddc_on = 10;
326 -       u32 leddc_off = 90;
327 +       if (cc->capabilities & BCMA_CC_CAP_PMU)
328 +               return bcma_pmu_get_alp_clock(cc);
329  
330 -       if (cc->setup_done)
331 +       return 20000000;
332 +}
333 +EXPORT_SYMBOL_GPL(bcma_chipco_get_alp_clock);
334 +
335 +static u32 bcma_chipco_watchdog_get_max_timer(struct bcma_drv_cc *cc)
336 +{
337 +       struct bcma_bus *bus = cc->core->bus;
338 +       u32 nb;
339 +
340 +       if (cc->capabilities & BCMA_CC_CAP_PMU) {
341 +               if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706)
342 +                       nb = 32;
343 +               else if (cc->core->id.rev < 26)
344 +                       nb = 16;
345 +               else
346 +                       nb = (cc->core->id.rev >= 37) ? 32 : 24;
347 +       } else {
348 +               nb = 28;
349 +       }
350 +       if (nb == 32)
351 +               return 0xffffffff;
352 +       else
353 +               return (1 << nb) - 1;
354 +}
355 +
356 +static u32 bcma_chipco_watchdog_timer_set_wdt(struct bcm47xx_wdt *wdt,
357 +                                             u32 ticks)
358 +{
359 +       struct bcma_drv_cc *cc = bcm47xx_wdt_get_drvdata(wdt);
360 +
361 +       return bcma_chipco_watchdog_timer_set(cc, ticks);
362 +}
363 +
364 +static u32 bcma_chipco_watchdog_timer_set_ms_wdt(struct bcm47xx_wdt *wdt,
365 +                                                u32 ms)
366 +{
367 +       struct bcma_drv_cc *cc = bcm47xx_wdt_get_drvdata(wdt);
368 +       u32 ticks;
369 +
370 +       ticks = bcma_chipco_watchdog_timer_set(cc, cc->ticks_per_ms * ms);
371 +       return ticks / cc->ticks_per_ms;
372 +}
373 +
374 +static int bcma_chipco_watchdog_ticks_per_ms(struct bcma_drv_cc *cc)
375 +{
376 +       struct bcma_bus *bus = cc->core->bus;
377 +
378 +       if (cc->capabilities & BCMA_CC_CAP_PMU) {
379 +               if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706)
380 +                       /* 4706 CC and PMU watchdogs are clocked at 1/4 of ALP clock */
381 +                       return bcma_chipco_get_alp_clock(cc) / 4000;
382 +               else
383 +                       /* based on 32KHz ILP clock */
384 +                       return 32;
385 +       } else {
386 +               return bcma_chipco_get_alp_clock(cc) / 1000;
387 +       }
388 +}
389 +
390 +int bcma_chipco_watchdog_register(struct bcma_drv_cc *cc)
391 +{
392 +       struct bcm47xx_wdt wdt = {};
393 +       struct platform_device *pdev;
394 +
395 +       wdt.driver_data = cc;
396 +       wdt.timer_set = bcma_chipco_watchdog_timer_set_wdt;
397 +       wdt.timer_set_ms = bcma_chipco_watchdog_timer_set_ms_wdt;
398 +       wdt.max_timer_ms = bcma_chipco_watchdog_get_max_timer(cc) / cc->ticks_per_ms;
399 +
400 +       pdev = platform_device_register_data(NULL, "bcm47xx-wdt",
401 +                                            cc->core->bus->num, &wdt,
402 +                                            sizeof(wdt));
403 +       if (IS_ERR(pdev))
404 +               return PTR_ERR(pdev);
405 +
406 +       cc->watchdog = pdev;
407 +
408 +       return 0;
409 +}
410 +
411 +void bcma_core_chipcommon_early_init(struct bcma_drv_cc *cc)
412 +{
413 +       if (cc->early_setup_done)
414                 return;
415  
416 +       spin_lock_init(&cc->gpio_lock);
417 +
418         if (cc->core->id.rev >= 11)
419                 cc->status = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
420         cc->capabilities = bcma_cc_read32(cc, BCMA_CC_CAP);
421         if (cc->core->id.rev >= 35)
422                 cc->capabilities_ext = bcma_cc_read32(cc, BCMA_CC_CAP_EXT);
423  
424 +       if (cc->capabilities & BCMA_CC_CAP_PMU)
425 +               bcma_pmu_early_init(cc);
426 +
427 +       cc->early_setup_done = true;
428 +}
429 +
430 +void bcma_core_chipcommon_init(struct bcma_drv_cc *cc)
431 +{
432 +       u32 leddc_on = 10;
433 +       u32 leddc_off = 90;
434 +
435 +       if (cc->setup_done)
436 +               return;
437 +
438 +       bcma_core_chipcommon_early_init(cc);
439 +
440         if (cc->core->id.rev >= 20) {
441 -               bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, 0);
442 -               bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, 0);
443 +               u32 pullup = 0, pulldown = 0;
444 +
445 +               if (cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM43142) {
446 +                       pullup = 0x402e0;
447 +                       pulldown = 0x20500;
448 +               }
449 +
450 +               bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, pullup);
451 +               bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, pulldown);
452         }
453  
454         if (cc->capabilities & BCMA_CC_CAP_PMU)
455                 bcma_pmu_init(cc);
456         if (cc->capabilities & BCMA_CC_CAP_PCTL)
457 -               pr_err("Power control not implemented!\n");
458 +               bcma_err(cc->core->bus, "Power control not implemented!\n");
459  
460         if (cc->core->id.rev >= 16) {
461                 if (cc->core->bus->sprom.leddc_on_time &&
462 @@ -56,15 +166,33 @@ void bcma_core_chipcommon_init(struct bc
463                         ((leddc_on << BCMA_CC_GPIOTIMER_ONTIME_SHIFT) |
464                          (leddc_off << BCMA_CC_GPIOTIMER_OFFTIME_SHIFT)));
465         }
466 +       cc->ticks_per_ms = bcma_chipco_watchdog_ticks_per_ms(cc);
467  
468         cc->setup_done = true;
469  }
470  
471  /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
472 -void bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks)
473 +u32 bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks)
474  {
475 -       /* instant NMI */
476 -       bcma_cc_write32(cc, BCMA_CC_WATCHDOG, ticks);
477 +       u32 maxt;
478 +       enum bcma_clkmode clkmode;
479 +
480 +       maxt = bcma_chipco_watchdog_get_max_timer(cc);
481 +       if (cc->capabilities & BCMA_CC_CAP_PMU) {
482 +               if (ticks == 1)
483 +                       ticks = 2;
484 +               else if (ticks > maxt)
485 +                       ticks = maxt;
486 +               bcma_cc_write32(cc, BCMA_CC_PMU_WATCHDOG, ticks);
487 +       } else {
488 +               clkmode = ticks ? BCMA_CLKMODE_FAST : BCMA_CLKMODE_DYNAMIC;
489 +               bcma_core_set_clockmode(cc->core, clkmode);
490 +               if (ticks > maxt)
491 +                       ticks = maxt;
492 +               /* instant NMI */
493 +               bcma_cc_write32(cc, BCMA_CC_WATCHDOG, ticks);
494 +       }
495 +       return ticks;
496  }
497  
498  void bcma_chipco_irq_mask(struct bcma_drv_cc *cc, u32 mask, u32 value)
499 @@ -84,28 +212,99 @@ u32 bcma_chipco_gpio_in(struct bcma_drv_
500  
501  u32 bcma_chipco_gpio_out(struct bcma_drv_cc *cc, u32 mask, u32 value)
502  {
503 -       return bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUT, mask, value);
504 +       unsigned long flags;
505 +       u32 res;
506 +
507 +       spin_lock_irqsave(&cc->gpio_lock, flags);
508 +       res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUT, mask, value);
509 +       spin_unlock_irqrestore(&cc->gpio_lock, flags);
510 +
511 +       return res;
512  }
513 +EXPORT_SYMBOL_GPL(bcma_chipco_gpio_out);
514  
515  u32 bcma_chipco_gpio_outen(struct bcma_drv_cc *cc, u32 mask, u32 value)
516  {
517 -       return bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUTEN, mask, value);
518 +       unsigned long flags;
519 +       u32 res;
520 +
521 +       spin_lock_irqsave(&cc->gpio_lock, flags);
522 +       res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUTEN, mask, value);
523 +       spin_unlock_irqrestore(&cc->gpio_lock, flags);
524 +
525 +       return res;
526  }
527 +EXPORT_SYMBOL_GPL(bcma_chipco_gpio_outen);
528  
529 +/*
530 + * If the bit is set to 0, chipcommon controlls this GPIO,
531 + * if the bit is set to 1, it is used by some part of the chip and not our code.
532 + */
533  u32 bcma_chipco_gpio_control(struct bcma_drv_cc *cc, u32 mask, u32 value)
534  {
535 -       return bcma_cc_write32_masked(cc, BCMA_CC_GPIOCTL, mask, value);
536 +       unsigned long flags;
537 +       u32 res;
538 +
539 +       spin_lock_irqsave(&cc->gpio_lock, flags);
540 +       res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOCTL, mask, value);
541 +       spin_unlock_irqrestore(&cc->gpio_lock, flags);
542 +
543 +       return res;
544  }
545  EXPORT_SYMBOL_GPL(bcma_chipco_gpio_control);
546  
547  u32 bcma_chipco_gpio_intmask(struct bcma_drv_cc *cc, u32 mask, u32 value)
548  {
549 -       return bcma_cc_write32_masked(cc, BCMA_CC_GPIOIRQ, mask, value);
550 +       unsigned long flags;
551 +       u32 res;
552 +
553 +       spin_lock_irqsave(&cc->gpio_lock, flags);
554 +       res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOIRQ, mask, value);
555 +       spin_unlock_irqrestore(&cc->gpio_lock, flags);
556 +
557 +       return res;
558  }
559  
560  u32 bcma_chipco_gpio_polarity(struct bcma_drv_cc *cc, u32 mask, u32 value)
561  {
562 -       return bcma_cc_write32_masked(cc, BCMA_CC_GPIOPOL, mask, value);
563 +       unsigned long flags;
564 +       u32 res;
565 +
566 +       spin_lock_irqsave(&cc->gpio_lock, flags);
567 +       res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPOL, mask, value);
568 +       spin_unlock_irqrestore(&cc->gpio_lock, flags);
569 +
570 +       return res;
571 +}
572 +
573 +u32 bcma_chipco_gpio_pullup(struct bcma_drv_cc *cc, u32 mask, u32 value)
574 +{
575 +       unsigned long flags;
576 +       u32 res;
577 +
578 +       if (cc->core->id.rev < 20)
579 +               return 0;
580 +
581 +       spin_lock_irqsave(&cc->gpio_lock, flags);
582 +       res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPULLUP, mask, value);
583 +       spin_unlock_irqrestore(&cc->gpio_lock, flags);
584 +
585 +       return res;
586 +}
587 +
588 +u32 bcma_chipco_gpio_pulldown(struct bcma_drv_cc *cc, u32 mask, u32 value)
589 +{
590 +       unsigned long flags;
591 +       u32 res;
592 +
593 +       if (cc->core->id.rev < 20)
594 +               return 0;
595 +
596 +       spin_lock_irqsave(&cc->gpio_lock, flags);
597 +       res = bcma_cc_write32_masked(cc, BCMA_CC_GPIOPULLDOWN, mask, value);
598 +       spin_unlock_irqrestore(&cc->gpio_lock, flags);
599 +
600 +       return res;
601  }
602  
603  #ifdef CONFIG_BCMA_DRIVER_MIPS
604 @@ -118,8 +317,7 @@ void bcma_chipco_serial_init(struct bcma
605         struct bcma_serial_port *ports = cc->serial_ports;
606  
607         if (ccrev >= 11 && ccrev != 15) {
608 -               /* Fixed ALP clock */
609 -               baud_base = bcma_pmu_alp_clock(cc);
610 +               baud_base = bcma_chipco_get_alp_clock(cc);
611                 if (ccrev >= 21) {
612                         /* Turn off UART clock before switching clocksource. */
613                         bcma_cc_write32(cc, BCMA_CC_CORECTL,
614 @@ -137,12 +335,11 @@ void bcma_chipco_serial_init(struct bcma
615                                        | BCMA_CC_CORECTL_UARTCLKEN);
616                 }
617         } else {
618 -               pr_err("serial not supported on this device ccrev: 0x%x\n",
619 -                      ccrev);
620 +               bcma_err(cc->core->bus, "serial not supported on this device ccrev: 0x%x\n", ccrev);
621                 return;
622         }
623  
624 -       irq = bcma_core_mips_irq(cc->core);
625 +       irq = bcma_core_irq(cc->core);
626  
627         /* Determine the registers of the UARTs */
628         cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART);
629 --- /dev/null
630 +++ b/drivers/bcma/driver_chipcommon_nflash.c
631 @@ -0,0 +1,44 @@
632 +/*
633 + * Broadcom specific AMBA
634 + * ChipCommon NAND flash interface
635 + *
636 + * Licensed under the GNU/GPL. See COPYING for details.
637 + */
638 +
639 +#include "bcma_private.h"
640 +
641 +#include <linux/platform_device.h>
642 +#include <linux/bcma/bcma.h>
643 +
644 +struct platform_device bcma_nflash_dev = {
645 +       .name           = "bcma_nflash",
646 +       .num_resources  = 0,
647 +};
648 +
649 +/* Initialize NAND flash access */
650 +int bcma_nflash_init(struct bcma_drv_cc *cc)
651 +{
652 +       struct bcma_bus *bus = cc->core->bus;
653 +
654 +       if (bus->chipinfo.id != BCMA_CHIP_ID_BCM4706 &&
655 +           cc->core->id.rev != 38) {
656 +               bcma_err(bus, "NAND flash on unsupported board!\n");
657 +               return -ENOTSUPP;
658 +       }
659 +
660 +       if (!(cc->capabilities & BCMA_CC_CAP_NFLASH)) {
661 +               bcma_err(bus, "NAND flash not present according to ChipCommon\n");
662 +               return -ENODEV;
663 +       }
664 +
665 +       cc->nflash.present = true;
666 +       if (cc->core->id.rev == 38 &&
667 +           (cc->status & BCMA_CC_CHIPST_5357_NAND_BOOT))
668 +               cc->nflash.boot = true;
669 +
670 +       /* Prepare platform device, but don't register it yet. It's too early,
671 +        * malloc (required by device_private_init) is not available yet. */
672 +       bcma_nflash_dev.dev.platform_data = &cc->nflash;
673 +
674 +       return 0;
675 +}
676 --- a/drivers/bcma/driver_chipcommon_pmu.c
677 +++ b/drivers/bcma/driver_chipcommon_pmu.c
678 @@ -3,7 +3,8 @@
679   * ChipCommon Power Management Unit driver
680   *
681   * Copyright 2009, Michael Buesch <m@bues.ch>
682 - * Copyright 2007, Broadcom Corporation
683 + * Copyright 2007, 2011, Broadcom Corporation
684 + * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
685   *
686   * Licensed under the GNU/GPL. See COPYING for details.
687   */
688 @@ -12,12 +13,13 @@
689  #include <linux/export.h>
690  #include <linux/bcma/bcma.h>
691  
692 -static u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
693 +u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
694  {
695         bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
696         bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
697         return bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
698  }
699 +EXPORT_SYMBOL_GPL(bcma_chipco_pll_read);
700  
701  void bcma_chipco_pll_write(struct bcma_drv_cc *cc, u32 offset, u32 value)
702  {
703 @@ -54,19 +56,106 @@ void bcma_chipco_regctl_maskset(struct b
704  }
705  EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset);
706  
707 +static u32 bcma_pmu_xtalfreq(struct bcma_drv_cc *cc)
708 +{
709 +       u32 ilp_ctl, alp_hz;
710 +
711 +       if (!(bcma_cc_read32(cc, BCMA_CC_PMU_STAT) &
712 +             BCMA_CC_PMU_STAT_EXT_LPO_AVAIL))
713 +               return 0;
714 +
715 +       bcma_cc_write32(cc, BCMA_CC_PMU_XTAL_FREQ,
716 +                       BIT(BCMA_CC_PMU_XTAL_FREQ_MEASURE_SHIFT));
717 +       usleep_range(1000, 2000);
718 +
719 +       ilp_ctl = bcma_cc_read32(cc, BCMA_CC_PMU_XTAL_FREQ);
720 +       ilp_ctl &= BCMA_CC_PMU_XTAL_FREQ_ILPCTL_MASK;
721 +
722 +       bcma_cc_write32(cc, BCMA_CC_PMU_XTAL_FREQ, 0);
723 +
724 +       alp_hz = ilp_ctl * 32768 / 4;
725 +       return (alp_hz + 50000) / 100000 * 100;
726 +}
727 +
728 +static void bcma_pmu2_pll_init0(struct bcma_drv_cc *cc, u32 xtalfreq)
729 +{
730 +       struct bcma_bus *bus = cc->core->bus;
731 +       u32 freq_tgt_target = 0, freq_tgt_current;
732 +       u32 pll0, mask;
733 +
734 +       switch (bus->chipinfo.id) {
735 +       case BCMA_CHIP_ID_BCM43142:
736 +               /* pmu2_xtaltab0_adfll_485 */
737 +               switch (xtalfreq) {
738 +               case 12000:
739 +                       freq_tgt_target = 0x50D52;
740 +                       break;
741 +               case 20000:
742 +                       freq_tgt_target = 0x307FE;
743 +                       break;
744 +               case 26000:
745 +                       freq_tgt_target = 0x254EA;
746 +                       break;
747 +               case 37400:
748 +                       freq_tgt_target = 0x19EF8;
749 +                       break;
750 +               case 52000:
751 +                       freq_tgt_target = 0x12A75;
752 +                       break;
753 +               }
754 +               break;
755 +       }
756 +
757 +       if (!freq_tgt_target) {
758 +               bcma_err(bus, "Unknown TGT frequency for xtalfreq %d\n",
759 +                        xtalfreq);
760 +               return;
761 +       }
762 +
763 +       pll0 = bcma_chipco_pll_read(cc, BCMA_CC_PMU15_PLL_PLLCTL0);
764 +       freq_tgt_current = (pll0 & BCMA_CC_PMU15_PLL_PC0_FREQTGT_MASK) >>
765 +               BCMA_CC_PMU15_PLL_PC0_FREQTGT_SHIFT;
766 +
767 +       if (freq_tgt_current == freq_tgt_target) {
768 +               bcma_debug(bus, "Target TGT frequency already set\n");
769 +               return;
770 +       }
771 +
772 +       /* Turn off PLL */
773 +       switch (bus->chipinfo.id) {
774 +       case BCMA_CHIP_ID_BCM43142:
775 +               mask = (u32)~(BCMA_RES_4314_HT_AVAIL |
776 +                             BCMA_RES_4314_MACPHY_CLK_AVAIL);
777 +
778 +               bcma_cc_mask32(cc, BCMA_CC_PMU_MINRES_MSK, mask);
779 +               bcma_cc_mask32(cc, BCMA_CC_PMU_MAXRES_MSK, mask);
780 +               bcma_wait_value(cc->core, BCMA_CLKCTLST,
781 +                               BCMA_CLKCTLST_HAVEHT, 0, 20000);
782 +               break;
783 +       }
784 +
785 +       pll0 &= ~BCMA_CC_PMU15_PLL_PC0_FREQTGT_MASK;
786 +       pll0 |= freq_tgt_target << BCMA_CC_PMU15_PLL_PC0_FREQTGT_SHIFT;
787 +       bcma_chipco_pll_write(cc, BCMA_CC_PMU15_PLL_PLLCTL0, pll0);
788 +
789 +       /* Flush */
790 +       if (cc->pmu.rev >= 2)
791 +               bcma_cc_set32(cc, BCMA_CC_PMU_CTL, BCMA_CC_PMU_CTL_PLL_UPD);
792 +
793 +       /* TODO: Do we need to update OTP? */
794 +}
795 +
796  static void bcma_pmu_pll_init(struct bcma_drv_cc *cc)
797  {
798         struct bcma_bus *bus = cc->core->bus;
799 +       u32 xtalfreq = bcma_pmu_xtalfreq(cc);
800  
801         switch (bus->chipinfo.id) {
802 -       case 0x4313:
803 -       case 0x4331:
804 -       case 43224:
805 -       case 43225:
806 +       case BCMA_CHIP_ID_BCM43142:
807 +               if (xtalfreq == 0)
808 +                       xtalfreq = 20000;
809 +               bcma_pmu2_pll_init0(cc, xtalfreq);
810                 break;
811 -       default:
812 -               pr_err("PLL init unknown for device 0x%04X\n",
813 -                       bus->chipinfo.id);
814         }
815  }
816  
817 @@ -76,16 +165,32 @@ static void bcma_pmu_resources_init(stru
818         u32 min_msk = 0, max_msk = 0;
819  
820         switch (bus->chipinfo.id) {
821 -       case 0x4313:
822 +       case BCMA_CHIP_ID_BCM4313:
823                 min_msk = 0x200D;
824                 max_msk = 0xFFFF;
825                 break;
826 -       case 43224:
827 -       case 43225:
828 +       case BCMA_CHIP_ID_BCM43142:
829 +               min_msk = BCMA_RES_4314_LPLDO_PU |
830 +                         BCMA_RES_4314_PMU_SLEEP_DIS |
831 +                         BCMA_RES_4314_PMU_BG_PU |
832 +                         BCMA_RES_4314_CBUCK_LPOM_PU |
833 +                         BCMA_RES_4314_CBUCK_PFM_PU |
834 +                         BCMA_RES_4314_CLDO_PU |
835 +                         BCMA_RES_4314_LPLDO2_LVM |
836 +                         BCMA_RES_4314_WL_PMU_PU |
837 +                         BCMA_RES_4314_LDO3P3_PU |
838 +                         BCMA_RES_4314_OTP_PU |
839 +                         BCMA_RES_4314_WL_PWRSW_PU |
840 +                         BCMA_RES_4314_LQ_AVAIL |
841 +                         BCMA_RES_4314_LOGIC_RET |
842 +                         BCMA_RES_4314_MEM_SLEEP |
843 +                         BCMA_RES_4314_MACPHY_RET |
844 +                         BCMA_RES_4314_WL_CORE_READY;
845 +               max_msk = 0x3FFFFFFF;
846                 break;
847         default:
848 -               pr_err("PMU resource config unknown for device 0x%04X\n",
849 -                       bus->chipinfo.id);
850 +               bcma_debug(bus, "PMU resource config unknown or not needed for device 0x%04X\n",
851 +                          bus->chipinfo.id);
852         }
853  
854         /* Set the resource masks. */
855 @@ -93,22 +198,12 @@ static void bcma_pmu_resources_init(stru
856                 bcma_cc_write32(cc, BCMA_CC_PMU_MINRES_MSK, min_msk);
857         if (max_msk)
858                 bcma_cc_write32(cc, BCMA_CC_PMU_MAXRES_MSK, max_msk);
859 -}
860  
861 -void bcma_pmu_swreg_init(struct bcma_drv_cc *cc)
862 -{
863 -       struct bcma_bus *bus = cc->core->bus;
864 -
865 -       switch (bus->chipinfo.id) {
866 -       case 0x4313:
867 -       case 0x4331:
868 -       case 43224:
869 -       case 43225:
870 -               break;
871 -       default:
872 -               pr_err("PMU switch/regulators init unknown for device "
873 -                       "0x%04X\n", bus->chipinfo.id);
874 -       }
875 +       /*
876 +        * Add some delay; allow resources to come up and settle.
877 +        * Delay is required for SoC (early init).
878 +        */
879 +       mdelay(2);
880  }
881  
882  /* Disable to allow reading SPROM. Don't know the adventages of enabling it. */
883 @@ -122,51 +217,69 @@ void bcma_chipco_bcm4331_ext_pa_lines_ct
884                 val |= BCMA_CHIPCTL_4331_EXTPA_EN;
885                 if (bus->chipinfo.pkg == 9 || bus->chipinfo.pkg == 11)
886                         val |= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
887 +               else if (bus->chipinfo.rev > 0)
888 +                       val |= BCMA_CHIPCTL_4331_EXTPA_EN2;
889         } else {
890                 val &= ~BCMA_CHIPCTL_4331_EXTPA_EN;
891 +               val &= ~BCMA_CHIPCTL_4331_EXTPA_EN2;
892                 val &= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
893         }
894         bcma_cc_write32(cc, BCMA_CC_CHIPCTL, val);
895  }
896  
897 -void bcma_pmu_workarounds(struct bcma_drv_cc *cc)
898 +static void bcma_pmu_workarounds(struct bcma_drv_cc *cc)
899  {
900         struct bcma_bus *bus = cc->core->bus;
901  
902         switch (bus->chipinfo.id) {
903 -       case 0x4313:
904 -               bcma_chipco_chipctl_maskset(cc, 0, ~0, 0x7);
905 +       case BCMA_CHIP_ID_BCM4313:
906 +               /* enable 12 mA drive strenth for 4313 and set chipControl
907 +                  register bit 1 */
908 +               bcma_chipco_chipctl_maskset(cc, 0,
909 +                                           ~BCMA_CCTRL_4313_12MA_LED_DRIVE,
910 +                                           BCMA_CCTRL_4313_12MA_LED_DRIVE);
911                 break;
912 -       case 0x4331:
913 -               /* BCM4331 workaround is SPROM-related, we put it in sprom.c */
914 +       case BCMA_CHIP_ID_BCM4331:
915 +       case BCMA_CHIP_ID_BCM43431:
916 +               /* Ext PA lines must be enabled for tx on BCM4331 */
917 +               bcma_chipco_bcm4331_ext_pa_lines_ctl(cc, true);
918                 break;
919 -       case 43224:
920 +       case BCMA_CHIP_ID_BCM43224:
921 +       case BCMA_CHIP_ID_BCM43421:
922 +               /* enable 12 mA drive strenth for 43224 and set chipControl
923 +                  register bit 15 */
924                 if (bus->chipinfo.rev == 0) {
925 -                       pr_err("Workarounds for 43224 rev 0 not fully "
926 -                               "implemented\n");
927 -                       bcma_chipco_chipctl_maskset(cc, 0, ~0, 0x00F000F0);
928 +                       bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL,
929 +                                         ~BCMA_CCTRL_43224_GPIO_TOGGLE,
930 +                                         BCMA_CCTRL_43224_GPIO_TOGGLE);
931 +                       bcma_chipco_chipctl_maskset(cc, 0,
932 +                                                   ~BCMA_CCTRL_43224A0_12MA_LED_DRIVE,
933 +                                                   BCMA_CCTRL_43224A0_12MA_LED_DRIVE);
934                 } else {
935 -                       bcma_chipco_chipctl_maskset(cc, 0, ~0, 0xF0);
936 +                       bcma_chipco_chipctl_maskset(cc, 0,
937 +                                                   ~BCMA_CCTRL_43224B0_12MA_LED_DRIVE,
938 +                                                   BCMA_CCTRL_43224B0_12MA_LED_DRIVE);
939                 }
940                 break;
941 -       case 43225:
942 -               break;
943         default:
944 -               pr_err("Workarounds unknown for device 0x%04X\n",
945 -                       bus->chipinfo.id);
946 +               bcma_debug(bus, "Workarounds unknown or not needed for device 0x%04X\n",
947 +                          bus->chipinfo.id);
948         }
949  }
950  
951 -void bcma_pmu_init(struct bcma_drv_cc *cc)
952 +void bcma_pmu_early_init(struct bcma_drv_cc *cc)
953  {
954         u32 pmucap;
955  
956         pmucap = bcma_cc_read32(cc, BCMA_CC_PMU_CAP);
957         cc->pmu.rev = (pmucap & BCMA_CC_PMU_CAP_REVISION);
958  
959 -       pr_debug("Found rev %u PMU (capabilities 0x%08X)\n", cc->pmu.rev,
960 -                pmucap);
961 +       bcma_debug(cc->core->bus, "Found rev %u PMU (capabilities 0x%08X)\n",
962 +                  cc->pmu.rev, pmucap);
963 +}
964  
965 +void bcma_pmu_init(struct bcma_drv_cc *cc)
966 +{
967         if (cc->pmu.rev == 1)
968                 bcma_cc_mask32(cc, BCMA_CC_PMU_CTL,
969                               ~BCMA_CC_PMU_CTL_NOILPONW);
970 @@ -174,37 +287,48 @@ void bcma_pmu_init(struct bcma_drv_cc *c
971                 bcma_cc_set32(cc, BCMA_CC_PMU_CTL,
972                              BCMA_CC_PMU_CTL_NOILPONW);
973  
974 -       if (cc->core->id.id == 0x4329 && cc->core->id.rev == 2)
975 -               pr_err("Fix for 4329b0 bad LPOM state not implemented!\n");
976 -
977         bcma_pmu_pll_init(cc);
978         bcma_pmu_resources_init(cc);
979 -       bcma_pmu_swreg_init(cc);
980         bcma_pmu_workarounds(cc);
981  }
982  
983 -u32 bcma_pmu_alp_clock(struct bcma_drv_cc *cc)
984 +u32 bcma_pmu_get_alp_clock(struct bcma_drv_cc *cc)
985  {
986         struct bcma_bus *bus = cc->core->bus;
987  
988         switch (bus->chipinfo.id) {
989 -       case 0x4716:
990 -       case 0x4748:
991 -       case 47162:
992 -       case 0x4313:
993 -       case 0x5357:
994 -       case 0x4749:
995 -       case 53572:
996 +       case BCMA_CHIP_ID_BCM4313:
997 +       case BCMA_CHIP_ID_BCM43224:
998 +       case BCMA_CHIP_ID_BCM43225:
999 +       case BCMA_CHIP_ID_BCM43227:
1000 +       case BCMA_CHIP_ID_BCM43228:
1001 +       case BCMA_CHIP_ID_BCM4331:
1002 +       case BCMA_CHIP_ID_BCM43421:
1003 +       case BCMA_CHIP_ID_BCM43428:
1004 +       case BCMA_CHIP_ID_BCM43431:
1005 +       case BCMA_CHIP_ID_BCM4716:
1006 +       case BCMA_CHIP_ID_BCM47162:
1007 +       case BCMA_CHIP_ID_BCM4748:
1008 +       case BCMA_CHIP_ID_BCM4749:
1009 +       case BCMA_CHIP_ID_BCM5357:
1010 +       case BCMA_CHIP_ID_BCM53572:
1011 +       case BCMA_CHIP_ID_BCM6362:
1012                 /* always 20Mhz */
1013                 return 20000 * 1000;
1014 -       case 0x5356:
1015 -       case 0x5300:
1016 +       case BCMA_CHIP_ID_BCM4706:
1017 +       case BCMA_CHIP_ID_BCM5356:
1018                 /* always 25Mhz */
1019                 return 25000 * 1000;
1020 +       case BCMA_CHIP_ID_BCM43460:
1021 +       case BCMA_CHIP_ID_BCM4352:
1022 +       case BCMA_CHIP_ID_BCM4360:
1023 +               if (cc->status & BCMA_CC_CHIPST_4360_XTAL_40MZ)
1024 +                       return 40000 * 1000;
1025 +               else
1026 +                       return 20000 * 1000;
1027         default:
1028 -               pr_warn("No ALP clock specified for %04X device, "
1029 -                       "pmu rev. %d, using default %d Hz\n",
1030 -                       bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK);
1031 +               bcma_warn(bus, "No ALP clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
1032 +                         bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK);
1033         }
1034         return BCMA_CC_PMU_ALP_CLOCK;
1035  }
1036 @@ -212,7 +336,7 @@ u32 bcma_pmu_alp_clock(struct bcma_drv_c
1037  /* Find the output of the "m" pll divider given pll controls that start with
1038   * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
1039   */
1040 -static u32 bcma_pmu_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
1041 +static u32 bcma_pmu_pll_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
1042  {
1043         u32 tmp, div, ndiv, p1, p2, fc;
1044         struct bcma_bus *bus = cc->core->bus;
1045 @@ -221,7 +345,8 @@ static u32 bcma_pmu_clock(struct bcma_dr
1046  
1047         BUG_ON(!m || m > 4);
1048  
1049 -       if (bus->chipinfo.id == 0x5357 || bus->chipinfo.id == 0x4749) {
1050 +       if (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
1051 +           bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) {
1052                 /* Detect failure in clock setting */
1053                 tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
1054                 if (tmp & 0x40000)
1055 @@ -240,60 +365,96 @@ static u32 bcma_pmu_clock(struct bcma_dr
1056         ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT;
1057  
1058         /* Do calculation in Mhz */
1059 -       fc = bcma_pmu_alp_clock(cc) / 1000000;
1060 +       fc = bcma_pmu_get_alp_clock(cc) / 1000000;
1061         fc = (p1 * ndiv * fc) / p2;
1062  
1063         /* Return clock in Hertz */
1064         return (fc / div) * 1000000;
1065  }
1066  
1067 +static u32 bcma_pmu_pll_clock_bcm4706(struct bcma_drv_cc *cc, u32 pll0, u32 m)
1068 +{
1069 +       u32 tmp, ndiv, p1div, p2div;
1070 +       u32 clock;
1071 +
1072 +       BUG_ON(!m || m > 4);
1073 +
1074 +       /* Get N, P1 and P2 dividers to determine CPU clock */
1075 +       tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PMU6_4706_PROCPLL_OFF);
1076 +       ndiv = (tmp & BCMA_CC_PMU6_4706_PROC_NDIV_INT_MASK)
1077 +               >> BCMA_CC_PMU6_4706_PROC_NDIV_INT_SHIFT;
1078 +       p1div = (tmp & BCMA_CC_PMU6_4706_PROC_P1DIV_MASK)
1079 +               >> BCMA_CC_PMU6_4706_PROC_P1DIV_SHIFT;
1080 +       p2div = (tmp & BCMA_CC_PMU6_4706_PROC_P2DIV_MASK)
1081 +               >> BCMA_CC_PMU6_4706_PROC_P2DIV_SHIFT;
1082 +
1083 +       tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
1084 +       if (tmp & BCMA_CC_CHIPST_4706_PKG_OPTION)
1085 +               /* Low cost bonding: Fixed reference clock 25MHz and m = 4 */
1086 +               clock = (25000000 / 4) * ndiv * p2div / p1div;
1087 +       else
1088 +               /* Fixed reference clock 25MHz and m = 2 */
1089 +               clock = (25000000 / 2) * ndiv * p2div / p1div;
1090 +
1091 +       if (m == BCMA_CC_PMU5_MAINPLL_SSB)
1092 +               clock = clock / 4;
1093 +
1094 +       return clock;
1095 +}
1096 +
1097  /* query bus clock frequency for PMU-enabled chipcommon */
1098 -u32 bcma_pmu_get_clockcontrol(struct bcma_drv_cc *cc)
1099 +u32 bcma_pmu_get_bus_clock(struct bcma_drv_cc *cc)
1100  {
1101         struct bcma_bus *bus = cc->core->bus;
1102  
1103         switch (bus->chipinfo.id) {
1104 -       case 0x4716:
1105 -       case 0x4748:
1106 -       case 47162:
1107 -               return bcma_pmu_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
1108 -                                     BCMA_CC_PMU5_MAINPLL_SSB);
1109 -       case 0x5356:
1110 -               return bcma_pmu_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
1111 -                                     BCMA_CC_PMU5_MAINPLL_SSB);
1112 -       case 0x5357:
1113 -       case 0x4749:
1114 -               return bcma_pmu_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
1115 -                                     BCMA_CC_PMU5_MAINPLL_SSB);
1116 -       case 0x5300:
1117 -               return bcma_pmu_clock(cc, BCMA_CC_PMU4706_MAINPLL_PLL0,
1118 -                                     BCMA_CC_PMU5_MAINPLL_SSB);
1119 -       case 53572:
1120 +       case BCMA_CHIP_ID_BCM4716:
1121 +       case BCMA_CHIP_ID_BCM4748:
1122 +       case BCMA_CHIP_ID_BCM47162:
1123 +               return bcma_pmu_pll_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
1124 +                                         BCMA_CC_PMU5_MAINPLL_SSB);
1125 +       case BCMA_CHIP_ID_BCM5356:
1126 +               return bcma_pmu_pll_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
1127 +                                         BCMA_CC_PMU5_MAINPLL_SSB);
1128 +       case BCMA_CHIP_ID_BCM5357:
1129 +       case BCMA_CHIP_ID_BCM4749:
1130 +               return bcma_pmu_pll_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
1131 +                                         BCMA_CC_PMU5_MAINPLL_SSB);
1132 +       case BCMA_CHIP_ID_BCM4706:
1133 +               return bcma_pmu_pll_clock_bcm4706(cc,
1134 +                                                 BCMA_CC_PMU4706_MAINPLL_PLL0,
1135 +                                                 BCMA_CC_PMU5_MAINPLL_SSB);
1136 +       case BCMA_CHIP_ID_BCM53572:
1137                 return 75000000;
1138         default:
1139 -               pr_warn("No backplane clock specified for %04X device, "
1140 -                       "pmu rev. %d, using default %d Hz\n",
1141 -                       bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
1142 +               bcma_warn(bus, "No bus clock specified for %04X device, pmu rev. %d, using default %d Hz\n",
1143 +                         bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
1144         }
1145         return BCMA_CC_PMU_HT_CLOCK;
1146  }
1147 +EXPORT_SYMBOL_GPL(bcma_pmu_get_bus_clock);
1148  
1149  /* query cpu clock frequency for PMU-enabled chipcommon */
1150 -u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc)
1151 +u32 bcma_pmu_get_cpu_clock(struct bcma_drv_cc *cc)
1152  {
1153         struct bcma_bus *bus = cc->core->bus;
1154  
1155 -       if (bus->chipinfo.id == 53572)
1156 +       if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53572)
1157                 return 300000000;
1158  
1159 +       /* New PMUs can have different clock for bus and CPU */
1160         if (cc->pmu.rev >= 5) {
1161                 u32 pll;
1162                 switch (bus->chipinfo.id) {
1163 -               case 0x5356:
1164 +               case BCMA_CHIP_ID_BCM4706:
1165 +                       return bcma_pmu_pll_clock_bcm4706(cc,
1166 +                                               BCMA_CC_PMU4706_MAINPLL_PLL0,
1167 +                                               BCMA_CC_PMU5_MAINPLL_CPU);
1168 +               case BCMA_CHIP_ID_BCM5356:
1169                         pll = BCMA_CC_PMU5356_MAINPLL_PLL0;
1170                         break;
1171 -               case 0x5357:
1172 -               case 0x4749:
1173 +               case BCMA_CHIP_ID_BCM5357:
1174 +               case BCMA_CHIP_ID_BCM4749:
1175                         pll = BCMA_CC_PMU5357_MAINPLL_PLL0;
1176                         break;
1177                 default:
1178 @@ -301,10 +462,189 @@ u32 bcma_pmu_get_clockcpu(struct bcma_dr
1179                         break;
1180                 }
1181  
1182 -               /* TODO: if (bus->chipinfo.id == 0x5300)
1183 -                 return si_4706_pmu_clock(sih, osh, cc, PMU4706_MAINPLL_PLL0, PMU5_MAINPLL_CPU); */
1184 -               return bcma_pmu_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
1185 +               return bcma_pmu_pll_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
1186 +       }
1187 +
1188 +       /* On old PMUs CPU has the same clock as the bus */
1189 +       return bcma_pmu_get_bus_clock(cc);
1190 +}
1191 +
1192 +static void bcma_pmu_spuravoid_pll_write(struct bcma_drv_cc *cc, u32 offset,
1193 +                                        u32 value)
1194 +{
1195 +       bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
1196 +       bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value);
1197 +}
1198 +
1199 +void bcma_pmu_spuravoid_pllupdate(struct bcma_drv_cc *cc, int spuravoid)
1200 +{
1201 +       u32 tmp = 0;
1202 +       u8 phypll_offset = 0;
1203 +       u8 bcm5357_bcm43236_p1div[] = {0x1, 0x5, 0x5};
1204 +       u8 bcm5357_bcm43236_ndiv[] = {0x30, 0xf6, 0xfc};
1205 +       struct bcma_bus *bus = cc->core->bus;
1206 +
1207 +       switch (bus->chipinfo.id) {
1208 +       case BCMA_CHIP_ID_BCM5357:
1209 +       case BCMA_CHIP_ID_BCM4749:
1210 +       case BCMA_CHIP_ID_BCM53572:
1211 +               /* 5357[ab]0, 43236[ab]0, and 6362b0 */
1212 +
1213 +               /* BCM5357 needs to touch PLL1_PLLCTL[02],
1214 +                  so offset PLL0_PLLCTL[02] by 6 */
1215 +               phypll_offset = (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
1216 +                      bus->chipinfo.id == BCMA_CHIP_ID_BCM4749 ||
1217 +                      bus->chipinfo.id == BCMA_CHIP_ID_BCM53572) ? 6 : 0;
1218 +
1219 +               /* RMW only the P1 divider */
1220 +               bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR,
1221 +                               BCMA_CC_PMU_PLL_CTL0 + phypll_offset);
1222 +               tmp = bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
1223 +               tmp &= (~(BCMA_CC_PMU1_PLL0_PC0_P1DIV_MASK));
1224 +               tmp |= (bcm5357_bcm43236_p1div[spuravoid] << BCMA_CC_PMU1_PLL0_PC0_P1DIV_SHIFT);
1225 +               bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, tmp);
1226 +
1227 +               /* RMW only the int feedback divider */
1228 +               bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR,
1229 +                               BCMA_CC_PMU_PLL_CTL2 + phypll_offset);
1230 +               tmp = bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
1231 +               tmp &= ~(BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_MASK);
1232 +               tmp |= (bcm5357_bcm43236_ndiv[spuravoid]) << BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_SHIFT;
1233 +               bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, tmp);
1234 +
1235 +               tmp = BCMA_CC_PMU_CTL_PLL_UPD;
1236 +               break;
1237 +
1238 +       case BCMA_CHIP_ID_BCM4331:
1239 +       case BCMA_CHIP_ID_BCM43431:
1240 +               if (spuravoid == 2) {
1241 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1242 +                                                    0x11500014);
1243 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1244 +                                                    0x0FC00a08);
1245 +               } else if (spuravoid == 1) {
1246 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1247 +                                                    0x11500014);
1248 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1249 +                                                    0x0F600a08);
1250 +               } else {
1251 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1252 +                                                    0x11100014);
1253 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1254 +                                                    0x03000a08);
1255 +               }
1256 +               tmp = BCMA_CC_PMU_CTL_PLL_UPD;
1257 +               break;
1258 +
1259 +       case BCMA_CHIP_ID_BCM43224:
1260 +       case BCMA_CHIP_ID_BCM43225:
1261 +       case BCMA_CHIP_ID_BCM43421:
1262 +               if (spuravoid == 1) {
1263 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1264 +                                                    0x11500010);
1265 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
1266 +                                                    0x000C0C06);
1267 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1268 +                                                    0x0F600a08);
1269 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
1270 +                                                    0x00000000);
1271 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
1272 +                                                    0x2001E920);
1273 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
1274 +                                                    0x88888815);
1275 +               } else {
1276 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1277 +                                                    0x11100010);
1278 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
1279 +                                                    0x000c0c06);
1280 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1281 +                                                    0x03000a08);
1282 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
1283 +                                                    0x00000000);
1284 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
1285 +                                                    0x200005c0);
1286 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
1287 +                                                    0x88888815);
1288 +               }
1289 +               tmp = BCMA_CC_PMU_CTL_PLL_UPD;
1290 +               break;
1291 +
1292 +       case BCMA_CHIP_ID_BCM4716:
1293 +       case BCMA_CHIP_ID_BCM4748:
1294 +       case BCMA_CHIP_ID_BCM47162:
1295 +               if (spuravoid == 1) {
1296 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1297 +                                                    0x11500060);
1298 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
1299 +                                                    0x080C0C06);
1300 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1301 +                                                    0x0F600000);
1302 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
1303 +                                                    0x00000000);
1304 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
1305 +                                                    0x2001E924);
1306 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
1307 +                                                    0x88888815);
1308 +               } else {
1309 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1310 +                                                    0x11100060);
1311 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
1312 +                                                    0x080c0c06);
1313 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1314 +                                                    0x03000000);
1315 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
1316 +                                                    0x00000000);
1317 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
1318 +                                                    0x200005c0);
1319 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
1320 +                                                    0x88888815);
1321 +               }
1322 +
1323 +               tmp = BCMA_CC_PMU_CTL_PLL_UPD | BCMA_CC_PMU_CTL_NOILPONW;
1324 +               break;
1325 +
1326 +       case BCMA_CHIP_ID_BCM43227:
1327 +       case BCMA_CHIP_ID_BCM43228:
1328 +       case BCMA_CHIP_ID_BCM43428:
1329 +               /* LCNXN */
1330 +               /* PLL Settings for spur avoidance on/off mode,
1331 +                  no on2 support for 43228A0 */
1332 +               if (spuravoid == 1) {
1333 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1334 +                                                    0x01100014);
1335 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
1336 +                                                    0x040C0C06);
1337 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1338 +                                                    0x03140A08);
1339 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
1340 +                                                    0x00333333);
1341 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
1342 +                                                    0x202C2820);
1343 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
1344 +                                                    0x88888815);
1345 +               } else {
1346 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL0,
1347 +                                                    0x11100014);
1348 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL1,
1349 +                                                    0x040c0c06);
1350 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL2,
1351 +                                                    0x03000a08);
1352 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL3,
1353 +                                                    0x00000000);
1354 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL4,
1355 +                                                    0x200005c0);
1356 +                       bcma_pmu_spuravoid_pll_write(cc, BCMA_CC_PMU_PLL_CTL5,
1357 +                                                    0x88888815);
1358 +               }
1359 +               tmp = BCMA_CC_PMU_CTL_PLL_UPD;
1360 +               break;
1361 +       default:
1362 +               bcma_err(bus, "Unknown spuravoidance settings for chip 0x%04X, not changing PLL\n",
1363 +                        bus->chipinfo.id);
1364 +               break;
1365         }
1366  
1367 -       return bcma_pmu_get_clockcontrol(cc);
1368 +       tmp |= bcma_cc_read32(cc, BCMA_CC_PMU_CTL);
1369 +       bcma_cc_write32(cc, BCMA_CC_PMU_CTL, tmp);
1370  }
1371 +EXPORT_SYMBOL_GPL(bcma_pmu_spuravoid_pllupdate);
1372 --- /dev/null
1373 +++ b/drivers/bcma/driver_chipcommon_sflash.c
1374 @@ -0,0 +1,165 @@
1375 +/*
1376 + * Broadcom specific AMBA
1377 + * ChipCommon serial flash interface
1378 + *
1379 + * Licensed under the GNU/GPL. See COPYING for details.
1380 + */
1381 +
1382 +#include "bcma_private.h"
1383 +
1384 +#include <linux/platform_device.h>
1385 +#include <linux/bcma/bcma.h>
1386 +
1387 +static struct resource bcma_sflash_resource = {
1388 +       .name   = "bcma_sflash",
1389 +       .start  = BCMA_SOC_FLASH2,
1390 +       .end    = 0,
1391 +       .flags  = IORESOURCE_MEM | IORESOURCE_READONLY,
1392 +};
1393 +
1394 +struct platform_device bcma_sflash_dev = {
1395 +       .name           = "bcma_sflash",
1396 +       .resource       = &bcma_sflash_resource,
1397 +       .num_resources  = 1,
1398 +};
1399 +
1400 +struct bcma_sflash_tbl_e {
1401 +       char *name;
1402 +       u32 id;
1403 +       u32 blocksize;
1404 +       u16 numblocks;
1405 +};
1406 +
1407 +static const struct bcma_sflash_tbl_e bcma_sflash_st_tbl[] = {
1408 +       { "M25P20", 0x11, 0x10000, 4, },
1409 +       { "M25P40", 0x12, 0x10000, 8, },
1410 +
1411 +       { "M25P16", 0x14, 0x10000, 32, },
1412 +       { "M25P32", 0x15, 0x10000, 64, },
1413 +       { "M25P64", 0x16, 0x10000, 128, },
1414 +       { "M25FL128", 0x17, 0x10000, 256, },
1415 +       { 0 },
1416 +};
1417 +
1418 +static const struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {
1419 +       { "SST25WF512", 1, 0x1000, 16, },
1420 +       { "SST25VF512", 0x48, 0x1000, 16, },
1421 +       { "SST25WF010", 2, 0x1000, 32, },
1422 +       { "SST25VF010", 0x49, 0x1000, 32, },
1423 +       { "SST25WF020", 3, 0x1000, 64, },
1424 +       { "SST25VF020", 0x43, 0x1000, 64, },
1425 +       { "SST25WF040", 4, 0x1000, 128, },
1426 +       { "SST25VF040", 0x44, 0x1000, 128, },
1427 +       { "SST25VF040B", 0x8d, 0x1000, 128, },
1428 +       { "SST25WF080", 5, 0x1000, 256, },
1429 +       { "SST25VF080B", 0x8e, 0x1000, 256, },
1430 +       { "SST25VF016", 0x41, 0x1000, 512, },
1431 +       { "SST25VF032", 0x4a, 0x1000, 1024, },
1432 +       { "SST25VF064", 0x4b, 0x1000, 2048, },
1433 +       { 0 },
1434 +};
1435 +
1436 +static const struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {
1437 +       { "AT45DB011", 0xc, 256, 512, },
1438 +       { "AT45DB021", 0x14, 256, 1024, },
1439 +       { "AT45DB041", 0x1c, 256, 2048, },
1440 +       { "AT45DB081", 0x24, 256, 4096, },
1441 +       { "AT45DB161", 0x2c, 512, 4096, },
1442 +       { "AT45DB321", 0x34, 512, 8192, },
1443 +       { "AT45DB642", 0x3c, 1024, 8192, },
1444 +       { 0 },
1445 +};
1446 +
1447 +static void bcma_sflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
1448 +{
1449 +       int i;
1450 +       bcma_cc_write32(cc, BCMA_CC_FLASHCTL,
1451 +                       BCMA_CC_FLASHCTL_START | opcode);
1452 +       for (i = 0; i < 1000; i++) {
1453 +               if (!(bcma_cc_read32(cc, BCMA_CC_FLASHCTL) &
1454 +                     BCMA_CC_FLASHCTL_BUSY))
1455 +                       return;
1456 +               cpu_relax();
1457 +       }
1458 +       bcma_err(cc->core->bus, "SFLASH control command failed (timeout)!\n");
1459 +}
1460 +
1461 +/* Initialize serial flash access */
1462 +int bcma_sflash_init(struct bcma_drv_cc *cc)
1463 +{
1464 +       struct bcma_bus *bus = cc->core->bus;
1465 +       struct bcma_sflash *sflash = &cc->sflash;
1466 +       const struct bcma_sflash_tbl_e *e;
1467 +       u32 id, id2;
1468 +
1469 +       switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
1470 +       case BCMA_CC_FLASHT_STSER:
1471 +               bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_DP);
1472 +
1473 +               bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 0);
1474 +               bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
1475 +               id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
1476 +
1477 +               bcma_cc_write32(cc, BCMA_CC_FLASHADDR, 1);
1478 +               bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_ST_RES);
1479 +               id2 = bcma_cc_read32(cc, BCMA_CC_FLASHDATA);
1480 +
1481 +               switch (id) {
1482 +               case 0xbf:
1483 +                       for (e = bcma_sflash_sst_tbl; e->name; e++) {
1484 +                               if (e->id == id2)
1485 +                                       break;
1486 +                       }
1487 +                       break;
1488 +               case 0x13:
1489 +                       return -ENOTSUPP;
1490 +               default:
1491 +                       for (e = bcma_sflash_st_tbl; e->name; e++) {
1492 +                               if (e->id == id)
1493 +                                       break;
1494 +                       }
1495 +                       break;
1496 +               }
1497 +               if (!e->name) {
1498 +                       bcma_err(bus, "Unsupported ST serial flash (id: 0x%X, id2: 0x%X)\n", id, id2);
1499 +                       return -ENOTSUPP;
1500 +               }
1501 +
1502 +               break;
1503 +       case BCMA_CC_FLASHT_ATSER:
1504 +               bcma_sflash_cmd(cc, BCMA_CC_FLASHCTL_AT_STATUS);
1505 +               id = bcma_cc_read32(cc, BCMA_CC_FLASHDATA) & 0x3c;
1506 +
1507 +               for (e = bcma_sflash_at_tbl; e->name; e++) {
1508 +                       if (e->id == id)
1509 +                               break;
1510 +               }
1511 +               if (!e->name) {
1512 +                       bcma_err(bus, "Unsupported Atmel serial flash (id: 0x%X)\n", id);
1513 +                       return -ENOTSUPP;
1514 +               }
1515 +
1516 +               break;
1517 +       default:
1518 +               bcma_err(bus, "Unsupported flash type\n");
1519 +               return -ENOTSUPP;
1520 +       }
1521 +
1522 +       sflash->window = BCMA_SOC_FLASH2;
1523 +       sflash->blocksize = e->blocksize;
1524 +       sflash->numblocks = e->numblocks;
1525 +       sflash->size = sflash->blocksize * sflash->numblocks;
1526 +       sflash->present = true;
1527 +
1528 +       bcma_info(bus, "Found %s serial flash (size: %dKiB, blocksize: 0x%X, blocks: %d)\n",
1529 +                 e->name, sflash->size / 1024, sflash->blocksize,
1530 +                 sflash->numblocks);
1531 +
1532 +       /* Prepare platform device, but don't register it yet. It's too early,
1533 +        * malloc (required by device_private_init) is not available yet. */
1534 +       bcma_sflash_dev.resource[0].end = bcma_sflash_dev.resource[0].start +
1535 +                                         sflash->size;
1536 +       bcma_sflash_dev.dev.platform_data = sflash;
1537 +
1538 +       return 0;
1539 +}
1540 --- /dev/null
1541 +++ b/drivers/bcma/driver_gmac_cmn.c
1542 @@ -0,0 +1,14 @@
1543 +/*
1544 + * Broadcom specific AMBA
1545 + * GBIT MAC COMMON Core
1546 + *
1547 + * Licensed under the GNU/GPL. See COPYING for details.
1548 + */
1549 +
1550 +#include "bcma_private.h"
1551 +#include <linux/bcma/bcma.h>
1552 +
1553 +void __devinit bcma_core_gmac_cmn_init(struct bcma_drv_gmac_cmn *gc)
1554 +{
1555 +       mutex_init(&gc->phy_mutex);
1556 +}
1557 --- /dev/null
1558 +++ b/drivers/bcma/driver_gpio.c
1559 @@ -0,0 +1,114 @@
1560 +/*
1561 + * Broadcom specific AMBA
1562 + * GPIO driver
1563 + *
1564 + * Copyright 2011, Broadcom Corporation
1565 + * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
1566 + *
1567 + * Licensed under the GNU/GPL. See COPYING for details.
1568 + */
1569 +
1570 +#include <linux/gpio.h>
1571 +#include <linux/export.h>
1572 +#include <linux/bcma/bcma.h>
1573 +
1574 +#include "bcma_private.h"
1575 +
1576 +static inline struct bcma_drv_cc *bcma_gpio_get_cc(struct gpio_chip *chip)
1577 +{
1578 +       return container_of(chip, struct bcma_drv_cc, gpio);
1579 +}
1580 +
1581 +static int bcma_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
1582 +{
1583 +       struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
1584 +
1585 +       return !!bcma_chipco_gpio_in(cc, 1 << gpio);
1586 +}
1587 +
1588 +static void bcma_gpio_set_value(struct gpio_chip *chip, unsigned gpio,
1589 +                               int value)
1590 +{
1591 +       struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
1592 +
1593 +       bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0);
1594 +}
1595 +
1596 +static int bcma_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
1597 +{
1598 +       struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
1599 +
1600 +       bcma_chipco_gpio_outen(cc, 1 << gpio, 0);
1601 +       return 0;
1602 +}
1603 +
1604 +static int bcma_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
1605 +                                     int value)
1606 +{
1607 +       struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
1608 +
1609 +       bcma_chipco_gpio_outen(cc, 1 << gpio, 1 << gpio);
1610 +       bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0);
1611 +       return 0;
1612 +}
1613 +
1614 +static int bcma_gpio_request(struct gpio_chip *chip, unsigned gpio)
1615 +{
1616 +       struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
1617 +
1618 +       bcma_chipco_gpio_control(cc, 1 << gpio, 0);
1619 +       /* clear pulldown */
1620 +       bcma_chipco_gpio_pulldown(cc, 1 << gpio, 0);
1621 +       /* Set pullup */
1622 +       bcma_chipco_gpio_pullup(cc, 1 << gpio, 1 << gpio);
1623 +
1624 +       return 0;
1625 +}
1626 +
1627 +static void bcma_gpio_free(struct gpio_chip *chip, unsigned gpio)
1628 +{
1629 +       struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
1630 +
1631 +       /* clear pullup */
1632 +       bcma_chipco_gpio_pullup(cc, 1 << gpio, 0);
1633 +}
1634 +
1635 +static int bcma_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
1636 +{
1637 +       struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
1638 +
1639 +       if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
1640 +               return bcma_core_irq(cc->core);
1641 +       else
1642 +               return -EINVAL;
1643 +}
1644 +
1645 +int bcma_gpio_init(struct bcma_drv_cc *cc)
1646 +{
1647 +       struct gpio_chip *chip = &cc->gpio;
1648 +
1649 +       chip->label             = "bcma_gpio";
1650 +       chip->owner             = THIS_MODULE;
1651 +       chip->request           = bcma_gpio_request;
1652 +       chip->free              = bcma_gpio_free;
1653 +       chip->get               = bcma_gpio_get_value;
1654 +       chip->set               = bcma_gpio_set_value;
1655 +       chip->direction_input   = bcma_gpio_direction_input;
1656 +       chip->direction_output  = bcma_gpio_direction_output;
1657 +       chip->to_irq            = bcma_gpio_to_irq;
1658 +       chip->ngpio             = 16;
1659 +       /* There is just one SoC in one device and its GPIO addresses should be
1660 +        * deterministic to address them more easily. The other buses could get
1661 +        * a random base number. */
1662 +       if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
1663 +               chip->base              = 0;
1664 +       else
1665 +               chip->base              = -1;
1666 +
1667 +       return gpiochip_add(chip);
1668 +}
1669 +
1670 +int bcma_gpio_unregister(struct bcma_drv_cc *cc)
1671 +{
1672 +       return gpiochip_remove(&cc->gpio);
1673 +}
1674 --- a/drivers/bcma/driver_mips.c
1675 +++ b/drivers/bcma/driver_mips.c
1676 @@ -14,23 +14,45 @@
1677  
1678  #include <linux/bcma/bcma.h>
1679  
1680 +#include <linux/mtd/physmap.h>
1681 +#include <linux/platform_device.h>
1682  #include <linux/serial.h>
1683  #include <linux/serial_core.h>
1684  #include <linux/serial_reg.h>
1685  #include <linux/time.h>
1686  
1687 +static const char * const part_probes[] = { "bcm47xxpart", NULL };
1688 +
1689 +static struct physmap_flash_data bcma_pflash_data = {
1690 +       .part_probe_types       = part_probes,
1691 +};
1692 +
1693 +static struct resource bcma_pflash_resource = {
1694 +       .name   = "bcma_pflash",
1695 +       .flags  = IORESOURCE_MEM,
1696 +};
1697 +
1698 +struct platform_device bcma_pflash_dev = {
1699 +       .name           = "physmap-flash",
1700 +       .dev            = {
1701 +               .platform_data  = &bcma_pflash_data,
1702 +       },
1703 +       .resource       = &bcma_pflash_resource,
1704 +       .num_resources  = 1,
1705 +};
1706 +
1707  /* The 47162a0 hangs when reading MIPS DMP registers registers */
1708  static inline bool bcma_core_mips_bcm47162a0_quirk(struct bcma_device *dev)
1709  {
1710 -       return dev->bus->chipinfo.id == 47162 && dev->bus->chipinfo.rev == 0 &&
1711 -              dev->id.id == BCMA_CORE_MIPS_74K;
1712 +       return dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM47162 &&
1713 +              dev->bus->chipinfo.rev == 0 && dev->id.id == BCMA_CORE_MIPS_74K;
1714  }
1715  
1716  /* The 5357b0 hangs when reading USB20H DMP registers */
1717  static inline bool bcma_core_mips_bcm5357b0_quirk(struct bcma_device *dev)
1718  {
1719 -       return (dev->bus->chipinfo.id == 0x5357 ||
1720 -               dev->bus->chipinfo.id == 0x4749) &&
1721 +       return (dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
1722 +               dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) &&
1723                dev->bus->chipinfo.pkg == 11 &&
1724                dev->id.id == BCMA_CORE_USB20_HOST;
1725  }
1726 @@ -74,28 +96,41 @@ static u32 bcma_core_mips_irqflag(struct
1727                 return dev->core_index;
1728         flag = bcma_aread32(dev, BCMA_MIPS_OOBSELOUTA30);
1729  
1730 -       return flag & 0x1F;
1731 +       if (flag)
1732 +               return flag & 0x1F;
1733 +       else
1734 +               return 0x3f;
1735  }
1736  
1737  /* Get the MIPS IRQ assignment for a specified device.
1738   * If unassigned, 0 is returned.
1739 + * If disabled, 5 is returned.
1740 + * If not supported, 6 is returned.
1741   */
1742 -unsigned int bcma_core_mips_irq(struct bcma_device *dev)
1743 +static unsigned int bcma_core_mips_irq(struct bcma_device *dev)
1744  {
1745         struct bcma_device *mdev = dev->bus->drv_mips.core;
1746         u32 irqflag;
1747         unsigned int irq;
1748  
1749         irqflag = bcma_core_mips_irqflag(dev);
1750 +       if (irqflag == 0x3f)
1751 +               return 6;
1752  
1753 -       for (irq = 1; irq <= 4; irq++)
1754 +       for (irq = 0; irq <= 4; irq++)
1755                 if (bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq)) &
1756                     (1 << irqflag))
1757                         return irq;
1758  
1759 -       return 0;
1760 +       return 5;
1761 +}
1762 +
1763 +unsigned int bcma_core_irq(struct bcma_device *dev)
1764 +{
1765 +       unsigned int mips_irq = bcma_core_mips_irq(dev);
1766 +       return mips_irq <= 4 ? mips_irq + 2 : 0;
1767  }
1768 -EXPORT_SYMBOL(bcma_core_mips_irq);
1769 +EXPORT_SYMBOL(bcma_core_irq);
1770  
1771  static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
1772  {
1773 @@ -114,8 +149,8 @@ static void bcma_core_mips_set_irq(struc
1774                 bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
1775                             bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) &
1776                             ~(1 << irqflag));
1777 -       else
1778 -               bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq), 0);
1779 +       else if (oldirq != 5)
1780 +               bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(oldirq), 0);
1781  
1782         /* assign the new one */
1783         if (irq == 0) {
1784 @@ -123,17 +158,17 @@ static void bcma_core_mips_set_irq(struc
1785                             bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) |
1786                             (1 << irqflag));
1787         } else {
1788 -               u32 oldirqflag = bcma_read32(mdev,
1789 -                                            BCMA_MIPS_MIPS74K_INTMASK(irq));
1790 -               if (oldirqflag) {
1791 +               u32 irqinitmask = bcma_read32(mdev,
1792 +                                             BCMA_MIPS_MIPS74K_INTMASK(irq));
1793 +               if (irqinitmask) {
1794                         struct bcma_device *core;
1795  
1796                         /* backplane irq line is in use, find out who uses
1797                          * it and set user to irq 0
1798                          */
1799 -                       list_for_each_entry_reverse(core, &bus->cores, list) {
1800 +                       list_for_each_entry(core, &bus->cores, list) {
1801                                 if ((1 << bcma_core_mips_irqflag(core)) ==
1802 -                                   oldirqflag) {
1803 +                                   irqinitmask) {
1804                                         bcma_core_mips_set_irq(core, 0);
1805                                         break;
1806                                 }
1807 @@ -143,15 +178,31 @@ static void bcma_core_mips_set_irq(struc
1808                              1 << irqflag);
1809         }
1810  
1811 -       pr_info("set_irq: core 0x%04x, irq %d => %d\n",
1812 -               dev->id.id, oldirq + 2, irq + 2);
1813 +       bcma_debug(bus, "set_irq: core 0x%04x, irq %d => %d\n",
1814 +                  dev->id.id, oldirq <= 4 ? oldirq + 2 : 0, irq + 2);
1815 +}
1816 +
1817 +static void bcma_core_mips_set_irq_name(struct bcma_bus *bus, unsigned int irq,
1818 +                                       u16 coreid, u8 unit)
1819 +{
1820 +       struct bcma_device *core;
1821 +
1822 +       core = bcma_find_core_unit(bus, coreid, unit);
1823 +       if (!core) {
1824 +               bcma_warn(bus,
1825 +                         "Can not find core (id: 0x%x, unit %i) for IRQ configuration.\n",
1826 +                         coreid, unit);
1827 +               return;
1828 +       }
1829 +
1830 +       bcma_core_mips_set_irq(core, irq);
1831  }
1832  
1833  static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
1834  {
1835         int i;
1836         static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
1837 -       printk(KERN_INFO KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
1838 +       printk(KERN_DEBUG KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
1839         for (i = 0; i <= 6; i++)
1840                 printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
1841         printk("\n");
1842 @@ -161,7 +212,7 @@ static void bcma_core_mips_dump_irq(stru
1843  {
1844         struct bcma_device *core;
1845  
1846 -       list_for_each_entry_reverse(core, &bus->cores, list) {
1847 +       list_for_each_entry(core, &bus->cores, list) {
1848                 bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
1849         }
1850  }
1851 @@ -171,9 +222,9 @@ u32 bcma_cpu_clock(struct bcma_drv_mips
1852         struct bcma_bus *bus = mcore->core->bus;
1853  
1854         if (bus->drv_cc.capabilities & BCMA_CC_CAP_PMU)
1855 -               return bcma_pmu_get_clockcpu(&bus->drv_cc);
1856 +               return bcma_pmu_get_cpu_clock(&bus->drv_cc);
1857  
1858 -       pr_err("No PMU available, need this to get the cpu clock\n");
1859 +       bcma_err(bus, "No PMU available, need this to get the cpu clock\n");
1860         return 0;
1861  }
1862  EXPORT_SYMBOL(bcma_cpu_clock);
1863 @@ -181,25 +232,81 @@ EXPORT_SYMBOL(bcma_cpu_clock);
1864  static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
1865  {
1866         struct bcma_bus *bus = mcore->core->bus;
1867 +       struct bcma_drv_cc *cc = &bus->drv_cc;
1868 +       struct bcma_pflash *pflash = &cc->pflash;
1869  
1870 -       switch (bus->drv_cc.capabilities & BCMA_CC_CAP_FLASHT) {
1871 +       switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
1872         case BCMA_CC_FLASHT_STSER:
1873         case BCMA_CC_FLASHT_ATSER:
1874 -               pr_err("Serial flash not supported.\n");
1875 +               bcma_debug(bus, "Found serial flash\n");
1876 +               bcma_sflash_init(cc);
1877                 break;
1878         case BCMA_CC_FLASHT_PARA:
1879 -               pr_info("found parallel flash.\n");
1880 -               bus->drv_cc.pflash.window = 0x1c000000;
1881 -               bus->drv_cc.pflash.window_size = 0x02000000;
1882 +               bcma_debug(bus, "Found parallel flash\n");
1883 +               pflash->present = true;
1884 +               pflash->window = BCMA_SOC_FLASH2;
1885 +               pflash->window_size = BCMA_SOC_FLASH2_SZ;
1886  
1887 -               if ((bcma_read32(bus->drv_cc.core, BCMA_CC_FLASH_CFG) &
1888 +               if ((bcma_read32(cc->core, BCMA_CC_FLASH_CFG) &
1889                      BCMA_CC_FLASH_CFG_DS) == 0)
1890 -                       bus->drv_cc.pflash.buswidth = 1;
1891 +                       pflash->buswidth = 1;
1892                 else
1893 -                       bus->drv_cc.pflash.buswidth = 2;
1894 +                       pflash->buswidth = 2;
1895 +
1896 +               bcma_pflash_data.width = pflash->buswidth;
1897 +               bcma_pflash_resource.start = pflash->window;
1898 +               bcma_pflash_resource.end = pflash->window + pflash->window_size;
1899 +
1900                 break;
1901         default:
1902 -               pr_err("flash not supported.\n");
1903 +               bcma_err(bus, "Flash type not supported\n");
1904 +       }
1905 +
1906 +       if (cc->core->id.rev == 38 ||
1907 +           bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
1908 +               if (cc->capabilities & BCMA_CC_CAP_NFLASH) {
1909 +                       bcma_debug(bus, "Found NAND flash\n");
1910 +                       bcma_nflash_init(cc);
1911 +               }
1912 +       }
1913 +}
1914 +
1915 +void bcma_core_mips_early_init(struct bcma_drv_mips *mcore)
1916 +{
1917 +       struct bcma_bus *bus = mcore->core->bus;
1918 +
1919 +       if (mcore->early_setup_done)
1920 +               return;
1921 +
1922 +       bcma_chipco_serial_init(&bus->drv_cc);
1923 +       bcma_core_mips_flash_detect(mcore);
1924 +
1925 +       mcore->early_setup_done = true;
1926 +}
1927 +
1928 +static void bcma_fix_i2s_irqflag(struct bcma_bus *bus)
1929 +{
1930 +       struct bcma_device *cpu, *pcie, *i2s;
1931 +
1932 +       /* Fixup the interrupts in 4716/4748 for i2s core (2010 Broadcom SDK)
1933 +        * (IRQ flags > 7 are ignored when setting the interrupt masks)
1934 +        */
1935 +       if (bus->chipinfo.id != BCMA_CHIP_ID_BCM4716 &&
1936 +           bus->chipinfo.id != BCMA_CHIP_ID_BCM4748)
1937 +               return;
1938 +
1939 +       cpu = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
1940 +       pcie = bcma_find_core(bus, BCMA_CORE_PCIE);
1941 +       i2s = bcma_find_core(bus, BCMA_CORE_I2S);
1942 +       if (cpu && pcie && i2s &&
1943 +           bcma_aread32(cpu, BCMA_MIPS_OOBSELINA74) == 0x08060504 &&
1944 +           bcma_aread32(pcie, BCMA_MIPS_OOBSELINA74) == 0x08060504 &&
1945 +           bcma_aread32(i2s, BCMA_MIPS_OOBSELOUTA30) == 0x88) {
1946 +               bcma_awrite32(cpu, BCMA_MIPS_OOBSELINA74, 0x07060504);
1947 +               bcma_awrite32(pcie, BCMA_MIPS_OOBSELINA74, 0x07060504);
1948 +               bcma_awrite32(i2s, BCMA_MIPS_OOBSELOUTA30, 0x87);
1949 +               bcma_debug(bus,
1950 +                          "Moved i2s interrupt to oob line 7 instead of 8\n");
1951         }
1952  }
1953  
1954 @@ -209,48 +316,59 @@ void bcma_core_mips_init(struct bcma_drv
1955         struct bcma_device *core;
1956         bus = mcore->core->bus;
1957  
1958 -       pr_info("Initializing MIPS core...\n");
1959 +       if (mcore->setup_done)
1960 +               return;
1961  
1962 -       if (!mcore->setup_done)
1963 -               mcore->assigned_irqs = 1;
1964 +       bcma_debug(bus, "Initializing MIPS core...\n");
1965  
1966 -       /* Assign IRQs to all cores on the bus */
1967 -       list_for_each_entry_reverse(core, &bus->cores, list) {
1968 -               int mips_irq;
1969 -               if (core->irq)
1970 -                       continue;
1971 -
1972 -               mips_irq = bcma_core_mips_irq(core);
1973 -               if (mips_irq > 4)
1974 -                       core->irq = 0;
1975 -               else
1976 -                       core->irq = mips_irq + 2;
1977 -               if (core->irq > 5)
1978 -                       continue;
1979 -               switch (core->id.id) {
1980 -               case BCMA_CORE_PCI:
1981 -               case BCMA_CORE_PCIE:
1982 -               case BCMA_CORE_ETHERNET:
1983 -               case BCMA_CORE_ETHERNET_GBIT:
1984 -               case BCMA_CORE_MAC_GBIT:
1985 -               case BCMA_CORE_80211:
1986 -               case BCMA_CORE_USB20_HOST:
1987 -                       /* These devices get their own IRQ line if available,
1988 -                        * the rest goes on IRQ0
1989 -                        */
1990 -                       if (mcore->assigned_irqs <= 4)
1991 -                               bcma_core_mips_set_irq(core,
1992 -                                                      mcore->assigned_irqs++);
1993 -                       break;
1994 +       bcma_core_mips_early_init(mcore);
1995 +
1996 +       bcma_fix_i2s_irqflag(bus);
1997 +
1998 +       switch (bus->chipinfo.id) {
1999 +       case BCMA_CHIP_ID_BCM4716:
2000 +       case BCMA_CHIP_ID_BCM4748:
2001 +               bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
2002 +               bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
2003 +               bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
2004 +               bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_PCIE, 0);
2005 +               bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
2006 +               bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
2007 +               break;
2008 +       case BCMA_CHIP_ID_BCM5356:
2009 +       case BCMA_CHIP_ID_BCM47162:
2010 +       case BCMA_CHIP_ID_BCM53572:
2011 +               bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
2012 +               bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
2013 +               bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
2014 +               break;
2015 +       case BCMA_CHIP_ID_BCM5357:
2016 +       case BCMA_CHIP_ID_BCM4749:
2017 +               bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
2018 +               bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
2019 +               bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
2020 +               bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
2021 +               bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
2022 +               break;
2023 +       case BCMA_CHIP_ID_BCM4706:
2024 +               bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_PCIE, 0);
2025 +               bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_4706_MAC_GBIT,
2026 +                                           0);
2027 +               bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_PCIE, 1);
2028 +               bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_USB20_HOST, 0);
2029 +               bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_4706_CHIPCOMMON,
2030 +                                           0);
2031 +               break;
2032 +       default:
2033 +               list_for_each_entry(core, &bus->cores, list) {
2034 +                       core->irq = bcma_core_irq(core);
2035                 }
2036 +               bcma_err(bus,
2037 +                        "Unknown device (0x%x) found, can not configure IRQs\n",
2038 +                        bus->chipinfo.id);
2039         }
2040 -       pr_info("IRQ reconfiguration done\n");
2041 +       bcma_debug(bus, "IRQ reconfiguration done\n");
2042         bcma_core_mips_dump_irq(bus);
2043  
2044 -       if (mcore->setup_done)
2045 -               return;
2046 -
2047 -       bcma_chipco_serial_init(&bus->drv_cc);
2048 -       bcma_core_mips_flash_detect(mcore);
2049         mcore->setup_done = true;
2050  }
2051 --- a/drivers/bcma/driver_pci.c
2052 +++ b/drivers/bcma/driver_pci.c
2053 @@ -2,8 +2,9 @@
2054   * Broadcom specific AMBA
2055   * PCI Core
2056   *
2057 - * Copyright 2005, Broadcom Corporation
2058 + * Copyright 2005, 2011, Broadcom Corporation
2059   * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
2060 + * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
2061   *
2062   * Licensed under the GNU/GPL. See COPYING for details.
2063   */
2064 @@ -16,120 +17,131 @@
2065   * R/W ops.
2066   **************************************************/
2067  
2068 -static u32 bcma_pcie_read(struct bcma_drv_pci *pc, u32 address)
2069 +u32 bcma_pcie_read(struct bcma_drv_pci *pc, u32 address)
2070  {
2071 -       pcicore_write32(pc, 0x130, address);
2072 -       pcicore_read32(pc, 0x130);
2073 -       return pcicore_read32(pc, 0x134);
2074 +       pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_ADDR, address);
2075 +       pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_ADDR);
2076 +       return pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_DATA);
2077  }
2078  
2079 -#if 0
2080  static void bcma_pcie_write(struct bcma_drv_pci *pc, u32 address, u32 data)
2081  {
2082 -       pcicore_write32(pc, 0x130, address);
2083 -       pcicore_read32(pc, 0x130);
2084 -       pcicore_write32(pc, 0x134, data);
2085 +       pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_ADDR, address);
2086 +       pcicore_read32(pc, BCMA_CORE_PCI_PCIEIND_ADDR);
2087 +       pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_DATA, data);
2088  }
2089 -#endif
2090  
2091 -static void bcma_pcie_mdio_set_phy(struct bcma_drv_pci *pc, u8 phy)
2092 +static void bcma_pcie_mdio_set_phy(struct bcma_drv_pci *pc, u16 phy)
2093  {
2094 -       const u16 mdio_control = 0x128;
2095 -       const u16 mdio_data = 0x12C;
2096         u32 v;
2097         int i;
2098  
2099 -       v = (1 << 30); /* Start of Transaction */
2100 -       v |= (1 << 28); /* Write Transaction */
2101 -       v |= (1 << 17); /* Turnaround */
2102 -       v |= (0x1F << 18);
2103 +       v = BCMA_CORE_PCI_MDIODATA_START;
2104 +       v |= BCMA_CORE_PCI_MDIODATA_WRITE;
2105 +       v |= (BCMA_CORE_PCI_MDIODATA_DEV_ADDR <<
2106 +             BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF);
2107 +       v |= (BCMA_CORE_PCI_MDIODATA_BLK_ADDR <<
2108 +             BCMA_CORE_PCI_MDIODATA_REGADDR_SHF);
2109 +       v |= BCMA_CORE_PCI_MDIODATA_TA;
2110         v |= (phy << 4);
2111 -       pcicore_write32(pc, mdio_data, v);
2112 +       pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v);
2113  
2114         udelay(10);
2115         for (i = 0; i < 200; i++) {
2116 -               v = pcicore_read32(pc, mdio_control);
2117 -               if (v & 0x100 /* Trans complete */)
2118 +               v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL);
2119 +               if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE)
2120                         break;
2121 -               msleep(1);
2122 +               usleep_range(1000, 2000);
2123         }
2124  }
2125  
2126 -static u16 bcma_pcie_mdio_read(struct bcma_drv_pci *pc, u8 device, u8 address)
2127 +static u16 bcma_pcie_mdio_read(struct bcma_drv_pci *pc, u16 device, u8 address)
2128  {
2129 -       const u16 mdio_control = 0x128;
2130 -       const u16 mdio_data = 0x12C;
2131         int max_retries = 10;
2132         u16 ret = 0;
2133         u32 v;
2134         int i;
2135  
2136 -       v = 0x80; /* Enable Preamble Sequence */
2137 -       v |= 0x2; /* MDIO Clock Divisor */
2138 -       pcicore_write32(pc, mdio_control, v);
2139 +       /* enable mdio access to SERDES */
2140 +       v = BCMA_CORE_PCI_MDIOCTL_PREAM_EN;
2141 +       v |= BCMA_CORE_PCI_MDIOCTL_DIVISOR_VAL;
2142 +       pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, v);
2143  
2144         if (pc->core->id.rev >= 10) {
2145                 max_retries = 200;
2146                 bcma_pcie_mdio_set_phy(pc, device);
2147 +               v = (BCMA_CORE_PCI_MDIODATA_DEV_ADDR <<
2148 +                    BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF);
2149 +               v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF);
2150 +       } else {
2151 +               v = (device << BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF_OLD);
2152 +               v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF_OLD);
2153         }
2154  
2155 -       v = (1 << 30); /* Start of Transaction */
2156 -       v |= (1 << 29); /* Read Transaction */
2157 -       v |= (1 << 17); /* Turnaround */
2158 -       if (pc->core->id.rev < 10)
2159 -               v |= (u32)device << 22;
2160 -       v |= (u32)address << 18;
2161 -       pcicore_write32(pc, mdio_data, v);
2162 +       v = BCMA_CORE_PCI_MDIODATA_START;
2163 +       v |= BCMA_CORE_PCI_MDIODATA_READ;
2164 +       v |= BCMA_CORE_PCI_MDIODATA_TA;
2165 +
2166 +       pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v);
2167         /* Wait for the device to complete the transaction */
2168         udelay(10);
2169         for (i = 0; i < max_retries; i++) {
2170 -               v = pcicore_read32(pc, mdio_control);
2171 -               if (v & 0x100 /* Trans complete */) {
2172 +               v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL);
2173 +               if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE) {
2174                         udelay(10);
2175 -                       ret = pcicore_read32(pc, mdio_data);
2176 +                       ret = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_DATA);
2177                         break;
2178                 }
2179 -               msleep(1);
2180 +               usleep_range(1000, 2000);
2181         }
2182 -       pcicore_write32(pc, mdio_control, 0);
2183 +       pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, 0);
2184         return ret;
2185  }
2186  
2187 -static void bcma_pcie_mdio_write(struct bcma_drv_pci *pc, u8 device,
2188 +static void bcma_pcie_mdio_write(struct bcma_drv_pci *pc, u16 device,
2189                                 u8 address, u16 data)
2190  {
2191 -       const u16 mdio_control = 0x128;
2192 -       const u16 mdio_data = 0x12C;
2193         int max_retries = 10;
2194         u32 v;
2195         int i;
2196  
2197 -       v = 0x80; /* Enable Preamble Sequence */
2198 -       v |= 0x2; /* MDIO Clock Divisor */
2199 -       pcicore_write32(pc, mdio_control, v);
2200 +       /* enable mdio access to SERDES */
2201 +       v = BCMA_CORE_PCI_MDIOCTL_PREAM_EN;
2202 +       v |= BCMA_CORE_PCI_MDIOCTL_DIVISOR_VAL;
2203 +       pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, v);
2204  
2205         if (pc->core->id.rev >= 10) {
2206                 max_retries = 200;
2207                 bcma_pcie_mdio_set_phy(pc, device);
2208 +               v = (BCMA_CORE_PCI_MDIODATA_DEV_ADDR <<
2209 +                    BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF);
2210 +               v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF);
2211 +       } else {
2212 +               v = (device << BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF_OLD);
2213 +               v |= (address << BCMA_CORE_PCI_MDIODATA_REGADDR_SHF_OLD);
2214         }
2215  
2216 -       v = (1 << 30); /* Start of Transaction */
2217 -       v |= (1 << 28); /* Write Transaction */
2218 -       v |= (1 << 17); /* Turnaround */
2219 -       if (pc->core->id.rev < 10)
2220 -               v |= (u32)device << 22;
2221 -       v |= (u32)address << 18;
2222 +       v = BCMA_CORE_PCI_MDIODATA_START;
2223 +       v |= BCMA_CORE_PCI_MDIODATA_WRITE;
2224 +       v |= BCMA_CORE_PCI_MDIODATA_TA;
2225         v |= data;
2226 -       pcicore_write32(pc, mdio_data, v);
2227 +       pcicore_write32(pc, BCMA_CORE_PCI_MDIO_DATA, v);
2228         /* Wait for the device to complete the transaction */
2229         udelay(10);
2230         for (i = 0; i < max_retries; i++) {
2231 -               v = pcicore_read32(pc, mdio_control);
2232 -               if (v & 0x100 /* Trans complete */)
2233 +               v = pcicore_read32(pc, BCMA_CORE_PCI_MDIO_CONTROL);
2234 +               if (v & BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE)
2235                         break;
2236 -               msleep(1);
2237 +               usleep_range(1000, 2000);
2238         }
2239 -       pcicore_write32(pc, mdio_control, 0);
2240 +       pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, 0);
2241 +}
2242 +
2243 +static u16 bcma_pcie_mdio_writeread(struct bcma_drv_pci *pc, u16 device,
2244 +                                   u8 address, u16 data)
2245 +{
2246 +       bcma_pcie_mdio_write(pc, device, address, data);
2247 +       return bcma_pcie_mdio_read(pc, device, address);
2248  }
2249  
2250  /**************************************************
2251 @@ -138,88 +150,134 @@ static void bcma_pcie_mdio_write(struct
2252  
2253  static u8 bcma_pcicore_polarity_workaround(struct bcma_drv_pci *pc)
2254  {
2255 -       return (bcma_pcie_read(pc, 0x204) & 0x10) ? 0xC0 : 0x80;
2256 +       u32 tmp;
2257 +
2258 +       tmp = bcma_pcie_read(pc, BCMA_CORE_PCI_PLP_STATUSREG);
2259 +       if (tmp & BCMA_CORE_PCI_PLP_POLARITYINV_STAT)
2260 +               return BCMA_CORE_PCI_SERDES_RX_CTRL_FORCE |
2261 +                      BCMA_CORE_PCI_SERDES_RX_CTRL_POLARITY;
2262 +       else
2263 +               return BCMA_CORE_PCI_SERDES_RX_CTRL_FORCE;
2264  }
2265  
2266  static void bcma_pcicore_serdes_workaround(struct bcma_drv_pci *pc)
2267  {
2268 -       const u8 serdes_pll_device = 0x1D;
2269 -       const u8 serdes_rx_device = 0x1F;
2270         u16 tmp;
2271  
2272 -       bcma_pcie_mdio_write(pc, serdes_rx_device, 1 /* Control */,
2273 -                             bcma_pcicore_polarity_workaround(pc));
2274 -       tmp = bcma_pcie_mdio_read(pc, serdes_pll_device, 1 /* Control */);
2275 -       if (tmp & 0x4000)
2276 -               bcma_pcie_mdio_write(pc, serdes_pll_device, 1, tmp & ~0x4000);
2277 +       bcma_pcie_mdio_write(pc, BCMA_CORE_PCI_MDIODATA_DEV_RX,
2278 +                            BCMA_CORE_PCI_SERDES_RX_CTRL,
2279 +                            bcma_pcicore_polarity_workaround(pc));
2280 +       tmp = bcma_pcie_mdio_read(pc, BCMA_CORE_PCI_MDIODATA_DEV_PLL,
2281 +                                 BCMA_CORE_PCI_SERDES_PLL_CTRL);
2282 +       if (tmp & BCMA_CORE_PCI_PLL_CTRL_FREQDET_EN)
2283 +               bcma_pcie_mdio_write(pc, BCMA_CORE_PCI_MDIODATA_DEV_PLL,
2284 +                                    BCMA_CORE_PCI_SERDES_PLL_CTRL,
2285 +                                    tmp & ~BCMA_CORE_PCI_PLL_CTRL_FREQDET_EN);
2286 +}
2287 +
2288 +static void bcma_core_pci_fixcfg(struct bcma_drv_pci *pc)
2289 +{
2290 +       struct bcma_device *core = pc->core;
2291 +       u16 val16, core_index;
2292 +       uint regoff;
2293 +
2294 +       regoff = BCMA_CORE_PCI_SPROM(BCMA_CORE_PCI_SPROM_PI_OFFSET);
2295 +       core_index = (u16)core->core_index;
2296 +
2297 +       val16 = pcicore_read16(pc, regoff);
2298 +       if (((val16 & BCMA_CORE_PCI_SPROM_PI_MASK) >> BCMA_CORE_PCI_SPROM_PI_SHIFT)
2299 +            != core_index) {
2300 +               val16 = (core_index << BCMA_CORE_PCI_SPROM_PI_SHIFT) |
2301 +                       (val16 & ~BCMA_CORE_PCI_SPROM_PI_MASK);
2302 +               pcicore_write16(pc, regoff, val16);
2303 +       }
2304 +}
2305 +
2306 +/* Fix MISC config to allow coming out of L2/L3-Ready state w/o PRST */
2307 +/* Needs to happen when coming out of 'standby'/'hibernate' */
2308 +static void bcma_core_pci_config_fixup(struct bcma_drv_pci *pc)
2309 +{
2310 +       u16 val16;
2311 +       uint regoff;
2312 +
2313 +       regoff = BCMA_CORE_PCI_SPROM(BCMA_CORE_PCI_SPROM_MISC_CONFIG);
2314 +
2315 +       val16 = pcicore_read16(pc, regoff);
2316 +
2317 +       if (!(val16 & BCMA_CORE_PCI_SPROM_L23READY_EXIT_NOPERST)) {
2318 +               val16 |= BCMA_CORE_PCI_SPROM_L23READY_EXIT_NOPERST;
2319 +               pcicore_write16(pc, regoff, val16);
2320 +       }
2321  }
2322  
2323  /**************************************************
2324   * Init.
2325   **************************************************/
2326  
2327 -static void bcma_core_pci_clientmode_init(struct bcma_drv_pci *pc)
2328 +static void __devinit bcma_core_pci_clientmode_init(struct bcma_drv_pci *pc)
2329  {
2330 +       bcma_core_pci_fixcfg(pc);
2331         bcma_pcicore_serdes_workaround(pc);
2332 +       bcma_core_pci_config_fixup(pc);
2333  }
2334  
2335 -static bool bcma_core_pci_is_in_hostmode(struct bcma_drv_pci *pc)
2336 -{
2337 -       struct bcma_bus *bus = pc->core->bus;
2338 -       u16 chipid_top;
2339 -
2340 -       chipid_top = (bus->chipinfo.id & 0xFF00);
2341 -       if (chipid_top != 0x4700 &&
2342 -           chipid_top != 0x5300)
2343 -               return false;
2344 -
2345 -#ifdef CONFIG_SSB_DRIVER_PCICORE
2346 -       if (bus->sprom.boardflags_lo & SSB_BFL_NOPCI)
2347 -               return false;
2348 -#endif /* CONFIG_SSB_DRIVER_PCICORE */
2349 -
2350 -#if 0
2351 -       /* TODO: on BCMA we use address from EROM instead of magic formula */
2352 -       u32 tmp;
2353 -       return !mips_busprobe32(tmp, (bus->mmio +
2354 -               (pc->core->core_index * BCMA_CORE_SIZE)));
2355 -#endif
2356 -
2357 -       return true;
2358 -}
2359 -
2360 -void bcma_core_pci_init(struct bcma_drv_pci *pc)
2361 +void __devinit bcma_core_pci_init(struct bcma_drv_pci *pc)
2362  {
2363         if (pc->setup_done)
2364                 return;
2365  
2366 -       if (bcma_core_pci_is_in_hostmode(pc)) {
2367  #ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE
2368 +       pc->hostmode = bcma_core_pci_is_in_hostmode(pc);
2369 +       if (pc->hostmode)
2370                 bcma_core_pci_hostmode_init(pc);
2371 -#else
2372 -               pr_err("Driver compiled without support for hostmode PCI\n");
2373  #endif /* CONFIG_BCMA_DRIVER_PCI_HOSTMODE */
2374 -       } else {
2375 +
2376 +       if (!pc->hostmode)
2377                 bcma_core_pci_clientmode_init(pc);
2378 -       }
2379 +}
2380 +
2381 +void bcma_core_pci_power_save(struct bcma_bus *bus, bool up)
2382 +{
2383 +       struct bcma_drv_pci *pc;
2384 +       u16 data;
2385  
2386 -       pc->setup_done = true;
2387 +       if (bus->hosttype != BCMA_HOSTTYPE_PCI)
2388 +               return;
2389 +
2390 +       pc = &bus->drv_pci[0];
2391 +
2392 +       if (pc->core->id.rev >= 15 && pc->core->id.rev <= 20) {
2393 +               data = up ? 0x74 : 0x7C;
2394 +               bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
2395 +                                        BCMA_CORE_PCI_MDIO_BLK1_MGMT1, 0x7F64);
2396 +               bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
2397 +                                        BCMA_CORE_PCI_MDIO_BLK1_MGMT3, data);
2398 +       } else if (pc->core->id.rev >= 21 && pc->core->id.rev <= 22) {
2399 +               data = up ? 0x75 : 0x7D;
2400 +               bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
2401 +                                        BCMA_CORE_PCI_MDIO_BLK1_MGMT1, 0x7E65);
2402 +               bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
2403 +                                        BCMA_CORE_PCI_MDIO_BLK1_MGMT3, data);
2404 +       }
2405  }
2406 +EXPORT_SYMBOL_GPL(bcma_core_pci_power_save);
2407  
2408  int bcma_core_pci_irq_ctl(struct bcma_drv_pci *pc, struct bcma_device *core,
2409                           bool enable)
2410  {
2411 -       struct pci_dev *pdev = pc->core->bus->host_pci;
2412 +       struct pci_dev *pdev;
2413         u32 coremask, tmp;
2414         int err = 0;
2415  
2416 -       if (core->bus->hosttype != BCMA_HOSTTYPE_PCI) {
2417 +       if (!pc || core->bus->hosttype != BCMA_HOSTTYPE_PCI) {
2418                 /* This bcma device is not on a PCI host-bus. So the IRQs are
2419                  * not routed through the PCI core.
2420                  * So we must not enable routing through the PCI core. */
2421                 goto out;
2422         }
2423  
2424 +       pdev = pc->core->bus->host_pci;
2425 +
2426         err = pci_read_config_dword(pdev, BCMA_PCI_IRQMASK, &tmp);
2427         if (err)
2428                 goto out;
2429 @@ -236,3 +294,42 @@ out:
2430         return err;
2431  }
2432  EXPORT_SYMBOL_GPL(bcma_core_pci_irq_ctl);
2433 +
2434 +static void bcma_core_pci_extend_L1timer(struct bcma_drv_pci *pc, bool extend)
2435 +{
2436 +       u32 w;
2437 +
2438 +       w = bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG);
2439 +       if (extend)
2440 +               w |= BCMA_CORE_PCI_ASPMTIMER_EXTEND;
2441 +       else
2442 +               w &= ~BCMA_CORE_PCI_ASPMTIMER_EXTEND;
2443 +       bcma_pcie_write(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG, w);
2444 +       bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG);
2445 +}
2446 +
2447 +void bcma_core_pci_up(struct bcma_bus *bus)
2448 +{
2449 +       struct bcma_drv_pci *pc;
2450 +
2451 +       if (bus->hosttype != BCMA_HOSTTYPE_PCI)
2452 +               return;
2453 +
2454 +       pc = &bus->drv_pci[0];
2455 +
2456 +       bcma_core_pci_extend_L1timer(pc, true);
2457 +}
2458 +EXPORT_SYMBOL_GPL(bcma_core_pci_up);
2459 +
2460 +void bcma_core_pci_down(struct bcma_bus *bus)
2461 +{
2462 +       struct bcma_drv_pci *pc;
2463 +
2464 +       if (bus->hosttype != BCMA_HOSTTYPE_PCI)
2465 +               return;
2466 +
2467 +       pc = &bus->drv_pci[0];
2468 +
2469 +       bcma_core_pci_extend_L1timer(pc, false);
2470 +}
2471 +EXPORT_SYMBOL_GPL(bcma_core_pci_down);
2472 --- a/drivers/bcma/driver_pci_host.c
2473 +++ b/drivers/bcma/driver_pci_host.c
2474 @@ -2,13 +2,622 @@
2475   * Broadcom specific AMBA
2476   * PCI Core in hostmode
2477   *
2478 + * Copyright 2005 - 2011, Broadcom Corporation
2479 + * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
2480 + * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
2481 + *
2482   * Licensed under the GNU/GPL. See COPYING for details.
2483   */
2484  
2485  #include "bcma_private.h"
2486 +#include <linux/pci.h>
2487 +#include <linux/export.h>
2488  #include <linux/bcma/bcma.h>
2489 +#include <asm/paccess.h>
2490 +
2491 +/* Probe a 32bit value on the bus and catch bus exceptions.
2492 + * Returns nonzero on a bus exception.
2493 + * This is MIPS specific */
2494 +#define mips_busprobe32(val, addr)     get_dbe((val), ((u32 *)(addr)))
2495 +
2496 +/* Assume one-hot slot wiring */
2497 +#define BCMA_PCI_SLOT_MAX      16
2498 +#define        PCI_CONFIG_SPACE_SIZE   256
2499 +
2500 +bool __devinit bcma_core_pci_is_in_hostmode(struct bcma_drv_pci *pc)
2501 +{
2502 +       struct bcma_bus *bus = pc->core->bus;
2503 +       u16 chipid_top;
2504 +       u32 tmp;
2505 +
2506 +       chipid_top = (bus->chipinfo.id & 0xFF00);
2507 +       if (chipid_top != 0x4700 &&
2508 +           chipid_top != 0x5300)
2509 +               return false;
2510 +
2511 +       bcma_core_enable(pc->core, 0);
2512 +
2513 +       return !mips_busprobe32(tmp, pc->core->io_addr);
2514 +}
2515 +
2516 +static u32 bcma_pcie_read_config(struct bcma_drv_pci *pc, u32 address)
2517 +{
2518 +       pcicore_write32(pc, BCMA_CORE_PCI_CONFIG_ADDR, address);
2519 +       pcicore_read32(pc, BCMA_CORE_PCI_CONFIG_ADDR);
2520 +       return pcicore_read32(pc, BCMA_CORE_PCI_CONFIG_DATA);
2521 +}
2522 +
2523 +static void bcma_pcie_write_config(struct bcma_drv_pci *pc, u32 address,
2524 +                                  u32 data)
2525 +{
2526 +       pcicore_write32(pc, BCMA_CORE_PCI_CONFIG_ADDR, address);
2527 +       pcicore_read32(pc, BCMA_CORE_PCI_CONFIG_ADDR);
2528 +       pcicore_write32(pc, BCMA_CORE_PCI_CONFIG_DATA, data);
2529 +}
2530 +
2531 +static u32 bcma_get_cfgspace_addr(struct bcma_drv_pci *pc, unsigned int dev,
2532 +                            unsigned int func, unsigned int off)
2533 +{
2534 +       u32 addr = 0;
2535 +
2536 +       /* Issue config commands only when the data link is up (atleast
2537 +        * one external pcie device is present).
2538 +        */
2539 +       if (dev >= 2 || !(bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_LSREG)
2540 +                         & BCMA_CORE_PCI_DLLP_LSREG_LINKUP))
2541 +               goto out;
2542 +
2543 +       /* Type 0 transaction */
2544 +       /* Slide the PCI window to the appropriate slot */
2545 +       pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI1, BCMA_CORE_PCI_SBTOPCI_CFG0);
2546 +       /* Calculate the address */
2547 +       addr = pc->host_controller->host_cfg_addr;
2548 +       addr |= (dev << BCMA_CORE_PCI_CFG_SLOT_SHIFT);
2549 +       addr |= (func << BCMA_CORE_PCI_CFG_FUN_SHIFT);
2550 +       addr |= (off & ~3);
2551 +
2552 +out:
2553 +       return addr;
2554 +}
2555 +
2556 +static int bcma_extpci_read_config(struct bcma_drv_pci *pc, unsigned int dev,
2557 +                                 unsigned int func, unsigned int off,
2558 +                                 void *buf, int len)
2559 +{
2560 +       int err = -EINVAL;
2561 +       u32 addr, val;
2562 +       void __iomem *mmio = 0;
2563 +
2564 +       WARN_ON(!pc->hostmode);
2565 +       if (unlikely(len != 1 && len != 2 && len != 4))
2566 +               goto out;
2567 +       if (dev == 0) {
2568 +               /* we support only two functions on device 0 */
2569 +               if (func > 1)
2570 +                       goto out;
2571 +
2572 +               /* accesses to config registers with offsets >= 256
2573 +                * requires indirect access.
2574 +                */
2575 +               if (off >= PCI_CONFIG_SPACE_SIZE) {
2576 +                       addr = (func << 12);
2577 +                       addr |= (off & 0x0FFC);
2578 +                       val = bcma_pcie_read_config(pc, addr);
2579 +               } else {
2580 +                       addr = BCMA_CORE_PCI_PCICFG0;
2581 +                       addr |= (func << 8);
2582 +                       addr |= (off & 0xFC);
2583 +                       val = pcicore_read32(pc, addr);
2584 +               }
2585 +       } else {
2586 +               addr = bcma_get_cfgspace_addr(pc, dev, func, off);
2587 +               if (unlikely(!addr))
2588 +                       goto out;
2589 +               err = -ENOMEM;
2590 +               mmio = ioremap_nocache(addr, sizeof(val));
2591 +               if (!mmio)
2592 +                       goto out;
2593 +
2594 +               if (mips_busprobe32(val, mmio)) {
2595 +                       val = 0xFFFFFFFF;
2596 +                       goto unmap;
2597 +               }
2598 +       }
2599 +       val >>= (8 * (off & 3));
2600 +
2601 +       switch (len) {
2602 +       case 1:
2603 +               *((u8 *)buf) = (u8)val;
2604 +               break;
2605 +       case 2:
2606 +               *((u16 *)buf) = (u16)val;
2607 +               break;
2608 +       case 4:
2609 +               *((u32 *)buf) = (u32)val;
2610 +               break;
2611 +       }
2612 +       err = 0;
2613 +unmap:
2614 +       if (mmio)
2615 +               iounmap(mmio);
2616 +out:
2617 +       return err;
2618 +}
2619  
2620 -void bcma_core_pci_hostmode_init(struct bcma_drv_pci *pc)
2621 +static int bcma_extpci_write_config(struct bcma_drv_pci *pc, unsigned int dev,
2622 +                                  unsigned int func, unsigned int off,
2623 +                                  const void *buf, int len)
2624  {
2625 -       pr_err("No support for PCI core in hostmode yet\n");
2626 +       int err = -EINVAL;
2627 +       u32 addr, val;
2628 +       void __iomem *mmio = 0;
2629 +       u16 chipid = pc->core->bus->chipinfo.id;
2630 +
2631 +       WARN_ON(!pc->hostmode);
2632 +       if (unlikely(len != 1 && len != 2 && len != 4))
2633 +               goto out;
2634 +       if (dev == 0) {
2635 +               /* we support only two functions on device 0 */
2636 +               if (func > 1)
2637 +                       goto out;
2638 +
2639 +               /* accesses to config registers with offsets >= 256
2640 +                * requires indirect access.
2641 +                */
2642 +               if (off >= PCI_CONFIG_SPACE_SIZE) {
2643 +                       addr = (func << 12);
2644 +                       addr |= (off & 0x0FFC);
2645 +                       val = bcma_pcie_read_config(pc, addr);
2646 +               } else {
2647 +                       addr = BCMA_CORE_PCI_PCICFG0;
2648 +                       addr |= (func << 8);
2649 +                       addr |= (off & 0xFC);
2650 +                       val = pcicore_read32(pc, addr);
2651 +               }
2652 +       } else {
2653 +               addr = bcma_get_cfgspace_addr(pc, dev, func, off);
2654 +               if (unlikely(!addr))
2655 +                       goto out;
2656 +               err = -ENOMEM;
2657 +               mmio = ioremap_nocache(addr, sizeof(val));
2658 +               if (!mmio)
2659 +                       goto out;
2660 +
2661 +               if (mips_busprobe32(val, mmio)) {
2662 +                       val = 0xFFFFFFFF;
2663 +                       goto unmap;
2664 +               }
2665 +       }
2666 +
2667 +       switch (len) {
2668 +       case 1:
2669 +               val &= ~(0xFF << (8 * (off & 3)));
2670 +               val |= *((const u8 *)buf) << (8 * (off & 3));
2671 +               break;
2672 +       case 2:
2673 +               val &= ~(0xFFFF << (8 * (off & 3)));
2674 +               val |= *((const u16 *)buf) << (8 * (off & 3));
2675 +               break;
2676 +       case 4:
2677 +               val = *((const u32 *)buf);
2678 +               break;
2679 +       }
2680 +       if (dev == 0) {
2681 +               /* accesses to config registers with offsets >= 256
2682 +                * requires indirect access.
2683 +                */
2684 +               if (off >= PCI_CONFIG_SPACE_SIZE)
2685 +                       bcma_pcie_write_config(pc, addr, val);
2686 +               else
2687 +                       pcicore_write32(pc, addr, val);
2688 +       } else {
2689 +               writel(val, mmio);
2690 +
2691 +               if (chipid == BCMA_CHIP_ID_BCM4716 ||
2692 +                   chipid == BCMA_CHIP_ID_BCM4748)
2693 +                       readl(mmio);
2694 +       }
2695 +
2696 +       err = 0;
2697 +unmap:
2698 +       if (mmio)
2699 +               iounmap(mmio);
2700 +out:
2701 +       return err;
2702 +}
2703 +
2704 +static int bcma_core_pci_hostmode_read_config(struct pci_bus *bus,
2705 +                                             unsigned int devfn,
2706 +                                             int reg, int size, u32 *val)
2707 +{
2708 +       unsigned long flags;
2709 +       int err;
2710 +       struct bcma_drv_pci *pc;
2711 +       struct bcma_drv_pci_host *pc_host;
2712 +
2713 +       pc_host = container_of(bus->ops, struct bcma_drv_pci_host, pci_ops);
2714 +       pc = pc_host->pdev;
2715 +
2716 +       spin_lock_irqsave(&pc_host->cfgspace_lock, flags);
2717 +       err = bcma_extpci_read_config(pc, PCI_SLOT(devfn),
2718 +                                    PCI_FUNC(devfn), reg, val, size);
2719 +       spin_unlock_irqrestore(&pc_host->cfgspace_lock, flags);
2720 +
2721 +       return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
2722 +}
2723 +
2724 +static int bcma_core_pci_hostmode_write_config(struct pci_bus *bus,
2725 +                                              unsigned int devfn,
2726 +                                              int reg, int size, u32 val)
2727 +{
2728 +       unsigned long flags;
2729 +       int err;
2730 +       struct bcma_drv_pci *pc;
2731 +       struct bcma_drv_pci_host *pc_host;
2732 +
2733 +       pc_host = container_of(bus->ops, struct bcma_drv_pci_host, pci_ops);
2734 +       pc = pc_host->pdev;
2735 +
2736 +       spin_lock_irqsave(&pc_host->cfgspace_lock, flags);
2737 +       err = bcma_extpci_write_config(pc, PCI_SLOT(devfn),
2738 +                                     PCI_FUNC(devfn), reg, &val, size);
2739 +       spin_unlock_irqrestore(&pc_host->cfgspace_lock, flags);
2740 +
2741 +       return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
2742 +}
2743 +
2744 +/* return cap_offset if requested capability exists in the PCI config space */
2745 +static u8 __devinit bcma_find_pci_capability(struct bcma_drv_pci *pc,
2746 +                                            unsigned int dev,
2747 +                                            unsigned int func, u8 req_cap_id,
2748 +                                            unsigned char *buf, u32 *buflen)
2749 +{
2750 +       u8 cap_id;
2751 +       u8 cap_ptr = 0;
2752 +       u32 bufsize;
2753 +       u8 byte_val;
2754 +
2755 +       /* check for Header type 0 */
2756 +       bcma_extpci_read_config(pc, dev, func, PCI_HEADER_TYPE, &byte_val,
2757 +                               sizeof(u8));
2758 +       if ((byte_val & 0x7F) != PCI_HEADER_TYPE_NORMAL)
2759 +               return cap_ptr;
2760 +
2761 +       /* check if the capability pointer field exists */
2762 +       bcma_extpci_read_config(pc, dev, func, PCI_STATUS, &byte_val,
2763 +                               sizeof(u8));
2764 +       if (!(byte_val & PCI_STATUS_CAP_LIST))
2765 +               return cap_ptr;
2766 +
2767 +       /* check if the capability pointer is 0x00 */
2768 +       bcma_extpci_read_config(pc, dev, func, PCI_CAPABILITY_LIST, &cap_ptr,
2769 +                               sizeof(u8));
2770 +       if (cap_ptr == 0x00)
2771 +               return cap_ptr;
2772 +
2773 +       /* loop thr'u the capability list and see if the requested capabilty
2774 +        * exists */
2775 +       bcma_extpci_read_config(pc, dev, func, cap_ptr, &cap_id, sizeof(u8));
2776 +       while (cap_id != req_cap_id) {
2777 +               bcma_extpci_read_config(pc, dev, func, cap_ptr + 1, &cap_ptr,
2778 +                                       sizeof(u8));
2779 +               if (cap_ptr == 0x00)
2780 +                       return cap_ptr;
2781 +               bcma_extpci_read_config(pc, dev, func, cap_ptr, &cap_id,
2782 +                                       sizeof(u8));
2783 +       }
2784 +
2785 +       /* found the caller requested capability */
2786 +       if ((buf != NULL) && (buflen != NULL)) {
2787 +               u8 cap_data;
2788 +
2789 +               bufsize = *buflen;
2790 +               if (!bufsize)
2791 +                       return cap_ptr;
2792 +
2793 +               *buflen = 0;
2794 +
2795 +               /* copy the cpability data excluding cap ID and next ptr */
2796 +               cap_data = cap_ptr + 2;
2797 +               if ((bufsize + cap_data)  > PCI_CONFIG_SPACE_SIZE)
2798 +                       bufsize = PCI_CONFIG_SPACE_SIZE - cap_data;
2799 +               *buflen = bufsize;
2800 +               while (bufsize--) {
2801 +                       bcma_extpci_read_config(pc, dev, func, cap_data, buf,
2802 +                                               sizeof(u8));
2803 +                       cap_data++;
2804 +                       buf++;
2805 +               }
2806 +       }
2807 +
2808 +       return cap_ptr;
2809 +}
2810 +
2811 +/* If the root port is capable of returning Config Request
2812 + * Retry Status (CRS) Completion Status to software then
2813 + * enable the feature.
2814 + */
2815 +static void __devinit bcma_core_pci_enable_crs(struct bcma_drv_pci *pc)
2816 +{
2817 +       struct bcma_bus *bus = pc->core->bus;
2818 +       u8 cap_ptr, root_ctrl, root_cap, dev;
2819 +       u16 val16;
2820 +       int i;
2821 +
2822 +       cap_ptr = bcma_find_pci_capability(pc, 0, 0, PCI_CAP_ID_EXP, NULL,
2823 +                                          NULL);
2824 +       root_cap = cap_ptr + PCI_EXP_RTCAP;
2825 +       bcma_extpci_read_config(pc, 0, 0, root_cap, &val16, sizeof(u16));
2826 +       if (val16 & BCMA_CORE_PCI_RC_CRS_VISIBILITY) {
2827 +               /* Enable CRS software visibility */
2828 +               root_ctrl = cap_ptr + PCI_EXP_RTCTL;
2829 +               val16 = PCI_EXP_RTCTL_CRSSVE;
2830 +               bcma_extpci_read_config(pc, 0, 0, root_ctrl, &val16,
2831 +                                       sizeof(u16));
2832 +
2833 +               /* Initiate a configuration request to read the vendor id
2834 +                * field of the device function's config space header after
2835 +                * 100 ms wait time from the end of Reset. If the device is
2836 +                * not done with its internal initialization, it must at
2837 +                * least return a completion TLP, with a completion status
2838 +                * of "Configuration Request Retry Status (CRS)". The root
2839 +                * complex must complete the request to the host by returning
2840 +                * a read-data value of 0001h for the Vendor ID field and
2841 +                * all 1s for any additional bytes included in the request.
2842 +                * Poll using the config reads for max wait time of 1 sec or
2843 +                * until we receive the successful completion status. Repeat
2844 +                * the procedure for all the devices.
2845 +                */
2846 +               for (dev = 1; dev < BCMA_PCI_SLOT_MAX; dev++) {
2847 +                       for (i = 0; i < 100000; i++) {
2848 +                               bcma_extpci_read_config(pc, dev, 0,
2849 +                                                       PCI_VENDOR_ID, &val16,
2850 +                                                       sizeof(val16));
2851 +                               if (val16 != 0x1)
2852 +                                       break;
2853 +                               udelay(10);
2854 +                       }
2855 +                       if (val16 == 0x1)
2856 +                               bcma_err(bus, "PCI: Broken device in slot %d\n",
2857 +                                        dev);
2858 +               }
2859 +       }
2860 +}
2861 +
2862 +void __devinit bcma_core_pci_hostmode_init(struct bcma_drv_pci *pc)
2863 +{
2864 +       struct bcma_bus *bus = pc->core->bus;
2865 +       struct bcma_drv_pci_host *pc_host;
2866 +       u32 tmp;
2867 +       u32 pci_membase_1G;
2868 +       unsigned long io_map_base;
2869 +
2870 +       bcma_info(bus, "PCIEcore in host mode found\n");
2871 +
2872 +       if (bus->sprom.boardflags_lo & BCMA_CORE_PCI_BFL_NOPCI) {
2873 +               bcma_info(bus, "This PCIE core is disabled and not working\n");
2874 +               return;
2875 +       }
2876 +
2877 +       pc_host = kzalloc(sizeof(*pc_host), GFP_KERNEL);
2878 +       if (!pc_host)  {
2879 +               bcma_err(bus, "can not allocate memory");
2880 +               return;
2881 +       }
2882 +
2883 +       spin_lock_init(&pc_host->cfgspace_lock);
2884 +
2885 +       pc->host_controller = pc_host;
2886 +       pc_host->pci_controller.io_resource = &pc_host->io_resource;
2887 +       pc_host->pci_controller.mem_resource = &pc_host->mem_resource;
2888 +       pc_host->pci_controller.pci_ops = &pc_host->pci_ops;
2889 +       pc_host->pdev = pc;
2890 +
2891 +       pci_membase_1G = BCMA_SOC_PCI_DMA;
2892 +       pc_host->host_cfg_addr = BCMA_SOC_PCI_CFG;
2893 +
2894 +       pc_host->pci_ops.read = bcma_core_pci_hostmode_read_config;
2895 +       pc_host->pci_ops.write = bcma_core_pci_hostmode_write_config;
2896 +
2897 +       pc_host->mem_resource.name = "BCMA PCIcore external memory",
2898 +       pc_host->mem_resource.start = BCMA_SOC_PCI_DMA;
2899 +       pc_host->mem_resource.end = BCMA_SOC_PCI_DMA + BCMA_SOC_PCI_DMA_SZ - 1;
2900 +       pc_host->mem_resource.flags = IORESOURCE_MEM | IORESOURCE_PCI_FIXED;
2901 +
2902 +       pc_host->io_resource.name = "BCMA PCIcore external I/O",
2903 +       pc_host->io_resource.start = 0x100;
2904 +       pc_host->io_resource.end = 0x7FF;
2905 +       pc_host->io_resource.flags = IORESOURCE_IO | IORESOURCE_PCI_FIXED;
2906 +
2907 +       /* Reset RC */
2908 +       usleep_range(3000, 5000);
2909 +       pcicore_write32(pc, BCMA_CORE_PCI_CTL, BCMA_CORE_PCI_CTL_RST_OE);
2910 +       msleep(50);
2911 +       pcicore_write32(pc, BCMA_CORE_PCI_CTL, BCMA_CORE_PCI_CTL_RST |
2912 +                       BCMA_CORE_PCI_CTL_RST_OE);
2913 +
2914 +       /* 64 MB I/O access window. On 4716, use
2915 +        * sbtopcie0 to access the device registers. We
2916 +        * can't use address match 2 (1 GB window) region
2917 +        * as mips can't generate 64-bit address on the
2918 +        * backplane.
2919 +        */
2920 +       if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4716 ||
2921 +           bus->chipinfo.id == BCMA_CHIP_ID_BCM4748) {
2922 +               pc_host->mem_resource.start = BCMA_SOC_PCI_MEM;
2923 +               pc_host->mem_resource.end = BCMA_SOC_PCI_MEM +
2924 +                                           BCMA_SOC_PCI_MEM_SZ - 1;
2925 +               pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI0,
2926 +                               BCMA_CORE_PCI_SBTOPCI_MEM | BCMA_SOC_PCI_MEM);
2927 +       } else if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
2928 +               tmp = BCMA_CORE_PCI_SBTOPCI_MEM;
2929 +               tmp |= BCMA_CORE_PCI_SBTOPCI_PREF;
2930 +               tmp |= BCMA_CORE_PCI_SBTOPCI_BURST;
2931 +               if (pc->core->core_unit == 0) {
2932 +                       pc_host->mem_resource.start = BCMA_SOC_PCI_MEM;
2933 +                       pc_host->mem_resource.end = BCMA_SOC_PCI_MEM +
2934 +                                                   BCMA_SOC_PCI_MEM_SZ - 1;
2935 +                       pc_host->io_resource.start = 0x100;
2936 +                       pc_host->io_resource.end = 0x47F;
2937 +                       pci_membase_1G = BCMA_SOC_PCIE_DMA_H32;
2938 +                       pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI0,
2939 +                                       tmp | BCMA_SOC_PCI_MEM);
2940 +               } else if (pc->core->core_unit == 1) {
2941 +                       pc_host->mem_resource.start = BCMA_SOC_PCI1_MEM;
2942 +                       pc_host->mem_resource.end = BCMA_SOC_PCI1_MEM +
2943 +                                                   BCMA_SOC_PCI_MEM_SZ - 1;
2944 +                       pc_host->io_resource.start = 0x480;
2945 +                       pc_host->io_resource.end = 0x7FF;
2946 +                       pci_membase_1G = BCMA_SOC_PCIE1_DMA_H32;
2947 +                       pc_host->host_cfg_addr = BCMA_SOC_PCI1_CFG;
2948 +                       pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI0,
2949 +                                       tmp | BCMA_SOC_PCI1_MEM);
2950 +               }
2951 +       } else
2952 +               pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI0,
2953 +                               BCMA_CORE_PCI_SBTOPCI_IO);
2954 +
2955 +       /* 64 MB configuration access window */
2956 +       pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI1, BCMA_CORE_PCI_SBTOPCI_CFG0);
2957 +
2958 +       /* 1 GB memory access window */
2959 +       pcicore_write32(pc, BCMA_CORE_PCI_SBTOPCI2,
2960 +                       BCMA_CORE_PCI_SBTOPCI_MEM | pci_membase_1G);
2961 +
2962 +
2963 +       /* As per PCI Express Base Spec 1.1 we need to wait for
2964 +        * at least 100 ms from the end of a reset (cold/warm/hot)
2965 +        * before issuing configuration requests to PCI Express
2966 +        * devices.
2967 +        */
2968 +       msleep(100);
2969 +
2970 +       bcma_core_pci_enable_crs(pc);
2971 +
2972 +       if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706 ||
2973 +           bus->chipinfo.id == BCMA_CHIP_ID_BCM4716) {
2974 +               u16 val16;
2975 +               bcma_extpci_read_config(pc, 0, 0, BCMA_CORE_PCI_CFG_DEVCTRL,
2976 +                                       &val16, sizeof(val16));
2977 +               val16 |= (2 << 5);      /* Max payload size of 512 */
2978 +               val16 |= (2 << 12);     /* MRRS 512 */
2979 +               bcma_extpci_write_config(pc, 0, 0, BCMA_CORE_PCI_CFG_DEVCTRL,
2980 +                                        &val16, sizeof(val16));
2981 +       }
2982 +
2983 +       /* Enable PCI bridge BAR0 memory & master access */
2984 +       tmp = PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
2985 +       bcma_extpci_write_config(pc, 0, 0, PCI_COMMAND, &tmp, sizeof(tmp));
2986 +
2987 +       /* Enable PCI interrupts */
2988 +       pcicore_write32(pc, BCMA_CORE_PCI_IMASK, BCMA_CORE_PCI_IMASK_INTA);
2989 +
2990 +       /* Ok, ready to run, register it to the system.
2991 +        * The following needs change, if we want to port hostmode
2992 +        * to non-MIPS platform. */
2993 +       io_map_base = (unsigned long)ioremap_nocache(pc_host->mem_resource.start,
2994 +                                                    resource_size(&pc_host->mem_resource));
2995 +       pc_host->pci_controller.io_map_base = io_map_base;
2996 +       set_io_port_base(pc_host->pci_controller.io_map_base);
2997 +       /* Give some time to the PCI controller to configure itself with the new
2998 +        * values. Not waiting at this point causes crashes of the machine. */
2999 +       usleep_range(10000, 15000);
3000 +       register_pci_controller(&pc_host->pci_controller);
3001 +       return;
3002 +}
3003 +
3004 +/* Early PCI fixup for a device on the PCI-core bridge. */
3005 +static void bcma_core_pci_fixup_pcibridge(struct pci_dev *dev)
3006 +{
3007 +       if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
3008 +               /* This is not a device on the PCI-core bridge. */
3009 +               return;
3010 +       }
3011 +       if (PCI_SLOT(dev->devfn) != 0)
3012 +               return;
3013 +
3014 +       pr_info("PCI: Fixing up bridge %s\n", pci_name(dev));
3015 +
3016 +       /* Enable PCI bridge bus mastering and memory space */
3017 +       pci_set_master(dev);
3018 +       if (pcibios_enable_device(dev, ~0) < 0) {
3019 +               pr_err("PCI: BCMA bridge enable failed\n");
3020 +               return;
3021 +       }
3022 +
3023 +       /* Enable PCI bridge BAR1 prefetch and burst */
3024 +       pci_write_config_dword(dev, BCMA_PCI_BAR1_CONTROL, 3);
3025 +}
3026 +DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, bcma_core_pci_fixup_pcibridge);
3027 +
3028 +/* Early PCI fixup for all PCI-cores to set the correct memory address. */
3029 +static void bcma_core_pci_fixup_addresses(struct pci_dev *dev)
3030 +{
3031 +       struct resource *res;
3032 +       int pos, err;
3033 +
3034 +       if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
3035 +               /* This is not a device on the PCI-core bridge. */
3036 +               return;
3037 +       }
3038 +       if (PCI_SLOT(dev->devfn) == 0)
3039 +               return;
3040 +
3041 +       pr_info("PCI: Fixing up addresses %s\n", pci_name(dev));
3042 +
3043 +       for (pos = 0; pos < 6; pos++) {
3044 +               res = &dev->resource[pos];
3045 +               if (res->flags & (IORESOURCE_IO | IORESOURCE_MEM)) {
3046 +                       err = pci_assign_resource(dev, pos);
3047 +                       if (err)
3048 +                               pr_err("PCI: Problem fixing up the addresses on %s\n",
3049 +                                      pci_name(dev));
3050 +               }
3051 +       }
3052 +}
3053 +DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, bcma_core_pci_fixup_addresses);
3054 +
3055 +/* This function is called when doing a pci_enable_device().
3056 + * We must first check if the device is a device on the PCI-core bridge. */
3057 +int bcma_core_pci_plat_dev_init(struct pci_dev *dev)
3058 +{
3059 +       struct bcma_drv_pci_host *pc_host;
3060 +       int readrq;
3061 +
3062 +       if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
3063 +               /* This is not a device on the PCI-core bridge. */
3064 +               return -ENODEV;
3065 +       }
3066 +       pc_host = container_of(dev->bus->ops, struct bcma_drv_pci_host,
3067 +                              pci_ops);
3068 +
3069 +       pr_info("PCI: Fixing up device %s\n", pci_name(dev));
3070 +
3071 +       /* Fix up interrupt lines */
3072 +       dev->irq = bcma_core_irq(pc_host->pdev->core);
3073 +       pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
3074 +
3075 +       readrq = pcie_get_readrq(dev);
3076 +       if (readrq > 128) {
3077 +               pr_info("change PCIe max read request size from %i to 128\n", readrq);
3078 +               pcie_set_readrq(dev, 128);
3079 +       }
3080 +       return 0;
3081 +}
3082 +EXPORT_SYMBOL(bcma_core_pci_plat_dev_init);
3083 +
3084 +/* PCI device IRQ mapping. */
3085 +int bcma_core_pci_pcibios_map_irq(const struct pci_dev *dev)
3086 +{
3087 +       struct bcma_drv_pci_host *pc_host;
3088 +
3089 +       if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
3090 +               /* This is not a device on the PCI-core bridge. */
3091 +               return -ENODEV;
3092 +       }
3093 +
3094 +       pc_host = container_of(dev->bus->ops, struct bcma_drv_pci_host,
3095 +                              pci_ops);
3096 +       return bcma_core_irq(pc_host->pdev->core);
3097  }
3098 +EXPORT_SYMBOL(bcma_core_pci_pcibios_map_irq);
3099 --- a/drivers/bcma/host_pci.c
3100 +++ b/drivers/bcma/host_pci.c
3101 @@ -18,7 +18,7 @@ static void bcma_host_pci_switch_core(st
3102         pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN2,
3103                                core->wrap);
3104         core->bus->mapped_core = core;
3105 -       pr_debug("Switched to core: 0x%X\n", core->id.id);
3106 +       bcma_debug(core->bus, "Switched to core: 0x%X\n", core->id.id);
3107  }
3108  
3109  /* Provides access to the requested core. Returns base offset that has to be
3110 @@ -77,8 +77,8 @@ static void bcma_host_pci_write32(struct
3111  }
3112  
3113  #ifdef CONFIG_BCMA_BLOCKIO
3114 -void bcma_host_pci_block_read(struct bcma_device *core, void *buffer,
3115 -                             size_t count, u16 offset, u8 reg_width)
3116 +static void bcma_host_pci_block_read(struct bcma_device *core, void *buffer,
3117 +                                    size_t count, u16 offset, u8 reg_width)
3118  {
3119         void __iomem *addr = core->bus->mmio + offset;
3120         if (core->bus->mapped_core != core)
3121 @@ -100,8 +100,9 @@ void bcma_host_pci_block_read(struct bcm
3122         }
3123  }
3124  
3125 -void bcma_host_pci_block_write(struct bcma_device *core, const void *buffer,
3126 -                              size_t count, u16 offset, u8 reg_width)
3127 +static void bcma_host_pci_block_write(struct bcma_device *core,
3128 +                                     const void *buffer, size_t count,
3129 +                                     u16 offset, u8 reg_width)
3130  {
3131         void __iomem *addr = core->bus->mmio + offset;
3132         if (core->bus->mapped_core != core)
3133 @@ -139,7 +140,7 @@ static void bcma_host_pci_awrite32(struc
3134         iowrite32(value, core->bus->mmio + (1 * BCMA_CORE_SIZE) + offset);
3135  }
3136  
3137 -const struct bcma_host_ops bcma_host_pci_ops = {
3138 +static const struct bcma_host_ops bcma_host_pci_ops = {
3139         .read8          = bcma_host_pci_read8,
3140         .read16         = bcma_host_pci_read16,
3141         .read32         = bcma_host_pci_read32,
3142 @@ -154,8 +155,8 @@ const struct bcma_host_ops bcma_host_pci
3143         .awrite32       = bcma_host_pci_awrite32,
3144  };
3145  
3146 -static int bcma_host_pci_probe(struct pci_dev *dev,
3147 -                            const struct pci_device_id *id)
3148 +static int __devinit bcma_host_pci_probe(struct pci_dev *dev,
3149 +                                        const struct pci_device_id *id)
3150  {
3151         struct bcma_bus *bus;
3152         int err = -ENOMEM;
3153 @@ -188,7 +189,7 @@ static int bcma_host_pci_probe(struct pc
3154  
3155         /* SSB needed additional powering up, do we have any AMBA PCI cards? */
3156         if (!pci_is_pcie(dev))
3157 -               pr_err("PCI card detected, report problems.\n");
3158 +               bcma_err(bus, "PCI card detected, report problems.\n");
3159  
3160         /* Map MMIO */
3161         err = -ENOMEM;
3162 @@ -201,6 +202,9 @@ static int bcma_host_pci_probe(struct pc
3163         bus->hosttype = BCMA_HOSTTYPE_PCI;
3164         bus->ops = &bcma_host_pci_ops;
3165  
3166 +       bus->boardinfo.vendor = bus->host_pci->subsystem_vendor;
3167 +       bus->boardinfo.type = bus->host_pci->subsystem_device;
3168 +
3169         /* Register */
3170         err = bcma_bus_register(bus);
3171         if (err)
3172 @@ -222,7 +226,7 @@ err_kfree_bus:
3173         return err;
3174  }
3175  
3176 -static void bcma_host_pci_remove(struct pci_dev *dev)
3177 +static void __devexit bcma_host_pci_remove(struct pci_dev *dev)
3178  {
3179         struct bcma_bus *bus = pci_get_drvdata(dev);
3180  
3181 @@ -234,7 +238,7 @@ static void bcma_host_pci_remove(struct
3182         pci_set_drvdata(dev, NULL);
3183  }
3184  
3185 -#ifdef CONFIG_PM
3186 +#ifdef CONFIG_PM_SLEEP
3187  static int bcma_host_pci_suspend(struct device *dev)
3188  {
3189         struct pci_dev *pdev = to_pci_dev(dev);
3190 @@ -257,17 +261,21 @@ static SIMPLE_DEV_PM_OPS(bcma_pm_ops, bc
3191                          bcma_host_pci_resume);
3192  #define BCMA_PM_OPS    (&bcma_pm_ops)
3193  
3194 -#else /* CONFIG_PM */
3195 +#else /* CONFIG_PM_SLEEP */
3196  
3197  #define BCMA_PM_OPS     NULL
3198  
3199 -#endif /* CONFIG_PM */
3200 +#endif /* CONFIG_PM_SLEEP */
3201  
3202  static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
3203         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) },
3204 +       { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 43224) },
3205         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4331) },
3206         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) },
3207         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4357) },
3208 +       { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4358) },
3209 +       { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4359) },
3210 +       { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4365) },
3211         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) },
3212         { 0, },
3213  };
3214 @@ -277,7 +285,7 @@ static struct pci_driver bcma_pci_bridge
3215         .name = "bcma-pci-bridge",
3216         .id_table = bcma_pci_bridge_tbl,
3217         .probe = bcma_host_pci_probe,
3218 -       .remove = bcma_host_pci_remove,
3219 +       .remove = __devexit_p(bcma_host_pci_remove),
3220         .driver.pm = BCMA_PM_OPS,
3221  };
3222  
3223 --- a/drivers/bcma/host_soc.c
3224 +++ b/drivers/bcma/host_soc.c
3225 @@ -143,7 +143,7 @@ static void bcma_host_soc_awrite32(struc
3226         writel(value, core->io_wrap + offset);
3227  }
3228  
3229 -const struct bcma_host_ops bcma_host_soc_ops = {
3230 +static const struct bcma_host_ops bcma_host_soc_ops = {
3231         .read8          = bcma_host_soc_read8,
3232         .read16         = bcma_host_soc_read16,
3233         .read32         = bcma_host_soc_read32,
3234 --- a/drivers/bcma/main.c
3235 +++ b/drivers/bcma/main.c
3236 @@ -7,12 +7,19 @@
3237  
3238  #include "bcma_private.h"
3239  #include <linux/module.h>
3240 +#include <linux/platform_device.h>
3241  #include <linux/bcma/bcma.h>
3242  #include <linux/slab.h>
3243  
3244  MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
3245  MODULE_LICENSE("GPL");
3246  
3247 +/* contains the number the next bus should get. */
3248 +static unsigned int bcma_bus_next_num = 0;
3249 +
3250 +/* bcma_buses_mutex locks the bcma_bus_next_num */
3251 +static DEFINE_MUTEX(bcma_buses_mutex);
3252 +
3253  static int bcma_bus_match(struct device *dev, struct device_driver *drv);
3254  static int bcma_device_probe(struct device *dev);
3255  static int bcma_device_remove(struct device *dev);
3256 @@ -55,7 +62,14 @@ static struct bus_type bcma_bus_type = {
3257         .dev_attrs      = bcma_device_attrs,
3258  };
3259  
3260 -static struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid)
3261 +static u16 bcma_cc_core_id(struct bcma_bus *bus)
3262 +{
3263 +       if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706)
3264 +               return BCMA_CORE_4706_CHIPCOMMON;
3265 +       return BCMA_CORE_CHIPCOMMON;
3266 +}
3267 +
3268 +struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid)
3269  {
3270         struct bcma_device *core;
3271  
3272 @@ -65,6 +79,38 @@ static struct bcma_device *bcma_find_cor
3273         }
3274         return NULL;
3275  }
3276 +EXPORT_SYMBOL_GPL(bcma_find_core);
3277 +
3278 +struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
3279 +                                       u8 unit)
3280 +{
3281 +       struct bcma_device *core;
3282 +
3283 +       list_for_each_entry(core, &bus->cores, list) {
3284 +               if (core->id.id == coreid && core->core_unit == unit)
3285 +                       return core;
3286 +       }
3287 +       return NULL;
3288 +}
3289 +
3290 +bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
3291 +                    int timeout)
3292 +{
3293 +       unsigned long deadline = jiffies + timeout;
3294 +       u32 val;
3295 +
3296 +       do {
3297 +               val = bcma_read32(core, reg);
3298 +               if ((val & mask) == value)
3299 +                       return true;
3300 +               cpu_relax();
3301 +               udelay(10);
3302 +       } while (!time_after_eq(jiffies, deadline));
3303 +
3304 +       bcma_warn(core->bus, "Timeout waiting for register 0x%04X!\n", reg);
3305 +
3306 +       return false;
3307 +}
3308  
3309  static void bcma_release_core_dev(struct device *dev)
3310  {
3311 @@ -84,16 +130,23 @@ static int bcma_register_cores(struct bc
3312         list_for_each_entry(core, &bus->cores, list) {
3313                 /* We support that cores ourself */
3314                 switch (core->id.id) {
3315 +               case BCMA_CORE_4706_CHIPCOMMON:
3316                 case BCMA_CORE_CHIPCOMMON:
3317                 case BCMA_CORE_PCI:
3318                 case BCMA_CORE_PCIE:
3319                 case BCMA_CORE_MIPS_74K:
3320 +               case BCMA_CORE_4706_MAC_GBIT_COMMON:
3321                         continue;
3322                 }
3323  
3324 +               /* Only first GMAC core on BCM4706 is connected and working */
3325 +               if (core->id.id == BCMA_CORE_4706_MAC_GBIT &&
3326 +                   core->core_unit > 0)
3327 +                       continue;
3328 +
3329                 core->dev.release = bcma_release_core_dev;
3330                 core->dev.bus = &bcma_bus_type;
3331 -               dev_set_name(&core->dev, "bcma%d:%d", 0/*bus->num*/, dev_id);
3332 +               dev_set_name(&core->dev, "bcma%d:%d", bus->num, dev_id);
3333  
3334                 switch (bus->hosttype) {
3335                 case BCMA_HOSTTYPE_PCI:
3336 @@ -111,41 +164,98 @@ static int bcma_register_cores(struct bc
3337  
3338                 err = device_register(&core->dev);
3339                 if (err) {
3340 -                       pr_err("Could not register dev for core 0x%03X\n",
3341 -                              core->id.id);
3342 +                       bcma_err(bus,
3343 +                                "Could not register dev for core 0x%03X\n",
3344 +                                core->id.id);
3345                         continue;
3346                 }
3347                 core->dev_registered = true;
3348                 dev_id++;
3349         }
3350  
3351 +#ifdef CONFIG_BCMA_DRIVER_MIPS
3352 +       if (bus->drv_cc.pflash.present) {
3353 +               err = platform_device_register(&bcma_pflash_dev);
3354 +               if (err)
3355 +                       bcma_err(bus, "Error registering parallel flash\n");
3356 +       }
3357 +#endif
3358 +
3359 +#ifdef CONFIG_BCMA_SFLASH
3360 +       if (bus->drv_cc.sflash.present) {
3361 +               err = platform_device_register(&bcma_sflash_dev);
3362 +               if (err)
3363 +                       bcma_err(bus, "Error registering serial flash\n");
3364 +       }
3365 +#endif
3366 +
3367 +#ifdef CONFIG_BCMA_NFLASH
3368 +       if (bus->drv_cc.nflash.present) {
3369 +               err = platform_device_register(&bcma_nflash_dev);
3370 +               if (err)
3371 +                       bcma_err(bus, "Error registering NAND flash\n");
3372 +       }
3373 +#endif
3374 +       err = bcma_gpio_init(&bus->drv_cc);
3375 +       if (err == -ENOTSUPP)
3376 +               bcma_debug(bus, "GPIO driver not activated\n");
3377 +       else if (err)
3378 +               bcma_err(bus, "Error registering GPIO driver: %i\n", err);
3379 +
3380 +       if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
3381 +               err = bcma_chipco_watchdog_register(&bus->drv_cc);
3382 +               if (err)
3383 +                       bcma_err(bus, "Error registering watchdog driver\n");
3384 +       }
3385 +
3386         return 0;
3387  }
3388  
3389  static void bcma_unregister_cores(struct bcma_bus *bus)
3390  {
3391 -       struct bcma_device *core;
3392 +       struct bcma_device *core, *tmp;
3393  
3394 -       list_for_each_entry(core, &bus->cores, list) {
3395 +       list_for_each_entry_safe(core, tmp, &bus->cores, list) {
3396 +               list_del(&core->list);
3397                 if (core->dev_registered)
3398                         device_unregister(&core->dev);
3399         }
3400 +       if (bus->hosttype == BCMA_HOSTTYPE_SOC)
3401 +               platform_device_unregister(bus->drv_cc.watchdog);
3402  }
3403  
3404 -int bcma_bus_register(struct bcma_bus *bus)
3405 +int __devinit bcma_bus_register(struct bcma_bus *bus)
3406  {
3407         int err;
3408         struct bcma_device *core;
3409  
3410 +       mutex_lock(&bcma_buses_mutex);
3411 +       bus->num = bcma_bus_next_num++;
3412 +       mutex_unlock(&bcma_buses_mutex);
3413 +
3414         /* Scan for devices (cores) */
3415         err = bcma_bus_scan(bus);
3416         if (err) {
3417 -               pr_err("Failed to scan: %d\n", err);
3418 -               return -1;
3419 +               bcma_err(bus, "Failed to scan: %d\n", err);
3420 +               return err;
3421         }
3422  
3423 +       /* Early init CC core */
3424 +       core = bcma_find_core(bus, bcma_cc_core_id(bus));
3425 +       if (core) {
3426 +               bus->drv_cc.core = core;
3427 +               bcma_core_chipcommon_early_init(&bus->drv_cc);
3428 +       }
3429 +
3430 +       /* Try to get SPROM */
3431 +       err = bcma_sprom_get(bus);
3432 +       if (err == -ENOENT) {
3433 +               bcma_err(bus, "No SPROM available\n");
3434 +       } else if (err)
3435 +               bcma_err(bus, "Failed to get SPROM: %d\n", err);
3436 +
3437         /* Init CC core */
3438 -       core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
3439 +       core = bcma_find_core(bus, bcma_cc_core_id(bus));
3440         if (core) {
3441                 bus->drv_cc.core = core;
3442                 bcma_core_chipcommon_init(&bus->drv_cc);
3443 @@ -159,30 +269,54 @@ int bcma_bus_register(struct bcma_bus *b
3444         }
3445  
3446         /* Init PCIE core */
3447 -       core = bcma_find_core(bus, BCMA_CORE_PCIE);
3448 +       core = bcma_find_core_unit(bus, BCMA_CORE_PCIE, 0);
3449         if (core) {
3450 -               bus->drv_pci.core = core;
3451 -               bcma_core_pci_init(&bus->drv_pci);
3452 +               bus->drv_pci[0].core = core;
3453 +               bcma_core_pci_init(&bus->drv_pci[0]);
3454         }
3455  
3456 -       /* Try to get SPROM */
3457 -       err = bcma_sprom_get(bus);
3458 -       if (err == -ENOENT) {
3459 -               pr_err("No SPROM available\n");
3460 -       } else if (err)
3461 -               pr_err("Failed to get SPROM: %d\n", err);
3462 +       /* Init PCIE core */
3463 +       core = bcma_find_core_unit(bus, BCMA_CORE_PCIE, 1);
3464 +       if (core) {
3465 +               bus->drv_pci[1].core = core;
3466 +               bcma_core_pci_init(&bus->drv_pci[1]);
3467 +       }
3468 +
3469 +       /* Init GBIT MAC COMMON core */
3470 +       core = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON);
3471 +       if (core) {
3472 +               bus->drv_gmac_cmn.core = core;
3473 +               bcma_core_gmac_cmn_init(&bus->drv_gmac_cmn);
3474 +       }
3475  
3476         /* Register found cores */
3477         bcma_register_cores(bus);
3478  
3479 -       pr_info("Bus registered\n");
3480 +       bcma_info(bus, "Bus registered\n");
3481  
3482         return 0;
3483  }
3484  
3485  void bcma_bus_unregister(struct bcma_bus *bus)
3486  {
3487 +       struct bcma_device *cores[3];
3488 +       int err;
3489 +
3490 +       err = bcma_gpio_unregister(&bus->drv_cc);
3491 +       if (err == -EBUSY)
3492 +               bcma_err(bus, "Some GPIOs are still in use.\n");
3493 +       else if (err)
3494 +               bcma_err(bus, "Can not unregister GPIO driver: %i\n", err);
3495 +
3496 +       cores[0] = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
3497 +       cores[1] = bcma_find_core(bus, BCMA_CORE_PCIE);
3498 +       cores[2] = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON);
3499 +
3500         bcma_unregister_cores(bus);
3501 +
3502 +       kfree(cores[2]);
3503 +       kfree(cores[1]);
3504 +       kfree(cores[0]);
3505  }
3506  
3507  int __init bcma_bus_early_register(struct bcma_bus *bus,
3508 @@ -196,14 +330,14 @@ int __init bcma_bus_early_register(struc
3509         bcma_init_bus(bus);
3510  
3511         match.manuf = BCMA_MANUF_BCM;
3512 -       match.id = BCMA_CORE_CHIPCOMMON;
3513 +       match.id = bcma_cc_core_id(bus);
3514         match.class = BCMA_CL_SIM;
3515         match.rev = BCMA_ANY_REV;
3516  
3517         /* Scan for chip common core */
3518         err = bcma_bus_scan_early(bus, &match, core_cc);
3519         if (err) {
3520 -               pr_err("Failed to scan for common core: %d\n", err);
3521 +               bcma_err(bus, "Failed to scan for common core: %d\n", err);
3522                 return -1;
3523         }
3524  
3525 @@ -215,25 +349,25 @@ int __init bcma_bus_early_register(struc
3526         /* Scan for mips core */
3527         err = bcma_bus_scan_early(bus, &match, core_mips);
3528         if (err) {
3529 -               pr_err("Failed to scan for mips core: %d\n", err);
3530 +               bcma_err(bus, "Failed to scan for mips core: %d\n", err);
3531                 return -1;
3532         }
3533  
3534 -       /* Init CC core */
3535 -       core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
3536 +       /* Early init CC core */
3537 +       core = bcma_find_core(bus, bcma_cc_core_id(bus));
3538         if (core) {
3539                 bus->drv_cc.core = core;
3540 -               bcma_core_chipcommon_init(&bus->drv_cc);
3541 +               bcma_core_chipcommon_early_init(&bus->drv_cc);
3542         }
3543  
3544 -       /* Init MIPS core */
3545 +       /* Early init MIPS core */
3546         core = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
3547         if (core) {
3548                 bus->drv_mips.core = core;
3549 -               bcma_core_mips_init(&bus->drv_mips);
3550 +               bcma_core_mips_early_init(&bus->drv_mips);
3551         }
3552  
3553 -       pr_info("Early bus registered\n");
3554 +       bcma_info(bus, "Early bus registered\n");
3555  
3556         return 0;
3557  }
3558 @@ -259,8 +393,7 @@ int bcma_bus_resume(struct bcma_bus *bus
3559         struct bcma_device *core;
3560  
3561         /* Init CC core */
3562 -       core = bcma_find_core(bus, BCMA_CORE_CHIPCOMMON);
3563 -       if (core) {
3564 +       if (bus->drv_cc.core) {
3565                 bus->drv_cc.setup_done = false;
3566                 bcma_core_chipcommon_init(&bus->drv_cc);
3567         }
3568 --- a/drivers/bcma/scan.c
3569 +++ b/drivers/bcma/scan.c
3570 @@ -19,15 +19,39 @@ struct bcma_device_id_name {
3571         u16 id;
3572         const char *name;
3573  };
3574 -struct bcma_device_id_name bcma_device_names[] = {
3575 +
3576 +static const struct bcma_device_id_name bcma_arm_device_names[] = {
3577 +       { BCMA_CORE_4706_MAC_GBIT_COMMON, "BCM4706 GBit MAC Common" },
3578 +       { BCMA_CORE_ARM_1176, "ARM 1176" },
3579 +       { BCMA_CORE_ARM_7TDMI, "ARM 7TDMI" },
3580 +       { BCMA_CORE_ARM_CM3, "ARM CM3" },
3581 +};
3582 +
3583 +static const struct bcma_device_id_name bcma_bcm_device_names[] = {
3584         { BCMA_CORE_OOB_ROUTER, "OOB Router" },
3585 +       { BCMA_CORE_4706_CHIPCOMMON, "BCM4706 ChipCommon" },
3586 +       { BCMA_CORE_4706_SOC_RAM, "BCM4706 SOC RAM" },
3587 +       { BCMA_CORE_4706_MAC_GBIT, "BCM4706 GBit MAC" },
3588 +       { BCMA_CORE_PCIEG2, "PCIe Gen 2" },
3589 +       { BCMA_CORE_DMA, "DMA" },
3590 +       { BCMA_CORE_SDIO3, "SDIO3" },
3591 +       { BCMA_CORE_USB20, "USB 2.0" },
3592 +       { BCMA_CORE_USB30, "USB 3.0" },
3593 +       { BCMA_CORE_A9JTAG, "ARM Cortex A9 JTAG" },
3594 +       { BCMA_CORE_DDR23, "Denali DDR2/DDR3 memory controller" },
3595 +       { BCMA_CORE_ROM, "ROM" },
3596 +       { BCMA_CORE_NAND, "NAND flash controller" },
3597 +       { BCMA_CORE_QSPI, "SPI flash controller" },
3598 +       { BCMA_CORE_CHIPCOMMON_B, "Chipcommon B" },
3599 +       { BCMA_CORE_ARMCA9, "ARM Cortex A9 core (ihost)" },
3600 +       { BCMA_CORE_AMEMC, "AMEMC (DDR)" },
3601 +       { BCMA_CORE_ALTA, "ALTA (I2S)" },
3602         { BCMA_CORE_INVALID, "Invalid" },
3603         { BCMA_CORE_CHIPCOMMON, "ChipCommon" },
3604         { BCMA_CORE_ILINE20, "ILine 20" },
3605         { BCMA_CORE_SRAM, "SRAM" },
3606         { BCMA_CORE_SDRAM, "SDRAM" },
3607         { BCMA_CORE_PCI, "PCI" },
3608 -       { BCMA_CORE_MIPS, "MIPS" },
3609         { BCMA_CORE_ETHERNET, "Fast Ethernet" },
3610         { BCMA_CORE_V90, "V90" },
3611         { BCMA_CORE_USB11_HOSTDEV, "USB 1.1 Hostdev" },
3612 @@ -44,7 +68,6 @@ struct bcma_device_id_name bcma_device_n
3613         { BCMA_CORE_PHY_A, "PHY A" },
3614         { BCMA_CORE_PHY_B, "PHY B" },
3615         { BCMA_CORE_PHY_G, "PHY G" },
3616 -       { BCMA_CORE_MIPS_3302, "MIPS 3302" },
3617         { BCMA_CORE_USB11_HOST, "USB 1.1 Host" },
3618         { BCMA_CORE_USB11_DEV, "USB 1.1 Device" },
3619         { BCMA_CORE_USB20_HOST, "USB 2.0 Host" },
3620 @@ -58,15 +81,11 @@ struct bcma_device_id_name bcma_device_n
3621         { BCMA_CORE_PHY_N, "PHY N" },
3622         { BCMA_CORE_SRAM_CTL, "SRAM Controller" },
3623         { BCMA_CORE_MINI_MACPHY, "Mini MACPHY" },
3624 -       { BCMA_CORE_ARM_1176, "ARM 1176" },
3625 -       { BCMA_CORE_ARM_7TDMI, "ARM 7TDMI" },
3626         { BCMA_CORE_PHY_LP, "PHY LP" },
3627         { BCMA_CORE_PMU, "PMU" },
3628         { BCMA_CORE_PHY_SSN, "PHY SSN" },
3629         { BCMA_CORE_SDIO_DEV, "SDIO Device" },
3630 -       { BCMA_CORE_ARM_CM3, "ARM CM3" },
3631         { BCMA_CORE_PHY_HT, "PHY HT" },
3632 -       { BCMA_CORE_MIPS_74K, "MIPS 74K" },
3633         { BCMA_CORE_MAC_GBIT, "GBit MAC" },
3634         { BCMA_CORE_DDR12_MEM_CTL, "DDR1/DDR2 Memory Controller" },
3635         { BCMA_CORE_PCIE_RC, "PCIe Root Complex" },
3636 @@ -77,18 +96,45 @@ struct bcma_device_id_name bcma_device_n
3637         { BCMA_CORE_I2S, "I2S" },
3638         { BCMA_CORE_SDR_DDR1_MEM_CTL, "SDR/DDR1 Memory Controller" },
3639         { BCMA_CORE_SHIM, "SHIM" },
3640 +       { BCMA_CORE_PCIE2, "PCIe Gen2" },
3641 +       { BCMA_CORE_ARM_CR4, "ARM CR4" },
3642         { BCMA_CORE_DEFAULT, "Default" },
3643  };
3644 -const char *bcma_device_name(struct bcma_device_id *id)
3645 +
3646 +static const struct bcma_device_id_name bcma_mips_device_names[] = {
3647 +       { BCMA_CORE_MIPS, "MIPS" },
3648 +       { BCMA_CORE_MIPS_3302, "MIPS 3302" },
3649 +       { BCMA_CORE_MIPS_74K, "MIPS 74K" },
3650 +};
3651 +
3652 +static const char *bcma_device_name(const struct bcma_device_id *id)
3653  {
3654 -       int i;
3655 +       const struct bcma_device_id_name *names;
3656 +       int size, i;
3657  
3658 -       if (id->manuf == BCMA_MANUF_BCM) {
3659 -               for (i = 0; i < ARRAY_SIZE(bcma_device_names); i++) {
3660 -                       if (bcma_device_names[i].id == id->id)
3661 -                               return bcma_device_names[i].name;
3662 -               }
3663 +       /* search manufacturer specific names */
3664 +       switch (id->manuf) {
3665 +       case BCMA_MANUF_ARM:
3666 +               names = bcma_arm_device_names;
3667 +               size = ARRAY_SIZE(bcma_arm_device_names);
3668 +               break;
3669 +       case BCMA_MANUF_BCM:
3670 +               names = bcma_bcm_device_names;
3671 +               size = ARRAY_SIZE(bcma_bcm_device_names);
3672 +               break;
3673 +       case BCMA_MANUF_MIPS:
3674 +               names = bcma_mips_device_names;
3675 +               size = ARRAY_SIZE(bcma_mips_device_names);
3676 +               break;
3677 +       default:
3678 +               return "UNKNOWN";
3679 +       }
3680 +
3681 +       for (i = 0; i < size; i++) {
3682 +               if (names[i].id == id->id)
3683 +                       return names[i].name;
3684         }
3685 +
3686         return "UNKNOWN";
3687  }
3688  
3689 @@ -105,19 +151,19 @@ static void bcma_scan_switch_core(struct
3690                                        addr);
3691  }
3692  
3693 -static u32 bcma_erom_get_ent(struct bcma_bus *bus, u32 **eromptr)
3694 +static u32 bcma_erom_get_ent(struct bcma_bus *bus, u32 __iomem **eromptr)
3695  {
3696         u32 ent = readl(*eromptr);
3697         (*eromptr)++;
3698         return ent;
3699  }
3700  
3701 -static void bcma_erom_push_ent(u32 **eromptr)
3702 +static void bcma_erom_push_ent(u32 __iomem **eromptr)
3703  {
3704         (*eromptr)--;
3705  }
3706  
3707 -static s32 bcma_erom_get_ci(struct bcma_bus *bus, u32 **eromptr)
3708 +static s32 bcma_erom_get_ci(struct bcma_bus *bus, u32 __iomem **eromptr)
3709  {
3710         u32 ent = bcma_erom_get_ent(bus, eromptr);
3711         if (!(ent & SCAN_ER_VALID))
3712 @@ -127,14 +173,14 @@ static s32 bcma_erom_get_ci(struct bcma_
3713         return ent;
3714  }
3715  
3716 -static bool bcma_erom_is_end(struct bcma_bus *bus, u32 **eromptr)
3717 +static bool bcma_erom_is_end(struct bcma_bus *bus, u32 __iomem **eromptr)
3718  {
3719         u32 ent = bcma_erom_get_ent(bus, eromptr);
3720         bcma_erom_push_ent(eromptr);
3721         return (ent == (SCAN_ER_TAG_END | SCAN_ER_VALID));
3722  }
3723  
3724 -static bool bcma_erom_is_bridge(struct bcma_bus *bus, u32 **eromptr)
3725 +static bool bcma_erom_is_bridge(struct bcma_bus *bus, u32 __iomem **eromptr)
3726  {
3727         u32 ent = bcma_erom_get_ent(bus, eromptr);
3728         bcma_erom_push_ent(eromptr);
3729 @@ -143,7 +189,7 @@ static bool bcma_erom_is_bridge(struct b
3730                 ((ent & SCAN_ADDR_TYPE) == SCAN_ADDR_TYPE_BRIDGE));
3731  }
3732  
3733 -static void bcma_erom_skip_component(struct bcma_bus *bus, u32 **eromptr)
3734 +static void bcma_erom_skip_component(struct bcma_bus *bus, u32 __iomem **eromptr)
3735  {
3736         u32 ent;
3737         while (1) {
3738 @@ -157,7 +203,7 @@ static void bcma_erom_skip_component(str
3739         bcma_erom_push_ent(eromptr);
3740  }
3741  
3742 -static s32 bcma_erom_get_mst_port(struct bcma_bus *bus, u32 **eromptr)
3743 +static s32 bcma_erom_get_mst_port(struct bcma_bus *bus, u32 __iomem **eromptr)
3744  {
3745         u32 ent = bcma_erom_get_ent(bus, eromptr);
3746         if (!(ent & SCAN_ER_VALID))
3747 @@ -167,7 +213,7 @@ static s32 bcma_erom_get_mst_port(struct
3748         return ent;
3749  }
3750  
3751 -static s32 bcma_erom_get_addr_desc(struct bcma_bus *bus, u32 **eromptr,
3752 +static u32 bcma_erom_get_addr_desc(struct bcma_bus *bus, u32 __iomem **eromptr,
3753                                   u32 type, u8 port)
3754  {
3755         u32 addrl, addrh, sizel, sizeh = 0;
3756 @@ -179,7 +225,7 @@ static s32 bcma_erom_get_addr_desc(struc
3757             ((ent & SCAN_ADDR_TYPE) != type) ||
3758             (((ent & SCAN_ADDR_PORT) >> SCAN_ADDR_PORT_SHIFT) != port)) {
3759                 bcma_erom_push_ent(eromptr);
3760 -               return -EINVAL;
3761 +               return (u32)-EINVAL;
3762         }
3763  
3764         addrl = ent & SCAN_ADDR_ADDR;
3765 @@ -212,11 +258,24 @@ static struct bcma_device *bcma_find_cor
3766         return NULL;
3767  }
3768  
3769 +static struct bcma_device *bcma_find_core_reverse(struct bcma_bus *bus, u16 coreid)
3770 +{
3771 +       struct bcma_device *core;
3772 +
3773 +       list_for_each_entry_reverse(core, &bus->cores, list) {
3774 +               if (core->id.id == coreid)
3775 +                       return core;
3776 +       }
3777 +       return NULL;
3778 +}
3779 +
3780 +#define IS_ERR_VALUE_U32(x) ((x) >= (u32)-MAX_ERRNO)
3781 +
3782  static int bcma_get_next_core(struct bcma_bus *bus, u32 __iomem **eromptr,
3783                               struct bcma_device_id *match, int core_num,
3784                               struct bcma_device *core)
3785  {
3786 -       s32 tmp;
3787 +       u32 tmp;
3788         u8 i, j;
3789         s32 cia, cib;
3790         u8 ports[2], wrappers[2];
3791 @@ -252,11 +311,15 @@ static int bcma_get_next_core(struct bcm
3792  
3793         /* check if component is a core at all */
3794         if (wrappers[0] + wrappers[1] == 0) {
3795 -               /* we could save addrl of the router
3796 -               if (cid == BCMA_CORE_OOB_ROUTER)
3797 -                */
3798 -               bcma_erom_skip_component(bus, eromptr);
3799 -               return -ENXIO;
3800 +               /* Some specific cores don't need wrappers */
3801 +               switch (core->id.id) {
3802 +               case BCMA_CORE_4706_MAC_GBIT_COMMON:
3803 +               /* Not used yet: case BCMA_CORE_OOB_ROUTER: */
3804 +                       break;
3805 +               default:
3806 +                       bcma_erom_skip_component(bus, eromptr);
3807 +                       return -ENXIO;
3808 +               }
3809         }
3810  
3811         if (bcma_erom_is_bridge(bus, eromptr)) {
3812 @@ -286,19 +349,36 @@ static int bcma_get_next_core(struct bcm
3813                         return -EILSEQ;
3814         }
3815  
3816 +       /* First Slave Address Descriptor should be port 0:
3817 +        * the main register space for the core
3818 +        */
3819 +       tmp = bcma_erom_get_addr_desc(bus, eromptr, SCAN_ADDR_TYPE_SLAVE, 0);
3820 +       if (tmp == 0 || IS_ERR_VALUE_U32(tmp)) {
3821 +               /* Try again to see if it is a bridge */
3822 +               tmp = bcma_erom_get_addr_desc(bus, eromptr,
3823 +                                             SCAN_ADDR_TYPE_BRIDGE, 0);
3824 +               if (tmp == 0 || IS_ERR_VALUE_U32(tmp)) {
3825 +                       return -EILSEQ;
3826 +               } else {
3827 +                       bcma_info(bus, "Bridge found\n");
3828 +                       return -ENXIO;
3829 +               }
3830 +       }
3831 +       core->addr = tmp;
3832 +
3833         /* get & parse slave ports */
3834         for (i = 0; i < ports[1]; i++) {
3835                 for (j = 0; ; j++) {
3836                         tmp = bcma_erom_get_addr_desc(bus, eromptr,
3837                                 SCAN_ADDR_TYPE_SLAVE, i);
3838 -                       if (tmp < 0) {
3839 +                       if (IS_ERR_VALUE_U32(tmp)) {
3840                                 /* no more entries for port _i_ */
3841                                 /* pr_debug("erom: slave port %d "
3842                                  * "has %d descriptors\n", i, j); */
3843                                 break;
3844                         } else {
3845                                 if (i == 0 && j == 0)
3846 -                                       core->addr = tmp;
3847 +                                       core->addr1 = tmp;
3848                         }
3849                 }
3850         }
3851 @@ -308,7 +388,7 @@ static int bcma_get_next_core(struct bcm
3852                 for (j = 0; ; j++) {
3853                         tmp = bcma_erom_get_addr_desc(bus, eromptr,
3854                                 SCAN_ADDR_TYPE_MWRAP, i);
3855 -                       if (tmp < 0) {
3856 +                       if (IS_ERR_VALUE_U32(tmp)) {
3857                                 /* no more entries for port _i_ */
3858                                 /* pr_debug("erom: master wrapper %d "
3859                                  * "has %d descriptors\n", i, j); */
3860 @@ -326,7 +406,7 @@ static int bcma_get_next_core(struct bcm
3861                 for (j = 0; ; j++) {
3862                         tmp = bcma_erom_get_addr_desc(bus, eromptr,
3863                                 SCAN_ADDR_TYPE_SWRAP, i + hack);
3864 -                       if (tmp < 0) {
3865 +                       if (IS_ERR_VALUE_U32(tmp)) {
3866                                 /* no more entries for port _i_ */
3867                                 /* pr_debug("erom: master wrapper %d "
3868                                  * has %d descriptors\n", i, j); */
3869 @@ -353,6 +433,7 @@ static int bcma_get_next_core(struct bcm
3870  void bcma_init_bus(struct bcma_bus *bus)
3871  {
3872         s32 tmp;
3873 +       struct bcma_chipinfo *chipinfo = &(bus->chipinfo);
3874  
3875         if (bus->init_done)
3876                 return;
3877 @@ -363,9 +444,12 @@ void bcma_init_bus(struct bcma_bus *bus)
3878         bcma_scan_switch_core(bus, BCMA_ADDR_BASE);
3879  
3880         tmp = bcma_scan_read32(bus, 0, BCMA_CC_ID);
3881 -       bus->chipinfo.id = (tmp & BCMA_CC_ID_ID) >> BCMA_CC_ID_ID_SHIFT;
3882 -       bus->chipinfo.rev = (tmp & BCMA_CC_ID_REV) >> BCMA_CC_ID_REV_SHIFT;
3883 -       bus->chipinfo.pkg = (tmp & BCMA_CC_ID_PKG) >> BCMA_CC_ID_PKG_SHIFT;
3884 +       chipinfo->id = (tmp & BCMA_CC_ID_ID) >> BCMA_CC_ID_ID_SHIFT;
3885 +       chipinfo->rev = (tmp & BCMA_CC_ID_REV) >> BCMA_CC_ID_REV_SHIFT;
3886 +       chipinfo->pkg = (tmp & BCMA_CC_ID_PKG) >> BCMA_CC_ID_PKG_SHIFT;
3887 +       bcma_info(bus, "Found chip with id 0x%04X, rev 0x%02X and package 0x%02X\n",
3888 +                 chipinfo->id, chipinfo->rev, chipinfo->pkg);
3889 +
3890         bus->init_done = true;
3891  }
3892  
3893 @@ -392,9 +476,12 @@ int bcma_bus_scan(struct bcma_bus *bus)
3894         bcma_scan_switch_core(bus, erombase);
3895  
3896         while (eromptr < eromend) {
3897 +               struct bcma_device *other_core;
3898                 struct bcma_device *core = kzalloc(sizeof(*core), GFP_KERNEL);
3899 -               if (!core)
3900 -                       return -ENOMEM;
3901 +               if (!core) {
3902 +                       err = -ENOMEM;
3903 +                       goto out;
3904 +               }
3905                 INIT_LIST_HEAD(&core->list);
3906                 core->bus = bus;
3907  
3908 @@ -409,25 +496,28 @@ int bcma_bus_scan(struct bcma_bus *bus)
3909                         } else if (err == -ESPIPE) {
3910                                 break;
3911                         }
3912 -                       return err;
3913 +                       goto out;
3914                 }
3915  
3916                 core->core_index = core_num++;
3917                 bus->nr_cores++;
3918 +               other_core = bcma_find_core_reverse(bus, core->id.id);
3919 +               core->core_unit = (other_core == NULL) ? 0 : other_core->core_unit + 1;
3920  
3921 -               pr_info("Core %d found: %s "
3922 -                       "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
3923 -                       core->core_index, bcma_device_name(&core->id),
3924 -                       core->id.manuf, core->id.id, core->id.rev,
3925 -                       core->id.class);
3926 +               bcma_info(bus, "Core %d found: %s (manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
3927 +                         core->core_index, bcma_device_name(&core->id),
3928 +                         core->id.manuf, core->id.id, core->id.rev,
3929 +                         core->id.class);
3930  
3931 -               list_add(&core->list, &bus->cores);
3932 +               list_add_tail(&core->list, &bus->cores);
3933         }
3934  
3935 +       err = 0;
3936 +out:
3937         if (bus->hosttype == BCMA_HOSTTYPE_SOC)
3938                 iounmap(eromptr);
3939  
3940 -       return 0;
3941 +       return err;
3942  }
3943  
3944  int __init bcma_bus_scan_early(struct bcma_bus *bus,
3945 @@ -467,21 +557,21 @@ int __init bcma_bus_scan_early(struct bc
3946                 else if (err == -ESPIPE)
3947                         break;
3948                 else if (err < 0)
3949 -                       return err;
3950 +                       goto out;
3951  
3952                 core->core_index = core_num++;
3953                 bus->nr_cores++;
3954 -               pr_info("Core %d found: %s "
3955 -                       "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
3956 -                       core->core_index, bcma_device_name(&core->id),
3957 -                       core->id.manuf, core->id.id, core->id.rev,
3958 -                       core->id.class);
3959 +               bcma_info(bus, "Core %d found: %s (manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
3960 +                         core->core_index, bcma_device_name(&core->id),
3961 +                         core->id.manuf, core->id.id, core->id.rev,
3962 +                         core->id.class);
3963  
3964 -               list_add(&core->list, &bus->cores);
3965 +               list_add_tail(&core->list, &bus->cores);
3966                 err = 0;
3967                 break;
3968         }
3969  
3970 +out:
3971         if (bus->hosttype == BCMA_HOSTTYPE_SOC)
3972                 iounmap(eromptr);
3973  
3974 --- a/drivers/bcma/scan.h
3975 +++ b/drivers/bcma/scan.h
3976 @@ -27,7 +27,7 @@
3977  #define SCAN_CIB_NMW           0x0007C000
3978  #define SCAN_CIB_NMW_SHIFT     14
3979  #define SCAN_CIB_NSW           0x00F80000
3980 -#define SCAN_CIB_NSW_SHIFT     17
3981 +#define SCAN_CIB_NSW_SHIFT     19
3982  #define SCAN_CIB_REV           0xFF000000
3983  #define SCAN_CIB_REV_SHIFT     24
3984  
3985 --- a/drivers/bcma/sprom.c
3986 +++ b/drivers/bcma/sprom.c
3987 @@ -2,6 +2,8 @@
3988   * Broadcom specific AMBA
3989   * SPROM reading
3990   *
3991 + * Copyright 2011, 2012, Hauke Mehrtens <hauke@hauke-m.de>
3992 + *
3993   * Licensed under the GNU/GPL. See COPYING for details.
3994   */
3995  
3996 @@ -14,18 +16,68 @@
3997  #include <linux/dma-mapping.h>
3998  #include <linux/slab.h>
3999  
4000 -#define SPOFF(offset)  ((offset) / sizeof(u16))
4001 +static int(*get_fallback_sprom)(struct bcma_bus *dev, struct ssb_sprom *out);
4002 +
4003 +/**
4004 + * bcma_arch_register_fallback_sprom - Registers a method providing a
4005 + * fallback SPROM if no SPROM is found.
4006 + *
4007 + * @sprom_callback: The callback function.
4008 + *
4009 + * With this function the architecture implementation may register a
4010 + * callback handler which fills the SPROM data structure. The fallback is
4011 + * used for PCI based BCMA devices, where no valid SPROM can be found
4012 + * in the shadow registers and to provide the SPROM for SoCs where BCMA is
4013 + * to controll the system bus.
4014 + *
4015 + * This function is useful for weird architectures that have a half-assed
4016 + * BCMA device hardwired to their PCI bus.
4017 + *
4018 + * This function is available for architecture code, only. So it is not
4019 + * exported.
4020 + */
4021 +int bcma_arch_register_fallback_sprom(int (*sprom_callback)(struct bcma_bus *bus,
4022 +                                    struct ssb_sprom *out))
4023 +{
4024 +       if (get_fallback_sprom)
4025 +               return -EEXIST;
4026 +       get_fallback_sprom = sprom_callback;
4027 +
4028 +       return 0;
4029 +}
4030 +
4031 +static int bcma_fill_sprom_with_fallback(struct bcma_bus *bus,
4032 +                                        struct ssb_sprom *out)
4033 +{
4034 +       int err;
4035 +
4036 +       if (!get_fallback_sprom) {
4037 +               err = -ENOENT;
4038 +               goto fail;
4039 +       }
4040 +
4041 +       err = get_fallback_sprom(bus, out);
4042 +       if (err)
4043 +               goto fail;
4044 +
4045 +       bcma_debug(bus, "Using SPROM revision %d provided by platform.\n",
4046 +                  bus->sprom.revision);
4047 +       return 0;
4048 +fail:
4049 +       bcma_warn(bus, "Using fallback SPROM failed (err %d)\n", err);
4050 +       return err;
4051 +}
4052  
4053  /**************************************************
4054   * R/W ops.
4055   **************************************************/
4056  
4057 -static void bcma_sprom_read(struct bcma_bus *bus, u16 offset, u16 *sprom)
4058 +static void bcma_sprom_read(struct bcma_bus *bus, u16 offset, u16 *sprom,
4059 +                           size_t words)
4060  {
4061         int i;
4062 -       for (i = 0; i < SSB_SPROMSIZE_WORDS_R4; i++)
4063 -               sprom[i] = bcma_read16(bus->drv_cc.core,
4064 -                                      offset + (i * 2));
4065 +       for (i = 0; i < words; i++)
4066 +               sprom[i] = bcma_read16(bus->drv_cc.core, offset + (i * 2));
4067  }
4068  
4069  /**************************************************
4070 @@ -72,29 +124,29 @@ static inline u8 bcma_crc8(u8 crc, u8 da
4071         return t[crc ^ data];
4072  }
4073  
4074 -static u8 bcma_sprom_crc(const u16 *sprom)
4075 +static u8 bcma_sprom_crc(const u16 *sprom, size_t words)
4076  {
4077         int word;
4078         u8 crc = 0xFF;
4079  
4080 -       for (word = 0; word < SSB_SPROMSIZE_WORDS_R4 - 1; word++) {
4081 +       for (word = 0; word < words - 1; word++) {
4082                 crc = bcma_crc8(crc, sprom[word] & 0x00FF);
4083                 crc = bcma_crc8(crc, (sprom[word] & 0xFF00) >> 8);
4084         }
4085 -       crc = bcma_crc8(crc, sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & 0x00FF);
4086 +       crc = bcma_crc8(crc, sprom[words - 1] & 0x00FF);
4087         crc ^= 0xFF;
4088  
4089         return crc;
4090  }
4091  
4092 -static int bcma_sprom_check_crc(const u16 *sprom)
4093 +static int bcma_sprom_check_crc(const u16 *sprom, size_t words)
4094  {
4095         u8 crc;
4096         u8 expected_crc;
4097         u16 tmp;
4098  
4099 -       crc = bcma_sprom_crc(sprom);
4100 -       tmp = sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & SSB_SPROM_REVISION_CRC;
4101 +       crc = bcma_sprom_crc(sprom, words);
4102 +       tmp = sprom[words - 1] & SSB_SPROM_REVISION_CRC;
4103         expected_crc = tmp >> SSB_SPROM_REVISION_CRC_SHIFT;
4104         if (crc != expected_crc)
4105                 return -EPROTO;
4106 @@ -102,21 +154,25 @@ static int bcma_sprom_check_crc(const u1
4107         return 0;
4108  }
4109  
4110 -static int bcma_sprom_valid(const u16 *sprom)
4111 +static int bcma_sprom_valid(struct bcma_bus *bus, const u16 *sprom,
4112 +                           size_t words)
4113  {
4114         u16 revision;
4115         int err;
4116  
4117 -       err = bcma_sprom_check_crc(sprom);
4118 +       err = bcma_sprom_check_crc(sprom, words);
4119         if (err)
4120                 return err;
4121  
4122 -       revision = sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & SSB_SPROM_REVISION_REV;
4123 -       if (revision != 8 && revision != 9) {
4124 +       revision = sprom[words - 1] & SSB_SPROM_REVISION_REV;
4125 +       if (revision != 8 && revision != 9 && revision != 10) {
4126                 pr_err("Unsupported SPROM revision: %d\n", revision);
4127                 return -ENOENT;
4128         }
4129  
4130 +       bus->sprom.revision = revision;
4131 +       bcma_debug(bus, "Found SPROM revision %d\n", revision);
4132 +
4133         return 0;
4134  }
4135  
4136 @@ -124,124 +180,439 @@ static int bcma_sprom_valid(const u16 *s
4137   * SPROM extraction.
4138   **************************************************/
4139  
4140 +#define SPOFF(offset)  ((offset) / sizeof(u16))
4141 +
4142 +#define SPEX(_field, _offset, _mask, _shift)   \
4143 +       bus->sprom._field = ((sprom[SPOFF(_offset)] & (_mask)) >> (_shift))
4144 +
4145 +#define SPEX32(_field, _offset, _mask, _shift) \
4146 +       bus->sprom._field = ((((u32)sprom[SPOFF((_offset)+2)] << 16 | \
4147 +                               sprom[SPOFF(_offset)]) & (_mask)) >> (_shift))
4148 +
4149 +#define SPEX_ARRAY8(_field, _offset, _mask, _shift)    \
4150 +       do {    \
4151 +               SPEX(_field[0], _offset +  0, _mask, _shift);   \
4152 +               SPEX(_field[1], _offset +  2, _mask, _shift);   \
4153 +               SPEX(_field[2], _offset +  4, _mask, _shift);   \
4154 +               SPEX(_field[3], _offset +  6, _mask, _shift);   \
4155 +               SPEX(_field[4], _offset +  8, _mask, _shift);   \
4156 +               SPEX(_field[5], _offset + 10, _mask, _shift);   \
4157 +               SPEX(_field[6], _offset + 12, _mask, _shift);   \
4158 +               SPEX(_field[7], _offset + 14, _mask, _shift);   \
4159 +       } while (0)
4160 +
4161  static void bcma_sprom_extract_r8(struct bcma_bus *bus, const u16 *sprom)
4162  {
4163 -       u16 v;
4164 +       u16 v, o;
4165         int i;
4166 -
4167 -       bus->sprom.revision = sprom[SSB_SPROMSIZE_WORDS_R4 - 1] &
4168 -               SSB_SPROM_REVISION_REV;
4169 +       u16 pwr_info_offset[] = {
4170 +               SSB_SROM8_PWR_INFO_CORE0, SSB_SROM8_PWR_INFO_CORE1,
4171 +               SSB_SROM8_PWR_INFO_CORE2, SSB_SROM8_PWR_INFO_CORE3
4172 +       };
4173 +       BUILD_BUG_ON(ARRAY_SIZE(pwr_info_offset) !=
4174 +                       ARRAY_SIZE(bus->sprom.core_pwr_info));
4175  
4176         for (i = 0; i < 3; i++) {
4177                 v = sprom[SPOFF(SSB_SPROM8_IL0MAC) + i];
4178                 *(((__be16 *)bus->sprom.il0mac) + i) = cpu_to_be16(v);
4179         }
4180  
4181 -       bus->sprom.board_rev = sprom[SPOFF(SSB_SPROM8_BOARDREV)];
4182 +       SPEX(board_rev, SSB_SPROM8_BOARDREV, ~0, 0);
4183 +       SPEX(board_type, SSB_SPROM1_SPID, ~0, 0);
4184 +
4185 +       SPEX(txpid2g[0], SSB_SPROM4_TXPID2G01, SSB_SPROM4_TXPID2G0,
4186 +            SSB_SPROM4_TXPID2G0_SHIFT);
4187 +       SPEX(txpid2g[1], SSB_SPROM4_TXPID2G01, SSB_SPROM4_TXPID2G1,
4188 +            SSB_SPROM4_TXPID2G1_SHIFT);
4189 +       SPEX(txpid2g[2], SSB_SPROM4_TXPID2G23, SSB_SPROM4_TXPID2G2,
4190 +            SSB_SPROM4_TXPID2G2_SHIFT);
4191 +       SPEX(txpid2g[3], SSB_SPROM4_TXPID2G23, SSB_SPROM4_TXPID2G3,
4192 +            SSB_SPROM4_TXPID2G3_SHIFT);
4193 +
4194 +       SPEX(txpid5gl[0], SSB_SPROM4_TXPID5GL01, SSB_SPROM4_TXPID5GL0,
4195 +            SSB_SPROM4_TXPID5GL0_SHIFT);
4196 +       SPEX(txpid5gl[1], SSB_SPROM4_TXPID5GL01, SSB_SPROM4_TXPID5GL1,
4197 +            SSB_SPROM4_TXPID5GL1_SHIFT);
4198 +       SPEX(txpid5gl[2], SSB_SPROM4_TXPID5GL23, SSB_SPROM4_TXPID5GL2,
4199 +            SSB_SPROM4_TXPID5GL2_SHIFT);
4200 +       SPEX(txpid5gl[3], SSB_SPROM4_TXPID5GL23, SSB_SPROM4_TXPID5GL3,
4201 +            SSB_SPROM4_TXPID5GL3_SHIFT);
4202 +
4203 +       SPEX(txpid5g[0], SSB_SPROM4_TXPID5G01, SSB_SPROM4_TXPID5G0,
4204 +            SSB_SPROM4_TXPID5G0_SHIFT);
4205 +       SPEX(txpid5g[1], SSB_SPROM4_TXPID5G01, SSB_SPROM4_TXPID5G1,
4206 +            SSB_SPROM4_TXPID5G1_SHIFT);
4207 +       SPEX(txpid5g[2], SSB_SPROM4_TXPID5G23, SSB_SPROM4_TXPID5G2,
4208 +            SSB_SPROM4_TXPID5G2_SHIFT);
4209 +       SPEX(txpid5g[3], SSB_SPROM4_TXPID5G23, SSB_SPROM4_TXPID5G3,
4210 +            SSB_SPROM4_TXPID5G3_SHIFT);
4211 +
4212 +       SPEX(txpid5gh[0], SSB_SPROM4_TXPID5GH01, SSB_SPROM4_TXPID5GH0,
4213 +            SSB_SPROM4_TXPID5GH0_SHIFT);
4214 +       SPEX(txpid5gh[1], SSB_SPROM4_TXPID5GH01, SSB_SPROM4_TXPID5GH1,
4215 +            SSB_SPROM4_TXPID5GH1_SHIFT);
4216 +       SPEX(txpid5gh[2], SSB_SPROM4_TXPID5GH23, SSB_SPROM4_TXPID5GH2,
4217 +            SSB_SPROM4_TXPID5GH2_SHIFT);
4218 +       SPEX(txpid5gh[3], SSB_SPROM4_TXPID5GH23, SSB_SPROM4_TXPID5GH3,
4219 +            SSB_SPROM4_TXPID5GH3_SHIFT);
4220 +
4221 +       SPEX(boardflags_lo, SSB_SPROM8_BFLLO, ~0, 0);
4222 +       SPEX(boardflags_hi, SSB_SPROM8_BFLHI, ~0, 0);
4223 +       SPEX(boardflags2_lo, SSB_SPROM8_BFL2LO, ~0, 0);
4224 +       SPEX(boardflags2_hi, SSB_SPROM8_BFL2HI, ~0, 0);
4225 +
4226 +       SPEX(alpha2[0], SSB_SPROM8_CCODE, 0xff00, 8);
4227 +       SPEX(alpha2[1], SSB_SPROM8_CCODE, 0x00ff, 0);
4228 +
4229 +       /* Extract cores power info info */
4230 +       for (i = 0; i < ARRAY_SIZE(pwr_info_offset); i++) {
4231 +               o = pwr_info_offset[i];
4232 +               SPEX(core_pwr_info[i].itssi_2g, o + SSB_SROM8_2G_MAXP_ITSSI,
4233 +                       SSB_SPROM8_2G_ITSSI, SSB_SPROM8_2G_ITSSI_SHIFT);
4234 +               SPEX(core_pwr_info[i].maxpwr_2g, o + SSB_SROM8_2G_MAXP_ITSSI,
4235 +                       SSB_SPROM8_2G_MAXP, 0);
4236 +
4237 +               SPEX(core_pwr_info[i].pa_2g[0], o + SSB_SROM8_2G_PA_0, ~0, 0);
4238 +               SPEX(core_pwr_info[i].pa_2g[1], o + SSB_SROM8_2G_PA_1, ~0, 0);
4239 +               SPEX(core_pwr_info[i].pa_2g[2], o + SSB_SROM8_2G_PA_2, ~0, 0);
4240 +
4241 +               SPEX(core_pwr_info[i].itssi_5g, o + SSB_SROM8_5G_MAXP_ITSSI,
4242 +                       SSB_SPROM8_5G_ITSSI, SSB_SPROM8_5G_ITSSI_SHIFT);
4243 +               SPEX(core_pwr_info[i].maxpwr_5g, o + SSB_SROM8_5G_MAXP_ITSSI,
4244 +                       SSB_SPROM8_5G_MAXP, 0);
4245 +               SPEX(core_pwr_info[i].maxpwr_5gh, o + SSB_SPROM8_5GHL_MAXP,
4246 +                       SSB_SPROM8_5GH_MAXP, 0);
4247 +               SPEX(core_pwr_info[i].maxpwr_5gl, o + SSB_SPROM8_5GHL_MAXP,
4248 +                       SSB_SPROM8_5GL_MAXP, SSB_SPROM8_5GL_MAXP_SHIFT);
4249 +
4250 +               SPEX(core_pwr_info[i].pa_5gl[0], o + SSB_SROM8_5GL_PA_0, ~0, 0);
4251 +               SPEX(core_pwr_info[i].pa_5gl[1], o + SSB_SROM8_5GL_PA_1, ~0, 0);
4252 +               SPEX(core_pwr_info[i].pa_5gl[2], o + SSB_SROM8_5GL_PA_2, ~0, 0);
4253 +               SPEX(core_pwr_info[i].pa_5g[0], o + SSB_SROM8_5G_PA_0, ~0, 0);
4254 +               SPEX(core_pwr_info[i].pa_5g[1], o + SSB_SROM8_5G_PA_1, ~0, 0);
4255 +               SPEX(core_pwr_info[i].pa_5g[2], o + SSB_SROM8_5G_PA_2, ~0, 0);
4256 +               SPEX(core_pwr_info[i].pa_5gh[0], o + SSB_SROM8_5GH_PA_0, ~0, 0);
4257 +               SPEX(core_pwr_info[i].pa_5gh[1], o + SSB_SROM8_5GH_PA_1, ~0, 0);
4258 +               SPEX(core_pwr_info[i].pa_5gh[2], o + SSB_SROM8_5GH_PA_2, ~0, 0);
4259 +       }
4260 +
4261 +       SPEX(fem.ghz2.tssipos, SSB_SPROM8_FEM2G, SSB_SROM8_FEM_TSSIPOS,
4262 +            SSB_SROM8_FEM_TSSIPOS_SHIFT);
4263 +       SPEX(fem.ghz2.extpa_gain, SSB_SPROM8_FEM2G, SSB_SROM8_FEM_EXTPA_GAIN,
4264 +            SSB_SROM8_FEM_EXTPA_GAIN_SHIFT);
4265 +       SPEX(fem.ghz2.pdet_range, SSB_SPROM8_FEM2G, SSB_SROM8_FEM_PDET_RANGE,
4266 +            SSB_SROM8_FEM_PDET_RANGE_SHIFT);
4267 +       SPEX(fem.ghz2.tr_iso, SSB_SPROM8_FEM2G, SSB_SROM8_FEM_TR_ISO,
4268 +            SSB_SROM8_FEM_TR_ISO_SHIFT);
4269 +       SPEX(fem.ghz2.antswlut, SSB_SPROM8_FEM2G, SSB_SROM8_FEM_ANTSWLUT,
4270 +            SSB_SROM8_FEM_ANTSWLUT_SHIFT);
4271 +
4272 +       SPEX(fem.ghz5.tssipos, SSB_SPROM8_FEM5G, SSB_SROM8_FEM_TSSIPOS,
4273 +            SSB_SROM8_FEM_TSSIPOS_SHIFT);
4274 +       SPEX(fem.ghz5.extpa_gain, SSB_SPROM8_FEM5G, SSB_SROM8_FEM_EXTPA_GAIN,
4275 +            SSB_SROM8_FEM_EXTPA_GAIN_SHIFT);
4276 +       SPEX(fem.ghz5.pdet_range, SSB_SPROM8_FEM5G, SSB_SROM8_FEM_PDET_RANGE,
4277 +            SSB_SROM8_FEM_PDET_RANGE_SHIFT);
4278 +       SPEX(fem.ghz5.tr_iso, SSB_SPROM8_FEM5G, SSB_SROM8_FEM_TR_ISO,
4279 +            SSB_SROM8_FEM_TR_ISO_SHIFT);
4280 +       SPEX(fem.ghz5.antswlut, SSB_SPROM8_FEM5G, SSB_SROM8_FEM_ANTSWLUT,
4281 +            SSB_SROM8_FEM_ANTSWLUT_SHIFT);
4282 +
4283 +       SPEX(ant_available_a, SSB_SPROM8_ANTAVAIL, SSB_SPROM8_ANTAVAIL_A,
4284 +            SSB_SPROM8_ANTAVAIL_A_SHIFT);
4285 +       SPEX(ant_available_bg, SSB_SPROM8_ANTAVAIL, SSB_SPROM8_ANTAVAIL_BG,
4286 +            SSB_SPROM8_ANTAVAIL_BG_SHIFT);
4287 +       SPEX(maxpwr_bg, SSB_SPROM8_MAXP_BG, SSB_SPROM8_MAXP_BG_MASK, 0);
4288 +       SPEX(itssi_bg, SSB_SPROM8_MAXP_BG, SSB_SPROM8_ITSSI_BG,
4289 +            SSB_SPROM8_ITSSI_BG_SHIFT);
4290 +       SPEX(maxpwr_a, SSB_SPROM8_MAXP_A, SSB_SPROM8_MAXP_A_MASK, 0);
4291 +       SPEX(itssi_a, SSB_SPROM8_MAXP_A, SSB_SPROM8_ITSSI_A,
4292 +            SSB_SPROM8_ITSSI_A_SHIFT);
4293 +       SPEX(maxpwr_ah, SSB_SPROM8_MAXP_AHL, SSB_SPROM8_MAXP_AH_MASK, 0);
4294 +       SPEX(maxpwr_al, SSB_SPROM8_MAXP_AHL, SSB_SPROM8_MAXP_AL_MASK,
4295 +            SSB_SPROM8_MAXP_AL_SHIFT);
4296 +       SPEX(gpio0, SSB_SPROM8_GPIOA, SSB_SPROM8_GPIOA_P0, 0);
4297 +       SPEX(gpio1, SSB_SPROM8_GPIOA, SSB_SPROM8_GPIOA_P1,
4298 +            SSB_SPROM8_GPIOA_P1_SHIFT);
4299 +       SPEX(gpio2, SSB_SPROM8_GPIOB, SSB_SPROM8_GPIOB_P2, 0);
4300 +       SPEX(gpio3, SSB_SPROM8_GPIOB, SSB_SPROM8_GPIOB_P3,
4301 +            SSB_SPROM8_GPIOB_P3_SHIFT);
4302 +       SPEX(tri2g, SSB_SPROM8_TRI25G, SSB_SPROM8_TRI2G, 0);
4303 +       SPEX(tri5g, SSB_SPROM8_TRI25G, SSB_SPROM8_TRI5G,
4304 +            SSB_SPROM8_TRI5G_SHIFT);
4305 +       SPEX(tri5gl, SSB_SPROM8_TRI5GHL, SSB_SPROM8_TRI5GL, 0);
4306 +       SPEX(tri5gh, SSB_SPROM8_TRI5GHL, SSB_SPROM8_TRI5GH,
4307 +            SSB_SPROM8_TRI5GH_SHIFT);
4308 +       SPEX(rxpo2g, SSB_SPROM8_RXPO, SSB_SPROM8_RXPO2G,
4309 +            SSB_SPROM8_RXPO2G_SHIFT);
4310 +       SPEX(rxpo5g, SSB_SPROM8_RXPO, SSB_SPROM8_RXPO5G,
4311 +            SSB_SPROM8_RXPO5G_SHIFT);
4312 +       SPEX(rssismf2g, SSB_SPROM8_RSSIPARM2G, SSB_SPROM8_RSSISMF2G, 0);
4313 +       SPEX(rssismc2g, SSB_SPROM8_RSSIPARM2G, SSB_SPROM8_RSSISMC2G,
4314 +            SSB_SPROM8_RSSISMC2G_SHIFT);
4315 +       SPEX(rssisav2g, SSB_SPROM8_RSSIPARM2G, SSB_SPROM8_RSSISAV2G,
4316 +            SSB_SPROM8_RSSISAV2G_SHIFT);
4317 +       SPEX(bxa2g, SSB_SPROM8_RSSIPARM2G, SSB_SPROM8_BXA2G,
4318 +            SSB_SPROM8_BXA2G_SHIFT);
4319 +       SPEX(rssismf5g, SSB_SPROM8_RSSIPARM5G, SSB_SPROM8_RSSISMF5G, 0);
4320 +       SPEX(rssismc5g, SSB_SPROM8_RSSIPARM5G, SSB_SPROM8_RSSISMC5G,
4321 +            SSB_SPROM8_RSSISMC5G_SHIFT);
4322 +       SPEX(rssisav5g, SSB_SPROM8_RSSIPARM5G, SSB_SPROM8_RSSISAV5G,
4323 +            SSB_SPROM8_RSSISAV5G_SHIFT);
4324 +       SPEX(bxa5g, SSB_SPROM8_RSSIPARM5G, SSB_SPROM8_BXA5G,
4325 +            SSB_SPROM8_BXA5G_SHIFT);
4326 +
4327 +       SPEX(pa0b0, SSB_SPROM8_PA0B0, ~0, 0);
4328 +       SPEX(pa0b1, SSB_SPROM8_PA0B1, ~0, 0);
4329 +       SPEX(pa0b2, SSB_SPROM8_PA0B2, ~0, 0);
4330 +       SPEX(pa1b0, SSB_SPROM8_PA1B0, ~0, 0);
4331 +       SPEX(pa1b1, SSB_SPROM8_PA1B1, ~0, 0);
4332 +       SPEX(pa1b2, SSB_SPROM8_PA1B2, ~0, 0);
4333 +       SPEX(pa1lob0, SSB_SPROM8_PA1LOB0, ~0, 0);
4334 +       SPEX(pa1lob1, SSB_SPROM8_PA1LOB1, ~0, 0);
4335 +       SPEX(pa1lob2, SSB_SPROM8_PA1LOB2, ~0, 0);
4336 +       SPEX(pa1hib0, SSB_SPROM8_PA1HIB0, ~0, 0);
4337 +       SPEX(pa1hib1, SSB_SPROM8_PA1HIB1, ~0, 0);
4338 +       SPEX(pa1hib2, SSB_SPROM8_PA1HIB2, ~0, 0);
4339 +       SPEX(cck2gpo, SSB_SPROM8_CCK2GPO, ~0, 0);
4340 +       SPEX32(ofdm2gpo, SSB_SPROM8_OFDM2GPO, ~0, 0);
4341 +       SPEX32(ofdm5glpo, SSB_SPROM8_OFDM5GLPO, ~0, 0);
4342 +       SPEX32(ofdm5gpo, SSB_SPROM8_OFDM5GPO, ~0, 0);
4343 +       SPEX32(ofdm5ghpo, SSB_SPROM8_OFDM5GHPO, ~0, 0);
4344 +
4345 +       /* Extract the antenna gain values. */
4346 +       SPEX(antenna_gain.a0, SSB_SPROM8_AGAIN01,
4347 +            SSB_SPROM8_AGAIN0, SSB_SPROM8_AGAIN0_SHIFT);
4348 +       SPEX(antenna_gain.a1, SSB_SPROM8_AGAIN01,
4349 +            SSB_SPROM8_AGAIN1, SSB_SPROM8_AGAIN1_SHIFT);
4350 +       SPEX(antenna_gain.a2, SSB_SPROM8_AGAIN23,
4351 +            SSB_SPROM8_AGAIN2, SSB_SPROM8_AGAIN2_SHIFT);
4352 +       SPEX(antenna_gain.a3, SSB_SPROM8_AGAIN23,
4353 +            SSB_SPROM8_AGAIN3, SSB_SPROM8_AGAIN3_SHIFT);
4354 +
4355 +       SPEX(leddc_on_time, SSB_SPROM8_LEDDC, SSB_SPROM8_LEDDC_ON,
4356 +            SSB_SPROM8_LEDDC_ON_SHIFT);
4357 +       SPEX(leddc_off_time, SSB_SPROM8_LEDDC, SSB_SPROM8_LEDDC_OFF,
4358 +            SSB_SPROM8_LEDDC_OFF_SHIFT);
4359 +
4360 +       SPEX(txchain, SSB_SPROM8_TXRXC, SSB_SPROM8_TXRXC_TXCHAIN,
4361 +            SSB_SPROM8_TXRXC_TXCHAIN_SHIFT);
4362 +       SPEX(rxchain, SSB_SPROM8_TXRXC, SSB_SPROM8_TXRXC_RXCHAIN,
4363 +            SSB_SPROM8_TXRXC_RXCHAIN_SHIFT);
4364 +       SPEX(antswitch, SSB_SPROM8_TXRXC, SSB_SPROM8_TXRXC_SWITCH,
4365 +            SSB_SPROM8_TXRXC_SWITCH_SHIFT);
4366 +
4367 +       SPEX(opo, SSB_SPROM8_OFDM2GPO, 0x00ff, 0);
4368 +
4369 +       SPEX_ARRAY8(mcs2gpo, SSB_SPROM8_2G_MCSPO, ~0, 0);
4370 +       SPEX_ARRAY8(mcs5gpo, SSB_SPROM8_5G_MCSPO, ~0, 0);
4371 +       SPEX_ARRAY8(mcs5glpo, SSB_SPROM8_5GL_MCSPO, ~0, 0);
4372 +       SPEX_ARRAY8(mcs5ghpo, SSB_SPROM8_5GH_MCSPO, ~0, 0);
4373 +
4374 +       SPEX(rawtempsense, SSB_SPROM8_RAWTS, SSB_SPROM8_RAWTS_RAWTEMP,
4375 +            SSB_SPROM8_RAWTS_RAWTEMP_SHIFT);
4376 +       SPEX(measpower, SSB_SPROM8_RAWTS, SSB_SPROM8_RAWTS_MEASPOWER,
4377 +            SSB_SPROM8_RAWTS_MEASPOWER_SHIFT);
4378 +       SPEX(tempsense_slope, SSB_SPROM8_OPT_CORRX,
4379 +            SSB_SPROM8_OPT_CORRX_TEMP_SLOPE,
4380 +            SSB_SPROM8_OPT_CORRX_TEMP_SLOPE_SHIFT);
4381 +       SPEX(tempcorrx, SSB_SPROM8_OPT_CORRX, SSB_SPROM8_OPT_CORRX_TEMPCORRX,
4382 +            SSB_SPROM8_OPT_CORRX_TEMPCORRX_SHIFT);
4383 +       SPEX(tempsense_option, SSB_SPROM8_OPT_CORRX,
4384 +            SSB_SPROM8_OPT_CORRX_TEMP_OPTION,
4385 +            SSB_SPROM8_OPT_CORRX_TEMP_OPTION_SHIFT);
4386 +       SPEX(freqoffset_corr, SSB_SPROM8_HWIQ_IQSWP,
4387 +            SSB_SPROM8_HWIQ_IQSWP_FREQ_CORR,
4388 +            SSB_SPROM8_HWIQ_IQSWP_FREQ_CORR_SHIFT);
4389 +       SPEX(iqcal_swp_dis, SSB_SPROM8_HWIQ_IQSWP,
4390 +            SSB_SPROM8_HWIQ_IQSWP_IQCAL_SWP,
4391 +            SSB_SPROM8_HWIQ_IQSWP_IQCAL_SWP_SHIFT);
4392 +       SPEX(hw_iqcal_en, SSB_SPROM8_HWIQ_IQSWP, SSB_SPROM8_HWIQ_IQSWP_HW_IQCAL,
4393 +            SSB_SPROM8_HWIQ_IQSWP_HW_IQCAL_SHIFT);
4394 +
4395 +       SPEX(bw40po, SSB_SPROM8_BW40PO, ~0, 0);
4396 +       SPEX(cddpo, SSB_SPROM8_CDDPO, ~0, 0);
4397 +       SPEX(stbcpo, SSB_SPROM8_STBCPO, ~0, 0);
4398 +       SPEX(bwduppo, SSB_SPROM8_BWDUPPO, ~0, 0);
4399 +
4400 +       SPEX(tempthresh, SSB_SPROM8_THERMAL, SSB_SPROM8_THERMAL_TRESH,
4401 +            SSB_SPROM8_THERMAL_TRESH_SHIFT);
4402 +       SPEX(tempoffset, SSB_SPROM8_THERMAL, SSB_SPROM8_THERMAL_OFFSET,
4403 +            SSB_SPROM8_THERMAL_OFFSET_SHIFT);
4404 +       SPEX(phycal_tempdelta, SSB_SPROM8_TEMPDELTA,
4405 +            SSB_SPROM8_TEMPDELTA_PHYCAL,
4406 +            SSB_SPROM8_TEMPDELTA_PHYCAL_SHIFT);
4407 +       SPEX(temps_period, SSB_SPROM8_TEMPDELTA, SSB_SPROM8_TEMPDELTA_PERIOD,
4408 +            SSB_SPROM8_TEMPDELTA_PERIOD_SHIFT);
4409 +       SPEX(temps_hysteresis, SSB_SPROM8_TEMPDELTA,
4410 +            SSB_SPROM8_TEMPDELTA_HYSTERESIS,
4411 +            SSB_SPROM8_TEMPDELTA_HYSTERESIS_SHIFT);
4412 +}
4413 +
4414 +/*
4415 + * Indicates the presence of external SPROM.
4416 + */
4417 +static bool bcma_sprom_ext_available(struct bcma_bus *bus)
4418 +{
4419 +       u32 chip_status;
4420 +       u32 srom_control;
4421 +       u32 present_mask;
4422 +
4423 +       if (bus->drv_cc.core->id.rev >= 31) {
4424 +               if (!(bus->drv_cc.capabilities & BCMA_CC_CAP_SPROM))
4425 +                       return false;
4426 +
4427 +               srom_control = bcma_read32(bus->drv_cc.core,
4428 +                                          BCMA_CC_SROM_CONTROL);
4429 +               return srom_control & BCMA_CC_SROM_CONTROL_PRESENT;
4430 +       }
4431 +
4432 +       /* older chipcommon revisions use chip status register */
4433 +       chip_status = bcma_read32(bus->drv_cc.core, BCMA_CC_CHIPSTAT);
4434 +       switch (bus->chipinfo.id) {
4435 +       case BCMA_CHIP_ID_BCM4313:
4436 +               present_mask = BCMA_CC_CHIPST_4313_SPROM_PRESENT;
4437 +               break;
4438 +
4439 +       case BCMA_CHIP_ID_BCM4331:
4440 +               present_mask = BCMA_CC_CHIPST_4331_SPROM_PRESENT;
4441 +               break;
4442  
4443 -       bus->sprom.txpid2g[0] = (sprom[SPOFF(SSB_SPROM4_TXPID2G01)] &
4444 -            SSB_SPROM4_TXPID2G0) >> SSB_SPROM4_TXPID2G0_SHIFT;
4445 -       bus->sprom.txpid2g[1] = (sprom[SPOFF(SSB_SPROM4_TXPID2G01)] &
4446 -            SSB_SPROM4_TXPID2G1) >> SSB_SPROM4_TXPID2G1_SHIFT;
4447 -       bus->sprom.txpid2g[2] = (sprom[SPOFF(SSB_SPROM4_TXPID2G23)] &
4448 -            SSB_SPROM4_TXPID2G2) >> SSB_SPROM4_TXPID2G2_SHIFT;
4449 -       bus->sprom.txpid2g[3] = (sprom[SPOFF(SSB_SPROM4_TXPID2G23)] &
4450 -            SSB_SPROM4_TXPID2G3) >> SSB_SPROM4_TXPID2G3_SHIFT;
4451 -
4452 -       bus->sprom.txpid5gl[0] = (sprom[SPOFF(SSB_SPROM4_TXPID5GL01)] &
4453 -            SSB_SPROM4_TXPID5GL0) >> SSB_SPROM4_TXPID5GL0_SHIFT;
4454 -       bus->sprom.txpid5gl[1] = (sprom[SPOFF(SSB_SPROM4_TXPID5GL01)] &
4455 -            SSB_SPROM4_TXPID5GL1) >> SSB_SPROM4_TXPID5GL1_SHIFT;
4456 -       bus->sprom.txpid5gl[2] = (sprom[SPOFF(SSB_SPROM4_TXPID5GL23)] &
4457 -            SSB_SPROM4_TXPID5GL2) >> SSB_SPROM4_TXPID5GL2_SHIFT;
4458 -       bus->sprom.txpid5gl[3] = (sprom[SPOFF(SSB_SPROM4_TXPID5GL23)] &
4459 -            SSB_SPROM4_TXPID5GL3) >> SSB_SPROM4_TXPID5GL3_SHIFT;
4460 -
4461 -       bus->sprom.txpid5g[0] = (sprom[SPOFF(SSB_SPROM4_TXPID5G01)] &
4462 -            SSB_SPROM4_TXPID5G0) >> SSB_SPROM4_TXPID5G0_SHIFT;
4463 -       bus->sprom.txpid5g[1] = (sprom[SPOFF(SSB_SPROM4_TXPID5G01)] &
4464 -            SSB_SPROM4_TXPID5G1) >> SSB_SPROM4_TXPID5G1_SHIFT;
4465 -       bus->sprom.txpid5g[2] = (sprom[SPOFF(SSB_SPROM4_TXPID5G23)] &
4466 -            SSB_SPROM4_TXPID5G2) >> SSB_SPROM4_TXPID5G2_SHIFT;
4467 -       bus->sprom.txpid5g[3] = (sprom[SPOFF(SSB_SPROM4_TXPID5G23)] &
4468 -            SSB_SPROM4_TXPID5G3) >> SSB_SPROM4_TXPID5G3_SHIFT;
4469 -
4470 -       bus->sprom.txpid5gh[0] = (sprom[SPOFF(SSB_SPROM4_TXPID5GH01)] &
4471 -            SSB_SPROM4_TXPID5GH0) >> SSB_SPROM4_TXPID5GH0_SHIFT;
4472 -       bus->sprom.txpid5gh[1] = (sprom[SPOFF(SSB_SPROM4_TXPID5GH01)] &
4473 -            SSB_SPROM4_TXPID5GH1) >> SSB_SPROM4_TXPID5GH1_SHIFT;
4474 -       bus->sprom.txpid5gh[2] = (sprom[SPOFF(SSB_SPROM4_TXPID5GH23)] &
4475 -            SSB_SPROM4_TXPID5GH2) >> SSB_SPROM4_TXPID5GH2_SHIFT;
4476 -       bus->sprom.txpid5gh[3] = (sprom[SPOFF(SSB_SPROM4_TXPID5GH23)] &
4477 -            SSB_SPROM4_TXPID5GH3) >> SSB_SPROM4_TXPID5GH3_SHIFT;
4478 -
4479 -       bus->sprom.boardflags_lo = sprom[SPOFF(SSB_SPROM8_BFLLO)];
4480 -       bus->sprom.boardflags_hi = sprom[SPOFF(SSB_SPROM8_BFLHI)];
4481 -       bus->sprom.boardflags2_lo = sprom[SPOFF(SSB_SPROM8_BFL2LO)];
4482 -       bus->sprom.boardflags2_hi = sprom[SPOFF(SSB_SPROM8_BFL2HI)];
4483 -
4484 -       bus->sprom.country_code = sprom[SPOFF(SSB_SPROM8_CCODE)];
4485 -
4486 -       bus->sprom.fem.ghz2.tssipos = (sprom[SPOFF(SSB_SPROM8_FEM2G)] &
4487 -               SSB_SROM8_FEM_TSSIPOS) >> SSB_SROM8_FEM_TSSIPOS_SHIFT;
4488 -       bus->sprom.fem.ghz2.extpa_gain = (sprom[SPOFF(SSB_SPROM8_FEM2G)] &
4489 -               SSB_SROM8_FEM_EXTPA_GAIN) >> SSB_SROM8_FEM_EXTPA_GAIN_SHIFT;
4490 -       bus->sprom.fem.ghz2.pdet_range = (sprom[SPOFF(SSB_SPROM8_FEM2G)] &
4491 -               SSB_SROM8_FEM_PDET_RANGE) >> SSB_SROM8_FEM_PDET_RANGE_SHIFT;
4492 -       bus->sprom.fem.ghz2.tr_iso = (sprom[SPOFF(SSB_SPROM8_FEM2G)] &
4493 -               SSB_SROM8_FEM_TR_ISO) >> SSB_SROM8_FEM_TR_ISO_SHIFT;
4494 -       bus->sprom.fem.ghz2.antswlut = (sprom[SPOFF(SSB_SPROM8_FEM2G)] &
4495 -               SSB_SROM8_FEM_ANTSWLUT) >> SSB_SROM8_FEM_ANTSWLUT_SHIFT;
4496 -
4497 -       bus->sprom.fem.ghz5.tssipos = (sprom[SPOFF(SSB_SPROM8_FEM5G)] &
4498 -               SSB_SROM8_FEM_TSSIPOS) >> SSB_SROM8_FEM_TSSIPOS_SHIFT;
4499 -       bus->sprom.fem.ghz5.extpa_gain = (sprom[SPOFF(SSB_SPROM8_FEM5G)] &
4500 -               SSB_SROM8_FEM_EXTPA_GAIN) >> SSB_SROM8_FEM_EXTPA_GAIN_SHIFT;
4501 -       bus->sprom.fem.ghz5.pdet_range = (sprom[SPOFF(SSB_SPROM8_FEM5G)] &
4502 -               SSB_SROM8_FEM_PDET_RANGE) >> SSB_SROM8_FEM_PDET_RANGE_SHIFT;
4503 -       bus->sprom.fem.ghz5.tr_iso = (sprom[SPOFF(SSB_SPROM8_FEM5G)] &
4504 -               SSB_SROM8_FEM_TR_ISO) >> SSB_SROM8_FEM_TR_ISO_SHIFT;
4505 -       bus->sprom.fem.ghz5.antswlut = (sprom[SPOFF(SSB_SPROM8_FEM5G)] &
4506 -               SSB_SROM8_FEM_ANTSWLUT) >> SSB_SROM8_FEM_ANTSWLUT_SHIFT;
4507 +       default:
4508 +               return true;
4509 +       }
4510 +
4511 +       return chip_status & present_mask;
4512 +}
4513 +
4514 +/*
4515 + * Indicates that on-chip OTP memory is present and enabled.
4516 + */
4517 +static bool bcma_sprom_onchip_available(struct bcma_bus *bus)
4518 +{
4519 +       u32 chip_status;
4520 +       u32 otpsize = 0;
4521 +       bool present;
4522 +
4523 +       chip_status = bcma_read32(bus->drv_cc.core, BCMA_CC_CHIPSTAT);
4524 +       switch (bus->chipinfo.id) {
4525 +       case BCMA_CHIP_ID_BCM4313:
4526 +               present = chip_status & BCMA_CC_CHIPST_4313_OTP_PRESENT;
4527 +               break;
4528 +
4529 +       case BCMA_CHIP_ID_BCM4331:
4530 +               present = chip_status & BCMA_CC_CHIPST_4331_OTP_PRESENT;
4531 +               break;
4532 +       case BCMA_CHIP_ID_BCM43142:
4533 +       case BCMA_CHIP_ID_BCM43224:
4534 +       case BCMA_CHIP_ID_BCM43225:
4535 +               /* for these chips OTP is always available */
4536 +               present = true;
4537 +               break;
4538 +       case BCMA_CHIP_ID_BCM43227:
4539 +       case BCMA_CHIP_ID_BCM43228:
4540 +       case BCMA_CHIP_ID_BCM43428:
4541 +               present = chip_status & BCMA_CC_CHIPST_43228_OTP_PRESENT;
4542 +               break;
4543 +       default:
4544 +               present = false;
4545 +               break;
4546 +       }
4547 +
4548 +       if (present) {
4549 +               otpsize = bus->drv_cc.capabilities & BCMA_CC_CAP_OTPS;
4550 +               otpsize >>= BCMA_CC_CAP_OTPS_SHIFT;
4551 +       }
4552 +
4553 +       return otpsize != 0;
4554 +}
4555 +
4556 +/*
4557 + * Verify OTP is filled and determine the byte
4558 + * offset where SPROM data is located.
4559 + *
4560 + * On error, returns 0; byte offset otherwise.
4561 + */
4562 +static int bcma_sprom_onchip_offset(struct bcma_bus *bus)
4563 +{
4564 +       struct bcma_device *cc = bus->drv_cc.core;
4565 +       u32 offset;
4566 +
4567 +       /* verify OTP status */
4568 +       if ((bcma_read32(cc, BCMA_CC_OTPS) & BCMA_CC_OTPS_GU_PROG_HW) == 0)
4569 +               return 0;
4570 +
4571 +       /* obtain bit offset from otplayout register */
4572 +       offset = (bcma_read32(cc, BCMA_CC_OTPL) & BCMA_CC_OTPL_GURGN_OFFSET);
4573 +       return BCMA_CC_SPROM + (offset >> 3);
4574  }
4575  
4576  int bcma_sprom_get(struct bcma_bus *bus)
4577  {
4578 -       u16 offset;
4579 +       u16 offset = BCMA_CC_SPROM;
4580         u16 *sprom;
4581 -       int err = 0;
4582 +       size_t sprom_sizes[] = { SSB_SPROMSIZE_WORDS_R4,
4583 +                                SSB_SPROMSIZE_WORDS_R10, };
4584 +       int i, err = 0;
4585  
4586         if (!bus->drv_cc.core)
4587                 return -EOPNOTSUPP;
4588  
4589 -       if (!(bus->drv_cc.capabilities & BCMA_CC_CAP_SPROM))
4590 -               return -ENOENT;
4591 +       if (!bcma_sprom_ext_available(bus)) {
4592 +               bool sprom_onchip;
4593  
4594 -       sprom = kcalloc(SSB_SPROMSIZE_WORDS_R4, sizeof(u16),
4595 -                       GFP_KERNEL);
4596 -       if (!sprom)
4597 -               return -ENOMEM;
4598 +               /*
4599 +                * External SPROM takes precedence so check
4600 +                * on-chip OTP only when no external SPROM
4601 +                * is present.
4602 +                */
4603 +               sprom_onchip = bcma_sprom_onchip_available(bus);
4604 +               if (sprom_onchip) {
4605 +                       /* determine offset */
4606 +                       offset = bcma_sprom_onchip_offset(bus);
4607 +               }
4608 +               if (!offset || !sprom_onchip) {
4609 +                       /*
4610 +                        * Maybe there is no SPROM on the device?
4611 +                        * Now we ask the arch code if there is some sprom
4612 +                        * available for this device in some other storage.
4613 +                        */
4614 +                       err = bcma_fill_sprom_with_fallback(bus, &bus->sprom);
4615 +                       return err;
4616 +               }
4617 +       }
4618  
4619 -       if (bus->chipinfo.id == 0x4331)
4620 +       if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4331 ||
4621 +           bus->chipinfo.id == BCMA_CHIP_ID_BCM43431)
4622                 bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, false);
4623  
4624 -       /* Most cards have SPROM moved by additional offset 0x30 (48 dwords).
4625 -        * According to brcm80211 this applies to cards with PCIe rev >= 6
4626 -        * TODO: understand this condition and use it */
4627 -       offset = (bus->chipinfo.id == 0x4331) ? BCMA_CC_SPROM :
4628 -               BCMA_CC_SPROM_PCIE6;
4629 -       bcma_sprom_read(bus, offset, sprom);
4630 +       bcma_debug(bus, "SPROM offset 0x%x\n", offset);
4631 +       for (i = 0; i < ARRAY_SIZE(sprom_sizes); i++) {
4632 +               size_t words = sprom_sizes[i];
4633 +
4634 +               sprom = kcalloc(words, sizeof(u16), GFP_KERNEL);
4635 +               if (!sprom)
4636 +                       return -ENOMEM;
4637 +
4638 +               bcma_sprom_read(bus, offset, sprom, words);
4639 +               err = bcma_sprom_valid(bus, sprom, words);
4640 +               if (!err)
4641 +                       break;
4642  
4643 -       if (bus->chipinfo.id == 0x4331)
4644 -               bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, true);
4645 +               kfree(sprom);
4646 +       }
4647  
4648 -       err = bcma_sprom_valid(sprom);
4649 -       if (err)
4650 -               goto out;
4651 +       if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4331 ||
4652 +           bus->chipinfo.id == BCMA_CHIP_ID_BCM43431)
4653 +               bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, true);
4654  
4655 -       bcma_sprom_extract_r8(bus, sprom);
4656 +       if (err) {
4657 +               bcma_warn(bus, "Invalid SPROM read from the PCIe card, trying to use fallback SPROM\n");
4658 +               err = bcma_fill_sprom_with_fallback(bus, &bus->sprom);
4659 +       } else {
4660 +               bcma_sprom_extract_r8(bus, sprom);
4661 +               kfree(sprom);
4662 +       }
4663  
4664 -out:
4665 -       kfree(sprom);
4666         return err;
4667  }
4668 --- a/include/linux/bcma/bcma.h
4669 +++ b/include/linux/bcma/bcma.h
4670 @@ -7,9 +7,10 @@
4671  #include <linux/bcma/bcma_driver_chipcommon.h>
4672  #include <linux/bcma/bcma_driver_pci.h>
4673  #include <linux/bcma/bcma_driver_mips.h>
4674 +#include <linux/bcma/bcma_driver_gmac_cmn.h>
4675  #include <linux/ssb/ssb.h> /* SPROM sharing */
4676  
4677 -#include "bcma_regs.h"
4678 +#include <linux/bcma/bcma_regs.h>
4679  
4680  struct bcma_device;
4681  struct bcma_bus;
4682 @@ -26,6 +27,11 @@ struct bcma_chipinfo {
4683         u8 pkg;
4684  };
4685  
4686 +struct bcma_boardinfo {
4687 +       u16 vendor;
4688 +       u16 type;
4689 +};
4690 +
4691  enum bcma_clkmode {
4692         BCMA_CLKMODE_FAST,
4693         BCMA_CLKMODE_DYNAMIC,
4694 @@ -65,6 +71,25 @@ struct bcma_host_ops {
4695  
4696  /* Core-ID values. */
4697  #define BCMA_CORE_OOB_ROUTER           0x367   /* Out of band */
4698 +#define BCMA_CORE_4706_CHIPCOMMON      0x500
4699 +#define BCMA_CORE_PCIEG2               0x501
4700 +#define BCMA_CORE_DMA                  0x502
4701 +#define BCMA_CORE_SDIO3                        0x503
4702 +#define BCMA_CORE_USB20                        0x504
4703 +#define BCMA_CORE_USB30                        0x505
4704 +#define BCMA_CORE_A9JTAG               0x506
4705 +#define BCMA_CORE_DDR23                        0x507
4706 +#define BCMA_CORE_ROM                  0x508
4707 +#define BCMA_CORE_NAND                 0x509
4708 +#define BCMA_CORE_QSPI                 0x50A
4709 +#define BCMA_CORE_CHIPCOMMON_B         0x50B
4710 +#define BCMA_CORE_4706_SOC_RAM         0x50E
4711 +#define BCMA_CORE_ARMCA9               0x510
4712 +#define BCMA_CORE_4706_MAC_GBIT                0x52D
4713 +#define BCMA_CORE_AMEMC                        0x52E   /* DDR1/2 memory controller core */
4714 +#define BCMA_CORE_ALTA                 0x534   /* I2S core */
4715 +#define BCMA_CORE_4706_MAC_GBIT_COMMON 0x5DC
4716 +#define BCMA_CORE_DDR23_PHY            0x5DD
4717  #define BCMA_CORE_INVALID              0x700
4718  #define BCMA_CORE_CHIPCOMMON           0x800
4719  #define BCMA_CORE_ILINE20              0x801
4720 @@ -121,10 +146,112 @@ struct bcma_host_ops {
4721  #define BCMA_CORE_I2S                  0x834
4722  #define BCMA_CORE_SDR_DDR1_MEM_CTL     0x835   /* SDR/DDR1 memory controller core */
4723  #define BCMA_CORE_SHIM                 0x837   /* SHIM component in ubus/6362 */
4724 +#define BCMA_CORE_PHY_AC               0x83B
4725 +#define BCMA_CORE_PCIE2                        0x83C   /* PCI Express Gen2 */
4726 +#define BCMA_CORE_USB30_DEV            0x83D
4727 +#define BCMA_CORE_ARM_CR4              0x83E
4728  #define BCMA_CORE_DEFAULT              0xFFF
4729  
4730  #define BCMA_MAX_NR_CORES              16
4731  
4732 +/* Chip IDs of PCIe devices */
4733 +#define BCMA_CHIP_ID_BCM4313   0x4313
4734 +#define BCMA_CHIP_ID_BCM43142  43142
4735 +#define BCMA_CHIP_ID_BCM43131  43131
4736 +#define BCMA_CHIP_ID_BCM43217  43217
4737 +#define BCMA_CHIP_ID_BCM43222  43222
4738 +#define BCMA_CHIP_ID_BCM43224  43224
4739 +#define  BCMA_PKG_ID_BCM43224_FAB_CSM  0x8
4740 +#define  BCMA_PKG_ID_BCM43224_FAB_SMIC 0xa
4741 +#define BCMA_CHIP_ID_BCM43225  43225
4742 +#define BCMA_CHIP_ID_BCM43227  43227
4743 +#define BCMA_CHIP_ID_BCM43228  43228
4744 +#define BCMA_CHIP_ID_BCM43421  43421
4745 +#define BCMA_CHIP_ID_BCM43428  43428
4746 +#define BCMA_CHIP_ID_BCM43431  43431
4747 +#define BCMA_CHIP_ID_BCM43460  43460
4748 +#define BCMA_CHIP_ID_BCM4331   0x4331
4749 +#define BCMA_CHIP_ID_BCM6362   0x6362
4750 +#define BCMA_CHIP_ID_BCM4360   0x4360
4751 +#define BCMA_CHIP_ID_BCM4352   0x4352
4752 +
4753 +/* Chip IDs of SoCs */
4754 +#define BCMA_CHIP_ID_BCM4706   0x5300
4755 +#define  BCMA_PKG_ID_BCM4706L  1
4756 +#define BCMA_CHIP_ID_BCM4716   0x4716
4757 +#define  BCMA_PKG_ID_BCM4716   8
4758 +#define  BCMA_PKG_ID_BCM4717   9
4759 +#define  BCMA_PKG_ID_BCM4718   10
4760 +#define BCMA_CHIP_ID_BCM47162  47162
4761 +#define BCMA_CHIP_ID_BCM4748   0x4748
4762 +#define BCMA_CHIP_ID_BCM4749   0x4749
4763 +#define BCMA_CHIP_ID_BCM5356   0x5356
4764 +#define BCMA_CHIP_ID_BCM5357   0x5357
4765 +#define  BCMA_PKG_ID_BCM5358   9
4766 +#define  BCMA_PKG_ID_BCM47186  10
4767 +#define  BCMA_PKG_ID_BCM5357   11
4768 +#define BCMA_CHIP_ID_BCM53572  53572
4769 +#define  BCMA_PKG_ID_BCM47188  9
4770 +#define BCMA_CHIP_ID_BCM4707   53010
4771 +#define  BCMA_PKG_ID_BCM4707   1
4772 +#define  BCMA_PKG_ID_BCM4708   2
4773 +#define  BCMA_PKG_ID_BCM4709   0
4774 +#define BCMA_CHIP_ID_BCM53018  53018
4775 +
4776 +/* Board types (on PCI usually equals to the subsystem dev id) */
4777 +/* BCM4313 */
4778 +#define BCMA_BOARD_TYPE_BCM94313BU     0X050F
4779 +#define BCMA_BOARD_TYPE_BCM94313HM     0X0510
4780 +#define BCMA_BOARD_TYPE_BCM94313EPA    0X0511
4781 +#define BCMA_BOARD_TYPE_BCM94313HMG    0X051C
4782 +/* BCM4716 */
4783 +#define BCMA_BOARD_TYPE_BCM94716NR2    0X04CD
4784 +/* BCM43224 */
4785 +#define BCMA_BOARD_TYPE_BCM943224X21   0X056E
4786 +#define BCMA_BOARD_TYPE_BCM943224X21_FCC       0X00D1
4787 +#define BCMA_BOARD_TYPE_BCM943224X21B  0X00E9
4788 +#define BCMA_BOARD_TYPE_BCM943224M93   0X008B
4789 +#define BCMA_BOARD_TYPE_BCM943224M93A  0X0090
4790 +#define BCMA_BOARD_TYPE_BCM943224X16   0X0093
4791 +#define BCMA_BOARD_TYPE_BCM94322X9     0X008D
4792 +#define BCMA_BOARD_TYPE_BCM94322M35E   0X008E
4793 +/* BCM43228 */
4794 +#define BCMA_BOARD_TYPE_BCM943228BU8   0X0540
4795 +#define BCMA_BOARD_TYPE_BCM943228BU9   0X0541
4796 +#define BCMA_BOARD_TYPE_BCM943228BU    0X0542
4797 +#define BCMA_BOARD_TYPE_BCM943227HM4L  0X0543
4798 +#define BCMA_BOARD_TYPE_BCM943227HMB   0X0544
4799 +#define BCMA_BOARD_TYPE_BCM943228HM4L  0X0545
4800 +#define BCMA_BOARD_TYPE_BCM943228SD    0X0573
4801 +/* BCM4331 */
4802 +#define BCMA_BOARD_TYPE_BCM94331X19    0X00D6
4803 +#define BCMA_BOARD_TYPE_BCM94331X28    0X00E4
4804 +#define BCMA_BOARD_TYPE_BCM94331X28B   0X010E
4805 +#define BCMA_BOARD_TYPE_BCM94331PCIEBT3AX      0X00E4
4806 +#define BCMA_BOARD_TYPE_BCM94331X12_2G 0X00EC
4807 +#define BCMA_BOARD_TYPE_BCM94331X12_5G 0X00ED
4808 +#define BCMA_BOARD_TYPE_BCM94331X29B   0X00EF
4809 +#define BCMA_BOARD_TYPE_BCM94331CSAX   0X00EF
4810 +#define BCMA_BOARD_TYPE_BCM94331X19C   0X00F5
4811 +#define BCMA_BOARD_TYPE_BCM94331X33    0X00F4
4812 +#define BCMA_BOARD_TYPE_BCM94331BU     0X0523
4813 +#define BCMA_BOARD_TYPE_BCM94331S9BU   0X0524
4814 +#define BCMA_BOARD_TYPE_BCM94331MC     0X0525
4815 +#define BCMA_BOARD_TYPE_BCM94331MCI    0X0526
4816 +#define BCMA_BOARD_TYPE_BCM94331PCIEBT4        0X0527
4817 +#define BCMA_BOARD_TYPE_BCM94331HM     0X0574
4818 +#define BCMA_BOARD_TYPE_BCM94331PCIEDUAL       0X059B
4819 +#define BCMA_BOARD_TYPE_BCM94331MCH5   0X05A9
4820 +#define BCMA_BOARD_TYPE_BCM94331CS     0X05C6
4821 +#define BCMA_BOARD_TYPE_BCM94331CD     0X05DA
4822 +/* BCM53572 */
4823 +#define BCMA_BOARD_TYPE_BCM953572BU    0X058D
4824 +#define BCMA_BOARD_TYPE_BCM953572NR2   0X058E
4825 +#define BCMA_BOARD_TYPE_BCM947188NR2   0X058F
4826 +#define BCMA_BOARD_TYPE_BCM953572SDRNR2        0X0590
4827 +/* BCM43142 */
4828 +#define BCMA_BOARD_TYPE_BCM943142HM    0X05E0
4829 +
4830  struct bcma_device {
4831         struct bcma_bus *bus;
4832         struct bcma_device_id id;
4833 @@ -136,8 +263,10 @@ struct bcma_device {
4834         bool dev_registered;
4835  
4836         u8 core_index;
4837 +       u8 core_unit;
4838  
4839         u32 addr;
4840 +       u32 addr1;
4841         u32 wrap;
4842  
4843         void __iomem *io_addr;
4844 @@ -175,6 +304,12 @@ int __bcma_driver_register(struct bcma_d
4845  
4846  extern void bcma_driver_unregister(struct bcma_driver *drv);
4847  
4848 +/* Set a fallback SPROM.
4849 + * See kdoc at the function definition for complete documentation. */
4850 +extern int bcma_arch_register_fallback_sprom(
4851 +               int (*sprom_callback)(struct bcma_bus *bus,
4852 +               struct ssb_sprom *out));
4853 +
4854  struct bcma_bus {
4855         /* The MMIO area. */
4856         void __iomem *mmio;
4857 @@ -191,14 +326,18 @@ struct bcma_bus {
4858  
4859         struct bcma_chipinfo chipinfo;
4860  
4861 +       struct bcma_boardinfo boardinfo;
4862 +
4863         struct bcma_device *mapped_core;
4864         struct list_head cores;
4865         u8 nr_cores;
4866         u8 init_done:1;
4867 +       u8 num;
4868  
4869         struct bcma_drv_cc drv_cc;
4870 -       struct bcma_drv_pci drv_pci;
4871 +       struct bcma_drv_pci drv_pci[2];
4872         struct bcma_drv_mips drv_mips;
4873 +       struct bcma_drv_gmac_cmn drv_gmac_cmn;
4874  
4875         /* We decided to share SPROM struct with SSB as long as we do not need
4876          * any hacks for BCMA. This simplifies drivers code. */
4877 @@ -282,6 +421,7 @@ static inline void bcma_maskset16(struct
4878         bcma_write16(cc, offset, (bcma_read16(cc, offset) & mask) | set);
4879  }
4880  
4881 +extern struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid);
4882  extern bool bcma_core_is_enabled(struct bcma_device *core);
4883  extern void bcma_core_disable(struct bcma_device *core, u32 flags);
4884  extern int bcma_core_enable(struct bcma_device *core, u32 flags);
4885 @@ -289,6 +429,7 @@ extern void bcma_core_set_clockmode(stru
4886                                     enum bcma_clkmode clkmode);
4887  extern void bcma_core_pll_ctl(struct bcma_device *core, u32 req, u32 status,
4888                               bool on);
4889 +extern u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset);
4890  #define BCMA_DMA_TRANSLATION_MASK      0xC0000000
4891  #define  BCMA_DMA_TRANSLATION_NONE     0x00000000
4892  #define  BCMA_DMA_TRANSLATION_DMA32_CMT        0x40000000 /* Client Mode Translation for 32-bit DMA */
4893 --- a/include/linux/bcma/bcma_driver_chipcommon.h
4894 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
4895 @@ -1,6 +1,9 @@
4896  #ifndef LINUX_BCMA_DRIVER_CC_H_
4897  #define LINUX_BCMA_DRIVER_CC_H_
4898  
4899 +#include <linux/platform_device.h>
4900 +#include <linux/gpio.h>
4901 +
4902  /** ChipCommon core registers. **/
4903  #define BCMA_CC_ID                     0x0000
4904  #define  BCMA_CC_ID_ID                 0x0000FFFF
4905 @@ -24,7 +27,7 @@
4906  #define   BCMA_CC_FLASHT_NONE          0x00000000      /* No flash */
4907  #define   BCMA_CC_FLASHT_STSER         0x00000100      /* ST serial flash */
4908  #define   BCMA_CC_FLASHT_ATSER         0x00000200      /* Atmel serial flash */
4909 -#define   BCMA_CC_FLASHT_NFLASH                0x00000200
4910 +#define   BCMA_CC_FLASHT_NAND          0x00000300      /* NAND flash */
4911  #define          BCMA_CC_FLASHT_PARA           0x00000700      /* Parallel flash */
4912  #define  BCMA_CC_CAP_PLLT              0x00038000      /* PLL Type */
4913  #define   BCMA_PLLTYPE_NONE            0x00000000
4914 @@ -45,6 +48,7 @@
4915  #define  BCMA_CC_CAP_PMU               0x10000000      /* PMU available (rev >= 20) */
4916  #define  BCMA_CC_CAP_ECI               0x20000000      /* ECI available (rev >= 20) */
4917  #define  BCMA_CC_CAP_SPROM             0x40000000      /* SPROM present */
4918 +#define  BCMA_CC_CAP_NFLASH            0x80000000      /* NAND flash present (rev >= 35 or BCM4706?) */
4919  #define BCMA_CC_CORECTL                        0x0008
4920  #define  BCMA_CC_CORECTL_UARTCLK0      0x00000001      /* Drive UART with internal clock */
4921  #define         BCMA_CC_CORECTL_SE             0x00000002      /* sync clk out enable (corerev >= 3) */
4922 @@ -56,6 +60,9 @@
4923  #define         BCMA_CC_OTPS_HW_PROTECT        0x00000001
4924  #define         BCMA_CC_OTPS_SW_PROTECT        0x00000002
4925  #define         BCMA_CC_OTPS_CID_PROTECT       0x00000004
4926 +#define  BCMA_CC_OTPS_GU_PROG_IND      0x00000F00      /* General Use programmed indication */
4927 +#define  BCMA_CC_OTPS_GU_PROG_IND_SHIFT        8
4928 +#define  BCMA_CC_OTPS_GU_PROG_HW       0x00000100      /* HW region programmed */
4929  #define BCMA_CC_OTPC                   0x0014          /* OTP control */
4930  #define         BCMA_CC_OTPC_RECWAIT           0xFF000000
4931  #define         BCMA_CC_OTPC_PROGWAIT          0x00FFFF00
4932 @@ -72,6 +79,8 @@
4933  #define         BCMA_CC_OTPP_READ              0x40000000
4934  #define         BCMA_CC_OTPP_START             0x80000000
4935  #define         BCMA_CC_OTPP_BUSY              0x80000000
4936 +#define BCMA_CC_OTPL                   0x001C          /* OTP layout */
4937 +#define  BCMA_CC_OTPL_GURGN_OFFSET     0x00000FFF      /* offset of general use region */
4938  #define BCMA_CC_IRQSTAT                        0x0020
4939  #define BCMA_CC_IRQMASK                        0x0024
4940  #define         BCMA_CC_IRQ_GPIO               0x00000001      /* gpio intr */
4941 @@ -79,6 +88,23 @@
4942  #define         BCMA_CC_IRQ_WDRESET            0x80000000      /* watchdog reset occurred */
4943  #define BCMA_CC_CHIPCTL                        0x0028          /* Rev >= 11 only */
4944  #define BCMA_CC_CHIPSTAT               0x002C          /* Rev >= 11 only */
4945 +#define  BCMA_CC_CHIPST_4313_SPROM_PRESENT     1
4946 +#define  BCMA_CC_CHIPST_4313_OTP_PRESENT       2
4947 +#define  BCMA_CC_CHIPST_4331_SPROM_PRESENT     2
4948 +#define  BCMA_CC_CHIPST_4331_OTP_PRESENT       4
4949 +#define  BCMA_CC_CHIPST_43228_ILP_DIV_EN       0x00000001
4950 +#define  BCMA_CC_CHIPST_43228_OTP_PRESENT      0x00000002
4951 +#define  BCMA_CC_CHIPST_43228_SERDES_REFCLK_PADSEL     0x00000004
4952 +#define  BCMA_CC_CHIPST_43228_SDIO_MODE                0x00000008
4953 +#define  BCMA_CC_CHIPST_43228_SDIO_OTP_PRESENT 0x00000010
4954 +#define  BCMA_CC_CHIPST_43228_SDIO_RESET       0x00000020
4955 +#define  BCMA_CC_CHIPST_4706_PKG_OPTION                BIT(0) /* 0: full-featured package 1: low-cost package */
4956 +#define  BCMA_CC_CHIPST_4706_SFLASH_PRESENT    BIT(1) /* 0: parallel, 1: serial flash is present */
4957 +#define  BCMA_CC_CHIPST_4706_SFLASH_TYPE       BIT(2) /* 0: 8b-p/ST-s flash, 1: 16b-p/Atmal-s flash */
4958 +#define  BCMA_CC_CHIPST_4706_MIPS_BENDIAN      BIT(3) /* 0: little, 1: big endian */
4959 +#define  BCMA_CC_CHIPST_4706_PCIE1_DISABLE     BIT(5) /* PCIE1 enable strap pin */
4960 +#define  BCMA_CC_CHIPST_5357_NAND_BOOT         BIT(4) /* NAND boot, valid for CC rev 38 and/or BCM5357 */
4961 +#define  BCMA_CC_CHIPST_4360_XTAL_40MZ         0x00000001
4962  #define BCMA_CC_JCMD                   0x0030          /* Rev >= 10 only */
4963  #define  BCMA_CC_JCMD_START            0x80000000
4964  #define  BCMA_CC_JCMD_BUSY             0x80000000
4965 @@ -108,10 +134,58 @@
4966  #define  BCMA_CC_JCTL_EXT_EN           2               /* Enable external targets */
4967  #define  BCMA_CC_JCTL_EN               1               /* Enable Jtag master */
4968  #define BCMA_CC_FLASHCTL               0x0040
4969 +/* Start/busy bit in flashcontrol */
4970 +#define  BCMA_CC_FLASHCTL_OPCODE       0x000000ff
4971 +#define  BCMA_CC_FLASHCTL_ACTION       0x00000700
4972 +#define  BCMA_CC_FLASHCTL_CS_ACTIVE    0x00001000      /* Chip Select Active, rev >= 20 */
4973  #define  BCMA_CC_FLASHCTL_START                0x80000000
4974  #define  BCMA_CC_FLASHCTL_BUSY         BCMA_CC_FLASHCTL_START
4975 +/* Flashcontrol action + opcodes for ST flashes */
4976 +#define  BCMA_CC_FLASHCTL_ST_WREN      0x0006          /* Write Enable */
4977 +#define  BCMA_CC_FLASHCTL_ST_WRDIS     0x0004          /* Write Disable */
4978 +#define  BCMA_CC_FLASHCTL_ST_RDSR      0x0105          /* Read Status Register */
4979 +#define  BCMA_CC_FLASHCTL_ST_WRSR      0x0101          /* Write Status Register */
4980 +#define  BCMA_CC_FLASHCTL_ST_READ      0x0303          /* Read Data Bytes */
4981 +#define  BCMA_CC_FLASHCTL_ST_PP                0x0302          /* Page Program */
4982 +#define  BCMA_CC_FLASHCTL_ST_SE                0x02d8          /* Sector Erase */
4983 +#define  BCMA_CC_FLASHCTL_ST_BE                0x00c7          /* Bulk Erase */
4984 +#define  BCMA_CC_FLASHCTL_ST_DP                0x00b9          /* Deep Power-down */
4985 +#define  BCMA_CC_FLASHCTL_ST_RES       0x03ab          /* Read Electronic Signature */
4986 +#define  BCMA_CC_FLASHCTL_ST_CSA       0x1000          /* Keep chip select asserted */
4987 +#define  BCMA_CC_FLASHCTL_ST_SSE       0x0220          /* Sub-sector Erase */
4988 +/* Flashcontrol action + opcodes for Atmel flashes */
4989 +#define  BCMA_CC_FLASHCTL_AT_READ                      0x07e8
4990 +#define  BCMA_CC_FLASHCTL_AT_PAGE_READ                 0x07d2
4991 +#define  BCMA_CC_FLASHCTL_AT_STATUS                    0x01d7
4992 +#define  BCMA_CC_FLASHCTL_AT_BUF1_WRITE                        0x0384
4993 +#define  BCMA_CC_FLASHCTL_AT_BUF2_WRITE                        0x0387
4994 +#define  BCMA_CC_FLASHCTL_AT_BUF1_ERASE_PROGRAM                0x0283
4995 +#define  BCMA_CC_FLASHCTL_AT_BUF2_ERASE_PROGRAM                0x0286
4996 +#define  BCMA_CC_FLASHCTL_AT_BUF1_PROGRAM              0x0288
4997 +#define  BCMA_CC_FLASHCTL_AT_BUF2_PROGRAM              0x0289
4998 +#define  BCMA_CC_FLASHCTL_AT_PAGE_ERASE                        0x0281
4999 +#define  BCMA_CC_FLASHCTL_AT_BLOCK_ERASE               0x0250
5000 +#define  BCMA_CC_FLASHCTL_AT_BUF1_WRITE_ERASE_PROGRAM  0x0382
5001 +#define  BCMA_CC_FLASHCTL_AT_BUF2_WRITE_ERASE_PROGRAM  0x0385
5002 +#define  BCMA_CC_FLASHCTL_AT_BUF1_LOAD                 0x0253
5003 +#define  BCMA_CC_FLASHCTL_AT_BUF2_LOAD                 0x0255
5004 +#define  BCMA_CC_FLASHCTL_AT_BUF1_COMPARE              0x0260
5005 +#define  BCMA_CC_FLASHCTL_AT_BUF2_COMPARE              0x0261
5006 +#define  BCMA_CC_FLASHCTL_AT_BUF1_REPROGRAM            0x0258
5007 +#define  BCMA_CC_FLASHCTL_AT_BUF2_REPROGRAM            0x0259
5008  #define BCMA_CC_FLASHADDR              0x0044
5009  #define BCMA_CC_FLASHDATA              0x0048
5010 +/* Status register bits for ST flashes */
5011 +#define  BCMA_CC_FLASHDATA_ST_WIP      0x01            /* Write In Progress */
5012 +#define  BCMA_CC_FLASHDATA_ST_WEL      0x02            /* Write Enable Latch */
5013 +#define  BCMA_CC_FLASHDATA_ST_BP_MASK  0x1c            /* Block Protect */
5014 +#define  BCMA_CC_FLASHDATA_ST_BP_SHIFT 2
5015 +#define  BCMA_CC_FLASHDATA_ST_SRWD     0x80            /* Status Register Write Disable */
5016 +/* Status register bits for Atmel flashes */
5017 +#define  BCMA_CC_FLASHDATA_AT_READY    0x80
5018 +#define  BCMA_CC_FLASHDATA_AT_MISMATCH 0x40
5019 +#define  BCMA_CC_FLASHDATA_AT_ID_MASK  0x38
5020 +#define  BCMA_CC_FLASHDATA_AT_ID_SHIFT 3
5021  #define BCMA_CC_BCAST_ADDR             0x0050
5022  #define BCMA_CC_BCAST_DATA             0x0054
5023  #define BCMA_CC_GPIOPULLUP             0x0058          /* Rev >= 20 only */
5024 @@ -181,6 +255,45 @@
5025  #define BCMA_CC_FLASH_CFG              0x0128
5026  #define  BCMA_CC_FLASH_CFG_DS          0x0010  /* Data size, 0=8bit, 1=16bit */
5027  #define BCMA_CC_FLASH_WAITCNT          0x012C
5028 +#define BCMA_CC_SROM_CONTROL           0x0190
5029 +#define  BCMA_CC_SROM_CONTROL_START    0x80000000
5030 +#define  BCMA_CC_SROM_CONTROL_BUSY     0x80000000
5031 +#define  BCMA_CC_SROM_CONTROL_OPCODE   0x60000000
5032 +#define  BCMA_CC_SROM_CONTROL_OP_READ  0x00000000
5033 +#define  BCMA_CC_SROM_CONTROL_OP_WRITE 0x20000000
5034 +#define  BCMA_CC_SROM_CONTROL_OP_WRDIS 0x40000000
5035 +#define  BCMA_CC_SROM_CONTROL_OP_WREN  0x60000000
5036 +#define  BCMA_CC_SROM_CONTROL_OTPSEL   0x00000010
5037 +#define  BCMA_CC_SROM_CONTROL_LOCK     0x00000008
5038 +#define  BCMA_CC_SROM_CONTROL_SIZE_MASK        0x00000006
5039 +#define  BCMA_CC_SROM_CONTROL_SIZE_1K  0x00000000
5040 +#define  BCMA_CC_SROM_CONTROL_SIZE_4K  0x00000002
5041 +#define  BCMA_CC_SROM_CONTROL_SIZE_16K 0x00000004
5042 +#define  BCMA_CC_SROM_CONTROL_SIZE_SHIFT       1
5043 +#define  BCMA_CC_SROM_CONTROL_PRESENT  0x00000001
5044 +/* Block 0x140 - 0x190 registers are chipset specific */
5045 +#define BCMA_CC_4706_FLASHSCFG         0x18C           /* Flash struct configuration */
5046 +#define  BCMA_CC_4706_FLASHSCFG_MASK   0x000000ff
5047 +#define  BCMA_CC_4706_FLASHSCFG_SF1    0x00000001      /* 2nd serial flash present */
5048 +#define  BCMA_CC_4706_FLASHSCFG_PF1    0x00000002      /* 2nd parallel flash present */
5049 +#define  BCMA_CC_4706_FLASHSCFG_SF1_TYPE       0x00000004      /* 2nd serial flash type : 0 : ST, 1 : Atmel */
5050 +#define  BCMA_CC_4706_FLASHSCFG_NF1    0x00000008      /* 2nd NAND flash present */
5051 +#define  BCMA_CC_4706_FLASHSCFG_1ST_MADDR_SEG_MASK     0x000000f0
5052 +#define  BCMA_CC_4706_FLASHSCFG_1ST_MADDR_SEG_4MB      0x00000010      /* 4MB */
5053 +#define  BCMA_CC_4706_FLASHSCFG_1ST_MADDR_SEG_8MB      0x00000020      /* 8MB */
5054 +#define  BCMA_CC_4706_FLASHSCFG_1ST_MADDR_SEG_16MB     0x00000030      /* 16MB */
5055 +#define  BCMA_CC_4706_FLASHSCFG_1ST_MADDR_SEG_32MB     0x00000040      /* 32MB */
5056 +#define  BCMA_CC_4706_FLASHSCFG_1ST_MADDR_SEG_64MB     0x00000050      /* 64MB */
5057 +#define  BCMA_CC_4706_FLASHSCFG_1ST_MADDR_SEG_128MB    0x00000060      /* 128MB */
5058 +#define  BCMA_CC_4706_FLASHSCFG_1ST_MADDR_SEG_256MB    0x00000070      /* 256MB */
5059 +/* NAND flash registers for BCM4706 (corerev = 31) */
5060 +#define BCMA_CC_NFLASH_CTL             0x01A0
5061 +#define  BCMA_CC_NFLASH_CTL_ERR                0x08000000
5062 +#define BCMA_CC_NFLASH_CONF            0x01A4
5063 +#define BCMA_CC_NFLASH_COL_ADDR                0x01A8
5064 +#define BCMA_CC_NFLASH_ROW_ADDR                0x01AC
5065 +#define BCMA_CC_NFLASH_DATA            0x01B0
5066 +#define BCMA_CC_NFLASH_WAITCNT0                0x01B4
5067  /* 0x1E0 is defined as shared BCMA_CLKCTLST */
5068  #define BCMA_CC_HW_WORKAROUND          0x01E4 /* Hardware workaround (rev >= 20) */
5069  #define BCMA_CC_UART0_DATA             0x0300
5070 @@ -203,6 +316,9 @@
5071  #define BCMA_CC_PMU_CTL                        0x0600 /* PMU control */
5072  #define  BCMA_CC_PMU_CTL_ILP_DIV       0xFFFF0000 /* ILP div mask */
5073  #define  BCMA_CC_PMU_CTL_ILP_DIV_SHIFT 16
5074 +#define  BCMA_CC_PMU_CTL_RES           0x00006000 /* reset control mask */
5075 +#define  BCMA_CC_PMU_CTL_RES_SHIFT     13
5076 +#define  BCMA_CC_PMU_CTL_RES_RELOAD    0x2     /* reload POR values */
5077  #define  BCMA_CC_PMU_CTL_PLL_UPD       0x00000400
5078  #define  BCMA_CC_PMU_CTL_NOILPONW      0x00000200 /* No ILP on wait */
5079  #define  BCMA_CC_PMU_CTL_HTREQEN       0x00000100 /* HT req enable */
5080 @@ -214,6 +330,8 @@
5081  #define BCMA_CC_PMU_CAP                        0x0604 /* PMU capabilities */
5082  #define  BCMA_CC_PMU_CAP_REVISION      0x000000FF /* Revision mask */
5083  #define BCMA_CC_PMU_STAT               0x0608 /* PMU status */
5084 +#define  BCMA_CC_PMU_STAT_EXT_LPO_AVAIL        0x00000100
5085 +#define  BCMA_CC_PMU_STAT_WDRESET      0x00000080
5086  #define  BCMA_CC_PMU_STAT_INTPEND      0x00000040 /* Interrupt pending */
5087  #define  BCMA_CC_PMU_STAT_SBCLKST      0x00000030 /* Backplane clock status? */
5088  #define  BCMA_CC_PMU_STAT_HAVEALP      0x00000008 /* ALP available */
5089 @@ -239,8 +357,66 @@
5090  #define BCMA_CC_REGCTL_DATA            0x065C
5091  #define BCMA_CC_PLLCTL_ADDR            0x0660
5092  #define BCMA_CC_PLLCTL_DATA            0x0664
5093 +#define BCMA_CC_PMU_STRAPOPT           0x0668 /* (corerev >= 28) */
5094 +#define BCMA_CC_PMU_XTAL_FREQ          0x066C /* (pmurev >= 10) */
5095 +#define  BCMA_CC_PMU_XTAL_FREQ_ILPCTL_MASK     0x00001FFF
5096 +#define  BCMA_CC_PMU_XTAL_FREQ_MEASURE_MASK    0x80000000
5097 +#define  BCMA_CC_PMU_XTAL_FREQ_MEASURE_SHIFT   31
5098  #define BCMA_CC_SPROM                  0x0800 /* SPROM beginning */
5099 -#define BCMA_CC_SPROM_PCIE6            0x0830 /* SPROM beginning on PCIe rev >= 6 */
5100 +/* NAND flash MLC controller registers (corerev >= 38) */
5101 +#define BCMA_CC_NAND_REVISION          0x0C00
5102 +#define BCMA_CC_NAND_CMD_START         0x0C04
5103 +#define BCMA_CC_NAND_CMD_ADDR_X                0x0C08
5104 +#define BCMA_CC_NAND_CMD_ADDR          0x0C0C
5105 +#define BCMA_CC_NAND_CMD_END_ADDR      0x0C10
5106 +#define BCMA_CC_NAND_CS_NAND_SELECT    0x0C14
5107 +#define BCMA_CC_NAND_CS_NAND_XOR       0x0C18
5108 +#define BCMA_CC_NAND_SPARE_RD0         0x0C20
5109 +#define BCMA_CC_NAND_SPARE_RD4         0x0C24
5110 +#define BCMA_CC_NAND_SPARE_RD8         0x0C28
5111 +#define BCMA_CC_NAND_SPARE_RD12                0x0C2C
5112 +#define BCMA_CC_NAND_SPARE_WR0         0x0C30
5113 +#define BCMA_CC_NAND_SPARE_WR4         0x0C34
5114 +#define BCMA_CC_NAND_SPARE_WR8         0x0C38
5115 +#define BCMA_CC_NAND_SPARE_WR12                0x0C3C
5116 +#define BCMA_CC_NAND_ACC_CONTROL       0x0C40
5117 +#define BCMA_CC_NAND_CONFIG            0x0C48
5118 +#define BCMA_CC_NAND_TIMING_1          0x0C50
5119 +#define BCMA_CC_NAND_TIMING_2          0x0C54
5120 +#define BCMA_CC_NAND_SEMAPHORE         0x0C58
5121 +#define BCMA_CC_NAND_DEVID             0x0C60
5122 +#define BCMA_CC_NAND_DEVID_X           0x0C64
5123 +#define BCMA_CC_NAND_BLOCK_LOCK_STATUS 0x0C68
5124 +#define BCMA_CC_NAND_INTFC_STATUS      0x0C6C
5125 +#define BCMA_CC_NAND_ECC_CORR_ADDR_X   0x0C70
5126 +#define BCMA_CC_NAND_ECC_CORR_ADDR     0x0C74
5127 +#define BCMA_CC_NAND_ECC_UNC_ADDR_X    0x0C78
5128 +#define BCMA_CC_NAND_ECC_UNC_ADDR      0x0C7C
5129 +#define BCMA_CC_NAND_READ_ERROR_COUNT  0x0C80
5130 +#define BCMA_CC_NAND_CORR_STAT_THRESHOLD       0x0C84
5131 +#define BCMA_CC_NAND_READ_ADDR_X       0x0C90
5132 +#define BCMA_CC_NAND_READ_ADDR         0x0C94
5133 +#define BCMA_CC_NAND_PAGE_PROGRAM_ADDR_X       0x0C98
5134 +#define BCMA_CC_NAND_PAGE_PROGRAM_ADDR 0x0C9C
5135 +#define BCMA_CC_NAND_COPY_BACK_ADDR_X  0x0CA0
5136 +#define BCMA_CC_NAND_COPY_BACK_ADDR    0x0CA4
5137 +#define BCMA_CC_NAND_BLOCK_ERASE_ADDR_X        0x0CA8
5138 +#define BCMA_CC_NAND_BLOCK_ERASE_ADDR  0x0CAC
5139 +#define BCMA_CC_NAND_INV_READ_ADDR_X   0x0CB0
5140 +#define BCMA_CC_NAND_INV_READ_ADDR     0x0CB4
5141 +#define BCMA_CC_NAND_BLK_WR_PROTECT    0x0CC0
5142 +#define BCMA_CC_NAND_ACC_CONTROL_CS1   0x0CD0
5143 +#define BCMA_CC_NAND_CONFIG_CS1                0x0CD4
5144 +#define BCMA_CC_NAND_TIMING_1_CS1      0x0CD8
5145 +#define BCMA_CC_NAND_TIMING_2_CS1      0x0CDC
5146 +#define BCMA_CC_NAND_SPARE_RD16                0x0D30
5147 +#define BCMA_CC_NAND_SPARE_RD20                0x0D34
5148 +#define BCMA_CC_NAND_SPARE_RD24                0x0D38
5149 +#define BCMA_CC_NAND_SPARE_RD28                0x0D3C
5150 +#define BCMA_CC_NAND_CACHE_ADDR                0x0D40
5151 +#define BCMA_CC_NAND_CACHE_DATA                0x0D44
5152 +#define BCMA_CC_NAND_CTRL_CONFIG       0x0D48
5153 +#define BCMA_CC_NAND_CTRL_STATUS       0x0D4C
5154  
5155  /* Divider allocation in 4716/47162/5356 */
5156  #define BCMA_CC_PMU5_MAINPLL_CPU       1
5157 @@ -256,6 +432,32 @@
5158  
5159  /* 4706 PMU */
5160  #define BCMA_CC_PMU4706_MAINPLL_PLL0   0
5161 +#define BCMA_CC_PMU6_4706_PROCPLL_OFF  4       /* The CPU PLL */
5162 +#define  BCMA_CC_PMU6_4706_PROC_P2DIV_MASK     0x000f0000
5163 +#define  BCMA_CC_PMU6_4706_PROC_P2DIV_SHIFT    16
5164 +#define  BCMA_CC_PMU6_4706_PROC_P1DIV_MASK     0x0000f000
5165 +#define  BCMA_CC_PMU6_4706_PROC_P1DIV_SHIFT    12
5166 +#define  BCMA_CC_PMU6_4706_PROC_NDIV_INT_MASK  0x00000ff8
5167 +#define  BCMA_CC_PMU6_4706_PROC_NDIV_INT_SHIFT 3
5168 +#define  BCMA_CC_PMU6_4706_PROC_NDIV_MODE_MASK 0x00000007
5169 +#define  BCMA_CC_PMU6_4706_PROC_NDIV_MODE_SHIFT        0
5170 +
5171 +/* PMU rev 15 */
5172 +#define BCMA_CC_PMU15_PLL_PLLCTL0      0
5173 +#define  BCMA_CC_PMU15_PLL_PC0_CLKSEL_MASK     0x00000003
5174 +#define  BCMA_CC_PMU15_PLL_PC0_CLKSEL_SHIFT    0
5175 +#define  BCMA_CC_PMU15_PLL_PC0_FREQTGT_MASK    0x003FFFFC
5176 +#define  BCMA_CC_PMU15_PLL_PC0_FREQTGT_SHIFT   2
5177 +#define  BCMA_CC_PMU15_PLL_PC0_PRESCALE_MASK   0x00C00000
5178 +#define  BCMA_CC_PMU15_PLL_PC0_PRESCALE_SHIFT  22
5179 +#define  BCMA_CC_PMU15_PLL_PC0_KPCTRL_MASK     0x07000000
5180 +#define  BCMA_CC_PMU15_PLL_PC0_KPCTRL_SHIFT    24
5181 +#define  BCMA_CC_PMU15_PLL_PC0_FCNTCTRL_MASK   0x38000000
5182 +#define  BCMA_CC_PMU15_PLL_PC0_FCNTCTRL_SHIFT  27
5183 +#define  BCMA_CC_PMU15_PLL_PC0_FDCMODE_MASK    0x40000000
5184 +#define  BCMA_CC_PMU15_PLL_PC0_FDCMODE_SHIFT   30
5185 +#define  BCMA_CC_PMU15_PLL_PC0_CTRLBIAS_MASK   0x80000000
5186 +#define  BCMA_CC_PMU15_PLL_PC0_CTRLBIAS_SHIFT  31
5187  
5188  /* ALP clock on pre-PMU chips */
5189  #define BCMA_CC_PMU_ALP_CLOCK          20000000
5190 @@ -284,6 +486,19 @@
5191  #define BCMA_CC_PPL_PCHI_OFF           5
5192  #define BCMA_CC_PPL_PCHI_MASK          0x0000003f
5193  
5194 +#define BCMA_CC_PMU_PLL_CTL0           0
5195 +#define BCMA_CC_PMU_PLL_CTL1           1
5196 +#define BCMA_CC_PMU_PLL_CTL2           2
5197 +#define BCMA_CC_PMU_PLL_CTL3           3
5198 +#define BCMA_CC_PMU_PLL_CTL4           4
5199 +#define BCMA_CC_PMU_PLL_CTL5           5
5200 +
5201 +#define BCMA_CC_PMU1_PLL0_PC0_P1DIV_MASK       0x00f00000
5202 +#define BCMA_CC_PMU1_PLL0_PC0_P1DIV_SHIFT      20
5203 +
5204 +#define BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_MASK    0x1ff00000
5205 +#define BCMA_CC_PMU1_PLL0_PC2_NDIV_INT_SHIFT   20
5206 +
5207  /* BCM4331 ChipControl numbers. */
5208  #define BCMA_CHIPCTL_4331_BT_COEXIST           BIT(0)  /* 0 disable */
5209  #define BCMA_CHIPCTL_4331_SECI                 BIT(1)  /* 0 SECI is disabled (JATG functional) */
5210 @@ -297,9 +512,56 @@
5211  #define BCMA_CHIPCTL_4331_OVR_PIPEAUXPWRDOWN   BIT(9)  /* override core control on pipe_AuxPowerDown */
5212  #define BCMA_CHIPCTL_4331_PCIE_AUXCLKEN                BIT(10) /* pcie_auxclkenable */
5213  #define BCMA_CHIPCTL_4331_PCIE_PIPE_PLLDOWN    BIT(11) /* pcie_pipe_pllpowerdown */
5214 +#define BCMA_CHIPCTL_4331_EXTPA_EN2            BIT(12) /* 0 ext pa disable, 1 ext pa enabled */
5215  #define BCMA_CHIPCTL_4331_BT_SHD0_ON_GPIO4     BIT(16) /* enable bt_shd0 at gpio4 */
5216  #define BCMA_CHIPCTL_4331_BT_SHD1_ON_GPIO5     BIT(17) /* enable bt_shd1 at gpio5 */
5217  
5218 +/* 43224 chip-specific ChipControl register bits */
5219 +#define BCMA_CCTRL_43224_GPIO_TOGGLE           0x8000          /* gpio[3:0] pins as btcoex or s/w gpio */
5220 +#define BCMA_CCTRL_43224A0_12MA_LED_DRIVE      0x00F000F0      /* 12 mA drive strength */
5221 +#define BCMA_CCTRL_43224B0_12MA_LED_DRIVE      0xF0            /* 12 mA drive strength for later 43224s */
5222 +
5223 +/* 4313 Chip specific ChipControl register bits */
5224 +#define BCMA_CCTRL_4313_12MA_LED_DRIVE         0x00000007      /* 12 mA drive strengh for later 4313 */
5225 +
5226 +/* BCM5357 ChipControl register bits */
5227 +#define BCMA_CHIPCTL_5357_EXTPA                        BIT(14)
5228 +#define BCMA_CHIPCTL_5357_ANT_MUX_2O3          BIT(15)
5229 +#define BCMA_CHIPCTL_5357_NFLASH               BIT(16)
5230 +#define BCMA_CHIPCTL_5357_I2S_PINS_ENABLE      BIT(18)
5231 +#define BCMA_CHIPCTL_5357_I2CSPI_PINS_ENABLE   BIT(19)
5232 +
5233 +#define BCMA_RES_4314_LPLDO_PU                 BIT(0)
5234 +#define BCMA_RES_4314_PMU_SLEEP_DIS            BIT(1)
5235 +#define BCMA_RES_4314_PMU_BG_PU                        BIT(2)
5236 +#define BCMA_RES_4314_CBUCK_LPOM_PU            BIT(3)
5237 +#define BCMA_RES_4314_CBUCK_PFM_PU             BIT(4)
5238 +#define BCMA_RES_4314_CLDO_PU                  BIT(5)
5239 +#define BCMA_RES_4314_LPLDO2_LVM               BIT(6)
5240 +#define BCMA_RES_4314_WL_PMU_PU                        BIT(7)
5241 +#define BCMA_RES_4314_LNLDO_PU                 BIT(8)
5242 +#define BCMA_RES_4314_LDO3P3_PU                        BIT(9)
5243 +#define BCMA_RES_4314_OTP_PU                   BIT(10)
5244 +#define BCMA_RES_4314_XTAL_PU                  BIT(11)
5245 +#define BCMA_RES_4314_WL_PWRSW_PU              BIT(12)
5246 +#define BCMA_RES_4314_LQ_AVAIL                 BIT(13)
5247 +#define BCMA_RES_4314_LOGIC_RET                        BIT(14)
5248 +#define BCMA_RES_4314_MEM_SLEEP                        BIT(15)
5249 +#define BCMA_RES_4314_MACPHY_RET               BIT(16)
5250 +#define BCMA_RES_4314_WL_CORE_READY            BIT(17)
5251 +#define BCMA_RES_4314_ILP_REQ                  BIT(18)
5252 +#define BCMA_RES_4314_ALP_AVAIL                        BIT(19)
5253 +#define BCMA_RES_4314_MISC_PWRSW_PU            BIT(20)
5254 +#define BCMA_RES_4314_SYNTH_PWRSW_PU           BIT(21)
5255 +#define BCMA_RES_4314_RX_PWRSW_PU              BIT(22)
5256 +#define BCMA_RES_4314_RADIO_PU                 BIT(23)
5257 +#define BCMA_RES_4314_VCO_LDO_PU               BIT(24)
5258 +#define BCMA_RES_4314_AFE_LDO_PU               BIT(25)
5259 +#define BCMA_RES_4314_RX_LDO_PU                        BIT(26)
5260 +#define BCMA_RES_4314_TX_LDO_PU                        BIT(27)
5261 +#define BCMA_RES_4314_HT_AVAIL                 BIT(28)
5262 +#define BCMA_RES_4314_MACPHY_CLK_AVAIL         BIT(29)
5263 +
5264  /* Data for the PMU, if available.
5265   * Check availability with ((struct bcma_chipcommon)->capabilities & BCMA_CC_CAP_PMU)
5266   */
5267 @@ -310,11 +572,36 @@ struct bcma_chipcommon_pmu {
5268  
5269  #ifdef CONFIG_BCMA_DRIVER_MIPS
5270  struct bcma_pflash {
5271 +       bool present;
5272         u8 buswidth;
5273         u32 window;
5274         u32 window_size;
5275  };
5276  
5277 +#ifdef CONFIG_BCMA_SFLASH
5278 +struct bcma_sflash {
5279 +       bool present;
5280 +       u32 window;
5281 +       u32 blocksize;
5282 +       u16 numblocks;
5283 +       u32 size;
5284 +
5285 +       struct mtd_info *mtd;
5286 +       void *priv;
5287 +};
5288 +#endif
5289 +
5290 +#ifdef CONFIG_BCMA_NFLASH
5291 +struct mtd_info;
5292 +
5293 +struct bcma_nflash {
5294 +       bool present;
5295 +       bool boot;              /* This is the flash the SoC boots from */
5296 +
5297 +       struct mtd_info *mtd;
5298 +};
5299 +#endif
5300 +
5301  struct bcma_serial_port {
5302         void *regs;
5303         unsigned long clockspeed;
5304 @@ -330,15 +617,30 @@ struct bcma_drv_cc {
5305         u32 capabilities;
5306         u32 capabilities_ext;
5307         u8 setup_done:1;
5308 +       u8 early_setup_done:1;
5309         /* Fast Powerup Delay constant */
5310         u16 fast_pwrup_delay;
5311         struct bcma_chipcommon_pmu pmu;
5312  #ifdef CONFIG_BCMA_DRIVER_MIPS
5313         struct bcma_pflash pflash;
5314 +#ifdef CONFIG_BCMA_SFLASH
5315 +       struct bcma_sflash sflash;
5316 +#endif
5317 +#ifdef CONFIG_BCMA_NFLASH
5318 +       struct bcma_nflash nflash;
5319 +#endif
5320  
5321         int nr_serial_ports;
5322         struct bcma_serial_port serial_ports[4];
5323  #endif /* CONFIG_BCMA_DRIVER_MIPS */
5324 +       u32 ticks_per_ms;
5325 +       struct platform_device *watchdog;
5326 +
5327 +       /* Lock for GPIO register access. */
5328 +       spinlock_t gpio_lock;
5329 +#ifdef CONFIG_BCMA_DRIVER_GPIO
5330 +       struct gpio_chip gpio;
5331 +#endif
5332  };
5333  
5334  /* Register access */
5335 @@ -355,14 +657,16 @@ struct bcma_drv_cc {
5336         bcma_cc_write32(cc, offset, (bcma_cc_read32(cc, offset) & (mask)) | (set))
5337  
5338  extern void bcma_core_chipcommon_init(struct bcma_drv_cc *cc);
5339 +extern void bcma_core_chipcommon_early_init(struct bcma_drv_cc *cc);
5340  
5341  extern void bcma_chipco_suspend(struct bcma_drv_cc *cc);
5342  extern void bcma_chipco_resume(struct bcma_drv_cc *cc);
5343  
5344  void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc *cc, bool enable);
5345  
5346 -extern void bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc,
5347 -                                         u32 ticks);
5348 +extern u32 bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks);
5349 +
5350 +extern u32 bcma_chipco_get_alp_clock(struct bcma_drv_cc *cc);
5351  
5352  void bcma_chipco_irq_mask(struct bcma_drv_cc *cc, u32 mask, u32 value);
5353  
5354 @@ -375,9 +679,12 @@ u32 bcma_chipco_gpio_outen(struct bcma_d
5355  u32 bcma_chipco_gpio_control(struct bcma_drv_cc *cc, u32 mask, u32 value);
5356  u32 bcma_chipco_gpio_intmask(struct bcma_drv_cc *cc, u32 mask, u32 value);
5357  u32 bcma_chipco_gpio_polarity(struct bcma_drv_cc *cc, u32 mask, u32 value);
5358 +u32 bcma_chipco_gpio_pullup(struct bcma_drv_cc *cc, u32 mask, u32 value);
5359 +u32 bcma_chipco_gpio_pulldown(struct bcma_drv_cc *cc, u32 mask, u32 value);
5360  
5361  /* PMU support */
5362  extern void bcma_pmu_init(struct bcma_drv_cc *cc);
5363 +extern void bcma_pmu_early_init(struct bcma_drv_cc *cc);
5364  
5365  extern void bcma_chipco_pll_write(struct bcma_drv_cc *cc, u32 offset,
5366                                   u32 value);
5367 @@ -387,5 +694,8 @@ extern void bcma_chipco_chipctl_maskset(
5368                                         u32 offset, u32 mask, u32 set);
5369  extern void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc,
5370                                        u32 offset, u32 mask, u32 set);
5371 +extern void bcma_pmu_spuravoid_pllupdate(struct bcma_drv_cc *cc, int spuravoid);
5372 +
5373 +extern u32 bcma_pmu_get_bus_clock(struct bcma_drv_cc *cc);
5374  
5375  #endif /* LINUX_BCMA_DRIVER_CC_H_ */
5376 --- /dev/null
5377 +++ b/include/linux/bcma/bcma_driver_gmac_cmn.h
5378 @@ -0,0 +1,100 @@
5379 +#ifndef LINUX_BCMA_DRIVER_GMAC_CMN_H_
5380 +#define LINUX_BCMA_DRIVER_GMAC_CMN_H_
5381 +
5382 +#include <linux/types.h>
5383 +
5384 +#define BCMA_GMAC_CMN_STAG0            0x000
5385 +#define BCMA_GMAC_CMN_STAG1            0x004
5386 +#define BCMA_GMAC_CMN_STAG2            0x008
5387 +#define BCMA_GMAC_CMN_STAG3            0x00C
5388 +#define BCMA_GMAC_CMN_PARSER_CTL       0x020
5389 +#define BCMA_GMAC_CMN_MIB_MAX_LEN      0x024
5390 +#define BCMA_GMAC_CMN_PHY_ACCESS       0x100
5391 +#define  BCMA_GMAC_CMN_PA_DATA_MASK    0x0000ffff
5392 +#define  BCMA_GMAC_CMN_PA_ADDR_MASK    0x001f0000
5393 +#define  BCMA_GMAC_CMN_PA_ADDR_SHIFT   16
5394 +#define  BCMA_GMAC_CMN_PA_REG_MASK     0x1f000000
5395 +#define  BCMA_GMAC_CMN_PA_REG_SHIFT    24
5396 +#define  BCMA_GMAC_CMN_PA_WRITE                0x20000000
5397 +#define  BCMA_GMAC_CMN_PA_START                0x40000000
5398 +#define BCMA_GMAC_CMN_PHY_CTL          0x104
5399 +#define  BCMA_GMAC_CMN_PC_EPA_MASK     0x0000001f
5400 +#define  BCMA_GMAC_CMN_PC_MCT_MASK     0x007f0000
5401 +#define  BCMA_GMAC_CMN_PC_MCT_SHIFT    16
5402 +#define  BCMA_GMAC_CMN_PC_MTE          0x00800000
5403 +#define BCMA_GMAC_CMN_GMAC0_RGMII_CTL  0x110
5404 +#define BCMA_GMAC_CMN_CFP_ACCESS       0x200
5405 +#define BCMA_GMAC_CMN_CFP_TCAM_DATA0   0x210
5406 +#define BCMA_GMAC_CMN_CFP_TCAM_DATA1   0x214
5407 +#define BCMA_GMAC_CMN_CFP_TCAM_DATA2   0x218
5408 +#define BCMA_GMAC_CMN_CFP_TCAM_DATA3   0x21C
5409 +#define BCMA_GMAC_CMN_CFP_TCAM_DATA4   0x220
5410 +#define BCMA_GMAC_CMN_CFP_TCAM_DATA5   0x224
5411 +#define BCMA_GMAC_CMN_CFP_TCAM_DATA6   0x228
5412 +#define BCMA_GMAC_CMN_CFP_TCAM_DATA7   0x22C
5413 +#define BCMA_GMAC_CMN_CFP_TCAM_MASK0   0x230
5414 +#define BCMA_GMAC_CMN_CFP_TCAM_MASK1   0x234
5415 +#define BCMA_GMAC_CMN_CFP_TCAM_MASK2   0x238
5416 +#define BCMA_GMAC_CMN_CFP_TCAM_MASK3   0x23C
5417 +#define BCMA_GMAC_CMN_CFP_TCAM_MASK4   0x240
5418 +#define BCMA_GMAC_CMN_CFP_TCAM_MASK5   0x244
5419 +#define BCMA_GMAC_CMN_CFP_TCAM_MASK6   0x248
5420 +#define BCMA_GMAC_CMN_CFP_TCAM_MASK7   0x24C
5421 +#define BCMA_GMAC_CMN_CFP_ACTION_DATA  0x250
5422 +#define BCMA_GMAC_CMN_TCAM_BIST_CTL    0x2A0
5423 +#define BCMA_GMAC_CMN_TCAM_BIST_STATUS 0x2A4
5424 +#define BCMA_GMAC_CMN_TCAM_CMP_STATUS  0x2A8
5425 +#define BCMA_GMAC_CMN_TCAM_DISABLE     0x2AC
5426 +#define BCMA_GMAC_CMN_TCAM_TEST_CTL    0x2F0
5427 +#define BCMA_GMAC_CMN_UDF_0_A3_A0      0x300
5428 +#define BCMA_GMAC_CMN_UDF_0_A7_A4      0x304
5429 +#define BCMA_GMAC_CMN_UDF_0_A8         0x308
5430 +#define BCMA_GMAC_CMN_UDF_1_A3_A0      0x310
5431 +#define BCMA_GMAC_CMN_UDF_1_A7_A4      0x314
5432 +#define BCMA_GMAC_CMN_UDF_1_A8         0x318
5433 +#define BCMA_GMAC_CMN_UDF_2_A3_A0      0x320
5434 +#define BCMA_GMAC_CMN_UDF_2_A7_A4      0x324
5435 +#define BCMA_GMAC_CMN_UDF_2_A8         0x328
5436 +#define BCMA_GMAC_CMN_UDF_0_B3_B0      0x330
5437 +#define BCMA_GMAC_CMN_UDF_0_B7_B4      0x334
5438 +#define BCMA_GMAC_CMN_UDF_0_B8         0x338
5439 +#define BCMA_GMAC_CMN_UDF_1_B3_B0      0x340
5440 +#define BCMA_GMAC_CMN_UDF_1_B7_B4      0x344
5441 +#define BCMA_GMAC_CMN_UDF_1_B8         0x348
5442 +#define BCMA_GMAC_CMN_UDF_2_B3_B0      0x350
5443 +#define BCMA_GMAC_CMN_UDF_2_B7_B4      0x354
5444 +#define BCMA_GMAC_CMN_UDF_2_B8         0x358
5445 +#define BCMA_GMAC_CMN_UDF_0_C3_C0      0x360
5446 +#define BCMA_GMAC_CMN_UDF_0_C7_C4      0x364
5447 +#define BCMA_GMAC_CMN_UDF_0_C8         0x368
5448 +#define BCMA_GMAC_CMN_UDF_1_C3_C0      0x370
5449 +#define BCMA_GMAC_CMN_UDF_1_C7_C4      0x374
5450 +#define BCMA_GMAC_CMN_UDF_1_C8         0x378
5451 +#define BCMA_GMAC_CMN_UDF_2_C3_C0      0x380
5452 +#define BCMA_GMAC_CMN_UDF_2_C7_C4      0x384
5453 +#define BCMA_GMAC_CMN_UDF_2_C8         0x388
5454 +#define BCMA_GMAC_CMN_UDF_0_D3_D0      0x390
5455 +#define BCMA_GMAC_CMN_UDF_0_D7_D4      0x394
5456 +#define BCMA_GMAC_CMN_UDF_0_D11_D8     0x394
5457 +
5458 +struct bcma_drv_gmac_cmn {
5459 +       struct bcma_device *core;
5460 +
5461 +       /* Drivers accessing BCMA_GMAC_CMN_PHY_ACCESS and
5462 +        * BCMA_GMAC_CMN_PHY_CTL need to take that mutex first. */
5463 +       struct mutex phy_mutex;
5464 +};
5465 +
5466 +/* Register access */
5467 +#define gmac_cmn_read16(gc, offset)            bcma_read16((gc)->core, offset)
5468 +#define gmac_cmn_read32(gc, offset)            bcma_read32((gc)->core, offset)
5469 +#define gmac_cmn_write16(gc, offset, val)      bcma_write16((gc)->core, offset, val)
5470 +#define gmac_cmn_write32(gc, offset, val)      bcma_write32((gc)->core, offset, val)
5471 +
5472 +#ifdef CONFIG_BCMA_DRIVER_GMAC_CMN
5473 +extern void __devinit bcma_core_gmac_cmn_init(struct bcma_drv_gmac_cmn *gc);
5474 +#else
5475 +static inline void bcma_core_gmac_cmn_init(struct bcma_drv_gmac_cmn *gc) { }
5476 +#endif
5477 +
5478 +#endif /* LINUX_BCMA_DRIVER_GMAC_CMN_H_ */
5479 --- a/include/linux/bcma/bcma_driver_mips.h
5480 +++ b/include/linux/bcma/bcma_driver_mips.h
5481 @@ -28,6 +28,7 @@
5482  #define BCMA_MIPS_MIPS74K_GPIOEN       0x0048
5483  #define BCMA_MIPS_MIPS74K_CLKCTLST     0x01E0
5484  
5485 +#define BCMA_MIPS_OOBSELINA74          0x004
5486  #define BCMA_MIPS_OOBSELOUTA30         0x100
5487  
5488  struct bcma_device;
5489 @@ -35,17 +36,24 @@ struct bcma_device;
5490  struct bcma_drv_mips {
5491         struct bcma_device *core;
5492         u8 setup_done:1;
5493 -       unsigned int assigned_irqs;
5494 +       u8 early_setup_done:1;
5495  };
5496  
5497  #ifdef CONFIG_BCMA_DRIVER_MIPS
5498  extern void bcma_core_mips_init(struct bcma_drv_mips *mcore);
5499 +extern void bcma_core_mips_early_init(struct bcma_drv_mips *mcore);
5500 +
5501 +extern unsigned int bcma_core_irq(struct bcma_device *core);
5502  #else
5503  static inline void bcma_core_mips_init(struct bcma_drv_mips *mcore) { }
5504 +static inline void bcma_core_mips_early_init(struct bcma_drv_mips *mcore) { }
5505 +
5506 +static inline unsigned int bcma_core_irq(struct bcma_device *core)
5507 +{
5508 +       return 0;
5509 +}
5510  #endif
5511  
5512  extern u32 bcma_cpu_clock(struct bcma_drv_mips *mcore);
5513  
5514 -extern unsigned int bcma_core_mips_irq(struct bcma_device *dev);
5515 -
5516  #endif /* LINUX_BCMA_DRIVER_MIPS_H_ */
5517 --- a/include/linux/bcma/bcma_driver_pci.h
5518 +++ b/include/linux/bcma/bcma_driver_pci.h
5519 @@ -53,11 +53,47 @@ struct pci_dev;
5520  #define  BCMA_CORE_PCI_SBTOPCI1_MASK           0xFC000000
5521  #define BCMA_CORE_PCI_SBTOPCI2                 0x0108  /* Backplane to PCI translation 2 (sbtopci2) */
5522  #define  BCMA_CORE_PCI_SBTOPCI2_MASK           0xC0000000
5523 +#define BCMA_CORE_PCI_CONFIG_ADDR              0x0120  /* pcie config space access */
5524 +#define BCMA_CORE_PCI_CONFIG_DATA              0x0124  /* pcie config space access */
5525 +#define BCMA_CORE_PCI_MDIO_CONTROL             0x0128  /* controls the mdio access */
5526 +#define  BCMA_CORE_PCI_MDIOCTL_DIVISOR_MASK    0x7f    /* clock to be used on MDIO */
5527 +#define  BCMA_CORE_PCI_MDIOCTL_DIVISOR_VAL     0x2
5528 +#define  BCMA_CORE_PCI_MDIOCTL_PREAM_EN                0x80    /* Enable preamble sequnce */
5529 +#define  BCMA_CORE_PCI_MDIOCTL_ACCESS_DONE     0x100   /* Tranaction complete */
5530 +#define BCMA_CORE_PCI_MDIO_DATA                        0x012c  /* Data to the mdio access */
5531 +#define  BCMA_CORE_PCI_MDIODATA_MASK           0x0000ffff /* data 2 bytes */
5532 +#define  BCMA_CORE_PCI_MDIODATA_TA             0x00020000 /* Turnaround */
5533 +#define  BCMA_CORE_PCI_MDIODATA_REGADDR_SHF_OLD        18      /* Regaddr shift (rev < 10) */
5534 +#define  BCMA_CORE_PCI_MDIODATA_REGADDR_MASK_OLD       0x003c0000 /* Regaddr Mask (rev < 10) */
5535 +#define  BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF_OLD        22      /* Physmedia devaddr shift (rev < 10) */
5536 +#define  BCMA_CORE_PCI_MDIODATA_DEVADDR_MASK_OLD       0x0fc00000 /* Physmedia devaddr Mask (rev < 10) */
5537 +#define  BCMA_CORE_PCI_MDIODATA_REGADDR_SHF    18      /* Regaddr shift */
5538 +#define  BCMA_CORE_PCI_MDIODATA_REGADDR_MASK   0x007c0000 /* Regaddr Mask */
5539 +#define  BCMA_CORE_PCI_MDIODATA_DEVADDR_SHF    23      /* Physmedia devaddr shift */
5540 +#define  BCMA_CORE_PCI_MDIODATA_DEVADDR_MASK   0x0f800000 /* Physmedia devaddr Mask */
5541 +#define  BCMA_CORE_PCI_MDIODATA_WRITE          0x10000000 /* write Transaction */
5542 +#define  BCMA_CORE_PCI_MDIODATA_READ           0x20000000 /* Read Transaction */
5543 +#define  BCMA_CORE_PCI_MDIODATA_START          0x40000000 /* start of Transaction */
5544 +#define  BCMA_CORE_PCI_MDIODATA_DEV_ADDR       0x0     /* dev address for serdes */
5545 +#define  BCMA_CORE_PCI_MDIODATA_BLK_ADDR       0x1F    /* blk address for serdes */
5546 +#define  BCMA_CORE_PCI_MDIODATA_DEV_PLL                0x1d    /* SERDES PLL Dev */
5547 +#define  BCMA_CORE_PCI_MDIODATA_DEV_TX         0x1e    /* SERDES TX Dev */
5548 +#define  BCMA_CORE_PCI_MDIODATA_DEV_RX         0x1f    /* SERDES RX Dev */
5549 +#define BCMA_CORE_PCI_PCIEIND_ADDR             0x0130  /* indirect access to the internal register */
5550 +#define BCMA_CORE_PCI_PCIEIND_DATA             0x0134  /* Data to/from the internal regsiter */
5551 +#define BCMA_CORE_PCI_CLKREQENCTRL             0x0138  /*  >= rev 6, Clkreq rdma control */
5552  #define BCMA_CORE_PCI_PCICFG0                  0x0400  /* PCI config space 0 (rev >= 8) */
5553  #define BCMA_CORE_PCI_PCICFG1                  0x0500  /* PCI config space 1 (rev >= 8) */
5554  #define BCMA_CORE_PCI_PCICFG2                  0x0600  /* PCI config space 2 (rev >= 8) */
5555  #define BCMA_CORE_PCI_PCICFG3                  0x0700  /* PCI config space 3 (rev >= 8) */
5556  #define BCMA_CORE_PCI_SPROM(wordoffset)                (0x0800 + ((wordoffset) * 2)) /* SPROM shadow area (72 bytes) */
5557 +#define  BCMA_CORE_PCI_SPROM_PI_OFFSET         0       /* first word */
5558 +#define   BCMA_CORE_PCI_SPROM_PI_MASK          0xf000  /* bit 15:12 */
5559 +#define   BCMA_CORE_PCI_SPROM_PI_SHIFT         12      /* bit 15:12 */
5560 +#define  BCMA_CORE_PCI_SPROM_MISC_CONFIG       5       /* word 5 */
5561 +#define   BCMA_CORE_PCI_SPROM_L23READY_EXIT_NOPERST    0x8000  /* bit 15 */
5562 +#define   BCMA_CORE_PCI_SPROM_CLKREQ_OFFSET_REV5       20      /* word 20 for srom rev <= 5 */
5563 +#define   BCMA_CORE_PCI_SPROM_CLKREQ_ENB       0x0800  /* bit 11 */
5564  
5565  /* SBtoPCIx */
5566  #define BCMA_CORE_PCI_SBTOPCI_MEM              0x00000000
5567 @@ -72,20 +108,143 @@ struct pci_dev;
5568  #define  BCMA_CORE_PCI_SBTOPCI_RC_READL                0x00000010 /* Memory read line */
5569  #define  BCMA_CORE_PCI_SBTOPCI_RC_READM                0x00000020 /* Memory read multiple */
5570  
5571 +/* PCIE protocol PHY diagnostic registers */
5572 +#define BCMA_CORE_PCI_PLP_MODEREG              0x200   /* Mode */
5573 +#define BCMA_CORE_PCI_PLP_STATUSREG            0x204   /* Status */
5574 +#define  BCMA_CORE_PCI_PLP_POLARITYINV_STAT    0x10    /* Status reg PCIE_PLP_STATUSREG */
5575 +#define BCMA_CORE_PCI_PLP_LTSSMCTRLREG         0x208   /* LTSSM control */
5576 +#define BCMA_CORE_PCI_PLP_LTLINKNUMREG         0x20c   /* Link Training Link number */
5577 +#define BCMA_CORE_PCI_PLP_LTLANENUMREG         0x210   /* Link Training Lane number */
5578 +#define BCMA_CORE_PCI_PLP_LTNFTSREG            0x214   /* Link Training N_FTS */
5579 +#define BCMA_CORE_PCI_PLP_ATTNREG              0x218   /* Attention */
5580 +#define BCMA_CORE_PCI_PLP_ATTNMASKREG          0x21C   /* Attention Mask */
5581 +#define BCMA_CORE_PCI_PLP_RXERRCTR             0x220   /* Rx Error */
5582 +#define BCMA_CORE_PCI_PLP_RXFRMERRCTR          0x224   /* Rx Framing Error */
5583 +#define BCMA_CORE_PCI_PLP_RXERRTHRESHREG       0x228   /* Rx Error threshold */
5584 +#define BCMA_CORE_PCI_PLP_TESTCTRLREG          0x22C   /* Test Control reg */
5585 +#define BCMA_CORE_PCI_PLP_SERDESCTRLOVRDREG    0x230   /* SERDES Control Override */
5586 +#define BCMA_CORE_PCI_PLP_TIMINGOVRDREG                0x234   /* Timing param override */
5587 +#define BCMA_CORE_PCI_PLP_RXTXSMDIAGREG                0x238   /* RXTX State Machine Diag */
5588 +#define BCMA_CORE_PCI_PLP_LTSSMDIAGREG         0x23C   /* LTSSM State Machine Diag */
5589 +
5590 +/* PCIE protocol DLLP diagnostic registers */
5591 +#define BCMA_CORE_PCI_DLLP_LCREG               0x100   /* Link Control */
5592 +#define BCMA_CORE_PCI_DLLP_LSREG               0x104   /* Link Status */
5593 +#define BCMA_CORE_PCI_DLLP_LAREG               0x108   /* Link Attention */
5594 +#define  BCMA_CORE_PCI_DLLP_LSREG_LINKUP       (1 << 16)
5595 +#define BCMA_CORE_PCI_DLLP_LAMASKREG           0x10C   /* Link Attention Mask */
5596 +#define BCMA_CORE_PCI_DLLP_NEXTTXSEQNUMREG     0x110   /* Next Tx Seq Num */
5597 +#define BCMA_CORE_PCI_DLLP_ACKEDTXSEQNUMREG    0x114   /* Acked Tx Seq Num */
5598 +#define BCMA_CORE_PCI_DLLP_PURGEDTXSEQNUMREG   0x118   /* Purged Tx Seq Num */
5599 +#define BCMA_CORE_PCI_DLLP_RXSEQNUMREG         0x11C   /* Rx Sequence Number */
5600 +#define BCMA_CORE_PCI_DLLP_LRREG               0x120   /* Link Replay */
5601 +#define BCMA_CORE_PCI_DLLP_LACKTOREG           0x124   /* Link Ack Timeout */
5602 +#define BCMA_CORE_PCI_DLLP_PMTHRESHREG         0x128   /* Power Management Threshold */
5603 +#define  BCMA_CORE_PCI_ASPMTIMER_EXTEND                0x01000000 /* > rev7: enable extend ASPM timer */
5604 +#define BCMA_CORE_PCI_DLLP_RTRYWPREG           0x12C   /* Retry buffer write ptr */
5605 +#define BCMA_CORE_PCI_DLLP_RTRYRPREG           0x130   /* Retry buffer Read ptr */
5606 +#define BCMA_CORE_PCI_DLLP_RTRYPPREG           0x134   /* Retry buffer Purged ptr */
5607 +#define BCMA_CORE_PCI_DLLP_RTRRWREG            0x138   /* Retry buffer Read/Write */
5608 +#define BCMA_CORE_PCI_DLLP_ECTHRESHREG         0x13C   /* Error Count Threshold */
5609 +#define BCMA_CORE_PCI_DLLP_TLPERRCTRREG                0x140   /* TLP Error Counter */
5610 +#define BCMA_CORE_PCI_DLLP_ERRCTRREG           0x144   /* Error Counter */
5611 +#define BCMA_CORE_PCI_DLLP_NAKRXCTRREG         0x148   /* NAK Received Counter */
5612 +#define BCMA_CORE_PCI_DLLP_TESTREG             0x14C   /* Test */
5613 +#define BCMA_CORE_PCI_DLLP_PKTBIST             0x150   /* Packet BIST */
5614 +#define BCMA_CORE_PCI_DLLP_PCIE11              0x154   /* DLLP PCIE 1.1 reg */
5615 +
5616 +/* SERDES RX registers */
5617 +#define BCMA_CORE_PCI_SERDES_RX_CTRL           1       /* Rx cntrl */
5618 +#define  BCMA_CORE_PCI_SERDES_RX_CTRL_FORCE    0x80    /* rxpolarity_force */
5619 +#define  BCMA_CORE_PCI_SERDES_RX_CTRL_POLARITY 0x40    /* rxpolarity_value */
5620 +#define BCMA_CORE_PCI_SERDES_RX_TIMER1         2       /* Rx Timer1 */
5621 +#define BCMA_CORE_PCI_SERDES_RX_CDR            6       /* CDR */
5622 +#define BCMA_CORE_PCI_SERDES_RX_CDRBW          7       /* CDR BW */
5623 +
5624 +/* SERDES PLL registers */
5625 +#define BCMA_CORE_PCI_SERDES_PLL_CTRL          1       /* PLL control reg */
5626 +#define BCMA_CORE_PCI_PLL_CTRL_FREQDET_EN      0x4000  /* bit 14 is FREQDET on */
5627 +
5628  /* PCIcore specific boardflags */
5629  #define BCMA_CORE_PCI_BFL_NOPCI                        0x00000400 /* Board leaves PCI floating */
5630  
5631 +/* PCIE Config space accessing MACROS */
5632 +#define BCMA_CORE_PCI_CFG_BUS_SHIFT            24      /* Bus shift */
5633 +#define BCMA_CORE_PCI_CFG_SLOT_SHIFT           19      /* Slot/Device shift */
5634 +#define BCMA_CORE_PCI_CFG_FUN_SHIFT            16      /* Function shift */
5635 +#define BCMA_CORE_PCI_CFG_OFF_SHIFT            0       /* Register shift */
5636 +
5637 +#define BCMA_CORE_PCI_CFG_BUS_MASK             0xff    /* Bus mask */
5638 +#define BCMA_CORE_PCI_CFG_SLOT_MASK            0x1f    /* Slot/Device mask */
5639 +#define BCMA_CORE_PCI_CFG_FUN_MASK             7       /* Function mask */
5640 +#define BCMA_CORE_PCI_CFG_OFF_MASK             0xfff   /* Register mask */
5641 +
5642 +#define BCMA_CORE_PCI_CFG_DEVCTRL              0xd8
5643 +
5644 +#define BCMA_CORE_PCI_
5645 +
5646 +/* MDIO devices (SERDES modules) */
5647 +#define BCMA_CORE_PCI_MDIO_IEEE0               0x000
5648 +#define BCMA_CORE_PCI_MDIO_IEEE1               0x001
5649 +#define BCMA_CORE_PCI_MDIO_BLK0                        0x800
5650 +#define BCMA_CORE_PCI_MDIO_BLK1                        0x801
5651 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT0         0x16
5652 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT1         0x17
5653 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT2         0x18
5654 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT3         0x19
5655 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT4         0x1A
5656 +#define BCMA_CORE_PCI_MDIO_BLK2                        0x802
5657 +#define BCMA_CORE_PCI_MDIO_BLK3                        0x803
5658 +#define BCMA_CORE_PCI_MDIO_BLK4                        0x804
5659 +#define BCMA_CORE_PCI_MDIO_TXPLL               0x808   /* TXPLL register block idx */
5660 +#define BCMA_CORE_PCI_MDIO_TXCTRL0             0x820
5661 +#define BCMA_CORE_PCI_MDIO_SERDESID            0x831
5662 +#define BCMA_CORE_PCI_MDIO_RXCTRL0             0x840
5663 +
5664 +/* PCIE Root Capability Register bits (Host mode only) */
5665 +#define BCMA_CORE_PCI_RC_CRS_VISIBILITY                0x0001
5666 +
5667 +struct bcma_drv_pci;
5668 +struct bcma_bus;
5669 +
5670 +#ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE
5671 +struct bcma_drv_pci_host {
5672 +       struct bcma_drv_pci *pdev;
5673 +
5674 +       u32 host_cfg_addr;
5675 +       spinlock_t cfgspace_lock;
5676 +
5677 +       struct pci_controller pci_controller;
5678 +       struct pci_ops pci_ops;
5679 +       struct resource mem_resource;
5680 +       struct resource io_resource;
5681 +};
5682 +#endif
5683 +
5684  struct bcma_drv_pci {
5685         struct bcma_device *core;
5686         u8 setup_done:1;
5687 +       u8 hostmode:1;
5688 +
5689 +#ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE
5690 +       struct bcma_drv_pci_host *host_controller;
5691 +#endif
5692  };
5693  
5694  /* Register access */
5695 +#define pcicore_read16(pc, offset)             bcma_read16((pc)->core, offset)
5696  #define pcicore_read32(pc, offset)             bcma_read32((pc)->core, offset)
5697 +#define pcicore_write16(pc, offset, val)       bcma_write16((pc)->core, offset, val)
5698  #define pcicore_write32(pc, offset, val)       bcma_write32((pc)->core, offset, val)
5699  
5700 -extern void bcma_core_pci_init(struct bcma_drv_pci *pc);
5701 +extern void __devinit bcma_core_pci_init(struct bcma_drv_pci *pc);
5702  extern int bcma_core_pci_irq_ctl(struct bcma_drv_pci *pc,
5703                                  struct bcma_device *core, bool enable);
5704 +extern void bcma_core_pci_up(struct bcma_bus *bus);
5705 +extern void bcma_core_pci_down(struct bcma_bus *bus);
5706 +extern void bcma_core_pci_power_save(struct bcma_bus *bus, bool up);
5707 +
5708 +extern int bcma_core_pci_pcibios_map_irq(const struct pci_dev *dev);
5709 +extern int bcma_core_pci_plat_dev_init(struct pci_dev *dev);
5710  
5711  #endif /* LINUX_BCMA_DRIVER_PCI_H_ */
5712 --- a/include/linux/bcma/bcma_regs.h
5713 +++ b/include/linux/bcma/bcma_regs.h
5714 @@ -11,11 +11,13 @@
5715  #define  BCMA_CLKCTLST_HAVEHTREQ       0x00000010 /* HT available request */
5716  #define  BCMA_CLKCTLST_HWCROFF         0x00000020 /* Force HW clock request off */
5717  #define  BCMA_CLKCTLST_EXTRESREQ       0x00000700 /* Mask of external resource requests */
5718 +#define  BCMA_CLKCTLST_EXTRESREQ_SHIFT 8
5719  #define  BCMA_CLKCTLST_HAVEALP         0x00010000 /* ALP available */
5720  #define  BCMA_CLKCTLST_HAVEHT          0x00020000 /* HT available */
5721  #define  BCMA_CLKCTLST_BP_ON_ALP       0x00040000 /* RO: running on ALP clock */
5722  #define  BCMA_CLKCTLST_BP_ON_HT                0x00080000 /* RO: running on HT clock */
5723  #define  BCMA_CLKCTLST_EXTRESST                0x07000000 /* Mask of external resource status */
5724 +#define  BCMA_CLKCTLST_EXTRESST_SHIFT  24
5725  /* Is there any BCM4328 on BCMA bus? */
5726  #define  BCMA_CLKCTLST_4328A0_HAVEHT   0x00010000 /* 4328a0 has reversed bits */
5727  #define  BCMA_CLKCTLST_4328A0_HAVEALP  0x00020000 /* 4328a0 has reversed bits */
5728 @@ -35,6 +37,7 @@
5729  #define  BCMA_IOST_BIST_DONE           0x8000
5730  #define BCMA_RESET_CTL                 0x0800
5731  #define  BCMA_RESET_CTL_RESET          0x0001
5732 +#define BCMA_RESET_ST                  0x0804
5733  
5734  /* BCMA PCI config space registers. */
5735  #define BCMA_PCI_PMCSR                 0x44
5736 @@ -56,4 +59,36 @@
5737  #define  BCMA_PCI_GPIO_XTAL            0x40    /* PCI config space GPIO 14 for Xtal powerup */
5738  #define  BCMA_PCI_GPIO_PLL             0x80    /* PCI config space GPIO 15 for PLL powerdown */
5739  
5740 +/* SiliconBackplane Address Map.
5741 + * All regions may not exist on all chips.
5742 + */
5743 +#define BCMA_SOC_SDRAM_BASE            0x00000000U     /* Physical SDRAM */
5744 +#define BCMA_SOC_PCI_MEM               0x08000000U     /* Host Mode sb2pcitranslation0 (64 MB) */
5745 +#define BCMA_SOC_PCI_MEM_SZ            (64 * 1024 * 1024)
5746 +#define BCMA_SOC_PCI_CFG               0x0c000000U     /* Host Mode sb2pcitranslation1 (64 MB) */
5747 +#define BCMA_SOC_SDRAM_SWAPPED         0x10000000U     /* Byteswapped Physical SDRAM */
5748 +#define BCMA_SOC_SDRAM_R2              0x80000000U     /* Region 2 for sdram (512 MB) */
5749 +
5750 +
5751 +#define BCMA_SOC_PCI_DMA               0x40000000U     /* Client Mode sb2pcitranslation2 (1 GB) */
5752 +#define BCMA_SOC_PCI_DMA2              0x80000000U     /* Client Mode sb2pcitranslation2 (1 GB) */
5753 +#define BCMA_SOC_PCI_DMA_SZ            0x40000000U     /* Client Mode sb2pcitranslation2 size in bytes */
5754 +#define BCMA_SOC_PCIE_DMA_L32          0x00000000U     /* PCIE Client Mode sb2pcitranslation2
5755 +                                                        * (2 ZettaBytes), low 32 bits
5756 +                                                        */
5757 +#define BCMA_SOC_PCIE_DMA_H32          0x80000000U     /* PCIE Client Mode sb2pcitranslation2
5758 +                                                        * (2 ZettaBytes), high 32 bits
5759 +                                                        */
5760 +
5761 +#define BCMA_SOC_PCI1_MEM              0x40000000U     /* Host Mode sb2pcitranslation0 (64 MB) */
5762 +#define BCMA_SOC_PCI1_CFG              0x44000000U     /* Host Mode sb2pcitranslation1 (64 MB) */
5763 +#define BCMA_SOC_PCIE1_DMA_H32         0xc0000000U     /* PCIE Client Mode sb2pcitranslation2
5764 +                                                        * (2 ZettaBytes), high 32 bits
5765 +                                                        */
5766 +
5767 +#define BCMA_SOC_FLASH1                        0x1fc00000      /* MIPS Flash Region 1 */
5768 +#define BCMA_SOC_FLASH1_SZ             0x00400000      /* MIPS Size of Flash Region 1 */
5769 +#define BCMA_SOC_FLASH2                        0x1c000000      /* Flash Region 2 (region 1 shadowed here) */
5770 +#define BCMA_SOC_FLASH2_SZ             0x02000000      /* Size of Flash Region 2 */
5771 +
5772  #endif /* LINUX_BCMA_REGS_H_ */
5773 --- a/drivers/net/wireless/b43/main.c
5774 +++ b/drivers/net/wireless/b43/main.c
5775 @@ -4618,7 +4618,7 @@ static int b43_wireless_core_init(struct
5776         switch (dev->dev->bus_type) {
5777  #ifdef CONFIG_B43_BCMA
5778         case B43_BUS_BCMA:
5779 -               bcma_core_pci_irq_ctl(&dev->dev->bdev->bus->drv_pci,
5780 +               bcma_core_pci_irq_ctl(&dev->dev->bdev->bus->drv_pci[0],
5781                                       dev->dev->bdev, true);
5782                 break;
5783  #endif
5784 --- a/drivers/net/wireless/brcm80211/brcmsmac/aiutils.c
5785 +++ b/drivers/net/wireless/brcm80211/brcmsmac/aiutils.c
5786 @@ -533,7 +533,7 @@ ai_buscore_setup(struct si_info *sii, st
5787  
5788         /* fixup necessary chip/core configurations */
5789         if (!sii->pch) {
5790 -               sii->pch = pcicore_init(&sii->pub, sii->icbus->drv_pci.core);
5791 +               sii->pch = pcicore_init(&sii->pub, sii->icbus->drv_pci[0].core);
5792                 if (sii->pch == NULL)
5793                         return false;
5794         }