summaryrefslogtreecommitdiff
path: root/firmware/drivers/ata.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/ata.c')
-rw-r--r--firmware/drivers/ata.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 13f60ef29e..e067235d95 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -813,8 +813,6 @@ bool ata_disk_is_active(void)
813 813
814static int ata_perform_sleep(void) 814static int ata_perform_sleep(void)
815{ 815{
816 int ret = 0;
817
818 mutex_lock(&ata_mtx); 816 mutex_lock(&ata_mtx);
819 817
820 SET_REG(ATA_SELECT, ata_device); 818 SET_REG(ATA_SELECT, ata_device);
@@ -830,12 +828,13 @@ static int ata_perform_sleep(void)
830 if (!wait_for_rdy()) 828 if (!wait_for_rdy())
831 { 829 {
832 DEBUGF("ata_perform_sleep() - CMD failed\n"); 830 DEBUGF("ata_perform_sleep() - CMD failed\n");
833 ret = -2; 831 mutex_unlock(&ata_mtx);
832 return -2;
834 } 833 }
835 834
836 sleeping = true; 835 sleeping = true;
837 mutex_unlock(&ata_mtx); 836 mutex_unlock(&ata_mtx);
838 return ret; 837 return 0;
839} 838}
840 839
841void ata_sleep(void) 840void ata_sleep(void)
@@ -954,10 +953,9 @@ static int perform_soft_reset(void)
954 * ATA -> Flash interface automatically sleeps almost immediately after the 953 * ATA -> Flash interface automatically sleeps almost immediately after the
955 * last command. 954 * last command.
956 */ 955 */
957#ifndef IPOD_NANO
958 int ret; 956 int ret;
959 int retry_count; 957 int retry_count;
960 958
961 SET_REG(ATA_SELECT, SELECT_LBA | ata_device ); 959 SET_REG(ATA_SELECT, SELECT_LBA | ata_device );
962 SET_REG(ATA_CONTROL, CONTROL_nIEN|CONTROL_SRST ); 960 SET_REG(ATA_CONTROL, CONTROL_nIEN|CONTROL_SRST );
963 sleep(1); /* >= 5us */ 961 sleep(1); /* >= 5us */
@@ -972,13 +970,19 @@ static int perform_soft_reset(void)
972 ret = wait_for_rdy(); 970 ret = wait_for_rdy();
973 } while(!ret && retry_count--); 971 } while(!ret && retry_count--);
974 972
975 /* Massage the return code so it is 0 on success and -1 on failure */ 973 if (!ret)
976 ret = ret?0:-1; 974 return -1;
977 975
978 return ret; 976 if (set_features())
979#else 977 return -2;
980 return 0; /* Always report success */ 978
981#endif 979 if (set_multiple_mode(multisectors))
980 return -3;
981
982 if (freeze_lock())
983 return -4;
984
985 return 0;
982} 986}
983 987
984int ata_soft_reset(void) 988int ata_soft_reset(void)
@@ -1096,10 +1100,10 @@ static int set_features(void)
1096 unsigned char subcommand; 1100 unsigned char subcommand;
1097 unsigned char parameter; 1101 unsigned char parameter;
1098 } features[] = { 1102 } features[] = {
1099 { 83, 3, 0x05, 0x80 }, /* power management: lowest power without standby */ 1103 { 83, 14, 0x03, 0 }, /* force PIO mode */
1104 { 83, 3, 0x05, 0x80 }, /* adv. power management: lowest w/o standby */
1100 { 83, 9, 0x42, 0x80 }, /* acoustic management: lowest noise */ 1105 { 83, 9, 0x42, 0x80 }, /* acoustic management: lowest noise */
1101 { 82, 6, 0xaa, 0 }, /* enable read look-ahead */ 1106 { 82, 6, 0xaa, 0 }, /* enable read look-ahead */
1102 { 83, 14, 0x03, 0 }, /* force PIO mode */
1103 }; 1107 };
1104 int i; 1108 int i;
1105 int pio_mode = 2; 1109 int pio_mode = 2;
@@ -1111,9 +1115,9 @@ static int set_features(void)
1111 if(identify_info[64] & 1) 1115 if(identify_info[64] & 1)
1112 pio_mode = 3; 1116 pio_mode = 3;
1113 1117
1114 /* Update the table */ 1118 /* Update the table: set highest supported pio mode that we also support */
1115 features[3].parameter = 8 + pio_mode; 1119 features[0].parameter = 8 + pio_mode;
1116 1120
1117 SET_REG(ATA_SELECT, ata_device); 1121 SET_REG(ATA_SELECT, ata_device);
1118 1122
1119 if (!wait_for_rdy()) { 1123 if (!wait_for_rdy()) {
@@ -1132,7 +1136,9 @@ static int set_features(void)
1132 return -10 - i; 1136 return -10 - i;
1133 } 1137 }
1134 1138
1135 if(ATA_ALT_STATUS & STATUS_ERR) { 1139 if((ATA_ALT_STATUS & STATUS_ERR) && (i != 1)) {
1140 /* some CF cards don't like advanced powermanagement
1141 even if they mark it as supported - go figure... */
1136 if(ATA_ERROR & ERROR_ABRT) { 1142 if(ATA_ERROR & ERROR_ABRT) {
1137 return -20 - i; 1143 return -20 - i;
1138 } 1144 }