From 0f2cbe3f5eddbdf3848265f35e4f714434929cff Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 26 Aug 2008 15:01:27 -0500 Subject: Add proper SPD definitions for DDR1/2/3 Also adds helper functions for DDR1/2 to verify the checksum. Signed-off-by: Kumar Gala --- common/ddr_spd.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 common/ddr_spd.c (limited to 'common/ddr_spd.c') diff --git a/common/ddr_spd.c b/common/ddr_spd.c new file mode 100644 index 0000000000..78e3c5d9f2 --- /dev/null +++ b/common/ddr_spd.c @@ -0,0 +1,61 @@ +/* + * Copyright 2008 Freescale Semiconductor, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * Version 2 as published by the Free Software Foundation. + */ + +#include +#include + +/* used for ddr1 and ddr2 spd */ +static int +spd_check(const u8 *buf, u8 spd_rev, u8 spd_cksum) +{ + unsigned int cksum = 0; + unsigned int i; + + /* + * Check SPD revision supported + * Rev 1.2 or less supported by this code + */ + if (spd_rev > 0x12) { + printf("SPD revision %02X not supported by this code\n", + spd_rev); + return 1; + } + + /* + * Calculate checksum + */ + for (i = 0; i < 63; i++) { + cksum += *buf++; + } + cksum &= 0xFF; + + if (cksum != spd_cksum) { + printf("SPD checksum unexpected. " + "Checksum in SPD = %02X, computed SPD = %02X\n", + spd_cksum, cksum); + return 1; + } + + return 0; +} + +unsigned int +ddr1_spd_check(const ddr1_spd_eeprom_t *spd) +{ + const u8 *p = (const u8 *)spd; + + return spd_check(p, spd->spd_rev, spd->cksum); +} + +unsigned int +ddr2_spd_check(const ddr2_spd_eeprom_t *spd) +{ + const u8 *p = (const u8 *)spd; + + return spd_check(p, spd->spd_rev, spd->cksum); +} -- cgit v1.2.1