blob: 11ca08d1a0b94f09104b1397e8a1697da5ec7ad0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Kumar Gala3ab0b2d2008-08-12 11:13:08 -05002/*
3 * Copyright 2008 Freescale Semiconductor, Inc.
Kumar Gala3ab0b2d2008-08-12 11:13:08 -05004 */
5
6#include <common.h>
Kumar Gala3ab0b2d2008-08-12 11:13:08 -05007
York Sunf0626592013-09-30 09:22:09 -07008#include <fsl_ddr_sdram.h>
9#include <fsl_ddr_dimm_params.h>
Kumar Gala3ab0b2d2008-08-12 11:13:08 -050010
York Sunb6d2ef62011-10-03 09:19:53 -070011struct board_specific_parameters {
Haiying Wangbcf35e52008-10-03 12:37:41 -040012 u32 n_ranks;
York Sunb6d2ef62011-10-03 09:19:53 -070013 u32 datarate_mhz_high;
Haiying Wangbcf35e52008-10-03 12:37:41 -040014 u32 clk_adjust;
15 u32 cpo;
16 u32 write_data_delay;
Priyanka Jain4a717412013-09-25 10:41:19 +053017 u32 force_2t;
York Sunb6d2ef62011-10-03 09:19:53 -070018};
Haiying Wangbcf35e52008-10-03 12:37:41 -040019
York Sun5e0c0702011-03-17 11:18:11 -070020/*
York Sunb6d2ef62011-10-03 09:19:53 -070021 * This table contains all valid speeds we want to override with board
22 * specific parameters. datarate_mhz_high values need to be in ascending order
23 * for each n_ranks group.
York Sun5e0c0702011-03-17 11:18:11 -070024 *
25 * For DDR2 DIMM, all combinations of clk_adjust and write_data_delay have been
26 * tested. For RDIMM, clk_adjust = 4 and write_data_delay = 3 is optimized for
27 * all clocks from 400MT/s to 800MT/s, verified with Kingston KVR800D2D8P6/2G.
28 * For UDIMM, clk_adjust = 8 and write_delay = 5 is optimized for all clocks
29 * from 400MT/s to 800MT/s, verified with Micron MT18HTF25672AY-800E1.
York Sunb6d2ef62011-10-03 09:19:53 -070030 *
31 * CPO value doesn't matter if workaround for errata 111 and 134 enabled.
Haiying Wangbcf35e52008-10-03 12:37:41 -040032 */
York Sunb6d2ef62011-10-03 09:19:53 -070033static const struct board_specific_parameters udimm0[] = {
York Sun5e0c0702011-03-17 11:18:11 -070034 /*
York Sunb6d2ef62011-10-03 09:19:53 -070035 * memory controller 0
36 * num| hi| clk| cpo|wrdata|2T
37 * ranks| mhz|adjst| | delay|
York Sun5e0c0702011-03-17 11:18:11 -070038 */
York Sunb6d2ef62011-10-03 09:19:53 -070039 {2, 333, 8, 7, 5, 0},
40 {2, 400, 8, 9, 5, 0},
41 {2, 549, 8, 11, 5, 0},
42 {2, 680, 8, 10, 5, 0},
43 {2, 850, 8, 12, 5, 1},
44 {1, 333, 6, 7, 3, 0},
45 {1, 400, 6, 9, 3, 0},
46 {1, 549, 6, 11, 3, 0},
47 {1, 680, 1, 10, 5, 0},
48 {1, 850, 1, 12, 5, 0},
49 {}
50};
Haiying Wangbcf35e52008-10-03 12:37:41 -040051
York Sunb6d2ef62011-10-03 09:19:53 -070052static const struct board_specific_parameters udimm1[] = {
York Sun5e0c0702011-03-17 11:18:11 -070053 /*
York Sunb6d2ef62011-10-03 09:19:53 -070054 * memory controller 1
55 * num| hi| clk| cpo|wrdata|2T
56 * ranks| mhz|adjst| | delay|
York Sun5e0c0702011-03-17 11:18:11 -070057 */
York Sunb6d2ef62011-10-03 09:19:53 -070058 {2, 333, 8, 7, 5, 0},
59 {2, 400, 8, 9, 5, 0},
60 {2, 549, 8, 11, 5, 0},
61 {2, 680, 8, 11, 5, 0},
62 {2, 850, 8, 13, 5, 1},
63 {1, 333, 6, 7, 3, 0},
64 {1, 400, 6, 9, 3, 0},
65 {1, 549, 6, 11, 3, 0},
66 {1, 680, 1, 11, 6, 0},
67 {1, 850, 1, 13, 6, 0},
68 {}
69};
70
71static const struct board_specific_parameters *udimms[] = {
72 udimm0,
73 udimm1,
Haiying Wangbcf35e52008-10-03 12:37:41 -040074};
75
York Sunb6d2ef62011-10-03 09:19:53 -070076static const struct board_specific_parameters rdimm0[] = {
York Sun5e0c0702011-03-17 11:18:11 -070077 /*
York Sunb6d2ef62011-10-03 09:19:53 -070078 * memory controller 0
79 * num| hi| clk| cpo|wrdata|2T
80 * ranks| mhz|adjst| | delay|
York Sun5e0c0702011-03-17 11:18:11 -070081 */
York Sunb6d2ef62011-10-03 09:19:53 -070082 {2, 333, 4, 7, 3, 0},
83 {2, 400, 4, 9, 3, 0},
84 {2, 549, 4, 11, 3, 0},
85 {2, 680, 4, 10, 3, 0},
86 {2, 850, 4, 12, 3, 1},
87 {}
88};
York Sun5e0c0702011-03-17 11:18:11 -070089
York Sunb6d2ef62011-10-03 09:19:53 -070090static const struct board_specific_parameters rdimm1[] = {
York Sun5e0c0702011-03-17 11:18:11 -070091 /*
York Sunb6d2ef62011-10-03 09:19:53 -070092 * memory controller 1
93 * num| hi| clk| cpo|wrdata|2T
94 * ranks| mhz|adjst| | delay|
York Sun5e0c0702011-03-17 11:18:11 -070095 */
York Sunb6d2ef62011-10-03 09:19:53 -070096 {2, 333, 4, 7, 3, 0},
97 {2, 400, 4, 9, 3, 0},
98 {2, 549, 4, 11, 3, 0},
99 {2, 680, 4, 11, 3, 0},
100 {2, 850, 4, 13, 3, 1},
101 {}
York Sun5e0c0702011-03-17 11:18:11 -0700102};
103
York Sunb6d2ef62011-10-03 09:19:53 -0700104static const struct board_specific_parameters *rdimms[] = {
105 rdimm0,
106 rdimm1,
107};
108
Haiying Wangfa440362008-10-03 12:36:55 -0400109void fsl_ddr_board_options(memctl_options_t *popts,
110 dimm_params_t *pdimm,
111 unsigned int ctrl_num)
Kumar Gala3ab0b2d2008-08-12 11:13:08 -0500112{
York Sunb6d2ef62011-10-03 09:19:53 -0700113 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
Haiying Wangbcf35e52008-10-03 12:37:41 -0400114 ulong ddr_freq;
York Sun5e0c0702011-03-17 11:18:11 -0700115
York Sunb6d2ef62011-10-03 09:19:53 -0700116 if (ctrl_num > 1) {
117 printf("Wrong parameter for controller number %d", ctrl_num);
York Sun5e0c0702011-03-17 11:18:11 -0700118 return;
York Sun5e0c0702011-03-17 11:18:11 -0700119 }
York Sunb6d2ef62011-10-03 09:19:53 -0700120 if (!pdimm->n_ranks)
121 return;
Kumar Gala3ab0b2d2008-08-12 11:13:08 -0500122
York Sunb6d2ef62011-10-03 09:19:53 -0700123 if (popts->registered_dimm_en)
124 pbsp = rdimms[ctrl_num];
125 else
126 pbsp = udimms[ctrl_num];
Kumar Gala3ab0b2d2008-08-12 11:13:08 -0500127
Haiying Wangbcf35e52008-10-03 12:37:41 -0400128 /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
129 * freqency and n_banks specified in board_specific_parameters table.
Kumar Gala3ab0b2d2008-08-12 11:13:08 -0500130 */
Haiying Wangbcf35e52008-10-03 12:37:41 -0400131 ddr_freq = get_ddr_freq(0) / 1000000;
York Sunb6d2ef62011-10-03 09:19:53 -0700132 while (pbsp->datarate_mhz_high) {
133 if (pbsp->n_ranks == pdimm->n_ranks) {
134 if (ddr_freq <= pbsp->datarate_mhz_high) {
135 popts->clk_adjust = pbsp->clk_adjust;
136 popts->cpo_override = pbsp->cpo;
137 popts->write_data_delay =
138 pbsp->write_data_delay;
Priyanka Jain4a717412013-09-25 10:41:19 +0530139 popts->twot_en = pbsp->force_2t;
York Sunb6d2ef62011-10-03 09:19:53 -0700140 goto found;
141 }
142 pbsp_highest = pbsp;
Haiying Wangbcf35e52008-10-03 12:37:41 -0400143 }
144 pbsp++;
145 }
Kumar Gala3ab0b2d2008-08-12 11:13:08 -0500146
York Sunb6d2ef62011-10-03 09:19:53 -0700147 if (pbsp_highest) {
148 printf("Error: board specific timing not found "
149 "for data rate %lu MT/s!\n"
150 "Trying to use the highest speed (%u) parameters\n",
151 ddr_freq, pbsp_highest->datarate_mhz_high);
152 popts->clk_adjust = pbsp->clk_adjust;
153 popts->cpo_override = pbsp->cpo;
154 popts->write_data_delay = pbsp->write_data_delay;
Priyanka Jain4a717412013-09-25 10:41:19 +0530155 popts->twot_en = pbsp->force_2t;
York Sunb6d2ef62011-10-03 09:19:53 -0700156 } else {
157 panic("DIMM is not supported by this board");
York Sun24b66e52011-06-27 13:30:55 -0700158 }
York Sun5e0c0702011-03-17 11:18:11 -0700159
York Sunb6d2ef62011-10-03 09:19:53 -0700160found:
Kumar Gala3ab0b2d2008-08-12 11:13:08 -0500161 /*
162 * Factors to consider for half-strength driver enable:
163 * - number of DIMMs installed
164 */
165 popts->half_strength_driver_enable = 0;
166}