1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2011 Freescale Semiconductor, Inc.
10 #include <asm/global_data.h>
12 #include <fsl_ddr_sdram.h>
13 #include <fsl_ddr_dimm_params.h>
14 #include <asm/fsl_law.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 struct board_specific_parameters {
20 u32 datarate_mhz_high;
29 * This table contains all valid speeds we want to override with board
30 * specific parameters. datarate_mhz_high values need to be in ascending order
31 * for each n_ranks group.
33 * ranges for parameters:
38 static const struct board_specific_parameters dimm0[] = {
41 * num| hi| clk| wrlvl | cpo |wrdata|2T
42 * ranks| mhz|adjst| start | delay|
44 {2, 750, 3, 5, 0xff, 2, 0},
45 {2, 1250, 4, 6, 0xff, 2, 0},
46 {2, 1350, 5, 7, 0xff, 2, 0},
47 {2, 1666, 5, 8, 0xff, 2, 0},
51 void fsl_ddr_board_options(memctl_options_t *popts,
53 unsigned int ctrl_num)
55 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
59 printf("Wrong parameter for controller number %d", ctrl_num);
68 * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
69 * freqency and n_banks specified in board_specific_parameters table.
71 ddr_freq = get_ddr_freq(0) / 1000000;
72 while (pbsp->datarate_mhz_high) {
73 if (pbsp->n_ranks == pdimm->n_ranks) {
74 if (ddr_freq <= pbsp->datarate_mhz_high) {
75 popts->cpo_override = pbsp->cpo;
76 popts->write_data_delay =
77 pbsp->write_data_delay;
78 popts->clk_adjust = pbsp->clk_adjust;
79 popts->wrlvl_start = pbsp->wrlvl_start;
80 popts->twot_en = pbsp->force_2t;
89 printf("Error: board specific timing not found "
90 "for data rate %lu MT/s!\n"
91 "Trying to use the highest speed (%u) parameters\n",
92 ddr_freq, pbsp_highest->datarate_mhz_high);
93 popts->cpo_override = pbsp_highest->cpo;
94 popts->write_data_delay = pbsp_highest->write_data_delay;
95 popts->clk_adjust = pbsp_highest->clk_adjust;
96 popts->wrlvl_start = pbsp_highest->wrlvl_start;
97 popts->twot_en = pbsp_highest->force_2t;
99 panic("DIMM is not supported by this board");
104 * Factors to consider for half-strength driver enable:
105 * - number of DIMMs installed
107 popts->half_strength_driver_enable = 0;
108 /* Write leveling override */
109 popts->wrlvl_override = 1;
110 popts->wrlvl_sample = 0xf;
112 /* Rtt and Rtt_WR override */
113 popts->rtt_override = 0;
115 /* Enable ZQ calibration */
118 /* DHC_EN =1, ODT = 60 Ohm */
119 popts->ddr_cdr1 = DDR_CDR1_DHC_EN;
124 phys_size_t dram_size = 0;
126 puts("Initializing....");
130 dram_size = fsl_ddr_sdram();
132 puts("no SPD and fixed parameters\n");
136 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
137 dram_size *= 0x100000;
140 gd->ram_size = dram_size;