blob: 6e55af924f2b4575dea9e7711dd55f8481da9fa5 [file] [log] [blame]
Hao Zhang7f8406d2014-07-09 23:44:49 +03001/*
2 * Keystone2: DDR3 configuration
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>
11
12#include <i2c.h>
13#include <asm/arch/ddr3.h>
14#include <asm/arch/hardware.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18/* DDR3 PHY configuration data with 1600M rate, 8GB size */
19struct ddr3_phy_config ddr3phy_1600_8g = {
20 .pllcr = 0x0001C000ul,
21 .pgcr1_mask = (IODDRM_MASK | ZCKSEL_MASK),
22 .pgcr1_val = ((1 << 2) | (1 << 7) | (1 << 23)),
23 .ptr0 = 0x42C21590ul,
24 .ptr1 = 0xD05612C0ul,
25 .ptr2 = 0, /* not set in gel */
26 .ptr3 = 0x0D861A80ul,
27 .ptr4 = 0x0C827100ul,
28 .dcr_mask = (PDQ_MASK | MPRDQ_MASK | BYTEMASK_MASK),
29 .dcr_val = ((1 << 10)),
30 .dtpr0 = 0xA19DBB66ul,
31 .dtpr1 = 0x32868300ul,
32 .dtpr2 = 0x50035200ul,
33 .mr0 = 0x00001C70ul,
34 .mr1 = 0x00000006ul,
35 .mr2 = 0x00000018ul,
36 .dtcr = 0x730035C7ul,
37 .pgcr2 = 0x00F07A12ul,
38 .zq0cr1 = 0x0000005Dul,
39 .zq1cr1 = 0x0000005Bul,
40 .zq2cr1 = 0x0000005Bul,
41 .pir_v1 = 0x00000033ul,
42 .pir_v2 = 0x0000FF81ul,
43};
44
45/* DDR3 EMIF configuration data with 1600M rate, 8GB size */
46struct ddr3_emif_config ddr3_1600_8g = {
47 .sdcfg = 0x6200CE6Aul,
48 .sdtim1 = 0x16709C55ul,
49 .sdtim2 = 0x00001D4Aul,
50 .sdtim3 = 0x435DFF54ul,
51 .sdtim4 = 0x553F0CFFul,
52 .zqcfg = 0xF0073200ul,
53 .sdrfc = 0x00001869ul,
54};
55
56#ifdef CONFIG_K2HK_EVM
57/* DDR3 PHY configuration data with 1333M rate, and 2GB size */
58struct ddr3_phy_config ddr3phy_1333_2g = {
59 .pllcr = 0x0005C000ul,
60 .pgcr1_mask = (IODDRM_MASK | ZCKSEL_MASK),
61 .pgcr1_val = ((1 << 2) | (1 << 7) | (1 << 23)),
62 .ptr0 = 0x42C21590ul,
63 .ptr1 = 0xD05612C0ul,
64 .ptr2 = 0, /* not set in gel */
65 .ptr3 = 0x0B4515C2ul,
66 .ptr4 = 0x0A6E08B4ul,
67 .dcr_mask = (PDQ_MASK | MPRDQ_MASK | BYTEMASK_MASK),
68 .dcr_val = ((1 << 10)),
69 .dtpr0 = 0x8558AA55ul,
70 .dtpr1 = 0x32857280ul,
71 .dtpr2 = 0x5002C200ul,
72 .mr0 = 0x00001A60ul,
73 .mr1 = 0x00000006ul,
74 .mr2 = 0x00000010ul,
75 .dtcr = 0x710035C7ul,
76 .pgcr2 = 0x00F065B8ul,
77 .zq0cr1 = 0x0000005Dul,
78 .zq1cr1 = 0x0000005Bul,
79 .zq2cr1 = 0x0000005Bul,
80 .pir_v1 = 0x00000033ul,
81 .pir_v2 = 0x0000FF81ul,
82};
83
84/* DDR3 EMIF configuration data with 1333M rate, and 2GB size */
85struct ddr3_emif_config ddr3_1333_2g = {
86 .sdcfg = 0x62008C62ul,
87 .sdtim1 = 0x125C8044ul,
88 .sdtim2 = 0x00001D29ul,
89 .sdtim3 = 0x32CDFF43ul,
90 .sdtim4 = 0x543F0ADFul,
91 .zqcfg = 0x70073200ul,
92 .sdrfc = 0x00001457ul,
93};
94#endif
95
96int ddr3_get_dimm_params(char *dimm_name)
97{
98 int ret;
99 int old_bus;
100 u8 spd_params[256];
101
102 i2c_init(CONFIG_SYS_DAVINCI_I2C_SPEED, CONFIG_SYS_DAVINCI_I2C_SLAVE);
103
104 old_bus = i2c_get_bus_num();
105 i2c_set_bus_num(1);
106
107 ret = i2c_read(0x53, 0, 1, spd_params, 256);
108
109 i2c_set_bus_num(old_bus);
110
111 dimm_name[0] = '\0';
112
113 if (ret) {
114 puts("Cannot read DIMM params\n");
115 return 1;
116 }
117
118 /*
119 * We need to convert spd data to dimm parameters
120 * and to DDR3 EMIF and PHY regirsters values.
121 * For now we just return DIMM type string value.
122 * Caller may use this value to choose appropriate
123 * a pre-set DDR3 configuration
124 */
125
126 strncpy(dimm_name, (char *)&spd_params[0x80], 18);
127 dimm_name[18] = '\0';
128
129 return 0;
130}