Daisuke Nojiri | a6712f3 | 2015-01-23 10:06:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2015 Google 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. |
Daisuke Nojiri | a6712f3 | 2015-01-23 10:06:19 -0800 | [diff] [blame] | 14 | */ |
| 15 | #include <console/console.h> |
Icarus Chau | d5f551a | 2015-02-13 15:16:37 -0800 | [diff] [blame] | 16 | #include <symbols.h> |
Daisuke Nojiri | a6712f3 | 2015-01-23 10:06:19 -0800 | [diff] [blame] | 17 | #include <soc/sdram.h> |
| 18 | |
Icarus Chau | d5f551a | 2015-02-13 15:16:37 -0800 | [diff] [blame] | 19 | #define DRAM_TEST_LEN 0x8000000 |
| 20 | |
| 21 | static void test_ddr(void) |
| 22 | { |
| 23 | if (IS_ENABLED(CONFIG_CYGNUS_SDRAM_TEST_DDR)) { |
| 24 | uint32_t *test_buffer = (uint32_t *) _dram; |
| 25 | uint32_t len = DRAM_TEST_LEN; |
| 26 | uint32_t i; |
| 27 | uint32_t fail_count = 0; |
| 28 | |
| 29 | printk(BIOS_INFO, "test ddr start from 0x%p to 0x%p\n", test_buffer, |
| 30 | test_buffer + len); |
| 31 | |
| 32 | for (i = 0; i < len; i++) |
| 33 | *(test_buffer + i) = i; |
| 34 | |
| 35 | for (i = 0; i < len; i++) { |
| 36 | int val = *(test_buffer + i); |
| 37 | |
| 38 | if ((i % 0x10000) == 0) |
| 39 | printk(BIOS_INFO, "#"); |
| 40 | |
| 41 | if (i != val) { |
| 42 | printk(BIOS_ERR, "\ntest_ddr: @ 0x%p: %d != %d\n", |
| 43 | test_buffer + i, i, val); |
| 44 | fail_count++; |
| 45 | } |
| 46 | } |
| 47 | printk(BIOS_INFO, "\ntest ddr end: fail=%d\n", fail_count); |
| 48 | } |
| 49 | } |
| 50 | |
Daisuke Nojiri | a6712f3 | 2015-01-23 10:06:19 -0800 | [diff] [blame] | 51 | void sdram_init(void) |
| 52 | { |
Icarus Chau | d5f551a | 2015-02-13 15:16:37 -0800 | [diff] [blame] | 53 | printk(BIOS_INFO, "sdram initialization is in progress...\n"); |
| 54 | ddr_init2(); |
| 55 | printk(BIOS_INFO, "sdram initialization is completed.\n"); |
| 56 | |
| 57 | test_ddr(); |
Daisuke Nojiri | a6712f3 | 2015-01-23 10:06:19 -0800 | [diff] [blame] | 58 | } |
Daisuke Nojiri | 99d3956 | 2015-03-02 14:38:37 -0800 | [diff] [blame] | 59 | |
| 60 | uint32_t sdram_size_mb(void) |
| 61 | { |
| 62 | return CONFIG_DRAM_SIZE_MB; |
| 63 | } |