triflex.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * IDE Chipset driver for the Compaq TriFlex IDE controller.
  3. *
  4. * Known to work with the Compaq Workstation 5x00 series.
  5. *
  6. * Copyright (C) 2002 Hewlett-Packard Development Group, L.P.
  7. * Author: Torben Mathiasen <torben.mathiasen@hp.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * Loosely based on the piix & svwks drivers.
  23. *
  24. * Documentation:
  25. * Not publicly available.
  26. */
  27. #include <linux/types.h>
  28. #include <linux/module.h>
  29. #include <linux/kernel.h>
  30. #include <linux/pci.h>
  31. #include <linux/ide.h>
  32. #include <linux/init.h>
  33. #define DRV_NAME "triflex"
  34. static void triflex_set_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  35. {
  36. struct pci_dev *dev = to_pci_dev(hwif->dev);
  37. u32 triflex_timings = 0;
  38. u16 timing = 0;
  39. u8 channel_offset = hwif->channel ? 0x74 : 0x70, unit = drive->dn & 1;
  40. pci_read_config_dword(dev, channel_offset, &triflex_timings);
  41. switch (drive->dma_mode) {
  42. case XFER_MW_DMA_2:
  43. timing = 0x0103;
  44. break;
  45. case XFER_MW_DMA_1:
  46. timing = 0x0203;
  47. break;
  48. case XFER_MW_DMA_0:
  49. timing = 0x0808;
  50. break;
  51. case XFER_SW_DMA_2:
  52. case XFER_SW_DMA_1:
  53. case XFER_SW_DMA_0:
  54. timing = 0x0f0f;
  55. break;
  56. case XFER_PIO_4:
  57. timing = 0x0202;
  58. break;
  59. case XFER_PIO_3:
  60. timing = 0x0204;
  61. break;
  62. case XFER_PIO_2:
  63. timing = 0x0404;
  64. break;
  65. case XFER_PIO_1:
  66. timing = 0x0508;
  67. break;
  68. case XFER_PIO_0:
  69. timing = 0x0808;
  70. break;
  71. }
  72. triflex_timings &= ~(0xFFFF << (16 * unit));
  73. triflex_timings |= (timing << (16 * unit));
  74. pci_write_config_dword(dev, channel_offset, triflex_timings);
  75. }
  76. static void triflex_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  77. {
  78. drive->dma_mode = drive->pio_mode;
  79. triflex_set_mode(hwif, drive);
  80. }
  81. static const struct ide_port_ops triflex_port_ops = {
  82. .set_pio_mode = triflex_set_pio_mode,
  83. .set_dma_mode = triflex_set_mode,
  84. };
  85. static const struct ide_port_info triflex_device = {
  86. .name = DRV_NAME,
  87. .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
  88. .port_ops = &triflex_port_ops,
  89. .pio_mask = ATA_PIO4,
  90. .swdma_mask = ATA_SWDMA2,
  91. .mwdma_mask = ATA_MWDMA2,
  92. };
  93. static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  94. {
  95. return ide_pci_init_one(dev, &triflex_device, NULL);
  96. }
  97. static const struct pci_device_id triflex_pci_tbl[] = {
  98. { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), 0 },
  99. { 0, },
  100. };
  101. MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
  102. #ifdef CONFIG_PM
  103. static int triflex_ide_pci_suspend(struct pci_dev *dev, pm_message_t state)
  104. {
  105. /*
  106. * We must not disable or powerdown the device.
  107. * APM bios refuses to suspend if IDE is not accessible.
  108. */
  109. pci_save_state(dev);
  110. return 0;
  111. }
  112. #else
  113. #define triflex_ide_pci_suspend NULL
  114. #endif
  115. static struct pci_driver triflex_pci_driver = {
  116. .name = "TRIFLEX_IDE",
  117. .id_table = triflex_pci_tbl,
  118. .probe = triflex_init_one,
  119. .remove = ide_pci_remove,
  120. .suspend = triflex_ide_pci_suspend,
  121. .resume = ide_pci_resume,
  122. };
  123. static int __init triflex_ide_init(void)
  124. {
  125. return ide_pci_register_driver(&triflex_pci_driver);
  126. }
  127. static void __exit triflex_ide_exit(void)
  128. {
  129. pci_unregister_driver(&triflex_pci_driver);
  130. }
  131. module_init(triflex_ide_init);
  132. module_exit(triflex_ide_exit);
  133. MODULE_AUTHOR("Torben Mathiasen");
  134. MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE");
  135. MODULE_LICENSE("GPL");