myri10ge: support new firmware counters
[linux-2.6-block.git] / drivers / ata / pata_triflex.c
CommitLineData
669a5db4
JG
1/*
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"
a0fcdc02 46#define DRV_VERSION "0.2.8"
669a5db4
JG
47
48/**
c961922b 49 * triflex_prereset - probe begin
669a5db4
JG
50 * @ap: ATA port
51 *
52 * Set up cable type and use generic probe init
53 */
54
c961922b 55static int triflex_prereset(struct ata_port *ap)
669a5db4
JG
56{
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);
85cd7251 63
c961922b
AC
64 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
65 return -ENOENT;
669a5db4
JG
66 return ata_std_prereset(ap);
67}
68
69
70
71static void triflex_error_handler(struct ata_port *ap)
72{
c961922b 73 ata_bmdma_drive_eh(ap, triflex_prereset, ata_std_softreset, NULL, ata_std_postreset);
669a5db4
JG
74}
75
76/**
77 * triflex_load_timing - timing configuration
78 * @ap: ATA interface
79 * @adev: Device on the bus
80 * @speed: speed to configure
81 *
82 * The Triflex has one set of timings per device per channel. This
83 * means we must do some switching. As the PIO and DMA timings don't
84 * match we have to do some reloading unlike PIIX devices where tuning
85 * tricks can avoid it.
86 */
87
88static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
89{
90 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
91 u32 timing = 0;
92 u32 triflex_timing, old_triflex_timing;
93 int channel_offset = ap->port_no ? 0x74: 0x70;
94 unsigned int is_slave = (adev->devno != 0);
95
96
97 pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
98 triflex_timing = old_triflex_timing;
99
100 switch(speed)
101 {
102 case XFER_MW_DMA_2:
103 timing = 0x0103;break;
104 case XFER_MW_DMA_1:
105 timing = 0x0203;break;
106 case XFER_MW_DMA_0:
107 timing = 0x0808;break;
108 case XFER_SW_DMA_2:
109 case XFER_SW_DMA_1:
110 case XFER_SW_DMA_0:
111 timing = 0x0F0F;break;
112 case XFER_PIO_4:
113 timing = 0x0202;break;
114 case XFER_PIO_3:
115 timing = 0x0204;break;
116 case XFER_PIO_2:
117 timing = 0x0404;break;
118 case XFER_PIO_1:
119 timing = 0x0508;break;
120 case XFER_PIO_0:
121 timing = 0x0808;break;
122 default:
123 BUG();
124 }
125 triflex_timing &= ~ (0xFFFF << (16 * is_slave));
126 triflex_timing |= (timing << (16 * is_slave));
127
128 if (triflex_timing != old_triflex_timing)
129 pci_write_config_dword(pdev, channel_offset, triflex_timing);
130}
131
132/**
133 * triflex_set_piomode - set initial PIO mode data
134 * @ap: ATA interface
135 * @adev: ATA device
136 *
137 * Use the timing loader to set up the PIO mode. We have to do this
138 * because DMA start/stop will only be called once DMA occurs. If there
139 * has been no DMA then the PIO timings are still needed.
140 */
141static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
142{
143 triflex_load_timing(ap, adev, adev->pio_mode);
144}
145
146/**
147 * triflex_dma_start - DMA start callback
148 * @qc: Command in progress
149 *
150 * Usually drivers set the DMA timing at the point the set_dmamode call
151 * is made. Triflex however requires we load new timings on the
152 * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
153 * We load the DMA timings just before starting DMA and then restore
154 * the PIO timing when the DMA is finished.
155 */
156
157static void triflex_bmdma_start(struct ata_queued_cmd *qc)
158{
159 triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
160 ata_bmdma_start(qc);
161}
162
163/**
164 * triflex_dma_stop - DMA stop callback
165 * @ap: ATA interface
166 * @adev: ATA device
167 *
168 * We loaded new timings in dma_start, as a result we need to restore
169 * the PIO timings in dma_stop so that the next command issue gets the
170 * right clock values.
171 */
172
173static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
174{
175 ata_bmdma_stop(qc);
176 triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
177}
178
179static struct scsi_host_template triflex_sht = {
180 .module = THIS_MODULE,
181 .name = DRV_NAME,
182 .ioctl = ata_scsi_ioctl,
183 .queuecommand = ata_scsi_queuecmd,
184 .can_queue = ATA_DEF_QUEUE,
185 .this_id = ATA_SHT_THIS_ID,
186 .sg_tablesize = LIBATA_MAX_PRD,
669a5db4
JG
187 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
188 .emulated = ATA_SHT_EMULATED,
189 .use_clustering = ATA_SHT_USE_CLUSTERING,
190 .proc_name = DRV_NAME,
191 .dma_boundary = ATA_DMA_BOUNDARY,
192 .slave_configure = ata_scsi_slave_config,
afdfe899 193 .slave_destroy = ata_scsi_slave_destroy,
669a5db4 194 .bios_param = ata_std_bios_param,
438ac6d5 195#ifdef CONFIG_PM
30ced0f0
A
196 .resume = ata_scsi_device_resume,
197 .suspend = ata_scsi_device_suspend,
438ac6d5 198#endif
669a5db4
JG
199};
200
201static 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,
205
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,
211
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,
a0fcdc02 216 .cable_detect = ata_cable_40wire,
669a5db4
JG
217
218 .bmdma_setup = ata_bmdma_setup,
219 .bmdma_start = triflex_bmdma_start,
220 .bmdma_stop = triflex_bmdma_stop,
221 .bmdma_status = ata_bmdma_status,
222
223 .qc_prep = ata_qc_prep,
224 .qc_issue = ata_qc_issue_prot,
bda30288 225
0d5ff566 226 .data_xfer = ata_data_xfer,
669a5db4
JG
227
228 .irq_handler = ata_interrupt,
229 .irq_clear = ata_bmdma_irq_clear,
246ce3b6
AI
230 .irq_on = ata_irq_on,
231 .irq_ack = ata_irq_ack,
669a5db4
JG
232
233 .port_start = ata_port_start,
669a5db4
JG
234};
235
236static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
237{
238 static struct ata_port_info info = {
239 .sht = &triflex_sht,
240 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
241 .pio_mask = 0x1f,
242 .mwdma_mask = 0x07,
243 .port_ops = &triflex_port_ops
244 };
245 static struct ata_port_info *port_info[2] = { &info, &info };
246 static int printed_version;
247
248 if (!printed_version++)
249 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n");
250
251 return ata_pci_init_one(dev, port_info, 2);
252}
253
254static const struct pci_device_id triflex[] = {
2d2744fc
JG
255 { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), },
256
257 { },
669a5db4
JG
258};
259
260static struct pci_driver triflex_pci_driver = {
2d2744fc 261 .name = DRV_NAME,
669a5db4
JG
262 .id_table = triflex,
263 .probe = triflex_init_one,
30ced0f0 264 .remove = ata_pci_remove_one,
438ac6d5 265#ifdef CONFIG_PM
30ced0f0
A
266 .suspend = ata_pci_device_suspend,
267 .resume = ata_pci_device_resume,
438ac6d5 268#endif
669a5db4
JG
269};
270
271static int __init triflex_init(void)
272{
273 return pci_register_driver(&triflex_pci_driver);
274}
275
669a5db4
JG
276static void __exit triflex_exit(void)
277{
278 pci_unregister_driver(&triflex_pci_driver);
279}
280
669a5db4
JG
281MODULE_AUTHOR("Alan Cox");
282MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
283MODULE_LICENSE("GPL");
284MODULE_DEVICE_TABLE(pci, triflex);
285MODULE_VERSION(DRV_VERSION);
286
287module_init(triflex_init);
288module_exit(triflex_exit);