m29f400bt.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2000 Silicon Integrated System Corporation
  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. #include "flash.h"
  21. #include "chipdrivers.h"
  22. /* WARNING!
  23. This chip uses the standard JEDEC Addresses in 16-bit mode as word
  24. addresses. In byte mode, 0xAAA has to be used instead of 0x555 and
  25. 0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC
  26. functions. */
  27. /* chunksize is 1 */
  28. int write_m29f400bt(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len)
  29. {
  30. int i;
  31. chipaddr bios = flash->virtual_memory;
  32. chipaddr dst = flash->virtual_memory + start;
  33. for (i = 0; i < len; i++) {
  34. chip_writeb(flash, 0xAA, bios + 0xAAA);
  35. chip_writeb(flash, 0x55, bios + 0x555);
  36. chip_writeb(flash, 0xA0, bios + 0xAAA);
  37. /* transfer data from source to destination */
  38. chip_writeb(flash, *src, dst);
  39. toggle_ready_jedec(flash, dst);
  40. #if 0
  41. /* We only want to print something in the error case. */
  42. msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",
  43. (dst - bios), chip_readb(flash, dst), *src);
  44. #endif
  45. dst++;
  46. src++;
  47. }
  48. /* FIXME: Ignore errors for now. */
  49. return 0;
  50. }
  51. int probe_m29f400bt(struct flashctx *flash)
  52. {
  53. chipaddr bios = flash->virtual_memory;
  54. uint8_t id1, id2;
  55. chip_writeb(flash, 0xAA, bios + 0xAAA);
  56. chip_writeb(flash, 0x55, bios + 0x555);
  57. chip_writeb(flash, 0x90, bios + 0xAAA);
  58. programmer_delay(10);
  59. id1 = chip_readb(flash, bios);
  60. /* The data sheet says id2 is at (bios + 0x01) and id2 listed in
  61. * flash.h does not match. It should be possible to use JEDEC probe.
  62. */
  63. id2 = chip_readb(flash, bios + 0x02);
  64. chip_writeb(flash, 0xAA, bios + 0xAAA);
  65. chip_writeb(flash, 0x55, bios + 0x555);
  66. chip_writeb(flash, 0xF0, bios + 0xAAA);
  67. programmer_delay(10);
  68. msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2);
  69. if (id1 == flash->manufacture_id && id2 == flash->model_id)
  70. return 1;
  71. return 0;
  72. }
  73. int erase_m29f400bt(struct flashctx *flash)
  74. {
  75. chipaddr bios = flash->virtual_memory;
  76. chip_writeb(flash, 0xAA, bios + 0xAAA);
  77. chip_writeb(flash, 0x55, bios + 0x555);
  78. chip_writeb(flash, 0x80, bios + 0xAAA);
  79. chip_writeb(flash, 0xAA, bios + 0xAAA);
  80. chip_writeb(flash, 0x55, bios + 0x555);
  81. chip_writeb(flash, 0x10, bios + 0xAAA);
  82. programmer_delay(10);
  83. toggle_ready_jedec(flash, bios);
  84. /* FIXME: Check the status register for errors. */
  85. return 0;
  86. }
  87. int block_erase_m29f400bt(struct flashctx *flash, unsigned int start, unsigned int len)
  88. {
  89. chipaddr bios = flash->virtual_memory;
  90. chipaddr dst = bios + start;
  91. chip_writeb(flash, 0xAA, bios + 0xAAA);
  92. chip_writeb(flash, 0x55, bios + 0x555);
  93. chip_writeb(flash, 0x80, bios + 0xAAA);
  94. chip_writeb(flash, 0xAA, bios + 0xAAA);
  95. chip_writeb(flash, 0x55, bios + 0x555);
  96. chip_writeb(flash, 0x30, dst);
  97. programmer_delay(10);
  98. toggle_ready_jedec(flash, bios);
  99. /* FIXME: Check the status register for errors. */
  100. return 0;
  101. }
  102. int block_erase_chip_m29f400bt(struct flashctx *flash, unsigned int address, unsigned int blocklen)
  103. {
  104. if ((address != 0) || (blocklen != flash->total_size * 1024)) {
  105. msg_cerr("%s called with incorrect arguments\n",
  106. __func__);
  107. return -1;
  108. }
  109. return erase_m29f400bt(flash);
  110. }