pata_marvell.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.0.5u"
  22. /**
  23. * marvell_pre_reset - check for 40/80 pin
  24. * @ap: Port
  25. *
  26. * Perform the PATA port setup we need.
  27. */
  28. static int marvell_pre_reset(struct ata_port *ap)
  29. {
  30. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  31. u32 devices;
  32. void __iomem *barp;
  33. int i;
  34. /* Check if our port is enabled */
  35. barp = pci_iomap(pdev, 5, 0x10);
  36. if (barp == NULL)
  37. return -ENOMEM;
  38. printk("BAR5:");
  39. for(i = 0; i <= 0x0F; i++)
  40. printk("%02X:%02X ", i, readb(barp + i));
  41. printk("\n");
  42. devices = readl(barp + 0x0C);
  43. pci_iounmap(pdev, barp);
  44. if ((pdev->device == 0x6145) && (ap->port_no == 0) &&
  45. (!(devices & 0x10))) /* PATA enable ? */
  46. return -ENOENT;
  47. /* Cable type */
  48. switch(ap->port_no)
  49. {
  50. case 0:
  51. /* Might be backward, docs unclear */
  52. if (inb(ap->ioaddr.bmdma_addr + 1) & 1)
  53. ap->cbl = ATA_CBL_PATA80;
  54. else
  55. ap->cbl = ATA_CBL_PATA40;
  56. case 1: /* Legacy SATA port */
  57. ap->cbl = ATA_CBL_SATA;
  58. break;
  59. }
  60. return ata_std_prereset(ap);
  61. }
  62. /**
  63. * marvell_error_handler - Setup and error handler
  64. * @ap: Port to handle
  65. *
  66. * LOCKING:
  67. * None (inherited from caller).
  68. */
  69. static void marvell_error_handler(struct ata_port *ap)
  70. {
  71. return ata_bmdma_drive_eh(ap, marvell_pre_reset, ata_std_softreset,
  72. NULL, ata_std_postreset);
  73. }
  74. /* No PIO or DMA methods needed for this device */
  75. static struct scsi_host_template marvell_sht = {
  76. .module = THIS_MODULE,
  77. .name = DRV_NAME,
  78. .ioctl = ata_scsi_ioctl,
  79. .queuecommand = ata_scsi_queuecmd,
  80. .can_queue = ATA_DEF_QUEUE,
  81. .this_id = ATA_SHT_THIS_ID,
  82. .sg_tablesize = LIBATA_MAX_PRD,
  83. .max_sectors = ATA_MAX_SECTORS,
  84. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  85. .emulated = ATA_SHT_EMULATED,
  86. .use_clustering = ATA_SHT_USE_CLUSTERING,
  87. .proc_name = DRV_NAME,
  88. .dma_boundary = ATA_DMA_BOUNDARY,
  89. .slave_configure = ata_scsi_slave_config,
  90. /* Use standard CHS mapping rules */
  91. .bios_param = ata_std_bios_param,
  92. };
  93. static const struct ata_port_operations marvell_ops = {
  94. .port_disable = ata_port_disable,
  95. /* Task file is PCI ATA format, use helpers */
  96. .tf_load = ata_tf_load,
  97. .tf_read = ata_tf_read,
  98. .check_status = ata_check_status,
  99. .exec_command = ata_exec_command,
  100. .dev_select = ata_std_dev_select,
  101. .freeze = ata_bmdma_freeze,
  102. .thaw = ata_bmdma_thaw,
  103. .error_handler = marvell_error_handler,
  104. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  105. /* BMDMA handling is PCI ATA format, use helpers */
  106. .bmdma_setup = ata_bmdma_setup,
  107. .bmdma_start = ata_bmdma_start,
  108. .bmdma_stop = ata_bmdma_stop,
  109. .bmdma_status = ata_bmdma_status,
  110. .qc_prep = ata_qc_prep,
  111. .qc_issue = ata_qc_issue_prot,
  112. .data_xfer = ata_pio_data_xfer,
  113. /* Timeout handling */
  114. .irq_handler = ata_interrupt,
  115. .irq_clear = ata_bmdma_irq_clear,
  116. /* Generic PATA PCI ATA helpers */
  117. .port_start = ata_port_start,
  118. .port_stop = ata_port_stop,
  119. .host_stop = ata_host_stop,
  120. };
  121. /**
  122. * marvell_init_one - Register Marvell ATA PCI device with kernel services
  123. * @pdev: PCI device to register
  124. * @ent: Entry in marvell_pci_tbl matching with @pdev
  125. *
  126. * Called from kernel PCI layer.
  127. *
  128. * LOCKING:
  129. * Inherited from PCI layer (may sleep).
  130. *
  131. * RETURNS:
  132. * Zero on success, or -ERRNO value.
  133. */
  134. static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  135. {
  136. static struct ata_port_info info = {
  137. .sht = &marvell_sht,
  138. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  139. .pio_mask = 0x1f,
  140. .mwdma_mask = 0x07,
  141. .udma_mask = 0x3f,
  142. .port_ops = &marvell_ops,
  143. };
  144. static struct ata_port_info info_sata = {
  145. .sht = &marvell_sht,
  146. /* Slave possible as its magically mapped not real */
  147. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  148. .pio_mask = 0x1f,
  149. .mwdma_mask = 0x07,
  150. .udma_mask = 0x7f,
  151. .port_ops = &marvell_ops,
  152. };
  153. struct ata_port_info *port_info[2] = { &info, &info_sata };
  154. int n_port = 2;
  155. if (pdev->device == 0x6101)
  156. n_port = 1;
  157. return ata_pci_init_one(pdev, port_info, n_port);
  158. }
  159. static const struct pci_device_id marvell_pci_tbl[] = {
  160. { PCI_DEVICE(0x11AB, 0x6101), },
  161. { PCI_DEVICE(0x11AB, 0x6145), },
  162. { } /* terminate list */
  163. };
  164. static struct pci_driver marvell_pci_driver = {
  165. .name = DRV_NAME,
  166. .id_table = marvell_pci_tbl,
  167. .probe = marvell_init_one,
  168. .remove = ata_pci_remove_one,
  169. };
  170. static int __init marvell_init(void)
  171. {
  172. return pci_register_driver(&marvell_pci_driver);
  173. }
  174. static void __exit marvell_exit(void)
  175. {
  176. pci_unregister_driver(&marvell_pci_driver);
  177. }
  178. module_init(marvell_init);
  179. module_exit(marvell_exit);
  180. MODULE_AUTHOR("Alan Cox");
  181. MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
  182. MODULE_LICENSE("GPL");
  183. MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
  184. MODULE_VERSION(DRV_VERSION);