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