2 * pata_triflex.c - Compaq PATA for new ATA layer
4 * Alan Cox <alan@redhat.com>
10 * IDE Chipset driver for the Compaq TriFlex IDE controller.
12 * Known to work with the Compaq Workstation 5x00 series.
14 * Copyright (C) 2002 Hewlett-Packard Development Group, L.P.
15 * Author: Torben Mathiasen <torben.mathiasen@hp.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 * Loosely based on the piix & svwks drivers.
33 * Not publically available.
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/pci.h>
39 #include <linux/init.h>
40 #include <linux/blkdev.h>
41 #include <linux/delay.h>
42 #include <scsi/scsi_host.h>
43 #include <linux/libata.h>
45 #define DRV_NAME "pata_triflex"
46 #define DRV_VERSION "0.2.5"
49 * triflex_probe_init - probe begin
52 * Set up cable type and use generic probe init
55 static int triflex_probe_init(struct ata_port
*ap
)
57 static const struct pci_bits triflex_enable_bits
[] = {
58 { 0x80, 1, 0x01, 0x01 },
59 { 0x80, 1, 0x02, 0x02 }
62 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
64 if (!pci_test_config_bits(pdev
, &triflex_enable_bits
[ap
->port_no
])) {
66 printk(KERN_INFO
"ata%u: port disabled. ignoring.\n", ap
->id
);
69 ap
->cbl
= ATA_CBL_PATA40
;
70 return ata_std_prereset(ap
);
75 static void triflex_error_handler(struct ata_port
*ap
)
77 ata_bmdma_drive_eh(ap
, triflex_probe_init
, ata_std_softreset
, NULL
, ata_std_postreset
);
81 * triflex_load_timing - timing configuration
83 * @adev: Device on the bus
84 * @speed: speed to configure
86 * The Triflex has one set of timings per device per channel. This
87 * means we must do some switching. As the PIO and DMA timings don't
88 * match we have to do some reloading unlike PIIX devices where tuning
89 * tricks can avoid it.
92 static void triflex_load_timing(struct ata_port
*ap
, struct ata_device
*adev
, int speed
)
94 struct pci_dev
*pdev
= to_pci_dev(ap
->host
->dev
);
96 u32 triflex_timing
, old_triflex_timing
;
97 int channel_offset
= ap
->port_no
? 0x74: 0x70;
98 unsigned int is_slave
= (adev
->devno
!= 0);
101 pci_read_config_dword(pdev
, channel_offset
, &old_triflex_timing
);
102 triflex_timing
= old_triflex_timing
;
107 timing
= 0x0103;break;
109 timing
= 0x0203;break;
111 timing
= 0x0808;break;
115 timing
= 0x0F0F;break;
117 timing
= 0x0202;break;
119 timing
= 0x0204;break;
121 timing
= 0x0404;break;
123 timing
= 0x0508;break;
125 timing
= 0x0808;break;
129 triflex_timing
&= ~ (0xFFFF << (16 * is_slave
));
130 triflex_timing
|= (timing
<< (16 * is_slave
));
132 if (triflex_timing
!= old_triflex_timing
)
133 pci_write_config_dword(pdev
, channel_offset
, triflex_timing
);
137 * triflex_set_piomode - set initial PIO mode data
141 * Use the timing loader to set up the PIO mode. We have to do this
142 * because DMA start/stop will only be called once DMA occurs. If there
143 * has been no DMA then the PIO timings are still needed.
145 static void triflex_set_piomode(struct ata_port
*ap
, struct ata_device
*adev
)
147 triflex_load_timing(ap
, adev
, adev
->pio_mode
);
151 * triflex_dma_start - DMA start callback
152 * @qc: Command in progress
154 * Usually drivers set the DMA timing at the point the set_dmamode call
155 * is made. Triflex however requires we load new timings on the
156 * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
157 * We load the DMA timings just before starting DMA and then restore
158 * the PIO timing when the DMA is finished.
161 static void triflex_bmdma_start(struct ata_queued_cmd
*qc
)
163 triflex_load_timing(qc
->ap
, qc
->dev
, qc
->dev
->dma_mode
);
168 * triflex_dma_stop - DMA stop callback
172 * We loaded new timings in dma_start, as a result we need to restore
173 * the PIO timings in dma_stop so that the next command issue gets the
174 * right clock values.
177 static void triflex_bmdma_stop(struct ata_queued_cmd
*qc
)
180 triflex_load_timing(qc
->ap
, qc
->dev
, qc
->dev
->pio_mode
);
183 static struct scsi_host_template triflex_sht
= {
184 .module
= THIS_MODULE
,
186 .ioctl
= ata_scsi_ioctl
,
187 .queuecommand
= ata_scsi_queuecmd
,
188 .can_queue
= ATA_DEF_QUEUE
,
189 .this_id
= ATA_SHT_THIS_ID
,
190 .sg_tablesize
= LIBATA_MAX_PRD
,
191 .max_sectors
= ATA_MAX_SECTORS
,
192 .cmd_per_lun
= ATA_SHT_CMD_PER_LUN
,
193 .emulated
= ATA_SHT_EMULATED
,
194 .use_clustering
= ATA_SHT_USE_CLUSTERING
,
195 .proc_name
= DRV_NAME
,
196 .dma_boundary
= ATA_DMA_BOUNDARY
,
197 .slave_configure
= ata_scsi_slave_config
,
198 .bios_param
= ata_std_bios_param
,
201 static struct ata_port_operations triflex_port_ops
= {
202 .port_disable
= ata_port_disable
,
203 .set_piomode
= triflex_set_piomode
,
204 .mode_filter
= ata_pci_default_filter
,
206 .tf_load
= ata_tf_load
,
207 .tf_read
= ata_tf_read
,
208 .check_status
= ata_check_status
,
209 .exec_command
= ata_exec_command
,
210 .dev_select
= ata_std_dev_select
,
212 .freeze
= ata_bmdma_freeze
,
213 .thaw
= ata_bmdma_thaw
,
214 .error_handler
= triflex_error_handler
,
215 .post_internal_cmd
= ata_bmdma_post_internal_cmd
,
217 .bmdma_setup
= ata_bmdma_setup
,
218 .bmdma_start
= triflex_bmdma_start
,
219 .bmdma_stop
= triflex_bmdma_stop
,
220 .bmdma_status
= ata_bmdma_status
,
222 .qc_prep
= ata_qc_prep
,
223 .qc_issue
= ata_qc_issue_prot
,
224 .eng_timeout
= ata_eng_timeout
,
225 .data_xfer
= ata_pio_data_xfer
,
227 .irq_handler
= ata_interrupt
,
228 .irq_clear
= ata_bmdma_irq_clear
,
230 .port_start
= ata_port_start
,
231 .port_stop
= ata_port_stop
,
232 .host_stop
= ata_host_stop
235 static int triflex_init_one(struct pci_dev
*dev
, const struct pci_device_id
*id
)
237 static struct ata_port_info info
= {
239 .flags
= ATA_FLAG_SLAVE_POSS
| ATA_FLAG_SRST
,
242 .port_ops
= &triflex_port_ops
244 static struct ata_port_info
*port_info
[2] = { &info
, &info
};
245 static int printed_version
;
247 if (!printed_version
++)
248 dev_printk(KERN_DEBUG
, &dev
->dev
, "version " DRV_VERSION
"\n");
250 return ata_pci_init_one(dev
, port_info
, 2);
253 static const struct pci_device_id triflex
[] = {
254 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE
,
255 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
259 static struct pci_driver triflex_pci_driver
= {
262 .probe
= triflex_init_one
,
263 .remove
= ata_pci_remove_one
266 static int __init
triflex_init(void)
268 return pci_register_driver(&triflex_pci_driver
);
272 static void __exit
triflex_exit(void)
274 pci_unregister_driver(&triflex_pci_driver
);
278 MODULE_AUTHOR("Alan Cox");
279 MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
280 MODULE_LICENSE("GPL");
281 MODULE_DEVICE_TABLE(pci
, triflex
);
282 MODULE_VERSION(DRV_VERSION
);
284 module_init(triflex_init
);
285 module_exit(triflex_exit
);