sst28sf040.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2000 Silicon Integrated System Corporation
  5. * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org>
  6. * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "flash.h"
  23. #include "chipdrivers.h"
  24. #define AUTO_PG_ERASE1 0x20
  25. #define AUTO_PG_ERASE2 0xD0
  26. #define AUTO_PGRM 0x10
  27. #define CHIP_ERASE 0x30
  28. #define RESET 0xFF
  29. #define READ_ID 0x90
  30. int protect_28sf040(struct flashctx *flash)
  31. {
  32. chipaddr bios = flash->virtual_memory;
  33. chip_readb(flash, bios + 0x1823);
  34. chip_readb(flash, bios + 0x1820);
  35. chip_readb(flash, bios + 0x1822);
  36. chip_readb(flash, bios + 0x0418);
  37. chip_readb(flash, bios + 0x041B);
  38. chip_readb(flash, bios + 0x0419);
  39. chip_readb(flash, bios + 0x040A);
  40. return 0;
  41. }
  42. int unprotect_28sf040(struct flashctx *flash)
  43. {
  44. chipaddr bios = flash->virtual_memory;
  45. chip_readb(flash, bios + 0x1823);
  46. chip_readb(flash, bios + 0x1820);
  47. chip_readb(flash, bios + 0x1822);
  48. chip_readb(flash, bios + 0x0418);
  49. chip_readb(flash, bios + 0x041B);
  50. chip_readb(flash, bios + 0x0419);
  51. chip_readb(flash, bios + 0x041A);
  52. return 0;
  53. }
  54. int erase_sector_28sf040(struct flashctx *flash, unsigned int address,
  55. unsigned int sector_size)
  56. {
  57. chipaddr bios = flash->virtual_memory;
  58. /* This command sequence is very similar to erase_block_82802ab. */
  59. chip_writeb(flash, AUTO_PG_ERASE1, bios);
  60. chip_writeb(flash, AUTO_PG_ERASE2, bios + address);
  61. /* wait for Toggle bit ready */
  62. toggle_ready_jedec(flash, bios);
  63. /* FIXME: Check the status register for errors. */
  64. return 0;
  65. }
  66. /* chunksize is 1 */
  67. int write_28sf040(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
  68. {
  69. int i;
  70. chipaddr bios = flash->virtual_memory;
  71. chipaddr dst = flash->virtual_memory + start;
  72. for (i = 0; i < len; i++) {
  73. /* transfer data from source to destination */
  74. if (*src == 0xFF) {
  75. dst++, src++;
  76. /* If the data is 0xFF, don't program it */
  77. continue;
  78. }
  79. /*issue AUTO PROGRAM command */
  80. chip_writeb(flash, AUTO_PGRM, dst);
  81. chip_writeb(flash, *src++, dst++);
  82. /* wait for Toggle bit ready */
  83. toggle_ready_jedec(flash, bios);
  84. }
  85. return 0;
  86. }
  87. static int erase_28sf040(struct flashctx *flash)
  88. {
  89. chipaddr bios = flash->virtual_memory;
  90. chip_writeb(flash, CHIP_ERASE, bios);
  91. chip_writeb(flash, CHIP_ERASE, bios);
  92. programmer_delay(10);
  93. toggle_ready_jedec(flash, bios);
  94. /* FIXME: Check the status register for errors. */
  95. return 0;
  96. }
  97. int erase_chip_28sf040(struct flashctx *flash, unsigned int addr,
  98. unsigned int blocklen)
  99. {
  100. if ((addr != 0) || (blocklen != flash->chip->total_size * 1024)) {
  101. msg_cerr("%s called with incorrect arguments\n",
  102. __func__);
  103. return -1;
  104. }
  105. return erase_28sf040(flash);
  106. }