1bfe18815SJohn Schmoller /*
2bfe18815SJohn Schmoller * Copyright 2010 Extreme Engineering Solutions, Inc.
3bfe18815SJohn Schmoller * Copyright 2007-2008 Freescale Semiconductor, Inc.
4bfe18815SJohn Schmoller *
51a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
6bfe18815SJohn Schmoller */
7bfe18815SJohn Schmoller
8bfe18815SJohn Schmoller #include <common.h>
9bfe18815SJohn Schmoller #include <i2c.h>
10bfe18815SJohn Schmoller
11*5614e71bSYork Sun #include <fsl_ddr_sdram.h>
12*5614e71bSYork Sun #include <fsl_ddr_dimm_params.h>
13bfe18815SJohn Schmoller
get_spd(ddr3_spd_eeprom_t * spd,u8 i2c_address)14c39f44dcSKumar Gala void get_spd(ddr3_spd_eeprom_t *spd, u8 i2c_address)
15bfe18815SJohn Schmoller {
16bfe18815SJohn Schmoller i2c_read(i2c_address, SPD_EEPROM_OFFSET, 2, (uchar *)spd,
17bfe18815SJohn Schmoller sizeof(ddr3_spd_eeprom_t));
18bfe18815SJohn Schmoller }
19bfe18815SJohn Schmoller
20bfe18815SJohn Schmoller /*
21bfe18815SJohn Schmoller * There are traditionally three board-specific SDRAM timing parameters
22bfe18815SJohn Schmoller * which must be calculated based on the particular PCB artwork. These are:
23bfe18815SJohn Schmoller * 1.) CPO (Read Capture Delay)
24bfe18815SJohn Schmoller * - TIMING_CFG_2 register
25bfe18815SJohn Schmoller * Source: Calculation based on board trace lengths and
26bfe18815SJohn Schmoller * chip-specific internal delays.
27bfe18815SJohn Schmoller * 2.) CLK_ADJUST (Clock and Addr/Cmd alignment control)
28bfe18815SJohn Schmoller * - DDR_SDRAM_CLK_CNTL register
29bfe18815SJohn Schmoller * Source: Signal Integrity Simulations
30bfe18815SJohn Schmoller * 3.) 2T Timing on Addr/Ctl
31bfe18815SJohn Schmoller * - TIMING_CFG_2 register
32bfe18815SJohn Schmoller * Source: Signal Integrity Simulations
33bfe18815SJohn Schmoller * Usually only needed with heavy load/very high speed (>DDR2-800)
34bfe18815SJohn Schmoller *
35bfe18815SJohn Schmoller * ====== XPedite550x DDR3-800 read delay calculations ======
36bfe18815SJohn Schmoller *
37bfe18815SJohn Schmoller * The P2020 processor provides an autoleveling option. Setting CPO to
38bfe18815SJohn Schmoller * 0x1f enables this auto configuration.
39bfe18815SJohn Schmoller */
40bfe18815SJohn Schmoller
41bfe18815SJohn Schmoller typedef struct {
42bfe18815SJohn Schmoller unsigned short datarate_mhz_low;
43bfe18815SJohn Schmoller unsigned short datarate_mhz_high;
44bfe18815SJohn Schmoller unsigned char clk_adjust;
45bfe18815SJohn Schmoller unsigned char cpo;
46bfe18815SJohn Schmoller } board_specific_parameters_t;
47bfe18815SJohn Schmoller
48bfe18815SJohn Schmoller const board_specific_parameters_t board_specific_parameters[][20] = {
49bfe18815SJohn Schmoller {
50bfe18815SJohn Schmoller /* Controller 0 */
51bfe18815SJohn Schmoller {
52bfe18815SJohn Schmoller /* DDR3-600/667 */
53bfe18815SJohn Schmoller .datarate_mhz_low = 500,
54bfe18815SJohn Schmoller .datarate_mhz_high = 750,
55bfe18815SJohn Schmoller .clk_adjust = 5,
56bfe18815SJohn Schmoller .cpo = 31,
57bfe18815SJohn Schmoller },
58bfe18815SJohn Schmoller {
59bfe18815SJohn Schmoller /* DDR3-800 */
60bfe18815SJohn Schmoller .datarate_mhz_low = 750,
61bfe18815SJohn Schmoller .datarate_mhz_high = 850,
62bfe18815SJohn Schmoller .clk_adjust = 5,
63bfe18815SJohn Schmoller .cpo = 31,
64bfe18815SJohn Schmoller },
65bfe18815SJohn Schmoller },
66bfe18815SJohn Schmoller };
67bfe18815SJohn Schmoller
fsl_ddr_board_options(memctl_options_t * popts,dimm_params_t * pdimm,unsigned int ctrl_num)68bfe18815SJohn Schmoller void fsl_ddr_board_options(memctl_options_t *popts,
69bfe18815SJohn Schmoller dimm_params_t *pdimm,
70bfe18815SJohn Schmoller unsigned int ctrl_num)
71bfe18815SJohn Schmoller {
72bfe18815SJohn Schmoller const board_specific_parameters_t *pbsp =
73bfe18815SJohn Schmoller &(board_specific_parameters[ctrl_num][0]);
74bfe18815SJohn Schmoller u32 num_params = sizeof(board_specific_parameters[ctrl_num]) /
75bfe18815SJohn Schmoller sizeof(board_specific_parameters[0][0]);
76bfe18815SJohn Schmoller u32 i;
77bfe18815SJohn Schmoller ulong ddr_freq;
78bfe18815SJohn Schmoller
79bfe18815SJohn Schmoller /*
80bfe18815SJohn Schmoller * Set odt_rd_cfg and odt_wr_cfg. If the there is only one dimm in
81bfe18815SJohn Schmoller * that controller, set odt_wr_cfg to 4 for CS0, and 0 to CS1. If
82bfe18815SJohn Schmoller * there are two dimms in the controller, set odt_rd_cfg to 3 and
83bfe18815SJohn Schmoller * odt_wr_cfg to 3 for the even CS, 0 for the odd CS.
84bfe18815SJohn Schmoller */
85bfe18815SJohn Schmoller for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
86bfe18815SJohn Schmoller if (i&1) { /* odd CS */
87bfe18815SJohn Schmoller popts->cs_local_opts[i].odt_rd_cfg = 0;
88bfe18815SJohn Schmoller popts->cs_local_opts[i].odt_wr_cfg = 0;
89bfe18815SJohn Schmoller } else { /* even CS */
90bfe18815SJohn Schmoller if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
91bfe18815SJohn Schmoller popts->cs_local_opts[i].odt_rd_cfg = 0;
92bfe18815SJohn Schmoller popts->cs_local_opts[i].odt_wr_cfg = 4;
93bfe18815SJohn Schmoller } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
94bfe18815SJohn Schmoller popts->cs_local_opts[i].odt_rd_cfg = 3;
95bfe18815SJohn Schmoller popts->cs_local_opts[i].odt_wr_cfg = 3;
96bfe18815SJohn Schmoller }
97bfe18815SJohn Schmoller }
98bfe18815SJohn Schmoller }
99bfe18815SJohn Schmoller
100bfe18815SJohn Schmoller /*
101bfe18815SJohn Schmoller * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
102bfe18815SJohn Schmoller * freqency and n_banks specified in board_specific_parameters table.
103bfe18815SJohn Schmoller */
104bfe18815SJohn Schmoller ddr_freq = get_ddr_freq(0) / 1000000;
105bfe18815SJohn Schmoller
106bfe18815SJohn Schmoller for (i = 0; i < num_params; i++) {
107bfe18815SJohn Schmoller if (ddr_freq >= pbsp->datarate_mhz_low &&
108bfe18815SJohn Schmoller ddr_freq <= pbsp->datarate_mhz_high) {
109bfe18815SJohn Schmoller popts->clk_adjust = pbsp->clk_adjust;
110bfe18815SJohn Schmoller popts->cpo_override = pbsp->cpo;
1110dd38a35SPriyanka Jain popts->twot_en = 0;
112939e5bf9SYork Sun break;
113bfe18815SJohn Schmoller }
114bfe18815SJohn Schmoller pbsp++;
115bfe18815SJohn Schmoller }
116bfe18815SJohn Schmoller
117939e5bf9SYork Sun if (i == num_params) {
118939e5bf9SYork Sun printf("Warning: board specific timing not found "
119939e5bf9SYork Sun "for data rate %lu MT/s!\n", ddr_freq);
120939e5bf9SYork Sun }
121939e5bf9SYork Sun
122bfe18815SJohn Schmoller /*
123bfe18815SJohn Schmoller * Factors to consider for half-strength driver enable:
124bfe18815SJohn Schmoller * - number of DIMMs installed
125bfe18815SJohn Schmoller */
126bfe18815SJohn Schmoller popts->half_strength_driver_enable = 0;
127bfe18815SJohn Schmoller
128bfe18815SJohn Schmoller /*
129bfe18815SJohn Schmoller * Enable on-die termination.
130bfe18815SJohn Schmoller * From the Micron Technical Node TN-41-04, RTT_Nom should typically
131bfe18815SJohn Schmoller * be 30 to 40 ohms, while RTT_WR should be 120 ohms. Setting RTT_WR
132bfe18815SJohn Schmoller * is handled in the Freescale DDR3 driver. Set RTT_Nom here.
133bfe18815SJohn Schmoller */
134bfe18815SJohn Schmoller popts->rtt_override = 1;
135bfe18815SJohn Schmoller popts->rtt_override_value = 3;
136bfe18815SJohn Schmoller }
137