blob: f75dfda6165d5f3a3bd263d1895757e9411948fa [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer00636b02012-04-04 00:08:51 +02002
3#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02005#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +02006#include <bootmode.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02007#include <delay.h>
8#include <device/device.h>
9#include <device/pci.h>
10#include <device/pci_ids.h>
Ronald G. Minnich69efaa02013-02-26 10:07:40 -080011#include <device/pci_ops.h>
Nico Huber18228162017-06-08 16:31:57 +020012#include <drivers/intel/gma/libgfxinit.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050013#include <drivers/intel/gma/opregion.h>
Patrick Rudolphda9302a2019-03-24 17:01:41 +010014#include <southbridge/intel/bd82x6x/pch.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020015#include <types.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020016
17#include "chip.h"
18#include "sandybridge.h"
19
Duncan Lauriedd585b82012-04-09 12:05:18 -070020struct gt_powermeter {
21 u16 reg;
22 u32 value;
23};
24
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070025static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070026 { 0xa200, 0xcc000000 },
27 { 0xa204, 0x07000040 },
28 { 0xa208, 0x0000fe00 },
29 { 0xa20c, 0x00000000 },
30 { 0xa210, 0x17000000 },
31 { 0xa214, 0x00000021 },
32 { 0xa218, 0x0817fe19 },
33 { 0xa21c, 0x00000000 },
34 { 0xa220, 0x00000000 },
35 { 0xa224, 0xcc000000 },
36 { 0xa228, 0x07000040 },
37 { 0xa22c, 0x0000fe00 },
38 { 0xa230, 0x00000000 },
39 { 0xa234, 0x17000000 },
40 { 0xa238, 0x00000021 },
41 { 0xa23c, 0x0817fe19 },
42 { 0xa240, 0x00000000 },
43 { 0xa244, 0x00000000 },
44 { 0xa248, 0x8000421e },
Angel Pons7c49cb82020-03-16 23:17:32 +010045 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -070046};
47
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070048static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070049 { 0xa200, 0x330000a6 },
50 { 0xa204, 0x402d0031 },
51 { 0xa208, 0x00165f83 },
52 { 0xa20c, 0xf1000000 },
53 { 0xa210, 0x00000000 },
54 { 0xa214, 0x00160016 },
55 { 0xa218, 0x002a002b },
56 { 0xa21c, 0x00000000 },
57 { 0xa220, 0x00000000 },
58 { 0xa224, 0x330000a6 },
59 { 0xa228, 0x402d0031 },
60 { 0xa22c, 0x00165f83 },
61 { 0xa230, 0xf1000000 },
62 { 0xa234, 0x00000000 },
63 { 0xa238, 0x00160016 },
64 { 0xa23c, 0x002a002b },
65 { 0xa240, 0x00000000 },
66 { 0xa244, 0x00000000 },
67 { 0xa248, 0x8000421e },
Angel Pons7c49cb82020-03-16 23:17:32 +010068 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -070069};
70
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070071static const struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070072 { 0xa800, 0x00000000 },
73 { 0xa804, 0x00021c00 },
74 { 0xa808, 0x00000403 },
75 { 0xa80c, 0x02001700 },
76 { 0xa810, 0x05000200 },
77 { 0xa814, 0x00000000 },
78 { 0xa818, 0x00690500 },
79 { 0xa81c, 0x0000007f },
80 { 0xa820, 0x01002501 },
81 { 0xa824, 0x00000300 },
82 { 0xa828, 0x01000331 },
83 { 0xa82c, 0x0000000c },
84 { 0xa830, 0x00010016 },
85 { 0xa834, 0x01100101 },
86 { 0xa838, 0x00010103 },
87 { 0xa83c, 0x00041300 },
88 { 0xa840, 0x00000b30 },
89 { 0xa844, 0x00000000 },
90 { 0xa848, 0x7f000000 },
91 { 0xa84c, 0x05000008 },
92 { 0xa850, 0x00000001 },
93 { 0xa854, 0x00000004 },
94 { 0xa858, 0x00000007 },
95 { 0xa85c, 0x00000000 },
96 { 0xa860, 0x00010000 },
97 { 0xa248, 0x0000221e },
98 { 0xa900, 0x00000000 },
99 { 0xa904, 0x00001c00 },
100 { 0xa908, 0x00000000 },
101 { 0xa90c, 0x06000000 },
102 { 0xa910, 0x09000200 },
103 { 0xa914, 0x00000000 },
104 { 0xa918, 0x00590000 },
105 { 0xa91c, 0x00000000 },
106 { 0xa920, 0x04002501 },
107 { 0xa924, 0x00000100 },
108 { 0xa928, 0x03000410 },
109 { 0xa92c, 0x00000000 },
110 { 0xa930, 0x00020000 },
111 { 0xa934, 0x02070106 },
112 { 0xa938, 0x00010100 },
113 { 0xa93c, 0x00401c00 },
114 { 0xa940, 0x00000000 },
115 { 0xa944, 0x00000000 },
116 { 0xa948, 0x10000e00 },
117 { 0xa94c, 0x02000004 },
118 { 0xa950, 0x00000001 },
119 { 0xa954, 0x00000004 },
120 { 0xa960, 0x00060000 },
121 { 0xaa3c, 0x00001c00 },
122 { 0xaa54, 0x00000004 },
123 { 0xaa60, 0x00060000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100124 { 0 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700125};
126
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700127static const struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700128 { 0xa800, 0x20000000 },
129 { 0xa804, 0x000e3800 },
130 { 0xa808, 0x00000806 },
131 { 0xa80c, 0x0c002f00 },
132 { 0xa810, 0x0c000800 },
133 { 0xa814, 0x00000000 },
134 { 0xa818, 0x00d20d00 },
135 { 0xa81c, 0x000000ff },
136 { 0xa820, 0x03004b02 },
137 { 0xa824, 0x00000600 },
138 { 0xa828, 0x07000773 },
139 { 0xa82c, 0x00000000 },
140 { 0xa830, 0x00020032 },
141 { 0xa834, 0x1520040d },
142 { 0xa838, 0x00020105 },
143 { 0xa83c, 0x00083700 },
144 { 0xa840, 0x000016ff },
145 { 0xa844, 0x00000000 },
146 { 0xa848, 0xff000000 },
147 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700148 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700149 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700150 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700151 { 0xa85c, 0x00000000 },
152 { 0xa860, 0x00020000 },
153 { 0xa248, 0x0000221e },
154 { 0xa900, 0x00000000 },
155 { 0xa904, 0x00003800 },
156 { 0xa908, 0x00000000 },
157 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700158 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700159 { 0xa914, 0x00000000 },
160 { 0xa918, 0x00b20000 },
161 { 0xa91c, 0x00000000 },
162 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700163 { 0xa924, 0x00000300 },
164 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700165 { 0xa92c, 0x00000000 },
166 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700167 { 0xa934, 0x15150406 },
168 { 0xa938, 0x00020300 },
169 { 0xa93c, 0x00903900 },
170 { 0xa940, 0x00000000 },
171 { 0xa944, 0x00000000 },
172 { 0xa948, 0x20001b00 },
173 { 0xa94c, 0x0a000010 },
174 { 0xa950, 0x00000000 },
175 { 0xa954, 0x00000008 },
176 { 0xa960, 0x00110000 },
177 { 0xaa3c, 0x00003900 },
178 { 0xaa54, 0x00000008 },
179 { 0xaa60, 0x00110000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100180 { 0 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700181};
182
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700183static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700184 { 0xa800, 0x00000000 },
185 { 0xa804, 0x00030400 },
186 { 0xa808, 0x00000806 },
187 { 0xa80c, 0x0c002f00 },
188 { 0xa810, 0x0c000300 },
189 { 0xa814, 0x00000000 },
190 { 0xa818, 0x00d20d00 },
191 { 0xa81c, 0x000000ff },
192 { 0xa820, 0x03004b02 },
193 { 0xa824, 0x00000600 },
194 { 0xa828, 0x07000773 },
195 { 0xa82c, 0x00000000 },
196 { 0xa830, 0x00020032 },
197 { 0xa834, 0x1520040d },
198 { 0xa838, 0x00020105 },
199 { 0xa83c, 0x00083700 },
200 { 0xa840, 0x000016ff },
201 { 0xa844, 0x00000000 },
202 { 0xa848, 0xff000000 },
203 { 0xa84c, 0x0a000010 },
204 { 0xa850, 0x00000001 },
205 { 0xa854, 0x00000008 },
206 { 0xa858, 0x00000008 },
207 { 0xa85c, 0x00000000 },
208 { 0xa860, 0x00020000 },
209 { 0xa248, 0x0000221e },
210 { 0xa900, 0x00000000 },
211 { 0xa904, 0x00003800 },
212 { 0xa908, 0x00000000 },
213 { 0xa90c, 0x0c000000 },
214 { 0xa910, 0x12000800 },
215 { 0xa914, 0x00000000 },
216 { 0xa918, 0x00b20000 },
217 { 0xa91c, 0x00000000 },
218 { 0xa920, 0x08004b02 },
219 { 0xa924, 0x00000300 },
220 { 0xa928, 0x01000820 },
221 { 0xa92c, 0x00000000 },
222 { 0xa930, 0x00030000 },
223 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700224 { 0xa938, 0x00020300 },
225 { 0xa93c, 0x00903900 },
226 { 0xa940, 0x00000000 },
227 { 0xa944, 0x00000000 },
228 { 0xa948, 0x20001b00 },
229 { 0xa94c, 0x0a000010 },
230 { 0xa950, 0x00000000 },
231 { 0xa954, 0x00000008 },
232 { 0xa960, 0x00110000 },
233 { 0xaa3c, 0x00003900 },
234 { 0xaa54, 0x00000008 },
235 { 0xaa60, 0x00110000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100236 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700237};
238
Angel Pons7c49cb82020-03-16 23:17:32 +0100239/*
240 * Some VGA option roms are used for several chipsets but they only have one PCI ID in their
241 * header. If we encounter such an option rom, we need to do the mapping ourselves.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200242 */
243
244u32 map_oprom_vendev(u32 vendev)
245{
Nico Huber23b93dd2017-07-29 01:46:23 +0200246 u32 new_vendev = vendev;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200247
248 switch (vendev) {
Nico Huber23b93dd2017-07-29 01:46:23 +0200249 case 0x80860102: /* SNB GT1 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100250 case 0x8086010a: /* SNB GT1 Server */
Nico Huber23b93dd2017-07-29 01:46:23 +0200251 case 0x80860112: /* SNB GT2 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100252 case 0x80860116: /* SNB GT2 Mobile */
Nico Huber23b93dd2017-07-29 01:46:23 +0200253 case 0x80860122: /* SNB GT2 Desktop >=1.3GHz */
Angel Pons7c49cb82020-03-16 23:17:32 +0100254 case 0x80860126: /* SNB GT2 Mobile >=1.3GHz */
Nico Huber23b93dd2017-07-29 01:46:23 +0200255 case 0x80860152: /* IVB GT1 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100256 case 0x80860156: /* IVB GT1 Mobile */
Nico Huber23b93dd2017-07-29 01:46:23 +0200257 case 0x80860162: /* IVB GT2 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100258 case 0x80860166: /* IVB GT2 Mobile */
259 case 0x8086016a: /* IVB GT2 Server */
260 new_vendev = 0x80860106;/* SNB GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200261 break;
262 }
263
264 return new_vendev;
265}
266
267static struct resource *gtt_res = NULL;
268
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200269u32 gtt_read(u32 reg)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200270{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800271 return read32(res2mmio(gtt_res, reg, 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200272}
273
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200274void gtt_write(u32 reg, u32 data)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200275{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800276 write32(res2mmio(gtt_res, reg, 0), data);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200277}
278
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700279static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700280{
281 for (; pm && pm->reg; pm++)
282 gtt_write(pm->reg, pm->value);
283}
284
Stefan Reinauer00636b02012-04-04 00:08:51 +0200285#define GTT_RETRY 1000
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200286int gtt_poll(u32 reg, u32 mask, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200287{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530288 unsigned int try = GTT_RETRY;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200289 u32 data;
290
291 while (try--) {
292 data = gtt_read(reg);
293 if ((data & mask) == value)
294 return 1;
295 udelay(10);
296 }
297
298 printk(BIOS_ERR, "GT init timeout\n");
299 return 0;
300}
301
302static void gma_pm_init_pre_vbios(struct device *dev)
303{
304 u32 reg32;
305
306 printk(BIOS_DEBUG, "GT Power Management Init\n");
307
308 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
309 if (!gtt_res || !gtt_res->base)
310 return;
311
312 if (bridge_silicon_revision() < IVB_STEP_C0) {
313 /* 1: Enable force wake */
314 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700315 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200316 } else {
317 gtt_write(0xa180, 1 << 5);
318 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700319 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200320 }
321
322 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
323 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
324 reg32 = gtt_read(0x42004);
325 reg32 |= (1 << 14) | (1 << 15);
326 gtt_write(0x42004, reg32);
327 }
328
329 if (bridge_silicon_revision() >= IVB_STEP_A0) {
330 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200331 reg32 = gtt_read(0x45010);
332 reg32 |= (1 << 1) | (1 << 0);
333 gtt_write(0x45010, reg32);
334 }
335
336 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700337 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200338 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200339 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700340 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
341 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200342 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700343 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
344 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200345 }
346 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700347 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700348
Duncan Laurie8508cff2012-04-12 16:02:43 -0700349 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700350 /* GT1 SKU */
351 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
352 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700353 } else {
354 /* GT2 SKU */
355 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
356 tdp /= (1 << unit);
357
358 if (tdp <= 17) {
359 /* <=17W ULV */
Angel Pons7c49cb82020-03-16 23:17:32 +0100360 printk(BIOS_DEBUG, "IVB GT2 17W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700361 gtt_write_powermeter(ivb_pm_gt2_17w);
362 } else if ((tdp >= 25) && (tdp <= 35)) {
363 /* 25W-35W */
Angel Pons7c49cb82020-03-16 23:17:32 +0100364 printk(BIOS_DEBUG, "IVB GT2 25W-35W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700365 gtt_write_powermeter(ivb_pm_gt2_35w);
366 } else {
367 /* All others */
Angel Pons7c49cb82020-03-16 23:17:32 +0100368 printk(BIOS_DEBUG, "IVB GT2 35W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700369 gtt_write_powermeter(ivb_pm_gt2_35w);
370 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700371 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200372 }
373
374 /* 3: Gear ratio map */
375 gtt_write(0xa004, 0x00000010);
376
377 /* 4: GFXPAUSE */
378 gtt_write(0xa000, 0x00070020);
379
380 /* 5: Dynamic EU trip control */
381 gtt_write(0xa080, 0x00000004);
382
383 /* 6: ECO bits */
384 reg32 = gtt_read(0xa180);
385 reg32 |= (1 << 26) | (1 << 31);
386 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
387 if (bridge_silicon_revision() >= SNB_STEP_D1)
388 reg32 |= (1 << 20);
389 gtt_write(0xa180, reg32);
390
391 /* 6a: for SnB step D2+ only */
392 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
393 (bridge_silicon_revision() >= SNB_STEP_D2)) {
394 reg32 = gtt_read(0x9400);
395 reg32 |= (1 << 7);
396 gtt_write(0x9400, reg32);
397
398 reg32 = gtt_read(0x941c);
399 reg32 &= 0xf;
400 reg32 |= (1 << 1);
401 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700402 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200403 }
404
405 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
406 reg32 = gtt_read(0x907c);
407 reg32 |= (1 << 16);
408 gtt_write(0x907c, reg32);
409
410 /* 6b: Clocking reset controls */
411 gtt_write(0x9424, 0x00000001);
412 } else {
413 /* 6b: Clocking reset controls */
414 gtt_write(0x9424, 0x00000000);
415 }
416
417 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700418 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
419 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
420 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
421 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
422 gtt_write(0x138124, 0x8000000a);
423 gtt_poll(0x138124, (1 << 31), (0 << 31));
424 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200425
426 /* 8 */
427 gtt_write(0xa090, 0x00000000); /* RC Control */
428 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
429 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
430 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
431 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
432 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
433
434 /* 9 */
435 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
436 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
437 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
438
439 /* 10 */
440 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
441 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
442 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
443 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
444 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
445
446 /* 11 */
447 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
448 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
449 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
450 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
451 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
452 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
453 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
454
Evgeny Zinoviev0df0c7e2020-06-16 03:53:37 +0300455 /*
456 * 11a: Enable Render Standby (RC6)
457 *
458 * IvyBridge should also support DeepRenderStandby.
459 *
460 * Unfortunately it does not work reliably on all SKUs so
461 * disable it here and it can be enabled by the kernel.
462 */
463 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200464
465 /* 12: Normal Frequency Request */
Felix Held6b6c94b2017-11-25 00:45:23 +0100466 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 */
467 /* only the lower 7 bits are used and shifted left by 25 */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200468 reg32 = MCHBAR32(0x5998);
469 reg32 >>= 16;
Felix Held6b6c94b2017-11-25 00:45:23 +0100470 reg32 &= 0x7f;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200471 reg32 <<= 25;
472 gtt_write(0xa008, reg32);
473
474 /* 13: RP Control */
475 gtt_write(0xa024, 0x00000592);
476
477 /* 14: Enable PM Interrupts */
478 gtt_write(0x4402c, 0x03000076);
479
480 /* Clear 0x6c024 [8:6] */
481 reg32 = gtt_read(0x6c024);
482 reg32 &= ~0x000001c0;
483 gtt_write(0x6c024, reg32);
Nico Huber07e206a2016-10-19 15:20:17 +0200484
485 /* Initialize DP buffer translation with recommended defaults */
486 gtt_write(0xe4f00, 0x0100030c);
487 gtt_write(0xe4f04, 0x00b8230c);
488 gtt_write(0xe4f08, 0x06f8930c);
489 gtt_write(0xe4f0c, 0x05f8e38e);
490 gtt_write(0xe4f10, 0x00b8030c);
491 gtt_write(0xe4f14, 0x0b78830c);
492 gtt_write(0xe4f18, 0x09f8d3cf);
493 gtt_write(0xe4f1c, 0x01e8030c);
494 gtt_write(0xe4f20, 0x09f863cf);
495 gtt_write(0xe4f24, 0x0ff803cf);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200496}
497
498static void gma_pm_init_post_vbios(struct device *dev)
499{
500 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
501 u32 reg32;
502
503 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
504
505 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700506 if (bridge_silicon_revision() < IVB_STEP_C0) {
507 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700508 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700509 } else {
510 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700511 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
512 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700513 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200514
515 /* 16: SW RC Control */
516 gtt_write(0xa094, 0x00060000);
517
518 /* Setup Digital Port Hotplug */
519 reg32 = gtt_read(0xc4030);
520 if (!reg32) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100521 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200522 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
523 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
524 gtt_write(0xc4030, reg32);
525 }
526
527 /* Setup Panel Power On Delays */
528 reg32 = gtt_read(0xc7208);
529 if (!reg32) {
530 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
531 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
532 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
533 gtt_write(0xc7208, reg32);
534 }
535
536 /* Setup Panel Power Off Delays */
537 reg32 = gtt_read(0xc720c);
538 if (!reg32) {
539 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
540 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
541 gtt_write(0xc720c, reg32);
542 }
543
544 /* Setup Panel Power Cycle Delay */
545 if (conf->gpu_panel_power_cycle_delay) {
546 reg32 = gtt_read(0xc7210);
547 reg32 &= ~0xff;
548 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
549 gtt_write(0xc7210, reg32);
550 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700551
552 /* Enable Backlight if needed */
553 if (conf->gpu_cpu_backlight) {
554 gtt_write(0x48250, (1 << 31));
555 gtt_write(0x48254, conf->gpu_cpu_backlight);
556 }
557 if (conf->gpu_pch_backlight) {
558 gtt_write(0xc8250, (1 << 31));
559 gtt_write(0xc8254, conf->gpu_pch_backlight);
560 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200561}
562
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200563/* Enable SCI to ACPI _GPE._L06 */
564static void gma_enable_swsci(void)
565{
566 u16 reg16;
567
Angel Pons7c49cb82020-03-16 23:17:32 +0100568 /* Clear DMISCI status */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200569 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
570 reg16 &= DMISCI_STS;
571 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
572
Angel Pons7c49cb82020-03-16 23:17:32 +0100573 /* Clear ACPI TCO status */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200574 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
575
Angel Pons7c49cb82020-03-16 23:17:32 +0100576 /* Enable ACPI TCO SCIs */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200577 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
578 reg16 |= TCOSCI_EN;
579 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
580}
581
Stefan Reinauer00636b02012-04-04 00:08:51 +0200582static void gma_func0_init(struct device *dev)
583{
Nico Huberf2a0be22020-04-26 17:01:25 +0200584 intel_gma_init_igd_opregion();
585
Stefan Reinauer00636b02012-04-04 00:08:51 +0200586 /* Init graphics power management */
587 gma_pm_init_pre_vbios(dev);
588
Nico Huberdd597622020-04-26 19:46:35 +0200589 if (!CONFIG(NO_GFX_INIT))
590 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
591
Nico Huberd1b99d22019-05-30 15:11:42 +0200592 if (!CONFIG(MAINBOARD_USE_LIBGFXINIT))
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700593 /* PCI Init, will run VBIOS */
594 pci_dev_init(dev);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200595
596 /* Post VBIOS init */
597 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800598
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200599 int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1;
600
Patrick Rudolphde4a1a02017-06-20 19:13:33 +0200601 /* Running graphics init on S3 breaks Linux drm driver. */
602 if (!acpi_is_wakeup_s3() &&
Julius Wernercd49cce2019-03-05 16:53:33 -0800603 CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200604 if (vga_disable) {
605 printk(BIOS_INFO,
606 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
Nico Huber88c64872016-10-05 18:02:01 +0200607 } else {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200608 /* This should probably run before post VBIOS init. */
609 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200610 int lightup_ok;
Arthur Heymansa6be58f2018-07-18 16:43:43 +0200611 gma_gfxinit(&lightup_ok);
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200612 if (lightup_ok)
613 gfx_set_init_done(1);
Nico Huber88c64872016-10-05 18:02:01 +0200614 }
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700615 }
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200616
617 gma_enable_swsci();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200618}
619
Furquan Shaikh7536a392020-04-24 21:59:21 -0700620static void gma_generate_ssdt(const struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100621{
Matt DeVillier348f9f02020-03-30 19:30:18 -0500622 const struct northbridge_intel_sandybridge_config *chip = device->chip_info;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100623
Matt DeVillier348f9f02020-03-30 19:30:18 -0500624 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100625}
626
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600627static const char *gma_acpi_name(const struct device *dev)
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200628{
629 return "GFX0";
630}
631
Angel Pons7c49cb82020-03-16 23:17:32 +0100632/* Called by PCI set_vga_bridge function */
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200633static void gma_func0_disable(struct device *dev)
634{
Angel Pons9733f6a2020-06-07 19:23:03 +0200635 /* Disable VGA decode */
636 pci_or_config16(pcidev_on_root(0, 0), GGC, 1 << 1);
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200637
638 dev->enabled = 0;
639}
640
Stefan Reinauer00636b02012-04-04 00:08:51 +0200641static struct device_operations gma_func0_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200642 .read_resources = pci_dev_read_resources,
643 .set_resources = pci_dev_set_resources,
644 .enable_resources = pci_dev_enable_resources,
Matt DeVillier348f9f02020-03-30 19:30:18 -0500645 .acpi_fill_ssdt = gma_generate_ssdt,
Nico Huber68680dd2020-03-31 17:34:52 +0200646 .init = gma_func0_init,
Nico Huber68680dd2020-03-31 17:34:52 +0200647 .disable = gma_func0_disable,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200648 .ops_pci = &pci_dev_ops_pci,
Nico Huber68680dd2020-03-31 17:34:52 +0200649 .acpi_name = gma_acpi_name,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200650};
651
Angel Pons7c49cb82020-03-16 23:17:32 +0100652static const unsigned short pci_device_ids[] = {
653 0x0102, 0x0106, 0x010a, 0x0112,
654 0x0116, 0x0122, 0x0126, 0x0156,
655 0x0166, 0x0162, 0x016a, 0x0152,
656 0
657};
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800658
659static const struct pci_driver gma __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100660 .ops = &gma_func0_ops,
661 .vendor = PCI_VENDOR_ID_INTEL,
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800662 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200663};