blob: 6d9a5de1c51f569d46533fa13279e9ae0e56b9e6 [file] [log] [blame]
Mingkai Hu4f1d1b72011-07-07 12:29:15 +08001/*
2 * Copyright 2011 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#include <hwconfig.h>
12#include <asm/mmu.h>
13#include <asm/fsl_ddr_sdram.h>
14#include <asm/fsl_ddr_dimm_params.h>
15#include <asm/fsl_law.h>
16
York Sun712cf7a2011-10-03 09:19:53 -070017struct board_specific_parameters {
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080018 u32 n_ranks;
York Sun712cf7a2011-10-03 09:19:53 -070019 u32 datarate_mhz_high;
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080020 u32 clk_adjust;
21 u32 wrlvl_start;
22 u32 cpo;
23 u32 write_data_delay;
24 u32 force_2T;
York Sun712cf7a2011-10-03 09:19:53 -070025};
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080026
27/*
York Sun712cf7a2011-10-03 09:19:53 -070028 * This table contains all valid speeds we want to override with board
29 * specific parameters. datarate_mhz_high values need to be in ascending order
30 * for each n_ranks group.
31 *
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080032 * ranges for parameters:
33 * wr_data_delay = 0-6
34 * clk adjust = 0-8
35 * cpo 2-0x1E (30)
36 */
York Sun712cf7a2011-10-03 09:19:53 -070037static const struct board_specific_parameters dimm0[] = {
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080038 /*
39 * memory controller 0
York Sun712cf7a2011-10-03 09:19:53 -070040 * num| hi| clk| wrlvl | cpo |wrdata|2T
41 * ranks| mhz|adjst| start | delay|
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080042 */
York Sun712cf7a2011-10-03 09:19:53 -070043 {2, 750, 3, 5, 0xff, 2, 0},
44 {2, 1250, 4, 6, 0xff, 2, 0},
45 {2, 1350, 5, 7, 0xff, 2, 0},
46 {2, 1666, 5, 8, 0xff, 2, 0},
47 {}
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080048};
49
50void fsl_ddr_board_options(memctl_options_t *popts,
51 dimm_params_t *pdimm,
52 unsigned int ctrl_num)
53{
York Sun712cf7a2011-10-03 09:19:53 -070054 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080055 ulong ddr_freq;
56
York Sun712cf7a2011-10-03 09:19:53 -070057 if (ctrl_num) {
58 printf("Wrong parameter for controller number %d", ctrl_num);
59 return;
60 }
61 if (!pdimm->n_ranks)
62 return;
63
64 pbsp = dimm0;
65
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080066 /*
67 * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
68 * freqency and n_banks specified in board_specific_parameters table.
69 */
70 ddr_freq = get_ddr_freq(0) / 1000000;
York Sun712cf7a2011-10-03 09:19:53 -070071 while (pbsp->datarate_mhz_high) {
72 if (pbsp->n_ranks == pdimm->n_ranks) {
73 if (ddr_freq <= pbsp->datarate_mhz_high) {
74 popts->cpo_override = pbsp->cpo;
75 popts->write_data_delay =
76 pbsp->write_data_delay;
77 popts->clk_adjust = pbsp->clk_adjust;
78 popts->wrlvl_start = pbsp->wrlvl_start;
79 popts->twoT_en = pbsp->force_2T;
80 goto found;
81 }
82 pbsp_highest = pbsp;
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080083 }
84 pbsp++;
85 }
86
York Sun712cf7a2011-10-03 09:19:53 -070087 if (pbsp_highest) {
88 printf("Error: board specific timing not found "
89 "for data rate %lu MT/s!\n"
90 "Trying to use the highest speed (%u) parameters\n",
91 ddr_freq, pbsp_highest->datarate_mhz_high);
92 popts->cpo_override = pbsp_highest->cpo;
93 popts->write_data_delay = pbsp_highest->write_data_delay;
94 popts->clk_adjust = pbsp_highest->clk_adjust;
95 popts->wrlvl_start = pbsp_highest->wrlvl_start;
96 popts->twoT_en = pbsp_highest->force_2T;
97 } else {
98 panic("DIMM is not supported by this board");
Mingkai Hu4f1d1b72011-07-07 12:29:15 +080099 }
100
York Sun712cf7a2011-10-03 09:19:53 -0700101found:
Mingkai Hu4f1d1b72011-07-07 12:29:15 +0800102 /*
103 * Factors to consider for half-strength driver enable:
104 * - number of DIMMs installed
105 */
106 popts->half_strength_driver_enable = 0;
107 /* Write leveling override */
108 popts->wrlvl_override = 1;
109 popts->wrlvl_sample = 0xf;
110
111 /* Rtt and Rtt_WR override */
112 popts->rtt_override = 0;
113
114 /* Enable ZQ calibration */
115 popts->zq_en = 1;
116
117 /* DHC_EN =1, ODT = 60 Ohm */
118 popts->ddr_cdr1 = DDR_CDR1_DHC_EN;
119}
120
121phys_size_t initdram(int board_type)
122{
123 phys_size_t dram_size = 0;
124
125 puts("Initializing....");
126
127 if (fsl_use_spd()) {
128 puts("using SPD\n");
129 dram_size = fsl_ddr_sdram();
130 } else {
131 puts("no SPD and fixed parameters\n");
132 return dram_size;
133 }
134
135 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
136 dram_size *= 0x100000;
137
Wolfgang Denk21cd5812011-07-25 10:13:53 +0200138 debug(" DDR: ");
Mingkai Hu4f1d1b72011-07-07 12:29:15 +0800139 return dram_size;
140}