2 * Copyright 2008 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.
12 #include <asm/fsl_ddr_sdram.h>
13 #include <asm/fsl_ddr_dimm_params.h>
15 static void get_spd(ddr2_spd_eeprom_t *spd, unsigned char i2c_address)
17 i2c_read(i2c_address, 0, 1, (uchar *)spd, sizeof(ddr2_spd_eeprom_t));
20 unsigned int fsl_ddr_get_mem_data_rate(void)
22 return get_ddr_freq(0);
25 void fsl_ddr_get_spd(ddr2_spd_eeprom_t *ctrl_dimms_spd,
26 unsigned int ctrl_num)
29 unsigned int i2c_address = 0;
31 for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
32 if (ctrl_num == 0 && i == 0) {
33 i2c_address = SPD_EEPROM_ADDRESS1;
35 if (ctrl_num == 1 && i == 0) {
36 i2c_address = SPD_EEPROM_ADDRESS2;
38 get_spd(&(ctrl_dimms_spd[i]), i2c_address);
44 u32 datarate_mhz_high;
50 } board_specific_parameters_t;
52 /* ranges for parameters:
59 /* XXX: these values need to be checked for all interleaving modes. */
60 /* XXX: No reliable dual-rank 800 MHz setting has been found. It may
61 * seem reliable, but errors will appear when memory intensive
63 /* XXX: Single rank at 800 MHz is OK. */
64 const board_specific_parameters_t board_specific_parameters[][20] = {
66 /* memory controller 0 */
67 /* lo| hi| num| clk| cpo|wrdata|2T */
68 /* mhz| mhz|ranks|adjst| | delay| */
69 { 0, 333, 2, 6, 7, 3, 0},
70 {334, 400, 2, 6, 9, 3, 0},
71 {401, 549, 2, 6, 11, 3, 0},
72 {550, 680, 2, 1, 10, 5, 0},
73 {681, 850, 2, 1, 12, 5, 1},
74 { 0, 333, 1, 6, 7, 3, 0},
75 {334, 400, 1, 6, 9, 3, 0},
76 {401, 549, 1, 6, 11, 3, 0},
77 {550, 680, 1, 1, 10, 5, 0},
78 {681, 850, 1, 1, 12, 5, 0}
82 /* memory controller 1 */
83 /* lo| hi| num| clk| cpo|wrdata|2T */
84 /* mhz| mhz|ranks|adjst| | delay| */
85 { 0, 333, 2, 6, 7, 3, 0},
86 {334, 400, 2, 6, 9, 3, 0},
87 {401, 549, 2, 6, 11, 3, 0},
88 {550, 680, 2, 1, 11, 6, 0},
89 {681, 850, 2, 1, 13, 6, 1},
90 { 0, 333, 1, 6, 7, 3, 0},
91 {334, 400, 1, 6, 9, 3, 0},
92 {401, 549, 1, 6, 11, 3, 0},
93 {550, 680, 1, 1, 11, 6, 0},
94 {681, 850, 1, 1, 13, 6, 0}
98 void fsl_ddr_board_options(memctl_options_t *popts,
100 unsigned int ctrl_num)
102 const board_specific_parameters_t *pbsp =
103 &(board_specific_parameters[ctrl_num][0]);
104 u32 num_params = sizeof(board_specific_parameters[ctrl_num]) /
105 sizeof(board_specific_parameters[0][0]);
109 /* set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
110 * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
111 * there are two dimms in the controller, set odt_rd_cfg to 3 and
112 * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
114 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
115 if (i&1) { /* odd CS */
116 popts->cs_local_opts[i].odt_rd_cfg = 0;
117 popts->cs_local_opts[i].odt_wr_cfg = 0;
118 } else { /* even CS */
119 if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
120 popts->cs_local_opts[i].odt_rd_cfg = 0;
121 popts->cs_local_opts[i].odt_wr_cfg = 4;
122 } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
123 popts->cs_local_opts[i].odt_rd_cfg = 3;
124 popts->cs_local_opts[i].odt_wr_cfg = 3;
129 /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
130 * freqency and n_banks specified in board_specific_parameters table.
132 ddr_freq = get_ddr_freq(0) / 1000000;
133 for (i = 0; i < num_params; i++) {
134 if (ddr_freq >= pbsp->datarate_mhz_low &&
135 ddr_freq <= pbsp->datarate_mhz_high &&
136 pdimm->n_ranks == pbsp->n_ranks) {
137 popts->clk_adjust = pbsp->clk_adjust;
138 popts->cpo_override = pbsp->cpo;
139 popts->write_data_delay = pbsp->write_data_delay;
140 popts->twoT_en = pbsp->force_2T;
146 * Factors to consider for half-strength driver enable:
147 * - number of DIMMs installed
149 popts->half_strength_driver_enable = 0;