11#ifndef __DEV_MMCSD_CORE_H__
12#define __DEV_MMCSD_CORE_H__
24#define mmcsd_dbg(fmt, ...) rt_kprintf(fmt, ##__VA_ARGS__)
26#define mmcsd_dbg(fmt, ...)
36#define DATA_DIR_WRITE (1 << 0)
37#define DATA_DIR_READ (1 << 1)
38#define DATA_STREAM (1 << 2)
63#define RESP_MASK (0xF)
65#define RESP_R1 (1 << 0)
66#define RESP_R1B (2 << 0)
67#define RESP_R2 (3 << 0)
68#define RESP_R3 (4 << 0)
69#define RESP_R4 (5 << 0)
70#define RESP_R6 (6 << 0)
71#define RESP_R7 (7 << 0)
72#define RESP_R5 (8 << 0)
76#define CMD_MASK (3 << 4)
77#define CMD_AC (0 << 4)
78#define CMD_ADTC (1 << 4)
79#define CMD_BC (2 << 4)
80#define CMD_BCR (3 << 4)
82#define resp_type(cmd) ((cmd)->flags & RESP_MASK)
87#define RESP_SPI_MASK (0x7 << 6)
88#define RESP_SPI_R1 (1 << 6)
89#define RESP_SPI_R1B (2 << 6)
90#define RESP_SPI_R2 (3 << 6)
91#define RESP_SPI_R3 (4 << 6)
92#define RESP_SPI_R4 (5 << 6)
93#define RESP_SPI_R5 (6 << 6)
94#define RESP_SPI_R7 (7 << 6)
96#define spi_resp_type(cmd) ((cmd)->flags & RESP_SPI_MASK)
100#define cmd_type(cmd) ((cmd)->flags & CMD_MASK)
121#define R1_OUT_OF_RANGE (1 << 31)
122#define R1_ADDRESS_ERROR (1 << 30)
123#define R1_BLOCK_LEN_ERROR (1 << 29)
124#define R1_ERASE_SEQ_ERROR (1 << 28)
125#define R1_ERASE_PARAM (1 << 27)
126#define R1_WP_VIOLATION (1 << 26)
127#define R1_CARD_IS_LOCKED (1 << 25)
128#define R1_LOCK_UNLOCK_FAILED (1 << 24)
129#define R1_COM_CRC_ERROR (1 << 23)
130#define R1_ILLEGAL_COMMAND (1 << 22)
131#define R1_CARD_ECC_FAILED (1 << 21)
132#define R1_CC_ERROR (1 << 20)
133#define R1_ERROR (1 << 19)
134#define R1_UNDERRUN (1 << 18)
135#define R1_OVERRUN (1 << 17)
136#define R1_CID_CSD_OVERWRITE (1 << 16)
137#define R1_WP_ERASE_SKIP (1 << 15)
138#define R1_CARD_ECC_DISABLED (1 << 14)
139#define R1_ERASE_RESET (1 << 13)
140#define R1_STATUS(x) (x & 0xFFFFE000)
141#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9)
142#define R1_READY_FOR_DATA (1 << 8)
143#define R1_APP_CMD (1 << 5)
146#define R1_SPI_IDLE (1 << 0)
147#define R1_SPI_ERASE_RESET (1 << 1)
148#define R1_SPI_ILLEGAL_COMMAND (1 << 2)
149#define R1_SPI_COM_CRC (1 << 3)
150#define R1_SPI_ERASE_SEQ (1 << 4)
151#define R1_SPI_ADDRESS (1 << 5)
152#define R1_SPI_PARAMETER (1 << 6)
154#define R2_SPI_CARD_LOCKED (1 << 8)
155#define R2_SPI_WP_ERASE_SKIP (1 << 9)
156#define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP
157#define R2_SPI_ERROR (1 << 10)
158#define R2_SPI_CC_ERROR (1 << 11)
159#define R2_SPI_CARD_ECC_ERROR (1 << 12)
160#define R2_SPI_WP_VIOLATION (1 << 13)
161#define R2_SPI_ERASE_PARAM (1 << 14)
162#define R2_SPI_OUT_OF_RANGE (1 << 15)
163#define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE
165#define CARD_BUSY 0x80000000
168#define R5_COM_CRC_ERROR (1 << 15)
169#define R5_ILLEGAL_COMMAND (1 << 14)
170#define R5_ERROR (1 << 11)
171#define R5_FUNCTION_NUMBER (1 << 9)
172#define R5_OUT_OF_RANGE (1 << 8)
173#define R5_STATUS(x) (x & 0xCB00)
174#define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12)
192 if (!(val & 0xffff0000u))
197 if (!(val & 0xff000000u))
202 if (!(val & 0xf0000000u))
207 if (!(val & 0xc0000000u))
212 if (!(val & 0x80000000u))
220#define MMCSD_HOST_PLUGED 0
221#define MMCSD_HOST_UNPLUGED 1
int mmcsd_wait_cd_changed(rt_int32_t timeout)
void mmcsd_set_timing(struct rt_mmcsd_host *host, rt_uint32_t timing)
rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
rt_int32_t mmcsd_spi_read_ocr(struct rt_mmcsd_host *host, rt_int32_t high_capacity, rt_uint32_t *ocr)
struct rt_mmcsd_host * mmcsd_alloc_host(void)
rt_int32_t mmcsd_excute_tuning(struct rt_mmcsd_card *card)
void mmcsd_detect(void *param)
rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid)
rt_int32_t mmcsd_go_idle(struct rt_mmcsd_host *host)
void mmcsd_change(struct rt_mmcsd_host *host)
rt_int32_t mmcsd_deselect_cards(struct rt_mmcsd_card *host)
rt_int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, rt_uint32_t *csd)
rt_int32_t mmcsd_select_card(struct rt_mmcsd_card *card)
void mmcsd_set_bus_mode(struct rt_mmcsd_host *host, rt_uint32_t mode)
void mmcsd_set_chip_select(struct rt_mmcsd_host *host, rt_int32_t mode)
rt_int32_t mmcsd_all_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid)
void mmcsd_req_complete(struct rt_mmcsd_host *host)
void mmcsd_set_clock(struct rt_mmcsd_host *host, rt_uint32_t clk)
rt_int32_t mmcsd_send_cmd(struct rt_mmcsd_host *host, struct rt_mmcsd_cmd *cmd, int retries)
rt_inline rt_uint32_t __rt_fls(rt_uint32_t val)
rt_int32_t mmcsd_spi_use_crc(struct rt_mmcsd_host *host, rt_int32_t use_crc)
rt_uint32_t mmcsd_select_voltage(struct rt_mmcsd_host *host, rt_uint32_t ocr)
void mmcsd_host_unlock(struct rt_mmcsd_host *host)
void mmcsd_send_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
void mmcsd_free_host(struct rt_mmcsd_host *host)
void mmcsd_set_bus_width(struct rt_mmcsd_host *host, rt_uint32_t width)
void mmcsd_host_init(struct rt_mmcsd_host *host)
void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
void mmcsd_host_lock(struct rt_mmcsd_host *host)
void mmcsd_set_data_timeout(struct rt_mmcsd_data *data, const struct rt_mmcsd_card *card)
int rt_mmcsd_core_init(void)
unsigned short rt_uint16_t
struct rt_mmcsd_req * mrq
struct rt_mmcsd_data * data
unsigned int busy_timeout
unsigned int bytes_xfered
struct rt_mmcsd_cmd * stop
struct rt_mmcsd_req * mrq
struct rt_mmcsd_card * card
struct rt_mmcsd_cmd * cmd
struct rt_mmcsd_cmd * stop
struct rt_mmcsd_data * data
struct rt_mmcsd_cmd * sbc