blob: be8715dcee05ec735c35c8b88eb2493f0305736e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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 Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/pci.h>
32#include <linux/ide.h>
33#include <linux/init.h>
34
Bartlomiej Zolnierkiewiczced3ec82008-07-24 22:53:32 +020035#define DRV_NAME "triflex"
36
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020037static void triflex_set_mode(ide_drive_t *drive, const u8 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +010040 struct pci_dev *dev = to_pci_dev(hwif->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 u8 channel_offset = hwif->channel ? 0x74 : 0x70;
42 u16 timing = 0;
43 u32 triflex_timings = 0;
44 u8 unit = (drive->select.b.unit & 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46 pci_read_config_dword(dev, channel_offset, &triflex_timings);
47
48 switch(speed) {
49 case XFER_MW_DMA_2:
50 timing = 0x0103;
51 break;
52 case XFER_MW_DMA_1:
53 timing = 0x0203;
54 break;
55 case XFER_MW_DMA_0:
56 timing = 0x0808;
57 break;
58 case XFER_SW_DMA_2:
59 case XFER_SW_DMA_1:
60 case XFER_SW_DMA_0:
61 timing = 0x0f0f;
62 break;
63 case XFER_PIO_4:
64 timing = 0x0202;
65 break;
66 case XFER_PIO_3:
67 timing = 0x0204;
68 break;
69 case XFER_PIO_2:
70 timing = 0x0404;
71 break;
72 case XFER_PIO_1:
73 timing = 0x0508;
74 break;
75 case XFER_PIO_0:
76 timing = 0x0808;
77 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 }
79
80 triflex_timings &= ~(0xFFFF << (16 * unit));
81 triflex_timings |= (timing << (16 * unit));
82
83 pci_write_config_dword(dev, channel_offset, triflex_timings);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +020086static void triflex_set_pio_mode(ide_drive_t *drive, const u8 pio)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020088 triflex_set_mode(drive, XFER_PIO_0 + pio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020091static const struct ide_port_ops triflex_port_ops = {
92 .set_pio_mode = triflex_set_pio_mode,
93 .set_dma_mode = triflex_set_mode,
94};
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Bartlomiej Zolnierkiewicz85620432007-10-20 00:32:34 +020096static const struct ide_port_info triflex_device __devinitdata = {
Bartlomiej Zolnierkiewiczced3ec82008-07-24 22:53:32 +020097 .name = DRV_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020099 .port_ops = &triflex_port_ops,
Bartlomiej Zolnierkiewicz4099d142007-07-20 01:11:59 +0200100 .pio_mask = ATA_PIO4,
Bartlomiej Zolnierkiewicz5f8b6c32007-10-19 00:30:07 +0200101 .swdma_mask = ATA_SWDMA2,
102 .mwdma_mask = ATA_MWDMA2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103};
104
105static int __devinit triflex_init_one(struct pci_dev *dev,
106 const struct pci_device_id *id)
107{
Bartlomiej Zolnierkiewicz6cdf6eb2008-07-24 22:53:14 +0200108 return ide_pci_init_one(dev, &triflex_device, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Bartlomiej Zolnierkiewicz9cbcc5e2007-10-16 22:29:56 +0200111static const struct pci_device_id triflex_pci_tbl[] = {
112 { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 { 0, },
114};
115MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
116
117static struct pci_driver driver = {
118 .name = "TRIFLEX_IDE",
119 .id_table = triflex_pci_tbl,
120 .probe = triflex_init_one,
Bartlomiej Zolnierkiewicz29d72f22008-07-24 22:53:26 +0200121 .remove = ide_pci_remove,
Bartlomiej Zolnierkiewiczfeb22b72008-10-10 22:39:32 +0200122 .suspend = ide_pci_suspend,
123 .resume = ide_pci_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124};
125
Bartlomiej Zolnierkiewicz82ab1ee2007-01-27 13:46:56 +0100126static int __init triflex_ide_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 return ide_pci_register_driver(&driver);
129}
130
Bartlomiej Zolnierkiewicz29d72f22008-07-24 22:53:26 +0200131static void __exit triflex_ide_exit(void)
132{
133 pci_unregister_driver(&driver);
134}
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136module_init(triflex_ide_init);
Bartlomiej Zolnierkiewicz29d72f22008-07-24 22:53:26 +0200137module_exit(triflex_ide_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139MODULE_AUTHOR("Torben Mathiasen");
140MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE");
141MODULE_LICENSE("GPL");
142
143