diff options
-rw-r--r-- | firmware/drivers/ata.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 1b2cbd369c..0b7a37e5ec 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c | |||
@@ -188,6 +188,7 @@ int ata_read_sectors(unsigned long start, | |||
188 | poweroff = false; | 188 | poweroff = false; |
189 | } | 189 | } |
190 | 190 | ||
191 | ATA_SELECT = ata_device; | ||
191 | if (!wait_for_rdy()) | 192 | if (!wait_for_rdy()) |
192 | { | 193 | { |
193 | mutex_unlock(&ata_mtx); | 194 | mutex_unlock(&ata_mtx); |
@@ -308,6 +309,7 @@ int ata_write_sectors(unsigned long start, | |||
308 | poweroff = false; | 309 | poweroff = false; |
309 | } | 310 | } |
310 | 311 | ||
312 | ATA_SELECT = ata_device; | ||
311 | if (!wait_for_rdy()) | 313 | if (!wait_for_rdy()) |
312 | { | 314 | { |
313 | mutex_unlock(&ata_mtx); | 315 | mutex_unlock(&ata_mtx); |
@@ -398,6 +400,8 @@ static int check_registers(void) | |||
398 | 400 | ||
399 | static int freeze_lock(void) | 401 | static int freeze_lock(void) |
400 | { | 402 | { |
403 | ATA_SELECT = ata_device; | ||
404 | |||
401 | if (!wait_for_rdy()) | 405 | if (!wait_for_rdy()) |
402 | return -1; | 406 | return -1; |
403 | 407 | ||
@@ -435,13 +439,14 @@ static int ata_perform_sleep(void) | |||
435 | 439 | ||
436 | mutex_lock(&ata_mtx); | 440 | mutex_lock(&ata_mtx); |
437 | 441 | ||
442 | ATA_SELECT = ata_device; | ||
443 | |||
438 | if(!wait_for_rdy()) { | 444 | if(!wait_for_rdy()) { |
439 | DEBUGF("ata_perform_sleep() - not RDY\n"); | 445 | DEBUGF("ata_perform_sleep() - not RDY\n"); |
440 | mutex_unlock(&ata_mtx); | 446 | mutex_unlock(&ata_mtx); |
441 | return -1; | 447 | return -1; |
442 | } | 448 | } |
443 | 449 | ||
444 | ATA_SELECT = ata_device; | ||
445 | ATA_COMMAND = CMD_SLEEP; | 450 | ATA_COMMAND = CMD_SLEEP; |
446 | 451 | ||
447 | if (!wait_for_rdy()) | 452 | if (!wait_for_rdy()) |
@@ -537,6 +542,7 @@ int ata_hard_reset(void) | |||
537 | sleep(1); /* > 2ms */ | 542 | sleep(1); /* > 2ms */ |
538 | 543 | ||
539 | /* state HRR2 */ | 544 | /* state HRR2 */ |
545 | ATA_SELECT = ata_device; /* select the right device */ | ||
540 | ret = wait_for_bsy(); | 546 | ret = wait_for_bsy(); |
541 | 547 | ||
542 | /* Massage the return code so it is 0 on success and -1 on failure */ | 548 | /* Massage the return code so it is 0 on success and -1 on failure */ |
@@ -590,12 +596,12 @@ static int ata_power_on(void) | |||
590 | if( ata_hard_reset() ) | 596 | if( ata_hard_reset() ) |
591 | return -1; | 597 | return -1; |
592 | 598 | ||
593 | ATA_SELECT = SELECT_LBA; | ||
594 | ATA_CONTROL = CONTROL_nIEN; | ||
595 | |||
596 | if (set_multiple_mode(multisectors)) | 599 | if (set_multiple_mode(multisectors)) |
597 | return -2; | 600 | return -2; |
598 | 601 | ||
602 | if (freeze_lock()) | ||
603 | return -3; | ||
604 | |||
599 | sleeping = false; | 605 | sleeping = false; |
600 | poweroff = false; | 606 | poweroff = false; |
601 | return 0; | 607 | return 0; |
@@ -676,12 +682,13 @@ static int identify(void) | |||
676 | { | 682 | { |
677 | int i; | 683 | int i; |
678 | 684 | ||
685 | ATA_SELECT = ata_device; | ||
686 | |||
679 | if(!wait_for_rdy()) { | 687 | if(!wait_for_rdy()) { |
680 | DEBUGF("identify() - not RDY\n"); | 688 | DEBUGF("identify() - not RDY\n"); |
681 | return -1; | 689 | return -1; |
682 | } | 690 | } |
683 | 691 | ||
684 | ATA_SELECT = ata_device; | ||
685 | ATA_COMMAND = CMD_IDENTIFY; | 692 | ATA_COMMAND = CMD_IDENTIFY; |
686 | 693 | ||
687 | if (!wait_for_start_of_transfer()) | 694 | if (!wait_for_start_of_transfer()) |
@@ -699,12 +706,13 @@ static int identify(void) | |||
699 | 706 | ||
700 | static int set_multiple_mode(int sectors) | 707 | static int set_multiple_mode(int sectors) |
701 | { | 708 | { |
709 | ATA_SELECT = ata_device; | ||
710 | |||
702 | if(!wait_for_rdy()) { | 711 | if(!wait_for_rdy()) { |
703 | DEBUGF("set_multiple_mode() - not RDY\n"); | 712 | DEBUGF("set_multiple_mode() - not RDY\n"); |
704 | return -1; | 713 | return -1; |
705 | } | 714 | } |
706 | 715 | ||
707 | ATA_SELECT = ata_device; | ||
708 | ATA_NSECTOR = sectors; | 716 | ATA_NSECTOR = sectors; |
709 | ATA_COMMAND = CMD_SET_MULTIPLE_MODE; | 717 | ATA_COMMAND = CMD_SET_MULTIPLE_MODE; |
710 | 718 | ||
@@ -756,8 +764,5 @@ int ata_init(void) | |||
756 | if (set_multiple_mode(multisectors)) | 764 | if (set_multiple_mode(multisectors)) |
757 | return -6; | 765 | return -6; |
758 | 766 | ||
759 | ATA_SELECT = SELECT_LBA; | ||
760 | ATA_CONTROL = CONTROL_nIEN; | ||
761 | |||
762 | return 0; | 767 | return 0; |
763 | } | 768 | } |