programmer.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2009,2010,2011 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; 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 "programmer.h"
  22. static const struct par_programmer par_programmer_none = {
  23. .chip_readb = noop_chip_readb,
  24. .chip_readw = fallback_chip_readw,
  25. .chip_readl = fallback_chip_readl,
  26. .chip_readn = fallback_chip_readn,
  27. .chip_writeb = noop_chip_writeb,
  28. .chip_writew = fallback_chip_writew,
  29. .chip_writel = fallback_chip_writel,
  30. .chip_writen = fallback_chip_writen,
  31. };
  32. const struct par_programmer *par_programmer = &par_programmer_none;
  33. /* No-op shutdown() for programmers which don't need special handling */
  34. int noop_shutdown(void)
  35. {
  36. return 0;
  37. }
  38. /* Fallback map() for programmers which don't need special handling */
  39. void *fallback_map(const char *descr, unsigned long phys_addr, size_t len)
  40. {
  41. /* FIXME: Should return phys_addr. */
  42. return NULL;
  43. }
  44. /* No-op/fallback unmap() for programmers which don't need special handling */
  45. void fallback_unmap(void *virt_addr, size_t len)
  46. {
  47. }
  48. /* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
  49. uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr)
  50. {
  51. return 0xff;
  52. }
  53. /* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
  54. void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
  55. {
  56. }
  57. /* Little-endian fallback for drivers not supporting 16 bit accesses */
  58. void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
  59. {
  60. chip_writeb(flash, val & 0xff, addr);
  61. chip_writeb(flash, (val >> 8) & 0xff, addr + 1);
  62. }
  63. /* Little-endian fallback for drivers not supporting 16 bit accesses */
  64. uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr)
  65. {
  66. uint16_t val;
  67. val = chip_readb(flash, addr);
  68. val |= chip_readb(flash, addr + 1) << 8;
  69. return val;
  70. }
  71. /* Little-endian fallback for drivers not supporting 32 bit accesses */
  72. void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
  73. {
  74. chip_writew(flash, val & 0xffff, addr);
  75. chip_writew(flash, (val >> 16) & 0xffff, addr + 2);
  76. }
  77. /* Little-endian fallback for drivers not supporting 32 bit accesses */
  78. uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr)
  79. {
  80. uint32_t val;
  81. val = chip_readw(flash, addr);
  82. val |= chip_readw(flash, addr + 2) << 16;
  83. return val;
  84. }
  85. void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
  86. {
  87. size_t i;
  88. for (i = 0; i < len; i++)
  89. chip_writeb(flash, buf[i], addr + i);
  90. return;
  91. }
  92. void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
  93. {
  94. size_t i;
  95. for (i = 0; i < len; i++)
  96. buf[i] = chip_readb(flash, addr + i);
  97. return;
  98. }
  99. void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses)
  100. {
  101. par_programmer = pgm;
  102. buses_supported |= buses;
  103. }
  104. struct programmer_alias aliases[] = {
  105. { "ec", ALIAS_EC },
  106. { "host", ALIAS_HOST },
  107. { NULL },
  108. };
  109. struct programmer_alias *alias;