blob: b8ec9176330f3cfab7fa7e1fad4f71e599282466 [file] [log] [blame]
Martin Rothac35e622017-11-07 13:43:02 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2017 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
Martin Rothac35e622017-11-07 13:43:02 -070016#include <baseboard/variants.h>
Marc Jonesfede56b2017-11-16 18:53:47 -070017#include <console/console.h>
18#include <gpio.h> /* src/include/gpio.h */
19#include <spd_bin.h>
Martin Rothac35e622017-11-07 13:43:02 -070020#include <variant/gpio.h>
Marc Jonesfede56b2017-11-16 18:53:47 -070021#include <amdblocks/dimm_spd.h>
Martin Rothac35e622017-11-07 13:43:02 -070022
Marc Jones71f7f0a2017-11-21 23:29:55 -070023uint8_t __attribute__((weak)) variant_memory_sku(void)
Martin Rothac35e622017-11-07 13:43:02 -070024{
25 gpio_t pads[] = {
26 [3] = MEM_CONFIG3,
27 [2] = MEM_CONFIG2,
28 [1] = MEM_CONFIG1,
29 [0] = MEM_CONFIG0,
30 };
31
Martin Roth1cdb6f22017-11-17 09:25:02 -070032 return gpio_base2_value(pads, ARRAY_SIZE(pads));
Martin Rothac35e622017-11-07 13:43:02 -070033}
Marc Jonesfede56b2017-11-16 18:53:47 -070034
35int __attribute__((weak)) variant_mainboard_read_spd(uint8_t spdAddress,
36 char *buf, size_t len)
37{
38 struct region_device spd_rdev;
39 u8 spd_index = variant_memory_sku();
40
41 printk(BIOS_INFO, "%s SPD index %d\n", __func__, spd_index);
42
43 if (get_spd_cbfs_rdev(&spd_rdev, spd_index) < 0) {
44 printk(BIOS_ERR, "Error: spd.bin not found\n");
45 return -1;
46 }
47
48 if (len != region_device_sz(&spd_rdev)) {
49 printk(BIOS_ERR, "Error: spd.bin is not the correct size\n");
50 return -1;
51 }
52
53 if (rdev_readat(&spd_rdev, buf, 0, len) != len) {
54 printk(BIOS_ERR, "Error: couldn't read spd.bin\n");
55 return -1;
56 }
57
58 return 0;
59}