blob: d9571206e580166cc41b2de872b94d3d61bf2cbf [file] [log] [blame]
Jeff Garzik669a5db2006-08-29 18:12:40 -04001/*
2 * pata_amd.c - AMD PATA for new ATA layer
3 * (C) 2005-2006 Red Hat Inc
4 * Alan Cox <alan@redhat.com>
5 *
6 * Based on pata-sil680. Errata information is taken from data sheets
7 * and the amd74xx.c driver by Vojtech Pavlik. Nvidia SATA devices are
8 * claimed by sata-nv.c.
9 *
10 * TODO:
11 * Variable system clock when/if it makes sense
12 * Power management on ports
13 *
14 *
15 * Documentation publically available.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/pci.h>
21#include <linux/init.h>
22#include <linux/blkdev.h>
23#include <linux/delay.h>
24#include <scsi/scsi_host.h>
25#include <linux/libata.h>
26
27#define DRV_NAME "pata_amd"
Alanc3041932006-11-27 16:21:24 +000028#define DRV_VERSION "0.2.7"
Jeff Garzik669a5db2006-08-29 18:12:40 -040029
30/**
31 * timing_setup - shared timing computation and load
32 * @ap: ATA port being set up
33 * @adev: drive being configured
34 * @offset: port offset
35 * @speed: target speed
36 * @clock: clock multiplier (number of times 33MHz for this part)
37 *
38 * Perform the actual timing set up for Nvidia or AMD PATA devices.
39 * The actual devices vary so they all call into this helper function
40 * providing the clock multipler and offset (because AMD and Nvidia put
41 * the ports at different locations).
42 */
43
44static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offset, int speed, int clock)
45{
46 static const unsigned char amd_cyc2udma[] = {
47 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7
48 };
49
50 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
51 struct ata_device *peer = ata_dev_pair(adev);
52 int dn = ap->port_no * 2 + adev->devno;
53 struct ata_timing at, apeer;
54 int T, UT;
55 const int amd_clock = 33333; /* KHz. */
56 u8 t;
57
58 T = 1000000000 / amd_clock;
59 UT = T / min_t(int, max_t(int, clock, 1), 2);
60
61 if (ata_timing_compute(adev, speed, &at, T, UT) < 0) {
62 dev_printk(KERN_ERR, &pdev->dev, "unknown mode %d.\n", speed);
63 return;
64 }
65
66 if (peer) {
67 /* This may be over conservative */
68 if (peer->dma_mode) {
69 ata_timing_compute(peer, peer->dma_mode, &apeer, T, UT);
70 ata_timing_merge(&apeer, &at, &at, ATA_TIMING_8BIT);
71 }
72 ata_timing_compute(peer, peer->pio_mode, &apeer, T, UT);
73 ata_timing_merge(&apeer, &at, &at, ATA_TIMING_8BIT);
74 }
75
76 if (speed == XFER_UDMA_5 && amd_clock <= 33333) at.udma = 1;
77 if (speed == XFER_UDMA_6 && amd_clock <= 33333) at.udma = 15;
78
79 /*
80 * Now do the setup work
81 */
82
83 /* Configure the address set up timing */
84 pci_read_config_byte(pdev, offset + 0x0C, &t);
85 t = (t & ~(3 << ((3 - dn) << 1))) | ((FIT(at.setup, 1, 4) - 1) << ((3 - dn) << 1));
86 pci_write_config_byte(pdev, offset + 0x0C , t);
87
88 /* Configure the 8bit I/O timing */
89 pci_write_config_byte(pdev, offset + 0x0E + (1 - (dn >> 1)),
90 ((FIT(at.act8b, 1, 16) - 1) << 4) | (FIT(at.rec8b, 1, 16) - 1));
91
92 /* Drive timing */
93 pci_write_config_byte(pdev, offset + 0x08 + (3 - dn),
94 ((FIT(at.active, 1, 16) - 1) << 4) | (FIT(at.recover, 1, 16) - 1));
95
96 switch (clock) {
97 case 1:
98 t = at.udma ? (0xc0 | (FIT(at.udma, 2, 5) - 2)) : 0x03;
99 break;
100
101 case 2:
102 t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 2, 10)]) : 0x03;
103 break;
104
105 case 3:
106 t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 1, 10)]) : 0x03;
107 break;
108
109 case 4:
110 t = at.udma ? (0xc0 | amd_cyc2udma[FIT(at.udma, 1, 15)]) : 0x03;
111 break;
112
113 default:
114 return;
115 }
116
117 /* UDMA timing */
118 pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t);
119}
120
121/**
122 * amd_probe_init - cable detection
123 * @ap: ATA port
124 *
125 * Perform cable detection. The BIOS stores this in PCI config
126 * space for us.
127 */
128
129static int amd_pre_reset(struct ata_port *ap)
130{
131 static const u32 bitmask[2] = {0x03, 0xC0};
132 static const struct pci_bits amd_enable_bits[] = {
133 { 0x40, 1, 0x02, 0x02 },
134 { 0x40, 1, 0x01, 0x01 }
135 };
136
137 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
138 u8 ata66;
Jeff Garzik85cd7252006-08-31 00:03:49 -0400139
Alan Coxc9619222006-09-26 17:53:38 +0100140 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
141 return -ENOENT;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400142
143 pci_read_config_byte(pdev, 0x42, &ata66);
144 if (ata66 & bitmask[ap->port_no])
145 ap->cbl = ATA_CBL_PATA80;
146 else
147 ap->cbl = ATA_CBL_PATA40;
148 return ata_std_prereset(ap);
149
150}
151
152static void amd_error_handler(struct ata_port *ap)
153{
154 return ata_bmdma_drive_eh(ap, amd_pre_reset,
155 ata_std_softreset, NULL,
156 ata_std_postreset);
157}
158
159static int amd_early_pre_reset(struct ata_port *ap)
160{
161 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
162 static struct pci_bits amd_enable_bits[] = {
163 { 0x40, 1, 0x02, 0x02 },
164 { 0x40, 1, 0x01, 0x01 }
165 };
166
Alan Coxc9619222006-09-26 17:53:38 +0100167 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
168 return -ENOENT;
169
Jeff Garzik669a5db2006-08-29 18:12:40 -0400170 /* No host side cable detection */
171 ap->cbl = ATA_CBL_PATA80;
172 return ata_std_prereset(ap);
173
174}
175
176static void amd_early_error_handler(struct ata_port *ap)
177{
178 ata_bmdma_drive_eh(ap, amd_early_pre_reset,
179 ata_std_softreset, NULL,
180 ata_std_postreset);
181}
182
183/**
184 * amd33_set_piomode - set initial PIO mode data
185 * @ap: ATA interface
186 * @adev: ATA device
187 *
188 * Program the AMD registers for PIO mode.
189 */
190
191static void amd33_set_piomode(struct ata_port *ap, struct ata_device *adev)
192{
193 timing_setup(ap, adev, 0x40, adev->pio_mode, 1);
194}
195
196static void amd66_set_piomode(struct ata_port *ap, struct ata_device *adev)
197{
198 timing_setup(ap, adev, 0x40, adev->pio_mode, 2);
199}
200
201static void amd100_set_piomode(struct ata_port *ap, struct ata_device *adev)
202{
203 timing_setup(ap, adev, 0x40, adev->pio_mode, 3);
204}
205
206static void amd133_set_piomode(struct ata_port *ap, struct ata_device *adev)
207{
208 timing_setup(ap, adev, 0x40, adev->pio_mode, 4);
209}
210
211/**
212 * amd33_set_dmamode - set initial DMA mode data
213 * @ap: ATA interface
214 * @adev: ATA device
215 *
216 * Program the MWDMA/UDMA modes for the AMD and Nvidia
217 * chipset.
218 */
219
220static void amd33_set_dmamode(struct ata_port *ap, struct ata_device *adev)
221{
222 timing_setup(ap, adev, 0x40, adev->dma_mode, 1);
223}
224
225static void amd66_set_dmamode(struct ata_port *ap, struct ata_device *adev)
226{
227 timing_setup(ap, adev, 0x40, adev->dma_mode, 2);
228}
229
230static void amd100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
231{
232 timing_setup(ap, adev, 0x40, adev->dma_mode, 3);
233}
234
235static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
236{
237 timing_setup(ap, adev, 0x40, adev->dma_mode, 4);
238}
239
240
241/**
242 * nv_probe_init - cable detection
243 * @ap: ATA port
244 *
245 * Perform cable detection. The BIOS stores this in PCI config
246 * space for us.
247 */
248
249static int nv_pre_reset(struct ata_port *ap) {
250 static const u8 bitmask[2] = {0x03, 0xC0};
Alan Cox76ff3c62006-09-12 17:14:03 +0100251 static const struct pci_bits nv_enable_bits[] = {
252 { 0x50, 1, 0x02, 0x02 },
253 { 0x50, 1, 0x01, 0x01 }
254 };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400255
256 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
257 u8 ata66;
258 u16 udma;
259
Alan Coxc9619222006-09-26 17:53:38 +0100260 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
261 return -ENOENT;
Alan Cox76ff3c62006-09-12 17:14:03 +0100262
Jeff Garzik669a5db2006-08-29 18:12:40 -0400263 pci_read_config_byte(pdev, 0x52, &ata66);
264 if (ata66 & bitmask[ap->port_no])
265 ap->cbl = ATA_CBL_PATA80;
266 else
267 ap->cbl = ATA_CBL_PATA40;
268
269 /* We now have to double check because the Nvidia boxes BIOS
270 doesn't always set the cable bits but does set mode bits */
271
272 pci_read_config_word(pdev, 0x62 - 2 * ap->port_no, &udma);
273 if ((udma & 0xC4) == 0xC4 || (udma & 0xC400) == 0xC400)
274 ap->cbl = ATA_CBL_PATA80;
275 return ata_std_prereset(ap);
276}
277
278static void nv_error_handler(struct ata_port *ap)
279{
280 ata_bmdma_drive_eh(ap, nv_pre_reset,
281 ata_std_softreset, NULL,
282 ata_std_postreset);
283}
284/**
285 * nv100_set_piomode - set initial PIO mode data
286 * @ap: ATA interface
287 * @adev: ATA device
288 *
289 * Program the AMD registers for PIO mode.
290 */
291
292static void nv100_set_piomode(struct ata_port *ap, struct ata_device *adev)
293{
294 timing_setup(ap, adev, 0x50, adev->pio_mode, 3);
295}
296
297static void nv133_set_piomode(struct ata_port *ap, struct ata_device *adev)
298{
299 timing_setup(ap, adev, 0x50, adev->pio_mode, 4);
300}
301
302/**
303 * nv100_set_dmamode - set initial DMA mode data
304 * @ap: ATA interface
305 * @adev: ATA device
306 *
307 * Program the MWDMA/UDMA modes for the AMD and Nvidia
308 * chipset.
309 */
310
311static void nv100_set_dmamode(struct ata_port *ap, struct ata_device *adev)
312{
313 timing_setup(ap, adev, 0x50, adev->dma_mode, 3);
314}
315
316static void nv133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
317{
318 timing_setup(ap, adev, 0x50, adev->dma_mode, 4);
319}
320
321static struct scsi_host_template amd_sht = {
322 .module = THIS_MODULE,
323 .name = DRV_NAME,
324 .ioctl = ata_scsi_ioctl,
325 .queuecommand = ata_scsi_queuecmd,
326 .can_queue = ATA_DEF_QUEUE,
327 .this_id = ATA_SHT_THIS_ID,
328 .sg_tablesize = LIBATA_MAX_PRD,
329 .max_sectors = ATA_MAX_SECTORS,
330 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
331 .emulated = ATA_SHT_EMULATED,
332 .use_clustering = ATA_SHT_USE_CLUSTERING,
333 .proc_name = DRV_NAME,
334 .dma_boundary = ATA_DMA_BOUNDARY,
335 .slave_configure = ata_scsi_slave_config,
Tejun Heoafdfe892006-11-29 11:26:47 +0900336 .slave_destroy = ata_scsi_slave_destroy,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400337 .bios_param = ata_std_bios_param,
Alanc3041932006-11-27 16:21:24 +0000338 .resume = ata_scsi_device_resume,
339 .suspend = ata_scsi_device_suspend,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400340};
341
342static struct ata_port_operations amd33_port_ops = {
343 .port_disable = ata_port_disable,
344 .set_piomode = amd33_set_piomode,
345 .set_dmamode = amd33_set_dmamode,
346 .mode_filter = ata_pci_default_filter,
347 .tf_load = ata_tf_load,
348 .tf_read = ata_tf_read,
349 .check_status = ata_check_status,
350 .exec_command = ata_exec_command,
351 .dev_select = ata_std_dev_select,
352
353 .freeze = ata_bmdma_freeze,
354 .thaw = ata_bmdma_thaw,
355 .error_handler = amd_early_error_handler,
356 .post_internal_cmd = ata_bmdma_post_internal_cmd,
357
358 .bmdma_setup = ata_bmdma_setup,
359 .bmdma_start = ata_bmdma_start,
360 .bmdma_stop = ata_bmdma_stop,
361 .bmdma_status = ata_bmdma_status,
362
363 .qc_prep = ata_qc_prep,
364 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400365
Jeff Garzik669a5db2006-08-29 18:12:40 -0400366 .data_xfer = ata_pio_data_xfer,
367
368 .irq_handler = ata_interrupt,
369 .irq_clear = ata_bmdma_irq_clear,
370
371 .port_start = ata_port_start,
372 .port_stop = ata_port_stop,
373 .host_stop = ata_host_stop
374};
375
376static struct ata_port_operations amd66_port_ops = {
377 .port_disable = ata_port_disable,
378 .set_piomode = amd66_set_piomode,
379 .set_dmamode = amd66_set_dmamode,
380 .mode_filter = ata_pci_default_filter,
381 .tf_load = ata_tf_load,
382 .tf_read = ata_tf_read,
383 .check_status = ata_check_status,
384 .exec_command = ata_exec_command,
385 .dev_select = ata_std_dev_select,
386
387 .freeze = ata_bmdma_freeze,
388 .thaw = ata_bmdma_thaw,
389 .error_handler = amd_early_error_handler,
390 .post_internal_cmd = ata_bmdma_post_internal_cmd,
391
392 .bmdma_setup = ata_bmdma_setup,
393 .bmdma_start = ata_bmdma_start,
394 .bmdma_stop = ata_bmdma_stop,
395 .bmdma_status = ata_bmdma_status,
396
397 .qc_prep = ata_qc_prep,
398 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400399
Jeff Garzik669a5db2006-08-29 18:12:40 -0400400 .data_xfer = ata_pio_data_xfer,
401
402 .irq_handler = ata_interrupt,
403 .irq_clear = ata_bmdma_irq_clear,
404
405 .port_start = ata_port_start,
406 .port_stop = ata_port_stop,
407 .host_stop = ata_host_stop
408};
409
410static struct ata_port_operations amd100_port_ops = {
411 .port_disable = ata_port_disable,
412 .set_piomode = amd100_set_piomode,
413 .set_dmamode = amd100_set_dmamode,
414 .mode_filter = ata_pci_default_filter,
415 .tf_load = ata_tf_load,
416 .tf_read = ata_tf_read,
417 .check_status = ata_check_status,
418 .exec_command = ata_exec_command,
419 .dev_select = ata_std_dev_select,
420
421 .freeze = ata_bmdma_freeze,
422 .thaw = ata_bmdma_thaw,
423 .error_handler = amd_error_handler,
424 .post_internal_cmd = ata_bmdma_post_internal_cmd,
425
426 .bmdma_setup = ata_bmdma_setup,
427 .bmdma_start = ata_bmdma_start,
428 .bmdma_stop = ata_bmdma_stop,
429 .bmdma_status = ata_bmdma_status,
430
431 .qc_prep = ata_qc_prep,
432 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400433
Jeff Garzik669a5db2006-08-29 18:12:40 -0400434 .data_xfer = ata_pio_data_xfer,
435
436 .irq_handler = ata_interrupt,
437 .irq_clear = ata_bmdma_irq_clear,
438
439 .port_start = ata_port_start,
440 .port_stop = ata_port_stop,
441 .host_stop = ata_host_stop
442};
443
444static struct ata_port_operations amd133_port_ops = {
445 .port_disable = ata_port_disable,
446 .set_piomode = amd133_set_piomode,
447 .set_dmamode = amd133_set_dmamode,
448 .mode_filter = ata_pci_default_filter,
449 .tf_load = ata_tf_load,
450 .tf_read = ata_tf_read,
451 .check_status = ata_check_status,
452 .exec_command = ata_exec_command,
453 .dev_select = ata_std_dev_select,
454
455 .freeze = ata_bmdma_freeze,
456 .thaw = ata_bmdma_thaw,
457 .error_handler = amd_error_handler,
458 .post_internal_cmd = ata_bmdma_post_internal_cmd,
459
460 .bmdma_setup = ata_bmdma_setup,
461 .bmdma_start = ata_bmdma_start,
462 .bmdma_stop = ata_bmdma_stop,
463 .bmdma_status = ata_bmdma_status,
464
465 .qc_prep = ata_qc_prep,
466 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400467
Jeff Garzik669a5db2006-08-29 18:12:40 -0400468 .data_xfer = ata_pio_data_xfer,
469
470 .irq_handler = ata_interrupt,
471 .irq_clear = ata_bmdma_irq_clear,
472
473 .port_start = ata_port_start,
474 .port_stop = ata_port_stop,
475 .host_stop = ata_host_stop
476};
477
478static struct ata_port_operations nv100_port_ops = {
479 .port_disable = ata_port_disable,
480 .set_piomode = nv100_set_piomode,
481 .set_dmamode = nv100_set_dmamode,
482 .mode_filter = ata_pci_default_filter,
483 .tf_load = ata_tf_load,
484 .tf_read = ata_tf_read,
485 .check_status = ata_check_status,
486 .exec_command = ata_exec_command,
487 .dev_select = ata_std_dev_select,
488
489 .freeze = ata_bmdma_freeze,
490 .thaw = ata_bmdma_thaw,
491 .error_handler = nv_error_handler,
492 .post_internal_cmd = ata_bmdma_post_internal_cmd,
493
494 .bmdma_setup = ata_bmdma_setup,
495 .bmdma_start = ata_bmdma_start,
496 .bmdma_stop = ata_bmdma_stop,
497 .bmdma_status = ata_bmdma_status,
498
499 .qc_prep = ata_qc_prep,
500 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400501
Jeff Garzik669a5db2006-08-29 18:12:40 -0400502 .data_xfer = ata_pio_data_xfer,
503
504 .irq_handler = ata_interrupt,
505 .irq_clear = ata_bmdma_irq_clear,
506
507 .port_start = ata_port_start,
508 .port_stop = ata_port_stop,
509 .host_stop = ata_host_stop
510};
511
512static struct ata_port_operations nv133_port_ops = {
513 .port_disable = ata_port_disable,
514 .set_piomode = nv133_set_piomode,
515 .set_dmamode = nv133_set_dmamode,
516 .mode_filter = ata_pci_default_filter,
517 .tf_load = ata_tf_load,
518 .tf_read = ata_tf_read,
519 .check_status = ata_check_status,
520 .exec_command = ata_exec_command,
521 .dev_select = ata_std_dev_select,
522
523 .freeze = ata_bmdma_freeze,
524 .thaw = ata_bmdma_thaw,
525 .error_handler = nv_error_handler,
526 .post_internal_cmd = ata_bmdma_post_internal_cmd,
527
528 .bmdma_setup = ata_bmdma_setup,
529 .bmdma_start = ata_bmdma_start,
530 .bmdma_stop = ata_bmdma_stop,
531 .bmdma_status = ata_bmdma_status,
532
533 .qc_prep = ata_qc_prep,
534 .qc_issue = ata_qc_issue_prot,
Jeff Garzikbda30282006-09-27 05:41:13 -0400535
Jeff Garzik669a5db2006-08-29 18:12:40 -0400536 .data_xfer = ata_pio_data_xfer,
537
538 .irq_handler = ata_interrupt,
539 .irq_clear = ata_bmdma_irq_clear,
540
541 .port_start = ata_port_start,
542 .port_stop = ata_port_stop,
543 .host_stop = ata_host_stop
544};
545
546static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
547{
548 static struct ata_port_info info[10] = {
549 { /* 0: AMD 7401 */
550 .sht = &amd_sht,
551 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
552 .pio_mask = 0x1f,
553 .mwdma_mask = 0x07, /* No SWDMA */
554 .udma_mask = 0x07, /* UDMA 33 */
555 .port_ops = &amd33_port_ops
556 },
557 { /* 1: Early AMD7409 - no swdma */
558 .sht = &amd_sht,
559 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
560 .pio_mask = 0x1f,
561 .mwdma_mask = 0x07,
562 .udma_mask = 0x1f, /* UDMA 66 */
563 .port_ops = &amd66_port_ops
564 },
565 { /* 2: AMD 7409, no swdma errata */
566 .sht = &amd_sht,
567 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
568 .pio_mask = 0x1f,
569 .mwdma_mask = 0x07,
570 .udma_mask = 0x1f, /* UDMA 66 */
571 .port_ops = &amd66_port_ops
572 },
573 { /* 3: AMD 7411 */
574 .sht = &amd_sht,
575 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
576 .pio_mask = 0x1f,
577 .mwdma_mask = 0x07,
578 .udma_mask = 0x3f, /* UDMA 100 */
579 .port_ops = &amd100_port_ops
580 },
581 { /* 4: AMD 7441 */
582 .sht = &amd_sht,
583 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
584 .pio_mask = 0x1f,
585 .mwdma_mask = 0x07,
586 .udma_mask = 0x3f, /* UDMA 100 */
587 .port_ops = &amd100_port_ops
588 },
589 { /* 5: AMD 8111*/
590 .sht = &amd_sht,
591 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
592 .pio_mask = 0x1f,
593 .mwdma_mask = 0x07,
594 .udma_mask = 0x7f, /* UDMA 133, no swdma */
595 .port_ops = &amd133_port_ops
596 },
597 { /* 6: AMD 8111 UDMA 100 (Serenade) */
598 .sht = &amd_sht,
599 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
600 .pio_mask = 0x1f,
601 .mwdma_mask = 0x07,
602 .udma_mask = 0x3f, /* UDMA 100, no swdma */
603 .port_ops = &amd133_port_ops
604 },
605 { /* 7: Nvidia Nforce */
606 .sht = &amd_sht,
607 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
608 .pio_mask = 0x1f,
609 .mwdma_mask = 0x07,
610 .udma_mask = 0x3f, /* UDMA 100 */
611 .port_ops = &nv100_port_ops
612 },
613 { /* 8: Nvidia Nforce2 and later */
614 .sht = &amd_sht,
615 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
616 .pio_mask = 0x1f,
617 .mwdma_mask = 0x07,
618 .udma_mask = 0x7f, /* UDMA 133, no swdma */
619 .port_ops = &nv133_port_ops
620 },
621 { /* 9: AMD CS5536 (Geode companion) */
622 .sht = &amd_sht,
623 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
624 .pio_mask = 0x1f,
625 .mwdma_mask = 0x07,
626 .udma_mask = 0x3f, /* UDMA 100 */
627 .port_ops = &amd100_port_ops
628 }
629 };
630 static struct ata_port_info *port_info[2];
631 static int printed_version;
632 int type = id->driver_data;
633 u8 rev;
634 u8 fifo;
635
636 if (!printed_version++)
637 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
638
639 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
640 pci_read_config_byte(pdev, 0x41, &fifo);
641
642 /* Check for AMD7409 without swdma errata and if found adjust type */
643 if (type == 1 && rev > 0x7)
644 type = 2;
645
646 /* Check for AMD7411 */
647 if (type == 3)
648 /* FIFO is broken */
649 pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
650 else
651 pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
652
653 /* Serenade ? */
654 if (type == 5 && pdev->subsystem_vendor == PCI_VENDOR_ID_AMD &&
655 pdev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE)
656 type = 6; /* UDMA 100 only */
657
658 if (type < 3)
659 ata_pci_clear_simplex(pdev);
660
661 /* And fire it up */
662
663 port_info[0] = port_info[1] = &info[type];
664 return ata_pci_init_one(pdev, port_info, 2);
665}
666
Alanc3041932006-11-27 16:21:24 +0000667static int amd_reinit_one(struct pci_dev *pdev)
668{
669 if (pdev->vendor == PCI_VENDOR_ID_AMD) {
670 u8 fifo;
671 pci_read_config_byte(pdev, 0x41, &fifo);
672 if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7411)
673 /* FIFO is broken */
674 pci_write_config_byte(pdev, 0x41, fifo & 0x0F);
675 else
676 pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
677 if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 ||
678 pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
679 ata_pci_clear_simplex(pdev);
680 }
681 return ata_pci_device_resume(pdev);
682}
683
Jeff Garzik669a5db2006-08-29 18:12:40 -0400684static const struct pci_device_id amd[] = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400685 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_COBRA_7401), 0 },
686 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7409), 1 },
687 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_VIPER_7411), 3 },
688 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_OPUS_7441), 4 },
689 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_8111_IDE), 5 },
690 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE), 7 },
691 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE), 8 },
692 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE), 8 },
693 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE), 8 },
694 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE), 8 },
695 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE), 8 },
696 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE), 8 },
697 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_IDE), 8 },
698 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_IDE), 8 },
699 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_IDE), 8 },
Peer Chen05e28672006-11-02 17:58:21 -0500700 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_IDE), 8 },
701 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_IDE), 8 },
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400702 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CS5536_IDE), 9 },
703
704 { },
Jeff Garzik669a5db2006-08-29 18:12:40 -0400705};
706
707static struct pci_driver amd_pci_driver = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400708 .name = DRV_NAME,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400709 .id_table = amd,
710 .probe = amd_init_one,
Alanc3041932006-11-27 16:21:24 +0000711 .remove = ata_pci_remove_one,
712 .suspend = ata_pci_device_suspend,
713 .resume = amd_reinit_one,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400714};
715
716static int __init amd_init(void)
717{
718 return pci_register_driver(&amd_pci_driver);
719}
720
721static void __exit amd_exit(void)
722{
723 pci_unregister_driver(&amd_pci_driver);
724}
725
Jeff Garzik669a5db2006-08-29 18:12:40 -0400726MODULE_AUTHOR("Alan Cox");
727MODULE_DESCRIPTION("low-level driver for AMD PATA IDE");
728MODULE_LICENSE("GPL");
729MODULE_DEVICE_TABLE(pci, amd);
730MODULE_VERSION(DRV_VERSION);
731
732module_init(amd_init);
733module_exit(amd_exit);