Christian Walter | b646e28 | 2020-01-09 15:42:42 +0100 | [diff] [blame] | 1 | /* 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 | */ |
| 12 | int 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 Pons | 329ebb3 | 2020-11-24 15:03:38 +0100 | [diff] [blame] | 17 | /* Check signature */ |
Christian Walter | b646e28 | 2020-01-09 15:42:42 +0100 | [diff] [blame] | 18 | 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 Pons | 329ebb3 | 2020-11-24 15:03:38 +0100 | [diff] [blame] | 28 | /* Read data from offset and write it to offset in UPD */ |
Christian Walter | b646e28 | 2020-01-09 15:42:42 +0100 | [diff] [blame] | 29 | bool 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 Pons | 13c5000 | 2020-11-24 15:39:26 +0100 | [diff] [blame^] | 34 | 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 Walter | b646e28 | 2020-01-09 15:42:42 +0100 | [diff] [blame] | 36 | |
| 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 Pons | 329ebb3 | 2020-11-24 15:03:38 +0100 | [diff] [blame] | 49 | /* Write to UPD */ |
Christian Walter | b646e28 | 2020-01-09 15:42:42 +0100 | [diff] [blame] | 50 | 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 Pons | 13c5000 | 2020-11-24 15:39:26 +0100 | [diff] [blame^] | 58 | pci_write_config32(PCH_DEV_SMBUS, HOSTC, smb_ctrl_reg); |
Christian Walter | b646e28 | 2020-01-09 15:42:42 +0100 | [diff] [blame] | 59 | |
| 60 | return ret; |
| 61 | } |