mmcsd_card.h 7.5 KB

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