blob: 00670bc5a709c89eaa55d418e7cf19d7b1e23919 [file] [log] [blame]
Kumar Galacad506c2008-08-26 15:01:35 -05001/*
York Sunb6d2ef62011-10-03 09:19:53 -07002 * Copyright 2008,2011 Freescale Semiconductor, Inc.
Kumar Galacad506c2008-08-26 15:01:35 -05003 *
Tom Rinie2378802016-01-14 22:05:13 -05004 * SPDX-License-Identifier: GPL-2.0
Kumar Galacad506c2008-08-26 15:01:35 -05005 */
6
7#include <common.h>
Kumar Galacad506c2008-08-26 15:01:35 -05008
York Sunf0626592013-09-30 09:22:09 -07009#include <fsl_ddr_sdram.h>
10#include <fsl_ddr_dimm_params.h>
Kumar Galacad506c2008-08-26 15:01:35 -050011
York Sunb6d2ef62011-10-03 09:19:53 -070012struct board_specific_parameters {
Wolfgang Denk82f15f32008-11-02 16:14:22 +010013 u32 n_ranks;
York Sunb6d2ef62011-10-03 09:19:53 -070014 u32 datarate_mhz_high;
Wolfgang Denk82f15f32008-11-02 16:14:22 +010015 u32 clk_adjust;
16 u32 cpo;
17 u32 write_data_delay;
York Sunb6d2ef62011-10-03 09:19:53 -070018};
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040019
York Sunb6d2ef62011-10-03 09:19:53 -070020/*
21 * 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.
24 */
25const struct board_specific_parameters dimm0[] = {
26 /*
27 * memory controller 0
28 * num| hi| clk| cpo|wrdata|2T
29 * ranks| mhz|adjst| | delay|
30 */
31 {4, 333, 7, 7, 3},
32 {4, 549, 7, 9, 3},
33 {4, 650, 7, 10, 4},
34 {2, 333, 7, 7, 3},
35 {2, 549, 7, 9, 3},
36 {2, 650, 7, 10, 4},
37 {1, 333, 7, 7, 3},
38 {1, 549, 7, 9, 3},
39 {1, 650, 7, 10, 4},
40 {}
41};
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040042
York Sunb6d2ef62011-10-03 09:19:53 -070043/*
44 * The two slots have slightly different timing. The center values are good
45 * for both slots. We use identical speed tables for them. In future use, if
46 * DIMMs have fewer center values that require two separated tables, copy the
47 * udimm0 table to udimm1 and make changes to clk_adjust and wrlvl_start.
48 */
49const struct board_specific_parameters *dimms[] = {
50 dimm0,
51 dimm0,
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040052};
53
Haiying Wangfa440362008-10-03 12:36:55 -040054void fsl_ddr_board_options(memctl_options_t *popts,
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040055 dimm_params_t *pdimm,
56 unsigned int ctrl_num)
Kumar Galacad506c2008-08-26 15:01:35 -050057{
York Sunb6d2ef62011-10-03 09:19:53 -070058 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
59 unsigned int i;
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040060 ulong ddr_freq;
Kumar Galacad506c2008-08-26 15:01:35 -050061
York Sunb6d2ef62011-10-03 09:19:53 -070062 if (ctrl_num > 1) {
63 printf("Wrong parameter for controller number %d", ctrl_num);
64 return;
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040065 }
York Sunb6d2ef62011-10-03 09:19:53 -070066 for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
67 if (pdimm[i].n_ranks)
68 break;
69 }
70 if (i >= CONFIG_DIMM_SLOTS_PER_CTLR) /* no DIMM */
71 return;
72
73 pbsp = dimms[ctrl_num];
Kumar Galacad506c2008-08-26 15:01:35 -050074
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040075 /* Get clk_adjust, cpo, write_data_delay, according to the board ddr
76 * freqency and n_banks specified in board_specific_parameters table.
Kumar Galacad506c2008-08-26 15:01:35 -050077 */
Kumar Galab78c7bf2011-01-31 20:36:02 -060078 ddr_freq = get_ddr_freq(0) / 1000000;
York Sunb6d2ef62011-10-03 09:19:53 -070079 while (pbsp->datarate_mhz_high) {
80 if (pbsp->n_ranks == pdimm[i].n_ranks) {
81 if (ddr_freq <= pbsp->datarate_mhz_high) {
82 popts->clk_adjust = pbsp->clk_adjust;
83 popts->cpo_override = pbsp->cpo;
84 popts->write_data_delay =
85 pbsp->write_data_delay;
86 goto found;
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040087 }
York Sunb6d2ef62011-10-03 09:19:53 -070088 pbsp_highest = pbsp;
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040089 }
York Sunb6d2ef62011-10-03 09:19:53 -070090 pbsp++;
Haiying Wang4e0dd7f2008-10-03 12:37:57 -040091 }
Kumar Galacad506c2008-08-26 15:01:35 -050092
York Sunb6d2ef62011-10-03 09:19:53 -070093 if (pbsp_highest) {
94 printf("Error: board specific timing not found "
95 "for data rate %lu MT/s!\n"
96 "Trying to use the highest speed (%u) parameters\n",
97 ddr_freq, pbsp_highest->datarate_mhz_high);
98 popts->clk_adjust = pbsp_highest->clk_adjust;
99 popts->cpo_override = pbsp_highest->cpo;
100 popts->write_data_delay = pbsp_highest->write_data_delay;
101 } else {
102 panic("DIMM is not supported by this board");
York Sun24b66e52011-06-27 13:30:55 -0700103 }
104
York Sunb6d2ef62011-10-03 09:19:53 -0700105found:
Dave Liua06d74c2008-11-21 16:31:43 +0800106 /* 2T timing enable */
Priyanka Jain4a717412013-09-25 10:41:19 +0530107 popts->twot_en = 1;
Kumar Galacad506c2008-08-26 15:01:35 -0500108}