pata_marvell.c 5.4 KB

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