pata_marvell.c 4.4 KB

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