blob: d7ad8febb104e215af463d4e30d18089add2e727 [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
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
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_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700143 { 0xa800, 0x20000000 },
144 { 0xa804, 0x000e3800 },
145 { 0xa808, 0x00000806 },
146 { 0xa80c, 0x0c002f00 },
147 { 0xa810, 0x0c000800 },
148 { 0xa814, 0x00000000 },
149 { 0xa818, 0x00d20d00 },
150 { 0xa81c, 0x000000ff },
151 { 0xa820, 0x03004b02 },
152 { 0xa824, 0x00000600 },
153 { 0xa828, 0x07000773 },
154 { 0xa82c, 0x00000000 },
155 { 0xa830, 0x00020032 },
156 { 0xa834, 0x1520040d },
157 { 0xa838, 0x00020105 },
158 { 0xa83c, 0x00083700 },
159 { 0xa840, 0x000016ff },
160 { 0xa844, 0x00000000 },
161 { 0xa848, 0xff000000 },
162 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700163 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700164 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700165 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700166 { 0xa85c, 0x00000000 },
167 { 0xa860, 0x00020000 },
168 { 0xa248, 0x0000221e },
169 { 0xa900, 0x00000000 },
170 { 0xa904, 0x00003800 },
171 { 0xa908, 0x00000000 },
172 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700173 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700174 { 0xa914, 0x00000000 },
175 { 0xa918, 0x00b20000 },
176 { 0xa91c, 0x00000000 },
177 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700178 { 0xa924, 0x00000300 },
179 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700180 { 0xa92c, 0x00000000 },
181 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700182 { 0xa934, 0x15150406 },
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_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700199 { 0xa800, 0x00000000 },
200 { 0xa804, 0x00030400 },
201 { 0xa808, 0x00000806 },
202 { 0xa80c, 0x0c002f00 },
203 { 0xa810, 0x0c000300 },
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 },
219 { 0xa850, 0x00000001 },
220 { 0xa854, 0x00000008 },
221 { 0xa858, 0x00000008 },
222 { 0xa85c, 0x00000000 },
223 { 0xa860, 0x00020000 },
224 { 0xa248, 0x0000221e },
225 { 0xa900, 0x00000000 },
226 { 0xa904, 0x00003800 },
227 { 0xa908, 0x00000000 },
228 { 0xa90c, 0x0c000000 },
229 { 0xa910, 0x12000800 },
230 { 0xa914, 0x00000000 },
231 { 0xa918, 0x00b20000 },
232 { 0xa91c, 0x00000000 },
233 { 0xa920, 0x08004b02 },
234 { 0xa924, 0x00000300 },
235 { 0xa928, 0x01000820 },
236 { 0xa92c, 0x00000000 },
237 { 0xa930, 0x00030000 },
238 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700239 { 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 Reinauer00636b02012-04-04 00:08:51 +0200254/* some vga option roms are used for several chipsets but they only have one
255 * PCI ID in their header. If we encounter such an option rom, we need to do
256 * the mapping ourselfes
257 */
258
259u32 map_oprom_vendev(u32 vendev)
260{
261 u32 new_vendev=vendev;
262
263 switch (vendev) {
Martin Rothe9dfdd92012-04-26 16:04:18 -0600264 case 0x80860102: /* GT1 Desktop */
265 case 0x8086010a: /* GT1 Server */
266 case 0x80860112: /* GT2 Desktop */
267 case 0x80860116: /* GT2 Mobile */
268 case 0x80860122: /* GT2 Desktop >=1.3GHz */
269 case 0x80860126: /* GT2 Mobile >=1.3GHz */
Stefan Reinauer816e9d12013-01-14 10:25:43 -0800270 case 0x80860156: /* IVB */
Martin Rothe9dfdd92012-04-26 16:04:18 -0600271 case 0x80860166: /* IVB */
272 new_vendev=0x80860106; /* GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200273 break;
274 }
275
276 return new_vendev;
277}
278
279static struct resource *gtt_res = NULL;
280
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200281u32 gtt_read(u32 reg)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200282{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800283 return read32(res2mmio(gtt_res, reg, 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200284}
285
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200286void gtt_write(u32 reg, u32 data)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200287{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800288 write32(res2mmio(gtt_res, reg, 0), data);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200289}
290
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700291static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700292{
293 for (; pm && pm->reg; pm++)
294 gtt_write(pm->reg, pm->value);
295}
296
Stefan Reinauer00636b02012-04-04 00:08:51 +0200297#define GTT_RETRY 1000
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200298int gtt_poll(u32 reg, u32 mask, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200299{
300 unsigned try = GTT_RETRY;
301 u32 data;
302
303 while (try--) {
304 data = gtt_read(reg);
305 if ((data & mask) == value)
306 return 1;
307 udelay(10);
308 }
309
310 printk(BIOS_ERR, "GT init timeout\n");
311 return 0;
312}
313
314static void gma_pm_init_pre_vbios(struct device *dev)
315{
316 u32 reg32;
317
318 printk(BIOS_DEBUG, "GT Power Management Init\n");
319
320 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
321 if (!gtt_res || !gtt_res->base)
322 return;
323
324 if (bridge_silicon_revision() < IVB_STEP_C0) {
325 /* 1: Enable force wake */
326 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700327 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200328 } else {
329 gtt_write(0xa180, 1 << 5);
330 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700331 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200332 }
333
334 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
335 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
336 reg32 = gtt_read(0x42004);
337 reg32 |= (1 << 14) | (1 << 15);
338 gtt_write(0x42004, reg32);
339 }
340
341 if (bridge_silicon_revision() >= IVB_STEP_A0) {
342 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200343 reg32 = gtt_read(0x45010);
344 reg32 |= (1 << 1) | (1 << 0);
345 gtt_write(0x45010, reg32);
346 }
347
348 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700349 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200350 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200351 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700352 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
353 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200354 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700355 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
356 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200357 }
358 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700359 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700360
Duncan Laurie8508cff2012-04-12 16:02:43 -0700361 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700362 /* GT1 SKU */
363 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
364 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700365 } else {
366 /* GT2 SKU */
367 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
368 tdp /= (1 << unit);
369
370 if (tdp <= 17) {
371 /* <=17W ULV */
372 printk(BIOS_DEBUG, "IVB GT2 17W "
373 "Power Meter Weights\n");
374 gtt_write_powermeter(ivb_pm_gt2_17w);
375 } else if ((tdp >= 25) && (tdp <= 35)) {
376 /* 25W-35W */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700377 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
Duncan Laurie8508cff2012-04-12 16:02:43 -0700378 "Power Meter Weights\n");
379 gtt_write_powermeter(ivb_pm_gt2_35w);
380 } else {
381 /* All others */
382 printk(BIOS_DEBUG, "IVB GT2 35W "
383 "Power Meter Weights\n");
384 gtt_write_powermeter(ivb_pm_gt2_35w);
385 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700386 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200387 }
388
389 /* 3: Gear ratio map */
390 gtt_write(0xa004, 0x00000010);
391
392 /* 4: GFXPAUSE */
393 gtt_write(0xa000, 0x00070020);
394
395 /* 5: Dynamic EU trip control */
396 gtt_write(0xa080, 0x00000004);
397
398 /* 6: ECO bits */
399 reg32 = gtt_read(0xa180);
400 reg32 |= (1 << 26) | (1 << 31);
401 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
402 if (bridge_silicon_revision() >= SNB_STEP_D1)
403 reg32 |= (1 << 20);
404 gtt_write(0xa180, reg32);
405
406 /* 6a: for SnB step D2+ only */
407 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
408 (bridge_silicon_revision() >= SNB_STEP_D2)) {
409 reg32 = gtt_read(0x9400);
410 reg32 |= (1 << 7);
411 gtt_write(0x9400, reg32);
412
413 reg32 = gtt_read(0x941c);
414 reg32 &= 0xf;
415 reg32 |= (1 << 1);
416 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700417 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200418 }
419
420 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
421 reg32 = gtt_read(0x907c);
422 reg32 |= (1 << 16);
423 gtt_write(0x907c, reg32);
424
425 /* 6b: Clocking reset controls */
426 gtt_write(0x9424, 0x00000001);
427 } else {
428 /* 6b: Clocking reset controls */
429 gtt_write(0x9424, 0x00000000);
430 }
431
432 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700433 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
434 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
435 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
436 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
437 gtt_write(0x138124, 0x8000000a);
438 gtt_poll(0x138124, (1 << 31), (0 << 31));
439 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200440
441 /* 8 */
442 gtt_write(0xa090, 0x00000000); /* RC Control */
443 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
444 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
445 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
446 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
447 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
448
449 /* 9 */
450 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
451 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
452 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
453
454 /* 10 */
455 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
456 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
457 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
458 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
459 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
460
461 /* 11 */
462 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
463 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
464 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
465 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
466 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
467 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
468 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
469
470 /* 11a: Enable Render Standby (RC6) */
471 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700472 /*
473 * IvyBridge should also support DeepRenderStandby.
474 *
475 * Unfortunately it does not work reliably on all SKUs so
476 * disable it here and it can be enabled by the kernel.
477 */
478 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200479 } else {
480 gtt_write(0xa090, 0x88040000); /* HW RC Control */
481 }
482
483 /* 12: Normal Frequency Request */
484 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
485 reg32 = MCHBAR32(0x5998);
486 reg32 >>= 16;
487 reg32 &= 0xef;
488 reg32 <<= 25;
489 gtt_write(0xa008, reg32);
490
491 /* 13: RP Control */
492 gtt_write(0xa024, 0x00000592);
493
494 /* 14: Enable PM Interrupts */
495 gtt_write(0x4402c, 0x03000076);
496
497 /* Clear 0x6c024 [8:6] */
498 reg32 = gtt_read(0x6c024);
499 reg32 &= ~0x000001c0;
500 gtt_write(0x6c024, reg32);
501}
502
503static void gma_pm_init_post_vbios(struct device *dev)
504{
505 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
506 u32 reg32;
507
508 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
509
510 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700511 if (bridge_silicon_revision() < IVB_STEP_C0) {
512 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700513 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700514 } else {
515 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700516 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
517 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700518 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200519
520 /* 16: SW RC Control */
521 gtt_write(0xa094, 0x00060000);
522
523 /* Setup Digital Port Hotplug */
524 reg32 = gtt_read(0xc4030);
525 if (!reg32) {
526 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
527 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
528 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
529 gtt_write(0xc4030, reg32);
530 }
531
532 /* Setup Panel Power On Delays */
533 reg32 = gtt_read(0xc7208);
534 if (!reg32) {
535 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
536 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
537 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
538 gtt_write(0xc7208, reg32);
539 }
540
541 /* Setup Panel Power Off Delays */
542 reg32 = gtt_read(0xc720c);
543 if (!reg32) {
544 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
545 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
546 gtt_write(0xc720c, reg32);
547 }
548
549 /* Setup Panel Power Cycle Delay */
550 if (conf->gpu_panel_power_cycle_delay) {
551 reg32 = gtt_read(0xc7210);
552 reg32 &= ~0xff;
553 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
554 gtt_write(0xc7210, reg32);
555 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700556
557 /* Enable Backlight if needed */
558 if (conf->gpu_cpu_backlight) {
559 gtt_write(0x48250, (1 << 31));
560 gtt_write(0x48254, conf->gpu_cpu_backlight);
561 }
562 if (conf->gpu_pch_backlight) {
563 gtt_write(0xc8250, (1 << 31));
564 gtt_write(0xc8254, conf->gpu_pch_backlight);
565 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200566}
567
568static void gma_func0_init(struct device *dev)
569{
570 u32 reg32;
571
572 /* IGD needs to be Bus Master */
573 reg32 = pci_read_config32(dev, PCI_COMMAND);
574 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
575 pci_write_config32(dev, PCI_COMMAND, reg32);
576
577 /* Init graphics power management */
578 gma_pm_init_pre_vbios(dev);
579
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800580#if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
Stefan Reinauer00636b02012-04-04 00:08:51 +0200581 /* PCI Init, will run VBIOS */
582 pci_dev_init(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800583#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +0200584
585 /* Post VBIOS init */
586 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800587
588#if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
589 /* This should probably run before post VBIOS init. */
590 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800591 u8 *mmiobase;
592 u32 iobase, physbase, graphics_base;
Vladimir Serbinenko12fcb862014-02-23 00:09:48 +0100593 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800594 iobase = dev->resource_list[2].base;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800595 mmiobase = res2mmio(&dev->resource_list[0], 0, 0);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800596 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
Aaron Durbinbb4e79a2013-03-26 14:09:47 -0500597 graphics_base = dev->resource_list[1].base;
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800598
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200599 int lightup_ok = i915lightup_sandy(&conf->gfx, physbase, iobase, mmiobase, graphics_base);
Vladimir Serbinenko1783a3c2014-02-23 00:10:35 +0100600 if (lightup_ok)
601 gfx_set_init_done(1);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800602#endif
Stefan Reinauer00636b02012-04-04 00:08:51 +0200603}
604
605static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
606{
607 if (!vendor || !device) {
608 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
609 pci_read_config32(dev, PCI_VENDOR_ID));
610 } else {
611 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
612 ((device & 0xffff) << 16) | (vendor & 0xffff));
613 }
614}
615
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100616const struct i915_gpu_controller_info *
617intel_gma_get_controller_info(void)
618{
619 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
620 if (!dev) {
621 return NULL;
622 }
623 struct northbridge_intel_sandybridge_config *chip = dev->chip_info;
624 return &chip->gfx;
625}
626
627static void gma_ssdt(void)
628{
629 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
630 if (!gfx) {
631 return;
632 }
633
634 drivers_intel_gma_displays_ssdt_generate(gfx);
635}
636
Stefan Reinauer00636b02012-04-04 00:08:51 +0200637static struct pci_operations gma_pci_ops = {
638 .set_subsystem = gma_set_subsystem,
639};
640
641static struct device_operations gma_func0_ops = {
Vladimir Serbinenko30fe6122014-02-05 23:25:28 +0100642 .read_resources = pci_dev_read_resources,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200643 .set_resources = pci_dev_set_resources,
644 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100645 .acpi_fill_ssdt_generator = gma_ssdt,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200646 .init = gma_func0_init,
647 .scan_bus = 0,
648 .enable = 0,
649 .ops_pci = &gma_pci_ops,
650};
651
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800652static const unsigned short pci_device_ids[] = { 0x0102, 0x0106, 0x010a, 0x0112,
653 0x0116, 0x0122, 0x0126, 0x0156,
654 0x0166,
655 0 };
656
657static const struct pci_driver gma __pci_driver = {
658 .ops = &gma_func0_ops,
659 .vendor = PCI_VENDOR_ID_INTEL,
660 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200661};