]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/x86/cpu/ivybridge/gma.c
Merge branch 'master' of git://www.denx.de/git/u-boot-imx
[karo-tx-uboot.git] / arch / x86 / cpu / ivybridge / gma.c
1 /*
2  * From Coreboot file of the same name
3  *
4  * Copyright (C) 2011 Chromium OS Authors
5  *
6  * SPDX-License-Identifier:     GPL-2.0
7  */
8
9 #include <common.h>
10 #include <bios_emul.h>
11 #include <errno.h>
12 #include <fdtdec.h>
13 #include <pci_rom.h>
14 #include <asm/io.h>
15 #include <asm/pci.h>
16 #include <asm/arch/pch.h>
17 #include <asm/arch/sandybridge.h>
18
19 struct gt_powermeter {
20         u16 reg;
21         u32 value;
22 };
23
24 static const struct gt_powermeter snb_pm_gt1[] = {
25         { 0xa200, 0xcc000000 },
26         { 0xa204, 0x07000040 },
27         { 0xa208, 0x0000fe00 },
28         { 0xa20c, 0x00000000 },
29         { 0xa210, 0x17000000 },
30         { 0xa214, 0x00000021 },
31         { 0xa218, 0x0817fe19 },
32         { 0xa21c, 0x00000000 },
33         { 0xa220, 0x00000000 },
34         { 0xa224, 0xcc000000 },
35         { 0xa228, 0x07000040 },
36         { 0xa22c, 0x0000fe00 },
37         { 0xa230, 0x00000000 },
38         { 0xa234, 0x17000000 },
39         { 0xa238, 0x00000021 },
40         { 0xa23c, 0x0817fe19 },
41         { 0xa240, 0x00000000 },
42         { 0xa244, 0x00000000 },
43         { 0xa248, 0x8000421e },
44         { 0 }
45 };
46
47 static const struct gt_powermeter snb_pm_gt2[] = {
48         { 0xa200, 0x330000a6 },
49         { 0xa204, 0x402d0031 },
50         { 0xa208, 0x00165f83 },
51         { 0xa20c, 0xf1000000 },
52         { 0xa210, 0x00000000 },
53         { 0xa214, 0x00160016 },
54         { 0xa218, 0x002a002b },
55         { 0xa21c, 0x00000000 },
56         { 0xa220, 0x00000000 },
57         { 0xa224, 0x330000a6 },
58         { 0xa228, 0x402d0031 },
59         { 0xa22c, 0x00165f83 },
60         { 0xa230, 0xf1000000 },
61         { 0xa234, 0x00000000 },
62         { 0xa238, 0x00160016 },
63         { 0xa23c, 0x002a002b },
64         { 0xa240, 0x00000000 },
65         { 0xa244, 0x00000000 },
66         { 0xa248, 0x8000421e },
67         { 0 }
68 };
69
70 static const struct gt_powermeter ivb_pm_gt1[] = {
71         { 0xa800, 0x00000000 },
72         { 0xa804, 0x00021c00 },
73         { 0xa808, 0x00000403 },
74         { 0xa80c, 0x02001700 },
75         { 0xa810, 0x05000200 },
76         { 0xa814, 0x00000000 },
77         { 0xa818, 0x00690500 },
78         { 0xa81c, 0x0000007f },
79         { 0xa820, 0x01002501 },
80         { 0xa824, 0x00000300 },
81         { 0xa828, 0x01000331 },
82         { 0xa82c, 0x0000000c },
83         { 0xa830, 0x00010016 },
84         { 0xa834, 0x01100101 },
85         { 0xa838, 0x00010103 },
86         { 0xa83c, 0x00041300 },
87         { 0xa840, 0x00000b30 },
88         { 0xa844, 0x00000000 },
89         { 0xa848, 0x7f000000 },
90         { 0xa84c, 0x05000008 },
91         { 0xa850, 0x00000001 },
92         { 0xa854, 0x00000004 },
93         { 0xa858, 0x00000007 },
94         { 0xa85c, 0x00000000 },
95         { 0xa860, 0x00010000 },
96         { 0xa248, 0x0000221e },
97         { 0xa900, 0x00000000 },
98         { 0xa904, 0x00001c00 },
99         { 0xa908, 0x00000000 },
100         { 0xa90c, 0x06000000 },
101         { 0xa910, 0x09000200 },
102         { 0xa914, 0x00000000 },
103         { 0xa918, 0x00590000 },
104         { 0xa91c, 0x00000000 },
105         { 0xa920, 0x04002501 },
106         { 0xa924, 0x00000100 },
107         { 0xa928, 0x03000410 },
108         { 0xa92c, 0x00000000 },
109         { 0xa930, 0x00020000 },
110         { 0xa934, 0x02070106 },
111         { 0xa938, 0x00010100 },
112         { 0xa93c, 0x00401c00 },
113         { 0xa940, 0x00000000 },
114         { 0xa944, 0x00000000 },
115         { 0xa948, 0x10000e00 },
116         { 0xa94c, 0x02000004 },
117         { 0xa950, 0x00000001 },
118         { 0xa954, 0x00000004 },
119         { 0xa960, 0x00060000 },
120         { 0xaa3c, 0x00001c00 },
121         { 0xaa54, 0x00000004 },
122         { 0xaa60, 0x00060000 },
123         { 0 }
124 };
125
126 static const struct gt_powermeter ivb_pm_gt2[] = {
127         { 0xa800, 0x10000000 },
128         { 0xa804, 0x00033800 },
129         { 0xa808, 0x00000902 },
130         { 0xa80c, 0x0c002f00 },
131         { 0xa810, 0x12000400 },
132         { 0xa814, 0x00000000 },
133         { 0xa818, 0x00d20800 },
134         { 0xa81c, 0x00000002 },
135         { 0xa820, 0x03004b02 },
136         { 0xa824, 0x00000600 },
137         { 0xa828, 0x07000773 },
138         { 0xa82c, 0x00000000 },
139         { 0xa830, 0x00010032 },
140         { 0xa834, 0x1520040d },
141         { 0xa838, 0x00020105 },
142         { 0xa83c, 0x00083700 },
143         { 0xa840, 0x0000151d },
144         { 0xa844, 0x00000000 },
145         { 0xa848, 0x20001b00 },
146         { 0xa84c, 0x0a000010 },
147         { 0xa850, 0x00000000 },
148         { 0xa854, 0x00000008 },
149         { 0xa858, 0x00000008 },
150         { 0xa85c, 0x00000000 },
151         { 0xa860, 0x00020000 },
152         { 0xa248, 0x0000221e },
153         { 0xa900, 0x00000000 },
154         { 0xa904, 0x00003500 },
155         { 0xa908, 0x00000000 },
156         { 0xa90c, 0x0c000000 },
157         { 0xa910, 0x12000500 },
158         { 0xa914, 0x00000000 },
159         { 0xa918, 0x00b20000 },
160         { 0xa91c, 0x00000000 },
161         { 0xa920, 0x08004b02 },
162         { 0xa924, 0x00000200 },
163         { 0xa928, 0x07000820 },
164         { 0xa92c, 0x00000000 },
165         { 0xa930, 0x00030000 },
166         { 0xa934, 0x050f020d },
167         { 0xa938, 0x00020300 },
168         { 0xa93c, 0x00903900 },
169         { 0xa940, 0x00000000 },
170         { 0xa944, 0x00000000 },
171         { 0xa948, 0x20001b00 },
172         { 0xa94c, 0x0a000010 },
173         { 0xa950, 0x00000000 },
174         { 0xa954, 0x00000008 },
175         { 0xa960, 0x00110000 },
176         { 0xaa3c, 0x00003900 },
177         { 0xaa54, 0x00000008 },
178         { 0xaa60, 0x00110000 },
179         { 0 }
180 };
181
182 static const struct gt_powermeter ivb_pm_gt2_17w[] = {
183         { 0xa800, 0x20000000 },
184         { 0xa804, 0x000e3800 },
185         { 0xa808, 0x00000806 },
186         { 0xa80c, 0x0c002f00 },
187         { 0xa810, 0x0c000800 },
188         { 0xa814, 0x00000000 },
189         { 0xa818, 0x00d20d00 },
190         { 0xa81c, 0x000000ff },
191         { 0xa820, 0x03004b02 },
192         { 0xa824, 0x00000600 },
193         { 0xa828, 0x07000773 },
194         { 0xa82c, 0x00000000 },
195         { 0xa830, 0x00020032 },
196         { 0xa834, 0x1520040d },
197         { 0xa838, 0x00020105 },
198         { 0xa83c, 0x00083700 },
199         { 0xa840, 0x000016ff },
200         { 0xa844, 0x00000000 },
201         { 0xa848, 0xff000000 },
202         { 0xa84c, 0x0a000010 },
203         { 0xa850, 0x00000002 },
204         { 0xa854, 0x00000008 },
205         { 0xa858, 0x0000000f },
206         { 0xa85c, 0x00000000 },
207         { 0xa860, 0x00020000 },
208         { 0xa248, 0x0000221e },
209         { 0xa900, 0x00000000 },
210         { 0xa904, 0x00003800 },
211         { 0xa908, 0x00000000 },
212         { 0xa90c, 0x0c000000 },
213         { 0xa910, 0x12000800 },
214         { 0xa914, 0x00000000 },
215         { 0xa918, 0x00b20000 },
216         { 0xa91c, 0x00000000 },
217         { 0xa920, 0x08004b02 },
218         { 0xa924, 0x00000300 },
219         { 0xa928, 0x01000820 },
220         { 0xa92c, 0x00000000 },
221         { 0xa930, 0x00030000 },
222         { 0xa934, 0x15150406 },
223         { 0xa938, 0x00020300 },
224         { 0xa93c, 0x00903900 },
225         { 0xa940, 0x00000000 },
226         { 0xa944, 0x00000000 },
227         { 0xa948, 0x20001b00 },
228         { 0xa94c, 0x0a000010 },
229         { 0xa950, 0x00000000 },
230         { 0xa954, 0x00000008 },
231         { 0xa960, 0x00110000 },
232         { 0xaa3c, 0x00003900 },
233         { 0xaa54, 0x00000008 },
234         { 0xaa60, 0x00110000 },
235         { 0 }
236 };
237
238 static const struct gt_powermeter ivb_pm_gt2_35w[] = {
239         { 0xa800, 0x00000000 },
240         { 0xa804, 0x00030400 },
241         { 0xa808, 0x00000806 },
242         { 0xa80c, 0x0c002f00 },
243         { 0xa810, 0x0c000300 },
244         { 0xa814, 0x00000000 },
245         { 0xa818, 0x00d20d00 },
246         { 0xa81c, 0x000000ff },
247         { 0xa820, 0x03004b02 },
248         { 0xa824, 0x00000600 },
249         { 0xa828, 0x07000773 },
250         { 0xa82c, 0x00000000 },
251         { 0xa830, 0x00020032 },
252         { 0xa834, 0x1520040d },
253         { 0xa838, 0x00020105 },
254         { 0xa83c, 0x00083700 },
255         { 0xa840, 0x000016ff },
256         { 0xa844, 0x00000000 },
257         { 0xa848, 0xff000000 },
258         { 0xa84c, 0x0a000010 },
259         { 0xa850, 0x00000001 },
260         { 0xa854, 0x00000008 },
261         { 0xa858, 0x00000008 },
262         { 0xa85c, 0x00000000 },
263         { 0xa860, 0x00020000 },
264         { 0xa248, 0x0000221e },
265         { 0xa900, 0x00000000 },
266         { 0xa904, 0x00003800 },
267         { 0xa908, 0x00000000 },
268         { 0xa90c, 0x0c000000 },
269         { 0xa910, 0x12000800 },
270         { 0xa914, 0x00000000 },
271         { 0xa918, 0x00b20000 },
272         { 0xa91c, 0x00000000 },
273         { 0xa920, 0x08004b02 },
274         { 0xa924, 0x00000300 },
275         { 0xa928, 0x01000820 },
276         { 0xa92c, 0x00000000 },
277         { 0xa930, 0x00030000 },
278         { 0xa934, 0x15150406 },
279         { 0xa938, 0x00020300 },
280         { 0xa93c, 0x00903900 },
281         { 0xa940, 0x00000000 },
282         { 0xa944, 0x00000000 },
283         { 0xa948, 0x20001b00 },
284         { 0xa94c, 0x0a000010 },
285         { 0xa950, 0x00000000 },
286         { 0xa954, 0x00000008 },
287         { 0xa960, 0x00110000 },
288         { 0xaa3c, 0x00003900 },
289         { 0xaa54, 0x00000008 },
290         { 0xaa60, 0x00110000 },
291         { 0 }
292 };
293
294 /*
295  * Some vga option roms are used for several chipsets but they only have one
296  * PCI ID in their header. If we encounter such an option rom, we need to do
297  * the mapping ourselves.
298  */
299
300 u32 map_oprom_vendev(u32 vendev)
301 {
302         u32 new_vendev = vendev;
303
304         switch (vendev) {
305         case 0x80860102:                /* GT1 Desktop */
306         case 0x8086010a:                /* GT1 Server */
307         case 0x80860112:                /* GT2 Desktop */
308         case 0x80860116:                /* GT2 Mobile */
309         case 0x80860122:                /* GT2 Desktop >=1.3GHz */
310         case 0x80860126:                /* GT2 Mobile >=1.3GHz */
311         case 0x80860156:                /* IVB */
312         case 0x80860166:                /* IVB */
313                 /* Set to GT1 Mobile */
314                 new_vendev = 0x80860106;
315                 break;
316         }
317
318         return new_vendev;
319 }
320
321 static inline u32 gtt_read(void *bar, u32 reg)
322 {
323         return readl(bar + reg);
324 }
325
326 static inline void gtt_write(void *bar, u32 reg, u32 data)
327 {
328         writel(data, bar + reg);
329 }
330
331 static void gtt_write_powermeter(void *bar, const struct gt_powermeter *pm)
332 {
333         for (; pm && pm->reg; pm++)
334                 gtt_write(bar, pm->reg, pm->value);
335 }
336
337 #define GTT_RETRY 1000
338 static int gtt_poll(void *bar, u32 reg, u32 mask, u32 value)
339 {
340         unsigned try = GTT_RETRY;
341         u32 data;
342
343         while (try--) {
344                 data = gtt_read(bar, reg);
345                 if ((data & mask) == value)
346                         return 1;
347                 udelay(10);
348         }
349
350         printf("GT init timeout\n");
351         return 0;
352 }
353
354 static int gma_pm_init_pre_vbios(void *gtt_bar)
355 {
356         u32 reg32;
357
358         debug("GT Power Management Init, silicon = %#x\n",
359               bridge_silicon_revision());
360
361         if (bridge_silicon_revision() < IVB_STEP_C0) {
362                 /* 1: Enable force wake */
363                 gtt_write(gtt_bar, 0xa18c, 0x00000001);
364                 gtt_poll(gtt_bar, 0x130090, (1 << 0), (1 << 0));
365         } else {
366                 gtt_write(gtt_bar, 0xa180, 1 << 5);
367                 gtt_write(gtt_bar, 0xa188, 0xffff0001);
368                 gtt_poll(gtt_bar, 0x130040, (1 << 0), (1 << 0));
369         }
370
371         if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
372                 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
373                 reg32 = gtt_read(gtt_bar, 0x42004);
374                 reg32 |= (1 << 14) | (1 << 15);
375                 gtt_write(gtt_bar, 0x42004, reg32);
376         }
377
378         if (bridge_silicon_revision() >= IVB_STEP_A0) {
379                 /* Display Reset Acknowledge Settings */
380                 reg32 = gtt_read(gtt_bar, 0x45010);
381                 reg32 |= (1 << 1) | (1 << 0);
382                 gtt_write(gtt_bar, 0x45010, reg32);
383         }
384
385         /* 2: Get GT SKU from GTT+0x911c[13] */
386         reg32 = gtt_read(gtt_bar, 0x911c);
387         if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
388                 if (reg32 & (1 << 13)) {
389                         debug("SNB GT1 Power Meter Weights\n");
390                         gtt_write_powermeter(gtt_bar, snb_pm_gt1);
391                 } else {
392                         debug("SNB GT2 Power Meter Weights\n");
393                         gtt_write_powermeter(gtt_bar, snb_pm_gt2);
394                 }
395         } else {
396                 u32 unit = readl(MCHBAR_REG(0x5938)) & 0xf;
397
398                 if (reg32 & (1 << 13)) {
399                         /* GT1 SKU */
400                         debug("IVB GT1 Power Meter Weights\n");
401                         gtt_write_powermeter(gtt_bar, ivb_pm_gt1);
402                 } else {
403                         /* GT2 SKU */
404                         u32 tdp = readl(MCHBAR_REG(0x5930)) & 0x7fff;
405                         tdp /= (1 << unit);
406
407                         if (tdp <= 17) {
408                                 /* <=17W ULV */
409                                 debug("IVB GT2 17W Power Meter Weights\n");
410                                 gtt_write_powermeter(gtt_bar, ivb_pm_gt2_17w);
411                         } else if ((tdp >= 25) && (tdp <= 35)) {
412                                 /* 25W-35W */
413                                 debug("IVB GT2 25W-35W Power Meter Weights\n");
414                                 gtt_write_powermeter(gtt_bar, ivb_pm_gt2_35w);
415                         } else {
416                                 /* All others */
417                                 debug("IVB GT2 35W Power Meter Weights\n");
418                                 gtt_write_powermeter(gtt_bar, ivb_pm_gt2_35w);
419                         }
420                 }
421         }
422
423         /* 3: Gear ratio map */
424         gtt_write(gtt_bar, 0xa004, 0x00000010);
425
426         /* 4: GFXPAUSE */
427         gtt_write(gtt_bar, 0xa000, 0x00070020);
428
429         /* 5: Dynamic EU trip control */
430         gtt_write(gtt_bar, 0xa080, 0x00000004);
431
432         /* 6: ECO bits */
433         reg32 = gtt_read(gtt_bar, 0xa180);
434         reg32 |= (1 << 26) | (1 << 31);
435         /* (bit 20=1 for SNB step D1+ / IVB A0+) */
436         if (bridge_silicon_revision() >= SNB_STEP_D1)
437                 reg32 |= (1 << 20);
438         gtt_write(gtt_bar, 0xa180, reg32);
439
440         /* 6a: for SnB step D2+ only */
441         if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
442             (bridge_silicon_revision() >= SNB_STEP_D2)) {
443                 reg32 = gtt_read(gtt_bar, 0x9400);
444                 reg32 |= (1 << 7);
445                 gtt_write(gtt_bar, 0x9400, reg32);
446
447                 reg32 = gtt_read(gtt_bar, 0x941c);
448                 reg32 &= 0xf;
449                 reg32 |= (1 << 1);
450                 gtt_write(gtt_bar, 0x941c, reg32);
451                 gtt_poll(gtt_bar, 0x941c, (1 << 1), (0 << 1));
452         }
453
454         if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
455                 reg32 = gtt_read(gtt_bar, 0x907c);
456                 reg32 |= (1 << 16);
457                 gtt_write(gtt_bar, 0x907c, reg32);
458
459                 /* 6b: Clocking reset controls */
460                 gtt_write(gtt_bar, 0x9424, 0x00000001);
461         } else {
462                 /* 6b: Clocking reset controls */
463                 gtt_write(gtt_bar, 0x9424, 0x00000000);
464         }
465
466         /* 7 */
467         if (gtt_poll(gtt_bar, 0x138124, (1 << 31), (0 << 31))) {
468                 gtt_write(gtt_bar, 0x138128, 0x00000029); /* Mailbox Data */
469                 /* Mailbox Cmd for RC6 VID */
470                 gtt_write(gtt_bar, 0x138124, 0x80000004);
471                 if (gtt_poll(gtt_bar, 0x138124, (1 << 31), (0 << 31)))
472                         gtt_write(gtt_bar, 0x138124, 0x8000000a);
473                 gtt_poll(gtt_bar, 0x138124, (1 << 31), (0 << 31));
474         }
475
476         /* 8 */
477         gtt_write(gtt_bar, 0xa090, 0x00000000); /* RC Control */
478         gtt_write(gtt_bar, 0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
479         gtt_write(gtt_bar, 0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
480         gtt_write(gtt_bar, 0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
481         gtt_write(gtt_bar, 0xa0a8, 0x0001e848); /* RC Evaluation Interval */
482         gtt_write(gtt_bar, 0xa0ac, 0x00000019); /* RC Idle Hysteresis */
483
484         /* 9 */
485         gtt_write(gtt_bar, 0x2054, 0x0000000a); /* Render Idle Max Count */
486         gtt_write(gtt_bar, 0x12054, 0x0000000a); /* Video Idle Max Count */
487         gtt_write(gtt_bar, 0x22054, 0x0000000a); /* Blitter Idle Max Count */
488
489         /* 10 */
490         gtt_write(gtt_bar, 0xa0b0, 0x00000000); /* Unblock Ack to Busy */
491         gtt_write(gtt_bar, 0xa0b4, 0x000003e8); /* RC1e Threshold */
492         gtt_write(gtt_bar, 0xa0b8, 0x0000c350); /* RC6 Threshold */
493         gtt_write(gtt_bar, 0xa0bc, 0x000186a0); /* RC6p Threshold */
494         gtt_write(gtt_bar, 0xa0c0, 0x0000fa00); /* RC6pp Threshold */
495
496         /* 11 */
497         gtt_write(gtt_bar, 0xa010, 0x000f4240); /* RP Down Timeout */
498         gtt_write(gtt_bar, 0xa014, 0x12060000); /* RP Interrupt Limits */
499         gtt_write(gtt_bar, 0xa02c, 0x00015f90); /* RP Up Threshold */
500         gtt_write(gtt_bar, 0xa030, 0x000186a0); /* RP Down Threshold */
501         gtt_write(gtt_bar, 0xa068, 0x000186a0); /* RP Up EI */
502         gtt_write(gtt_bar, 0xa06c, 0x000493e0); /* RP Down EI */
503         gtt_write(gtt_bar, 0xa070, 0x0000000a); /* RP Idle Hysteresis */
504
505         /* 11a: Enable Render Standby (RC6) */
506         if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
507                 /*
508                  * IvyBridge should also support DeepRenderStandby.
509                  *
510                  * Unfortunately it does not work reliably on all SKUs so
511                  * disable it here and it can be enabled by the kernel.
512                  */
513                 gtt_write(gtt_bar, 0xa090, 0x88040000); /* HW RC Control */
514         } else {
515                 gtt_write(gtt_bar, 0xa090, 0x88040000); /* HW RC Control */
516         }
517
518         /* 12: Normal Frequency Request */
519         /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
520         reg32 = readl(MCHBAR_REG(0x5998));
521         reg32 >>= 16;
522         reg32 &= 0xef;
523         reg32 <<= 25;
524         gtt_write(gtt_bar, 0xa008, reg32);
525
526         /* 13: RP Control */
527         gtt_write(gtt_bar, 0xa024, 0x00000592);
528
529         /* 14: Enable PM Interrupts */
530         gtt_write(gtt_bar, 0x4402c, 0x03000076);
531
532         /* Clear 0x6c024 [8:6] */
533         reg32 = gtt_read(gtt_bar, 0x6c024);
534         reg32 &= ~0x000001c0;
535         gtt_write(gtt_bar, 0x6c024, reg32);
536
537         return 0;
538 }
539
540 int gma_pm_init_post_vbios(void *gtt_bar, const void *blob, int node)
541 {
542         u32 reg32, cycle_delay;
543
544         debug("GT Power Management Init (post VBIOS)\n");
545
546         /* 15: Deassert Force Wake */
547         if (bridge_silicon_revision() < IVB_STEP_C0) {
548                 gtt_write(gtt_bar, 0xa18c, gtt_read(gtt_bar, 0xa18c) & ~1);
549                 gtt_poll(gtt_bar, 0x130090, (1 << 0), (0 << 0));
550         } else {
551                 gtt_write(gtt_bar, 0xa188, 0x1fffe);
552                 if (gtt_poll(gtt_bar, 0x130040, (1 << 0), (0 << 0))) {
553                         gtt_write(gtt_bar, 0xa188,
554                                   gtt_read(gtt_bar, 0xa188) | 1);
555                 }
556         }
557
558         /* 16: SW RC Control */
559         gtt_write(gtt_bar, 0xa094, 0x00060000);
560
561         /* Setup Digital Port Hotplug */
562         reg32 = gtt_read(gtt_bar, 0xc4030);
563         if (!reg32) {
564                 u32 dp_hotplug[3];
565
566                 if (fdtdec_get_int_array(blob, node, "intel,dp_hotplug",
567                                          dp_hotplug, ARRAY_SIZE(dp_hotplug)))
568                         return -EINVAL;
569
570                 reg32 = (dp_hotplug[0] & 0x7) << 2;
571                 reg32 |= (dp_hotplug[0] & 0x7) << 10;
572                 reg32 |= (dp_hotplug[0] & 0x7) << 18;
573                 gtt_write(gtt_bar, 0xc4030, reg32);
574         }
575
576         /* Setup Panel Power On Delays */
577         reg32 = gtt_read(gtt_bar, 0xc7208);
578         if (!reg32) {
579                 reg32 = (unsigned)fdtdec_get_int(blob, node,
580                                                  "panel-port-select", 0) << 30;
581                 reg32 |= fdtdec_get_int(blob, node, "panel-power-up-delay", 0)
582                                 << 16;
583                 reg32 |= fdtdec_get_int(blob, node,
584                                         "panel-power-backlight-on-delay", 0);
585                 gtt_write(gtt_bar, 0xc7208, reg32);
586         }
587
588         /* Setup Panel Power Off Delays */
589         reg32 = gtt_read(gtt_bar, 0xc720c);
590         if (!reg32) {
591                 reg32 = fdtdec_get_int(blob, node, "panel-power-down-delay", 0)
592                                 << 16;
593                 reg32 |= fdtdec_get_int(blob, node,
594                                         "panel-power-backlight-off-delay", 0);
595                 gtt_write(gtt_bar, 0xc720c, reg32);
596         }
597
598         /* Setup Panel Power Cycle Delay */
599         cycle_delay = fdtdec_get_int(blob, node,
600                                      "intel,panel-power-cycle-delay", 0);
601         if (cycle_delay) {
602                 reg32 = gtt_read(gtt_bar, 0xc7210);
603                 reg32 &= ~0xff;
604                 reg32 |= cycle_delay;
605                 gtt_write(gtt_bar, 0xc7210, reg32);
606         }
607
608         /* Enable Backlight if needed */
609         reg32 = fdtdec_get_int(blob, node, "intel,cpu-backlight", 0);
610         if (reg32) {
611                 gtt_write(gtt_bar, 0x48250, (1 << 31));
612                 gtt_write(gtt_bar, 0x48254, reg32);
613         }
614         reg32 = fdtdec_get_int(blob, node, "intel,pch-backlight", 0);
615         if (reg32) {
616                 gtt_write(gtt_bar, 0xc8250, (1 << 31));
617                 gtt_write(gtt_bar, 0xc8254, reg32);
618         }
619
620         return 0;
621 }
622
623 /*
624  * Some vga option roms are used for several chipsets but they only have one
625  * PCI ID in their header. If we encounter such an option rom, we need to do
626  * the mapping ourselves.
627  */
628
629 uint32_t board_map_oprom_vendev(uint32_t vendev)
630 {
631         switch (vendev) {
632         case 0x80860102:                /* GT1 Desktop */
633         case 0x8086010a:                /* GT1 Server */
634         case 0x80860112:                /* GT2 Desktop */
635         case 0x80860116:                /* GT2 Mobile */
636         case 0x80860122:                /* GT2 Desktop >=1.3GHz */
637         case 0x80860126:                /* GT2 Mobile >=1.3GHz */
638         case 0x80860156:                /* IVB */
639         case 0x80860166:                /* IVB */
640                 return 0x80860106;      /* GT1 Mobile */
641         }
642
643         return vendev;
644 }
645
646 static int int15_handler(void)
647 {
648         int res = 0;
649
650         debug("%s: INT15 function %04x!\n", __func__, M.x86.R_AX);
651
652         switch (M.x86.R_AX) {
653         case 0x5f34:
654                 /*
655                  * Set Panel Fitting Hook:
656                  *  bit 2 = Graphics Stretching
657                  *  bit 1 = Text Stretching
658                  *  bit 0 = Centering (do not set with bit1 or bit2)
659                  *  0     = video bios default
660                  */
661                 M.x86.R_AX = 0x005f;
662                 M.x86.R_CL = 0x00; /* Use video bios default */
663                 res = 1;
664                 break;
665         case 0x5f35:
666                 /*
667                  * Boot Display Device Hook:
668                  *  bit 0 = CRT
669                  *  bit 1 = TV (eDP)
670                  *  bit 2 = EFP
671                  *  bit 3 = LFP
672                  *  bit 4 = CRT2
673                  *  bit 5 = TV2 (eDP)
674                  *  bit 6 = EFP2
675                  *  bit 7 = LFP2
676                  */
677                 M.x86.R_AX = 0x005f;
678                 M.x86.R_CX = 0x0000; /* Use video bios default */
679                 res = 1;
680                 break;
681         case 0x5f51:
682                 /*
683                  * Hook to select active LFP configuration:
684                  *  00h = No LVDS, VBIOS does not enable LVDS
685                  *  01h = Int-LVDS, LFP driven by integrated LVDS decoder
686                  *  02h = SVDO-LVDS, LFP driven by SVDO decoder
687                  *  03h = eDP, LFP Driven by Int-DisplayPort encoder
688                  */
689                 M.x86.R_AX = 0x005f;
690                 M.x86.R_CX = 0x0003; /* eDP */
691                 res = 1;
692                 break;
693         case 0x5f70:
694                 switch (M.x86.R_CH) {
695                 case 0:
696                         /* Get Mux */
697                         M.x86.R_AX = 0x005f;
698                         M.x86.R_CX = 0x0000;
699                         res = 1;
700                         break;
701                 case 1:
702                         /* Set Mux */
703                         M.x86.R_AX = 0x005f;
704                         M.x86.R_CX = 0x0000;
705                         res = 1;
706                         break;
707                 case 2:
708                         /* Get SG/Non-SG mode */
709                         M.x86.R_AX = 0x005f;
710                         M.x86.R_CX = 0x0000;
711                         res = 1;
712                         break;
713                 default:
714                         /* Interrupt was not handled */
715                         debug("Unknown INT15 5f70 function: 0x%02x\n",
716                               M.x86.R_CH);
717                         break;
718                 }
719                 break;
720         case 0x5fac:
721                 res = 1;
722                 break;
723         default:
724                 debug("Unknown INT15 function %04x!\n", M.x86.R_AX);
725                 break;
726         }
727         return res;
728 }
729
730 int gma_func0_init(pci_dev_t dev, struct pci_controller *hose,
731                    const void *blob, int node)
732 {
733         void *gtt_bar;
734         u32 reg32;
735         int ret;
736
737         /* IGD needs to be Bus Master */
738         reg32 = pci_read_config32(dev, PCI_COMMAND);
739         reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
740         pci_write_config32(dev, PCI_COMMAND, reg32);
741
742         gtt_bar = (void *)pci_read_bar32(pci_bus_to_hose(0), dev, 0);
743         debug("GT bar %p\n", gtt_bar);
744         ret = gma_pm_init_pre_vbios(gtt_bar);
745         if (ret)
746                 return ret;
747
748         ret = pci_run_vga_bios(dev, int15_handler, false);
749
750         /* Post VBIOS init */
751         ret = gma_pm_init_post_vbios(gtt_bar, blob, node);
752         if (ret)
753                 return ret;
754
755         return 0;
756 }