aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ssb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ssb')
-rw-r--r--drivers/ssb/Kconfig2
-rw-r--r--drivers/ssb/b43_pci_bridge.c1
-rw-r--r--drivers/ssb/driver_chipcommon.c68
-rw-r--r--drivers/ssb/driver_chipcommon_pmu.c2
-rw-r--r--drivers/ssb/driver_pcicore.c257
-rw-r--r--drivers/ssb/main.c129
-rw-r--r--drivers/ssb/pci.c118
-rw-r--r--drivers/ssb/pcihost_wrapper.c7
-rw-r--r--drivers/ssb/pcmcia.c3
-rw-r--r--drivers/ssb/scan.c22
-rw-r--r--drivers/ssb/sprom.c45
-rw-r--r--drivers/ssb/ssb_private.h3
12 files changed, 483 insertions, 174 deletions
diff --git a/drivers/ssb/Kconfig b/drivers/ssb/Kconfig
index 2d8cc455dbc7..42cdaa9a4d8a 100644
--- a/drivers/ssb/Kconfig
+++ b/drivers/ssb/Kconfig
@@ -82,7 +82,7 @@ config SSB_SDIOHOST
82 82
83config SSB_SILENT 83config SSB_SILENT
84 bool "No SSB kernel messages" 84 bool "No SSB kernel messages"
85 depends on SSB && EMBEDDED 85 depends on SSB && EXPERT
86 help 86 help
87 This option turns off all Sonics Silicon Backplane printks. 87 This option turns off all Sonics Silicon Backplane printks.
88 Note that you won't be able to identify problems, once 88 Note that you won't be able to identify problems, once
diff --git a/drivers/ssb/b43_pci_bridge.c b/drivers/ssb/b43_pci_bridge.c
index ef9c6a04ad8f..744d3f6e4709 100644
--- a/drivers/ssb/b43_pci_bridge.c
+++ b/drivers/ssb/b43_pci_bridge.c
@@ -24,6 +24,7 @@ static const struct pci_device_id b43_pci_bridge_tbl[] = {
24 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4312) }, 24 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4312) },
25 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4315) }, 25 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4315) },
26 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4318) }, 26 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4318) },
27 { PCI_DEVICE(PCI_VENDOR_ID_BCM_GVC, 0x4318) },
27 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4319) }, 28 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4319) },
28 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4320) }, 29 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4320) },
29 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4321) }, 30 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4321) },
diff --git a/drivers/ssb/driver_chipcommon.c b/drivers/ssb/driver_chipcommon.c
index 7c031fdc8205..06d15b6f2215 100644
--- a/drivers/ssb/driver_chipcommon.c
+++ b/drivers/ssb/driver_chipcommon.c
@@ -46,40 +46,66 @@ void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc,
46 if (!ccdev) 46 if (!ccdev)
47 return; 47 return;
48 bus = ccdev->bus; 48 bus = ccdev->bus;
49
50 /* We support SLOW only on 6..9 */
51 if (ccdev->id.revision >= 10 && mode == SSB_CLKMODE_SLOW)
52 mode = SSB_CLKMODE_DYNAMIC;
53
54 if (cc->capabilities & SSB_CHIPCO_CAP_PMU)
55 return; /* PMU controls clockmode, separated function needed */
56 SSB_WARN_ON(ccdev->id.revision >= 20);
57
49 /* chipcommon cores prior to rev6 don't support dynamic clock control */ 58 /* chipcommon cores prior to rev6 don't support dynamic clock control */
50 if (ccdev->id.revision < 6) 59 if (ccdev->id.revision < 6)
51 return; 60 return;
52 /* chipcommon cores rev10 are a whole new ball game */ 61
62 /* ChipCommon cores rev10+ need testing */
53 if (ccdev->id.revision >= 10) 63 if (ccdev->id.revision >= 10)
54 return; 64 return;
65
55 if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL)) 66 if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
56 return; 67 return;
57 68
58 switch (mode) { 69 switch (mode) {
59 case SSB_CLKMODE_SLOW: 70 case SSB_CLKMODE_SLOW: /* For revs 6..9 only */
60 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 71 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
61 tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW; 72 tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW;
62 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 73 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
63 break; 74 break;
64 case SSB_CLKMODE_FAST: 75 case SSB_CLKMODE_FAST:
65 ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */ 76 if (ccdev->id.revision < 10) {
66 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 77 ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */
67 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; 78 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
68 tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL; 79 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
69 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 80 tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL;
81 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
82 } else {
83 chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
84 (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) |
85 SSB_CHIPCO_SYSCLKCTL_FORCEHT));
86 /* udelay(150); TODO: not available in early init */
87 }
70 break; 88 break;
71 case SSB_CLKMODE_DYNAMIC: 89 case SSB_CLKMODE_DYNAMIC:
72 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL); 90 if (ccdev->id.revision < 10) {
73 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW; 91 tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
74 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL; 92 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
75 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL; 93 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL;
76 if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) != SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL) 94 tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
77 tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL; 95 if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) !=
78 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp); 96 SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL)
79 97 tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
80 /* for dynamic control, we have to release our xtal_pu "force on" */ 98 chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
81 if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL) 99
82 ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0); 100 /* For dynamic control, we have to release our xtal_pu
101 * "force on" */
102 if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL)
103 ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0);
104 } else {
105 chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
106 (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) &
107 ~SSB_CHIPCO_SYSCLKCTL_FORCEHT));
108 }
83 break; 109 break;
84 default: 110 default:
85 SSB_WARN_ON(1); 111 SSB_WARN_ON(1);
@@ -260,6 +286,12 @@ void ssb_chipcommon_init(struct ssb_chipcommon *cc)
260 if (cc->dev->id.revision >= 11) 286 if (cc->dev->id.revision >= 11)
261 cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT); 287 cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT);
262 ssb_dprintk(KERN_INFO PFX "chipcommon status is 0x%x\n", cc->status); 288 ssb_dprintk(KERN_INFO PFX "chipcommon status is 0x%x\n", cc->status);
289
290 if (cc->dev->id.revision >= 20) {
291 chipco_write32(cc, SSB_CHIPCO_GPIOPULLUP, 0);
292 chipco_write32(cc, SSB_CHIPCO_GPIOPULLDOWN, 0);
293 }
294
263 ssb_pmu_init(cc); 295 ssb_pmu_init(cc);
264 chipco_powercontrol_init(cc); 296 chipco_powercontrol_init(cc);
265 ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST); 297 ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
diff --git a/drivers/ssb/driver_chipcommon_pmu.c b/drivers/ssb/driver_chipcommon_pmu.c
index 5732bb2c3578..305ade7825f7 100644
--- a/drivers/ssb/driver_chipcommon_pmu.c
+++ b/drivers/ssb/driver_chipcommon_pmu.c
@@ -423,6 +423,8 @@ static void ssb_pmu_resources_init(struct ssb_chipcommon *cc)
423 423
424 switch (bus->chip_id) { 424 switch (bus->chip_id) {
425 case 0x4312: 425 case 0x4312:
426 min_msk = 0xCBB;
427 break;
426 case 0x4322: 428 case 0x4322:
427 /* We keep the default settings: 429 /* We keep the default settings:
428 * min_msk = 0xCBB 430 * min_msk = 0xCBB
diff --git a/drivers/ssb/driver_pcicore.c b/drivers/ssb/driver_pcicore.c
index 0e8d35224614..d6620ad309ce 100644
--- a/drivers/ssb/driver_pcicore.c
+++ b/drivers/ssb/driver_pcicore.c
@@ -15,6 +15,11 @@
15 15
16#include "ssb_private.h" 16#include "ssb_private.h"
17 17
18static u32 ssb_pcie_read(struct ssb_pcicore *pc, u32 address);
19static void ssb_pcie_write(struct ssb_pcicore *pc, u32 address, u32 data);
20static u16 ssb_pcie_mdio_read(struct ssb_pcicore *pc, u8 device, u8 address);
21static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
22 u8 address, u16 data);
18 23
19static inline 24static inline
20u32 pcicore_read32(struct ssb_pcicore *pc, u16 offset) 25u32 pcicore_read32(struct ssb_pcicore *pc, u16 offset)
@@ -403,6 +408,107 @@ static int pcicore_is_in_hostmode(struct ssb_pcicore *pc)
403} 408}
404#endif /* CONFIG_SSB_PCICORE_HOSTMODE */ 409#endif /* CONFIG_SSB_PCICORE_HOSTMODE */
405 410
411/**************************************************
412 * Workarounds.
413 **************************************************/
414
415static void ssb_pcicore_fix_sprom_core_index(struct ssb_pcicore *pc)
416{
417 u16 tmp = pcicore_read16(pc, SSB_PCICORE_SPROM(0));
418 if (((tmp & 0xF000) >> 12) != pc->dev->core_index) {
419 tmp &= ~0xF000;
420 tmp |= (pc->dev->core_index << 12);
421 pcicore_write16(pc, SSB_PCICORE_SPROM(0), tmp);
422 }
423}
424
425static u8 ssb_pcicore_polarity_workaround(struct ssb_pcicore *pc)
426{
427 return (ssb_pcie_read(pc, 0x204) & 0x10) ? 0xC0 : 0x80;
428}
429
430static void ssb_pcicore_serdes_workaround(struct ssb_pcicore *pc)
431{
432 const u8 serdes_pll_device = 0x1D;
433 const u8 serdes_rx_device = 0x1F;
434 u16 tmp;
435
436 ssb_pcie_mdio_write(pc, serdes_rx_device, 1 /* Control */,
437 ssb_pcicore_polarity_workaround(pc));
438 tmp = ssb_pcie_mdio_read(pc, serdes_pll_device, 1 /* Control */);
439 if (tmp & 0x4000)
440 ssb_pcie_mdio_write(pc, serdes_pll_device, 1, tmp & ~0x4000);
441}
442
443static void ssb_pcicore_pci_setup_workarounds(struct ssb_pcicore *pc)
444{
445 struct ssb_device *pdev = pc->dev;
446 struct ssb_bus *bus = pdev->bus;
447 u32 tmp;
448
449 tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
450 tmp |= SSB_PCICORE_SBTOPCI_PREF;
451 tmp |= SSB_PCICORE_SBTOPCI_BURST;
452 pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
453
454 if (pdev->id.revision < 5) {
455 tmp = ssb_read32(pdev, SSB_IMCFGLO);
456 tmp &= ~SSB_IMCFGLO_SERTO;
457 tmp |= 2;
458 tmp &= ~SSB_IMCFGLO_REQTO;
459 tmp |= 3 << SSB_IMCFGLO_REQTO_SHIFT;
460 ssb_write32(pdev, SSB_IMCFGLO, tmp);
461 ssb_commit_settings(bus);
462 } else if (pdev->id.revision >= 11) {
463 tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
464 tmp |= SSB_PCICORE_SBTOPCI_MRM;
465 pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
466 }
467}
468
469static void ssb_pcicore_pcie_setup_workarounds(struct ssb_pcicore *pc)
470{
471 u32 tmp;
472 u8 rev = pc->dev->id.revision;
473
474 if (rev == 0 || rev == 1) {
475 /* TLP Workaround register. */
476 tmp = ssb_pcie_read(pc, 0x4);
477 tmp |= 0x8;
478 ssb_pcie_write(pc, 0x4, tmp);
479 }
480 if (rev == 1) {
481 /* DLLP Link Control register. */
482 tmp = ssb_pcie_read(pc, 0x100);
483 tmp |= 0x40;
484 ssb_pcie_write(pc, 0x100, tmp);
485 }
486
487 if (rev == 0) {
488 const u8 serdes_rx_device = 0x1F;
489
490 ssb_pcie_mdio_write(pc, serdes_rx_device,
491 2 /* Timer */, 0x8128);
492 ssb_pcie_mdio_write(pc, serdes_rx_device,
493 6 /* CDR */, 0x0100);
494 ssb_pcie_mdio_write(pc, serdes_rx_device,
495 7 /* CDR BW */, 0x1466);
496 } else if (rev == 3 || rev == 4 || rev == 5) {
497 /* TODO: DLLP Power Management Threshold */
498 ssb_pcicore_serdes_workaround(pc);
499 /* TODO: ASPM */
500 } else if (rev == 7) {
501 /* TODO: No PLL down */
502 }
503
504 if (rev >= 6) {
505 /* Miscellaneous Configuration Fixup */
506 tmp = pcicore_read16(pc, SSB_PCICORE_SPROM(5));
507 if (!(tmp & 0x8000))
508 pcicore_write16(pc, SSB_PCICORE_SPROM(5),
509 tmp | 0x8000);
510 }
511}
406 512
407/************************************************** 513/**************************************************
408 * Generic and Clientmode operation code. 514 * Generic and Clientmode operation code.
@@ -410,18 +516,25 @@ static int pcicore_is_in_hostmode(struct ssb_pcicore *pc)
410 516
411static void ssb_pcicore_init_clientmode(struct ssb_pcicore *pc) 517static void ssb_pcicore_init_clientmode(struct ssb_pcicore *pc)
412{ 518{
519 ssb_pcicore_fix_sprom_core_index(pc);
520
413 /* Disable PCI interrupts. */ 521 /* Disable PCI interrupts. */
414 ssb_write32(pc->dev, SSB_INTVEC, 0); 522 ssb_write32(pc->dev, SSB_INTVEC, 0);
523
524 /* Additional PCIe always once-executed workarounds */
525 if (pc->dev->id.coreid == SSB_DEV_PCIE) {
526 ssb_pcicore_serdes_workaround(pc);
527 /* TODO: ASPM */
528 /* TODO: Clock Request Update */
529 }
415} 530}
416 531
417void ssb_pcicore_init(struct ssb_pcicore *pc) 532void ssb_pcicore_init(struct ssb_pcicore *pc)
418{ 533{
419 struct ssb_device *dev = pc->dev; 534 struct ssb_device *dev = pc->dev;
420 struct ssb_bus *bus;
421 535
422 if (!dev) 536 if (!dev)
423 return; 537 return;
424 bus = dev->bus;
425 if (!ssb_device_is_enabled(dev)) 538 if (!ssb_device_is_enabled(dev))
426 ssb_device_enable(dev, 0); 539 ssb_device_enable(dev, 0);
427 540
@@ -446,11 +559,35 @@ static void ssb_pcie_write(struct ssb_pcicore *pc, u32 address, u32 data)
446 pcicore_write32(pc, 0x134, data); 559 pcicore_write32(pc, 0x134, data);
447} 560}
448 561
449static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device, 562static void ssb_pcie_mdio_set_phy(struct ssb_pcicore *pc, u8 phy)
450 u8 address, u16 data) 563{
564 const u16 mdio_control = 0x128;
565 const u16 mdio_data = 0x12C;
566 u32 v;
567 int i;
568
569 v = (1 << 30); /* Start of Transaction */
570 v |= (1 << 28); /* Write Transaction */
571 v |= (1 << 17); /* Turnaround */
572 v |= (0x1F << 18);
573 v |= (phy << 4);
574 pcicore_write32(pc, mdio_data, v);
575
576 udelay(10);
577 for (i = 0; i < 200; i++) {
578 v = pcicore_read32(pc, mdio_control);
579 if (v & 0x100 /* Trans complete */)
580 break;
581 msleep(1);
582 }
583}
584
585static u16 ssb_pcie_mdio_read(struct ssb_pcicore *pc, u8 device, u8 address)
451{ 586{
452 const u16 mdio_control = 0x128; 587 const u16 mdio_control = 0x128;
453 const u16 mdio_data = 0x12C; 588 const u16 mdio_data = 0x12C;
589 int max_retries = 10;
590 u16 ret = 0;
454 u32 v; 591 u32 v;
455 int i; 592 int i;
456 593
@@ -458,46 +595,68 @@ static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
458 v |= 0x2; /* MDIO Clock Divisor */ 595 v |= 0x2; /* MDIO Clock Divisor */
459 pcicore_write32(pc, mdio_control, v); 596 pcicore_write32(pc, mdio_control, v);
460 597
598 if (pc->dev->id.revision >= 10) {
599 max_retries = 200;
600 ssb_pcie_mdio_set_phy(pc, device);
601 }
602
461 v = (1 << 30); /* Start of Transaction */ 603 v = (1 << 30); /* Start of Transaction */
462 v |= (1 << 28); /* Write Transaction */ 604 v |= (1 << 29); /* Read Transaction */
463 v |= (1 << 17); /* Turnaround */ 605 v |= (1 << 17); /* Turnaround */
464 v |= (u32)device << 22; 606 if (pc->dev->id.revision < 10)
607 v |= (u32)device << 22;
465 v |= (u32)address << 18; 608 v |= (u32)address << 18;
466 v |= data;
467 pcicore_write32(pc, mdio_data, v); 609 pcicore_write32(pc, mdio_data, v);
468 /* Wait for the device to complete the transaction */ 610 /* Wait for the device to complete the transaction */
469 udelay(10); 611 udelay(10);
470 for (i = 0; i < 10; i++) { 612 for (i = 0; i < max_retries; i++) {
471 v = pcicore_read32(pc, mdio_control); 613 v = pcicore_read32(pc, mdio_control);
472 if (v & 0x100 /* Trans complete */) 614 if (v & 0x100 /* Trans complete */) {
615 udelay(10);
616 ret = pcicore_read32(pc, mdio_data);
473 break; 617 break;
618 }
474 msleep(1); 619 msleep(1);
475 } 620 }
476 pcicore_write32(pc, mdio_control, 0); 621 pcicore_write32(pc, mdio_control, 0);
622 return ret;
477} 623}
478 624
479static void ssb_broadcast_value(struct ssb_device *dev, 625static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
480 u32 address, u32 data) 626 u8 address, u16 data)
481{ 627{
482 /* This is used for both, PCI and ChipCommon core, so be careful. */ 628 const u16 mdio_control = 0x128;
483 BUILD_BUG_ON(SSB_PCICORE_BCAST_ADDR != SSB_CHIPCO_BCAST_ADDR); 629 const u16 mdio_data = 0x12C;
484 BUILD_BUG_ON(SSB_PCICORE_BCAST_DATA != SSB_CHIPCO_BCAST_DATA); 630 int max_retries = 10;
485 631 u32 v;
486 ssb_write32(dev, SSB_PCICORE_BCAST_ADDR, address); 632 int i;
487 ssb_read32(dev, SSB_PCICORE_BCAST_ADDR); /* flush */
488 ssb_write32(dev, SSB_PCICORE_BCAST_DATA, data);
489 ssb_read32(dev, SSB_PCICORE_BCAST_DATA); /* flush */
490}
491 633
492static void ssb_commit_settings(struct ssb_bus *bus) 634 v = 0x80; /* Enable Preamble Sequence */
493{ 635 v |= 0x2; /* MDIO Clock Divisor */
494 struct ssb_device *dev; 636 pcicore_write32(pc, mdio_control, v);
495 637
496 dev = bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev; 638 if (pc->dev->id.revision >= 10) {
497 if (WARN_ON(!dev)) 639 max_retries = 200;
498 return; 640 ssb_pcie_mdio_set_phy(pc, device);
499 /* This forces an update of the cached registers. */ 641 }
500 ssb_broadcast_value(dev, 0xFD8, 0); 642
643 v = (1 << 30); /* Start of Transaction */
644 v |= (1 << 28); /* Write Transaction */
645 v |= (1 << 17); /* Turnaround */
646 if (pc->dev->id.revision < 10)
647 v |= (u32)device << 22;
648 v |= (u32)address << 18;
649 v |= data;
650 pcicore_write32(pc, mdio_data, v);
651 /* Wait for the device to complete the transaction */
652 udelay(10);
653 for (i = 0; i < max_retries; i++) {
654 v = pcicore_read32(pc, mdio_control);
655 if (v & 0x100 /* Trans complete */)
656 break;
657 msleep(1);
658 }
659 pcicore_write32(pc, mdio_control, 0);
501} 660}
502 661
503int ssb_pcicore_dev_irqvecs_enable(struct ssb_pcicore *pc, 662int ssb_pcicore_dev_irqvecs_enable(struct ssb_pcicore *pc,
@@ -550,48 +709,10 @@ int ssb_pcicore_dev_irqvecs_enable(struct ssb_pcicore *pc,
550 if (pc->setup_done) 709 if (pc->setup_done)
551 goto out; 710 goto out;
552 if (pdev->id.coreid == SSB_DEV_PCI) { 711 if (pdev->id.coreid == SSB_DEV_PCI) {
553 tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2); 712 ssb_pcicore_pci_setup_workarounds(pc);
554 tmp |= SSB_PCICORE_SBTOPCI_PREF;
555 tmp |= SSB_PCICORE_SBTOPCI_BURST;
556 pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
557
558 if (pdev->id.revision < 5) {
559 tmp = ssb_read32(pdev, SSB_IMCFGLO);
560 tmp &= ~SSB_IMCFGLO_SERTO;
561 tmp |= 2;
562 tmp &= ~SSB_IMCFGLO_REQTO;
563 tmp |= 3 << SSB_IMCFGLO_REQTO_SHIFT;
564 ssb_write32(pdev, SSB_IMCFGLO, tmp);
565 ssb_commit_settings(bus);
566 } else if (pdev->id.revision >= 11) {
567 tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
568 tmp |= SSB_PCICORE_SBTOPCI_MRM;
569 pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
570 }
571 } else { 713 } else {
572 WARN_ON(pdev->id.coreid != SSB_DEV_PCIE); 714 WARN_ON(pdev->id.coreid != SSB_DEV_PCIE);
573 //TODO: Better make defines for all these magic PCIE values. 715 ssb_pcicore_pcie_setup_workarounds(pc);
574 if ((pdev->id.revision == 0) || (pdev->id.revision == 1)) {
575 /* TLP Workaround register. */
576 tmp = ssb_pcie_read(pc, 0x4);
577 tmp |= 0x8;
578 ssb_pcie_write(pc, 0x4, tmp);
579 }
580 if (pdev->id.revision == 0) {
581 const u8 serdes_rx_device = 0x1F;
582
583 ssb_pcie_mdio_write(pc, serdes_rx_device,
584 2 /* Timer */, 0x8128);
585 ssb_pcie_mdio_write(pc, serdes_rx_device,
586 6 /* CDR */, 0x0100);
587 ssb_pcie_mdio_write(pc, serdes_rx_device,
588 7 /* CDR BW */, 0x1466);
589 } else if (pdev->id.revision == 1) {
590 /* DLLP Link Control register. */
591 tmp = ssb_pcie_read(pc, 0x100);
592 tmp |= 0x40;
593 ssb_pcie_write(pc, 0x100, tmp);
594 }
595 } 716 }
596 pc->setup_done = 1; 717 pc->setup_done = 1;
597out: 718out:
diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 7892ac163522..f8a13f863217 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -20,7 +20,6 @@
20#include <linux/mmc/sdio_func.h> 20#include <linux/mmc/sdio_func.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22 22
23#include <pcmcia/cs.h>
24#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
25#include <pcmcia/ds.h> 24#include <pcmcia/ds.h>
26 25
@@ -384,6 +383,35 @@ static int ssb_device_uevent(struct device *dev, struct kobj_uevent_env *env)
384 ssb_dev->id.revision); 383 ssb_dev->id.revision);
385} 384}
386 385
386#define ssb_config_attr(attrib, field, format_string) \
387static ssize_t \
388attrib##_show(struct device *dev, struct device_attribute *attr, char *buf) \
389{ \
390 return sprintf(buf, format_string, dev_to_ssb_dev(dev)->field); \
391}
392
393ssb_config_attr(core_num, core_index, "%u\n")
394ssb_config_attr(coreid, id.coreid, "0x%04x\n")
395ssb_config_attr(vendor, id.vendor, "0x%04x\n")
396ssb_config_attr(revision, id.revision, "%u\n")
397ssb_config_attr(irq, irq, "%u\n")
398static ssize_t
399name_show(struct device *dev, struct device_attribute *attr, char *buf)
400{
401 return sprintf(buf, "%s\n",
402 ssb_core_name(dev_to_ssb_dev(dev)->id.coreid));
403}
404
405static struct device_attribute ssb_device_attrs[] = {
406 __ATTR_RO(name),
407 __ATTR_RO(core_num),
408 __ATTR_RO(coreid),
409 __ATTR_RO(vendor),
410 __ATTR_RO(revision),
411 __ATTR_RO(irq),
412 __ATTR_NULL,
413};
414
387static struct bus_type ssb_bustype = { 415static struct bus_type ssb_bustype = {
388 .name = "ssb", 416 .name = "ssb",
389 .match = ssb_bus_match, 417 .match = ssb_bus_match,
@@ -393,6 +421,7 @@ static struct bus_type ssb_bustype = {
393 .suspend = ssb_device_suspend, 421 .suspend = ssb_device_suspend,
394 .resume = ssb_device_resume, 422 .resume = ssb_device_resume,
395 .uevent = ssb_device_uevent, 423 .uevent = ssb_device_uevent,
424 .dev_attrs = ssb_device_attrs,
396}; 425};
397 426
398static void ssb_buses_lock(void) 427static void ssb_buses_lock(void)
@@ -1088,23 +1117,22 @@ static u32 ssb_tmslow_reject_bitmask(struct ssb_device *dev)
1088{ 1117{
1089 u32 rev = ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_SSBREV; 1118 u32 rev = ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_SSBREV;
1090 1119
1091 /* The REJECT bit changed position in TMSLOW between 1120 /* The REJECT bit seems to be different for Backplane rev 2.3 */
1092 * Backplane revisions. */
1093 switch (rev) { 1121 switch (rev) {
1094 case SSB_IDLOW_SSBREV_22: 1122 case SSB_IDLOW_SSBREV_22:
1095 return SSB_TMSLOW_REJECT_22; 1123 case SSB_IDLOW_SSBREV_24:
1124 case SSB_IDLOW_SSBREV_26:
1125 return SSB_TMSLOW_REJECT;
1096 case SSB_IDLOW_SSBREV_23: 1126 case SSB_IDLOW_SSBREV_23:
1097 return SSB_TMSLOW_REJECT_23; 1127 return SSB_TMSLOW_REJECT_23;
1098 case SSB_IDLOW_SSBREV_24: /* TODO - find the proper REJECT bits */ 1128 case SSB_IDLOW_SSBREV_25: /* TODO - find the proper REJECT bit */
1099 case SSB_IDLOW_SSBREV_25: /* same here */
1100 case SSB_IDLOW_SSBREV_26: /* same here */
1101 case SSB_IDLOW_SSBREV_27: /* same here */ 1129 case SSB_IDLOW_SSBREV_27: /* same here */
1102 return SSB_TMSLOW_REJECT_23; /* this is a guess */ 1130 return SSB_TMSLOW_REJECT; /* this is a guess */
1103 default: 1131 default:
1104 printk(KERN_INFO "ssb: Backplane Revision 0x%.8X\n", rev); 1132 printk(KERN_INFO "ssb: Backplane Revision 0x%.8X\n", rev);
1105 WARN_ON(1); 1133 WARN_ON(1);
1106 } 1134 }
1107 return (SSB_TMSLOW_REJECT_22 | SSB_TMSLOW_REJECT_23); 1135 return (SSB_TMSLOW_REJECT | SSB_TMSLOW_REJECT_23);
1108} 1136}
1109 1137
1110int ssb_device_is_enabled(struct ssb_device *dev) 1138int ssb_device_is_enabled(struct ssb_device *dev)
@@ -1163,10 +1191,10 @@ void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags)
1163} 1191}
1164EXPORT_SYMBOL(ssb_device_enable); 1192EXPORT_SYMBOL(ssb_device_enable);
1165 1193
1166/* Wait for a bit in a register to get set or unset. 1194/* Wait for bitmask in a register to get set or cleared.
1167 * timeout is in units of ten-microseconds */ 1195 * timeout is in units of ten-microseconds */
1168static int ssb_wait_bit(struct ssb_device *dev, u16 reg, u32 bitmask, 1196static int ssb_wait_bits(struct ssb_device *dev, u16 reg, u32 bitmask,
1169 int timeout, int set) 1197 int timeout, int set)
1170{ 1198{
1171 int i; 1199 int i;
1172 u32 val; 1200 u32 val;
@@ -1174,7 +1202,7 @@ static int ssb_wait_bit(struct ssb_device *dev, u16 reg, u32 bitmask,
1174 for (i = 0; i < timeout; i++) { 1202 for (i = 0; i < timeout; i++) {
1175 val = ssb_read32(dev, reg); 1203 val = ssb_read32(dev, reg);
1176 if (set) { 1204 if (set) {
1177 if (val & bitmask) 1205 if ((val & bitmask) == bitmask)
1178 return 0; 1206 return 0;
1179 } else { 1207 } else {
1180 if (!(val & bitmask)) 1208 if (!(val & bitmask))
@@ -1191,20 +1219,38 @@ static int ssb_wait_bit(struct ssb_device *dev, u16 reg, u32 bitmask,
1191 1219
1192void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags) 1220void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags)
1193{ 1221{
1194 u32 reject; 1222 u32 reject, val;
1195 1223
1196 if (ssb_read32(dev, SSB_TMSLOW) & SSB_TMSLOW_RESET) 1224 if (ssb_read32(dev, SSB_TMSLOW) & SSB_TMSLOW_RESET)
1197 return; 1225 return;
1198 1226
1199 reject = ssb_tmslow_reject_bitmask(dev); 1227 reject = ssb_tmslow_reject_bitmask(dev);
1200 ssb_write32(dev, SSB_TMSLOW, reject | SSB_TMSLOW_CLOCK); 1228
1201 ssb_wait_bit(dev, SSB_TMSLOW, reject, 1000, 1); 1229 if (ssb_read32(dev, SSB_TMSLOW) & SSB_TMSLOW_CLOCK) {
1202 ssb_wait_bit(dev, SSB_TMSHIGH, SSB_TMSHIGH_BUSY, 1000, 0); 1230 ssb_write32(dev, SSB_TMSLOW, reject | SSB_TMSLOW_CLOCK);
1203 ssb_write32(dev, SSB_TMSLOW, 1231 ssb_wait_bits(dev, SSB_TMSLOW, reject, 1000, 1);
1204 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK | 1232 ssb_wait_bits(dev, SSB_TMSHIGH, SSB_TMSHIGH_BUSY, 1000, 0);
1205 reject | SSB_TMSLOW_RESET | 1233
1206 core_specific_flags); 1234 if (ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_INITIATOR) {
1207 ssb_flush_tmslow(dev); 1235 val = ssb_read32(dev, SSB_IMSTATE);
1236 val |= SSB_IMSTATE_REJECT;
1237 ssb_write32(dev, SSB_IMSTATE, val);
1238 ssb_wait_bits(dev, SSB_IMSTATE, SSB_IMSTATE_BUSY, 1000,
1239 0);
1240 }
1241
1242 ssb_write32(dev, SSB_TMSLOW,
1243 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
1244 reject | SSB_TMSLOW_RESET |
1245 core_specific_flags);
1246 ssb_flush_tmslow(dev);
1247
1248 if (ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_INITIATOR) {
1249 val = ssb_read32(dev, SSB_IMSTATE);
1250 val &= ~SSB_IMSTATE_REJECT;
1251 ssb_write32(dev, SSB_IMSTATE, val);
1252 }
1253 }
1208 1254
1209 ssb_write32(dev, SSB_TMSLOW, 1255 ssb_write32(dev, SSB_TMSLOW,
1210 reject | SSB_TMSLOW_RESET | 1256 reject | SSB_TMSLOW_RESET |
@@ -1262,20 +1308,20 @@ EXPORT_SYMBOL(ssb_bus_may_powerdown);
1262 1308
1263int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl) 1309int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl)
1264{ 1310{
1265 struct ssb_chipcommon *cc;
1266 int err; 1311 int err;
1267 enum ssb_clkmode mode; 1312 enum ssb_clkmode mode;
1268 1313
1269 err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1); 1314 err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
1270 if (err) 1315 if (err)
1271 goto error; 1316 goto error;
1272 cc = &bus->chipco;
1273 mode = dynamic_pctl ? SSB_CLKMODE_DYNAMIC : SSB_CLKMODE_FAST;
1274 ssb_chipco_set_clockmode(cc, mode);
1275 1317
1276#ifdef CONFIG_SSB_DEBUG 1318#ifdef CONFIG_SSB_DEBUG
1277 bus->powered_up = 1; 1319 bus->powered_up = 1;
1278#endif 1320#endif
1321
1322 mode = dynamic_pctl ? SSB_CLKMODE_DYNAMIC : SSB_CLKMODE_FAST;
1323 ssb_chipco_set_clockmode(&bus->chipco, mode);
1324
1279 return 0; 1325 return 0;
1280error: 1326error:
1281 ssb_printk(KERN_ERR PFX "Bus powerup failed\n"); 1327 ssb_printk(KERN_ERR PFX "Bus powerup failed\n");
@@ -1283,6 +1329,37 @@ error:
1283} 1329}
1284EXPORT_SYMBOL(ssb_bus_powerup); 1330EXPORT_SYMBOL(ssb_bus_powerup);
1285 1331
1332static void ssb_broadcast_value(struct ssb_device *dev,
1333 u32 address, u32 data)
1334{
1335#ifdef CONFIG_SSB_DRIVER_PCICORE
1336 /* This is used for both, PCI and ChipCommon core, so be careful. */
1337 BUILD_BUG_ON(SSB_PCICORE_BCAST_ADDR != SSB_CHIPCO_BCAST_ADDR);
1338 BUILD_BUG_ON(SSB_PCICORE_BCAST_DATA != SSB_CHIPCO_BCAST_DATA);
1339#endif
1340
1341 ssb_write32(dev, SSB_CHIPCO_BCAST_ADDR, address);
1342 ssb_read32(dev, SSB_CHIPCO_BCAST_ADDR); /* flush */
1343 ssb_write32(dev, SSB_CHIPCO_BCAST_DATA, data);
1344 ssb_read32(dev, SSB_CHIPCO_BCAST_DATA); /* flush */
1345}
1346
1347void ssb_commit_settings(struct ssb_bus *bus)
1348{
1349 struct ssb_device *dev;
1350
1351#ifdef CONFIG_SSB_DRIVER_PCICORE
1352 dev = bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev;
1353#else
1354 dev = bus->chipco.dev;
1355#endif
1356 if (WARN_ON(!dev))
1357 return;
1358 /* This forces an update of the cached registers. */
1359 ssb_broadcast_value(dev, 0xFD8, 0);
1360}
1361EXPORT_SYMBOL(ssb_commit_settings);
1362
1286u32 ssb_admatch_base(u32 adm) 1363u32 ssb_admatch_base(u32 adm)
1287{ 1364{
1288 u32 base = 0; 1365 u32 base = 0;
diff --git a/drivers/ssb/pci.c b/drivers/ssb/pci.c
index 6e88d2b603b4..7ad48585c5e6 100644
--- a/drivers/ssb/pci.c
+++ b/drivers/ssb/pci.c
@@ -406,6 +406,46 @@ static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in)
406 out->antenna_gain.ghz5.a3 = gain; 406 out->antenna_gain.ghz5.a3 = gain;
407} 407}
408 408
409/* Revs 4 5 and 8 have partially shared layout */
410static void sprom_extract_r458(struct ssb_sprom *out, const u16 *in)
411{
412 SPEX(txpid2g[0], SSB_SPROM4_TXPID2G01,
413 SSB_SPROM4_TXPID2G0, SSB_SPROM4_TXPID2G0_SHIFT);
414 SPEX(txpid2g[1], SSB_SPROM4_TXPID2G01,
415 SSB_SPROM4_TXPID2G1, SSB_SPROM4_TXPID2G1_SHIFT);
416 SPEX(txpid2g[2], SSB_SPROM4_TXPID2G23,
417 SSB_SPROM4_TXPID2G2, SSB_SPROM4_TXPID2G2_SHIFT);
418 SPEX(txpid2g[3], SSB_SPROM4_TXPID2G23,
419 SSB_SPROM4_TXPID2G3, SSB_SPROM4_TXPID2G3_SHIFT);
420
421 SPEX(txpid5gl[0], SSB_SPROM4_TXPID5GL01,
422 SSB_SPROM4_TXPID5GL0, SSB_SPROM4_TXPID5GL0_SHIFT);
423 SPEX(txpid5gl[1], SSB_SPROM4_TXPID5GL01,
424 SSB_SPROM4_TXPID5GL1, SSB_SPROM4_TXPID5GL1_SHIFT);
425 SPEX(txpid5gl[2], SSB_SPROM4_TXPID5GL23,
426 SSB_SPROM4_TXPID5GL2, SSB_SPROM4_TXPID5GL2_SHIFT);
427 SPEX(txpid5gl[3], SSB_SPROM4_TXPID5GL23,
428 SSB_SPROM4_TXPID5GL3, SSB_SPROM4_TXPID5GL3_SHIFT);
429
430 SPEX(txpid5g[0], SSB_SPROM4_TXPID5G01,
431 SSB_SPROM4_TXPID5G0, SSB_SPROM4_TXPID5G0_SHIFT);
432 SPEX(txpid5g[1], SSB_SPROM4_TXPID5G01,
433 SSB_SPROM4_TXPID5G1, SSB_SPROM4_TXPID5G1_SHIFT);
434 SPEX(txpid5g[2], SSB_SPROM4_TXPID5G23,
435 SSB_SPROM4_TXPID5G2, SSB_SPROM4_TXPID5G2_SHIFT);
436 SPEX(txpid5g[3], SSB_SPROM4_TXPID5G23,
437 SSB_SPROM4_TXPID5G3, SSB_SPROM4_TXPID5G3_SHIFT);
438
439 SPEX(txpid5gh[0], SSB_SPROM4_TXPID5GH01,
440 SSB_SPROM4_TXPID5GH0, SSB_SPROM4_TXPID5GH0_SHIFT);
441 SPEX(txpid5gh[1], SSB_SPROM4_TXPID5GH01,
442 SSB_SPROM4_TXPID5GH1, SSB_SPROM4_TXPID5GH1_SHIFT);
443 SPEX(txpid5gh[2], SSB_SPROM4_TXPID5GH23,
444 SSB_SPROM4_TXPID5GH2, SSB_SPROM4_TXPID5GH2_SHIFT);
445 SPEX(txpid5gh[3], SSB_SPROM4_TXPID5GH23,
446 SSB_SPROM4_TXPID5GH3, SSB_SPROM4_TXPID5GH3_SHIFT);
447}
448
409static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in) 449static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in)
410{ 450{
411 int i; 451 int i;
@@ -428,10 +468,14 @@ static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in)
428 SPEX(country_code, SSB_SPROM4_CCODE, 0xFFFF, 0); 468 SPEX(country_code, SSB_SPROM4_CCODE, 0xFFFF, 0);
429 SPEX(boardflags_lo, SSB_SPROM4_BFLLO, 0xFFFF, 0); 469 SPEX(boardflags_lo, SSB_SPROM4_BFLLO, 0xFFFF, 0);
430 SPEX(boardflags_hi, SSB_SPROM4_BFLHI, 0xFFFF, 0); 470 SPEX(boardflags_hi, SSB_SPROM4_BFLHI, 0xFFFF, 0);
471 SPEX(boardflags2_lo, SSB_SPROM4_BFL2LO, 0xFFFF, 0);
472 SPEX(boardflags2_hi, SSB_SPROM4_BFL2HI, 0xFFFF, 0);
431 } else { 473 } else {
432 SPEX(country_code, SSB_SPROM5_CCODE, 0xFFFF, 0); 474 SPEX(country_code, SSB_SPROM5_CCODE, 0xFFFF, 0);
433 SPEX(boardflags_lo, SSB_SPROM5_BFLLO, 0xFFFF, 0); 475 SPEX(boardflags_lo, SSB_SPROM5_BFLLO, 0xFFFF, 0);
434 SPEX(boardflags_hi, SSB_SPROM5_BFLHI, 0xFFFF, 0); 476 SPEX(boardflags_hi, SSB_SPROM5_BFLHI, 0xFFFF, 0);
477 SPEX(boardflags2_lo, SSB_SPROM5_BFL2LO, 0xFFFF, 0);
478 SPEX(boardflags2_hi, SSB_SPROM5_BFL2HI, 0xFFFF, 0);
435 } 479 }
436 SPEX(ant_available_a, SSB_SPROM4_ANTAVAIL, SSB_SPROM4_ANTAVAIL_A, 480 SPEX(ant_available_a, SSB_SPROM4_ANTAVAIL, SSB_SPROM4_ANTAVAIL_A,
437 SSB_SPROM4_ANTAVAIL_A_SHIFT); 481 SSB_SPROM4_ANTAVAIL_A_SHIFT);
@@ -471,6 +515,8 @@ static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in)
471 memcpy(&out->antenna_gain.ghz5, &out->antenna_gain.ghz24, 515 memcpy(&out->antenna_gain.ghz5, &out->antenna_gain.ghz24,
472 sizeof(out->antenna_gain.ghz5)); 516 sizeof(out->antenna_gain.ghz5));
473 517
518 sprom_extract_r458(out, in);
519
474 /* TODO - get remaining rev 4 stuff needed */ 520 /* TODO - get remaining rev 4 stuff needed */
475} 521}
476 522
@@ -561,6 +607,8 @@ static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in)
561 memcpy(&out->antenna_gain.ghz5, &out->antenna_gain.ghz24, 607 memcpy(&out->antenna_gain.ghz5, &out->antenna_gain.ghz24,
562 sizeof(out->antenna_gain.ghz5)); 608 sizeof(out->antenna_gain.ghz5));
563 609
610 sprom_extract_r458(out, in);
611
564 /* TODO - get remaining rev 8 stuff needed */ 612 /* TODO - get remaining rev 8 stuff needed */
565} 613}
566 614
@@ -573,37 +621,34 @@ static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out,
573 ssb_dprintk(KERN_DEBUG PFX "SPROM revision %d detected.\n", out->revision); 621 ssb_dprintk(KERN_DEBUG PFX "SPROM revision %d detected.\n", out->revision);
574 memset(out->et0mac, 0xFF, 6); /* preset et0 and et1 mac */ 622 memset(out->et0mac, 0xFF, 6); /* preset et0 and et1 mac */
575 memset(out->et1mac, 0xFF, 6); 623 memset(out->et1mac, 0xFF, 6);
624
576 if ((bus->chip_id & 0xFF00) == 0x4400) { 625 if ((bus->chip_id & 0xFF00) == 0x4400) {
577 /* Workaround: The BCM44XX chip has a stupid revision 626 /* Workaround: The BCM44XX chip has a stupid revision
578 * number stored in the SPROM. 627 * number stored in the SPROM.
579 * Always extract r1. */ 628 * Always extract r1. */
580 out->revision = 1; 629 out->revision = 1;
630 ssb_dprintk(KERN_DEBUG PFX "SPROM treated as revision %d\n", out->revision);
631 }
632
633 switch (out->revision) {
634 case 1:
635 case 2:
636 case 3:
581 sprom_extract_r123(out, in); 637 sprom_extract_r123(out, in);
582 } else if (bus->chip_id == 0x4321) { 638 break;
583 /* the BCM4328 has a chipid == 0x4321 and a rev 4 SPROM */ 639 case 4:
584 out->revision = 4; 640 case 5:
585 sprom_extract_r45(out, in); 641 sprom_extract_r45(out, in);
586 } else { 642 break;
587 switch (out->revision) { 643 case 8:
588 case 1: 644 sprom_extract_r8(out, in);
589 case 2: 645 break;
590 case 3: 646 default:
591 sprom_extract_r123(out, in); 647 ssb_printk(KERN_WARNING PFX "Unsupported SPROM"
592 break; 648 " revision %d detected. Will extract"
593 case 4: 649 " v1\n", out->revision);
594 case 5: 650 out->revision = 1;
595 sprom_extract_r45(out, in); 651 sprom_extract_r123(out, in);
596 break;
597 case 8:
598 sprom_extract_r8(out, in);
599 break;
600 default:
601 ssb_printk(KERN_WARNING PFX "Unsupported SPROM"
602 " revision %d detected. Will extract"
603 " v1\n", out->revision);
604 out->revision = 1;
605 sprom_extract_r123(out, in);
606 }
607 } 652 }
608 653
609 if (out->boardflags_lo == 0xFFFF) 654 if (out->boardflags_lo == 0xFFFF)
@@ -617,15 +662,14 @@ static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out,
617static int ssb_pci_sprom_get(struct ssb_bus *bus, 662static int ssb_pci_sprom_get(struct ssb_bus *bus,
618 struct ssb_sprom *sprom) 663 struct ssb_sprom *sprom)
619{ 664{
620 const struct ssb_sprom *fallback; 665 int err;
621 int err = -ENOMEM;
622 u16 *buf; 666 u16 *buf;
623 667
624 if (!ssb_is_sprom_available(bus)) { 668 if (!ssb_is_sprom_available(bus)) {
625 ssb_printk(KERN_ERR PFX "No SPROM available!\n"); 669 ssb_printk(KERN_ERR PFX "No SPROM available!\n");
626 return -ENODEV; 670 return -ENODEV;
627 } 671 }
628 if (bus->chipco.dev) { /* can be unavailible! */ 672 if (bus->chipco.dev) { /* can be unavailable! */
629 /* 673 /*
630 * get SPROM offset: SSB_SPROM_BASE1 except for 674 * get SPROM offset: SSB_SPROM_BASE1 except for
631 * chipcommon rev >= 31 or chip ID is 0x4312 and 675 * chipcommon rev >= 31 or chip ID is 0x4312 and
@@ -645,7 +689,7 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus,
645 689
646 buf = kcalloc(SSB_SPROMSIZE_WORDS_R123, sizeof(u16), GFP_KERNEL); 690 buf = kcalloc(SSB_SPROMSIZE_WORDS_R123, sizeof(u16), GFP_KERNEL);
647 if (!buf) 691 if (!buf)
648 goto out; 692 return -ENOMEM;
649 bus->sprom_size = SSB_SPROMSIZE_WORDS_R123; 693 bus->sprom_size = SSB_SPROMSIZE_WORDS_R123;
650 sprom_do_read(bus, buf); 694 sprom_do_read(bus, buf);
651 err = sprom_check_crc(buf, bus->sprom_size); 695 err = sprom_check_crc(buf, bus->sprom_size);
@@ -655,17 +699,24 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus,
655 buf = kcalloc(SSB_SPROMSIZE_WORDS_R4, sizeof(u16), 699 buf = kcalloc(SSB_SPROMSIZE_WORDS_R4, sizeof(u16),
656 GFP_KERNEL); 700 GFP_KERNEL);
657 if (!buf) 701 if (!buf)
658 goto out; 702 return -ENOMEM;
659 bus->sprom_size = SSB_SPROMSIZE_WORDS_R4; 703 bus->sprom_size = SSB_SPROMSIZE_WORDS_R4;
660 sprom_do_read(bus, buf); 704 sprom_do_read(bus, buf);
661 err = sprom_check_crc(buf, bus->sprom_size); 705 err = sprom_check_crc(buf, bus->sprom_size);
662 if (err) { 706 if (err) {
663 /* All CRC attempts failed. 707 /* All CRC attempts failed.
664 * Maybe there is no SPROM on the device? 708 * Maybe there is no SPROM on the device?
665 * If we have a fallback, use that. */ 709 * Now we ask the arch code if there is some sprom
666 fallback = ssb_get_fallback_sprom(); 710 * available for this device in some other storage */
667 if (fallback) { 711 err = ssb_fill_sprom_with_fallback(bus, sprom);
668 memcpy(sprom, fallback, sizeof(*sprom)); 712 if (err) {
713 ssb_printk(KERN_WARNING PFX "WARNING: Using"
714 " fallback SPROM failed (err %d)\n",
715 err);
716 } else {
717 ssb_dprintk(KERN_DEBUG PFX "Using SPROM"
718 " revision %d provided by"
719 " platform.\n", sprom->revision);
669 err = 0; 720 err = 0;
670 goto out_free; 721 goto out_free;
671 } 722 }
@@ -677,7 +728,6 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus,
677 728
678out_free: 729out_free:
679 kfree(buf); 730 kfree(buf);
680out:
681 return err; 731 return err;
682} 732}
683 733
diff --git a/drivers/ssb/pcihost_wrapper.c b/drivers/ssb/pcihost_wrapper.c
index 6536a041d90d..f6c8c81a0025 100644
--- a/drivers/ssb/pcihost_wrapper.c
+++ b/drivers/ssb/pcihost_wrapper.c
@@ -59,6 +59,7 @@ static int ssb_pcihost_probe(struct pci_dev *dev,
59 struct ssb_bus *ssb; 59 struct ssb_bus *ssb;
60 int err = -ENOMEM; 60 int err = -ENOMEM;
61 const char *name; 61 const char *name;
62 u32 val;
62 63
63 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL); 64 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
64 if (!ssb) 65 if (!ssb)
@@ -74,6 +75,12 @@ static int ssb_pcihost_probe(struct pci_dev *dev,
74 goto err_pci_disable; 75 goto err_pci_disable;
75 pci_set_master(dev); 76 pci_set_master(dev);
76 77
78 /* Disable the RETRY_TIMEOUT register (0x41) to keep
79 * PCI Tx retries from interfering with C3 CPU state */
80 pci_read_config_dword(dev, 0x40, &val);
81 if ((val & 0x0000ff00) != 0)
82 pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
83
77 err = ssb_bus_pcibus_register(ssb, dev); 84 err = ssb_bus_pcibus_register(ssb, dev);
78 if (err) 85 if (err)
79 goto err_pci_release_regions; 86 goto err_pci_release_regions;
diff --git a/drivers/ssb/pcmcia.c b/drivers/ssb/pcmcia.c
index 526682d68de8..f8533795ee7f 100644
--- a/drivers/ssb/pcmcia.c
+++ b/drivers/ssb/pcmcia.c
@@ -13,7 +13,6 @@
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/etherdevice.h> 14#include <linux/etherdevice.h>
15 15
16#include <pcmcia/cs.h>
17#include <pcmcia/cistpl.h> 16#include <pcmcia/cistpl.h>
18#include <pcmcia/ciscode.h> 17#include <pcmcia/ciscode.h>
19#include <pcmcia/ds.h> 18#include <pcmcia/ds.h>
@@ -734,7 +733,7 @@ int ssb_pcmcia_get_invariants(struct ssb_bus *bus,
734 733
735 /* Fetch the vendor specific tuples. */ 734 /* Fetch the vendor specific tuples. */
736 res = pcmcia_loop_tuple(bus->host_pcmcia, SSB_PCMCIA_CIS, 735 res = pcmcia_loop_tuple(bus->host_pcmcia, SSB_PCMCIA_CIS,
737 ssb_pcmcia_do_get_invariants, sprom); 736 ssb_pcmcia_do_get_invariants, iv);
738 if ((res == 0) || (res == -ENOSPC)) 737 if ((res == 0) || (res == -ENOSPC))
739 return 0; 738 return 0;
740 739
diff --git a/drivers/ssb/scan.c b/drivers/ssb/scan.c
index 9738cad4ba13..45e5babd3961 100644
--- a/drivers/ssb/scan.c
+++ b/drivers/ssb/scan.c
@@ -17,7 +17,6 @@
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/io.h> 18#include <linux/io.h>
19 19
20#include <pcmcia/cs.h>
21#include <pcmcia/cistpl.h> 20#include <pcmcia/cistpl.h>
22#include <pcmcia/ds.h> 21#include <pcmcia/ds.h>
23 22
@@ -259,7 +258,10 @@ static int we_support_multiple_80211_cores(struct ssb_bus *bus)
259#ifdef CONFIG_SSB_PCIHOST 258#ifdef CONFIG_SSB_PCIHOST
260 if (bus->bustype == SSB_BUSTYPE_PCI) { 259 if (bus->bustype == SSB_BUSTYPE_PCI) {
261 if (bus->host_pci->vendor == PCI_VENDOR_ID_BROADCOM && 260 if (bus->host_pci->vendor == PCI_VENDOR_ID_BROADCOM &&
262 bus->host_pci->device == 0x4324) 261 ((bus->host_pci->device == 0x4313) ||
262 (bus->host_pci->device == 0x431A) ||
263 (bus->host_pci->device == 0x4321) ||
264 (bus->host_pci->device == 0x4324)))
263 return 1; 265 return 1;
264 } 266 }
265#endif /* CONFIG_SSB_PCIHOST */ 267#endif /* CONFIG_SSB_PCIHOST */
@@ -308,7 +310,7 @@ int ssb_bus_scan(struct ssb_bus *bus,
308 } else { 310 } else {
309 if (bus->bustype == SSB_BUSTYPE_PCI) { 311 if (bus->bustype == SSB_BUSTYPE_PCI) {
310 bus->chip_id = pcidev_to_chipid(bus->host_pci); 312 bus->chip_id = pcidev_to_chipid(bus->host_pci);
311 pci_read_config_word(bus->host_pci, PCI_REVISION_ID, 313 pci_read_config_byte(bus->host_pci, PCI_REVISION_ID,
312 &bus->chip_rev); 314 &bus->chip_rev);
313 bus->chip_package = 0; 315 bus->chip_package = 0;
314 } else { 316 } else {
@@ -406,10 +408,10 @@ int ssb_bus_scan(struct ssb_bus *bus,
406 /* Ignore PCI cores on PCI-E cards. 408 /* Ignore PCI cores on PCI-E cards.
407 * Ignore PCI-E cores on PCI cards. */ 409 * Ignore PCI-E cores on PCI cards. */
408 if (dev->id.coreid == SSB_DEV_PCI) { 410 if (dev->id.coreid == SSB_DEV_PCI) {
409 if (bus->host_pci->is_pcie) 411 if (pci_is_pcie(bus->host_pci))
410 continue; 412 continue;
411 } else { 413 } else {
412 if (!bus->host_pci->is_pcie) 414 if (!pci_is_pcie(bus->host_pci))
413 continue; 415 continue;
414 } 416 }
415 } 417 }
@@ -421,6 +423,16 @@ int ssb_bus_scan(struct ssb_bus *bus,
421 bus->pcicore.dev = dev; 423 bus->pcicore.dev = dev;
422#endif /* CONFIG_SSB_DRIVER_PCICORE */ 424#endif /* CONFIG_SSB_DRIVER_PCICORE */
423 break; 425 break;
426 case SSB_DEV_ETHERNET:
427 if (bus->bustype == SSB_BUSTYPE_PCI) {
428 if (bus->host_pci->vendor == PCI_VENDOR_ID_BROADCOM &&
429 (bus->host_pci->device & 0xFF00) == 0x4300) {
430 /* This is a dangling ethernet core on a
431 * wireless device. Ignore it. */
432 continue;
433 }
434 }
435 break;
424 default: 436 default:
425 break; 437 break;
426 } 438 }
diff --git a/drivers/ssb/sprom.c b/drivers/ssb/sprom.c
index 4f7cc8d13277..45ff0e3a3828 100644
--- a/drivers/ssb/sprom.c
+++ b/drivers/ssb/sprom.c
@@ -17,7 +17,7 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18 18
19 19
20static const struct ssb_sprom *fallback_sprom; 20static int(*get_fallback_sprom)(struct ssb_bus *dev, struct ssb_sprom *out);
21 21
22 22
23static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len, 23static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len,
@@ -145,36 +145,43 @@ out:
145} 145}
146 146
147/** 147/**
148 * ssb_arch_set_fallback_sprom - Set a fallback SPROM for use if no SPROM is found. 148 * ssb_arch_register_fallback_sprom - Registers a method providing a
149 * fallback SPROM if no SPROM is found.
149 * 150 *
150 * @sprom: The SPROM data structure to register. 151 * @sprom_callback: The callback function.
151 * 152 *
152 * With this function the architecture implementation may register a fallback 153 * With this function the architecture implementation may register a
153 * SPROM data structure. The fallback is only used for PCI based SSB devices, 154 * callback handler which fills the SPROM data structure. The fallback is
154 * where no valid SPROM can be found in the shadow registers. 155 * only used for PCI based SSB devices, where no valid SPROM can be found
156 * in the shadow registers.
155 * 157 *
156 * This function is useful for weird architectures that have a half-assed SSB device 158 * This function is useful for weird architectures that have a half-assed
157 * hardwired to their PCI bus. 159 * SSB device hardwired to their PCI bus.
158 * 160 *
159 * Note that it does only work with PCI attached SSB devices. PCMCIA devices currently 161 * Note that it does only work with PCI attached SSB devices. PCMCIA
160 * don't use this fallback. 162 * devices currently don't use this fallback.
161 * Architectures must provide the SPROM for native SSB devices anyway, 163 * Architectures must provide the SPROM for native SSB devices anyway, so
162 * so the fallback also isn't used for native devices. 164 * the fallback also isn't used for native devices.
163 * 165 *
164 * This function is available for architecture code, only. So it is not exported. 166 * This function is available for architecture code, only. So it is not
167 * exported.
165 */ 168 */
166int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom) 169int ssb_arch_register_fallback_sprom(int (*sprom_callback)(struct ssb_bus *bus,
170 struct ssb_sprom *out))
167{ 171{
168 if (fallback_sprom) 172 if (get_fallback_sprom)
169 return -EEXIST; 173 return -EEXIST;
170 fallback_sprom = sprom; 174 get_fallback_sprom = sprom_callback;
171 175
172 return 0; 176 return 0;
173} 177}
174 178
175const struct ssb_sprom *ssb_get_fallback_sprom(void) 179int ssb_fill_sprom_with_fallback(struct ssb_bus *bus, struct ssb_sprom *out)
176{ 180{
177 return fallback_sprom; 181 if (!get_fallback_sprom)
182 return -ENOENT;
183
184 return get_fallback_sprom(bus, out);
178} 185}
179 186
180/* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */ 187/* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */
@@ -185,7 +192,7 @@ bool ssb_is_sprom_available(struct ssb_bus *bus)
185 /* this routine differs from specs as we do not access SPROM directly 192 /* this routine differs from specs as we do not access SPROM directly
186 on PCMCIA */ 193 on PCMCIA */
187 if (bus->bustype == SSB_BUSTYPE_PCI && 194 if (bus->bustype == SSB_BUSTYPE_PCI &&
188 bus->chipco.dev && /* can be unavailible! */ 195 bus->chipco.dev && /* can be unavailable! */
189 bus->chipco.dev->id.revision >= 31) 196 bus->chipco.dev->id.revision >= 31)
190 return bus->chipco.capabilities & SSB_CHIPCO_CAP_SPROM; 197 return bus->chipco.capabilities & SSB_CHIPCO_CAP_SPROM;
191 198
diff --git a/drivers/ssb/ssb_private.h b/drivers/ssb/ssb_private.h
index 0331139a726f..77653014db0b 100644
--- a/drivers/ssb/ssb_private.h
+++ b/drivers/ssb/ssb_private.h
@@ -171,7 +171,8 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus,
171 const char *buf, size_t count, 171 const char *buf, size_t count,
172 int (*sprom_check_crc)(const u16 *sprom, size_t size), 172 int (*sprom_check_crc)(const u16 *sprom, size_t size),
173 int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom)); 173 int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom));
174extern const struct ssb_sprom *ssb_get_fallback_sprom(void); 174extern int ssb_fill_sprom_with_fallback(struct ssb_bus *bus,
175 struct ssb_sprom *out);
175 176
176 177
177/* core.c */ 178/* core.c */