kernel: bcma: update bcma to a version from kernel 3.14-rc1
[openwrt.git] / target / linux / generic / patches-3.10 / 025-bcma_backport.patch
1 --- a/drivers/bcma/Kconfig
2 +++ b/drivers/bcma/Kconfig
3 @@ -26,6 +26,7 @@ config BCMA_HOST_PCI_POSSIBLE
4  config BCMA_HOST_PCI
5         bool "Support for BCMA on PCI-host bus"
6         depends on BCMA_HOST_PCI_POSSIBLE
7 +       default y
8  
9  config BCMA_DRIVER_PCI_HOSTMODE
10         bool "Driver for PCI core working in hostmode"
11 @@ -34,8 +35,14 @@ config BCMA_DRIVER_PCI_HOSTMODE
12           PCI core hostmode operation (external PCI bus).
13  
14  config BCMA_HOST_SOC
15 -       bool
16 -       depends on BCMA_DRIVER_MIPS
17 +       bool "Support for BCMA in a SoC"
18 +       depends on BCMA
19 +       help
20 +         Host interface for a Broadcom AIX bus directly mapped into
21 +         the memory. This only works with the Broadcom SoCs from the
22 +         BCM47XX line.
23 +
24 +         If unsure, say N
25  
26  config BCMA_DRIVER_MIPS
27         bool "BCMA Broadcom MIPS core driver"
28 @@ -68,6 +75,7 @@ config BCMA_DRIVER_GMAC_CMN
29  config BCMA_DRIVER_GPIO
30         bool "BCMA GPIO driver"
31         depends on BCMA && GPIOLIB
32 +       select IRQ_DOMAIN if BCMA_HOST_SOC
33         help
34           Driver to provide access to the GPIO pins of the bcma bus.
35  
36 --- a/drivers/bcma/bcma_private.h
37 +++ b/drivers/bcma/bcma_private.h
38 @@ -22,6 +22,8 @@
39  struct bcma_bus;
40  
41  /* main.c */
42 +bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
43 +                    int timeout);
44  int bcma_bus_register(struct bcma_bus *bus);
45  void bcma_bus_unregister(struct bcma_bus *bus);
46  int __init bcma_bus_early_register(struct bcma_bus *bus,
47 @@ -31,8 +33,6 @@ int __init bcma_bus_early_register(struc
48  int bcma_bus_suspend(struct bcma_bus *bus);
49  int bcma_bus_resume(struct bcma_bus *bus);
50  #endif
51 -struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
52 -                                       u8 unit);
53  
54  /* scan.c */
55  int bcma_bus_scan(struct bcma_bus *bus);
56 --- a/drivers/bcma/core.c
57 +++ b/drivers/bcma/core.c
58 @@ -9,6 +9,25 @@
59  #include <linux/export.h>
60  #include <linux/bcma/bcma.h>
61  
62 +static bool bcma_core_wait_value(struct bcma_device *core, u16 reg, u32 mask,
63 +                                u32 value, int timeout)
64 +{
65 +       unsigned long deadline = jiffies + timeout;
66 +       u32 val;
67 +
68 +       do {
69 +               val = bcma_aread32(core, reg);
70 +               if ((val & mask) == value)
71 +                       return true;
72 +               cpu_relax();
73 +               udelay(10);
74 +       } while (!time_after_eq(jiffies, deadline));
75 +
76 +       bcma_warn(core->bus, "Timeout waiting for register 0x%04X!\n", reg);
77 +
78 +       return false;
79 +}
80 +
81  bool bcma_core_is_enabled(struct bcma_device *core)
82  {
83         if ((bcma_aread32(core, BCMA_IOCTL) & (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC))
84 @@ -25,13 +44,15 @@ void bcma_core_disable(struct bcma_devic
85         if (bcma_aread32(core, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
86                 return;
87  
88 -       bcma_awrite32(core, BCMA_IOCTL, flags);
89 -       bcma_aread32(core, BCMA_IOCTL);
90 -       udelay(10);
91 +       bcma_core_wait_value(core, BCMA_RESET_ST, ~0, 0, 300);
92  
93         bcma_awrite32(core, BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);
94         bcma_aread32(core, BCMA_RESET_CTL);
95         udelay(1);
96 +
97 +       bcma_awrite32(core, BCMA_IOCTL, flags);
98 +       bcma_aread32(core, BCMA_IOCTL);
99 +       udelay(10);
100  }
101  EXPORT_SYMBOL_GPL(bcma_core_disable);
102  
103 @@ -43,6 +64,7 @@ int bcma_core_enable(struct bcma_device
104         bcma_aread32(core, BCMA_IOCTL);
105  
106         bcma_awrite32(core, BCMA_RESET_CTL, 0);
107 +       bcma_aread32(core, BCMA_RESET_CTL);
108         udelay(1);
109  
110         bcma_awrite32(core, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
111 --- a/drivers/bcma/driver_chipcommon.c
112 +++ b/drivers/bcma/driver_chipcommon.c
113 @@ -140,8 +140,15 @@ void bcma_core_chipcommon_init(struct bc
114         bcma_core_chipcommon_early_init(cc);
115  
116         if (cc->core->id.rev >= 20) {
117 -               bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, 0);
118 -               bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, 0);
119 +               u32 pullup = 0, pulldown = 0;
120 +
121 +               if (cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM43142) {
122 +                       pullup = 0x402e0;
123 +                       pulldown = 0x20500;
124 +               }
125 +
126 +               bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, pullup);
127 +               bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, pulldown);
128         }
129  
130         if (cc->capabilities & BCMA_CC_CAP_PMU)
131 --- a/drivers/bcma/driver_chipcommon_pmu.c
132 +++ b/drivers/bcma/driver_chipcommon_pmu.c
133 @@ -56,6 +56,109 @@ void bcma_chipco_regctl_maskset(struct b
134  }
135  EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset);
136  
137 +static u32 bcma_pmu_xtalfreq(struct bcma_drv_cc *cc)
138 +{
139 +       u32 ilp_ctl, alp_hz;
140 +
141 +       if (!(bcma_cc_read32(cc, BCMA_CC_PMU_STAT) &
142 +             BCMA_CC_PMU_STAT_EXT_LPO_AVAIL))
143 +               return 0;
144 +
145 +       bcma_cc_write32(cc, BCMA_CC_PMU_XTAL_FREQ,
146 +                       BIT(BCMA_CC_PMU_XTAL_FREQ_MEASURE_SHIFT));
147 +       usleep_range(1000, 2000);
148 +
149 +       ilp_ctl = bcma_cc_read32(cc, BCMA_CC_PMU_XTAL_FREQ);
150 +       ilp_ctl &= BCMA_CC_PMU_XTAL_FREQ_ILPCTL_MASK;
151 +
152 +       bcma_cc_write32(cc, BCMA_CC_PMU_XTAL_FREQ, 0);
153 +
154 +       alp_hz = ilp_ctl * 32768 / 4;
155 +       return (alp_hz + 50000) / 100000 * 100;
156 +}
157 +
158 +static void bcma_pmu2_pll_init0(struct bcma_drv_cc *cc, u32 xtalfreq)
159 +{
160 +       struct bcma_bus *bus = cc->core->bus;
161 +       u32 freq_tgt_target = 0, freq_tgt_current;
162 +       u32 pll0, mask;
163 +
164 +       switch (bus->chipinfo.id) {
165 +       case BCMA_CHIP_ID_BCM43142:
166 +               /* pmu2_xtaltab0_adfll_485 */
167 +               switch (xtalfreq) {
168 +               case 12000:
169 +                       freq_tgt_target = 0x50D52;
170 +                       break;
171 +               case 20000:
172 +                       freq_tgt_target = 0x307FE;
173 +                       break;
174 +               case 26000:
175 +                       freq_tgt_target = 0x254EA;
176 +                       break;
177 +               case 37400:
178 +                       freq_tgt_target = 0x19EF8;
179 +                       break;
180 +               case 52000:
181 +                       freq_tgt_target = 0x12A75;
182 +                       break;
183 +               }
184 +               break;
185 +       }
186 +
187 +       if (!freq_tgt_target) {
188 +               bcma_err(bus, "Unknown TGT frequency for xtalfreq %d\n",
189 +                        xtalfreq);
190 +               return;
191 +       }
192 +
193 +       pll0 = bcma_chipco_pll_read(cc, BCMA_CC_PMU15_PLL_PLLCTL0);
194 +       freq_tgt_current = (pll0 & BCMA_CC_PMU15_PLL_PC0_FREQTGT_MASK) >>
195 +               BCMA_CC_PMU15_PLL_PC0_FREQTGT_SHIFT;
196 +
197 +       if (freq_tgt_current == freq_tgt_target) {
198 +               bcma_debug(bus, "Target TGT frequency already set\n");
199 +               return;
200 +       }
201 +
202 +       /* Turn off PLL */
203 +       switch (bus->chipinfo.id) {
204 +       case BCMA_CHIP_ID_BCM43142:
205 +               mask = (u32)~(BCMA_RES_4314_HT_AVAIL |
206 +                             BCMA_RES_4314_MACPHY_CLK_AVAIL);
207 +
208 +               bcma_cc_mask32(cc, BCMA_CC_PMU_MINRES_MSK, mask);
209 +               bcma_cc_mask32(cc, BCMA_CC_PMU_MAXRES_MSK, mask);
210 +               bcma_wait_value(cc->core, BCMA_CLKCTLST,
211 +                               BCMA_CLKCTLST_HAVEHT, 0, 20000);
212 +               break;
213 +       }
214 +
215 +       pll0 &= ~BCMA_CC_PMU15_PLL_PC0_FREQTGT_MASK;
216 +       pll0 |= freq_tgt_target << BCMA_CC_PMU15_PLL_PC0_FREQTGT_SHIFT;
217 +       bcma_chipco_pll_write(cc, BCMA_CC_PMU15_PLL_PLLCTL0, pll0);
218 +
219 +       /* Flush */
220 +       if (cc->pmu.rev >= 2)
221 +               bcma_cc_set32(cc, BCMA_CC_PMU_CTL, BCMA_CC_PMU_CTL_PLL_UPD);
222 +
223 +       /* TODO: Do we need to update OTP? */
224 +}
225 +
226 +static void bcma_pmu_pll_init(struct bcma_drv_cc *cc)
227 +{
228 +       struct bcma_bus *bus = cc->core->bus;
229 +       u32 xtalfreq = bcma_pmu_xtalfreq(cc);
230 +
231 +       switch (bus->chipinfo.id) {
232 +       case BCMA_CHIP_ID_BCM43142:
233 +               if (xtalfreq == 0)
234 +                       xtalfreq = 20000;
235 +               bcma_pmu2_pll_init0(cc, xtalfreq);
236 +               break;
237 +       }
238 +}
239 +
240  static void bcma_pmu_resources_init(struct bcma_drv_cc *cc)
241  {
242         struct bcma_bus *bus = cc->core->bus;
243 @@ -66,6 +169,25 @@ static void bcma_pmu_resources_init(stru
244                 min_msk = 0x200D;
245                 max_msk = 0xFFFF;
246                 break;
247 +       case BCMA_CHIP_ID_BCM43142:
248 +               min_msk = BCMA_RES_4314_LPLDO_PU |
249 +                         BCMA_RES_4314_PMU_SLEEP_DIS |
250 +                         BCMA_RES_4314_PMU_BG_PU |
251 +                         BCMA_RES_4314_CBUCK_LPOM_PU |
252 +                         BCMA_RES_4314_CBUCK_PFM_PU |
253 +                         BCMA_RES_4314_CLDO_PU |
254 +                         BCMA_RES_4314_LPLDO2_LVM |
255 +                         BCMA_RES_4314_WL_PMU_PU |
256 +                         BCMA_RES_4314_LDO3P3_PU |
257 +                         BCMA_RES_4314_OTP_PU |
258 +                         BCMA_RES_4314_WL_PWRSW_PU |
259 +                         BCMA_RES_4314_LQ_AVAIL |
260 +                         BCMA_RES_4314_LOGIC_RET |
261 +                         BCMA_RES_4314_MEM_SLEEP |
262 +                         BCMA_RES_4314_MACPHY_RET |
263 +                         BCMA_RES_4314_WL_CORE_READY;
264 +               max_msk = 0x3FFFFFFF;
265 +               break;
266         default:
267                 bcma_debug(bus, "PMU resource config unknown or not needed for device 0x%04X\n",
268                            bus->chipinfo.id);
269 @@ -165,6 +287,7 @@ void bcma_pmu_init(struct bcma_drv_cc *c
270                 bcma_cc_set32(cc, BCMA_CC_PMU_CTL,
271                              BCMA_CC_PMU_CTL_NOILPONW);
272  
273 +       bcma_pmu_pll_init(cc);
274         bcma_pmu_resources_init(cc);
275         bcma_pmu_workarounds(cc);
276  }
277 --- a/drivers/bcma/driver_chipcommon_sflash.c
278 +++ b/drivers/bcma/driver_chipcommon_sflash.c
279 @@ -30,7 +30,7 @@ struct bcma_sflash_tbl_e {
280         u16 numblocks;
281  };
282  
283 -static struct bcma_sflash_tbl_e bcma_sflash_st_tbl[] = {
284 +static const struct bcma_sflash_tbl_e bcma_sflash_st_tbl[] = {
285         { "M25P20", 0x11, 0x10000, 4, },
286         { "M25P40", 0x12, 0x10000, 8, },
287  
288 @@ -38,10 +38,10 @@ static struct bcma_sflash_tbl_e bcma_sfl
289         { "M25P32", 0x15, 0x10000, 64, },
290         { "M25P64", 0x16, 0x10000, 128, },
291         { "M25FL128", 0x17, 0x10000, 256, },
292 -       { 0 },
293 +       { NULL },
294  };
295  
296 -static struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {
297 +static const struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {
298         { "SST25WF512", 1, 0x1000, 16, },
299         { "SST25VF512", 0x48, 0x1000, 16, },
300         { "SST25WF010", 2, 0x1000, 32, },
301 @@ -56,10 +56,10 @@ static struct bcma_sflash_tbl_e bcma_sfl
302         { "SST25VF016", 0x41, 0x1000, 512, },
303         { "SST25VF032", 0x4a, 0x1000, 1024, },
304         { "SST25VF064", 0x4b, 0x1000, 2048, },
305 -       { 0 },
306 +       { NULL },
307  };
308  
309 -static struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {
310 +static const struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {
311         { "AT45DB011", 0xc, 256, 512, },
312         { "AT45DB021", 0x14, 256, 1024, },
313         { "AT45DB041", 0x1c, 256, 2048, },
314 @@ -67,7 +67,7 @@ static struct bcma_sflash_tbl_e bcma_sfl
315         { "AT45DB161", 0x2c, 512, 4096, },
316         { "AT45DB321", 0x34, 512, 8192, },
317         { "AT45DB642", 0x3c, 1024, 8192, },
318 -       { 0 },
319 +       { NULL },
320  };
321  
322  static void bcma_sflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
323 @@ -89,7 +89,7 @@ int bcma_sflash_init(struct bcma_drv_cc
324  {
325         struct bcma_bus *bus = cc->core->bus;
326         struct bcma_sflash *sflash = &cc->sflash;
327 -       struct bcma_sflash_tbl_e *e;
328 +       const struct bcma_sflash_tbl_e *e;
329         u32 id, id2;
330  
331         switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
332 --- a/drivers/bcma/driver_gpio.c
333 +++ b/drivers/bcma/driver_gpio.c
334 @@ -9,6 +9,9 @@
335   */
336  
337  #include <linux/gpio.h>
338 +#include <linux/irq.h>
339 +#include <linux/interrupt.h>
340 +#include <linux/irqdomain.h>
341  #include <linux/export.h>
342  #include <linux/bcma/bcma.h>
343  
344 @@ -73,19 +76,136 @@ static void bcma_gpio_free(struct gpio_c
345         bcma_chipco_gpio_pullup(cc, 1 << gpio, 0);
346  }
347  
348 +#if IS_BUILTIN(CONFIG_BCMA_HOST_SOC)
349  static int bcma_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
350  {
351         struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
352  
353         if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
354 -               return bcma_core_irq(cc->core);
355 +               return irq_find_mapping(cc->irq_domain, gpio);
356         else
357                 return -EINVAL;
358  }
359  
360 +static void bcma_gpio_irq_unmask(struct irq_data *d)
361 +{
362 +       struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
363 +       int gpio = irqd_to_hwirq(d);
364 +       u32 val = bcma_chipco_gpio_in(cc, BIT(gpio));
365 +
366 +       bcma_chipco_gpio_polarity(cc, BIT(gpio), val);
367 +       bcma_chipco_gpio_intmask(cc, BIT(gpio), BIT(gpio));
368 +}
369 +
370 +static void bcma_gpio_irq_mask(struct irq_data *d)
371 +{
372 +       struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
373 +       int gpio = irqd_to_hwirq(d);
374 +
375 +       bcma_chipco_gpio_intmask(cc, BIT(gpio), 0);
376 +}
377 +
378 +static struct irq_chip bcma_gpio_irq_chip = {
379 +       .name           = "BCMA-GPIO",
380 +       .irq_mask       = bcma_gpio_irq_mask,
381 +       .irq_unmask     = bcma_gpio_irq_unmask,
382 +};
383 +
384 +static irqreturn_t bcma_gpio_irq_handler(int irq, void *dev_id)
385 +{
386 +       struct bcma_drv_cc *cc = dev_id;
387 +       u32 val = bcma_cc_read32(cc, BCMA_CC_GPIOIN);
388 +       u32 mask = bcma_cc_read32(cc, BCMA_CC_GPIOIRQ);
389 +       u32 pol = bcma_cc_read32(cc, BCMA_CC_GPIOPOL);
390 +       unsigned long irqs = (val ^ pol) & mask;
391 +       int gpio;
392 +
393 +       if (!irqs)
394 +               return IRQ_NONE;
395 +
396 +       for_each_set_bit(gpio, &irqs, cc->gpio.ngpio)
397 +               generic_handle_irq(bcma_gpio_to_irq(&cc->gpio, gpio));
398 +       bcma_chipco_gpio_polarity(cc, irqs, val & irqs);
399 +
400 +       return IRQ_HANDLED;
401 +}
402 +
403 +static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
404 +{
405 +       struct gpio_chip *chip = &cc->gpio;
406 +       int gpio, hwirq, err;
407 +
408 +       if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
409 +               return 0;
410 +
411 +       cc->irq_domain = irq_domain_add_linear(NULL, chip->ngpio,
412 +                                              &irq_domain_simple_ops, cc);
413 +       if (!cc->irq_domain) {
414 +               err = -ENODEV;
415 +               goto err_irq_domain;
416 +       }
417 +       for (gpio = 0; gpio < chip->ngpio; gpio++) {
418 +               int irq = irq_create_mapping(cc->irq_domain, gpio);
419 +
420 +               irq_set_chip_data(irq, cc);
421 +               irq_set_chip_and_handler(irq, &bcma_gpio_irq_chip,
422 +                                        handle_simple_irq);
423 +       }
424 +
425 +       hwirq = bcma_core_irq(cc->core);
426 +       err = request_irq(hwirq, bcma_gpio_irq_handler, IRQF_SHARED, "gpio",
427 +                         cc);
428 +       if (err)
429 +               goto err_req_irq;
430 +
431 +       bcma_chipco_gpio_intmask(cc, ~0, 0);
432 +       bcma_cc_set32(cc, BCMA_CC_IRQMASK, BCMA_CC_IRQ_GPIO);
433 +
434 +       return 0;
435 +
436 +err_req_irq:
437 +       for (gpio = 0; gpio < chip->ngpio; gpio++) {
438 +               int irq = irq_find_mapping(cc->irq_domain, gpio);
439 +
440 +               irq_dispose_mapping(irq);
441 +       }
442 +       irq_domain_remove(cc->irq_domain);
443 +err_irq_domain:
444 +       return err;
445 +}
446 +
447 +static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
448 +{
449 +       struct gpio_chip *chip = &cc->gpio;
450 +       int gpio;
451 +
452 +       if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
453 +               return;
454 +
455 +       bcma_cc_mask32(cc, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO);
456 +       free_irq(bcma_core_irq(cc->core), cc);
457 +       for (gpio = 0; gpio < chip->ngpio; gpio++) {
458 +               int irq = irq_find_mapping(cc->irq_domain, gpio);
459 +
460 +               irq_dispose_mapping(irq);
461 +       }
462 +       irq_domain_remove(cc->irq_domain);
463 +}
464 +#else
465 +static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
466 +{
467 +       return 0;
468 +}
469 +
470 +static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
471 +{
472 +}
473 +#endif
474 +
475  int bcma_gpio_init(struct bcma_drv_cc *cc)
476  {
477         struct gpio_chip *chip = &cc->gpio;
478 +       int err;
479  
480         chip->label             = "bcma_gpio";
481         chip->owner             = THIS_MODULE;
482 @@ -95,7 +215,9 @@ int bcma_gpio_init(struct bcma_drv_cc *c
483         chip->set               = bcma_gpio_set_value;
484         chip->direction_input   = bcma_gpio_direction_input;
485         chip->direction_output  = bcma_gpio_direction_output;
486 +#if IS_BUILTIN(CONFIG_BCMA_HOST_SOC)
487         chip->to_irq            = bcma_gpio_to_irq;
488 +#endif
489         chip->ngpio             = 16;
490         /* There is just one SoC in one device and its GPIO addresses should be
491          * deterministic to address them more easily. The other buses could get
492 @@ -105,10 +227,21 @@ int bcma_gpio_init(struct bcma_drv_cc *c
493         else
494                 chip->base              = -1;
495  
496 -       return gpiochip_add(chip);
497 +       err = bcma_gpio_irq_domain_init(cc);
498 +       if (err)
499 +               return err;
500 +
501 +       err = gpiochip_add(chip);
502 +       if (err) {
503 +               bcma_gpio_irq_domain_exit(cc);
504 +               return err;
505 +       }
506 +
507 +       return 0;
508  }
509  
510  int bcma_gpio_unregister(struct bcma_drv_cc *cc)
511  {
512 +       bcma_gpio_irq_domain_exit(cc);
513         return gpiochip_remove(&cc->gpio);
514  }
515 --- a/drivers/bcma/driver_pci.c
516 +++ b/drivers/bcma/driver_pci.c
517 @@ -31,7 +31,7 @@ static void bcma_pcie_write(struct bcma_
518         pcicore_write32(pc, BCMA_CORE_PCI_PCIEIND_DATA, data);
519  }
520  
521 -static void bcma_pcie_mdio_set_phy(struct bcma_drv_pci *pc, u8 phy)
522 +static void bcma_pcie_mdio_set_phy(struct bcma_drv_pci *pc, u16 phy)
523  {
524         u32 v;
525         int i;
526 @@ -55,7 +55,7 @@ static void bcma_pcie_mdio_set_phy(struc
527         }
528  }
529  
530 -static u16 bcma_pcie_mdio_read(struct bcma_drv_pci *pc, u8 device, u8 address)
531 +static u16 bcma_pcie_mdio_read(struct bcma_drv_pci *pc, u16 device, u8 address)
532  {
533         int max_retries = 10;
534         u16 ret = 0;
535 @@ -98,7 +98,7 @@ static u16 bcma_pcie_mdio_read(struct bc
536         return ret;
537  }
538  
539 -static void bcma_pcie_mdio_write(struct bcma_drv_pci *pc, u8 device,
540 +static void bcma_pcie_mdio_write(struct bcma_drv_pci *pc, u16 device,
541                                 u8 address, u16 data)
542  {
543         int max_retries = 10;
544 @@ -137,6 +137,13 @@ static void bcma_pcie_mdio_write(struct
545         pcicore_write32(pc, BCMA_CORE_PCI_MDIO_CONTROL, 0);
546  }
547  
548 +static u16 bcma_pcie_mdio_writeread(struct bcma_drv_pci *pc, u16 device,
549 +                                   u8 address, u16 data)
550 +{
551 +       bcma_pcie_mdio_write(pc, device, address, data);
552 +       return bcma_pcie_mdio_read(pc, device, address);
553 +}
554 +
555  /**************************************************
556   * Workarounds.
557   **************************************************/
558 @@ -229,6 +236,32 @@ void bcma_core_pci_init(struct bcma_drv_
559                 bcma_core_pci_clientmode_init(pc);
560  }
561  
562 +void bcma_core_pci_power_save(struct bcma_bus *bus, bool up)
563 +{
564 +       struct bcma_drv_pci *pc;
565 +       u16 data;
566 +
567 +       if (bus->hosttype != BCMA_HOSTTYPE_PCI)
568 +               return;
569 +
570 +       pc = &bus->drv_pci[0];
571 +
572 +       if (pc->core->id.rev >= 15 && pc->core->id.rev <= 20) {
573 +               data = up ? 0x74 : 0x7C;
574 +               bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
575 +                                        BCMA_CORE_PCI_MDIO_BLK1_MGMT1, 0x7F64);
576 +               bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
577 +                                        BCMA_CORE_PCI_MDIO_BLK1_MGMT3, data);
578 +       } else if (pc->core->id.rev >= 21 && pc->core->id.rev <= 22) {
579 +               data = up ? 0x75 : 0x7D;
580 +               bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
581 +                                        BCMA_CORE_PCI_MDIO_BLK1_MGMT1, 0x7E65);
582 +               bcma_pcie_mdio_writeread(pc, BCMA_CORE_PCI_MDIO_BLK1,
583 +                                        BCMA_CORE_PCI_MDIO_BLK1_MGMT3, data);
584 +       }
585 +}
586 +EXPORT_SYMBOL_GPL(bcma_core_pci_power_save);
587 +
588  int bcma_core_pci_irq_ctl(struct bcma_drv_pci *pc, struct bcma_device *core,
589                           bool enable)
590  {
591 @@ -262,7 +295,7 @@ out:
592  }
593  EXPORT_SYMBOL_GPL(bcma_core_pci_irq_ctl);
594  
595 -void bcma_core_pci_extend_L1timer(struct bcma_drv_pci *pc, bool extend)
596 +static void bcma_core_pci_extend_L1timer(struct bcma_drv_pci *pc, bool extend)
597  {
598         u32 w;
599  
600 @@ -274,4 +307,29 @@ void bcma_core_pci_extend_L1timer(struct
601         bcma_pcie_write(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG, w);
602         bcma_pcie_read(pc, BCMA_CORE_PCI_DLLP_PMTHRESHREG);
603  }
604 -EXPORT_SYMBOL_GPL(bcma_core_pci_extend_L1timer);
605 +
606 +void bcma_core_pci_up(struct bcma_bus *bus)
607 +{
608 +       struct bcma_drv_pci *pc;
609 +
610 +       if (bus->hosttype != BCMA_HOSTTYPE_PCI)
611 +               return;
612 +
613 +       pc = &bus->drv_pci[0];
614 +
615 +       bcma_core_pci_extend_L1timer(pc, true);
616 +}
617 +EXPORT_SYMBOL_GPL(bcma_core_pci_up);
618 +
619 +void bcma_core_pci_down(struct bcma_bus *bus)
620 +{
621 +       struct bcma_drv_pci *pc;
622 +
623 +       if (bus->hosttype != BCMA_HOSTTYPE_PCI)
624 +               return;
625 +
626 +       pc = &bus->drv_pci[0];
627 +
628 +       bcma_core_pci_extend_L1timer(pc, false);
629 +}
630 +EXPORT_SYMBOL_GPL(bcma_core_pci_down);
631 --- a/drivers/bcma/driver_pci_host.c
632 +++ b/drivers/bcma/driver_pci_host.c
633 @@ -581,6 +581,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI
634  int bcma_core_pci_plat_dev_init(struct pci_dev *dev)
635  {
636         struct bcma_drv_pci_host *pc_host;
637 +       int readrq;
638  
639         if (dev->bus->ops->read != bcma_core_pci_hostmode_read_config) {
640                 /* This is not a device on the PCI-core bridge. */
641 @@ -595,6 +596,11 @@ int bcma_core_pci_plat_dev_init(struct p
642         dev->irq = bcma_core_irq(pc_host->pdev->core);
643         pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
644  
645 +       readrq = pcie_get_readrq(dev);
646 +       if (readrq > 128) {
647 +               pr_info("change PCIe max read request size from %i to 128\n", readrq);
648 +               pcie_set_readrq(dev, 128);
649 +       }
650         return 0;
651  }
652  EXPORT_SYMBOL(bcma_core_pci_plat_dev_init);
653 --- a/drivers/bcma/host_pci.c
654 +++ b/drivers/bcma/host_pci.c
655 @@ -188,8 +188,11 @@ static int bcma_host_pci_probe(struct pc
656                 pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
657  
658         /* SSB needed additional powering up, do we have any AMBA PCI cards? */
659 -       if (!pci_is_pcie(dev))
660 -               bcma_err(bus, "PCI card detected, report problems.\n");
661 +       if (!pci_is_pcie(dev)) {
662 +               bcma_err(bus, "PCI card detected, they are not supported.\n");
663 +               err = -ENXIO;
664 +               goto err_pci_release_regions;
665 +       }
666  
667         /* Map MMIO */
668         err = -ENOMEM;
669 @@ -235,7 +238,6 @@ static void bcma_host_pci_remove(struct
670         pci_release_regions(dev);
671         pci_disable_device(dev);
672         kfree(bus);
673 -       pci_set_drvdata(dev, NULL);
674  }
675  
676  #ifdef CONFIG_PM_SLEEP
677 @@ -267,14 +269,16 @@ static SIMPLE_DEV_PM_OPS(bcma_pm_ops, bc
678  
679  #endif /* CONFIG_PM_SLEEP */
680  
681 -static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
682 +static const struct pci_device_id bcma_pci_bridge_tbl[] = {
683         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) },
684 +       { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4313) },
685         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 43224) },
686         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4331) },
687         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) },
688         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4357) },
689         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4358) },
690         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4359) },
691 +       { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4365) },
692         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) },
693         { 0, },
694  };
695 --- a/drivers/bcma/main.c
696 +++ b/drivers/bcma/main.c
697 @@ -69,28 +69,36 @@ static u16 bcma_cc_core_id(struct bcma_b
698         return BCMA_CORE_CHIPCOMMON;
699  }
700  
701 -struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid)
702 +struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
703 +                                       u8 unit)
704  {
705         struct bcma_device *core;
706  
707         list_for_each_entry(core, &bus->cores, list) {
708 -               if (core->id.id == coreid)
709 +               if (core->id.id == coreid && core->core_unit == unit)
710                         return core;
711         }
712         return NULL;
713  }
714 -EXPORT_SYMBOL_GPL(bcma_find_core);
715 +EXPORT_SYMBOL_GPL(bcma_find_core_unit);
716  
717 -struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
718 -                                       u8 unit)
719 +bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
720 +                    int timeout)
721  {
722 -       struct bcma_device *core;
723 +       unsigned long deadline = jiffies + timeout;
724 +       u32 val;
725  
726 -       list_for_each_entry(core, &bus->cores, list) {
727 -               if (core->id.id == coreid && core->core_unit == unit)
728 -                       return core;
729 -       }
730 -       return NULL;
731 +       do {
732 +               val = bcma_read32(core, reg);
733 +               if ((val & mask) == value)
734 +                       return true;
735 +               cpu_relax();
736 +               udelay(10);
737 +       } while (!time_after_eq(jiffies, deadline));
738 +
739 +       bcma_warn(core->bus, "Timeout waiting for register 0x%04X!\n", reg);
740 +
741 +       return false;
742  }
743  
744  static void bcma_release_core_dev(struct device *dev)
745 @@ -148,6 +156,7 @@ static int bcma_register_cores(struct bc
746                         bcma_err(bus,
747                                  "Could not register dev for core 0x%03X\n",
748                                  core->id.id);
749 +                       put_device(&core->dev);
750                         continue;
751                 }
752                 core->dev_registered = true;
753 @@ -218,7 +227,7 @@ int bcma_bus_register(struct bcma_bus *b
754         err = bcma_bus_scan(bus);
755         if (err) {
756                 bcma_err(bus, "Failed to scan: %d\n", err);
757 -               return -1;
758 +               return err;
759         }
760  
761         /* Early init CC core */
762 --- a/drivers/bcma/scan.c
763 +++ b/drivers/bcma/scan.c
764 @@ -32,6 +32,18 @@ static const struct bcma_device_id_name
765         { BCMA_CORE_4706_CHIPCOMMON, "BCM4706 ChipCommon" },
766         { BCMA_CORE_4706_SOC_RAM, "BCM4706 SOC RAM" },
767         { BCMA_CORE_4706_MAC_GBIT, "BCM4706 GBit MAC" },
768 +       { BCMA_CORE_PCIEG2, "PCIe Gen 2" },
769 +       { BCMA_CORE_DMA, "DMA" },
770 +       { BCMA_CORE_SDIO3, "SDIO3" },
771 +       { BCMA_CORE_USB20, "USB 2.0" },
772 +       { BCMA_CORE_USB30, "USB 3.0" },
773 +       { BCMA_CORE_A9JTAG, "ARM Cortex A9 JTAG" },
774 +       { BCMA_CORE_DDR23, "Denali DDR2/DDR3 memory controller" },
775 +       { BCMA_CORE_ROM, "ROM" },
776 +       { BCMA_CORE_NAND, "NAND flash controller" },
777 +       { BCMA_CORE_QSPI, "SPI flash controller" },
778 +       { BCMA_CORE_CHIPCOMMON_B, "Chipcommon B" },
779 +       { BCMA_CORE_ARMCA9, "ARM Cortex A9 core (ihost)" },
780         { BCMA_CORE_AMEMC, "AMEMC (DDR)" },
781         { BCMA_CORE_ALTA, "ALTA (I2S)" },
782         { BCMA_CORE_INVALID, "Invalid" },
783 @@ -201,7 +213,7 @@ static s32 bcma_erom_get_mst_port(struct
784         return ent;
785  }
786  
787 -static s32 bcma_erom_get_addr_desc(struct bcma_bus *bus, u32 __iomem **eromptr,
788 +static u32 bcma_erom_get_addr_desc(struct bcma_bus *bus, u32 __iomem **eromptr,
789                                   u32 type, u8 port)
790  {
791         u32 addrl, addrh, sizel, sizeh = 0;
792 @@ -213,7 +225,7 @@ static s32 bcma_erom_get_addr_desc(struc
793             ((ent & SCAN_ADDR_TYPE) != type) ||
794             (((ent & SCAN_ADDR_PORT) >> SCAN_ADDR_PORT_SHIFT) != port)) {
795                 bcma_erom_push_ent(eromptr);
796 -               return -EINVAL;
797 +               return (u32)-EINVAL;
798         }
799  
800         addrl = ent & SCAN_ADDR_ADDR;
801 @@ -257,11 +269,13 @@ static struct bcma_device *bcma_find_cor
802         return NULL;
803  }
804  
805 +#define IS_ERR_VALUE_U32(x) ((x) >= (u32)-MAX_ERRNO)
806 +
807  static int bcma_get_next_core(struct bcma_bus *bus, u32 __iomem **eromptr,
808                               struct bcma_device_id *match, int core_num,
809                               struct bcma_device *core)
810  {
811 -       s32 tmp;
812 +       u32 tmp;
813         u8 i, j;
814         s32 cia, cib;
815         u8 ports[2], wrappers[2];
816 @@ -339,11 +353,11 @@ static int bcma_get_next_core(struct bcm
817          * the main register space for the core
818          */
819         tmp = bcma_erom_get_addr_desc(bus, eromptr, SCAN_ADDR_TYPE_SLAVE, 0);
820 -       if (tmp <= 0) {
821 +       if (tmp == 0 || IS_ERR_VALUE_U32(tmp)) {
822                 /* Try again to see if it is a bridge */
823                 tmp = bcma_erom_get_addr_desc(bus, eromptr,
824                                               SCAN_ADDR_TYPE_BRIDGE, 0);
825 -               if (tmp <= 0) {
826 +               if (tmp == 0 || IS_ERR_VALUE_U32(tmp)) {
827                         return -EILSEQ;
828                 } else {
829                         bcma_info(bus, "Bridge found\n");
830 @@ -357,7 +371,7 @@ static int bcma_get_next_core(struct bcm
831                 for (j = 0; ; j++) {
832                         tmp = bcma_erom_get_addr_desc(bus, eromptr,
833                                 SCAN_ADDR_TYPE_SLAVE, i);
834 -                       if (tmp < 0) {
835 +                       if (IS_ERR_VALUE_U32(tmp)) {
836                                 /* no more entries for port _i_ */
837                                 /* pr_debug("erom: slave port %d "
838                                  * "has %d descriptors\n", i, j); */
839 @@ -374,7 +388,7 @@ static int bcma_get_next_core(struct bcm
840                 for (j = 0; ; j++) {
841                         tmp = bcma_erom_get_addr_desc(bus, eromptr,
842                                 SCAN_ADDR_TYPE_MWRAP, i);
843 -                       if (tmp < 0) {
844 +                       if (IS_ERR_VALUE_U32(tmp)) {
845                                 /* no more entries for port _i_ */
846                                 /* pr_debug("erom: master wrapper %d "
847                                  * "has %d descriptors\n", i, j); */
848 @@ -392,7 +406,7 @@ static int bcma_get_next_core(struct bcm
849                 for (j = 0; ; j++) {
850                         tmp = bcma_erom_get_addr_desc(bus, eromptr,
851                                 SCAN_ADDR_TYPE_SWRAP, i + hack);
852 -                       if (tmp < 0) {
853 +                       if (IS_ERR_VALUE_U32(tmp)) {
854                                 /* no more entries for port _i_ */
855                                 /* pr_debug("erom: master wrapper %d "
856                                  * has %d descriptors\n", i, j); */
857 --- a/drivers/bcma/sprom.c
858 +++ b/drivers/bcma/sprom.c
859 @@ -72,12 +72,12 @@ fail:
860   * R/W ops.
861   **************************************************/
862  
863 -static void bcma_sprom_read(struct bcma_bus *bus, u16 offset, u16 *sprom)
864 +static void bcma_sprom_read(struct bcma_bus *bus, u16 offset, u16 *sprom,
865 +                           size_t words)
866  {
867         int i;
868 -       for (i = 0; i < SSB_SPROMSIZE_WORDS_R4; i++)
869 -               sprom[i] = bcma_read16(bus->drv_cc.core,
870 -                                      offset + (i * 2));
871 +       for (i = 0; i < words; i++)
872 +               sprom[i] = bcma_read16(bus->drv_cc.core, offset + (i * 2));
873  }
874  
875  /**************************************************
876 @@ -124,29 +124,29 @@ static inline u8 bcma_crc8(u8 crc, u8 da
877         return t[crc ^ data];
878  }
879  
880 -static u8 bcma_sprom_crc(const u16 *sprom)
881 +static u8 bcma_sprom_crc(const u16 *sprom, size_t words)
882  {
883         int word;
884         u8 crc = 0xFF;
885  
886 -       for (word = 0; word < SSB_SPROMSIZE_WORDS_R4 - 1; word++) {
887 +       for (word = 0; word < words - 1; word++) {
888                 crc = bcma_crc8(crc, sprom[word] & 0x00FF);
889                 crc = bcma_crc8(crc, (sprom[word] & 0xFF00) >> 8);
890         }
891 -       crc = bcma_crc8(crc, sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & 0x00FF);
892 +       crc = bcma_crc8(crc, sprom[words - 1] & 0x00FF);
893         crc ^= 0xFF;
894  
895         return crc;
896  }
897  
898 -static int bcma_sprom_check_crc(const u16 *sprom)
899 +static int bcma_sprom_check_crc(const u16 *sprom, size_t words)
900  {
901         u8 crc;
902         u8 expected_crc;
903         u16 tmp;
904  
905 -       crc = bcma_sprom_crc(sprom);
906 -       tmp = sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & SSB_SPROM_REVISION_CRC;
907 +       crc = bcma_sprom_crc(sprom, words);
908 +       tmp = sprom[words - 1] & SSB_SPROM_REVISION_CRC;
909         expected_crc = tmp >> SSB_SPROM_REVISION_CRC_SHIFT;
910         if (crc != expected_crc)
911                 return -EPROTO;
912 @@ -154,21 +154,25 @@ static int bcma_sprom_check_crc(const u1
913         return 0;
914  }
915  
916 -static int bcma_sprom_valid(const u16 *sprom)
917 +static int bcma_sprom_valid(struct bcma_bus *bus, const u16 *sprom,
918 +                           size_t words)
919  {
920         u16 revision;
921         int err;
922  
923 -       err = bcma_sprom_check_crc(sprom);
924 +       err = bcma_sprom_check_crc(sprom, words);
925         if (err)
926                 return err;
927  
928 -       revision = sprom[SSB_SPROMSIZE_WORDS_R4 - 1] & SSB_SPROM_REVISION_REV;
929 -       if (revision != 8 && revision != 9) {
930 +       revision = sprom[words - 1] & SSB_SPROM_REVISION_REV;
931 +       if (revision != 8 && revision != 9 && revision != 10) {
932                 pr_err("Unsupported SPROM revision: %d\n", revision);
933                 return -ENOENT;
934         }
935  
936 +       bus->sprom.revision = revision;
937 +       bcma_debug(bus, "Found SPROM revision %d\n", revision);
938 +
939         return 0;
940  }
941  
942 @@ -208,9 +212,6 @@ static void bcma_sprom_extract_r8(struct
943         BUILD_BUG_ON(ARRAY_SIZE(pwr_info_offset) !=
944                         ARRAY_SIZE(bus->sprom.core_pwr_info));
945  
946 -       bus->sprom.revision = sprom[SSB_SPROMSIZE_WORDS_R4 - 1] &
947 -               SSB_SPROM_REVISION_REV;
948 -
949         for (i = 0; i < 3; i++) {
950                 v = sprom[SPOFF(SSB_SPROM8_IL0MAC) + i];
951                 *(((__be16 *)bus->sprom.il0mac) + i) = cpu_to_be16(v);
952 @@ -502,7 +503,7 @@ static bool bcma_sprom_onchip_available(
953         case BCMA_CHIP_ID_BCM4331:
954                 present = chip_status & BCMA_CC_CHIPST_4331_OTP_PRESENT;
955                 break;
956 -
957 +       case BCMA_CHIP_ID_BCM43142:
958         case BCMA_CHIP_ID_BCM43224:
959         case BCMA_CHIP_ID_BCM43225:
960                 /* for these chips OTP is always available */
961 @@ -550,7 +551,9 @@ int bcma_sprom_get(struct bcma_bus *bus)
962  {
963         u16 offset = BCMA_CC_SPROM;
964         u16 *sprom;
965 -       int err = 0;
966 +       size_t sprom_sizes[] = { SSB_SPROMSIZE_WORDS_R4,
967 +                                SSB_SPROMSIZE_WORDS_R10, };
968 +       int i, err = 0;
969  
970         if (!bus->drv_cc.core)
971                 return -EOPNOTSUPP;
972 @@ -579,32 +582,37 @@ int bcma_sprom_get(struct bcma_bus *bus)
973                 }
974         }
975  
976 -       sprom = kcalloc(SSB_SPROMSIZE_WORDS_R4, sizeof(u16),
977 -                       GFP_KERNEL);
978 -       if (!sprom)
979 -               return -ENOMEM;
980 -
981         if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4331 ||
982             bus->chipinfo.id == BCMA_CHIP_ID_BCM43431)
983                 bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, false);
984  
985         bcma_debug(bus, "SPROM offset 0x%x\n", offset);
986 -       bcma_sprom_read(bus, offset, sprom);
987 +       for (i = 0; i < ARRAY_SIZE(sprom_sizes); i++) {
988 +               size_t words = sprom_sizes[i];
989 +
990 +               sprom = kcalloc(words, sizeof(u16), GFP_KERNEL);
991 +               if (!sprom)
992 +                       return -ENOMEM;
993 +
994 +               bcma_sprom_read(bus, offset, sprom, words);
995 +               err = bcma_sprom_valid(bus, sprom, words);
996 +               if (!err)
997 +                       break;
998 +
999 +               kfree(sprom);
1000 +       }
1001  
1002         if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4331 ||
1003             bus->chipinfo.id == BCMA_CHIP_ID_BCM43431)
1004                 bcma_chipco_bcm4331_ext_pa_lines_ctl(&bus->drv_cc, true);
1005  
1006 -       err = bcma_sprom_valid(sprom);
1007         if (err) {
1008 -               bcma_warn(bus, "invalid sprom read from the PCIe card, try to use fallback sprom\n");
1009 +               bcma_warn(bus, "Invalid SPROM read from the PCIe card, trying to use fallback SPROM\n");
1010                 err = bcma_fill_sprom_with_fallback(bus, &bus->sprom);
1011 -               goto out;
1012 +       } else {
1013 +               bcma_sprom_extract_r8(bus, sprom);
1014 +               kfree(sprom);
1015         }
1016  
1017 -       bcma_sprom_extract_r8(bus, sprom);
1018 -
1019 -out:
1020 -       kfree(sprom);
1021         return err;
1022  }
1023 --- a/include/linux/bcma/bcma.h
1024 +++ b/include/linux/bcma/bcma.h
1025 @@ -72,7 +72,19 @@ struct bcma_host_ops {
1026  /* Core-ID values. */
1027  #define BCMA_CORE_OOB_ROUTER           0x367   /* Out of band */
1028  #define BCMA_CORE_4706_CHIPCOMMON      0x500
1029 +#define BCMA_CORE_PCIEG2               0x501
1030 +#define BCMA_CORE_DMA                  0x502
1031 +#define BCMA_CORE_SDIO3                        0x503
1032 +#define BCMA_CORE_USB20                        0x504
1033 +#define BCMA_CORE_USB30                        0x505
1034 +#define BCMA_CORE_A9JTAG               0x506
1035 +#define BCMA_CORE_DDR23                        0x507
1036 +#define BCMA_CORE_ROM                  0x508
1037 +#define BCMA_CORE_NAND                 0x509
1038 +#define BCMA_CORE_QSPI                 0x50A
1039 +#define BCMA_CORE_CHIPCOMMON_B         0x50B
1040  #define BCMA_CORE_4706_SOC_RAM         0x50E
1041 +#define BCMA_CORE_ARMCA9               0x510
1042  #define BCMA_CORE_4706_MAC_GBIT                0x52D
1043  #define BCMA_CORE_AMEMC                        0x52E   /* DDR1/2 memory controller core */
1044  #define BCMA_CORE_ALTA                 0x534   /* I2S core */
1045 @@ -144,6 +156,7 @@ struct bcma_host_ops {
1046  
1047  /* Chip IDs of PCIe devices */
1048  #define BCMA_CHIP_ID_BCM4313   0x4313
1049 +#define BCMA_CHIP_ID_BCM43142  43142
1050  #define BCMA_CHIP_ID_BCM43224  43224
1051  #define  BCMA_PKG_ID_BCM43224_FAB_CSM  0x8
1052  #define  BCMA_PKG_ID_BCM43224_FAB_SMIC 0xa
1053 @@ -176,6 +189,11 @@ struct bcma_host_ops {
1054  #define  BCMA_PKG_ID_BCM5357   11
1055  #define BCMA_CHIP_ID_BCM53572  53572
1056  #define  BCMA_PKG_ID_BCM47188  9
1057 +#define BCMA_CHIP_ID_BCM4707   53010
1058 +#define  BCMA_PKG_ID_BCM4707   1
1059 +#define  BCMA_PKG_ID_BCM4708   2
1060 +#define  BCMA_PKG_ID_BCM4709   0
1061 +#define BCMA_CHIP_ID_BCM53018  53018
1062  
1063  /* Board types (on PCI usually equals to the subsystem dev id) */
1064  /* BCM4313 */
1065 @@ -400,7 +418,14 @@ static inline void bcma_maskset16(struct
1066         bcma_write16(cc, offset, (bcma_read16(cc, offset) & mask) | set);
1067  }
1068  
1069 -extern struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid);
1070 +extern struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
1071 +                                              u8 unit);
1072 +static inline struct bcma_device *bcma_find_core(struct bcma_bus *bus,
1073 +                                                u16 coreid)
1074 +{
1075 +       return bcma_find_core_unit(bus, coreid, 0);
1076 +}
1077 +
1078  extern bool bcma_core_is_enabled(struct bcma_device *core);
1079  extern void bcma_core_disable(struct bcma_device *core, u32 flags);
1080  extern int bcma_core_enable(struct bcma_device *core, u32 flags);
1081 --- a/include/linux/bcma/bcma_driver_chipcommon.h
1082 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
1083 @@ -330,6 +330,8 @@
1084  #define BCMA_CC_PMU_CAP                        0x0604 /* PMU capabilities */
1085  #define  BCMA_CC_PMU_CAP_REVISION      0x000000FF /* Revision mask */
1086  #define BCMA_CC_PMU_STAT               0x0608 /* PMU status */
1087 +#define  BCMA_CC_PMU_STAT_EXT_LPO_AVAIL        0x00000100
1088 +#define  BCMA_CC_PMU_STAT_WDRESET      0x00000080
1089  #define  BCMA_CC_PMU_STAT_INTPEND      0x00000040 /* Interrupt pending */
1090  #define  BCMA_CC_PMU_STAT_SBCLKST      0x00000030 /* Backplane clock status? */
1091  #define  BCMA_CC_PMU_STAT_HAVEALP      0x00000008 /* ALP available */
1092 @@ -355,6 +357,11 @@
1093  #define BCMA_CC_REGCTL_DATA            0x065C
1094  #define BCMA_CC_PLLCTL_ADDR            0x0660
1095  #define BCMA_CC_PLLCTL_DATA            0x0664
1096 +#define BCMA_CC_PMU_STRAPOPT           0x0668 /* (corerev >= 28) */
1097 +#define BCMA_CC_PMU_XTAL_FREQ          0x066C /* (pmurev >= 10) */
1098 +#define  BCMA_CC_PMU_XTAL_FREQ_ILPCTL_MASK     0x00001FFF
1099 +#define  BCMA_CC_PMU_XTAL_FREQ_MEASURE_MASK    0x80000000
1100 +#define  BCMA_CC_PMU_XTAL_FREQ_MEASURE_SHIFT   31
1101  #define BCMA_CC_SPROM                  0x0800 /* SPROM beginning */
1102  /* NAND flash MLC controller registers (corerev >= 38) */
1103  #define BCMA_CC_NAND_REVISION          0x0C00
1104 @@ -435,6 +442,23 @@
1105  #define  BCMA_CC_PMU6_4706_PROC_NDIV_MODE_MASK 0x00000007
1106  #define  BCMA_CC_PMU6_4706_PROC_NDIV_MODE_SHIFT        0
1107  
1108 +/* PMU rev 15 */
1109 +#define BCMA_CC_PMU15_PLL_PLLCTL0      0
1110 +#define  BCMA_CC_PMU15_PLL_PC0_CLKSEL_MASK     0x00000003
1111 +#define  BCMA_CC_PMU15_PLL_PC0_CLKSEL_SHIFT    0
1112 +#define  BCMA_CC_PMU15_PLL_PC0_FREQTGT_MASK    0x003FFFFC
1113 +#define  BCMA_CC_PMU15_PLL_PC0_FREQTGT_SHIFT   2
1114 +#define  BCMA_CC_PMU15_PLL_PC0_PRESCALE_MASK   0x00C00000
1115 +#define  BCMA_CC_PMU15_PLL_PC0_PRESCALE_SHIFT  22
1116 +#define  BCMA_CC_PMU15_PLL_PC0_KPCTRL_MASK     0x07000000
1117 +#define  BCMA_CC_PMU15_PLL_PC0_KPCTRL_SHIFT    24
1118 +#define  BCMA_CC_PMU15_PLL_PC0_FCNTCTRL_MASK   0x38000000
1119 +#define  BCMA_CC_PMU15_PLL_PC0_FCNTCTRL_SHIFT  27
1120 +#define  BCMA_CC_PMU15_PLL_PC0_FDCMODE_MASK    0x40000000
1121 +#define  BCMA_CC_PMU15_PLL_PC0_FDCMODE_SHIFT   30
1122 +#define  BCMA_CC_PMU15_PLL_PC0_CTRLBIAS_MASK   0x80000000
1123 +#define  BCMA_CC_PMU15_PLL_PC0_CTRLBIAS_SHIFT  31
1124 +
1125  /* ALP clock on pre-PMU chips */
1126  #define BCMA_CC_PMU_ALP_CLOCK          20000000
1127  /* HT clock for systems with PMU-enabled chipcommon */
1128 @@ -507,6 +531,37 @@
1129  #define BCMA_CHIPCTL_5357_I2S_PINS_ENABLE      BIT(18)
1130  #define BCMA_CHIPCTL_5357_I2CSPI_PINS_ENABLE   BIT(19)
1131  
1132 +#define BCMA_RES_4314_LPLDO_PU                 BIT(0)
1133 +#define BCMA_RES_4314_PMU_SLEEP_DIS            BIT(1)
1134 +#define BCMA_RES_4314_PMU_BG_PU                        BIT(2)
1135 +#define BCMA_RES_4314_CBUCK_LPOM_PU            BIT(3)
1136 +#define BCMA_RES_4314_CBUCK_PFM_PU             BIT(4)
1137 +#define BCMA_RES_4314_CLDO_PU                  BIT(5)
1138 +#define BCMA_RES_4314_LPLDO2_LVM               BIT(6)
1139 +#define BCMA_RES_4314_WL_PMU_PU                        BIT(7)
1140 +#define BCMA_RES_4314_LNLDO_PU                 BIT(8)
1141 +#define BCMA_RES_4314_LDO3P3_PU                        BIT(9)
1142 +#define BCMA_RES_4314_OTP_PU                   BIT(10)
1143 +#define BCMA_RES_4314_XTAL_PU                  BIT(11)
1144 +#define BCMA_RES_4314_WL_PWRSW_PU              BIT(12)
1145 +#define BCMA_RES_4314_LQ_AVAIL                 BIT(13)
1146 +#define BCMA_RES_4314_LOGIC_RET                        BIT(14)
1147 +#define BCMA_RES_4314_MEM_SLEEP                        BIT(15)
1148 +#define BCMA_RES_4314_MACPHY_RET               BIT(16)
1149 +#define BCMA_RES_4314_WL_CORE_READY            BIT(17)
1150 +#define BCMA_RES_4314_ILP_REQ                  BIT(18)
1151 +#define BCMA_RES_4314_ALP_AVAIL                        BIT(19)
1152 +#define BCMA_RES_4314_MISC_PWRSW_PU            BIT(20)
1153 +#define BCMA_RES_4314_SYNTH_PWRSW_PU           BIT(21)
1154 +#define BCMA_RES_4314_RX_PWRSW_PU              BIT(22)
1155 +#define BCMA_RES_4314_RADIO_PU                 BIT(23)
1156 +#define BCMA_RES_4314_VCO_LDO_PU               BIT(24)
1157 +#define BCMA_RES_4314_AFE_LDO_PU               BIT(25)
1158 +#define BCMA_RES_4314_RX_LDO_PU                        BIT(26)
1159 +#define BCMA_RES_4314_TX_LDO_PU                        BIT(27)
1160 +#define BCMA_RES_4314_HT_AVAIL                 BIT(28)
1161 +#define BCMA_RES_4314_MACPHY_CLK_AVAIL         BIT(29)
1162 +
1163  /* Data for the PMU, if available.
1164   * Check availability with ((struct bcma_chipcommon)->capabilities & BCMA_CC_CAP_PMU)
1165   */
1166 @@ -585,6 +640,7 @@ struct bcma_drv_cc {
1167         spinlock_t gpio_lock;
1168  #ifdef CONFIG_BCMA_DRIVER_GPIO
1169         struct gpio_chip gpio;
1170 +       struct irq_domain *irq_domain;
1171  #endif
1172  };
1173  
1174 --- a/include/linux/bcma/bcma_driver_pci.h
1175 +++ b/include/linux/bcma/bcma_driver_pci.h
1176 @@ -181,10 +181,31 @@ struct pci_dev;
1177  
1178  #define BCMA_CORE_PCI_CFG_DEVCTRL              0xd8
1179  
1180 +#define BCMA_CORE_PCI_
1181 +
1182 +/* MDIO devices (SERDES modules) */
1183 +#define BCMA_CORE_PCI_MDIO_IEEE0               0x000
1184 +#define BCMA_CORE_PCI_MDIO_IEEE1               0x001
1185 +#define BCMA_CORE_PCI_MDIO_BLK0                        0x800
1186 +#define BCMA_CORE_PCI_MDIO_BLK1                        0x801
1187 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT0         0x16
1188 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT1         0x17
1189 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT2         0x18
1190 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT3         0x19
1191 +#define  BCMA_CORE_PCI_MDIO_BLK1_MGMT4         0x1A
1192 +#define BCMA_CORE_PCI_MDIO_BLK2                        0x802
1193 +#define BCMA_CORE_PCI_MDIO_BLK3                        0x803
1194 +#define BCMA_CORE_PCI_MDIO_BLK4                        0x804
1195 +#define BCMA_CORE_PCI_MDIO_TXPLL               0x808   /* TXPLL register block idx */
1196 +#define BCMA_CORE_PCI_MDIO_TXCTRL0             0x820
1197 +#define BCMA_CORE_PCI_MDIO_SERDESID            0x831
1198 +#define BCMA_CORE_PCI_MDIO_RXCTRL0             0x840
1199 +
1200  /* PCIE Root Capability Register bits (Host mode only) */
1201  #define BCMA_CORE_PCI_RC_CRS_VISIBILITY                0x0001
1202  
1203  struct bcma_drv_pci;
1204 +struct bcma_bus;
1205  
1206  #ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE
1207  struct bcma_drv_pci_host {
1208 @@ -219,7 +240,9 @@ struct bcma_drv_pci {
1209  extern void bcma_core_pci_init(struct bcma_drv_pci *pc);
1210  extern int bcma_core_pci_irq_ctl(struct bcma_drv_pci *pc,
1211                                  struct bcma_device *core, bool enable);
1212 -extern void bcma_core_pci_extend_L1timer(struct bcma_drv_pci *pc, bool extend);
1213 +extern void bcma_core_pci_up(struct bcma_bus *bus);
1214 +extern void bcma_core_pci_down(struct bcma_bus *bus);
1215 +extern void bcma_core_pci_power_save(struct bcma_bus *bus, bool up);
1216  
1217  extern int bcma_core_pci_pcibios_map_irq(const struct pci_dev *dev);
1218  extern int bcma_core_pci_plat_dev_init(struct pci_dev *dev);
1219 --- a/drivers/net/wireless/brcm80211/brcmsmac/aiutils.c
1220 +++ b/drivers/net/wireless/brcm80211/brcmsmac/aiutils.c
1221 @@ -679,27 +679,6 @@ bool ai_clkctl_cc(struct si_pub *sih, en
1222         return mode == BCMA_CLKMODE_FAST;
1223  }
1224  
1225 -void ai_pci_up(struct si_pub *sih)
1226 -{
1227 -       struct si_info *sii;
1228 -
1229 -       sii = container_of(sih, struct si_info, pub);
1230 -
1231 -       if (sii->icbus->hosttype == BCMA_HOSTTYPE_PCI)
1232 -               bcma_core_pci_extend_L1timer(&sii->icbus->drv_pci[0], true);
1233 -}
1234 -
1235 -/* Unconfigure and/or apply various WARs when going down */
1236 -void ai_pci_down(struct si_pub *sih)
1237 -{
1238 -       struct si_info *sii;
1239 -
1240 -       sii = container_of(sih, struct si_info, pub);
1241 -
1242 -       if (sii->icbus->hosttype == BCMA_HOSTTYPE_PCI)
1243 -               bcma_core_pci_extend_L1timer(&sii->icbus->drv_pci[0], false);
1244 -}
1245 -
1246  /* Enable BT-COEX & Ex-PA for 4313 */
1247  void ai_epa_4313war(struct si_pub *sih)
1248  {
1249 --- a/drivers/net/wireless/brcm80211/brcmsmac/aiutils.h
1250 +++ b/drivers/net/wireless/brcm80211/brcmsmac/aiutils.h
1251 @@ -183,9 +183,6 @@ extern u16 ai_clkctl_fast_pwrup_delay(st
1252  extern bool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode);
1253  extern bool ai_deviceremoved(struct si_pub *sih);
1254  
1255 -extern void ai_pci_down(struct si_pub *sih);
1256 -extern void ai_pci_up(struct si_pub *sih);
1257 -
1258  /* Enable Ex-PA for 4313 */
1259  extern void ai_epa_4313war(struct si_pub *sih);
1260  
1261 --- a/drivers/net/wireless/brcm80211/brcmsmac/main.c
1262 +++ b/drivers/net/wireless/brcm80211/brcmsmac/main.c
1263 @@ -4667,7 +4667,7 @@ static int brcms_b_attach(struct brcms_c
1264         brcms_c_coredisable(wlc_hw);
1265  
1266         /* Match driver "down" state */
1267 -       ai_pci_down(wlc_hw->sih);
1268 +       bcma_core_pci_down(wlc_hw->d11core->bus);
1269  
1270         /* turn off pll and xtal to match driver "down" state */
1271         brcms_b_xtal(wlc_hw, OFF);
1272 @@ -5010,12 +5010,12 @@ static int brcms_b_up_prep(struct brcms_
1273          */
1274         if (brcms_b_radio_read_hwdisabled(wlc_hw)) {
1275                 /* put SB PCI in down state again */
1276 -               ai_pci_down(wlc_hw->sih);
1277 +               bcma_core_pci_down(wlc_hw->d11core->bus);
1278                 brcms_b_xtal(wlc_hw, OFF);
1279                 return -ENOMEDIUM;
1280         }
1281  
1282 -       ai_pci_up(wlc_hw->sih);
1283 +       bcma_core_pci_up(wlc_hw->d11core->bus);
1284  
1285         /* reset the d11 core */
1286         brcms_b_corereset(wlc_hw, BRCMS_USE_COREFLAGS);
1287 @@ -5212,7 +5212,7 @@ static int brcms_b_down_finish(struct br
1288  
1289                 /* turn off primary xtal and pll */
1290                 if (!wlc_hw->noreset) {
1291 -                       ai_pci_down(wlc_hw->sih);
1292 +                       bcma_core_pci_down(wlc_hw->d11core->bus);
1293                         brcms_b_xtal(wlc_hw, OFF);
1294                 }
1295         }