blob: 1308ab262dbfb39049daee43b2c3a2869114e494 [file] [log] [blame]
Duncan Laurie2663a552014-05-14 15:59:37 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
Duncan Laurie2663a552014-05-14 15:59:37 -070020#include <cbfs.h>
21#include <console/console.h>
Julius Werner9ff8f6f2015-02-23 14:31:09 -080022#include <endian.h>
Duncan Laurie2663a552014-05-14 15:59:37 -070023#include <string.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070024#include <soc/gpio.h>
25#include <soc/pei_data.h>
26#include <soc/romstage.h>
Duncan Lauriec2531892014-06-18 14:03:08 +080027#include <ec/google/chromeec/ec.h>
28#include <mainboard/google/samus/ec.h>
Duncan Lauriefe8b7882014-05-22 08:22:51 -070029#include <mainboard/google/samus/gpio.h>
30#include <mainboard/google/samus/spd/spd.h>
Duncan Laurie2663a552014-05-14 15:59:37 -070031
32static void mainboard_print_spd_info(uint8_t spd[])
33{
34 const int spd_banks[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
35 const int spd_capmb[8] = { 1, 2, 4, 8, 16, 32, 64, 0 };
36 const int spd_rows[8] = { 12, 13, 14, 15, 16, -1, -1, -1 };
37 const int spd_cols[8] = { 9, 10, 11, 12, -1, -1, -1, -1 };
38 const int spd_ranks[8] = { 1, 2, 3, 4, -1, -1, -1, -1 };
39 const int spd_devw[8] = { 4, 8, 16, 32, -1, -1, -1, -1 };
40 const int spd_busw[8] = { 8, 16, 32, 64, -1, -1, -1, -1 };
41 char spd_name[SPD_PART_LEN+1] = { 0 };
42
43 int banks = spd_banks[(spd[SPD_DENSITY_BANKS] >> 4) & 7];
44 int capmb = spd_capmb[spd[SPD_DENSITY_BANKS] & 7] * 256;
45 int rows = spd_rows[(spd[SPD_ADDRESSING] >> 3) & 7];
46 int cols = spd_cols[spd[SPD_ADDRESSING] & 7];
47 int ranks = spd_ranks[(spd[SPD_ORGANIZATION] >> 3) & 7];
48 int devw = spd_devw[spd[SPD_ORGANIZATION] & 7];
49 int busw = spd_busw[spd[SPD_BUS_DEV_WIDTH] & 7];
50
51 /* Module type */
52 printk(BIOS_INFO, "SPD: module type is ");
53 switch (spd[SPD_DRAM_TYPE]) {
54 case SPD_DRAM_DDR3:
55 printk(BIOS_INFO, "DDR3\n");
56 break;
57 case SPD_DRAM_LPDDR3:
58 printk(BIOS_INFO, "LPDDR3\n");
59 break;
60 default:
61 printk(BIOS_INFO, "Unknown (%02x)\n", spd[SPD_DRAM_TYPE]);
62 break;
63 }
64
65 /* Module Part Number */
66 memcpy(spd_name, &spd[SPD_PART_OFF], SPD_PART_LEN);
67 spd_name[SPD_PART_LEN] = 0;
68 printk(BIOS_INFO, "SPD: module part is %s\n", spd_name);
69
70 printk(BIOS_INFO, "SPD: banks %d, ranks %d, rows %d, columns %d, "
71 "density %d Mb\n", banks, ranks, rows, cols, capmb);
72 printk(BIOS_INFO, "SPD: device width %d bits, bus width %d bits\n",
73 devw, busw);
74
75 if (capmb > 0 && busw > 0 && devw > 0 && ranks > 0) {
76 /* SIZE = DENSITY / 8 * BUS_WIDTH / SDRAM_WIDTH * RANKS */
77 printk(BIOS_INFO, "SPD: module size is %u MB (per channel)\n",
78 capmb / 8 * busw / devw * ranks);
79 }
80}
81
82/* Copy SPD data for on-board memory */
83void mainboard_fill_spd_data(struct pei_data *pei_data)
84{
Duncan Lauriec2531892014-06-18 14:03:08 +080085 int spd_bits[4] = {
86 SPD_GPIO_BIT0,
87 SPD_GPIO_BIT1,
88 SPD_GPIO_BIT2,
89 SPD_GPIO_BIT3
90 };
Duncan Laurie25c6f752014-05-22 08:25:36 -070091 int spd_gpio[4];
Duncan Laurie2663a552014-05-14 15:59:37 -070092 int spd_index;
93 int spd_file_len;
94 struct cbfs_file *spd_file;
95
Duncan Lauriec2531892014-06-18 14:03:08 +080096 spd_gpio[0] = get_gpio(spd_bits[0]);
97 spd_gpio[1] = get_gpio(spd_bits[1]);
98 spd_gpio[2] = get_gpio(spd_bits[2]);
99 spd_gpio[3] = get_gpio(spd_bits[3]);
Duncan Laurie2663a552014-05-14 15:59:37 -0700100
Duncan Laurie25c6f752014-05-22 08:25:36 -0700101 spd_index = (spd_gpio[3] << 3) | (spd_gpio[2] << 2) |
102 (spd_gpio[1] << 1) | spd_gpio[0];
Duncan Laurie2663a552014-05-14 15:59:37 -0700103
Duncan Laurie25c6f752014-05-22 08:25:36 -0700104 printk(BIOS_DEBUG, "SPD: index %d (GPIO%d=%d GPIO%d=%d "
105 "GPIO%d=%d GPIO%d=%d)\n", spd_index,
Duncan Lauriec2531892014-06-18 14:03:08 +0800106 spd_bits[3], spd_gpio[3], spd_bits[2], spd_gpio[2],
107 spd_bits[1], spd_gpio[1], spd_bits[0], spd_gpio[0]);
Duncan Laurie2663a552014-05-14 15:59:37 -0700108
109 spd_file = cbfs_get_file(CBFS_DEFAULT_MEDIA, "spd.bin");
110 if (!spd_file)
111 die("SPD data not found.");
112 spd_file_len = ntohl(spd_file->len);
113
114 if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
115 printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
116 spd_index = 0;
117 }
118
119 if (spd_file_len < SPD_LEN)
120 die("Missing SPD data.");
121
122 /* Assume same memory in both channels */
123 spd_index *= SPD_LEN;
124 memcpy(pei_data->spd_data[0][0],
125 ((char*)CBFS_SUBHEADER(spd_file)) + spd_index, SPD_LEN);
126 memcpy(pei_data->spd_data[1][0],
127 ((char*)CBFS_SUBHEADER(spd_file)) + spd_index, SPD_LEN);
128
Duncan Lauriec2531892014-06-18 14:03:08 +0800129 /* Make sure a valid SPD was found */
130 if (pei_data->spd_data[0][0][0] == 0)
131 die("Invalid SPD data.");
132
Duncan Laurie2663a552014-05-14 15:59:37 -0700133 mainboard_print_spd_info(pei_data->spd_data[0][0]);
134}