blob: 52707bd04ccb1fc23e88a0c887e682546543f589 [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
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070035static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070036 { 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
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070058static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070059 { 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
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070081static const struct 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
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700137static const struct 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
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700193static const struct 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
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700249static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700250 { 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 */
Stefan Reinauer816e9d12013-01-14 10:25:43 -0800321 case 0x80860156: /* IVB */
Martin Rothe9dfdd92012-04-26 16:04:18 -0600322 case 0x80860166: /* IVB */
323 new_vendev=0x80860106; /* GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200324 break;
325 }
326
327 return new_vendev;
328}
329
330static struct resource *gtt_res = NULL;
331
332static inline u32 gtt_read(u32 reg)
333{
334 return read32(gtt_res->base + reg);
335}
336
337static inline void gtt_write(u32 reg, u32 data)
338{
339 write32(gtt_res->base + reg, data);
340}
341
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700342static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700343{
344 for (; pm && pm->reg; pm++)
345 gtt_write(pm->reg, pm->value);
346}
347
Stefan Reinauer00636b02012-04-04 00:08:51 +0200348#define GTT_RETRY 1000
349static int gtt_poll(u32 reg, u32 mask, u32 value)
350{
351 unsigned try = GTT_RETRY;
352 u32 data;
353
354 while (try--) {
355 data = gtt_read(reg);
356 if ((data & mask) == value)
357 return 1;
358 udelay(10);
359 }
360
361 printk(BIOS_ERR, "GT init timeout\n");
362 return 0;
363}
364
365static void gma_pm_init_pre_vbios(struct device *dev)
366{
367 u32 reg32;
368
369 printk(BIOS_DEBUG, "GT Power Management Init\n");
370
371 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
372 if (!gtt_res || !gtt_res->base)
373 return;
374
375 if (bridge_silicon_revision() < IVB_STEP_C0) {
376 /* 1: Enable force wake */
377 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700378 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200379 } else {
380 gtt_write(0xa180, 1 << 5);
381 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700382 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200383 }
384
385 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
386 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
387 reg32 = gtt_read(0x42004);
388 reg32 |= (1 << 14) | (1 << 15);
389 gtt_write(0x42004, reg32);
390 }
391
392 if (bridge_silicon_revision() >= IVB_STEP_A0) {
393 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200394 reg32 = gtt_read(0x45010);
395 reg32 |= (1 << 1) | (1 << 0);
396 gtt_write(0x45010, reg32);
397 }
398
399 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700400 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200401 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200402 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700403 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
404 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200405 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700406 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
407 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200408 }
409 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700410 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700411
Duncan Laurie8508cff2012-04-12 16:02:43 -0700412 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700413 /* GT1 SKU */
414 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
415 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700416 } else {
417 /* GT2 SKU */
418 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
419 tdp /= (1 << unit);
420
421 if (tdp <= 17) {
422 /* <=17W ULV */
423 printk(BIOS_DEBUG, "IVB GT2 17W "
424 "Power Meter Weights\n");
425 gtt_write_powermeter(ivb_pm_gt2_17w);
426 } else if ((tdp >= 25) && (tdp <= 35)) {
427 /* 25W-35W */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700428 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
Duncan Laurie8508cff2012-04-12 16:02:43 -0700429 "Power Meter Weights\n");
430 gtt_write_powermeter(ivb_pm_gt2_35w);
431 } else {
432 /* All others */
433 printk(BIOS_DEBUG, "IVB GT2 35W "
434 "Power Meter Weights\n");
435 gtt_write_powermeter(ivb_pm_gt2_35w);
436 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700437 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200438 }
439
440 /* 3: Gear ratio map */
441 gtt_write(0xa004, 0x00000010);
442
443 /* 4: GFXPAUSE */
444 gtt_write(0xa000, 0x00070020);
445
446 /* 5: Dynamic EU trip control */
447 gtt_write(0xa080, 0x00000004);
448
449 /* 6: ECO bits */
450 reg32 = gtt_read(0xa180);
451 reg32 |= (1 << 26) | (1 << 31);
452 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
453 if (bridge_silicon_revision() >= SNB_STEP_D1)
454 reg32 |= (1 << 20);
455 gtt_write(0xa180, reg32);
456
457 /* 6a: for SnB step D2+ only */
458 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
459 (bridge_silicon_revision() >= SNB_STEP_D2)) {
460 reg32 = gtt_read(0x9400);
461 reg32 |= (1 << 7);
462 gtt_write(0x9400, reg32);
463
464 reg32 = gtt_read(0x941c);
465 reg32 &= 0xf;
466 reg32 |= (1 << 1);
467 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700468 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200469 }
470
471 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
472 reg32 = gtt_read(0x907c);
473 reg32 |= (1 << 16);
474 gtt_write(0x907c, reg32);
475
476 /* 6b: Clocking reset controls */
477 gtt_write(0x9424, 0x00000001);
478 } else {
479 /* 6b: Clocking reset controls */
480 gtt_write(0x9424, 0x00000000);
481 }
482
483 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700484 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
485 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
486 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
487 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
488 gtt_write(0x138124, 0x8000000a);
489 gtt_poll(0x138124, (1 << 31), (0 << 31));
490 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200491
492 /* 8 */
493 gtt_write(0xa090, 0x00000000); /* RC Control */
494 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
495 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
496 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
497 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
498 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
499
500 /* 9 */
501 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
502 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
503 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
504
505 /* 10 */
506 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
507 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
508 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
509 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
510 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
511
512 /* 11 */
513 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
514 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
515 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
516 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
517 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
518 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
519 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
520
521 /* 11a: Enable Render Standby (RC6) */
522 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700523 /*
524 * IvyBridge should also support DeepRenderStandby.
525 *
526 * Unfortunately it does not work reliably on all SKUs so
527 * disable it here and it can be enabled by the kernel.
528 */
529 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200530 } else {
531 gtt_write(0xa090, 0x88040000); /* HW RC Control */
532 }
533
534 /* 12: Normal Frequency Request */
535 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
536 reg32 = MCHBAR32(0x5998);
537 reg32 >>= 16;
538 reg32 &= 0xef;
539 reg32 <<= 25;
540 gtt_write(0xa008, reg32);
541
542 /* 13: RP Control */
543 gtt_write(0xa024, 0x00000592);
544
545 /* 14: Enable PM Interrupts */
546 gtt_write(0x4402c, 0x03000076);
547
548 /* Clear 0x6c024 [8:6] */
549 reg32 = gtt_read(0x6c024);
550 reg32 &= ~0x000001c0;
551 gtt_write(0x6c024, reg32);
552}
553
554static void gma_pm_init_post_vbios(struct device *dev)
555{
556 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
557 u32 reg32;
558
559 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
560
561 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700562 if (bridge_silicon_revision() < IVB_STEP_C0) {
563 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700564 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700565 } else {
566 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700567 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
568 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700569 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200570
571 /* 16: SW RC Control */
572 gtt_write(0xa094, 0x00060000);
573
574 /* Setup Digital Port Hotplug */
575 reg32 = gtt_read(0xc4030);
576 if (!reg32) {
577 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
578 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
579 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
580 gtt_write(0xc4030, reg32);
581 }
582
583 /* Setup Panel Power On Delays */
584 reg32 = gtt_read(0xc7208);
585 if (!reg32) {
586 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
587 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
588 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
589 gtt_write(0xc7208, reg32);
590 }
591
592 /* Setup Panel Power Off Delays */
593 reg32 = gtt_read(0xc720c);
594 if (!reg32) {
595 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
596 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
597 gtt_write(0xc720c, reg32);
598 }
599
600 /* Setup Panel Power Cycle Delay */
601 if (conf->gpu_panel_power_cycle_delay) {
602 reg32 = gtt_read(0xc7210);
603 reg32 &= ~0xff;
604 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
605 gtt_write(0xc7210, reg32);
606 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700607
608 /* Enable Backlight if needed */
609 if (conf->gpu_cpu_backlight) {
610 gtt_write(0x48250, (1 << 31));
611 gtt_write(0x48254, conf->gpu_cpu_backlight);
612 }
613 if (conf->gpu_pch_backlight) {
614 gtt_write(0xc8250, (1 << 31));
615 gtt_write(0xc8254, conf->gpu_pch_backlight);
616 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200617}
618
619static void gma_func0_init(struct device *dev)
620{
621 u32 reg32;
622
623 /* IGD needs to be Bus Master */
624 reg32 = pci_read_config32(dev, PCI_COMMAND);
625 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
626 pci_write_config32(dev, PCI_COMMAND, reg32);
627
628 /* Init graphics power management */
629 gma_pm_init_pre_vbios(dev);
630
631 /* PCI Init, will run VBIOS */
632 pci_dev_init(dev);
633
634 /* Post VBIOS init */
635 gma_pm_init_post_vbios(dev);
636}
637
638static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
639{
640 if (!vendor || !device) {
641 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
642 pci_read_config32(dev, PCI_VENDOR_ID));
643 } else {
644 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
645 ((device & 0xffff) << 16) | (vendor & 0xffff));
646 }
647}
648
649static struct pci_operations gma_pci_ops = {
650 .set_subsystem = gma_set_subsystem,
651};
652
653static struct device_operations gma_func0_ops = {
654 .read_resources = pci_dev_read_resources,
655 .set_resources = pci_dev_set_resources,
656 .enable_resources = pci_dev_enable_resources,
657 .init = gma_func0_init,
658 .scan_bus = 0,
659 .enable = 0,
660 .ops_pci = &gma_pci_ops,
661};
662
Patrick Georgiefff7332012-07-26 19:48:23 +0200663static const unsigned short gma_ids[] = {
Stefan Reinauer816e9d12013-01-14 10:25:43 -0800664 0x0102, 0x0106, 0x010a, 0x0112, 0x0116, 0x0122, 0x0126, 0x0156, 0x166,
Patrick Georgiefff7332012-07-26 19:48:23 +0200665 0,
666};
Stefan Reinauer00636b02012-04-04 00:08:51 +0200667static const struct pci_driver gma_gt1_desktop __pci_driver = {
668 .ops = &gma_func0_ops,
669 .vendor = PCI_VENDOR_ID_INTEL,
Patrick Georgiefff7332012-07-26 19:48:23 +0200670 .devices= gma_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200671};