sf_internal.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * SPI flash internal definitions
  3. *
  4. * Copyright (C) 2008 Atmel Corporation
  5. * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc.
  6. *
  7. * Licensed under the GPL-2 or later.
  8. */
  9. #ifndef _SPI_FLASH_INTERNAL_H_
  10. #define _SPI_FLASH_INTERNAL_H_
  11. #define SPI_FLASH_16MB_BOUN 0x1000000
  12. /* SECT flags */
  13. #define SECT_4K (1 << 1)
  14. #define SECT_32K (1 << 2)
  15. #define E_FSR (1 << 3)
  16. /* Erase commands */
  17. #define CMD_ERASE_4K 0x20
  18. #define CMD_ERASE_32K 0x52
  19. #define CMD_ERASE_CHIP 0xc7
  20. #define CMD_ERASE_64K 0xd8
  21. /* Write commands */
  22. #define CMD_WRITE_STATUS 0x01
  23. #define CMD_PAGE_PROGRAM 0x02
  24. #define CMD_WRITE_DISABLE 0x04
  25. #define CMD_READ_STATUS 0x05
  26. #define CMD_WRITE_ENABLE 0x06
  27. #define CMD_READ_CONFIG 0x35
  28. #define CMD_FLAG_STATUS 0x70
  29. /* Read commands */
  30. #define CMD_READ_ARRAY_SLOW 0x03
  31. #define CMD_READ_ARRAY_FAST 0x0b
  32. #define CMD_READ_ID 0x9f
  33. /* Bank addr access commands */
  34. #ifdef CONFIG_SPI_FLASH_BAR
  35. # define CMD_BANKADDR_BRWR 0x17
  36. # define CMD_BANKADDR_BRRD 0x16
  37. # define CMD_EXTNADDR_WREAR 0xC5
  38. # define CMD_EXTNADDR_RDEAR 0xC8
  39. #endif
  40. /* Common status */
  41. #define STATUS_WIP 0x01
  42. #define STATUS_PEC 0x80
  43. /* Flash timeout values */
  44. #define SPI_FLASH_PROG_TIMEOUT (2 * CONFIG_SYS_HZ)
  45. #define SPI_FLASH_PAGE_ERASE_TIMEOUT (5 * CONFIG_SYS_HZ)
  46. #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
  47. /* SST specific */
  48. #ifdef CONFIG_SPI_FLASH_SST
  49. # define SST_WP 0x01 /* Supports AAI word program */
  50. # define CMD_SST_BP 0x02 /* Byte Program */
  51. # define CMD_SST_AAI_WP 0xAD /* Auto Address Incr Word Program */
  52. int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
  53. const void *buf);
  54. #endif
  55. /* Send a single-byte command to the device and read the response */
  56. int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);
  57. /*
  58. * Send a multi-byte command to the device and read the response. Used
  59. * for flash array reads, etc.
  60. */
  61. int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
  62. size_t cmd_len, void *data, size_t data_len);
  63. /*
  64. * Send a multi-byte command to the device followed by (optional)
  65. * data. Used for programming the flash array, etc.
  66. */
  67. int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
  68. const void *data, size_t data_len);
  69. /* Flash erase(sectors) operation, support all possible erase commands */
  70. int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len);
  71. /* Program the status register */
  72. int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
  73. /* Set quad enbale bit */
  74. int spi_flash_set_qeb(struct spi_flash *flash);
  75. /* Enable writing on the SPI flash */
  76. static inline int spi_flash_cmd_write_enable(struct spi_flash *flash)
  77. {
  78. return spi_flash_cmd(flash->spi, CMD_WRITE_ENABLE, NULL, 0);
  79. }
  80. /* Disable writing on the SPI flash */
  81. static inline int spi_flash_cmd_write_disable(struct spi_flash *flash)
  82. {
  83. return spi_flash_cmd(flash->spi, CMD_WRITE_DISABLE, NULL, 0);
  84. }
  85. /*
  86. * Send the read status command to the device and wait for the wip
  87. * (write-in-progress) bit to clear itself.
  88. */
  89. int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
  90. /*
  91. * Used for spi_flash write operation
  92. * - SPI claim
  93. * - spi_flash_cmd_write_enable
  94. * - spi_flash_cmd_write
  95. * - spi_flash_cmd_wait_ready
  96. * - SPI release
  97. */
  98. int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
  99. size_t cmd_len, const void *buf, size_t buf_len);
  100. /*
  101. * Flash write operation, support all possible write commands.
  102. * Write the requested data out breaking it up into multiple write
  103. * commands as needed per the write size.
  104. */
  105. int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
  106. size_t len, const void *buf);
  107. /*
  108. * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  109. * bus. Used as common part of the ->read() operation.
  110. */
  111. int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
  112. size_t cmd_len, void *data, size_t data_len);
  113. /* Flash read operation, support all possible read commands */
  114. int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
  115. size_t len, void *data);
  116. #endif /* _SPI_FLASH_INTERNAL_H_ */