1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/pci.h>
22#include <linux/init.h>
23#include <linux/blkdev.h>
24#include <linux/delay.h>
25#include <linux/device.h>
26#include <scsi/scsi_host.h>
27#include <linux/libata.h>
28#include <linux/ata.h>
29
30#define DRV_NAME "pata_artop"
31#define DRV_VERSION "0.4.5"
32
33
34
35
36
37
38
39
40static int clock = 0;
41
42static int artop6210_pre_reset(struct ata_link *link, unsigned long deadline)
43{
44 struct ata_port *ap = link->ap;
45 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
46 const struct pci_bits artop_enable_bits[] = {
47 { 0x4AU, 1U, 0x02UL, 0x02UL },
48 { 0x4AU, 1U, 0x04UL, 0x04UL },
49 };
50
51 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
52 return -ENOENT;
53
54 return ata_sff_prereset(link, deadline);
55}
56
57
58
59
60
61
62
63
64
65
66static int artop6260_pre_reset(struct ata_link *link, unsigned long deadline)
67{
68 static const struct pci_bits artop_enable_bits[] = {
69 { 0x4AU, 1U, 0x02UL, 0x02UL },
70 { 0x4AU, 1U, 0x04UL, 0x04UL },
71 };
72
73 struct ata_port *ap = link->ap;
74 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
75
76
77 if ((pdev->device & 1) &&
78 !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
79 return -ENOENT;
80
81 return ata_sff_prereset(link, deadline);
82}
83
84
85
86
87
88
89
90
91static int artop6260_cable_detect(struct ata_port *ap)
92{
93 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
94 u8 tmp;
95 pci_read_config_byte(pdev, 0x49, &tmp);
96 if (tmp & (1 << ap->port_no))
97 return ATA_CBL_PATA40;
98 return ATA_CBL_PATA80;
99}
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115static void artop6210_load_piomode(struct ata_port *ap, struct ata_device *adev, unsigned int pio)
116{
117 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
118 int dn = adev->devno + 2 * ap->port_no;
119 const u16 timing[2][5] = {
120 { 0x0000, 0x000A, 0x0008, 0x0303, 0x0301 },
121 { 0x0700, 0x070A, 0x0708, 0x0403, 0x0401 }
122
123 };
124
125 pci_write_config_word(pdev, 0x40 + 2 * dn, timing[clock][pio]);
126}
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142static void artop6210_set_piomode(struct ata_port *ap, struct ata_device *adev)
143{
144 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
145 int dn = adev->devno + 2 * ap->port_no;
146 u8 ultra;
147
148 artop6210_load_piomode(ap, adev, adev->pio_mode - XFER_PIO_0);
149
150
151 pci_read_config_byte(pdev, 0x54, &ultra);
152 ultra &= ~(3 << (2 * dn));
153 pci_write_config_byte(pdev, 0x54, ultra);
154}
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169static void artop6260_load_piomode (struct ata_port *ap, struct ata_device *adev, unsigned int pio)
170{
171 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
172 int dn = adev->devno + 2 * ap->port_no;
173 const u8 timing[2][5] = {
174 { 0x00, 0x0A, 0x08, 0x33, 0x31 },
175 { 0x70, 0x7A, 0x78, 0x43, 0x41 }
176
177 };
178
179 pci_write_config_byte(pdev, 0x40 + dn, timing[clock][pio]);
180}
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196static void artop6260_set_piomode(struct ata_port *ap, struct ata_device *adev)
197{
198 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
199 u8 ultra;
200
201 artop6260_load_piomode(ap, adev, adev->pio_mode - XFER_PIO_0);
202
203
204 pci_read_config_byte(pdev, 0x44 + ap->port_no, &ultra);
205 ultra &= ~(7 << (4 * adev->devno));
206 pci_write_config_byte(pdev, 0x44 + ap->port_no, ultra);
207}
208
209
210
211
212
213
214
215
216
217
218
219
220static void artop6210_set_dmamode (struct ata_port *ap, struct ata_device *adev)
221{
222 unsigned int pio;
223 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
224 int dn = adev->devno + 2 * ap->port_no;
225 u8 ultra;
226
227 if (adev->dma_mode == XFER_MW_DMA_0)
228 pio = 1;
229 else
230 pio = 4;
231
232
233 artop6210_load_piomode(ap, adev, pio);
234
235 pci_read_config_byte(pdev, 0x54, &ultra);
236 ultra &= ~(3 << (2 * dn));
237
238
239 if (adev->dma_mode >= XFER_UDMA_0) {
240 u8 mode = (adev->dma_mode - XFER_UDMA_0) + 1 - clock;
241 if (mode == 0)
242 mode = 1;
243 ultra |= (mode << (2 * dn));
244 }
245 pci_write_config_byte(pdev, 0x54, ultra);
246}
247
248
249
250
251
252
253
254
255
256
257
258
259
260static void artop6260_set_dmamode (struct ata_port *ap, struct ata_device *adev)
261{
262 unsigned int pio = adev->pio_mode - XFER_PIO_0;
263 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
264 u8 ultra;
265
266 if (adev->dma_mode == XFER_MW_DMA_0)
267 pio = 1;
268 else
269 pio = 4;
270
271
272 artop6260_load_piomode(ap, adev, pio);
273
274
275 pci_read_config_byte(pdev, 0x44 + ap->port_no, &ultra);
276 ultra &= ~(7 << (4 * adev->devno));
277 if (adev->dma_mode >= XFER_UDMA_0) {
278 u8 mode = adev->dma_mode - XFER_UDMA_0 + 1 - clock;
279 if (mode == 0)
280 mode = 1;
281 ultra |= (mode << (4 * adev->devno));
282 }
283 pci_write_config_byte(pdev, 0x44 + ap->port_no, ultra);
284}
285
286
287
288
289
290
291
292
293static int artop6210_qc_defer(struct ata_queued_cmd *qc)
294{
295 struct ata_host *host = qc->ap->host;
296 struct ata_port *alt = host->ports[1 ^ qc->ap->port_no];
297 int rc;
298
299
300 rc = ata_std_qc_defer(qc);
301 if (rc != 0)
302 return rc;
303
304
305
306 if (alt && alt->qc_active)
307 return ATA_DEFER_PORT;
308 return 0;
309}
310
311static struct scsi_host_template artop_sht = {
312 ATA_BMDMA_SHT(DRV_NAME),
313};
314
315static struct ata_port_operations artop6210_ops = {
316 .inherits = &ata_bmdma_port_ops,
317 .cable_detect = ata_cable_40wire,
318 .set_piomode = artop6210_set_piomode,
319 .set_dmamode = artop6210_set_dmamode,
320 .prereset = artop6210_pre_reset,
321 .qc_defer = artop6210_qc_defer,
322};
323
324static struct ata_port_operations artop6260_ops = {
325 .inherits = &ata_bmdma_port_ops,
326 .cable_detect = artop6260_cable_detect,
327 .set_piomode = artop6260_set_piomode,
328 .set_dmamode = artop6260_set_dmamode,
329 .prereset = artop6260_pre_reset,
330};
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
348{
349 static int printed_version;
350 static const struct ata_port_info info_6210 = {
351 .flags = ATA_FLAG_SLAVE_POSS,
352 .pio_mask = ATA_PIO4,
353 .mwdma_mask = ATA_MWDMA2,
354 .udma_mask = ATA_UDMA2,
355 .port_ops = &artop6210_ops,
356 };
357 static const struct ata_port_info info_626x = {
358 .flags = ATA_FLAG_SLAVE_POSS,
359 .pio_mask = ATA_PIO4,
360 .mwdma_mask = ATA_MWDMA2,
361 .udma_mask = ATA_UDMA4,
362 .port_ops = &artop6260_ops,
363 };
364 static const struct ata_port_info info_628x = {
365 .flags = ATA_FLAG_SLAVE_POSS,
366 .pio_mask = ATA_PIO4,
367 .mwdma_mask = ATA_MWDMA2,
368 .udma_mask = ATA_UDMA5,
369 .port_ops = &artop6260_ops,
370 };
371 static const struct ata_port_info info_628x_fast = {
372 .flags = ATA_FLAG_SLAVE_POSS,
373 .pio_mask = ATA_PIO4,
374 .mwdma_mask = ATA_MWDMA2,
375 .udma_mask = ATA_UDMA6,
376 .port_ops = &artop6260_ops,
377 };
378 const struct ata_port_info *ppi[] = { NULL, NULL };
379 int rc;
380
381 if (!printed_version++)
382 dev_printk(KERN_DEBUG, &pdev->dev,
383 "version " DRV_VERSION "\n");
384
385 rc = pcim_enable_device(pdev);
386 if (rc)
387 return rc;
388
389 if (id->driver_data == 0) {
390 ppi[0] = &info_6210;
391
392 pci_write_config_byte(pdev, 0x54, 0);
393 }
394 else if (id->driver_data == 1)
395 ppi[0] = &info_626x;
396 else if (id->driver_data == 2) {
397 unsigned long io = pci_resource_start(pdev, 4);
398 u8 reg;
399
400 ppi[0] = &info_628x;
401 if (inb(io) & 0x10)
402 ppi[0] = &info_628x_fast;
403
404
405
406
407 pci_read_config_byte(pdev, 0x49, ®);
408 pci_write_config_byte(pdev, 0x49, reg & ~ 0x30);
409
410
411
412
413 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, ®);
414 if (reg <= 0x80)
415 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x90);
416
417
418 pci_read_config_byte(pdev, 0x4a, ®);
419 pci_write_config_byte(pdev, 0x4a, (reg & ~0x01) | 0x80);
420
421 }
422
423 BUG_ON(ppi[0] == NULL);
424
425 return ata_pci_bmdma_init_one(pdev, ppi, &artop_sht, NULL, 0);
426}
427
428static const struct pci_device_id artop_pci_tbl[] = {
429 { PCI_VDEVICE(ARTOP, 0x0005), 0 },
430 { PCI_VDEVICE(ARTOP, 0x0006), 1 },
431 { PCI_VDEVICE(ARTOP, 0x0007), 1 },
432 { PCI_VDEVICE(ARTOP, 0x0008), 2 },
433 { PCI_VDEVICE(ARTOP, 0x0009), 2 },
434
435 { }
436};
437
438static struct pci_driver artop_pci_driver = {
439 .name = DRV_NAME,
440 .id_table = artop_pci_tbl,
441 .probe = artop_init_one,
442 .remove = ata_pci_remove_one,
443};
444
445static int __init artop_init(void)
446{
447 return pci_register_driver(&artop_pci_driver);
448}
449
450static void __exit artop_exit(void)
451{
452 pci_unregister_driver(&artop_pci_driver);
453}
454
455module_init(artop_init);
456module_exit(artop_exit);
457
458MODULE_AUTHOR("Alan Cox");
459MODULE_DESCRIPTION("SCSI low-level driver for ARTOP PATA");
460MODULE_LICENSE("GPL");
461MODULE_DEVICE_TABLE(pci, artop_pci_tbl);
462MODULE_VERSION(DRV_VERSION);
463
464