blob: 4dcbfb30eec2f61723214ff25618049c15cd0946 [file] [log] [blame]
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Chromium OS Authors
5 * Copyright (C) 2013 Vladimir Serbinenko
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010015 */
16
17#include <arch/io.h>
18#include <console/console.h>
19#include <delay.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <string.h>
24#include <device/pci_ops.h>
25#include <cpu/x86/msr.h>
26#include <cpu/x86/mtrr.h>
Vladimir Serbinenko13157302014-02-19 22:18:08 +010027#include <drivers/intel/gma/edid.h>
28#include <drivers/intel/gma/i915.h>
Patrick Rudolph5c820262017-05-17 19:39:12 +020029#include <drivers/intel/gma/intel_bios.h>
Nico Huber18228162017-06-08 16:31:57 +020030#include <drivers/intel/gma/libgfxinit.h>
Vladimir Serbinenko13157302014-02-19 22:18:08 +010031#include <pc80/vga.h>
32#include <pc80/vga_io.h>
Patrick Rudolph2be28402017-04-12 16:54:55 +020033#include <southbridge/intel/ibexpeak/nvs.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050034#include <drivers/intel/gma/opregion.h>
Patrick Rudolph2be28402017-04-12 16:54:55 +020035#include <cbmem.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010036
37#include "chip.h"
38#include "nehalem.h"
39
40struct gt_powermeter {
41 u16 reg;
42 u32 value;
43};
44
45static const struct gt_powermeter snb_pm_gt1[] = {
46 {0xa200, 0xcc000000},
47 {0xa204, 0x07000040},
48 {0xa208, 0x0000fe00},
49 {0xa20c, 0x00000000},
50 {0xa210, 0x17000000},
51 {0xa214, 0x00000021},
52 {0xa218, 0x0817fe19},
53 {0xa21c, 0x00000000},
54 {0xa220, 0x00000000},
55 {0xa224, 0xcc000000},
56 {0xa228, 0x07000040},
57 {0xa22c, 0x0000fe00},
58 {0xa230, 0x00000000},
59 {0xa234, 0x17000000},
60 {0xa238, 0x00000021},
61 {0xa23c, 0x0817fe19},
62 {0xa240, 0x00000000},
63 {0xa244, 0x00000000},
64 {0xa248, 0x8000421e},
65 {0}
66};
67
68static const struct gt_powermeter snb_pm_gt2[] = {
69 {0xa200, 0x330000a6},
70 {0xa204, 0x402d0031},
71 {0xa208, 0x00165f83},
72 {0xa20c, 0xf1000000},
73 {0xa210, 0x00000000},
74 {0xa214, 0x00160016},
75 {0xa218, 0x002a002b},
76 {0xa21c, 0x00000000},
77 {0xa220, 0x00000000},
78 {0xa224, 0x330000a6},
79 {0xa228, 0x402d0031},
80 {0xa22c, 0x00165f83},
81 {0xa230, 0xf1000000},
82 {0xa234, 0x00000000},
83 {0xa238, 0x00160016},
84 {0xa23c, 0x002a002b},
85 {0xa240, 0x00000000},
86 {0xa244, 0x00000000},
87 {0xa248, 0x8000421e},
88 {0}
89};
90
91static const struct gt_powermeter ivb_pm_gt1[] = {
92 {0xa800, 0x00000000},
93 {0xa804, 0x00021c00},
94 {0xa808, 0x00000403},
95 {0xa80c, 0x02001700},
96 {0xa810, 0x05000200},
97 {0xa814, 0x00000000},
98 {0xa818, 0x00690500},
99 {0xa81c, 0x0000007f},
100 {0xa820, 0x01002501},
101 {0xa824, 0x00000300},
102 {0xa828, 0x01000331},
103 {0xa82c, 0x0000000c},
104 {0xa830, 0x00010016},
105 {0xa834, 0x01100101},
106 {0xa838, 0x00010103},
107 {0xa83c, 0x00041300},
108 {0xa840, 0x00000b30},
109 {0xa844, 0x00000000},
110 {0xa848, 0x7f000000},
111 {0xa84c, 0x05000008},
112 {0xa850, 0x00000001},
113 {0xa854, 0x00000004},
114 {0xa858, 0x00000007},
115 {0xa85c, 0x00000000},
116 {0xa860, 0x00010000},
117 {0xa248, 0x0000221e},
118 {0xa900, 0x00000000},
119 {0xa904, 0x00001c00},
120 {0xa908, 0x00000000},
121 {0xa90c, 0x06000000},
122 {0xa910, 0x09000200},
123 {0xa914, 0x00000000},
124 {0xa918, 0x00590000},
125 {0xa91c, 0x00000000},
126 {0xa920, 0x04002501},
127 {0xa924, 0x00000100},
128 {0xa928, 0x03000410},
129 {0xa92c, 0x00000000},
130 {0xa930, 0x00020000},
131 {0xa934, 0x02070106},
132 {0xa938, 0x00010100},
133 {0xa93c, 0x00401c00},
134 {0xa940, 0x00000000},
135 {0xa944, 0x00000000},
136 {0xa948, 0x10000e00},
137 {0xa94c, 0x02000004},
138 {0xa950, 0x00000001},
139 {0xa954, 0x00000004},
140 {0xa960, 0x00060000},
141 {0xaa3c, 0x00001c00},
142 {0xaa54, 0x00000004},
143 {0xaa60, 0x00060000},
144 {0}
145};
146
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100147static const struct gt_powermeter ivb_pm_gt2_17w[] = {
148 {0xa800, 0x20000000},
149 {0xa804, 0x000e3800},
150 {0xa808, 0x00000806},
151 {0xa80c, 0x0c002f00},
152 {0xa810, 0x0c000800},
153 {0xa814, 0x00000000},
154 {0xa818, 0x00d20d00},
155 {0xa81c, 0x000000ff},
156 {0xa820, 0x03004b02},
157 {0xa824, 0x00000600},
158 {0xa828, 0x07000773},
159 {0xa82c, 0x00000000},
160 {0xa830, 0x00020032},
161 {0xa834, 0x1520040d},
162 {0xa838, 0x00020105},
163 {0xa83c, 0x00083700},
164 {0xa840, 0x000016ff},
165 {0xa844, 0x00000000},
166 {0xa848, 0xff000000},
167 {0xa84c, 0x0a000010},
168 {0xa850, 0x00000002},
169 {0xa854, 0x00000008},
170 {0xa858, 0x0000000f},
171 {0xa85c, 0x00000000},
172 {0xa860, 0x00020000},
173 {0xa248, 0x0000221e},
174 {0xa900, 0x00000000},
175 {0xa904, 0x00003800},
176 {0xa908, 0x00000000},
177 {0xa90c, 0x0c000000},
178 {0xa910, 0x12000800},
179 {0xa914, 0x00000000},
180 {0xa918, 0x00b20000},
181 {0xa91c, 0x00000000},
182 {0xa920, 0x08004b02},
183 {0xa924, 0x00000300},
184 {0xa928, 0x01000820},
185 {0xa92c, 0x00000000},
186 {0xa930, 0x00030000},
187 {0xa934, 0x15150406},
188 {0xa938, 0x00020300},
189 {0xa93c, 0x00903900},
190 {0xa940, 0x00000000},
191 {0xa944, 0x00000000},
192 {0xa948, 0x20001b00},
193 {0xa94c, 0x0a000010},
194 {0xa950, 0x00000000},
195 {0xa954, 0x00000008},
196 {0xa960, 0x00110000},
197 {0xaa3c, 0x00003900},
198 {0xaa54, 0x00000008},
199 {0xaa60, 0x00110000},
200 {0}
201};
202
203static const struct gt_powermeter ivb_pm_gt2_35w[] = {
204 {0xa800, 0x00000000},
205 {0xa804, 0x00030400},
206 {0xa808, 0x00000806},
207 {0xa80c, 0x0c002f00},
208 {0xa810, 0x0c000300},
209 {0xa814, 0x00000000},
210 {0xa818, 0x00d20d00},
211 {0xa81c, 0x000000ff},
212 {0xa820, 0x03004b02},
213 {0xa824, 0x00000600},
214 {0xa828, 0x07000773},
215 {0xa82c, 0x00000000},
216 {0xa830, 0x00020032},
217 {0xa834, 0x1520040d},
218 {0xa838, 0x00020105},
219 {0xa83c, 0x00083700},
220 {0xa840, 0x000016ff},
221 {0xa844, 0x00000000},
222 {0xa848, 0xff000000},
223 {0xa84c, 0x0a000010},
224 {0xa850, 0x00000001},
225 {0xa854, 0x00000008},
226 {0xa858, 0x00000008},
227 {0xa85c, 0x00000000},
228 {0xa860, 0x00020000},
229 {0xa248, 0x0000221e},
230 {0xa900, 0x00000000},
231 {0xa904, 0x00003800},
232 {0xa908, 0x00000000},
233 {0xa90c, 0x0c000000},
234 {0xa910, 0x12000800},
235 {0xa914, 0x00000000},
236 {0xa918, 0x00b20000},
237 {0xa91c, 0x00000000},
238 {0xa920, 0x08004b02},
239 {0xa924, 0x00000300},
240 {0xa928, 0x01000820},
241 {0xa92c, 0x00000000},
242 {0xa930, 0x00030000},
243 {0xa934, 0x15150406},
244 {0xa938, 0x00020300},
245 {0xa93c, 0x00903900},
246 {0xa940, 0x00000000},
247 {0xa944, 0x00000000},
248 {0xa948, 0x20001b00},
249 {0xa94c, 0x0a000010},
250 {0xa950, 0x00000000},
251 {0xa954, 0x00000008},
252 {0xa960, 0x00110000},
253 {0xaa3c, 0x00003900},
254 {0xaa54, 0x00000008},
255 {0xaa60, 0x00110000},
256 {0}
257};
258
259/* some vga option roms are used for several chipsets but they only have one
260 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -0700261 * the mapping ourselves
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100262 */
263
264u32 map_oprom_vendev(u32 vendev)
265{
266 u32 new_vendev = vendev;
267
Martin Roth128c1042016-11-18 09:29:03 -0700268 /* none currently. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100269
270 return new_vendev;
271}
272
273static struct resource *gtt_res = NULL;
274
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700275u32 gtt_read(u32 reg)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100276{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800277 return read32(res2mmio(gtt_res, reg, 0));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100278}
279
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700280void gtt_write(u32 reg, u32 data)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100281{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800282 write32(res2mmio(gtt_res, reg, 0), data);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100283}
284
285static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
286{
287 for (; pm && pm->reg; pm++)
288 gtt_write(pm->reg, pm->value);
289}
290
291#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700292int gtt_poll(u32 reg, u32 mask, u32 value)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100293{
294 unsigned try = GTT_RETRY;
295 u32 data;
296
297 while (try--) {
298 data = gtt_read(reg);
299 if ((data & mask) == value)
300 return 1;
301 udelay(10);
302 }
303
304 printk(BIOS_ERR, "GT init timeout\n");
305 return 0;
306}
307
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200308uintptr_t gma_get_gnvs_aslb(const void *gnvs)
309{
310 const global_nvs_t *gnvs_ptr = gnvs;
311 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
312}
313
314void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
315{
316 global_nvs_t *gnvs_ptr = gnvs;
317 if (gnvs_ptr)
318 gnvs_ptr->aslb = aslb;
319}
320
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100321static void gma_pm_init_pre_vbios(struct device *dev)
322{
323 u32 reg32;
324
325 printk(BIOS_DEBUG, "GT Power Management Init\n");
326
327 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
328 if (!gtt_res || !gtt_res->base)
329 return;
330
331 if (bridge_silicon_revision() < IVB_STEP_C0) {
332 /* 1: Enable force wake */
333 gtt_write(0xa18c, 0x00000001);
334 gtt_poll(0x130090, (1 << 0), (1 << 0));
335 } else {
336 gtt_write(0xa180, 1 << 5);
337 gtt_write(0xa188, 0xffff0001);
338 gtt_poll(0x130040, (1 << 0), (1 << 0));
339 }
340
341 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
342 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
343 reg32 = gtt_read(0x42004);
344 reg32 |= (1 << 14) | (1 << 15);
345 gtt_write(0x42004, reg32);
346 }
347
348 if (bridge_silicon_revision() >= IVB_STEP_A0) {
349 /* Display Reset Acknowledge Settings */
350 reg32 = gtt_read(0x45010);
351 reg32 |= (1 << 1) | (1 << 0);
352 gtt_write(0x45010, reg32);
353 }
354
355 /* 2: Get GT SKU from GTT+0x911c[13] */
356 reg32 = gtt_read(0x911c);
357 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
358 if (reg32 & (1 << 13)) {
359 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
360 gtt_write_powermeter(snb_pm_gt1);
361 } else {
362 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
363 gtt_write_powermeter(snb_pm_gt2);
364 }
365 } else {
366 u32 unit = MCHBAR32(0x5938) & 0xf;
367
368 if (reg32 & (1 << 13)) {
369 /* GT1 SKU */
370 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
371 gtt_write_powermeter(ivb_pm_gt1);
372 } else {
373 /* GT2 SKU */
374 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
375 tdp /= (1 << unit);
376
377 if (tdp <= 17) {
378 /* <=17W ULV */
379 printk(BIOS_DEBUG, "IVB GT2 17W "
380 "Power Meter Weights\n");
381 gtt_write_powermeter(ivb_pm_gt2_17w);
382 } else if ((tdp >= 25) && (tdp <= 35)) {
383 /* 25W-35W */
384 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
385 "Power Meter Weights\n");
386 gtt_write_powermeter(ivb_pm_gt2_35w);
387 } else {
388 /* All others */
389 printk(BIOS_DEBUG, "IVB GT2 35W "
390 "Power Meter Weights\n");
391 gtt_write_powermeter(ivb_pm_gt2_35w);
392 }
393 }
394 }
395
396 /* 3: Gear ratio map */
397 gtt_write(0xa004, 0x00000010);
398
399 /* 4: GFXPAUSE */
400 gtt_write(0xa000, 0x00070020);
401
402 /* 5: Dynamic EU trip control */
403 gtt_write(0xa080, 0x00000004);
404
405 /* 6: ECO bits */
406 reg32 = gtt_read(0xa180);
407 reg32 |= (1 << 26) | (1 << 31);
408 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
409 if (bridge_silicon_revision() >= SNB_STEP_D1)
410 reg32 |= (1 << 20);
411 gtt_write(0xa180, reg32);
412
413 /* 6a: for SnB step D2+ only */
414 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
415 (bridge_silicon_revision() >= SNB_STEP_D2)) {
416 reg32 = gtt_read(0x9400);
417 reg32 |= (1 << 7);
418 gtt_write(0x9400, reg32);
419
420 reg32 = gtt_read(0x941c);
421 reg32 &= 0xf;
422 reg32 |= (1 << 1);
423 gtt_write(0x941c, reg32);
424 gtt_poll(0x941c, (1 << 1), (0 << 1));
425 }
426
427 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
428 reg32 = gtt_read(0x907c);
429 reg32 |= (1 << 16);
430 gtt_write(0x907c, reg32);
431
432 /* 6b: Clocking reset controls */
433 gtt_write(0x9424, 0x00000001);
434 } else {
435 /* 6b: Clocking reset controls */
436 gtt_write(0x9424, 0x00000000);
437 }
438
439 /* 7 */
440 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
441 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
442 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
443 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
444 gtt_write(0x138124, 0x8000000a);
445 gtt_poll(0x138124, (1 << 31), (0 << 31));
446 }
447
448 /* 8 */
449 gtt_write(0xa090, 0x00000000); /* RC Control */
450 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
451 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
452 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
453 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
454 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
455
456 /* 9 */
457 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
458 gtt_write(0x12054, 0x0000000a); /* Video Idle Max Count */
459 gtt_write(0x22054, 0x0000000a); /* Blitter Idle Max Count */
460
461 /* 10 */
462 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
463 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
464 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
465 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
466 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
467
468 /* 11 */
469 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
470 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
471 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
472 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
473 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
474 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
475 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
476
477 /* 11a: Enable Render Standby (RC6) */
478 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
479 /*
480 * IvyBridge should also support DeepRenderStandby.
481 *
482 * Unfortunately it does not work reliably on all SKUs so
483 * disable it here and it can be enabled by the kernel.
484 */
485 gtt_write(0xa090, 0x88040000); /* HW RC Control */
486 } else {
487 gtt_write(0xa090, 0x88040000); /* HW RC Control */
488 }
489
490 /* 12: Normal Frequency Request */
Felix Held6b6c94b2017-11-25 00:45:23 +0100491 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 */
492 /* only the lower 7 bits are used and shifted left by 25 */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100493 reg32 = MCHBAR32(0x5998);
494 reg32 >>= 16;
Felix Held6b6c94b2017-11-25 00:45:23 +0100495 reg32 &= 0x7f;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100496 reg32 <<= 25;
497 gtt_write(0xa008, reg32);
498
499 /* 13: RP Control */
500 gtt_write(0xa024, 0x00000592);
501
502 /* 14: Enable PM Interrupts */
503 gtt_write(0x4402c, 0x03000076);
504
505 /* Clear 0x6c024 [8:6] */
506 reg32 = gtt_read(0x6c024);
507 reg32 &= ~0x000001c0;
508 gtt_write(0x6c024, reg32);
509}
510
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100511static void gma_pm_init_post_vbios(struct device *dev)
512{
513 struct northbridge_intel_nehalem_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 */
519 if (bridge_silicon_revision() < IVB_STEP_C0) {
520 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
521 gtt_poll(0x130090, (1 << 0), (0 << 0));
522 } else {
523 gtt_write(0xa188, 0x1fffe);
524 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
525 gtt_write(0xa188, gtt_read(0xa188) | 1);
526 }
527
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 }
564
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 }
574}
575
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800576static void train_link(u8 *mmio)
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100577{
578 /* Clear interrupts. */
579 write32(mmio + DEIIR, 0xffffffff);
580
581 write32(mmio + 0x000f0018, 0x000000ff);
582 write32(mmio + 0x000f1018, 0x000000ff);
583 write32(mmio + 0x000f000c, 0x001a2050);
584 write32(mmio + 0x00060100, 0x001c4000);
585 write32(mmio + 0x00060100, 0x801c4000);
586 write32(mmio + 0x000f000c, 0x801a2050);
587 write32(mmio + 0x00060100, 0x801c4000);
588 write32(mmio + 0x000f000c, 0x801a2050);
589 mdelay(1);
590
591 read32(mmio + 0x000f0014); // = 0x00000100
592 write32(mmio + 0x000f0014, 0x00000100);
593 write32(mmio + 0x00060100, 0x901c4000);
594 write32(mmio + 0x000f000c, 0x901a2050);
595 mdelay(1);
596 read32(mmio + 0x000f0014); // = 0x00000600
597}
598
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800599static void power_port(u8 *mmio)
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100600{
601 read32(mmio + 0x000e1100); // = 0x00000000
602 write32(mmio + 0x000e1100, 0x00000000);
603 write32(mmio + 0x000e1100, 0x00010000);
604 read32(mmio + 0x000e1100); // = 0x00010000
605 read32(mmio + 0x000e1100); // = 0x00010000
606 read32(mmio + 0x000e1100); // = 0x00000000
607 write32(mmio + 0x000e1100, 0x00000000);
608 read32(mmio + 0x000e1100); // = 0x00000000
609 read32(mmio + 0x000e4200); // = 0x0000001c
610 write32(mmio + 0x000e4210, 0x8004003e);
611 write32(mmio + 0x000e4214, 0x80060002);
612 write32(mmio + 0x000e4218, 0x01000000);
613 read32(mmio + 0x000e4210); // = 0x5144003e
614 write32(mmio + 0x000e4210, 0x5344003e);
615 read32(mmio + 0x000e4210); // = 0x0144003e
616 write32(mmio + 0x000e4210, 0x8074003e);
617 read32(mmio + 0x000e4210); // = 0x5144003e
618 read32(mmio + 0x000e4210); // = 0x5144003e
619 write32(mmio + 0x000e4210, 0x5344003e);
620 read32(mmio + 0x000e4210); // = 0x0144003e
621 write32(mmio + 0x000e4210, 0x8074003e);
622 read32(mmio + 0x000e4210); // = 0x5144003e
623 read32(mmio + 0x000e4210); // = 0x5144003e
624 write32(mmio + 0x000e4210, 0x5344003e);
625 read32(mmio + 0x000e4210); // = 0x0144003e
626 write32(mmio + 0x000e4210, 0x8074003e);
627 read32(mmio + 0x000e4210); // = 0x5144003e
628 read32(mmio + 0x000e4210); // = 0x5144003e
629 write32(mmio + 0x000e4210, 0x5344003e);
630 write32(mmio + 0x000e4f00, 0x0100030c);
631 write32(mmio + 0x000e4f04, 0x00b8230c);
632 write32(mmio + 0x000e4f08, 0x06f8930c);
633 write32(mmio + 0x000e4f0c, 0x09f8e38e);
634 write32(mmio + 0x000e4f10, 0x00b8030c);
635 write32(mmio + 0x000e4f14, 0x0b78830c);
636 write32(mmio + 0x000e4f18, 0x0ff8d3cf);
637 write32(mmio + 0x000e4f1c, 0x01e8030c);
638 write32(mmio + 0x000e4f20, 0x0ff863cf);
639 write32(mmio + 0x000e4f24, 0x0ff803cf);
640 write32(mmio + 0x000c4030, 0x00001000);
641 read32(mmio + 0x000c4000); // = 0x00000000
642 write32(mmio + 0x000c4030, 0x00001000);
643 read32(mmio + 0x000e1150); // = 0x0000001c
644 write32(mmio + 0x000e1150, 0x0000089c);
645 write32(mmio + 0x000fcc00, 0x01986f00);
646 write32(mmio + 0x000fcc0c, 0x01986f00);
647 write32(mmio + 0x000fcc18, 0x01986f00);
648 write32(mmio + 0x000fcc24, 0x01986f00);
649 read32(mmio + 0x000c4000); // = 0x00000000
650 read32(mmio + 0x000e1180); // = 0x40000002
651}
652
653static void intel_gma_init(const struct northbridge_intel_nehalem_config *info,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800654 u8 *mmio, u32 physbase, u16 piobase, u32 lfb)
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100655{
656 int i;
657 u8 edid_data[128];
658 struct edid edid;
Nicolas Reineckeb142b842015-10-03 17:32:38 +0200659 struct edid_mode *mode;
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100660 u32 hactive, vactive, right_border, bottom_border;
661 int hpolarity, vpolarity;
662 u32 vsync, hsync, vblank, hblank, hfront_porch, vfront_porch;
663 u32 candp1, candn;
664 u32 best_delta = 0xffffffff;
665 u32 target_frequency;
666 u32 pixel_p1 = 1;
667 u32 pixel_n = 1;
668 u32 pixel_m1 = 1;
669 u32 pixel_m2 = 1;
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200670 u32 link_frequency = info->gfx.link_frequency_270_mhz ? 270000 : 162000;
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100671 u32 data_m1;
672 u32 data_n1 = 0x00800000;
673 u32 link_m1;
674 u32 link_n1 = 0x00080000;
675
676 write32(mmio + 0x00070080, 0x00000000);
677 write32(mmio + DSPCNTR(0), 0x00000000);
678 write32(mmio + 0x00071180, 0x00000000);
679 write32(mmio + CPU_VGACNTRL, 0x0000298e | VGA_DISP_DISABLE);
680 write32(mmio + 0x0007019c, 0x00000000);
681 write32(mmio + 0x0007119c, 0x00000000);
682 write32(mmio + 0x000fc008, 0x2c010000);
683 write32(mmio + 0x000fc020, 0x2c010000);
684 write32(mmio + 0x000fc038, 0x2c010000);
685 write32(mmio + 0x000fc050, 0x2c010000);
686 write32(mmio + 0x000fc408, 0x2c010000);
687 write32(mmio + 0x000fc420, 0x2c010000);
688 write32(mmio + 0x000fc438, 0x2c010000);
689 write32(mmio + 0x000fc450, 0x2c010000);
690 vga_gr_write(0x18, 0);
691 write32(mmio + 0x00042004, 0x02000000);
692 write32(mmio + 0x000fd034, 0x8421ffe0);
693
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200694 /* Setup GTT. */
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100695 for (i = 0; i < 0x2000; i++)
696 {
697 outl((i << 2) | 1, piobase);
698 outl(physbase + (i << 12) + 1, piobase + 4);
699 }
700
701 vga_misc_write(0x67);
702
703 const u8 cr[] = { 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
704 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
705 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
706 0xff
707 };
708 vga_cr_write(0x11, 0);
709
710 for (i = 0; i <= 0x18; i++)
711 vga_cr_write(i, cr[i]);
712
713 power_port(mmio);
714
Arthur Heymans8da22862017-08-06 15:56:30 +0200715 intel_gmbus_read_edid(mmio + PCH_GMBUS0, GMBUS_PORT_PANEL, 0x50,
716 edid_data, sizeof(edid_data));
Vladimir Serbinenko428130e2015-05-19 09:45:22 +0200717 intel_gmbus_stop(mmio + PCH_GMBUS0);
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100718 decode_edid(edid_data,
719 sizeof(edid_data), &edid);
Nicolas Reineckeb142b842015-10-03 17:32:38 +0200720 mode = &edid.mode;
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100721
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200722 /* Disable screen memory to prevent garbage from appearing. */
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100723 vga_sr_write(1, vga_sr_read(1) | 0x20);
724
725 hactive = edid.x_resolution;
726 vactive = edid.y_resolution;
Nicolas Reineckeb142b842015-10-03 17:32:38 +0200727 right_border = mode->hborder;
728 bottom_border = mode->vborder;
729 hpolarity = (mode->phsync == '-');
730 vpolarity = (mode->pvsync == '-');
731 vsync = mode->vspw;
732 hsync = mode->hspw;
733 vblank = mode->vbl;
734 hblank = mode->hbl;
735 hfront_porch = mode->hso;
736 vfront_porch = mode->vso;
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100737
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200738 target_frequency = mode->lvds_dual_channel ? mode->pixel_clock
Nicolas Reineckeb142b842015-10-03 17:32:38 +0200739 : (2 * mode->pixel_clock);
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100740 vga_textmode_init();
Nico Huber6d8266b2017-05-20 16:46:01 +0200741
742 if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) {
743 vga_sr_write(1, 1);
744 vga_sr_write(0x2, 0xf);
745 vga_sr_write(0x3, 0x0);
746 vga_sr_write(0x4, 0xe);
747 vga_gr_write(0, 0x0);
748 vga_gr_write(1, 0x0);
749 vga_gr_write(2, 0x0);
750 vga_gr_write(3, 0x0);
751 vga_gr_write(4, 0x0);
752 vga_gr_write(5, 0x0);
753 vga_gr_write(6, 0x5);
754 vga_gr_write(7, 0xf);
755 vga_gr_write(0x10, 0x1);
756 vga_gr_write(0x11, 0);
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100757
758
Nico Huber6d8266b2017-05-20 16:46:01 +0200759 edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63;
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100760
Nico Huber6d8266b2017-05-20 16:46:01 +0200761 write32(mmio + DSPCNTR(0), DISPPLANE_BGRX888);
762 write32(mmio + DSPADDR(0), 0);
763 write32(mmio + DSPSTRIDE(0), edid.bytes_per_line);
764 write32(mmio + DSPSURF(0), 0);
765 for (i = 0; i < 0x100; i++)
766 write32(mmio + LGC_PALETTE(0) + 4 * i, i * 0x010101);
767 }
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100768
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200769 /* Find suitable divisors. */
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100770 for (candp1 = 1; candp1 <= 8; candp1++) {
771 for (candn = 5; candn <= 10; candn++) {
772 u32 cur_frequency;
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200773 u32 m; /* 77 - 131. */
774 u32 denom; /* 35 - 560. */
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100775 u32 current_delta;
776
777 denom = candn * candp1 * 7;
Martin Roth128c1042016-11-18 09:29:03 -0700778 /* Doesn't overflow for up to
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200779 5000000 kHz = 5 GHz. */
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100780 m = (target_frequency * denom + 60000) / 120000;
781
782 if (m < 77 || m > 131)
783 continue;
784
785 cur_frequency = (120000 * m) / denom;
786 if (target_frequency > cur_frequency)
787 current_delta = target_frequency - cur_frequency;
788 else
789 current_delta = cur_frequency - target_frequency;
790
791
792 if (best_delta > current_delta) {
793 best_delta = current_delta;
794 pixel_n = candn;
795 pixel_p1 = candp1;
796 pixel_m2 = ((m + 3) % 5) + 7;
797 pixel_m1 = (m - pixel_m2) / 5;
798 }
799 }
800 }
801
802 if (best_delta == 0xffffffff) {
803 printk (BIOS_ERR, "Couldn't find GFX clock divisors\n");
804 return;
805 }
806
Nicolas Reineckeb142b842015-10-03 17:32:38 +0200807 link_m1 = ((uint64_t)link_n1 * mode->pixel_clock) / link_frequency;
808 data_m1 = ((uint64_t)data_n1 * 18 * mode->pixel_clock)
Vladimir Serbinenkoc48f5ef2015-10-11 02:05:55 +0200809 / (link_frequency * 8 * 4);
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100810
811 printk(BIOS_INFO, "bringing up panel at resolution %d x %d\n",
812 hactive, vactive);
813 printk(BIOS_DEBUG, "Borders %d x %d\n",
814 right_border, bottom_border);
815 printk(BIOS_DEBUG, "Blank %d x %d\n",
816 hblank, vblank);
817 printk(BIOS_DEBUG, "Sync %d x %d\n",
818 hsync, vsync);
819 printk(BIOS_DEBUG, "Front porch %d x %d\n",
820 hfront_porch, vfront_porch);
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200821 printk(BIOS_DEBUG, (info->gfx.use_spread_spectrum_clock
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100822 ? "Spread spectrum clock\n" : "DREF clock\n"));
823 printk(BIOS_DEBUG,
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200824 mode->lvds_dual_channel ? "Dual channel\n" : "Single channel\n");
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100825 printk(BIOS_DEBUG, "Polarities %d, %d\n",
826 hpolarity, vpolarity);
827 printk(BIOS_DEBUG, "Data M1=%d, N1=%d\n",
828 data_m1, data_n1);
829 printk(BIOS_DEBUG, "Link frequency %d kHz\n",
830 link_frequency);
831 printk(BIOS_DEBUG, "Link M1=%d, N1=%d\n",
832 link_m1, link_n1);
833 printk(BIOS_DEBUG, "Pixel N=%d, M1=%d, M2=%d, P1=%d\n",
834 pixel_n, pixel_m1, pixel_m2, pixel_p1);
835 printk(BIOS_DEBUG, "Pixel clock %d kHz\n",
836 120000 * (5 * pixel_m1 + pixel_m2) / pixel_n
837 / (pixel_p1 * 7));
838
839 write32(mmio + PCH_LVDS,
840 (hpolarity << 20) | (vpolarity << 21)
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200841 | (mode->lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100842 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
843 | LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL
844 | LVDS_DETECTED);
845 write32(mmio + BLC_PWM_CPU_CTL2, (1 << 31));
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200846 write32(mmio + PCH_DREF_CONTROL, (info->gfx.use_spread_spectrum_clock
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100847 ? 0x1002 : 0x400));
848 mdelay(1);
849 write32(mmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS
850 | (read32(mmio + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK));
851 write32(mmio + _PCH_FP0(0),
852 ((pixel_n - 2) << 16)
853 | ((pixel_m1 - 2) << 8) | pixel_m2);
854 write32(mmio + _PCH_DPLL(0),
855 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200856 | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100857 : DPLLB_LVDS_P2_CLOCK_DIV_14)
858 | (0x10000 << (pixel_p1 - 1))
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200859 | ((info->gfx.use_spread_spectrum_clock ? 3 : 0) << 13)
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100860 | (0x1 << (pixel_p1 - 1)));
861 mdelay(1);
862 write32(mmio + _PCH_DPLL(0),
863 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200864 | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100865 : DPLLB_LVDS_P2_CLOCK_DIV_14)
866 | (0x10000 << (pixel_p1 - 1))
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200867 | ((info->gfx.use_spread_spectrum_clock ? 3 : 0) << 13)
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100868 | (0x1 << (pixel_p1 - 1)));
869 /* Re-lock the registers. */
870 write32(mmio + PCH_PP_CONTROL,
871 (read32(mmio + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK));
872
873 write32(mmio + PCH_LVDS,
874 (hpolarity << 20) | (vpolarity << 21)
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200875 | (mode->lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100876 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
877 | LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL
878 | LVDS_DETECTED);
879
880 write32(mmio + HTOTAL(0),
881 ((hactive + right_border + hblank - 1) << 16)
882 | (hactive - 1));
883 write32(mmio + HBLANK(0),
884 ((hactive + right_border + hblank - 1) << 16)
885 | (hactive + right_border - 1));
886 write32(mmio + HSYNC(0),
887 ((hactive + right_border + hfront_porch + hsync - 1) << 16)
888 | (hactive + right_border + hfront_porch - 1));
889
890 write32(mmio + VTOTAL(0), ((vactive + bottom_border + vblank - 1) << 16)
891 | (vactive - 1));
892 write32(mmio + VBLANK(0), ((vactive + bottom_border + vblank - 1) << 16)
893 | (vactive + bottom_border - 1));
894 write32(mmio + VSYNC(0),
895 (vactive + bottom_border + vfront_porch + vsync - 1)
896 | (vactive + bottom_border + vfront_porch - 1));
897
898 write32(mmio + PIPECONF(0), PIPECONF_DISABLE);
899
900 write32(mmio + PF_WIN_POS(0), 0);
Nico Huber6d8266b2017-05-20 16:46:01 +0200901 if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) {
902 write32(mmio + PIPESRC(0), (hactive - 1) << 16 | (vactive - 1));
903 write32(mmio + PF_CTL(0), 0);
904 write32(mmio + PF_WIN_SZ(0), 0);
905 } else {
906 write32(mmio + PIPESRC(0), (639 << 16) | 399);
907 write32(mmio + PF_CTL(0), PF_ENABLE | PF_FILTER_MED_3x3);
908 write32(mmio + PF_WIN_SZ(0), vactive | (hactive << 16));
909 }
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100910
911 mdelay(1);
912
913 write32(mmio + PIPE_DATA_M1(0), 0x7e000000 | data_m1);
914 write32(mmio + PIPE_DATA_N1(0), data_n1);
915 write32(mmio + PIPE_LINK_M1(0), link_m1);
916 write32(mmio + PIPE_LINK_N1(0), link_n1);
917
918 write32(mmio + 0x000f000c, 0x00002040);
919 mdelay(1);
920 write32(mmio + 0x000f000c, 0x00002050);
921 write32(mmio + 0x00060100, 0x00044000);
922 mdelay(1);
923 write32(mmio + PIPECONF(0), PIPECONF_BPP_6);
924 write32(mmio + 0x000f0008, 0x00000040);
925 write32(mmio + 0x000f000c, 0x00022050);
926 write32(mmio + PIPECONF(0), PIPECONF_BPP_6 | PIPECONF_DITHER_EN);
927 write32(mmio + PIPECONF(0), PIPECONF_ENABLE | PIPECONF_BPP_6 | PIPECONF_DITHER_EN);
928
Nico Huber6d8266b2017-05-20 16:46:01 +0200929 if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER))
930 write32(mmio + CPU_VGACNTRL, 0x20298e | VGA_DISP_DISABLE);
931 else
932 write32(mmio + CPU_VGACNTRL, 0x20298e);
933
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100934 train_link(mmio);
935
Nico Huber6d8266b2017-05-20 16:46:01 +0200936 if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) {
937 write32(mmio + DSPCNTR(0),
938 DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888);
939 mdelay(1);
940 }
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100941
942 write32(mmio + TRANS_HTOTAL(0),
943 ((hactive + right_border + hblank - 1) << 16)
944 | (hactive - 1));
945 write32(mmio + TRANS_HBLANK(0),
946 ((hactive + right_border + hblank - 1) << 16)
947 | (hactive + right_border - 1));
948 write32(mmio + TRANS_HSYNC(0),
949 ((hactive + right_border + hfront_porch + hsync - 1) << 16)
950 | (hactive + right_border + hfront_porch - 1));
951
952 write32(mmio + TRANS_VTOTAL(0),
953 ((vactive + bottom_border + vblank - 1) << 16)
954 | (vactive - 1));
955 write32(mmio + TRANS_VBLANK(0),
956 ((vactive + bottom_border + vblank - 1) << 16)
957 | (vactive + bottom_border - 1));
958 write32(mmio + TRANS_VSYNC(0),
959 (vactive + bottom_border + vfront_porch + vsync - 1)
960 | (vactive + bottom_border + vfront_porch - 1));
961
962 write32(mmio + 0x00060100, 0xb01c4000);
963 write32(mmio + 0x000f000c, 0xb01a2050);
964 mdelay(1);
Nico Huber6d8266b2017-05-20 16:46:01 +0200965 write32(mmio + TRANSCONF(0), TRANS_ENABLE | TRANS_6BPC |
966 (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER) ? TRANS_STATE_MASK : 0));
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100967 write32(mmio + PCH_LVDS,
968 LVDS_PORT_ENABLE
969 | (hpolarity << 20) | (vpolarity << 21)
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200970 | (mode->lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100971 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
972 | LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL
973 | LVDS_DETECTED);
974
975 write32(mmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
976 write32(mmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET);
977 mdelay(1);
978 write32(mmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS
979 | PANEL_POWER_ON | PANEL_POWER_RESET);
980
981 printk (BIOS_DEBUG, "waiting for panel powerup\n");
982 while (1) {
983 u32 reg32;
984 reg32 = read32(mmio + PCH_PP_STATUS);
985 if (((reg32 >> 28) & 3) == 0)
986 break;
987 }
988 printk (BIOS_DEBUG, "panel powered up\n");
989
990 write32(mmio + PCH_PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET);
991
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200992 /* Enable screen memory. */
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100993 vga_sr_write(1, vga_sr_read(1) & ~0x20);
994
995 /* Clear interrupts. */
996 write32(mmio + DEIIR, 0xffffffff);
997 write32(mmio + SDEIIR, 0xffffffff);
998
Vladimir Serbinenko428130e2015-05-19 09:45:22 +0200999 /* Doesn't change any hw behaviour but vga oprom expects it there. */
1000 write32(mmio + 0x0004f040, 0x01000008);
1001 write32(mmio + 0x0004f04c, 0x7f7f0000);
1002 write32(mmio + 0x0004f054, 0x0000020d);
1003
Nico Huber6d8266b2017-05-20 16:46:01 +02001004 if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) {
1005 memset((void *)lfb, 0,
1006 edid.x_resolution * edid.y_resolution * 4);
1007 set_vbe_mode_info_valid(&edid, lfb);
1008 }
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001009}
1010
Patrick Rudolph64a702f2017-06-20 18:28:56 +02001011/* Enable SCI to ACPI _GPE._L06 */
1012static void gma_enable_swsci(void)
1013{
1014 u16 reg16;
1015
1016 /* clear DMISCI status */
1017 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
1018 reg16 &= DMISCI_STS;
1019 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
1020
1021 /* clear acpi tco status */
1022 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
1023
1024 /* enable acpi tco scis */
1025 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
1026 reg16 |= TCOSCI_EN;
1027 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
1028}
1029
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001030static void gma_func0_init(struct device *dev)
1031{
1032 u32 reg32;
1033
1034 /* IGD needs to be Bus Master */
1035 reg32 = pci_read_config32(dev, PCI_COMMAND);
1036 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
1037 pci_write_config32(dev, PCI_COMMAND, reg32);
1038
1039 /* Init graphics power management */
1040 gma_pm_init_pre_vbios(dev);
1041
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001042 if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT) ||
1043 IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) {
1044 u32 physbase;
1045 struct northbridge_intel_nehalem_config *conf = dev->chip_info;
1046 struct resource *lfb_res;
1047 struct resource *pio_res;
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001048
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001049 lfb_res = find_resource(dev, PCI_BASE_ADDRESS_2);
1050 pio_res = find_resource(dev, PCI_BASE_ADDRESS_4);
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001051
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001052 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001053
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001054 if (gtt_res && gtt_res->base && physbase &&
1055 pio_res && pio_res->base && lfb_res && lfb_res->base) {
1056 printk(BIOS_SPEW,
1057 "Initializing VGA without OPROM. MMIO 0x%llx\n",
1058 gtt_res->base);
1059 if (IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) {
1060 int lightup_ok;
Nico Huber504d1ef2017-07-16 16:40:41 +02001061 gma_gfxinit(&lightup_ok);
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001062 } else {
1063 intel_gma_init(conf, res2mmio(gtt_res, 0, 0),
1064 physbase, pio_res->base, lfb_res->base);
1065 }
Nico Huber88c64872016-10-05 18:02:01 +02001066 }
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001067
1068 /* Linux relies on VBT for panel info. */
1069 generate_fake_intel_oprom(&conf->gfx, dev,
1070 "$VBT IRONLAKE-MOBILE");
1071 } else {
1072 /* PCI Init, will run VBIOS */
1073 pci_dev_init(dev);
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001074 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001075
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001076 /* Post VBIOS init */
1077 gma_pm_init_post_vbios(dev);
Patrick Rudolph64a702f2017-06-20 18:28:56 +02001078
1079 gma_enable_swsci();
1080 intel_gma_restore_opregion();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001081}
1082
1083static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
1084{
1085 if (!vendor || !device) {
1086 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
1087 pci_read_config32(dev, PCI_VENDOR_ID));
1088 } else {
1089 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
1090 ((device & 0xffff) << 16) | (vendor &
1091 0xffff));
1092 }
1093}
1094
1095static void gma_read_resources(struct device *dev)
1096{
1097 pci_dev_read_resources(dev);
1098
1099 struct resource *res;
1100
1101 /* Set the graphics memory to write combining. */
1102 res = find_resource(dev, PCI_BASE_ADDRESS_2);
1103 if (res == NULL) {
1104 printk(BIOS_DEBUG, "gma: memory resource not found.\n");
1105 return;
1106 }
1107 res->flags |= IORESOURCE_RESERVE | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
Elyes HAOUAScf5430f2016-09-13 21:27:22 +02001108 pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001);
1109 pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4, 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001110 res->base = (resource_t) 0xd0000000;
1111 res->size = (resource_t) 0x10000000;
1112}
1113
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +01001114const struct i915_gpu_controller_info *
1115intel_gma_get_controller_info(void)
1116{
1117 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
1118 if (!dev) {
1119 return NULL;
1120 }
1121 struct northbridge_intel_nehalem_config *chip = dev->chip_info;
1122 return &chip->gfx;
1123}
1124
Alexander Couzens5eea4582015-04-12 22:18:55 +02001125static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +01001126{
1127 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
1128 if (!gfx) {
1129 return;
1130 }
1131
1132 drivers_intel_gma_displays_ssdt_generate(gfx);
1133}
1134
Patrick Rudolph2be28402017-04-12 16:54:55 +02001135static unsigned long
1136gma_write_acpi_tables(struct device *const dev,
1137 unsigned long current,
1138 struct acpi_rsdp *const rsdp)
1139{
Patrick Rudolph5c820262017-05-17 19:39:12 +02001140 igd_opregion_t *opregion = (igd_opregion_t *)current;
Patrick Rudolph2be28402017-04-12 16:54:55 +02001141 global_nvs_t *gnvs;
1142
Matt DeVillierebe08e02017-07-14 13:28:42 -05001143 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolph5c820262017-05-17 19:39:12 +02001144 return current;
1145
1146 current += sizeof(igd_opregion_t);
1147
1148 /* GNVS has been already set up */
1149 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
1150 if (gnvs) {
1151 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +02001152 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Patrick Rudolph5c820262017-05-17 19:39:12 +02001153 } else {
1154 printk(BIOS_ERR, "Error: GNVS table not found.\n");
Patrick Rudolph2be28402017-04-12 16:54:55 +02001155 }
1156
Patrick Rudolph5c820262017-05-17 19:39:12 +02001157 current = acpi_align_current(current);
Patrick Rudolph2be28402017-04-12 16:54:55 +02001158 return current;
1159}
1160
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001161static struct pci_operations gma_pci_ops = {
1162 .set_subsystem = gma_set_subsystem,
1163};
1164
1165static struct device_operations gma_func0_ops = {
1166 .read_resources = gma_read_resources,
1167 .set_resources = pci_dev_set_resources,
1168 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +01001169 .acpi_fill_ssdt_generator = gma_ssdt,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001170 .init = gma_func0_init,
1171 .scan_bus = 0,
1172 .enable = 0,
1173 .ops_pci = &gma_pci_ops,
Patrick Rudolph2be28402017-04-12 16:54:55 +02001174 .write_acpi_tables = gma_write_acpi_tables,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001175};
1176
Elyes HAOUAScf5430f2016-09-13 21:27:22 +02001177static const unsigned short pci_device_ids[] = {
1178 0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001179 0x0116, 0x0122, 0x0126, 0x0156,
1180 0x0166,
1181 0
1182};
1183
1184static const struct pci_driver gma __pci_driver = {
1185 .ops = &gma_func0_ops,
1186 .vendor = PCI_VENDOR_ID_INTEL,
1187 .devices = pci_device_ids,
1188};