blob: 510569957d10fdd295cfa553a257040969aa3d96 [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"
Jeff Garzika0fcdc02007-03-09 07:24:15 -050046#define DRV_VERSION "0.2.8"
Jeff Garzik669a5db2006-08-29 18:12:40 -040047
48/**
Alan Coxc9619222006-09-26 17:53:38 +010049 * triflex_prereset - probe begin
Tejun Heocc0680a2007-08-06 18:36:23 +090050 * @link: ATA link
Tejun Heod4b2bab2007-02-02 16:50:52 +090051 * @deadline: deadline jiffies for the operation
Jeff Garzik669a5db2006-08-29 18:12:40 -040052 *
53 * Set up cable type and use generic probe init
54 */
55
Tejun Heocc0680a2007-08-06 18:36:23 +090056static int triflex_prereset(struct ata_link *link, unsigned long deadline)
Jeff Garzik669a5db2006-08-29 18:12:40 -040057{
58 static const struct pci_bits triflex_enable_bits[] = {
59 { 0x80, 1, 0x01, 0x01 },
60 { 0x80, 1, 0x02, 0x02 }
61 };
62
Tejun Heocc0680a2007-08-06 18:36:23 +090063 struct ata_port *ap = link->ap;
Jeff Garzik669a5db2006-08-29 18:12:40 -040064 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Jeff Garzik85cd7252006-08-31 00:03:49 -040065
Alan Coxc9619222006-09-26 17:53:38 +010066 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
67 return -ENOENT;
Tejun Heod4b2bab2007-02-02 16:50:52 +090068
Tejun Heocc0680a2007-08-06 18:36:23 +090069 return ata_std_prereset(link, deadline);
Jeff Garzik669a5db2006-08-29 18:12:40 -040070}
71
72
73
74static void triflex_error_handler(struct ata_port *ap)
75{
Alan Coxc9619222006-09-26 17:53:38 +010076 ata_bmdma_drive_eh(ap, triflex_prereset, ata_std_softreset, NULL, ata_std_postreset);
Jeff Garzik669a5db2006-08-29 18:12:40 -040077}
78
79/**
80 * triflex_load_timing - timing configuration
81 * @ap: ATA interface
82 * @adev: Device on the bus
83 * @speed: speed to configure
84 *
85 * The Triflex has one set of timings per device per channel. This
86 * means we must do some switching. As the PIO and DMA timings don't
87 * match we have to do some reloading unlike PIIX devices where tuning
88 * tricks can avoid it.
89 */
90
91static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
92{
93 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
94 u32 timing = 0;
95 u32 triflex_timing, old_triflex_timing;
96 int channel_offset = ap->port_no ? 0x74: 0x70;
97 unsigned int is_slave = (adev->devno != 0);
98
99
100 pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
101 triflex_timing = old_triflex_timing;
102
103 switch(speed)
104 {
105 case XFER_MW_DMA_2:
106 timing = 0x0103;break;
107 case XFER_MW_DMA_1:
108 timing = 0x0203;break;
109 case XFER_MW_DMA_0:
110 timing = 0x0808;break;
111 case XFER_SW_DMA_2:
112 case XFER_SW_DMA_1:
113 case XFER_SW_DMA_0:
114 timing = 0x0F0F;break;
115 case XFER_PIO_4:
116 timing = 0x0202;break;
117 case XFER_PIO_3:
118 timing = 0x0204;break;
119 case XFER_PIO_2:
120 timing = 0x0404;break;
121 case XFER_PIO_1:
122 timing = 0x0508;break;
123 case XFER_PIO_0:
124 timing = 0x0808;break;
125 default:
126 BUG();
127 }
128 triflex_timing &= ~ (0xFFFF << (16 * is_slave));
129 triflex_timing |= (timing << (16 * is_slave));
130
131 if (triflex_timing != old_triflex_timing)
132 pci_write_config_dword(pdev, channel_offset, triflex_timing);
133}
134
135/**
136 * triflex_set_piomode - set initial PIO mode data
137 * @ap: ATA interface
138 * @adev: ATA device
139 *
140 * Use the timing loader to set up the PIO mode. We have to do this
141 * because DMA start/stop will only be called once DMA occurs. If there
142 * has been no DMA then the PIO timings are still needed.
143 */
144static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
145{
146 triflex_load_timing(ap, adev, adev->pio_mode);
147}
148
149/**
150 * triflex_dma_start - DMA start callback
151 * @qc: Command in progress
152 *
153 * Usually drivers set the DMA timing at the point the set_dmamode call
154 * is made. Triflex however requires we load new timings on the
155 * transition or keep matching PIO/DMA pairs (ie MWDMA2/PIO4 etc).
156 * We load the DMA timings just before starting DMA and then restore
157 * the PIO timing when the DMA is finished.
158 */
159
160static void triflex_bmdma_start(struct ata_queued_cmd *qc)
161{
162 triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
163 ata_bmdma_start(qc);
164}
165
166/**
167 * triflex_dma_stop - DMA stop callback
168 * @ap: ATA interface
169 * @adev: ATA device
170 *
171 * We loaded new timings in dma_start, as a result we need to restore
172 * the PIO timings in dma_stop so that the next command issue gets the
173 * right clock values.
174 */
175
176static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
177{
178 ata_bmdma_stop(qc);
179 triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
180}
181
182static struct scsi_host_template triflex_sht = {
Tejun Heo68d1d072008-03-25 12:22:49 +0900183 ATA_BMDMA_SHT(DRV_NAME),
Jeff Garzik669a5db2006-08-29 18:12:40 -0400184};
185
186static struct ata_port_operations triflex_port_ops = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400187 .set_piomode = triflex_set_piomode,
188 .mode_filter = ata_pci_default_filter,
189
190 .tf_load = ata_tf_load,
191 .tf_read = ata_tf_read,
192 .check_status = ata_check_status,
193 .exec_command = ata_exec_command,
194 .dev_select = ata_std_dev_select,
195
196 .freeze = ata_bmdma_freeze,
197 .thaw = ata_bmdma_thaw,
198 .error_handler = triflex_error_handler,
199 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Jeff Garzika0fcdc02007-03-09 07:24:15 -0500200 .cable_detect = ata_cable_40wire,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400201
202 .bmdma_setup = ata_bmdma_setup,
203 .bmdma_start = triflex_bmdma_start,
204 .bmdma_stop = triflex_bmdma_stop,
205 .bmdma_status = ata_bmdma_status,
206
207 .qc_prep = ata_qc_prep,
208 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400209
Tejun Heo0d5ff562007-02-01 15:06:36 +0900210 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400211
212 .irq_handler = ata_interrupt,
213 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900214 .irq_on = ata_irq_on,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400215
Alan Cox81ad1832007-08-22 22:55:41 +0100216 .port_start = ata_sff_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400217};
218
219static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
220{
Tejun Heo1626aeb2007-05-04 12:43:58 +0200221 static const struct ata_port_info info = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400222 .sht = &triflex_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400223 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400224 .pio_mask = 0x1f,
225 .mwdma_mask = 0x07,
226 .port_ops = &triflex_port_ops
227 };
Tejun Heo1626aeb2007-05-04 12:43:58 +0200228 const struct ata_port_info *ppi[] = { &info, NULL };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400229 static int printed_version;
230
231 if (!printed_version++)
232 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n");
233
Tejun Heo1626aeb2007-05-04 12:43:58 +0200234 return ata_pci_init_one(dev, ppi);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400235}
236
237static const struct pci_device_id triflex[] = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400238 { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), },
239
240 { },
Jeff Garzik669a5db2006-08-29 18:12:40 -0400241};
242
243static struct pci_driver triflex_pci_driver = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400244 .name = DRV_NAME,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400245 .id_table = triflex,
246 .probe = triflex_init_one,
Alan30ced0f2006-11-22 16:57:36 +0000247 .remove = ata_pci_remove_one,
Tejun Heo438ac6d2007-03-02 17:31:26 +0900248#ifdef CONFIG_PM
Alan30ced0f2006-11-22 16:57:36 +0000249 .suspend = ata_pci_device_suspend,
250 .resume = ata_pci_device_resume,
Tejun Heo438ac6d2007-03-02 17:31:26 +0900251#endif
Jeff Garzik669a5db2006-08-29 18:12:40 -0400252};
253
254static int __init triflex_init(void)
255{
256 return pci_register_driver(&triflex_pci_driver);
257}
258
Jeff Garzik669a5db2006-08-29 18:12:40 -0400259static void __exit triflex_exit(void)
260{
261 pci_unregister_driver(&triflex_pci_driver);
262}
263
Jeff Garzik669a5db2006-08-29 18:12:40 -0400264MODULE_AUTHOR("Alan Cox");
265MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
266MODULE_LICENSE("GPL");
267MODULE_DEVICE_TABLE(pci, triflex);
268MODULE_VERSION(DRV_VERSION);
269
270module_init(triflex_init);
271module_exit(triflex_exit);