blob: 4a043ebb35fe2765e1a4cad4e64470f169b7e6af [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Chromium OS Authors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer00636b02012-04-04 00:08:51 +020018 */
19
20#include <arch/io.h>
21#include <console/console.h>
22#include <delay.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
Ronald G. Minnich69efaa02013-02-26 10:07:40 -080026#include <device/pci_ops.h>
27#include <cpu/x86/msr.h>
28#include <cpu/x86/mtrr.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020029
30#include "chip.h"
31#include "sandybridge.h"
32
Duncan Lauriedd585b82012-04-09 12:05:18 -070033struct gt_powermeter {
34 u16 reg;
35 u32 value;
36};
37
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070038static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070039 { 0xa200, 0xcc000000 },
40 { 0xa204, 0x07000040 },
41 { 0xa208, 0x0000fe00 },
42 { 0xa20c, 0x00000000 },
43 { 0xa210, 0x17000000 },
44 { 0xa214, 0x00000021 },
45 { 0xa218, 0x0817fe19 },
46 { 0xa21c, 0x00000000 },
47 { 0xa220, 0x00000000 },
48 { 0xa224, 0xcc000000 },
49 { 0xa228, 0x07000040 },
50 { 0xa22c, 0x0000fe00 },
51 { 0xa230, 0x00000000 },
52 { 0xa234, 0x17000000 },
53 { 0xa238, 0x00000021 },
54 { 0xa23c, 0x0817fe19 },
55 { 0xa240, 0x00000000 },
56 { 0xa244, 0x00000000 },
57 { 0xa248, 0x8000421e },
58 { 0 }
59};
60
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070061static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070062 { 0xa200, 0x330000a6 },
63 { 0xa204, 0x402d0031 },
64 { 0xa208, 0x00165f83 },
65 { 0xa20c, 0xf1000000 },
66 { 0xa210, 0x00000000 },
67 { 0xa214, 0x00160016 },
68 { 0xa218, 0x002a002b },
69 { 0xa21c, 0x00000000 },
70 { 0xa220, 0x00000000 },
71 { 0xa224, 0x330000a6 },
72 { 0xa228, 0x402d0031 },
73 { 0xa22c, 0x00165f83 },
74 { 0xa230, 0xf1000000 },
75 { 0xa234, 0x00000000 },
76 { 0xa238, 0x00160016 },
77 { 0xa23c, 0x002a002b },
78 { 0xa240, 0x00000000 },
79 { 0xa244, 0x00000000 },
80 { 0xa248, 0x8000421e },
81 { 0 }
82};
83
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070084static const struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070085 { 0xa800, 0x00000000 },
86 { 0xa804, 0x00021c00 },
87 { 0xa808, 0x00000403 },
88 { 0xa80c, 0x02001700 },
89 { 0xa810, 0x05000200 },
90 { 0xa814, 0x00000000 },
91 { 0xa818, 0x00690500 },
92 { 0xa81c, 0x0000007f },
93 { 0xa820, 0x01002501 },
94 { 0xa824, 0x00000300 },
95 { 0xa828, 0x01000331 },
96 { 0xa82c, 0x0000000c },
97 { 0xa830, 0x00010016 },
98 { 0xa834, 0x01100101 },
99 { 0xa838, 0x00010103 },
100 { 0xa83c, 0x00041300 },
101 { 0xa840, 0x00000b30 },
102 { 0xa844, 0x00000000 },
103 { 0xa848, 0x7f000000 },
104 { 0xa84c, 0x05000008 },
105 { 0xa850, 0x00000001 },
106 { 0xa854, 0x00000004 },
107 { 0xa858, 0x00000007 },
108 { 0xa85c, 0x00000000 },
109 { 0xa860, 0x00010000 },
110 { 0xa248, 0x0000221e },
111 { 0xa900, 0x00000000 },
112 { 0xa904, 0x00001c00 },
113 { 0xa908, 0x00000000 },
114 { 0xa90c, 0x06000000 },
115 { 0xa910, 0x09000200 },
116 { 0xa914, 0x00000000 },
117 { 0xa918, 0x00590000 },
118 { 0xa91c, 0x00000000 },
119 { 0xa920, 0x04002501 },
120 { 0xa924, 0x00000100 },
121 { 0xa928, 0x03000410 },
122 { 0xa92c, 0x00000000 },
123 { 0xa930, 0x00020000 },
124 { 0xa934, 0x02070106 },
125 { 0xa938, 0x00010100 },
126 { 0xa93c, 0x00401c00 },
127 { 0xa940, 0x00000000 },
128 { 0xa944, 0x00000000 },
129 { 0xa948, 0x10000e00 },
130 { 0xa94c, 0x02000004 },
131 { 0xa950, 0x00000001 },
132 { 0xa954, 0x00000004 },
133 { 0xa960, 0x00060000 },
134 { 0xaa3c, 0x00001c00 },
135 { 0xaa54, 0x00000004 },
136 { 0xaa60, 0x00060000 },
137 { 0 }
138};
139
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700140static const struct gt_powermeter ivb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700141 { 0xa800, 0x10000000 },
142 { 0xa804, 0x00033800 },
143 { 0xa808, 0x00000902 },
144 { 0xa80c, 0x0c002f00 },
145 { 0xa810, 0x12000400 },
146 { 0xa814, 0x00000000 },
147 { 0xa818, 0x00d20800 },
148 { 0xa81c, 0x00000002 },
149 { 0xa820, 0x03004b02 },
150 { 0xa824, 0x00000600 },
151 { 0xa828, 0x07000773 },
152 { 0xa82c, 0x00000000 },
153 { 0xa830, 0x00010032 },
154 { 0xa834, 0x1520040d },
155 { 0xa838, 0x00020105 },
156 { 0xa83c, 0x00083700 },
157 { 0xa840, 0x0000151d },
158 { 0xa844, 0x00000000 },
159 { 0xa848, 0x20001b00 },
160 { 0xa84c, 0x0a000010 },
161 { 0xa850, 0x00000000 },
162 { 0xa854, 0x00000008 },
163 { 0xa858, 0x00000008 },
164 { 0xa85c, 0x00000000 },
165 { 0xa860, 0x00020000 },
166 { 0xa248, 0x0000221e },
167 { 0xa900, 0x00000000 },
168 { 0xa904, 0x00003500 },
169 { 0xa908, 0x00000000 },
170 { 0xa90c, 0x0c000000 },
171 { 0xa910, 0x12000500 },
172 { 0xa914, 0x00000000 },
173 { 0xa918, 0x00b20000 },
174 { 0xa91c, 0x00000000 },
175 { 0xa920, 0x08004b02 },
176 { 0xa924, 0x00000200 },
177 { 0xa928, 0x07000820 },
178 { 0xa92c, 0x00000000 },
179 { 0xa930, 0x00030000 },
180 { 0xa934, 0x050f020d },
181 { 0xa938, 0x00020300 },
182 { 0xa93c, 0x00903900 },
183 { 0xa940, 0x00000000 },
184 { 0xa944, 0x00000000 },
185 { 0xa948, 0x20001b00 },
186 { 0xa94c, 0x0a000010 },
187 { 0xa950, 0x00000000 },
188 { 0xa954, 0x00000008 },
189 { 0xa960, 0x00110000 },
190 { 0xaa3c, 0x00003900 },
191 { 0xaa54, 0x00000008 },
192 { 0xaa60, 0x00110000 },
193 { 0 }
194};
195
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700196static const struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700197 { 0xa800, 0x20000000 },
198 { 0xa804, 0x000e3800 },
199 { 0xa808, 0x00000806 },
200 { 0xa80c, 0x0c002f00 },
201 { 0xa810, 0x0c000800 },
202 { 0xa814, 0x00000000 },
203 { 0xa818, 0x00d20d00 },
204 { 0xa81c, 0x000000ff },
205 { 0xa820, 0x03004b02 },
206 { 0xa824, 0x00000600 },
207 { 0xa828, 0x07000773 },
208 { 0xa82c, 0x00000000 },
209 { 0xa830, 0x00020032 },
210 { 0xa834, 0x1520040d },
211 { 0xa838, 0x00020105 },
212 { 0xa83c, 0x00083700 },
213 { 0xa840, 0x000016ff },
214 { 0xa844, 0x00000000 },
215 { 0xa848, 0xff000000 },
216 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700217 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700218 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700219 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700220 { 0xa85c, 0x00000000 },
221 { 0xa860, 0x00020000 },
222 { 0xa248, 0x0000221e },
223 { 0xa900, 0x00000000 },
224 { 0xa904, 0x00003800 },
225 { 0xa908, 0x00000000 },
226 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700227 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700228 { 0xa914, 0x00000000 },
229 { 0xa918, 0x00b20000 },
230 { 0xa91c, 0x00000000 },
231 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700232 { 0xa924, 0x00000300 },
233 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700234 { 0xa92c, 0x00000000 },
235 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700236 { 0xa934, 0x15150406 },
237 { 0xa938, 0x00020300 },
238 { 0xa93c, 0x00903900 },
239 { 0xa940, 0x00000000 },
240 { 0xa944, 0x00000000 },
241 { 0xa948, 0x20001b00 },
242 { 0xa94c, 0x0a000010 },
243 { 0xa950, 0x00000000 },
244 { 0xa954, 0x00000008 },
245 { 0xa960, 0x00110000 },
246 { 0xaa3c, 0x00003900 },
247 { 0xaa54, 0x00000008 },
248 { 0xaa60, 0x00110000 },
249 { 0 }
250};
251
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700252static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700253 { 0xa800, 0x00000000 },
254 { 0xa804, 0x00030400 },
255 { 0xa808, 0x00000806 },
256 { 0xa80c, 0x0c002f00 },
257 { 0xa810, 0x0c000300 },
258 { 0xa814, 0x00000000 },
259 { 0xa818, 0x00d20d00 },
260 { 0xa81c, 0x000000ff },
261 { 0xa820, 0x03004b02 },
262 { 0xa824, 0x00000600 },
263 { 0xa828, 0x07000773 },
264 { 0xa82c, 0x00000000 },
265 { 0xa830, 0x00020032 },
266 { 0xa834, 0x1520040d },
267 { 0xa838, 0x00020105 },
268 { 0xa83c, 0x00083700 },
269 { 0xa840, 0x000016ff },
270 { 0xa844, 0x00000000 },
271 { 0xa848, 0xff000000 },
272 { 0xa84c, 0x0a000010 },
273 { 0xa850, 0x00000001 },
274 { 0xa854, 0x00000008 },
275 { 0xa858, 0x00000008 },
276 { 0xa85c, 0x00000000 },
277 { 0xa860, 0x00020000 },
278 { 0xa248, 0x0000221e },
279 { 0xa900, 0x00000000 },
280 { 0xa904, 0x00003800 },
281 { 0xa908, 0x00000000 },
282 { 0xa90c, 0x0c000000 },
283 { 0xa910, 0x12000800 },
284 { 0xa914, 0x00000000 },
285 { 0xa918, 0x00b20000 },
286 { 0xa91c, 0x00000000 },
287 { 0xa920, 0x08004b02 },
288 { 0xa924, 0x00000300 },
289 { 0xa928, 0x01000820 },
290 { 0xa92c, 0x00000000 },
291 { 0xa930, 0x00030000 },
292 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700293 { 0xa938, 0x00020300 },
294 { 0xa93c, 0x00903900 },
295 { 0xa940, 0x00000000 },
296 { 0xa944, 0x00000000 },
297 { 0xa948, 0x20001b00 },
298 { 0xa94c, 0x0a000010 },
299 { 0xa950, 0x00000000 },
300 { 0xa954, 0x00000008 },
301 { 0xa960, 0x00110000 },
302 { 0xaa3c, 0x00003900 },
303 { 0xaa54, 0x00000008 },
304 { 0xaa60, 0x00110000 },
305 { 0 }
306};
307
Stefan Reinauer00636b02012-04-04 00:08:51 +0200308/* some vga option roms are used for several chipsets but they only have one
309 * PCI ID in their header. If we encounter such an option rom, we need to do
310 * the mapping ourselfes
311 */
312
313u32 map_oprom_vendev(u32 vendev)
314{
315 u32 new_vendev=vendev;
316
317 switch (vendev) {
Martin Rothe9dfdd92012-04-26 16:04:18 -0600318 case 0x80860102: /* GT1 Desktop */
319 case 0x8086010a: /* GT1 Server */
320 case 0x80860112: /* GT2 Desktop */
321 case 0x80860116: /* GT2 Mobile */
322 case 0x80860122: /* GT2 Desktop >=1.3GHz */
323 case 0x80860126: /* GT2 Mobile >=1.3GHz */
Stefan Reinauer816e9d12013-01-14 10:25:43 -0800324 case 0x80860156: /* IVB */
Martin Rothe9dfdd92012-04-26 16:04:18 -0600325 case 0x80860166: /* IVB */
326 new_vendev=0x80860106; /* GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200327 break;
328 }
329
330 return new_vendev;
331}
332
333static struct resource *gtt_res = NULL;
334
335static inline u32 gtt_read(u32 reg)
336{
337 return read32(gtt_res->base + reg);
338}
339
340static inline void gtt_write(u32 reg, u32 data)
341{
342 write32(gtt_res->base + reg, data);
343}
344
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700345static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700346{
347 for (; pm && pm->reg; pm++)
348 gtt_write(pm->reg, pm->value);
349}
350
Stefan Reinauer00636b02012-04-04 00:08:51 +0200351#define GTT_RETRY 1000
352static int gtt_poll(u32 reg, u32 mask, u32 value)
353{
354 unsigned try = GTT_RETRY;
355 u32 data;
356
357 while (try--) {
358 data = gtt_read(reg);
359 if ((data & mask) == value)
360 return 1;
361 udelay(10);
362 }
363
364 printk(BIOS_ERR, "GT init timeout\n");
365 return 0;
366}
367
368static void gma_pm_init_pre_vbios(struct device *dev)
369{
370 u32 reg32;
371
372 printk(BIOS_DEBUG, "GT Power Management Init\n");
373
374 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
375 if (!gtt_res || !gtt_res->base)
376 return;
377
378 if (bridge_silicon_revision() < IVB_STEP_C0) {
379 /* 1: Enable force wake */
380 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700381 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200382 } else {
383 gtt_write(0xa180, 1 << 5);
384 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700385 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200386 }
387
388 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
389 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
390 reg32 = gtt_read(0x42004);
391 reg32 |= (1 << 14) | (1 << 15);
392 gtt_write(0x42004, reg32);
393 }
394
395 if (bridge_silicon_revision() >= IVB_STEP_A0) {
396 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200397 reg32 = gtt_read(0x45010);
398 reg32 |= (1 << 1) | (1 << 0);
399 gtt_write(0x45010, reg32);
400 }
401
402 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700403 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200404 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200405 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700406 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
407 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200408 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700409 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
410 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200411 }
412 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700413 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700414
Duncan Laurie8508cff2012-04-12 16:02:43 -0700415 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700416 /* GT1 SKU */
417 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
418 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700419 } else {
420 /* GT2 SKU */
421 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
422 tdp /= (1 << unit);
423
424 if (tdp <= 17) {
425 /* <=17W ULV */
426 printk(BIOS_DEBUG, "IVB GT2 17W "
427 "Power Meter Weights\n");
428 gtt_write_powermeter(ivb_pm_gt2_17w);
429 } else if ((tdp >= 25) && (tdp <= 35)) {
430 /* 25W-35W */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700431 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
Duncan Laurie8508cff2012-04-12 16:02:43 -0700432 "Power Meter Weights\n");
433 gtt_write_powermeter(ivb_pm_gt2_35w);
434 } else {
435 /* All others */
436 printk(BIOS_DEBUG, "IVB GT2 35W "
437 "Power Meter Weights\n");
438 gtt_write_powermeter(ivb_pm_gt2_35w);
439 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700440 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200441 }
442
443 /* 3: Gear ratio map */
444 gtt_write(0xa004, 0x00000010);
445
446 /* 4: GFXPAUSE */
447 gtt_write(0xa000, 0x00070020);
448
449 /* 5: Dynamic EU trip control */
450 gtt_write(0xa080, 0x00000004);
451
452 /* 6: ECO bits */
453 reg32 = gtt_read(0xa180);
454 reg32 |= (1 << 26) | (1 << 31);
455 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
456 if (bridge_silicon_revision() >= SNB_STEP_D1)
457 reg32 |= (1 << 20);
458 gtt_write(0xa180, reg32);
459
460 /* 6a: for SnB step D2+ only */
461 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
462 (bridge_silicon_revision() >= SNB_STEP_D2)) {
463 reg32 = gtt_read(0x9400);
464 reg32 |= (1 << 7);
465 gtt_write(0x9400, reg32);
466
467 reg32 = gtt_read(0x941c);
468 reg32 &= 0xf;
469 reg32 |= (1 << 1);
470 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700471 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200472 }
473
474 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
475 reg32 = gtt_read(0x907c);
476 reg32 |= (1 << 16);
477 gtt_write(0x907c, reg32);
478
479 /* 6b: Clocking reset controls */
480 gtt_write(0x9424, 0x00000001);
481 } else {
482 /* 6b: Clocking reset controls */
483 gtt_write(0x9424, 0x00000000);
484 }
485
486 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700487 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
488 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
489 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
490 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
491 gtt_write(0x138124, 0x8000000a);
492 gtt_poll(0x138124, (1 << 31), (0 << 31));
493 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200494
495 /* 8 */
496 gtt_write(0xa090, 0x00000000); /* RC Control */
497 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
498 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
499 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
500 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
501 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
502
503 /* 9 */
504 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
505 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
506 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
507
508 /* 10 */
509 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
510 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
511 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
512 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
513 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
514
515 /* 11 */
516 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
517 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
518 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
519 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
520 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
521 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
522 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
523
524 /* 11a: Enable Render Standby (RC6) */
525 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700526 /*
527 * IvyBridge should also support DeepRenderStandby.
528 *
529 * Unfortunately it does not work reliably on all SKUs so
530 * disable it here and it can be enabled by the kernel.
531 */
532 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200533 } else {
534 gtt_write(0xa090, 0x88040000); /* HW RC Control */
535 }
536
537 /* 12: Normal Frequency Request */
538 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
539 reg32 = MCHBAR32(0x5998);
540 reg32 >>= 16;
541 reg32 &= 0xef;
542 reg32 <<= 25;
543 gtt_write(0xa008, reg32);
544
545 /* 13: RP Control */
546 gtt_write(0xa024, 0x00000592);
547
548 /* 14: Enable PM Interrupts */
549 gtt_write(0x4402c, 0x03000076);
550
551 /* Clear 0x6c024 [8:6] */
552 reg32 = gtt_read(0x6c024);
553 reg32 &= ~0x000001c0;
554 gtt_write(0x6c024, reg32);
555}
556
557static void gma_pm_init_post_vbios(struct device *dev)
558{
559 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
560 u32 reg32;
561
562 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
563
564 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700565 if (bridge_silicon_revision() < IVB_STEP_C0) {
566 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700567 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700568 } else {
569 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700570 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
571 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700572 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200573
574 /* 16: SW RC Control */
575 gtt_write(0xa094, 0x00060000);
576
577 /* Setup Digital Port Hotplug */
578 reg32 = gtt_read(0xc4030);
579 if (!reg32) {
580 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
581 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
582 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
583 gtt_write(0xc4030, reg32);
584 }
585
586 /* Setup Panel Power On Delays */
587 reg32 = gtt_read(0xc7208);
588 if (!reg32) {
589 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
590 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
591 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
592 gtt_write(0xc7208, reg32);
593 }
594
595 /* Setup Panel Power Off Delays */
596 reg32 = gtt_read(0xc720c);
597 if (!reg32) {
598 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
599 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
600 gtt_write(0xc720c, reg32);
601 }
602
603 /* Setup Panel Power Cycle Delay */
604 if (conf->gpu_panel_power_cycle_delay) {
605 reg32 = gtt_read(0xc7210);
606 reg32 &= ~0xff;
607 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
608 gtt_write(0xc7210, reg32);
609 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700610
611 /* Enable Backlight if needed */
612 if (conf->gpu_cpu_backlight) {
613 gtt_write(0x48250, (1 << 31));
614 gtt_write(0x48254, conf->gpu_cpu_backlight);
615 }
616 if (conf->gpu_pch_backlight) {
617 gtt_write(0xc8250, (1 << 31));
618 gtt_write(0xc8254, conf->gpu_pch_backlight);
619 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200620}
621
622static void gma_func0_init(struct device *dev)
623{
624 u32 reg32;
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800625 u32 graphics_base, graphics_size;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200626
627 /* IGD needs to be Bus Master */
628 reg32 = pci_read_config32(dev, PCI_COMMAND);
629 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
630 pci_write_config32(dev, PCI_COMMAND, reg32);
631
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800632 /* Set up an MTRR for the graphics memory BAR to vastly improve
633 * speed of VGA initialization (and later access). To stay out of
634 * the way of the MTRR init code, we are using MTRR #8 to cover
635 * that range.
636 */
637 graphics_base = dev->resource_list[1].base;
638 graphics_size = dev->resource_list[1].size;
639 printk(BIOS_DEBUG, "Setting up MTRR for graphics 0x%08x (%dK)\n",
640 graphics_base, graphics_size / 1024);
641 set_var_mtrr(8, graphics_base >> 10, graphics_size >> 10,
642 MTRR_TYPE_WRCOMB, 0x24);
643
Stefan Reinauer00636b02012-04-04 00:08:51 +0200644 /* Init graphics power management */
645 gma_pm_init_pre_vbios(dev);
646
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800647#if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
Stefan Reinauer00636b02012-04-04 00:08:51 +0200648 /* PCI Init, will run VBIOS */
649 pci_dev_init(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800650#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +0200651
652 /* Post VBIOS init */
653 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800654
655#if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
656 /* This should probably run before post VBIOS init. */
657 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
658 u32 iobase, mmiobase, physbase;
659 iobase = dev->resource_list[2].base;
660 mmiobase = dev->resource_list[0].base;
661 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
662
663 int i915lightup(u32 physbase, u32 iobase, u32 mmiobase, u32 gfx);
664 i915lightup(physbase, iobase, mmiobase, graphics_base);
665#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +0200666}
667
668static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
669{
670 if (!vendor || !device) {
671 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
672 pci_read_config32(dev, PCI_VENDOR_ID));
673 } else {
674 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
675 ((device & 0xffff) << 16) | (vendor & 0xffff));
676 }
677}
678
679static struct pci_operations gma_pci_ops = {
680 .set_subsystem = gma_set_subsystem,
681};
682
683static struct device_operations gma_func0_ops = {
684 .read_resources = pci_dev_read_resources,
685 .set_resources = pci_dev_set_resources,
686 .enable_resources = pci_dev_enable_resources,
687 .init = gma_func0_init,
688 .scan_bus = 0,
689 .enable = 0,
690 .ops_pci = &gma_pci_ops,
691};
692
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800693static const unsigned short pci_device_ids[] = { 0x0102, 0x0106, 0x010a, 0x0112,
694 0x0116, 0x0122, 0x0126, 0x0156,
695 0x0166,
696 0 };
697
698static const struct pci_driver gma __pci_driver = {
699 .ops = &gma_func0_ops,
700 .vendor = PCI_VENDOR_ID_INTEL,
701 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200702};