gd_sdio.h 7.4 KB

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