blob: a01fe9f7717a1f013d3881861c75e2c44f0275a7 [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>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020022#include <bootmode.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020023#include <delay.h>
Vladimir Serbinenkof2e206a2014-02-23 00:13:56 +010024#include <string.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020025#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_ids.h>
Ronald G. Minnich69efaa02013-02-26 10:07:40 -080028#include <device/pci_ops.h>
29#include <cpu/x86/msr.h>
30#include <cpu/x86/mtrr.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020031
32#include "chip.h"
33#include "sandybridge.h"
34
Duncan Lauriedd585b82012-04-09 12:05:18 -070035struct gt_powermeter {
36 u16 reg;
37 u32 value;
38};
39
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070040static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070041 { 0xa200, 0xcc000000 },
42 { 0xa204, 0x07000040 },
43 { 0xa208, 0x0000fe00 },
44 { 0xa20c, 0x00000000 },
45 { 0xa210, 0x17000000 },
46 { 0xa214, 0x00000021 },
47 { 0xa218, 0x0817fe19 },
48 { 0xa21c, 0x00000000 },
49 { 0xa220, 0x00000000 },
50 { 0xa224, 0xcc000000 },
51 { 0xa228, 0x07000040 },
52 { 0xa22c, 0x0000fe00 },
53 { 0xa230, 0x00000000 },
54 { 0xa234, 0x17000000 },
55 { 0xa238, 0x00000021 },
56 { 0xa23c, 0x0817fe19 },
57 { 0xa240, 0x00000000 },
58 { 0xa244, 0x00000000 },
59 { 0xa248, 0x8000421e },
60 { 0 }
61};
62
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070063static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070064 { 0xa200, 0x330000a6 },
65 { 0xa204, 0x402d0031 },
66 { 0xa208, 0x00165f83 },
67 { 0xa20c, 0xf1000000 },
68 { 0xa210, 0x00000000 },
69 { 0xa214, 0x00160016 },
70 { 0xa218, 0x002a002b },
71 { 0xa21c, 0x00000000 },
72 { 0xa220, 0x00000000 },
73 { 0xa224, 0x330000a6 },
74 { 0xa228, 0x402d0031 },
75 { 0xa22c, 0x00165f83 },
76 { 0xa230, 0xf1000000 },
77 { 0xa234, 0x00000000 },
78 { 0xa238, 0x00160016 },
79 { 0xa23c, 0x002a002b },
80 { 0xa240, 0x00000000 },
81 { 0xa244, 0x00000000 },
82 { 0xa248, 0x8000421e },
83 { 0 }
84};
85
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070086static const struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070087 { 0xa800, 0x00000000 },
88 { 0xa804, 0x00021c00 },
89 { 0xa808, 0x00000403 },
90 { 0xa80c, 0x02001700 },
91 { 0xa810, 0x05000200 },
92 { 0xa814, 0x00000000 },
93 { 0xa818, 0x00690500 },
94 { 0xa81c, 0x0000007f },
95 { 0xa820, 0x01002501 },
96 { 0xa824, 0x00000300 },
97 { 0xa828, 0x01000331 },
98 { 0xa82c, 0x0000000c },
99 { 0xa830, 0x00010016 },
100 { 0xa834, 0x01100101 },
101 { 0xa838, 0x00010103 },
102 { 0xa83c, 0x00041300 },
103 { 0xa840, 0x00000b30 },
104 { 0xa844, 0x00000000 },
105 { 0xa848, 0x7f000000 },
106 { 0xa84c, 0x05000008 },
107 { 0xa850, 0x00000001 },
108 { 0xa854, 0x00000004 },
109 { 0xa858, 0x00000007 },
110 { 0xa85c, 0x00000000 },
111 { 0xa860, 0x00010000 },
112 { 0xa248, 0x0000221e },
113 { 0xa900, 0x00000000 },
114 { 0xa904, 0x00001c00 },
115 { 0xa908, 0x00000000 },
116 { 0xa90c, 0x06000000 },
117 { 0xa910, 0x09000200 },
118 { 0xa914, 0x00000000 },
119 { 0xa918, 0x00590000 },
120 { 0xa91c, 0x00000000 },
121 { 0xa920, 0x04002501 },
122 { 0xa924, 0x00000100 },
123 { 0xa928, 0x03000410 },
124 { 0xa92c, 0x00000000 },
125 { 0xa930, 0x00020000 },
126 { 0xa934, 0x02070106 },
127 { 0xa938, 0x00010100 },
128 { 0xa93c, 0x00401c00 },
129 { 0xa940, 0x00000000 },
130 { 0xa944, 0x00000000 },
131 { 0xa948, 0x10000e00 },
132 { 0xa94c, 0x02000004 },
133 { 0xa950, 0x00000001 },
134 { 0xa954, 0x00000004 },
135 { 0xa960, 0x00060000 },
136 { 0xaa3c, 0x00001c00 },
137 { 0xaa54, 0x00000004 },
138 { 0xaa60, 0x00060000 },
139 { 0 }
140};
141
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700142static const struct gt_powermeter ivb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700143 { 0xa800, 0x10000000 },
144 { 0xa804, 0x00033800 },
145 { 0xa808, 0x00000902 },
146 { 0xa80c, 0x0c002f00 },
147 { 0xa810, 0x12000400 },
148 { 0xa814, 0x00000000 },
149 { 0xa818, 0x00d20800 },
150 { 0xa81c, 0x00000002 },
151 { 0xa820, 0x03004b02 },
152 { 0xa824, 0x00000600 },
153 { 0xa828, 0x07000773 },
154 { 0xa82c, 0x00000000 },
155 { 0xa830, 0x00010032 },
156 { 0xa834, 0x1520040d },
157 { 0xa838, 0x00020105 },
158 { 0xa83c, 0x00083700 },
159 { 0xa840, 0x0000151d },
160 { 0xa844, 0x00000000 },
161 { 0xa848, 0x20001b00 },
162 { 0xa84c, 0x0a000010 },
163 { 0xa850, 0x00000000 },
164 { 0xa854, 0x00000008 },
165 { 0xa858, 0x00000008 },
166 { 0xa85c, 0x00000000 },
167 { 0xa860, 0x00020000 },
168 { 0xa248, 0x0000221e },
169 { 0xa900, 0x00000000 },
170 { 0xa904, 0x00003500 },
171 { 0xa908, 0x00000000 },
172 { 0xa90c, 0x0c000000 },
173 { 0xa910, 0x12000500 },
174 { 0xa914, 0x00000000 },
175 { 0xa918, 0x00b20000 },
176 { 0xa91c, 0x00000000 },
177 { 0xa920, 0x08004b02 },
178 { 0xa924, 0x00000200 },
179 { 0xa928, 0x07000820 },
180 { 0xa92c, 0x00000000 },
181 { 0xa930, 0x00030000 },
182 { 0xa934, 0x050f020d },
183 { 0xa938, 0x00020300 },
184 { 0xa93c, 0x00903900 },
185 { 0xa940, 0x00000000 },
186 { 0xa944, 0x00000000 },
187 { 0xa948, 0x20001b00 },
188 { 0xa94c, 0x0a000010 },
189 { 0xa950, 0x00000000 },
190 { 0xa954, 0x00000008 },
191 { 0xa960, 0x00110000 },
192 { 0xaa3c, 0x00003900 },
193 { 0xaa54, 0x00000008 },
194 { 0xaa60, 0x00110000 },
195 { 0 }
196};
197
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700198static const struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700199 { 0xa800, 0x20000000 },
200 { 0xa804, 0x000e3800 },
201 { 0xa808, 0x00000806 },
202 { 0xa80c, 0x0c002f00 },
203 { 0xa810, 0x0c000800 },
204 { 0xa814, 0x00000000 },
205 { 0xa818, 0x00d20d00 },
206 { 0xa81c, 0x000000ff },
207 { 0xa820, 0x03004b02 },
208 { 0xa824, 0x00000600 },
209 { 0xa828, 0x07000773 },
210 { 0xa82c, 0x00000000 },
211 { 0xa830, 0x00020032 },
212 { 0xa834, 0x1520040d },
213 { 0xa838, 0x00020105 },
214 { 0xa83c, 0x00083700 },
215 { 0xa840, 0x000016ff },
216 { 0xa844, 0x00000000 },
217 { 0xa848, 0xff000000 },
218 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700219 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700220 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700221 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700222 { 0xa85c, 0x00000000 },
223 { 0xa860, 0x00020000 },
224 { 0xa248, 0x0000221e },
225 { 0xa900, 0x00000000 },
226 { 0xa904, 0x00003800 },
227 { 0xa908, 0x00000000 },
228 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700229 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700230 { 0xa914, 0x00000000 },
231 { 0xa918, 0x00b20000 },
232 { 0xa91c, 0x00000000 },
233 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700234 { 0xa924, 0x00000300 },
235 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700236 { 0xa92c, 0x00000000 },
237 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700238 { 0xa934, 0x15150406 },
239 { 0xa938, 0x00020300 },
240 { 0xa93c, 0x00903900 },
241 { 0xa940, 0x00000000 },
242 { 0xa944, 0x00000000 },
243 { 0xa948, 0x20001b00 },
244 { 0xa94c, 0x0a000010 },
245 { 0xa950, 0x00000000 },
246 { 0xa954, 0x00000008 },
247 { 0xa960, 0x00110000 },
248 { 0xaa3c, 0x00003900 },
249 { 0xaa54, 0x00000008 },
250 { 0xaa60, 0x00110000 },
251 { 0 }
252};
253
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700254static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700255 { 0xa800, 0x00000000 },
256 { 0xa804, 0x00030400 },
257 { 0xa808, 0x00000806 },
258 { 0xa80c, 0x0c002f00 },
259 { 0xa810, 0x0c000300 },
260 { 0xa814, 0x00000000 },
261 { 0xa818, 0x00d20d00 },
262 { 0xa81c, 0x000000ff },
263 { 0xa820, 0x03004b02 },
264 { 0xa824, 0x00000600 },
265 { 0xa828, 0x07000773 },
266 { 0xa82c, 0x00000000 },
267 { 0xa830, 0x00020032 },
268 { 0xa834, 0x1520040d },
269 { 0xa838, 0x00020105 },
270 { 0xa83c, 0x00083700 },
271 { 0xa840, 0x000016ff },
272 { 0xa844, 0x00000000 },
273 { 0xa848, 0xff000000 },
274 { 0xa84c, 0x0a000010 },
275 { 0xa850, 0x00000001 },
276 { 0xa854, 0x00000008 },
277 { 0xa858, 0x00000008 },
278 { 0xa85c, 0x00000000 },
279 { 0xa860, 0x00020000 },
280 { 0xa248, 0x0000221e },
281 { 0xa900, 0x00000000 },
282 { 0xa904, 0x00003800 },
283 { 0xa908, 0x00000000 },
284 { 0xa90c, 0x0c000000 },
285 { 0xa910, 0x12000800 },
286 { 0xa914, 0x00000000 },
287 { 0xa918, 0x00b20000 },
288 { 0xa91c, 0x00000000 },
289 { 0xa920, 0x08004b02 },
290 { 0xa924, 0x00000300 },
291 { 0xa928, 0x01000820 },
292 { 0xa92c, 0x00000000 },
293 { 0xa930, 0x00030000 },
294 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700295 { 0xa938, 0x00020300 },
296 { 0xa93c, 0x00903900 },
297 { 0xa940, 0x00000000 },
298 { 0xa944, 0x00000000 },
299 { 0xa948, 0x20001b00 },
300 { 0xa94c, 0x0a000010 },
301 { 0xa950, 0x00000000 },
302 { 0xa954, 0x00000008 },
303 { 0xa960, 0x00110000 },
304 { 0xaa3c, 0x00003900 },
305 { 0xaa54, 0x00000008 },
306 { 0xaa60, 0x00110000 },
307 { 0 }
308};
309
Stefan Reinauer00636b02012-04-04 00:08:51 +0200310/* some vga option roms are used for several chipsets but they only have one
311 * PCI ID in their header. If we encounter such an option rom, we need to do
312 * the mapping ourselfes
313 */
314
315u32 map_oprom_vendev(u32 vendev)
316{
317 u32 new_vendev=vendev;
318
319 switch (vendev) {
Martin Rothe9dfdd92012-04-26 16:04:18 -0600320 case 0x80860102: /* GT1 Desktop */
321 case 0x8086010a: /* GT1 Server */
322 case 0x80860112: /* GT2 Desktop */
323 case 0x80860116: /* GT2 Mobile */
324 case 0x80860122: /* GT2 Desktop >=1.3GHz */
325 case 0x80860126: /* GT2 Mobile >=1.3GHz */
Stefan Reinauer816e9d12013-01-14 10:25:43 -0800326 case 0x80860156: /* IVB */
Martin Rothe9dfdd92012-04-26 16:04:18 -0600327 case 0x80860166: /* IVB */
328 new_vendev=0x80860106; /* GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200329 break;
330 }
331
332 return new_vendev;
333}
334
335static struct resource *gtt_res = NULL;
336
337static inline u32 gtt_read(u32 reg)
338{
339 return read32(gtt_res->base + reg);
340}
341
342static inline void gtt_write(u32 reg, u32 data)
343{
344 write32(gtt_res->base + reg, data);
345}
346
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700347static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700348{
349 for (; pm && pm->reg; pm++)
350 gtt_write(pm->reg, pm->value);
351}
352
Stefan Reinauer00636b02012-04-04 00:08:51 +0200353#define GTT_RETRY 1000
354static int gtt_poll(u32 reg, u32 mask, u32 value)
355{
356 unsigned try = GTT_RETRY;
357 u32 data;
358
359 while (try--) {
360 data = gtt_read(reg);
361 if ((data & mask) == value)
362 return 1;
363 udelay(10);
364 }
365
366 printk(BIOS_ERR, "GT init timeout\n");
367 return 0;
368}
369
370static void gma_pm_init_pre_vbios(struct device *dev)
371{
372 u32 reg32;
373
374 printk(BIOS_DEBUG, "GT Power Management Init\n");
375
376 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
377 if (!gtt_res || !gtt_res->base)
378 return;
379
380 if (bridge_silicon_revision() < IVB_STEP_C0) {
381 /* 1: Enable force wake */
382 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700383 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200384 } else {
385 gtt_write(0xa180, 1 << 5);
386 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700387 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200388 }
389
390 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
391 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
392 reg32 = gtt_read(0x42004);
393 reg32 |= (1 << 14) | (1 << 15);
394 gtt_write(0x42004, reg32);
395 }
396
397 if (bridge_silicon_revision() >= IVB_STEP_A0) {
398 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200399 reg32 = gtt_read(0x45010);
400 reg32 |= (1 << 1) | (1 << 0);
401 gtt_write(0x45010, reg32);
402 }
403
404 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700405 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200406 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200407 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700408 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
409 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200410 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700411 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
412 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200413 }
414 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700415 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700416
Duncan Laurie8508cff2012-04-12 16:02:43 -0700417 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700418 /* GT1 SKU */
419 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
420 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700421 } else {
422 /* GT2 SKU */
423 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
424 tdp /= (1 << unit);
425
426 if (tdp <= 17) {
427 /* <=17W ULV */
428 printk(BIOS_DEBUG, "IVB GT2 17W "
429 "Power Meter Weights\n");
430 gtt_write_powermeter(ivb_pm_gt2_17w);
431 } else if ((tdp >= 25) && (tdp <= 35)) {
432 /* 25W-35W */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700433 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
Duncan Laurie8508cff2012-04-12 16:02:43 -0700434 "Power Meter Weights\n");
435 gtt_write_powermeter(ivb_pm_gt2_35w);
436 } else {
437 /* All others */
438 printk(BIOS_DEBUG, "IVB GT2 35W "
439 "Power Meter Weights\n");
440 gtt_write_powermeter(ivb_pm_gt2_35w);
441 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700442 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200443 }
444
445 /* 3: Gear ratio map */
446 gtt_write(0xa004, 0x00000010);
447
448 /* 4: GFXPAUSE */
449 gtt_write(0xa000, 0x00070020);
450
451 /* 5: Dynamic EU trip control */
452 gtt_write(0xa080, 0x00000004);
453
454 /* 6: ECO bits */
455 reg32 = gtt_read(0xa180);
456 reg32 |= (1 << 26) | (1 << 31);
457 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
458 if (bridge_silicon_revision() >= SNB_STEP_D1)
459 reg32 |= (1 << 20);
460 gtt_write(0xa180, reg32);
461
462 /* 6a: for SnB step D2+ only */
463 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
464 (bridge_silicon_revision() >= SNB_STEP_D2)) {
465 reg32 = gtt_read(0x9400);
466 reg32 |= (1 << 7);
467 gtt_write(0x9400, reg32);
468
469 reg32 = gtt_read(0x941c);
470 reg32 &= 0xf;
471 reg32 |= (1 << 1);
472 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700473 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200474 }
475
476 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
477 reg32 = gtt_read(0x907c);
478 reg32 |= (1 << 16);
479 gtt_write(0x907c, reg32);
480
481 /* 6b: Clocking reset controls */
482 gtt_write(0x9424, 0x00000001);
483 } else {
484 /* 6b: Clocking reset controls */
485 gtt_write(0x9424, 0x00000000);
486 }
487
488 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700489 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
490 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
491 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
492 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
493 gtt_write(0x138124, 0x8000000a);
494 gtt_poll(0x138124, (1 << 31), (0 << 31));
495 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200496
497 /* 8 */
498 gtt_write(0xa090, 0x00000000); /* RC Control */
499 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
500 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
501 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
502 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
503 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
504
505 /* 9 */
506 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
507 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
508 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
509
510 /* 10 */
511 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
512 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
513 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
514 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
515 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
516
517 /* 11 */
518 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
519 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
520 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
521 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
522 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
523 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
524 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
525
526 /* 11a: Enable Render Standby (RC6) */
527 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700528 /*
529 * IvyBridge should also support DeepRenderStandby.
530 *
531 * Unfortunately it does not work reliably on all SKUs so
532 * disable it here and it can be enabled by the kernel.
533 */
534 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200535 } else {
536 gtt_write(0xa090, 0x88040000); /* HW RC Control */
537 }
538
539 /* 12: Normal Frequency Request */
540 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
541 reg32 = MCHBAR32(0x5998);
542 reg32 >>= 16;
543 reg32 &= 0xef;
544 reg32 <<= 25;
545 gtt_write(0xa008, reg32);
546
547 /* 13: RP Control */
548 gtt_write(0xa024, 0x00000592);
549
550 /* 14: Enable PM Interrupts */
551 gtt_write(0x4402c, 0x03000076);
552
553 /* Clear 0x6c024 [8:6] */
554 reg32 = gtt_read(0x6c024);
555 reg32 &= ~0x000001c0;
556 gtt_write(0x6c024, reg32);
557}
558
559static void gma_pm_init_post_vbios(struct device *dev)
560{
561 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
562 u32 reg32;
563
564 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
565
566 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700567 if (bridge_silicon_revision() < IVB_STEP_C0) {
568 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700569 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700570 } else {
571 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700572 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
573 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700574 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200575
576 /* 16: SW RC Control */
577 gtt_write(0xa094, 0x00060000);
578
579 /* Setup Digital Port Hotplug */
580 reg32 = gtt_read(0xc4030);
581 if (!reg32) {
582 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
583 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
584 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
585 gtt_write(0xc4030, reg32);
586 }
587
588 /* Setup Panel Power On Delays */
589 reg32 = gtt_read(0xc7208);
590 if (!reg32) {
591 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
592 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
593 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
594 gtt_write(0xc7208, reg32);
595 }
596
597 /* Setup Panel Power Off Delays */
598 reg32 = gtt_read(0xc720c);
599 if (!reg32) {
600 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
601 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
602 gtt_write(0xc720c, reg32);
603 }
604
605 /* Setup Panel Power Cycle Delay */
606 if (conf->gpu_panel_power_cycle_delay) {
607 reg32 = gtt_read(0xc7210);
608 reg32 &= ~0xff;
609 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
610 gtt_write(0xc7210, reg32);
611 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700612
613 /* Enable Backlight if needed */
614 if (conf->gpu_cpu_backlight) {
615 gtt_write(0x48250, (1 << 31));
616 gtt_write(0x48254, conf->gpu_cpu_backlight);
617 }
618 if (conf->gpu_pch_backlight) {
619 gtt_write(0xc8250, (1 << 31));
620 gtt_write(0xc8254, conf->gpu_pch_backlight);
621 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200622}
623
624static void gma_func0_init(struct device *dev)
625{
626 u32 reg32;
627
628 /* IGD needs to be Bus Master */
629 reg32 = pci_read_config32(dev, PCI_COMMAND);
630 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
631 pci_write_config32(dev, PCI_COMMAND, reg32);
632
633 /* Init graphics power management */
634 gma_pm_init_pre_vbios(dev);
635
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800636#if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
Stefan Reinauer00636b02012-04-04 00:08:51 +0200637 /* PCI Init, will run VBIOS */
638 pci_dev_init(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800639#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +0200640
641 /* Post VBIOS init */
642 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800643
644#if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
645 /* This should probably run before post VBIOS init. */
646 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
Aaron Durbinbb4e79a2013-03-26 14:09:47 -0500647 u32 iobase, mmiobase, physbase, graphics_base;
Vladimir Serbinenko12fcb862014-02-23 00:09:48 +0100648 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800649 iobase = dev->resource_list[2].base;
650 mmiobase = dev->resource_list[0].base;
651 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
Aaron Durbinbb4e79a2013-03-26 14:09:47 -0500652 graphics_base = dev->resource_list[1].base;
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800653
Vladimir Serbinenko1783a3c2014-02-23 00:10:35 +0100654 int lightup_ok = i915lightup(conf, physbase, iobase, mmiobase, graphics_base);
655 if (lightup_ok)
656 gfx_set_init_done(1);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800657#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +0200658}
659
660static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
661{
662 if (!vendor || !device) {
663 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
664 pci_read_config32(dev, PCI_VENDOR_ID));
665 } else {
666 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
667 ((device & 0xffff) << 16) | (vendor & 0xffff));
668 }
669}
670
671static struct pci_operations gma_pci_ops = {
672 .set_subsystem = gma_set_subsystem,
673};
674
675static struct device_operations gma_func0_ops = {
Vladimir Serbinenko30fe6122014-02-05 23:25:28 +0100676 .read_resources = pci_dev_read_resources,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200677 .set_resources = pci_dev_set_resources,
678 .enable_resources = pci_dev_enable_resources,
679 .init = gma_func0_init,
680 .scan_bus = 0,
681 .enable = 0,
682 .ops_pci = &gma_pci_ops,
683};
684
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800685static const unsigned short pci_device_ids[] = { 0x0102, 0x0106, 0x010a, 0x0112,
686 0x0116, 0x0122, 0x0126, 0x0156,
687 0x0166,
688 0 };
689
690static const struct pci_driver gma __pci_driver = {
691 .ops = &gma_func0_ops,
692 .vendor = PCI_VENDOR_ID_INTEL,
693 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200694};