blob: b8bbcdf2a86ce5d8a05f18d98e456f246a50acc0 [file] [log] [blame]
Mingkai Huf354b532011-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>
York Sunf0626592013-09-30 09:22:09 -070013#include <fsl_ddr_sdram.h>
14#include <fsl_ddr_dimm_params.h>
Mingkai Huf354b532011-07-07 12:29:15 +080015#include <asm/fsl_law.h>
16
York Sunb6d2ef62011-10-03 09:19:53 -070017struct board_specific_parameters {
Mingkai Huf354b532011-07-07 12:29:15 +080018 u32 n_ranks;
York Sunb6d2ef62011-10-03 09:19:53 -070019 u32 datarate_mhz_high;
Mingkai Huf354b532011-07-07 12:29:15 +080020 u32 clk_adjust;
21 u32 wrlvl_start;
22 u32 cpo;
23 u32 write_data_delay;
Priyanka Jain4a717412013-09-25 10:41:19 +053024 u32 force_2t;
York Sunb6d2ef62011-10-03 09:19:53 -070025};
Mingkai Huf354b532011-07-07 12:29:15 +080026
27/*
York Sunb6d2ef62011-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 Huf354b532011-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 Sunb6d2ef62011-10-03 09:19:53 -070037static const struct board_specific_parameters dimm0[] = {
Mingkai Huf354b532011-07-07 12:29:15 +080038 /*
39 * memory controller 0
York Sunb6d2ef62011-10-03 09:19:53 -070040 * num| hi| clk| wrlvl | cpo |wrdata|2T
41 * ranks| mhz|adjst| start | delay|
Mingkai Huf354b532011-07-07 12:29:15 +080042 */
York Sunb6d2ef62011-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 Huf354b532011-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 Sunb6d2ef62011-10-03 09:19:53 -070054 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
Mingkai Huf354b532011-07-07 12:29:15 +080055 ulong ddr_freq;
56
York Sunb6d2ef62011-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 Huf354b532011-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 Sunb6d2ef62011-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;
Priyanka Jain4a717412013-09-25 10:41:19 +053079 popts->twot_en = pbsp->force_2t;
York Sunb6d2ef62011-10-03 09:19:53 -070080 goto found;
81 }
82 pbsp_highest = pbsp;
Mingkai Huf354b532011-07-07 12:29:15 +080083 }
84 pbsp++;
85 }
86
York Sunb6d2ef62011-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;
Priyanka Jain4a717412013-09-25 10:41:19 +053096 popts->twot_en = pbsp_highest->force_2t;
York Sunb6d2ef62011-10-03 09:19:53 -070097 } else {
98 panic("DIMM is not supported by this board");
Mingkai Huf354b532011-07-07 12:29:15 +080099 }
100
York Sunb6d2ef62011-10-03 09:19:53 -0700101found:
Mingkai Huf354b532011-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 Denkf2bbb532011-07-25 10:13:53 +0200138 debug(" DDR: ");
Mingkai Huf354b532011-07-07 12:29:15 +0800139 return dram_size;
140}