summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/target/arm/as3525/sd-as3525v2.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c
index 7eeac21f5e..f1d21c04ab 100644
--- a/firmware/target/arm/as3525/sd-as3525v2.c
+++ b/firmware/target/arm/as3525/sd-as3525v2.c
@@ -64,6 +64,7 @@
64#define MCI_NO_RESP (0<<0) 64#define MCI_NO_RESP (0<<0)
65#define MCI_RESP (1<<0) 65#define MCI_RESP (1<<0)
66#define MCI_LONG_RESP (1<<1) 66#define MCI_LONG_RESP (1<<1)
67#define MCI_ACMD (1<<2)
67 68
68/* controller registers */ 69/* controller registers */
69#define SD_BASE 0xC6070000 70#define SD_BASE 0xC6070000
@@ -396,6 +397,10 @@ static bool send_cmd(const int drive, const int cmd, const int arg, const int fl
396 unsigned long *response) 397 unsigned long *response)
397{ 398{
398 int card_no; 399 int card_no;
400
401 if ((flags & MCI_ACMD) && /* send SD_APP_CMD first */
402 !send_cmd(drive, SD_APP_CMD, card_info[drive].rca, MCI_RESP, response))
403 return false;
399 404
400#if defined(HAVE_MULTIDRIVE) 405#if defined(HAVE_MULTIDRIVE)
401 if(sd_present(SD_SLOT_AS3525)) 406 if(sd_present(SD_SLOT_AS3525))
@@ -491,6 +496,8 @@ static int sd_init_card(const int drive)
491 long init_timeout; 496 long init_timeout;
492 bool sd_v2 = false; 497 bool sd_v2 = false;
493 498
499 card_info[drive].rca = 0;
500
494 /* assume 24 MHz clock / 60 = 400 kHz */ 501 /* assume 24 MHz clock / 60 = 400 kHz */
495 MCI_CLKDIV = (MCI_CLKDIV & ~(0xFF)) | 0x3C; /* CLK_DIV_0 : bits 7:0 */ 502 MCI_CLKDIV = (MCI_CLKDIV & ~(0xFF)) | 0x3C; /* CLK_DIV_0 : bits 7:0 */
496 503
@@ -516,12 +523,9 @@ static int sd_init_card(const int drive)
516 if(TIME_AFTER(current_tick, init_timeout)) 523 if(TIME_AFTER(current_tick, init_timeout))
517 return -2; 524 return -2;
518 525
519 /* app_cmd */
520 send_cmd(drive, SD_APP_CMD, 0, MCI_RESP, &response);
521
522 /* ACMD41 For v2 cards set HCS bit[30] & send host voltage range to all */ 526 /* ACMD41 For v2 cards set HCS bit[30] & send host voltage range to all */
523 if(!send_cmd(drive, SD_APP_OP_COND, (0x00FF8000 | (sd_v2 ? 1<<30 : 0)), 527 if(!send_cmd(drive, SD_APP_OP_COND, (0x00FF8000 | (sd_v2 ? 1<<30 : 0)),
524 MCI_RESP, &card_info[drive].ocr)) 528 MCI_ACMD|MCI_RESP, &card_info[drive].ocr))
525 return -3; 529 return -3;
526 } while(!(card_info[drive].ocr & (1<<31)) ); 530 } while(!(card_info[drive].ocr & (1<<31)) );
527 531
@@ -583,18 +587,12 @@ static int sd_init_card(const int drive)
583 /* Switch to to 4 bit widebus mode */ 587 /* Switch to to 4 bit widebus mode */
584 if(sd_wait_for_tran_state(drive) < 0) 588 if(sd_wait_for_tran_state(drive) < 0)
585 return -13; 589 return -13;
586 /* CMD55 */ /* Response is requested due to timing issue */
587 if(!send_cmd(drive, SD_APP_CMD, card_info[drive].rca, MCI_RESP, &response))
588 return -14;
589 /* ACMD6 */ 590 /* ACMD6 */
590 if(!send_cmd(drive, SD_SET_BUS_WIDTH, 2, MCI_NO_RESP, NULL)) 591 if(!send_cmd(drive, SD_SET_BUS_WIDTH, 2, MCI_ACMD|MCI_NO_RESP, NULL))
591 return -15; 592 return -15;
592 mci_delay(); 593 mci_delay();
593 /* CMD55 */ /* Response is requested due to timing issue */
594 if(!send_cmd(drive, SD_APP_CMD, card_info[drive].rca, MCI_RESP, &response))
595 return -16;
596 /* ACMD42 */ 594 /* ACMD42 */
597 if(!send_cmd(drive, SD_SET_CLR_CARD_DETECT, 0, MCI_NO_RESP, NULL)) 595 if(!send_cmd(drive, SD_SET_CLR_CARD_DETECT, 0, MCI_ACMD|MCI_NO_RESP, NULL))
598 return -17; 596 return -17;
599 597
600 /* Now that card is widebus make controller aware */ 598 /* Now that card is widebus make controller aware */