gd_sdio.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #ifndef _GD_SDIO_H_
  2. #define _GD_SDIO_H_
  3. #include <gtypes.h>
  4. #include <gmodids.h>
  5. #define GD_SDIO0 0
  6. #define GD_SDIO1 1
  7. #define SDIO_CLK_DIV 0x01//0x02
  8. /*!
  9. *******************************************************************************
  10. **
  11. ** SDIO OPEN parameter.
  12. **
  13. ******************************************************************************/
  14. typedef struct
  15. {
  16. U32 isConnected;
  17. U32 sectorSize;
  18. U32 sectorCount;
  19. U32 mediaType;
  20. U32 manufacturerID;
  21. U32 applicationID;
  22. U32 productRevision;
  23. U32 serialNumber;
  24. U32 dataIoNumber;
  25. U8 productName[5];
  26. }GD_SDIO_VolumeInfoT;
  27. /*!
  28. *************************************************************************
  29. ** \brief Version of the SDIO driver.
  30. **
  31. ** This number consists of a \b major version number stored in bits
  32. ** 16 to 31 (upper word) and a \b minor version number stored in bits
  33. ** 0 to 15 (lower word).
  34. ** - The \b major number has to be increased when a parameter change
  35. ** occurs for the existing driver's API after its first release.
  36. ** - The \b minor number has to be increased when functions are added to
  37. ** the existing driver's API after its first release.
  38. **
  39. ** \note This value has to be assigend to the \b version field of the
  40. ** GAPI_SDIO_OpenParamsT structure.
  41. **
  42. *************************************************************************
  43. */
  44. typedef enum {
  45. GAPI_SDIO_VERSION = (S32)0x00010000 //!< The current driver version
  46. } GD_SDIO_VersionEnumT;
  47. typedef enum {
  48. GAPI_SDIO_TRANSFER_TYPE_NORMAL = 0, //!< Normal transfer type for SD/SDHC/MMC cards (default)
  49. GAPI_SDIO_TRANSFER_TYPE_DIRECT, //!< Direct transfer mode special for SDIO cards
  50. GAPI_SDIO_TRANSFER_TYPE_SECURE, //!< Spezial secure transfer mode for SD-Cards
  51. GAPI_SDIO_TRANSFER_TYPE_WIFI
  52. } GD_SDIO_TransferTypeEnumT;
  53. enum card_type
  54. {
  55. CARDTYPE_NONE = 0,
  56. CARDTYPE_MMC,
  57. CARDTYPE_SD10,
  58. CARDTYPE_SD20,
  59. CARDTYPE_SDHC
  60. };
  61. /*!
  62. ****************************************************************************
  63. **
  64. ** \brief SDIO callback function signature
  65. **
  66. ** This is the callback function signature required by the SDIO driver
  67. ** for internally notification functions.
  68. **
  69. ** \param comState Comunication status.
  70. ** \param optArgPtr Optional arg pointer.
  71. **
  72. ****************************************************************************
  73. */
  74. typedef void (*GD_SDIO_NotifyFuncT)(U32 index, U32 comState, void* optArgPtr);
  75. typedef void (*GD_SDIO_IRQFuncT)();
  76. typedef void (*GD_SDIO_RESETFuncT)(U32 index);
  77. /*!
  78. *************************************************************************
  79. ** \brief Open parameters for the SDIO driver.
  80. **
  81. ** This data structure covers all parameters which need to be specified
  82. ** when an instance of the driver is opened.
  83. **
  84. *************************************************************************
  85. */
  86. typedef struct {
  87. /*!
  88. The version of the driver.
  89. \ref GAPI_SDIO_VersionEnumT "GAPI_SDIO_VERSION".
  90. */
  91. GD_SDIO_VersionEnumT version;
  92. GD_SDIO_TransferTypeEnumT type;
  93. /*!
  94. ** The handle specific notification function.
  95. */
  96. GD_SDIO_NotifyFuncT notifyFunc;
  97. GD_SDIO_IRQFuncT irqFunc;
  98. GD_SDIO_RESETFuncT resetFunc;
  99. /*!
  100. ** Optional data pointer for the notification function.
  101. */
  102. void* notifyFuncOptPtr;
  103. /*!
  104. Flag to request DMA for read/write transfer operation.
  105. */
  106. U32 isUseDmaWay;
  107. } GD_SDIO_OpenParamsT;
  108. /*cid info */
  109. typedef struct
  110. {
  111. U8 MID; /*Manufacturer ID width:8[127:120]*/
  112. U16 OID; /*OEM/Application ID width:16[119:104]*/
  113. U8 PNM[5]; /*Product name width:40[103:64]*/
  114. U8 PRV; /*Product revision width:8[63:56]*/
  115. U32 PSN; /*Product serial number width:32[55:24]*/
  116. U16 MDT; /*Manufacturing date width:12[19:8]*/
  117. }sdioCidInfo;
  118. /*I just care about usefull info of CSD*/
  119. typedef struct
  120. {
  121. U8 csdStructure; /*csd revision*/
  122. U32 classes; /*Describes the card command classes CCC*/
  123. U32 tranSpeed; /*transfer speed*/
  124. U8 eraseBlkEn; /*erase block enable*/
  125. U8 permWriteProtect; /*write protect*/
  126. U8 tmpWriteProtect; /*write protect*/
  127. }sdiocsdInfo;
  128. /*I just case ablot usefull info of SCR*/
  129. typedef struct
  130. {
  131. U32 scrStructure; // SCR Register Structure Version
  132. U32 sdSpec; // Describes the Physical Layer Specification Version supported by the card.
  133. U32 stateaftererase; // Defines the data status after erase, whether it is 0 or 1.
  134. U32 sdSecurity; // Describes the Security Specification Version supported by the card.
  135. U32 sdBusWith; // Describes all the DAT bus widths that are supported by this card.
  136. }sdioScrInfo;
  137. typedef struct
  138. {
  139. U32 index; /*index of handle array*/
  140. U32 ocr; /*card volage info*/
  141. U32 csd[4]; /*csd info (invert)*/
  142. U32 read_bl_len;
  143. U32 write_bl_len;
  144. U64 capacity_user;
  145. U32 sectorcount;
  146. U32 inhighspeed;
  147. U32 maxTransferBlk;
  148. U32 eraseGrpSize;
  149. sdioScrInfo scr;
  150. sdiocsdInfo csdInfo;
  151. U32 tran_speed; /*max transfer speed*/
  152. U32 rca; /*card address*/
  153. U32 cid[4]; /*card cid info*/
  154. enum card_type type; /*card type*/
  155. U32 highCapacity; /*is high capacity*/
  156. sdioCidInfo cidInfo;
  157. }sdioBlockT;
  158. /* SDIO specific handle */
  159. typedef struct
  160. {
  161. U32 inUse; /* specifies if handle is in use */
  162. U32 index; /*index of handle array*/
  163. GD_SDIO_OpenParamsT openParams; /* open params of the handle */
  164. sdioBlockT devicePtr; /* pointer to hardware device */
  165. } sdioHandleT;
  166. typedef struct
  167. {
  168. U32 IRQStatus; /*!< content of IRQ status register.*/
  169. }SDIO_DATA_S;
  170. #define GD_SDIO_ERR_BASE (GD_SDIO_MODULE_ID<<16)
  171. //#define SDIO_INT_MODE
  172. enum
  173. {
  174. GD_ERR_SDIO_CARD_INIT_FAILED = GD_SDIO_ERR_BASE,
  175. GD_ERR_SDIO_INT_ERR,
  176. GD_ERR_SDIO_NO_CARD,
  177. GD_ERR_SDIO_CARD_BUSY,
  178. GD_ERR_SDIO_READ_FAILED,
  179. GD_ERR_SDIO_WRITE_FAILED,
  180. GD_ERR_SDIO_ERASE_FAILED,
  181. GD_ERR_SDIO_CMD_NO_SUPPORTED,
  182. GD_ERR_SDIO_SET_BLOCK_SIZE,
  183. GD_ERR_SDIO_CMD_FAILED,
  184. GD_ERR_SDIO_CARD_LOCKED
  185. };
  186. /*!
  187. *******************************************************************************
  188. **
  189. ** SDIO API functions.
  190. **
  191. ******************************************************************************/
  192. #ifdef __cplusplus
  193. extern "C" {
  194. #endif
  195. GERR GD_SDIO_Init(GD_SDIO_OpenParamsT* openParamsP, U32 index);
  196. GERR GD_SDIO_Exit(sdioHandleT *sdiohandle, U32 index);
  197. GERR GD_SDIO_Rsponse(void);
  198. GERR GD_SDIO_Open(GD_SDIO_OpenParamsT *openParamsP,sdioHandleT *pHandle, U32 index);
  199. GERR GD_SDIO_Close(sdioHandleT *sdiohandle, U32 index);
  200. GERR GD_SDIO_ReadSector(sdioHandleT * sdiohandle, U32 startblk, void* buffer, U32 blkcount);
  201. GERR GD_SDIO_WriteSector(sdioHandleT * sdiohandle, U32 startblk, void* buffer, U32 blkcount);
  202. GERR GD_SDIO_EraseSector(sdioHandleT * sdiohandle, U32 start, U32 blkcnt);
  203. GERR GD_SDIO_GetCardInfo(sdioHandleT * sdiohandle,GD_SDIO_VolumeInfoT * info,U32 index);
  204. #ifdef __cplusplus
  205. }
  206. #endif
  207. #endif