Skip to content

Commit

Permalink
Do the same with the SD Gecko on the Wii
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Jan 5, 2025
1 parent 329b800 commit 9034d1b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions gc/sdcard/card_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/* CSD Register */
#define CSD_STRUCTURE(drv_no) ((u8)((g_CSD[drv_no][0]>>6)&0x03))
#define TRAN_SPEED(drv_no) ((u8)(g_CSD[drv_no][3]))
#define CCC(drv_no) ((u16)((g_CSD[drv_no][4]<<4)|((g_CSD[drv_no][5]>>4)&0x0f)))
#define READ_BL_LEN(drv_no) ((u8)(g_CSD[drv_no][5]&0x0f))
#define C_SIZE(drv_no) ((u16)(((g_CSD[drv_no][6]&0x03)<<10)|(g_CSD[drv_no][7]<<2)|((g_CSD[drv_no][8]>>6)&0x03)))
Expand Down
31 changes: 31 additions & 0 deletions libogc/sdgecko_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,27 @@ static s32 __card_sendopcond(s32 drv_no)
return CARDIO_ERROR_READY;
}

static s32 __card_sendCMD6(s32 drv_no,u32 switch_func)
{
s32 ret;
u8 arg[4] = {0,0,0,0};

if(drv_no<0 || drv_no>=MAX_DRIVE) return CARDIO_ERROR_NOCARD;

arg[0] = (switch_func>>24)&0xff;
arg[1] = (switch_func>>16)&0xff;
arg[2] = (switch_func>>8)&0xff;
arg[3] = switch_func&0xff;
if((ret=__card_sendcmd(drv_no,0x06,arg))!=0) {
#ifdef _CARDIO_DEBUG
printf("__card_sendCMD6(%d): sd write cmd failed.\n",ret);
#endif
return ret;
}
if((ret=__card_response1(drv_no))!=0) return ret;
return __card_dataread(drv_no,_ioResponse[drv_no],64);
}

static s32 __card_sendCMD8(s32 drv_no)
{
s32 ret;
Expand Down Expand Up @@ -1238,6 +1259,7 @@ s32 sdgecko_initIO(s32 drv_no)
{
if(drv_no<0 || drv_no>=MAX_DRIVE) return CARDIO_ERROR_NOCARD;

if(_ioCardFreq[drv_no]>EXI_SPEED32MHZ) _ioCardFreq[drv_no] = EXI_SPEED32MHZ;
if(_ioRetryCnt>=3) _ioCardFreq[drv_no] = EXI_SPEED16MHZ;
if(_ioRetryCnt>=6) {
_ioRetryCnt = 0;
Expand Down Expand Up @@ -1283,6 +1305,15 @@ s32 sdgecko_initIO(s32 drv_no)
_ioPageSize[drv_no] = PAGE_SIZE512;
if(__card_setblocklen(drv_no,_ioPageSize[drv_no])!=0) goto exit;

#if defined(HW_RVL)
if(CCC(drv_no)&(1<<10) && _ioCardFreq[drv_no]==EXI_SPEED32MHZ) {
if(__card_sendCMD6(drv_no,0x00fffff0)!=0) goto exit;
if(((u16*)_ioResponse[drv_no])[6]&(1<<1)) {
if(__card_sendCMD6(drv_no,0x80fffff1)!=0) goto exit;
if((_ioResponse[drv_no][16]&0xf)==1) _ioCardFreq[drv_no] = EXI_SPEED64MHZ;
}
}
#endif
if(__card_sd_status(drv_no)!=0) goto exit;

_ioRetryCnt = 0;
Expand Down
3 changes: 2 additions & 1 deletion libogc/wiisd.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
#define SDIO_STATUS_CARD_SDHC 0x100000

#define CSD_STRUCTURE ((u8)((__sd0_csd[13]>>6)&0x03))
#define TRAN_SPEED ((u8)(__sd0_csd[8]))
#define CCC ((u16)((__sd0_csd[9]<<4)|((__sd0_csd[10]>>4)&0x0f)))
#define READ_BL_LEN ((u8)(__sd0_csd[10]&0x0f))
#define C_SIZE ((u16)(((__sd0_csd[11]&0x03)<<10)|(__sd0_csd[4]<<2)|((__sd0_csd[5]>>6)&0x03)))
Expand Down Expand Up @@ -517,7 +518,7 @@ static bool __sd0_initio(DISC_INTERFACE *disc)
return false;
}

if(__sd0_functions[13] & (1 << 1)) {
if(((u16*)__sd0_functions)[6] & (1 << 1)) {
ret = __sdio_sendcommand(SDIO_CMD_SWITCHFUNC, 1, SDIO_RESPONSE_R1, 0x80fffff1, 1, sizeof(__sd0_functions), __sd0_functions, NULL, 0);
if(ret<0) {
__sd0_deselect();
Expand Down

0 comments on commit 9034d1b

Please sign in to comment.