blob: 1f5251144bbc069238204a311ab75962aa55bbd4 [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.
Stefan Reinauer00636b02012-04-04 00:08:51 +020014 */
15
16#include <arch/io.h>
17#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020018#include <bootmode.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020019#include <delay.h>
Vladimir Serbinenkof2e206a2014-02-23 00:13:56 +010020#include <string.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020021#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
Ronald G. Minnich69efaa02013-02-26 10:07:40 -080024#include <device/pci_ops.h>
25#include <cpu/x86/msr.h>
26#include <cpu/x86/mtrr.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020027
28#include "chip.h"
29#include "sandybridge.h"
30
Duncan Lauriedd585b82012-04-09 12:05:18 -070031struct gt_powermeter {
32 u16 reg;
33 u32 value;
34};
35
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070036static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070037 { 0xa200, 0xcc000000 },
38 { 0xa204, 0x07000040 },
39 { 0xa208, 0x0000fe00 },
40 { 0xa20c, 0x00000000 },
41 { 0xa210, 0x17000000 },
42 { 0xa214, 0x00000021 },
43 { 0xa218, 0x0817fe19 },
44 { 0xa21c, 0x00000000 },
45 { 0xa220, 0x00000000 },
46 { 0xa224, 0xcc000000 },
47 { 0xa228, 0x07000040 },
48 { 0xa22c, 0x0000fe00 },
49 { 0xa230, 0x00000000 },
50 { 0xa234, 0x17000000 },
51 { 0xa238, 0x00000021 },
52 { 0xa23c, 0x0817fe19 },
53 { 0xa240, 0x00000000 },
54 { 0xa244, 0x00000000 },
55 { 0xa248, 0x8000421e },
56 { 0 }
57};
58
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070059static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070060 { 0xa200, 0x330000a6 },
61 { 0xa204, 0x402d0031 },
62 { 0xa208, 0x00165f83 },
63 { 0xa20c, 0xf1000000 },
64 { 0xa210, 0x00000000 },
65 { 0xa214, 0x00160016 },
66 { 0xa218, 0x002a002b },
67 { 0xa21c, 0x00000000 },
68 { 0xa220, 0x00000000 },
69 { 0xa224, 0x330000a6 },
70 { 0xa228, 0x402d0031 },
71 { 0xa22c, 0x00165f83 },
72 { 0xa230, 0xf1000000 },
73 { 0xa234, 0x00000000 },
74 { 0xa238, 0x00160016 },
75 { 0xa23c, 0x002a002b },
76 { 0xa240, 0x00000000 },
77 { 0xa244, 0x00000000 },
78 { 0xa248, 0x8000421e },
79 { 0 }
80};
81
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070082static const struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070083 { 0xa800, 0x00000000 },
84 { 0xa804, 0x00021c00 },
85 { 0xa808, 0x00000403 },
86 { 0xa80c, 0x02001700 },
87 { 0xa810, 0x05000200 },
88 { 0xa814, 0x00000000 },
89 { 0xa818, 0x00690500 },
90 { 0xa81c, 0x0000007f },
91 { 0xa820, 0x01002501 },
92 { 0xa824, 0x00000300 },
93 { 0xa828, 0x01000331 },
94 { 0xa82c, 0x0000000c },
95 { 0xa830, 0x00010016 },
96 { 0xa834, 0x01100101 },
97 { 0xa838, 0x00010103 },
98 { 0xa83c, 0x00041300 },
99 { 0xa840, 0x00000b30 },
100 { 0xa844, 0x00000000 },
101 { 0xa848, 0x7f000000 },
102 { 0xa84c, 0x05000008 },
103 { 0xa850, 0x00000001 },
104 { 0xa854, 0x00000004 },
105 { 0xa858, 0x00000007 },
106 { 0xa85c, 0x00000000 },
107 { 0xa860, 0x00010000 },
108 { 0xa248, 0x0000221e },
109 { 0xa900, 0x00000000 },
110 { 0xa904, 0x00001c00 },
111 { 0xa908, 0x00000000 },
112 { 0xa90c, 0x06000000 },
113 { 0xa910, 0x09000200 },
114 { 0xa914, 0x00000000 },
115 { 0xa918, 0x00590000 },
116 { 0xa91c, 0x00000000 },
117 { 0xa920, 0x04002501 },
118 { 0xa924, 0x00000100 },
119 { 0xa928, 0x03000410 },
120 { 0xa92c, 0x00000000 },
121 { 0xa930, 0x00020000 },
122 { 0xa934, 0x02070106 },
123 { 0xa938, 0x00010100 },
124 { 0xa93c, 0x00401c00 },
125 { 0xa940, 0x00000000 },
126 { 0xa944, 0x00000000 },
127 { 0xa948, 0x10000e00 },
128 { 0xa94c, 0x02000004 },
129 { 0xa950, 0x00000001 },
130 { 0xa954, 0x00000004 },
131 { 0xa960, 0x00060000 },
132 { 0xaa3c, 0x00001c00 },
133 { 0xaa54, 0x00000004 },
134 { 0xaa60, 0x00060000 },
135 { 0 }
136};
137
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700138static const struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700139 { 0xa800, 0x20000000 },
140 { 0xa804, 0x000e3800 },
141 { 0xa808, 0x00000806 },
142 { 0xa80c, 0x0c002f00 },
143 { 0xa810, 0x0c000800 },
144 { 0xa814, 0x00000000 },
145 { 0xa818, 0x00d20d00 },
146 { 0xa81c, 0x000000ff },
147 { 0xa820, 0x03004b02 },
148 { 0xa824, 0x00000600 },
149 { 0xa828, 0x07000773 },
150 { 0xa82c, 0x00000000 },
151 { 0xa830, 0x00020032 },
152 { 0xa834, 0x1520040d },
153 { 0xa838, 0x00020105 },
154 { 0xa83c, 0x00083700 },
155 { 0xa840, 0x000016ff },
156 { 0xa844, 0x00000000 },
157 { 0xa848, 0xff000000 },
158 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700159 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700160 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700161 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700162 { 0xa85c, 0x00000000 },
163 { 0xa860, 0x00020000 },
164 { 0xa248, 0x0000221e },
165 { 0xa900, 0x00000000 },
166 { 0xa904, 0x00003800 },
167 { 0xa908, 0x00000000 },
168 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700169 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700170 { 0xa914, 0x00000000 },
171 { 0xa918, 0x00b20000 },
172 { 0xa91c, 0x00000000 },
173 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700174 { 0xa924, 0x00000300 },
175 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700176 { 0xa92c, 0x00000000 },
177 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700178 { 0xa934, 0x15150406 },
179 { 0xa938, 0x00020300 },
180 { 0xa93c, 0x00903900 },
181 { 0xa940, 0x00000000 },
182 { 0xa944, 0x00000000 },
183 { 0xa948, 0x20001b00 },
184 { 0xa94c, 0x0a000010 },
185 { 0xa950, 0x00000000 },
186 { 0xa954, 0x00000008 },
187 { 0xa960, 0x00110000 },
188 { 0xaa3c, 0x00003900 },
189 { 0xaa54, 0x00000008 },
190 { 0xaa60, 0x00110000 },
191 { 0 }
192};
193
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700194static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700195 { 0xa800, 0x00000000 },
196 { 0xa804, 0x00030400 },
197 { 0xa808, 0x00000806 },
198 { 0xa80c, 0x0c002f00 },
199 { 0xa810, 0x0c000300 },
200 { 0xa814, 0x00000000 },
201 { 0xa818, 0x00d20d00 },
202 { 0xa81c, 0x000000ff },
203 { 0xa820, 0x03004b02 },
204 { 0xa824, 0x00000600 },
205 { 0xa828, 0x07000773 },
206 { 0xa82c, 0x00000000 },
207 { 0xa830, 0x00020032 },
208 { 0xa834, 0x1520040d },
209 { 0xa838, 0x00020105 },
210 { 0xa83c, 0x00083700 },
211 { 0xa840, 0x000016ff },
212 { 0xa844, 0x00000000 },
213 { 0xa848, 0xff000000 },
214 { 0xa84c, 0x0a000010 },
215 { 0xa850, 0x00000001 },
216 { 0xa854, 0x00000008 },
217 { 0xa858, 0x00000008 },
218 { 0xa85c, 0x00000000 },
219 { 0xa860, 0x00020000 },
220 { 0xa248, 0x0000221e },
221 { 0xa900, 0x00000000 },
222 { 0xa904, 0x00003800 },
223 { 0xa908, 0x00000000 },
224 { 0xa90c, 0x0c000000 },
225 { 0xa910, 0x12000800 },
226 { 0xa914, 0x00000000 },
227 { 0xa918, 0x00b20000 },
228 { 0xa91c, 0x00000000 },
229 { 0xa920, 0x08004b02 },
230 { 0xa924, 0x00000300 },
231 { 0xa928, 0x01000820 },
232 { 0xa92c, 0x00000000 },
233 { 0xa930, 0x00030000 },
234 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700235 { 0xa938, 0x00020300 },
236 { 0xa93c, 0x00903900 },
237 { 0xa940, 0x00000000 },
238 { 0xa944, 0x00000000 },
239 { 0xa948, 0x20001b00 },
240 { 0xa94c, 0x0a000010 },
241 { 0xa950, 0x00000000 },
242 { 0xa954, 0x00000008 },
243 { 0xa960, 0x00110000 },
244 { 0xaa3c, 0x00003900 },
245 { 0xaa54, 0x00000008 },
246 { 0xaa60, 0x00110000 },
247 { 0 }
248};
249
Stefan Reinauer00636b02012-04-04 00:08:51 +0200250/* some vga option roms are used for several chipsets but they only have one
251 * PCI ID in their header. If we encounter such an option rom, we need to do
252 * the mapping ourselfes
253 */
254
255u32 map_oprom_vendev(u32 vendev)
256{
257 u32 new_vendev=vendev;
258
259 switch (vendev) {
Martin Rothe9dfdd92012-04-26 16:04:18 -0600260 case 0x80860102: /* GT1 Desktop */
261 case 0x8086010a: /* GT1 Server */
262 case 0x80860112: /* GT2 Desktop */
263 case 0x80860116: /* GT2 Mobile */
264 case 0x80860122: /* GT2 Desktop >=1.3GHz */
265 case 0x80860126: /* GT2 Mobile >=1.3GHz */
Stefan Reinauer816e9d12013-01-14 10:25:43 -0800266 case 0x80860156: /* IVB */
Martin Rothe9dfdd92012-04-26 16:04:18 -0600267 case 0x80860166: /* IVB */
268 new_vendev=0x80860106; /* GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200269 break;
270 }
271
272 return new_vendev;
273}
274
275static struct resource *gtt_res = NULL;
276
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200277u32 gtt_read(u32 reg)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200278{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800279 return read32(res2mmio(gtt_res, reg, 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200280}
281
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200282void gtt_write(u32 reg, u32 data)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200283{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800284 write32(res2mmio(gtt_res, reg, 0), data);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200285}
286
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700287static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700288{
289 for (; pm && pm->reg; pm++)
290 gtt_write(pm->reg, pm->value);
291}
292
Stefan Reinauer00636b02012-04-04 00:08:51 +0200293#define GTT_RETRY 1000
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200294int gtt_poll(u32 reg, u32 mask, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200295{
296 unsigned try = GTT_RETRY;
297 u32 data;
298
299 while (try--) {
300 data = gtt_read(reg);
301 if ((data & mask) == value)
302 return 1;
303 udelay(10);
304 }
305
306 printk(BIOS_ERR, "GT init timeout\n");
307 return 0;
308}
309
310static void gma_pm_init_pre_vbios(struct device *dev)
311{
312 u32 reg32;
313
314 printk(BIOS_DEBUG, "GT Power Management Init\n");
315
316 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
317 if (!gtt_res || !gtt_res->base)
318 return;
319
320 if (bridge_silicon_revision() < IVB_STEP_C0) {
321 /* 1: Enable force wake */
322 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700323 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200324 } else {
325 gtt_write(0xa180, 1 << 5);
326 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700327 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200328 }
329
330 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
331 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
332 reg32 = gtt_read(0x42004);
333 reg32 |= (1 << 14) | (1 << 15);
334 gtt_write(0x42004, reg32);
335 }
336
337 if (bridge_silicon_revision() >= IVB_STEP_A0) {
338 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200339 reg32 = gtt_read(0x45010);
340 reg32 |= (1 << 1) | (1 << 0);
341 gtt_write(0x45010, reg32);
342 }
343
344 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700345 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200346 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200347 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700348 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
349 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200350 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700351 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
352 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200353 }
354 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700355 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700356
Duncan Laurie8508cff2012-04-12 16:02:43 -0700357 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700358 /* GT1 SKU */
359 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
360 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700361 } else {
362 /* GT2 SKU */
363 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
364 tdp /= (1 << unit);
365
366 if (tdp <= 17) {
367 /* <=17W ULV */
368 printk(BIOS_DEBUG, "IVB GT2 17W "
369 "Power Meter Weights\n");
370 gtt_write_powermeter(ivb_pm_gt2_17w);
371 } else if ((tdp >= 25) && (tdp <= 35)) {
372 /* 25W-35W */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700373 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
Duncan Laurie8508cff2012-04-12 16:02:43 -0700374 "Power Meter Weights\n");
375 gtt_write_powermeter(ivb_pm_gt2_35w);
376 } else {
377 /* All others */
378 printk(BIOS_DEBUG, "IVB GT2 35W "
379 "Power Meter Weights\n");
380 gtt_write_powermeter(ivb_pm_gt2_35w);
381 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700382 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200383 }
384
385 /* 3: Gear ratio map */
386 gtt_write(0xa004, 0x00000010);
387
388 /* 4: GFXPAUSE */
389 gtt_write(0xa000, 0x00070020);
390
391 /* 5: Dynamic EU trip control */
392 gtt_write(0xa080, 0x00000004);
393
394 /* 6: ECO bits */
395 reg32 = gtt_read(0xa180);
396 reg32 |= (1 << 26) | (1 << 31);
397 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
398 if (bridge_silicon_revision() >= SNB_STEP_D1)
399 reg32 |= (1 << 20);
400 gtt_write(0xa180, reg32);
401
402 /* 6a: for SnB step D2+ only */
403 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
404 (bridge_silicon_revision() >= SNB_STEP_D2)) {
405 reg32 = gtt_read(0x9400);
406 reg32 |= (1 << 7);
407 gtt_write(0x9400, reg32);
408
409 reg32 = gtt_read(0x941c);
410 reg32 &= 0xf;
411 reg32 |= (1 << 1);
412 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700413 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200414 }
415
416 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
417 reg32 = gtt_read(0x907c);
418 reg32 |= (1 << 16);
419 gtt_write(0x907c, reg32);
420
421 /* 6b: Clocking reset controls */
422 gtt_write(0x9424, 0x00000001);
423 } else {
424 /* 6b: Clocking reset controls */
425 gtt_write(0x9424, 0x00000000);
426 }
427
428 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700429 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
430 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
431 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
432 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
433 gtt_write(0x138124, 0x8000000a);
434 gtt_poll(0x138124, (1 << 31), (0 << 31));
435 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200436
437 /* 8 */
438 gtt_write(0xa090, 0x00000000); /* RC Control */
439 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
440 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
441 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
442 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
443 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
444
445 /* 9 */
446 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
447 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
448 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
449
450 /* 10 */
451 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
452 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
453 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
454 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
455 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
456
457 /* 11 */
458 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
459 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
460 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
461 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
462 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
463 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
464 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
465
466 /* 11a: Enable Render Standby (RC6) */
467 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700468 /*
469 * IvyBridge should also support DeepRenderStandby.
470 *
471 * Unfortunately it does not work reliably on all SKUs so
472 * disable it here and it can be enabled by the kernel.
473 */
474 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200475 } else {
476 gtt_write(0xa090, 0x88040000); /* HW RC Control */
477 }
478
479 /* 12: Normal Frequency Request */
480 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
481 reg32 = MCHBAR32(0x5998);
482 reg32 >>= 16;
483 reg32 &= 0xef;
484 reg32 <<= 25;
485 gtt_write(0xa008, reg32);
486
487 /* 13: RP Control */
488 gtt_write(0xa024, 0x00000592);
489
490 /* 14: Enable PM Interrupts */
491 gtt_write(0x4402c, 0x03000076);
492
493 /* Clear 0x6c024 [8:6] */
494 reg32 = gtt_read(0x6c024);
495 reg32 &= ~0x000001c0;
496 gtt_write(0x6c024, reg32);
Nico Huber07e206a2016-10-19 15:20:17 +0200497
498 /* Initialize DP buffer translation with recommended defaults */
499 gtt_write(0xe4f00, 0x0100030c);
500 gtt_write(0xe4f04, 0x00b8230c);
501 gtt_write(0xe4f08, 0x06f8930c);
502 gtt_write(0xe4f0c, 0x05f8e38e);
503 gtt_write(0xe4f10, 0x00b8030c);
504 gtt_write(0xe4f14, 0x0b78830c);
505 gtt_write(0xe4f18, 0x09f8d3cf);
506 gtt_write(0xe4f1c, 0x01e8030c);
507 gtt_write(0xe4f20, 0x09f863cf);
508 gtt_write(0xe4f24, 0x0ff803cf);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200509}
510
511static void gma_pm_init_post_vbios(struct device *dev)
512{
513 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
514 u32 reg32;
515
516 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
517
518 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700519 if (bridge_silicon_revision() < IVB_STEP_C0) {
520 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700521 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700522 } else {
523 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700524 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
525 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700526 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200527
528 /* 16: SW RC Control */
529 gtt_write(0xa094, 0x00060000);
530
531 /* Setup Digital Port Hotplug */
532 reg32 = gtt_read(0xc4030);
533 if (!reg32) {
534 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
535 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
536 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
537 gtt_write(0xc4030, reg32);
538 }
539
540 /* Setup Panel Power On Delays */
541 reg32 = gtt_read(0xc7208);
542 if (!reg32) {
543 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
544 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
545 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
546 gtt_write(0xc7208, reg32);
547 }
548
549 /* Setup Panel Power Off Delays */
550 reg32 = gtt_read(0xc720c);
551 if (!reg32) {
552 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
553 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
554 gtt_write(0xc720c, reg32);
555 }
556
557 /* Setup Panel Power Cycle Delay */
558 if (conf->gpu_panel_power_cycle_delay) {
559 reg32 = gtt_read(0xc7210);
560 reg32 &= ~0xff;
561 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
562 gtt_write(0xc7210, reg32);
563 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700564
565 /* Enable Backlight if needed */
566 if (conf->gpu_cpu_backlight) {
567 gtt_write(0x48250, (1 << 31));
568 gtt_write(0x48254, conf->gpu_cpu_backlight);
569 }
570 if (conf->gpu_pch_backlight) {
571 gtt_write(0xc8250, (1 << 31));
572 gtt_write(0xc8254, conf->gpu_pch_backlight);
573 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200574}
575
576static void gma_func0_init(struct device *dev)
577{
578 u32 reg32;
579
580 /* IGD needs to be Bus Master */
581 reg32 = pci_read_config32(dev, PCI_COMMAND);
582 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
583 pci_write_config32(dev, PCI_COMMAND, reg32);
584
585 /* Init graphics power management */
586 gma_pm_init_pre_vbios(dev);
587
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700588 if (!IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT))
589 /* PCI Init, will run VBIOS */
590 pci_dev_init(dev);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200591
592 /* Post VBIOS init */
593 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800594
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700595 if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) {
596 /* This should probably run before post VBIOS init. */
597 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
598 u8 *mmiobase;
599 u32 iobase, physbase, graphics_base;
600 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
601 iobase = dev->resource_list[2].base;
602 mmiobase = res2mmio(&dev->resource_list[0], 0, 0);
603 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
604 graphics_base = dev->resource_list[1].base;
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800605
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700606 int lightup_ok = i915lightup_sandy(&conf->gfx, physbase, iobase,
607 mmiobase, graphics_base);
608 if (lightup_ok)
609 gfx_set_init_done(1);
610 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200611}
612
613static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
614{
615 if (!vendor || !device) {
616 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
617 pci_read_config32(dev, PCI_VENDOR_ID));
618 } else {
619 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
620 ((device & 0xffff) << 16) | (vendor & 0xffff));
621 }
622}
623
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100624const struct i915_gpu_controller_info *
625intel_gma_get_controller_info(void)
626{
627 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
628 if (!dev) {
629 return NULL;
630 }
631 struct northbridge_intel_sandybridge_config *chip = dev->chip_info;
632 return &chip->gfx;
633}
634
Alexander Couzens5eea4582015-04-12 22:18:55 +0200635static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100636{
637 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
638 if (!gfx) {
639 return;
640 }
641
642 drivers_intel_gma_displays_ssdt_generate(gfx);
643}
644
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200645/* called by pci set_vga_bridge function */
646static void gma_func0_disable(struct device *dev)
647{
648 u16 reg16;
649 device_t dev_host = dev_find_slot(0, PCI_DEVFN(0,0));
650
651 reg16 = pci_read_config16(dev_host, GGC);
652 reg16 |= (1 << 1); /* disable VGA decode */
653 pci_write_config16(dev_host, GGC, reg16);
654
655 dev->enabled = 0;
656}
657
Stefan Reinauer00636b02012-04-04 00:08:51 +0200658static struct pci_operations gma_pci_ops = {
659 .set_subsystem = gma_set_subsystem,
660};
661
662static struct device_operations gma_func0_ops = {
Vladimir Serbinenko30fe6122014-02-05 23:25:28 +0100663 .read_resources = pci_dev_read_resources,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200664 .set_resources = pci_dev_set_resources,
665 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100666 .acpi_fill_ssdt_generator = gma_ssdt,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200667 .init = gma_func0_init,
668 .scan_bus = 0,
669 .enable = 0,
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200670 .disable = gma_func0_disable,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200671 .ops_pci = &gma_pci_ops,
672};
673
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800674static const unsigned short pci_device_ids[] = { 0x0102, 0x0106, 0x010a, 0x0112,
675 0x0116, 0x0122, 0x0126, 0x0156,
Damien Zammit3162a1d2015-07-13 16:10:52 +1000676 0x0166, 0x0162, 0x0152,
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800677 0 };
678
679static const struct pci_driver gma __pci_driver = {
680 .ops = &gma_func0_ops,
681 .vendor = PCI_VENDOR_ID_INTEL,
682 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200683};