pata_marvell.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Marvell PATA driver.
  3. *
  4. * For the moment we drive the PATA port in legacy mode. That
  5. * isn't making full use of the device functionality but it is
  6. * easy to get working.
  7. *
  8. * (c) 2006 Red Hat
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/pci.h>
  13. #include <linux/blkdev.h>
  14. #include <linux/delay.h>
  15. #include <linux/device.h>
  16. #include <scsi/scsi_host.h>
  17. #include <linux/libata.h>
  18. #include <linux/ata.h>
  19. #define DRV_NAME "pata_marvell"
  20. #define DRV_VERSION "0.1.6"
  21. /**
  22. * marvell_pata_active - check if PATA is active
  23. * @pdev: PCI device
  24. *
  25. * Returns 1 if the PATA port may be active. We know how to check this
  26. * for the 6145 but not the other devices
  27. */
  28. static int marvell_pata_active(struct pci_dev *pdev)
  29. {
  30. int i;
  31. u32 devices;
  32. void __iomem *barp;
  33. /* We don't yet know how to do this for other devices */
  34. if (pdev->device != 0x6145)
  35. return 1;
  36. barp = pci_iomap(pdev, 5, 0x10);
  37. if (barp == NULL)
  38. return -ENOMEM;
  39. printk("BAR5:");
  40. for(i = 0; i <= 0x0F; i++)
  41. printk("%02X:%02X ", i, ioread8(barp + i));
  42. printk("\n");
  43. devices = ioread32(barp + 0x0C);
  44. pci_iounmap(pdev, barp);
  45. if (devices & 0x10)
  46. return 1;
  47. return 0;
  48. }
  49. /**
  50. * marvell_pre_reset - probe begin
  51. * @link: link
  52. * @deadline: deadline jiffies for the operation
  53. *
  54. * Perform the PATA port setup we need.
  55. */
  56. static int marvell_pre_reset(struct ata_link *link, unsigned long deadline)
  57. {
  58. struct ata_port *ap = link->ap;
  59. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  60. if (pdev->device == 0x6145 && ap->port_no == 0 &&
  61. !marvell_pata_active(pdev)) /* PATA enable ? */
  62. return -ENOENT;
  63. return ata_sff_prereset(link, deadline);
  64. }
  65. static int marvell_cable_detect(struct ata_port *ap)
  66. {
  67. /* Cable type */
  68. switch(ap->port_no)
  69. {
  70. case 0:
  71. if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
  72. return ATA_CBL_PATA40;
  73. return ATA_CBL_PATA80;
  74. case 1: /* Legacy SATA port */
  75. return ATA_CBL_SATA;
  76. }
  77. BUG();
  78. return 0; /* Our BUG macro needs the right markup */
  79. }
  80. /* No PIO or DMA methods needed for this device */
  81. static struct scsi_host_template marvell_sht = {
  82. ATA_BMDMA_SHT(DRV_NAME),
  83. };
  84. static struct ata_port_operations marvell_ops = {
  85. .inherits = &ata_bmdma_port_ops,
  86. .cable_detect = marvell_cable_detect,
  87. .prereset = marvell_pre_reset,
  88. };
  89. /**
  90. * marvell_init_one - Register Marvell ATA PCI device with kernel services
  91. * @pdev: PCI device to register
  92. * @ent: Entry in marvell_pci_tbl matching with @pdev
  93. *
  94. * Called from kernel PCI layer.
  95. *
  96. * LOCKING:
  97. * Inherited from PCI layer (may sleep).
  98. *
  99. * RETURNS:
  100. * Zero on success, or -ERRNO value.
  101. */
  102. static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  103. {
  104. static const struct ata_port_info info = {
  105. .flags = ATA_FLAG_SLAVE_POSS,
  106. .pio_mask = ATA_PIO4,
  107. .mwdma_mask = ATA_MWDMA2,
  108. .udma_mask = ATA_UDMA5,
  109. .port_ops = &marvell_ops,
  110. };
  111. static const struct ata_port_info info_sata = {
  112. /* Slave possible as its magically mapped not real */
  113. .flags = ATA_FLAG_SLAVE_POSS,
  114. .pio_mask = ATA_PIO4,
  115. .mwdma_mask = ATA_MWDMA2,
  116. .udma_mask = ATA_UDMA6,
  117. .port_ops = &marvell_ops,
  118. };
  119. const struct ata_port_info *ppi[] = { &info, &info_sata };
  120. if (pdev->device == 0x6101)
  121. ppi[1] = &ata_dummy_port_info;
  122. #if defined(CONFIG_SATA_AHCI) || defined(CONFIG_SATA_AHCI_MODULE)
  123. if (!marvell_pata_active(pdev)) {
  124. printk(KERN_INFO DRV_NAME ": PATA port not active, deferring to AHCI driver.\n");
  125. return -ENODEV;
  126. }
  127. #endif
  128. return ata_pci_bmdma_init_one(pdev, ppi, &marvell_sht, NULL, 0);
  129. }
  130. static const struct pci_device_id marvell_pci_tbl[] = {
  131. { PCI_DEVICE(0x11AB, 0x6101), },
  132. { PCI_DEVICE(0x11AB, 0x6121), },
  133. { PCI_DEVICE(0x11AB, 0x6123), },
  134. { PCI_DEVICE(0x11AB, 0x6145), },
  135. { PCI_DEVICE(0x1B4B, 0x91A0), },
  136. { PCI_DEVICE(0x1B4B, 0x91A4), },
  137. { } /* terminate list */
  138. };
  139. static struct pci_driver marvell_pci_driver = {
  140. .name = DRV_NAME,
  141. .id_table = marvell_pci_tbl,
  142. .probe = marvell_init_one,
  143. .remove = ata_pci_remove_one,
  144. #ifdef CONFIG_PM_SLEEP
  145. .suspend = ata_pci_device_suspend,
  146. .resume = ata_pci_device_resume,
  147. #endif
  148. };
  149. module_pci_driver(marvell_pci_driver);
  150. MODULE_AUTHOR("Alan Cox");
  151. MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
  152. MODULE_LICENSE("GPL");
  153. MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
  154. MODULE_VERSION(DRV_VERSION);