blob: 7f1af9493f0efbb92fc6fa06ac6a3f7d4a59b689 [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:
Lucas De Marchi25985ed2011-03-30 22:57:33 -030025 * Not publicly available.
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 */
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 Zolnierkiewicz87761682010-01-19 01:45:29 -080037static void triflex_set_mode(ide_hwif_t *hwif, ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +010039 struct pci_dev *dev = to_pci_dev(hwif->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 u32 triflex_timings = 0;
Bartlomiej Zolnierkiewicz123995b2008-10-13 21:39:40 +020041 u16 timing = 0;
42 u8 channel_offset = hwif->channel ? 0x74 : 0x70, unit = drive->dn & 1;
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 pci_read_config_dword(dev, channel_offset, &triflex_timings);
Bartlomiej Zolnierkiewicz123995b2008-10-13 21:39:40 +020045
Bartlomiej Zolnierkiewicz87761682010-01-19 01:45:29 -080046 switch (drive->dma_mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 case XFER_MW_DMA_2:
48 timing = 0x0103;
49 break;
50 case XFER_MW_DMA_1:
51 timing = 0x0203;
52 break;
53 case XFER_MW_DMA_0:
54 timing = 0x0808;
55 break;
56 case XFER_SW_DMA_2:
57 case XFER_SW_DMA_1:
58 case XFER_SW_DMA_0:
59 timing = 0x0f0f;
60 break;
61 case XFER_PIO_4:
62 timing = 0x0202;
63 break;
64 case XFER_PIO_3:
65 timing = 0x0204;
66 break;
67 case XFER_PIO_2:
68 timing = 0x0404;
69 break;
70 case XFER_PIO_1:
71 timing = 0x0508;
72 break;
73 case XFER_PIO_0:
74 timing = 0x0808;
75 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 }
77
78 triflex_timings &= ~(0xFFFF << (16 * unit));
79 triflex_timings |= (timing << (16 * unit));
80
81 pci_write_config_dword(dev, channel_offset, triflex_timings);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Bartlomiej Zolnierkiewicze085b3c2010-01-19 01:44:41 -080084static void triflex_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Bartlomiej Zolnierkiewicz87761682010-01-19 01:45:29 -080086 drive->dma_mode = drive->pio_mode;
87 triflex_set_mode(hwif, drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020090static const struct ide_port_ops triflex_port_ops = {
91 .set_pio_mode = triflex_set_pio_mode,
92 .set_dma_mode = triflex_set_mode,
93};
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -080095static const struct ide_port_info triflex_device = {
Bartlomiej Zolnierkiewiczced3ec82008-07-24 22:53:32 +020096 .name = DRV_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020098 .port_ops = &triflex_port_ops,
Bartlomiej Zolnierkiewicz4099d142007-07-20 01:11:59 +020099 .pio_mask = ATA_PIO4,
Bartlomiej Zolnierkiewicz5f8b6c32007-10-19 00:30:07 +0200100 .swdma_mask = ATA_SWDMA2,
101 .mwdma_mask = ATA_MWDMA2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102};
103
Greg Kroah-Hartmanfe31edc2012-12-21 13:21:03 -0800104static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Bartlomiej Zolnierkiewicz6cdf6eb2008-07-24 22:53:14 +0200106 return ide_pci_init_one(dev, &triflex_device, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
Bartlomiej Zolnierkiewicz9cbcc5e2007-10-16 22:29:56 +0200109static const struct pci_device_id triflex_pci_tbl[] = {
110 { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 { 0, },
112};
113MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
114
Mikulas Patocka839e7302011-10-12 04:31:51 +0000115#ifdef CONFIG_PM
116static int triflex_ide_pci_suspend(struct pci_dev *dev, pm_message_t state)
117{
118 /*
119 * We must not disable or powerdown the device.
120 * APM bios refuses to suspend if IDE is not accessible.
121 */
122 pci_save_state(dev);
123 return 0;
124}
125#else
126#define triflex_ide_pci_suspend NULL
127#endif
128
Bartlomiej Zolnierkiewicza9ab09e2008-10-13 21:39:41 +0200129static struct pci_driver triflex_pci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .name = "TRIFLEX_IDE",
131 .id_table = triflex_pci_tbl,
132 .probe = triflex_init_one,
Bartlomiej Zolnierkiewicz29d72f22008-07-24 22:53:26 +0200133 .remove = ide_pci_remove,
Mikulas Patocka839e7302011-10-12 04:31:51 +0000134 .suspend = triflex_ide_pci_suspend,
Bartlomiej Zolnierkiewiczfeb22b72008-10-10 22:39:32 +0200135 .resume = ide_pci_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136};
137
Bartlomiej Zolnierkiewicz82ab1ee2007-01-27 13:46:56 +0100138static int __init triflex_ide_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Bartlomiej Zolnierkiewicza9ab09e2008-10-13 21:39:41 +0200140 return ide_pci_register_driver(&triflex_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Bartlomiej Zolnierkiewicz29d72f22008-07-24 22:53:26 +0200143static void __exit triflex_ide_exit(void)
144{
Bartlomiej Zolnierkiewicza9ab09e2008-10-13 21:39:41 +0200145 pci_unregister_driver(&triflex_pci_driver);
Bartlomiej Zolnierkiewicz29d72f22008-07-24 22:53:26 +0200146}
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148module_init(triflex_ide_init);
Bartlomiej Zolnierkiewicz29d72f22008-07-24 22:53:26 +0200149module_exit(triflex_ide_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151MODULE_AUTHOR("Torben Mathiasen");
152MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE");
153MODULE_LICENSE("GPL");
154
155