pata_marvell.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 <alan@redhat.com>
  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.4"
  22. /**
  23. * marvell_pre_reset - check for 40/80 pin
  24. * @link: link
  25. * @deadline: deadline jiffies for the operation
  26. *
  27. * Perform the PATA port setup we need.
  28. */
  29. static int marvell_pre_reset(struct ata_link *link, unsigned long deadline)
  30. {
  31. struct ata_port *ap = link->ap;
  32. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  33. u32 devices;
  34. void __iomem *barp;
  35. int i;
  36. /* Check if our port is enabled */
  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 ((pdev->device == 0x6145) && (ap->port_no == 0) &&
  47. (!(devices & 0x10))) /* PATA enable ? */
  48. return -ENOENT;
  49. return ata_sff_prereset(link, deadline);
  50. }
  51. static int marvell_cable_detect(struct ata_port *ap)
  52. {
  53. /* Cable type */
  54. switch(ap->port_no)
  55. {
  56. case 0:
  57. if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
  58. return ATA_CBL_PATA40;
  59. return ATA_CBL_PATA80;
  60. case 1: /* Legacy SATA port */
  61. return ATA_CBL_SATA;
  62. }
  63. BUG();
  64. return 0; /* Our BUG macro needs the right markup */
  65. }
  66. /* No PIO or DMA methods needed for this device */
  67. static struct scsi_host_template marvell_sht = {
  68. ATA_BMDMA_SHT(DRV_NAME),
  69. };
  70. static struct ata_port_operations marvell_ops = {
  71. .inherits = &ata_bmdma_port_ops,
  72. .cable_detect = marvell_cable_detect,
  73. .prereset = marvell_pre_reset,
  74. };
  75. /**
  76. * marvell_init_one - Register Marvell ATA PCI device with kernel services
  77. * @pdev: PCI device to register
  78. * @ent: Entry in marvell_pci_tbl matching with @pdev
  79. *
  80. * Called from kernel PCI layer.
  81. *
  82. * LOCKING:
  83. * Inherited from PCI layer (may sleep).
  84. *
  85. * RETURNS:
  86. * Zero on success, or -ERRNO value.
  87. */
  88. static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  89. {
  90. static const struct ata_port_info info = {
  91. .flags = ATA_FLAG_SLAVE_POSS,
  92. .pio_mask = 0x1f,
  93. .mwdma_mask = 0x07,
  94. .udma_mask = ATA_UDMA5,
  95. .port_ops = &marvell_ops,
  96. };
  97. static const struct ata_port_info info_sata = {
  98. /* Slave possible as its magically mapped not real */
  99. .flags = ATA_FLAG_SLAVE_POSS,
  100. .pio_mask = 0x1f,
  101. .mwdma_mask = 0x07,
  102. .udma_mask = ATA_UDMA6,
  103. .port_ops = &marvell_ops,
  104. };
  105. const struct ata_port_info *ppi[] = { &info, &info_sata };
  106. if (pdev->device == 0x6101)
  107. ppi[1] = &ata_dummy_port_info;
  108. return ata_pci_sff_init_one(pdev, ppi, &marvell_sht, NULL);
  109. }
  110. static const struct pci_device_id marvell_pci_tbl[] = {
  111. { PCI_DEVICE(0x11AB, 0x6101), },
  112. { PCI_DEVICE(0x11AB, 0x6121), },
  113. { PCI_DEVICE(0x11AB, 0x6123), },
  114. { PCI_DEVICE(0x11AB, 0x6145), },
  115. { } /* terminate list */
  116. };
  117. static struct pci_driver marvell_pci_driver = {
  118. .name = DRV_NAME,
  119. .id_table = marvell_pci_tbl,
  120. .probe = marvell_init_one,
  121. .remove = ata_pci_remove_one,
  122. #ifdef CONFIG_PM
  123. .suspend = ata_pci_device_suspend,
  124. .resume = ata_pci_device_resume,
  125. #endif
  126. };
  127. static int __init marvell_init(void)
  128. {
  129. return pci_register_driver(&marvell_pci_driver);
  130. }
  131. static void __exit marvell_exit(void)
  132. {
  133. pci_unregister_driver(&marvell_pci_driver);
  134. }
  135. module_init(marvell_init);
  136. module_exit(marvell_exit);
  137. MODULE_AUTHOR("Alan Cox");
  138. MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
  139. MODULE_LICENSE("GPL");
  140. MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
  141. MODULE_VERSION(DRV_VERSION);