blob: 70932115f4b9ee88910f87ad415cd800758d3f31 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Timur Tabic59e1b42010-06-14 15:28:24 -05002/*
3 * Copyright 2010 Freescale Semiconductor, Inc.
4 * Authors: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
5 * Timur Tabi <timur@freescale.com>
Timur Tabic59e1b42010-06-14 15:28:24 -05006 */
7
8#include <common.h>
Timur Tabic59e1b42010-06-14 15:28:24 -05009
York Sun5614e712013-09-30 09:22:09 -070010#include <fsl_ddr_sdram.h>
11#include <fsl_ddr_dimm_params.h>
Timur Tabic59e1b42010-06-14 15:28:24 -050012
York Sun712cf7a2011-10-03 09:19:53 -070013struct board_specific_parameters {
Timur Tabic59e1b42010-06-14 15:28:24 -050014 u32 n_ranks;
York Sun712cf7a2011-10-03 09:19:53 -070015 u32 datarate_mhz_high;
Timur Tabic59e1b42010-06-14 15:28:24 -050016 u32 clk_adjust; /* Range: 0-8 */
17 u32 cpo; /* Range: 2-31 */
18 u32 write_data_delay; /* Range: 0-6 */
Priyanka Jain0dd38a32013-09-25 10:41:19 +053019 u32 force_2t;
York Sun712cf7a2011-10-03 09:19:53 -070020};
Timur Tabic59e1b42010-06-14 15:28:24 -050021
Timur Tabic59e1b42010-06-14 15:28:24 -050022/*
York Sun712cf7a2011-10-03 09:19:53 -070023 * This table contains all valid speeds we want to override with board
24 * specific parameters. datarate_mhz_high values need to be in ascending order
25 * for each n_ranks group.
Timur Tabic59e1b42010-06-14 15:28:24 -050026 */
York Sun712cf7a2011-10-03 09:19:53 -070027static const struct board_specific_parameters dimm0[] = {
28 /*
29 * memory controller 0
30 * num| hi| clk| cpo|wrdata|2T
31 * ranks| mhz|adjst| | delay|
32 */
33 {1, 549, 5, 31, 3, 0},
34 {1, 850, 5, 31, 5, 0},
35 {2, 549, 5, 31, 3, 0},
36 {2, 850, 5, 31, 5, 0},
37 {}
Timur Tabic59e1b42010-06-14 15:28:24 -050038};
39
40void fsl_ddr_board_options(memctl_options_t *popts, dimm_params_t *pdimm,
41 unsigned int ctrl_num)
42{
York Sun712cf7a2011-10-03 09:19:53 -070043 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
Timur Tabic59e1b42010-06-14 15:28:24 -050044 unsigned long ddr_freq;
45 unsigned int i;
46
York Sun712cf7a2011-10-03 09:19:53 -070047
48 if (ctrl_num) {
49 printf("Wrong parameter for controller number %d", ctrl_num);
50 return;
51 }
52 if (!pdimm->n_ranks)
53 return;
54
Timur Tabic59e1b42010-06-14 15:28:24 -050055 /* set odt_rd_cfg and odt_wr_cfg. */
56 for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
57 popts->cs_local_opts[i].odt_rd_cfg = 0;
58 popts->cs_local_opts[i].odt_wr_cfg = 1;
59 }
60
York Sun712cf7a2011-10-03 09:19:53 -070061 pbsp = dimm0;
Timur Tabic59e1b42010-06-14 15:28:24 -050062 /*
63 * Get clk_adjust, cpo, write_data_delay,2T, according to the board ddr
64 * freqency and n_banks specified in board_specific_parameters table.
65 */
66 ddr_freq = get_ddr_freq(0) / 1000000;
York Sun712cf7a2011-10-03 09:19:53 -070067 while (pbsp->datarate_mhz_high) {
68 if (pbsp->n_ranks == pdimm->n_ranks) {
69 if (ddr_freq <= pbsp->datarate_mhz_high) {
70 popts->clk_adjust = pbsp->clk_adjust;
71 popts->cpo_override = pbsp->cpo;
72 popts->write_data_delay =
73 pbsp->write_data_delay;
Priyanka Jain0dd38a32013-09-25 10:41:19 +053074 popts->twot_en = pbsp->force_2t;
York Sun712cf7a2011-10-03 09:19:53 -070075 goto found;
76 }
77 pbsp_highest = pbsp;
Timur Tabic59e1b42010-06-14 15:28:24 -050078 }
York Sun712cf7a2011-10-03 09:19:53 -070079 pbsp++;
Timur Tabic59e1b42010-06-14 15:28:24 -050080 }
81
York Sun712cf7a2011-10-03 09:19:53 -070082 if (pbsp_highest) {
83 printf("Error: board specific timing not found "
84 "for data rate %lu MT/s!\n"
85 "Trying to use the highest speed (%u) parameters\n",
86 ddr_freq, pbsp_highest->datarate_mhz_high);
87 popts->clk_adjust = pbsp->clk_adjust;
88 popts->cpo_override = pbsp->cpo;
89 popts->write_data_delay = pbsp->write_data_delay;
Priyanka Jain0dd38a32013-09-25 10:41:19 +053090 popts->twot_en = pbsp->force_2t;
York Sun712cf7a2011-10-03 09:19:53 -070091 } else {
92 panic("DIMM is not supported by this board");
93 }
94
95found:
Timur Tabic59e1b42010-06-14 15:28:24 -050096 popts->half_strength_driver_enable = 1;
97
98 /* Per AN4039, enable ZQ calibration. */
99 popts->zq_en = 1;
100
101 /*
102 * For wake-up on ARP, we need auto self refresh enabled
103 */
104 popts->auto_self_refresh_en = 1;
105 popts->sr_it = 0xb;
106}