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.c69
1 files changed, 40 insertions, 29 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 60b6a87488..9a0476f5cc 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -977,7 +977,7 @@ static int master_slave_detect(void)
977} 977}
978 978
979#if CONFIG_CPU == SH7034 /* special archos quirk */ 979#if CONFIG_CPU == SH7034 /* special archos quirk */
980static int io_address_detect(void) 980static void io_address_detect(void)
981{ /* now, use the HW mask instead of probing */ 981{ /* now, use the HW mask instead of probing */
982 if (read_hw_mask() & ATA_ADDRESS_200) 982 if (read_hw_mask() & ATA_ADDRESS_200)
983 { 983 {
@@ -991,8 +991,6 @@ static int io_address_detect(void)
991 old_recorder = true; 991 old_recorder = true;
992 ata_control = ATA_CONTROL2; 992 ata_control = ATA_CONTROL2;
993 } 993 }
994
995 return 0;
996} 994}
997#endif 995#endif
998 996
@@ -1117,10 +1115,37 @@ unsigned short* ata_get_identify(void)
1117 return identify_info; 1115 return identify_info;
1118} 1116}
1119 1117
1118static int init_and_check(bool hard_reset)
1119{
1120 int rc;
1121
1122 if (hard_reset)
1123 {
1124 /* This should reset both master and slave, we don't yet know what's in */
1125 ata_device = 0;
1126 if (ata_hard_reset())
1127 return -1;
1128 }
1129
1130 rc = master_slave_detect();
1131 if (rc)
1132 return -10 + rc;
1133
1134 /* symptom fix: else check_registers() below may fail */
1135 if (hard_reset && !wait_for_bsy())
1136 return -20;
1137
1138 rc = check_registers();
1139 if (rc)
1140 return -30 + rc;
1141
1142 return 0;
1143}
1144
1120int ata_init(void) 1145int ata_init(void)
1121{ 1146{
1122 int rc; 1147 int rc;
1123 bool coldstart = (PACR2 & 0x4000) != 0; 1148 bool coldstart = (PACR2 & 0x4000) != 0;
1124 1149
1125 mutex_init(&ata_mtx); 1150 mutex_init(&ata_mtx);
1126 1151
@@ -1144,34 +1169,20 @@ int ata_init(void)
1144 sleep(HZ); /* allow voltage to build up */ 1169 sleep(HZ); /* allow voltage to build up */
1145 } 1170 }
1146 1171
1147 if (coldstart)
1148 {
1149 /* This should reset both master and slave, we don't yet know what's in */
1150 ata_device = 0;
1151 if (ata_hard_reset())
1152 return -1;
1153 }
1154
1155 rc = master_slave_detect();
1156 if (rc)
1157 return -10 + rc;
1158
1159#if CONFIG_CPU == SH7034 1172#if CONFIG_CPU == SH7034
1160 rc = io_address_detect(); 1173 io_address_detect();
1161 if (rc) 1174#endif
1162 return -20 + rc; 1175 /* first try, hard reset at cold start only */
1163#endif 1176 rc = init_and_check(coldstart);
1164 1177
1165 /* symptom fix: else check_registers() below may fail */ 1178 if (rc)
1166 if (coldstart && !wait_for_bsy()) 1179 { /* failed? -> second try, always with hard reset */
1167 { 1180 DEBUGF("ata: init failed, retrying...\n");
1168 return -29; 1181 rc = init_and_check(true);
1182 if (rc)
1183 return rc;
1169 } 1184 }
1170 1185
1171 rc = check_registers();
1172 if (rc)
1173 return -30 + rc;
1174
1175 rc = identify(); 1186 rc = identify();
1176 if (rc) 1187 if (rc)
1177 return -40 + rc; 1188 return -40 + rc;