Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 1 | /* |
| 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 Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 11 | #include "ddr3_cfg.h" |
Khoronzhuk, Ivan | 0b86858 | 2014-07-09 19:48:40 +0300 | [diff] [blame] | 12 | #include <asm/arch/ddr3.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 14 | |
| 15 | struct pll_init_data ddr3a_333 = DDR3_PLL_333(A); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 16 | struct pll_init_data ddr3a_400 = DDR3_PLL_400(A); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 17 | |
Khoronzhuk, Ivan | 0b86858 | 2014-07-09 19:48:40 +0300 | [diff] [blame] | 18 | void ddr3_init(void) |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 19 | { |
| 20 | char dimm_name[32]; |
| 21 | |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 22 | ddr3_get_dimm_params(dimm_name); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 23 | |
| 24 | printf("Detected SO-DIMM [%s]\n", dimm_name); |
| 25 | |
| 26 | if (!strcmp(dimm_name, "18KSF1G72HZ-1G6E2 ")) { |
| 27 | init_pll(&ddr3a_400); |
| 28 | if (cpu_revision() > 0) { |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 29 | if (cpu_revision() > 1) { |
| 30 | /* PG 2.0 */ |
| 31 | /* Reset DDR3A PHY after PLL enabled */ |
| 32 | ddr3_reset_ddrphy(); |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 33 | ddr3phy_1600_8g.zq0cr1 |= 0x10000; |
| 34 | ddr3phy_1600_8g.zq1cr1 |= 0x10000; |
| 35 | ddr3phy_1600_8g.zq2cr1 |= 0x10000; |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 36 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 37 | &ddr3phy_1600_8g); |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 38 | } else { |
| 39 | /* PG 1.1 */ |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 40 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 41 | &ddr3phy_1600_8g); |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 42 | } |
| 43 | |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 44 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 45 | &ddr3_1600_8g); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 46 | printf("DRAM: Capacity 8 GiB (includes reported below)\n"); |
| 47 | } else { |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 48 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &ddr3phy_1600_8g); |
| 49 | ddr3_1600_8g.sdcfg |= 0x1000; |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 50 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 51 | &ddr3_1600_8g); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 52 | printf("DRAM: Capacity 4 GiB (includes reported below)\n"); |
| 53 | } |
| 54 | } else if (!strcmp(dimm_name, "SQR-SD3T-2G1333SED")) { |
| 55 | init_pll(&ddr3a_333); |
| 56 | if (cpu_revision() > 0) { |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 57 | if (cpu_revision() > 1) { |
| 58 | /* PG 2.0 */ |
| 59 | /* Reset DDR3A PHY after PLL enabled */ |
| 60 | ddr3_reset_ddrphy(); |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 61 | ddr3phy_1333_2g.zq0cr1 |= 0x10000; |
| 62 | ddr3phy_1333_2g.zq1cr1 |= 0x10000; |
| 63 | ddr3phy_1333_2g.zq2cr1 |= 0x10000; |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 64 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 65 | &ddr3phy_1333_2g); |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 66 | } else { |
| 67 | /* PG 1.1 */ |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 68 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 69 | &ddr3phy_1333_2g); |
Hao Zhang | 101eec5 | 2014-07-09 19:48:41 +0300 | [diff] [blame] | 70 | } |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 71 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 72 | &ddr3_1333_2g); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 73 | } else { |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 74 | ddr3_init_ddrphy(KS2_DDR3A_DDRPHYC, &ddr3phy_1333_2g); |
| 75 | ddr3_1333_2g.sdcfg |= 0x1000; |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 76 | ddr3_init_ddremif(KS2_DDR3A_EMIF_CTRL_BASE, |
Hao Zhang | b1babef | 2014-07-09 23:44:49 +0300 | [diff] [blame] | 77 | &ddr3_1333_2g); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 78 | } |
| 79 | } else { |
| 80 | printf("Unknown SO-DIMM. Cannot configure DDR3\n"); |
| 81 | while (1) |
| 82 | ; |
| 83 | } |
Murali Karicheri | 6c34382 | 2014-09-10 15:54:59 +0300 | [diff] [blame] | 84 | |
| 85 | /* Apply the workaround for PG 1.0 and 1.1 Silicons */ |
| 86 | if (cpu_revision() <= 1) |
| 87 | ddr3_err_reset_workaround(); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 88 | } |