pata_triflex.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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.5"
  45. /**
  46. * triflex_prereset - probe begin
  47. * @ap: ATA port
  48. *
  49. * Set up cable type and use generic probe init
  50. */
  51. static int triflex_prereset(struct ata_port *ap)
  52. {
  53. static const struct pci_bits triflex_enable_bits[] = {
  54. { 0x80, 1, 0x01, 0x01 },
  55. { 0x80, 1, 0x02, 0x02 }
  56. };
  57. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  58. if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
  59. return -ENOENT;
  60. ap->cbl = ATA_CBL_PATA40;
  61. return ata_std_prereset(ap);
  62. }
  63. static void triflex_error_handler(struct ata_port *ap)
  64. {
  65. ata_bmdma_drive_eh(ap, triflex_prereset, ata_std_softreset, NULL, ata_std_postreset);
  66. }
  67. /**
  68. * triflex_load_timing - timing configuration
  69. * @ap: ATA interface
  70. * @adev: Device on the bus
  71. * @speed: speed to configure
  72. *
  73. * The Triflex has one set of timings per device per channel. This
  74. * means we must do some switching. As the PIO and DMA timings don't
  75. * match we have to do some reloading unlike PIIX devices where tuning
  76. * tricks can avoid it.
  77. */
  78. static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
  79. {
  80. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  81. u32 timing = 0;
  82. u32 triflex_timing, old_triflex_timing;
  83. int channel_offset = ap->port_no ? 0x74: 0x70;
  84. unsigned int is_slave = (adev->devno != 0);
  85. pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
  86. triflex_timing = old_triflex_timing;
  87. switch(speed)
  88. {
  89. case XFER_MW_DMA_2:
  90. timing = 0x0103;break;
  91. case XFER_MW_DMA_1:
  92. timing = 0x0203;break;
  93. case XFER_MW_DMA_0:
  94. timing = 0x0808;break;
  95. case XFER_SW_DMA_2:
  96. case XFER_SW_DMA_1:
  97. case XFER_SW_DMA_0:
  98. timing = 0x0F0F;break;
  99. case XFER_PIO_4:
  100. timing = 0x0202;break;
  101. case XFER_PIO_3:
  102. timing = 0x0204;break;
  103. case XFER_PIO_2:
  104. timing = 0x0404;break;
  105. case XFER_PIO_1:
  106. timing = 0x0508;break;
  107. case XFER_PIO_0:
  108. timing = 0x0808;break;
  109. default:
  110. BUG();
  111. }
  112. triflex_timing &= ~ (0xFFFF << (16 * is_slave));
  113. triflex_timing |= (timing << (16 * is_slave));
  114. if (triflex_timing != old_triflex_timing)
  115. pci_write_config_dword(pdev, channel_offset, triflex_timing);
  116. }
  117. /**
  118. * triflex_set_piomode - set initial PIO mode data
  119. * @ap: ATA interface
  120. * @adev: ATA device
  121. *
  122. * Use the timing loader to set up the PIO mode. We have to do this
  123. * because DMA start/stop will only be called once DMA occurs. If there
  124. * has been no DMA then the PIO timings are still needed.
  125. */
  126. static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
  127. {
  128. triflex_load_timing(ap, adev, adev->pio_mode);
  129. }
  130. /**
  131. * triflex_dma_start - DMA start callback
  132. * @qc: Command in progress
  133. *
  134. * Usually drivers set the DMA timing at the point the set_dmamode call
  135. * is made. Triflex however requires we load new timings on the
  136. * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
  137. * We load the DMA timings just before starting DMA and then restore
  138. * the PIO timing when the DMA is finished.
  139. */
  140. static void triflex_bmdma_start(struct ata_queued_cmd *qc)
  141. {
  142. triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
  143. ata_bmdma_start(qc);
  144. }
  145. /**
  146. * triflex_dma_stop - DMA stop callback
  147. * @ap: ATA interface
  148. * @adev: ATA device
  149. *
  150. * We loaded new timings in dma_start, as a result we need to restore
  151. * the PIO timings in dma_stop so that the next command issue gets the
  152. * right clock values.
  153. */
  154. static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
  155. {
  156. ata_bmdma_stop(qc);
  157. triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
  158. }
  159. static struct scsi_host_template triflex_sht = {
  160. .module = THIS_MODULE,
  161. .name = DRV_NAME,
  162. .ioctl = ata_scsi_ioctl,
  163. .queuecommand = ata_scsi_queuecmd,
  164. .can_queue = ATA_DEF_QUEUE,
  165. .this_id = ATA_SHT_THIS_ID,
  166. .sg_tablesize = LIBATA_MAX_PRD,
  167. .max_sectors = ATA_MAX_SECTORS,
  168. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  169. .emulated = ATA_SHT_EMULATED,
  170. .use_clustering = ATA_SHT_USE_CLUSTERING,
  171. .proc_name = DRV_NAME,
  172. .dma_boundary = ATA_DMA_BOUNDARY,
  173. .slave_configure = ata_scsi_slave_config,
  174. .bios_param = ata_std_bios_param,
  175. };
  176. static struct ata_port_operations triflex_port_ops = {
  177. .port_disable = ata_port_disable,
  178. .set_piomode = triflex_set_piomode,
  179. .mode_filter = ata_pci_default_filter,
  180. .tf_load = ata_tf_load,
  181. .tf_read = ata_tf_read,
  182. .check_status = ata_check_status,
  183. .exec_command = ata_exec_command,
  184. .dev_select = ata_std_dev_select,
  185. .freeze = ata_bmdma_freeze,
  186. .thaw = ata_bmdma_thaw,
  187. .error_handler = triflex_error_handler,
  188. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  189. .bmdma_setup = ata_bmdma_setup,
  190. .bmdma_start = triflex_bmdma_start,
  191. .bmdma_stop = triflex_bmdma_stop,
  192. .bmdma_status = ata_bmdma_status,
  193. .qc_prep = ata_qc_prep,
  194. .qc_issue = ata_qc_issue_prot,
  195. .data_xfer = ata_pio_data_xfer,
  196. .irq_handler = ata_interrupt,
  197. .irq_clear = ata_bmdma_irq_clear,
  198. .port_start = ata_port_start,
  199. .port_stop = ata_port_stop,
  200. .host_stop = ata_host_stop
  201. };
  202. static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  203. {
  204. static struct ata_port_info info = {
  205. .sht = &triflex_sht,
  206. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  207. .pio_mask = 0x1f,
  208. .mwdma_mask = 0x07,
  209. .port_ops = &triflex_port_ops
  210. };
  211. static struct ata_port_info *port_info[2] = { &info, &info };
  212. static int printed_version;
  213. if (!printed_version++)
  214. dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n");
  215. return ata_pci_init_one(dev, port_info, 2);
  216. }
  217. static const struct pci_device_id triflex[] = {
  218. { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), },
  219. { },
  220. };
  221. static struct pci_driver triflex_pci_driver = {
  222. .name = DRV_NAME,
  223. .id_table = triflex,
  224. .probe = triflex_init_one,
  225. .remove = ata_pci_remove_one
  226. };
  227. static int __init triflex_init(void)
  228. {
  229. return pci_register_driver(&triflex_pci_driver);
  230. }
  231. static void __exit triflex_exit(void)
  232. {
  233. pci_unregister_driver(&triflex_pci_driver);
  234. }
  235. MODULE_AUTHOR("Alan Cox");
  236. MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
  237. MODULE_LICENSE("GPL");
  238. MODULE_DEVICE_TABLE(pci, triflex);
  239. MODULE_VERSION(DRV_VERSION);
  240. module_init(triflex_init);
  241. module_exit(triflex_exit);