kernel: update kernel 3.18 to version 3.18.23
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-3.18 / 026-bcma-from-3.20.patch
1 --- a/drivers/bcma/bcma_private.h
2 +++ b/drivers/bcma/bcma_private.h
3 @@ -25,22 +25,18 @@ struct bcma_bus;
4 bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
5 int timeout);
6 void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core);
7 +void bcma_init_bus(struct bcma_bus *bus);
8 int bcma_bus_register(struct bcma_bus *bus);
9 void bcma_bus_unregister(struct bcma_bus *bus);
10 -int __init bcma_bus_early_register(struct bcma_bus *bus,
11 - struct bcma_device *core_cc,
12 - struct bcma_device *core_mips);
13 +int __init bcma_bus_early_register(struct bcma_bus *bus);
14 #ifdef CONFIG_PM
15 int bcma_bus_suspend(struct bcma_bus *bus);
16 int bcma_bus_resume(struct bcma_bus *bus);
17 #endif
18
19 /* scan.c */
20 +void bcma_detect_chip(struct bcma_bus *bus);
21 int bcma_bus_scan(struct bcma_bus *bus);
22 -int __init bcma_bus_scan_early(struct bcma_bus *bus,
23 - struct bcma_device_id *match,
24 - struct bcma_device *core);
25 -void bcma_init_bus(struct bcma_bus *bus);
26
27 /* sprom.c */
28 int bcma_sprom_get(struct bcma_bus *bus);
29 @@ -111,6 +107,14 @@ extern int bcma_chipco_watchdog_register
30 #ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE
31 bool bcma_core_pci_is_in_hostmode(struct bcma_drv_pci *pc);
32 void bcma_core_pci_hostmode_init(struct bcma_drv_pci *pc);
33 +#else
34 +static inline bool bcma_core_pci_is_in_hostmode(struct bcma_drv_pci *pc)
35 +{
36 + return false;
37 +}
38 +static inline void bcma_core_pci_hostmode_init(struct bcma_drv_pci *pc)
39 +{
40 +}
41 #endif /* CONFIG_BCMA_DRIVER_PCI_HOSTMODE */
42
43 #ifdef CONFIG_BCMA_DRIVER_GPIO
44 --- a/drivers/bcma/driver_chipcommon.c
45 +++ b/drivers/bcma/driver_chipcommon.c
46 @@ -79,7 +79,9 @@ static int bcma_chipco_watchdog_ticks_pe
47
48 if (cc->capabilities & BCMA_CC_CAP_PMU) {
49 if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706)
50 - /* 4706 CC and PMU watchdogs are clocked at 1/4 of ALP clock */
51 + /* 4706 CC and PMU watchdogs are clocked at 1/4 of ALP
52 + * clock
53 + */
54 return bcma_chipco_get_alp_clock(cc) / 4000;
55 else
56 /* based on 32KHz ILP clock */
57 @@ -97,7 +99,8 @@ int bcma_chipco_watchdog_register(struct
58 wdt.driver_data = cc;
59 wdt.timer_set = bcma_chipco_watchdog_timer_set_wdt;
60 wdt.timer_set_ms = bcma_chipco_watchdog_timer_set_ms_wdt;
61 - wdt.max_timer_ms = bcma_chipco_watchdog_get_max_timer(cc) / cc->ticks_per_ms;
62 + wdt.max_timer_ms =
63 + bcma_chipco_watchdog_get_max_timer(cc) / cc->ticks_per_ms;
64
65 pdev = platform_device_register_data(NULL, "bcm47xx-wdt",
66 cc->core->bus->num, &wdt,
67 @@ -175,7 +178,6 @@ void bcma_core_chipcommon_init(struct bc
68 u32 bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks)
69 {
70 u32 maxt;
71 - enum bcma_clkmode clkmode;
72
73 maxt = bcma_chipco_watchdog_get_max_timer(cc);
74 if (cc->capabilities & BCMA_CC_CAP_PMU) {
75 @@ -185,8 +187,13 @@ u32 bcma_chipco_watchdog_timer_set(struc
76 ticks = maxt;
77 bcma_cc_write32(cc, BCMA_CC_PMU_WATCHDOG, ticks);
78 } else {
79 - clkmode = ticks ? BCMA_CLKMODE_FAST : BCMA_CLKMODE_DYNAMIC;
80 - bcma_core_set_clockmode(cc->core, clkmode);
81 + struct bcma_bus *bus = cc->core->bus;
82 +
83 + if (bus->chipinfo.id != BCMA_CHIP_ID_BCM4707 &&
84 + bus->chipinfo.id != BCMA_CHIP_ID_BCM53018)
85 + bcma_core_set_clockmode(cc->core,
86 + ticks ? BCMA_CLKMODE_FAST : BCMA_CLKMODE_DYNAMIC);
87 +
88 if (ticks > maxt)
89 ticks = maxt;
90 /* instant NMI */
91 @@ -335,7 +342,8 @@ void bcma_chipco_serial_init(struct bcma
92 | BCMA_CC_CORECTL_UARTCLKEN);
93 }
94 } else {
95 - bcma_err(cc->core->bus, "serial not supported on this device ccrev: 0x%x\n", ccrev);
96 + bcma_err(cc->core->bus, "serial not supported on this device ccrev: 0x%x\n",
97 + ccrev);
98 return;
99 }
100
101 --- a/drivers/bcma/driver_pci.c
102 +++ b/drivers/bcma/driver_pci.c
103 @@ -145,6 +145,47 @@ static u16 bcma_pcie_mdio_writeread(stru
104 }
105
106 /**************************************************
107 + * Early init.
108 + **************************************************/
109 +
110 +static void bcma_core_pci_fixcfg(struct bcma_drv_pci *pc)
111 +{
112 + struct bcma_device *core = pc->core;
113 + u16 val16, core_index;
114 + uint regoff;
115 +
116 + regoff = BCMA_CORE_PCI_SPROM(BCMA_CORE_PCI_SPROM_PI_OFFSET);
117 + core_index = (u16)core->core_index;
118 +
119 + val16 = pcicore_read16(pc, regoff);
120 + if (((val16 & BCMA_CORE_PCI_SPROM_PI_MASK) >> BCMA_CORE_PCI_SPROM_PI_SHIFT)
121 + != core_index) {
122 + val16 = (core_index << BCMA_CORE_PCI_SPROM_PI_SHIFT) |
123 + (val16 & ~BCMA_CORE_PCI_SPROM_PI_MASK);
124 + pcicore_write16(pc, regoff, val16);
125 + }
126 +}
127 +
128 +/*
129 + * Apply some early fixes required before accessing SPROM.
130 + * See also si_pci_fixcfg.
131 + */
132 +void bcma_core_pci_early_init(struct bcma_drv_pci *pc)
133 +{
134 + if (pc->early_setup_done)
135 + return;
136 +
137 + pc->hostmode = bcma_core_pci_is_in_hostmode(pc);
138 + if (pc->hostmode)
139 + goto out;
140 +
141 + bcma_core_pci_fixcfg(pc);
142 +
143 +out:
144 + pc->early_setup_done = true;
145 +}
146 +
147 +/**************************************************
148 * Workarounds.
149 **************************************************/
150
151 @@ -175,24 +216,6 @@ static void bcma_pcicore_serdes_workarou
152 tmp & ~BCMA_CORE_PCI_PLL_CTRL_FREQDET_EN);
153 }
154
155 -static void bcma_core_pci_fixcfg(struct bcma_drv_pci *pc)
156 -{
157 - struct bcma_device *core = pc->core;
158 - u16 val16, core_index;
159 - uint regoff;
160 -
161 - regoff = BCMA_CORE_PCI_SPROM(BCMA_CORE_PCI_SPROM_PI_OFFSET);
162 - core_index = (u16)core->core_index;
163 -
164 - val16 = pcicore_read16(pc, regoff);
165 - if (((val16 & BCMA_CORE_PCI_SPROM_PI_MASK) >> BCMA_CORE_PCI_SPROM_PI_SHIFT)
166 - != core_index) {
167 - val16 = (core_index << BCMA_CORE_PCI_SPROM_PI_SHIFT) |
168 - (val16 & ~BCMA_CORE_PCI_SPROM_PI_MASK);
169 - pcicore_write16(pc, regoff, val16);
170 - }
171 -}
172 -
173 /* Fix MISC config to allow coming out of L2/L3-Ready state w/o PRST */
174 /* Needs to happen when coming out of 'standby'/'hibernate' */
175 static void bcma_core_pci_config_fixup(struct bcma_drv_pci *pc)
176 @@ -216,7 +239,6 @@ static void bcma_core_pci_config_fixup(s
177
178 static void bcma_core_pci_clientmode_init(struct bcma_drv_pci *pc)
179 {
180 - bcma_core_pci_fixcfg(pc);
181 bcma_pcicore_serdes_workaround(pc);
182 bcma_core_pci_config_fixup(pc);
183 }
184 @@ -226,13 +248,11 @@ void bcma_core_pci_init(struct bcma_drv_
185 if (pc->setup_done)
186 return;
187
188 -#ifdef CONFIG_BCMA_DRIVER_PCI_HOSTMODE
189 - pc->hostmode = bcma_core_pci_is_in_hostmode(pc);
190 + bcma_core_pci_early_init(pc);
191 +
192 if (pc->hostmode)
193 bcma_core_pci_hostmode_init(pc);
194 -#endif /* CONFIG_BCMA_DRIVER_PCI_HOSTMODE */
195 -
196 - if (!pc->hostmode)
197 + else
198 bcma_core_pci_clientmode_init(pc);
199 }
200
201 --- a/drivers/bcma/host_pci.c
202 +++ b/drivers/bcma/host_pci.c
203 @@ -13,10 +13,12 @@
204
205 static void bcma_host_pci_switch_core(struct bcma_device *core)
206 {
207 + int win2 = core->bus->host_is_pcie2 ?
208 + BCMA_PCIE2_BAR0_WIN2 : BCMA_PCI_BAR0_WIN2;
209 +
210 pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN,
211 core->addr);
212 - pci_write_config_dword(core->bus->host_pci, BCMA_PCI_BAR0_WIN2,
213 - core->wrap);
214 + pci_write_config_dword(core->bus->host_pci, win2, core->wrap);
215 core->bus->mapped_core = core;
216 bcma_debug(core->bus, "Switched to core: 0x%X\n", core->id.id);
217 }
218 --- a/drivers/bcma/host_soc.c
219 +++ b/drivers/bcma/host_soc.c
220 @@ -193,7 +193,7 @@ int __init bcma_host_soc_init(struct bcm
221 int err;
222
223 /* Scan bus and initialize it */
224 - err = bcma_bus_early_register(bus, &soc->core_cc, &soc->core_mips);
225 + err = bcma_bus_early_register(bus);
226 if (err)
227 iounmap(bus->mmio);
228
229 --- a/drivers/bcma/main.c
230 +++ b/drivers/bcma/main.c
231 @@ -268,6 +268,18 @@ void bcma_prepare_core(struct bcma_bus *
232 }
233 }
234
235 +void bcma_init_bus(struct bcma_bus *bus)
236 +{
237 + mutex_lock(&bcma_buses_mutex);
238 + bus->num = bcma_bus_next_num++;
239 + mutex_unlock(&bcma_buses_mutex);
240 +
241 + INIT_LIST_HEAD(&bus->cores);
242 + bus->nr_cores = 0;
243 +
244 + bcma_detect_chip(bus);
245 +}
246 +
247 static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core)
248 {
249 int err;
250 @@ -356,12 +368,19 @@ static void bcma_unregister_cores(struct
251 struct bcma_device *core, *tmp;
252
253 list_for_each_entry_safe(core, tmp, &bus->cores, list) {
254 + if (!core->dev_registered)
255 + continue;
256 list_del(&core->list);
257 - if (core->dev_registered)
258 - device_unregister(&core->dev);
259 + device_unregister(&core->dev);
260 }
261 if (bus->hosttype == BCMA_HOSTTYPE_SOC)
262 platform_device_unregister(bus->drv_cc.watchdog);
263 +
264 + /* Now noone uses internally-handled cores, we can free them */
265 + list_for_each_entry_safe(core, tmp, &bus->cores, list) {
266 + list_del(&core->list);
267 + kfree(core);
268 + }
269 }
270
271 int bcma_bus_register(struct bcma_bus *bus)
272 @@ -369,10 +388,6 @@ int bcma_bus_register(struct bcma_bus *b
273 int err;
274 struct bcma_device *core;
275
276 - mutex_lock(&bcma_buses_mutex);
277 - bus->num = bcma_bus_next_num++;
278 - mutex_unlock(&bcma_buses_mutex);
279 -
280 /* Scan for devices (cores) */
281 err = bcma_bus_scan(bus);
282 if (err) {
283 @@ -387,6 +402,13 @@ int bcma_bus_register(struct bcma_bus *b
284 bcma_core_chipcommon_early_init(&bus->drv_cc);
285 }
286
287 + /* Early init PCIE core */
288 + core = bcma_find_core(bus, BCMA_CORE_PCIE);
289 + if (core) {
290 + bus->drv_pci[0].core = core;
291 + bcma_core_pci_early_init(&bus->drv_pci[0]);
292 + }
293 +
294 /* Cores providing flash access go before SPROM init */
295 list_for_each_entry(core, &bus->cores, list) {
296 if (bcma_is_core_needed_early(core->id.id))
297 @@ -459,7 +481,6 @@ int bcma_bus_register(struct bcma_bus *b
298
299 void bcma_bus_unregister(struct bcma_bus *bus)
300 {
301 - struct bcma_device *cores[3];
302 int err;
303
304 err = bcma_gpio_unregister(&bus->drv_cc);
305 @@ -470,46 +491,23 @@ void bcma_bus_unregister(struct bcma_bus
306
307 bcma_core_chipcommon_b_free(&bus->drv_cc_b);
308
309 - cores[0] = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
310 - cores[1] = bcma_find_core(bus, BCMA_CORE_PCIE);
311 - cores[2] = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON);
312 -
313 bcma_unregister_cores(bus);
314 -
315 - kfree(cores[2]);
316 - kfree(cores[1]);
317 - kfree(cores[0]);
318 }
319
320 -int __init bcma_bus_early_register(struct bcma_bus *bus,
321 - struct bcma_device *core_cc,
322 - struct bcma_device *core_mips)
323 +/*
324 + * This is a special version of bus registration function designed for SoCs.
325 + * It scans bus and performs basic initialization of main cores only.
326 + * Please note it requires memory allocation, however it won't try to sleep.
327 + */
328 +int __init bcma_bus_early_register(struct bcma_bus *bus)
329 {
330 int err;
331 struct bcma_device *core;
332 - struct bcma_device_id match;
333 -
334 - match.manuf = BCMA_MANUF_BCM;
335 - match.id = bcma_cc_core_id(bus);
336 - match.class = BCMA_CL_SIM;
337 - match.rev = BCMA_ANY_REV;
338
339 - /* Scan for chip common core */
340 - err = bcma_bus_scan_early(bus, &match, core_cc);
341 - if (err) {
342 - bcma_err(bus, "Failed to scan for common core: %d\n", err);
343 - return -1;
344 - }
345 -
346 - match.manuf = BCMA_MANUF_MIPS;
347 - match.id = BCMA_CORE_MIPS_74K;
348 - match.class = BCMA_CL_SIM;
349 - match.rev = BCMA_ANY_REV;
350 -
351 - /* Scan for mips core */
352 - err = bcma_bus_scan_early(bus, &match, core_mips);
353 + /* Scan for devices (cores) */
354 + err = bcma_bus_scan(bus);
355 if (err) {
356 - bcma_err(bus, "Failed to scan for mips core: %d\n", err);
357 + bcma_err(bus, "Failed to scan bus: %d\n", err);
358 return -1;
359 }
360
361 --- a/drivers/bcma/scan.c
362 +++ b/drivers/bcma/scan.c
363 @@ -435,15 +435,12 @@ static int bcma_get_next_core(struct bcm
364 return 0;
365 }
366
367 -void bcma_init_bus(struct bcma_bus *bus)
368 +void bcma_detect_chip(struct bcma_bus *bus)
369 {
370 s32 tmp;
371 struct bcma_chipinfo *chipinfo = &(bus->chipinfo);
372 char chip_id[8];
373
374 - INIT_LIST_HEAD(&bus->cores);
375 - bus->nr_cores = 0;
376 -
377 bcma_scan_switch_core(bus, BCMA_ADDR_BASE);
378
379 tmp = bcma_scan_read32(bus, 0, BCMA_CC_ID);
380 @@ -464,6 +461,10 @@ int bcma_bus_scan(struct bcma_bus *bus)
381
382 int err, core_num = 0;
383
384 + /* Skip if bus was already scanned (e.g. during early register) */
385 + if (bus->nr_cores)
386 + return 0;
387 +
388 erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
389 if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
390 eromptr = ioremap_nocache(erombase, BCMA_CORE_SIZE);
391 @@ -519,64 +520,6 @@ int bcma_bus_scan(struct bcma_bus *bus)
392 out:
393 if (bus->hosttype == BCMA_HOSTTYPE_SOC)
394 iounmap(eromptr);
395 -
396 - return err;
397 -}
398 -
399 -int __init bcma_bus_scan_early(struct bcma_bus *bus,
400 - struct bcma_device_id *match,
401 - struct bcma_device *core)
402 -{
403 - u32 erombase;
404 - u32 __iomem *eromptr, *eromend;
405 -
406 - int err = -ENODEV;
407 - int core_num = 0;
408 -
409 - erombase = bcma_scan_read32(bus, 0, BCMA_CC_EROM);
410 - if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
411 - eromptr = ioremap_nocache(erombase, BCMA_CORE_SIZE);
412 - if (!eromptr)
413 - return -ENOMEM;
414 - } else {
415 - eromptr = bus->mmio;
416 - }
417 -
418 - eromend = eromptr + BCMA_CORE_SIZE / sizeof(u32);
419 -
420 - bcma_scan_switch_core(bus, erombase);
421 -
422 - while (eromptr < eromend) {
423 - memset(core, 0, sizeof(*core));
424 - INIT_LIST_HEAD(&core->list);
425 - core->bus = bus;
426 -
427 - err = bcma_get_next_core(bus, &eromptr, match, core_num, core);
428 - if (err == -ENODEV) {
429 - core_num++;
430 - continue;
431 - } else if (err == -ENXIO)
432 - continue;
433 - else if (err == -ESPIPE)
434 - break;
435 - else if (err < 0)
436 - goto out;
437 -
438 - core->core_index = core_num++;
439 - bus->nr_cores++;
440 - bcma_info(bus, "Core %d found: %s (manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
441 - core->core_index, bcma_device_name(&core->id),
442 - core->id.manuf, core->id.id, core->id.rev,
443 - core->id.class);
444 -
445 - list_add_tail(&core->list, &bus->cores);
446 - err = 0;
447 - break;
448 - }
449 -
450 -out:
451 - if (bus->hosttype == BCMA_HOSTTYPE_SOC)
452 - iounmap(eromptr);
453
454 return err;
455 }
456 --- a/drivers/bcma/sprom.c
457 +++ b/drivers/bcma/sprom.c
458 @@ -579,7 +579,8 @@ int bcma_sprom_get(struct bcma_bus *bus)
459 u16 offset = BCMA_CC_SPROM;
460 u16 *sprom;
461 size_t sprom_sizes[] = { SSB_SPROMSIZE_WORDS_R4,
462 - SSB_SPROMSIZE_WORDS_R10, };
463 + SSB_SPROMSIZE_WORDS_R10,
464 + SSB_SPROMSIZE_WORDS_R11, };
465 int i, err = 0;
466
467 if (!bus->drv_cc.core)
468 --- a/include/linux/bcma/bcma.h
469 +++ b/include/linux/bcma/bcma.h
470 @@ -318,6 +318,7 @@ struct bcma_bus {
471 const struct bcma_host_ops *ops;
472
473 enum bcma_hosttype hosttype;
474 + bool host_is_pcie2; /* Used for BCMA_HOSTTYPE_PCI only */
475 union {
476 /* Pointer to the PCI bus (only for BCMA_HOSTTYPE_PCI) */
477 struct pci_dev *host_pci;
478 --- a/include/linux/bcma/bcma_driver_pci.h
479 +++ b/include/linux/bcma/bcma_driver_pci.h
480 @@ -223,6 +223,7 @@ struct bcma_drv_pci_host {
481
482 struct bcma_drv_pci {
483 struct bcma_device *core;
484 + u8 early_setup_done:1;
485 u8 setup_done:1;
486 u8 hostmode:1;
487
488 @@ -237,6 +238,7 @@ struct bcma_drv_pci {
489 #define pcicore_write16(pc, offset, val) bcma_write16((pc)->core, offset, val)
490 #define pcicore_write32(pc, offset, val) bcma_write32((pc)->core, offset, val)
491
492 +extern void bcma_core_pci_early_init(struct bcma_drv_pci *pc);
493 extern void bcma_core_pci_init(struct bcma_drv_pci *pc);
494 extern int bcma_core_pci_irq_ctl(struct bcma_drv_pci *pc,
495 struct bcma_device *core, bool enable);
496 --- a/include/linux/bcma/bcma_regs.h
497 +++ b/include/linux/bcma/bcma_regs.h
498 @@ -64,6 +64,8 @@
499 #define BCMA_PCI_GPIO_XTAL 0x40 /* PCI config space GPIO 14 for Xtal powerup */
500 #define BCMA_PCI_GPIO_PLL 0x80 /* PCI config space GPIO 15 for PLL powerdown */
501
502 +#define BCMA_PCIE2_BAR0_WIN2 0x70
503 +
504 /* SiliconBackplane Address Map.
505 * All regions may not exist on all chips.
506 */
507 --- a/include/linux/bcma/bcma_soc.h
508 +++ b/include/linux/bcma/bcma_soc.h
509 @@ -5,8 +5,6 @@
510
511 struct bcma_soc {
512 struct bcma_bus bus;
513 - struct bcma_device core_cc;
514 - struct bcma_device core_mips;
515 };
516
517 int __init bcma_host_soc_register(struct bcma_soc *soc);
518 --- a/include/linux/ssb/ssb_regs.h
519 +++ b/include/linux/ssb/ssb_regs.h
520 @@ -173,6 +173,7 @@
521 #define SSB_SPROMSIZE_BYTES_R123 (SSB_SPROMSIZE_WORDS_R123 * sizeof(u16))
522 #define SSB_SPROMSIZE_BYTES_R4 (SSB_SPROMSIZE_WORDS_R4 * sizeof(u16))
523 #define SSB_SPROMSIZE_WORDS_R10 230
524 +#define SSB_SPROMSIZE_WORDS_R11 234
525 #define SSB_SPROM_BASE1 0x1000
526 #define SSB_SPROM_BASE31 0x0800
527 #define SSB_SPROM_REVISION 0x007E