en29lv640b.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2000 Silicon Integrated System Corporation
  5. * Copyright (C) 2012 Rudolf Marek <r.marek@assembler.cz>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "flash.h"
  22. #include "chipdrivers.h"
  23. /*
  24. * WARNING!
  25. * This chip uses the standard JEDEC addresses in 16-bit mode as word
  26. * addresses. In byte mode, 0xAAA has to be used instead of 0x555 and
  27. * 0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC
  28. * functions.
  29. */
  30. /* chunksize is 1 */
  31. int write_en29lv640b(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
  32. {
  33. int i;
  34. chipaddr bios = flash->virtual_memory;
  35. chipaddr dst = flash->virtual_memory + start;
  36. for (i = 0; i < len; i += 2) {
  37. chip_writeb(flash, 0xAA, bios + 0xAAA);
  38. chip_writeb(flash, 0x55, bios + 0x555);
  39. chip_writeb(flash, 0xA0, bios + 0xAAA);
  40. /* Transfer data from source to destination. */
  41. chip_writew(flash, (*src) | ((*(src + 1)) << 8 ), dst);
  42. toggle_ready_jedec(flash, dst);
  43. #if 0
  44. /* We only want to print something in the error case. */
  45. msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",
  46. (dst - bios), chip_readb(flash, dst), *src);
  47. #endif
  48. dst += 2;
  49. src += 2;
  50. }
  51. /* FIXME: Ignore errors for now. */
  52. return 0;
  53. }
  54. int probe_en29lv640b(struct flashctx *flash)
  55. {
  56. chipaddr bios = flash->virtual_memory;
  57. uint16_t id1, id2;
  58. chip_writeb(flash, 0xAA, bios + 0xAAA);
  59. chip_writeb(flash, 0x55, bios + 0x555);
  60. chip_writeb(flash, 0x90, bios + 0xAAA);
  61. programmer_delay(10);
  62. id1 = chip_readb(flash, bios + 0x200);
  63. id1 |= (chip_readb(flash, bios) << 8);
  64. id2 = chip_readb(flash, bios + 0x02);
  65. chip_writeb(flash, 0xF0, bios + 0xAAA);
  66. programmer_delay(10);
  67. msg_cdbg("%s: id1 0x%04x, id2 0x%04x\n", __func__, id1, id2);
  68. if (id1 == flash->chip->manufacture_id && id2 == flash->chip->model_id)
  69. return 1;
  70. return 0;
  71. }