blob: b9a2eef5a6f023ecc05b68e6b5f1abd13d863595 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekf5ff7bc2013-06-17 14:37:01 +02002/*
3 * Copyright (C) 2012 - 2013 Michal Simek <monstr@monstr.eu>
Michal Simek98d0f1f2018-01-17 07:37:47 +01004 * Copyright (C) 2012 - 2017 Xilinx, Inc. All rights reserved.
Michal Simekf5ff7bc2013-06-17 14:37:01 +02005 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <linux/string.h>
Michal Simekf5ff7bc2013-06-17 14:37:01 +02008#include <asm/io.h>
9#include <asm/arch/sys_proto.h>
10#include <asm/arch/hardware.h>
11
Siva Durga Prasad Paladugud8e4e1c2017-05-12 15:04:11 +053012#ifndef CONFIG_ZYNQ_DDRC_INIT
13void zynq_ddrc_init(void) {}
14#else
Michal Simekf5ff7bc2013-06-17 14:37:01 +020015/* Control regsiter bitfield definitions */
16#define ZYNQ_DDRC_CTRLREG_BUSWIDTH_MASK 0xC
17#define ZYNQ_DDRC_CTRLREG_BUSWIDTH_SHIFT 2
18#define ZYNQ_DDRC_CTRLREG_BUSWIDTH_16BIT 1
19
20/* ECC scrub regsiter definitions */
21#define ZYNQ_DDRC_ECC_SCRUBREG_ECC_MODE_MASK 0x7
22#define ZYNQ_DDRC_ECC_SCRUBREG_ECCMODE_SECDED 0x4
23
24void zynq_ddrc_init(void)
25{
26 u32 width, ecctype;
27
28 width = readl(&ddrc_base->ddrc_ctrl);
29 width = (width & ZYNQ_DDRC_CTRLREG_BUSWIDTH_MASK) >>
30 ZYNQ_DDRC_CTRLREG_BUSWIDTH_SHIFT;
31 ecctype = (readl(&ddrc_base->ecc_scrub) &
32 ZYNQ_DDRC_ECC_SCRUBREG_ECC_MODE_MASK);
33
34 /* ECC is enabled when memory is in 16bit mode and it is enabled */
35 if ((ecctype == ZYNQ_DDRC_ECC_SCRUBREG_ECCMODE_SECDED) &&
36 (width == ZYNQ_DDRC_CTRLREG_BUSWIDTH_16BIT)) {
Michal Simek79e67942014-05-15 09:40:14 +020037 puts("ECC enabled ");
Michal Simekf5ff7bc2013-06-17 14:37:01 +020038 /*
39 * Clear the first 1MB because it is not initialized from
40 * first stage bootloader. To get ECC to work all memory has
41 * been initialized by writing any value.
42 */
Wolfgang Denk6ae80832014-11-06 14:02:57 +010043 /* cppcheck-suppress nullPointer */
Michal Simek5d688f22014-04-25 14:19:00 +020044 memset((void *)0, 0, 1 * 1024 * 1024);
Michal Simekf5ff7bc2013-06-17 14:37:01 +020045 } else {
Michal Simek79e67942014-05-15 09:40:14 +020046 puts("ECC disabled ");
Michal Simekf5ff7bc2013-06-17 14:37:01 +020047 }
Michal Simekf5ff7bc2013-06-17 14:37:01 +020048}
Siva Durga Prasad Paladugud8e4e1c2017-05-12 15:04:11 +053049#endif