drv_mmc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * File : drv_mmc.h
  3. * This file is part of gkipc BSP for RT-Thread distribution.
  4. *
  5. * Copyright (c) 2017 chengdu goke Microelectronics Co., Ltd.
  6. * All rights reserved
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Visit http://www.goke.com to get contact with goke.
  23. *
  24. * Change Logs:
  25. * Date Author Notes
  26. */
  27. #ifndef MMC_H_
  28. #define MMC_H_
  29. #include "rtdevice.h"
  30. #define MMC_FEQ_MIN 100000
  31. #define MMC_FEQ_MAX 50000000
  32. #define MMC_DMA_DESC_BUFF_SIZE (0x1f00)
  33. #define MMC_HANDLE_COUNT 2
  34. #define CARD_UNPLUGED 1
  35. #define CARD_PLUGED 0
  36. typedef enum {
  37. RT_GAPI_SDIO_VERSION = (rt_int32_t)0x00010000 //!< The current driver version
  38. } RT_SDIO_VersionEnumT;
  39. typedef enum {
  40. RT_GAPI_SDIO_TRANSFER_TYPE_NORMAL = 0, //!< Normal transfer type for SD/SDHC/MMC cards (default)
  41. RT_GAPI_SDIO_TRANSFER_TYPE_DIRECT, //!< Direct transfer mode special for SDIO cards
  42. RT_GAPI_SDIO_TRANSFER_TYPE_SECURE, //!< Spezial secure transfer mode for SD-Cards
  43. RT_GAPI_SDIO_TRANSFER_TYPE_WIFI
  44. } RT_SDIO_TransferTypeEnumT;
  45. typedef enum rt_card_type
  46. {
  47. RT_CARDTYPE_NONE = 0,
  48. RT_CARDTYPE_MMC,
  49. RT_CARDTYPE_SD10,
  50. RT_CARDTYPE_SD20,
  51. RT_CARDTYPE_SDHC
  52. }RT_SDIO_Card_Type;
  53. /*!
  54. ****************************************************************************
  55. **
  56. ** \brief SDIO callback function signature
  57. **
  58. ** This is the callback function signature required by the SDIO driver
  59. ** for internally notification functions.
  60. **
  61. ** \param comState Comunication status.
  62. ** \param optArgPtr Optional arg pointer.
  63. **
  64. ****************************************************************************
  65. */
  66. typedef void (*RT_SDIO_NotifyFuncT)(rt_uint32_t index, rt_uint32_t comState, void* optArgPtr);
  67. typedef void (*RT_SDIO_IRQFuncT)();
  68. typedef void (*RT_SDIO_RESETFuncT)(rt_uint32_t index);
  69. typedef struct {
  70. /*!
  71. The version of the driver.
  72. \ref GAPI_SDIO_VersionEnumT "GAPI_SDIO_VERSION".
  73. */
  74. RT_SDIO_VersionEnumT version;
  75. RT_SDIO_TransferTypeEnumT type;
  76. /*!
  77. ** The handle specific notification function.
  78. */
  79. RT_SDIO_NotifyFuncT notifyFunc;
  80. RT_SDIO_IRQFuncT irqFunc;
  81. RT_SDIO_RESETFuncT resetFunc;
  82. /*!
  83. ** Optional data pointer for the notification function.
  84. */
  85. void* notifyFuncOptPtr;
  86. /*!
  87. Flag to request DMA for read/write transfer operation.
  88. */
  89. rt_uint32_t isUseDmaWay;
  90. }RT_SDIO_OpenParamsT;
  91. /*cid info */
  92. typedef struct
  93. {
  94. rt_uint8_t MID; /*Manufacturer ID width:8[127:120]*/
  95. rt_uint16_t OID; /*OEM/Application ID width:16[119:104]*/
  96. rt_uint8_t PNM[5]; /*Product name width:40[103:64]*/
  97. rt_uint8_t PRV; /*Product revision width:8[63:56]*/
  98. rt_uint32_t PSN; /*Product serial number width:32[55:24]*/
  99. rt_uint16_t MDT; /*Manufacturing date width:12[19:8]*/
  100. }rtSdioCidInfo;
  101. /*I just care about usefull info of CSD*/
  102. typedef struct
  103. {
  104. rt_uint8_t csdStructure; /*csd revision*/
  105. rt_uint32_t classes; /*Describes the card command classes CCC*/
  106. rt_uint32_t tranSpeed; /*transfer speed*/
  107. rt_uint8_t eraseBlkEn; /*erase block enable*/
  108. rt_uint8_t permWriteProtect; /*write protect*/
  109. rt_uint8_t tmpWriteProtect; /*write protect*/
  110. }rtSdiocsdInfo;
  111. /*I just case ablot usefull info of SCR*/
  112. typedef struct
  113. {
  114. rt_uint32_t scrStructure; // SCR Register Structure Version
  115. rt_uint32_t sdSpec; // Describes the Physical Layer Specification Version supported by the card.
  116. rt_uint32_t stateaftererase; // Defines the data status after erase, whether it is 0 or 1.
  117. rt_uint32_t sdSecurity; // Describes the Security Specification Version supported by the card.
  118. rt_uint32_t sdBusWith; // Describes all the DAT bus widths that are supported by this card.
  119. }rtSdioScrInfo;
  120. typedef struct
  121. {
  122. rt_uint32_t index; /*index of handle array*/
  123. rt_uint32_t ocr; /*card volage info*/
  124. rt_uint32_t csd[4]; /*csd info (invert)*/
  125. rt_uint32_t read_bl_len;
  126. rt_uint32_t write_bl_len;
  127. unsigned long long capacity_user;
  128. rt_uint32_t sectorcount;
  129. rt_uint32_t inhighspeed;
  130. rt_uint32_t maxTransferBlk;
  131. rt_uint32_t eraseGrpSize;
  132. rtSdioScrInfo scr;
  133. rtSdiocsdInfo csdInfo;
  134. rt_uint32_t tran_speed; /*max transfer speed*/
  135. rt_uint32_t rca; /*card address*/
  136. rt_uint32_t cid[4]; /*card cid info*/
  137. enum rt_card_type type; /*card type*/
  138. rt_uint32_t highCapacity; /*is high capacity*/
  139. rtSdioCidInfo cidInfo;
  140. }rtSdioBlockT;
  141. /* SDIO specific handle */
  142. typedef struct
  143. {
  144. rt_uint32_t inUse; /* specifies if handle is in use */
  145. rt_uint32_t index; /*index of handle array*/
  146. RT_SDIO_OpenParamsT openParams; /* open params of the handle */
  147. rtSdioBlockT devicePtr; /* pointer to hardware device */
  148. } rtSdioHandleT;
  149. typedef struct gk_mmc_driver
  150. {
  151. rtSdioHandleT handle;
  152. RT_SDIO_OpenParamsT openParams;
  153. struct rt_device *deviceP[MMC_HANDLE_COUNT];
  154. struct dfs_partition *partP[MMC_HANDLE_COUNT];
  155. }gk_mmc_driver_s;
  156. typedef void (*fs_sdio_notify_func_t)(rt_uint32_t index, rt_uint32_t comState, void* optArgPtr);
  157. int rt_hw_mmc_init(gk_mmc_driver_s *pMmcParams);
  158. #endif /* MMC_H_ */