blob: 4884fa24d04ef81ff3da5958a3aebff987b5d1c1 [file] [log] [blame]
York Sun7b08d212014-06-23 15:15:56 -07001/*
2 * Copyright 2014 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <fsl_ddr_sdram.h>
9#include <fsl_ddr_dimm_params.h>
10#include "ddr.h"
11
12DECLARE_GLOBAL_DATA_PTR;
13
14void fsl_ddr_board_options(memctl_options_t *popts,
15 dimm_params_t *pdimm,
16 unsigned int ctrl_num)
17{
18 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
19 ulong ddr_freq;
20
21 if (ctrl_num > 3) {
22 printf("Not supported controller number %d\n", ctrl_num);
23 return;
24 }
25 if (!pdimm->n_ranks)
26 return;
27
28 /*
29 * we use identical timing for all slots. If needed, change the code
30 * to pbsp = rdimms[ctrl_num] or pbsp = udimms[ctrl_num];
31 */
32 if (popts->registered_dimm_en)
York Sunc7a0e302014-08-13 10:21:05 -070033 pbsp = rdimms[ctrl_num];
York Sun7b08d212014-06-23 15:15:56 -070034 else
York Sunc7a0e302014-08-13 10:21:05 -070035 pbsp = udimms[ctrl_num];
York Sun7b08d212014-06-23 15:15:56 -070036
37
38 /* Get clk_adjust, wrlvl_start, wrlvl_ctl, according to the board ddr
39 * freqency and n_banks specified in board_specific_parameters table.
40 */
41 ddr_freq = get_ddr_freq(0) / 1000000;
42 while (pbsp->datarate_mhz_high) {
43 if (pbsp->n_ranks == pdimm->n_ranks &&
44 (pdimm->rank_density >> 30) >= pbsp->rank_gb) {
45 if (ddr_freq <= pbsp->datarate_mhz_high) {
46 popts->clk_adjust = pbsp->clk_adjust;
47 popts->wrlvl_start = pbsp->wrlvl_start;
48 popts->wrlvl_ctl_2 = pbsp->wrlvl_ctl_2;
49 popts->wrlvl_ctl_3 = pbsp->wrlvl_ctl_3;
50 goto found;
51 }
52 pbsp_highest = pbsp;
53 }
54 pbsp++;
55 }
56
57 if (pbsp_highest) {
58 printf("Error: board specific timing not found for data rate %lu MT/s\n"
59 "Trying to use the highest speed (%u) parameters\n",
60 ddr_freq, pbsp_highest->datarate_mhz_high);
61 popts->clk_adjust = pbsp_highest->clk_adjust;
62 popts->wrlvl_start = pbsp_highest->wrlvl_start;
63 popts->wrlvl_ctl_2 = pbsp->wrlvl_ctl_2;
64 popts->wrlvl_ctl_3 = pbsp->wrlvl_ctl_3;
65 } else {
66 panic("DIMM is not supported by this board");
67 }
68found:
69 debug("Found timing match: n_ranks %d, data rate %d, rank_gb %d\n"
70 "\tclk_adjust %d, wrlvl_start %d, wrlvl_ctrl_2 0x%x, wrlvl_ctrl_3 0x%x\n",
71 pbsp->n_ranks, pbsp->datarate_mhz_high, pbsp->rank_gb,
72 pbsp->clk_adjust, pbsp->wrlvl_start, pbsp->wrlvl_ctl_2,
73 pbsp->wrlvl_ctl_3);
74
York Sunc7a0e302014-08-13 10:21:05 -070075 if (ctrl_num == CONFIG_DP_DDR_CTRL) {
76 /* force DDR bus width to 32 bits */
77 popts->data_bus_width = 1;
78 popts->otf_burst_chop_en = 0;
79 popts->burst_length = DDR_BL8;
York Sunf2891b62015-01-06 13:18:51 -080080 popts->bstopre = 0; /* enable auto precharge */
York Sunc7a0e302014-08-13 10:21:05 -070081 }
York Sun7b08d212014-06-23 15:15:56 -070082 /*
83 * Factors to consider for half-strength driver enable:
84 * - number of DIMMs installed
85 */
86 popts->half_strength_driver_enable = 1;
87 /*
88 * Write leveling override
89 */
90 popts->wrlvl_override = 1;
91 popts->wrlvl_sample = 0xf;
92
93 /*
94 * Rtt and Rtt_WR override
95 */
96 popts->rtt_override = 0;
97
98 /* Enable ZQ calibration */
99 popts->zq_en = 1;
100
101#ifdef CONFIG_SYS_FSL_DDR4
102 popts->ddr_cdr1 = DDR_CDR1_DHC_EN | DDR_CDR1_ODT(DDR_CDR_ODT_80ohm);
103 popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_80ohm) |
104 DDR_CDR2_VREF_OVRD(70); /* Vref = 70% */
105#else
106 /* DHC_EN =1, ODT = 75 Ohm */
107 popts->ddr_cdr1 = DDR_CDR1_DHC_EN | DDR_CDR1_ODT(DDR_CDR_ODT_75ohm);
108 popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_75ohm);
109#endif
110}
111
112#ifdef CONFIG_SYS_DDR_RAW_TIMING
113dimm_params_t ddr_raw_timing = {
114 .n_ranks = 2,
115 .rank_density = 1073741824u,
116 .capacity = 2147483648,
117 .primary_sdram_width = 64,
118 .ec_sdram_width = 0,
119 .registered_dimm = 0,
120 .mirrored_dimm = 0,
121 .n_row_addr = 14,
122 .n_col_addr = 10,
123 .n_banks_per_sdram_device = 8,
124 .edc_config = 0,
125 .burst_lengths_bitmask = 0x0c,
126
127 .tckmin_x_ps = 937,
128 .caslat_x = 0x6FC << 4, /* 14,13,11,10,9,8,7,6 */
129 .taa_ps = 13090,
130 .twr_ps = 15000,
131 .trcd_ps = 13090,
132 .trrd_ps = 5000,
133 .trp_ps = 13090,
134 .tras_ps = 33000,
135 .trc_ps = 46090,
136 .trfc_ps = 160000,
137 .twtr_ps = 7500,
138 .trtp_ps = 7500,
139 .refresh_rate_ps = 7800000,
140 .tfaw_ps = 25000,
141};
142
143int fsl_ddr_get_dimm_params(dimm_params_t *pdimm,
144 unsigned int controller_number,
145 unsigned int dimm_number)
146{
147 const char dimm_model[] = "Fixed DDR on board";
148
149 if (((controller_number == 0) && (dimm_number == 0)) ||
150 ((controller_number == 1) && (dimm_number == 0))) {
151 memcpy(pdimm, &ddr_raw_timing, sizeof(dimm_params_t));
152 memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
153 memcpy(pdimm->mpart, dimm_model, sizeof(dimm_model) - 1);
154 }
155
156 return 0;
157}
158#endif
159phys_size_t initdram(int board_type)
160{
161 phys_size_t dram_size;
162
163 puts("Initializing DDR....");
164
165 puts("using SPD\n");
166 dram_size = fsl_ddr_sdram();
167
168 return dram_size;
169}
170
171void dram_init_banksize(void)
172{
York Sunc7a0e302014-08-13 10:21:05 -0700173#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
174 phys_size_t dp_ddr_size;
175#endif
176
York Sun7b08d212014-06-23 15:15:56 -0700177 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
178 if (gd->ram_size > CONFIG_SYS_LS2_DDR_BLOCK1_SIZE) {
179 gd->bd->bi_dram[0].size = CONFIG_SYS_LS2_DDR_BLOCK1_SIZE;
180 gd->bd->bi_dram[1].start = CONFIG_SYS_DDR_BLOCK2_BASE;
181 gd->bd->bi_dram[1].size = gd->ram_size -
182 CONFIG_SYS_LS2_DDR_BLOCK1_SIZE;
183 } else {
184 gd->bd->bi_dram[0].size = gd->ram_size;
185 }
York Sunc7a0e302014-08-13 10:21:05 -0700186
187#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
188 /* initialize DP-DDR here */
189 puts("DP-DDR: ");
190 /*
191 * DDR controller use 0 as the base address for binding.
192 * It is mapped to CONFIG_SYS_DP_DDR_BASE for core to access.
193 */
194 dp_ddr_size = fsl_other_ddr_sdram(CONFIG_SYS_DP_DDR_BASE_PHY,
195 CONFIG_DP_DDR_CTRL,
196 CONFIG_DP_DDR_NUM_CTRLS,
197 CONFIG_DP_DDR_DIMM_SLOTS_PER_CTLR,
198 NULL, NULL, NULL);
199 if (dp_ddr_size) {
200 gd->bd->bi_dram[2].start = CONFIG_SYS_DP_DDR_BASE;
201 gd->bd->bi_dram[2].size = dp_ddr_size;
202 } else {
203 puts("Not detected");
204 }
205#endif
York Sun7b08d212014-06-23 15:15:56 -0700206}