sf_internal.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * SPI flash internal definitions
  3. *
  4. * Copyright (C) 2008 Atmel Corporation
  5. * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #ifndef _SF_INTERNAL_H_
  10. #define _SF_INTERNAL_H_
  11. #define SPI_FLASH_3B_ADDR_LEN 3
  12. #define SPI_FLASH_CMD_LEN (1 + SPI_FLASH_3B_ADDR_LEN)
  13. #define SPI_FLASH_16MB_BOUN 0x1000000
  14. /* CFI Manufacture ID's */
  15. #define SPI_FLASH_CFI_MFR_SPANSION 0x01
  16. #define SPI_FLASH_CFI_MFR_STMICRO 0x20
  17. #define SPI_FLASH_CFI_MFR_MACRONIX 0xc2
  18. #define SPI_FLASH_CFI_MFR_WINBOND 0xef
  19. /* Erase commands */
  20. #define CMD_ERASE_4K 0x20
  21. #define CMD_ERASE_32K 0x52
  22. #define CMD_ERASE_CHIP 0xc7
  23. #define CMD_ERASE_64K 0xd8
  24. /* Write commands */
  25. #define CMD_WRITE_STATUS 0x01
  26. #define CMD_PAGE_PROGRAM 0x02
  27. #define CMD_WRITE_DISABLE 0x04
  28. #define CMD_READ_STATUS 0x05
  29. #define CMD_QUAD_PAGE_PROGRAM 0x32
  30. #define CMD_READ_STATUS1 0x35
  31. #define CMD_WRITE_ENABLE 0x06
  32. #define CMD_READ_CONFIG 0x35
  33. #define CMD_FLAG_STATUS 0x70
  34. /* Read commands */
  35. #define CMD_READ_ARRAY_SLOW 0x03
  36. #define CMD_READ_ARRAY_FAST 0x0b
  37. #define CMD_READ_DUAL_OUTPUT_FAST 0x3b
  38. #define CMD_READ_DUAL_IO_FAST 0xbb
  39. #define CMD_READ_QUAD_OUTPUT_FAST 0x6b
  40. #define CMD_READ_QUAD_IO_FAST 0xeb
  41. #define CMD_READ_ID 0x9f
  42. /* Bank addr access commands */
  43. #ifdef CONFIG_SPI_FLASH_BAR
  44. # define CMD_BANKADDR_BRWR 0x17
  45. # define CMD_BANKADDR_BRRD 0x16
  46. # define CMD_EXTNADDR_WREAR 0xC5
  47. # define CMD_EXTNADDR_RDEAR 0xC8
  48. #endif
  49. /* Common status */
  50. #define STATUS_WIP (1 << 0)
  51. #define STATUS_QEB_WINSPAN (1 << 1)
  52. #define STATUS_QEB_MXIC (1 << 6)
  53. #define STATUS_PEC (1 << 7)
  54. #ifdef CONFIG_SYS_SPI_ST_ENABLE_WP_PIN
  55. #define STATUS_SRWD (1 << 7) /* SR write protect */
  56. #endif
  57. /* Flash timeout values */
  58. #define SPI_FLASH_PROG_TIMEOUT (2 * CONFIG_SYS_HZ)
  59. #define SPI_FLASH_PAGE_ERASE_TIMEOUT (5 * CONFIG_SYS_HZ)
  60. #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
  61. /* SST specific */
  62. #ifdef CONFIG_SPI_FLASH_SST
  63. # define SST_WP 0x01 /* Supports AAI word program */
  64. # define CMD_SST_BP 0x02 /* Byte Program */
  65. # define CMD_SST_AAI_WP 0xAD /* Auto Address Incr Word Program */
  66. int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
  67. const void *buf);
  68. #endif
  69. /* Send a single-byte command to the device and read the response */
  70. int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);
  71. /*
  72. * Send a multi-byte command to the device and read the response. Used
  73. * for flash array reads, etc.
  74. */
  75. int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
  76. size_t cmd_len, void *data, size_t data_len);
  77. /*
  78. * Send a multi-byte command to the device followed by (optional)
  79. * data. Used for programming the flash array, etc.
  80. */
  81. int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
  82. const void *data, size_t data_len);
  83. /* Flash erase(sectors) operation, support all possible erase commands */
  84. int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len);
  85. /* Read the status register */
  86. int spi_flash_cmd_read_status(struct spi_flash *flash, u8 *rs);
  87. /* Program the status register */
  88. int spi_flash_cmd_write_status(struct spi_flash *flash, u8 ws);
  89. /* Read the config register */
  90. int spi_flash_cmd_read_config(struct spi_flash *flash, u8 *rc);
  91. /* Program the config register */
  92. int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc);
  93. /* Enable writing on the SPI flash */
  94. static inline int spi_flash_cmd_write_enable(struct spi_flash *flash)
  95. {
  96. return spi_flash_cmd(flash->spi, CMD_WRITE_ENABLE, NULL, 0);
  97. }
  98. /* Disable writing on the SPI flash */
  99. static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)
  100. {
  101. return spi_flash_cmd(flash->spi, CMD_WRITE_DISABLE, NULL, 0);
  102. }
  103. /*
  104. * Send the read status command to the device and wait for the wip
  105. * (write-in-progress) bit to clear itself.
  106. */
  107. int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
  108. /*
  109. * Used for spi_flash write operation
  110. * - SPI claim
  111. * - spi_flash_cmd_write_enable
  112. * - spi_flash_cmd_write
  113. * - spi_flash_cmd_wait_ready
  114. * - SPI release
  115. */
  116. int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
  117. size_t cmd_len, const void *buf, size_t buf_len);
  118. /*
  119. * Flash write operation, support all possible write commands.
  120. * Write the requested data out breaking it up into multiple write
  121. * commands as needed per the write size.
  122. */
  123. int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
  124. size_t len, const void *buf);
  125. /*
  126. * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  127. * bus. Used as common part of the ->read() operation.
  128. */
  129. int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
  130. size_t cmd_len, void *data, size_t data_len);
  131. /* Flash read operation, support all possible read commands */
  132. int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
  133. size_t len, void *data);
  134. #endif /* _SF_INTERNAL_H_ */