1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2011-07-25 weety first version 9 */ 10 11 #ifndef __MMCSD_CARD_H__ 12 #define __MMCSD_CARD_H__ 13 14 #include <drivers/mmcsd_host.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #define SD_SCR_BUS_WIDTH_1 (1 << 0) 21 #define SD_SCR_BUS_WIDTH_4 (1 << 2) 22 23 struct rt_mmcsd_cid { 24 rt_uint8_t mid; /* ManufacturerID */ 25 rt_uint8_t prv; /* Product Revision */ 26 rt_uint16_t oid; /* OEM/Application ID */ 27 rt_uint32_t psn; /* Product Serial Number */ 28 rt_uint8_t pnm[5]; /* Product Name */ 29 rt_uint8_t reserved1;/* reserved */ 30 rt_uint16_t mdt; /* Manufacturing Date */ 31 rt_uint8_t crc; /* CID CRC */ 32 rt_uint8_t reserved2;/* not used, always 1 */ 33 }; 34 35 struct rt_mmcsd_csd { 36 rt_uint8_t csd_structure; /* CSD register version */ 37 rt_uint8_t taac; 38 rt_uint8_t nsac; 39 rt_uint8_t tran_speed; /* max data transfer rate */ 40 rt_uint16_t card_cmd_class; /* card command classes */ 41 rt_uint8_t rd_blk_len; /* max read data block length */ 42 rt_uint8_t rd_blk_part; 43 rt_uint8_t wr_blk_misalign; 44 rt_uint8_t rd_blk_misalign; 45 rt_uint8_t dsr_imp; /* DSR implemented */ 46 rt_uint8_t c_size_mult; /* CSD 1.0 , device size multiplier */ 47 rt_uint32_t c_size; /* device size */ 48 rt_uint8_t r2w_factor; 49 rt_uint8_t wr_blk_len; /* max wtire data block length */ 50 rt_uint8_t wr_blk_partial; 51 rt_uint8_t csd_crc; 52 53 }; 54 55 struct rt_sd_scr { 56 rt_uint8_t sd_version; 57 rt_uint8_t sd_bus_widths; 58 }; 59 60 struct rt_sdio_cccr { 61 rt_uint8_t sdio_version; 62 rt_uint8_t sd_version; 63 rt_uint8_t direct_cmd:1, /* Card Supports Direct Commands during data transfer 64 only SD mode, not used for SPI mode */ 65 multi_block:1, /* Card Supports Multi-Block */ 66 read_wait:1, /* Card Supports Read Wait 67 only SD mode, not used for SPI mode */ 68 suspend_resume:1, /* Card supports Suspend/Resume 69 only SD mode, not used for SPI mode */ 70 s4mi:1, /* generate interrupts during a 4-bit 71 multi-block data transfer */ 72 e4mi:1, /* Enable the multi-block IRQ during 73 4-bit transfer for the SDIO card */ 74 low_speed:1, /* Card is a Low-Speed card */ 75 low_speed_4:1; /* 4-bit support for Low-Speed cards */ 76 77 rt_uint8_t bus_width:1, /* Support SDIO bus width, 1:4bit, 0:1bit */ 78 cd_disable:1, /* Connect[0]/Disconnect[1] the 10K-90K ohm pull-up 79 resistor on CD/DAT[3] (pin 1) of the card */ 80 power_ctrl:1, /* Support Master Power Control */ 81 high_speed:1; /* Support High-Speed */ 82 83 84 }; 85 86 struct rt_sdio_cis { 87 rt_uint16_t manufacturer; 88 rt_uint16_t product; 89 rt_uint16_t func0_blk_size; 90 rt_uint32_t max_tran_speed; 91 }; 92 93 /* 94 * SDIO function CIS tuple (unknown to the core) 95 */ 96 struct rt_sdio_function_tuple { 97 struct rt_sdio_function_tuple *next; 98 rt_uint8_t code; 99 rt_uint8_t size; 100 rt_uint8_t *data; 101 }; 102 103 struct rt_sdio_function; 104 typedef void (rt_sdio_irq_handler_t)(struct rt_sdio_function *); 105 106 /* 107 * SDIO function devices 108 */ 109 struct rt_sdio_function { 110 struct rt_mmcsd_card *card; /* the card this device belongs to */ 111 rt_sdio_irq_handler_t *irq_handler; /* IRQ callback */ 112 rt_uint8_t num; /* function number */ 113 114 rt_uint8_t func_code; /* Standard SDIO Function interface code */ 115 rt_uint16_t manufacturer; /* manufacturer id */ 116 rt_uint16_t product; /* product id */ 117 118 rt_uint32_t max_blk_size; /* maximum block size */ 119 rt_uint32_t cur_blk_size; /* current block size */ 120 121 rt_uint32_t enable_timeout_val; /* max enable timeout in msec */ 122 123 struct rt_sdio_function_tuple *tuples; 124 125 void *priv; 126 }; 127 128 #define SDIO_MAX_FUNCTIONS 7 129 130 131 132 struct rt_mmcsd_card { 133 struct rt_mmcsd_host *host; 134 rt_uint32_t rca; /* card addr */ 135 rt_uint32_t resp_cid[4]; /* card CID register */ 136 rt_uint32_t resp_csd[4]; /* card CSD register */ 137 rt_uint32_t resp_scr[2]; /* card SCR register */ 138 139 rt_uint16_t tacc_clks; /* data access time by ns */ 140 rt_uint32_t tacc_ns; /* data access time by clk cycles */ 141 rt_uint32_t max_data_rate; /* max data transfer rate */ 142 rt_uint32_t card_capacity; /* card capacity, unit:KB */ 143 rt_uint32_t card_blksize; /* card block size */ 144 rt_uint32_t erase_size; /* erase size in sectors */ 145 rt_uint16_t card_type; 146 #define CARD_TYPE_MMC 0 /* MMC card */ 147 #define CARD_TYPE_SD 1 /* SD card */ 148 #define CARD_TYPE_SDIO 2 /* SDIO card */ 149 #define CARD_TYPE_SDIO_COMBO 3 /* SD combo (IO+mem) card */ 150 151 rt_uint16_t flags; 152 #define CARD_FLAG_HIGHSPEED (1 << 0) /* SDIO bus speed 50MHz */ 153 #define CARD_FLAG_SDHC (1 << 1) /* SDHC card */ 154 #define CARD_FLAG_SDXC (1 << 2) /* SDXC card */ 155 156 struct rt_sd_scr scr; 157 struct rt_mmcsd_csd csd; 158 rt_uint32_t hs_max_data_rate; /* max data transfer rate in high speed mode */ 159 160 rt_uint8_t sdio_function_num; /* totol number of SDIO functions */ 161 struct rt_sdio_cccr cccr; /* common card info */ 162 struct rt_sdio_cis cis; /* common tuple info */ 163 struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */ 164 165 }; 166 167 #ifdef __cplusplus 168 } 169 #endif 170 171 #endif 172