1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include <linux/kernel.h>
37#include <linux/module.h>
38#include <linux/pci.h>
39#include <linux/blkdev.h>
40#include <linux/delay.h>
41#include <scsi/scsi_host.h>
42#include <linux/libata.h>
43
44#define DRV_NAME "pata_triflex"
45#define DRV_VERSION "0.2.8"
46
47
48
49
50
51
52
53
54
55static int triflex_prereset(struct ata_link *link, unsigned long deadline)
56{
57 static const struct pci_bits triflex_enable_bits[] = {
58 { 0x80, 1, 0x01, 0x01 },
59 { 0x80, 1, 0x02, 0x02 }
60 };
61
62 struct ata_port *ap = link->ap;
63 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
64
65 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
66 return -ENOENT;
67
68 return ata_sff_prereset(link, deadline);
69}
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85static void triflex_load_timing(struct ata_port *ap, struct ata_device *adev, int speed)
86{
87 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
88 u32 timing = 0;
89 u32 triflex_timing, old_triflex_timing;
90 int channel_offset = ap->port_no ? 0x74: 0x70;
91 unsigned int is_slave = (adev->devno != 0);
92
93
94 pci_read_config_dword(pdev, channel_offset, &old_triflex_timing);
95 triflex_timing = old_triflex_timing;
96
97 switch(speed)
98 {
99 case XFER_MW_DMA_2:
100 timing = 0x0103;break;
101 case XFER_MW_DMA_1:
102 timing = 0x0203;break;
103 case XFER_MW_DMA_0:
104 timing = 0x0808;break;
105 case XFER_SW_DMA_2:
106 case XFER_SW_DMA_1:
107 case XFER_SW_DMA_0:
108 timing = 0x0F0F;break;
109 case XFER_PIO_4:
110 timing = 0x0202;break;
111 case XFER_PIO_3:
112 timing = 0x0204;break;
113 case XFER_PIO_2:
114 timing = 0x0404;break;
115 case XFER_PIO_1:
116 timing = 0x0508;break;
117 case XFER_PIO_0:
118 timing = 0x0808;break;
119 default:
120 BUG();
121 }
122 triflex_timing &= ~ (0xFFFF << (16 * is_slave));
123 triflex_timing |= (timing << (16 * is_slave));
124
125 if (triflex_timing != old_triflex_timing)
126 pci_write_config_dword(pdev, channel_offset, triflex_timing);
127}
128
129
130
131
132
133
134
135
136
137
138static void triflex_set_piomode(struct ata_port *ap, struct ata_device *adev)
139{
140 triflex_load_timing(ap, adev, adev->pio_mode);
141}
142
143
144
145
146
147
148
149
150
151
152
153
154static void triflex_bmdma_start(struct ata_queued_cmd *qc)
155{
156 triflex_load_timing(qc->ap, qc->dev, qc->dev->dma_mode);
157 ata_bmdma_start(qc);
158}
159
160
161
162
163
164
165
166
167
168
169
170static void triflex_bmdma_stop(struct ata_queued_cmd *qc)
171{
172 ata_bmdma_stop(qc);
173 triflex_load_timing(qc->ap, qc->dev, qc->dev->pio_mode);
174}
175
176static struct scsi_host_template triflex_sht = {
177 ATA_BMDMA_SHT(DRV_NAME),
178};
179
180static struct ata_port_operations triflex_port_ops = {
181 .inherits = &ata_bmdma_port_ops,
182 .bmdma_start = triflex_bmdma_start,
183 .bmdma_stop = triflex_bmdma_stop,
184 .cable_detect = ata_cable_40wire,
185 .set_piomode = triflex_set_piomode,
186 .prereset = triflex_prereset,
187};
188
189static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
190{
191 static const struct ata_port_info info = {
192 .flags = ATA_FLAG_SLAVE_POSS,
193 .pio_mask = ATA_PIO4,
194 .mwdma_mask = ATA_MWDMA2,
195 .port_ops = &triflex_port_ops
196 };
197 const struct ata_port_info *ppi[] = { &info, NULL };
198
199 ata_print_version_once(&dev->dev, DRV_VERSION);
200
201 return ata_pci_bmdma_init_one(dev, ppi, &triflex_sht, NULL, 0);
202}
203
204static const struct pci_device_id triflex[] = {
205 { PCI_VDEVICE(COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE), },
206
207 { },
208};
209
210#ifdef CONFIG_PM_SLEEP
211static int triflex_ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
212{
213 struct ata_host *host = pci_get_drvdata(pdev);
214 int rc = 0;
215
216 rc = ata_host_suspend(host, mesg);
217 if (rc)
218 return rc;
219
220
221
222
223
224 pci_save_state(pdev);
225
226 return 0;
227}
228
229#endif
230
231static struct pci_driver triflex_pci_driver = {
232 .name = DRV_NAME,
233 .id_table = triflex,
234 .probe = triflex_init_one,
235 .remove = ata_pci_remove_one,
236#ifdef CONFIG_PM_SLEEP
237 .suspend = triflex_ata_pci_device_suspend,
238 .resume = ata_pci_device_resume,
239#endif
240};
241
242module_pci_driver(triflex_pci_driver);
243
244MODULE_AUTHOR("Alan Cox");
245MODULE_DESCRIPTION("low-level driver for Compaq Triflex");
246MODULE_LICENSE("GPL");
247MODULE_DEVICE_TABLE(pci, triflex);
248MODULE_VERSION(DRV_VERSION);
249