hpm_sdmmc_emmc.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. /*
  2. * Copyright (c) 2021-2024 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_SDMMC_EMMC_H
  8. #define HPM_SDMMC_EMMC_H
  9. /**
  10. *
  11. * @brief HPM SDMMC eMMC driver APIs
  12. * @defgroup hpm_sdmmc HPM SDMMC stack
  13. * @ingroup hpm_sdmmc_interfaces
  14. * @{
  15. *
  16. */
  17. #include "hpm_sdmmc_common.h"
  18. #include "hpm_sdmmc_card.h"
  19. #include "hpm_sdmmc_port.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. typedef enum {
  24. emmc_switch_cmd_access_mode_command_set = 0,
  25. emmc_switch_cmd_access_mode_set_bits = 1,
  26. emmc_switch_cmd_access_mode_clear_bits = 2,
  27. emmc_switch_cmd_access_mode_write_byte = 3,
  28. } emmc_switch_cmd_access_mode_t;
  29. typedef union {
  30. struct {
  31. uint8_t cmd_set;
  32. uint8_t value;
  33. uint8_t index;
  34. uint8_t access;
  35. };
  36. uint32_t argument;
  37. } emmc_switch_cmd_arg_t;
  38. #define EMMC_EXT_CSD_INDEX_CMD_SET (191)
  39. #define EMMC_EXT_CSD_INDEX_POWER_CLASS (187)
  40. #define EMMC_EXT_CSD_INDEX_HS_TIMING (185)
  41. #define EMMC_EXT_CSD_INDEX_BUS_WDITH (183)
  42. #define EMMC_EXT_CSD_INDEX_PARTITION_CONFIG (179)
  43. #define EMMC_EXT_CSD_INDEX_BOOT_CONFIG_PROT (178)
  44. #define EMMC_EXT_CSD_INDEX_BOOT_BUS_CONDITIONS (177)
  45. #define EMMC_EXT_CSD_INDEX_ERASE_GROUP_DEF (175)
  46. #define EMMC_EXT_CSD_INDEX_BOOT_WP (173)
  47. #define EMMC_EXT_CSD_INDEX_USER_WP (171)
  48. #define EMMC_EXT_CSD_INDEX_FW_CONFIG (169)
  49. #define EMMC_EXT_CSD_INDEX_WR_REL_SET (167)
  50. #define EMMC_EXT_CSD_INDEX_SANITIZE_START (165)
  51. #define EMMC_EXT_CSD_INDEX_BKOPS_START (164)
  52. #define EMMC_EXT_CSD_INDEX_BKOPS_EN (163)
  53. #define EMMC_EXT_CSD_INDEX_RSTn_FUNCTION (162)
  54. #define EMMC_EXT_CSD_INDEX_HPI_MGMT (161)
  55. #define EMMC_EXT_CSD_INDEX_PARTITIONS_ATTRIBUTE (156)
  56. #define EMMC_EXT_CSD_INDEX_PARTITION_SETTING_COMPLETED (155)
  57. #define EMMC_EXT_CSD_INDEX_SEC_BAD_BLK_MGMNT (134)
  58. #define EMMC_EXT_CSD_INDEX_PRODUCTION_STATE_AWARENESS (133)
  59. #define EMMC_EXT_CSD_INDEX_PERIODIC_WAKEUP (131)
  60. #define EMMC_EXT_CSD_INDEX_USE_NATIVE_SECTOR (62)
  61. #define EMMC_EXT_CSD_INDEX_CLASS_6_CTRL (59)
  62. #define EMMC_EXT_CSD_INDEX_POWER_OFF_NOTIFICATION (34)
  63. #define EMMC_EXT_CSD_INDEX_CACHE_CTRL (33)
  64. #define EMMC_EXT_CSD_INDEX_FLUSH_CACHE (32)
  65. #define EMMC_EXT_CSD_INDEX_BARRIER_CTRL (31)
  66. #define EMMC_EXT_CSD_INDEX_MODE_CONFIG (30)
  67. #define EMMC_EXT_CSD_INDEX_PRODUCT_STATE_AWARENESS_ENABLEMENT (17)
  68. #define EMMC_EXT_CSD_INDEX_SECURE_REMOVAL_TYPE (16)
  69. #define EMMC_EXT_CSD_INDEX_CMDQ_MODE_EN (15)
  70. typedef union {
  71. struct {
  72. uint32_t : 7;
  73. uint32_t voltage_170_195: 1;
  74. uint32_t voltage_200_260: 7;
  75. uint32_t voltage_270_360: 9;
  76. uint32_t : 5;
  77. uint32_t access_mode: 2;
  78. uint32_t powerup_status: 1;
  79. };
  80. uint32_t ocr_word;
  81. } emmc_ocr_t;
  82. typedef union {
  83. struct {
  84. uint8_t reserved;
  85. uint8_t mdt; /*!< Manufacturing Date */
  86. uint8_t psn[4]; /*!< Product serial number */
  87. uint8_t prv; /*!< Product revision */
  88. uint8_t pnm[6]; /*!< Product name */
  89. uint8_t oid; /*!< OEM/Application ID */
  90. struct {
  91. uint8_t cbx: 2; /*!< Device/BGA */
  92. uint8_t bin: 6; /*!< Bank Index Number */
  93. };
  94. uint8_t mid; /*!< Manufacturer ID */
  95. };
  96. uint32_t cid_words[4];
  97. } emmc_cid_t;
  98. typedef union {
  99. struct {
  100. uint32_t: 5; /*!< Bit[4:0] */
  101. uint32_t app_cmd: 1; /*!< Bit[5] */
  102. uint32_t exception_event: 1; /*!< Bit[6] */
  103. uint32_t switch_error: 1; /*!< Bit[7] */
  104. uint32_t ready_for_data: 1; /*!< Bit[8] */
  105. uint32_t current_state: 4; /*!< Bit[12:9] */
  106. uint32_t erase_reset: 1; /*!< Bit[13] */
  107. uint32_t : 1; /*!< Bit[14] */
  108. uint32_t wp_erase_skip: 1; /*!< Bit[15] */
  109. uint32_t cid_or_csd_overwrite: 1; /*!< Bit[16] */
  110. uint32_t : 2; /*!< Bit[18:17] */
  111. uint32_t error: 1; /*!< Bit[19] */
  112. uint32_t cc_error: 1; /*!< Bit[20] */
  113. uint32_t device_ecc_failed: 1; /*!< Bit[21] */
  114. uint32_t illegal_command: 1; /*!< Bit[22] */
  115. uint32_t com_crc_err: 1; /*!< Bit[23] */
  116. uint32_t lock_unlock_failed: 1; /*!< Bit[24] */
  117. uint32_t device_is_locked: 1; /*!< Bit[25] */
  118. uint32_t wp_violation: 1; /*!< Bit[26] */
  119. uint32_t erase_param: 1; /*!< Bit[27] */
  120. uint32_t erase_seq_error: 1; /*!< Bit[28] */
  121. uint32_t block_len_error: 1; /*!< Bit[29] */
  122. uint32_t address_error: 1; /*!< Bit[30] */
  123. uint32_t out_of_range: 1; /*!< Bit[31] */
  124. };
  125. uint32_t card_status;
  126. } emmc_card_status_t;
  127. typedef enum {
  128. emmc_csd_vdd_current_min_0_5ma,
  129. emmc_csd_vdd_current_min_1ma,
  130. emmc_csd_vdd_current_min_5ma,
  131. emmc_csd_vdd_current_min_10ma,
  132. emmc_csd_vdd_current_min_25ma,
  133. emmc_csd_vdd_current_min_35ma,
  134. emmc_csd_vdd_current_min_60ma,
  135. emmc_csd_vdd_current_min_100ma,
  136. } emmc_csd_vdd_current_min_t;
  137. typedef enum {
  138. emmc_csd_vdd_current_max_1ma,
  139. emmc_csd_vdd_current_max_5ma,
  140. emmc_csd_vdd_current_max_10ma,
  141. emmc_csd_vdd_current_max_25ma,
  142. emmc_csd_vdd_current_max_35ma,
  143. emmc_csd_vdd_current_max_45ma,
  144. emmc_csd_vdd_current_max_80ma,
  145. emmc_csd_vdd_current_max_200ma,
  146. } emmc_csd_vdd_current_max_t;
  147. typedef enum vdd_current_min_def {
  148. vdd_current_min_0_5ma,
  149. vdd_current_min_1ma,
  150. vdd_current_min_5ma,
  151. vdd_current_min_10ma,
  152. vdd_current_min_25ma,
  153. vdd_current_min_35ma,
  154. vdd_current_min_60ma,
  155. vdd_current_min_100ma,
  156. } vdd_current_min_t;
  157. typedef enum vdd_current_max_def {
  158. vdd_current_max_1ma,
  159. vdd_current_max_5ma,
  160. vdd_current_max_10ma,
  161. vdd_current_max_25ma,
  162. vdd_current_max_35ma,
  163. vdd_current_max_45ma,
  164. vdd_current_max_80ma,
  165. vdd_current_max_200ma,
  166. } vdd_current_max_t;
  167. typedef enum {
  168. emmc_csd_file_format_hard_disk_like_file_system_with_partition_table,
  169. emmc_csd_file_format_dos_fat_with_boot_sector_only,
  170. emmc_csd_file_format_universal_file_format,
  171. emmc_csd_file_format_others_or_unknown
  172. } emmc_csd_file_format_t;
  173. typedef struct {
  174. uint8_t csd_structure;
  175. uint8_t spec_version;
  176. uint16_t nsac_cycles;
  177. uint32_t taac_ns;
  178. bool support_read_block_partial;
  179. bool support_write_block_misalignment;
  180. bool support_read_block_misalignment;
  181. bool is_dsr_implemented;
  182. bool support_content_protect_app;
  183. bool is_write_protection_group_enabled;
  184. bool support_write_block_partial;
  185. bool is_predefined_file_format;
  186. bool support_copy;
  187. bool support_permanent_write_protect;
  188. bool support_temporary_write_protect;
  189. uint8_t file_format;
  190. uint16_t card_command_class;
  191. uint8_t write_speed_factor;
  192. emmc_csd_vdd_current_min_t read_current_vdd_min;
  193. emmc_csd_vdd_current_max_t read_current_vdd_max;
  194. emmc_csd_vdd_current_min_t write_current_vdd_min;
  195. emmc_csd_vdd_current_max_t write_current_vdd_max;
  196. uint8_t ecc_type;
  197. uint32_t sector_size;
  198. uint32_t erase_group_size;
  199. uint32_t max_read_block_len;
  200. uint32_t max_write_block_len;
  201. uint32_t write_protect_group_size;
  202. uint32_t max_freq;
  203. uint64_t device_size_in_bytes;
  204. } emmc_csd_t;
  205. typedef union {
  206. uint8_t device_type;
  207. struct {
  208. uint8_t support_high_speed_sdr_at_26mhz: 1;
  209. uint8_t support_high_speed_sdr_at_52mhz: 1;
  210. uint8_t support_high_speed_ddr_at_52mhz_1v8_or_3v: 1;
  211. uint8_t support_high_speed_ddr_at_52mhz_1v2: 1;
  212. uint8_t support_hs200_at_200mhz_1v8: 1;
  213. uint8_t support_hs200_at_200mhz_1v2: 1;
  214. uint8_t support_hs400_at_200mhz_1v8: 1;
  215. uint8_t support_hs400_at_200mhz_1v2: 1;
  216. };
  217. } emmc_device_type_t;
  218. #pragma pack(1)
  219. typedef struct {
  220. /*
  221. * Mode segment
  222. */
  223. uint8_t reserved0[15]; /*!< [14:0] */
  224. uint8_t command_queue_mode_enable; /*!< [15] */
  225. uint8_t secure_removal_type; /*!< [16] */
  226. uint8_t product_state_awareness_enablement; /*!< [17] */
  227. uint8_t max_pre_loading_data_size[4]; /*!< [21:18] */
  228. uint8_t pre_loading_data_size[4]; /*!< [25:22] */
  229. uint8_t ffu_status; /*!< [26] */
  230. uint8_t reserved1[2]; /*!< [28:27] */
  231. uint8_t mode_operation_codes; /*!< [29] */
  232. uint8_t mode_config; /*!< [30] */
  233. uint8_t barrier_control; /*!< [31] */
  234. uint8_t flush_cache; /*!< [32] */
  235. uint8_t cache_control; /*!< [33] */
  236. uint8_t power_off_notification; /*!< [34] */
  237. uint8_t packed_command_failure_index; /*!< [35] */
  238. uint8_t packed_command_status; /*!< [36] */
  239. uint8_t context_config[15]; /*!< [51:37] */
  240. uint8_t extended_partitions_attribute[2]; /*!< [53:52] */
  241. uint8_t exception_events_status[2]; /*!< [55:54] */
  242. uint8_t exception_events_control[2]; /*!< [57:56] */
  243. uint8_t dyncap_needed; /*!< [58] */
  244. uint8_t class6_commands_control; /*!< [59] */
  245. uint8_t init_timeout_after_disabling_emulation; /*!< [60] 100ms * init_timeout_after_disabling_emulation */
  246. uint8_t data_sector_size; /*!< [61] 0 - 512Bytes, 1 - 4KB */
  247. uint8_t sector_size_emulation; /*!< [62] */
  248. uint8_t native_sector_size; /*!< [63] 0 - 512Bytes, 1 - 4KB */
  249. uint8_t vendor_specific_field[64]; /*!< [127:64] */
  250. uint8_t reserved02[2]; /*!< [129:128] */
  251. uint8_t program_cid_or_csd_in_ddr_mode_supported; /*!< [130] */
  252. uint8_t periodic_wakeup; /*!< [131] */
  253. uint8_t tcase_support; /*!< [132] */
  254. uint8_t production_state_awareness; /*!< [133] */
  255. uint8_t bad_block_management_mode; /*!< [134] */
  256. uint8_t reserved03; /*!< [135] */
  257. uint32_t enhanced_user_data_start_address; /*!< [139:136] */
  258. uint8_t enhanced_user_data_area_size[3]; /*!< [142:140] 512KB * enhanced_user_data_area_size * high_capacity_erase_unit_size */
  259. uint8_t general_purpose_partition_size[4][3]; /*!< [154:143] */
  260. uint8_t partitioning_setting; /*!< [155] */
  261. uint8_t partitioning_attribute; /*!< [156] */
  262. uint8_t max_enh_size_mult[3]; /*!< [159:157] */
  263. uint8_t partitioning_support; /*!< [160] */
  264. uint8_t hw_reset_function; /*!< [161] */
  265. uint8_t hpi_management; /*!< [162] */
  266. uint8_t bkops_en; /*!< [163] */
  267. uint8_t bkops_start; /*!< [164] */
  268. uint8_t sanitize_start; /*!< [165] */
  269. uint8_t write_reliability_parameter; /*!< [166] */
  270. uint8_t write_reliability_setting; /*!< [167] bit0-user area, bit[4:1] general purpose partition 4-1 */
  271. uint8_t rpmb_size; /*!< [168] 128KB * rpmb_size */
  272. uint8_t fw_config; /*!< [169] */
  273. uint8_t reserved04; /*!< [170] */
  274. /* bit0 - US_PWR_WP_EN, bit2 - US_PERM_WP_EN, bit3 - US_PWR_WP_DIS, bit4 - US_PERM_WP_DIS
  275. * bit6 - CD_PERM_WP_DIS, bit7 - PERM_PSWD_DIS
  276. */
  277. uint8_t user_wp; /*!< [171] */
  278. uint8_t reserved05; /*!< [172] */
  279. /* bit0 - B_PWR_WP_EN, bit1 - B_PWR_WP_SEC_SEL, bit2 - B_PERM_WP_EN, bit3 - B_PERM_WP_SEC_SEL
  280. * bit4 - B_PERM_WP_DIS, bit6 - B_PWR_WP_DIS, bit7 - B_SEC_WP_SEL
  281. *
  282. */
  283. uint8_t boot_wp; /*!< [173] */
  284. uint8_t boot_wp_status; /*!< [174] bit[1:0] B_AREA_1_WP, bit[3:2] B_AREA_2_WP */
  285. uint8_t erase_group_def; /*!< [175] 0 - old group size, 1 - high-capacity erase unit size */
  286. uint8_t reserved06; /*!< [176] */
  287. /* bit[1:0] BOOT_BUS_WIDTH
  288. * 0 - x1 SDR or x4 DDR in boot operation mode, 1 - X4 (SDR/DDR) bus width in boot operation mode
  289. * 2 - x8 (SDR/DDR) bus width in boot operation mode
  290. * bit2 RESET_BOOT_BUS_CONDITIONS
  291. * 0 - Reset bus width to x1
  292. * 1 - Retain BOOT_BUS_WIDTH and BOOT_MODE values after boot operation
  293. * bit[4:3] BOOT_MODE
  294. * 0 - SDR @ normal speed timing, 1 - SDR @ High Speed timing, 2 - DDR
  295. *
  296. */
  297. uint8_t boot_bus_conditions; /*!< [177] */
  298. /* bit0 - PWR_BOOT_CONFIG_PROT
  299. * bit4 - PERM_BOOT_CONFIG_PROT
  300. */
  301. uint8_t boot_config_prot; /*!< [178] */
  302. /* bit[2:0] PARTITION_ACCESS
  303. * 0 - No access to boot partition, 1 - R/W boot partition 1, 2 - R/W boot partition 2
  304. * 3 - R/W RPMB, 4 - Access to General Purpose partition 1, 5 - Access to General Purpose partition 2
  305. * 6 - Access to General Purpose partition 3, 7 - Access to General partition 4
  306. * bit[5:3] BOOT_PARTITION_ENABLE
  307. * 0 - Device not boot enabled, 1 - Boot partition 1 enabled for boot, 2 - boot partition 2 enabled for boot
  308. * 7 - User area enabled for boot
  309. * bit[6] BOOT_ACK
  310. */
  311. uint8_t partition_config; /*!< [179] */
  312. uint8_t reserved07; /*!< [180] */
  313. uint8_t erased_mem_content; /*!< [181] 0 - Read as all 0x00s for erased region, 1 - read as all 0xffs for erased region */
  314. uint8_t reserved08; /*!< [182] */
  315. /* bit[3:0] bus mode selection: 0-1bit data bus, 1 - 4bit data bus, 2 - 8bit data bus,
  316. * 5- 4bit data bus @DDR mode, 6 - 8bit data bus @DDR mode
  317. * bit7 Enhanced Strobe
  318. */
  319. uint8_t bus_width; /*!< [183] */
  320. uint8_t strobe_support; /*!< [184] 0 - no support for enhanced strobe mode, 1 - supports enhanced strobe mode */
  321. /* bit[3:0] timing interface: 0 - normal, 1 - high speed, 2 - HS200, 3 - HS400
  322. * bit[7:4] selected driver strength
  323. */
  324. uint8_t hs_timing; /*!< [185] */
  325. uint8_t reserved09; /*!< [186] */
  326. uint8_t power_class; /*!< [187] */
  327. uint8_t reserved10; /*!< [188] */
  328. uint8_t cmd_set_revision; /*!< [189] 0 - v4.0 */
  329. uint8_t reserved11; /*!< [190] */
  330. uint8_t cmd_set; /*!< [191] */
  331. /*
  332. * Properties Segment
  333. */
  334. uint8_t ext_csd_rev; /*!< [192] 0-4.0, 1-4.1, 2-4.2, 3-4.3, 5-4.41, 6-4.51, 7-5.01, 8-5.1 */
  335. uint8_t reserved12; /*!< [193] */
  336. uint8_t csd_structure; /*!< [194] 0 - CSD 1.0, 1 - CSD 1.1, 2 - CSD 1.2 */
  337. uint8_t reserved13; /*!< [195] */
  338. /*
  339. * bit0 - HS @ 26MHz, bit1 - HS @ 52MHz, bit2 - HS DDR @52MHz, 1.8V or 3V
  340. * bit3 - HS DDR @ 52Mhz, 12.V, bit4 - HS200 SDR @200MHz, 1.8V, bit5 - HS200 SDR @200MHz, 1.2V
  341. * bit6 - HS400 DDR @ 1.8V, bit7 - HS400 DDR @ 1.2V
  342. */
  343. uint8_t device_type; /*!< [196] */
  344. uint8_t driver_strength; /*!< [197] bit0 - type 0, bit1 - type 1, bit2 - type 2, bit3 - type 3, bit4 - type 4 */
  345. uint8_t out_of_interrupt_timing; /*!< [198] 10ms * out_of_interrupt_timing */
  346. uint8_t partition_switch_timing; /*!< [199] 10ms * partition_switch_timing */
  347. uint8_t pwr_cl_52_195; /*!< [200] */
  348. uint8_t pwr_cl_26_195; /*!< [201] */
  349. uint8_t pwr_cl_52_360; /*!< [202] */
  350. uint8_t pwr_cl_26_360; /*!< [203] */
  351. uint8_t reserved14; /*!< [204] */
  352. uint8_t min_perf_r_4_26; /*!< [205] SDR mode : 150kB/S * value, DDR mode = 300kB/s * value * 2 */
  353. uint8_t ming_perf_w_4_26; /*!< [206] SDR mode : 150kB/S * value, DDR mode = 300kB/s * value * 2 */
  354. uint8_t min_perf_r_8_26_4_52; /*!< [207] SDR mode : 150kB/S * value, DDR mode = 300kB/s * value * 2 */
  355. uint8_t min_perf_w_8_26_4_52; /*!< [208] SDR mode : 150kB/S * value, DDR mode = 300kB/s * value * 2 */
  356. uint8_t min_perf_r_8_52; /*!< [209] SDR mode : 150kB/S * value, DDR mode = 300kB/s * value * 2 */
  357. uint8_t min_perf_w_8_52; /*!< [210] SDR mode : 150kB/S * value, DDR mode = 300kB/s * value * 2 */
  358. uint8_t secure_wp_info; /*!< [211] bit0-SECURE_WP_SUPPORT, bit1-SECURE_WP_EN_STATUS */
  359. uint32_t sector_count; /*!< [215:212] Device density = sector_count * 512Bytes */
  360. uint8_t sleep_notification_timeout; /*!< [216] 10us * 2 ^ sleep_notification_timeout */
  361. uint8_t sleep_or_awake_timeout; /*!< [217] 100ns * 2^sleep_or_awake_timeout */
  362. uint8_t production_state_awareness_timeout; /*!< [218] 100us * 2 ^ production_state_awareness_timeout */
  363. uint8_t sleep_current_vccq; /*!< [219] 1uA * 2 ^ sleep_current_vccq */
  364. uint8_t sleep_current_vcc; /*!< [220] 1uA * 2 ^ sleep_current_vcc */
  365. /* 512KB * high_capacity_erase_unit_size * high_capacity_write_protect_group_size */
  366. uint8_t high_capacity_write_protect_group_size; /*!< [221] */
  367. uint8_t reliable_write_sector_count; /* !< [222] shall be set to 1 */
  368. uint8_t erase_timeout_mult; /*!< [223] 300ms * erase_timeout_mult */
  369. uint8_t high_capacity_erase_unit_size; /*!< [224] 512KB * high_capacity_erase_unit_size */
  370. uint8_t access_size; /*!< [225] bit[3:0] - SUPER_PAGE_SIZE = 512 * 2 ^ (SUPER_PAGE_SIZE - 1) */
  371. uint8_t boot_partition_size_mult; /*!< [226] 128KB * boot_partition_size_mult */
  372. uint8_t reserved15; /*!< [227] */
  373. uint8_t boot_info; /*!< [228] bit0-ALT_BOOT_MODE, bit1-DDR_BOOT_MODE, bit2-HS_BOOT_MODE */
  374. uint8_t secure_trim_mult; /*!< [229] 300ms * secure_trim_mult */
  375. uint8_t secure_erase_mult; /*!< [230] 300ms * secure_erase_mult */
  376. uint8_t secure_feature_support; /*!< [231] bit0-SECURE_ER_EN, bitt2-SEC_BD_BLK_EN, bit4-SEC_GB_CL_EN, bit6-SEC_SANITIZE */
  377. uint8_t trim_mult; /*!< [232] 300ms * trim_mult */
  378. uint8_t reserved16; /*!< [233] */
  379. uint8_t min_perf_ddr_r_8_52; /*!< [234] */
  380. uint8_t min_perf_ddr_w_8_52; /*!< [235] */
  381. uint8_t pwr_cl_200_130; /*!< [236] */
  382. uint8_t pwr_cl_200_195; /*!< [237] */
  383. uint8_t pwr_cl_ddr_52_195; /*!< [238] */
  384. uint8_t pwr_cl_ddr_52_360; /*!< [239] */
  385. uint8_t cache_flush_policy; /*!< [240] 0 - none, 1 - FIFO policy */
  386. uint8_t init_timeout_after_partitioning; /*!< [241] 100ms * init_timeout_after_partitioning */
  387. uint32_t number_of_correctly_programmed_sectors; /*!< [245:242] */
  388. uint8_t bkops_status; /*!< [246] bit[1:0] 0:no operations required, 1:non-critical, 2:lower performance, 3:critical */
  389. uint8_t power_off_long_timeout; /*!< [247] 10ms * power_off_long_timeout */
  390. uint8_t generic_cmd6_timeout; /*!< [248] 10ms * generic_cmd6_timeout */
  391. uint32_t cache_size; /*!< [252:249] cache_size * 1kb */
  392. uint8_t pwr_cl_ddr_200_360; /*!< [253] */
  393. uint8_t firmware_version[8]; /*!< [261:254] */
  394. uint8_t device_version[2]; /*!< [263:262] */
  395. uint8_t optimal_trim_unit_size; /*!< [264] 4KB * 2 ^(optmial_trim_unit_size - 1) */
  396. uint8_t optimal_write_size; /*!< [265] 4KB * optimal_write_size */
  397. uint8_t optimal_read_size; /*!< [266] 4KB * optimal_read_size */
  398. uint8_t pre_eol_info; /*!< [267] 1-Normal, 2-Warning, 3-Urgent */
  399. uint8_t device_lifetime_estimation_type_a; /*!< [268] */
  400. uint8_t device_lifetime_estimation_type_b; /*!< [269] */
  401. uint8_t vendor_proprietary_health_report[32];/*!< [301:270] */
  402. uint32_t number_of_correctly_programmed_fw_sectors; /*!< [305:302] */
  403. uint8_t reserved17; /*!< [306] */
  404. uint8_t cmdq_depth; /*!< [307] bit[4:0] N, depth = N+1 */
  405. uint8_t cmdq_support; /*!< [308] 1 - supported, others - not supported */
  406. uint8_t reserved18[177]; /*!< [485:309] */
  407. uint8_t barrier_support; /*!< [486] */
  408. uint8_t ffu_arg[4]; /*!< [490:487] */
  409. uint8_t operation_code_timeout; /*!< [491] 100us * 2 ^ operation_code_timeout */
  410. uint8_t ffu_features; /*!< [492] 0 - device does not support mode_operation_codes */
  411. uint8_t supported_modes; /*!< [493] bit0 - FFU, 0:not supported, 1:supported, bit1 Vendor Specific Mode, 0:not supported */
  412. uint8_t extended_partitions_attribute_support; /*!< [494] bit0 system code, bit1 non-persistent */
  413. uint8_t large_unit_size; /*!< [495] 1MB * large_unit_size */
  414. uint8_t context_capabilities; /*!< [496] bit[3:0] max_context_id, bit[6:4] maximum large_unit_size */
  415. uint8_t tag_resource_size; /*!< [497] [n * tag_unit_size) * 2 ^tag_resource_size] / 1024 */
  416. uint8_t tag_unit_size; /*!< [498] 2^tag_unit_size * sector_size */
  417. uint8_t data_tag_support; /*!< [499] */
  418. uint8_t max_packed_writes; /*!< [500] minimum value: 3 */
  419. uint8_t max_packed_reads; /*!< [501] minimum value:5 */
  420. uint8_t bkops_support; /*!< [502] */
  421. uint8_t hpi_features; /*!< [503] */
  422. uint8_t supported_cmd_sets; /*!< [504] */
  423. uint8_t extended_security_error; /*!< [505] */
  424. uint8_t reserved19[6]; /*!< [511:506] */
  425. } emmc_ext_csd_t;
  426. #pragma pack()
  427. typedef enum _emmc_partition {
  428. emmc_partition_boot_area_1 = 0,
  429. emmc_partition_boot_area_2 = 1,
  430. emmc_partition_rpmb = 2,
  431. emmc_partition_user_data = 3,
  432. } emmc_partition_t;
  433. typedef enum _emmc_hs_timing {
  434. emmc_timing_legacy = 0,
  435. emmc_timing_high_speed = 1,
  436. emmc_timing_hs200 = 2,
  437. emmc_timing_hs400 = 3,
  438. emmc_timing_high_speed_ddr = 4,
  439. } emmc_hs_timing_t;
  440. typedef enum {
  441. emmc_power_3v6_max_rms_100ma_peak_200ma = 0,
  442. emmc_power_3v6_max_rms_120ma_peak_220ma = 1,
  443. emmc_power_3v6_max_rms_150ma_peak_250ma = 2,
  444. emmc_power_3v6_max_rms_180ma_peak_280ma = 3,
  445. emmc_power_3v6_max_rms_200ma_peak_300ma = 4,
  446. emmc_power_3v6_max_rms_220ma_peak_320ma = 5,
  447. emmc_power_3v6_max_rms_250ma_peak_350ma = 6,
  448. emmc_power_3v6_max_rms_300ma_peak_400ma = 7,
  449. emmc_power_3v6_max_rms_350ma_peak_450ma = 8,
  450. emmc_power_3v6_max_rms_400ma_peak_500ma = 9,
  451. emmc_power_3v6_max_rms_450ma_peak_550ma = 10,
  452. emmc_power_3v6_max_rms_500ma_peak_600ma = 11,
  453. emmc_power_3v6_max_rms_600ma_peak_700ma = 12,
  454. emmc_power_3v6_max_rms_700ma_peak_800ma = 13,
  455. emmc_power_3v6_max_rms_800ma_peak_900ma = 14,
  456. emmc_power_3v6_max_rms_gt800ma_peak_gt900ma = 15,
  457. } emmc_power_class_3v6_t;
  458. typedef enum {
  459. emmc_power_1v95_max_rms_65ma_peak_130ma = 0,
  460. emmc_power_1v95_max_rms_70ma_peak_140ma = 1,
  461. emmc_power_1v95_max_rms_80ma_peak_160ma = 2,
  462. emmc_power_1v95_max_rms_90ma_peak_180ma = 3,
  463. emmc_power_1v95_max_rms_100ma_peak_200ma = 4,
  464. emmc_power_1v95_max_rms_120ma_peak_220ma = 5,
  465. emmc_power_1v95_max_rms_140ma_peak_240ma = 6,
  466. emmc_power_1v95_max_rms_160ma_peak_260ma = 7,
  467. emmc_power_1v95_max_rms_180ma_peak_280ma = 8,
  468. emmc_power_1v95_max_rms_200ma_peak_300ma = 9,
  469. emmc_power_1v95_max_rms_250ma_peak_350ma = 10,
  470. emmc_power_1v95_max_rms_300ma_peak_400ma = 11,
  471. emmc_power_1v95_max_rms_350ma_peak_450ma = 12,
  472. emmc_power_1v95_max_rms_400ma_peak_500ma = 13,
  473. emmc_power_1v95_max_rms_500ma_peak_600ma = 14,
  474. emmc_power_1v95_max_rms_gt500ma_peak_gt600ma = 15,
  475. } emmc_power_class_1v95_t;
  476. typedef union {
  477. emmc_power_class_3v6_t power_class_3v6;
  478. emmc_power_class_1v95_t power_class_1v95;
  479. } emmc_power_class_t;
  480. typedef enum {
  481. emmc_bus_mode_x1_sdr = 0,
  482. emmc_bus_mode_x4_sdr = 1,
  483. emmc_bus_mode_x8_sdr = 2,
  484. emmc_bus_mode_x4_ddr = 5,
  485. emmc_bus_mode_x8_ddr = 6,
  486. emmc_bus_mode_x8_ddr_ds = 0x86,
  487. } emmc_bus_mode_t;
  488. typedef enum {
  489. emmc_write_protection_mode_legacy = 0,
  490. emmc_write_protection_mode_secure = 1,
  491. } emmc_write_protection_mode_t;
  492. typedef struct {
  493. bool is_alt_boot_mode_supported;
  494. bool is_ddr_boot_mode_supported;
  495. bool is_hs_boot_mode_supported;
  496. uint8_t reserved;
  497. } boot_info_t;
  498. typedef struct {
  499. bool is_secure_erase_supported;
  500. bool is_secure_bad_block_management_supported;
  501. bool is_secure_insecure_trim_supported;
  502. bool is_secure_sanitize_supported;
  503. } secure_feature_info_t;
  504. typedef enum {
  505. emmc_boot_partition_mode_not_enabled = 0,
  506. emmc_boot_partition_mode_boot_partition1 = 1,
  507. emmc_boot_partition_mode_boot_partition2 = 2,
  508. emmc_boot_partition_mode_user_area = 7,
  509. } emmc_boot_partition_mode_t;
  510. typedef enum {
  511. emmc_partition_access_boot_partition_disabled = 0,
  512. emmc_partition_access_read_or_write_boot_partition1 = 1,
  513. emmc_partition_access_read_or_write_boot_partition2 = 2,
  514. emmc_partition_access_read_or_write_rpmb = 3,
  515. emmc_partition_access_access_to_gp_partition1 = 4,
  516. emmc_partition_access_access_to_gp_partition2 = 5,
  517. emmc_partition_access_access_to_gp_partition3 = 6,
  518. emmc_partition_access_access_to_gp_partition4 = 7,
  519. } emmc_partition_access_t;
  520. typedef enum {
  521. emmc_boot_mode_sdr_legacy = 0, emmc_boot_mode_sdr_high_speed_timing, emmc_boot_mode_ddr,
  522. } emmc_boot_mode_t;
  523. typedef struct {
  524. bool enable_boot_ack;
  525. bool enable_boot_config_protection_until_next_power_cycle;
  526. bool enable_boot_config_protection_permanently;
  527. bool reset_boot_bus_conditions;
  528. emmc_boot_mode_t boot_mode;
  529. emmc_bus_mode_t boot_bus_mode;
  530. emmc_boot_partition_mode_t emmc_boot_partition_mode;
  531. emmc_partition_access_t partition_access;
  532. } emmc_boot_setting_t;
  533. typedef struct {
  534. bool is_secure_write_protection_supported;
  535. emmc_device_type_t device_type;
  536. emmc_write_protection_mode_t write_protection_mode;
  537. boot_info_t boot_info;
  538. secure_feature_info_t secure_feature_info;
  539. uint32_t boot_partition_size;
  540. uint32_t rpmb_partition_size;
  541. uint32_t max_enhanced_area_size;
  542. uint32_t gp_partition_size[4];
  543. uint32_t super_page_size;
  544. uint32_t write_protect_group_size;
  545. uint32_t erase_group_size;
  546. uint64_t device_size_in_bytes;
  547. uint32_t sector_count;
  548. uint32_t sector_size;
  549. uint32_t large_unit_size;
  550. uint32_t optimal_read_size;
  551. uint32_t optimal_write_size;
  552. uint64_t optimal_trim_unit_size;
  553. uint32_t operation_codes_timeout_us;
  554. uint32_t switch_cmd_timeout_ms;
  555. uint32_t power_off_timeout_ms;
  556. uint32_t init_timeout_after_partition_ms;
  557. uint32_t trim_timeout_ms;
  558. uint32_t secure_erase_timeout_ms;
  559. uint32_t secure_trim_timeout_ms;
  560. uint32_t erase_timeout_ms;
  561. uint32_t partition_switch_timeout_ms;
  562. uint32_t out_of_interrupt_timeout_ms;
  563. uint32_t sleep_notification_timeout_us;
  564. uint32_t sleep_awake_timeout_ns;
  565. uint32_t production_state_awareness_timeout_us;
  566. uint32_t sleep_current_vcc_ua;
  567. uint32_t sleep_current_vccq_ua;
  568. bool use_high_capacity_erase_unit_size;
  569. bool is_all_0xffs_for_erased_region;
  570. bool is_enhanced_strobe_supported;
  571. bool is_cmd_queue_mode_enabled;
  572. } emmc_device_attribute_t;
  573. typedef struct _sdmmc_emmc {
  574. sdmmc_host_t *host;
  575. uint16_t relative_addr;
  576. emmc_cid_t cid;
  577. emmc_ocr_t ocr;
  578. emmc_csd_t csd;
  579. emmc_ext_csd_t ext_csd;
  580. emmc_device_attribute_t device_attribute;
  581. sdmmc_operation_voltage_t operation_voltage;
  582. emmc_card_status_t current_r1_status;
  583. emmc_partition_t current_partition;
  584. emmc_hs_timing_t current_hs_timing;
  585. emmc_bus_mode_t current_bus_mode;
  586. emmc_power_class_t current_power_class;
  587. emmc_boot_setting_t boot_setting;
  588. bool is_host_ready;
  589. } emmc_card_t;
  590. typedef enum {
  591. emmc_idle_option_go_idle_state = 0,
  592. emmc_idle_option_go_pre_idle_state = 0xF0F0F0F0U,
  593. emmc_idle_option_boot_initialization = 0xFFFFFFFAU,
  594. } emmc_idle_option_t;
  595. typedef enum {
  596. emmc_erase_option_erase = 0, /*!< eMMC Erase operation */
  597. emmc_erase_option_trim = 1, /*!< eMMC Trim operation */
  598. emmc_erase_option_discard = 2, /*!< eMMC Discard operation */
  599. } emmc_erase_option_t;
  600. typedef enum {
  601. boot_partition_enable_option_not_enabled = 0,
  602. boot_partition_enable_option_boot_partition1 = 1,
  603. boot_partition_enable_option_boot_partition2 = 2,
  604. boot_partition_enable_option_user_area = 7,
  605. } emmc_boot_partition_enable_option_t;
  606. typedef enum {
  607. partition_access_option_no_access_to_boot_partition = 0,
  608. partition_access_option_read_write_boot_partition1 = 1,
  609. partition_access_option_read_write_boot_partition2 = 2,
  610. partition_access_option_read_write_rpmb = 3,
  611. partition_access_option_access_to_gp_partition1 = 4,
  612. partition_access_option_access_to_gp_partition2 = 5,
  613. partition_access_option_access_to_gp_partition3 = 6,
  614. partition_access_option_access_to_gp_partition4 = 7
  615. } emmc_partition_access_option_t;
  616. typedef struct {
  617. bool enable_boot_ack;
  618. emmc_boot_partition_enable_option_t boot_partition_enable_option;
  619. emmc_partition_access_t partition_access_option;
  620. } emmc_config_partition_option_t;
  621. /**
  622. * @brief Initialize eMMC device, include both host and the device
  623. *
  624. * @param [in,out] card eMMC card context
  625. *
  626. * @return Command execution status
  627. */
  628. hpm_stat_t emmc_init(emmc_card_t *card);
  629. /**
  630. * @brief De-Initialize eMMC device
  631. *
  632. * @param [in,out] card eMMC card context
  633. *
  634. * @return Command execution status
  635. */
  636. void emmc_deinit(emmc_card_t *card);
  637. /**
  638. * @brief Initialize eMMC device
  639. *
  640. * @param [in,out] card eMMC card context
  641. *
  642. * @return Command execution status
  643. */
  644. hpm_stat_t emmc_card_init(emmc_card_t *card);
  645. /**
  646. * @brief Request eMMC device to send CID to Host
  647. *
  648. * @param [in,out] card eMMC card context
  649. *
  650. * @return Command execution status
  651. */
  652. hpm_stat_t emmc_send_cid(emmc_card_t *card);
  653. /**
  654. * @brief Probe eMMC device
  655. *
  656. * @param [in,out] card eMMC card context
  657. *
  658. * @return Command execution status
  659. */
  660. hpm_stat_t emmc_probe_device(emmc_card_t *card);
  661. /**
  662. * @brief Select eMMC device
  663. *
  664. * @param [in,out] card eMMC card context
  665. * @param [in] is_selected Select/De-select the eMMC device
  666. *
  667. * @return Command execution status
  668. */
  669. hpm_stat_t emmc_select_card(const emmc_card_t *card, bool is_selected);
  670. /**
  671. * @brief Go to Idle mode
  672. *
  673. * @param [in,out] card eMMC card context
  674. * @param [in] option eMMC idle options
  675. *
  676. * @return Command execution status
  677. */
  678. hpm_stat_t emmc_go_idle(emmc_card_t *card, emmc_idle_option_t option);
  679. /**
  680. * @brief Switch eMMC function
  681. *
  682. * @param [in,out] card eMMC card context
  683. * @param [in] arg Switch command argument
  684. * @param [in] timeout_us Timeout in microseconds
  685. *
  686. * @return Command Execution status
  687. */
  688. hpm_stat_t emmc_switch_function(const emmc_card_t *card, emmc_switch_cmd_arg_t arg, uint32_t timeout_us);
  689. /**
  690. * @brief Configure eMMC Partition
  691. *
  692. * @param [in,out] card eMMC card context
  693. * @param [in] option Partition configuration option
  694. *
  695. * @return Command Execution status
  696. */
  697. hpm_stat_t emmc_configure_partition(const emmc_card_t *card, emmc_config_partition_option_t option);
  698. /**
  699. * @brief Enable High Density Erase group
  700. * @param [in,out] card eMMC card context
  701. * @param [in] enable Flag for enabling the high density erase group
  702. *
  703. * @return Command Execution status
  704. */
  705. hpm_stat_t emmc_enable_high_density_erase_group(emmc_card_t *card, bool enable);
  706. /**
  707. * @brief Program CSD register
  708. *
  709. * @param [in,out] card eMMC card context
  710. * @param [in] raw_csd raw CSD buffer
  711. *
  712. * @return Command Execution status
  713. */
  714. hpm_stat_t emmc_program_csd(emmc_card_t *card, const uint32_t *raw_csd);
  715. /**
  716. * @brief Read eMMC blocks
  717. *
  718. * @param [in,out] card eMMC card context
  719. * @param [out] buffer Data buffer
  720. * @param [in] start_block Start Block index
  721. * @param [in] block_count Number of blocks to be read
  722. *
  723. * @return Command Execution status
  724. */
  725. hpm_stat_t emmc_read_blocks(emmc_card_t *card, uint8_t *buffer, uint32_t start_block, uint32_t block_count);
  726. /**
  727. * @brief Write eMMC blocks
  728. *
  729. * @param [in,out] card eMMC card context
  730. * @param [in] buffer Buffer to be written
  731. * @param [in] start_block Start block index
  732. * @param [in] block_count Number of blocks to be written
  733. *
  734. * @return Command Execution status
  735. */
  736. hpm_stat_t emmc_write_blocks(emmc_card_t *card, const uint8_t *buffer, uint32_t start_block, uint32_t block_count);
  737. /**
  738. * @brief Erase eMMC Blocks
  739. *
  740. * @param [in,out] card eMMC card context
  741. * @param [in] start_block The start block =
  742. * @param [in] block_count Number of blocks to be erased
  743. * @param [in] option Erase option
  744. *
  745. * @return Command Execution status
  746. */
  747. hpm_stat_t emmc_erase_blocks(emmc_card_t *card, uint32_t start_block, uint32_t block_count, emmc_erase_option_t option);
  748. /**
  749. * @brief Switch eMMC device into sleep mode
  750. *
  751. * @param [in,out] card eMMC card context
  752. *
  753. * @return Command Execution status
  754. */
  755. hpm_stat_t emmc_enter_sleep_mode(const emmc_card_t *card);
  756. /**
  757. * @brief Switch eMMC device into standby mode
  758. *
  759. * @param [in,out] card eMMC card context
  760. *
  761. * @return Command Execution status
  762. */
  763. hpm_stat_t emmc_exit_sleep_mode(const emmc_card_t *card);
  764. #ifdef __cplusplus
  765. }
  766. #endif
  767. /**
  768. * @}
  769. */
  770. #endif /* HPM_SDMMC_EMMC_H */