aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/pata_amd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/pata_amd.c')
-rw-r--r--drivers/ata/pata_amd.c268
1 files changed, 50 insertions, 218 deletions
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index 4b8d9b592ca4..26665c396485 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -56,7 +56,9 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
56 u8 t; 56 u8 t;
57 57
58 T = 1000000000 / amd_clock; 58 T = 1000000000 / amd_clock;
59 UT = T / min_t(int, max_t(int, clock, 1), 2); 59 UT = T;
60 if (clock >= 2)
61 UT = T / 2;
60 62
61 if (ata_timing_compute(adev, speed, &at, T, UT) < 0) { 63 if (ata_timing_compute(adev, speed, &at, T, UT) < 0) {
62 dev_printk(KERN_ERR, &pdev->dev, "unknown mode %d.\n", speed); 64 dev_printk(KERN_ERR, &pdev->dev, "unknown mode %d.\n", speed);
@@ -141,13 +143,7 @@ static int amd_pre_reset(struct ata_link *link, unsigned long deadline)
141 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no])) 143 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
142 return -ENOENT; 144 return -ENOENT;
143 145
144 return ata_std_prereset(link, deadline); 146 return ata_sff_prereset(link, deadline);
145}
146
147static void amd_error_handler(struct ata_port *ap)
148{
149 ata_bmdma_drive_eh(ap, amd_pre_reset, ata_std_softreset, NULL,
150 ata_std_postreset);
151} 147}
152 148
153static int amd_cable_detect(struct ata_port *ap) 149static int amd_cable_detect(struct ata_port *ap)
@@ -297,14 +293,7 @@ static int nv_pre_reset(struct ata_link *link, unsigned long deadline)
297 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no])) 293 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
298 return -ENOENT; 294 return -ENOENT;
299 295
300 return ata_std_prereset(link, deadline); 296 return ata_sff_prereset(link, deadline);
301}
302
303static void nv_error_handler(struct ata_port *ap)
304{
305 ata_bmdma_drive_eh(ap, nv_pre_reset,
306 ata_std_softreset, NULL,
307 ata_std_postreset);
308} 297}
309 298
310/** 299/**
@@ -353,228 +342,66 @@ static void nv_host_stop(struct ata_host *host)
353} 342}
354 343
355static struct scsi_host_template amd_sht = { 344static struct scsi_host_template amd_sht = {
356 .module = THIS_MODULE, 345 ATA_BMDMA_SHT(DRV_NAME),
357 .name = DRV_NAME, 346};
358 .ioctl = ata_scsi_ioctl, 347
359 .queuecommand = ata_scsi_queuecmd, 348static const struct ata_port_operations amd_base_port_ops = {
360 .can_queue = ATA_DEF_QUEUE, 349 .inherits = &ata_bmdma_port_ops,
361 .this_id = ATA_SHT_THIS_ID, 350 .prereset = amd_pre_reset,
362 .sg_tablesize = LIBATA_MAX_PRD,
363 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
364 .emulated = ATA_SHT_EMULATED,
365 .use_clustering = ATA_SHT_USE_CLUSTERING,
366 .proc_name = DRV_NAME,
367 .dma_boundary = ATA_DMA_BOUNDARY,
368 .slave_configure = ata_scsi_slave_config,
369 .slave_destroy = ata_scsi_slave_destroy,
370 .bios_param = ata_std_bios_param,
371}; 351};
372 352
373static struct ata_port_operations amd33_port_ops = { 353static struct ata_port_operations amd33_port_ops = {
354 .inherits = &amd_base_port_ops,
355 .cable_detect = ata_cable_40wire,
374 .set_piomode = amd33_set_piomode, 356 .set_piomode = amd33_set_piomode,
375 .set_dmamode = amd33_set_dmamode, 357 .set_dmamode = amd33_set_dmamode,
376 .mode_filter = ata_pci_default_filter,
377 .tf_load = ata_tf_load,
378 .tf_read = ata_tf_read,
379 .check_status = ata_check_status,
380 .exec_command = ata_exec_command,
381 .dev_select = ata_std_dev_select,
382
383 .freeze = ata_bmdma_freeze,
384 .thaw = ata_bmdma_thaw,
385 .error_handler = amd_error_handler,
386 .post_internal_cmd = ata_bmdma_post_internal_cmd,
387 .cable_detect = ata_cable_40wire,
388
389 .bmdma_setup = ata_bmdma_setup,
390 .bmdma_start = ata_bmdma_start,
391 .bmdma_stop = ata_bmdma_stop,
392 .bmdma_status = ata_bmdma_status,
393
394 .qc_prep = ata_qc_prep,
395 .qc_issue = ata_qc_issue_prot,
396
397 .data_xfer = ata_data_xfer,
398
399 .irq_handler = ata_interrupt,
400 .irq_clear = ata_bmdma_irq_clear,
401 .irq_on = ata_irq_on,
402
403 .port_start = ata_sff_port_start,
404}; 358};
405 359
406static struct ata_port_operations amd66_port_ops = { 360static struct ata_port_operations amd66_port_ops = {
361 .inherits = &amd_base_port_ops,
362 .cable_detect = ata_cable_unknown,
407 .set_piomode = amd66_set_piomode, 363 .set_piomode = amd66_set_piomode,
408 .set_dmamode = amd66_set_dmamode, 364 .set_dmamode = amd66_set_dmamode,
409 .mode_filter = ata_pci_default_filter,
410 .tf_load = ata_tf_load,
411 .tf_read = ata_tf_read,
412 .check_status = ata_check_status,
413 .exec_command = ata_exec_command,
414 .dev_select = ata_std_dev_select,
415
416 .freeze = ata_bmdma_freeze,
417 .thaw = ata_bmdma_thaw,
418 .error_handler = amd_error_handler,
419 .post_internal_cmd = ata_bmdma_post_internal_cmd,
420 .cable_detect = ata_cable_unknown,
421
422 .bmdma_setup = ata_bmdma_setup,
423 .bmdma_start = ata_bmdma_start,
424 .bmdma_stop = ata_bmdma_stop,
425 .bmdma_status = ata_bmdma_status,
426
427 .qc_prep = ata_qc_prep,
428 .qc_issue = ata_qc_issue_prot,
429
430 .data_xfer = ata_data_xfer,
431
432 .irq_handler = ata_interrupt,
433 .irq_clear = ata_bmdma_irq_clear,
434 .irq_on = ata_irq_on,
435
436 .port_start = ata_sff_port_start,
437}; 365};
438 366
439static struct ata_port_operations amd100_port_ops = { 367static struct ata_port_operations amd100_port_ops = {
368 .inherits = &amd_base_port_ops,
369 .cable_detect = ata_cable_unknown,
440 .set_piomode = amd100_set_piomode, 370 .set_piomode = amd100_set_piomode,
441 .set_dmamode = amd100_set_dmamode, 371 .set_dmamode = amd100_set_dmamode,
442 .mode_filter = ata_pci_default_filter,
443 .tf_load = ata_tf_load,
444 .tf_read = ata_tf_read,
445 .check_status = ata_check_status,
446 .exec_command = ata_exec_command,
447 .dev_select = ata_std_dev_select,
448
449 .freeze = ata_bmdma_freeze,
450 .thaw = ata_bmdma_thaw,
451 .error_handler = amd_error_handler,
452 .post_internal_cmd = ata_bmdma_post_internal_cmd,
453 .cable_detect = ata_cable_unknown,
454
455 .bmdma_setup = ata_bmdma_setup,
456 .bmdma_start = ata_bmdma_start,
457 .bmdma_stop = ata_bmdma_stop,
458 .bmdma_status = ata_bmdma_status,
459
460 .qc_prep = ata_qc_prep,
461 .qc_issue = ata_qc_issue_prot,
462
463 .data_xfer = ata_data_xfer,
464
465 .irq_handler = ata_interrupt,
466 .irq_clear = ata_bmdma_irq_clear,
467 .irq_on = ata_irq_on,
468
469 .port_start = ata_sff_port_start,
470}; 372};
471 373
472static struct ata_port_operations amd133_port_ops = { 374static struct ata_port_operations amd133_port_ops = {
375 .inherits = &amd_base_port_ops,
376 .cable_detect = amd_cable_detect,
473 .set_piomode = amd133_set_piomode, 377 .set_piomode = amd133_set_piomode,
474 .set_dmamode = amd133_set_dmamode, 378 .set_dmamode = amd133_set_dmamode,
475 .mode_filter = ata_pci_default_filter, 379};
476 .tf_load = ata_tf_load,
477 .tf_read = ata_tf_read,
478 .check_status = ata_check_status,
479 .exec_command = ata_exec_command,
480 .dev_select = ata_std_dev_select,
481
482 .freeze = ata_bmdma_freeze,
483 .thaw = ata_bmdma_thaw,
484 .error_handler = amd_error_handler,
485 .post_internal_cmd = ata_bmdma_post_internal_cmd,
486 .cable_detect = amd_cable_detect,
487
488 .bmdma_setup = ata_bmdma_setup,
489 .bmdma_start = ata_bmdma_start,
490 .bmdma_stop = ata_bmdma_stop,
491 .bmdma_status = ata_bmdma_status,
492
493 .qc_prep = ata_qc_prep,
494 .qc_issue = ata_qc_issue_prot,
495
496 .data_xfer = ata_data_xfer,
497
498 .irq_handler = ata_interrupt,
499 .irq_clear = ata_bmdma_irq_clear,
500 .irq_on = ata_irq_on,
501 380
502 .port_start = ata_sff_port_start, 381static const struct ata_port_operations nv_base_port_ops = {
382 .inherits = &ata_bmdma_port_ops,
383 .cable_detect = ata_cable_ignore,
384 .mode_filter = nv_mode_filter,
385 .prereset = nv_pre_reset,
386 .host_stop = nv_host_stop,
503}; 387};
504 388
505static struct ata_port_operations nv100_port_ops = { 389static struct ata_port_operations nv100_port_ops = {
390 .inherits = &nv_base_port_ops,
506 .set_piomode = nv100_set_piomode, 391 .set_piomode = nv100_set_piomode,
507 .set_dmamode = nv100_set_dmamode, 392 .set_dmamode = nv100_set_dmamode,
508 .tf_load = ata_tf_load,
509 .tf_read = ata_tf_read,
510 .check_status = ata_check_status,
511 .exec_command = ata_exec_command,
512 .dev_select = ata_std_dev_select,
513
514 .freeze = ata_bmdma_freeze,
515 .thaw = ata_bmdma_thaw,
516 .error_handler = nv_error_handler,
517 .post_internal_cmd = ata_bmdma_post_internal_cmd,
518 .cable_detect = ata_cable_ignore,
519 .mode_filter = nv_mode_filter,
520
521 .bmdma_setup = ata_bmdma_setup,
522 .bmdma_start = ata_bmdma_start,
523 .bmdma_stop = ata_bmdma_stop,
524 .bmdma_status = ata_bmdma_status,
525
526 .qc_prep = ata_qc_prep,
527 .qc_issue = ata_qc_issue_prot,
528
529 .data_xfer = ata_data_xfer,
530
531 .irq_handler = ata_interrupt,
532 .irq_clear = ata_bmdma_irq_clear,
533 .irq_on = ata_irq_on,
534
535 .port_start = ata_sff_port_start,
536 .host_stop = nv_host_stop,
537}; 393};
538 394
539static struct ata_port_operations nv133_port_ops = { 395static struct ata_port_operations nv133_port_ops = {
396 .inherits = &nv_base_port_ops,
540 .set_piomode = nv133_set_piomode, 397 .set_piomode = nv133_set_piomode,
541 .set_dmamode = nv133_set_dmamode, 398 .set_dmamode = nv133_set_dmamode,
542 .tf_load = ata_tf_load,
543 .tf_read = ata_tf_read,
544 .check_status = ata_check_status,
545 .exec_command = ata_exec_command,
546 .dev_select = ata_std_dev_select,
547
548 .freeze = ata_bmdma_freeze,
549 .thaw = ata_bmdma_thaw,
550 .error_handler = nv_error_handler,
551 .post_internal_cmd = ata_bmdma_post_internal_cmd,
552 .cable_detect = ata_cable_ignore,
553 .mode_filter = nv_mode_filter,
554
555 .bmdma_setup = ata_bmdma_setup,
556 .bmdma_start = ata_bmdma_start,
557 .bmdma_stop = ata_bmdma_stop,
558 .bmdma_status = ata_bmdma_status,
559
560 .qc_prep = ata_qc_prep,
561 .qc_issue = ata_qc_issue_prot,
562
563 .data_xfer = ata_data_xfer,
564
565 .irq_handler = ata_interrupt,
566 .irq_clear = ata_bmdma_irq_clear,
567 .irq_on = ata_irq_on,
568
569 .port_start = ata_sff_port_start,
570 .host_stop = nv_host_stop,
571}; 399};
572 400
573static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 401static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
574{ 402{
575 static const struct ata_port_info info[10] = { 403 static const struct ata_port_info info[10] = {
576 { /* 0: AMD 7401 */ 404 { /* 0: AMD 7401 */
577 .sht = &amd_sht,
578 .flags = ATA_FLAG_SLAVE_POSS, 405 .flags = ATA_FLAG_SLAVE_POSS,
579 .pio_mask = 0x1f, 406 .pio_mask = 0x1f,
580 .mwdma_mask = 0x07, /* No SWDMA */ 407 .mwdma_mask = 0x07, /* No SWDMA */
@@ -582,7 +409,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
582 .port_ops = &amd33_port_ops 409 .port_ops = &amd33_port_ops
583 }, 410 },
584 { /* 1: Early AMD7409 - no swdma */ 411 { /* 1: Early AMD7409 - no swdma */
585 .sht = &amd_sht,
586 .flags = ATA_FLAG_SLAVE_POSS, 412 .flags = ATA_FLAG_SLAVE_POSS,
587 .pio_mask = 0x1f, 413 .pio_mask = 0x1f,
588 .mwdma_mask = 0x07, 414 .mwdma_mask = 0x07,
@@ -590,7 +416,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
590 .port_ops = &amd66_port_ops 416 .port_ops = &amd66_port_ops
591 }, 417 },
592 { /* 2: AMD 7409, no swdma errata */ 418 { /* 2: AMD 7409, no swdma errata */
593 .sht = &amd_sht,
594 .flags = ATA_FLAG_SLAVE_POSS, 419 .flags = ATA_FLAG_SLAVE_POSS,
595 .pio_mask = 0x1f, 420 .pio_mask = 0x1f,
596 .mwdma_mask = 0x07, 421 .mwdma_mask = 0x07,
@@ -598,7 +423,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
598 .port_ops = &amd66_port_ops 423 .port_ops = &amd66_port_ops
599 }, 424 },
600 { /* 3: AMD 7411 */ 425 { /* 3: AMD 7411 */
601 .sht = &amd_sht,
602 .flags = ATA_FLAG_SLAVE_POSS, 426 .flags = ATA_FLAG_SLAVE_POSS,
603 .pio_mask = 0x1f, 427 .pio_mask = 0x1f,
604 .mwdma_mask = 0x07, 428 .mwdma_mask = 0x07,
@@ -606,7 +430,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
606 .port_ops = &amd100_port_ops 430 .port_ops = &amd100_port_ops
607 }, 431 },
608 { /* 4: AMD 7441 */ 432 { /* 4: AMD 7441 */
609 .sht = &amd_sht,
610 .flags = ATA_FLAG_SLAVE_POSS, 433 .flags = ATA_FLAG_SLAVE_POSS,
611 .pio_mask = 0x1f, 434 .pio_mask = 0x1f,
612 .mwdma_mask = 0x07, 435 .mwdma_mask = 0x07,
@@ -614,7 +437,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
614 .port_ops = &amd100_port_ops 437 .port_ops = &amd100_port_ops
615 }, 438 },
616 { /* 5: AMD 8111*/ 439 { /* 5: AMD 8111*/
617 .sht = &amd_sht,
618 .flags = ATA_FLAG_SLAVE_POSS, 440 .flags = ATA_FLAG_SLAVE_POSS,
619 .pio_mask = 0x1f, 441 .pio_mask = 0x1f,
620 .mwdma_mask = 0x07, 442 .mwdma_mask = 0x07,
@@ -622,7 +444,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
622 .port_ops = &amd133_port_ops 444 .port_ops = &amd133_port_ops
623 }, 445 },
624 { /* 6: AMD 8111 UDMA 100 (Serenade) */ 446 { /* 6: AMD 8111 UDMA 100 (Serenade) */
625 .sht = &amd_sht,
626 .flags = ATA_FLAG_SLAVE_POSS, 447 .flags = ATA_FLAG_SLAVE_POSS,
627 .pio_mask = 0x1f, 448 .pio_mask = 0x1f,
628 .mwdma_mask = 0x07, 449 .mwdma_mask = 0x07,
@@ -630,7 +451,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
630 .port_ops = &amd133_port_ops 451 .port_ops = &amd133_port_ops
631 }, 452 },
632 { /* 7: Nvidia Nforce */ 453 { /* 7: Nvidia Nforce */
633 .sht = &amd_sht,
634 .flags = ATA_FLAG_SLAVE_POSS, 454 .flags = ATA_FLAG_SLAVE_POSS,
635 .pio_mask = 0x1f, 455 .pio_mask = 0x1f,
636 .mwdma_mask = 0x07, 456 .mwdma_mask = 0x07,
@@ -638,7 +458,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
638 .port_ops = &nv100_port_ops 458 .port_ops = &nv100_port_ops
639 }, 459 },
640 { /* 8: Nvidia Nforce2 and later */ 460 { /* 8: Nvidia Nforce2 and later */
641 .sht = &amd_sht,
642 .flags = ATA_FLAG_SLAVE_POSS, 461 .flags = ATA_FLAG_SLAVE_POSS,
643 .pio_mask = 0x1f, 462 .pio_mask = 0x1f,
644 .mwdma_mask = 0x07, 463 .mwdma_mask = 0x07,
@@ -646,7 +465,6 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
646 .port_ops = &nv133_port_ops 465 .port_ops = &nv133_port_ops
647 }, 466 },
648 { /* 9: AMD CS5536 (Geode companion) */ 467 { /* 9: AMD CS5536 (Geode companion) */
649 .sht = &amd_sht,
650 .flags = ATA_FLAG_SLAVE_POSS, 468 .flags = ATA_FLAG_SLAVE_POSS,
651 .pio_mask = 0x1f, 469 .pio_mask = 0x1f,
652 .mwdma_mask = 0x07, 470 .mwdma_mask = 0x07,
@@ -654,15 +472,20 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
654 .port_ops = &amd100_port_ops 472 .port_ops = &amd100_port_ops
655 } 473 }
656 }; 474 };
657 struct ata_port_info pi; 475 const struct ata_port_info *ppi[] = { NULL, NULL };
658 const struct ata_port_info *ppi[] = { &pi, NULL };
659 static int printed_version; 476 static int printed_version;
660 int type = id->driver_data; 477 int type = id->driver_data;
478 void *hpriv = NULL;
661 u8 fifo; 479 u8 fifo;
480 int rc;
662 481
663 if (!printed_version++) 482 if (!printed_version++)
664 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 483 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
665 484
485 rc = pcim_enable_device(pdev);
486 if (rc)
487 return rc;
488
666 pci_read_config_byte(pdev, 0x41, &fifo); 489 pci_read_config_byte(pdev, 0x41, &fifo);
667 490
668 /* Check for AMD7409 without swdma errata and if found adjust type */ 491 /* Check for AMD7409 without swdma errata and if found adjust type */
@@ -677,10 +500,10 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
677 /* 500 /*
678 * Okay, type is determined now. Apply type-specific workarounds. 501 * Okay, type is determined now. Apply type-specific workarounds.
679 */ 502 */
680 pi = info[type]; 503 ppi[0] = &info[type];
681 504
682 if (type < 3) 505 if (type < 3)
683 ata_pci_clear_simplex(pdev); 506 ata_pci_bmdma_clear_simplex(pdev);
684 507
685 /* Check for AMD7411 */ 508 /* Check for AMD7411 */
686 if (type == 3) 509 if (type == 3)
@@ -696,16 +519,23 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
696 u32 udma; 519 u32 udma;
697 520
698 pci_read_config_dword(pdev, 0x60, &udma); 521 pci_read_config_dword(pdev, 0x60, &udma);
699 pi.private_data = (void *)(unsigned long)udma; 522 hpriv = (void *)(unsigned long)udma;
700 } 523 }
701 524
702 /* And fire it up */ 525 /* And fire it up */
703 return ata_pci_init_one(pdev, ppi); 526 return ata_pci_sff_init_one(pdev, ppi, &amd_sht, hpriv);
704} 527}
705 528
706#ifdef CONFIG_PM 529#ifdef CONFIG_PM
707static int amd_reinit_one(struct pci_dev *pdev) 530static int amd_reinit_one(struct pci_dev *pdev)
708{ 531{
532 struct ata_host *host = dev_get_drvdata(&pdev->dev);
533 int rc;
534
535 rc = ata_pci_device_do_resume(pdev);
536 if (rc)
537 return rc;
538
709 if (pdev->vendor == PCI_VENDOR_ID_AMD) { 539 if (pdev->vendor == PCI_VENDOR_ID_AMD) {
710 u8 fifo; 540 u8 fifo;
711 pci_read_config_byte(pdev, 0x41, &fifo); 541 pci_read_config_byte(pdev, 0x41, &fifo);
@@ -716,9 +546,11 @@ static int amd_reinit_one(struct pci_dev *pdev)
716 pci_write_config_byte(pdev, 0x41, fifo | 0xF0); 546 pci_write_config_byte(pdev, 0x41, fifo | 0xF0);
717 if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 || 547 if (pdev->device == PCI_DEVICE_ID_AMD_VIPER_7409 ||
718 pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401) 548 pdev->device == PCI_DEVICE_ID_AMD_COBRA_7401)
719 ata_pci_clear_simplex(pdev); 549 ata_pci_bmdma_clear_simplex(pdev);
720 } 550 }
721 return ata_pci_device_resume(pdev); 551
552 ata_host_resume(host);
553 return 0;
722} 554}
723#endif 555#endif
724 556