blob: a57bf6bd88b1ddf88bfb8d364f7dbad64850130b [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <arch/io.h>
22#include <console/console.h>
23#include <delay.h>
24#include <device/device.h>
25#include <device/pci.h>
26#include <device/pci_ids.h>
27#include <string.h>
28#include <device/pci_ops.h>
29#include <cpu/x86/msr.h>
30#include <cpu/x86/mtrr.h>
Vladimir Serbinenko13157302014-02-19 22:18:08 +010031#include <drivers/intel/gma/edid.h>
32#include <drivers/intel/gma/i915.h>
33#include <pc80/vga.h>
34#include <pc80/vga_io.h>
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +020035#include <drivers/intel/gma/intel_bios.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
261 * the mapping ourselfes
262 */
263
264u32 map_oprom_vendev(u32 vendev)
265{
266 u32 new_vendev = vendev;
267
268 /* none curently. */
269
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{
277 return read32(gtt_res->base + reg);
278}
279
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700280void gtt_write(u32 reg, u32 data)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100281{
282 write32(gtt_res->base + reg, data);
283}
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
308static void gma_pm_init_pre_vbios(struct device *dev)
309{
310 u32 reg32;
311
312 printk(BIOS_DEBUG, "GT Power Management Init\n");
313
314 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
315 if (!gtt_res || !gtt_res->base)
316 return;
317
318 if (bridge_silicon_revision() < IVB_STEP_C0) {
319 /* 1: Enable force wake */
320 gtt_write(0xa18c, 0x00000001);
321 gtt_poll(0x130090, (1 << 0), (1 << 0));
322 } else {
323 gtt_write(0xa180, 1 << 5);
324 gtt_write(0xa188, 0xffff0001);
325 gtt_poll(0x130040, (1 << 0), (1 << 0));
326 }
327
328 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
329 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
330 reg32 = gtt_read(0x42004);
331 reg32 |= (1 << 14) | (1 << 15);
332 gtt_write(0x42004, reg32);
333 }
334
335 if (bridge_silicon_revision() >= IVB_STEP_A0) {
336 /* Display Reset Acknowledge Settings */
337 reg32 = gtt_read(0x45010);
338 reg32 |= (1 << 1) | (1 << 0);
339 gtt_write(0x45010, reg32);
340 }
341
342 /* 2: Get GT SKU from GTT+0x911c[13] */
343 reg32 = gtt_read(0x911c);
344 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
345 if (reg32 & (1 << 13)) {
346 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
347 gtt_write_powermeter(snb_pm_gt1);
348 } else {
349 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
350 gtt_write_powermeter(snb_pm_gt2);
351 }
352 } else {
353 u32 unit = MCHBAR32(0x5938) & 0xf;
354
355 if (reg32 & (1 << 13)) {
356 /* GT1 SKU */
357 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
358 gtt_write_powermeter(ivb_pm_gt1);
359 } else {
360 /* GT2 SKU */
361 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
362 tdp /= (1 << unit);
363
364 if (tdp <= 17) {
365 /* <=17W ULV */
366 printk(BIOS_DEBUG, "IVB GT2 17W "
367 "Power Meter Weights\n");
368 gtt_write_powermeter(ivb_pm_gt2_17w);
369 } else if ((tdp >= 25) && (tdp <= 35)) {
370 /* 25W-35W */
371 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
372 "Power Meter Weights\n");
373 gtt_write_powermeter(ivb_pm_gt2_35w);
374 } else {
375 /* All others */
376 printk(BIOS_DEBUG, "IVB GT2 35W "
377 "Power Meter Weights\n");
378 gtt_write_powermeter(ivb_pm_gt2_35w);
379 }
380 }
381 }
382
383 /* 3: Gear ratio map */
384 gtt_write(0xa004, 0x00000010);
385
386 /* 4: GFXPAUSE */
387 gtt_write(0xa000, 0x00070020);
388
389 /* 5: Dynamic EU trip control */
390 gtt_write(0xa080, 0x00000004);
391
392 /* 6: ECO bits */
393 reg32 = gtt_read(0xa180);
394 reg32 |= (1 << 26) | (1 << 31);
395 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
396 if (bridge_silicon_revision() >= SNB_STEP_D1)
397 reg32 |= (1 << 20);
398 gtt_write(0xa180, reg32);
399
400 /* 6a: for SnB step D2+ only */
401 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
402 (bridge_silicon_revision() >= SNB_STEP_D2)) {
403 reg32 = gtt_read(0x9400);
404 reg32 |= (1 << 7);
405 gtt_write(0x9400, reg32);
406
407 reg32 = gtt_read(0x941c);
408 reg32 &= 0xf;
409 reg32 |= (1 << 1);
410 gtt_write(0x941c, reg32);
411 gtt_poll(0x941c, (1 << 1), (0 << 1));
412 }
413
414 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
415 reg32 = gtt_read(0x907c);
416 reg32 |= (1 << 16);
417 gtt_write(0x907c, reg32);
418
419 /* 6b: Clocking reset controls */
420 gtt_write(0x9424, 0x00000001);
421 } else {
422 /* 6b: Clocking reset controls */
423 gtt_write(0x9424, 0x00000000);
424 }
425
426 /* 7 */
427 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
428 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
429 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
430 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
431 gtt_write(0x138124, 0x8000000a);
432 gtt_poll(0x138124, (1 << 31), (0 << 31));
433 }
434
435 /* 8 */
436 gtt_write(0xa090, 0x00000000); /* RC Control */
437 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
438 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
439 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
440 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
441 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
442
443 /* 9 */
444 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
445 gtt_write(0x12054, 0x0000000a); /* Video Idle Max Count */
446 gtt_write(0x22054, 0x0000000a); /* Blitter Idle Max Count */
447
448 /* 10 */
449 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
450 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
451 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
452 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
453 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
454
455 /* 11 */
456 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
457 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
458 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
459 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
460 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
461 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
462 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
463
464 /* 11a: Enable Render Standby (RC6) */
465 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
466 /*
467 * IvyBridge should also support DeepRenderStandby.
468 *
469 * Unfortunately it does not work reliably on all SKUs so
470 * disable it here and it can be enabled by the kernel.
471 */
472 gtt_write(0xa090, 0x88040000); /* HW RC Control */
473 } else {
474 gtt_write(0xa090, 0x88040000); /* HW RC Control */
475 }
476
477 /* 12: Normal Frequency Request */
478 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
479 reg32 = MCHBAR32(0x5998);
480 reg32 >>= 16;
481 reg32 &= 0xef;
482 reg32 <<= 25;
483 gtt_write(0xa008, reg32);
484
485 /* 13: RP Control */
486 gtt_write(0xa024, 0x00000592);
487
488 /* 14: Enable PM Interrupts */
489 gtt_write(0x4402c, 0x03000076);
490
491 /* Clear 0x6c024 [8:6] */
492 reg32 = gtt_read(0x6c024);
493 reg32 &= ~0x000001c0;
494 gtt_write(0x6c024, reg32);
495}
496
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100497static void gma_pm_init_post_vbios(struct device *dev)
498{
499 struct northbridge_intel_nehalem_config *conf = dev->chip_info;
500 u32 reg32;
501
502 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
503
504 /* 15: Deassert Force Wake */
505 if (bridge_silicon_revision() < IVB_STEP_C0) {
506 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
507 gtt_poll(0x130090, (1 << 0), (0 << 0));
508 } else {
509 gtt_write(0xa188, 0x1fffe);
510 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
511 gtt_write(0xa188, gtt_read(0xa188) | 1);
512 }
513
514 /* 16: SW RC Control */
515 gtt_write(0xa094, 0x00060000);
516
517 /* Setup Digital Port Hotplug */
518 reg32 = gtt_read(0xc4030);
519 if (!reg32) {
520 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
521 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
522 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
523 gtt_write(0xc4030, reg32);
524 }
525
526 /* Setup Panel Power On Delays */
527 reg32 = gtt_read(0xc7208);
528 if (!reg32) {
529 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
530 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
531 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
532 gtt_write(0xc7208, reg32);
533 }
534
535 /* Setup Panel Power Off Delays */
536 reg32 = gtt_read(0xc720c);
537 if (!reg32) {
538 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
539 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
540 gtt_write(0xc720c, reg32);
541 }
542
543 /* Setup Panel Power Cycle Delay */
544 if (conf->gpu_panel_power_cycle_delay) {
545 reg32 = gtt_read(0xc7210);
546 reg32 &= ~0xff;
547 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
548 gtt_write(0xc7210, reg32);
549 }
550
551 /* Enable Backlight if needed */
552 if (conf->gpu_cpu_backlight) {
553 gtt_write(0x48250, (1 << 31));
554 gtt_write(0x48254, conf->gpu_cpu_backlight);
555 }
556 if (conf->gpu_pch_backlight) {
557 gtt_write(0xc8250, (1 << 31));
558 gtt_write(0xc8254, conf->gpu_pch_backlight);
559 }
560}
561
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100562#if IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)
563
564static void train_link(u32 mmio)
565{
566 /* Clear interrupts. */
567 write32(mmio + DEIIR, 0xffffffff);
568
569 write32(mmio + 0x000f0018, 0x000000ff);
570 write32(mmio + 0x000f1018, 0x000000ff);
571 write32(mmio + 0x000f000c, 0x001a2050);
572 write32(mmio + 0x00060100, 0x001c4000);
573 write32(mmio + 0x00060100, 0x801c4000);
574 write32(mmio + 0x000f000c, 0x801a2050);
575 write32(mmio + 0x00060100, 0x801c4000);
576 write32(mmio + 0x000f000c, 0x801a2050);
577 mdelay(1);
578
579 read32(mmio + 0x000f0014); // = 0x00000100
580 write32(mmio + 0x000f0014, 0x00000100);
581 write32(mmio + 0x00060100, 0x901c4000);
582 write32(mmio + 0x000f000c, 0x901a2050);
583 mdelay(1);
584 read32(mmio + 0x000f0014); // = 0x00000600
585}
586
587static void power_port(u32 mmio)
588{
589 read32(mmio + 0x000e1100); // = 0x00000000
590 write32(mmio + 0x000e1100, 0x00000000);
591 write32(mmio + 0x000e1100, 0x00010000);
592 read32(mmio + 0x000e1100); // = 0x00010000
593 read32(mmio + 0x000e1100); // = 0x00010000
594 read32(mmio + 0x000e1100); // = 0x00000000
595 write32(mmio + 0x000e1100, 0x00000000);
596 read32(mmio + 0x000e1100); // = 0x00000000
597 read32(mmio + 0x000e4200); // = 0x0000001c
598 write32(mmio + 0x000e4210, 0x8004003e);
599 write32(mmio + 0x000e4214, 0x80060002);
600 write32(mmio + 0x000e4218, 0x01000000);
601 read32(mmio + 0x000e4210); // = 0x5144003e
602 write32(mmio + 0x000e4210, 0x5344003e);
603 read32(mmio + 0x000e4210); // = 0x0144003e
604 write32(mmio + 0x000e4210, 0x8074003e);
605 read32(mmio + 0x000e4210); // = 0x5144003e
606 read32(mmio + 0x000e4210); // = 0x5144003e
607 write32(mmio + 0x000e4210, 0x5344003e);
608 read32(mmio + 0x000e4210); // = 0x0144003e
609 write32(mmio + 0x000e4210, 0x8074003e);
610 read32(mmio + 0x000e4210); // = 0x5144003e
611 read32(mmio + 0x000e4210); // = 0x5144003e
612 write32(mmio + 0x000e4210, 0x5344003e);
613 read32(mmio + 0x000e4210); // = 0x0144003e
614 write32(mmio + 0x000e4210, 0x8074003e);
615 read32(mmio + 0x000e4210); // = 0x5144003e
616 read32(mmio + 0x000e4210); // = 0x5144003e
617 write32(mmio + 0x000e4210, 0x5344003e);
618 write32(mmio + 0x000e4f00, 0x0100030c);
619 write32(mmio + 0x000e4f04, 0x00b8230c);
620 write32(mmio + 0x000e4f08, 0x06f8930c);
621 write32(mmio + 0x000e4f0c, 0x09f8e38e);
622 write32(mmio + 0x000e4f10, 0x00b8030c);
623 write32(mmio + 0x000e4f14, 0x0b78830c);
624 write32(mmio + 0x000e4f18, 0x0ff8d3cf);
625 write32(mmio + 0x000e4f1c, 0x01e8030c);
626 write32(mmio + 0x000e4f20, 0x0ff863cf);
627 write32(mmio + 0x000e4f24, 0x0ff803cf);
628 write32(mmio + 0x000c4030, 0x00001000);
629 read32(mmio + 0x000c4000); // = 0x00000000
630 write32(mmio + 0x000c4030, 0x00001000);
631 read32(mmio + 0x000e1150); // = 0x0000001c
632 write32(mmio + 0x000e1150, 0x0000089c);
633 write32(mmio + 0x000fcc00, 0x01986f00);
634 write32(mmio + 0x000fcc0c, 0x01986f00);
635 write32(mmio + 0x000fcc18, 0x01986f00);
636 write32(mmio + 0x000fcc24, 0x01986f00);
637 read32(mmio + 0x000c4000); // = 0x00000000
638 read32(mmio + 0x000e1180); // = 0x40000002
639}
640
641static void intel_gma_init(const struct northbridge_intel_nehalem_config *info,
642 u32 mmio, u32 physbase, u16 piobase, u32 lfb)
643{
644 int i;
645 u8 edid_data[128];
646 struct edid edid;
647 u32 hactive, vactive, right_border, bottom_border;
648 int hpolarity, vpolarity;
649 u32 vsync, hsync, vblank, hblank, hfront_porch, vfront_porch;
650 u32 candp1, candn;
651 u32 best_delta = 0xffffffff;
652 u32 target_frequency;
653 u32 pixel_p1 = 1;
654 u32 pixel_n = 1;
655 u32 pixel_m1 = 1;
656 u32 pixel_m2 = 1;
657 u32 link_frequency = info->gpu_link_frequency_270_mhz ? 270000 : 162000;
658 u32 data_m1;
659 u32 data_n1 = 0x00800000;
660 u32 link_m1;
661 u32 link_n1 = 0x00080000;
662
663 write32(mmio + 0x00070080, 0x00000000);
664 write32(mmio + DSPCNTR(0), 0x00000000);
665 write32(mmio + 0x00071180, 0x00000000);
666 write32(mmio + CPU_VGACNTRL, 0x0000298e | VGA_DISP_DISABLE);
667 write32(mmio + 0x0007019c, 0x00000000);
668 write32(mmio + 0x0007119c, 0x00000000);
669 write32(mmio + 0x000fc008, 0x2c010000);
670 write32(mmio + 0x000fc020, 0x2c010000);
671 write32(mmio + 0x000fc038, 0x2c010000);
672 write32(mmio + 0x000fc050, 0x2c010000);
673 write32(mmio + 0x000fc408, 0x2c010000);
674 write32(mmio + 0x000fc420, 0x2c010000);
675 write32(mmio + 0x000fc438, 0x2c010000);
676 write32(mmio + 0x000fc450, 0x2c010000);
677 vga_gr_write(0x18, 0);
678 write32(mmio + 0x00042004, 0x02000000);
679 write32(mmio + 0x000fd034, 0x8421ffe0);
680
681 /* Setup GTT. */
682 for (i = 0; i < 0x2000; i++)
683 {
684 outl((i << 2) | 1, piobase);
685 outl(physbase + (i << 12) + 1, piobase + 4);
686 }
687
688 vga_misc_write(0x67);
689
690 const u8 cr[] = { 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
691 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
692 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
693 0xff
694 };
695 vga_cr_write(0x11, 0);
696
697 for (i = 0; i <= 0x18; i++)
698 vga_cr_write(i, cr[i]);
699
700 power_port(mmio);
701
702 intel_gmbus_read_edid(mmio + PCH_GMBUS0, 3, 0x50, edid_data, 128);
703 decode_edid(edid_data,
704 sizeof(edid_data), &edid);
705
706 /* Disable screen memory to prevent garbage from appearing. */
707 vga_sr_write(1, vga_sr_read(1) | 0x20);
708
709 hactive = edid.x_resolution;
710 vactive = edid.y_resolution;
711 right_border = edid.hborder;
712 bottom_border = edid.vborder;
713 hpolarity = (edid.phsync == '-');
714 vpolarity = (edid.pvsync == '-');
715 vsync = edid.vspw;
716 hsync = edid.hspw;
717 vblank = edid.vbl;
718 hblank = edid.hbl;
719 hfront_porch = edid.hso;
720 vfront_porch = edid.vso;
721
722 target_frequency = info->gpu_lvds_dual_channel ? edid.pixel_clock
723 : (2 * edid.pixel_clock);
724#if !IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
725 vga_textmode_init();
726#else
727 vga_sr_write(1, 1);
728 vga_sr_write(0x2, 0xf);
729 vga_sr_write(0x3, 0x0);
730 vga_sr_write(0x4, 0xe);
731 vga_gr_write(0, 0x0);
732 vga_gr_write(1, 0x0);
733 vga_gr_write(2, 0x0);
734 vga_gr_write(3, 0x0);
735 vga_gr_write(4, 0x0);
736 vga_gr_write(5, 0x0);
737 vga_gr_write(6, 0x5);
738 vga_gr_write(7, 0xf);
739 vga_gr_write(0x10, 0x1);
740 vga_gr_write(0x11, 0);
741
742
743 edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63;
744
745 write32(mmio + DSPCNTR(0), DISPPLANE_BGRX888);
746 write32(mmio + DSPADDR(0), 0);
747 write32(mmio + DSPSTRIDE(0), edid.bytes_per_line);
748 write32(mmio + DSPSURF(0), 0);
749 for (i = 0; i < 0x100; i++)
750 write32(mmio + LGC_PALETTE(0) + 4 * i, i * 0x010101);
751#endif
752
753 /* Find suitable divisors. */
754 for (candp1 = 1; candp1 <= 8; candp1++) {
755 for (candn = 5; candn <= 10; candn++) {
756 u32 cur_frequency;
757 u32 m; /* 77 - 131. */
758 u32 denom; /* 35 - 560. */
759 u32 current_delta;
760
761 denom = candn * candp1 * 7;
762 /* Doesnt overflow for up to
763 5000000 kHz = 5 GHz. */
764 m = (target_frequency * denom + 60000) / 120000;
765
766 if (m < 77 || m > 131)
767 continue;
768
769 cur_frequency = (120000 * m) / denom;
770 if (target_frequency > cur_frequency)
771 current_delta = target_frequency - cur_frequency;
772 else
773 current_delta = cur_frequency - target_frequency;
774
775
776 if (best_delta > current_delta) {
777 best_delta = current_delta;
778 pixel_n = candn;
779 pixel_p1 = candp1;
780 pixel_m2 = ((m + 3) % 5) + 7;
781 pixel_m1 = (m - pixel_m2) / 5;
782 }
783 }
784 }
785
786 if (best_delta == 0xffffffff) {
787 printk (BIOS_ERR, "Couldn't find GFX clock divisors\n");
788 return;
789 }
790
791 link_m1 = ((uint64_t)link_n1 * edid.pixel_clock) / link_frequency;
792 data_m1 = ((uint64_t)data_n1 * 18 * edid.pixel_clock)
793 / (link_frequency * 8 * (info->gpu_lvds_num_lanes ? : 4));
794
795 printk(BIOS_INFO, "bringing up panel at resolution %d x %d\n",
796 hactive, vactive);
797 printk(BIOS_DEBUG, "Borders %d x %d\n",
798 right_border, bottom_border);
799 printk(BIOS_DEBUG, "Blank %d x %d\n",
800 hblank, vblank);
801 printk(BIOS_DEBUG, "Sync %d x %d\n",
802 hsync, vsync);
803 printk(BIOS_DEBUG, "Front porch %d x %d\n",
804 hfront_porch, vfront_porch);
805 printk(BIOS_DEBUG, (info->gpu_use_spread_spectrum_clock
806 ? "Spread spectrum clock\n" : "DREF clock\n"));
807 printk(BIOS_DEBUG,
808 info->gpu_lvds_dual_channel ? "Dual channel\n" : "Single channel\n");
809 printk(BIOS_DEBUG, "Polarities %d, %d\n",
810 hpolarity, vpolarity);
811 printk(BIOS_DEBUG, "Data M1=%d, N1=%d\n",
812 data_m1, data_n1);
813 printk(BIOS_DEBUG, "Link frequency %d kHz\n",
814 link_frequency);
815 printk(BIOS_DEBUG, "Link M1=%d, N1=%d\n",
816 link_m1, link_n1);
817 printk(BIOS_DEBUG, "Pixel N=%d, M1=%d, M2=%d, P1=%d\n",
818 pixel_n, pixel_m1, pixel_m2, pixel_p1);
819 printk(BIOS_DEBUG, "Pixel clock %d kHz\n",
820 120000 * (5 * pixel_m1 + pixel_m2) / pixel_n
821 / (pixel_p1 * 7));
822
823 write32(mmio + PCH_LVDS,
824 (hpolarity << 20) | (vpolarity << 21)
825 | (info->gpu_lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
826 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
827 | LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL
828 | LVDS_DETECTED);
829 write32(mmio + BLC_PWM_CPU_CTL2, (1 << 31));
830 write32(mmio + PCH_DREF_CONTROL, (info->gpu_use_spread_spectrum_clock
831 ? 0x1002 : 0x400));
832 mdelay(1);
833 write32(mmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS
834 | (read32(mmio + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK));
835 write32(mmio + _PCH_FP0(0),
836 ((pixel_n - 2) << 16)
837 | ((pixel_m1 - 2) << 8) | pixel_m2);
838 write32(mmio + _PCH_DPLL(0),
839 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
840 | (info->gpu_lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
841 : DPLLB_LVDS_P2_CLOCK_DIV_14)
842 | (0x10000 << (pixel_p1 - 1))
843 | ((info->gpu_use_spread_spectrum_clock ? 3 : 0) << 13)
844 | (0x1 << (pixel_p1 - 1)));
845 mdelay(1);
846 write32(mmio + _PCH_DPLL(0),
847 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
848 | (info->gpu_lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
849 : DPLLB_LVDS_P2_CLOCK_DIV_14)
850 | (0x10000 << (pixel_p1 - 1))
851 | ((info->gpu_use_spread_spectrum_clock ? 3 : 0) << 13)
852 | (0x1 << (pixel_p1 - 1)));
853 /* Re-lock the registers. */
854 write32(mmio + PCH_PP_CONTROL,
855 (read32(mmio + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK));
856
857 write32(mmio + PCH_LVDS,
858 (hpolarity << 20) | (vpolarity << 21)
859 | (info->gpu_lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
860 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
861 | LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL
862 | LVDS_DETECTED);
863
864 write32(mmio + HTOTAL(0),
865 ((hactive + right_border + hblank - 1) << 16)
866 | (hactive - 1));
867 write32(mmio + HBLANK(0),
868 ((hactive + right_border + hblank - 1) << 16)
869 | (hactive + right_border - 1));
870 write32(mmio + HSYNC(0),
871 ((hactive + right_border + hfront_porch + hsync - 1) << 16)
872 | (hactive + right_border + hfront_porch - 1));
873
874 write32(mmio + VTOTAL(0), ((vactive + bottom_border + vblank - 1) << 16)
875 | (vactive - 1));
876 write32(mmio + VBLANK(0), ((vactive + bottom_border + vblank - 1) << 16)
877 | (vactive + bottom_border - 1));
878 write32(mmio + VSYNC(0),
879 (vactive + bottom_border + vfront_porch + vsync - 1)
880 | (vactive + bottom_border + vfront_porch - 1));
881
882 write32(mmio + PIPECONF(0), PIPECONF_DISABLE);
883
884 write32(mmio + PF_WIN_POS(0), 0);
885#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
886 write32(mmio + PIPESRC(0), ((hactive - 1) << 16) | (vactive - 1));
887 write32(mmio + PF_CTL(0),0);
888 write32(mmio + PF_WIN_SZ(0), 0);
889#else
890 write32(mmio + PIPESRC(0), (639 << 16) | 399);
891 write32(mmio + PF_CTL(0),PF_ENABLE | PF_FILTER_MED_3x3);
892 write32(mmio + PF_WIN_SZ(0), vactive | (hactive << 16));
893#endif
894
895 mdelay(1);
896
897 write32(mmio + PIPE_DATA_M1(0), 0x7e000000 | data_m1);
898 write32(mmio + PIPE_DATA_N1(0), data_n1);
899 write32(mmio + PIPE_LINK_M1(0), link_m1);
900 write32(mmio + PIPE_LINK_N1(0), link_n1);
901
902 write32(mmio + 0x000f000c, 0x00002040);
903 mdelay(1);
904 write32(mmio + 0x000f000c, 0x00002050);
905 write32(mmio + 0x00060100, 0x00044000);
906 mdelay(1);
907 write32(mmio + PIPECONF(0), PIPECONF_BPP_6);
908 write32(mmio + 0x000f0008, 0x00000040);
909 write32(mmio + 0x000f000c, 0x00022050);
910 write32(mmio + PIPECONF(0), PIPECONF_BPP_6 | PIPECONF_DITHER_EN);
911 write32(mmio + PIPECONF(0), PIPECONF_ENABLE | PIPECONF_BPP_6 | PIPECONF_DITHER_EN);
912
913#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
914 write32(mmio + CPU_VGACNTRL, 0x20298e | VGA_DISP_DISABLE);
915#else
916 write32(mmio + CPU_VGACNTRL, 0x20298e);
917#endif
918 train_link(mmio);
919
920#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
921 write32(mmio + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888);
922 mdelay(1);
923#endif
924
925 write32(mmio + TRANS_HTOTAL(0),
926 ((hactive + right_border + hblank - 1) << 16)
927 | (hactive - 1));
928 write32(mmio + TRANS_HBLANK(0),
929 ((hactive + right_border + hblank - 1) << 16)
930 | (hactive + right_border - 1));
931 write32(mmio + TRANS_HSYNC(0),
932 ((hactive + right_border + hfront_porch + hsync - 1) << 16)
933 | (hactive + right_border + hfront_porch - 1));
934
935 write32(mmio + TRANS_VTOTAL(0),
936 ((vactive + bottom_border + vblank - 1) << 16)
937 | (vactive - 1));
938 write32(mmio + TRANS_VBLANK(0),
939 ((vactive + bottom_border + vblank - 1) << 16)
940 | (vactive + bottom_border - 1));
941 write32(mmio + TRANS_VSYNC(0),
942 (vactive + bottom_border + vfront_porch + vsync - 1)
943 | (vactive + bottom_border + vfront_porch - 1));
944
945 write32(mmio + 0x00060100, 0xb01c4000);
946 write32(mmio + 0x000f000c, 0xb01a2050);
947 mdelay(1);
948 write32(mmio + TRANSCONF(0), TRANS_ENABLE | TRANS_6BPC
949#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
950 | TRANS_STATE_MASK
951#endif
952 );
953 write32(mmio + PCH_LVDS,
954 LVDS_PORT_ENABLE
955 | (hpolarity << 20) | (vpolarity << 21)
956 | (info->gpu_lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
957 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
958 | LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL
959 | LVDS_DETECTED);
960
961 write32(mmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
962 write32(mmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET);
963 mdelay(1);
964 write32(mmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS
965 | PANEL_POWER_ON | PANEL_POWER_RESET);
966
967 printk (BIOS_DEBUG, "waiting for panel powerup\n");
968 while (1) {
969 u32 reg32;
970 reg32 = read32(mmio + PCH_PP_STATUS);
971 if (((reg32 >> 28) & 3) == 0)
972 break;
973 }
974 printk (BIOS_DEBUG, "panel powered up\n");
975
976 write32(mmio + PCH_PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET);
977
978 /* Enable screen memory. */
979 vga_sr_write(1, vga_sr_read(1) & ~0x20);
980
981 /* Clear interrupts. */
982 write32(mmio + DEIIR, 0xffffffff);
983 write32(mmio + SDEIIR, 0xffffffff);
984
985#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
986 memset ((void *) lfb, 0, edid.x_resolution * edid.y_resolution * 4);
987 set_vbe_mode_info_valid(&edid, lfb);
988#endif
989}
990
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +0200991static size_t generate_vbt(const struct northbridge_intel_nehalem_config *conf,
992 void *vbt)
993{
994 struct vbt_header *head = vbt;
995 struct bdb_header *bdb_head;
996 struct bdb_general_features *genfeat;
997 u8 *ptr;
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100998
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +0200999 memset(head, 0, sizeof (*head));
1000
1001 memcpy (head->signature, "$VBT IRONLAKE-MOBILE", 20);
1002 head->version = 100;
1003 head->header_size = sizeof (*head);
1004 head->bdb_offset = sizeof (*head);
1005
1006 bdb_head = (struct bdb_header *) (head + 1);
1007 memset(bdb_head, 0, sizeof (*bdb_head));
1008 memcpy(bdb_head->signature, "BIOS_DATA_BLOCK ", 16);
1009 bdb_head->version = 0xa8;
1010 bdb_head->header_size = sizeof (*bdb_head);
1011
1012 ptr = (u8 *) (bdb_head + 1);
1013
1014 ptr[0] = BDB_GENERAL_FEATURES;
1015 ptr[1] = sizeof (*genfeat);
1016 ptr[2] = sizeof (*genfeat) >> 8;
1017 ptr += 3;
1018
1019 genfeat = (struct bdb_general_features *) ptr;
1020 memset(genfeat, 0, sizeof (*genfeat));
1021 genfeat->panel_fitting = 3;
1022 genfeat->flexaim = 1;
1023 genfeat->download_ext_vbt = 1;
1024 genfeat->enable_ssc = conf->gpu_use_spread_spectrum_clock;
1025 genfeat->ssc_freq = !conf->gpu_link_frequency_270_mhz;
1026 genfeat->rsvd10 = 0x4;
1027 genfeat->legacy_monitor_detect = 1;
1028 genfeat->int_crt_support = 1;
1029 genfeat->dp_ssc_enb = 1;
1030
1031 ptr += sizeof (*genfeat);
1032
1033 bdb_head->bdb_size = ptr - (u8 *)bdb_head;
1034 head->vbt_size = ptr - (u8 *)head;
1035 head->vbt_checksum = 0;
1036 return ptr - (u8 *)head;
1037}
1038#endif
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001039
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001040static void gma_func0_init(struct device *dev)
1041{
1042 u32 reg32;
1043
1044 /* IGD needs to be Bus Master */
1045 reg32 = pci_read_config32(dev, PCI_COMMAND);
1046 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
1047 pci_write_config32(dev, PCI_COMMAND, reg32);
1048
1049 /* Init graphics power management */
1050 gma_pm_init_pre_vbios(dev);
1051
1052#if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
1053 /* PCI Init, will run VBIOS */
1054 pci_dev_init(dev);
1055#else
Vladimir Serbinenko13157302014-02-19 22:18:08 +01001056 u32 physbase;
1057 struct northbridge_intel_nehalem_config *conf = dev->chip_info;
1058 struct resource *lfb_res;
1059 struct resource *pio_res;
1060
1061 lfb_res = find_resource(dev, PCI_BASE_ADDRESS_2);
1062 pio_res = find_resource(dev, PCI_BASE_ADDRESS_4);
1063
1064 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
1065
1066 if (gtt_res && gtt_res->base && physbase && pio_res && pio_res->base
1067 && lfb_res && lfb_res->base) {
1068 printk(BIOS_SPEW, "Initializing VGA without OPROM. MMIO 0x%llx\n",
1069 gtt_res->base);
1070 intel_gma_init(conf, gtt_res->base, physbase, pio_res->base,
1071 lfb_res->base);
1072 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001073
1074 /* Linux relies on VBT for panel info. */
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +02001075 if (read16(PCI_VGA_RAM_IMAGE_START) != OPROM_SIGNATURE) {
1076 optionrom_header_t *oh = (void *)PCI_VGA_RAM_IMAGE_START;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001077 optionrom_pcir_t *pcir;
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +02001078 size_t vbt_size;
1079 size_t fake_oprom_size;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001080
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +02001081 memset(oh, 0, 8192);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001082
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +02001083 oh->signature = OPROM_SIGNATURE;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001084 oh->pcir_offset = 0x40;
1085 oh->vbt_offset = 0x80;
1086
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +02001087 pcir = (void *)(PCI_VGA_RAM_IMAGE_START + 0x40);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001088 pcir->signature = 0x52494350; // PCIR
1089 pcir->vendor = dev->vendor;
1090 pcir->device = dev->device;
1091 pcir->length = sizeof(*pcir);
1092 pcir->revision = dev->class;
1093 pcir->classcode[0] = dev->class >> 8;
1094 pcir->classcode[1] = dev->class >> 16;
1095 pcir->classcode[2] = dev->class >> 24;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001096 pcir->indicator = 0x80;
1097
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +02001098 vbt_size = generate_vbt (conf, (void *)(PCI_VGA_RAM_IMAGE_START + 0x80));
1099 fake_oprom_size = (0x80 + vbt_size + 511) / 512;
1100 oh->size = fake_oprom_size;
1101 pcir->imagelength = fake_oprom_size;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001102 }
Vladimir Serbinenko5aa28f52014-05-31 22:26:42 +02001103#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001104
1105
1106 /* Post VBIOS init */
1107 gma_pm_init_post_vbios(dev);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001108}
1109
1110static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
1111{
1112 if (!vendor || !device) {
1113 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
1114 pci_read_config32(dev, PCI_VENDOR_ID));
1115 } else {
1116 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
1117 ((device & 0xffff) << 16) | (vendor &
1118 0xffff));
1119 }
1120}
1121
1122static void gma_read_resources(struct device *dev)
1123{
1124 pci_dev_read_resources(dev);
1125
1126 struct resource *res;
1127
1128 /* Set the graphics memory to write combining. */
1129 res = find_resource(dev, PCI_BASE_ADDRESS_2);
1130 if (res == NULL) {
1131 printk(BIOS_DEBUG, "gma: memory resource not found.\n");
1132 return;
1133 }
1134 res->flags |= IORESOURCE_RESERVE | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
1135 pci_write_config32(dev, PCI_BASE_ADDRESS_2,
1136 0xd0000001);
1137 pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4,
1138 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001139 res->base = (resource_t) 0xd0000000;
1140 res->size = (resource_t) 0x10000000;
1141}
1142
1143static struct pci_operations gma_pci_ops = {
1144 .set_subsystem = gma_set_subsystem,
1145};
1146
1147static struct device_operations gma_func0_ops = {
1148 .read_resources = gma_read_resources,
1149 .set_resources = pci_dev_set_resources,
1150 .enable_resources = pci_dev_enable_resources,
1151 .init = gma_func0_init,
1152 .scan_bus = 0,
1153 .enable = 0,
1154 .ops_pci = &gma_pci_ops,
1155};
1156
1157static const unsigned short pci_device_ids[] =
1158 { 0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
1159 0x0116, 0x0122, 0x0126, 0x0156,
1160 0x0166,
1161 0
1162};
1163
1164static const struct pci_driver gma __pci_driver = {
1165 .ops = &gma_func0_ops,
1166 .vendor = PCI_VENDOR_ID_INTEL,
1167 .devices = pci_device_ids,
1168};