spi.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2007, 2008 Carl-Daniel Hailfinger
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef __SPI_H__
  20. #define __SPI_H__ 1
  21. /*
  22. * Contains the generic SPI headers
  23. */
  24. /* Read Electronic ID */
  25. #define JEDEC_RDID 0x9f
  26. #define JEDEC_RDID_OUTSIZE 0x01
  27. /* INSIZE may be 0x04 for some chips*/
  28. #define JEDEC_RDID_INSIZE 0x03
  29. /* AT25F512A has bit 3 as don't care bit in commands */
  30. #define AT25F512A_RDID 0x15 /* 0x15 or 0x1d */
  31. #define AT25F512A_RDID_OUTSIZE 0x01
  32. #define AT25F512A_RDID_INSIZE 0x02
  33. /* Read Electronic Manufacturer Signature */
  34. #define JEDEC_REMS 0x90
  35. #define JEDEC_REMS_OUTSIZE 0x04
  36. #define JEDEC_REMS_INSIZE 0x02
  37. /* Read Electronic Signature */
  38. #define JEDEC_RES 0xab
  39. #define JEDEC_RES_OUTSIZE 0x04
  40. /* INSIZE may be 0x02 for some chips*/
  41. #define JEDEC_RES_INSIZE 0x01
  42. /* Write Enable */
  43. #define JEDEC_WREN 0x06
  44. #define JEDEC_WREN_OUTSIZE 0x01
  45. #define JEDEC_WREN_INSIZE 0x00
  46. /* Write Disable */
  47. #define JEDEC_WRDI 0x04
  48. #define JEDEC_WRDI_OUTSIZE 0x01
  49. #define JEDEC_WRDI_INSIZE 0x00
  50. /* Chip Erase 0x60 is supported by Macronix/SST chips. */
  51. #define JEDEC_CE_60 0x60
  52. #define JEDEC_CE_60_OUTSIZE 0x01
  53. #define JEDEC_CE_60_INSIZE 0x00
  54. /* Chip Erase 0xc7 is supported by SST/ST/EON/Macronix chips. */
  55. #define JEDEC_CE_C7 0xc7
  56. #define JEDEC_CE_C7_OUTSIZE 0x01
  57. #define JEDEC_CE_C7_INSIZE 0x00
  58. /* Block Erase 0x52 is supported by SST and old Atmel chips. */
  59. #define JEDEC_BE_52 0x52
  60. #define JEDEC_BE_52_OUTSIZE 0x04
  61. #define JEDEC_BE_52_INSIZE 0x00
  62. /* Block Erase 0xd8 is supported by EON/Macronix chips. */
  63. #define JEDEC_BE_D8 0xd8
  64. #define JEDEC_BE_D8_OUTSIZE 0x04
  65. #define JEDEC_BE_D8_INSIZE 0x00
  66. /* Block Erase 0xd7 is supported by PMC chips. */
  67. #define JEDEC_BE_D7 0xd7
  68. #define JEDEC_BE_D7_OUTSIZE 0x04
  69. #define JEDEC_BE_D7_INSIZE 0x00
  70. /* Block Erase 0xdc is supported by Spansion chips, takes 4 byte address */
  71. #define JEDEC_BE_DC 0xdc
  72. #define JEDEC_BE_DC_OUTSIZE 0x05
  73. #define JEDEC_BE_DC_INSIZE 0x00
  74. /* Sector Erase 0x20 is supported by Macronix/SST chips. */
  75. #define JEDEC_SE 0x20
  76. #define JEDEC_SE_OUTSIZE 0x04
  77. #define JEDEC_SE_INSIZE 0x00
  78. /* Read Status Register */
  79. #define JEDEC_RDSR 0x05
  80. #define JEDEC_RDSR_OUTSIZE 0x01
  81. #define JEDEC_RDSR_INSIZE 0x01
  82. #define JEDEC_RDSR_BIT_WIP (0x01 << 0)
  83. #define JEDEC_RDSR_BIT_ERASE_ERR (0x01 << 5)
  84. /* Write Status Enable */
  85. #define JEDEC_EWSR 0x50
  86. #define JEDEC_EWSR_OUTSIZE 0x01
  87. #define JEDEC_EWSR_INSIZE 0x00
  88. /* Write Status Register */
  89. #define JEDEC_WRSR 0x01
  90. #define JEDEC_WRSR_OUTSIZE 0x02
  91. #define JEDEC_WRSR_INSIZE 0x00
  92. /* Read the memory */
  93. #define JEDEC_READ 0x03
  94. #define JEDEC_READ_OUTSIZE 0x04
  95. /* JEDEC_READ_INSIZE : any length */
  96. /* Write memory byte */
  97. #define JEDEC_BYTE_PROGRAM 0x02
  98. #define JEDEC_BYTE_PROGRAM_OUTSIZE 0x05
  99. #define JEDEC_BYTE_PROGRAM_INSIZE 0x00
  100. /* Write AAI word (SST25VF080B) */
  101. #define JEDEC_AAI_WORD_PROGRAM 0xad
  102. #define JEDEC_AAI_WORD_PROGRAM_OUTSIZE 0x06
  103. #define JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE 0x03
  104. #define JEDEC_AAI_WORD_PROGRAM_INSIZE 0x00
  105. /* Error codes */
  106. #define SPI_GENERIC_ERROR -1
  107. #define SPI_INVALID_OPCODE -2
  108. #define SPI_INVALID_ADDRESS -3
  109. #define SPI_INVALID_LENGTH -4
  110. #define SPI_FLASHROM_BUG -5
  111. #define SPI_PROGRAMMER_ERROR -6
  112. #define SPI_ACCESS_DENIED -7
  113. void clear_spi_id_cache(void);
  114. #endif /* !__SPI_H__ */