blob: c43f874c92a5462974e087be8fe1d5fd01b01bc2 [file] [log] [blame]
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -05001/*
2 * Copyright 2008-2009 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>
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050010
11#include <asm/fsl_ddr_sdram.h>
12#include <asm/fsl_ddr_dimm_params.h>
13
York Sun712cf7a2011-10-03 09:19:53 -070014struct board_specific_parameters {
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050015 u32 n_ranks;
York Sun712cf7a2011-10-03 09:19:53 -070016 u32 datarate_mhz_high;
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050017 u32 clk_adjust;
18 u32 cpo;
19 u32 write_data_delay;
20 u32 force_2T;
York Sun712cf7a2011-10-03 09:19:53 -070021};
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050022
York Sun712cf7a2011-10-03 09:19:53 -070023
24/*
25 * This table contains all valid speeds we want to override with board
26 * specific parameters. datarate_mhz_high values need to be in ascending order
27 * for each n_ranks group.
28 *
29 * ranges for parameters:
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050030 * wr_data_delay = 0-6
31 * clk adjust = 0-8
32 * cpo 2-0x1E (30)
33 */
York Sun712cf7a2011-10-03 09:19:53 -070034static const struct board_specific_parameters dimm0[] = {
35 /*
36 * memory controller 0
37 * num| hi| clk| cpo|wrdata|2T
38 * ranks| mhz|adjst| | delay|
39 */
york394c46c2010-07-02 22:25:58 +000040#ifdef CONFIG_FSL_DDR2
York Sun712cf7a2011-10-03 09:19:53 -070041 {2, 549, 4, 0x1f, 2, 0},
42 {2, 680, 4, 0x1f, 3, 0},
43 {2, 850, 4, 0x1f, 4, 0},
44 {1, 549, 4, 0x1f, 2, 0},
45 {1, 680, 4, 0x1f, 3, 0},
46 {1, 850, 4, 0x1f, 4, 0},
york394c46c2010-07-02 22:25:58 +000047#else
York Sun712cf7a2011-10-03 09:19:53 -070048 {2, 850, 6, 0x1f, 4, 0},
49 {1, 850, 4, 0x1f, 4, 0},
york394c46c2010-07-02 22:25:58 +000050#endif
York Sun712cf7a2011-10-03 09:19:53 -070051 {}
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050052};
53
54void fsl_ddr_board_options(memctl_options_t *popts,
55 dimm_params_t *pdimm,
56 unsigned int ctrl_num)
57{
York Sun712cf7a2011-10-03 09:19:53 -070058 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050059 ulong ddr_freq;
60
York Sun712cf7a2011-10-03 09:19:53 -070061 if (ctrl_num) {
62 printf("Wrong parameter for controller number %d", ctrl_num);
63 return;
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050064 }
York Sun712cf7a2011-10-03 09:19:53 -070065 if (!pdimm->n_ranks)
66 return;
67
68 pbsp = dimm0;
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050069
70 /* Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
71 * freqency and n_banks specified in board_specific_parameters table.
72 */
73 ddr_freq = get_ddr_freq(0) / 1000000;
York Sun712cf7a2011-10-03 09:19:53 -070074 while (pbsp->datarate_mhz_high) {
75 if (pbsp->n_ranks == pdimm->n_ranks) {
76 if (ddr_freq <= pbsp->datarate_mhz_high) {
77 popts->clk_adjust = pbsp->clk_adjust;
78 popts->cpo_override = pbsp->cpo;
79 popts->write_data_delay =
80 pbsp->write_data_delay;
81 popts->twoT_en = pbsp->force_2T;
82 goto found;
83 }
84 pbsp_highest = pbsp;
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -050085 }
86 pbsp++;
87 }
88
York Sun712cf7a2011-10-03 09:19:53 -070089 if (pbsp_highest) {
90 printf("Error: board specific timing not found "
91 "for data rate %lu MT/s!\n"
92 "Trying to use the highest speed (%u) parameters\n",
93 ddr_freq, pbsp_highest->datarate_mhz_high);
94 popts->clk_adjust = pbsp_highest->clk_adjust;
95 popts->cpo_override = pbsp_highest->cpo;
96 popts->write_data_delay = pbsp_highest->write_data_delay;
97 popts->twoT_en = pbsp_highest->force_2T;
98 } else {
99 panic("DIMM is not supported by this board");
York Sun939e5bf2011-06-27 13:30:55 -0700100 }
101
York Sun712cf7a2011-10-03 09:19:53 -0700102found:
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -0500103 /*
104 * Factors to consider for half-strength driver enable:
105 * - number of DIMMs installed
106 */
107 popts->half_strength_driver_enable = 0;
york394c46c2010-07-02 22:25:58 +0000108 popts->wrlvl_en = 1;
109 /* Write leveling override */
110 popts->wrlvl_override = 1;
111 popts->wrlvl_sample = 0xa;
York Sun8d9207c2010-08-27 16:25:56 -0500112 popts->wrlvl_start = 0x8;
york394c46c2010-07-02 22:25:58 +0000113 /* Rtt and Rtt_WR override */
114 popts->rtt_override = 1;
115 popts->rtt_override_value = DDR3_RTT_120_OHM;
116 popts->rtt_wr_override_value = 0; /* Rtt_WR= dynamic ODT off */
Srikanth Srinivasanfeb78382009-04-03 15:36:13 -0500117}