Angel Pons | 58c0d32 | 2020-04-05 13:20:46 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 2 | |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 3 | #include <cbfs.h> |
| 4 | #include <console/console.h> |
Julius Werner | 9ff8f6f | 2015-02-23 14:31:09 -0800 | [diff] [blame] | 5 | #include <endian.h> |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 6 | #include <string.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 7 | #include <soc/gpio.h> |
| 8 | #include <soc/pei_data.h> |
| 9 | #include <soc/romstage.h> |
Duncan Laurie | c253189 | 2014-06-18 14:03:08 +0800 | [diff] [blame] | 10 | #include <ec/google/chromeec/ec.h> |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 11 | #include <mainboard/google/auron/ec.h> |
Matt DeVillier | 45e11aa | 2016-12-18 11:59:58 -0600 | [diff] [blame] | 12 | #include <variant/spd.h> |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 13 | |
| 14 | static 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 */ |
| 65 | void mainboard_fill_spd_data(struct pei_data *pei_data) |
| 66 | { |
Duncan Laurie | c253189 | 2014-06-18 14:03:08 +0800 | [diff] [blame] | 67 | int spd_bits[4] = { |
| 68 | SPD_GPIO_BIT0, |
| 69 | SPD_GPIO_BIT1, |
| 70 | SPD_GPIO_BIT2, |
| 71 | SPD_GPIO_BIT3 |
| 72 | }; |
Duncan Laurie | 25c6f75 | 2014-05-22 08:25:36 -0700 | [diff] [blame] | 73 | int spd_gpio[4]; |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 74 | int spd_index; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 75 | size_t spd_file_len; |
| 76 | char *spd_file; |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 77 | |
Duncan Laurie | c253189 | 2014-06-18 14:03:08 +0800 | [diff] [blame] | 78 | 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 Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 82 | |
Duncan Laurie | 25c6f75 | 2014-05-22 08:25:36 -0700 | [diff] [blame] | 83 | spd_index = (spd_gpio[3] << 3) | (spd_gpio[2] << 2) | |
| 84 | (spd_gpio[1] << 1) | spd_gpio[0]; |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 85 | |
Duncan Laurie | 25c6f75 | 2014-05-22 08:25:36 -0700 | [diff] [blame] | 86 | printk(BIOS_DEBUG, "SPD: index %d (GPIO%d=%d GPIO%d=%d " |
| 87 | "GPIO%d=%d GPIO%d=%d)\n", spd_index, |
Duncan Laurie | c253189 | 2014-06-18 14:03:08 +0800 | [diff] [blame] | 88 | 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 Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 90 | |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame^] | 91 | spd_file = cbfs_map("spd.bin", &spd_file_len); |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 92 | if (!spd_file) |
| 93 | die("SPD data not found."); |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 94 | |
| 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 Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 105 | 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 Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 107 | |
Duncan Laurie | c253189 | 2014-06-18 14:03:08 +0800 | [diff] [blame] | 108 | /* Make sure a valid SPD was found */ |
| 109 | if (pei_data->spd_data[0][0][0] == 0) |
| 110 | die("Invalid SPD data."); |
| 111 | |
Duncan Laurie | 2663a55 | 2014-05-14 15:59:37 -0700 | [diff] [blame] | 112 | mainboard_print_spd_info(pei_data->spd_data[0][0]); |
| 113 | } |