AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / NB / HY / mnphyhy.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mnphyHy.c
6  *
7  * Northbridge Phy support for Hydra
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/NB/HY)
12  * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 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 "amdlib.h"
58 #include "Ids.h"
59 #include "ma.h"
60 #include "mm.h"
61 #include "mn.h"
62 #include "mt.h"
63 #include "mu.h"
64 #include "OptionMemory.h"       // need def for MEM_FEAT_BLOCK_NB
65 #include "mnhy.h"
66 #include "PlatformMemoryConfiguration.h"
67 #include "Filecode.h"
68 CODE_GROUP (G1_PEICC)
69 RDATA_GROUP (G2_PEI)
70
71 #define FILECODE PROC_MEM_NB_HY_MNPHYHY_FILECODE
72 /*----------------------------------------------------------------------------
73  *                          DEFINITIONS AND MACROS
74  *
75  *----------------------------------------------------------------------------
76  */
77 #define UNUSED_CLK 4
78
79 /*----------------------------------------------------------------------------
80  *                           TYPEDEFS AND STRUCTURES
81  *
82  *----------------------------------------------------------------------------
83  */
84
85 /*----------------------------------------------------------------------------
86  *                        PROTOTYPES OF LOCAL FUNCTIONS
87  *
88  *----------------------------------------------------------------------------
89  */
90
91
92
93 /*----------------------------------------------------------------------------
94  *                            EXPORTED FUNCTIONS
95  *
96  *----------------------------------------------------------------------------
97  */
98 /* -----------------------------------------------------------------------------*/
99
100
101 /* -----------------------------------------------------------------------------*/
102 /**
103  *
104  *
105  *   This function initializes the DDR phy compensation logic
106  *
107  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
108  *
109  */
110
111 VOID
112 MemNInitPhyCompHy (
113   IN OUT   MEM_NB_BLOCK *NBPtr
114   )
115 {
116   CONST UINT8 TableCompRiseSlew20x[] = {7, 3, 2, 2};
117   CONST UINT8 TableCompRiseSlew15x[] = {7, 7, 3, 2};
118   CONST UINT8 TableCompFallSlew20x[] = {7, 5, 3, 2};
119   CONST UINT8 TableCompFallSlew15x[] = {7, 7, 5, 3};
120   UINT8 i;
121   UINT8 j;
122   UINT8 CurrDct;
123   UINT8 MaxDimmsPerChannel;
124   UINT8 *DimmsPerChPtr;
125
126   CurrDct = NBPtr->Dct;
127
128   //
129   // Get Platform Information
130   //
131   DimmsPerChPtr = FindPSOverrideEntry (NBPtr->RefPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, NBPtr->MCTPtr->SocketId, NBPtr->ChannelPtr->ChannelID, 0, NULL, NULL);
132   if (DimmsPerChPtr != NULL) {
133     MaxDimmsPerChannel = *DimmsPerChPtr;
134   } else {
135     MaxDimmsPerChannel = 2;
136   }
137
138   // 1. BIOS disables the phy compensation register by programming F2x9C_x08[DisAutoComp]=1
139   // 2. BIOS waits 5 us for the disabling of the compensation engine to complete.
140   // DisAutoComp will be cleared after Dram init has completed
141   //
142   MemNSwitchDCTNb (NBPtr, 0);
143   MemNSetBitFieldNb (NBPtr, BFDisAutoComp, 1);
144   MemUWait10ns (500, NBPtr->MemPtr);
145   MemNSwitchDCTNb (NBPtr, CurrDct);
146
147   // 3. For each normalized driver strength code read from
148   // F2x[1, 0]9C_x00[AddrCmdDrvStren], program the
149   // corresponding 3 bit predriver code in F2x9C_x0A[D3Cmp1NCal, D3Cmp1PCal].
150   //
151   // 4. For each normalized driver strength code read from
152   // F2x[1, 0]9C_x00[DataDrvStren], program the corresponding
153   // 3 bit predriver code in F2x9C_x0A[D3Cmp0NCal, D3Cmp0PCal, D3Cmp2NCal,
154   // D3Cmp2PCal].
155   //
156   j = (UINT8) MemNGetBitFieldNb (NBPtr, BFAddrCmdDrvStren);
157   i = (UINT8) MemNGetBitFieldNb (NBPtr, BFDataDrvStren);
158
159   MemNSwitchDCTNb (NBPtr, 0);
160   ASSERT (j <= 3);
161   MemNSetBitFieldNb (NBPtr, BFD3Cmp1NCal, TableCompRiseSlew20x[j]);
162   MemNSetBitFieldNb (NBPtr, BFD3Cmp1PCal, TableCompFallSlew20x[j]);
163
164   ASSERT (i <= 3);
165   MemNSetBitFieldNb (NBPtr, BFD3Cmp0NCal, TableCompRiseSlew15x[i]);
166   MemNSetBitFieldNb (NBPtr, BFD3Cmp0PCal, TableCompFallSlew15x[i]);
167   MemNSetBitFieldNb (NBPtr, BFD3Cmp2NCal, TableCompRiseSlew15x[i]);
168   MemNSetBitFieldNb (NBPtr, BFD3Cmp2PCal, TableCompFallSlew15x[i]);
169
170   //
171   // Special Case for certain configs
172   //
173   // 3DPCH Fully populated.
174   if ((MaxDimmsPerChannel == 3) && (NBPtr->ChannelPtr->Dimms == 3)) {
175     MemNSetBitFieldNb (NBPtr, BFD3Cmp0NCal, 3);
176     MemNSetBitFieldNb (NBPtr, BFD3Cmp0PCal, 5);
177     MemNSetBitFieldNb (NBPtr, BFD3Cmp2NCal, 3);
178     MemNSetBitFieldNb (NBPtr, BFD3Cmp2PCal, 5);
179   }
180
181   MemNSwitchDCTNb (NBPtr, CurrDct);
182 }
183
184 /* -----------------------------------------------------------------------------*/
185 /**
186  *
187  *
188  *   This is a general purpose function that executes before DRAM training
189  *
190  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
191  *
192  */
193
194 VOID
195 MemNBeforeDQSTrainingHy (
196   IN OUT   MEM_NB_BLOCK *NBPtr
197   )
198 {
199   UINT8 Dct;
200   UINT8 ChipSel;
201   UINT32 TestAddrRJ16;
202   UINT32 RealAddr;
203
204   MemTBeginTraining (NBPtr->TechPtr);
205
206   for (Dct = 0; Dct < NBPtr->DctCount; Dct++) {
207     MemNSwitchDCTNb (NBPtr, Dct);
208     if (NBPtr->DCTPtr->Timings.DctMemSize != 0) {
209       for (ChipSel = 0; ChipSel < MAX_CS_PER_CHANNEL; ChipSel += 2) {
210         if (MemNGetMCTSysAddrNb (NBPtr, ChipSel, &TestAddrRJ16)) {
211
212           RealAddr = MemUSetUpperFSbase (TestAddrRJ16, NBPtr->MemPtr);
213
214           MemUDummyCLRead (RealAddr);
215
216           MemNSetBitFieldNb (NBPtr, BFErr350, 0x8000);
217           MemUWait10ns (60, NBPtr->MemPtr);   // Wait 300ns
218           MemNSetBitFieldNb (NBPtr, BFErr350, 0x0000);
219           MemUWait10ns (400, NBPtr->MemPtr);  // Wait 2us
220           MemUProcIOClFlush (TestAddrRJ16, 1, NBPtr->MemPtr);
221           break;
222         }
223       }
224     }
225     if (NBPtr->IsSupported[CheckEccDLLPwrDnConfig]) {
226       if (!NBPtr->MCTPtr->Status[SbEccDimms]) {
227         MemNSetBitFieldNb (NBPtr, BFEccDLLPwrDnConf, 0x0010);
228       }
229       if (NBPtr->DCTPtr->Timings.Dimmx4Present == 0) {
230         MemNSetBitFieldNb (NBPtr, BFEccDLLConf, 0x0080);
231       }
232     }
233   }
234
235   MemTEndTraining (NBPtr->TechPtr);
236
237   MemNSetBitFieldNb (NBPtr, BFDisDatMsk, 1);
238 }