blob: 0607f34fb17fe447952da066a113d3effdd428d9 [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>
Vladimir Serbinenko13157302014-02-19 22:18:08 +010030#include <pc80/vga.h>
31#include <pc80/vga_io.h>
Patrick Rudolph2be28402017-04-12 16:54:55 +020032#include <southbridge/intel/ibexpeak/nvs.h>
Patrick Rudolph5c820262017-05-17 19:39:12 +020033#include <northbridge/intel/common/gma_opregion.h>
Patrick Rudolph2be28402017-04-12 16:54:55 +020034#include <cbmem.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010035
36#include "chip.h"
37#include "nehalem.h"
38
39struct gt_powermeter {
40 u16 reg;
41 u32 value;
42};
43
44static const struct gt_powermeter snb_pm_gt1[] = {
45 {0xa200, 0xcc000000},
46 {0xa204, 0x07000040},
47 {0xa208, 0x0000fe00},
48 {0xa20c, 0x00000000},
49 {0xa210, 0x17000000},
50 {0xa214, 0x00000021},
51 {0xa218, 0x0817fe19},
52 {0xa21c, 0x00000000},
53 {0xa220, 0x00000000},
54 {0xa224, 0xcc000000},
55 {0xa228, 0x07000040},
56 {0xa22c, 0x0000fe00},
57 {0xa230, 0x00000000},
58 {0xa234, 0x17000000},
59 {0xa238, 0x00000021},
60 {0xa23c, 0x0817fe19},
61 {0xa240, 0x00000000},
62 {0xa244, 0x00000000},
63 {0xa248, 0x8000421e},
64 {0}
65};
66
67static const struct gt_powermeter snb_pm_gt2[] = {
68 {0xa200, 0x330000a6},
69 {0xa204, 0x402d0031},
70 {0xa208, 0x00165f83},
71 {0xa20c, 0xf1000000},
72 {0xa210, 0x00000000},
73 {0xa214, 0x00160016},
74 {0xa218, 0x002a002b},
75 {0xa21c, 0x00000000},
76 {0xa220, 0x00000000},
77 {0xa224, 0x330000a6},
78 {0xa228, 0x402d0031},
79 {0xa22c, 0x00165f83},
80 {0xa230, 0xf1000000},
81 {0xa234, 0x00000000},
82 {0xa238, 0x00160016},
83 {0xa23c, 0x002a002b},
84 {0xa240, 0x00000000},
85 {0xa244, 0x00000000},
86 {0xa248, 0x8000421e},
87 {0}
88};
89
90static const struct gt_powermeter ivb_pm_gt1[] = {
91 {0xa800, 0x00000000},
92 {0xa804, 0x00021c00},
93 {0xa808, 0x00000403},
94 {0xa80c, 0x02001700},
95 {0xa810, 0x05000200},
96 {0xa814, 0x00000000},
97 {0xa818, 0x00690500},
98 {0xa81c, 0x0000007f},
99 {0xa820, 0x01002501},
100 {0xa824, 0x00000300},
101 {0xa828, 0x01000331},
102 {0xa82c, 0x0000000c},
103 {0xa830, 0x00010016},
104 {0xa834, 0x01100101},
105 {0xa838, 0x00010103},
106 {0xa83c, 0x00041300},
107 {0xa840, 0x00000b30},
108 {0xa844, 0x00000000},
109 {0xa848, 0x7f000000},
110 {0xa84c, 0x05000008},
111 {0xa850, 0x00000001},
112 {0xa854, 0x00000004},
113 {0xa858, 0x00000007},
114 {0xa85c, 0x00000000},
115 {0xa860, 0x00010000},
116 {0xa248, 0x0000221e},
117 {0xa900, 0x00000000},
118 {0xa904, 0x00001c00},
119 {0xa908, 0x00000000},
120 {0xa90c, 0x06000000},
121 {0xa910, 0x09000200},
122 {0xa914, 0x00000000},
123 {0xa918, 0x00590000},
124 {0xa91c, 0x00000000},
125 {0xa920, 0x04002501},
126 {0xa924, 0x00000100},
127 {0xa928, 0x03000410},
128 {0xa92c, 0x00000000},
129 {0xa930, 0x00020000},
130 {0xa934, 0x02070106},
131 {0xa938, 0x00010100},
132 {0xa93c, 0x00401c00},
133 {0xa940, 0x00000000},
134 {0xa944, 0x00000000},
135 {0xa948, 0x10000e00},
136 {0xa94c, 0x02000004},
137 {0xa950, 0x00000001},
138 {0xa954, 0x00000004},
139 {0xa960, 0x00060000},
140 {0xaa3c, 0x00001c00},
141 {0xaa54, 0x00000004},
142 {0xaa60, 0x00060000},
143 {0}
144};
145
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100146static const struct gt_powermeter ivb_pm_gt2_17w[] = {
147 {0xa800, 0x20000000},
148 {0xa804, 0x000e3800},
149 {0xa808, 0x00000806},
150 {0xa80c, 0x0c002f00},
151 {0xa810, 0x0c000800},
152 {0xa814, 0x00000000},
153 {0xa818, 0x00d20d00},
154 {0xa81c, 0x000000ff},
155 {0xa820, 0x03004b02},
156 {0xa824, 0x00000600},
157 {0xa828, 0x07000773},
158 {0xa82c, 0x00000000},
159 {0xa830, 0x00020032},
160 {0xa834, 0x1520040d},
161 {0xa838, 0x00020105},
162 {0xa83c, 0x00083700},
163 {0xa840, 0x000016ff},
164 {0xa844, 0x00000000},
165 {0xa848, 0xff000000},
166 {0xa84c, 0x0a000010},
167 {0xa850, 0x00000002},
168 {0xa854, 0x00000008},
169 {0xa858, 0x0000000f},
170 {0xa85c, 0x00000000},
171 {0xa860, 0x00020000},
172 {0xa248, 0x0000221e},
173 {0xa900, 0x00000000},
174 {0xa904, 0x00003800},
175 {0xa908, 0x00000000},
176 {0xa90c, 0x0c000000},
177 {0xa910, 0x12000800},
178 {0xa914, 0x00000000},
179 {0xa918, 0x00b20000},
180 {0xa91c, 0x00000000},
181 {0xa920, 0x08004b02},
182 {0xa924, 0x00000300},
183 {0xa928, 0x01000820},
184 {0xa92c, 0x00000000},
185 {0xa930, 0x00030000},
186 {0xa934, 0x15150406},
187 {0xa938, 0x00020300},
188 {0xa93c, 0x00903900},
189 {0xa940, 0x00000000},
190 {0xa944, 0x00000000},
191 {0xa948, 0x20001b00},
192 {0xa94c, 0x0a000010},
193 {0xa950, 0x00000000},
194 {0xa954, 0x00000008},
195 {0xa960, 0x00110000},
196 {0xaa3c, 0x00003900},
197 {0xaa54, 0x00000008},
198 {0xaa60, 0x00110000},
199 {0}
200};
201
202static const struct gt_powermeter ivb_pm_gt2_35w[] = {
203 {0xa800, 0x00000000},
204 {0xa804, 0x00030400},
205 {0xa808, 0x00000806},
206 {0xa80c, 0x0c002f00},
207 {0xa810, 0x0c000300},
208 {0xa814, 0x00000000},
209 {0xa818, 0x00d20d00},
210 {0xa81c, 0x000000ff},
211 {0xa820, 0x03004b02},
212 {0xa824, 0x00000600},
213 {0xa828, 0x07000773},
214 {0xa82c, 0x00000000},
215 {0xa830, 0x00020032},
216 {0xa834, 0x1520040d},
217 {0xa838, 0x00020105},
218 {0xa83c, 0x00083700},
219 {0xa840, 0x000016ff},
220 {0xa844, 0x00000000},
221 {0xa848, 0xff000000},
222 {0xa84c, 0x0a000010},
223 {0xa850, 0x00000001},
224 {0xa854, 0x00000008},
225 {0xa858, 0x00000008},
226 {0xa85c, 0x00000000},
227 {0xa860, 0x00020000},
228 {0xa248, 0x0000221e},
229 {0xa900, 0x00000000},
230 {0xa904, 0x00003800},
231 {0xa908, 0x00000000},
232 {0xa90c, 0x0c000000},
233 {0xa910, 0x12000800},
234 {0xa914, 0x00000000},
235 {0xa918, 0x00b20000},
236 {0xa91c, 0x00000000},
237 {0xa920, 0x08004b02},
238 {0xa924, 0x00000300},
239 {0xa928, 0x01000820},
240 {0xa92c, 0x00000000},
241 {0xa930, 0x00030000},
242 {0xa934, 0x15150406},
243 {0xa938, 0x00020300},
244 {0xa93c, 0x00903900},
245 {0xa940, 0x00000000},
246 {0xa944, 0x00000000},
247 {0xa948, 0x20001b00},
248 {0xa94c, 0x0a000010},
249 {0xa950, 0x00000000},
250 {0xa954, 0x00000008},
251 {0xa960, 0x00110000},
252 {0xaa3c, 0x00003900},
253 {0xaa54, 0x00000008},
254 {0xaa60, 0x00110000},
255 {0}
256};
257
258/* some vga option roms are used for several chipsets but they only have one
259 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -0700260 * the mapping ourselves
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100261 */
262
263u32 map_oprom_vendev(u32 vendev)
264{
265 u32 new_vendev = vendev;
266
Martin Roth128c1042016-11-18 09:29:03 -0700267 /* none currently. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100268
269 return new_vendev;
270}
271
272static struct resource *gtt_res = NULL;
273
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700274u32 gtt_read(u32 reg)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100275{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800276 return read32(res2mmio(gtt_res, reg, 0));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100277}
278
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700279void gtt_write(u32 reg, u32 data)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100280{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800281 write32(res2mmio(gtt_res, reg, 0), data);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100282}
283
284static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
285{
286 for (; pm && pm->reg; pm++)
287 gtt_write(pm->reg, pm->value);
288}
289
290#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700291int gtt_poll(u32 reg, u32 mask, u32 value)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100292{
293 unsigned try = GTT_RETRY;
294 u32 data;
295
296 while (try--) {
297 data = gtt_read(reg);
298 if ((data & mask) == value)
299 return 1;
300 udelay(10);
301 }
302
303 printk(BIOS_ERR, "GT init timeout\n");
304 return 0;
305}
306
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200307uintptr_t gma_get_gnvs_aslb(const void *gnvs)
308{
309 const global_nvs_t *gnvs_ptr = gnvs;
310 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
311}
312
313void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
314{
315 global_nvs_t *gnvs_ptr = gnvs;
316 if (gnvs_ptr)
317 gnvs_ptr->aslb = aslb;
318}
319
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100320static void gma_pm_init_pre_vbios(struct device *dev)
321{
322 u32 reg32;
323
324 printk(BIOS_DEBUG, "GT Power Management Init\n");
325
326 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
327 if (!gtt_res || !gtt_res->base)
328 return;
329
330 if (bridge_silicon_revision() < IVB_STEP_C0) {
331 /* 1: Enable force wake */
332 gtt_write(0xa18c, 0x00000001);
333 gtt_poll(0x130090, (1 << 0), (1 << 0));
334 } else {
335 gtt_write(0xa180, 1 << 5);
336 gtt_write(0xa188, 0xffff0001);
337 gtt_poll(0x130040, (1 << 0), (1 << 0));
338 }
339
340 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
341 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
342 reg32 = gtt_read(0x42004);
343 reg32 |= (1 << 14) | (1 << 15);
344 gtt_write(0x42004, reg32);
345 }
346
347 if (bridge_silicon_revision() >= IVB_STEP_A0) {
348 /* Display Reset Acknowledge Settings */
349 reg32 = gtt_read(0x45010);
350 reg32 |= (1 << 1) | (1 << 0);
351 gtt_write(0x45010, reg32);
352 }
353
354 /* 2: Get GT SKU from GTT+0x911c[13] */
355 reg32 = gtt_read(0x911c);
356 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
357 if (reg32 & (1 << 13)) {
358 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
359 gtt_write_powermeter(snb_pm_gt1);
360 } else {
361 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
362 gtt_write_powermeter(snb_pm_gt2);
363 }
364 } else {
365 u32 unit = MCHBAR32(0x5938) & 0xf;
366
367 if (reg32 & (1 << 13)) {
368 /* GT1 SKU */
369 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
370 gtt_write_powermeter(ivb_pm_gt1);
371 } else {
372 /* GT2 SKU */
373 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
374 tdp /= (1 << unit);
375
376 if (tdp <= 17) {
377 /* <=17W ULV */
378 printk(BIOS_DEBUG, "IVB GT2 17W "
379 "Power Meter Weights\n");
380 gtt_write_powermeter(ivb_pm_gt2_17w);
381 } else if ((tdp >= 25) && (tdp <= 35)) {
382 /* 25W-35W */
383 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
384 "Power Meter Weights\n");
385 gtt_write_powermeter(ivb_pm_gt2_35w);
386 } else {
387 /* All others */
388 printk(BIOS_DEBUG, "IVB GT2 35W "
389 "Power Meter Weights\n");
390 gtt_write_powermeter(ivb_pm_gt2_35w);
391 }
392 }
393 }
394
395 /* 3: Gear ratio map */
396 gtt_write(0xa004, 0x00000010);
397
398 /* 4: GFXPAUSE */
399 gtt_write(0xa000, 0x00070020);
400
401 /* 5: Dynamic EU trip control */
402 gtt_write(0xa080, 0x00000004);
403
404 /* 6: ECO bits */
405 reg32 = gtt_read(0xa180);
406 reg32 |= (1 << 26) | (1 << 31);
407 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
408 if (bridge_silicon_revision() >= SNB_STEP_D1)
409 reg32 |= (1 << 20);
410 gtt_write(0xa180, reg32);
411
412 /* 6a: for SnB step D2+ only */
413 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
414 (bridge_silicon_revision() >= SNB_STEP_D2)) {
415 reg32 = gtt_read(0x9400);
416 reg32 |= (1 << 7);
417 gtt_write(0x9400, reg32);
418
419 reg32 = gtt_read(0x941c);
420 reg32 &= 0xf;
421 reg32 |= (1 << 1);
422 gtt_write(0x941c, reg32);
423 gtt_poll(0x941c, (1 << 1), (0 << 1));
424 }
425
426 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
427 reg32 = gtt_read(0x907c);
428 reg32 |= (1 << 16);
429 gtt_write(0x907c, reg32);
430
431 /* 6b: Clocking reset controls */
432 gtt_write(0x9424, 0x00000001);
433 } else {
434 /* 6b: Clocking reset controls */
435 gtt_write(0x9424, 0x00000000);
436 }
437
438 /* 7 */
439 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
440 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
441 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
442 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
443 gtt_write(0x138124, 0x8000000a);
444 gtt_poll(0x138124, (1 << 31), (0 << 31));
445 }
446
447 /* 8 */
448 gtt_write(0xa090, 0x00000000); /* RC Control */
449 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
450 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
451 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
452 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
453 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
454
455 /* 9 */
456 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
457 gtt_write(0x12054, 0x0000000a); /* Video Idle Max Count */
458 gtt_write(0x22054, 0x0000000a); /* Blitter Idle Max Count */
459
460 /* 10 */
461 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
462 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
463 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
464 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
465 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
466
467 /* 11 */
468 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
469 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
470 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
471 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
472 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
473 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
474 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
475
476 /* 11a: Enable Render Standby (RC6) */
477 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
478 /*
479 * IvyBridge should also support DeepRenderStandby.
480 *
481 * Unfortunately it does not work reliably on all SKUs so
482 * disable it here and it can be enabled by the kernel.
483 */
484 gtt_write(0xa090, 0x88040000); /* HW RC Control */
485 } else {
486 gtt_write(0xa090, 0x88040000); /* HW RC Control */
487 }
488
489 /* 12: Normal Frequency Request */
490 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
491 reg32 = MCHBAR32(0x5998);
492 reg32 >>= 16;
493 reg32 &= 0xef;
494 reg32 <<= 25;
495 gtt_write(0xa008, reg32);
496
497 /* 13: RP Control */
498 gtt_write(0xa024, 0x00000592);
499
500 /* 14: Enable PM Interrupts */
501 gtt_write(0x4402c, 0x03000076);
502
503 /* Clear 0x6c024 [8:6] */
504 reg32 = gtt_read(0x6c024);
505 reg32 &= ~0x000001c0;
506 gtt_write(0x6c024, reg32);
507}
508
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100509static void gma_pm_init_post_vbios(struct device *dev)
510{
511 struct northbridge_intel_nehalem_config *conf = dev->chip_info;
512 u32 reg32;
513
514 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
515
516 /* 15: Deassert Force Wake */
517 if (bridge_silicon_revision() < IVB_STEP_C0) {
518 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
519 gtt_poll(0x130090, (1 << 0), (0 << 0));
520 } else {
521 gtt_write(0xa188, 0x1fffe);
522 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
523 gtt_write(0xa188, gtt_read(0xa188) | 1);
524 }
525
526 /* 16: SW RC Control */
527 gtt_write(0xa094, 0x00060000);
528
529 /* Setup Digital Port Hotplug */
530 reg32 = gtt_read(0xc4030);
531 if (!reg32) {
532 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
533 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
534 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
535 gtt_write(0xc4030, reg32);
536 }
537
538 /* Setup Panel Power On Delays */
539 reg32 = gtt_read(0xc7208);
540 if (!reg32) {
541 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
542 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
543 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
544 gtt_write(0xc7208, reg32);
545 }
546
547 /* Setup Panel Power Off Delays */
548 reg32 = gtt_read(0xc720c);
549 if (!reg32) {
550 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
551 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
552 gtt_write(0xc720c, reg32);
553 }
554
555 /* Setup Panel Power Cycle Delay */
556 if (conf->gpu_panel_power_cycle_delay) {
557 reg32 = gtt_read(0xc7210);
558 reg32 &= ~0xff;
559 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
560 gtt_write(0xc7210, reg32);
561 }
562
563 /* Enable Backlight if needed */
564 if (conf->gpu_cpu_backlight) {
565 gtt_write(0x48250, (1 << 31));
566 gtt_write(0x48254, conf->gpu_cpu_backlight);
567 }
568 if (conf->gpu_pch_backlight) {
569 gtt_write(0xc8250, (1 << 31));
570 gtt_write(0xc8254, conf->gpu_pch_backlight);
571 }
572}
573
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100574#if IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)
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 Heymans7141ff32016-10-10 17:49:00 +0200715 intel_gmbus_read_edid(mmio + PCH_GMBUS0, 3, 0x50, edid_data,
716 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
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +02001011#endif
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001012
Patrick Rudolph64a702f2017-06-20 18:28:56 +02001013/* Enable SCI to ACPI _GPE._L06 */
1014static void gma_enable_swsci(void)
1015{
1016 u16 reg16;
1017
1018 /* clear DMISCI status */
1019 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
1020 reg16 &= DMISCI_STS;
1021 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
1022
1023 /* clear acpi tco status */
1024 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
1025
1026 /* enable acpi tco scis */
1027 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
1028 reg16 |= TCOSCI_EN;
1029 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
1030}
1031
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001032static void gma_func0_init(struct device *dev)
1033{
1034 u32 reg32;
1035
1036 /* IGD needs to be Bus Master */
1037 reg32 = pci_read_config32(dev, PCI_COMMAND);
1038 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
1039 pci_write_config32(dev, PCI_COMMAND, reg32);
1040
1041 /* Init graphics power management */
1042 gma_pm_init_pre_vbios(dev);
1043
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001044 if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT) ||
1045 IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) {
1046 u32 physbase;
1047 struct northbridge_intel_nehalem_config *conf = dev->chip_info;
1048 struct resource *lfb_res;
1049 struct resource *pio_res;
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001050
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001051 lfb_res = find_resource(dev, PCI_BASE_ADDRESS_2);
1052 pio_res = find_resource(dev, PCI_BASE_ADDRESS_4);
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001053
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001054 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001055
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001056 if (gtt_res && gtt_res->base && physbase &&
1057 pio_res && pio_res->base && lfb_res && lfb_res->base) {
1058 printk(BIOS_SPEW,
1059 "Initializing VGA without OPROM. MMIO 0x%llx\n",
1060 gtt_res->base);
1061 if (IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) {
1062 int lightup_ok;
1063 gma_gfxinit(gtt_res->base, lfb_res->base,
1064 physbase, &lightup_ok);
1065 } else {
1066 intel_gma_init(conf, res2mmio(gtt_res, 0, 0),
1067 physbase, pio_res->base, lfb_res->base);
1068 }
Nico Huber88c64872016-10-05 18:02:01 +02001069 }
Nico Huberd4ebeaf2017-05-22 13:49:22 +02001070
1071 /* Linux relies on VBT for panel info. */
1072 generate_fake_intel_oprom(&conf->gfx, dev,
1073 "$VBT IRONLAKE-MOBILE");
1074 } else {
1075 /* PCI Init, will run VBIOS */
1076 pci_dev_init(dev);
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001077 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001078
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001079 /* Post VBIOS init */
1080 gma_pm_init_post_vbios(dev);
Patrick Rudolph64a702f2017-06-20 18:28:56 +02001081
1082 gma_enable_swsci();
1083 intel_gma_restore_opregion();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001084}
1085
1086static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
1087{
1088 if (!vendor || !device) {
1089 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
1090 pci_read_config32(dev, PCI_VENDOR_ID));
1091 } else {
1092 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
1093 ((device & 0xffff) << 16) | (vendor &
1094 0xffff));
1095 }
1096}
1097
1098static void gma_read_resources(struct device *dev)
1099{
1100 pci_dev_read_resources(dev);
1101
1102 struct resource *res;
1103
1104 /* Set the graphics memory to write combining. */
1105 res = find_resource(dev, PCI_BASE_ADDRESS_2);
1106 if (res == NULL) {
1107 printk(BIOS_DEBUG, "gma: memory resource not found.\n");
1108 return;
1109 }
1110 res->flags |= IORESOURCE_RESERVE | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
Elyes HAOUAScf5430f2016-09-13 21:27:22 +02001111 pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001);
1112 pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4, 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001113 res->base = (resource_t) 0xd0000000;
1114 res->size = (resource_t) 0x10000000;
1115}
1116
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +01001117const struct i915_gpu_controller_info *
1118intel_gma_get_controller_info(void)
1119{
1120 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
1121 if (!dev) {
1122 return NULL;
1123 }
1124 struct northbridge_intel_nehalem_config *chip = dev->chip_info;
1125 return &chip->gfx;
1126}
1127
Alexander Couzens5eea4582015-04-12 22:18:55 +02001128static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +01001129{
1130 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
1131 if (!gfx) {
1132 return;
1133 }
1134
1135 drivers_intel_gma_displays_ssdt_generate(gfx);
1136}
1137
Patrick Rudolph2be28402017-04-12 16:54:55 +02001138static unsigned long
1139gma_write_acpi_tables(struct device *const dev,
1140 unsigned long current,
1141 struct acpi_rsdp *const rsdp)
1142{
Patrick Rudolph5c820262017-05-17 19:39:12 +02001143 igd_opregion_t *opregion = (igd_opregion_t *)current;
Patrick Rudolph2be28402017-04-12 16:54:55 +02001144 global_nvs_t *gnvs;
1145
Patrick Rudolph5c820262017-05-17 19:39:12 +02001146 if (init_igd_opregion(opregion) != CB_SUCCESS)
1147 return current;
1148
1149 current += sizeof(igd_opregion_t);
1150
1151 /* GNVS has been already set up */
1152 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
1153 if (gnvs) {
1154 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +02001155 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Patrick Rudolph5c820262017-05-17 19:39:12 +02001156 } else {
1157 printk(BIOS_ERR, "Error: GNVS table not found.\n");
Patrick Rudolph2be28402017-04-12 16:54:55 +02001158 }
1159
Patrick Rudolph5c820262017-05-17 19:39:12 +02001160 current = acpi_align_current(current);
Patrick Rudolph2be28402017-04-12 16:54:55 +02001161 return current;
1162}
1163
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001164static struct pci_operations gma_pci_ops = {
1165 .set_subsystem = gma_set_subsystem,
1166};
1167
1168static struct device_operations gma_func0_ops = {
1169 .read_resources = gma_read_resources,
1170 .set_resources = pci_dev_set_resources,
1171 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +01001172 .acpi_fill_ssdt_generator = gma_ssdt,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001173 .init = gma_func0_init,
1174 .scan_bus = 0,
1175 .enable = 0,
1176 .ops_pci = &gma_pci_ops,
Patrick Rudolph2be28402017-04-12 16:54:55 +02001177 .write_acpi_tables = gma_write_acpi_tables,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001178};
1179
Elyes HAOUAScf5430f2016-09-13 21:27:22 +02001180static const unsigned short pci_device_ids[] = {
1181 0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001182 0x0116, 0x0122, 0x0126, 0x0156,
1183 0x0166,
1184 0
1185};
1186
1187static const struct pci_driver gma __pci_driver = {
1188 .ops = &gma_func0_ops,
1189 .vendor = PCI_VENDOR_ID_INTEL,
1190 .devices = pci_device_ids,
1191};