2 * Copyright 2008-2011 Freescale Semiconductor, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * Version 2 as published by the Free Software Foundation.
10 #include <asm/fsl_law.h>
15 * Round mclk_ps to nearest 10 ps in memory controller code.
17 * If an imprecise data rate is too high due to rounding error
18 * propagation, compute a suitably rounded mclk_ps to compute
19 * a working memory controller configuration.
21 unsigned int get_memory_clk_period_ps(void)
25 mclk_ps = 2000000000000ULL / get_ddr_freq(0);
26 /* round to nearest 10 ps */
27 return 10 * ((mclk_ps + 5) / 10);
30 /* Convert picoseconds into DRAM clock cycles (rounding up if needed). */
31 unsigned int picos_to_mclk(unsigned int picos)
33 const unsigned long long ULL_2e12 = 2000000000000ULL;
34 const unsigned long long ULL_8Fs = 0xFFFFFFFFULL;
35 unsigned long long clks;
36 unsigned long long clks_temp;
41 clks = get_ddr_freq(0) * (unsigned long long) picos;
43 clks = clks / ULL_2e12;
44 if (clks_temp % ULL_2e12) {
52 return (unsigned int) clks;
55 unsigned int mclk_to_picos(unsigned int mclk)
57 return get_memory_clk_period_ps() * mclk;
61 __fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params,
62 unsigned int memctl_interleaved,
63 unsigned int ctrl_num)
65 unsigned long long base = memctl_common_params->base_address;
66 unsigned long long size = memctl_common_params->total_mem;
69 * If no DIMMs on this controller, do not proceed any further.
71 if (!memctl_common_params->ndimms_present) {
75 #if !defined(CONFIG_PHYS_64BIT)
76 if (base >= CONFIG_MAX_MEM_MAPPED)
78 if ((base + size) >= CONFIG_MAX_MEM_MAPPED)
79 size = CONFIG_MAX_MEM_MAPPED - base;
84 * Set up LAW for DDR controller 1 space.
86 unsigned int lawbar1_target_id = memctl_interleaved
87 ? LAW_TRGT_IF_DDR_INTRLV : LAW_TRGT_IF_DDR_1;
89 if (set_ddr_laws(base, size, lawbar1_target_id) < 0) {
90 printf("%s: ERROR (ctrl #0, intrlv=%d)\n", __func__,
94 } else if (ctrl_num == 1) {
95 if (set_ddr_laws(base, size, LAW_TRGT_IF_DDR_2) < 0) {
96 printf("%s: ERROR (ctrl #1)\n", __func__);
100 printf("%s: unexpected DDR controller number (%u)\n", __func__,
105 __attribute__((weak, alias("__fsl_ddr_set_lawbar"))) void
106 fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params,
107 unsigned int memctl_interleaved,
108 unsigned int ctrl_num);
110 void board_add_ram_info(int use_default)
112 #if defined(CONFIG_MPC85xx)
113 volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
114 #elif defined(CONFIG_MPC86xx)
115 volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC86xx_DDR_ADDR);
117 #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
118 uint32_t cs0_config = in_be32(&ddr->cs0_config);
120 uint32_t sdram_cfg = in_be32(&ddr->sdram_cfg);
124 switch ((sdram_cfg & SDRAM_CFG_SDRAM_TYPE_MASK) >>
125 SDRAM_CFG_SDRAM_TYPE_SHIFT) {
126 case SDRAM_TYPE_DDR1:
129 case SDRAM_TYPE_DDR2:
132 case SDRAM_TYPE_DDR3:
140 if (sdram_cfg & SDRAM_CFG_32_BE)
142 else if (sdram_cfg & SDRAM_CFG_16_BE)
147 /* Calculate CAS latency based on timing cfg values */
148 cas_lat = ((in_be32(&ddr->timing_cfg_1) >> 16) & 0xf) + 1;
149 if ((in_be32(&ddr->timing_cfg_3) >> 12) & 1)
151 printf(", CL=%d", cas_lat >> 1);
155 if (sdram_cfg & SDRAM_CFG_ECC_EN)
160 #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
161 if (cs0_config & 0x20000000) {
163 puts(" DDR Controller Interleaving Mode: ");
165 switch ((cs0_config >> 24) & 0xf) {
166 case FSL_DDR_CACHE_LINE_INTERLEAVING:
169 case FSL_DDR_PAGE_INTERLEAVING:
172 case FSL_DDR_BANK_INTERLEAVING:
175 case FSL_DDR_SUPERBANK_INTERLEAVING:
185 if ((sdram_cfg >> 8) & 0x7f) {
187 puts(" DDR Chip-Select Interleaving Mode: ");
188 switch(sdram_cfg >> 8 & 0x7f) {
189 case FSL_DDR_CS0_CS1_CS2_CS3:
190 puts("CS0+CS1+CS2+CS3");
192 case FSL_DDR_CS0_CS1:
195 case FSL_DDR_CS2_CS3:
198 case FSL_DDR_CS0_CS1_AND_CS2_CS3:
199 puts("CS0+CS1 and CS2+CS3");