kernel: update ssb and bcma to linux-next next-20110627
[openwrt.git] / target / linux / generic / patches-2.6.39 / 020-ssb_update.patch
1 --- a/drivers/ssb/driver_chipcommon.c
2 +++ b/drivers/ssb/driver_chipcommon.c
3 @@ -46,40 +46,66 @@ void ssb_chipco_set_clockmode(struct ssb
4         if (!ccdev)
5                 return;
6         bus = ccdev->bus;
7 +
8 +       /* We support SLOW only on 6..9 */
9 +       if (ccdev->id.revision >= 10 && mode == SSB_CLKMODE_SLOW)
10 +               mode = SSB_CLKMODE_DYNAMIC;
11 +
12 +       if (cc->capabilities & SSB_CHIPCO_CAP_PMU)
13 +               return; /* PMU controls clockmode, separated function needed */
14 +       SSB_WARN_ON(ccdev->id.revision >= 20);
15 +
16         /* chipcommon cores prior to rev6 don't support dynamic clock control */
17         if (ccdev->id.revision < 6)
18                 return;
19 -       /* chipcommon cores rev10 are a whole new ball game */
20 +
21 +       /* ChipCommon cores rev10+ need testing */
22         if (ccdev->id.revision >= 10)
23                 return;
24 +
25         if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
26                 return;
27  
28         switch (mode) {
29 -       case SSB_CLKMODE_SLOW:
30 +       case SSB_CLKMODE_SLOW: /* For revs 6..9 only */
31                 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
32                 tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW;
33                 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
34                 break;
35         case SSB_CLKMODE_FAST:
36 -               ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */
37 -               tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
38 -               tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
39 -               tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL;
40 -               chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
41 +               if (ccdev->id.revision < 10) {
42 +                       ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */
43 +                       tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
44 +                       tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
45 +                       tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL;
46 +                       chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
47 +               } else {
48 +                       chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
49 +                               (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) |
50 +                                SSB_CHIPCO_SYSCLKCTL_FORCEHT));
51 +                       /* udelay(150); TODO: not available in early init */
52 +               }
53                 break;
54         case SSB_CLKMODE_DYNAMIC:
55 -               tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
56 -               tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
57 -               tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL;
58 -               tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
59 -               if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) != SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL)
60 -                       tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
61 -               chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
62 -
63 -               /* for dynamic control, we have to release our xtal_pu "force on" */
64 -               if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL)
65 -                       ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0);
66 +               if (ccdev->id.revision < 10) {
67 +                       tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
68 +                       tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
69 +                       tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL;
70 +                       tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
71 +                       if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) !=
72 +                           SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL)
73 +                               tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
74 +                       chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
75 +
76 +                       /* For dynamic control, we have to release our xtal_pu
77 +                        * "force on" */
78 +                       if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL)
79 +                               ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0);
80 +               } else {
81 +                       chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
82 +                               (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) &
83 +                                ~SSB_CHIPCO_SYSCLKCTL_FORCEHT));
84 +               }
85                 break;
86         default:
87                 SSB_WARN_ON(1);
88 @@ -260,6 +286,12 @@ void ssb_chipcommon_init(struct ssb_chip
89         if (cc->dev->id.revision >= 11)
90                 cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT);
91         ssb_dprintk(KERN_INFO PFX "chipcommon status is 0x%x\n", cc->status);
92 +
93 +       if (cc->dev->id.revision >= 20) {
94 +               chipco_write32(cc, SSB_CHIPCO_GPIOPULLUP, 0);
95 +               chipco_write32(cc, SSB_CHIPCO_GPIOPULLDOWN, 0);
96 +       }
97 +
98         ssb_pmu_init(cc);
99         chipco_powercontrol_init(cc);
100         ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
101 --- a/drivers/ssb/driver_chipcommon_pmu.c
102 +++ b/drivers/ssb/driver_chipcommon_pmu.c
103 @@ -417,12 +417,14 @@ static void ssb_pmu_resources_init(struc
104         u32 min_msk = 0, max_msk = 0;
105         unsigned int i;
106         const struct pmu_res_updown_tab_entry *updown_tab = NULL;
107 -       unsigned int updown_tab_size;
108 +       unsigned int updown_tab_size = 0;
109         const struct pmu_res_depend_tab_entry *depend_tab = NULL;
110 -       unsigned int depend_tab_size;
111 +       unsigned int depend_tab_size = 0;
112  
113         switch (bus->chip_id) {
114         case 0x4312:
115 +                min_msk = 0xCBB;
116 +                break;
117         case 0x4322:
118                 /* We keep the default settings:
119                  * min_msk = 0xCBB
120 --- a/drivers/ssb/driver_gige.c
121 +++ b/drivers/ssb/driver_gige.c
122 @@ -106,8 +106,9 @@ void gige_pcicfg_write32(struct ssb_gige
123         gige_write32(dev, SSB_GIGE_PCICFG + offset, value);
124  }
125  
126 -static int ssb_gige_pci_read_config(struct pci_bus *bus, unsigned int devfn,
127 -                                   int reg, int size, u32 *val)
128 +static int __devinit ssb_gige_pci_read_config(struct pci_bus *bus,
129 +                                             unsigned int devfn, int reg,
130 +                                             int size, u32 *val)
131  {
132         struct ssb_gige *dev = container_of(bus->ops, struct ssb_gige, pci_ops);
133         unsigned long flags;
134 @@ -136,8 +137,9 @@ static int ssb_gige_pci_read_config(stru
135         return PCIBIOS_SUCCESSFUL;
136  }
137  
138 -static int ssb_gige_pci_write_config(struct pci_bus *bus, unsigned int devfn,
139 -                                    int reg, int size, u32 val)
140 +static int __devinit ssb_gige_pci_write_config(struct pci_bus *bus,
141 +                                              unsigned int devfn, int reg,
142 +                                              int size, u32 val)
143  {
144         struct ssb_gige *dev = container_of(bus->ops, struct ssb_gige, pci_ops);
145         unsigned long flags;
146 @@ -166,7 +168,8 @@ static int ssb_gige_pci_write_config(str
147         return PCIBIOS_SUCCESSFUL;
148  }
149  
150 -static int ssb_gige_probe(struct ssb_device *sdev, const struct ssb_device_id *id)
151 +static int __devinit ssb_gige_probe(struct ssb_device *sdev,
152 +                                   const struct ssb_device_id *id)
153  {
154         struct ssb_gige *dev;
155         u32 base, tmslow, tmshigh;
156 --- a/drivers/ssb/driver_pcicore.c
157 +++ b/drivers/ssb/driver_pcicore.c
158 @@ -15,6 +15,11 @@
159  
160  #include "ssb_private.h"
161  
162 +static u32 ssb_pcie_read(struct ssb_pcicore *pc, u32 address);
163 +static void ssb_pcie_write(struct ssb_pcicore *pc, u32 address, u32 data);
164 +static u16 ssb_pcie_mdio_read(struct ssb_pcicore *pc, u8 device, u8 address);
165 +static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
166 +                               u8 address, u16 data);
167  
168  static inline
169  u32 pcicore_read32(struct ssb_pcicore *pc, u16 offset)
170 @@ -309,7 +314,7 @@ int ssb_pcicore_pcibios_map_irq(const st
171         return ssb_mips_irq(extpci_core->dev) + 2;
172  }
173  
174 -static void ssb_pcicore_init_hostmode(struct ssb_pcicore *pc)
175 +static void __devinit ssb_pcicore_init_hostmode(struct ssb_pcicore *pc)
176  {
177         u32 val;
178  
179 @@ -374,7 +379,7 @@ static void ssb_pcicore_init_hostmode(st
180         register_pci_controller(&ssb_pcicore_controller);
181  }
182  
183 -static int pcicore_is_in_hostmode(struct ssb_pcicore *pc)
184 +static int __devinit pcicore_is_in_hostmode(struct ssb_pcicore *pc)
185  {
186         struct ssb_bus *bus = pc->dev->bus;
187         u16 chipid_top;
188 @@ -403,28 +408,129 @@ static int pcicore_is_in_hostmode(struct
189  }
190  #endif /* CONFIG_SSB_PCICORE_HOSTMODE */
191  
192 +/**************************************************
193 + * Workarounds.
194 + **************************************************/
195 +
196 +static void __devinit ssb_pcicore_fix_sprom_core_index(struct ssb_pcicore *pc)
197 +{
198 +       u16 tmp = pcicore_read16(pc, SSB_PCICORE_SPROM(0));
199 +       if (((tmp & 0xF000) >> 12) != pc->dev->core_index) {
200 +               tmp &= ~0xF000;
201 +               tmp |= (pc->dev->core_index << 12);
202 +               pcicore_write16(pc, SSB_PCICORE_SPROM(0), tmp);
203 +       }
204 +}
205 +
206 +static u8 ssb_pcicore_polarity_workaround(struct ssb_pcicore *pc)
207 +{
208 +       return (ssb_pcie_read(pc, 0x204) & 0x10) ? 0xC0 : 0x80;
209 +}
210 +
211 +static void ssb_pcicore_serdes_workaround(struct ssb_pcicore *pc)
212 +{
213 +       const u8 serdes_pll_device = 0x1D;
214 +       const u8 serdes_rx_device = 0x1F;
215 +       u16 tmp;
216 +
217 +       ssb_pcie_mdio_write(pc, serdes_rx_device, 1 /* Control */,
218 +                           ssb_pcicore_polarity_workaround(pc));
219 +       tmp = ssb_pcie_mdio_read(pc, serdes_pll_device, 1 /* Control */);
220 +       if (tmp & 0x4000)
221 +               ssb_pcie_mdio_write(pc, serdes_pll_device, 1, tmp & ~0x4000);
222 +}
223 +
224 +static void ssb_pcicore_pci_setup_workarounds(struct ssb_pcicore *pc)
225 +{
226 +       struct ssb_device *pdev = pc->dev;
227 +       struct ssb_bus *bus = pdev->bus;
228 +       u32 tmp;
229 +
230 +       tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
231 +       tmp |= SSB_PCICORE_SBTOPCI_PREF;
232 +       tmp |= SSB_PCICORE_SBTOPCI_BURST;
233 +       pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
234 +
235 +       if (pdev->id.revision < 5) {
236 +               tmp = ssb_read32(pdev, SSB_IMCFGLO);
237 +               tmp &= ~SSB_IMCFGLO_SERTO;
238 +               tmp |= 2;
239 +               tmp &= ~SSB_IMCFGLO_REQTO;
240 +               tmp |= 3 << SSB_IMCFGLO_REQTO_SHIFT;
241 +               ssb_write32(pdev, SSB_IMCFGLO, tmp);
242 +               ssb_commit_settings(bus);
243 +       } else if (pdev->id.revision >= 11) {
244 +               tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
245 +               tmp |= SSB_PCICORE_SBTOPCI_MRM;
246 +               pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
247 +       }
248 +}
249 +
250 +static void ssb_pcicore_pcie_setup_workarounds(struct ssb_pcicore *pc)
251 +{
252 +       u32 tmp;
253 +       u8 rev = pc->dev->id.revision;
254 +
255 +       if (rev == 0 || rev == 1) {
256 +               /* TLP Workaround register. */
257 +               tmp = ssb_pcie_read(pc, 0x4);
258 +               tmp |= 0x8;
259 +               ssb_pcie_write(pc, 0x4, tmp);
260 +       }
261 +       if (rev == 1) {
262 +               /* DLLP Link Control register. */
263 +               tmp = ssb_pcie_read(pc, 0x100);
264 +               tmp |= 0x40;
265 +               ssb_pcie_write(pc, 0x100, tmp);
266 +       }
267 +
268 +       if (rev == 0) {
269 +               const u8 serdes_rx_device = 0x1F;
270 +
271 +               ssb_pcie_mdio_write(pc, serdes_rx_device,
272 +                                       2 /* Timer */, 0x8128);
273 +               ssb_pcie_mdio_write(pc, serdes_rx_device,
274 +                                       6 /* CDR */, 0x0100);
275 +               ssb_pcie_mdio_write(pc, serdes_rx_device,
276 +                                       7 /* CDR BW */, 0x1466);
277 +       } else if (rev == 3 || rev == 4 || rev == 5) {
278 +               /* TODO: DLLP Power Management Threshold */
279 +               ssb_pcicore_serdes_workaround(pc);
280 +               /* TODO: ASPM */
281 +       } else if (rev == 7) {
282 +               /* TODO: No PLL down */
283 +       }
284 +
285 +       if (rev >= 6) {
286 +               /* Miscellaneous Configuration Fixup */
287 +               tmp = pcicore_read16(pc, SSB_PCICORE_SPROM(5));
288 +               if (!(tmp & 0x8000))
289 +                       pcicore_write16(pc, SSB_PCICORE_SPROM(5),
290 +                                       tmp | 0x8000);
291 +       }
292 +}
293  
294  /**************************************************
295   * Generic and Clientmode operation code.
296   **************************************************/
297  
298 -static void ssb_pcicore_init_clientmode(struct ssb_pcicore *pc)
299 +static void __devinit ssb_pcicore_init_clientmode(struct ssb_pcicore *pc)
300  {
301         /* Disable PCI interrupts. */
302         ssb_write32(pc->dev, SSB_INTVEC, 0);
303  }
304  
305 -void ssb_pcicore_init(struct ssb_pcicore *pc)
306 +void __devinit ssb_pcicore_init(struct ssb_pcicore *pc)
307  {
308         struct ssb_device *dev = pc->dev;
309 -       struct ssb_bus *bus;
310  
311         if (!dev)
312                 return;
313 -       bus = dev->bus;
314         if (!ssb_device_is_enabled(dev))
315                 ssb_device_enable(dev, 0);
316  
317 +       ssb_pcicore_fix_sprom_core_index(pc);
318 +
319  #ifdef CONFIG_SSB_PCICORE_HOSTMODE
320         pc->hostmode = pcicore_is_in_hostmode(pc);
321         if (pc->hostmode)
322 @@ -432,6 +538,13 @@ void ssb_pcicore_init(struct ssb_pcicore
323  #endif /* CONFIG_SSB_PCICORE_HOSTMODE */
324         if (!pc->hostmode)
325                 ssb_pcicore_init_clientmode(pc);
326 +
327 +       /* Additional PCIe always once-executed workarounds */
328 +       if (dev->id.coreid == SSB_DEV_PCIE) {
329 +               ssb_pcicore_serdes_workaround(pc);
330 +               /* TODO: ASPM */
331 +               /* TODO: Clock Request Update */
332 +       }
333  }
334  
335  static u32 ssb_pcie_read(struct ssb_pcicore *pc, u32 address)
336 @@ -446,11 +559,35 @@ static void ssb_pcie_write(struct ssb_pc
337         pcicore_write32(pc, 0x134, data);
338  }
339  
340 -static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
341 -                               u8 address, u16 data)
342 +static void ssb_pcie_mdio_set_phy(struct ssb_pcicore *pc, u8 phy)
343 +{
344 +       const u16 mdio_control = 0x128;
345 +       const u16 mdio_data = 0x12C;
346 +       u32 v;
347 +       int i;
348 +
349 +       v = (1 << 30); /* Start of Transaction */
350 +       v |= (1 << 28); /* Write Transaction */
351 +       v |= (1 << 17); /* Turnaround */
352 +       v |= (0x1F << 18);
353 +       v |= (phy << 4);
354 +       pcicore_write32(pc, mdio_data, v);
355 +
356 +       udelay(10);
357 +       for (i = 0; i < 200; i++) {
358 +               v = pcicore_read32(pc, mdio_control);
359 +               if (v & 0x100 /* Trans complete */)
360 +                       break;
361 +               msleep(1);
362 +       }
363 +}
364 +
365 +static u16 ssb_pcie_mdio_read(struct ssb_pcicore *pc, u8 device, u8 address)
366  {
367         const u16 mdio_control = 0x128;
368         const u16 mdio_data = 0x12C;
369 +       int max_retries = 10;
370 +       u16 ret = 0;
371         u32 v;
372         int i;
373  
374 @@ -458,46 +595,68 @@ static void ssb_pcie_mdio_write(struct s
375         v |= 0x2; /* MDIO Clock Divisor */
376         pcicore_write32(pc, mdio_control, v);
377  
378 +       if (pc->dev->id.revision >= 10) {
379 +               max_retries = 200;
380 +               ssb_pcie_mdio_set_phy(pc, device);
381 +       }
382 +
383         v = (1 << 30); /* Start of Transaction */
384 -       v |= (1 << 28); /* Write Transaction */
385 +       v |= (1 << 29); /* Read Transaction */
386         v |= (1 << 17); /* Turnaround */
387 -       v |= (u32)device << 22;
388 +       if (pc->dev->id.revision < 10)
389 +               v |= (u32)device << 22;
390         v |= (u32)address << 18;
391 -       v |= data;
392         pcicore_write32(pc, mdio_data, v);
393         /* Wait for the device to complete the transaction */
394         udelay(10);
395 -       for (i = 0; i < 10; i++) {
396 +       for (i = 0; i < max_retries; i++) {
397                 v = pcicore_read32(pc, mdio_control);
398 -               if (v & 0x100 /* Trans complete */)
399 +               if (v & 0x100 /* Trans complete */) {
400 +                       udelay(10);
401 +                       ret = pcicore_read32(pc, mdio_data);
402                         break;
403 +               }
404                 msleep(1);
405         }
406         pcicore_write32(pc, mdio_control, 0);
407 +       return ret;
408  }
409  
410 -static void ssb_broadcast_value(struct ssb_device *dev,
411 -                               u32 address, u32 data)
412 +static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
413 +                               u8 address, u16 data)
414  {
415 -       /* This is used for both, PCI and ChipCommon core, so be careful. */
416 -       BUILD_BUG_ON(SSB_PCICORE_BCAST_ADDR != SSB_CHIPCO_BCAST_ADDR);
417 -       BUILD_BUG_ON(SSB_PCICORE_BCAST_DATA != SSB_CHIPCO_BCAST_DATA);
418 +       const u16 mdio_control = 0x128;
419 +       const u16 mdio_data = 0x12C;
420 +       int max_retries = 10;
421 +       u32 v;
422 +       int i;
423  
424 -       ssb_write32(dev, SSB_PCICORE_BCAST_ADDR, address);
425 -       ssb_read32(dev, SSB_PCICORE_BCAST_ADDR); /* flush */
426 -       ssb_write32(dev, SSB_PCICORE_BCAST_DATA, data);
427 -       ssb_read32(dev, SSB_PCICORE_BCAST_DATA); /* flush */
428 -}
429 +       v = 0x80; /* Enable Preamble Sequence */
430 +       v |= 0x2; /* MDIO Clock Divisor */
431 +       pcicore_write32(pc, mdio_control, v);
432  
433 -static void ssb_commit_settings(struct ssb_bus *bus)
434 -{
435 -       struct ssb_device *dev;
436 +       if (pc->dev->id.revision >= 10) {
437 +               max_retries = 200;
438 +               ssb_pcie_mdio_set_phy(pc, device);
439 +       }
440  
441 -       dev = bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev;
442 -       if (WARN_ON(!dev))
443 -               return;
444 -       /* This forces an update of the cached registers. */
445 -       ssb_broadcast_value(dev, 0xFD8, 0);
446 +       v = (1 << 30); /* Start of Transaction */
447 +       v |= (1 << 28); /* Write Transaction */
448 +       v |= (1 << 17); /* Turnaround */
449 +       if (pc->dev->id.revision < 10)
450 +               v |= (u32)device << 22;
451 +       v |= (u32)address << 18;
452 +       v |= data;
453 +       pcicore_write32(pc, mdio_data, v);
454 +       /* Wait for the device to complete the transaction */
455 +       udelay(10);
456 +       for (i = 0; i < max_retries; i++) {
457 +               v = pcicore_read32(pc, mdio_control);
458 +               if (v & 0x100 /* Trans complete */)
459 +                       break;
460 +               msleep(1);
461 +       }
462 +       pcicore_write32(pc, mdio_control, 0);
463  }
464  
465  int ssb_pcicore_dev_irqvecs_enable(struct ssb_pcicore *pc,
466 @@ -550,48 +709,10 @@ int ssb_pcicore_dev_irqvecs_enable(struc
467         if (pc->setup_done)
468                 goto out;
469         if (pdev->id.coreid == SSB_DEV_PCI) {
470 -               tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
471 -               tmp |= SSB_PCICORE_SBTOPCI_PREF;
472 -               tmp |= SSB_PCICORE_SBTOPCI_BURST;
473 -               pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
474 -
475 -               if (pdev->id.revision < 5) {
476 -                       tmp = ssb_read32(pdev, SSB_IMCFGLO);
477 -                       tmp &= ~SSB_IMCFGLO_SERTO;
478 -                       tmp |= 2;
479 -                       tmp &= ~SSB_IMCFGLO_REQTO;
480 -                       tmp |= 3 << SSB_IMCFGLO_REQTO_SHIFT;
481 -                       ssb_write32(pdev, SSB_IMCFGLO, tmp);
482 -                       ssb_commit_settings(bus);
483 -               } else if (pdev->id.revision >= 11) {
484 -                       tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
485 -                       tmp |= SSB_PCICORE_SBTOPCI_MRM;
486 -                       pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
487 -               }
488 +               ssb_pcicore_pci_setup_workarounds(pc);
489         } else {
490                 WARN_ON(pdev->id.coreid != SSB_DEV_PCIE);
491 -               //TODO: Better make defines for all these magic PCIE values.
492 -               if ((pdev->id.revision == 0) || (pdev->id.revision == 1)) {
493 -                       /* TLP Workaround register. */
494 -                       tmp = ssb_pcie_read(pc, 0x4);
495 -                       tmp |= 0x8;
496 -                       ssb_pcie_write(pc, 0x4, tmp);
497 -               }
498 -               if (pdev->id.revision == 0) {
499 -                       const u8 serdes_rx_device = 0x1F;
500 -
501 -                       ssb_pcie_mdio_write(pc, serdes_rx_device,
502 -                                           2 /* Timer */, 0x8128);
503 -                       ssb_pcie_mdio_write(pc, serdes_rx_device,
504 -                                           6 /* CDR */, 0x0100);
505 -                       ssb_pcie_mdio_write(pc, serdes_rx_device,
506 -                                           7 /* CDR BW */, 0x1466);
507 -               } else if (pdev->id.revision == 1) {
508 -                       /* DLLP Link Control register. */
509 -                       tmp = ssb_pcie_read(pc, 0x100);
510 -                       tmp |= 0x40;
511 -                       ssb_pcie_write(pc, 0x100, tmp);
512 -               }
513 +               ssb_pcicore_pcie_setup_workarounds(pc);
514         }
515         pc->setup_done = 1;
516  out:
517 --- a/drivers/ssb/main.c
518 +++ b/drivers/ssb/main.c
519 @@ -557,7 +557,7 @@ error:
520  }
521  
522  /* Needs ssb_buses_lock() */
523 -static int ssb_attach_queued_buses(void)
524 +static int __devinit ssb_attach_queued_buses(void)
525  {
526         struct ssb_bus *bus, *n;
527         int err = 0;
528 @@ -768,9 +768,9 @@ out:
529         return err;
530  }
531  
532 -static int ssb_bus_register(struct ssb_bus *bus,
533 -                           ssb_invariants_func_t get_invariants,
534 -                           unsigned long baseaddr)
535 +static int __devinit ssb_bus_register(struct ssb_bus *bus,
536 +                                     ssb_invariants_func_t get_invariants,
537 +                                     unsigned long baseaddr)
538  {
539         int err;
540  
541 @@ -851,8 +851,8 @@ err_disable_xtal:
542  }
543  
544  #ifdef CONFIG_SSB_PCIHOST
545 -int ssb_bus_pcibus_register(struct ssb_bus *bus,
546 -                           struct pci_dev *host_pci)
547 +int __devinit ssb_bus_pcibus_register(struct ssb_bus *bus,
548 +                                     struct pci_dev *host_pci)
549  {
550         int err;
551  
552 @@ -875,9 +875,9 @@ EXPORT_SYMBOL(ssb_bus_pcibus_register);
553  #endif /* CONFIG_SSB_PCIHOST */
554  
555  #ifdef CONFIG_SSB_PCMCIAHOST
556 -int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
557 -                              struct pcmcia_device *pcmcia_dev,
558 -                              unsigned long baseaddr)
559 +int __devinit ssb_bus_pcmciabus_register(struct ssb_bus *bus,
560 +                                        struct pcmcia_device *pcmcia_dev,
561 +                                        unsigned long baseaddr)
562  {
563         int err;
564  
565 @@ -897,8 +897,9 @@ EXPORT_SYMBOL(ssb_bus_pcmciabus_register
566  #endif /* CONFIG_SSB_PCMCIAHOST */
567  
568  #ifdef CONFIG_SSB_SDIOHOST
569 -int ssb_bus_sdiobus_register(struct ssb_bus *bus, struct sdio_func *func,
570 -                            unsigned int quirks)
571 +int __devinit ssb_bus_sdiobus_register(struct ssb_bus *bus,
572 +                                      struct sdio_func *func,
573 +                                      unsigned int quirks)
574  {
575         int err;
576  
577 @@ -918,9 +919,9 @@ int ssb_bus_sdiobus_register(struct ssb_
578  EXPORT_SYMBOL(ssb_bus_sdiobus_register);
579  #endif /* CONFIG_SSB_PCMCIAHOST */
580  
581 -int ssb_bus_ssbbus_register(struct ssb_bus *bus,
582 -                           unsigned long baseaddr,
583 -                           ssb_invariants_func_t get_invariants)
584 +int __devinit ssb_bus_ssbbus_register(struct ssb_bus *bus,
585 +                                     unsigned long baseaddr,
586 +                                     ssb_invariants_func_t get_invariants)
587  {
588         int err;
589  
590 @@ -1117,23 +1118,22 @@ static u32 ssb_tmslow_reject_bitmask(str
591  {
592         u32 rev = ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_SSBREV;
593  
594 -       /* The REJECT bit changed position in TMSLOW between
595 -        * Backplane revisions. */
596 +       /* The REJECT bit seems to be different for Backplane rev 2.3 */
597         switch (rev) {
598         case SSB_IDLOW_SSBREV_22:
599 -               return SSB_TMSLOW_REJECT_22;
600 +       case SSB_IDLOW_SSBREV_24:
601 +       case SSB_IDLOW_SSBREV_26:
602 +               return SSB_TMSLOW_REJECT;
603         case SSB_IDLOW_SSBREV_23:
604                 return SSB_TMSLOW_REJECT_23;
605 -       case SSB_IDLOW_SSBREV_24:     /* TODO - find the proper REJECT bits */
606 -       case SSB_IDLOW_SSBREV_25:     /* same here */
607 -       case SSB_IDLOW_SSBREV_26:     /* same here */
608 +       case SSB_IDLOW_SSBREV_25:     /* TODO - find the proper REJECT bit */
609         case SSB_IDLOW_SSBREV_27:     /* same here */
610 -               return SSB_TMSLOW_REJECT_23;    /* this is a guess */
611 +               return SSB_TMSLOW_REJECT;       /* this is a guess */
612         default:
613                 printk(KERN_INFO "ssb: Backplane Revision 0x%.8X\n", rev);
614                 WARN_ON(1);
615         }
616 -       return (SSB_TMSLOW_REJECT_22 | SSB_TMSLOW_REJECT_23);
617 +       return (SSB_TMSLOW_REJECT | SSB_TMSLOW_REJECT_23);
618  }
619  
620  int ssb_device_is_enabled(struct ssb_device *dev)
621 @@ -1309,20 +1309,20 @@ EXPORT_SYMBOL(ssb_bus_may_powerdown);
622  
623  int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl)
624  {
625 -       struct ssb_chipcommon *cc;
626         int err;
627         enum ssb_clkmode mode;
628  
629         err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
630         if (err)
631                 goto error;
632 -       cc = &bus->chipco;
633 -       mode = dynamic_pctl ? SSB_CLKMODE_DYNAMIC : SSB_CLKMODE_FAST;
634 -       ssb_chipco_set_clockmode(cc, mode);
635  
636  #ifdef CONFIG_SSB_DEBUG
637         bus->powered_up = 1;
638  #endif
639 +
640 +       mode = dynamic_pctl ? SSB_CLKMODE_DYNAMIC : SSB_CLKMODE_FAST;
641 +       ssb_chipco_set_clockmode(&bus->chipco, mode);
642 +
643         return 0;
644  error:
645         ssb_printk(KERN_ERR PFX "Bus powerup failed\n");
646 @@ -1330,6 +1330,37 @@ error:
647  }
648  EXPORT_SYMBOL(ssb_bus_powerup);
649  
650 +static void ssb_broadcast_value(struct ssb_device *dev,
651 +                               u32 address, u32 data)
652 +{
653 +#ifdef CONFIG_SSB_DRIVER_PCICORE
654 +       /* This is used for both, PCI and ChipCommon core, so be careful. */
655 +       BUILD_BUG_ON(SSB_PCICORE_BCAST_ADDR != SSB_CHIPCO_BCAST_ADDR);
656 +       BUILD_BUG_ON(SSB_PCICORE_BCAST_DATA != SSB_CHIPCO_BCAST_DATA);
657 +#endif
658 +
659 +       ssb_write32(dev, SSB_CHIPCO_BCAST_ADDR, address);
660 +       ssb_read32(dev, SSB_CHIPCO_BCAST_ADDR); /* flush */
661 +       ssb_write32(dev, SSB_CHIPCO_BCAST_DATA, data);
662 +       ssb_read32(dev, SSB_CHIPCO_BCAST_DATA); /* flush */
663 +}
664 +
665 +void ssb_commit_settings(struct ssb_bus *bus)
666 +{
667 +       struct ssb_device *dev;
668 +
669 +#ifdef CONFIG_SSB_DRIVER_PCICORE
670 +       dev = bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev;
671 +#else
672 +       dev = bus->chipco.dev;
673 +#endif
674 +       if (WARN_ON(!dev))
675 +               return;
676 +       /* This forces an update of the cached registers. */
677 +       ssb_broadcast_value(dev, 0xFD8, 0);
678 +}
679 +EXPORT_SYMBOL(ssb_commit_settings);
680 +
681  u32 ssb_admatch_base(u32 adm)
682  {
683         u32 base = 0;
684 --- a/drivers/ssb/pci.c
685 +++ b/drivers/ssb/pci.c
686 @@ -662,7 +662,6 @@ static int sprom_extract(struct ssb_bus
687  static int ssb_pci_sprom_get(struct ssb_bus *bus,
688                              struct ssb_sprom *sprom)
689  {
690 -       const struct ssb_sprom *fallback;
691         int err;
692         u16 *buf;
693  
694 @@ -707,10 +706,17 @@ static int ssb_pci_sprom_get(struct ssb_
695                 if (err) {
696                         /* All CRC attempts failed.
697                          * Maybe there is no SPROM on the device?
698 -                        * If we have a fallback, use that. */
699 -                       fallback = ssb_get_fallback_sprom();
700 -                       if (fallback) {
701 -                               memcpy(sprom, fallback, sizeof(*sprom));
702 +                        * Now we ask the arch code if there is some sprom
703 +                        * available for this device in some other storage */
704 +                       err = ssb_fill_sprom_with_fallback(bus, sprom);
705 +                       if (err) {
706 +                               ssb_printk(KERN_WARNING PFX "WARNING: Using"
707 +                                          " fallback SPROM failed (err %d)\n",
708 +                                          err);
709 +                       } else {
710 +                               ssb_dprintk(KERN_DEBUG PFX "Using SPROM"
711 +                                           " revision %d provided by"
712 +                                           " platform.\n", sprom->revision);
713                                 err = 0;
714                                 goto out_free;
715                         }
716 --- a/drivers/ssb/pcihost_wrapper.c
717 +++ b/drivers/ssb/pcihost_wrapper.c
718 @@ -53,8 +53,8 @@ static int ssb_pcihost_resume(struct pci
719  # define ssb_pcihost_resume    NULL
720  #endif /* CONFIG_PM */
721  
722 -static int ssb_pcihost_probe(struct pci_dev *dev,
723 -                            const struct pci_device_id *id)
724 +static int __devinit ssb_pcihost_probe(struct pci_dev *dev,
725 +                                      const struct pci_device_id *id)
726  {
727         struct ssb_bus *ssb;
728         int err = -ENOMEM;
729 @@ -110,7 +110,7 @@ static void ssb_pcihost_remove(struct pc
730         pci_set_drvdata(dev, NULL);
731  }
732  
733 -int ssb_pcihost_register(struct pci_driver *driver)
734 +int __devinit ssb_pcihost_register(struct pci_driver *driver)
735  {
736         driver->probe = ssb_pcihost_probe;
737         driver->remove = ssb_pcihost_remove;
738 --- a/drivers/ssb/scan.c
739 +++ b/drivers/ssb/scan.c
740 @@ -258,7 +258,10 @@ static int we_support_multiple_80211_cor
741  #ifdef CONFIG_SSB_PCIHOST
742         if (bus->bustype == SSB_BUSTYPE_PCI) {
743                 if (bus->host_pci->vendor == PCI_VENDOR_ID_BROADCOM &&
744 -                   bus->host_pci->device == 0x4324)
745 +                   ((bus->host_pci->device == 0x4313) ||
746 +                    (bus->host_pci->device == 0x431A) ||
747 +                    (bus->host_pci->device == 0x4321) ||
748 +                    (bus->host_pci->device == 0x4324)))
749                         return 1;
750         }
751  #endif /* CONFIG_SSB_PCIHOST */
752 @@ -307,7 +310,7 @@ int ssb_bus_scan(struct ssb_bus *bus,
753         } else {
754                 if (bus->bustype == SSB_BUSTYPE_PCI) {
755                         bus->chip_id = pcidev_to_chipid(bus->host_pci);
756 -                       pci_read_config_word(bus->host_pci, PCI_REVISION_ID,
757 +                       pci_read_config_byte(bus->host_pci, PCI_REVISION_ID,
758                                              &bus->chip_rev);
759                         bus->chip_package = 0;
760                 } else {
761 --- a/drivers/ssb/sprom.c
762 +++ b/drivers/ssb/sprom.c
763 @@ -17,7 +17,7 @@
764  #include <linux/slab.h>
765  
766  
767 -static const struct ssb_sprom *fallback_sprom;
768 +static int(*get_fallback_sprom)(struct ssb_bus *dev, struct ssb_sprom *out);
769  
770  
771  static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len,
772 @@ -145,36 +145,43 @@ out:
773  }
774  
775  /**
776 - * ssb_arch_set_fallback_sprom - Set a fallback SPROM for use if no SPROM is found.
777 + * ssb_arch_register_fallback_sprom - Registers a method providing a
778 + * fallback SPROM if no SPROM is found.
779   *
780 - * @sprom: The SPROM data structure to register.
781 + * @sprom_callback: The callback function.
782   *
783 - * With this function the architecture implementation may register a fallback
784 - * SPROM data structure. The fallback is only used for PCI based SSB devices,
785 - * where no valid SPROM can be found in the shadow registers.
786 + * With this function the architecture implementation may register a
787 + * callback handler which fills the SPROM data structure. The fallback is
788 + * only used for PCI based SSB devices, where no valid SPROM can be found
789 + * in the shadow registers.
790   *
791 - * This function is useful for weird architectures that have a half-assed SSB device
792 - * hardwired to their PCI bus.
793 + * This function is useful for weird architectures that have a half-assed
794 + * SSB device hardwired to their PCI bus.
795   *
796 - * Note that it does only work with PCI attached SSB devices. PCMCIA devices currently
797 - * don't use this fallback.
798 - * Architectures must provide the SPROM for native SSB devices anyway,
799 - * so the fallback also isn't used for native devices.
800 + * Note that it does only work with PCI attached SSB devices. PCMCIA
801 + * devices currently don't use this fallback.
802 + * Architectures must provide the SPROM for native SSB devices anyway, so
803 + * the fallback also isn't used for native devices.
804   *
805 - * This function is available for architecture code, only. So it is not exported.
806 + * This function is available for architecture code, only. So it is not
807 + * exported.
808   */
809 -int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom)
810 +int ssb_arch_register_fallback_sprom(int (*sprom_callback)(struct ssb_bus *bus,
811 +                                    struct ssb_sprom *out))
812  {
813 -       if (fallback_sprom)
814 +       if (get_fallback_sprom)
815                 return -EEXIST;
816 -       fallback_sprom = sprom;
817 +       get_fallback_sprom = sprom_callback;
818  
819         return 0;
820  }
821  
822 -const struct ssb_sprom *ssb_get_fallback_sprom(void)
823 +int ssb_fill_sprom_with_fallback(struct ssb_bus *bus, struct ssb_sprom *out)
824  {
825 -       return fallback_sprom;
826 +       if (!get_fallback_sprom)
827 +               return -ENOENT;
828 +
829 +       return get_fallback_sprom(bus, out);
830  }
831  
832  /* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */
833 --- a/drivers/ssb/ssb_private.h
834 +++ b/drivers/ssb/ssb_private.h
835 @@ -171,7 +171,8 @@ ssize_t ssb_attr_sprom_store(struct ssb_
836                              const char *buf, size_t count,
837                              int (*sprom_check_crc)(const u16 *sprom, size_t size),
838                              int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom));
839 -extern const struct ssb_sprom *ssb_get_fallback_sprom(void);
840 +extern int ssb_fill_sprom_with_fallback(struct ssb_bus *bus,
841 +                                       struct ssb_sprom *out);
842  
843  
844  /* core.c */
845 --- a/include/linux/ssb/ssb.h
846 +++ b/include/linux/ssb/ssb.h
847 @@ -308,7 +308,7 @@ struct ssb_bus {
848  
849         /* ID information about the Chip. */
850         u16 chip_id;
851 -       u16 chip_rev;
852 +       u8 chip_rev;
853         u16 sprom_offset;
854         u16 sprom_size;         /* number of words in sprom */
855         u8 chip_package;
856 @@ -404,7 +404,9 @@ extern bool ssb_is_sprom_available(struc
857  
858  /* Set a fallback SPROM.
859   * See kdoc at the function definition for complete documentation. */
860 -extern int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom);
861 +extern int ssb_arch_register_fallback_sprom(
862 +               int (*sprom_callback)(struct ssb_bus *bus,
863 +               struct ssb_sprom *out));
864  
865  /* Suspend a SSB bus.
866   * Call this from the parent bus suspend routine. */
867 @@ -518,6 +520,7 @@ extern int ssb_bus_may_powerdown(struct
868   * Otherwise static always-on powercontrol will be used. */
869  extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
870  
871 +extern void ssb_commit_settings(struct ssb_bus *bus);
872  
873  /* Various helper functions */
874  extern u32 ssb_admatch_base(u32 adm);
875 --- a/include/linux/ssb/ssb_driver_chipcommon.h
876 +++ b/include/linux/ssb/ssb_driver_chipcommon.h
877 @@ -123,6 +123,8 @@
878  #define SSB_CHIPCO_FLASHDATA           0x0048
879  #define SSB_CHIPCO_BCAST_ADDR          0x0050
880  #define SSB_CHIPCO_BCAST_DATA          0x0054
881 +#define SSB_CHIPCO_GPIOPULLUP          0x0058          /* Rev >= 20 only */
882 +#define SSB_CHIPCO_GPIOPULLDOWN                0x005C          /* Rev >= 20 only */
883  #define SSB_CHIPCO_GPIOIN              0x0060
884  #define SSB_CHIPCO_GPIOOUT             0x0064
885  #define SSB_CHIPCO_GPIOOUTEN           0x0068
886 @@ -131,6 +133,9 @@
887  #define SSB_CHIPCO_GPIOIRQ             0x0074
888  #define SSB_CHIPCO_WATCHDOG            0x0080
889  #define SSB_CHIPCO_GPIOTIMER           0x0088          /* LED powersave (corerev >= 16) */
890 +#define  SSB_CHIPCO_GPIOTIMER_OFFTIME  0x0000FFFF
891 +#define  SSB_CHIPCO_GPIOTIMER_OFFTIME_SHIFT    0
892 +#define  SSB_CHIPCO_GPIOTIMER_ONTIME   0xFFFF0000
893  #define  SSB_CHIPCO_GPIOTIMER_ONTIME_SHIFT     16
894  #define SSB_CHIPCO_GPIOTOUTM           0x008C          /* LED powersave (corerev >= 16) */
895  #define SSB_CHIPCO_CLOCK_N             0x0090
896 @@ -189,8 +194,10 @@
897  #define  SSB_CHIPCO_CLKCTLST_HAVEALPREQ        0x00000008 /* ALP available request */
898  #define  SSB_CHIPCO_CLKCTLST_HAVEHTREQ 0x00000010 /* HT available request */
899  #define  SSB_CHIPCO_CLKCTLST_HWCROFF   0x00000020 /* Force HW clock request off */
900 -#define  SSB_CHIPCO_CLKCTLST_HAVEHT    0x00010000 /* HT available */
901 -#define  SSB_CHIPCO_CLKCTLST_HAVEALP   0x00020000 /* APL available */
902 +#define  SSB_CHIPCO_CLKCTLST_HAVEALP   0x00010000 /* ALP available */
903 +#define  SSB_CHIPCO_CLKCTLST_HAVEHT    0x00020000 /* HT available */
904 +#define  SSB_CHIPCO_CLKCTLST_4328A0_HAVEHT     0x00010000 /* 4328a0 has reversed bits */
905 +#define  SSB_CHIPCO_CLKCTLST_4328A0_HAVEALP    0x00020000 /* 4328a0 has reversed bits */
906  #define SSB_CHIPCO_HW_WORKAROUND       0x01E4 /* Hardware workaround (rev >= 20) */
907  #define SSB_CHIPCO_UART0_DATA          0x0300
908  #define SSB_CHIPCO_UART0_IMR           0x0304
909 --- a/include/linux/ssb/ssb_regs.h
910 +++ b/include/linux/ssb/ssb_regs.h
911 @@ -97,7 +97,7 @@
912  #define  SSB_INTVEC_ENET1      0x00000040 /* Enable interrupts for enet 1 */
913  #define SSB_TMSLOW             0x0F98     /* SB Target State Low */
914  #define  SSB_TMSLOW_RESET      0x00000001 /* Reset */
915 -#define  SSB_TMSLOW_REJECT_22  0x00000002 /* Reject (Backplane rev 2.2) */
916 +#define  SSB_TMSLOW_REJECT     0x00000002 /* Reject (Standard Backplane) */
917  #define  SSB_TMSLOW_REJECT_23  0x00000004 /* Reject (Backplane rev 2.3) */
918  #define  SSB_TMSLOW_CLOCK      0x00010000 /* Clock Enable */
919  #define  SSB_TMSLOW_FGC                0x00020000 /* Force Gated Clocks On */