diff options
-rw-r--r-- | firmware/drivers/ata.c | 240 |
1 files changed, 181 insertions, 59 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index bd1afec2d9..ae202e803a 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c | |||
@@ -47,8 +47,98 @@ | |||
47 | #define ATA_CONTROL1 ((volatile unsigned char*)0x06200206) | 47 | #define ATA_CONTROL1 ((volatile unsigned char*)0x06200206) |
48 | #define ATA_CONTROL2 ((volatile unsigned char*)0x06200306) | 48 | #define ATA_CONTROL2 ((volatile unsigned char*)0x06200306) |
49 | #define ATA_CONTROL (*ata_control) | 49 | #define ATA_CONTROL (*ata_control) |
50 | |||
50 | #endif | 51 | #endif |
51 | 52 | ||
53 | #if CONFIG_CPU == TCC730 | ||
54 | |||
55 | #define PREFER_C_READING | ||
56 | #define PREFER_C_WRITING | ||
57 | |||
58 | #define ATA_DATA_IDX (0xD0) | ||
59 | #define ATA_ERROR_IDX (0xD2) | ||
60 | #define ATA_NSECTOR_IDX (0xD4) | ||
61 | #define ATA_SECTOR_IDX (0xD6) | ||
62 | #define ATA_LCYL_IDX (0xD8) | ||
63 | #define ATA_HCYL_IDX (0xDA) | ||
64 | #define ATA_SELECT_IDX (0xDC) | ||
65 | #define ATA_COMMAND_IDX (0xDE) | ||
66 | #define ATA_CONTROL_IDX (0xEC) | ||
67 | |||
68 | #define ATA_FEATURE_IDX ATA_ERROR_IDX | ||
69 | #define ATA_STATUS_IDX ATA_COMMAND_IDX | ||
70 | #define ATA_ALT_STATUS_IDX ATA_CONTROL_IDX | ||
71 | |||
72 | #define SET_REG(reg, value) (ide_write_register(reg, value)) | ||
73 | #define GET_REG(reg) (ide_read_register(reg)) | ||
74 | |||
75 | #define ATA_DATA (GET_REG(ATA_DATA_IDX)) | ||
76 | #define ATA_ERROR (GET_REG(ATA_ERROR_IDX)) | ||
77 | #define ATA_NSECTOR (GET_REG(ATA_NSECTOR_IDX)) | ||
78 | #define ATA_SECTOR (GET_REG(ATA_SECTOR_IDX)) | ||
79 | #define ATA_LCYL (GET_REG(ATA_LCYL_IDX)) | ||
80 | #define ATA_HCYL (GET_REG(ATA_HCYL_IDX)) | ||
81 | #define ATA_SELECT (GET_REG(ATA_SELECT_IDX)) | ||
82 | #define ATA_COMMAND (GET_REG(ATA_COMMAND_IDX)) | ||
83 | |||
84 | #define ATA_STATUS (GET_REG(ATA_STATUS_IDX)) | ||
85 | #define ATA_ALT_STATUS (GET_REG(ATA_ALT_STATUS_IDX)) | ||
86 | #define ATA_FEATURE (GET_REG(ATA_FEATURE_IDX)) | ||
87 | |||
88 | |||
89 | #define SET_ATA_DATA(v) (SET_REG(ATA_DATA_IDX,v)) | ||
90 | #define SET_ATA_SELECT(v) (SET_REG(ATA_SELECT_IDX,v)) | ||
91 | #define SET_ATA_NSECTOR(v) (SET_REG(ATA_NSECTOR_IDX,v)) | ||
92 | #define SET_ATA_SECTOR(v) (SET_REG(ATA_SECTOR_IDX,v)) | ||
93 | #define SET_ATA_LCYL(v) (SET_REG(ATA_LCYL_IDX,v)) | ||
94 | #define SET_ATA_HCYL(v) (SET_REG(ATA_HCYL_IDX,v)) | ||
95 | #define SET_ATA_COMMAND(v) (SET_REG(ATA_COMMAND_IDX,v)) | ||
96 | #define SET_ATA_CONTROL(v) (SET_REG(ATA_CONTROL_IDX,v)) | ||
97 | #define SET_ATA_FEATURE(v) (SET_REG(ATA_FEATURE_IDX, v)) | ||
98 | |||
99 | |||
100 | extern int idatastart __attribute__ ((section(".idata"))); | ||
101 | |||
102 | static unsigned ide_reg_temp __attribute__ ((section(".idata"))); | ||
103 | |||
104 | void ide_write_register(int reg, int value) { | ||
105 | /* Archos firmware code does (sometimes!) this: | ||
106 | set the RAM speed to 8 cycles. | ||
107 | MIUSCFG |= 0x7; | ||
108 | */ | ||
109 | |||
110 | ide_reg_temp = value; | ||
111 | |||
112 | long extAddr = (long)reg << 16; | ||
113 | ddma_transfer(1, 1, (char*)&ide_reg_temp - (char*)&idatastart, extAddr, 2); | ||
114 | |||
115 | /* set the RAM speed to 6 cycles. | ||
116 | unsigned char miuscfg = MIUSCFG; | ||
117 | miuscfg = (miuscfg & ~7) | 5; | ||
118 | */ | ||
119 | } | ||
120 | |||
121 | int ide_read_register(int reg) { | ||
122 | /* set the RAM speed to 6 cycles. | ||
123 | unsigned char miuscfg = MIUSCFG; | ||
124 | miuscfg = (miuscfg & ~7) | 5; | ||
125 | MIUSCFG = miuscfg; */ | ||
126 | |||
127 | long extAddr = (long)reg << 16; | ||
128 | ddma_transfer(0, 1, (char*)&ide_reg_temp - (char*)&idatastart, extAddr, 2); | ||
129 | |||
130 | /* This is done like this in the archos firmware... | ||
131 | miuscfg = MIUSCFG; | ||
132 | miuscfg = (miuscfg & ~7) | 5; | ||
133 | MIUSCFG = miuscfg; | ||
134 | Though I'd expect MIUSCFG &= ~0x7; (1 cycle) */ | ||
135 | |||
136 | return ide_reg_temp; | ||
137 | } | ||
138 | |||
139 | |||
140 | #else | ||
141 | |||
52 | /* generic registers */ | 142 | /* generic registers */ |
53 | #define ATA_ERROR (*((volatile unsigned char*)ATA_IOBASE + 1)) | 143 | #define ATA_ERROR (*((volatile unsigned char*)ATA_IOBASE + 1)) |
54 | #define ATA_NSECTOR (*((volatile unsigned char*)ATA_IOBASE + 2)) | 144 | #define ATA_NSECTOR (*((volatile unsigned char*)ATA_IOBASE + 2)) |
@@ -61,6 +151,20 @@ | |||
61 | #define ATA_STATUS ATA_COMMAND | 151 | #define ATA_STATUS ATA_COMMAND |
62 | #define ATA_ALT_STATUS ATA_CONTROL | 152 | #define ATA_ALT_STATUS ATA_CONTROL |
63 | 153 | ||
154 | #define SET_REG(reg, value) ((reg) = (value)) | ||
155 | |||
156 | #define SET_ATA_DATA(v) (SET_REG(ATA_DATA,v)) | ||
157 | #define SET_ATA_SELECT(v) (SET_REG(ATA_SELECT,v)) | ||
158 | #define SET_ATA_NSECTOR(v) (SET_REG(ATA_NSECTOR,v)) | ||
159 | #define SET_ATA_SECTOR(v) (SET_REG(ATA_SECTOR,v)) | ||
160 | #define SET_ATA_LCYL(v) (SET_REG(ATA_LCYL,v)) | ||
161 | #define SET_ATA_HCYL(v) (SET_REG(ATA_HCYL,v)) | ||
162 | #define SET_ATA_COMMAND(v) (SET_REG(ATA_COMMAND,v)) | ||
163 | #define SET_ATA_CONTROL(v) (SET_REG(ATA_CONTROL,v)) | ||
164 | #define SET_ATA_FEATURE(v) (SET_REG(ATA_FEATURE, v)) | ||
165 | |||
166 | #endif | ||
167 | |||
64 | 168 | ||
65 | 169 | ||
66 | #define SELECT_DEVICE1 0x10 | 170 | #define SELECT_DEVICE1 0x10 |
@@ -147,7 +251,7 @@ static int wait_for_rdy(void) __attribute__ ((section (".icode"))); | |||
147 | static int wait_for_rdy(void) | 251 | static int wait_for_rdy(void) |
148 | { | 252 | { |
149 | int timeout; | 253 | int timeout; |
150 | 254 | ||
151 | if (!wait_for_bsy()) | 255 | if (!wait_for_bsy()) |
152 | return 0; | 256 | return 0; |
153 | 257 | ||
@@ -181,7 +285,11 @@ static int wait_for_end_of_transfer(void) | |||
181 | return (ATA_ALT_STATUS & (STATUS_RDY|STATUS_DRQ)) == STATUS_RDY; | 285 | return (ATA_ALT_STATUS & (STATUS_RDY|STATUS_DRQ)) == STATUS_RDY; |
182 | } | 286 | } |
183 | 287 | ||
184 | 288 | /* Optimization: don't do 256 calls to ddma_transfer; fuse with it | |
289 | * as in the Archos firmware. | ||
290 | * It actually possible to do a single dma transfer to copy a whole sector between ATA | ||
291 | * controller & cpu internal memory. | ||
292 | */ | ||
185 | /* the tight loop of ata_read_sectors(), to avoid the whole in IRAM */ | 293 | /* the tight loop of ata_read_sectors(), to avoid the whole in IRAM */ |
186 | static void copy_read_sectors(unsigned char* buf, | 294 | static void copy_read_sectors(unsigned char* buf, |
187 | int wordcount) | 295 | int wordcount) |
@@ -351,7 +459,7 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
351 | 459 | ||
352 | timeout = current_tick + READ_TIMEOUT; | 460 | timeout = current_tick + READ_TIMEOUT; |
353 | 461 | ||
354 | ATA_SELECT = ata_device; | 462 | SET_ATA_SELECT(ata_device); |
355 | if (!wait_for_rdy()) | 463 | if (!wait_for_rdy()) |
356 | { | 464 | { |
357 | mutex_unlock(&ata_mtx); | 465 | mutex_unlock(&ata_mtx); |
@@ -367,22 +475,22 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
367 | last_disk_activity = current_tick; | 475 | last_disk_activity = current_tick; |
368 | 476 | ||
369 | if ( count == 256 ) | 477 | if ( count == 256 ) |
370 | ATA_NSECTOR = 0; /* 0 means 256 sectors */ | 478 | SET_ATA_NSECTOR(0); /* 0 means 256 sectors */ |
371 | else | 479 | else |
372 | ATA_NSECTOR = (unsigned char)count; | 480 | SET_ATA_NSECTOR((unsigned char)count); |
373 | 481 | ||
374 | ATA_SECTOR = start & 0xff; | 482 | SET_ATA_SECTOR(start & 0xff); |
375 | ATA_LCYL = (start >> 8) & 0xff; | 483 | SET_ATA_LCYL((start >> 8) & 0xff); |
376 | ATA_HCYL = (start >> 16) & 0xff; | 484 | SET_ATA_HCYL((start >> 16) & 0xff); |
377 | ATA_SELECT = ((start >> 24) & 0xf) | SELECT_LBA | ata_device; | 485 | SET_ATA_SELECT(((start >> 24) & 0xf) | SELECT_LBA | ata_device); |
378 | ATA_COMMAND = CMD_READ_MULTIPLE; | 486 | SET_ATA_COMMAND(CMD_READ_MULTIPLE); |
379 | 487 | ||
380 | /* wait at least 400ns between writing command and reading status */ | 488 | /* wait at least 400ns between writing command and reading status */ |
381 | asm volatile ("nop"); | 489 | __asm__ volatile ("nop"); |
382 | asm volatile ("nop"); | 490 | __asm__ volatile ("nop"); |
383 | asm volatile ("nop"); | 491 | __asm__ volatile ("nop"); |
384 | asm volatile ("nop"); | 492 | __asm__ volatile ("nop"); |
385 | asm volatile ("nop"); | 493 | __asm__ volatile ("nop"); |
386 | 494 | ||
387 | while (count) { | 495 | while (count) { |
388 | int sectors; | 496 | int sectors; |
@@ -480,7 +588,7 @@ static void copy_write_sectors(const unsigned char* buf, int wordcount) | |||
480 | /* takes 13 clock cycles (2 pipeline stalls) */ | 588 | /* takes 13 clock cycles (2 pipeline stalls) */ |
481 | tmp = (unsigned short) *buf++; | 589 | tmp = (unsigned short) *buf++; |
482 | tmp |= (unsigned short) *buf++ << 8; /* I assume big endian */ | 590 | tmp |= (unsigned short) *buf++ << 8; /* I assume big endian */ |
483 | ATA_DATA = tmp; /* and don't use the SWAB16 macro */ | 591 | SET_ATA_DATA(tmp); /* and don't use the SWAB16 macro */ |
484 | } while (buf < bufend); /* tail loop is faster */ | 592 | } while (buf < bufend); /* tail loop is faster */ |
485 | } | 593 | } |
486 | else | 594 | else |
@@ -490,7 +598,7 @@ static void copy_write_sectors(const unsigned char* buf, int wordcount) | |||
490 | do | 598 | do |
491 | { /* loop compiles to 6 assembler instructions */ | 599 | { /* loop compiles to 6 assembler instructions */ |
492 | /* takes 10 clock cycles (2 pipeline stalls) */ | 600 | /* takes 10 clock cycles (2 pipeline stalls) */ |
493 | ATA_DATA = SWAB16(*wbuf); | 601 | SET_ATA_DATA(SWAB16(*wbuf)); |
494 | } while (++wbuf < wbufend); /* tail loop is faster */ | 602 | } while (++wbuf < wbufend); /* tail loop is faster */ |
495 | } | 603 | } |
496 | #else | 604 | #else |
@@ -620,7 +728,7 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
620 | } | 728 | } |
621 | } | 729 | } |
622 | 730 | ||
623 | ATA_SELECT = ata_device; | 731 | SET_ATA_SELECT(ata_device); |
624 | if (!wait_for_rdy()) | 732 | if (!wait_for_rdy()) |
625 | { | 733 | { |
626 | mutex_unlock(&ata_mtx); | 734 | mutex_unlock(&ata_mtx); |
@@ -629,14 +737,14 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
629 | } | 737 | } |
630 | 738 | ||
631 | if ( count == 256 ) | 739 | if ( count == 256 ) |
632 | ATA_NSECTOR = 0; /* 0 means 256 sectors */ | 740 | SET_ATA_NSECTOR(0); /* 0 means 256 sectors */ |
633 | else | 741 | else |
634 | ATA_NSECTOR = (unsigned char)count; | 742 | SET_ATA_NSECTOR((unsigned char)count); |
635 | ATA_SECTOR = start & 0xff; | 743 | SET_ATA_SECTOR(start & 0xff); |
636 | ATA_LCYL = (start >> 8) & 0xff; | 744 | SET_ATA_LCYL((start >> 8) & 0xff); |
637 | ATA_HCYL = (start >> 16) & 0xff; | 745 | SET_ATA_HCYL((start >> 16) & 0xff); |
638 | ATA_SELECT = ((start >> 24) & 0xf) | SELECT_LBA | ata_device; | 746 | SET_ATA_SELECT(((start >> 24) & 0xf) | SELECT_LBA | ata_device); |
639 | ATA_COMMAND = CMD_WRITE_SECTORS; | 747 | SET_ATA_COMMAND(CMD_WRITE_SECTORS); |
640 | 748 | ||
641 | for (i=0; i<count; i++) { | 749 | for (i=0; i<count; i++) { |
642 | 750 | ||
@@ -663,8 +771,10 @@ int ata_write_sectors(IF_MV2(int drive,) | |||
663 | last_disk_activity = current_tick; | 771 | last_disk_activity = current_tick; |
664 | } | 772 | } |
665 | 773 | ||
666 | if(!ret && !wait_for_end_of_transfer()) | 774 | if(!ret && !wait_for_end_of_transfer()) { |
775 | DEBUGF("End on transfer failed. -- jyp"); | ||
667 | ret = -4; | 776 | ret = -4; |
777 | } | ||
668 | 778 | ||
669 | led(false); | 779 | led(false); |
670 | 780 | ||
@@ -700,19 +810,22 @@ extern void ata_flush(void) | |||
700 | 810 | ||
701 | static int check_registers(void) | 811 | static int check_registers(void) |
702 | { | 812 | { |
813 | int i; | ||
703 | if ( ATA_STATUS & STATUS_BSY ) | 814 | if ( ATA_STATUS & STATUS_BSY ) |
704 | return -1; | 815 | return -1; |
705 | 816 | ||
706 | ATA_NSECTOR = 0xa5; | 817 | for (i = 0; i<64; i++) { |
707 | ATA_SECTOR = 0x5a; | 818 | SET_ATA_NSECTOR ( 0xa5); |
708 | ATA_LCYL = 0xaa; | 819 | SET_ATA_SECTOR ( 0x5a); |
709 | ATA_HCYL = 0x55; | 820 | SET_ATA_LCYL ( 0xaa); |
710 | 821 | SET_ATA_HCYL ( 0x55); | |
711 | if ((ATA_NSECTOR == 0xa5) && | 822 | |
712 | (ATA_SECTOR == 0x5a) && | 823 | if ((ATA_NSECTOR == 0xa5) && |
713 | (ATA_LCYL == 0xaa) && | 824 | (ATA_SECTOR == 0x5a) && |
714 | (ATA_HCYL == 0x55)) | 825 | (ATA_LCYL == 0xaa) && |
826 | (ATA_HCYL == 0x55)) | ||
715 | return 0; | 827 | return 0; |
828 | } | ||
716 | 829 | ||
717 | return -2; | 830 | return -2; |
718 | } | 831 | } |
@@ -722,12 +835,12 @@ static int freeze_lock(void) | |||
722 | /* does the disk support Security Mode feature set? */ | 835 | /* does the disk support Security Mode feature set? */ |
723 | if (identify_info[82] & 2) | 836 | if (identify_info[82] & 2) |
724 | { | 837 | { |
725 | ATA_SELECT = ata_device; | 838 | SET_ATA_SELECT (ata_device); |
726 | 839 | ||
727 | if (!wait_for_rdy()) | 840 | if (!wait_for_rdy()) |
728 | return -1; | 841 | return -1; |
729 | 842 | ||
730 | ATA_COMMAND = CMD_SECURITY_FREEZE_LOCK; | 843 | SET_ATA_COMMAND(CMD_SECURITY_FREEZE_LOCK); |
731 | 844 | ||
732 | if (!wait_for_rdy()) | 845 | if (!wait_for_rdy()) |
733 | return -2; | 846 | return -2; |
@@ -762,7 +875,7 @@ static int ata_perform_sleep(void) | |||
762 | 875 | ||
763 | mutex_lock(&ata_mtx); | 876 | mutex_lock(&ata_mtx); |
764 | 877 | ||
765 | ATA_SELECT = ata_device; | 878 | SET_ATA_SELECT(ata_device); |
766 | 879 | ||
767 | if(!wait_for_rdy()) { | 880 | if(!wait_for_rdy()) { |
768 | DEBUGF("ata_perform_sleep() - not RDY\n"); | 881 | DEBUGF("ata_perform_sleep() - not RDY\n"); |
@@ -770,7 +883,7 @@ static int ata_perform_sleep(void) | |||
770 | return -1; | 883 | return -1; |
771 | } | 884 | } |
772 | 885 | ||
773 | ATA_COMMAND = CMD_SLEEP; | 886 | SET_ATA_COMMAND(CMD_SLEEP); |
774 | 887 | ||
775 | if (!wait_for_rdy()) | 888 | if (!wait_for_rdy()) |
776 | { | 889 | { |
@@ -789,7 +902,7 @@ int ata_standby(int time) | |||
789 | 902 | ||
790 | mutex_lock(&ata_mtx); | 903 | mutex_lock(&ata_mtx); |
791 | 904 | ||
792 | ATA_SELECT = ata_device; | 905 | SET_ATA_SELECT(ata_device); |
793 | 906 | ||
794 | if(!wait_for_rdy()) { | 907 | if(!wait_for_rdy()) { |
795 | DEBUGF("ata_standby() - not RDY\n"); | 908 | DEBUGF("ata_standby() - not RDY\n"); |
@@ -798,11 +911,11 @@ int ata_standby(int time) | |||
798 | } | 911 | } |
799 | 912 | ||
800 | if(time) | 913 | if(time) |
801 | ATA_NSECTOR = ((time + 5) / 5) & 0xff; /* Round up to nearest 5 secs */ | 914 | SET_ATA_NSECTOR ( ((time + 5) / 5) & 0xff); /* Round up to nearest 5 secs */ |
802 | else | 915 | else |
803 | ATA_NSECTOR = 0; /* Disable standby */ | 916 | SET_ATA_NSECTOR ( 0); /* Disable standby */ |
804 | 917 | ||
805 | ATA_COMMAND = CMD_STANDBY; | 918 | SET_ATA_COMMAND(CMD_STANDBY); |
806 | 919 | ||
807 | if (!wait_for_rdy()) | 920 | if (!wait_for_rdy()) |
808 | { | 921 | { |
@@ -899,7 +1012,7 @@ int ata_hard_reset(void) | |||
899 | #endif | 1012 | #endif |
900 | 1013 | ||
901 | /* state HRR2 */ | 1014 | /* state HRR2 */ |
902 | ATA_SELECT = ata_device; /* select the right device */ | 1015 | SET_ATA_SELECT(ata_device); /* select the right device */ |
903 | ret = wait_for_bsy(); | 1016 | ret = wait_for_bsy(); |
904 | 1017 | ||
905 | /* Massage the return code so it is 0 on success and -1 on failure */ | 1018 | /* Massage the return code so it is 0 on success and -1 on failure */ |
@@ -913,11 +1026,11 @@ static int perform_soft_reset(void) | |||
913 | int ret; | 1026 | int ret; |
914 | int retry_count; | 1027 | int retry_count; |
915 | 1028 | ||
916 | ATA_SELECT = SELECT_LBA | ata_device; | 1029 | SET_ATA_SELECT ( SELECT_LBA | ata_device ); |
917 | ATA_CONTROL = CONTROL_nIEN|CONTROL_SRST; | 1030 | SET_ATA_CONTROL ( CONTROL_nIEN|CONTROL_SRST ); |
918 | sleep(1); /* >= 5us */ | 1031 | sleep(1); /* >= 5us */ |
919 | 1032 | ||
920 | ATA_CONTROL = CONTROL_nIEN; | 1033 | SET_ATA_CONTROL (CONTROL_nIEN); |
921 | sleep(1); /* >2ms */ | 1034 | sleep(1); /* >2ms */ |
922 | 1035 | ||
923 | /* This little sucker can take up to 30 seconds */ | 1036 | /* This little sucker can take up to 30 seconds */ |
@@ -969,14 +1082,14 @@ static int ata_power_on(void) | |||
969 | static int master_slave_detect(void) | 1082 | static int master_slave_detect(void) |
970 | { | 1083 | { |
971 | /* master? */ | 1084 | /* master? */ |
972 | ATA_SELECT = 0; | 1085 | SET_ATA_SELECT( 0 ); |
973 | if ( ATA_STATUS & (STATUS_RDY|STATUS_BSY) ) { | 1086 | if ( ATA_STATUS & (STATUS_RDY|STATUS_BSY) ) { |
974 | ata_device = 0; | 1087 | ata_device = 0; |
975 | DEBUGF("Found master harddisk\n"); | 1088 | DEBUGF("Found master harddisk\n"); |
976 | } | 1089 | } |
977 | else { | 1090 | else { |
978 | /* slave? */ | 1091 | /* slave? */ |
979 | ATA_SELECT = SELECT_DEVICE1; | 1092 | SET_ATA_SELECT( SELECT_DEVICE1 ); |
980 | if ( ATA_STATUS & (STATUS_RDY|STATUS_BSY) ) { | 1093 | if ( ATA_STATUS & (STATUS_RDY|STATUS_BSY) ) { |
981 | ata_device = SELECT_DEVICE1; | 1094 | ata_device = SELECT_DEVICE1; |
982 | DEBUGF("Found slave harddisk\n"); | 1095 | DEBUGF("Found slave harddisk\n"); |
@@ -1022,14 +1135,15 @@ static int identify(void) | |||
1022 | { | 1135 | { |
1023 | int i; | 1136 | int i; |
1024 | 1137 | ||
1025 | ATA_SELECT = ata_device; | 1138 | SET_ATA_SELECT ( ata_device ); |
1026 | 1139 | ||
1027 | if(!wait_for_rdy()) { | 1140 | if(!wait_for_rdy()) { |
1028 | DEBUGF("identify() - not RDY\n"); | 1141 | DEBUGF("identify() - not RDY\n"); |
1029 | return -1; | 1142 | return -1; |
1030 | } | 1143 | } |
1031 | 1144 | ||
1032 | ATA_COMMAND = CMD_IDENTIFY; | 1145 | |
1146 | SET_ATA_COMMAND ( CMD_IDENTIFY ); | ||
1033 | 1147 | ||
1034 | if (!wait_for_start_of_transfer()) | 1148 | if (!wait_for_start_of_transfer()) |
1035 | { | 1149 | { |
@@ -1037,6 +1151,7 @@ static int identify(void) | |||
1037 | return -2; | 1151 | return -2; |
1038 | } | 1152 | } |
1039 | 1153 | ||
1154 | |||
1040 | for (i=0; i<SECTOR_SIZE/2; i++) | 1155 | for (i=0; i<SECTOR_SIZE/2; i++) |
1041 | /* the IDENTIFY words are already swapped */ | 1156 | /* the IDENTIFY words are already swapped */ |
1042 | identify_info[i] = ATA_DATA; | 1157 | identify_info[i] = ATA_DATA; |
@@ -1046,15 +1161,15 @@ static int identify(void) | |||
1046 | 1161 | ||
1047 | static int set_multiple_mode(int sectors) | 1162 | static int set_multiple_mode(int sectors) |
1048 | { | 1163 | { |
1049 | ATA_SELECT = ata_device; | 1164 | SET_ATA_SELECT ( ata_device ); |
1050 | 1165 | ||
1051 | if(!wait_for_rdy()) { | 1166 | if(!wait_for_rdy()) { |
1052 | DEBUGF("set_multiple_mode() - not RDY\n"); | 1167 | DEBUGF("set_multiple_mode() - not RDY\n"); |
1053 | return -1; | 1168 | return -1; |
1054 | } | 1169 | } |
1055 | 1170 | ||
1056 | ATA_NSECTOR = sectors; | 1171 | SET_ATA_NSECTOR ( sectors ); |
1057 | ATA_COMMAND = CMD_SET_MULTIPLE_MODE; | 1172 | SET_ATA_COMMAND ( CMD_SET_MULTIPLE_MODE ); |
1058 | 1173 | ||
1059 | if (!wait_for_rdy()) | 1174 | if (!wait_for_rdy()) |
1060 | { | 1175 | { |
@@ -1092,7 +1207,7 @@ static int set_features(void) | |||
1092 | /* Update the table */ | 1207 | /* Update the table */ |
1093 | features[3].parameter = 8 + pio_mode; | 1208 | features[3].parameter = 8 + pio_mode; |
1094 | 1209 | ||
1095 | ATA_SELECT = ata_device; | 1210 | SET_ATA_SELECT( ata_device ); |
1096 | 1211 | ||
1097 | if (!wait_for_rdy()) { | 1212 | if (!wait_for_rdy()) { |
1098 | DEBUGF("set_features() - not RDY\n"); | 1213 | DEBUGF("set_features() - not RDY\n"); |
@@ -1101,9 +1216,9 @@ static int set_features(void) | |||
1101 | 1216 | ||
1102 | for (i=0; features[i].id_word; i++) { | 1217 | for (i=0; features[i].id_word; i++) { |
1103 | if (identify_info[features[i].id_word] & (1 << features[i].id_bit)) { | 1218 | if (identify_info[features[i].id_word] & (1 << features[i].id_bit)) { |
1104 | ATA_FEATURE = features[i].subcommand; | 1219 | SET_ATA_FEATURE ( features[i].subcommand ); |
1105 | ATA_NSECTOR = features[i].parameter; | 1220 | SET_ATA_NSECTOR ( features[i].parameter ); |
1106 | ATA_COMMAND = CMD_SET_FEATURES; | 1221 | SET_ATA_COMMAND ( CMD_SET_FEATURES ); |
1107 | 1222 | ||
1108 | if (!wait_for_rdy()) { | 1223 | if (!wait_for_rdy()) { |
1109 | DEBUGF("set_features() - CMD failed\n"); | 1224 | DEBUGF("set_features() - CMD failed\n"); |
@@ -1156,7 +1271,12 @@ static int init_and_check(bool hard_reset) | |||
1156 | int ata_init(void) | 1271 | int ata_init(void) |
1157 | { | 1272 | { |
1158 | int rc; | 1273 | int rc; |
1274 | #if CONFIG_CPU == TCC730 | ||
1275 | /* TODO: check for cold start (never happenning now) */ | ||
1276 | bool coldstart = false; | ||
1277 | #else | ||
1159 | bool coldstart = (PACR2 & 0x4000) != 0; | 1278 | bool coldstart = (PACR2 & 0x4000) != 0; |
1279 | #endif | ||
1160 | 1280 | ||
1161 | mutex_init(&ata_mtx); | 1281 | mutex_init(&ata_mtx); |
1162 | 1282 | ||
@@ -1199,7 +1319,7 @@ int ata_init(void) | |||
1199 | return -40 + rc; | 1319 | return -40 + rc; |
1200 | multisectors = identify_info[47] & 0xff; | 1320 | multisectors = identify_info[47] & 0xff; |
1201 | DEBUGF("ata: %d sectors per ata request\n",multisectors); | 1321 | DEBUGF("ata: %d sectors per ata request\n",multisectors); |
1202 | 1322 | ||
1203 | rc = freeze_lock(); | 1323 | rc = freeze_lock(); |
1204 | if (rc) | 1324 | if (rc) |
1205 | return -50 + rc; | 1325 | return -50 + rc; |
@@ -1214,6 +1334,8 @@ int ata_init(void) | |||
1214 | create_thread(ata_thread, ata_stack, | 1334 | create_thread(ata_thread, ata_stack, |
1215 | sizeof(ata_stack), ata_thread_name); | 1335 | sizeof(ata_stack), ata_thread_name); |
1216 | initialized = true; | 1336 | initialized = true; |
1337 | |||
1338 | |||
1217 | } | 1339 | } |
1218 | rc = set_multiple_mode(multisectors); | 1340 | rc = set_multiple_mode(multisectors); |
1219 | if (rc) | 1341 | if (rc) |