You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.9 KiB

  1. /*
  2. * Copyright 2008,2010 Freescale Semiconductor, Inc
  3. * Andy Fleming
  4. *
  5. * Copyright 2013 Google Inc. All rights reserved.
  6. * Copyright 2017 Intel Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #ifndef __COMMONLIB_STORAGE_H__
  19. #define __COMMONLIB_STORAGE_H__
  20. #include <commonlib/sd_mmc_ctrlr.h>
  21. /*
  22. * EXT_CSD fields
  23. */
  24. #define EXT_CSD_GP_SIZE_MULT_GP0 143 /* RO */
  25. #define EXT_CSD_GP_SIZE_MULT_GP1 146 /* RO */
  26. #define EXT_CSD_GP_SIZE_MULT_GP2 149 /* RO */
  27. #define EXT_CSD_GP_SIZE_MULT_GP3 152 /* RO */
  28. #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */
  29. #define EXT_CSD_RPMB_SIZE_MULT 168 /* RO */
  30. #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
  31. #define EXT_CSD_PART_CONF 179 /* R/W */
  32. #define EXT_CSD_BUS_WIDTH 183 /* R/W */
  33. #define EXT_CSD_STROBE_SUPPORT 184 /* RO */
  34. #define EXT_CSD_HS_TIMING 185 /* R/W */
  35. #define EXT_CSD_REV 192 /* RO */
  36. #define EXT_CSD_CARD_TYPE 196 /* RO */
  37. #define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
  38. #define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */
  39. #define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */
  40. #define EXT_CSD_BOOT_SIZE_MULT 226 /* RO */
  41. #define EXT_CSD_TRIM_MULT 232 /* RO */
  42. /*
  43. * EXT_CSD field definitions
  44. */
  45. #define EXT_CSD_CMD_SET_NORMAL (1 << 0)
  46. #define EXT_CSD_CMD_SET_SECURE (1 << 1)
  47. #define EXT_CSD_CMD_SET_CPSECURE (1 << 2)
  48. #define EXT_CSD_CARD_TYPE_26 (1 << 0) /* Card can run at 26MHz */
  49. #define EXT_CSD_CARD_TYPE_52 (1 << 1) /* Card can run at 52MHz */
  50. #define EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */
  51. #define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
  52. #define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */
  53. #define EXT_CSD_DDR_BUS_WIDTH_4 5 /* Card is in 4 bit DDR mode */
  54. #define EXT_CSD_DDR_BUS_WIDTH_8 6 /* Card is in 8 bit DDR mode */
  55. #define EXT_CSD_BUS_WIDTH_STROBE (1<<7) /* Enhanced strobe mode */
  56. #define EXT_CSD_TIMING_BC 0 /* Backwards compatility */
  57. #define EXT_CSD_TIMING_HS 1 /* High speed */
  58. #define EXT_CSD_TIMING_HS200 2 /* HS200 */
  59. #define EXT_CSD_TIMING_HS400 3 /* HS400 */
  60. #define EXT_CSD_SIZE 512
  61. /* 179: EXT_CSD_PART_CONF */
  62. #define EXT_CSD_PART_ACCESS_MASK 7 /* Partition access mask */
  63. /* 175: EXT_CSD_ERASE_GROUP_DEF */
  64. #define EXT_CSD_PARTITION_ENABLE 1 /* Enable partition access */
  65. struct storage_media {
  66. uint64_t capacity[8]; /* Partition capacity in bytes */
  67. struct sd_mmc_ctrlr *ctrlr;
  68. #define MMC_PARTITION_USER 0
  69. #define MMC_PARTITION_BOOT_1 1
  70. #define MMC_PARTITION_BOOT_2 2
  71. #define MMC_PARTITION_RPMB 3
  72. #define MMC_PARTITION_GP1 4
  73. #define MMC_PARTITION_GP2 5
  74. #define MMC_PARTITION_GP3 6
  75. #define MMC_PARTITION_GP4 7
  76. uint32_t caps;
  77. uint32_t version;
  78. #define SD_VERSION_SD 0x20000
  79. #define SD_VERSION_2 (SD_VERSION_SD | 0x20)
  80. #define SD_VERSION_1_0 (SD_VERSION_SD | 0x10)
  81. #define SD_VERSION_1_10 (SD_VERSION_SD | 0x1a)
  82. #define MMC_VERSION_MMC 0x10000
  83. #define MMC_VERSION_UNKNOWN (MMC_VERSION_MMC)
  84. #define MMC_VERSION_1_2 (MMC_VERSION_MMC | 0x12)
  85. #define MMC_VERSION_1_4 (MMC_VERSION_MMC | 0x14)
  86. #define MMC_VERSION_2_2 (MMC_VERSION_MMC | 0x22)
  87. #define MMC_VERSION_3 (MMC_VERSION_MMC | 0x30)
  88. #define MMC_VERSION_4 (MMC_VERSION_MMC | 0x40)
  89. uint32_t read_bl_len;
  90. uint32_t write_bl_len;
  91. int high_capacity;
  92. uint32_t tran_speed;
  93. /* Erase size in terms of block length. */
  94. uint32_t erase_blocks;
  95. /* Trim operation multiplier for determining timeout. */
  96. uint32_t trim_mult;
  97. uint32_t ocr;
  98. #define OCR_BUSY 0x80000000
  99. #define OCR_HCS 0x40000000
  100. #define OCR_VOLTAGE_MASK 0x00FFFF80
  101. #define OCR_ACCESS_MODE 0x60000000
  102. uint32_t op_cond_response; // The response byte from the last op_cond
  103. uint32_t scr[2];
  104. uint32_t csd[4];
  105. uint32_t cid[4];
  106. uint16_t rca;
  107. uint8_t partition_config; /* Duplicate of EXT_CSD_PART_CONF */
  108. };
  109. uint64_t storage_block_erase(struct storage_media *media, uint64_t start,
  110. uint64_t count);
  111. uint64_t storage_block_fill_write(struct storage_media *media, uint64_t start,
  112. uint64_t count, uint32_t fill_pattern);
  113. uint64_t storage_block_read(struct storage_media *media, uint64_t start,
  114. uint64_t count, void *buffer);
  115. uint64_t storage_block_write(struct storage_media *media, uint64_t start,
  116. uint64_t count, const void *buffer);
  117. unsigned int storage_get_current_partition(struct storage_media *media);
  118. const char *storage_partition_name(struct storage_media *media,
  119. unsigned int partition_number);
  120. int storage_setup_media(struct storage_media *media,
  121. struct sd_mmc_ctrlr *ctrlr);
  122. int storage_set_partition(struct storage_media *media,
  123. unsigned int partition_number);
  124. void storage_display_setup(struct storage_media *media);
  125. #endif /* __COMMONLIB_STORAGE_H__ */