This source file includes following definitions.
- oldpiix_pre_reset
- oldpiix_set_piomode
- oldpiix_set_dmamode
- oldpiix_qc_issue
- oldpiix_init_one
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/pci.h>
20 #include <linux/blkdev.h>
21 #include <linux/delay.h>
22 #include <linux/device.h>
23 #include <scsi/scsi_host.h>
24 #include <linux/libata.h>
25 #include <linux/ata.h>
26
27 #define DRV_NAME "pata_oldpiix"
28 #define DRV_VERSION "0.5.5"
29
30
31
32
33
34
35
36
37
38 static int oldpiix_pre_reset(struct ata_link *link, unsigned long deadline)
39 {
40 struct ata_port *ap = link->ap;
41 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
42 static const struct pci_bits oldpiix_enable_bits[] = {
43 { 0x41U, 1U, 0x80UL, 0x80UL },
44 { 0x43U, 1U, 0x80UL, 0x80UL },
45 };
46
47 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no]))
48 return -ENOENT;
49
50 return ata_sff_prereset(link, deadline);
51 }
52
53
54
55
56
57
58
59
60
61
62
63
64 static void oldpiix_set_piomode (struct ata_port *ap, struct ata_device *adev)
65 {
66 unsigned int pio = adev->pio_mode - XFER_PIO_0;
67 struct pci_dev *dev = to_pci_dev(ap->host->dev);
68 unsigned int idetm_port= ap->port_no ? 0x42 : 0x40;
69 u16 idetm_data;
70 int control = 0;
71
72
73
74
75
76
77
78 static const
79 u8 timings[][2] = { { 0, 0 },
80 { 0, 0 },
81 { 1, 0 },
82 { 2, 1 },
83 { 2, 3 }, };
84
85 if (pio > 1)
86 control |= 1;
87 if (ata_pio_need_iordy(adev))
88 control |= 2;
89
90
91 if (adev->class == ATA_DEV_ATA)
92 control |= 4;
93
94 pci_read_config_word(dev, idetm_port, &idetm_data);
95
96
97
98
99
100 if (adev->devno == 0) {
101 idetm_data &= 0xCCE0;
102 idetm_data |= control;
103 } else {
104 idetm_data &= 0xCC0E;
105 idetm_data |= (control << 4);
106 }
107 idetm_data |= (timings[pio][0] << 12) |
108 (timings[pio][1] << 8);
109 pci_write_config_word(dev, idetm_port, idetm_data);
110
111
112 ap->private_data = adev;
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126 static void oldpiix_set_dmamode (struct ata_port *ap, struct ata_device *adev)
127 {
128 struct pci_dev *dev = to_pci_dev(ap->host->dev);
129 u8 idetm_port = ap->port_no ? 0x42 : 0x40;
130 u16 idetm_data;
131
132 static const
133 u8 timings[][2] = { { 0, 0 },
134 { 0, 0 },
135 { 1, 0 },
136 { 2, 1 },
137 { 2, 3 }, };
138
139
140
141
142
143
144
145 unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
146 unsigned int control;
147 const unsigned int needed_pio[3] = {
148 XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
149 };
150 int pio = needed_pio[mwdma] - XFER_PIO_0;
151
152 pci_read_config_word(dev, idetm_port, &idetm_data);
153
154 control = 3;
155
156 if (adev->class == ATA_DEV_ATA)
157 control |= 4;
158
159
160
161
162 if (adev->pio_mode < needed_pio[mwdma])
163
164 control |= 8;
165
166
167
168 if (adev->devno == 0) {
169 idetm_data &= 0xCCE0;
170 idetm_data |= control;
171 } else {
172 idetm_data &= 0xCC0E;
173 idetm_data |= (control << 4);
174 }
175 idetm_data |= (timings[pio][0] << 12) | (timings[pio][1] << 8);
176 pci_write_config_word(dev, idetm_port, idetm_data);
177
178
179 ap->private_data = adev;
180 }
181
182
183
184
185
186
187
188
189
190
191
192
193 static unsigned int oldpiix_qc_issue(struct ata_queued_cmd *qc)
194 {
195 struct ata_port *ap = qc->ap;
196 struct ata_device *adev = qc->dev;
197
198 if (adev != ap->private_data) {
199 oldpiix_set_piomode(ap, adev);
200 if (ata_dma_enabled(adev))
201 oldpiix_set_dmamode(ap, adev);
202 }
203 return ata_bmdma_qc_issue(qc);
204 }
205
206
207 static struct scsi_host_template oldpiix_sht = {
208 ATA_BMDMA_SHT(DRV_NAME),
209 };
210
211 static struct ata_port_operations oldpiix_pata_ops = {
212 .inherits = &ata_bmdma_port_ops,
213 .qc_issue = oldpiix_qc_issue,
214 .cable_detect = ata_cable_40wire,
215 .set_piomode = oldpiix_set_piomode,
216 .set_dmamode = oldpiix_set_dmamode,
217 .prereset = oldpiix_pre_reset,
218 };
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236 static int oldpiix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
237 {
238 static const struct ata_port_info info = {
239 .flags = ATA_FLAG_SLAVE_POSS,
240 .pio_mask = ATA_PIO4,
241 .mwdma_mask = ATA_MWDMA12_ONLY,
242 .port_ops = &oldpiix_pata_ops,
243 };
244 const struct ata_port_info *ppi[] = { &info, NULL };
245
246 ata_print_version_once(&pdev->dev, DRV_VERSION);
247
248 return ata_pci_bmdma_init_one(pdev, ppi, &oldpiix_sht, NULL, 0);
249 }
250
251 static const struct pci_device_id oldpiix_pci_tbl[] = {
252 { PCI_VDEVICE(INTEL, 0x1230), },
253
254 { }
255 };
256
257 static struct pci_driver oldpiix_pci_driver = {
258 .name = DRV_NAME,
259 .id_table = oldpiix_pci_tbl,
260 .probe = oldpiix_init_one,
261 .remove = ata_pci_remove_one,
262 #ifdef CONFIG_PM_SLEEP
263 .suspend = ata_pci_device_suspend,
264 .resume = ata_pci_device_resume,
265 #endif
266 };
267
268 module_pci_driver(oldpiix_pci_driver);
269
270 MODULE_AUTHOR("Alan Cox");
271 MODULE_DESCRIPTION("SCSI low-level driver for early PIIX series controllers");
272 MODULE_LICENSE("GPL");
273 MODULE_DEVICE_TABLE(pci, oldpiix_pci_tbl);
274 MODULE_VERSION(DRV_VERSION);