/dev/sdio/slot0

From WiiBrew
< /dev‎ | sdio
Jump to: navigation, search

This allows access to the front SD slot.

GetDeviceStatus

SD_GetDeviceStatus
ios_ioctl( sd_fd, 0x0B, 0, 0, buffer, 4);

ResetDevice

SD_ResetDevice
ios_ioctl( sd_fd, 4, 0, 0, buffer, 4);

GetOCRegister

SD_GetOCRegister
ios_ioctl( sd_fd, 0xC, 0, 0, buffer, 4);

GetHCRegister

SD_GetHCRegister (untested iirc)
((u32*)inbuf)[0] = 0x28;
((u32*)inbuf)[3] = 1;
((u32*)inbuf)[4] = 0;

ios_ioctl( sd_fd, 2, inbuf, 0x18, outbuf, 4);

SetHCRegister

SD_SetHCRegister
((u32*)inbuf)[0] = 0x28;
((u32*)inbuf)[3] = 1;
((u32*)inbuf)[4] = value;

ios_ioctl( sd_fd, 1, inbuf, 0x18, 0, 0);

SendCMD

SD_SendCMD(cmd, cmd_type, resp_type, arg, buffer, block_count, sector_size)

((u32*)inbuf)[0]=cmd;
((u32*)inbuf)[1]=cmd_type;
((u32*)inbuf)[2]=resp_type;
((u32*)inbuf)[3]=arg;
((u32*)inbuf)[4]=block_count;
((u32*)inbuf)[5]=sector_size;
((u32*)inbuf)[6]=buffer;
((u32*)inbuf)[7]=0; // ?
((u32*)inbuf)[8]=0; // ?

ios_ioctl( sd_fd, 7, inbuf, 0x24, outbuf, 0x10);


SD Commands

SD_SendCmd(0x10, 3, 1, 0x200, 0, 0, 0) card_set_blocklen(0x200)
SD_SendCmd(0x37, 3, 1, ?, 0, 0, 0) set data bus width
SD_SendCmd(7, 3, 2, sd_status&0xFFFF0000, 0, 0, 0) -- select
SD_SendCmd(7, 3, 2, 0, 0, 0, 0) -- deselect 
IOS_Ioctl(fd, 11, 0, 0, (u32 *)&status, 4); -- get status
IOS_Ioctl(fd, 4, 0, 0, (u32 *)&status, 4) -- reset and get status
IOS_Ioctl(fd, 6, (u32 *)&clock, 4, 0, 0) -- using 1 as clock seems to work 
Set bus width to 4:
SD_SendCmd(0x37, 3, 1, sd_status&0xFFFF0000, 0, 0, 0)
SD_SendCmd(6, 3, 1, 2, 0, 0, 0)
Read the HCR register and AND it with ~0x2. If width is 4 bit OR it with 0x2 and write it back.

Block Read:
IOS_ioctlv(fd, 7, 2 /* input n */, 1 /* output n */, vectors)
First vector is {0x12, 3, 1, blockno * 0x200, 1, 0x200, &buffer /* 0x200 bytes */, 1, 0}, the second one is the buffer again (WTF?) and the third one a 0x10 byte reply buffer.
Do a reset and a select before the first read and set block length to 0x200, bus width to 4 and clock to 1 to make this command work.