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