ddr_spd.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * Version 2 as published by the Free Software Foundation.
  7. */
  8. #include <common.h>
  9. #include <ddr_spd.h>
  10. /* used for ddr1 and ddr2 spd */
  11. static int
  12. spd_check(const u8 *buf, u8 spd_rev, u8 spd_cksum)
  13. {
  14. unsigned int cksum = 0;
  15. unsigned int i;
  16. /*
  17. * Check SPD revision supported
  18. * Rev 1.2 or less supported by this code
  19. */
  20. if (spd_rev > 0x12) {
  21. printf("SPD revision %02X not supported by this code\n",
  22. spd_rev);
  23. return 1;
  24. }
  25. /*
  26. * Calculate checksum
  27. */
  28. for (i = 0; i < 63; i++) {
  29. cksum += *buf++;
  30. }
  31. cksum &= 0xFF;
  32. if (cksum != spd_cksum) {
  33. printf("SPD checksum unexpected. "
  34. "Checksum in SPD = %02X, computed SPD = %02X\n",
  35. spd_cksum, cksum);
  36. return 1;
  37. }
  38. return 0;
  39. }
  40. unsigned int
  41. ddr1_spd_check(const ddr1_spd_eeprom_t *spd)
  42. {
  43. const u8 *p = (const u8 *)spd;
  44. return spd_check(p, spd->spd_rev, spd->cksum);
  45. }
  46. unsigned int
  47. ddr2_spd_check(const ddr2_spd_eeprom_t *spd)
  48. {
  49. const u8 *p = (const u8 *)spd;
  50. return spd_check(p, spd->spd_rev, spd->cksum);
  51. }