blob: 12a9d7cb12a525a432da6ce3da78e4cf108e9e30 [file] [log] [blame]
Angel Pons58c0d322020-04-05 13:20:46 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jonesd8621212015-06-09 21:18:38 -06002
3#include <cbfs.h>
4#include <console/console.h>
5#include <endian.h>
6#include <string.h>
7#include <soc/gpio.h>
8#include <soc/pei_data.h>
9#include <soc/romstage.h>
10#include <ec/google/chromeec/ec.h>
11#include <mainboard/google/auron/ec.h>
Matt DeVillier45e11aa2016-12-18 11:59:58 -060012#include <variant/spd.h>
Marc Jonesd8621212015-06-09 21:18:38 -060013
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, "SPD: banks %d, ranks %d, rows %d, columns %d, "
53 , banks, ranks, rows, cols);
54 printk(BIOS_INFO, "density %d Mb\n", capmb);
55
56 printk(BIOS_INFO, "SPD: device width %d bits, bus width %d bits\n",
57 devw, busw);
58
59 if (capmb > 0 && busw > 0 && devw > 0 && ranks > 0) {
60 /* SIZE = DENSITY / 8 * BUS_WIDTH / SDRAM_WIDTH * RANKS */
61 printk(BIOS_INFO, "SPD: module size is %u MB (per channel)\n",
62 capmb / 8 * busw / devw * ranks);
63 }
64}
65
66/* Copy SPD data for on-board memory */
67void mainboard_fill_spd_data(struct pei_data *pei_data)
68{
69 int spd_bits[3] = {
70 SPD_GPIO_BIT0,
71 SPD_GPIO_BIT1,
72 SPD_GPIO_BIT2
73 };
74 int spd_gpio[3];
75 int spd_index;
76 size_t spd_file_len;
77 char *spd_file;
78
79 spd_gpio[0] = get_gpio(SPD_GPIO_BIT0);
80 spd_gpio[1] = get_gpio(SPD_GPIO_BIT1);
81 spd_gpio[2] = get_gpio(SPD_GPIO_BIT2);
82
83 spd_index = spd_gpio[2] << 2 | spd_gpio[1] << 1 | spd_gpio[0];
84
85 printk(BIOS_DEBUG, "SPD: index %d (GPIO%d=%d GPIO%d=%d GPIO%d=%d)\n",
86 spd_index,
87 spd_bits[2], spd_gpio[2],
88 spd_bits[1], spd_gpio[1],
89 spd_bits[0], spd_gpio[0]);
90
Julius Werner834b3ec2020-03-04 16:52:08 -080091 spd_file = cbfs_map("spd.bin", &spd_file_len);
Marc Jonesd8621212015-06-09 21:18:38 -060092 if (!spd_file)
93 die("SPD data not found.");
94
Marc Jonesd8621212015-06-09 21:18:38 -060095 if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
96 printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
97 spd_index = 0;
98 }
99
100 if (spd_file_len < SPD_LEN)
101 die("Missing SPD data.");
102
103 memcpy(pei_data->spd_data[0][0],
Tim Chenf3214d022014-10-14 20:17:11 +0800104 spd_file + (spd_index * SPD_LEN), SPD_LEN);
Marc Jonesd8621212015-06-09 21:18:38 -0600105 /* Index 0-2 are 4GB config with both CH0 and CH1.
106 * Index 4-6 are 2GB config with CH0 only. */
107 if (spd_index > 3)
108 pei_data->dimm_channel1_disabled = 3;
109 else
110 memcpy(pei_data->spd_data[1][0],
Tim Chenf3214d022014-10-14 20:17:11 +0800111 spd_file + (spd_index * SPD_LEN), SPD_LEN);
Marc Jonesd8621212015-06-09 21:18:38 -0600112
113 /* Make sure a valid SPD was found */
114 if (pei_data->spd_data[0][0][0] == 0)
115 die("Invalid SPD data.");
116
117 mainboard_print_spd_info(pei_data->spd_data[0][0]);
118}