blob: 9a8b6317efb2eb408cf7811afc2089054156bfdc [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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
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>
26
27#include "chip.h"
28#include "sandybridge.h"
29
Duncan Lauriedd585b82012-04-09 12:05:18 -070030struct gt_powermeter {
31 u16 reg;
32 u32 value;
33};
34
35struct gt_powermeter snb_pm_gt1[] = {
36 { 0xa200, 0xcc000000 },
37 { 0xa204, 0x07000040 },
38 { 0xa208, 0x0000fe00 },
39 { 0xa20c, 0x00000000 },
40 { 0xa210, 0x17000000 },
41 { 0xa214, 0x00000021 },
42 { 0xa218, 0x0817fe19 },
43 { 0xa21c, 0x00000000 },
44 { 0xa220, 0x00000000 },
45 { 0xa224, 0xcc000000 },
46 { 0xa228, 0x07000040 },
47 { 0xa22c, 0x0000fe00 },
48 { 0xa230, 0x00000000 },
49 { 0xa234, 0x17000000 },
50 { 0xa238, 0x00000021 },
51 { 0xa23c, 0x0817fe19 },
52 { 0xa240, 0x00000000 },
53 { 0xa244, 0x00000000 },
54 { 0xa248, 0x8000421e },
55 { 0 }
56};
57
58struct gt_powermeter snb_pm_gt2[] = {
59 { 0xa200, 0x330000a6 },
60 { 0xa204, 0x402d0031 },
61 { 0xa208, 0x00165f83 },
62 { 0xa20c, 0xf1000000 },
63 { 0xa210, 0x00000000 },
64 { 0xa214, 0x00160016 },
65 { 0xa218, 0x002a002b },
66 { 0xa21c, 0x00000000 },
67 { 0xa220, 0x00000000 },
68 { 0xa224, 0x330000a6 },
69 { 0xa228, 0x402d0031 },
70 { 0xa22c, 0x00165f83 },
71 { 0xa230, 0xf1000000 },
72 { 0xa234, 0x00000000 },
73 { 0xa238, 0x00160016 },
74 { 0xa23c, 0x002a002b },
75 { 0xa240, 0x00000000 },
76 { 0xa244, 0x00000000 },
77 { 0xa248, 0x8000421e },
78 { 0 }
79};
80
81struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070082 { 0xa800, 0x00000000 },
83 { 0xa804, 0x00021c00 },
84 { 0xa808, 0x00000403 },
85 { 0xa80c, 0x02001700 },
86 { 0xa810, 0x05000200 },
87 { 0xa814, 0x00000000 },
88 { 0xa818, 0x00690500 },
89 { 0xa81c, 0x0000007f },
90 { 0xa820, 0x01002501 },
91 { 0xa824, 0x00000300 },
92 { 0xa828, 0x01000331 },
93 { 0xa82c, 0x0000000c },
94 { 0xa830, 0x00010016 },
95 { 0xa834, 0x01100101 },
96 { 0xa838, 0x00010103 },
97 { 0xa83c, 0x00041300 },
98 { 0xa840, 0x00000b30 },
99 { 0xa844, 0x00000000 },
100 { 0xa848, 0x7f000000 },
101 { 0xa84c, 0x05000008 },
102 { 0xa850, 0x00000001 },
103 { 0xa854, 0x00000004 },
104 { 0xa858, 0x00000007 },
105 { 0xa85c, 0x00000000 },
106 { 0xa860, 0x00010000 },
107 { 0xa248, 0x0000221e },
108 { 0xa900, 0x00000000 },
109 { 0xa904, 0x00001c00 },
110 { 0xa908, 0x00000000 },
111 { 0xa90c, 0x06000000 },
112 { 0xa910, 0x09000200 },
113 { 0xa914, 0x00000000 },
114 { 0xa918, 0x00590000 },
115 { 0xa91c, 0x00000000 },
116 { 0xa920, 0x04002501 },
117 { 0xa924, 0x00000100 },
118 { 0xa928, 0x03000410 },
119 { 0xa92c, 0x00000000 },
120 { 0xa930, 0x00020000 },
121 { 0xa934, 0x02070106 },
122 { 0xa938, 0x00010100 },
123 { 0xa93c, 0x00401c00 },
124 { 0xa940, 0x00000000 },
125 { 0xa944, 0x00000000 },
126 { 0xa948, 0x10000e00 },
127 { 0xa94c, 0x02000004 },
128 { 0xa950, 0x00000001 },
129 { 0xa954, 0x00000004 },
130 { 0xa960, 0x00060000 },
131 { 0xaa3c, 0x00001c00 },
132 { 0xaa54, 0x00000004 },
133 { 0xaa60, 0x00060000 },
134 { 0 }
135};
136
137struct gt_powermeter ivb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700138 { 0xa800, 0x10000000 },
139 { 0xa804, 0x00033800 },
140 { 0xa808, 0x00000902 },
141 { 0xa80c, 0x0c002f00 },
142 { 0xa810, 0x12000400 },
143 { 0xa814, 0x00000000 },
144 { 0xa818, 0x00d20800 },
145 { 0xa81c, 0x00000002 },
146 { 0xa820, 0x03004b02 },
147 { 0xa824, 0x00000600 },
148 { 0xa828, 0x07000773 },
149 { 0xa82c, 0x00000000 },
150 { 0xa830, 0x00010032 },
151 { 0xa834, 0x1520040d },
152 { 0xa838, 0x00020105 },
153 { 0xa83c, 0x00083700 },
154 { 0xa840, 0x0000151d },
155 { 0xa844, 0x00000000 },
156 { 0xa848, 0x20001b00 },
157 { 0xa84c, 0x0a000010 },
158 { 0xa850, 0x00000000 },
159 { 0xa854, 0x00000008 },
160 { 0xa858, 0x00000008 },
161 { 0xa85c, 0x00000000 },
162 { 0xa860, 0x00020000 },
163 { 0xa248, 0x0000221e },
164 { 0xa900, 0x00000000 },
165 { 0xa904, 0x00003500 },
166 { 0xa908, 0x00000000 },
167 { 0xa90c, 0x0c000000 },
168 { 0xa910, 0x12000500 },
169 { 0xa914, 0x00000000 },
170 { 0xa918, 0x00b20000 },
171 { 0xa91c, 0x00000000 },
172 { 0xa920, 0x08004b02 },
173 { 0xa924, 0x00000200 },
174 { 0xa928, 0x07000820 },
175 { 0xa92c, 0x00000000 },
176 { 0xa930, 0x00030000 },
177 { 0xa934, 0x050f020d },
178 { 0xa938, 0x00020300 },
179 { 0xa93c, 0x00903900 },
180 { 0xa940, 0x00000000 },
181 { 0xa944, 0x00000000 },
182 { 0xa948, 0x20001b00 },
183 { 0xa94c, 0x0a000010 },
184 { 0xa950, 0x00000000 },
185 { 0xa954, 0x00000008 },
186 { 0xa960, 0x00110000 },
187 { 0xaa3c, 0x00003900 },
188 { 0xaa54, 0x00000008 },
189 { 0xaa60, 0x00110000 },
190 { 0 }
191};
192
Duncan Laurie8508cff2012-04-12 16:02:43 -0700193struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700194 { 0xa800, 0x20000000 },
195 { 0xa804, 0x000e3800 },
196 { 0xa808, 0x00000806 },
197 { 0xa80c, 0x0c002f00 },
198 { 0xa810, 0x0c000800 },
199 { 0xa814, 0x00000000 },
200 { 0xa818, 0x00d20d00 },
201 { 0xa81c, 0x000000ff },
202 { 0xa820, 0x03004b02 },
203 { 0xa824, 0x00000600 },
204 { 0xa828, 0x07000773 },
205 { 0xa82c, 0x00000000 },
206 { 0xa830, 0x00020032 },
207 { 0xa834, 0x1520040d },
208 { 0xa838, 0x00020105 },
209 { 0xa83c, 0x00083700 },
210 { 0xa840, 0x000016ff },
211 { 0xa844, 0x00000000 },
212 { 0xa848, 0xff000000 },
213 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700214 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700215 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700216 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700217 { 0xa85c, 0x00000000 },
218 { 0xa860, 0x00020000 },
219 { 0xa248, 0x0000221e },
220 { 0xa900, 0x00000000 },
221 { 0xa904, 0x00003800 },
222 { 0xa908, 0x00000000 },
223 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700224 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700225 { 0xa914, 0x00000000 },
226 { 0xa918, 0x00b20000 },
227 { 0xa91c, 0x00000000 },
228 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700229 { 0xa924, 0x00000300 },
230 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700231 { 0xa92c, 0x00000000 },
232 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700233 { 0xa934, 0x15150406 },
234 { 0xa938, 0x00020300 },
235 { 0xa93c, 0x00903900 },
236 { 0xa940, 0x00000000 },
237 { 0xa944, 0x00000000 },
238 { 0xa948, 0x20001b00 },
239 { 0xa94c, 0x0a000010 },
240 { 0xa950, 0x00000000 },
241 { 0xa954, 0x00000008 },
242 { 0xa960, 0x00110000 },
243 { 0xaa3c, 0x00003900 },
244 { 0xaa54, 0x00000008 },
245 { 0xaa60, 0x00110000 },
246 { 0 }
247};
248
249struct gt_powermeter ivb_pm_gt2_35w[] = {
250 { 0xa800, 0x00000000 },
251 { 0xa804, 0x00030400 },
252 { 0xa808, 0x00000806 },
253 { 0xa80c, 0x0c002f00 },
254 { 0xa810, 0x0c000300 },
255 { 0xa814, 0x00000000 },
256 { 0xa818, 0x00d20d00 },
257 { 0xa81c, 0x000000ff },
258 { 0xa820, 0x03004b02 },
259 { 0xa824, 0x00000600 },
260 { 0xa828, 0x07000773 },
261 { 0xa82c, 0x00000000 },
262 { 0xa830, 0x00020032 },
263 { 0xa834, 0x1520040d },
264 { 0xa838, 0x00020105 },
265 { 0xa83c, 0x00083700 },
266 { 0xa840, 0x000016ff },
267 { 0xa844, 0x00000000 },
268 { 0xa848, 0xff000000 },
269 { 0xa84c, 0x0a000010 },
270 { 0xa850, 0x00000001 },
271 { 0xa854, 0x00000008 },
272 { 0xa858, 0x00000008 },
273 { 0xa85c, 0x00000000 },
274 { 0xa860, 0x00020000 },
275 { 0xa248, 0x0000221e },
276 { 0xa900, 0x00000000 },
277 { 0xa904, 0x00003800 },
278 { 0xa908, 0x00000000 },
279 { 0xa90c, 0x0c000000 },
280 { 0xa910, 0x12000800 },
281 { 0xa914, 0x00000000 },
282 { 0xa918, 0x00b20000 },
283 { 0xa91c, 0x00000000 },
284 { 0xa920, 0x08004b02 },
285 { 0xa924, 0x00000300 },
286 { 0xa928, 0x01000820 },
287 { 0xa92c, 0x00000000 },
288 { 0xa930, 0x00030000 },
289 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700290 { 0xa938, 0x00020300 },
291 { 0xa93c, 0x00903900 },
292 { 0xa940, 0x00000000 },
293 { 0xa944, 0x00000000 },
294 { 0xa948, 0x20001b00 },
295 { 0xa94c, 0x0a000010 },
296 { 0xa950, 0x00000000 },
297 { 0xa954, 0x00000008 },
298 { 0xa960, 0x00110000 },
299 { 0xaa3c, 0x00003900 },
300 { 0xaa54, 0x00000008 },
301 { 0xaa60, 0x00110000 },
302 { 0 }
303};
304
Stefan Reinauer00636b02012-04-04 00:08:51 +0200305/* some vga option roms are used for several chipsets but they only have one
306 * PCI ID in their header. If we encounter such an option rom, we need to do
307 * the mapping ourselfes
308 */
309
310u32 map_oprom_vendev(u32 vendev)
311{
312 u32 new_vendev=vendev;
313
314 switch (vendev) {
Martin Rothe9dfdd92012-04-26 16:04:18 -0600315 case 0x80860102: /* GT1 Desktop */
316 case 0x8086010a: /* GT1 Server */
317 case 0x80860112: /* GT2 Desktop */
318 case 0x80860116: /* GT2 Mobile */
319 case 0x80860122: /* GT2 Desktop >=1.3GHz */
320 case 0x80860126: /* GT2 Mobile >=1.3GHz */
321 case 0x80860166: /* IVB */
322 new_vendev=0x80860106; /* GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200323 break;
324 }
325
326 return new_vendev;
327}
328
329static struct resource *gtt_res = NULL;
330
331static inline u32 gtt_read(u32 reg)
332{
333 return read32(gtt_res->base + reg);
334}
335
336static inline void gtt_write(u32 reg, u32 data)
337{
338 write32(gtt_res->base + reg, data);
339}
340
Duncan Lauriedd585b82012-04-09 12:05:18 -0700341static inline void gtt_write_powermeter(struct gt_powermeter *pm)
342{
343 for (; pm && pm->reg; pm++)
344 gtt_write(pm->reg, pm->value);
345}
346
Stefan Reinauer00636b02012-04-04 00:08:51 +0200347#define GTT_RETRY 1000
348static int gtt_poll(u32 reg, u32 mask, u32 value)
349{
350 unsigned try = GTT_RETRY;
351 u32 data;
352
353 while (try--) {
354 data = gtt_read(reg);
355 if ((data & mask) == value)
356 return 1;
357 udelay(10);
358 }
359
360 printk(BIOS_ERR, "GT init timeout\n");
361 return 0;
362}
363
364static void gma_pm_init_pre_vbios(struct device *dev)
365{
366 u32 reg32;
367
368 printk(BIOS_DEBUG, "GT Power Management Init\n");
369
370 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
371 if (!gtt_res || !gtt_res->base)
372 return;
373
374 if (bridge_silicon_revision() < IVB_STEP_C0) {
375 /* 1: Enable force wake */
376 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700377 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200378 } else {
379 gtt_write(0xa180, 1 << 5);
380 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700381 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200382 }
383
384 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
385 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
386 reg32 = gtt_read(0x42004);
387 reg32 |= (1 << 14) | (1 << 15);
388 gtt_write(0x42004, reg32);
389 }
390
391 if (bridge_silicon_revision() >= IVB_STEP_A0) {
392 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200393 reg32 = gtt_read(0x45010);
394 reg32 |= (1 << 1) | (1 << 0);
395 gtt_write(0x45010, reg32);
396 }
397
398 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700399 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200400 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200401 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700402 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
403 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200404 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700405 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
406 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200407 }
408 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700409 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700410
Duncan Laurie8508cff2012-04-12 16:02:43 -0700411 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700412 /* GT1 SKU */
413 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
414 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700415 } else {
416 /* GT2 SKU */
417 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
418 tdp /= (1 << unit);
419
420 if (tdp <= 17) {
421 /* <=17W ULV */
422 printk(BIOS_DEBUG, "IVB GT2 17W "
423 "Power Meter Weights\n");
424 gtt_write_powermeter(ivb_pm_gt2_17w);
425 } else if ((tdp >= 25) && (tdp <= 35)) {
426 /* 25W-35W */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700427 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
Duncan Laurie8508cff2012-04-12 16:02:43 -0700428 "Power Meter Weights\n");
429 gtt_write_powermeter(ivb_pm_gt2_35w);
430 } else {
431 /* All others */
432 printk(BIOS_DEBUG, "IVB GT2 35W "
433 "Power Meter Weights\n");
434 gtt_write_powermeter(ivb_pm_gt2_35w);
435 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700436 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200437 }
438
439 /* 3: Gear ratio map */
440 gtt_write(0xa004, 0x00000010);
441
442 /* 4: GFXPAUSE */
443 gtt_write(0xa000, 0x00070020);
444
445 /* 5: Dynamic EU trip control */
446 gtt_write(0xa080, 0x00000004);
447
448 /* 6: ECO bits */
449 reg32 = gtt_read(0xa180);
450 reg32 |= (1 << 26) | (1 << 31);
451 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
452 if (bridge_silicon_revision() >= SNB_STEP_D1)
453 reg32 |= (1 << 20);
454 gtt_write(0xa180, reg32);
455
456 /* 6a: for SnB step D2+ only */
457 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
458 (bridge_silicon_revision() >= SNB_STEP_D2)) {
459 reg32 = gtt_read(0x9400);
460 reg32 |= (1 << 7);
461 gtt_write(0x9400, reg32);
462
463 reg32 = gtt_read(0x941c);
464 reg32 &= 0xf;
465 reg32 |= (1 << 1);
466 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700467 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200468 }
469
470 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
471 reg32 = gtt_read(0x907c);
472 reg32 |= (1 << 16);
473 gtt_write(0x907c, reg32);
474
475 /* 6b: Clocking reset controls */
476 gtt_write(0x9424, 0x00000001);
477 } else {
478 /* 6b: Clocking reset controls */
479 gtt_write(0x9424, 0x00000000);
480 }
481
482 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700483 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
484 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
485 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
486 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
487 gtt_write(0x138124, 0x8000000a);
488 gtt_poll(0x138124, (1 << 31), (0 << 31));
489 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200490
491 /* 8 */
492 gtt_write(0xa090, 0x00000000); /* RC Control */
493 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
494 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
495 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
496 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
497 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
498
499 /* 9 */
500 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
501 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
502 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
503
504 /* 10 */
505 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
506 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
507 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
508 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
509 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
510
511 /* 11 */
512 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
513 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
514 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
515 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
516 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
517 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
518 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
519
520 /* 11a: Enable Render Standby (RC6) */
521 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700522 /*
523 * IvyBridge should also support DeepRenderStandby.
524 *
525 * Unfortunately it does not work reliably on all SKUs so
526 * disable it here and it can be enabled by the kernel.
527 */
528 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200529 } else {
530 gtt_write(0xa090, 0x88040000); /* HW RC Control */
531 }
532
533 /* 12: Normal Frequency Request */
534 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
535 reg32 = MCHBAR32(0x5998);
536 reg32 >>= 16;
537 reg32 &= 0xef;
538 reg32 <<= 25;
539 gtt_write(0xa008, reg32);
540
541 /* 13: RP Control */
542 gtt_write(0xa024, 0x00000592);
543
544 /* 14: Enable PM Interrupts */
545 gtt_write(0x4402c, 0x03000076);
546
547 /* Clear 0x6c024 [8:6] */
548 reg32 = gtt_read(0x6c024);
549 reg32 &= ~0x000001c0;
550 gtt_write(0x6c024, reg32);
551}
552
553static void gma_pm_init_post_vbios(struct device *dev)
554{
555 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
556 u32 reg32;
557
558 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
559
560 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700561 if (bridge_silicon_revision() < IVB_STEP_C0) {
562 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700563 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700564 } else {
565 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700566 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
567 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700568 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200569
570 /* 16: SW RC Control */
571 gtt_write(0xa094, 0x00060000);
572
573 /* Setup Digital Port Hotplug */
574 reg32 = gtt_read(0xc4030);
575 if (!reg32) {
576 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
577 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
578 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
579 gtt_write(0xc4030, reg32);
580 }
581
582 /* Setup Panel Power On Delays */
583 reg32 = gtt_read(0xc7208);
584 if (!reg32) {
585 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
586 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
587 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
588 gtt_write(0xc7208, reg32);
589 }
590
591 /* Setup Panel Power Off Delays */
592 reg32 = gtt_read(0xc720c);
593 if (!reg32) {
594 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
595 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
596 gtt_write(0xc720c, reg32);
597 }
598
599 /* Setup Panel Power Cycle Delay */
600 if (conf->gpu_panel_power_cycle_delay) {
601 reg32 = gtt_read(0xc7210);
602 reg32 &= ~0xff;
603 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
604 gtt_write(0xc7210, reg32);
605 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700606
607 /* Enable Backlight if needed */
608 if (conf->gpu_cpu_backlight) {
609 gtt_write(0x48250, (1 << 31));
610 gtt_write(0x48254, conf->gpu_cpu_backlight);
611 }
612 if (conf->gpu_pch_backlight) {
613 gtt_write(0xc8250, (1 << 31));
614 gtt_write(0xc8254, conf->gpu_pch_backlight);
615 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200616}
617
618static void gma_func0_init(struct device *dev)
619{
620 u32 reg32;
621
622 /* IGD needs to be Bus Master */
623 reg32 = pci_read_config32(dev, PCI_COMMAND);
624 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
625 pci_write_config32(dev, PCI_COMMAND, reg32);
626
627 /* Init graphics power management */
628 gma_pm_init_pre_vbios(dev);
629
630 /* PCI Init, will run VBIOS */
631 pci_dev_init(dev);
632
633 /* Post VBIOS init */
634 gma_pm_init_post_vbios(dev);
635}
636
637static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
638{
639 if (!vendor || !device) {
640 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
641 pci_read_config32(dev, PCI_VENDOR_ID));
642 } else {
643 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
644 ((device & 0xffff) << 16) | (vendor & 0xffff));
645 }
646}
647
648static struct pci_operations gma_pci_ops = {
649 .set_subsystem = gma_set_subsystem,
650};
651
652static struct device_operations gma_func0_ops = {
653 .read_resources = pci_dev_read_resources,
654 .set_resources = pci_dev_set_resources,
655 .enable_resources = pci_dev_enable_resources,
656 .init = gma_func0_init,
657 .scan_bus = 0,
658 .enable = 0,
659 .ops_pci = &gma_pci_ops,
660};
661
662static const struct pci_driver gma_gt1_desktop __pci_driver = {
663 .ops = &gma_func0_ops,
664 .vendor = PCI_VENDOR_ID_INTEL,
665 .device = 0x0102,
666};
667
668static const struct pci_driver gma_gt1_mobile __pci_driver = {
669 .ops = &gma_func0_ops,
670 .vendor = PCI_VENDOR_ID_INTEL,
671 .device = 0x0106,
672};
673
674static const struct pci_driver gma_gt1_server __pci_driver = {
675 .ops = &gma_func0_ops,
676 .vendor = PCI_VENDOR_ID_INTEL,
677 .device = 0x010a,
678};
679
680static const struct pci_driver gma_gt2_desktop __pci_driver = {
681 .ops = &gma_func0_ops,
682 .vendor = PCI_VENDOR_ID_INTEL,
683 .device = 0x0112,
684};
685
686static const struct pci_driver gma_gt2_mobile __pci_driver = {
687 .ops = &gma_func0_ops,
688 .vendor = PCI_VENDOR_ID_INTEL,
689 .device = 0x0116,
690};
691
692static const struct pci_driver gma_gt2_desktop_fast __pci_driver = {
693 .ops = &gma_func0_ops,
694 .vendor = PCI_VENDOR_ID_INTEL,
695 .device = 0x0122,
696};
697
698static const struct pci_driver gma_gt2_mobile_fast __pci_driver = {
699 .ops = &gma_func0_ops,
700 .vendor = PCI_VENDOR_ID_INTEL,
701 .device = 0x0126,
702};
703
704static const struct pci_driver gma_func0_driver_3 __pci_driver = {
705 .ops = &gma_func0_ops,
706 .vendor = PCI_VENDOR_ID_INTEL,
707 .device = 0x0166,
708};