emmc_csl_sdcmd.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2016 - 2020, Broadcom
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef CSL_SD_CMD_H
  7. #define CSL_SD_CMD_H
  8. #define SD_CMD_OK 0
  9. #define SD_CMD_ERROR -1
  10. #define SD_CMD_ERR_NO_IO_FUNC 5
  11. #define SD_CMD_ERR_INVALID_PARAMETER 6
  12. #define SD_CMD_ERR_R1_ILLEGAL_COMMAND 7
  13. #define SD_CMD_ERR_R1_COM_CRC_ERROR 8
  14. #define SD_CMD_ERR_R1_FUNC_NUM_ERROR 9
  15. #define SD_CMD_ERR_R1_ADDRESS_ERROR 10
  16. #define SD_CMD_ERR_R1_PARAMETER_ERROR 11
  17. #define SD_CMD_ERR_DATA_ERROR_TOKEN 12
  18. #define SD_CMD_ERR_DATA_NOT_ACCEPTED 13
  19. #define SD_CMD7_ARG_RCA_SHIFT 16
  20. #define SD_CARD_STATUS_PENDING 0x01
  21. #define SD_CARD_STATUS_BUFFER_OVERFLOW 0x01
  22. #define SD_CARD_STATUS_DEVICE_BUSY 0x02
  23. #define SD_CARD_STATUS_UNSUCCESSFUL 0x03
  24. #define SD_CARD_STATUS_NOT_IMPLEMENTED 0x04
  25. #define SD_CARD_STATUS_ACCESS_VIOLATION 0x05
  26. #define SD_CARD_STATUS_INVALID_HANDLE 0x06
  27. #define SD_CARD_STATUS_INVALID_PARAMETER 0x07
  28. #define SD_CARD_STATUS_NO_SUCH_DEVICE 0x08
  29. #define SD_CARD_STATUS_INVALID_DEVICE_REQUEST 0x09
  30. #define SD_CARD_STATUS_NO_MEMORY 0x0A
  31. #define SD_CARD_STATUS_BUS_DRIVER_NOT_READY 0x0B
  32. #define SD_CARD_STATUS_DATA_ERROR 0x0C
  33. #define SD_CARD_STATUS_CRC_ERROR 0x0D
  34. #define SD_CARD_STATUS_INSUFFICIENT_RESOURCES 0x0E
  35. #define SD_CARD_STATUS_DEVICE_NOT_CONNECTED 0x10
  36. #define SD_CARD_STATUS_DEVICE_REMOVED 0x11
  37. #define SD_CARD_STATUS_DEVICE_NOT_RESPONDING 0x12
  38. #define SD_CARD_STATUS_CANCELED 0x13
  39. #define SD_CARD_STATUS_RESPONSE_TIMEOUT 0x14
  40. #define SD_CARD_STATUS_DATA_TIMEOUT 0x15
  41. #define SD_CARD_STATUS_DEVICE_RESPONSE_ERROR 0x16
  42. #define SD_CARD_STATUS_DEVICE_UNSUPPORTED 0x17
  43. /* Response structure */
  44. struct sd_r2_resp {
  45. uint32_t rsp4; /* 127:96 */
  46. uint32_t rsp3; /* 95:64 */
  47. uint32_t rsp2; /* 63:32 */
  48. uint32_t rsp1; /* 31:0 */
  49. };
  50. struct sd_r3_resp {
  51. uint32_t ocr;
  52. };
  53. struct sd_r4_resp {
  54. uint8_t cardReady;
  55. uint8_t funcs;
  56. uint8_t memPresent;
  57. uint32_t ocr;
  58. };
  59. struct sd_r5_resp {
  60. uint8_t data;
  61. };
  62. struct sd_r6_resp {
  63. uint16_t rca;
  64. uint16_t cardStatus;
  65. };
  66. struct sd_r7_resp {
  67. uint16_t rca;
  68. };
  69. struct sd_resp {
  70. uint8_t r1;
  71. uint32_t cardStatus;
  72. uint32_t rawData[4];
  73. union {
  74. struct sd_r2_resp r2;
  75. struct sd_r3_resp r3;
  76. struct sd_r4_resp r4;
  77. struct sd_r5_resp r5;
  78. struct sd_r6_resp r6;
  79. struct sd_r7_resp r7;
  80. } data;
  81. };
  82. struct sd_card_info {
  83. uint32_t type; /* card type SD, MMC or SDIO */
  84. uint64_t size; /* card size */
  85. uint32_t speed; /* card speed */
  86. uint32_t voltage; /* voltage supported */
  87. uint32_t mId; /* manufacturer ID */
  88. uint32_t oId; /* OEM ID */
  89. uint32_t classes; /* card class */
  90. uint32_t name1; /* product name part 1 */
  91. uint32_t name2; /* product name part 2 */
  92. uint32_t revision; /* revison */
  93. uint32_t sn; /* serial number */
  94. uint32_t numIoFuns; /* total I/O function number */
  95. uint32_t maxRdBlkLen; /* max read block length */
  96. uint32_t maxWtBlkLen; /* max write block length */
  97. uint32_t blkMode; /* sdio card block mode support */
  98. uint32_t f0Cis; /* sdio card block mode support */
  99. uint32_t f1Cis; /* sdio card block mode support */
  100. uint8_t partRead; /* partial block read allowed */
  101. uint8_t partWrite; /* partial block write allowed */
  102. uint8_t dsr; /* card DSR */
  103. uint8_t rdCurMin; /* min current for read */
  104. uint8_t rdCurMax; /* max current for read */
  105. uint8_t wtCurMin; /* min current for write */
  106. uint8_t wtCurMax; /* max current for write */
  107. uint8_t erase; /* erase enable */
  108. uint8_t eraseSecSize; /* erase sector size */
  109. uint8_t proGrpSize; /* write protection group size */
  110. uint8_t protect; /* permanent write protection or not */
  111. uint8_t tmpProt; /* temp write protection or not */
  112. uint8_t wtSpeed; /* write speed relatively to read */
  113. uint8_t version; /* card version 0:1.0 - 1.01, 1:1.10, 2:2.0 */
  114. uint8_t eraseState; /* if the data will be 0 or 1 after erase */
  115. uint8_t bus; /* data with supported */
  116. uint8_t security; /* security support 0, 2:1.01 3:2.0 */
  117. uint8_t format; /* file format */
  118. uint8_t fileGrp; /* file group */
  119. char pwd[20]; /* password */
  120. };
  121. struct sd_handle {
  122. struct sd_dev *device;
  123. struct sd_card_info *card;
  124. };
  125. int sd_cmd0(struct sd_handle *handle);
  126. int sd_cmd1(struct sd_handle *handle, uint32_t initOcr, uint32_t *ocr);
  127. int sd_cmd2(struct sd_handle *handle);
  128. int sd_cmd3(struct sd_handle *handle);
  129. int sd_cmd7(struct sd_handle *handle, uint32_t rca);
  130. int sd_cmd9(struct sd_handle *handle, struct sd_card_data *card);
  131. int sd_cmd13(struct sd_handle *handle, uint32_t *status);
  132. int sd_cmd16(struct sd_handle *handle, uint32_t blockLen);
  133. int sd_cmd17(struct sd_handle *handle,
  134. uint32_t addr, uint32_t len, uint8_t *buffer);
  135. int sd_cmd18(struct sd_handle *handle,
  136. uint32_t addr, uint32_t len, uint8_t *buffer);
  137. #ifdef INCLUDE_EMMC_DRIVER_WRITE_CODE
  138. int sd_cmd24(struct sd_handle *handle,
  139. uint32_t addr, uint32_t len, uint8_t *buffer);
  140. int sd_cmd25(struct sd_handle *handle,
  141. uint32_t addr, uint32_t len, uint8_t *buffer);
  142. #endif
  143. #ifdef INCLUDE_EMMC_DRIVER_ERASE_CODE
  144. int sd_cmd35(struct sd_handle *handle, uint32_t start);
  145. int sd_cmd36(struct sd_handle *handle, uint32_t end);
  146. int sd_cmd38(struct sd_handle *handle);
  147. #endif
  148. int mmc_cmd6(struct sd_handle *handle, uint32_t argument);
  149. int mmc_cmd8(struct sd_handle *handle, uint8_t *extCsdReg);
  150. int send_cmd(struct sd_handle *handle, uint32_t cmdIndex,
  151. uint32_t argument, uint32_t options, struct sd_resp *resp);
  152. #endif /* CSL_SD_CMD_H */