spi4ba.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2014 Boris Baykov
  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; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /*
  21. * JEDEC flash chips instructions for 4-bytes addressing
  22. * SPI chip driver functions for 4-bytes addressing
  23. */
  24. #ifndef __SPI_4BA_H__
  25. #define __SPI_4BA_H__ 1
  26. /* Enter 4-byte Address Mode */
  27. #define JEDEC_ENTER_4_BYTE_ADDR_MODE 0xB7
  28. #define JEDEC_ENTER_4_BYTE_ADDR_MODE_OUTSIZE 0x01
  29. #define JEDEC_ENTER_4_BYTE_ADDR_MODE_INSIZE 0x00
  30. /* Exit 4-byte Address Mode */
  31. #define JEDEC_EXIT_4_BYTE_ADDR_MODE 0xE9
  32. #define JEDEC_EXIT_4_BYTE_ADDR_MODE_OUTSIZE 0x01
  33. #define JEDEC_EXIT_4_BYTE_ADDR_MODE_INSIZE 0x00
  34. /* Write Extended Address Register */
  35. #define JEDEC_WRITE_EXT_ADDR_REG 0xC5
  36. #define JEDEC_WRITE_EXT_ADDR_REG_OUTSIZE 0x02
  37. #define JEDEC_WRITE_EXT_ADDR_REG_INSIZE 0x00
  38. /* Read Extended Address Register */
  39. #define JEDEC_READ_EXT_ADDR_REG 0xC8
  40. #define JEDEC_READ_EXT_ADDR_REG_OUTSIZE 0x01
  41. #define JEDEC_READ_EXT_ADDR_REG_INSIZE 0x01
  42. /* Read the memory with 4-byte address
  43. From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */
  44. #define JEDEC_READ_4BA 0x13
  45. #define JEDEC_READ_4BA_OUTSIZE 0x05
  46. /* JEDEC_READ_4BA_INSIZE : any length */
  47. /* Write memory byte with 4-byte address
  48. From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */
  49. #define JEDEC_BYTE_PROGRAM_4BA 0x12
  50. #define JEDEC_BYTE_PROGRAM_4BA_OUTSIZE 0x06
  51. #define JEDEC_BYTE_PROGRAM_4BA_INSIZE 0x00
  52. /* Sector Erase 0x21 (with 4-byte address), usually 4k size.
  53. From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */
  54. #define JEDEC_SE_4BA 0x21
  55. #define JEDEC_SE_4BA_OUTSIZE 0x05
  56. #define JEDEC_SE_4BA_INSIZE 0x00
  57. /* Block Erase 0x5C (with 4-byte address), usually 32k size.
  58. From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */
  59. #define JEDEC_BE_5C_4BA 0x5C
  60. #define JEDEC_BE_5C_4BA_OUTSIZE 0x05
  61. #define JEDEC_BE_5C_4BA_INSIZE 0x00
  62. /* Block Erase 0xDC (with 4-byte address), usually 64k size.
  63. From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */
  64. #define JEDEC_BE_DC_4BA 0xdc
  65. #define JEDEC_BE_DC_4BA_OUTSIZE 0x05
  66. #define JEDEC_BE_DC_4BA_INSIZE 0x00
  67. /* enter 4-bytes addressing mode */
  68. int spi_enter_4ba_b7(struct flashctx *flash);
  69. int spi_enter_4ba_b7_we(struct flashctx *flash);
  70. /* read/write flash bytes in 4-bytes addressing mode */
  71. int spi_byte_program_4ba(struct flashctx *flash, unsigned int addr, uint8_t databyte);
  72. int spi_nbyte_program_4ba(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len);
  73. int spi_nbyte_read_4ba(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len);
  74. /* erase flash bytes in 4-bytes addressing mode */
  75. int spi_block_erase_20_4ba(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  76. int spi_block_erase_52_4ba(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  77. int spi_block_erase_d8_4ba(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  78. /* read/write flash bytes from 3-bytes addressing mode using extended address register */
  79. int spi_byte_program_4ba_ereg(struct flashctx *flash, unsigned int addr, uint8_t databyte);
  80. int spi_nbyte_program_4ba_ereg(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len);
  81. int spi_nbyte_read_4ba_ereg(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len);
  82. /* erase flash bytes from 3-bytes addressing mode using extended address register */
  83. int spi_block_erase_20_4ba_ereg(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  84. int spi_block_erase_52_4ba_ereg(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  85. int spi_block_erase_d8_4ba_ereg(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  86. /* read/write flash bytes with 4-bytes address from any mode (3-byte or 4-byte) */
  87. int spi_byte_program_4ba_direct(struct flashctx *flash, unsigned int addr, uint8_t databyte);
  88. int spi_nbyte_program_4ba_direct(struct flashctx *flash, unsigned int addr, const uint8_t *bytes, unsigned int len);
  89. int spi_nbyte_read_4ba_direct(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len);
  90. /* erase flash bytes with 4-bytes address from any mode (3-byte or 4-byte) */
  91. int spi_block_erase_21_4ba_direct(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  92. int spi_block_erase_5c_4ba_direct(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  93. int spi_block_erase_dc_4ba_direct(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
  94. #endif /* __SPI_4BA_H__ */