blob: 1ab15c98f199df73b09257e3b732f579c0b62917 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Kumar Galad5a1fb92008-08-26 21:34:55 -05002/*
3 * Copyright 2008 Freescale Semiconductor, Inc.
Kumar Galad5a1fb92008-08-26 21:34:55 -05004 */
5
6#include <common.h>
7#include <asm/io.h>
York Sunf0626592013-09-30 09:22:09 -07008#include <fsl_ddr_sdram.h>
Kumar Galad5a1fb92008-08-26 21:34:55 -05009
10#if (CONFIG_CHIP_SELECTS_PER_CTRL > 4)
11#error Invalid setting for CONFIG_CHIP_SELECTS_PER_CTRL
12#endif
13
14void fsl_ddr_set_memctl_regs(const fsl_ddr_cfg_regs_t *regs,
York Sun5e155552013-06-25 11:37:48 -070015 unsigned int ctrl_num, int step)
Kumar Galad5a1fb92008-08-26 21:34:55 -050016{
17 unsigned int i;
York Suna21803d2013-11-18 10:29:32 -080018 struct ccsr_ddr __iomem *ddr =
19 (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DDR_ADDR;
Kumar Galad5a1fb92008-08-26 21:34:55 -050020
21 if (ctrl_num != 0) {
22 printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num);
23 return;
24 }
25
26 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
27 if (i == 0) {
28 out_be32(&ddr->cs0_bnds, regs->cs[i].bnds);
29 out_be32(&ddr->cs0_config, regs->cs[i].config);
30
31 } else if (i == 1) {
32 out_be32(&ddr->cs1_bnds, regs->cs[i].bnds);
33 out_be32(&ddr->cs1_config, regs->cs[i].config);
34
35 } else if (i == 2) {
36 out_be32(&ddr->cs2_bnds, regs->cs[i].bnds);
37 out_be32(&ddr->cs2_config, regs->cs[i].config);
38
39 } else if (i == 3) {
40 out_be32(&ddr->cs3_bnds, regs->cs[i].bnds);
41 out_be32(&ddr->cs3_config, regs->cs[i].config);
42 }
43 }
44
45 out_be32(&ddr->timing_cfg_1, regs->timing_cfg_1);
46 out_be32(&ddr->timing_cfg_2, regs->timing_cfg_2);
47 out_be32(&ddr->sdram_mode, regs->ddr_sdram_mode);
48 out_be32(&ddr->sdram_interval, regs->ddr_sdram_interval);
York Sun32be34d2016-11-16 11:23:23 -080049#if defined(CONFIG_ARCH_MPC8555) || defined(CONFIG_ARCH_MPC8541)
Kumar Galad5a1fb92008-08-26 21:34:55 -050050 out_be32(&ddr->sdram_clk_cntl, regs->ddr_sdram_clk_cntl);
51#endif
52
53 /*
54 * 200 painful micro-seconds must elapse between
55 * the DDR clock setup and the DDR config enable.
56 */
57 udelay(200);
58 asm volatile("sync;isync");
59
60 out_be32(&ddr->sdram_cfg, regs->ddr_sdram_cfg);
61
62 asm("sync;isync;msync");
63 udelay(500);
64}
65
66#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Kumar Galad5a1fb92008-08-26 21:34:55 -050067/*
68 * Initialize all of memory for ECC, then enable errors.
69 */
70
71void
72ddr_enable_ecc(unsigned int dram_size)
73{
York Suna21803d2013-11-18 10:29:32 -080074 struct ccsr_ddr __iomem *ddr =
75 (struct ccsr_ddr __iomem *)(CONFIG_SYS_FSL_DDR_ADDR);
Kumar Galad5a1fb92008-08-26 21:34:55 -050076
Peter Tyser4e928b52009-06-30 17:15:48 -050077 dma_meminit(CONFIG_MEM_INIT_VALUE, dram_size);
Kumar Galad5a1fb92008-08-26 21:34:55 -050078
79 /*
80 * Enable errors for ECC.
81 */
82 debug("DMA DDR: err_disable = 0x%08x\n", ddr->err_disable);
83 ddr->err_disable = 0x00000000;
84 asm("sync;isync;msync");
85 debug("DMA DDR: err_disable = 0x%08x\n", ddr->err_disable);
86}
87
88#endif /* CONFIG_DDR_ECC && ! CONFIG_ECC_INIT_VIA_DDRCONTROLLER */