Angel Pons | 9b10c09 | 2020-04-05 13:21:20 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | 81485d2 | 2016-10-28 09:13:52 -0700 | [diff] [blame] | 2 | |
Duncan Laurie | 81485d2 | 2016-10-28 09:13:52 -0700 | [diff] [blame] | 3 | #include <cbfs.h> |
| 4 | #include <console/console.h> |
| 5 | #include <gpio.h> |
| 6 | #include <soc/gpio.h> |
Duncan Laurie | 81485d2 | 2016-10-28 09:13:52 -0700 | [diff] [blame] | 7 | #include <soc/romstage.h> |
| 8 | #include <string.h> |
| 9 | |
| 10 | #include "../gpio.h" |
| 11 | #include "spd.h" |
| 12 | |
| 13 | static void mainboard_print_spd_info(uint8_t spd[]) |
| 14 | { |
| 15 | const int spd_banks[8] = { 8, 16, 32, 64, -1, -1, -1, -1 }; |
| 16 | const int spd_capmb[8] = { 1, 2, 4, 8, 16, 32, 64, 0 }; |
| 17 | const int spd_rows[8] = { 12, 13, 14, 15, 16, -1, -1, -1 }; |
| 18 | const int spd_cols[8] = { 9, 10, 11, 12, -1, -1, -1, -1 }; |
| 19 | const int spd_ranks[8] = { 1, 2, 3, 4, -1, -1, -1, -1 }; |
| 20 | const int spd_devw[8] = { 4, 8, 16, 32, -1, -1, -1, -1 }; |
| 21 | const int spd_busw[8] = { 8, 16, 32, 64, -1, -1, -1, -1 }; |
| 22 | char spd_name[SPD_PART_LEN+1] = { 0 }; |
| 23 | |
| 24 | int banks = spd_banks[(spd[SPD_DENSITY_BANKS] >> 4) & 7]; |
| 25 | int capmb = spd_capmb[spd[SPD_DENSITY_BANKS] & 7] * 256; |
| 26 | int rows = spd_rows[(spd[SPD_ADDRESSING] >> 3) & 7]; |
| 27 | int cols = spd_cols[spd[SPD_ADDRESSING] & 7]; |
| 28 | int ranks = spd_ranks[(spd[SPD_ORGANIZATION] >> 3) & 7]; |
| 29 | int devw = spd_devw[spd[SPD_ORGANIZATION] & 7]; |
| 30 | int busw = spd_busw[spd[SPD_BUS_DEV_WIDTH] & 7]; |
| 31 | |
| 32 | /* Module type */ |
| 33 | printk(BIOS_INFO, "SPD: module type is "); |
| 34 | switch (spd[SPD_DRAM_TYPE]) { |
| 35 | case SPD_DRAM_DDR3: |
| 36 | printk(BIOS_INFO, "DDR3\n"); |
| 37 | break; |
| 38 | case SPD_DRAM_LPDDR3: |
| 39 | printk(BIOS_INFO, "LPDDR3\n"); |
| 40 | break; |
| 41 | default: |
| 42 | printk(BIOS_INFO, "Unknown (%02x)\n", spd[SPD_DRAM_TYPE]); |
| 43 | break; |
| 44 | } |
| 45 | |
| 46 | /* Module Part Number */ |
| 47 | memcpy(spd_name, &spd[SPD_PART_OFF], SPD_PART_LEN); |
| 48 | spd_name[SPD_PART_LEN] = 0; |
| 49 | printk(BIOS_INFO, "SPD: module part is %s\n", spd_name); |
| 50 | |
| 51 | printk(BIOS_INFO, |
| 52 | "SPD: banks %d, ranks %d, rows %d, columns %d, density %d Mb\n", |
| 53 | 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 | |
Duncan Laurie | 08117c4 | 2017-04-10 01:11:21 -0700 | [diff] [blame] | 64 | int mainboard_get_spd_index(void) |
Duncan Laurie | 81485d2 | 2016-10-28 09:13:52 -0700 | [diff] [blame] | 65 | { |
Duncan Laurie | 81485d2 | 2016-10-28 09:13:52 -0700 | [diff] [blame] | 66 | gpio_t spd_gpios[] = { |
| 67 | GPIO_MEM_CONFIG_0, |
| 68 | GPIO_MEM_CONFIG_1, |
| 69 | GPIO_MEM_CONFIG_2, |
| 70 | GPIO_MEM_CONFIG_3, |
| 71 | }; |
Duncan Laurie | 08117c4 | 2017-04-10 01:11:21 -0700 | [diff] [blame] | 72 | return gpio_base2_value(spd_gpios, ARRAY_SIZE(spd_gpios)); |
| 73 | } |
Duncan Laurie | 81485d2 | 2016-10-28 09:13:52 -0700 | [diff] [blame] | 74 | |
Duncan Laurie | 08117c4 | 2017-04-10 01:11:21 -0700 | [diff] [blame] | 75 | uintptr_t mainboard_get_spd_data(void) |
| 76 | { |
| 77 | char *spd_file; |
| 78 | size_t spd_file_len; |
| 79 | int spd_index; |
| 80 | |
| 81 | spd_index = mainboard_get_spd_index(); |
Duncan Laurie | 81485d2 | 2016-10-28 09:13:52 -0700 | [diff] [blame] | 82 | printk(BIOS_INFO, "SPD index %d\n", spd_index); |
| 83 | |
| 84 | /* Load SPD data from CBFS */ |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame^] | 85 | spd_file = cbfs_map("spd.bin", &spd_file_len); |
Duncan Laurie | 81485d2 | 2016-10-28 09:13:52 -0700 | [diff] [blame] | 86 | if (!spd_file) |
| 87 | die("SPD data not found."); |
| 88 | |
| 89 | /* make sure we have at least one SPD in the file. */ |
| 90 | if (spd_file_len < SPD_LEN) |
| 91 | die("Missing SPD data."); |
| 92 | |
| 93 | /* Make sure we did not overrun the buffer */ |
| 94 | if (spd_file_len < ((spd_index + 1) * SPD_LEN)) { |
| 95 | printk(BIOS_ERR, "SPD index override to 1 - old hardware?\n"); |
| 96 | spd_index = 1; |
| 97 | } |
| 98 | |
| 99 | spd_index *= SPD_LEN; |
| 100 | mainboard_print_spd_info((uint8_t *)(spd_file + spd_index)); |
| 101 | |
| 102 | return (uintptr_t)(spd_file + spd_index); |
| 103 | } |