pata_marvell.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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_std_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. /**
  67. * marvell_error_handler - Setup and error handler
  68. * @ap: Port to handle
  69. *
  70. * LOCKING:
  71. * None (inherited from caller).
  72. */
  73. static void marvell_error_handler(struct ata_port *ap)
  74. {
  75. return ata_bmdma_drive_eh(ap, marvell_pre_reset, ata_std_softreset,
  76. NULL, ata_std_postreset);
  77. }
  78. /* No PIO or DMA methods needed for this device */
  79. static struct scsi_host_template marvell_sht = {
  80. .module = THIS_MODULE,
  81. .name = DRV_NAME,
  82. .ioctl = ata_scsi_ioctl,
  83. .queuecommand = ata_scsi_queuecmd,
  84. .can_queue = ATA_DEF_QUEUE,
  85. .this_id = ATA_SHT_THIS_ID,
  86. .sg_tablesize = LIBATA_MAX_PRD,
  87. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  88. .emulated = ATA_SHT_EMULATED,
  89. .use_clustering = ATA_SHT_USE_CLUSTERING,
  90. .proc_name = DRV_NAME,
  91. .dma_boundary = ATA_DMA_BOUNDARY,
  92. .slave_configure = ata_scsi_slave_config,
  93. .slave_destroy = ata_scsi_slave_destroy,
  94. /* Use standard CHS mapping rules */
  95. .bios_param = ata_std_bios_param,
  96. };
  97. static const struct ata_port_operations marvell_ops = {
  98. /* Task file is PCI ATA format, use helpers */
  99. .tf_load = ata_tf_load,
  100. .tf_read = ata_tf_read,
  101. .check_status = ata_check_status,
  102. .exec_command = ata_exec_command,
  103. .dev_select = ata_std_dev_select,
  104. .freeze = ata_bmdma_freeze,
  105. .thaw = ata_bmdma_thaw,
  106. .error_handler = marvell_error_handler,
  107. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  108. .cable_detect = marvell_cable_detect,
  109. /* BMDMA handling is PCI ATA format, use helpers */
  110. .bmdma_setup = ata_bmdma_setup,
  111. .bmdma_start = ata_bmdma_start,
  112. .bmdma_stop = ata_bmdma_stop,
  113. .bmdma_status = ata_bmdma_status,
  114. .qc_prep = ata_qc_prep,
  115. .qc_issue = ata_qc_issue_prot,
  116. .data_xfer = ata_data_xfer,
  117. /* Timeout handling */
  118. .irq_handler = ata_interrupt,
  119. .irq_clear = ata_bmdma_irq_clear,
  120. .irq_on = ata_irq_on,
  121. /* Generic PATA PCI ATA helpers */
  122. .port_start = ata_sff_port_start,
  123. };
  124. /**
  125. * marvell_init_one - Register Marvell ATA PCI device with kernel services
  126. * @pdev: PCI device to register
  127. * @ent: Entry in marvell_pci_tbl matching with @pdev
  128. *
  129. * Called from kernel PCI layer.
  130. *
  131. * LOCKING:
  132. * Inherited from PCI layer (may sleep).
  133. *
  134. * RETURNS:
  135. * Zero on success, or -ERRNO value.
  136. */
  137. static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  138. {
  139. static const struct ata_port_info info = {
  140. .sht = &marvell_sht,
  141. .flags = ATA_FLAG_SLAVE_POSS,
  142. .pio_mask = 0x1f,
  143. .mwdma_mask = 0x07,
  144. .udma_mask = ATA_UDMA5,
  145. .port_ops = &marvell_ops,
  146. };
  147. static const struct ata_port_info info_sata = {
  148. .sht = &marvell_sht,
  149. /* Slave possible as its magically mapped not real */
  150. .flags = ATA_FLAG_SLAVE_POSS,
  151. .pio_mask = 0x1f,
  152. .mwdma_mask = 0x07,
  153. .udma_mask = ATA_UDMA6,
  154. .port_ops = &marvell_ops,
  155. };
  156. const struct ata_port_info *ppi[] = { &info, &info_sata };
  157. if (pdev->device == 0x6101)
  158. ppi[1] = &ata_dummy_port_info;
  159. return ata_pci_init_one(pdev, ppi);
  160. }
  161. static const struct pci_device_id marvell_pci_tbl[] = {
  162. { PCI_DEVICE(0x11AB, 0x6101), },
  163. { PCI_DEVICE(0x11AB, 0x6121), },
  164. { PCI_DEVICE(0x11AB, 0x6123), },
  165. { PCI_DEVICE(0x11AB, 0x6145), },
  166. { } /* terminate list */
  167. };
  168. static struct pci_driver marvell_pci_driver = {
  169. .name = DRV_NAME,
  170. .id_table = marvell_pci_tbl,
  171. .probe = marvell_init_one,
  172. .remove = ata_pci_remove_one,
  173. #ifdef CONFIG_PM
  174. .suspend = ata_pci_device_suspend,
  175. .resume = ata_pci_device_resume,
  176. #endif
  177. };
  178. static int __init marvell_init(void)
  179. {
  180. return pci_register_driver(&marvell_pci_driver);
  181. }
  182. static void __exit marvell_exit(void)
  183. {
  184. pci_unregister_driver(&marvell_pci_driver);
  185. }
  186. module_init(marvell_init);
  187. module_exit(marvell_exit);
  188. MODULE_AUTHOR("Alan Cox");
  189. MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
  190. MODULE_LICENSE("GPL");
  191. MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
  192. MODULE_VERSION(DRV_VERSION);