diff options
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/arm/as3525/ata_sd_as3525.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c index 33816d4e61..b61c49ca37 100644 --- a/firmware/target/arm/as3525/ata_sd_as3525.c +++ b/firmware/target/arm/as3525/ata_sd_as3525.c | |||
@@ -281,6 +281,9 @@ static int sd_init_card(const int drive) | |||
281 | 281 | ||
282 | } while(!(card_info[drive].ocr & (1<<31))); | 282 | } while(!(card_info[drive].ocr & (1<<31))); |
283 | 283 | ||
284 | MCI_CLOCK(drive) |= MCI_CLOCK_BYPASS; /* full speed for controller clock */ | ||
285 | mci_delay(); | ||
286 | |||
284 | /* send CID */ | 287 | /* send CID */ |
285 | if(!send_cmd(drive, SD_ALL_SEND_CID, 0, MCI_RESP|MCI_LONG_RESP|MCI_ARG, | 288 | if(!send_cmd(drive, SD_ALL_SEND_CID, 0, MCI_RESP|MCI_LONG_RESP|MCI_ARG, |
286 | temp_reg)) | 289 | temp_reg)) |
@@ -294,43 +297,38 @@ static int sd_init_card(const int drive) | |||
294 | &card_info[drive].rca)) | 297 | &card_info[drive].rca)) |
295 | return -6; | 298 | return -6; |
296 | 299 | ||
300 | /* Select card to put it in TRAN state */ | ||
301 | if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_ARG, NULL)) | ||
302 | return -7; | ||
303 | |||
304 | /* Try to switch V2 cards to HS timings, non HS seem to ignore this */ | ||
305 | if(sd_v2) | ||
306 | { | ||
307 | if(sd_wait_for_state(drive, SD_TRAN)) | ||
308 | return -8; | ||
309 | if(!send_cmd(drive, SD_SWITCH_FUNC, 0x80fffff1, MCI_ARG, NULL)) | ||
310 | return -9; | ||
311 | mci_delay(); | ||
312 | } | ||
313 | |||
314 | /* go back to STBY state so we can read csd */ | ||
315 | if(!send_cmd(drive, SD_DESELECT_CARD, 0, MCI_ARG, NULL)) | ||
316 | return -10; | ||
317 | |||
297 | /* send CSD */ | 318 | /* send CSD */ |
298 | if(!send_cmd(drive, SD_SEND_CSD, card_info[drive].rca, | 319 | if(!send_cmd(drive, SD_SEND_CSD, card_info[drive].rca, |
299 | MCI_RESP|MCI_LONG_RESP|MCI_ARG, temp_reg)) | 320 | MCI_RESP|MCI_LONG_RESP|MCI_ARG, temp_reg)) |
300 | return -7; | 321 | return -11; |
301 | 322 | ||
302 | for(i=0; i<4; i++) | 323 | for(i=0; i<4; i++) |
303 | card_info[drive].csd[3-i] = temp_reg[i]; | 324 | card_info[drive].csd[3-i] = temp_reg[i]; |
304 | 325 | ||
305 | sd_parse_csd(&card_info[drive]); | 326 | sd_parse_csd(&card_info[drive]); |
306 | 327 | ||
328 | /* Select card to put back in TRAN state */ | ||
307 | if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_ARG, NULL)) | 329 | if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_ARG, NULL)) |
308 | return -9; | ||
309 | |||
310 | if(!send_cmd(drive, SD_APP_CMD, card_info[drive].rca, MCI_ARG, NULL)) | ||
311 | return -10; | ||
312 | |||
313 | if(!send_cmd(drive, SD_SET_BUS_WIDTH, card_info[drive].rca | 2, MCI_ARG, NULL)) | ||
314 | return -11; | ||
315 | |||
316 | if(!send_cmd(drive, SD_SET_BLOCKLEN, card_info[drive].blocksize, MCI_ARG, | ||
317 | NULL)) | ||
318 | return -12; | 330 | return -12; |
319 | 331 | ||
320 | card_info[drive].initialized = 1; | ||
321 | |||
322 | MCI_CLOCK(drive) |= MCI_CLOCK_BYPASS; /* full speed for controller clock */ | ||
323 | mci_delay(); | ||
324 | |||
325 | /* If card is HS capable switch to HS timings */ | ||
326 | if(card_info[drive].speed > 125000) | ||
327 | { | ||
328 | if(sd_wait_for_state(drive, SD_TRAN)) | ||
329 | return -13; | ||
330 | if(!send_cmd(drive, SD_SWITCH_FUNC, 0x80fffff1, MCI_ARG, NULL)) | ||
331 | return -14; | ||
332 | } | ||
333 | |||
334 | /* | 332 | /* |
335 | * enable bank switching | 333 | * enable bank switching |
336 | * without issuing this command, we only have access to 1/4 of the blocks | 334 | * without issuing this command, we only have access to 1/4 of the blocks |
@@ -341,9 +339,11 @@ static int sd_init_card(const int drive) | |||
341 | { | 339 | { |
342 | const int ret = sd_select_bank(-1); | 340 | const int ret = sd_select_bank(-1); |
343 | if(ret < 0) | 341 | if(ret < 0) |
344 | return ret - 15; | 342 | return ret - 13; |
345 | } | 343 | } |
346 | 344 | ||
345 | card_info[drive].initialized = 1; | ||
346 | |||
347 | return 0; | 347 | return 0; |
348 | } | 348 | } |
349 | 349 | ||