blob: 05c050cee44061b72bd10b56790690897b44428c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04002/*
3 * Keystone2: DDR3 initialization
4 *
5 * (C) Copyright 2012-2014
6 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04007 */
8
Hao Zhang7f8406d2014-07-09 23:44:49 +03009#include "ddr3_cfg.h"
Khoronzhuk, Ivan50df5cc2014-07-09 19:48:40 +030010#include <asm/arch/ddr3.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040011#include <asm/arch/hardware.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040012
13struct pll_init_data ddr3a_333 = DDR3_PLL_333(A);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040014struct pll_init_data ddr3a_400 = DDR3_PLL_400(A);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040015
Vitaly Andrianova9554d62015-02-11 14:07:58 -050016u32 ddr3_init(void)
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040017{
Vitaly Andrianova9554d62015-02-11 14:07:58 -050018 u32 ddr3_size;
Vitaly Andrianovead26f62016-03-04 10:36:42 -060019 struct ddr3_spd_cb spd_cb;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040020
Vitaly Andrianovead26f62016-03-04 10:36:42 -060021 if (ddr3_get_dimm_params_from_spd(&spd_cb)) {
22 printf("Sorry, I don't know how to configure DDR3A.\n"
23 "Bye :(\n");
24 for (;;)
25 ;
26 }
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040027
Vitaly Andrianovead26f62016-03-04 10:36:42 -060028 printf("Detected SO-DIMM [%s]\n", spd_cb.dimm_name);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040029
Vitaly Andrianovead26f62016-03-04 10:36:42 -060030 if ((cpu_revision() > 1) ||
31 (__raw_readl(KS2_RSTCTRL_RSTYPE) & 0x1)) {
32 printf("DDR3 speed %d\n", spd_cb.ddrspdclock);
33 if (spd_cb.ddrspdclock == 1600)
34 init_pll(&ddr3a_400);
35 else
36 init_pll(&ddr3a_333);
37 }
Hao Zhangd6c508c2014-07-09 19:48:41 +030038
Vitaly Andrianovead26f62016-03-04 10:36:42 -060039 if (cpu_revision() > 0) {
40 if (cpu_revision() > 1) {
41 /* PG 2.0 */
42 /* Reset DDR3A PHY after PLL enabled */
43 ddr3_reset_ddrphy();
44 spd_cb.phy_cfg.zq0cr1 |= 0x10000;
45 spd_cb.phy_cfg.zq1cr1 |= 0x10000;
46 spd_cb.phy_cfg.zq2cr1 |= 0x10000;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040047 }
Vitaly Andrianovead26f62016-03-04 10:36:42 -060048 ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &spd_cb.phy_cfg);
49
50 ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, &spd_cb.emif_cfg);
51
52 ddr3_size = spd_cb.ddr_size_gbyte;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040053 } else {
Vitaly Andrianovead26f62016-03-04 10:36:42 -060054 ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &spd_cb.phy_cfg);
55 spd_cb.emif_cfg.sdcfg |= 0x1000;
56 ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, &spd_cb.emif_cfg);
57 ddr3_size = spd_cb.ddr_size_gbyte / 2;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040058 }
Vitaly Andrianovead26f62016-03-04 10:36:42 -060059 printf("DRAM: %d GiB (includes reported below)\n", ddr3_size);
Murali Karicheri39f45202014-09-10 15:54:59 +030060
61 /* Apply the workaround for PG 1.0 and 1.1 Silicons */
62 if (cpu_revision() <= 1)
63 ddr3_err_reset_workaround();
Vitaly Andrianov19173012014-10-22 17:47:58 +030064
Vitaly Andrianov19173012014-10-22 17:47:58 +030065 return ddr3_size;
66}