blob: 8674512ff447b9a8d4f94e46d0742db880302cbd [file] [log] [blame]
Angel Pons60ec3652020-04-03 01:22:13 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Rizwan Qureshi5ff73902016-08-24 20:50:54 +05302#include <cbfs.h>
3#include <console/console.h>
4#include <stdint.h>
5#include <string.h>
Rizwan Qureshi5ff73902016-08-24 20:50:54 +05306#include "boardid.h"
7#include "spd.h"
8
Jacob Garber8216b462019-05-29 14:29:45 -06009void mainboard_fill_dq_map_data(void *dq_map_ch0, void *dq_map_ch1)
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053010{
11 /* DQ byte map */
12 const u8 dq_map[2][12] = {
Elyes HAOUASa342f392018-10-17 10:56:26 +020013 { 0x0F, 0xF0, 0x00, 0xF0, 0x0F, 0xF0,
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053014 0x0F, 0x00, 0xFF, 0x00, 0xFF, 0x00 },
Elyes HAOUASa342f392018-10-17 10:56:26 +020015 { 0x0F, 0xF0, 0x00, 0xF0, 0x0F, 0xF0,
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053016 0x0F, 0x00, 0xFF, 0x00, 0xFF, 0x00 } };
Jacob Garber8216b462019-05-29 14:29:45 -060017 memcpy(dq_map_ch0, dq_map[0], sizeof(dq_map[0]));
18 memcpy(dq_map_ch1, dq_map[1], sizeof(dq_map[1]));
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053019}
20
Jacob Garber8216b462019-05-29 14:29:45 -060021void mainboard_fill_dqs_map_data(void *dqs_map_ch0, void *dqs_map_ch1)
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053022{
23 /* DQS CPU<>DRAM map */
24 const u8 dqs_map[2][8] = {
25 { 0, 1, 3, 2, 6, 5, 4, 7 },
26 { 2, 3, 0, 1, 6, 7, 4, 5 } };
Jacob Garber8216b462019-05-29 14:29:45 -060027 memcpy(dqs_map_ch0, dqs_map[0], sizeof(dqs_map[0]));
28 memcpy(dqs_map_ch1, dqs_map[1], sizeof(dqs_map[1]));
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053029}
30
31void mainboard_fill_rcomp_res_data(void *rcomp_ptr)
32{
33 /* Rcomp resistor */
34 const u16 RcompResistor[3] = { 200, 81, 162 };
35 memcpy(rcomp_ptr, RcompResistor,
36 sizeof(RcompResistor));
37}
38
39void mainboard_fill_rcomp_strength_data(void *rcomp_strength_ptr)
40{
41 int mem_cfg_id;
42
43 mem_cfg_id = get_spd_index();
44 /* Rcomp target */
Wim Vervoorn116a8372019-12-11 11:54:33 +010045 static const u16 RcompTarget[5] = {
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053046 100, 40, 40, 23, 40 };
47
48 /* Strengthen the Rcomp Target Ctrl for 8GB K4E6E304EE -EGCF */
Wim Vervoorn116a8372019-12-11 11:54:33 +010049 static const u16 StrengthendRcompTarget[5] = {
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053050 100, 40, 40, 21, 40 };
51
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053052 if (mem_cfg_id == K4E6E304EE_MEM_ID) {
53 memcpy(rcomp_strength_ptr, StrengthendRcompTarget,
54 sizeof(StrengthendRcompTarget));
55 } else {
56 memcpy(rcomp_strength_ptr, RcompTarget, sizeof(RcompTarget));
57 }
58
59}
60
61uintptr_t mainboard_get_spd_data(void)
62{
Elyes HAOUAS448d9fb2018-05-22 12:51:27 +020063 char *spd_file;
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053064 int spd_index, spd_span;
65 size_t spd_file_len;
66
67 spd_index = get_spd_index();
68 printk(BIOS_INFO, "SPD index %d\n", spd_index);
69
70 /* Load SPD data from CBFS */
Julius Werner834b3ec2020-03-04 16:52:08 -080071 spd_file = cbfs_map("spd.bin", &spd_file_len);
Rizwan Qureshic33f08b2016-09-16 19:45:08 +053072 if (!spd_file)
Rizwan Qureshi5ff73902016-08-24 20:50:54 +053073 die("SPD data not found.");
74
75 /* make sure we have at least one SPD in the file. */
76 if (spd_file_len < SPD_LEN)
77 die("Missing SPD data.");
78
79 /* Make sure we did not overrun the buffer */
80 if (spd_file_len < ((spd_index + 1) * SPD_LEN)) {
81 printk(BIOS_ERR, "SPD index override to 0 - old hardware?\n");
82 spd_index = 0;
83 }
84
85 spd_span = spd_index * SPD_LEN;
86 return (uintptr_t)(spd_file + spd_span);
87}
88
89int mainboard_has_dual_channel_mem(void)
90{
91 int spd_index;
92
93 spd_index = get_spd_index();
94
95 if (spd_index != HYNIX_SINGLE_CHAN && spd_index != SAMSUNG_SINGLE_CHAN
96 && spd_index != MIC_SINGLE_CHAN) {
97 printk(BIOS_INFO,
98 "Dual channel SPD detected writing second channel\n");
99 return 1;
100 }
101 return 0;
102}