blob: 09212bcee8cfd61064cf5cc488ab20fa57fdd243 [file] [log] [blame]
Timur Tabic59e1b42010-06-14 15:28:24 -05001/*
2 * Copyright 2010 Freescale Semiconductor, Inc.
3 * Authors: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
4 * Timur Tabi <timur@freescale.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Timur Tabic59e1b42010-06-14 15:28:24 -05007 */
8
9#include <common.h>
Timur Tabic59e1b42010-06-14 15:28:24 -050010
York Sun5614e712013-09-30 09:22:09 -070011#include <fsl_ddr_sdram.h>
12#include <fsl_ddr_dimm_params.h>
Timur Tabic59e1b42010-06-14 15:28:24 -050013
York Sun712cf7a2011-10-03 09:19:53 -070014struct board_specific_parameters {
Timur Tabic59e1b42010-06-14 15:28:24 -050015 u32 n_ranks;
York Sun712cf7a2011-10-03 09:19:53 -070016 u32 datarate_mhz_high;
Timur Tabic59e1b42010-06-14 15:28:24 -050017 u32 clk_adjust; /* Range: 0-8 */
18 u32 cpo; /* Range: 2-31 */
19 u32 write_data_delay; /* Range: 0-6 */
Priyanka Jain0dd38a32013-09-25 10:41:19 +053020 u32 force_2t;
York Sun712cf7a2011-10-03 09:19:53 -070021};
Timur Tabic59e1b42010-06-14 15:28:24 -050022
Timur Tabic59e1b42010-06-14 15:28:24 -050023/*
York Sun712cf7a2011-10-03 09:19:53 -070024 * This table contains all valid speeds we want to override with board
25 * specific parameters. datarate_mhz_high values need to be in ascending order
26 * for each n_ranks group.
Timur Tabic59e1b42010-06-14 15:28:24 -050027 */
York Sun712cf7a2011-10-03 09:19:53 -070028static const struct board_specific_parameters dimm0[] = {
29 /*
30 * memory controller 0
31 * num| hi| clk| cpo|wrdata|2T
32 * ranks| mhz|adjst| | delay|
33 */
34 {1, 549, 5, 31, 3, 0},
35 {1, 850, 5, 31, 5, 0},
36 {2, 549, 5, 31, 3, 0},
37 {2, 850, 5, 31, 5, 0},
38 {}
Timur Tabic59e1b42010-06-14 15:28:24 -050039};
40
41void fsl_ddr_board_options(memctl_options_t *popts, dimm_params_t *pdimm,
42 unsigned int ctrl_num)
43{
York Sun712cf7a2011-10-03 09:19:53 -070044 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
Timur Tabic59e1b42010-06-14 15:28:24 -050045 unsigned long ddr_freq;
46 unsigned int i;
47
York Sun712cf7a2011-10-03 09:19:53 -070048
49 if (ctrl_num) {
50 printf("Wrong parameter for controller number %d", ctrl_num);
51 return;
52 }
53 if (!pdimm->n_ranks)
54 return;
55
Timur Tabic59e1b42010-06-14 15:28:24 -050056 /* set odt_rd_cfg and odt_wr_cfg. */
57 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
58 popts->cs_local_opts[i].odt_rd_cfg = 0;
59 popts->cs_local_opts[i].odt_wr_cfg = 1;
60 }
61
York Sun712cf7a2011-10-03 09:19:53 -070062 pbsp = dimm0;
Timur Tabic59e1b42010-06-14 15:28:24 -050063 /*
64 * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
65 * freqency and n_banks specified in board_specific_parameters table.
66 */
67 ddr_freq = get_ddr_freq(0) / 1000000;
York Sun712cf7a2011-10-03 09:19:53 -070068 while (pbsp->datarate_mhz_high) {
69 if (pbsp->n_ranks == pdimm->n_ranks) {
70 if (ddr_freq <= pbsp->datarate_mhz_high) {
71 popts->clk_adjust = pbsp->clk_adjust;
72 popts->cpo_override = pbsp->cpo;
73 popts->write_data_delay =
74 pbsp->write_data_delay;
Priyanka Jain0dd38a32013-09-25 10:41:19 +053075 popts->twot_en = pbsp->force_2t;
York Sun712cf7a2011-10-03 09:19:53 -070076 goto found;
77 }
78 pbsp_highest = pbsp;
Timur Tabic59e1b42010-06-14 15:28:24 -050079 }
York Sun712cf7a2011-10-03 09:19:53 -070080 pbsp++;
Timur Tabic59e1b42010-06-14 15:28:24 -050081 }
82
York Sun712cf7a2011-10-03 09:19:53 -070083 if (pbsp_highest) {
84 printf("Error: board specific timing not found "
85 "for data rate %lu MT/s!\n"
86 "Trying to use the highest speed (%u) parameters\n",
87 ddr_freq, pbsp_highest->datarate_mhz_high);
88 popts->clk_adjust = pbsp->clk_adjust;
89 popts->cpo_override = pbsp->cpo;
90 popts->write_data_delay = pbsp->write_data_delay;
Priyanka Jain0dd38a32013-09-25 10:41:19 +053091 popts->twot_en = pbsp->force_2t;
York Sun712cf7a2011-10-03 09:19:53 -070092 } else {
93 panic("DIMM is not supported by this board");
94 }
95
96found:
Timur Tabic59e1b42010-06-14 15:28:24 -050097 popts->half_strength_driver_enable = 1;
98
99 /* Per AN4039, enable ZQ calibration. */
100 popts->zq_en = 1;
101
102 /*
103 * For wake-up on ARP, we need auto self refresh enabled
104 */
105 popts->auto_self_refresh_en = 1;
106 popts->sr_it = 0xb;
107}