Thomas Gleixner | 4505153 | 2019-05-29 16:57:47 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * Loosely based on the piix & svwks drivers. |
| 11 | * |
| 12 | * Documentation: |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 13 | * Not publicly available. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/types.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/pci.h> |
| 20 | #include <linux/ide.h> |
| 21 | #include <linux/init.h> |
| 22 | |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 23 | #define DRV_NAME "triflex" |
| 24 | |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 25 | static void triflex_set_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 27 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | u32 triflex_timings = 0; |
Bartlomiej Zolnierkiewicz | 123995b | 2008-10-13 21:39:40 +0200 | [diff] [blame] | 29 | u16 timing = 0; |
| 30 | u8 channel_offset = hwif->channel ? 0x74 : 0x70, unit = drive->dn & 1; |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | pci_read_config_dword(dev, channel_offset, &triflex_timings); |
Bartlomiej Zolnierkiewicz | 123995b | 2008-10-13 21:39:40 +0200 | [diff] [blame] | 33 | |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 34 | switch (drive->dma_mode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | case XFER_MW_DMA_2: |
| 36 | timing = 0x0103; |
| 37 | break; |
| 38 | case XFER_MW_DMA_1: |
| 39 | timing = 0x0203; |
| 40 | break; |
| 41 | case XFER_MW_DMA_0: |
| 42 | timing = 0x0808; |
| 43 | break; |
| 44 | case XFER_SW_DMA_2: |
| 45 | case XFER_SW_DMA_1: |
| 46 | case XFER_SW_DMA_0: |
| 47 | timing = 0x0f0f; |
| 48 | break; |
| 49 | case XFER_PIO_4: |
| 50 | timing = 0x0202; |
| 51 | break; |
| 52 | case XFER_PIO_3: |
| 53 | timing = 0x0204; |
| 54 | break; |
| 55 | case XFER_PIO_2: |
| 56 | timing = 0x0404; |
| 57 | break; |
| 58 | case XFER_PIO_1: |
| 59 | timing = 0x0508; |
| 60 | break; |
| 61 | case XFER_PIO_0: |
| 62 | timing = 0x0808; |
| 63 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | triflex_timings &= ~(0xFFFF << (16 * unit)); |
| 67 | triflex_timings |= (timing << (16 * unit)); |
| 68 | |
| 69 | pci_write_config_dword(dev, channel_offset, triflex_timings); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Bartlomiej Zolnierkiewicz | e085b3c | 2010-01-19 01:44:41 -0800 | [diff] [blame] | 72 | static void triflex_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Bartlomiej Zolnierkiewicz | 8776168 | 2010-01-19 01:45:29 -0800 | [diff] [blame] | 74 | drive->dma_mode = drive->pio_mode; |
| 75 | triflex_set_mode(hwif, drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 78 | static const struct ide_port_ops triflex_port_ops = { |
| 79 | .set_pio_mode = triflex_set_pio_mode, |
| 80 | .set_dma_mode = triflex_set_mode, |
| 81 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 83 | static const struct ide_port_info triflex_device = { |
Bartlomiej Zolnierkiewicz | ced3ec8 | 2008-07-24 22:53:32 +0200 | [diff] [blame] | 84 | .name = DRV_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}}, |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 86 | .port_ops = &triflex_port_ops, |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 87 | .pio_mask = ATA_PIO4, |
Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 88 | .swdma_mask = ATA_SWDMA2, |
| 89 | .mwdma_mask = ATA_MWDMA2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Greg Kroah-Hartman | fe31edc | 2012-12-21 13:21:03 -0800 | [diff] [blame] | 92 | static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Bartlomiej Zolnierkiewicz | 6cdf6eb | 2008-07-24 22:53:14 +0200 | [diff] [blame] | 94 | return ide_pci_init_one(dev, &triflex_device, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Bartlomiej Zolnierkiewicz | 9cbcc5e | 2007-10-16 22:29:56 +0200 | [diff] [blame] | 97 | static const struct pci_device_id triflex_pci_tbl[] = { |
| 98 | { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { 0, }, |
| 100 | }; |
| 101 | MODULE_DEVICE_TABLE(pci, triflex_pci_tbl); |
| 102 | |
Mikulas Patocka | 839e730 | 2011-10-12 04:31:51 +0000 | [diff] [blame] | 103 | #ifdef CONFIG_PM |
| 104 | static int triflex_ide_pci_suspend(struct pci_dev *dev, pm_message_t state) |
| 105 | { |
| 106 | /* |
| 107 | * We must not disable or powerdown the device. |
| 108 | * APM bios refuses to suspend if IDE is not accessible. |
| 109 | */ |
| 110 | pci_save_state(dev); |
| 111 | return 0; |
| 112 | } |
| 113 | #else |
| 114 | #define triflex_ide_pci_suspend NULL |
| 115 | #endif |
| 116 | |
Bartlomiej Zolnierkiewicz | a9ab09e2 | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 117 | static struct pci_driver triflex_pci_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | .name = "TRIFLEX_IDE", |
| 119 | .id_table = triflex_pci_tbl, |
| 120 | .probe = triflex_init_one, |
Bartlomiej Zolnierkiewicz | 29d72f2 | 2008-07-24 22:53:26 +0200 | [diff] [blame] | 121 | .remove = ide_pci_remove, |
Mikulas Patocka | 839e730 | 2011-10-12 04:31:51 +0000 | [diff] [blame] | 122 | .suspend = triflex_ide_pci_suspend, |
Bartlomiej Zolnierkiewicz | feb22b7 | 2008-10-10 22:39:32 +0200 | [diff] [blame] | 123 | .resume = ide_pci_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Bartlomiej Zolnierkiewicz | 82ab1ee | 2007-01-27 13:46:56 +0100 | [diff] [blame] | 126 | static int __init triflex_ide_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
Bartlomiej Zolnierkiewicz | a9ab09e2 | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 128 | return ide_pci_register_driver(&triflex_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Bartlomiej Zolnierkiewicz | 29d72f2 | 2008-07-24 22:53:26 +0200 | [diff] [blame] | 131 | static void __exit triflex_ide_exit(void) |
| 132 | { |
Bartlomiej Zolnierkiewicz | a9ab09e2 | 2008-10-13 21:39:41 +0200 | [diff] [blame] | 133 | pci_unregister_driver(&triflex_pci_driver); |
Bartlomiej Zolnierkiewicz | 29d72f2 | 2008-07-24 22:53:26 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | module_init(triflex_ide_init); |
Bartlomiej Zolnierkiewicz | 29d72f2 | 2008-07-24 22:53:26 +0200 | [diff] [blame] | 137 | module_exit(triflex_ide_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | MODULE_AUTHOR("Torben Mathiasen"); |
| 140 | MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE"); |
| 141 | MODULE_LICENSE("GPL"); |
| 142 | |
| 143 | |