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