pata_marvell.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. 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 (!ap->ioaddr.bmdma_addr)
  73. return ATA_CBL_PATA_UNK;
  74. if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
  75. return ATA_CBL_PATA40;
  76. return ATA_CBL_PATA80;
  77. case 1: /* Legacy SATA port */
  78. return ATA_CBL_SATA;
  79. }
  80. BUG();
  81. return 0; /* Our BUG macro needs the right markup */
  82. }
  83. /* No PIO or DMA methods needed for this device */
  84. static struct scsi_host_template marvell_sht = {
  85. ATA_BMDMA_SHT(DRV_NAME),
  86. };
  87. static struct ata_port_operations marvell_ops = {
  88. .inherits = &ata_bmdma_port_ops,
  89. .cable_detect = marvell_cable_detect,
  90. .prereset = marvell_pre_reset,
  91. };
  92. /**
  93. * marvell_init_one - Register Marvell ATA PCI device with kernel services
  94. * @pdev: PCI device to register
  95. * @ent: Entry in marvell_pci_tbl matching with @pdev
  96. *
  97. * Called from kernel PCI layer.
  98. *
  99. * LOCKING:
  100. * Inherited from PCI layer (may sleep).
  101. *
  102. * RETURNS:
  103. * Zero on success, or -ERRNO value.
  104. */
  105. static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  106. {
  107. static const struct ata_port_info info = {
  108. .flags = ATA_FLAG_SLAVE_POSS,
  109. .pio_mask = ATA_PIO4,
  110. .mwdma_mask = ATA_MWDMA2,
  111. .udma_mask = ATA_UDMA5,
  112. .port_ops = &marvell_ops,
  113. };
  114. static const struct ata_port_info info_sata = {
  115. /* Slave possible as its magically mapped not real */
  116. .flags = ATA_FLAG_SLAVE_POSS,
  117. .pio_mask = ATA_PIO4,
  118. .mwdma_mask = ATA_MWDMA2,
  119. .udma_mask = ATA_UDMA6,
  120. .port_ops = &marvell_ops,
  121. };
  122. const struct ata_port_info *ppi[] = { &info, &info_sata };
  123. if (pdev->device == 0x6101)
  124. ppi[1] = &ata_dummy_port_info;
  125. #if IS_ENABLED(CONFIG_SATA_AHCI)
  126. if (!marvell_pata_active(pdev)) {
  127. printk(KERN_INFO DRV_NAME ": PATA port not active, deferring to AHCI driver.\n");
  128. return -ENODEV;
  129. }
  130. #endif
  131. return ata_pci_bmdma_init_one(pdev, ppi, &marvell_sht, NULL, 0);
  132. }
  133. static const struct pci_device_id marvell_pci_tbl[] = {
  134. { PCI_DEVICE(0x11AB, 0x6101), },
  135. { PCI_DEVICE(0x11AB, 0x6121), },
  136. { PCI_DEVICE(0x11AB, 0x6123), },
  137. { PCI_DEVICE(0x11AB, 0x6145), },
  138. { PCI_DEVICE(0x1B4B, 0x91A0), },
  139. { PCI_DEVICE(0x1B4B, 0x91A4), },
  140. { } /* terminate list */
  141. };
  142. static struct pci_driver marvell_pci_driver = {
  143. .name = DRV_NAME,
  144. .id_table = marvell_pci_tbl,
  145. .probe = marvell_init_one,
  146. .remove = ata_pci_remove_one,
  147. #ifdef CONFIG_PM_SLEEP
  148. .suspend = ata_pci_device_suspend,
  149. .resume = ata_pci_device_resume,
  150. #endif
  151. };
  152. module_pci_driver(marvell_pci_driver);
  153. MODULE_AUTHOR("Alan Cox");
  154. MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
  155. MODULE_LICENSE("GPL");
  156. MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
  157. MODULE_VERSION(DRV_VERSION);