blob: 32a5ba7b96b67bba51c522bfe069e84addcbb7b1 [file] [log] [blame]
Patrick Georgi2efc8802012-11-06 11:03:53 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include <stdint.h>
23#include <stddef.h>
24#include <string.h>
25#include <arch/io.h>
26#include <arch/romcc_io.h>
27#include <device/pci_def.h>
28#include <device/pnp_def.h>
29#include <console/console.h>
30#include <cpu/x86/msr.h>
31
32#include "gm45.h"
33
34static int sku_freq_index(const gmch_gfx_t sku, const int low_power_mode)
35{
36 if (low_power_mode)
37 return 1;
38 switch (sku) {
39 case GMCH_GM45:
40 case GMCH_GE45:
41 case GMCH_GS45:
42 return 0;
43 case GMCH_GM47:
44 return 2;
45 case GMCH_GM49:
46 return 3;
47 default:
48 return 0;
49 }
50}
51static void init_freq_scaling(const gmch_gfx_t sku, const int low_power_mode)
52{
53 int i;
54
55 MCHBAR32(0x11cc) = (MCHBAR32(0x11cc) & ~(0x1f)) | 0x17;
56 switch (sku) {
57 case GMCH_GM45:
58 case GMCH_GE45:
59 case GMCH_GS45:
60 case GMCH_GM47:
61 case GMCH_GM49:
62 break;
63 default:
64 /* No more to be done for the others. */
65 return;
66 }
67
68 static const u32 voltage_mask =
69 (0x1f << 24) | (0x1f << 16) | (0x1f << 8) | 0x1f;
70 MCHBAR32(0x1120) = (MCHBAR32(0x1120) & ~voltage_mask) | 0x10111213;
71 MCHBAR32(0x1124) = (MCHBAR32(0x1124) & ~voltage_mask) | 0x14151617;
72 MCHBAR32(0x1128) = (MCHBAR32(0x1128) & ~voltage_mask) | 0x18191a1b;
73 MCHBAR32(0x112c) = (MCHBAR32(0x112c) & ~voltage_mask) | 0x1c1d1e1f;
74 MCHBAR32(0x1130) = (MCHBAR32(0x1130) & ~voltage_mask) | 0x00010203;
75 MCHBAR32(0x1134) = (MCHBAR32(0x1134) & ~voltage_mask) | 0x04050607;
76 MCHBAR32(0x1138) = (MCHBAR32(0x1138) & ~voltage_mask) | 0x08090a0b;
77 MCHBAR32(0x113c) = (MCHBAR32(0x113c) & ~voltage_mask) | 0x0c0d0e0f;
78
79 /* Program frequencies. */
80 static const u32 frequencies_from_sku_vco[][4][8] = {
81 /* GM45/GE45/GS45_perf */ {
82 /* VCO 2666 */ { 0xcd, 0xbc, 0x9b, 0x8a, 0x79, 0x78, 0x67, 0x56 },
83 /* VCO 3200 */ { 0xcd, 0xac, 0x9b, 0x8a, 0x89, 0x78, 0x67, 0x56 },
84 /* VCO 4000 */ { 0xac, 0x9b, 0x9a, 0x89, 0x89, 0x68, 0x56, 0x45 },
85 /* VCO 5333 */ { 0xab, 0x9a, 0x79, 0x68, 0x57, 0x56, 0x45, 0x34 },
86 },
87 /* GS45_low_power */ {
88 /* VCO 2666 */ { 0xcd, 0x8a },
89 /* VCO 3200 */ { 0xcd, 0x89 },
90 /* VCO 4000 */ { 0xac, 0x89 },
91 /* VCO 5333 */ { 0xab, 0x68 },
92 },
93 /* GM47 */ {
94 /* VCO 2666 */ { 0xcd, 0xcd, 0xbc, 0x9b, 0x79, 0x78, 0x67, 0x56 },
95 /* VCO 3200 */ { 0xde, 0xcd, 0xac, 0x9b, 0x89, 0x78, 0x67, 0x56 },
96 /* VCO 4000 */ { 0xcd, 0xac, 0x9b, 0x9a, 0x89, 0x68, 0x56, 0x45 },
97 /* VCO 5333 */ { 0xac, 0xab, 0x9a, 0x79, 0x68, 0x56, 0x45, 0x34 },
98 },
99 /* GM49 */ {
100 /* VCO 2666 */ { },
101 /* VCO 3200 */ { 0xef, 0xde, 0xcd, 0xac, 0x89, 0x78, 0x67, 0x56 },
102 /* VCO 4000 */ { 0xef, 0xde, 0xac, 0x9b, 0x89, 0x68, 0x56, 0x45 },
103 /* VCO 5333 */ { 0xce, 0xbd, 0xab, 0x9a, 0x68, 0x57, 0x45, 0x34 },
104 }};
105 const int sku_index = sku_freq_index(sku, low_power_mode);
106 const int vco_index = raminit_read_vco_index();
107 const int reg_limit = low_power_mode ? 1 : 4;
108 if (sku == GMCH_GM49)
109 MCHBAR8(0x1110+3) = 0x1b;
110 else
111 MCHBAR8(0x1110+3) = 0x17;
112 MCHBAR8(0x1110+1) = 0x17;
113 if (!low_power_mode) {
114 MCHBAR8(0x1114+3) = 0x17;
115 MCHBAR8(0x1114+1) = 0x17;
116 MCHBAR8(0x1118+3) = 0x17;
117 MCHBAR8(0x1118+1) = 0x17;
118 MCHBAR8(0x111c+3) = 0x17;
119 MCHBAR8(0x111c+1) = 0x17;
120 }
121 for (i = 0; i < reg_limit; ++i) {
122 const int mchbar = 0x1110 + (i * 4);
123 MCHBAR8(mchbar + 2) = frequencies_from_sku_vco
124 [sku_index][vco_index][i * 2 + 0];
125 MCHBAR8(mchbar + 0) = frequencies_from_sku_vco
126 [sku_index][vco_index][i * 2 + 1];
127 }
128
129 if (low_power_mode) {
130 MCHBAR16(0x1190) =
131 (MCHBAR16(0x1190) & ~((7 << 8) | (7 << 4) | 7)) |
132 (1 << 8) | (1 << 4) | 1;
133 } else {
134 MCHBAR16(0x1190) =
135 (MCHBAR16(0x1190) & ~((7 << 8) | (7 << 4))) | 7;
136 if (sku == GMCH_GS45) /* performance mode */
137 MCHBAR32(0x0ffc) &= ~(1 << 31);
138 }
139
140 MCHBAR16(0x0fc0) |= (1 << 11);
141 MCHBAR16(0x11b8) = 0x333c;
142 MCHBAR16(0x11c0 + 2) = 0x0303;
143 MCHBAR32(0x11c4) = 0x0a030a03;
144 MCHBAR16(0x1100) = (MCHBAR16(0x1100) & ~(0x1f << 8)) | (3 << 8);
145 MCHBAR16(0x11b8 + 2) = 0x4000;
146}
147
148void init_pm(const sysinfo_t *const sysinfo)
149{
150 const stepping_t stepping = sysinfo->stepping;
151 const fsb_clock_t fsb = sysinfo->selected_timings.fsb_clock;
152 const mem_clock_t memclk = sysinfo->selected_timings.mem_clock;
153
154 MCHBAR16(0xc14) = 0;
155 MCHBAR16(0xc20) = 0;
156 MCHBAR32(0xfc0) = 0x001f00fd;
157 MCHBAR32(0xfc0) |= 3 << 25;
158 MCHBAR32(0xfc0) |= 1 << 11;
159 MCHBAR8(0xfb0) = 3;
160 MCHBAR8(0xf10) |= 1 << 1;
161 if (fsb == FSB_CLOCK_667MHz) {
162 MCHBAR16(0xc3a) = 0xea6;
163 MCHBAR8(0xc16) = (MCHBAR8(0xc16) & 0x80) | 0x0e;
164 } else if (fsb == FSB_CLOCK_800MHz) {
165 MCHBAR16(0xc3a) = 0x1194;
166 MCHBAR8(0xc16) = (MCHBAR8(0xc16) & 0x80) | 0x10;
167 } else if (fsb == FSB_CLOCK_1067MHz) {
168 MCHBAR16(0xc3a) = 0x1777;
169 MCHBAR8(0xc16) = (MCHBAR8(0xc16) & 0x80) | 0x15;
170 }
171 MCHBAR8(0xfb8) = 3;
172 if (fsb == FSB_CLOCK_667MHz)
173 MCHBAR16(0xc38) = 0x0ea6;
174 else if (fsb == FSB_CLOCK_800MHz)
175 MCHBAR16(0xc38) = 0x1194;
176 else if (fsb == FSB_CLOCK_1067MHz)
177 MCHBAR16(0xc38) = 0x1777;
178 MCHBAR8(0xf10) |= 1 << 5;
179 MCHBAR16(0xc16) |= 3 << 12;
180 MCHBAR32(0xf60) = 0x01030419;
181 if (fsb == FSB_CLOCK_667MHz) {
182 MCHBAR32(0xf00) = 0x00000600;
183 MCHBAR32(0xf04) = 0x00001d80;
184 } else if (fsb == FSB_CLOCK_800MHz) {
185 MCHBAR32(0xf00) = 0x00000700;
186 MCHBAR32(0xf04) = 0x00002380;
187 } else if (fsb == FSB_CLOCK_1067MHz) {
188 MCHBAR32(0xf00) = 0x00000900;
189 MCHBAR32(0xf04) = 0x00002e80;
190 }
191 MCHBAR16(0xf08) = 0x730f;
192 if (fsb == FSB_CLOCK_667MHz)
193 MCHBAR16(0xf0c) = 0x0b96;
194 else if (fsb == FSB_CLOCK_800MHz)
195 MCHBAR16(0xf0c) = 0x0c99;
196 else if (fsb == FSB_CLOCK_1067MHz)
197 MCHBAR16(0xf0c) = 0x10a4;
198 MCHBAR32(0xf80) |= 1 << 31;
199
200 MCHBAR32(0x40) = (MCHBAR32(0x40) & ~(0x3f << 24)) |
201 (sysinfo->cores == 4) ? (1 << 24) : 0;
202
203 MCHBAR32(0x40) &= ~(1 << 19);
204 MCHBAR32(0x40) |= 1 << 13;
205 MCHBAR32(0x40) |= 1 << 21;
206 MCHBAR32(0x40) |= 1 << 9;
207 if (stepping > STEPPING_B1) {
208 if (fsb != FSB_CLOCK_1067MHz) {
209 MCHBAR32(0x70) |= 1 << 30;
210 } else {
211 MCHBAR32(0x70) &= ~(1 << 30);
212 }
213 }
214 if (stepping < STEPPING_B1)
215 MCHBAR32(0x70) |= 1 << 29;
216 else
217 MCHBAR32(0x70) &= ~(1 << 29);
218 if (stepping > STEPPING_B1) {
219 MCHBAR32(0x70) |= 1 << 28;
220 MCHBAR32(0x70) |= 1 << 25;
221 }
222 if (stepping > STEPPING_B0) {
223 if (fsb != FSB_CLOCK_667MHz)
224 MCHBAR32(0x70) = (MCHBAR32(0x70) & ~(3<<21)) | (1 << 21);
225 else
226 MCHBAR32(0x70) = (MCHBAR32(0x70) & ~(3<<21));
227 }
228 if (stepping > STEPPING_B2)
229 MCHBAR32(0x44) |= 1 << 30;
230 MCHBAR32(0x44) |= 1 << 31;
231 if (sysinfo->cores == 2)
232 MCHBAR32(0x44) |= 1 << 26;
233 MCHBAR32(0x44) |= 1 << 21;
234 MCHBAR32(0x44) = (MCHBAR32(0x44) & ~(3 << 24)) | (2 << 24);
235 MCHBAR32(0x44) |= 1 << 5;
236 MCHBAR32(0x44) |= 1 << 4;
237 MCHBAR32(0x90) = (MCHBAR32(0x90) & ~7) | 4;
238 MCHBAR32(0x94) |= 1 << 29;
239 MCHBAR32(0x94) |= 1 << 11;
240 if (stepping < STEPPING_B0)
241 MCHBAR32(0x94) = (MCHBAR32(0x94) & ~(3 << 19)) | (2 << 19);
242 if (stepping > STEPPING_B2)
243 MCHBAR32(0x94) |= 1 << 21;
244 MCHBAR8(0xb00) &= ~1;
245 MCHBAR8(0xb00) |= 1 << 7;
246 if (fsb != FSB_CLOCK_1067MHz)
247 MCHBAR8(0x75) |= 1 << 6;
248 else
249 MCHBAR8(0x75) &= 1 << 1;
250 MCHBAR8(0x77) |= 3;
251 if (stepping >= STEPPING_B1)
252 MCHBAR8(0x77) |= 1 << 2;
253 if (stepping > STEPPING_B2)
254 MCHBAR8(0x77) |= 1 << 4;
255 if (MCHBAR16(0x90) & 0x100)
256 MCHBAR8(0x90) &= ~(7 << 4);
257 if (stepping >= STEPPING_B0)
258 MCHBAR8(0xd0) |= 1 << 1;
259 MCHBAR8(0xbd8) |= 3 << 2;
260 if (stepping >= STEPPING_B3)
261 MCHBAR32(0x70) |= 1 << 0;
262 MCHBAR32(0x70) |= 1 << 3;
263 if (stepping >= STEPPING_B0)
264 MCHBAR32(0x70) &= ~(1 << 16);
265 else
266 MCHBAR32(0x70) |= 1 << 16;
267 if (stepping >= STEPPING_B3)
268 MCHBAR8(0xc14) |= 1 << 1;
269 if (stepping >= STEPPING_B1)
270 MCHBAR16(0xffc) = (MCHBAR16(0xffc) & ~0x7ff) | 0x7c0;
271 MCHBAR16(0x48) = (MCHBAR16(0x48) & ~(0xff << 2)) | (0xaa << 2);
272 if (stepping == STEPPING_CONVERSION_A1) {
273 MCHBAR16(0x40) |= 1 << 12;
274 MCHBAR32(0x94) |= 3 << 22;
275 }
276
277 const int cpu_supports_super_lfm = rdmsr(0xee).lo & (1 << 27);
278 if ((stepping >= STEPPING_B0) && cpu_supports_super_lfm) {
279 MCHBAR16(CLKCFG_MCHBAR) &= ~(1 << 7);
280 MCHBAR16(CLKCFG_MCHBAR) |= 1 << 14;
281 } else {
282 MCHBAR16(CLKCFG_MCHBAR) &= ~(1 << 14);
283 MCHBAR16(CLKCFG_MCHBAR) |= 1 << 7;
284 MCHBAR32(0x44) &= ~(1 << 31); /* Was set above. */
285 }
286
287 if ((sysinfo->gfx_type != GMCH_PM45) &&
288 (sysinfo->gfx_type != GMCH_UNKNOWN))
289 init_freq_scaling(sysinfo->gfx_type,
290 sysinfo->gs45_low_power_mode);
291
292 /* This has to be the last write to CLKCFG. */
293 if ((fsb == FSB_CLOCK_1067MHz) && (memclk == MEM_CLOCK_667MT))
294 MCHBAR32(CLKCFG_MCHBAR) &= ~(1 << 17);
295}