404
409
#endif /* CONFIG_SSB_PCICORE_HOSTMODE */
411
/**************************************************
413
**************************************************/
415
static void ssb_pcicore_fix_sprom_core_index(struct ssb_pcicore *pc)
417
u16 tmp = pcicore_read16(pc, SSB_PCICORE_SPROM(0));
418
if (((tmp & 0xF000) >> 12) != pc->dev->core_index) {
420
tmp |= (pc->dev->core_index << 12);
421
pcicore_write16(pc, SSB_PCICORE_SPROM(0), tmp);
425
static u8 ssb_pcicore_polarity_workaround(struct ssb_pcicore *pc)
427
return (ssb_pcie_read(pc, 0x204) & 0x10) ? 0xC0 : 0x80;
430
static void ssb_pcicore_serdes_workaround(struct ssb_pcicore *pc)
432
const u8 serdes_pll_device = 0x1D;
433
const u8 serdes_rx_device = 0x1F;
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 */);
440
ssb_pcie_mdio_write(pc, serdes_pll_device, 1, tmp & ~0x4000);
443
static void ssb_pcicore_pci_setup_workarounds(struct ssb_pcicore *pc)
445
struct ssb_device *pdev = pc->dev;
446
struct ssb_bus *bus = pdev->bus;
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);
454
if (pdev->id.revision < 5) {
455
tmp = ssb_read32(pdev, SSB_IMCFGLO);
456
tmp &= ~SSB_IMCFGLO_SERTO;
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);
469
static void ssb_pcicore_pcie_setup_workarounds(struct ssb_pcicore *pc)
472
u8 rev = pc->dev->id.revision;
474
if (rev == 0 || rev == 1) {
475
/* TLP Workaround register. */
476
tmp = ssb_pcie_read(pc, 0x4);
478
ssb_pcie_write(pc, 0x4, tmp);
481
/* DLLP Link Control register. */
482
tmp = ssb_pcie_read(pc, 0x100);
484
ssb_pcie_write(pc, 0x100, tmp);
488
const u8 serdes_rx_device = 0x1F;
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);
500
} else if (rev == 7) {
501
/* TODO: No PLL down */
505
/* Miscellaneous Configuration Fixup */
506
tmp = pcicore_read16(pc, SSB_PCICORE_SPROM(5));
508
pcicore_write16(pc, SSB_PCICORE_SPROM(5),
407
513
/**************************************************
408
514
* Generic and Clientmode operation code.
411
517
static void ssb_pcicore_init_clientmode(struct ssb_pcicore *pc)
519
ssb_pcicore_fix_sprom_core_index(pc);
413
521
/* Disable PCI interrupts. */
414
522
ssb_write32(pc->dev, SSB_INTVEC, 0);
524
/* Additional PCIe always once-executed workarounds */
525
if (pc->dev->id.coreid == SSB_DEV_PCIE) {
526
ssb_pcicore_serdes_workaround(pc);
528
/* TODO: Clock Request Update */
417
532
void ssb_pcicore_init(struct ssb_pcicore *pc)
419
534
struct ssb_device *dev = pc->dev;
425
538
if (!ssb_device_is_enabled(dev))
426
539
ssb_device_enable(dev, 0);
446
559
pcicore_write32(pc, 0x134, data);
562
static void ssb_pcie_mdio_set_phy(struct ssb_pcicore *pc, u8 phy)
564
const u16 mdio_control = 0x128;
565
const u16 mdio_data = 0x12C;
569
v = (1 << 30); /* Start of Transaction */
570
v |= (1 << 28); /* Write Transaction */
571
v |= (1 << 17); /* Turnaround */
574
pcicore_write32(pc, mdio_data, v);
577
for (i = 0; i < 200; i++) {
578
v = pcicore_read32(pc, mdio_control);
579
if (v & 0x100 /* Trans complete */)
585
static u16 ssb_pcie_mdio_read(struct ssb_pcicore *pc, u8 device, u8 address)
587
const u16 mdio_control = 0x128;
588
const u16 mdio_data = 0x12C;
589
int max_retries = 10;
594
v = 0x80; /* Enable Preamble Sequence */
595
v |= 0x2; /* MDIO Clock Divisor */
596
pcicore_write32(pc, mdio_control, v);
598
if (pc->dev->id.revision >= 10) {
600
ssb_pcie_mdio_set_phy(pc, device);
603
v = (1 << 30); /* Start of Transaction */
604
v |= (1 << 29); /* Read Transaction */
605
v |= (1 << 17); /* Turnaround */
606
if (pc->dev->id.revision < 10)
607
v |= (u32)device << 22;
608
v |= (u32)address << 18;
609
pcicore_write32(pc, mdio_data, v);
610
/* Wait for the device to complete the transaction */
612
for (i = 0; i < max_retries; i++) {
613
v = pcicore_read32(pc, mdio_control);
614
if (v & 0x100 /* Trans complete */) {
616
ret = pcicore_read32(pc, mdio_data);
621
pcicore_write32(pc, mdio_control, 0);
449
625
static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
450
626
u8 address, u16 data)
452
628
const u16 mdio_control = 0x128;
453
629
const u16 mdio_data = 0x12C;
630
int max_retries = 10;
458
635
v |= 0x2; /* MDIO Clock Divisor */
459
636
pcicore_write32(pc, mdio_control, v);
638
if (pc->dev->id.revision >= 10) {
640
ssb_pcie_mdio_set_phy(pc, device);
461
643
v = (1 << 30); /* Start of Transaction */
462
644
v |= (1 << 28); /* Write Transaction */
463
645
v |= (1 << 17); /* Turnaround */
464
v |= (u32)device << 22;
646
if (pc->dev->id.revision < 10)
647
v |= (u32)device << 22;
465
648
v |= (u32)address << 18;
467
650
pcicore_write32(pc, mdio_data, v);
468
651
/* Wait for the device to complete the transaction */
470
for (i = 0; i < 10; i++) {
653
for (i = 0; i < max_retries; i++) {
471
654
v = pcicore_read32(pc, mdio_control);
472
655
if (v & 0x100 /* Trans complete */)
476
659
pcicore_write32(pc, mdio_control, 0);
479
static void ssb_broadcast_value(struct ssb_device *dev,
480
u32 address, u32 data)
482
/* This is used for both, PCI and ChipCommon core, so be careful. */
483
BUILD_BUG_ON(SSB_PCICORE_BCAST_ADDR != SSB_CHIPCO_BCAST_ADDR);
484
BUILD_BUG_ON(SSB_PCICORE_BCAST_DATA != SSB_CHIPCO_BCAST_DATA);
486
ssb_write32(dev, SSB_PCICORE_BCAST_ADDR, address);
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 */
492
static void ssb_commit_settings(struct ssb_bus *bus)
494
struct ssb_device *dev;
496
dev = bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev;
499
/* This forces an update of the cached registers. */
500
ssb_broadcast_value(dev, 0xFD8, 0);
503
662
int ssb_pcicore_dev_irqvecs_enable(struct ssb_pcicore *pc,
504
663
struct ssb_device *dev)
550
709
if (pc->setup_done)
552
711
if (pdev->id.coreid == SSB_DEV_PCI) {
553
tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
554
tmp |= SSB_PCICORE_SBTOPCI_PREF;
555
tmp |= SSB_PCICORE_SBTOPCI_BURST;
556
pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
558
if (pdev->id.revision < 5) {
559
tmp = ssb_read32(pdev, SSB_IMCFGLO);
560
tmp &= ~SSB_IMCFGLO_SERTO;
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);
712
ssb_pcicore_pci_setup_workarounds(pc);
572
714
WARN_ON(pdev->id.coreid != SSB_DEV_PCIE);
573
//TODO: Better make defines for all these magic PCIE values.
574
if ((pdev->id.revision == 0) || (pdev->id.revision == 1)) {
575
/* TLP Workaround register. */
576
tmp = ssb_pcie_read(pc, 0x4);
578
ssb_pcie_write(pc, 0x4, tmp);
580
if (pdev->id.revision == 0) {
581
const u8 serdes_rx_device = 0x1F;
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);
593
ssb_pcie_write(pc, 0x100, tmp);
715
ssb_pcicore_pcie_setup_workarounds(pc);
596
717
pc->setup_done = 1;