kernel: bcma: update to wireless-testing master-2013-10-01
[openwrt/svn-archive/archive.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) {