blob: 95adf92901fcbe6c901957184ebda3f8a1f2df42 [file] [log] [blame]
Jeff Garzik669a5db2006-08-29 18:12:40 -04001/*
2 * pata_triflex.c - Compaq PATA for new ATA layer
3 * (C) 2005 Red Hat Inc
4 * Alan Cox <alan@redhat.com>
5 *
6 * based upon
7 *
8 * triflex.c
9 *
10 * IDE Chipset driver for the Compaq TriFlex IDE controller.
11 *
12 * Known to work with the Compaq Workstation 5x00 series.
13 *
14 * Copyright (C) 2002 Hewlett-Packard Development Group, L.P.
15 * Author: Torben Mathiasen <torben.mathiasen@hp.com>
16 *
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.
20 *
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.
25 *
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
29 *
30 * Loosely based on the piix & svwks drivers.
31 *
32 * Documentation:
33 * Not publically available.
34 */
35
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>
44
45#define DRV_NAME "pata_triflex"
46#define DRV_VERSION "0.2.5"
47
48/**
Alan Coxc9619222006-09-26 17:53:38 +010049 * triflex_prereset - probe begin
Jeff Garzik669a5db2006-08-29 18:12:40 -040050 * @ap: ATA port
51 *
52 * Set up cable type and use generic probe init
53 */
54
Alan Coxc9619222006-09-26 17:53:38 +010055static int triflex_prereset(struct ata_port *ap)
Jeff Garzik669a5db2006-08-29 18:12:40 -040056{
57 static const struct pci_bits triflex_enable_bits[] = {
58 { 0x80, 1, 0x01, 0x01 },
59 { 0x80, 1, 0x02, 0x02 }
60 };
61
62 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Jeff Garzik85cd7252006-08-31 00:03:49 -040063
Alan Coxc9619222006-09-26 17:53:38 +010064 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
65 return -ENOENT;
Jeff Garzik669a5db2006-08-29 18:12:40 -040066 ap->cbl = ATA_CBL_PATA40;
67 return ata_std_prereset(ap);
68}
69
70
71
72static void triflex_error_handler(struct ata_port *ap)
73{
Alan Coxc9619222006-09-26 17:53:38 +010074 ata_bmdma_drive_eh(ap, triflex_prereset, ata_std_softreset, NULL, ata_std_postreset);
Jeff Garzik669a5db2006-08-29 18:12:40 -040075}
76
77/**
78 * triflex_load_timing - timing configuration
79 * @ap: ATA interface
80 * @adev: Device on the bus
81 * @speed: speed to configure
82 *
83 * The Triflex has one set of timings per device per channel. This
84 * means we must do some switching. As the PIO and DMA timings don't
85 * match we have to do some reloading unlike PIIX devices where tuning
86 * tricks can avoid it.
87 */
88
89static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
90{
91 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
92 u32 timing = 0;
93 u32 triflex_timing, old_triflex_timing;
94 int channel_offset = ap->port_no ? 0x74: 0x70;
95 unsigned int is_slave = (adev->devno != 0);
96
97
98 pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
99 triflex_timing = old_triflex_timing;
100
101 switch(speed)
102 {
103 case XFER_MW_DMA_2:
104 timing = 0x0103;break;
105 case XFER_MW_DMA_1:
106 timing = 0x0203;break;
107 case XFER_MW_DMA_0:
108 timing = 0x0808;break;
109 case XFER_SW_DMA_2:
110 case XFER_SW_DMA_1:
111 case XFER_SW_DMA_0:
112 timing = 0x0F0F;break;
113 case XFER_PIO_4:
114 timing = 0x0202;break;
115 case XFER_PIO_3:
116 timing = 0x0204;break;
117 case XFER_PIO_2:
118 timing = 0x0404;break;
119 case XFER_PIO_1:
120 timing = 0x0508;break;
121 case XFER_PIO_0:
122 timing = 0x0808;break;
123 default:
124 BUG();
125 }
126 triflex_timing &= ~ (0xFFFF << (16 * is_slave));
127 triflex_timing |= (timing << (16 * is_slave));
128
129 if (triflex_timing != old_triflex_timing)
130 pci_write_config_dword(pdev, channel_offset, triflex_timing);
131}
132
133/**
134 * triflex_set_piomode - set initial PIO mode data
135 * @ap: ATA interface
136 * @adev: ATA device
137 *
138 * Use the timing loader to set up the PIO mode. We have to do this
139 * because DMA start/stop will only be called once DMA occurs. If there
140 * has been no DMA then the PIO timings are still needed.
141 */
142static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
143{
144 triflex_load_timing(ap, adev, adev->pio_mode);
145}
146
147/**
148 * triflex_dma_start - DMA start callback
149 * @qc: Command in progress
150 *
151 * Usually drivers set the DMA timing at the point the set_dmamode call
152 * is made. Triflex however requires we load new timings on the
153 * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
154 * We load the DMA timings just before starting DMA and then restore
155 * the PIO timing when the DMA is finished.
156 */
157
158static void triflex_bmdma_start(struct ata_queued_cmd *qc)
159{
160 triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
161 ata_bmdma_start(qc);
162}
163
164/**
165 * triflex_dma_stop - DMA stop callback
166 * @ap: ATA interface
167 * @adev: ATA device
168 *
169 * We loaded new timings in dma_start, as a result we need to restore
170 * the PIO timings in dma_stop so that the next command issue gets the
171 * right clock values.
172 */
173
174static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
175{
176 ata_bmdma_stop(qc);
177 triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
178}
179
180static struct scsi_host_template triflex_sht = {
181 .module = THIS_MODULE,
182 .name = DRV_NAME,
183 .ioctl = ata_scsi_ioctl,
184 .queuecommand = ata_scsi_queuecmd,
185 .can_queue = ATA_DEF_QUEUE,
186 .this_id = ATA_SHT_THIS_ID,
187 .sg_tablesize = LIBATA_MAX_PRD,
188 .max_sectors = ATA_MAX_SECTORS,
189 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
190 .emulated = ATA_SHT_EMULATED,
191 .use_clustering = ATA_SHT_USE_CLUSTERING,
192 .proc_name = DRV_NAME,
193 .dma_boundary = ATA_DMA_BOUNDARY,
194 .slave_configure = ata_scsi_slave_config,
195 .bios_param = ata_std_bios_param,
196};
197
198static struct ata_port_operations triflex_port_ops = {
199 .port_disable = ata_port_disable,
200 .set_piomode = triflex_set_piomode,
201 .mode_filter = ata_pci_default_filter,
202
203 .tf_load = ata_tf_load,
204 .tf_read = ata_tf_read,
205 .check_status = ata_check_status,
206 .exec_command = ata_exec_command,
207 .dev_select = ata_std_dev_select,
208
209 .freeze = ata_bmdma_freeze,
210 .thaw = ata_bmdma_thaw,
211 .error_handler = triflex_error_handler,
212 .post_internal_cmd = ata_bmdma_post_internal_cmd,
213
214 .bmdma_setup = ata_bmdma_setup,
215 .bmdma_start = triflex_bmdma_start,
216 .bmdma_stop = triflex_bmdma_stop,
217 .bmdma_status = ata_bmdma_status,
218
219 .qc_prep = ata_qc_prep,
220 .qc_issue = ata_qc_issue_prot,
221 .eng_timeout = ata_eng_timeout,
222 .data_xfer = ata_pio_data_xfer,
223
224 .irq_handler = ata_interrupt,
225 .irq_clear = ata_bmdma_irq_clear,
226
227 .port_start = ata_port_start,
228 .port_stop = ata_port_stop,
229 .host_stop = ata_host_stop
230};
231
232static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
233{
234 static struct ata_port_info info = {
235 .sht = &triflex_sht,
236 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
237 .pio_mask = 0x1f,
238 .mwdma_mask = 0x07,
239 .port_ops = &triflex_port_ops
240 };
241 static struct ata_port_info *port_info[2] = { &info, &info };
242 static int printed_version;
243
244 if (!printed_version++)
245 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n");
246
247 return ata_pci_init_one(dev, port_info, 2);
248}
249
250static const struct pci_device_id triflex[] = {
251 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE,
252 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
253 { 0, },
254};
255
256static struct pci_driver triflex_pci_driver = {
257 .name = DRV_NAME,
258 .id_table = triflex,
259 .probe = triflex_init_one,
260 .remove = ata_pci_remove_one
261};
262
263static int __init triflex_init(void)
264{
265 return pci_register_driver(&triflex_pci_driver);
266}
267
268
269static void __exit triflex_exit(void)
270{
271 pci_unregister_driver(&triflex_pci_driver);
272}
273
274
275MODULE_AUTHOR("Alan Cox");
276MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
277MODULE_LICENSE("GPL");
278MODULE_DEVICE_TABLE(pci, triflex);
279MODULE_VERSION(DRV_VERSION);
280
281module_init(triflex_init);
282module_exit(triflex_exit);