blob: 4cad47432c459104ec6fbbebf3615bd3054bd233 [file] [log] [blame]
Angel Pons58c0d322020-04-05 13:20:46 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurie2663a552014-05-14 15:59:37 -07002
Duncan Laurie2663a552014-05-14 15:59:37 -07003#include <cbfs.h>
4#include <console/console.h>
Julius Werner9ff8f6f2015-02-23 14:31:09 -08005#include <endian.h>
Duncan Laurie2663a552014-05-14 15:59:37 -07006#include <string.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -07007#include <soc/gpio.h>
8#include <soc/pei_data.h>
9#include <soc/romstage.h>
Duncan Lauriec2531892014-06-18 14:03:08 +080010#include <ec/google/chromeec/ec.h>
Matt DeVillier45e11aa2016-12-18 11:59:58 -060011#include <mainboard/google/auron/ec.h>
Matt DeVillier45e11aa2016-12-18 11:59:58 -060012#include <variant/spd.h>
Duncan Laurie2663a552014-05-14 15:59:37 -070013
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 "density %d Mb\n", banks, ranks, rows, cols, capmb);
54 printk(BIOS_INFO, "SPD: device width %d bits, bus width %d bits\n",
55 devw, busw);
56
57 if (capmb > 0 && busw > 0 && devw > 0 && ranks > 0) {
58 /* SIZE = DENSITY / 8 * BUS_WIDTH / SDRAM_WIDTH * RANKS */
59 printk(BIOS_INFO, "SPD: module size is %u MB (per channel)\n",
60 capmb / 8 * busw / devw * ranks);
61 }
62}
63
64/* Copy SPD data for on-board memory */
65void mainboard_fill_spd_data(struct pei_data *pei_data)
66{
Duncan Lauriec2531892014-06-18 14:03:08 +080067 int spd_bits[4] = {
68 SPD_GPIO_BIT0,
69 SPD_GPIO_BIT1,
70 SPD_GPIO_BIT2,
71 SPD_GPIO_BIT3
72 };
Duncan Laurie25c6f752014-05-22 08:25:36 -070073 int spd_gpio[4];
Duncan Laurie2663a552014-05-14 15:59:37 -070074 int spd_index;
Aaron Durbin899d13d2015-05-15 23:39:23 -050075 size_t spd_file_len;
76 char *spd_file;
Duncan Laurie2663a552014-05-14 15:59:37 -070077
Duncan Lauriec2531892014-06-18 14:03:08 +080078 spd_gpio[0] = get_gpio(spd_bits[0]);
79 spd_gpio[1] = get_gpio(spd_bits[1]);
80 spd_gpio[2] = get_gpio(spd_bits[2]);
81 spd_gpio[3] = get_gpio(spd_bits[3]);
Duncan Laurie2663a552014-05-14 15:59:37 -070082
Duncan Laurie25c6f752014-05-22 08:25:36 -070083 spd_index = (spd_gpio[3] << 3) | (spd_gpio[2] << 2) |
84 (spd_gpio[1] << 1) | spd_gpio[0];
Duncan Laurie2663a552014-05-14 15:59:37 -070085
Duncan Laurie25c6f752014-05-22 08:25:36 -070086 printk(BIOS_DEBUG, "SPD: index %d (GPIO%d=%d GPIO%d=%d "
87 "GPIO%d=%d GPIO%d=%d)\n", spd_index,
Duncan Lauriec2531892014-06-18 14:03:08 +080088 spd_bits[3], spd_gpio[3], spd_bits[2], spd_gpio[2],
89 spd_bits[1], spd_gpio[1], spd_bits[0], spd_gpio[0]);
Duncan Laurie2663a552014-05-14 15:59:37 -070090
Julius Werner834b3ec2020-03-04 16:52:08 -080091 spd_file = cbfs_map("spd.bin", &spd_file_len);
Duncan Laurie2663a552014-05-14 15:59:37 -070092 if (!spd_file)
93 die("SPD data not found.");
Duncan Laurie2663a552014-05-14 15:59:37 -070094
95 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 /* Assume same memory in both channels */
104 spd_index *= SPD_LEN;
Aaron Durbin899d13d2015-05-15 23:39:23 -0500105 memcpy(pei_data->spd_data[0][0], spd_file + spd_index, SPD_LEN);
106 memcpy(pei_data->spd_data[1][0], spd_file + spd_index, SPD_LEN);
Duncan Laurie2663a552014-05-14 15:59:37 -0700107
Duncan Lauriec2531892014-06-18 14:03:08 +0800108 /* Make sure a valid SPD was found */
109 if (pei_data->spd_data[0][0][0] == 0)
110 die("Invalid SPD data.");
111
Duncan Laurie2663a552014-05-14 15:59:37 -0700112 mainboard_print_spd_info(pei_data->spd_data[0][0]);
113}