| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 publically available. | 
|  | 26 | */ | 
|  | 27 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/types.h> | 
|  | 29 | #include <linux/module.h> | 
|  | 30 | #include <linux/kernel.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/hdreg.h> | 
|  | 32 | #include <linux/pci.h> | 
|  | 33 | #include <linux/ide.h> | 
|  | 34 | #include <linux/init.h> | 
|  | 35 |  | 
| Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 36 | static void triflex_set_mode(ide_drive_t *drive, const u8 speed) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { | 
|  | 38 | ide_hwif_t *hwif = HWIF(drive); | 
| Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 39 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | u8 channel_offset = hwif->channel ? 0x74 : 0x70; | 
|  | 41 | u16 timing = 0; | 
|  | 42 | u32 triflex_timings = 0; | 
|  | 43 | u8 unit = (drive->select.b.unit & 0x01); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 |  | 
|  | 45 | pci_read_config_dword(dev, channel_offset, &triflex_timings); | 
|  | 46 |  | 
|  | 47 | switch(speed) { | 
|  | 48 | case XFER_MW_DMA_2: | 
|  | 49 | timing = 0x0103; | 
|  | 50 | break; | 
|  | 51 | case XFER_MW_DMA_1: | 
|  | 52 | timing = 0x0203; | 
|  | 53 | break; | 
|  | 54 | case XFER_MW_DMA_0: | 
|  | 55 | timing = 0x0808; | 
|  | 56 | break; | 
|  | 57 | case XFER_SW_DMA_2: | 
|  | 58 | case XFER_SW_DMA_1: | 
|  | 59 | case XFER_SW_DMA_0: | 
|  | 60 | timing = 0x0f0f; | 
|  | 61 | break; | 
|  | 62 | case XFER_PIO_4: | 
|  | 63 | timing = 0x0202; | 
|  | 64 | break; | 
|  | 65 | case XFER_PIO_3: | 
|  | 66 | timing = 0x0204; | 
|  | 67 | break; | 
|  | 68 | case XFER_PIO_2: | 
|  | 69 | timing = 0x0404; | 
|  | 70 | break; | 
|  | 71 | case XFER_PIO_1: | 
|  | 72 | timing = 0x0508; | 
|  | 73 | break; | 
|  | 74 | case XFER_PIO_0: | 
|  | 75 | timing = 0x0808; | 
|  | 76 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } | 
|  | 78 |  | 
|  | 79 | triflex_timings &= ~(0xFFFF << (16 * unit)); | 
|  | 80 | triflex_timings |= (timing << (16 * unit)); | 
|  | 81 |  | 
|  | 82 | pci_write_config_dword(dev, channel_offset, triflex_timings); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } | 
|  | 84 |  | 
| Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 85 | static void triflex_set_pio_mode(ide_drive_t *drive, const u8 pio) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { | 
| Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 87 | triflex_set_mode(drive, XFER_PIO_0 + pio); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } | 
|  | 89 |  | 
| Herbert Xu | d6904ab | 2005-07-03 16:40:31 +0200 | [diff] [blame] | 90 | static void __devinit init_hwif_triflex(ide_hwif_t *hwif) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { | 
| Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 92 | hwif->set_pio_mode = &triflex_set_pio_mode; | 
| Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 93 | hwif->set_dma_mode = &triflex_set_mode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } | 
|  | 95 |  | 
| Bartlomiej Zolnierkiewicz | 8562043 | 2007-10-20 00:32:34 +0200 | [diff] [blame] | 96 | static const struct ide_port_info triflex_device __devinitdata = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | .name		= "TRIFLEX", | 
|  | 98 | .init_hwif	= init_hwif_triflex, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | .enablebits	= {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}}, | 
| Bartlomiej Zolnierkiewicz | 7cab14a | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 100 | .host_flags	= IDE_HFLAG_BOOTABLE, | 
| Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 101 | .pio_mask	= ATA_PIO4, | 
| Bartlomiej Zolnierkiewicz | 5f8b6c3 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 102 | .swdma_mask	= ATA_SWDMA2, | 
|  | 103 | .mwdma_mask	= ATA_MWDMA2, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | }; | 
|  | 105 |  | 
|  | 106 | static int __devinit triflex_init_one(struct pci_dev *dev, | 
|  | 107 | const struct pci_device_id *id) | 
|  | 108 | { | 
|  | 109 | return ide_setup_pci_device(dev, &triflex_device); | 
|  | 110 | } | 
|  | 111 |  | 
| Bartlomiej Zolnierkiewicz | 9cbcc5e | 2007-10-16 22:29:56 +0200 | [diff] [blame] | 112 | static const struct pci_device_id triflex_pci_tbl[] = { | 
|  | 113 | { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), 0 }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { 0, }, | 
|  | 115 | }; | 
|  | 116 | MODULE_DEVICE_TABLE(pci, triflex_pci_tbl); | 
|  | 117 |  | 
|  | 118 | static struct pci_driver driver = { | 
|  | 119 | .name		= "TRIFLEX_IDE", | 
|  | 120 | .id_table	= triflex_pci_tbl, | 
|  | 121 | .probe		= triflex_init_one, | 
|  | 122 | }; | 
|  | 123 |  | 
| Bartlomiej Zolnierkiewicz | 82ab1ee | 2007-01-27 13:46:56 +0100 | [diff] [blame] | 124 | static int __init triflex_ide_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { | 
|  | 126 | return ide_pci_register_driver(&driver); | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | module_init(triflex_ide_init); | 
|  | 130 |  | 
|  | 131 | MODULE_AUTHOR("Torben Mathiasen"); | 
|  | 132 | MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE"); | 
|  | 133 | MODULE_LICENSE("GPL"); | 
|  | 134 |  | 
|  | 135 |  |