AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Recovery / Mem / Tech / DDR3 / mrtsdi3.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mrtsdi3.c
6  *
7  * Technology Software DRAM Init for DDR3 Recovery
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Proc/Recovery/Mem)
12  * @e \$Revision: 49896 $ @e \$Date: 2011-03-30 02:18:18 -0600 (Wed, 30 Mar 2011) $
13  *
14  **/
15 /*****************************************************************************
16 *
17 * Copyright (C) 2012 Advanced Micro Devices, Inc.
18 * All rights reserved.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are met:
22 *     * Redistributions of source code must retain the above copyright
23 *       notice, this list of conditions and the following disclaimer.
24 *     * Redistributions in binary form must reproduce the above copyright
25 *       notice, this list of conditions and the following disclaimer in the
26 *       documentation and/or other materials provided with the distribution.
27 *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
28 *       its contributors may be used to endorse or promote products derived
29 *       from this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
35 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * ***************************************************************************
43 *
44 */
45
46
47 /*
48  *----------------------------------------------------------------------------
49  *                                MODULES USED
50  *
51  *----------------------------------------------------------------------------
52  */
53
54
55
56 #include "AGESA.h"
57 #include "OptionMemory.h"
58 #include "Ids.h"
59 #include "mm.h"
60 #include "mn.h"
61 #include "mru.h"
62 #include "mt.h"
63 #include "mrt3.h"
64 #include "Filecode.h"
65 CODE_GROUP (G2_PEI)
66 RDATA_GROUP (G2_PEI)
67
68 #define FILECODE PROC_RECOVERY_MEM_TECH_DDR3_MRTSDI3_FILECODE
69 /*----------------------------------------------------------------------------
70  *                          DEFINITIONS AND MACROS
71  *
72  *----------------------------------------------------------------------------
73  */
74
75 /*----------------------------------------------------------------------------
76  *                           TYPEDEFS AND STRUCTURES
77  *
78  *----------------------------------------------------------------------------
79  */
80
81 /*----------------------------------------------------------------------------
82  *                        PROTOTYPES OF LOCAL FUNCTIONS
83  *
84  *----------------------------------------------------------------------------
85  */
86
87
88 /*----------------------------------------------------------------------------
89  *                            EXPORTED FUNCTIONS
90  *
91  *----------------------------------------------------------------------------
92  */
93
94
95
96 /* -----------------------------------------------------------------------------*/
97 /**
98  *
99  *   This function initiates software DRAM init
100  *
101  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
102  *
103  */
104
105 VOID
106 MemRecTDramInitSw3 (
107   IN OUT   MEM_TECH_BLOCK *TechPtr
108   )
109 {
110   UINT8 ChipSel;
111   MEM_DATA_STRUCT *MemPtr;
112   MEM_NB_BLOCK  *NBPtr;
113
114   NBPtr = TechPtr->NBPtr;
115   MemPtr = NBPtr->MemPtr;
116
117   IDS_HDT_CONSOLE (MEM_STATUS, "\nStart Dram Init\n");
118   IDS_HDT_CONSOLE (MEM_FLOW, "\tEnDramInit = 1 for DCT%d\n", NBPtr->Dct);
119   // 3.Program F2x[1,0]7C[EnDramInit]=1
120   NBPtr->SetBitField (NBPtr, BFEnDramInit, 1);
121
122   // 4.wait 200us
123   MemRecUWait10ns (20000, MemPtr);
124
125   NBPtr->SetBitField (NBPtr, BFDeassertMemRstX, 1);
126
127   // 6.wait 500us
128   MemRecUWait10ns (50000, MemPtr);
129
130   // 7.NOP or deselect & take CKE high
131   NBPtr->SetBitField (NBPtr, BFAssertCke, 1);
132
133   // 8.wait 360ns
134   MemRecUWait10ns (36, MemPtr);
135
136   // The following steps are performed with registered DIMMs only and
137   // must be done for each chip select pair:
138   //
139   if (NBPtr->ChannelPtr->RegDimmPresent != 0) {
140     MemRecTDramControlRegInit3 (TechPtr);
141   }
142
143   for (ChipSel = 0; ChipSel < MAX_CS_PER_CHANNEL; ChipSel++) {
144     if ((NBPtr->DCTPtr->Timings.CsPresent & (UINT16) 1 << ChipSel) != 0) {
145
146       // Set Dram ODT per ChipSel
147       NBPtr->SetDramOdtRec (NBPtr, MISSION_MODE, ChipSel, (NBPtr->DimmToBeUsed << 1));
148
149       NBPtr->SetBitField (NBPtr, BFMrsChipSel, ChipSel);
150       // 13.Send EMRS(2)
151       MemRecTEMRS23 (TechPtr);
152       NBPtr->SendMrsCmd (NBPtr);
153
154       // 14.Send EMRS(3). Ordinarily at this time, MrsAddress[2:0]=000b
155       MemRecTEMRS33 (TechPtr);
156       NBPtr->SendMrsCmd (NBPtr);
157
158       // 15.Send EMRS(1).
159       MemRecTEMRS13 (TechPtr);
160       NBPtr->SendMrsCmd (NBPtr);
161
162       // 16.Send MRS with MrsAddress[8]=1(reset the DLL)
163       MemRecTMRS3 (TechPtr);
164       NBPtr->SendMrsCmd (NBPtr);
165
166       //wait 500us
167       MemRecUWait10ns (50000, MemPtr);
168
169       if (NBPtr->ChannelPtr->RegDimmPresent == 0) {
170         break;
171       }
172     }
173   }
174
175   // 17.Send two ZQCL commands (to even then odd chip select)
176   NBPtr->sendZQCmd (NBPtr);
177   NBPtr->sendZQCmd (NBPtr);
178
179   // 18.Program F2x[1,0]7C[EnDramInit]=0
180   NBPtr->SetBitField (NBPtr, BFEnDramInit, 0);
181   IDS_HDT_CONSOLE (MEM_FLOW, "End Dram Init\n\n");
182 }
183
184 /* -----------------------------------------------------------------------------*/
185 /**
186  *
187  *   This function calculates the EMRS1 value
188  *
189  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
190  *
191  */
192
193 VOID
194 MemRecTEMRS13 (
195   IN OUT   MEM_TECH_BLOCK *TechPtr
196   )
197 {
198   UINT16 MrsAddress;
199   UINT8 DramTerm;
200
201   MEM_NB_BLOCK  *NBPtr;
202
203   NBPtr = TechPtr->NBPtr;
204
205   // BA2=0,BA1=0,BA0=1
206   NBPtr->SetBitField (NBPtr, BFMrsBank, 1);
207
208   MrsAddress = 0;
209
210   // program MrsAddress[5,1]=output driver impedance control (DIC):
211   // based on F2x[1,0]84[DrvImpCtrl], which is 2'b01
212   MrsAddress |= ((UINT16) 1 << 1);
213
214   // program MrsAddress[9,6,2]=nominal termination resistance of ODT (RTT):
215   // based on F2x[1,0]84[DramTerm], which is 3'b001 (60 Ohms)
216   if (!(NBPtr->IsSupported[CheckDramTerm])) {
217     DramTerm = (UINT8) NBPtr->GetBitField (NBPtr, BFDramTerm);
218   } else {
219     DramTerm = NBPtr->PsPtr->DramTerm;
220   }
221   if ((DramTerm & 1) != 0) {
222     MrsAddress |= ((UINT16) 1 << 2);
223   }
224   if ((DramTerm & 2) != 0) {
225     MrsAddress |= ((UINT16) 1 << 6);
226   }
227   if ((DramTerm & 4) != 0) {
228     MrsAddress |= ((UINT16) 1 << 9);
229   }
230
231   // program MrsAddress[12]=output disable (QOFF):
232   // based on F2x[1,0]84[Qoff], which is 1'b0
233
234   // program MrsAddress[11]=TDQS:
235   // based on F2x[1,0]94[RDqsEn], which is 1'b0
236
237   NBPtr->SetBitField (NBPtr, BFMrsAddress, MrsAddress);
238 }
239
240 /* -----------------------------------------------------------------------------*/
241 /**
242  *
243  *   This function calculates the EMRS2 value
244  *
245  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
246  *
247  */
248
249 VOID
250 MemRecTEMRS23 (
251   IN OUT   MEM_TECH_BLOCK *TechPtr
252   )
253 {
254   UINT16 MrsAddress;
255   UINT8 DramTermDyn;
256   MEM_NB_BLOCK  *NBPtr;
257
258   NBPtr = TechPtr->NBPtr;
259
260   // BA2=0,BA1=1,BA0=0
261   NBPtr->SetBitField (NBPtr, BFMrsBank, 2);
262
263   // program MrsAddress[5:3]=CAS write latency (CWL):
264   // based on F2x[1,0]84[Tcwl], which is 3'b000
265   //
266   MrsAddress = 0;
267
268   // program MrsAddress[6]=auto self refresh method (ASR):
269   // based on F2x[1,0]84[ASR], which is 1'b1
270   // program MrsAddress[7]=self refresh temperature range (SRT):
271   // based on F2x[1,0]84[SRT], which is also 1'b0
272   //
273   MrsAddress |= (UINT16) 1 << 6;
274
275   // program MrsAddress[10:9]=dynamic termination during writes (RTT_WR):
276   // based on F2x[1,0]84[DramTermDyn]
277   //
278   if (!(NBPtr->IsSupported[CheckDramTermDyn])) {
279     DramTermDyn = (UINT8) NBPtr->GetBitField (NBPtr, BFDramTermDyn);
280   } else {
281     DramTermDyn = NBPtr->PsPtr->DynamicDramTerm;
282   }
283   MrsAddress |= (UINT16) DramTermDyn << 9;
284   NBPtr->SetBitField (NBPtr, BFMrsAddress, MrsAddress);
285 }
286
287 /* -----------------------------------------------------------------------------*/
288 /**
289  *
290  *   This function calculates the EMRS3 value
291  *
292  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
293  *
294  */
295
296 VOID
297 MemRecTEMRS33 (
298   IN OUT   MEM_TECH_BLOCK *TechPtr
299   )
300 {
301   MEM_NB_BLOCK  *NBPtr;
302
303   NBPtr = TechPtr->NBPtr;
304
305   // BA2=0,BA1=1,BA0=1
306   NBPtr->SetBitField (NBPtr, BFMrsBank, 3);
307
308   // program MrsAddress[1:0]=multi purpose register address location
309   // (MPR Location):based on F2x[1,0]84[MprLoc], which is 0
310   // program MrsAddress[2]=multi purpose register
311   // (MPR):based on F2x[1,0]84[MprEn], which is also 0
312   //
313   NBPtr->SetBitField (NBPtr, BFMrsAddress, 0);
314 }
315
316 /* -----------------------------------------------------------------------------*/
317 /**
318  *
319  *   This sets MSS value
320  *
321  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
322  *
323  */
324
325 VOID
326 MemRecTMRS3 (
327   IN OUT   MEM_TECH_BLOCK *TechPtr
328   )
329 {
330   UINT16 MrsAddress;
331   MEM_NB_BLOCK  *NBPtr;
332
333   NBPtr = TechPtr->NBPtr;
334
335   // BA2=0,BA1=0,BA0=0
336   NBPtr->SetBitField (NBPtr, BFMrsBank, 0);
337
338   // program MrsAddress[1:0]=burst length and control method
339   // (BL):based on F2x[1,0]84[BurstCtrl], which is 1'b0
340   //
341   MrsAddress = 0;
342
343   // program MrsAddress[3]=1 (BT):interleaved
344   MrsAddress |= (UINT16) 1 << 3;
345
346   // program MrsAddress[6:4,2]=read CAS latency
347   // (CL):based on F2x[1,0]88[Tcl], which is 4'b0010
348   MrsAddress |= (UINT16) 2 << 4;
349
350   // program MrsAddress[11:9]=write recovery for auto-precharge
351   // (WR):based on F2x[1,0]84[Twr], which is 3'b010
352   //
353   MrsAddress |= (UINT16) 2 << 9;
354
355   // program MrsAddress[12]=0 (PPD):slow exit
356
357   // program MrsAddress[8]=1 (DLL):DLL reset
358   MrsAddress |= (UINT16) 1 << 8;   // just issue DLL reset at first time
359
360   NBPtr->SetBitField (NBPtr, BFMrsAddress, MrsAddress);
361 }