mmc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * Copyright 2008,2010 Freescale Semiconductor, Inc
  3. * Andy Fleming
  4. *
  5. * Based (loosely) on the Linux code
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #ifndef _MMC_H_
  10. #define _MMC_H_
  11. #include <linux/list.h>
  12. #include <linux/sizes.h>
  13. #include <linux/compiler.h>
  14. #include <part.h>
  15. /* SD/MMC version bits; 8 flags, 8 major, 8 minor, 8 change */
  16. #define SD_VERSION_SD (1U << 31)
  17. #define MMC_VERSION_MMC (1U << 30)
  18. #define MAKE_SDMMC_VERSION(a, b, c) \
  19. ((((u32)(a)) << 16) | ((u32)(b) << 8) | (u32)(c))
  20. #define MAKE_SD_VERSION(a, b, c) \
  21. (SD_VERSION_SD | MAKE_SDMMC_VERSION(a, b, c))
  22. #define MAKE_MMC_VERSION(a, b, c) \
  23. (MMC_VERSION_MMC | MAKE_SDMMC_VERSION(a, b, c))
  24. #define EXTRACT_SDMMC_MAJOR_VERSION(x) \
  25. (((u32)(x) >> 16) & 0xff)
  26. #define EXTRACT_SDMMC_MINOR_VERSION(x) \
  27. (((u32)(x) >> 8) & 0xff)
  28. #define EXTRACT_SDMMC_CHANGE_VERSION(x) \
  29. ((u32)(x) & 0xff)
  30. #define SD_VERSION_3 MAKE_SD_VERSION(3, 0, 0)
  31. #define SD_VERSION_2 MAKE_SD_VERSION(2, 0, 0)
  32. #define SD_VERSION_1_0 MAKE_SD_VERSION(1, 0, 0)
  33. #define SD_VERSION_1_10 MAKE_SD_VERSION(1, 10, 0)
  34. #define MMC_VERSION_UNKNOWN MAKE_MMC_VERSION(0, 0, 0)
  35. #define MMC_VERSION_1_2 MAKE_MMC_VERSION(1, 2, 0)
  36. #define MMC_VERSION_1_4 MAKE_MMC_VERSION(1, 4, 0)
  37. #define MMC_VERSION_2_2 MAKE_MMC_VERSION(2, 2, 0)
  38. #define MMC_VERSION_3 MAKE_MMC_VERSION(3, 0, 0)
  39. #define MMC_VERSION_4 MAKE_MMC_VERSION(4, 0, 0)
  40. #define MMC_VERSION_4_1 MAKE_MMC_VERSION(4, 1, 0)
  41. #define MMC_VERSION_4_2 MAKE_MMC_VERSION(4, 2, 0)
  42. #define MMC_VERSION_4_3 MAKE_MMC_VERSION(4, 3, 0)
  43. #define MMC_VERSION_4_41 MAKE_MMC_VERSION(4, 4, 1)
  44. #define MMC_VERSION_4_5 MAKE_MMC_VERSION(4, 5, 0)
  45. #define MMC_VERSION_5_0 MAKE_MMC_VERSION(5, 0, 0)
  46. #define MMC_VERSION_5_1 MAKE_MMC_VERSION(5, 1, 0)
  47. #define MMC_MODE_HS (1 << 0)
  48. #define MMC_MODE_HS_52MHz (1 << 1)
  49. #define MMC_MODE_4BIT (1 << 2)
  50. #define MMC_MODE_8BIT (1 << 3)
  51. #define MMC_MODE_SPI (1 << 4)
  52. #define MMC_MODE_DDR_52MHz (1 << 5)
  53. #define SD_DATA_4BIT 0x00040000
  54. #define IS_SD(x) ((x)->version & SD_VERSION_SD)
  55. #define IS_MMC(x) ((x)->version & MMC_VERSION_MMC)
  56. #define MMC_DATA_READ 1
  57. #define MMC_DATA_WRITE 2
  58. #define MMC_CMD_GO_IDLE_STATE 0
  59. #define MMC_CMD_SEND_OP_COND 1
  60. #define MMC_CMD_ALL_SEND_CID 2
  61. #define MMC_CMD_SET_RELATIVE_ADDR 3
  62. #define MMC_CMD_SET_DSR 4
  63. #define MMC_CMD_SWITCH 6
  64. #define MMC_CMD_SELECT_CARD 7
  65. #define MMC_CMD_SEND_EXT_CSD 8
  66. #define MMC_CMD_SEND_CSD 9
  67. #define MMC_CMD_SEND_CID 10
  68. #define MMC_CMD_STOP_TRANSMISSION 12
  69. #define MMC_CMD_SEND_STATUS 13
  70. #define MMC_CMD_SET_BLOCKLEN 16
  71. #define MMC_CMD_READ_SINGLE_BLOCK 17
  72. #define MMC_CMD_READ_MULTIPLE_BLOCK 18
  73. #define MMC_CMD_SET_BLOCK_COUNT 23
  74. #define MMC_CMD_WRITE_SINGLE_BLOCK 24
  75. #define MMC_CMD_WRITE_MULTIPLE_BLOCK 25
  76. #define MMC_CMD_ERASE_GROUP_START 35
  77. #define MMC_CMD_ERASE_GROUP_END 36
  78. #define MMC_CMD_ERASE 38
  79. #define MMC_CMD_APP_CMD 55
  80. #define MMC_CMD_SPI_READ_OCR 58
  81. #define MMC_CMD_SPI_CRC_ON_OFF 59
  82. #define MMC_CMD_RES_MAN 62
  83. #define MMC_CMD62_ARG1 0xefac62ec
  84. #define MMC_CMD62_ARG2 0xcbaea7
  85. #define SD_CMD_SEND_RELATIVE_ADDR 3
  86. #define SD_CMD_SWITCH_FUNC 6
  87. #define SD_CMD_SEND_IF_COND 8
  88. #define SD_CMD_SWITCH_UHS18V 11
  89. #define SD_CMD_APP_SET_BUS_WIDTH 6
  90. #define SD_CMD_APP_SD_STATUS 13
  91. #define SD_CMD_ERASE_WR_BLK_START 32
  92. #define SD_CMD_ERASE_WR_BLK_END 33
  93. #define SD_CMD_APP_SEND_OP_COND 41
  94. #define SD_CMD_APP_SEND_SCR 51
  95. /* SCR definitions in different words */
  96. #define SD_HIGHSPEED_BUSY 0x00020000
  97. #define SD_HIGHSPEED_SUPPORTED 0x00020000
  98. #define OCR_BUSY 0x80000000
  99. #define OCR_HCS 0x40000000
  100. #define OCR_VOLTAGE_MASK 0x007FFF80
  101. #define OCR_ACCESS_MODE 0x60000000
  102. #define MMC_ERASE_ARG 0x00000000
  103. #define MMC_SECURE_ERASE_ARG 0x80000000
  104. #define MMC_TRIM_ARG 0x00000001
  105. #define MMC_DISCARD_ARG 0x00000003
  106. #define MMC_SECURE_TRIM1_ARG 0x80000001
  107. #define MMC_SECURE_TRIM2_ARG 0x80008000
  108. #define MMC_STATUS_MASK (~0x0206BF7F)
  109. #define MMC_STATUS_SWITCH_ERROR (1 << 7)
  110. #define MMC_STATUS_RDY_FOR_DATA (1 << 8)
  111. #define MMC_STATUS_CURR_STATE (0xf << 9)
  112. #define MMC_STATUS_ERROR (1 << 19)
  113. #define MMC_STATE_PRG (7 << 9)
  114. #define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
  115. #define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */
  116. #define MMC_VDD_21_22 0x00000200 /* VDD voltage 2.1 ~ 2.2 */
  117. #define MMC_VDD_22_23 0x00000400 /* VDD voltage 2.2 ~ 2.3 */
  118. #define MMC_VDD_23_24 0x00000800 /* VDD voltage 2.3 ~ 2.4 */
  119. #define MMC_VDD_24_25 0x00001000 /* VDD voltage 2.4 ~ 2.5 */
  120. #define MMC_VDD_25_26 0x00002000 /* VDD voltage 2.5 ~ 2.6 */
  121. #define MMC_VDD_26_27 0x00004000 /* VDD voltage 2.6 ~ 2.7 */
  122. #define MMC_VDD_27_28 0x00008000 /* VDD voltage 2.7 ~ 2.8 */
  123. #define MMC_VDD_28_29 0x00010000 /* VDD voltage 2.8 ~ 2.9 */
  124. #define MMC_VDD_29_30 0x00020000 /* VDD voltage 2.9 ~ 3.0 */
  125. #define MMC_VDD_30_31 0x00040000 /* VDD voltage 3.0 ~ 3.1 */
  126. #define MMC_VDD_31_32 0x00080000 /* VDD voltage 3.1 ~ 3.2 */
  127. #define MMC_VDD_32_33 0x00100000 /* VDD voltage 3.2 ~ 3.3 */
  128. #define MMC_VDD_33_34 0x00200000 /* VDD voltage 3.3 ~ 3.4 */
  129. #define MMC_VDD_34_35 0x00400000 /* VDD voltage 3.4 ~ 3.5 */
  130. #define MMC_VDD_35_36 0x00800000 /* VDD voltage 3.5 ~ 3.6 */
  131. #define MMC_SWITCH_MODE_CMD_SET 0x00 /* Change the command set */
  132. #define MMC_SWITCH_MODE_SET_BITS 0x01 /* Set bits in EXT_CSD byte
  133. addressed by index which are
  134. 1 in value field */
  135. #define MMC_SWITCH_MODE_CLEAR_BITS 0x02 /* Clear bits in EXT_CSD byte
  136. addressed by index, which are
  137. 1 in value field */
  138. #define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target byte to value */
  139. #define SD_SWITCH_CHECK 0
  140. #define SD_SWITCH_SWITCH 1
  141. /*
  142. * EXT_CSD fields
  143. */
  144. #define EXT_CSD_ENH_START_ADDR 136 /* R/W */
  145. #define EXT_CSD_ENH_SIZE_MULT 140 /* R/W */
  146. #define EXT_CSD_GP_SIZE_MULT 143 /* R/W */
  147. #define EXT_CSD_PARTITION_SETTING 155 /* R/W */
  148. #define EXT_CSD_PARTITIONS_ATTRIBUTE 156 /* R/W */
  149. #define EXT_CSD_MAX_ENH_SIZE_MULT 157 /* R */
  150. #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */
  151. #define EXT_CSD_RST_N_FUNCTION 162 /* R/W */
  152. #define EXT_CSD_BKOPS_EN 163 /* R/W & R/W/E */
  153. #define EXT_CSD_WR_REL_PARAM 166 /* R */
  154. #define EXT_CSD_WR_REL_SET 167 /* R/W */
  155. #define EXT_CSD_RPMB_MULT 168 /* RO */
  156. #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
  157. #define EXT_CSD_BOOT_BUS_WIDTH 177
  158. #define EXT_CSD_PART_CONF 179 /* R/W */
  159. #define EXT_CSD_BUS_WIDTH 183 /* R/W */
  160. #define EXT_CSD_HS_TIMING 185 /* R/W */
  161. #define EXT_CSD_REV 192 /* RO */
  162. #define EXT_CSD_CARD_TYPE 196 /* RO */
  163. #define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
  164. #define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */
  165. #define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */
  166. #define EXT_CSD_BOOT_MULT 226 /* RO */
  167. #define EXT_CSD_BKOPS_SUPPORT 502 /* RO */
  168. /*
  169. * EXT_CSD field definitions
  170. */
  171. #define EXT_CSD_CMD_SET_NORMAL (1 << 0)
  172. #define EXT_CSD_CMD_SET_SECURE (1 << 1)
  173. #define EXT_CSD_CMD_SET_CPSECURE (1 << 2)
  174. #define EXT_CSD_CARD_TYPE_26 (1 << 0) /* Card can run at 26MHz */
  175. #define EXT_CSD_CARD_TYPE_52 (1 << 1) /* Card can run at 52MHz */
  176. #define EXT_CSD_CARD_TYPE_DDR_1_8V (1 << 2)
  177. #define EXT_CSD_CARD_TYPE_DDR_1_2V (1 << 3)
  178. #define EXT_CSD_CARD_TYPE_DDR_52 (EXT_CSD_CARD_TYPE_DDR_1_8V \
  179. | EXT_CSD_CARD_TYPE_DDR_1_2V)
  180. #define EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */
  181. #define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
  182. #define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */
  183. #define EXT_CSD_DDR_BUS_WIDTH_4 5 /* Card is in 4 bit DDR mode */
  184. #define EXT_CSD_DDR_BUS_WIDTH_8 6 /* Card is in 8 bit DDR mode */
  185. #define EXT_CSD_BOOT_ACK_ENABLE (1 << 6)
  186. #define EXT_CSD_BOOT_PARTITION_ENABLE (1 << 3)
  187. #define EXT_CSD_PARTITION_ACCESS_ENABLE (1 << 0)
  188. #define EXT_CSD_PARTITION_ACCESS_DISABLE (0 << 0)
  189. #define EXT_CSD_BOOT_ACK(x) (x << 6)
  190. #define EXT_CSD_BOOT_PART_NUM(x) (x << 3)
  191. #define EXT_CSD_PARTITION_ACCESS(x) (x << 0)
  192. #define EXT_CSD_BOOT_BUS_WIDTH_MODE(x) (x << 3)
  193. #define EXT_CSD_BOOT_BUS_WIDTH_RESET(x) (x << 2)
  194. #define EXT_CSD_BOOT_BUS_WIDTH_WIDTH(x) (x)
  195. #define EXT_CSD_PARTITION_SETTING_COMPLETED (1 << 0)
  196. #define EXT_CSD_ENH_USR (1 << 0) /* user data area is enhanced */
  197. #define EXT_CSD_ENH_GP(x) (1 << ((x)+1)) /* GP part (x+1) is enhanced */
  198. #define EXT_CSD_HS_CTRL_REL (1 << 0) /* host controlled WR_REL_SET */
  199. #define EXT_CSD_WR_DATA_REL_USR (1 << 0) /* user data area WR_REL */
  200. #define EXT_CSD_WR_DATA_REL_GP(x) (1 << ((x)+1)) /* GP part (x+1) WR_REL */
  201. #define R1_ILLEGAL_COMMAND (1 << 22)
  202. #define R1_APP_CMD (1 << 5)
  203. #define MMC_RSP_PRESENT (1 << 0)
  204. #define MMC_RSP_136 (1 << 1) /* 136 bit response */
  205. #define MMC_RSP_CRC (1 << 2) /* expect valid crc */
  206. #define MMC_RSP_BUSY (1 << 3) /* card may send busy */
  207. #define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
  208. #define MMC_RSP_NONE (0)
  209. #define MMC_RSP_R1 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  210. #define MMC_RSP_R1b (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE| \
  211. MMC_RSP_BUSY)
  212. #define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
  213. #define MMC_RSP_R3 (MMC_RSP_PRESENT)
  214. #define MMC_RSP_R4 (MMC_RSP_PRESENT)
  215. #define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  216. #define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  217. #define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
  218. #define MMCPART_NOAVAILABLE (0xff)
  219. #define PART_ACCESS_MASK (0x7)
  220. #define PART_SUPPORT (0x1)
  221. #define ENHNCD_SUPPORT (0x2)
  222. #define PART_ENH_ATTRIB (0x1f)
  223. /* Maximum block size for MMC */
  224. #define MMC_MAX_BLOCK_LEN 512
  225. /* The number of MMC physical partitions. These consist of:
  226. * boot partitions (2), general purpose partitions (4) in MMC v4.4.
  227. */
  228. #define MMC_NUM_BOOT_PARTITION 2
  229. #define MMC_PART_RPMB 3 /* RPMB partition number */
  230. /* Driver model support */
  231. /**
  232. * struct mmc_uclass_priv - Holds information about a device used by the uclass
  233. */
  234. struct mmc_uclass_priv {
  235. struct mmc *mmc;
  236. };
  237. /**
  238. * mmc_get_mmc_dev() - get the MMC struct pointer for a device
  239. *
  240. * Provided that the device is already probed and ready for use, this value
  241. * will be available.
  242. *
  243. * @dev: Device
  244. * @return associated mmc struct pointer if available, else NULL
  245. */
  246. struct mmc *mmc_get_mmc_dev(struct udevice *dev);
  247. /* End of driver model support */
  248. struct mmc_cid {
  249. unsigned long psn;
  250. unsigned short oid;
  251. unsigned char mid;
  252. unsigned char prv;
  253. unsigned char mdt;
  254. char pnm[7];
  255. };
  256. struct mmc_cmd {
  257. ushort cmdidx;
  258. uint resp_type;
  259. uint cmdarg;
  260. uint response[4];
  261. };
  262. struct mmc_data {
  263. union {
  264. char *dest;
  265. const char *src; /* src buffers don't get written to */
  266. };
  267. uint flags;
  268. uint blocks;
  269. uint blocksize;
  270. };
  271. /* forward decl. */
  272. struct mmc;
  273. #if CONFIG_IS_ENABLED(DM_MMC_OPS)
  274. struct dm_mmc_ops {
  275. /**
  276. * send_cmd() - Send a command to the MMC device
  277. *
  278. * @dev: Device to receive the command
  279. * @cmd: Command to send
  280. * @data: Additional data to send/receive
  281. * @return 0 if OK, -ve on error
  282. */
  283. int (*send_cmd)(struct udevice *dev, struct mmc_cmd *cmd,
  284. struct mmc_data *data);
  285. /**
  286. * set_ios() - Set the I/O speed/width for an MMC device
  287. *
  288. * @dev: Device to update
  289. * @return 0 if OK, -ve on error
  290. */
  291. int (*set_ios)(struct udevice *dev);
  292. /**
  293. * get_cd() - See whether a card is present
  294. *
  295. * @dev: Device to check
  296. * @return 0 if not present, 1 if present, -ve on error
  297. */
  298. int (*get_cd)(struct udevice *dev);
  299. /**
  300. * get_wp() - See whether a card has write-protect enabled
  301. *
  302. * @dev: Device to check
  303. * @return 0 if write-enabled, 1 if write-protected, -ve on error
  304. */
  305. int (*get_wp)(struct udevice *dev);
  306. };
  307. #define mmc_get_ops(dev) ((struct dm_mmc_ops *)(dev)->driver->ops)
  308. int dm_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
  309. struct mmc_data *data);
  310. int dm_mmc_set_ios(struct udevice *dev);
  311. int dm_mmc_get_cd(struct udevice *dev);
  312. int dm_mmc_get_wp(struct udevice *dev);
  313. /* Transition functions for compatibility */
  314. int mmc_set_ios(struct mmc *mmc);
  315. int mmc_getcd(struct mmc *mmc);
  316. int mmc_getwp(struct mmc *mmc);
  317. #else
  318. struct mmc_ops {
  319. int (*send_cmd)(struct mmc *mmc,
  320. struct mmc_cmd *cmd, struct mmc_data *data);
  321. int (*set_ios)(struct mmc *mmc);
  322. int (*init)(struct mmc *mmc);
  323. int (*getcd)(struct mmc *mmc);
  324. int (*getwp)(struct mmc *mmc);
  325. };
  326. #endif
  327. struct mmc_config {
  328. const char *name;
  329. #if !CONFIG_IS_ENABLED(DM_MMC_OPS)
  330. const struct mmc_ops *ops;
  331. #endif
  332. uint host_caps;
  333. uint voltages;
  334. uint f_min;
  335. uint f_max;
  336. uint b_max;
  337. unsigned char part_type;
  338. };
  339. struct sd_ssr {
  340. unsigned int au; /* In sectors */
  341. unsigned int erase_timeout; /* In milliseconds */
  342. unsigned int erase_offset; /* In milliseconds */
  343. };
  344. /*
  345. * With CONFIG_DM_MMC enabled, struct mmc can be accessed from the MMC device
  346. * with mmc_get_mmc_dev().
  347. *
  348. * TODO struct mmc should be in mmc_private but it's hard to fix right now
  349. */
  350. struct mmc {
  351. #if !CONFIG_IS_ENABLED(BLK)
  352. struct list_head link;
  353. #endif
  354. const struct mmc_config *cfg; /* provided configuration */
  355. uint version;
  356. void *priv;
  357. uint has_init;
  358. int high_capacity;
  359. uint bus_width;
  360. uint clock;
  361. uint card_caps;
  362. uint ocr;
  363. uint dsr;
  364. uint dsr_imp;
  365. uint scr[2];
  366. uint csd[4];
  367. uint cid[4];
  368. ushort rca;
  369. u8 part_support;
  370. u8 part_attr;
  371. u8 wr_rel_set;
  372. u8 part_config;
  373. uint tran_speed;
  374. uint read_bl_len;
  375. uint write_bl_len;
  376. uint erase_grp_size; /* in 512-byte sectors */
  377. uint hc_wp_grp_size; /* in 512-byte sectors */
  378. struct sd_ssr ssr; /* SD status register */
  379. u64 capacity;
  380. u64 capacity_user;
  381. u64 capacity_boot;
  382. u64 capacity_rpmb;
  383. u64 capacity_gp[4];
  384. u64 enh_user_start;
  385. u64 enh_user_size;
  386. #if !CONFIG_IS_ENABLED(BLK)
  387. struct blk_desc block_dev;
  388. #endif
  389. char op_cond_pending; /* 1 if we are waiting on an op_cond command */
  390. char init_in_progress; /* 1 if we have done mmc_start_init() */
  391. char preinit; /* start init as early as possible */
  392. int ddr_mode;
  393. #if CONFIG_IS_ENABLED(DM_MMC)
  394. struct udevice *dev; /* Device for this MMC controller */
  395. #endif
  396. };
  397. struct mmc_hwpart_conf {
  398. struct {
  399. uint enh_start; /* in 512-byte sectors */
  400. uint enh_size; /* in 512-byte sectors, if 0 no enh area */
  401. unsigned wr_rel_change : 1;
  402. unsigned wr_rel_set : 1;
  403. } user;
  404. struct {
  405. uint size; /* in 512-byte sectors */
  406. unsigned enhanced : 1;
  407. unsigned wr_rel_change : 1;
  408. unsigned wr_rel_set : 1;
  409. } gp_part[4];
  410. };
  411. enum mmc_hwpart_conf_mode {
  412. MMC_HWPART_CONF_CHECK,
  413. MMC_HWPART_CONF_SET,
  414. MMC_HWPART_CONF_COMPLETE,
  415. };
  416. struct mmc *mmc_create(const struct mmc_config *cfg, void *priv);
  417. /**
  418. * mmc_bind() - Set up a new MMC device ready for probing
  419. *
  420. * A child block device is bound with the IF_TYPE_MMC interface type. This
  421. * allows the device to be used with CONFIG_BLK
  422. *
  423. * @dev: MMC device to set up
  424. * @mmc: MMC struct
  425. * @cfg: MMC configuration
  426. * @return 0 if OK, -ve on error
  427. */
  428. int mmc_bind(struct udevice *dev, struct mmc *mmc,
  429. const struct mmc_config *cfg);
  430. void mmc_destroy(struct mmc *mmc);
  431. /**
  432. * mmc_unbind() - Unbind a MMC device's child block device
  433. *
  434. * @dev: MMC device
  435. * @return 0 if OK, -ve on error
  436. */
  437. int mmc_unbind(struct udevice *dev);
  438. int mmc_initialize(bd_t *bis);
  439. int mmc_init(struct mmc *mmc);
  440. int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size);
  441. void mmc_set_clock(struct mmc *mmc, uint clock);
  442. struct mmc *find_mmc_device(int dev_num);
  443. int mmc_set_dev(int dev_num);
  444. void print_mmc_devices(char separator);
  445. /**
  446. * get_mmc_num() - get the total MMC device number
  447. *
  448. * @return 0 if there is no MMC device, else the number of devices
  449. */
  450. int get_mmc_num(void);
  451. int mmc_switch_part(struct mmc *mmc, unsigned int part_num);
  452. int mmc_hwpart_config(struct mmc *mmc, const struct mmc_hwpart_conf *conf,
  453. enum mmc_hwpart_conf_mode mode);
  454. #if !CONFIG_IS_ENABLED(DM_MMC_OPS)
  455. int mmc_getcd(struct mmc *mmc);
  456. int board_mmc_getcd(struct mmc *mmc);
  457. int mmc_getwp(struct mmc *mmc);
  458. int board_mmc_getwp(struct mmc *mmc);
  459. #endif
  460. int mmc_set_dsr(struct mmc *mmc, u16 val);
  461. /* Function to change the size of boot partition and rpmb partitions */
  462. int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
  463. unsigned long rpmbsize);
  464. /* Function to modify the PARTITION_CONFIG field of EXT_CSD */
  465. int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access);
  466. /* Function to modify the BOOT_BUS_WIDTH field of EXT_CSD */
  467. int mmc_set_boot_bus_width(struct mmc *mmc, u8 width, u8 reset, u8 mode);
  468. /* Function to modify the RST_n_FUNCTION field of EXT_CSD */
  469. int mmc_set_rst_n_function(struct mmc *mmc, u8 enable);
  470. /* Functions to read / write the RPMB partition */
  471. int mmc_rpmb_set_key(struct mmc *mmc, void *key);
  472. int mmc_rpmb_get_counter(struct mmc *mmc, unsigned long *counter);
  473. int mmc_rpmb_read(struct mmc *mmc, void *addr, unsigned short blk,
  474. unsigned short cnt, unsigned char *key);
  475. int mmc_rpmb_write(struct mmc *mmc, void *addr, unsigned short blk,
  476. unsigned short cnt, unsigned char *key);
  477. #ifdef CONFIG_CMD_BKOPS_ENABLE
  478. int mmc_set_bkops_enable(struct mmc *mmc);
  479. #endif
  480. /**
  481. * Start device initialization and return immediately; it does not block on
  482. * polling OCR (operation condition register) status. Then you should call
  483. * mmc_init, which would block on polling OCR status and complete the device
  484. * initializatin.
  485. *
  486. * @param mmc Pointer to a MMC device struct
  487. * @return 0 on success, IN_PROGRESS on waiting for OCR status, <0 on error.
  488. */
  489. int mmc_start_init(struct mmc *mmc);
  490. /**
  491. * Set preinit flag of mmc device.
  492. *
  493. * This will cause the device to be pre-inited during mmc_initialize(),
  494. * which may save boot time if the device is not accessed until later.
  495. * Some eMMC devices take 200-300ms to init, but unfortunately they
  496. * must be sent a series of commands to even get them to start preparing
  497. * for operation.
  498. *
  499. * @param mmc Pointer to a MMC device struct
  500. * @param preinit preinit flag value
  501. */
  502. void mmc_set_preinit(struct mmc *mmc, int preinit);
  503. #ifdef CONFIG_MMC_SPI
  504. #define mmc_host_is_spi(mmc) ((mmc)->cfg->host_caps & MMC_MODE_SPI)
  505. #else
  506. #define mmc_host_is_spi(mmc) 0
  507. #endif
  508. struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode);
  509. void board_mmc_power_init(void);
  510. int board_mmc_init(bd_t *bis);
  511. int cpu_mmc_init(bd_t *bis);
  512. int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr);
  513. int mmc_get_env_dev(void);
  514. struct pci_device_id;
  515. /**
  516. * pci_mmc_init() - set up PCI MMC devices
  517. *
  518. * This finds all the matching PCI IDs and sets them up as MMC devices.
  519. *
  520. * @name: Name to use for devices
  521. * @mmc_supported: PCI IDs to search for, terminated by {0, 0}
  522. */
  523. int pci_mmc_init(const char *name, struct pci_device_id *mmc_supported);
  524. /* Set block count limit because of 16 bit register limit on some hardware*/
  525. #ifndef CONFIG_SYS_MMC_MAX_BLK_COUNT
  526. #define CONFIG_SYS_MMC_MAX_BLK_COUNT 65535
  527. #endif
  528. /**
  529. * mmc_get_blk_desc() - Get the block descriptor for an MMC device
  530. *
  531. * @mmc: MMC device
  532. * @return block device if found, else NULL
  533. */
  534. struct blk_desc *mmc_get_blk_desc(struct mmc *mmc);
  535. #endif /* _MMC_H_ */