spiflash.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #pragma once
  2. #include "common.h"
  3. #define SPIFLASH_SECTOR_SIZE 4096 /* Erasable chunk */
  4. #define SPIFLASH_PAGE_SIZE 256 /* Programmable chunk */
  5. struct spz_stream;
  6. typedef struct spz_stream spz_stream;
  7. extern_c int spiflash_write_spz(spz_stream *spz);
  8. /* SPI flash command opcodes */
  9. enum romcmd {
  10. /* Standard SPI mode commands */
  11. ROM_WRITE_ENABLE = 0x06,
  12. ROM_VOLATILE_SR_WRITE_ENABLE = 0x50,
  13. ROM_WRITE_DISABLE = 0x04,
  14. ROM_RELEASE_POWERDOWN_ID = 0xab,
  15. ROM_MANUFACTURER_DEVICE_ID = 0x90,
  16. ROM_JEDEC_ID = 0x9f,
  17. ROM_READ_UNIQUE_ID = 0x4b,
  18. ROM_READ_DATA = 0x03, /* DO NOT USE */
  19. ROM_READ_DATA_32BIT = 0x13, /* DO NOT USE */
  20. ROM_FAST_READ = 0x0b,
  21. ROM_FAST_READ_32BIT = 0x0c,
  22. ROM_PAGE_PROGRAM = 0x02,
  23. ROM_PAGE_PROGRAM_32BIT = 0x12,
  24. ROM_ERASE_4K = 0x20,
  25. ROM_ERASE_4K_32BIT = 0x21,
  26. ROM_ERASE_32K = 0x52,
  27. ROM_ERASE_64K = 0xd8,
  28. ROM_ERASE_64K_32BIT = 0xdc,
  29. ROM_ERASE_ALL = 0xc7,
  30. ROM_READ_SR1 = 0x05,
  31. ROM_WRITE_SR1 = 0x01,
  32. ROM_READ_SR2 = 0x35,
  33. ROM_WRITE_SR2 = 0x31,
  34. ROM_READ_SR3 = 0x15,
  35. ROM_WRITE_SR3 = 0x11,
  36. ROM_READ_EAR = 0xc8, /* Extended address register */
  37. ROM_WRITE_EAR = 0xc5,
  38. ROM_READ_SFDP = 0x5a,
  39. ROM_ERASE_SECURITY = 0x44,
  40. ROM_PROGRAM_SECURITY = 0x42,
  41. ROM_READ_SECURITY = 0x48,
  42. ROM_GLOBAL_BLOCK_LOCK = 0x7e,
  43. ROM_GLOBAL_BLOCK_UNLOCK = 0x98,
  44. ROM_READ_BLOCK_LOCK = 0x3d,
  45. ROM_ONE_BLOCK_LOCK = 0x36,
  46. ROM_ONE_BLOCK_UNLOCK = 0x39,
  47. ROM_ERASE_PROGRAM_SUSPEND = 0x75,
  48. ROM_ERASE_PROGRAM_RESUME = 0x7a,
  49. ROM_POWER_DOWN = 0xb9,
  50. ROM_ENTER_32BIT = 0xb7,
  51. ROM_LEAVE_32BIT = 0xe9,
  52. ROM_ENTER_QPI = 0x48,
  53. ROM_ENABLE_RESET = 0x66,
  54. ROM_RESET = 0x99,
  55. /* Dual SPI commands */
  56. ROM_FAST_READ_DUAL = 0x3b,
  57. ROM_FAST_READ_DUAL_32BIT = 0x3c
  58. };
  59. #define SPIFLASH_SFDP_SIZE 256
  60. enum spiflash_addr_mode {
  61. SPIFLASH_ADDR_DYNAMIC, /* 24-bit for < 16 MB, otherwise 32 bit */
  62. SPIFLASH_ADDR_24BIT, /* 24-bit addressing only */
  63. SPIFLASH_ADDR_32BIT /* 32-bit addressing only */
  64. };