summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8702/ipod6g/storage_ata-ipod6g.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8702/ipod6g/storage_ata-ipod6g.c')
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/storage_ata-ipod6g.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/firmware/target/arm/s5l8702/ipod6g/storage_ata-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/storage_ata-ipod6g.c
index 53ec45ec6d..da45906b36 100644
--- a/firmware/target/arm/s5l8702/ipod6g/storage_ata-ipod6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/storage_ata-ipod6g.c
@@ -50,9 +50,6 @@
50/** static, private data **/ 50/** static, private data **/
51static uint8_t ceata_taskfile[16] STORAGE_ALIGN_ATTR; 51static uint8_t ceata_taskfile[16] STORAGE_ALIGN_ATTR;
52static uint16_t ata_identify_data[0x100] STORAGE_ALIGN_ATTR; 52static uint16_t ata_identify_data[0x100] STORAGE_ALIGN_ATTR;
53#ifdef HAVE_ATA_SMART
54static uint16_t ata_smart_data[0x100] STORAGE_ALIGN_ATTR;
55#endif
56static bool ceata; 53static bool ceata;
57static bool ata_swap; 54static bool ata_swap;
58static bool ata_lba48; 55static bool ata_lba48;
@@ -1217,56 +1214,50 @@ int ata_init(void)
1217#ifdef HAVE_ATA_SMART 1214#ifdef HAVE_ATA_SMART
1218static int ata_smart(uint16_t* buf) 1215static int ata_smart(uint16_t* buf)
1219{ 1216{
1220 mutex_lock(&ata_mutex); 1217 if (!ata_powered) PASS_RC(ata_power_up(), 3, 0);
1221 ata_power_up();
1222
1223 if (ceata) 1218 if (ceata)
1224 { 1219 {
1225 memset(ceata_taskfile, 0, 16); 1220 memset(ceata_taskfile, 0, 16);
1226 ceata_taskfile[0xc] = 0x4f; 1221 ceata_taskfile[0xc] = 0x4f;
1227 ceata_taskfile[0xd] = 0xc2; 1222 ceata_taskfile[0xd] = 0xc2;
1228 ceata_taskfile[0xe] = 0x40; /* Device/Head Register, bit6: 0->CHS, 1->LBA */ 1223 ceata_taskfile[0xe] = BIT(6);
1229 ceata_taskfile[0xf] = 0xb0; 1224 ceata_taskfile[0xf] = 0xb0;
1230 PASS_RC(ceata_wait_idle(), 3, 0); 1225 PASS_RC(ceata_wait_idle(), 3, 1);
1231 if (((uint8_t*)ata_identify_data)[54] != 'A') /* Model != aAmsung */ 1226 if (((uint8_t*)ata_identify_data)[54] != 'A') /* Model != aAmsung */
1232 { 1227 {
1233 ceata_taskfile[0x9] = 0xd8; /* SMART enable operations */ 1228 ceata_taskfile[0x9] = 0xd8; /* SMART enable operations */
1234 PASS_RC(ceata_write_multiple_register(0, ceata_taskfile, 16), 3, 1); 1229 PASS_RC(ceata_write_multiple_register(0, ceata_taskfile, 16), 3, 2);
1235 PASS_RC(ceata_check_error(), 3, 2); 1230 PASS_RC(ceata_check_error(), 3, 3);
1236 } 1231 }
1237 ceata_taskfile[0x9] = 0xd0; /* SMART read data */ 1232 ceata_taskfile[0x9] = 0xd0; /* SMART read data */
1238 PASS_RC(ceata_write_multiple_register(0, ceata_taskfile, 16), 3, 3); 1233 PASS_RC(ceata_write_multiple_register(0, ceata_taskfile, 16), 3, 4);
1239 PASS_RC(ceata_rw_multiple_block(false, buf, 1, CEATA_COMMAND_TIMEOUT * HZ / 1000000), 3, 4); 1234 PASS_RC(ceata_rw_multiple_block(false, buf, 1, CEATA_COMMAND_TIMEOUT * HZ / 1000000), 3, 5);
1240 } 1235 }
1241 else 1236 else
1242 { 1237 {
1243 int i; 1238 int i;
1244 uint32_t old = ATA_CFG; 1239 uint32_t old = ATA_CFG;
1245 ATA_CFG |= BIT(6); /* 16bit big-endian */ 1240 ATA_CFG |= BIT(6); /* 16bit big-endian */
1246 PASS_RC(ata_wait_for_not_bsy(10000000), 3, 5); 1241 PASS_RC(ata_wait_for_not_bsy(10000000), 3, 6);
1247 ata_write_cbr(&ATA_PIO_DAD, 0);
1248 ata_write_cbr(&ATA_PIO_FED, 0xd0); 1242 ata_write_cbr(&ATA_PIO_FED, 0xd0);
1249 ata_write_cbr(&ATA_PIO_SCR, 0);
1250 ata_write_cbr(&ATA_PIO_LLR, 0);
1251 ata_write_cbr(&ATA_PIO_LMR, 0x4f); 1243 ata_write_cbr(&ATA_PIO_LMR, 0x4f);
1252 ata_write_cbr(&ATA_PIO_LHR, 0xc2); 1244 ata_write_cbr(&ATA_PIO_LHR, 0xc2);
1253 ata_write_cbr(&ATA_PIO_DVR, BIT(6)); 1245 ata_write_cbr(&ATA_PIO_DVR, BIT(6));
1254 ata_write_cbr(&ATA_PIO_CSD, 0xb0); 1246 ata_write_cbr(&ATA_PIO_CSD, 0xb0);
1255 PASS_RC(ata_wait_for_start_of_transfer(10000000), 3, 6); 1247 PASS_RC(ata_wait_for_start_of_transfer(10000000), 3, 7);
1256 for (i = 0; i < 0x100; i++) buf[i] = ata_read_cbr(&ATA_PIO_DTR); 1248 for (i = 0; i < 0x100; i++) buf[i] = ata_read_cbr(&ATA_PIO_DTR);
1257 ATA_CFG = old; 1249 ATA_CFG = old;
1258 } 1250 }
1259
1260 ata_set_active(); 1251 ata_set_active();
1261 mutex_unlock(&ata_mutex);
1262
1263 return 0; 1252 return 0;
1264} 1253}
1265 1254
1266void* ata_read_smart(void) 1255int ata_read_smart(struct ata_smart_values* smart_data)
1267{ 1256{
1268 ata_smart(ata_smart_data); 1257 mutex_lock(&ata_mutex);
1269 return ata_smart_data; 1258 int rc = ata_smart((uint16_t*)smart_data);
1259 mutex_unlock(&ata_mutex);
1260 return rc;
1270} 1261}
1271#endif /* HAVE_ATA_SMART */ 1262#endif /* HAVE_ATA_SMART */
1272 1263