pata_jmicron.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include <linux/blkdev.h>
  13. #include <linux/delay.h>
  14. #include <linux/device.h>
  15. #include <scsi/scsi_host.h>
  16. #include <linux/libata.h>
  17. #include <linux/ata.h>
  18. #define DRV_NAME "pata_jmicron"
  19. #define DRV_VERSION "0.1.5"
  20. typedef enum {
  21. PORT_PATA0 = 0,
  22. PORT_PATA1 = 1,
  23. PORT_SATA = 2,
  24. } port_type;
  25. /**
  26. * jmicron_pre_reset - check for 40/80 pin
  27. * @link: ATA link
  28. * @deadline: deadline jiffies for the operation
  29. *
  30. * Perform the PATA port setup we need.
  31. *
  32. * On the Jmicron 361/363 there is a single PATA port that can be mapped
  33. * either as primary or secondary (or neither). We don't do any policy
  34. * and setup here. We assume that has been done by init_one and the
  35. * BIOS.
  36. */
  37. static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline)
  38. {
  39. struct ata_port *ap = link->ap;
  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. case PORT_PATA0:
  75. if ((control & (1 << 5)) == 0)
  76. return -ENOENT;
  77. if (control & (1 << 3)) /* 40/80 pin primary */
  78. ap->cbl = ATA_CBL_PATA40;
  79. else
  80. ap->cbl = ATA_CBL_PATA80;
  81. break;
  82. case PORT_PATA1:
  83. /* Bit 21 is set if the port is enabled */
  84. if ((control5 & (1 << 21)) == 0)
  85. return -ENOENT;
  86. if (control5 & (1 << 19)) /* 40/80 pin secondary */
  87. ap->cbl = ATA_CBL_PATA40;
  88. else
  89. ap->cbl = ATA_CBL_PATA80;
  90. break;
  91. case PORT_SATA:
  92. ap->cbl = ATA_CBL_SATA;
  93. break;
  94. }
  95. return ata_sff_prereset(link, deadline);
  96. }
  97. /* No PIO or DMA methods needed for this device */
  98. static struct scsi_host_template jmicron_sht = {
  99. ATA_BMDMA_SHT(DRV_NAME),
  100. };
  101. static struct ata_port_operations jmicron_ops = {
  102. .inherits = &ata_bmdma_port_ops,
  103. .prereset = jmicron_pre_reset,
  104. };
  105. /**
  106. * jmicron_init_one - Register Jmicron ATA PCI device with kernel services
  107. * @pdev: PCI device to register
  108. * @ent: Entry in jmicron_pci_tbl matching with @pdev
  109. *
  110. * Called from kernel PCI layer.
  111. *
  112. * LOCKING:
  113. * Inherited from PCI layer (may sleep).
  114. *
  115. * RETURNS:
  116. * Zero on success, or -ERRNO value.
  117. */
  118. static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
  119. {
  120. static const struct ata_port_info info = {
  121. .flags = ATA_FLAG_SLAVE_POSS,
  122. .pio_mask = ATA_PIO4,
  123. .mwdma_mask = ATA_MWDMA2,
  124. .udma_mask = ATA_UDMA5,
  125. .port_ops = &jmicron_ops,
  126. };
  127. const struct ata_port_info *ppi[] = { &info, NULL };
  128. return ata_pci_bmdma_init_one(pdev, ppi, &jmicron_sht, NULL, 0);
  129. }
  130. static const struct pci_device_id jmicron_pci_tbl[] = {
  131. { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  132. PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
  133. { } /* terminate list */
  134. };
  135. static struct pci_driver jmicron_pci_driver = {
  136. .name = DRV_NAME,
  137. .id_table = jmicron_pci_tbl,
  138. .probe = jmicron_init_one,
  139. .remove = ata_pci_remove_one,
  140. #ifdef CONFIG_PM_SLEEP
  141. .suspend = ata_pci_device_suspend,
  142. .resume = ata_pci_device_resume,
  143. #endif
  144. };
  145. module_pci_driver(jmicron_pci_driver);
  146. MODULE_AUTHOR("Alan Cox");
  147. MODULE_DESCRIPTION("SCSI low-level driver for Jmicron PATA ports");
  148. MODULE_LICENSE("GPL");
  149. MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
  150. MODULE_VERSION(DRV_VERSION);