Add AMD Family 12 cpu Agesa code
[coreboot.git] / src / vendorcode / amd / agesa / f12 / Proc / Mem / Ardk / LN / masln3.c
1 /* $NoKeywords:$ */
2 /*
3  * @file
4  *
5  * masln3.c
6  *
7  * Platform specific settings for LN DDR3 SO-dimms
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/Ardk)
12  * @e \$Revision: 47807 $ @e \$Date: 2011-03-01 01:53:18 +0800 (Tue, 01 Mar 2011) $
13  *
14  **/
15 /*****************************************************************************
16   *
17  * Copyright (c) 2011, 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 /* This file contains routine that add platform specific support AM3 */
46
47
48 #include "AGESA.h"
49 #include "amdlib.h"
50 #include "mport.h"
51 #include "PlatformMemoryConfiguration.h"
52 #include "ma.h"
53 #include "mu.h"
54 #include "Ids.h"
55 #include "F12PackageType.h"
56 #include "cpuFamRegisters.h"
57 #include "Filecode.h"
58 CODE_GROUP (G2_PEI)
59 RDATA_GROUP (G2_PEI)
60
61 #define FILECODE PROC_MEM_ARDK_LN_MASLN3_FILECODE
62 /*----------------------------------------------------------------------------
63  *                          DEFINITIONS AND MACROS
64  *
65  *----------------------------------------------------------------------------
66  */
67
68 /*----------------------------------------------------------------------------
69  *                           TYPEDEFS AND STRUCTURES
70  *
71  *----------------------------------------------------------------------------
72  */
73
74 /*----------------------------------------------------------------------------
75  *                        PROTOTYPES OF LOCAL FUNCTIONS
76  *
77  *----------------------------------------------------------------------------
78  */
79
80 /*
81  *-----------------------------------------------------------------------------
82  *                                EXPORTED FUNCTIONS
83  *
84  *-----------------------------------------------------------------------------
85  */
86
87 STATIC CONST UINT8 ROMDATA LnSDdr3CLKDis[]    = {0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
88 STATIC CONST UINT8 ROMDATA LnSDdr3CLKDisFM1[] = {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00};
89 STATIC CONST UINT8 ROMDATA LnSDdr3CKETri[] = {0x55, 0xAA};
90 STATIC CONST UINT8 ROMDATA LnSDdr3ODTTri[] = {0x01, 0x02, 0x04, 0x08};
91 STATIC CONST UINT8 ROMDATA LnSDdr3CSTri[] = {0x01, 0x02, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00};
92
93 /* -----------------------------------------------------------------------------*/
94 /**
95  *
96  *         This is function sets the platform specific settings for LN DDR3 SO-dimms
97  *
98  *
99  *     @param[in,out]   *MemData           Pointer to MEM_DATA_STRUCTURE
100  *     @param[in]       SocketID          Socket number
101  *     @param[in,out]   *CurrentChannel       Pointer to CH_DEF_STRUCT
102  *
103  *     @return          AGESA_SUCCESS
104  *     @return          CurrentChannel->MemClkDisMap     Points this pointer to LN MemClkDis table
105  *     @return          CurrentChannel->ChipSelTriMap    Points this pointer to LN CS table
106  *     @return          CurrentChannel->CKETriMap        Points this pointer to LN ODT table
107  *     @return          CurrentChannel->ODTTriMap        Points this pointer to LN CKE table
108  *     @return          CurrentChannel->DctEccDQSLike      Indicates the bytes that should be averaged for ECC
109  *     @return          CurrentChannel->DctEccDQSScale     Indicates the scale that should be used for Averaging ECC byte
110  *     @return          CurrentChannel->DctAddrTmg        Address Command Timing Settings for specified channel
111  *     @return          CurrentChannel->DctOdcCtl         Drive Strength settings for specified channel
112  *     @return          CurrentChannel->SlowMode             Slow Mode
113  *
114  *
115  */
116
117 AGESA_STATUS
118 MemAGetPsCfgSLN3 (
119   IN OUT   MEM_DATA_STRUCT *MemData,
120   IN       UINT8 SocketID,
121   IN OUT   CH_DEF_STRUCT *CurrentChannel
122   )
123 {
124   STATIC CONST ADV_PSCFG_ENTRY PSCfg[] = {
125     {DDR800_FREQUENCY, ANY_, 0x00000000, 0x00002222, 1},
126     {DDR800_FREQUENCY, ANY_, 0x00000039, 0x20222323, 2},
127     {DDR1066_FREQUENCY, ANY_, 0x003D3D3D, 0x10002222, 1},
128     {DDR1066_FREQUENCY, ANY_, 0x00000037, 0x30222323, 2},
129     {DDR1333_FREQUENCY, ANY_, 0x003D3D3D, 0x20002222, 1},
130     {DDR1333_FREQUENCY, ANY_, 0x00000035, 0x30222323, 2},
131     {DDR1600_FREQUENCY, ANY_, 0x003C3C3C, 0x30112222, 1},
132     {DDR1600_FREQUENCY, ANY_, 0x00000033, 0x30222323, 2},
133     {DDR1866_FREQUENCY, ANY_, 0x00003C3C, 0x30112222, 1},
134     {DDR1866_FREQUENCY, ANY_, 0x00000031, 0x30222323, 2},
135   };
136   //
137   // DIMM ODT Pattern
138   //
139   // Dimm Config ,
140   // Fn2_F4 180, Fn2_F4 181, Fn2_F4 182, Fn2_F4 183, # Dimms to match
141   //
142   STATIC CONST ADV_PSCFG_ODT_ENTRY PSCfgDIMMsODT[] = {
143     {SR_DIMM0, \
144       0x00000000, 0x00000000, 0x00000001, 0x00000000, 1},
145     {DR_DIMM0, \
146       0x00000000, 0x00000000, 0x00000201, 0x00000000, 1},
147     {SR_DIMM1, \
148       0x00000000, 0x00000000, 0x00040000, 0x00000000, 1},
149     {DR_DIMM1, \
150       0x00000000, 0x00000000, 0x08040000, 0x00000000, 1},
151     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
152       0x01010404, 0x00000000, 0x09050605, 0x00000000, 2}
153   };
154
155   UINT16 i;
156   UINT16 j;
157   UINT8 Loads;
158   UINT8 Dimms;
159   UINT16 Speed;
160   UINT32 AddrTmgCTL;
161   UINT32 DctOdcCtl;
162   UINT32 PhyRODTCS;
163   UINT32 PhyWODTCS;
164   UINT8 PhyWLODT[4];
165   BOOLEAN SlowMode;
166   UINT16 DIMMRankType;
167   UINT16 _DIMMRankType;
168   UINT8 DimmTpMatch;
169   UINT8 *DimmsPerChPtr;
170   UINT8 DimmsPerCH;
171
172   ASSERT (MemData != 0);
173   ASSERT (CurrentChannel != 0);
174
175   AddrTmgCTL = 0;
176   DctOdcCtl = 0;
177   PhyRODTCS = 0;
178   PhyWODTCS = 0;
179   PhyWLODT[0] = 0x0F;
180   PhyWLODT[1] = 0x0F;
181   PhyWLODT[2] = 0x0F;
182   PhyWLODT[3] = 0x0F;
183
184   if ((CurrentChannel->MCTPtr->LogicalCpuid.Family & AMD_FAMILY_LN) == 0) {
185     return AGESA_UNSUPPORTED;
186   }
187   if (CurrentChannel->TechType != DDR3_TECHNOLOGY) {
188     return AGESA_UNSUPPORTED;
189   }
190   if (CurrentChannel->SODimmPresent != CurrentChannel->ChDimmValid) {
191     return AGESA_UNSUPPORTED;
192   }
193
194   // Prepare inputs
195   DIMMRankType = MemAGetPsRankType (CurrentChannel);
196   Loads = CurrentChannel->Loads;
197   Dimms = CurrentChannel->Dimms;
198   Speed = CurrentChannel->DCTPtr->Timings.Speed;
199   SlowMode = TRUE;  // 2T
200   DimmsPerChPtr = FindPSOverrideEntry (MemData->ParameterListPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, SocketID, CurrentChannel->ChannelID);
201   if (DimmsPerChPtr != NULL) {
202     DimmsPerCH = *DimmsPerChPtr;
203   } else {
204     DimmsPerCH = 1;
205   }
206
207   for (i = 0; i < GET_SIZE_OF (PSCfg); i++) {
208     if ((PSCfg[i].Dimms == ANY_) || (PSCfg[i].Dimms == Dimms)) {
209       if ((PSCfg[i].Speed == ANY_) || (PSCfg[i].Speed == Speed)) {
210         if ((PSCfg[i].Loads == ANY_) || (PSCfg[i].Loads >= Loads)) {
211           AddrTmgCTL = PSCfg[i].AddrTmg;
212           DctOdcCtl = PSCfg[i].Odc;
213           break;
214         }
215       }
216     }
217   }
218   ASSERT (i < GET_SIZE_OF (PSCfg));
219
220   // Exceptions
221   if (Dimms == 1) {
222     if (Speed != DDR1866_FREQUENCY) {
223       SlowMode = FALSE;
224     }
225     if (CurrentChannel->DimmDrPresent != 0) {
226       if (Speed == DDR1066_FREQUENCY) {
227         AddrTmgCTL = 0x00000000;
228       } else if (Speed == DDR1333_FREQUENCY) {
229         AddrTmgCTL = 0x00003D3D;
230       } else if (Speed == DDR1600_FREQUENCY) {
231         AddrTmgCTL = 0x00003C3C;
232         SlowMode = TRUE;
233       }
234     }
235   }
236
237   //
238   // Programmable ODT pattern
239   //
240   for (i = 0; i  < GET_SIZE_OF (PSCfgDIMMsODT); i++) {
241     if (Dimms != PSCfgDIMMsODT[i].Dimms) {
242       continue;
243     }
244     DimmTpMatch = 0;
245     _DIMMRankType = DIMMRankType & PSCfgDIMMsODT[i].DIMMRankType;
246     for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
247       if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
248         DimmTpMatch++;
249       }
250     }
251     if (DimmTpMatch == PSCfgDIMMsODT[i].Dimms) {
252       PhyRODTCS = PSCfgDIMMsODT[i].PhyRODTCSLow;
253       PhyWODTCS = PSCfgDIMMsODT[i].PhyWODTCSLow;
254       break;
255     }
256   }
257
258   //
259   // WL ODT
260   //
261   PhyWLODT[0] = PhyWLODT[2] = (UINT8) (PhyWODTCS & 0x0F);
262   PhyWLODT[1] = PhyWLODT[3] = (UINT8) ((PhyWODTCS >> 16) & 0x0F);
263
264   if (LibAmdGetPackageType (&(MemData->StdHeader)) == PACKAGE_TYPE_FM1) {
265     CurrentChannel->MemClkDisMap = (UINT8 *) LnSDdr3CLKDisFM1;
266   } else {
267     CurrentChannel->MemClkDisMap = (UINT8 *) LnSDdr3CLKDis;
268   }
269   CurrentChannel->CKETriMap = (UINT8 *) LnSDdr3CKETri;
270   CurrentChannel->ODTTriMap = (UINT8 *) LnSDdr3ODTTri;
271   CurrentChannel->ChipSelTriMap = (UINT8 *) LnSDdr3CSTri;
272
273   CurrentChannel->DctAddrTmg = AddrTmgCTL;
274   CurrentChannel->DctOdcCtl = DctOdcCtl;
275   CurrentChannel->PhyRODTCSLow  = PhyRODTCS;
276   CurrentChannel->PhyWODTCSLow  = PhyWODTCS;
277   for (i = 0; i < sizeof (CurrentChannel->PhyWLODT); i++) {
278     CurrentChannel->PhyWLODT[i] = PhyWLODT[i];
279   }
280   CurrentChannel->SlowMode = SlowMode;
281
282   if ((DimmsPerCH == 2) && (Speed >= DDR1333_FREQUENCY) && (Dimms == 1)) {
283     // Set Dqs and DQ drive strength to 1.0x for 1 dimm on 2 dimms per channel DDR3-1333
284     CurrentChannel->DctOdcCtl |= 0x110000;
285   }
286
287   return AGESA_SUCCESS;
288 }