blob: 8dc249b99dc89180a76ea891ed7d3e7c13b41273 [file] [log] [blame]
Kumar Galacad506c2008-08-26 15:01:35 -05001/*
2 * Copyright 2008 Freescale Semiconductor, Inc.
3 *
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.
7 */
8
9#include <common.h>
10#include <i2c.h>
11
12#include <asm/fsl_ddr_sdram.h>
Haiying Wangfa440362008-10-03 12:36:55 -040013#include <asm/fsl_ddr_dimm_params.h>
Kumar Galacad506c2008-08-26 15:01:35 -050014
15static void
16get_spd(ddr2_spd_eeprom_t *spd, unsigned char i2c_address)
17{
18 i2c_read(i2c_address, 0, 1, (uchar *)spd, sizeof(ddr2_spd_eeprom_t));
19}
20
21unsigned int fsl_ddr_get_mem_data_rate(void)
22{
23 return get_bus_freq(0);
24}
25
26void fsl_ddr_get_spd(ddr2_spd_eeprom_t *ctrl_dimms_spd,
27 unsigned int ctrl_num)
28{
29 unsigned int i;
30 unsigned int i2c_address = 0;
31
32 for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
33 if (ctrl_num == 0 && i == 0) {
34 i2c_address = SPD_EEPROM_ADDRESS1;
35 }
36 if (ctrl_num == 0 && i == 1) {
37 i2c_address = SPD_EEPROM_ADDRESS2;
38 }
39 if (ctrl_num == 1 && i == 0) {
40 i2c_address = SPD_EEPROM_ADDRESS3;
41 }
42 if (ctrl_num == 1 && i == 1) {
43 i2c_address = SPD_EEPROM_ADDRESS4;
44 }
45 get_spd(&(ctrl_dimms_spd[i]), i2c_address);
46 }
47}
48
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040049typedef struct {
Wolfgang Denk82f15f32008-11-02 16:14:22 +010050 u32 datarate_mhz_low;
51 u32 datarate_mhz_high;
52 u32 n_ranks;
53 u32 clk_adjust;
54 u32 cpo;
55 u32 write_data_delay;
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040056} board_specific_parameters_t;
57
58/* XXX: these values need to be checked for all interleaving modes. */
59const board_specific_parameters_t board_specific_parameters[2][16] = {
60 {
61 /* memory controller 0 */
62 /* lo| hi| num| clk| cpo|wrdata */
63 /* mhz| mhz|ranks|adjst| | delay */
64 { 0, 333, 4, 7, 7, 3},
65 {334, 400, 4, 7, 9, 3},
66 {401, 549, 4, 7, 9, 3},
67 {550, 650, 4, 7, 10, 4},
68
69 { 0, 333, 3, 7, 7, 3},
70 {334, 400, 3, 7, 9, 3},
71 {401, 549, 3, 7, 9, 3},
72 {550, 650, 3, 7, 10, 4},
73
74 { 0, 333, 2, 7, 7, 3},
75 {334, 400, 2, 7, 9, 3},
76 {401, 549, 2, 7, 9, 3},
77 {550, 650, 2, 7, 10, 4},
78
79 { 0, 333, 1, 7, 7, 3},
80 {334, 400, 1, 7, 9, 3},
81 {401, 549, 1, 7, 9, 3},
82 {550, 650, 1, 7, 10, 4}
83 },
84
85 {
86 /* memory controller 1 */
Wolfgang Denk82f15f32008-11-02 16:14:22 +010087 /* lo| hi| num| clk| cpo|wrdata */
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040088 /* mhz| mhz|ranks|adjst| | delay */
89 { 0, 333, 4, 7, 7, 3},
90 {334, 400, 4, 7, 9, 3},
91 {401, 549, 4, 7, 9, 3},
92 {550, 650, 4, 7, 10, 4},
93
94 { 0, 333, 3, 7, 7, 3},
95 {334, 400, 3, 7, 9, 3},
96 {401, 549, 3, 7, 9, 3},
97 {550, 650, 3, 7, 10, 4},
98
99 { 0, 333, 2, 7, 7, 3},
100 {334, 400, 2, 7, 9, 3},
101 {401, 549, 2, 7, 9, 3},
102 {550, 650, 2, 7, 10, 4},
103
104 { 0, 333, 1, 7, 7, 3},
105 {334, 400, 1, 7, 9, 3},
106 {401, 549, 1, 7, 9, 3},
107 {550, 650, 1, 7, 10, 4}
108 }
109};
110
Haiying Wangfa440362008-10-03 12:36:55 -0400111void fsl_ddr_board_options(memctl_options_t *popts,
Haiying Wang4e0dd7f2008-10-03 12:37:57 -0400112 dimm_params_t *pdimm,
113 unsigned int ctrl_num)
Kumar Galacad506c2008-08-26 15:01:35 -0500114{
Haiying Wang4e0dd7f2008-10-03 12:37:57 -0400115 const board_specific_parameters_t *pbsp =
116 &(board_specific_parameters[ctrl_num][0]);
117 u32 num_params = sizeof(board_specific_parameters[ctrl_num]) /
118 sizeof(board_specific_parameters[0][0]);
119 u32 i;
120 u32 j;
121 ulong ddr_freq;
Kumar Galacad506c2008-08-26 15:01:35 -0500122
Haiying Wang4e0dd7f2008-10-03 12:37:57 -0400123 /* set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
124 * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
125 * there are two dimms in the controller, set odt_rd_cfg to 3 and
126 * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
Kumar Galacad506c2008-08-26 15:01:35 -0500127 */
Haiying Wang4e0dd7f2008-10-03 12:37:57 -0400128 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
129 if (i&1) { /* odd CS */
130 popts->cs_local_opts[i].odt_rd_cfg = 0;
131 popts->cs_local_opts[i].odt_wr_cfg = 0;
Wolfgang Denk82f15f32008-11-02 16:14:22 +0100132 } else { /* even CS */
Haiying Wang4e0dd7f2008-10-03 12:37:57 -0400133 if ((CONFIG_DIMM_SLOTS_PER_CTLR == 2) &&
134 (pdimm[i/2].n_ranks != 0)) {
135 popts->cs_local_opts[i].odt_rd_cfg = 3;
136 popts->cs_local_opts[i].odt_wr_cfg = 3;
137 } else {
138 popts->cs_local_opts[i].odt_rd_cfg = 0;
139 popts->cs_local_opts[i].odt_wr_cfg = 4;
140 }
141 }
142 }
Kumar Galacad506c2008-08-26 15:01:35 -0500143
Haiying Wang4e0dd7f2008-10-03 12:37:57 -0400144 /* Get clk_adjust, cpo, write_data_delay, according to the board ddr
145 * freqency and n_banks specified in board_specific_parameters table.
Kumar Galacad506c2008-08-26 15:01:35 -0500146 */
Haiying Wang4e0dd7f2008-10-03 12:37:57 -0400147 ddr_freq = fsl_ddr_get_mem_data_rate() / 1000000;
148 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
149 if (pdimm[j].n_ranks > 0) {
150 for (i = 0; i < num_params; i++) {
151 if (ddr_freq >= pbsp->datarate_mhz_low &&
152 ddr_freq <= pbsp->datarate_mhz_high &&
153 pdimm[j].n_ranks == pbsp->n_ranks) {
154 popts->clk_adjust = pbsp->clk_adjust;
155 popts->cpo_override = pbsp->cpo;
156 popts->write_data_delay =
157 pbsp->write_data_delay;
158 break;
159 }
160 pbsp++;
161 }
162 }
163 }
Kumar Galacad506c2008-08-26 15:01:35 -0500164
Dave Liua06d74c2008-11-21 16:31:43 +0800165 /* 2T timing enable */
166 popts->twoT_en = 1;
Kumar Galacad506c2008-08-26 15:01:35 -0500167}