pata_jmicron.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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.4"
  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. * @ap: Port
  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_port *ap, unsigned long deadline)
  39. {
  40. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  41. u32 control;
  42. u32 control5;
  43. int port_mask = 1<< (4 * ap->port_no);
  44. int port = ap->port_no;
  45. port_type port_map[2];
  46. /* Check if our port is enabled */
  47. pci_read_config_dword(pdev, 0x40, &control);
  48. if ((control & port_mask) == 0)
  49. return -ENOENT;
  50. /* There are two basic mappings. One has the two SATA ports merged
  51. as master/slave and the secondary as PATA, the other has only the
  52. SATA port mapped */
  53. if (control & (1 << 23)) {
  54. port_map[0] = PORT_SATA;
  55. port_map[1] = PORT_PATA0;
  56. } else {
  57. port_map[0] = PORT_SATA;
  58. port_map[1] = PORT_SATA;
  59. }
  60. /* The 365/366 may have this bit set to map the second PATA port
  61. as the internal primary channel */
  62. pci_read_config_dword(pdev, 0x80, &control5);
  63. if (control5 & (1<<24))
  64. port_map[0] = PORT_PATA1;
  65. /* The two ports may then be logically swapped by the firmware */
  66. if (control & (1 << 22))
  67. port = port ^ 1;
  68. /*
  69. * Now we know which physical port we are talking about we can
  70. * actually do our cable checking etc. Thankfully we don't need
  71. * to do the plumbing for other cases.
  72. */
  73. switch (port_map[port])
  74. {
  75. case PORT_PATA0:
  76. if (control & (1 << 5))
  77. return 0;
  78. if (control & (1 << 3)) /* 40/80 pin primary */
  79. ap->cbl = ATA_CBL_PATA40;
  80. else
  81. ap->cbl = ATA_CBL_PATA80;
  82. break;
  83. case PORT_PATA1:
  84. /* Bit 21 is set if the port is enabled */
  85. if ((control5 & (1 << 21)) == 0)
  86. return 0;
  87. if (control5 & (1 << 19)) /* 40/80 pin secondary */
  88. ap->cbl = ATA_CBL_PATA40;
  89. else
  90. ap->cbl = ATA_CBL_PATA80;
  91. break;
  92. case PORT_SATA:
  93. ap->cbl = ATA_CBL_SATA;
  94. break;
  95. }
  96. return ata_std_prereset(ap, deadline);
  97. }
  98. /**
  99. * jmicron_error_handler - Setup and error handler
  100. * @ap: Port to handle
  101. *
  102. * LOCKING:
  103. * None (inherited from caller).
  104. */
  105. static void jmicron_error_handler(struct ata_port *ap)
  106. {
  107. return ata_bmdma_drive_eh(ap, jmicron_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  108. }
  109. /* No PIO or DMA methods needed for this device */
  110. static struct scsi_host_template jmicron_sht = {
  111. .module = THIS_MODULE,
  112. .name = DRV_NAME,
  113. .ioctl = ata_scsi_ioctl,
  114. .queuecommand = ata_scsi_queuecmd,
  115. .can_queue = ATA_DEF_QUEUE,
  116. .this_id = ATA_SHT_THIS_ID,
  117. .sg_tablesize = LIBATA_MAX_PRD,
  118. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  119. .emulated = ATA_SHT_EMULATED,
  120. .use_clustering = ATA_SHT_USE_CLUSTERING,
  121. .proc_name = DRV_NAME,
  122. .dma_boundary = ATA_DMA_BOUNDARY,
  123. .slave_configure = ata_scsi_slave_config,
  124. .slave_destroy = ata_scsi_slave_destroy,
  125. /* Use standard CHS mapping rules */
  126. .bios_param = ata_std_bios_param,
  127. };
  128. static const struct ata_port_operations jmicron_ops = {
  129. .port_disable = ata_port_disable,
  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. .irq_ack = ata_irq_ack,
  153. /* Generic PATA PCI ATA helpers */
  154. .port_start = ata_port_start,
  155. };
  156. /**
  157. * jmicron_init_one - Register Jmicron ATA PCI device with kernel services
  158. * @pdev: PCI device to register
  159. * @ent: Entry in jmicron_pci_tbl matching with @pdev
  160. *
  161. * Called from kernel PCI layer.
  162. *
  163. * LOCKING:
  164. * Inherited from PCI layer (may sleep).
  165. *
  166. * RETURNS:
  167. * Zero on success, or -ERRNO value.
  168. */
  169. static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  170. {
  171. static const struct ata_port_info info = {
  172. .sht = &jmicron_sht,
  173. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  174. .pio_mask = 0x1f,
  175. .mwdma_mask = 0x07,
  176. .udma_mask = 0x3f,
  177. .port_ops = &jmicron_ops,
  178. };
  179. const struct ata_port_info *ppi[] = { &info, NULL };
  180. return ata_pci_init_one(pdev, ppi);
  181. }
  182. static const struct pci_device_id jmicron_pci_tbl[] = {
  183. { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361,
  184. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 361 },
  185. { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363,
  186. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 363 },
  187. { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365,
  188. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 365 },
  189. { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366,
  190. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 366 },
  191. { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368,
  192. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 368 },
  193. { } /* terminate list */
  194. };
  195. static struct pci_driver jmicron_pci_driver = {
  196. .name = DRV_NAME,
  197. .id_table = jmicron_pci_tbl,
  198. .probe = jmicron_init_one,
  199. .remove = ata_pci_remove_one,
  200. #ifdef CONFIG_PM
  201. .suspend = ata_pci_device_suspend,
  202. .resume = ata_pci_device_resume,
  203. #endif
  204. };
  205. static int __init jmicron_init(void)
  206. {
  207. return pci_register_driver(&jmicron_pci_driver);
  208. }
  209. static void __exit jmicron_exit(void)
  210. {
  211. pci_unregister_driver(&jmicron_pci_driver);
  212. }
  213. module_init(jmicron_init);
  214. module_exit(jmicron_exit);
  215. MODULE_AUTHOR("Alan Cox");
  216. MODULE_DESCRIPTION("SCSI low-level driver for Jmicron PATA ports");
  217. MODULE_LICENSE("GPL");
  218. MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
  219. MODULE_VERSION(DRV_VERSION);