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