spi_flash_internal.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * SPI flash internal definitions
  3. *
  4. * Copyright (C) 2008 Atmel Corporation
  5. */
  6. /* Common parameters -- kind of high, but they should only occur when there
  7. * is a problem (and well your system already is broken), so err on the side
  8. * of caution in case we're dealing with slower SPI buses and/or processors.
  9. */
  10. #ifndef __SPI_FLASH_INTERNAL_H_
  11. #define __SPI_FLASH_INTERNAL_H_
  12. #include <comdef.h>
  13. #define CONFIG_SYS_HZ 12000000
  14. #define SPI_FLASH_PROG_TIMEOUT (2 * CONFIG_SYS_HZ)
  15. #define SPI_FLASH_PAGE_ERASE_TIMEOUT (5 * CONFIG_SYS_HZ)
  16. #define SPI_FLASH_SECTOR_ERASE_TIMEOUT (10 * CONFIG_SYS_HZ)
  17. /* Common commands */
  18. #define CMD_READ_ARRAY_SLOW 0x03 /* Read Data Bytes */
  19. #define CMD_READ_ARRAY_FAST 0x0B
  20. #define CMD_READ_ARRAY_DUAL 0x3B
  21. #define CMD_READ_ARRAY_QUAD 0X6B
  22. #define CMD_READ_ARRAY_LEGACY 0xEB
  23. #define CMD_WRITE_STATUS 0x01 /* Write Status Register */
  24. #define CMD_WRITE_STATUS_1 0x01 /* Write Status Register */
  25. #define CMD_WRITE_STATUS_2 0x31 /* Write Status Register */
  26. #define CMD_WRITE_STATUS_3 0x11 /* Write Status Register */
  27. #define CMD_READ_STATUS_1 0x05 /* Read Status Register */
  28. #define CMD_READ_STATUS_2 0x35 /* Read Status Register */
  29. #define CMD_READ_STATUS_3 0x15 /* Read Status Register */
  30. #define CMD_PAGE_PROGRAM 0x02 /* Page Program */
  31. #define CMD_PAGE_PROGRAM_QUAD 0x32
  32. #define CMD_WRITE_DISABLE 0x04 /* Write Disable */
  33. #define CMD_READ_STATUS 0x05 /* Read Status Register */
  34. #define CMD_READ_STATUS1 0x35
  35. #define CMD_WRITE_ENABLE 0x06 /* Write Enable */
  36. #define CMD_W25_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
  37. #define CMD_W25_SE 0x20 /* Sector (4K) Erase */
  38. #define CMD_W25_BE 0xd8 /* Block (64K) Erase */
  39. #define CMD_W25_CE 0xc7 /* Chip Erase */
  40. #define CMD_W25_DP 0xb9 /* Deep Power-down */
  41. #define CMD_W25_RES 0xab /* Release from DP, and Read Signature */
  42. #define CMD_W25_BE_32 0x52 /* Sector (32K) Erase */
  43. #define CMD_STATUS_ENABLE 0x50
  44. /* Common status */
  45. #define STATUS_WIP 0x01
  46. #define FLASH_ENABLE 0x02
  47. #define STATUS_QE (0x01 << 1)
  48. /* Send a single-byte command to the device and read the response */
  49. int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, u32 len);
  50. /*
  51. * Send a multi-byte command to the device and read the response. Used
  52. * for flash array reads, etc.
  53. */
  54. int spi_flash_cmd_read(struct spi_slave *spi, u8 *cmd,u32 cmd_len,
  55. void *data, u32 data_len);
  56. int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
  57. u32 len, void *data, u32 mode);
  58. int spi_flash_read_mode(struct spi_flash *flash, u32 offset,
  59. u32 len, void *data, u32 mode);
  60. /*
  61. * Send a multi-byte command to the device followed by (optional)
  62. * data. Used for programming the flash array, etc.
  63. */
  64. int spi_flash_cmd_write(struct spi_slave *spi, u8 *cmd, u32 cmd_len,
  65. void *data, u32 data_len);
  66. /*
  67. * Write the requested data out breaking it up into multiple write
  68. * commands as needed per the write size.
  69. */
  70. int spi_flash_cmd_write_mode(struct spi_flash *flash, u32 offset,
  71. u32 len, void *buf, u32 mode);
  72. /*
  73. * Enable writing on the SPI flash.
  74. */
  75. int spi_flash_cmd_write_enable(struct spi_flash *flash);
  76. /*
  77. * Disable writing on the SPI flash.
  78. */
  79. int spi_flash_cmd_write_disable(struct spi_slave *spi);
  80. /*
  81. * Same as spi_flash_cmd_read() except it also claims/releases the SPI
  82. * bus. Used as common part of the ->read() operation.
  83. */
  84. int spi_flash_read_common(struct spi_flash *flash, u8 *cmd,
  85. u32 cmd_len, void *data, u32 data_len);
  86. /* Send a command to the device and wait for some bit to clear itself. */
  87. int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
  88. u8 cmd, u8 poll_bit);
  89. /*
  90. * Send the read status command to the device and wait for the wip
  91. * (write-in-progress) bit to clear itself.
  92. */
  93. int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
  94. /* Erase sectors. */
  95. int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd, u32 offset, u32 len);
  96. int spi_flash_erase_mode(struct spi_flash *flash, u32 offset, u32 len, u32 mode);
  97. /* Manufacturer-specific probe functions */
  98. struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode);
  99. struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode);
  100. struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode);
  101. struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode);
  102. struct spi_flash *spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode);
  103. struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 *idcode);
  104. struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode);
  105. struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode);
  106. struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode);
  107. struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
  108. unsigned int max_hz, u32 mode, u32 fifo_width);
  109. #endif