pata_marvell.c 5.3 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. * @ap: Port
  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_port *ap, unsigned long deadline)
  30. {
  31. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  32. u32 devices;
  33. void __iomem *barp;
  34. int i;
  35. /* Check if our port is enabled */
  36. barp = pci_iomap(pdev, 5, 0x10);
  37. if (barp == NULL)
  38. return -ENOMEM;
  39. printk("BAR5:");
  40. for(i = 0; i <= 0x0F; i++)
  41. printk("%02X:%02X ", i, readb(barp + i));
  42. printk("\n");
  43. devices = readl(barp + 0x0C);
  44. pci_iounmap(pdev, barp);
  45. if ((pdev->device == 0x6145) && (ap->port_no == 0) &&
  46. (!(devices & 0x10))) /* PATA enable ? */
  47. return -ENOENT;
  48. return ata_std_prereset(ap, deadline);
  49. }
  50. static int marvell_cable_detect(struct ata_port *ap)
  51. {
  52. /* Cable type */
  53. switch(ap->port_no)
  54. {
  55. case 0:
  56. if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
  57. return ATA_CBL_PATA40;
  58. return ATA_CBL_PATA80;
  59. case 1: /* Legacy SATA port */
  60. return ATA_CBL_SATA;
  61. }
  62. BUG();
  63. return 0; /* Our BUG macro needs the right markup */
  64. }
  65. /**
  66. * marvell_error_handler - Setup and error handler
  67. * @ap: Port to handle
  68. *
  69. * LOCKING:
  70. * None (inherited from caller).
  71. */
  72. static void marvell_error_handler(struct ata_port *ap)
  73. {
  74. return ata_bmdma_drive_eh(ap, marvell_pre_reset, ata_std_softreset,
  75. NULL, ata_std_postreset);
  76. }
  77. /* No PIO or DMA methods needed for this device */
  78. static struct scsi_host_template marvell_sht = {
  79. .module = THIS_MODULE,
  80. .name = DRV_NAME,
  81. .ioctl = ata_scsi_ioctl,
  82. .queuecommand = ata_scsi_queuecmd,
  83. .can_queue = ATA_DEF_QUEUE,
  84. .this_id = ATA_SHT_THIS_ID,
  85. .sg_tablesize = LIBATA_MAX_PRD,
  86. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  87. .emulated = ATA_SHT_EMULATED,
  88. .use_clustering = ATA_SHT_USE_CLUSTERING,
  89. .proc_name = DRV_NAME,
  90. .dma_boundary = ATA_DMA_BOUNDARY,
  91. .slave_configure = ata_scsi_slave_config,
  92. .slave_destroy = ata_scsi_slave_destroy,
  93. /* Use standard CHS mapping rules */
  94. .bios_param = ata_std_bios_param,
  95. };
  96. static const struct ata_port_operations marvell_ops = {
  97. .port_disable = ata_port_disable,
  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. .irq_ack = ata_irq_ack,
  122. /* Generic PATA PCI ATA helpers */
  123. .port_start = ata_port_start,
  124. };
  125. /**
  126. * marvell_init_one - Register Marvell ATA PCI device with kernel services
  127. * @pdev: PCI device to register
  128. * @ent: Entry in marvell_pci_tbl matching with @pdev
  129. *
  130. * Called from kernel PCI layer.
  131. *
  132. * LOCKING:
  133. * Inherited from PCI layer (may sleep).
  134. *
  135. * RETURNS:
  136. * Zero on success, or -ERRNO value.
  137. */
  138. static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  139. {
  140. static const struct ata_port_info info = {
  141. .sht = &marvell_sht,
  142. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  143. .pio_mask = 0x1f,
  144. .mwdma_mask = 0x07,
  145. .udma_mask = 0x3f,
  146. .port_ops = &marvell_ops,
  147. };
  148. static const struct ata_port_info info_sata = {
  149. .sht = &marvell_sht,
  150. /* Slave possible as its magically mapped not real */
  151. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  152. .pio_mask = 0x1f,
  153. .mwdma_mask = 0x07,
  154. .udma_mask = 0x7f,
  155. .port_ops = &marvell_ops,
  156. };
  157. const struct ata_port_info *ppi[] = { &info, &info_sata };
  158. if (pdev->device == 0x6101)
  159. ppi[1] = &ata_dummy_port_info;
  160. return ata_pci_init_one(pdev, ppi);
  161. }
  162. static const struct pci_device_id marvell_pci_tbl[] = {
  163. { PCI_DEVICE(0x11AB, 0x6101), },
  164. { PCI_DEVICE(0x11AB, 0x6145), },
  165. { } /* terminate list */
  166. };
  167. static struct pci_driver marvell_pci_driver = {
  168. .name = DRV_NAME,
  169. .id_table = marvell_pci_tbl,
  170. .probe = marvell_init_one,
  171. .remove = ata_pci_remove_one,
  172. #ifdef CONFIG_PM
  173. .suspend = ata_pci_device_suspend,
  174. .resume = ata_pci_device_resume,
  175. #endif
  176. };
  177. static int __init marvell_init(void)
  178. {
  179. return pci_register_driver(&marvell_pci_driver);
  180. }
  181. static void __exit marvell_exit(void)
  182. {
  183. pci_unregister_driver(&marvell_pci_driver);
  184. }
  185. module_init(marvell_init);
  186. module_exit(marvell_exit);
  187. MODULE_AUTHOR("Alan Cox");
  188. MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
  189. MODULE_LICENSE("GPL");
  190. MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
  191. MODULE_VERSION(DRV_VERSION);