pata_marvell.c 4.1 KB

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