pata_triflex.c 6.4 KB

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