mtd-cfi.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-02-25 GuEe-GUI the first version
  9. */
  10. #ifndef __MTD_CFI_H__
  11. #define __MTD_CFI_H__
  12. #include <rtthread.h>
  13. /* Values for the width of the port */
  14. #define FLASH_CFI_8BIT 0x01
  15. #define FLASH_CFI_16BIT 0x02
  16. #define FLASH_CFI_32BIT 0x04
  17. #define FLASH_CFI_64BIT 0x08
  18. /* Values for the width of the chip */
  19. #define FLASH_CFI_BY8 0x01
  20. #define FLASH_CFI_BY16 0x02
  21. #define FLASH_CFI_BY32 0x04
  22. #define FLASH_CFI_BY64 0x08
  23. /* Values for the flash device interface */
  24. #define FLASH_CFI_X8 0x00
  25. #define FLASH_CFI_X16 0x01
  26. #define FLASH_CFI_X8X16 0x02
  27. #define FLASH_CFI_X16X32 0x05
  28. /* Convert between bit value and numeric value */
  29. #define FLASH_CFI_SHIFT_WIDTH 3
  30. #define FLASH_CMD_CFI 0x98
  31. #define FLASH_CMD_READ_ID 0x90
  32. #define FLASH_CMD_RESET 0xff
  33. #define FLASH_CMD_BLOCK_ERASE 0x20
  34. #define FLASH_CMD_ERASE_CONFIRM 0xd0
  35. #define FLASH_CMD_WRITE 0x40
  36. #define FLASH_CMD_PROTECT 0x60
  37. #define FLASH_CMD_SETUP 0x60
  38. #define FLASH_CMD_SET_CR_CONFIRM 0x03
  39. #define FLASH_CMD_PROTECT_SET 0x01
  40. #define FLASH_CMD_PROTECT_CLEAR 0xd0
  41. #define FLASH_CMD_CLEAR_STATUS 0x50
  42. #define FLASH_CMD_READ_STATUS 0x70
  43. #define FLASH_CMD_WRITE_TO_BUFFER 0xe8
  44. #define FLASH_CMD_WRITE_BUFFER_PROG 0xe9
  45. #define FLASH_CMD_WRITE_BUFFER_CONFIRM 0xd0
  46. #define FLASH_STATUS_DONE 0x80
  47. #define FLASH_STATUS_ESS 0x40
  48. #define FLASH_STATUS_ECLBS 0x20
  49. #define FLASH_STATUS_PSLBS 0x10
  50. #define FLASH_STATUS_VPENS 0x08
  51. #define FLASH_STATUS_PSS 0x04
  52. #define FLASH_STATUS_DPS 0x02
  53. #define FLASH_STATUS_R 0x01
  54. #define FLASH_STATUS_PROTECT 0x01
  55. #define FLASH_CONTINUATION_CODE 0x7f
  56. #define FLASH_OFFSET_MANUFACTURER_ID 0x00
  57. #define FLASH_OFFSET_DEVICE_ID 0x01
  58. #define FLASH_OFFSET_LOWER_SW_BITS 0x0c
  59. #define FLASH_OFFSET_DEVICE_ID2 0x0e
  60. #define FLASH_OFFSET_DEVICE_ID3 0x0f
  61. #define FLASH_OFFSET_CFI 0x55
  62. #define FLASH_OFFSET_CFI_ALT 0x555
  63. #define FLASH_OFFSET_CFI_RESP 0x10 /* "QRY" */
  64. #define FLASH_OFFSET_PRIMARY_VENDOR 0x13 /* Primary OEM command set */
  65. #define FLASH_OFFSET_EXT_QUERY_T_P_ADDR 0x15 /* Extended query table primary address */
  66. #define FLASH_OFFSET_WTOUT 0x1f
  67. #define FLASH_OFFSET_WBTOUT 0x20
  68. #define FLASH_OFFSET_ETOUT 0x21
  69. #define FLASH_OFFSET_CETOUT 0x22
  70. #define FLASH_OFFSET_WMAX_TOUT 0x23
  71. #define FLASH_OFFSET_WBMAX_TOUT 0x24
  72. #define FLASH_OFFSET_EMAX_TOUT 0x25
  73. #define FLASH_OFFSET_CEMAX_TOUT 0x26
  74. #define FLASH_OFFSET_SIZE 0x27 /* 2^N bytes */
  75. #define FLASH_OFFSET_INTERFACE 0x28
  76. #define FLASH_OFFSET_BUFFER_SIZE 0x2a
  77. #define FLASH_OFFSET_NUM_ERASE_REGIONS 0x2c
  78. #define FLASH_OFFSET_ERASE_REGIONS 0x2d
  79. #define FLASH_OFFSET_PROTECT 0x02
  80. #define FLASH_OFFSET_USER_PROTECTION 0x85
  81. #define FLASH_OFFSET_INTEL_PROTECTION 0x81
  82. #define CFI_CMDSET_NONE 0
  83. #define CFI_CMDSET_INTEL_EXTENDED 1
  84. #define CFI_CMDSET_AMD_STANDARD 2
  85. #define CFI_CMDSET_INTEL_STANDARD 3
  86. #define CFI_CMDSET_AMD_EXTENDED 4
  87. #define CFI_CMDSET_MITSU_STANDARD 256
  88. #define CFI_CMDSET_MITSU_EXTENDED 257
  89. #define CFI_CMDSET_SST 258
  90. #define CFI_CMDSET_INTEL_PROG_REGIONS 512
  91. #define AMD_CMD_RESET 0xf0
  92. #define AMD_CMD_WRITE 0xa0
  93. #define AMD_CMD_ERASE_START 0x80
  94. #define AMD_CMD_ERASE_SECTOR 0x30
  95. #define AMD_CMD_UNLOCK_START 0xaa
  96. #define AMD_CMD_UNLOCK_ACK 0x55
  97. #define AMD_CMD_WRITE_TO_BUFFER 0x25
  98. #define AMD_CMD_WRITE_BUFFER_CONFIRM 0x29
  99. #define AMD_CMD_SET_PPB_ENTRY 0xc0
  100. #define AMD_CMD_SET_PPB_EXIT_BC1 0x90
  101. #define AMD_CMD_SET_PPB_EXIT_BC2 0x00
  102. #define AMD_CMD_PPB_UNLOCK_BC1 0x80
  103. #define AMD_CMD_PPB_UNLOCK_BC2 0x30
  104. #define AMD_CMD_PPB_LOCK_BC1 0xa0
  105. #define AMD_CMD_PPB_LOCK_BC2 0x00
  106. #define AMD_STATUS_TOGGLE 0x40
  107. #define AMD_STATUS_ERROR 0x20
  108. #define ATM_CMD_UNLOCK_SECT 0x70
  109. #define ATM_CMD_SOFTLOCK_START 0x80
  110. #define ATM_CMD_LOCK_SECT 0x40
  111. union cfi_word
  112. {
  113. rt_uint8_t w8;
  114. rt_uint16_t w16;
  115. rt_uint32_t w32;
  116. rt_uint64_t w64;
  117. };
  118. #ifndef CFI_FLASH_SECT_MAX
  119. #define CFI_FLASH_SECT_MAX 512
  120. #endif
  121. #ifndef CFI_QUERY_ERASE_REGIONS_MAX
  122. #define CFI_QUERY_ERASE_REGIONS_MAX CFI_FLASH_SECT_MAX
  123. #endif
  124. rt_packed(struct cfi_query
  125. {
  126. rt_uint8_t query[3]; /* "Q" "R" "Y" */
  127. rt_uint16_t primary_id; /* Unaligned */
  128. rt_uint16_t primary_address; /* Unaligned */
  129. rt_uint16_t alternate_id; /* Unaligned */
  130. rt_uint16_t alternate_address; /* Unaligned */
  131. rt_uint8_t vcc_min;
  132. rt_uint8_t vcc_max;
  133. rt_uint8_t vpp_min;
  134. rt_uint8_t vpp_max;
  135. rt_uint8_t word_write_timeout_type;
  136. rt_uint8_t buf_write_timeout_type;
  137. rt_uint8_t block_erase_timeout_type;
  138. rt_uint8_t chip_erase_timeout_type;
  139. rt_uint8_t word_write_timeout_max;
  140. rt_uint8_t buf_write_timeout_max;
  141. rt_uint8_t block_erase_timeout_max;
  142. rt_uint8_t chip_erase_timeout_max;
  143. rt_uint8_t dev_size;
  144. rt_uint16_t interface_desc; /* Aligned */
  145. rt_uint16_t max_buf_write_size; /* Aligned */
  146. rt_uint8_t num_erase_regions;
  147. rt_uint32_t erase_region_info[CFI_QUERY_ERASE_REGIONS_MAX]; /* Unaligned */
  148. });
  149. #endif /* __MTD_CFI_H__ */