1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #include <device/dram/common.h> 4 #include <types.h> 5 6 /** 7 * \brief Calculate the CRC of a DDR SPD data 8 * 9 * @param spd pointer to raw SPD data 10 * @param len length of data in SPD 11 * 12 * @return the CRC of the SPD data 13 */ ddr_crc16(const u8 * ptr,int n_crc)14u16 ddr_crc16(const u8 *ptr, int n_crc) 15 { 16 int i; 17 u16 crc = 0; 18 19 while (--n_crc >= 0) { 20 crc = crc ^ ((int)*ptr++ << 8); 21 for (i = 0; i < 8; ++i) 22 if (crc & 0x8000) 23 crc = (crc << 1) ^ 0x1021; 24 else 25 crc = crc << 1; 26 } 27 28 return crc; 29 } 30