blob: b36eb27bfaa74b5f15793c7996874aa658520bb2 [file] [log] [blame]
Vitaly Andrianovef509b92014-04-04 13:16:53 -04001/*
2 * Keystone2: DDR3 initialization
3 *
4 * (C) Copyright 2012-2014
5 * Texas Instruments Incorporated, <www.ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
Hao Zhangb1babef2014-07-09 23:44:49 +030011#include "ddr3_cfg.h"
Khoronzhuk, Ivan0b868582014-07-09 19:48:40 +030012#include <asm/arch/ddr3.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040013#include <asm/arch/hardware.h>
Vitaly Andrianovef509b92014-04-04 13:16:53 -040014
15struct pll_init_data ddr3a_333 = DDR3_PLL_333(A);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040016struct pll_init_data ddr3a_400 = DDR3_PLL_400(A);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040017
Vitaly Andrianov66c98a02015-02-11 14:07:58 -050018u32 ddr3_init(void)
Vitaly Andrianovef509b92014-04-04 13:16:53 -040019{
20 char dimm_name[32];
Vitaly Andrianov66c98a02015-02-11 14:07:58 -050021 u32 ddr3_size;
Vitaly Andrianovef509b92014-04-04 13:16:53 -040022
Hao Zhangb1babef2014-07-09 23:44:49 +030023 ddr3_get_dimm_params(dimm_name);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040024
25 printf("Detected SO-DIMM [%s]\n", dimm_name);
26
27 if (!strcmp(dimm_name, "18KSF1G72HZ-1G6E2 ")) {
28 init_pll(&ddr3a_400);
29 if (cpu_revision() > 0) {
Hao Zhang101eec52014-07-09 19:48:41 +030030 if (cpu_revision() > 1) {
31 /* PG 2.0 */
32 /* Reset DDR3A PHY after PLL enabled */
33 ddr3_reset_ddrphy();
Hao Zhangb1babef2014-07-09 23:44:49 +030034 ddr3phy_1600_8g.zq0cr1 |= 0x10000;
35 ddr3phy_1600_8g.zq1cr1 |= 0x10000;
36 ddr3phy_1600_8g.zq2cr1 |= 0x10000;
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030037 ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC,
Hao Zhangb1babef2014-07-09 23:44:49 +030038 &ddr3phy_1600_8g);
Hao Zhang101eec52014-07-09 19:48:41 +030039 } else {
40 /* PG 1.1 */
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030041 ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC,
Hao Zhangb1babef2014-07-09 23:44:49 +030042 &ddr3phy_1600_8g);
Hao Zhang101eec52014-07-09 19:48:41 +030043 }
44
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030045 ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE,
Hao Zhangb1babef2014-07-09 23:44:49 +030046 &ddr3_1600_8g);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040047 printf("DRAM: Capacity 8 GiB (includes reported below)\n");
Vitaly Andrianov89f44bb2014-10-22 17:47:58 +030048 ddr3_size = 8;
Vitaly Andrianovef509b92014-04-04 13:16:53 -040049 } else {
Hao Zhangb1babef2014-07-09 23:44:49 +030050 ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &ddr3phy_1600_8g);
51 ddr3_1600_8g.sdcfg |= 0x1000;
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030052 ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE,
Hao Zhangb1babef2014-07-09 23:44:49 +030053 &ddr3_1600_8g);
Vitaly Andrianovef509b92014-04-04 13:16:53 -040054 printf("DRAM: Capacity 4 GiB (includes reported below)\n");
Vitaly Andrianov89f44bb2014-10-22 17:47:58 +030055 ddr3_size = 4;
Vitaly Andrianovef509b92014-04-04 13:16:53 -040056 }
57 } else if (!strcmp(dimm_name, "SQR-SD3T-2G1333SED")) {
58 init_pll(&ddr3a_333);
59 if (cpu_revision() > 0) {
Hao Zhang101eec52014-07-09 19:48:41 +030060 if (cpu_revision() > 1) {
61 /* PG 2.0 */
62 /* Reset DDR3A PHY after PLL enabled */
63 ddr3_reset_ddrphy();
Hao Zhangb1babef2014-07-09 23:44:49 +030064 ddr3phy_1333_2g.zq0cr1 |= 0x10000;
65 ddr3phy_1333_2g.zq1cr1 |= 0x10000;
66 ddr3phy_1333_2g.zq2cr1 |= 0x10000;
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030067 ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC,
Hao Zhangb1babef2014-07-09 23:44:49 +030068 &ddr3phy_1333_2g);
Hao Zhang101eec52014-07-09 19:48:41 +030069 } else {
70 /* PG 1.1 */
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030071 ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC,
Hao Zhangb1babef2014-07-09 23:44:49 +030072 &ddr3phy_1333_2g);
Hao Zhang101eec52014-07-09 19:48:41 +030073 }
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030074 ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE,
Hao Zhangb1babef2014-07-09 23:44:49 +030075 &ddr3_1333_2g);
Vitaly Andrianov89f44bb2014-10-22 17:47:58 +030076 ddr3_size = 2;
77 printf("DRAM: 2 GiB");
Vitaly Andrianovef509b92014-04-04 13:16:53 -040078 } else {
Hao Zhangb1babef2014-07-09 23:44:49 +030079 ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &ddr3phy_1333_2g);
80 ddr3_1333_2g.sdcfg |= 0x1000;
Khoronzhuk, Ivan3d315382014-07-09 23:44:44 +030081 ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE,
Hao Zhangb1babef2014-07-09 23:44:49 +030082 &ddr3_1333_2g);
Vitaly Andrianov89f44bb2014-10-22 17:47:58 +030083 ddr3_size = 1;
84 printf("DRAM: 1 GiB");
Vitaly Andrianovef509b92014-04-04 13:16:53 -040085 }
86 } else {
87 printf("Unknown SO-DIMM. Cannot configure DDR3\n");
88 while (1)
89 ;
90 }
Murali Karicheri6c343822014-09-10 15:54:59 +030091
92 /* Apply the workaround for PG 1.0 and 1.1 Silicons */
93 if (cpu_revision() <= 1)
94 ddr3_err_reset_workaround();
Vitaly Andrianov89f44bb2014-10-22 17:47:58 +030095
Vitaly Andrianov89f44bb2014-10-22 17:47:58 +030096 return ddr3_size;
97}