Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 - 2013 Michal Simek <monstr@monstr.eu> |
Michal Simek | 98d0f1f | 2018-01-17 07:37:47 +0100 | [diff] [blame] | 3 | * Copyright (C) 2012 - 2017 Xilinx, Inc. All rights reserved. |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/sys_proto.h> |
| 11 | #include <asm/arch/hardware.h> |
| 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Siva Durga Prasad Paladugu | d8e4e1c | 2017-05-12 15:04:11 +0530 | [diff] [blame] | 15 | #ifndef CONFIG_ZYNQ_DDRC_INIT |
| 16 | void zynq_ddrc_init(void) {} |
| 17 | #else |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 18 | /* Control regsiter bitfield definitions */ |
| 19 | #define ZYNQ_DDRC_CTRLREG_BUSWIDTH_MASK 0xC |
| 20 | #define ZYNQ_DDRC_CTRLREG_BUSWIDTH_SHIFT 2 |
| 21 | #define ZYNQ_DDRC_CTRLREG_BUSWIDTH_16BIT 1 |
| 22 | |
| 23 | /* ECC scrub regsiter definitions */ |
| 24 | #define ZYNQ_DDRC_ECC_SCRUBREG_ECC_MODE_MASK 0x7 |
| 25 | #define ZYNQ_DDRC_ECC_SCRUBREG_ECCMODE_SECDED 0x4 |
| 26 | |
| 27 | void zynq_ddrc_init(void) |
| 28 | { |
| 29 | u32 width, ecctype; |
| 30 | |
| 31 | width = readl(&ddrc_base->ddrc_ctrl); |
| 32 | width = (width & ZYNQ_DDRC_CTRLREG_BUSWIDTH_MASK) >> |
| 33 | ZYNQ_DDRC_CTRLREG_BUSWIDTH_SHIFT; |
| 34 | ecctype = (readl(&ddrc_base->ecc_scrub) & |
| 35 | ZYNQ_DDRC_ECC_SCRUBREG_ECC_MODE_MASK); |
| 36 | |
| 37 | /* ECC is enabled when memory is in 16bit mode and it is enabled */ |
| 38 | if ((ecctype == ZYNQ_DDRC_ECC_SCRUBREG_ECCMODE_SECDED) && |
| 39 | (width == ZYNQ_DDRC_CTRLREG_BUSWIDTH_16BIT)) { |
Michal Simek | 79e6794 | 2014-05-15 09:40:14 +0200 | [diff] [blame] | 40 | puts("ECC enabled "); |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 41 | /* |
| 42 | * Clear the first 1MB because it is not initialized from |
| 43 | * first stage bootloader. To get ECC to work all memory has |
| 44 | * been initialized by writing any value. |
| 45 | */ |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 46 | /* cppcheck-suppress nullPointer */ |
Michal Simek | 5d688f2 | 2014-04-25 14:19:00 +0200 | [diff] [blame] | 47 | memset((void *)0, 0, 1 * 1024 * 1024); |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 48 | } else { |
Michal Simek | 79e6794 | 2014-05-15 09:40:14 +0200 | [diff] [blame] | 49 | puts("ECC disabled "); |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 50 | } |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 51 | } |
Siva Durga Prasad Paladugu | d8e4e1c | 2017-05-12 15:04:11 +0530 | [diff] [blame] | 52 | #endif |