spiflash.h 2.2 KB

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