blob: d386d756a6b82ff625ff8f906ea1a726f08baeaf [file] [log] [blame]
Werner Zehe5a1fc72021-07-01 13:40:11 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <baseboard/variants.h>
Werner Zeh59a83552021-10-07 16:12:06 +02004#include <console/console.h>
5#include <device/dram/common.h>
Elyes Haouas8823ba12022-12-05 08:48:50 +01006#include <device/mmio.h>
Werner Zeh59a83552021-10-07 16:12:06 +02007#include <hwilib.h>
Werner Zehe5a1fc72021-07-01 13:40:11 +02008#include <soc/meminit.h>
9#include <soc/romstage.h>
Werner Zeh59a83552021-10-07 16:12:06 +020010#include <string.h>
11#include <types.h>
Werner Zehe5a1fc72021-07-01 13:40:11 +020012
Mario Scheithauer81fb9812023-07-04 15:32:39 +020013bool __weak half_populated(void)
14{
15 return false;
16}
17
Werner Zehe5a1fc72021-07-01 13:40:11 +020018void mainboard_memory_init_params(FSPM_UPD *memupd)
19{
20 static struct spd_info spd_info;
21 const struct mb_cfg *board_cfg = variant_memcfg_config();
Werner Zeh06fe5d52022-03-09 08:47:23 +010022 static uint8_t spd_data[CONFIG_DIMM_SPD_SIZE];
Werner Zeh59a83552021-10-07 16:12:06 +020023 const char *cbfs_hwi_name = "hwinfo.hex";
Werner Zehe5a1fc72021-07-01 13:40:11 +020024
Werner Zeh57200482023-04-27 10:26:01 +020025 /* Initialize SPD information for LPDDR4x from HW-Info. */
Werner Zeh59a83552021-10-07 16:12:06 +020026 memset(spd_data, 0, sizeof(spd_data));
27 if ((hwilib_find_blocks(cbfs_hwi_name) == CB_SUCCESS) &&
28 (hwilib_get_field(SPD, spd_data, 0x80) == 0x80) &&
29 (ddr_crc16(spd_data, 126) == read16((void *)&spd_data[126]))) {
30 spd_info.spd_spec.spd_data_ptr_info.spd_data_ptr = (uintptr_t)spd_data;
Werner Zeh06fe5d52022-03-09 08:47:23 +010031 spd_info.spd_spec.spd_data_ptr_info.spd_data_len = CONFIG_DIMM_SPD_SIZE;
Werner Zeh59a83552021-10-07 16:12:06 +020032 spd_info.read_type = READ_SPD_MEMPTR;
33 } else {
Werner Zeh833bb442022-10-27 10:23:29 +020034 die("SPD in HW-Info not valid!\n");
Werner Zeh59a83552021-10-07 16:12:06 +020035 }
Werner Zehe5a1fc72021-07-01 13:40:11 +020036 /* Initialize variant specific configurations */
Mario Scheithauer81fb9812023-07-04 15:32:39 +020037 memcfg_init(&memupd->FspmConfig, board_cfg, &spd_info, half_populated());
Mario Scheithauerbb03e762021-11-02 14:39:17 +010038
39 /* Enable Row-Hammer prevention */
40 memupd->FspmConfig.RhPrevention = 1;
Werner Zeh722c0b72023-11-28 16:26:28 +010041 if (CONFIG(BOARD_SIEMENS_MC_EHL1)) {
42 /* Allow writes to EEPROM addresses 0x50..0x57. */
43 memupd->FspmConfig.SmbusSpdWriteDisable = 0;
44 }
Werner Zehe5a1fc72021-07-01 13:40:11 +020045}