pata_triflex.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * pata_triflex.c - Compaq PATA for new ATA layer
  4. * (C) 2005 Red Hat Inc
  5. * Alan Cox <[email protected]>
  6. *
  7. * based upon
  8. *
  9. * triflex.c
  10. *
  11. * IDE Chipset driver for the Compaq TriFlex IDE controller.
  12. *
  13. * Known to work with the Compaq Workstation 5x00 series.
  14. *
  15. * Copyright (C) 2002 Hewlett-Packard Development Group, L.P.
  16. * Author: Torben Mathiasen <[email protected]>
  17. *
  18. * Loosely based on the piix & svwks drivers.
  19. *
  20. * Documentation:
  21. * Not publicly available.
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/pci.h>
  26. #include <linux/blkdev.h>
  27. #include <linux/delay.h>
  28. #include <scsi/scsi_host.h>
  29. #include <linux/libata.h>
  30. #define DRV_NAME "pata_triflex"
  31. #define DRV_VERSION "0.2.8"
  32. /**
  33. * triflex_prereset - probe begin
  34. * @link: ATA link
  35. * @deadline: deadline jiffies for the operation
  36. *
  37. * Set up cable type and use generic probe init
  38. */
  39. static int triflex_prereset(struct ata_link *link, unsigned long deadline)
  40. {
  41. static const struct pci_bits triflex_enable_bits[] = {
  42. { 0x80, 1, 0x01, 0x01 },
  43. { 0x80, 1, 0x02, 0x02 }
  44. };
  45. struct ata_port *ap = link->ap;
  46. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  47. if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
  48. return -ENOENT;
  49. return ata_sff_prereset(link, deadline);
  50. }
  51. /**
  52. * triflex_load_timing - timing configuration
  53. * @ap: ATA interface
  54. * @adev: Device on the bus
  55. * @speed: speed to configure
  56. *
  57. * The Triflex has one set of timings per device per channel. This
  58. * means we must do some switching. As the PIO and DMA timings don't
  59. * match we have to do some reloading unlike PIIX devices where tuning
  60. * tricks can avoid it.
  61. */
  62. static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
  63. {
  64. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  65. u32 timing = 0;
  66. u32 triflex_timing, old_triflex_timing;
  67. int channel_offset = ap->port_no ? 0x74: 0x70;
  68. unsigned int is_slave = (adev->devno != 0);
  69. pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
  70. triflex_timing = old_triflex_timing;
  71. switch(speed)
  72. {
  73. case XFER_MW_DMA_2:
  74. timing = 0x0103;break;
  75. case XFER_MW_DMA_1:
  76. timing = 0x0203;break;
  77. case XFER_MW_DMA_0:
  78. timing = 0x0808;break;
  79. case XFER_SW_DMA_2:
  80. case XFER_SW_DMA_1:
  81. case XFER_SW_DMA_0:
  82. timing = 0x0F0F;break;
  83. case XFER_PIO_4:
  84. timing = 0x0202;break;
  85. case XFER_PIO_3:
  86. timing = 0x0204;break;
  87. case XFER_PIO_2:
  88. timing = 0x0404;break;
  89. case XFER_PIO_1:
  90. timing = 0x0508;break;
  91. case XFER_PIO_0:
  92. timing = 0x0808;break;
  93. default:
  94. BUG();
  95. }
  96. triflex_timing &= ~ (0xFFFF << (16 * is_slave));
  97. triflex_timing |= (timing << (16 * is_slave));
  98. if (triflex_timing != old_triflex_timing)
  99. pci_write_config_dword(pdev, channel_offset, triflex_timing);
  100. }
  101. /**
  102. * triflex_set_piomode - set initial PIO mode data
  103. * @ap: ATA interface
  104. * @adev: ATA device
  105. *
  106. * Use the timing loader to set up the PIO mode. We have to do this
  107. * because DMA start/stop will only be called once DMA occurs. If there
  108. * has been no DMA then the PIO timings are still needed.
  109. */
  110. static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
  111. {
  112. triflex_load_timing(ap, adev, adev->pio_mode);
  113. }
  114. /**
  115. * triflex_bmdma_start - DMA start callback
  116. * @qc: Command in progress
  117. *
  118. * Usually drivers set the DMA timing at the point the set_dmamode call
  119. * is made. Triflex however requires we load new timings on the
  120. * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
  121. * We load the DMA timings just before starting DMA and then restore
  122. * the PIO timing when the DMA is finished.
  123. */
  124. static void triflex_bmdma_start(struct ata_queued_cmd *qc)
  125. {
  126. triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
  127. ata_bmdma_start(qc);
  128. }
  129. /**
  130. * triflex_bmdma_stop - DMA stop callback
  131. * @qc: ATA command
  132. *
  133. * We loaded new timings in dma_start, as a result we need to restore
  134. * the PIO timings in dma_stop so that the next command issue gets the
  135. * right clock values.
  136. */
  137. static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
  138. {
  139. ata_bmdma_stop(qc);
  140. triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
  141. }
  142. static struct scsi_host_template triflex_sht = {
  143. ATA_BMDMA_SHT(DRV_NAME),
  144. };
  145. static struct ata_port_operations triflex_port_ops = {
  146. .inherits = &ata_bmdma_port_ops,
  147. .bmdma_start = triflex_bmdma_start,
  148. .bmdma_stop = triflex_bmdma_stop,
  149. .cable_detect = ata_cable_40wire,
  150. .set_piomode = triflex_set_piomode,
  151. .prereset = triflex_prereset,
  152. };
  153. static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  154. {
  155. static const struct ata_port_info info = {
  156. .flags = ATA_FLAG_SLAVE_POSS,
  157. .pio_mask = ATA_PIO4,
  158. .mwdma_mask = ATA_MWDMA2,
  159. .port_ops = &triflex_port_ops
  160. };
  161. const struct ata_port_info *ppi[] = { &info, NULL };
  162. ata_print_version_once(&dev->dev, DRV_VERSION);
  163. return ata_pci_bmdma_init_one(dev, ppi, &triflex_sht, NULL, 0);
  164. }
  165. static const struct pci_device_id triflex[] = {
  166. { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), },
  167. { },
  168. };
  169. #ifdef CONFIG_PM_SLEEP
  170. static int triflex_ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
  171. {
  172. struct ata_host *host = pci_get_drvdata(pdev);
  173. ata_host_suspend(host, mesg);
  174. /*
  175. * We must not disable or powerdown the device.
  176. * APM bios refuses to suspend if IDE is not accessible.
  177. */
  178. pci_save_state(pdev);
  179. return 0;
  180. }
  181. #endif
  182. static struct pci_driver triflex_pci_driver = {
  183. .name = DRV_NAME,
  184. .id_table = triflex,
  185. .probe = triflex_init_one,
  186. .remove = ata_pci_remove_one,
  187. #ifdef CONFIG_PM_SLEEP
  188. .suspend = triflex_ata_pci_device_suspend,
  189. .resume = ata_pci_device_resume,
  190. #endif
  191. };
  192. module_pci_driver(triflex_pci_driver);
  193. MODULE_AUTHOR("Alan Cox");
  194. MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
  195. MODULE_LICENSE("GPL");
  196. MODULE_DEVICE_TABLE(pci, triflex);
  197. MODULE_VERSION(DRV_VERSION);