Huayang Duan | c2ef102 | 2018-09-26 14:24:02 +0800 | [diff] [blame] | 1 | /* |
| 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 Duan | 4d15d2f | 2018-09-26 21:23:53 +0800 | [diff] [blame] | 16 | #include <assert.h> |
| 17 | #include <console/console.h> |
| 18 | #include <soc/dramc_pi_api.h> |
Huayang Duan | c2ef102 | 2018-09-26 14:24:02 +0800 | [diff] [blame] | 19 | #include <soc/emi.h> |
Huayang Duan | 4d15d2f | 2018-09-26 21:23:53 +0800 | [diff] [blame] | 20 | #include <symbols.h> |
Huayang Duan | c2ef102 | 2018-09-26 14:24:02 +0800 | [diff] [blame] | 21 | |
| 22 | void mt_mem_init(const struct sdram_params *params) |
| 23 | { |
Huayang Duan | 4d15d2f | 2018-09-26 21:23:53 +0800 | [diff] [blame] | 24 | u64 rank_size[RANK_MAX]; |
| 25 | |
Huayang Duan | c2ef102 | 2018-09-26 14:24:02 +0800 | [diff] [blame] | 26 | /* memory calibration */ |
| 27 | mt_set_emi(params); |
Huayang Duan | 4d15d2f | 2018-09-26 21:23:53 +0800 | [diff] [blame] | 28 | |
| 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 Duan | c2ef102 | 2018-09-26 14:24:02 +0800 | [diff] [blame] | 51 | } |