blob: 9bfb202bb99b8b56cf3d330c94fb9e183b11fa49 [file] [log] [blame]
Angel Pons62079a52020-04-05 13:21:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi406313d2015-07-20 22:01:32 +02002
Patrick Georgi406313d2015-07-20 22:01:32 +02003#include <cbfs.h>
4#include <console/console.h>
Aaron Durbin9506aea2015-07-24 13:06:12 -05005#include <gpio.h>
Duncan Laurie44b01fd2015-09-03 16:19:42 -07006#include <soc/gpio.h>
Patrick Georgi406313d2015-07-20 22:01:32 +02007#include <soc/romstage.h>
Duncan Laurie44b01fd2015-09-03 16:19:42 -07008#include <string.h>
Matt DeVillier0b9cfe62018-06-26 13:07:32 -05009#include <baseboard/variant.h>
Nico Huberfeb50f12019-05-04 17:06:06 +020010
11#include "spd_util.h"
Patrick Georgi406313d2015-07-20 22:01:32 +020012#include "spd.h"
13
14static void mainboard_print_spd_info(uint8_t spd[])
15{
16 const int spd_banks[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
17 const int spd_capmb[8] = { 1, 2, 4, 8, 16, 32, 64, 0 };
18 const int spd_rows[8] = { 12, 13, 14, 15, 16, -1, -1, -1 };
19 const int spd_cols[8] = { 9, 10, 11, 12, -1, -1, -1, -1 };
20 const int spd_ranks[8] = { 1, 2, 3, 4, -1, -1, -1, -1 };
21 const int spd_devw[8] = { 4, 8, 16, 32, -1, -1, -1, -1 };
22 const int spd_busw[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
23 char spd_name[SPD_PART_LEN+1] = { 0 };
24
25 int banks = spd_banks[(spd[SPD_DENSITY_BANKS] >> 4) & 7];
26 int capmb = spd_capmb[spd[SPD_DENSITY_BANKS] & 7] * 256;
27 int rows = spd_rows[(spd[SPD_ADDRESSING] >> 3) & 7];
28 int cols = spd_cols[spd[SPD_ADDRESSING] & 7];
29 int ranks = spd_ranks[(spd[SPD_ORGANIZATION] >> 3) & 7];
30 int devw = spd_devw[spd[SPD_ORGANIZATION] & 7];
31 int busw = spd_busw[spd[SPD_BUS_DEV_WIDTH] & 7];
32
33 /* Module type */
34 printk(BIOS_INFO, "SPD: module type is ");
35 switch (spd[SPD_DRAM_TYPE]) {
36 case SPD_DRAM_DDR3:
37 printk(BIOS_INFO, "DDR3\n");
38 break;
39 case SPD_DRAM_LPDDR3:
40 printk(BIOS_INFO, "LPDDR3\n");
41 break;
42 default:
43 printk(BIOS_INFO, "Unknown (%02x)\n", spd[SPD_DRAM_TYPE]);
44 break;
45 }
46
47 /* Module Part Number */
48 memcpy(spd_name, &spd[SPD_PART_OFF], SPD_PART_LEN);
49 spd_name[SPD_PART_LEN] = 0;
50 printk(BIOS_INFO, "SPD: module part is %s\n", spd_name);
51
52 printk(BIOS_INFO,
53 "SPD: banks %d, ranks %d, rows %d, columns %d, density %d Mb\n",
54 banks, ranks, rows, cols, capmb);
55 printk(BIOS_INFO, "SPD: device width %d bits, bus width %d bits\n",
56 devw, busw);
57
58 if (capmb > 0 && busw > 0 && devw > 0 && ranks > 0) {
59 /* SIZE = DENSITY / 8 * BUS_WIDTH / SDRAM_WIDTH * RANKS */
60 printk(BIOS_INFO, "SPD: module size is %u MB (per channel)\n",
61 capmb / 8 * busw / devw * ranks);
62 }
63}
64
Matt DeVillier0b9cfe62018-06-26 13:07:32 -050065__weak int is_dual_channel(const int spd_index)
66{
67 /* default to dual channel */
68 return 1;
69}
70
Patrick Georgi406313d2015-07-20 22:01:32 +020071/* Copy SPD data for on-board memory */
Michael Niewöhnerf89cb242019-10-09 21:02:36 +020072void spd_memory_init_params(FSPM_UPD *mupd, int spd_index)
Patrick Georgi406313d2015-07-20 22:01:32 +020073{
Michael Niewöhnerf89cb242019-10-09 21:02:36 +020074 FSP_M_CONFIG *mem_cfg;
75 mem_cfg = &mupd->FspmConfig;
Nico Huberfeb50f12019-05-04 17:06:06 +020076 uint8_t *spd_file;
Patrick Georgi406313d2015-07-20 22:01:32 +020077 size_t spd_file_len;
Duncan Lauried8d68662015-07-22 09:21:29 -070078
Duncan Laurie44b01fd2015-09-03 16:19:42 -070079 printk(BIOS_INFO, "SPD index %d\n", spd_index);
Patrick Georgi406313d2015-07-20 22:01:32 +020080
81 /* Load SPD data from CBFS */
Julius Werner834b3ec2020-03-04 16:52:08 -080082 spd_file = cbfs_map("spd.bin", &spd_file_len);
Patrick Georgi406313d2015-07-20 22:01:32 +020083 if (!spd_file)
84 die("SPD data not found.");
85
86 /* make sure we have at least one SPD in the file. */
87 if (spd_file_len < SPD_LEN)
88 die("Missing SPD data.");
89
Patrick Georgi406313d2015-07-20 22:01:32 +020090 /* Make sure we did not overrun the buffer */
91 if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
Duncan Lauried8d68662015-07-22 09:21:29 -070092 printk(BIOS_ERR, "SPD index override to 1 - old hardware?\n");
93 spd_index = 1;
Patrick Georgi406313d2015-07-20 22:01:32 +020094 }
95
Nico Huberfeb50f12019-05-04 17:06:06 +020096 const size_t spd_offset = spd_index * SPD_LEN;
Patrick Georgi406313d2015-07-20 22:01:32 +020097 /* Make sure a valid SPD was found */
Nico Huberfeb50f12019-05-04 17:06:06 +020098 if (spd_file[spd_offset] == 0)
Patrick Georgi406313d2015-07-20 22:01:32 +020099 die("Invalid SPD data.");
100
Nico Huberfeb50f12019-05-04 17:06:06 +0200101 /* Assume same memory in both channels */
Michael Niewöhnerf89cb242019-10-09 21:02:36 +0200102 mem_cfg->MemorySpdPtr00 = (uintptr_t)spd_file + spd_offset;
Nico Huberfeb50f12019-05-04 17:06:06 +0200103 if (is_dual_channel(spd_index))
Michael Niewöhnerf89cb242019-10-09 21:02:36 +0200104 mem_cfg->MemorySpdPtr10 = mem_cfg->MemorySpdPtr00;
Nico Huberfeb50f12019-05-04 17:06:06 +0200105
106 mainboard_print_spd_info(spd_file + spd_offset);
Patrick Georgi406313d2015-07-20 22:01:32 +0200107}