triflex.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * IDE Chipset driver for the Compaq TriFlex IDE controller.
  4. *
  5. * Known to work with the Compaq Workstation 5x00 series.
  6. *
  7. * Copyright (C) 2002 Hewlett-Packard Development Group, L.P.
  8. * Author: Torben Mathiasen <torben.mathiasen@hp.com>
  9. *
  10. * Loosely based on the piix & svwks drivers.
  11. *
  12. * Documentation:
  13. * Not publicly available.
  14. */
  15. #include <linux/types.h>
  16. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/pci.h>
  19. #include <linux/ide.h>
  20. #include <linux/init.h>
  21. #define DRV_NAME "triflex"
  22. static void triflex_set_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  23. {
  24. struct pci_dev *dev = to_pci_dev(hwif->dev);
  25. u32 triflex_timings = 0;
  26. u16 timing = 0;
  27. u8 channel_offset = hwif->channel ? 0x74 : 0x70, unit = drive->dn & 1;
  28. pci_read_config_dword(dev, channel_offset, &triflex_timings);
  29. switch (drive->dma_mode) {
  30. case XFER_MW_DMA_2:
  31. timing = 0x0103;
  32. break;
  33. case XFER_MW_DMA_1:
  34. timing = 0x0203;
  35. break;
  36. case XFER_MW_DMA_0:
  37. timing = 0x0808;
  38. break;
  39. case XFER_SW_DMA_2:
  40. case XFER_SW_DMA_1:
  41. case XFER_SW_DMA_0:
  42. timing = 0x0f0f;
  43. break;
  44. case XFER_PIO_4:
  45. timing = 0x0202;
  46. break;
  47. case XFER_PIO_3:
  48. timing = 0x0204;
  49. break;
  50. case XFER_PIO_2:
  51. timing = 0x0404;
  52. break;
  53. case XFER_PIO_1:
  54. timing = 0x0508;
  55. break;
  56. case XFER_PIO_0:
  57. timing = 0x0808;
  58. break;
  59. }
  60. triflex_timings &= ~(0xFFFF << (16 * unit));
  61. triflex_timings |= (timing << (16 * unit));
  62. pci_write_config_dword(dev, channel_offset, triflex_timings);
  63. }
  64. static void triflex_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  65. {
  66. drive->dma_mode = drive->pio_mode;
  67. triflex_set_mode(hwif, drive);
  68. }
  69. static const struct ide_port_ops triflex_port_ops = {
  70. .set_pio_mode = triflex_set_pio_mode,
  71. .set_dma_mode = triflex_set_mode,
  72. };
  73. static const struct ide_port_info triflex_device = {
  74. .name = DRV_NAME,
  75. .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
  76. .port_ops = &triflex_port_ops,
  77. .pio_mask = ATA_PIO4,
  78. .swdma_mask = ATA_SWDMA2,
  79. .mwdma_mask = ATA_MWDMA2,
  80. };
  81. static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  82. {
  83. return ide_pci_init_one(dev, &triflex_device, NULL);
  84. }
  85. static const struct pci_device_id triflex_pci_tbl[] = {
  86. { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), 0 },
  87. { 0, },
  88. };
  89. MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
  90. #ifdef CONFIG_PM
  91. static int triflex_ide_pci_suspend(struct pci_dev *dev, pm_message_t state)
  92. {
  93. /*
  94. * We must not disable or powerdown the device.
  95. * APM bios refuses to suspend if IDE is not accessible.
  96. */
  97. pci_save_state(dev);
  98. return 0;
  99. }
  100. #else
  101. #define triflex_ide_pci_suspend NULL
  102. #endif
  103. static struct pci_driver triflex_pci_driver = {
  104. .name = "TRIFLEX_IDE",
  105. .id_table = triflex_pci_tbl,
  106. .probe = triflex_init_one,
  107. .remove = ide_pci_remove,
  108. .suspend = triflex_ide_pci_suspend,
  109. .resume = ide_pci_resume,
  110. };
  111. static int __init triflex_ide_init(void)
  112. {
  113. return ide_pci_register_driver(&triflex_pci_driver);
  114. }
  115. static void __exit triflex_ide_exit(void)
  116. {
  117. pci_unregister_driver(&triflex_pci_driver);
  118. }
  119. module_init(triflex_ide_init);
  120. module_exit(triflex_ide_exit);
  121. MODULE_AUTHOR("Torben Mathiasen");
  122. MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE");
  123. MODULE_LICENSE("GPL");