| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#ifndef CSL_SD_CMD_H |
| 8 |
#define CSL_SD_CMD_H |
| 9 |
|
| 10 |
#define SD_CMD_OK 0 |
| 11 |
#define SD_CMD_ERROR -1 |
| 12 |
|
| 13 |
#define SD_CMD_ERR_NO_IO_FUNC 5 |
| 14 |
#define SD_CMD_ERR_INVALID_PARAMETER 6 |
| 15 |
#define SD_CMD_ERR_R1_ILLEGAL_COMMAND 7 |
| 16 |
#define SD_CMD_ERR_R1_COM_CRC_ERROR 8 |
| 17 |
#define SD_CMD_ERR_R1_FUNC_NUM_ERROR 9 |
| 18 |
#define SD_CMD_ERR_R1_ADDRESS_ERROR 10 |
| 19 |
#define SD_CMD_ERR_R1_PARAMETER_ERROR 11 |
| 20 |
#define SD_CMD_ERR_DATA_ERROR_TOKEN 12 |
| 21 |
#define SD_CMD_ERR_DATA_NOT_ACCEPTED 13 |
| 22 |
#define SD_CMD7_ARG_RCA_SHIFT 16 |
| 23 |
|
| 24 |
#define SD_CARD_STATUS_PENDING 0x01 |
| 25 |
#define SD_CARD_STATUS_BUFFER_OVERFLOW 0x01 |
| 26 |
#define SD_CARD_STATUS_DEVICE_BUSY 0x02 |
| 27 |
#define SD_CARD_STATUS_UNSUCCESSFUL 0x03 |
| 28 |
#define SD_CARD_STATUS_NOT_IMPLEMENTED 0x04 |
| 29 |
#define SD_CARD_STATUS_ACCESS_VIOLATION 0x05 |
| 30 |
#define SD_CARD_STATUS_INVALID_HANDLE 0x06 |
| 31 |
#define SD_CARD_STATUS_INVALID_PARAMETER 0x07 |
| 32 |
#define SD_CARD_STATUS_NO_SUCH_DEVICE 0x08 |
| 33 |
#define SD_CARD_STATUS_INVALID_DEVICE_REQUEST 0x09 |
| 34 |
#define SD_CARD_STATUS_NO_MEMORY 0x0A |
| 35 |
#define SD_CARD_STATUS_BUS_DRIVER_NOT_READY 0x0B |
| 36 |
#define SD_CARD_STATUS_DATA_ERROR 0x0C |
| 37 |
#define SD_CARD_STATUS_CRC_ERROR 0x0D |
| 38 |
#define SD_CARD_STATUS_INSUFFICIENT_RESOURCES 0x0E |
| 39 |
#define SD_CARD_STATUS_DEVICE_NOT_CONNECTED 0x10 |
| 40 |
#define SD_CARD_STATUS_DEVICE_REMOVED 0x11 |
| 41 |
#define SD_CARD_STATUS_DEVICE_NOT_RESPONDING 0x12 |
| 42 |
#define SD_CARD_STATUS_CANCELED 0x13 |
| 43 |
#define SD_CARD_STATUS_RESPONSE_TIMEOUT 0x14 |
| 44 |
#define SD_CARD_STATUS_DATA_TIMEOUT 0x15 |
| 45 |
#define SD_CARD_STATUS_DEVICE_RESPONSE_ERROR 0x16 |
| 46 |
#define SD_CARD_STATUS_DEVICE_UNSUPPORTED 0x17 |
| 47 |
|
| 48 |
|
| 49 |
struct sd_r2_resp { |
| 50 |
uint32_t rsp4; |
| 51 |
uint32_t rsp3; |
| 52 |
uint32_t rsp2; |
| 53 |
uint32_t rsp1; |
| 54 |
}; |
| 55 |
|
| 56 |
struct sd_r3_resp { |
| 57 |
uint32_t ocr; |
| 58 |
}; |
| 59 |
|
| 60 |
struct sd_r4_resp { |
| 61 |
uint8_t cardReady; |
| 62 |
uint8_t funcs; |
| 63 |
uint8_t memPresent; |
| 64 |
uint32_t ocr; |
| 65 |
}; |
| 66 |
|
| 67 |
struct sd_r5_resp { |
| 68 |
uint8_t data; |
| 69 |
}; |
| 70 |
|
| 71 |
struct sd_r6_resp { |
| 72 |
uint16_t rca; |
| 73 |
uint16_t cardStatus; |
| 74 |
}; |
| 75 |
|
| 76 |
struct sd_r7_resp { |
| 77 |
uint16_t rca; |
| 78 |
}; |
| 79 |
|
| 80 |
struct sd_resp { |
| 81 |
uint8_t r1; |
| 82 |
uint32_t cardStatus; |
| 83 |
uint32_t rawData[4]; |
| 84 |
union { |
| 85 |
struct sd_r2_resp r2; |
| 86 |
struct sd_r3_resp r3; |
| 87 |
struct sd_r4_resp r4; |
| 88 |
struct sd_r5_resp r5; |
| 89 |
struct sd_r6_resp r6; |
| 90 |
struct sd_r7_resp r7; |
| 91 |
} data; |
| 92 |
}; |
| 93 |
|
| 94 |
struct sd_card_info { |
| 95 |
uint32_t type; |
| 96 |
uint64_t size; |
| 97 |
uint32_t speed; |
| 98 |
uint32_t voltage; |
| 99 |
uint32_t mId; |
| 100 |
uint32_t oId; |
| 101 |
uint32_t classes; |
| 102 |
uint32_t name1; |
| 103 |
uint32_t name2; |
| 104 |
uint32_t revision; |
| 105 |
uint32_t sn; |
| 106 |
uint32_t numIoFuns; |
| 107 |
uint32_t maxRdBlkLen; |
| 108 |
uint32_t maxWtBlkLen; |
| 109 |
uint32_t blkMode; |
| 110 |
uint32_t f0Cis; |
| 111 |
uint32_t f1Cis; |
| 112 |
|
| 113 |
uint8_t partRead; |
| 114 |
uint8_t partWrite; |
| 115 |
uint8_t dsr; |
| 116 |
uint8_t rdCurMin; |
| 117 |
uint8_t rdCurMax; |
| 118 |
uint8_t wtCurMin; |
| 119 |
uint8_t wtCurMax; |
| 120 |
uint8_t erase; |
| 121 |
uint8_t eraseSecSize; |
| 122 |
uint8_t proGrpSize; |
| 123 |
uint8_t protect; |
| 124 |
uint8_t tmpProt; |
| 125 |
uint8_t wtSpeed; |
| 126 |
uint8_t version; |
| 127 |
uint8_t eraseState; |
| 128 |
uint8_t bus; |
| 129 |
uint8_t security; |
| 130 |
uint8_t format; |
| 131 |
uint8_t fileGrp; |
| 132 |
char pwd[20]; |
| 133 |
}; |
| 134 |
|
| 135 |
struct sd_handle { |
| 136 |
struct sd_dev *device; |
| 137 |
struct sd_card_info *card; |
| 138 |
}; |
| 139 |
|
| 140 |
int sd_cmd0(struct sd_handle *handle); |
| 141 |
int sd_cmd1(struct sd_handle *handle, uint32_t initOcr, uint32_t *ocr); |
| 142 |
int sd_cmd2(struct sd_handle *handle); |
| 143 |
int sd_cmd3(struct sd_handle *handle); |
| 144 |
int sd_cmd7(struct sd_handle *handle, uint32_t rca); |
| 145 |
int sd_cmd9(struct sd_handle *handle, struct sd_card_data *card); |
| 146 |
int sd_cmd13(struct sd_handle *handle, uint32_t *status); |
| 147 |
int sd_cmd16(struct sd_handle *handle, uint32_t blockLen); |
| 148 |
int sd_cmd17(struct sd_handle *handle, |
| 149 |
uint32_t addr, uint32_t len, uint8_t *buffer); |
| 150 |
int sd_cmd18(struct sd_handle *handle, |
| 151 |
uint32_t addr, uint32_t len, uint8_t *buffer); |
| 152 |
#ifdef INCLUDE_EMMC_DRIVER_WRITE_CODE |
| 153 |
int sd_cmd24(struct sd_handle *handle, |
| 154 |
uint32_t addr, uint32_t len, uint8_t *buffer); |
| 155 |
int sd_cmd25(struct sd_handle *handle, |
| 156 |
uint32_t addr, uint32_t len, uint8_t *buffer); |
| 157 |
#endif |
| 158 |
#ifdef INCLUDE_EMMC_DRIVER_ERASE_CODE |
| 159 |
int sd_cmd35(struct sd_handle *handle, uint32_t start); |
| 160 |
int sd_cmd36(struct sd_handle *handle, uint32_t end); |
| 161 |
int sd_cmd38(struct sd_handle *handle); |
| 162 |
#endif |
| 163 |
int mmc_cmd6(struct sd_handle *handle, uint32_t argument); |
| 164 |
int mmc_cmd8(struct sd_handle *handle, uint8_t *extCsdReg); |
| 165 |
|
| 166 |
int send_cmd(struct sd_handle *handle, uint32_t cmdIndex, |
| 167 |
uint32_t argument, uint32_t options, struct sd_resp *resp); |
| 168 |
#endif |