blob: fee40a078381ef13b0e4e7794f007c734fdd5b14 [file] [log] [blame]
Christian Walterb646e282020-01-09 15:42:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <device/pci_ops.h>
4#include <console/console.h>
5#include <device/smbus_host.h>
6#include "variants/baseboard/include/eeprom.h"
7
8/*
9 * Check Signature in EEPROM (M24C32-FMN6TP)
10 * If signature is there we assume that that the content is valid
11 */
12int check_signature(u8 addr)
13{
14 u8 blob[8] = {0};
15
16 if (!read_write_config(addr, blob, EEPROM_OFFSET_FSP_SIGNATURE, 0, ARRAY_SIZE(blob))) {
Angel Pons329ebb32020-11-24 15:03:38 +010017 /* Check signature */
Christian Walterb646e282020-01-09 15:42:42 +010018 if (*(uint64_t *)blob == FSP_UPD_SIGNATURE) {
19 printk(BIOS_DEBUG, "CFG EEPROM: Signature valid.\n");
20 return 1;
21 }
22 printk(BIOS_DEBUG, "CFG EEPROM: Signature invalid - skipping option write.\n");
23 return 0;
24 }
25 return 0;
26}
27
Angel Pons329ebb32020-11-24 15:03:38 +010028/* Read data from offset and write it to offset in UPD */
Christian Walterb646e282020-01-09 15:42:42 +010029bool read_write_config(u8 addr, void *blob, size_t read_offset, size_t write_offset,
30 size_t size)
31{
32 int ret = 0;
33
Angel Pons13c50002020-11-24 15:39:26 +010034 u32 smb_ctrl_reg = pci_read_config32(PCH_DEV_SMBUS, HOSTC);
35 pci_write_config32(PCH_DEV_SMBUS, HOSTC, smb_ctrl_reg | HOSTC_I2C_EN);
Christian Walterb646e282020-01-09 15:42:42 +010036
37 printk(BIOS_SPEW, "%s\tOffset: %04zx\tSize: %02zx\n", __func__,
38 read_offset, size);
39
40 /* We can always read two bytes at a time */
41 for (size_t i = 0; i < size; i = i + 2) {
42 u8 tmp[2] = {0};
43
44 ret = do_smbus_process_call(SMBUS_IO_BASE, addr, 0,
45 swab16(read_offset + i), (uint16_t *)&tmp[0]);
46 if (ret < 0)
47 break;
48
Angel Pons329ebb32020-11-24 15:03:38 +010049 /* Write to UPD */
Christian Walterb646e282020-01-09 15:42:42 +010050 uint8_t *writePointer = (uint8_t *)blob + write_offset + i;
51 if (size > 1 && (size % 2 == 0))
52 memcpy(writePointer, tmp, 2);
53 else
54 *writePointer = tmp[0];
55 }
56
57 /* Restore I2C_EN bit */
Angel Pons13c50002020-11-24 15:39:26 +010058 pci_write_config32(PCH_DEV_SMBUS, HOSTC, smb_ctrl_reg);
Christian Walterb646e282020-01-09 15:42:42 +010059
60 return ret;
61}