AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Ardk / RB / masRb3.c
1 /* $NoKeywords:$ */
2 /*
3  * @file
4  *
5  * masRb3.c
6  *
7  * Platform specific settings for RB DDR3 SO-dimms
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/Ardk/RB)
12  * @e \$Revision: 52286 $ @e \$Date: 2011-05-04 03:48:21 -0600 (Wed, 04 May 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 #include "AGESA.h"
49 #include "mport.h"
50 #include "ma.h"
51 #include "OptionMemory.h"
52 #include "PlatformMemoryConfiguration.h"
53 #include "mu.h"
54 #include "Ids.h"
55 #include "cpuFamRegisters.h"
56 #include "Filecode.h"
57 CODE_GROUP (G2_PEI)
58 RDATA_GROUP (G2_PEI)
59
60 #define FILECODE PROC_MEM_ARDK_RB_MASRB3_FILECODE
61 /*----------------------------------------------------------------------------
62  *                          DEFINITIONS AND MACROS
63  *
64  *----------------------------------------------------------------------------
65  */
66
67 /*----------------------------------------------------------------------------
68  *                           TYPEDEFS AND STRUCTURES
69  *
70  *----------------------------------------------------------------------------
71  */
72
73 /*----------------------------------------------------------------------------
74  *                        PROTOTYPES OF LOCAL FUNCTIONS
75  *
76  *----------------------------------------------------------------------------
77  */
78
79 /*
80  *-----------------------------------------------------------------------------
81  *                                EXPORTED FUNCTIONS
82  *
83  *-----------------------------------------------------------------------------
84  */
85
86 STATIC CONST UINT8 ROMDATA RbSDdr3CLKDis[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
87 // Even chip select maps to M[B,A]_CKE[0]
88 // Odd chip select maps to M[B,A]_CKE[1]
89 STATIC CONST UINT8 ROMDATA RbSDdr3CKETri[] = {0x55, 0xAA};
90 // Bit 0: M[B,A]0_ODT[0]
91 // Bit 1: M[B,A]1_ODT[0]
92 // Bit 2: M[B,A]0_ODT[1]
93 // Bit 3: M[B,A]1_ODT[1]
94 STATIC CONST UINT8 ROMDATA RbSDdr3ODTTri[] = {0x01, 0x04, 0x02, 0x08};
95 // Bit 0: M[B,A]0_CS_H/L[0]
96 // Bit 1: M[B,A]0_CS_H/L[1]
97 // Bit 2: M[B,A]0_CS_H/L[2]
98 // Bit 3: M[B,A]0_CS_H/L[3]
99 STATIC CONST UINT8 ROMDATA RbSDdr3CSTri[] = {0x01, 0x02, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00};
100
101 /* -----------------------------------------------------------------------------*/
102 /**
103  *
104  *         This is function sets the platform specific settings for RB DDR3 SO-dimms
105  *
106  *
107  *     @param[in,out]   *MemData           Pointer to MEM_DATA_STRUCTURE
108  *     @param[in]       SocketID          Socket number
109  *     @param[in,out]   *CurrentChannel       Pointer to CH_DEF_STRUCT
110  *
111  *     @return          AGESA_SUCCESS
112  *     @return          CurrentChannel->MemClkDisMap     Points this pointer to RB MemClkDis table
113  *     @return          CurrentChannel->ChipSelTriMap    Points this pointer to RB CS table
114  *     @return          CurrentChannel->CKETriMap        Points this pointer to RB ODT table
115  *     @return          CurrentChannel->ODTTriMap        Points this pointer to RB CKE table
116  *     @return          CurrentChannel->DctEccDQSLike      Indicates the bytes that should be averaged for ECC
117  *     @return          CurrentChannel->DctEccDQSScale     Indicates the scale that should be used for Averaging ECC byte
118  *     @return          CurrentChannel->DctAddrTmg        Address Command Timing Settings for specified channel
119  *     @return          CurrentChannel->DctOdcCtl         Drive Strength settings for specified channel
120  *     @return          CurrentChannel->SlowMode             Slow Mode
121  *
122  *
123  */
124
125 AGESA_STATUS
126 MemAGetPsCfgSRb3 (
127   IN OUT   MEM_DATA_STRUCT *MemData,
128   IN       UINT8 SocketID,
129   IN OUT   CH_DEF_STRUCT *CurrentChannel
130   )
131 {
132   STATIC CONST PSCFG_ENTRY PSCfg[] = {
133     {DDR800_FREQUENCY, 0xFF, 0x00000000, 0x00113222},
134     {DDR1066_FREQUENCY, 0xFF, 0x00000000, 0x10113222},
135     {DDR1333_FREQUENCY, 0xFF, 0x00000000, 0x20113222},
136   };
137
138   STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfgDIMMWlODT[] = {
139     {SR_DIMM1,            {0x00, 0x02, 0x00, 0x00}, 1},
140     {DR_DIMM1,            {0x00, 0x08, 0x00, 0x00}, 1},
141     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, {0x03, 0x03, 0x00, 0x00}, 2}
142   };
143
144   UINT16 i;
145   UINT16 j;
146   UINT8 Loads;
147   UINT8 Dimms;
148   UINT16 Speed;
149   UINT32 AddrTmgCTL;
150   UINT32 DctOdcCtl;
151   UINT8 PhyWLODT[4];
152   BOOLEAN SlowMode;
153   UINT8  MaxDimmPerCH;
154   UINT8 *DimmsPerChPtr;
155   UINT16 DIMMRankType;
156   UINT16 _DIMMRankType;
157   UINT8 DimmTpMatch;
158
159   ASSERT (MemData != 0);
160   ASSERT (CurrentChannel != 0);
161
162   AddrTmgCTL = 0;
163   DctOdcCtl = 0;
164   PhyWLODT[0] = 0x0F;
165   PhyWLODT[1] = 0x0F;
166   PhyWLODT[2] = 0x0F;
167   PhyWLODT[3] = 0x0F;
168   SlowMode = FALSE;  // 1T
169   if ((CurrentChannel->MCTPtr->LogicalCpuid.Family & AMD_FAMILY_10_RB) == 0) {
170     return AGESA_UNSUPPORTED;
171   }
172   if (CurrentChannel->TechType != DDR3_TECHNOLOGY) {
173     return AGESA_UNSUPPORTED;
174   }
175   if (CurrentChannel->SODimmPresent != CurrentChannel->ChDimmValid) {
176     return AGESA_UNSUPPORTED;
177   }
178   // Prepare inputs
179   Loads = CurrentChannel->Loads;
180   Dimms = CurrentChannel->Dimms;
181   Speed = CurrentChannel->DCTPtr->Timings.Speed;
182
183   DIMMRankType = MemAGetPsRankType (CurrentChannel);
184
185   DimmsPerChPtr = FindPSOverrideEntry (MemData->ParameterListPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, SocketID, CurrentChannel->ChannelID, 0, NULL, NULL);
186   if (DimmsPerChPtr != NULL) {
187     MaxDimmPerCH = *DimmsPerChPtr;
188   } else {
189     MaxDimmPerCH = 2;
190   }
191
192   for (i = 0; i < GET_SIZE_OF (PSCfg); i++) {
193     if (Speed == PSCfg[i].Speed) {
194       if (Loads <= PSCfg[i].Loads) {
195         AddrTmgCTL = PSCfg[i].AddrTmg;
196         DctOdcCtl = PSCfg[i].Odc;
197         break;
198       }
199     }
200   }
201
202   // WL ODT
203   for (i = 0; i < GET_SIZE_OF (PSCfgDIMMWlODT); i++) {
204     if (Dimms != PSCfgDIMMWlODT[i].Dimms) {
205       continue;
206     }
207     DimmTpMatch = 0;
208     _DIMMRankType = DIMMRankType & PSCfgDIMMWlODT[i].DIMMRankType;
209     for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
210       if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
211         DimmTpMatch++;
212       }
213     }
214     if (DimmTpMatch == PSCfgDIMMWlODT[i].Dimms) {
215       PhyWLODT[0] = PSCfgDIMMWlODT[i].PhyWrLvOdt[0];
216       PhyWLODT[1] = PSCfgDIMMWlODT[i].PhyWrLvOdt[1];
217       PhyWLODT[2] = PSCfgDIMMWlODT[i].PhyWrLvOdt[2];
218       PhyWLODT[3] = PSCfgDIMMWlODT[i].PhyWrLvOdt[3];
219       break;
220     }
221   }
222
223   //
224   // Overrides and/or exceptions
225   //
226   if (MaxDimmPerCH == 2) {
227     if (Dimms == 2) {
228       DctOdcCtl = 0x20223323;
229       SlowMode = TRUE;
230       if (Speed == DDR800_FREQUENCY) {
231         AddrTmgCTL = 0x00000039;
232       } else if (Speed == DDR1066_FREQUENCY) {
233         AddrTmgCTL = 0x00000037;
234       }
235     } else {
236       DctOdcCtl = 0x20113222;
237     }
238   } else {
239     if (CurrentChannel->DimmSRPresent != 0) {
240       PhyWLODT[0] = 1;
241     } else if (CurrentChannel->DimmDrPresent != 0) {
242       PhyWLODT[0] = 4;
243     }
244   }
245
246   CurrentChannel->MemClkDisMap = (UINT8 *) RbSDdr3CLKDis;
247   CurrentChannel->CKETriMap = (UINT8 *) RbSDdr3CKETri;
248   CurrentChannel->ODTTriMap = (UINT8 *) RbSDdr3ODTTri;
249   CurrentChannel->ChipSelTriMap = (UINT8 *) RbSDdr3CSTri;
250
251   CurrentChannel->DctAddrTmg = AddrTmgCTL;
252   CurrentChannel->DctOdcCtl = DctOdcCtl;
253   for (i = 0; i < sizeof (CurrentChannel->PhyWLODT); i++) {
254     CurrentChannel->PhyWLODT[i] = PhyWLODT[i];
255   }
256   CurrentChannel->SlowMode = SlowMode;
257
258   return AGESA_SUCCESS;
259 }