blob: 5aa11b12a46ec44619b6a0598a6929b9e6b9b29a [file] [log] [blame]
Priyanka Jain062ef1a2013-10-18 17:19:06 +05301/*
2 * Copyright 2013 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <i2c.h>
9#include <hwconfig.h>
10#include <asm/mmu.h>
York Sun5614e712013-09-30 09:22:09 -070011#include <fsl_ddr_sdram.h>
12#include <fsl_ddr_dimm_params.h>
Priyanka Jain062ef1a2013-10-18 17:19:06 +053013#include <asm/fsl_law.h>
Tang Yuantian00233522014-11-21 11:17:16 +080014#include <asm/mpc85xx_gpio.h>
Priyanka Jain062ef1a2013-10-18 17:19:06 +053015#include "ddr.h"
16
17DECLARE_GLOBAL_DATA_PTR;
18
19int fsl_ddr_get_dimm_params(dimm_params_t *pdimm,
20 unsigned int controller_number,
21 unsigned int dimm_number)
22{
23 const char dimm_model[] = "RAW timing DDR";
24
25 if ((controller_number == 0) && (dimm_number == 0)) {
26 memcpy(pdimm, &ddr_raw_timing, sizeof(dimm_params_t));
27 memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
28 memcpy(pdimm->mpart, dimm_model, sizeof(dimm_model) - 1);
29 }
30
31 return 0;
32}
33
34void fsl_ddr_board_options(memctl_options_t *popts,
35 dimm_params_t *pdimm,
36 unsigned int ctrl_num)
37{
38 const struct board_specific_parameters *pbsp, *pbsp_highest = NULL;
39 ulong ddr_freq;
40
41 if (ctrl_num > 1) {
42 printf("Not supported controller number %d\n", ctrl_num);
43 return;
44 }
45 if (!pdimm->n_ranks)
46 return;
47
48 pbsp = udimms[0];
49
Priyanka Jain96ac18c2014-02-26 09:38:37 +053050 /* Get clk_adjust according to the board ddr
Priyanka Jain062ef1a2013-10-18 17:19:06 +053051 * freqency and n_banks specified in board_specific_parameters table.
52 */
53 ddr_freq = get_ddr_freq(0) / 1000000;
54 while (pbsp->datarate_mhz_high) {
55 if (pbsp->n_ranks == pdimm->n_ranks &&
56 (pdimm->rank_density >> 30) >= pbsp->rank_gb) {
57 if (ddr_freq <= pbsp->datarate_mhz_high) {
Priyanka Jain062ef1a2013-10-18 17:19:06 +053058 popts->clk_adjust = pbsp->clk_adjust;
59 popts->wrlvl_start = pbsp->wrlvl_start;
60 popts->wrlvl_ctl_2 = pbsp->wrlvl_ctl_2;
61 popts->wrlvl_ctl_3 = pbsp->wrlvl_ctl_3;
Priyanka Jain062ef1a2013-10-18 17:19:06 +053062 goto found;
63 }
64 pbsp_highest = pbsp;
65 }
66 pbsp++;
67 }
68
69 if (pbsp_highest) {
70 printf("Error: board specific timing not found\n");
71 printf("for data rate %lu MT/s\n", ddr_freq);
72 printf("Trying to use the highest speed (%u) parameters\n",
73 pbsp_highest->datarate_mhz_high);
Priyanka Jain062ef1a2013-10-18 17:19:06 +053074 popts->clk_adjust = pbsp_highest->clk_adjust;
75 popts->wrlvl_start = pbsp_highest->wrlvl_start;
76 popts->wrlvl_ctl_2 = pbsp->wrlvl_ctl_2;
77 popts->wrlvl_ctl_3 = pbsp->wrlvl_ctl_3;
Priyanka Jain062ef1a2013-10-18 17:19:06 +053078 } else {
79 panic("DIMM is not supported by this board");
80 }
81found:
82 debug("Found timing match: n_ranks %d, data rate %d, rank_gb %d\n"
83 "\tclk_adjust %d, wrlvl_start %d, wrlvl_ctrl_2 0x%x, "
84 "wrlvl_ctrl_3 0x%x\n",
85 pbsp->n_ranks, pbsp->datarate_mhz_high, pbsp->rank_gb,
86 pbsp->clk_adjust, pbsp->wrlvl_start, pbsp->wrlvl_ctl_2,
87 pbsp->wrlvl_ctl_3);
88
89 /*
90 * Factors to consider for half-strength driver enable:
91 * - number of DIMMs installed
92 */
93 popts->half_strength_driver_enable = 0;
94 /*
95 * Write leveling override
96 */
97 popts->wrlvl_override = 1;
98 popts->wrlvl_sample = 0xf;
99
100 /*
101 * rtt and rtt_wr override
102 */
103 popts->rtt_override = 0;
104
105 /* Enable ZQ calibration */
106 popts->zq_en = 1;
107
108 /* DHC_EN =1, ODT = 75 Ohm */
Priyanka Jain92f7fed2014-09-05 15:18:31 +0530109 popts->ddr_cdr1 = DDR_CDR1_DHC_EN | DDR_CDR1_ODT(DDR_CDR_ODT_75ohm);
110 popts->ddr_cdr2 = DDR_CDR2_ODT(DDR_CDR_ODT_75ohm);
Priyanka Jain062ef1a2013-10-18 17:19:06 +0530111}
112
Tang Yuantian00233522014-11-21 11:17:16 +0800113#if defined(CONFIG_DEEP_SLEEP)
114void board_mem_sleep_setup(void)
115{
116 void __iomem *cpld_base = (void *)CONFIG_SYS_CPLD_BASE;
117
118 /* does not provide HW signals for power management */
119 clrbits_8(cpld_base + 0x17, 0x40);
120 /* Disable MCKE isolation */
121 gpio_set_value(2, 0);
122 udelay(1);
123}
124#endif
125
Priyanka Jain062ef1a2013-10-18 17:19:06 +0530126phys_size_t initdram(int board_type)
127{
128 phys_size_t dram_size;
129
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +0530130#if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_RAMBOOT_PBL)
Priyanka Jain062ef1a2013-10-18 17:19:06 +0530131 puts("Initializing....using SPD\n");
132
133 dram_size = fsl_ddr_sdram();
134
135 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
136 dram_size *= 0x100000;
137
Prabhakar Kushwaha18c01442014-04-08 19:13:56 +0530138#else
139 dram_size = fsl_ddr_sdram_size();
140#endif
Tang Yuantian00233522014-11-21 11:17:16 +0800141
142#if defined(CONFIG_DEEP_SLEEP) && !defined(CONFIG_SPL_BUILD)
143 fsl_dp_resume();
144#endif
145
Priyanka Jain062ef1a2013-10-18 17:19:06 +0530146 return dram_size;
147}