blob: f47b24f348b5cc2f25939fb2abde17baf7dbb864 [file] [log] [blame]
Ionela Voinescud6aaca92015-01-19 01:03:44 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Imagination Technologies
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include <stdint.h>
23#include <arch/cpu.h>
24#include <delay.h>
25#include <arch/io.h>
26#include <soc/ddr_init.h>
27#include <timer.h>
28
29#define MAX_WAIT_MICROS 100000
30
31#define TOPLEVEL_REGS 0xB8149000
32
33#define DDR_CTRL_OFFSET (0x0020)
34#define DDR_CLK_EN_MASK (0x00000002)
35#define DDR_CLK_EN_SHIFT (1)
36#define DDR_CLK_EN_LENGTH (1)
37
38#define DDR_PCTL 0xB8180000
39#define DDR_PCTL_TOGCNT1U_OFFSET (0x00C0)
40#define DDR_PCTL_TINIT_OFFSET (0x00C4)
41#define DDR_PCTL_TRSTH_OFFSET (0x00C8)
42#define DDR_PCTL_TOGG_CNTR_100NS_OFFSET (0x00CC)
43#define DDR_PCTL_MCFG_OFFSET (0x0080)
44#define DDR_PCTL_MCFG1_OFFSET (0x007C)
45#define DDR_PCTL_MSTAT_OFFSET (0x0088)
46#define DDR_PCTL_DFISTAT0_OFFSET (0x02C0)
47#define DDR_PCTL_POWCTL_OFFSET (0x0044)
48#define DDR_PCTL_POWSTAT_OFFSET (0x0048)
49#define DDR_PCTL_DTUAWDT_OFFSET (0x00B0)
50#define DDR_PCTL_TREFI_OFFSET (0x00D0)
51#define DDR_PCTL_TMRD_OFFSET (0x00D4)
52#define DDR_PCTL_TRFC_OFFSET (0x00D8)
53#define DDR_PCTL_TRP_OFFSET (0x00DC)
54#define DDR_PCTL_TAL_OFFSET (0x00E4)
55#define DDR_PCTL_TCL_OFFSET (0x00E8)
56#define DDR_PCTL_TCWL_OFFSET (0x00EC)
57#define DDR_PCTL_TRAS_OFFSET (0x00F0)
58#define DDR_PCTL_TRC_OFFSET (0x00F4)
59#define DDR_PCTL_TRCD_OFFSET (0x00F8)
60#define DDR_PCTL_TRRD_OFFSET (0x00FC)
61#define DDR_PCTL_TRTP_OFFSET (0x0100)
62#define DDR_PCTL_TWR_OFFSET (0x0104)
63#define DDR_PCTL_TWTR_OFFSET (0x0108)
64#define DDR_PCTL_TEXSR_OFFSET (0x010C)
65#define DDR_PCTL_TXP_OFFSET (0x0110)
66#define DDR_PCTL_TDQS_OFFSET (0x0120)
67#define DDR_PCTL_TXPDLL_OFFSET (0x0114)
68#define DDR_PCTL_TRTW_OFFSET (0x00E0)
69#define DDR_PCTL_TCKE_OFFSET (0x012C)
70#define DDR_PCTL_TMOD_OFFSET (0x0130)
71#define DDR_PCTL_TCKESR_OFFSET (0x0140)
72#define DDR_PCTL_SCFG_OFFSET (0x0000)
73#define DDR_PCTL_DFIWRLAT_OFFSET (0x0254)
74#define DDR_PCTL_DFITRDDATAEN_OFFSET (0x0260)
75#define DDR_PCTL_DFITPHYWRDATA_OFFSET (0x0250)
76#define DDR_PCTL_DFITPHYRDLAT_OFFSET (0x0264)
77#define DDR_PCTL_SCTL_OFFSET (0x0004)
78#define DDR_PCTL_STAT_OFFSET (0x0008)
79#define DDR_PCTL_DFISTCFG0_OFFSET (0x02C4)
80#define DDR_PCTL_DFISTCFG1_OFFSET (0x02C8)
81#define DDR_PCTL_DFISTCFG2_OFFSET (0x02D8)
82#define DDR_PCTL_DFILPCFG0_OFFSET (0x02F0)
83#define DDR_PCTL_DFIODTCFG_OFFSET (0x0244)
84#define DDR_PCTL_DFIODTCFG1_OFFSET (0x0248)
85#define DDR_PCTL_MCMD_OFFSET (0x0040)
86#define DDR_PCTL_DFIUPDCFG_OFFSET (0x0290)
87#define DDR_PCTL_CCFG_OFFSET (0x0480)
88#define DDR_PCTL_DCFG_OFFSET (0x0484)
89#define DDR_PCTL_PCFG0_OFFSET (0x0400)
90#define DDR_PCTL_DTUWACTL_OFFSET (0x0200)
91#define DDR_PCTL_DTURACTL_OFFSET (0x0204)
92#define DDR_PCTL_DTUCFG_OFFSET (0x0208)
93#define DDR_PCTL_DTUECTL_OFFSET (0x020C)
94#define DDR_PCTL_DTUWD0_OFFSET (0x0210)
95#define DDR_PCTL_DTUWD1_OFFSET (0x0214)
96#define DDR_PCTL_DTUWD2_OFFSET (0x0218)
97#define DDR_PCTL_DTUWD3_OFFSET (0x021C)
98#define DDR_PCTL_CCFG1_OFFSET (0x048C)
99
100#define DDR_PHY 0xB8180800
101#define DDRPHY_DCR_OFFSET (0x0030)
102#define DDRPHY_MR_OFFSET (0x0040)
103#define DDRPHY_EMR_OFFSET (0x0044)
104#define DDRPHY_EMR2_OFFSET (0x0048)
105#define DDRPHY_DSGCR_OFFSET (0x002C)
106#define DDRPHY_DTPR0_OFFSET (0x0034)
107#define DDRPHY_DTPR1_OFFSET (0x0038)
108#define DDRPHY_DTPR2_OFFSET (0x003C)
109#define DDRPHY_PTR0_OFFSET (0x0018)
110#define DDRPHY_PTR1_OFFSET (0x001C)
111#define DDRPHY_PGSR_OFFSET (0x000C)
112#define DDRPHY_PIR_OFFSET (0x0004)
113#define DDRPHY_BISTRR_OFFSET (0x0100)
114#define DDRPHY_BISTWCR_OFFSET (0x010C)
115#define DDRPHY_BISTAR0_OFFSET (0x0114)
116#define DDRPHY_BISTAR1_OFFSET (0x0118)
117#define DDRPHY_BISTAR2_OFFSET (0x011C)
118#define DDRPHY_BISTGSR_OFFSET (0x0124)
119#define DDRPHY_BISTUDPR_OFFSET (0x0120)
120#define DDRPHY_DLLGCR_OFFSET (0x0010)
121
Ionela Voinescu823f6072015-03-05 17:25:48 +0000122#define BL8 0
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000123
124#define DDR_TIMEOUT_VALUE_US 100000
125
126static int wait_for_completion(u32 reg, u32 exp_val)
127{
128 struct stopwatch sw;
129
130 stopwatch_init_usecs_expire(&sw, DDR_TIMEOUT_VALUE_US);
131 while (read32(reg) != exp_val) {
132 if (stopwatch_expired(&sw))
133 return DDR_TIMEOUT;
134 }
135 return 0;
136}
137
138/*
139 * Configuration for the Winbond W972GG6JB-25 part using
140 * Synopsys DDR uMCTL and DDR Phy
141 */
142int init_ddr2(void)
143{
144
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000145 /*
146 * Reset the AXI bridge and DDR Controller in case any spurious
147 * writes have already happened to DDR - note must be done together,
148 * not sequentially
149 */
150 write32(TOPLEVEL_REGS + DDR_CTRL_OFFSET, 0x00000000);
151 write32(TOPLEVEL_REGS + DDR_CTRL_OFFSET, 0x0000000F);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000152 /*
153 * Dummy read to fence the access between the reset above
154 * and thw DDR controller writes below
155 */
156 read32(TOPLEVEL_REGS + DDR_CTRL_OFFSET);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000157 /* Timings for 400MHz
158 * therefore 200MHz (5ns) uMCTL (Internal) Rate
159 */
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000160 /* TOGCNT1U: Toggle Counter 1U Register: 1us 200h C8h */
161 write32(DDR_PCTL + DDR_PCTL_TOGCNT1U_OFFSET, 0x000000C8);
162 /* TINIT: t_init Timing Register: at least 200us 200h C8h */
163 write32(DDR_PCTL + DDR_PCTL_TINIT_OFFSET, 0x000000C8);
164 /* TRSTH: Reset High Time Register DDR3 ONLY */
165 write32(DDR_PCTL + DDR_PCTL_TRSTH_OFFSET, 0x00000000);
166 /* TOGCNT100N: Toggle Counter 100N Register: 20d, 14h*/
167 write32(DDR_PCTL + DDR_PCTL_TOGG_CNTR_100NS_OFFSET, 0x00000014);
168 /* DTUAWDT DTU Address Width Register
169 * 1:0 column_addr_width Def 10 - 7 3 10 bits
170 * 4:3 bank_addr_width Def 3 - 2 1 3 bits (8 bank)
171 * 7:6 row_addr_width Def 14 - 13 1 3 bits
172 * 10:9 number_ranks Def 1 - 1 0 0 1 Rank
173 */
174 write32(DDR_PCTL + DDR_PCTL_DTUAWDT_OFFSET, 0x0000004B);
175 /* MCFG
176 * 0 BL 0 = 4 1 = 8
177 * 1 RDRIMM 0
178 * 2 BL8 Burst Terminate 0
179 * 3 2T = 0
180 * 4 Multi Rank 0
181 * 5 DDR3 En 0
182 * 6 LPDDR S4 En
183 * 7 BST En 0, 1 for LPDDR2/3
184 * 15:8 Power down Idle, passed by argument
185 * 16 Power Down Type, passed by argument
186 * 17 Power Down Exit 0 = slow, 1 = fast, pba
187 * 19:18 tFAW 45ns = 9 clk 5*2 -1 1h
188 * 21:20 mDDR/LPDDR2 BL 0
189 * 23:22 mDDR/LPDDR2 Enable 0
190 * 31:24 mDDR/LPDDR2/3 Dynamic Clock Stop 0
191 */
192 write32(DDR_PCTL + DDR_PCTL_MCFG_OFFSET,
193 0x00060000 | (BL8 ? 0x1 : 0x0));
194 /* MCFG1: Memory Configuration-1 Register
195 * c7:0 sr_idle Self Refresh Idle Entery 32 * nclks 14h, set 0 for BUB
196 * 10:8 Fine tune MCFG.19:18 -1
197 * 15:11 Reserved
198 * 23:16 Hardware Idle Period NA 0
199 * 30:24 Reserved
200 * 31 c_active_in_pin exit auto clk stop NA 0
201 */
202 write32(DDR_PCTL + DDR_PCTL_MCFG1_OFFSET, 0x00000100);
203 /* DCR DRAM Config
204 * 2:0 SDRAM => DDR2 2
205 * 3 DDR 8 Bank 1
206 * 6:4 Primary DQ DDR3 Only 0
207 * 7 Multi-Purpose Register DDR3 Only 0
208 * 9:8 DDRTYPE LPDDR2 00
209 * 26:10 Reserved
210 * 27 NOSRA No Simultaneous Rank Access 0
211 * 28 DDR 2T 0
212 * 29 UDIMM NA 0
213 * 30 RDIMM NA 0
214 * 31 TPD LPDDR2 0
215 */
216 write32(DDR_PHY + DDRPHY_DCR_OFFSET, 0x0000000A);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000217 /* Generate to use with PHY and PCTL
Ionela Voinescu59074ff2015-03-05 16:40:07 +0000218 * MR0 : MR Register, bits 12:0 imported dfrom MR
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000219 * 2:0 BL 8 011
220 * 3 BT Sequential 0 Interleaved 1 = 0
221 * 6:4 CL 6
222 * 7 TM Normal 0
223 * 8 DLL Reset 1 (self Clearing)
224 * 11:9 WR 15 ns 6 (101)
225 * 12 PD Slow 1 Fast 0 0
Ionela Voinescu59074ff2015-03-05 16:40:07 +0000226 * 15:13 RSVD RSVD
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000227 * 31:16 Reserved
228 */
Ionela Voinescu59074ff2015-03-05 16:40:07 +0000229 write32(DDR_PHY + DDRPHY_MR_OFFSET, 0x00000A62 | (BL8 ? 0x1 : 0x0));
230 /* MR1 : EMR Register
231 * Generate to use with PHY and PCTL
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000232 * 0 DE DLL Enable 0 Disable 1
233 * 1 DIC Output Driver Imp Ctl 0 Full, 1 Half
Ionela Voinescu59074ff2015-03-05 16:40:07 +0000234 * 6,2 ODT 0 Disable, 1 75R, 2 150R, 3 50R; LSB: 2, MSB: 6
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000235 * 5:3 AL = 0
236 * 9:7 OCD = 0
237 * 10 DQS 0 diff, 1 single = 0
238 * 11 RDQS NA 0
239 * 12 QOFF Normal mode 0
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000240 * 15:13 RSVD
241 * 31:16 Reserved
242 */
Ionela Voinescu51ad6ac2015-03-05 17:11:14 +0000243 write32(DDR_PHY + DDRPHY_EMR_OFFSET, 0x00000044);
Ionela Voinescu59074ff2015-03-05 16:40:07 +0000244 /* MR2 : EMR2 Register
245 * Generate to use with PHY and PCTL
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000246 * 2:0 PASR, NA 000
247 * 3 DDC NA 0
248 * 6:4 RSVD
249 * 7 SFR 0
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000250 * 15:8 RSVD
251 * 31:16 Reserved
252 */
Ionela Voinescu59074ff2015-03-05 16:40:07 +0000253 write32(DDR_PHY + DDRPHY_EMR2_OFFSET, 0x00000000);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000254 /* DSGCR
255 * 0 PUREN Def 1
256 * 1 BDISEN Def 1
257 * 2 ZUEN Def 1
258 * 3 LPIOPD DEf 1 0
259 * 4 LPDLLPD DEf 1 0
260 * 7:5 DQSGX DQS Extention 000
261 * 10:8 DQSGE DQS Early Gate
Ionela Voinescu5d997f92015-03-30 12:00:35 +0100262 * 11 NOBUB No Bubbles, adds latency 1
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000263 * 12 FXDLAT Fixed Read Latency 0
264 * 15:13 Reserved
265 * 19:16 CKEPDD CKE Power Down 0000
266 * 23:20 ODTPDD ODT Power Down 0000
267 * 24 NL2PD Power Down Non LPDDR2 pins 0
268 * 25 NL2OE Output Enable Non LPDDR2 pins 1
269 * 26 TPDPD LPDDR Only 0
270 * 27 TPDOE LPDDR Only 0
271 * 28 CKOE Output Enable Clk's 1
272 * 29 ODTOE Output Enable ODT 1
273 * 30 RSTOE RST# Output Enable 1
274 * 31 CKEOE CKE Output Enable 1
275 */
Ionela Voinescu5d997f92015-03-30 12:00:35 +0100276 write32(DDR_PHY + DDRPHY_DSGCR_OFFSET, 0xF2000807);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000277 /* DTPR0 : DRAM Timing Params 0
278 * 1:0 tMRD 2
279 * 4:2 tRTP 3
280 * 7:5 tWTR 3
281 * 11:8 tRP 6
282 * 15:12 tRCD 6
283 * 20:16 tRAS 18
284 * 24:21 tRRD 4
285 * 30:25 tRC 24 (23)
286 * 31 tCCD 0 BL/2 Cas to Cas
287 */
288 write32(DDR_PHY + DDRPHY_DTPR0_OFFSET, 0x3092666E);
289 /* DTPR1 : DRAM Timing Params 1
290 * 1:0 ODT On/Off Del Std 0
291 * 2 tRTW Rd2Wr Del 0 std 1 +1 0
292 * 8:3 tFAW 4 Bank Act 45ns = 18 18
293 * 10:9 tMOD DDR3 Only 0
294 * 11 tRTODT DDR3 Only 0
295 * 15:12 Reserved
296 * 23:16 tRFC 195ns 78 def 131 78d
297 * 26:24 tDQSCK LPDDR2 only 1
298 * 29:27 tDQSCKmax 1
299 * 31:30 Reserved
300 */
301 write32(DDR_PHY + DDRPHY_DTPR1_OFFSET, 0x094E0092);
302 /* DTPR2 : DRAM Timing Params 2
303 * 9:0 tXS exit SR def 200, 200d
304 * 14:10 tXP PD Exit Del 8 3
305 * 18:15 tCKE CKE Min pulse 3
306 * 28:19 tDLLK DLL Lock time 200d
307 * 32:29 Reserved
308 */
309 write32(DDR_PHY + DDRPHY_DTPR2_OFFSET, 0x06418CC8);
310 /* PTR0 : PHY Timing Params 0
311 * 5:0 tDLLRST Def 27
312 * 17:6 tDLLLOCK Def 2750
313 * 21:18 tITMSRST Def 8
314 * 31:22 Reserved 0
315 */
316 write32(DDR_PHY + DDRPHY_PTR0_OFFSET, 0x0022AF9B);
317 /* PTR1 : PHY Timing Params 1
318 * 18:0 : tDINITO DRAM Init time 200us 80,000 Dec 0x13880
319 * 29:19 : tDINIT1 DRAM Init time 400ns 160 Dec 0xA0
320 */
321 write32(DDR_PHY + DDRPHY_PTR1_OFFSET, 0x05013880);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000322 /* PGSR : Wait for INIT/DLL/Z Done from Power on Reset */
323 if (wait_for_completion(DDR_PHY + DDRPHY_PGSR_OFFSET, 0x00000007))
324 return DDR_TIMEOUT;
Ionela Voinescu59074ff2015-03-05 16:40:07 +0000325 /* PIR : use PHY for DRAM Init */
326 write32(DDR_PHY + DDRPHY_PIR_OFFSET, 0x000001DF);
327 /* PGSR : Wait for DRAM Init Done */
328 if (wait_for_completion(DDR_PHY + DDRPHY_PGSR_OFFSET, 0x0000001F))
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000329 return DDR_TIMEOUT;
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000330 /* DF1STAT0 : wait for DFI_INIT_COMPLETE */
331 if (wait_for_completion(DDR_PCTL + DDR_PCTL_DFISTAT0_OFFSET,
332 0x00000001))
333 return DDR_TIMEOUT;
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000334 /* POWCTL : Start the memory Power Up seq*/
335 write32(DDR_PCTL + DDR_PCTL_POWCTL_OFFSET, 0x00000001);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000336 /* POWSTAT : wait for POWER_UP_DONE */
337 if (wait_for_completion(DDR_PCTL + DDR_PCTL_POWSTAT_OFFSET,
338 0x00000001))
339 return DDR_TIMEOUT;
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000340 /*
341 * TREFI : t_refi Timing Register 1X
342 * 12:0 t_refi 7.8us in 100ns 0x4E
343 * 15:13 Reserved 0
344 * 18:16 num_add_ref 0
345 * 30:19 Reserved 0
346 * 31 Update 1
347 */
348 write32(DDR_PCTL + DDR_PCTL_TREFI_OFFSET, 0x8000004E);
349 /* TMRD : t_mrd Timing Register -- Range 2 to 3 */
350 write32(DDR_PCTL + DDR_PCTL_TMRD_OFFSET, 0x00000002);
351 /*
352 * TRFC : t_rfc Timing Register -- Range 15 to 131
353 * 195ns / 2.5ns 78 x4E
354 */
355 write32(DDR_PCTL + DDR_PCTL_TRFC_OFFSET, 0x0000004E);
356 /* TRP : t_rp Timing Register -- Range 3 to 7
357 * 4:0 tRP 12.5 / 2.5 = 5 6 For Now 6-6-6
358 * 17:16 rpea_extra tRPall 8 bank 1
359 */
360 write32(DDR_PCTL + DDR_PCTL_TRP_OFFSET, 0x00010006);
361 /* TAL : Additive Latency Register -- AL in MR1 */
362 write32(DDR_PCTL + DDR_PCTL_TAL_OFFSET, 0x00000000);
363 /* DFITPHYWRLAT : Write cmd to dfi_wrdata_en */
364 write32(DDR_PCTL + DDR_PCTL_DFIWRLAT_OFFSET, 0x00000002);
365 /* DFITRDDATAEN : Read cmd to dfi_rddata_en */
366 write32(DDR_PCTL + DDR_PCTL_DFITRDDATAEN_OFFSET, 0x00000002);
367 /* TCL : CAS Latency Timing Register -- CASL in MR0 6-6-6 */
368 write32(DDR_PCTL + DDR_PCTL_TCL_OFFSET, 0x00000006);
369 /* TCWL : CAS Write Latency Register --CASL-1 */
370 write32(DDR_PCTL + DDR_PCTL_TCWL_OFFSET, 0x00000005);
371 /*
372 * TRAS : Activate to Precharge cmd time
373 * Range 8 to 24: 45ns / 2.5ns = 18d
374 */
375 write32(DDR_PCTL + DDR_PCTL_TRAS_OFFSET, 0x00000012);
376 /*
377 * TRC : Min. ROW cylce time
378 * Range 11 to 31: 57.5ns / 2.5ns = 23d Playing safe 24
379 */
380 write32(DDR_PCTL + DDR_PCTL_TRC_OFFSET, 0x00000018);
381 /*
382 * TRCD : Row to Column Delay
383 * Range 3 to 7 (TCL = TRCD): 2.5ns / 2.5ns = 5 but running 6-6-6 6
384 */
385 write32(DDR_PCTL + DDR_PCTL_TRCD_OFFSET, 0x00000006);
386 /* TRRD : Row to Row delay -- Range 2 to 6: 2K Page 10ns / 2.5ns = 4*/
387 write32(DDR_PCTL + DDR_PCTL_TRRD_OFFSET, 0x00000004);
388 /* TRTP : Read to Precharge time -- Range 2 to 4: 7.3ns / 2.5ns = 3 */
389 write32(DDR_PCTL + DDR_PCTL_TRTP_OFFSET, 0x00000003);
390 /* TWR : Write recovery time -- WR in MR0: 15ns / 2.5ns = 6
391 */
392 write32(DDR_PCTL + DDR_PCTL_TWR_OFFSET, 0x00000006);
393 /*
394 * TWTR : Write to read turn around time
395 * Range 2 to 4: 7.3ns / 2.5ns = 3
396 */
397 write32(DDR_PCTL + DDR_PCTL_TWTR_OFFSET, 0x00000003);
398 /* TEXSR : Exit Self Refresh to first valid cmd: tXS 200*/
399 write32(DDR_PCTL + DDR_PCTL_TEXSR_OFFSET, 0x000000C8);
400 /*
401 * TXP : Exit Power Down to first valid cmd
402 * tXP 2, Settingto 3 to match PHY
403 */
404 write32(DDR_PCTL + DDR_PCTL_TXP_OFFSET, 0x00000003);
405 /*
406 * TDQS : t_dqs Timing Register
407 * DQS additional turn around Rank 2 Rank (1 Rank) Def 1
408 */
409 write32(DDR_PCTL + DDR_PCTL_TDQS_OFFSET, 0x00000001);
410 /*TRTW : Read to Write turn around time Def 2
411 * Actual gap t_bl + t_rtw
412 */
413 write32(DDR_PCTL + DDR_PCTL_TRTW_OFFSET, 0x00000002);
414 /* TCKE : CKE min pulse width DEf 3 */
415 write32(DDR_PCTL + DDR_PCTL_TCKE_OFFSET, 0x00000003);
416 /*
417 * TXPDLL : Slow Exit Power Down to first valid cmd delay
418 * tXARDS 10+AL = 10
419 */
420 write32(DDR_PCTL + DDR_PCTL_TXPDLL_OFFSET, 0x0000000A);
421 /*
422 * TCKESR : Min CKE Low width for Self refresh entry to exit
423 * t_ckesr = 0 DDR2
424 */
425 write32(DDR_PCTL + DDR_PCTL_TCKESR_OFFSET, 0x00000000);
426 /* SCFG : State Configuration Register (Enabling Self Refresh)
427 * 0 LP_en Leave Off for Bring Up 0
428 * 5:1 Reserved
429 * 6 Synopsys Internal Only 0
430 * 7 Enale PHY indication of LP Opportunity 1
431 * 11:8 bbflags_timing max UPCTL_TCU_SED_P - tRP (16 - 6) Use 4
432 * 16:12 Additional delay on accertion of ac_pdd 4
433 * 31:17 Reserved
434 */
435 write32(DDR_PCTL + DDR_PCTL_SCFG_OFFSET, 0x00004480);
436 /*
437 * DFITPHYWRDATA : dfi_wrdata_en to drive wr data
438 * DFI Clks wrdata_en to wrdata Def 1
439 */
440 write32(DDR_PCTL + DDR_PCTL_DFITPHYWRDATA_OFFSET, 0x00000000);
441 /*
442 * DFITPHYRDLAT : dfi_rddata_en to dfi_rddata_valid
443 * DFI clks max rddata_en to rddata_valid Def 15
444 */
445 write32(DDR_PCTL + DDR_PCTL_DFITPHYRDLAT_OFFSET, 0x00000008);
446 /* MCMD : PREA, Addr 0 Bank 0 Rank 0 Del 0
447 * 3:0 cmd_opcode PREA 00001
448 * 16:4 cmd_addr 0
449 * 19:17 bank_addr 0
450 * 23:20 rank_sel 0 0001
451 * 27:24 cmddelay 0
452 * 30:24 Reserved
453 */
454 write32(DDR_PCTL + DDR_PCTL_MCMD_OFFSET, 0x80100001);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000455 /* MRS cmd wait for completion */
456 if (wait_for_completion(DDR_PCTL + DDR_PCTL_MCMD_OFFSET, 0x00100001))
457 return DDR_TIMEOUT;
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000458 /* SCTL : UPCTL switch INIT CONFIG State */
459 write32(DDR_PCTL + DDR_PCTL_SCTL_OFFSET, 0x00000001);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000460 /* STAT : Wait for Switch INIT to Config State */
461 if (wait_for_completion(DDR_PCTL + DDR_PCTL_STAT_OFFSET, 0x00000001))
462 return DDR_TIMEOUT;
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000463 /* DFISTCFG0 : Drive various DFI signals appropriately
464 * 0 dfi_init_start 0
465 * 1 dfi_freq_ratio_en 1
466 * 2 dfi_data_byte_disable_en 1
467 */
468 write32(DDR_PCTL + DDR_PCTL_DFISTCFG0_OFFSET, 0x00000003);
469 /* DFISTCFG1 : Enable various DFI support
470 * 0 dfi_dram_clk_disable_en 1
471 * 1 dfi_dram_clk_disable_en_pdp only lPDDR 0
472 */
473 write32(DDR_PCTL + DDR_PCTL_DFISTCFG1_OFFSET, 0x00000001);
474 /* DFISTCFG2 : Enable Parity and asoc interrupt
475 * 0 dfi_parity_in Enable 1
476 * 1 Interrupt on dfi_parity_error 1
477 */
478 write32(DDR_PCTL + DDR_PCTL_DFISTCFG2_OFFSET, 0x00000003);
479 /* DFILPCFG0 : DFI Low Power Interface Configuration
480 * 0 Enable DFI LP IF during PD 1
481 * 3:1 Reserved
482 * 7:4 DFI tlp_wakeup time 0
483 * 8 Enable DFI LP IF during SR 1
484 * 11:9 Reserved
485 * 15:12 dfi_lp_wakeup in SR 0
486 * 19:16 tlp_resp DFI 2.1 recomend 7
487 * 23:20 Reserved
488 * 24 Enable DFI LP in Deep Power Down 0
489 * 27:25 Reserved
490 * 31:28 DFI LP Deep Power Down Value 0
491 */
492 write32(DDR_PCTL + DDR_PCTL_DFILPCFG0_OFFSET, 0x00070101);
493 /* DFIODTCFG : DFI ODT Configuration
494 * Only Enabled on Rank0 Writes
495 * 0 rank0_odt_read_nsel 0
496 * 1 rank0_odt_read_sel 0
497 * 2 rank0_odt_write_nsel 0
498 * 3 rank0_odt_write_sel 1
499 */
500 write32(DDR_PCTL + DDR_PCTL_DFIODTCFG_OFFSET, 0x00000008);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000501 /* DFIODTCFG1 : DFI ODT Configuration
502 * 4:0 odt_lat_w 4
503 * 12:8 odt_lat_r 0 Def
504 * 4:0 odt_len_bl8_w 6 Def
505 * 12:8 odt_len_bl8_r 6 Def
506 */
507 write32(DDR_PCTL + DDR_PCTL_DFIODTCFG1_OFFSET, 0x06060004);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000508 /* DCFG : DRAM Density 256 Mb 16 Bit IO Width
509 * 1:0 Devicw Width 1 x8, 2 x16, 3 x32 2
510 * 5:2 Density 2Gb = 5
511 * 6 Dram Type (MDDR/LPDDR2) Only 0
512 * 7 Reserved 0
Ionela Voinescua2c4f9e2015-03-30 11:59:10 +0100513 * 10:8 Address Map R/B/C = 1
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000514 * 31:11 Reserved
515 */
Ionela Voinescua2c4f9e2015-03-30 11:59:10 +0100516 write32(DDR_PCTL + DDR_PCTL_DCFG_OFFSET, 0x00000116);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000517 /* PCFG_0 : Port 0 AXI config */
Ionela Voinescu59074ff2015-03-05 16:40:07 +0000518 if (BL8)
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000519 write32(DDR_PCTL + DDR_PCTL_PCFG0_OFFSET, 0x000800A0);
520 else
521 write32(DDR_PCTL + DDR_PCTL_PCFG0_OFFSET, 0x000400A0);
Ionela Voinescud6aaca92015-01-19 01:03:44 +0000522 /* SCTL : UPCTL switch Config to ACCESS State */
523 write32(DDR_PCTL + DDR_PCTL_SCTL_OFFSET, 0x00000002);
524 /* STAT : Wait for switch CFG -> GO State */
525 if (wait_for_completion(DDR_PCTL + DDR_PCTL_STAT_OFFSET, 0x3))
526 return DDR_TIMEOUT;
527
528 return 0;
529}