Difference between revisions of "/dev/sdio/slot0"

From WiiBrew
< /dev‎ | sdio
Jump to navigation Jump to search
(small makeup)
Line 1: Line 1:
 
This allows access to the front SD slot.
 
This allows access to the front SD slot.
 
===GetDeviceStatus===
 
===GetDeviceStatus===
 +
<source lang="c">
 
  SD_GetDeviceStatus
 
  SD_GetDeviceStatus
 
  ios_ioctl( sd_fd, 0x0B, 0, 0, buffer, 4);
 
  ios_ioctl( sd_fd, 0x0B, 0, 0, buffer, 4);
 +
</source>
 
===ResetDevice===
 
===ResetDevice===
 +
<source lang="c">
 
  SD_ResetDevice
 
  SD_ResetDevice
 
  ios_ioctl( sd_fd, 4, 0, 0, buffer, 4);
 
  ios_ioctl( sd_fd, 4, 0, 0, buffer, 4);
 +
</source>
 
===GetOCRegister===
 
===GetOCRegister===
 +
<source lang="c">
 
  SD_GetOCRegister
 
  SD_GetOCRegister
 
  ios_ioctl( sd_fd, 0xC, 0, 0, buffer, 4);
 
  ios_ioctl( sd_fd, 0xC, 0, 0, buffer, 4);
 +
</source>
 
===GetHCRegister===
 
===GetHCRegister===
 +
<source lang="c">
 
  SD_GetHCRegister (untested iirc)
 
  SD_GetHCRegister (untested iirc)
 
  ((u32*)inbuf)[0] = 0x28;
 
  ((u32*)inbuf)[0] = 0x28;
Line 16: Line 23:
 
   
 
   
 
  ios_ioctl( sd_fd, 2, inbuf, 0x18, outbuf, 4);
 
  ios_ioctl( sd_fd, 2, inbuf, 0x18, outbuf, 4);
 
+
</source>
 
===SetHCRegister===
 
===SetHCRegister===
 +
<source lang="c">
 
  SD_SetHCRegister
 
  SD_SetHCRegister
 
  ((u32*)inbuf)[0] = 0x28;
 
  ((u32*)inbuf)[0] = 0x28;
Line 24: Line 32:
 
   
 
   
 
  ios_ioctl( sd_fd, 1, inbuf, 0x18, 0, 0);
 
  ios_ioctl( sd_fd, 1, inbuf, 0x18, 0, 0);
 +
</source>
 
===SendCMD===
 
===SendCMD===
 +
<source lang="c">
 
  SD_SendCMD(cmd, cmd_type, resp_type, arg, buffer, block_count, sector_size)
 
  SD_SendCMD(cmd, cmd_type, resp_type, arg, buffer, block_count, sector_size)
 
   
 
   
Line 38: Line 48:
 
   
 
   
 
  ios_ioctl( sd_fd, 7, inbuf, 0x24, outbuf, 0x10);
 
  ios_ioctl( sd_fd, 7, inbuf, 0x24, outbuf, 0x10);
 
+
</source>
  
 
===SD Commands===
 
===SD Commands===
 
+
<source lang="c">
  
 
  SD_SendCmd(0x10, 3, 1, 0x200, 0, 0, 0) card_set_blocklen(0x200)
 
  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(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, sd_status&0xFFFF0000, 0, 0, 0) // select
  SD_SendCmd(7, 3, 2, 0, 0, 0, 0) -- deselect  
+
  SD_SendCmd(7, 3, 2, 0, 0, 0, 0) // deselect  
  IOS_Ioctl(fd, 11, 0, 0, (u32 *)&status, 4); -- get status
+
  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, 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  
+
  IOS_Ioctl(fd, 6, (u32 *)&clock, 4, 0, 0) // using 1 as clock seems to work  
  
Set bus width to 4:
+
</source>
 +
====''Set bus width to 4''====
 +
<source lang="c">
 
  SD_SendCmd(0x37, 3, 1, sd_status&0xFFFF0000, 0, 0, 0)
 
  SD_SendCmd(0x37, 3, 1, sd_status&0xFFFF0000, 0, 0, 0)
 
  SD_SendCmd(6, 3, 1, 2, 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:
+
  //Read the HCR register and AND it with ~0x2. If width is 4 bit OR it with 0x2 and write it back.
 +
</source>
 +
 
 +
====''Block Read''====
 +
<source lang="c">
 
  IOS_ioctlv(fd, 7, 2 /* input n */, 1 /* output n */, vectors)
 
  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.
 
0x12 is CMD18 READ_MULTIPLE_BLOCK
 
3 seems to be CMDTYPE AC (Addressed Command) although it should be ADTC (Address Data Tranfer Command)
 
blockno * 0x200 (512) is the offset in bytes of the block as expected by CMD18
 
0x200 (512) is the default block size
 
  
  Block Write:
+
  // 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.
 +
// 0x12 is CMD18 READ_MULTIPLE_BLOCK
 +
// 3 seems to be CMDTYPE AC (Addressed Command) although it should be ADTC (Address Data Tranfer Command)
 +
// blockno * 0x200 (512) is the offset in bytes of the block as expected by CMD18
 +
// 0x200 (512) is the default block size
 +
</source>
 +
====''Block Write''====
 
  Works the same way as reading does. Just use 0x19 instead of 0x12 in the first vector.
 
  Works the same way as reading does. Just use 0x19 instead of 0x12 in the first vector.
 
  0x19 is CMD25 WRITE_MULTIPLE_BLOCK
 
  0x19 is CMD25 WRITE_MULTIPLE_BLOCK
 
 
 
[[Category:IOS API documentation]]
 
[[Category:IOS API documentation]]

Revision as of 13:08, 2 April 2008

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.
 // 0x12 is CMD18 READ_MULTIPLE_BLOCK
 // 3 seems to be CMDTYPE AC (Addressed Command) although it should be ADTC (Address Data Tranfer Command)
 // blockno * 0x200 (512) is the offset in bytes of the block as expected by CMD18
 // 0x200 (512) is the default block size

Block Write

Works the same way as reading does. Just use 0x19 instead of 0x12 in the first vector.
0x19 is CMD25 WRITE_MULTIPLE_BLOCK