~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/ssb/driver_pcicore.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include "ssb_private.h"
17
17
 
 
18
static u32 ssb_pcie_read(struct ssb_pcicore *pc, u32 address);
 
19
static void ssb_pcie_write(struct ssb_pcicore *pc, u32 address, u32 data);
 
20
static u16 ssb_pcie_mdio_read(struct ssb_pcicore *pc, u8 device, u8 address);
 
21
static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
 
22
                                u8 address, u16 data);
18
23
 
19
24
static inline
20
25
u32 pcicore_read32(struct ssb_pcicore *pc, u16 offset)
403
408
}
404
409
#endif /* CONFIG_SSB_PCICORE_HOSTMODE */
405
410
 
 
411
/**************************************************
 
412
 * Workarounds.
 
413
 **************************************************/
 
414
 
 
415
static 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
 
 
425
static u8 ssb_pcicore_polarity_workaround(struct ssb_pcicore *pc)
 
426
{
 
427
        return (ssb_pcie_read(pc, 0x204) & 0x10) ? 0xC0 : 0x80;
 
428
}
 
429
 
 
430
static 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
 
 
443
static 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
 
 
469
static 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
514
 * Generic and Clientmode operation code.
410
516
 
411
517
static void ssb_pcicore_init_clientmode(struct ssb_pcicore *pc)
412
518
{
 
519
        ssb_pcicore_fix_sprom_core_index(pc);
 
520
 
413
521
        /* Disable PCI interrupts. */
414
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
 
417
532
void ssb_pcicore_init(struct ssb_pcicore *pc)
418
533
{
419
534
        struct ssb_device *dev = pc->dev;
420
 
        struct ssb_bus *bus;
421
535
 
422
536
        if (!dev)
423
537
                return;
424
 
        bus = dev->bus;
425
538
        if (!ssb_device_is_enabled(dev))
426
539
                ssb_device_enable(dev, 0);
427
540
 
446
559
        pcicore_write32(pc, 0x134, data);
447
560
}
448
561
 
 
562
static void ssb_pcie_mdio_set_phy(struct ssb_pcicore *pc, u8 phy)
 
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
 
 
585
static u16 ssb_pcie_mdio_read(struct ssb_pcicore *pc, u8 device, u8 address)
 
586
{
 
587
        const u16 mdio_control = 0x128;
 
588
        const u16 mdio_data = 0x12C;
 
589
        int max_retries = 10;
 
590
        u16 ret = 0;
 
591
        u32 v;
 
592
        int i;
 
593
 
 
594
        v = 0x80; /* Enable Preamble Sequence */
 
595
        v |= 0x2; /* MDIO Clock Divisor */
 
596
        pcicore_write32(pc, mdio_control, v);
 
597
 
 
598
        if (pc->dev->id.revision >= 10) {
 
599
                max_retries = 200;
 
600
                ssb_pcie_mdio_set_phy(pc, device);
 
601
        }
 
602
 
 
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 */
 
611
        udelay(10);
 
612
        for (i = 0; i < max_retries; i++) {
 
613
                v = pcicore_read32(pc, mdio_control);
 
614
                if (v & 0x100 /* Trans complete */) {
 
615
                        udelay(10);
 
616
                        ret = pcicore_read32(pc, mdio_data);
 
617
                        break;
 
618
                }
 
619
                msleep(1);
 
620
        }
 
621
        pcicore_write32(pc, mdio_control, 0);
 
622
        return ret;
 
623
}
 
624
 
449
625
static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
450
626
                                u8 address, u16 data)
451
627
{
452
628
        const u16 mdio_control = 0x128;
453
629
        const u16 mdio_data = 0x12C;
 
630
        int max_retries = 10;
454
631
        u32 v;
455
632
        int i;
456
633
 
458
635
        v |= 0x2; /* MDIO Clock Divisor */
459
636
        pcicore_write32(pc, mdio_control, v);
460
637
 
 
638
        if (pc->dev->id.revision >= 10) {
 
639
                max_retries = 200;
 
640
                ssb_pcie_mdio_set_phy(pc, device);
 
641
        }
 
642
 
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;
466
649
        v |= data;
467
650
        pcicore_write32(pc, mdio_data, v);
468
651
        /* Wait for the device to complete the transaction */
469
652
        udelay(10);
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 */)
473
656
                        break;
476
659
        pcicore_write32(pc, mdio_control, 0);
477
660
}
478
661
 
479
 
static void ssb_broadcast_value(struct ssb_device *dev,
480
 
                                u32 address, u32 data)
481
 
{
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);
485
 
 
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 */
490
 
}
491
 
 
492
 
static void ssb_commit_settings(struct ssb_bus *bus)
493
 
{
494
 
        struct ssb_device *dev;
495
 
 
496
 
        dev = bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev;
497
 
        if (WARN_ON(!dev))
498
 
                return;
499
 
        /* This forces an update of the cached registers. */
500
 
        ssb_broadcast_value(dev, 0xFD8, 0);
501
 
}
502
 
 
503
662
int ssb_pcicore_dev_irqvecs_enable(struct ssb_pcicore *pc,
504
663
                                   struct ssb_device *dev)
505
664
{
550
709
        if (pc->setup_done)
551
710
                goto out;
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);
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
 
                }
 
712
                ssb_pcicore_pci_setup_workarounds(pc);
571
713
        } else {
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);
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
 
                }
 
715
                ssb_pcicore_pcie_setup_workarounds(pc);
595
716
        }
596
717
        pc->setup_done = 1;
597
718
out: