AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Recovery / Mem / Tech / DDR3 / mrtrci3.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mrtrci3.c
6  *
7  * Technology Control word initialization 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: 44324 $ @e \$Date: 2010-12-22 02:16:51 -0700 (Wed, 22 Dec 2010) $
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  *                                MODULES USED
49  *
50  *----------------------------------------------------------------------------
51  */
52
53
54
55 #include "AGESA.h"
56 #include "OptionMemory.h"
57 #include "Ids.h"
58 #include "mm.h"
59 #include "mn.h"
60 #include "mru.h"
61 #include "mt.h"
62 #include "Filecode.h"
63 CODE_GROUP (G2_PEI)
64 RDATA_GROUP (G2_PEI)
65
66 #define FILECODE PROC_RECOVERY_MEM_TECH_DDR3_MRTRCI3_FILECODE
67 /*----------------------------------------------------------------------------
68  *                          DEFINITIONS AND MACROS
69  *
70  *----------------------------------------------------------------------------
71  */
72
73 /*----------------------------------------------------------------------------
74  *                           TYPEDEFS AND STRUCTURES
75  *
76  *----------------------------------------------------------------------------
77  */
78
79 /*----------------------------------------------------------------------------
80  *                        PROTOTYPES OF LOCAL FUNCTIONS
81  *
82  *----------------------------------------------------------------------------
83  */
84
85 UINT8
86 STATIC
87 MemRecTGetCtlWord3 (
88   IN OUT   MEM_TECH_BLOCK *TechPtr,
89   IN       UINT8 CtrlWordNum
90   );
91
92 VOID
93 STATIC
94 MemRecTSendCtlWord3 (
95   IN OUT   MEM_TECH_BLOCK *TechPtr,
96   IN       UINT8 CmdNum,
97   IN       UINT8 Value
98   );
99
100 /*----------------------------------------------------------------------------
101  *                            EXPORTED FUNCTIONS
102  *
103  *----------------------------------------------------------------------------
104  */
105
106 /* -----------------------------------------------------------------------------*/
107 /**
108  *
109  *   This function sends control words
110  *
111  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
112  *
113  *     @return  pDCT->Timings.TrwtTO updated
114  */
115
116 VOID
117 MemRecTDramControlRegInit3 (
118   IN OUT   MEM_TECH_BLOCK *TechPtr
119   )
120 {
121   UINT8 RCNum;
122   UINT8 Data;
123
124   MEM_DATA_STRUCT *MemPtr;
125   MEM_NB_BLOCK  *NBPtr;
126
127   NBPtr = TechPtr->NBPtr;
128   MemPtr = NBPtr->MemPtr;
129
130   // wait 8us TACT must be changed to optimize to 8 MEM CLKs
131   // and wait 6us for PLL LOCK
132   MemRecUWait10ns (80 + 60, MemPtr);
133
134   // 2. Program F2x[1, 0]A8[CtrlWordCS]=bit mask for target chip selects.
135   NBPtr->SetBitField (NBPtr, BFCtrlWordCS, 3 << (NBPtr->DimmToBeUsed << 1));
136
137   for (RCNum = 0; RCNum <= 15; RCNum++) {
138     // wait 8us for TMRD, must be changed to optimize to 8 MEM CLKs
139     MemRecUWait10ns (80, MemPtr);
140
141     if ((RCNum != 6) && (RCNum != 7)) {
142       Data = MemRecTGetCtlWord3 (TechPtr, RCNum);
143       MemRecTSendCtlWord3 (TechPtr, RCNum, Data);
144     }
145   }
146
147   MemRecUWait10ns (60, MemPtr);   // wait 6us for TSTAB
148 }
149
150 /* -----------------------------------------------------------------------------*/
151 /**
152  *
153  *   This function calculates the ControlRC value
154  *
155  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
156  *     @param[in]     CtrlWordNum  -  control Word number.
157  *
158  *     @return  Control Word value
159  */
160
161 UINT8
162 STATIC
163 MemRecTGetCtlWord3 (
164   IN OUT   MEM_TECH_BLOCK *TechPtr,
165   IN       UINT8 CtrlWordNum
166   )
167 {
168   UINT8  Data;
169
170   CH_DEF_STRUCT *ChannelPtr;
171
172   ChannelPtr = TechPtr->NBPtr->ChannelPtr;
173
174   Data = 0;  //Default value for all control words is 0
175   switch (CtrlWordNum) {
176   case 0:
177     Data = 0x02;  // DA4=1
178     break;
179   case 1:
180     Data = 0x0C;  // if single rank, set DBA1 and DBA0
181     break;
182   case 3:
183     Data = ChannelPtr->CtrlWrd03[TechPtr->NBPtr->DimmToBeUsed];
184     break;
185   case 4:
186     Data = ChannelPtr->CtrlWrd04[TechPtr->NBPtr->DimmToBeUsed];
187     break;
188   case 5:
189     Data = ChannelPtr->CtrlWrd05[TechPtr->NBPtr->DimmToBeUsed];
190     break;
191   case 9:
192     Data = 0x0D;
193     break;
194   default:;
195   }
196
197   return (Data&0x0F);
198 }
199 /* -----------------------------------------------------------------------------*/
200 /**
201  *
202  *   This function sends control word command
203  *
204  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
205  *     @param[in]     CmdNum  -  control number.
206  *     @param[in]     Value  -  value to send
207  *
208  */
209
210 VOID
211 STATIC
212 MemRecTSendCtlWord3 (
213   IN OUT   MEM_TECH_BLOCK *TechPtr,
214   IN       UINT8 CmdNum,
215   IN       UINT8 Value
216   )
217 {
218   MEM_NB_BLOCK  *NBPtr;
219
220   ASSERT (CmdNum < 16);
221   ASSERT (Value < 16);
222
223   NBPtr = TechPtr->NBPtr;
224
225   // 1. Program MrsBank and MrsAddress.
226   //    n = [BA2, A2, A1, A0].
227   //    data = [BA1, BA0, A4, A3].
228   //    Set all other bits in MrsAddress to zero.
229   //
230   NBPtr->SetBitField (NBPtr, BFMrsBank, ((CmdNum&8) >> 1) | (Value >> 2));
231   NBPtr->SetBitField (NBPtr, BFMrsAddress, ((Value&3) << 3) | (CmdNum&7));
232   IDS_HDT_CONSOLE (MEM_FLOW, "\t\tCS%d RC%02d %04x\n",
233               (NBPtr->GetBitField (NBPtr, BFDramInitRegReg) >> 20) & 0xF,
234               ((NBPtr->GetBitField (NBPtr, BFDramInitRegReg) >> 15) & 8) |
235               (NBPtr->GetBitField (NBPtr, BFDramInitRegReg) & 7),
236               ((NBPtr->GetBitField (NBPtr, BFDramInitRegReg) >> 14) & 0xC) |
237               ((NBPtr->GetBitField (NBPtr, BFDramInitRegReg) >> 3) & 3));
238
239   // 2.Set SendCtrlWord=1
240   NBPtr->SetBitField (NBPtr, BFSendCtrlWord, 1);
241   // 3.Wait for BFSendCtrlWord=0
242   while (NBPtr->GetBitField (NBPtr, BFSendCtrlWord) != 0) {}
243 }