Skip to content

Commit

Permalink
SD: TEMP
Browse files Browse the repository at this point in the history
Change-Id: I9c831e348097f4fa2402377cfbec633ab0963a81
  • Loading branch information
bahusoid committed Jul 29, 2024
1 parent b2ce5a2 commit ce72b97
Showing 1 changed file with 60 additions and 50 deletions.
110 changes: 60 additions & 50 deletions firmware/target/arm/as3525/sd-as3525.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,14 @@ static int sd_init_card(const int drive)
#if defined(HAVE_MULTIDRIVE)
else
/* MCICLK = PCLK/2 = 31MHz(HS) or PCLK/4 = 15.5 Mhz (STD)*/
MCI_CLOCK(drive) = (hs_card ? MCI_HALFSPEED : MCI_QUARTERSPEED) |
MCI_CLOCK_POWERSAVE; /* SD supports powersave */
MCI_CLOCK(drive) = (hs_card ? MCI_HALFSPEED : MCI_QUARTERSPEED);
#endif

/* CMD7 w/rca: Select card to put it in TRAN state */
if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_RESP, &response))
return -10;

#if 0 /* FIXME : it seems that reading fails on some models */

if(sd_wait_for_tran_state(drive) < 0)
return -13;

Expand Down Expand Up @@ -490,6 +488,9 @@ static int sd_init_card(const int drive)
return -19;
}

if(sd_wait_for_tran_state(drive) < 0)
return -13;

card_info[drive].initialized = 1;

return 0;
Expand Down Expand Up @@ -690,7 +691,7 @@ static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,
const int drive = 0;
#endif
bool aligned = !((uintptr_t)buf & (CACHEALIGN_SIZE - 1));
int retry_all = 4;
int retry_all = 10;
int const retry_data_max = 2;
int retry_data = retry_data_max;
unsigned int real_numblocks;
Expand All @@ -706,6 +707,12 @@ static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,

enable_controller(true, drive);
led(true);
forceSlow = true;
// if (forceSlow && !write)
// {
// forceSlow = false;
// goto retry_with_reinit;
// }

while (card_info[drive].initialized<=0)
{
Expand All @@ -730,11 +737,11 @@ static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,

if (sd_wait_for_tran_state(drive) != 0)
{
led(false);
enable_controller(false, drive);

enable_controller(true, drive);
led(true);
// led(false);
// enable_controller(false, drive);
//
// enable_controller(true, drive);
// led(true);

ret = -20;
++stat_full_reinint_count;
Expand Down Expand Up @@ -856,6 +863,36 @@ static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,
break;
}

if (sd_wait_for_tran_state(drive) != 0)
{
udelay(4);

// led(false);
// enable_controller(false, drive);
//
// enable_controller(true, drive);
// led(true);
// mci_delay();
if (sd_wait_for_tran_state(drive) != 0 && sd_init_card(drive) < 0)
{
ret = -6 * 20;
break;
}

if (sd_wait_for_tran_state(drive) != 0)
{
ret = -7 * 20;
break;
}
++stat_sd_reinint_count;
}
/*
* If the write aborted early due to a tx underrun, disable the
* dma channel here, otherwise there are still 4 words in the fifo
* and the retried write will get corrupted.
*/
dma_disable_channel(1);

if(!transfer_error)
{
if(!write && !aligned)
Expand All @@ -878,44 +915,17 @@ static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,
ret = -24;
break;
}
if (sd_wait_for_tran_state(drive) != 0)
{
led(false);
enable_controller(false, drive);

enable_controller(true, drive);
led(true);
mci_delay();
if(sd_init_card(drive) < 0)
{
ret = -6 * 20;
break;
}

if (sd_wait_for_tran_state(drive) != 0)
{
ret = -7 * 20;
break;
}
++stat_sd_reinint_count;
}
/*
* If the write aborted early due to a tx underrun, disable the
* dma channel here, otherwise there are still 4 words in the fifo
* and the retried write will get corrupted.
*/
dma_disable_channel(1);
}
dma_release();
if (ret != 0) /* if we have error */
{
forceSlow = !forceSlow;
led(false);
enable_controller(false, drive);

enable_controller(true, drive);
led(true);
mci_delay();
forceSlow = write ? true: false;
// led(false);
// enable_controller(false, drive);
//
// enable_controller(true, drive);
// led(true);
// mci_delay();
++stat_full_reinint_count;
goto retry_with_reinit;
}
Expand All @@ -929,14 +939,14 @@ static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,
{
card_info[drive].initialized = 0;

panicf("error:%d response:%lu, stop: %d, full: %d, data: %d, retry_all: %d, retry_data: %d, status: %d, total writes: %d",
ret, response, stat_sd_reinint_count, stat_full_reinint_count, stat_sd_data_errors, retry_all, retry_data, lastStatus, totalWrites);
}
if (forceSlow)
{
forceSlow = false;
card_info[drive].initialized = 0;
panicf("%serror:%d response:%lu, stop: %d, full: %d, data: %d, retry_all: %d, retry_data: %d, status: %d, total writes: %d",
drive == INTERNAL_AS3525 ? "INTSD ": "", ret, response, stat_sd_reinint_count, stat_full_reinint_count, stat_sd_data_errors, retry_all, retry_data, lastStatus, totalWrites);
}
// if (forceSlow)
// {
// forceSlow = false;
// card_info[drive].initialized = 0;
// }
return ret;
}

Expand Down

0 comments on commit ce72b97

Please sign in to comment.