pata_marvell.c 5.2 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.1"
  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. if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
  52. ap->cbl = ATA_CBL_PATA40;
  53. else
  54. ap->cbl = ATA_CBL_PATA80;
  55. break;
  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. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  84. .emulated = ATA_SHT_EMULATED,
  85. .use_clustering = ATA_SHT_USE_CLUSTERING,
  86. .proc_name = DRV_NAME,
  87. .dma_boundary = ATA_DMA_BOUNDARY,
  88. .slave_configure = ata_scsi_slave_config,
  89. .slave_destroy = ata_scsi_slave_destroy,
  90. /* Use standard CHS mapping rules */
  91. .bios_param = ata_std_bios_param,
  92. #ifdef CONFIG_PM
  93. .resume = ata_scsi_device_resume,
  94. .suspend = ata_scsi_device_suspend,
  95. #endif
  96. };
  97. static const struct ata_port_operations marvell_ops = {
  98. .port_disable = ata_port_disable,
  99. /* Task file is PCI ATA format, use helpers */
  100. .tf_load = ata_tf_load,
  101. .tf_read = ata_tf_read,
  102. .check_status = ata_check_status,
  103. .exec_command = ata_exec_command,
  104. .dev_select = ata_std_dev_select,
  105. .freeze = ata_bmdma_freeze,
  106. .thaw = ata_bmdma_thaw,
  107. .error_handler = marvell_error_handler,
  108. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  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 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 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. struct ata_port_info *port_info[2] = { &info, &info_sata };
  158. int n_port = 2;
  159. if (pdev->device == 0x6101)
  160. n_port = 1;
  161. return ata_pci_init_one(pdev, port_info, n_port);
  162. }
  163. static const struct pci_device_id marvell_pci_tbl[] = {
  164. { PCI_DEVICE(0x11AB, 0x6101), },
  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);