blob: 905e196f7b5752fbb3adeda4b0fac343ebf6f5f5 [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{
Matt DeVillier45e11aa2016-12-18 11:59:58 -060069 int spd_bits[4] = {
Marc Jonesd8621212015-06-09 21:18:38 -060070 SPD_GPIO_BIT0,
71 SPD_GPIO_BIT1,
Matt DeVillier45e11aa2016-12-18 11:59:58 -060072 SPD_GPIO_BIT2,
73 SPD_GPIO_BIT3
Marc Jonesd8621212015-06-09 21:18:38 -060074 };
Matt DeVillier45e11aa2016-12-18 11:59:58 -060075 int spd_gpio[4];
Marc Jonesd8621212015-06-09 21:18:38 -060076 int spd_index;
77 size_t spd_file_len;
78 char *spd_file;
79
80 spd_gpio[0] = get_gpio(SPD_GPIO_BIT0);
81 spd_gpio[1] = get_gpio(SPD_GPIO_BIT1);
82 spd_gpio[2] = get_gpio(SPD_GPIO_BIT2);
Matt DeVillier45e11aa2016-12-18 11:59:58 -060083 spd_gpio[3] = get_gpio(SPD_GPIO_BIT3);
Marc Jonesd8621212015-06-09 21:18:38 -060084
Matt DeVillier45e11aa2016-12-18 11:59:58 -060085 spd_index = (spd_gpio[3] << 3) | (spd_gpio[2] << 2) |
86 (spd_gpio[1] << 1) | spd_gpio[0];
Marc Jonesd8621212015-06-09 21:18:38 -060087
Matt DeVillier45e11aa2016-12-18 11:59:58 -060088 printk(BIOS_DEBUG, "SPD: index %d (GPIO%d=%d GPIO%d=%d GPIO%d=%d GPIO%d=%d)\n",
89 spd_index,
90 spd_bits[3], spd_gpio[3],
91 spd_bits[2], spd_gpio[2],
92 spd_bits[1], spd_gpio[1],
93 spd_bits[0], spd_gpio[0]);
Marc Jonesd8621212015-06-09 21:18:38 -060094
Julius Werner834b3ec2020-03-04 16:52:08 -080095 spd_file = cbfs_map("spd.bin", &spd_file_len);
Marc Jonesd8621212015-06-09 21:18:38 -060096 if (!spd_file)
97 die("SPD data not found.");
98
Marc Jonesd8621212015-06-09 21:18:38 -060099 if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
100 printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
101 spd_index = 0;
102 }
103
104 if (spd_file_len < SPD_LEN)
105 die("Missing SPD data.");
106
Matt DeVillier45e11aa2016-12-18 11:59:58 -0600107 /* CH0 */
Marc Jonesd8621212015-06-09 21:18:38 -0600108 memcpy(pei_data->spd_data[0][0],
Tim Chenf3214d022014-10-14 20:17:11 +0800109 spd_file + (spd_index * SPD_LEN), SPD_LEN);
Matt DeVillier45e11aa2016-12-18 11:59:58 -0600110
111 /* CH1 not used in 2GB configurations */
112 if (!((spd_index == 0b0000) || (spd_index == 0b0011) ||
113 (spd_index == 0b1010))) {
Marc Jonesd8621212015-06-09 21:18:38 -0600114 memcpy(pei_data->spd_data[1][0],
Tim Chenf3214d022014-10-14 20:17:11 +0800115 spd_file + (spd_index * SPD_LEN), SPD_LEN);
Matt DeVillier45e11aa2016-12-18 11:59:58 -0600116 }
Marc Jonesd8621212015-06-09 21:18:38 -0600117
118 /* Make sure a valid SPD was found */
119 if (pei_data->spd_data[0][0][0] == 0)
120 die("Invalid SPD data.");
121
122 mainboard_print_spd_info(pei_data->spd_data[0][0]);
123}