blob: 5702b14a018dfcccd695fff0a5bb4192ac3e15a2 [file] [log] [blame]
Huayang Duanc2ef1022018-09-26 14:24:02 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2018 MediaTek 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
Huayang Duan4d15d2f2018-09-26 21:23:53 +080016#include <assert.h>
17#include <console/console.h>
18#include <soc/dramc_pi_api.h>
Huayang Duanc2ef1022018-09-26 14:24:02 +080019#include <soc/emi.h>
Huayang Duan4d15d2f2018-09-26 21:23:53 +080020#include <symbols.h>
Huayang Duanc2ef1022018-09-26 14:24:02 +080021
22void mt_mem_init(const struct sdram_params *params)
23{
Huayang Duan4d15d2f2018-09-26 21:23:53 +080024 u64 rank_size[RANK_MAX];
25
Huayang Duanc2ef1022018-09-26 14:24:02 +080026 /* memory calibration */
27 mt_set_emi(params);
Huayang Duan4d15d2f2018-09-26 21:23:53 +080028
29 if (IS_ENABLED(CONFIG_MEMORY_TEST)) {
30 size_t r;
31 u8 *addr = _dram;
32
33 dramc_get_rank_size(rank_size);
34
35 for (r = RANK_0; r < RANK_MAX; r++) {
36 int i;
37
38 if (rank_size[r] == 0)
39 break;
40
41 i = complex_mem_test(addr, 0x2000);
42
43 printk(BIOS_DEBUG, "[MEM] complex R/W mem test %s : %d\n",
44 (i == 0) ? "pass" : "fail", i);
45
46 ASSERT(i == 0);
47
48 addr += rank_size[r];
49 }
50 }
Huayang Duanc2ef1022018-09-26 14:24:02 +080051}