pata_jmicron.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * pata_jmicron.c - JMicron ATA driver for non AHCI mode. This drives the
  3. * PATA port of the controller. The SATA ports are
  4. * driven by AHCI in the usual configuration although
  5. * this driver can handle other setups if we need it.
  6. *
  7. * (c) 2006 Red Hat <alan@redhat.com>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include <linux/init.h>
  13. #include <linux/blkdev.h>
  14. #include <linux/delay.h>
  15. #include <linux/device.h>
  16. #include <scsi/scsi_host.h>
  17. #include <linux/libata.h>
  18. #include <linux/ata.h>
  19. #define DRV_NAME "pata_jmicron"
  20. #define DRV_VERSION "0.1.5"
  21. typedef enum {
  22. PORT_PATA0 = 0,
  23. PORT_PATA1 = 1,
  24. PORT_SATA = 2,
  25. } port_type;
  26. /**
  27. * jmicron_pre_reset - check for 40/80 pin
  28. * @link: ATA link
  29. * @deadline: deadline jiffies for the operation
  30. *
  31. * Perform the PATA port setup we need.
  32. *
  33. * On the Jmicron 361/363 there is a single PATA port that can be mapped
  34. * either as primary or secondary (or neither). We don't do any policy
  35. * and setup here. We assume that has been done by init_one and the
  36. * BIOS.
  37. */
  38. static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline)
  39. {
  40. struct ata_port *ap = link->ap;
  41. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  42. u32 control;
  43. u32 control5;
  44. int port_mask = 1<< (4 * ap->port_no);
  45. int port = ap->port_no;
  46. port_type port_map[2];
  47. /* Check if our port is enabled */
  48. pci_read_config_dword(pdev, 0x40, &control);
  49. if ((control & port_mask) == 0)
  50. return -ENOENT;
  51. /* There are two basic mappings. One has the two SATA ports merged
  52. as master/slave and the secondary as PATA, the other has only the
  53. SATA port mapped */
  54. if (control & (1 << 23)) {
  55. port_map[0] = PORT_SATA;
  56. port_map[1] = PORT_PATA0;
  57. } else {
  58. port_map[0] = PORT_SATA;
  59. port_map[1] = PORT_SATA;
  60. }
  61. /* The 365/366 may have this bit set to map the second PATA port
  62. as the internal primary channel */
  63. pci_read_config_dword(pdev, 0x80, &control5);
  64. if (control5 & (1<<24))
  65. port_map[0] = PORT_PATA1;
  66. /* The two ports may then be logically swapped by the firmware */
  67. if (control & (1 << 22))
  68. port = port ^ 1;
  69. /*
  70. * Now we know which physical port we are talking about we can
  71. * actually do our cable checking etc. Thankfully we don't need
  72. * to do the plumbing for other cases.
  73. */
  74. switch (port_map[port])
  75. {
  76. case PORT_PATA0:
  77. if (control & (1 << 5))
  78. return 0;
  79. if (control & (1 << 3)) /* 40/80 pin primary */
  80. ap->cbl = ATA_CBL_PATA40;
  81. else
  82. ap->cbl = ATA_CBL_PATA80;
  83. break;
  84. case PORT_PATA1:
  85. /* Bit 21 is set if the port is enabled */
  86. if ((control5 & (1 << 21)) == 0)
  87. return 0;
  88. if (control5 & (1 << 19)) /* 40/80 pin secondary */
  89. ap->cbl = ATA_CBL_PATA40;
  90. else
  91. ap->cbl = ATA_CBL_PATA80;
  92. break;
  93. case PORT_SATA:
  94. ap->cbl = ATA_CBL_SATA;
  95. break;
  96. }
  97. return ata_std_prereset(link, deadline);
  98. }
  99. /**
  100. * jmicron_error_handler - Setup and error handler
  101. * @ap: Port to handle
  102. *
  103. * LOCKING:
  104. * None (inherited from caller).
  105. */
  106. static void jmicron_error_handler(struct ata_port *ap)
  107. {
  108. return ata_bmdma_drive_eh(ap, jmicron_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  109. }
  110. /* No PIO or DMA methods needed for this device */
  111. static struct scsi_host_template jmicron_sht = {
  112. .module = THIS_MODULE,
  113. .name = DRV_NAME,
  114. .ioctl = ata_scsi_ioctl,
  115. .queuecommand = ata_scsi_queuecmd,
  116. .can_queue = ATA_DEF_QUEUE,
  117. .this_id = ATA_SHT_THIS_ID,
  118. .sg_tablesize = LIBATA_MAX_PRD,
  119. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  120. .emulated = ATA_SHT_EMULATED,
  121. .use_clustering = ATA_SHT_USE_CLUSTERING,
  122. .proc_name = DRV_NAME,
  123. .dma_boundary = ATA_DMA_BOUNDARY,
  124. .slave_configure = ata_scsi_slave_config,
  125. .slave_destroy = ata_scsi_slave_destroy,
  126. /* Use standard CHS mapping rules */
  127. .bios_param = ata_std_bios_param,
  128. };
  129. static const struct ata_port_operations jmicron_ops = {
  130. /* Task file is PCI ATA format, use helpers */
  131. .tf_load = ata_tf_load,
  132. .tf_read = ata_tf_read,
  133. .check_status = ata_check_status,
  134. .exec_command = ata_exec_command,
  135. .dev_select = ata_std_dev_select,
  136. .freeze = ata_bmdma_freeze,
  137. .thaw = ata_bmdma_thaw,
  138. .error_handler = jmicron_error_handler,
  139. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  140. /* BMDMA handling is PCI ATA format, use helpers */
  141. .bmdma_setup = ata_bmdma_setup,
  142. .bmdma_start = ata_bmdma_start,
  143. .bmdma_stop = ata_bmdma_stop,
  144. .bmdma_status = ata_bmdma_status,
  145. .qc_prep = ata_qc_prep,
  146. .qc_issue = ata_qc_issue_prot,
  147. .data_xfer = ata_data_xfer,
  148. /* IRQ-related hooks */
  149. .irq_handler = ata_interrupt,
  150. .irq_clear = ata_bmdma_irq_clear,
  151. .irq_on = ata_irq_on,
  152. /* Generic PATA PCI ATA helpers */
  153. .port_start = ata_port_start,
  154. };
  155. /**
  156. * jmicron_init_one - Register Jmicron ATA PCI device with kernel services
  157. * @pdev: PCI device to register
  158. * @ent: Entry in jmicron_pci_tbl matching with @pdev
  159. *
  160. * Called from kernel PCI layer.
  161. *
  162. * LOCKING:
  163. * Inherited from PCI layer (may sleep).
  164. *
  165. * RETURNS:
  166. * Zero on success, or -ERRNO value.
  167. */
  168. static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  169. {
  170. static const struct ata_port_info info = {
  171. .sht = &jmicron_sht,
  172. .flags = ATA_FLAG_SLAVE_POSS,
  173. .pio_mask = 0x1f,
  174. .mwdma_mask = 0x07,
  175. .udma_mask = ATA_UDMA5,
  176. .port_ops = &jmicron_ops,
  177. };
  178. const struct ata_port_info *ppi[] = { &info, NULL };
  179. return ata_pci_init_one(pdev, ppi);
  180. }
  181. static const struct pci_device_id jmicron_pci_tbl[] = {
  182. { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  183. PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
  184. { } /* terminate list */
  185. };
  186. static struct pci_driver jmicron_pci_driver = {
  187. .name = DRV_NAME,
  188. .id_table = jmicron_pci_tbl,
  189. .probe = jmicron_init_one,
  190. .remove = ata_pci_remove_one,
  191. #ifdef CONFIG_PM
  192. .suspend = ata_pci_device_suspend,
  193. .resume = ata_pci_device_resume,
  194. #endif
  195. };
  196. static int __init jmicron_init(void)
  197. {
  198. return pci_register_driver(&jmicron_pci_driver);
  199. }
  200. static void __exit jmicron_exit(void)
  201. {
  202. pci_unregister_driver(&jmicron_pci_driver);
  203. }
  204. module_init(jmicron_init);
  205. module_exit(jmicron_exit);
  206. MODULE_AUTHOR("Alan Cox");
  207. MODULE_DESCRIPTION("SCSI low-level driver for Jmicron PATA ports");
  208. MODULE_LICENSE("GPL");
  209. MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
  210. MODULE_VERSION(DRV_VERSION);