blob: ccb1e93604cbf76381bee145c740ee18d0338765 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070014 */
15
Duncan Lauriee86ac7e2014-10-07 15:19:54 -070016#include <arch/acpi.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070017#include <arch/io.h>
Marc Jonesa6354a12014-12-26 22:11:14 -070018#include <bootmode.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070019#include <console/console.h>
20#include <delay.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
24#include <stdlib.h>
25#include <string.h>
26#include <reg_script.h>
27#include <drivers/intel/gma/i915_reg.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070028#include <soc/cpu.h>
Duncan Laurie1e6b5912015-01-30 16:33:43 -080029#include <soc/pm.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070030#include <soc/ramstage.h>
31#include <soc/systemagent.h>
32#include <soc/intel/broadwell/chip.h>
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070033#include <vboot/vbnv.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070034
35#define GT_RETRY 1000
36#define GT_CDCLK_337 0
37#define GT_CDCLK_450 1
38#define GT_CDCLK_540 2
39#define GT_CDCLK_675 3
40
41struct reg_script haswell_early_init_script[] = {
42 /* Enable Force Wake */
43 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa180, 0x00000020),
44 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010001),
Edward O'Callaghan986e85c2014-10-29 12:15:34 +110045 REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 1, GT_RETRY),
Duncan Lauriec88c54c2014-04-30 16:36:13 -070046
47 /* Enable Counters */
48 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa248, 0x00000016),
49
50 /* GFXPAUSE settings */
51 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa000, 0x00070020),
52
53 /* ECO Settings */
54 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0xa180, 0xff3fffff, 0x15000000),
55
56 /* Enable DOP Clock Gating */
57 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9424, 0x000003fd),
58
59 /* Enable Unit Level Clock Gating */
60 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9400, 0x00000080),
61 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9404, 0x40401000),
62 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9408, 0x00000000),
63 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x940c, 0x02000001),
64
65 /*
66 * RC6 Settings
67 */
68
69 /* Wake Rate Limits */
70 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa090, 0x00000000),
71 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa098, 0x03e80000),
72 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa09c, 0x00280000),
73 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0a8, 0x0001e848),
74 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0ac, 0x00000019),
75
76 /* Render/Video/Blitter Idle Max Count */
77 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x02054, 0x0000000a),
78 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x12054, 0x0000000a),
79 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x22054, 0x0000000a),
80 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1a054, 0x0000000a),
81
82 /* RC Sleep / RCx Thresholds */
83 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b0, 0x00000000),
84 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b4, 0x000003e8),
85 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b8, 0x0000c350),
86
87 /* RP Settings */
88 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa010, 0x000f4240),
89 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa014, 0x12060000),
90 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa02c, 0x0000e808),
91 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa030, 0x0003bd08),
92 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa068, 0x000101d0),
93 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa06c, 0x00055730),
94 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa070, 0x0000000a),
95
96 /* RP Control */
97 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa024, 0x00000b92),
98
99 /* HW RC6 Control */
100 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa090, 0x88040000),
101
102 /* Video Frequency Request */
103 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa00c, 0x08000000),
104
105 /* Set RC6 VIDs */
106 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY),
107 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138128, 0),
108 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138124, 0x80000004),
109 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY),
110
111 /* Enable PM Interrupts */
112 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x4402c, 0x03000076),
113
114 /* Enable RC6 in idle */
115 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa094, 0x00040000),
116
117 REG_SCRIPT_END
118};
119
120static const struct reg_script haswell_late_init_script[] = {
121 /* Lock settings */
122 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a248, (1 << 31)),
123 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a004, (1 << 4)),
124 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a080, (1 << 2)),
125 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a180, (1 << 31)),
126
127 /* Disable Force Wake */
128 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010000),
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100129 REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 0, GT_RETRY),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700130 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00000001),
131
132 /* Enable power well for DP and Audio */
133 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x45400, (1 << 31)),
134 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x45400,
135 (1 << 30), (1 << 30), GT_RETRY),
136
137 REG_SCRIPT_END
138};
139
140static const struct reg_script broadwell_early_init_script[] = {
141 /* Enable Force Wake */
142 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010001),
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100143 REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 1, GT_RETRY),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700144
145 /* Enable push bus metric control and shift */
146 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa248, 0x00000004),
147 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa250, 0x000000ff),
148 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa25c, 0x00000010),
149
Duncan Laurie84b9cf42014-07-31 10:46:57 -0700150 /* GFXPAUSE settings (set based on stepping) */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700151
152 /* ECO Settings */
153 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa180, 0x45200000),
154
155 /* Enable DOP Clock Gating */
156 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9424, 0x000000fd),
157
158 /* Enable Unit Level Clock Gating */
159 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9400, 0x00000000),
160 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9404, 0x40401000),
161 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9408, 0x00000000),
162 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x940c, 0x02000001),
163 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1a054, 0x0000000a),
164
165 /* Video Frequency Request */
166 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa00c, 0x08000000),
167
Duncan Laurie84b9cf42014-07-31 10:46:57 -0700168 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138158, 0x00000009),
169 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x13815c, 0x0000000d),
170
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700171 /*
172 * RC6 Settings
173 */
174
175 /* Wake Rate Limits */
176 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x0a090, 0, 0),
177 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a098, 0x03e80000),
178 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a09c, 0x00280000),
179 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0a8, 0x0001e848),
180 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0ac, 0x00000019),
181
182 /* Render/Video/Blitter Idle Max Count */
183 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x02054, 0x0000000a),
184 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x12054, 0x0000000a),
185 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x22054, 0x0000000a),
186
187 /* RC Sleep / RCx Thresholds */
188 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0b0, 0x00000000),
189 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0b8, 0x00000271),
190
191 /* RP Settings */
192 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a010, 0x000f4240),
193 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a014, 0x12060000),
194 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a02c, 0x0000e808),
195 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a030, 0x0003bd08),
196 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a068, 0x000101d0),
197 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a06c, 0x00055730),
198 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a070, 0x0000000a),
199 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a168, 0x00000006),
200
201 /* RP Control */
202 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa024, 0x00000b92),
203
204 /* HW RC6 Control */
205 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa090, 0x90040000),
206
207 /* Set RC6 VIDs */
208 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY),
209 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138128, 0),
210 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138124, 0x80000004),
211 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY),
212
213 /* Enable PM Interrupts */
214 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x4402c, 0x03000076),
215
216 /* Enable RC6 in idle */
217 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa094, 0x00040000),
218
219 REG_SCRIPT_END
220};
221
222static const struct reg_script broadwell_late_init_script[] = {
223 /* Lock settings */
224 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a248, (1 << 31)),
225 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a000, (1 << 18)),
226 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a180, (1 << 31)),
227
228 /* Disable Force Wake */
229 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010000),
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100230 REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 0, GT_RETRY),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700231
232 /* Enable power well for DP and Audio */
233 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x45400, (1 << 31)),
234 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x45400,
235 (1 << 30), (1 << 30), GT_RETRY),
236
237 REG_SCRIPT_END
238};
239
240u32 map_oprom_vendev(u32 vendev)
241{
242 return SA_IGD_OPROM_VENDEV;
243}
244
245static struct resource *gtt_res = NULL;
246
247static unsigned long gtt_read(unsigned long reg)
248{
249 u32 val;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800250 val = read32(res2mmio(gtt_res, reg, 0));
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700251 return val;
252
253}
254
255static void gtt_write(unsigned long reg, unsigned long data)
256{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800257 write32(res2mmio(gtt_res, reg, 0), data);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700258}
259
260static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask)
261{
262 u32 val = gtt_read(reg);
263 val &= andmask;
264 val |= ormask;
265 gtt_write(reg, val);
266}
267
268static int gtt_poll(u32 reg, u32 mask, u32 value)
269{
270 unsigned try = GT_RETRY;
271 u32 data;
272
273 while (try--) {
274 data = gtt_read(reg);
275 if ((data & mask) == value)
276 return 1;
277 udelay(10);
278 }
279
280 printk(BIOS_ERR, "GT init timeout\n");
281 return 0;
282}
283
284static void igd_setup_panel(struct device *dev)
285{
286 config_t *conf = dev->chip_info;
287 u32 reg32;
288
289 /* Setup Digital Port Hotplug */
290 reg32 = gtt_read(PCH_PORT_HOTPLUG);
291 if (!reg32) {
292 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
293 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
294 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
295 gtt_write(PCH_PORT_HOTPLUG, reg32);
296 }
297
298 /* Setup Panel Power On Delays */
299 reg32 = gtt_read(PCH_PP_ON_DELAYS);
300 if (!reg32) {
301 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
302 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
303 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
304 gtt_write(PCH_PP_ON_DELAYS, reg32);
305 }
306
307 /* Setup Panel Power Off Delays */
308 reg32 = gtt_read(PCH_PP_OFF_DELAYS);
309 if (!reg32) {
310 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
311 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
312 gtt_write(PCH_PP_OFF_DELAYS, reg32);
313 }
314
315 /* Setup Panel Power Cycle Delay */
316 if (conf->gpu_panel_power_cycle_delay) {
317 reg32 = gtt_read(PCH_PP_DIVISOR);
318 reg32 &= ~0xff;
319 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
320 gtt_write(PCH_PP_DIVISOR, reg32);
321 }
322
323 /* Enable Backlight if needed */
324 if (conf->gpu_cpu_backlight) {
325 gtt_write(BLC_PWM_CPU_CTL2, BLC_PWM2_ENABLE);
326 gtt_write(BLC_PWM_CPU_CTL, conf->gpu_cpu_backlight);
327 }
328 if (conf->gpu_pch_backlight) {
329 gtt_write(BLC_PWM_PCH_CTL1, BLM_PCH_PWM_ENABLE);
330 gtt_write(BLC_PWM_PCH_CTL2, conf->gpu_pch_backlight);
331 }
332}
333
334static void igd_cdclk_init_haswell(struct device *dev)
335{
336 config_t *conf = dev->chip_info;
337 int cdclk = conf->cdclk;
338 int devid = pci_read_config16(dev, PCI_DEVICE_ID);
339 int gpu_is_ulx = 0;
340 u32 dpdiv, lpcll;
341
342 /* Check for ULX GT1 or GT2 */
343 if (devid == 0x0a0e || devid == 0x0a1e)
344 gpu_is_ulx = 1;
345
346 /* 675MHz is not supported on haswell */
347 if (cdclk == GT_CDCLK_675)
348 cdclk = GT_CDCLK_337;
349
350 /* If CD clock is fixed or ULT then set to 450MHz */
351 if ((gtt_read(0x42014) & 0x1000000) || cpu_is_ult())
352 cdclk = GT_CDCLK_450;
353
354 /* 540MHz is not supported on ULX */
355 if (gpu_is_ulx && cdclk == GT_CDCLK_540)
356 cdclk = GT_CDCLK_337;
357
358 /* 337.5MHz is not supported on non-ULT/ULX */
359 if (!gpu_is_ulx && !cpu_is_ult() && cdclk == GT_CDCLK_337)
360 cdclk = GT_CDCLK_450;
361
362 /* Set variables based on CD Clock setting */
363 switch (cdclk) {
364 case GT_CDCLK_337:
365 dpdiv = 169;
366 lpcll = (1 << 26);
367 break;
368 case GT_CDCLK_450:
369 dpdiv = 225;
370 lpcll = 0;
371 break;
372 case GT_CDCLK_540:
373 dpdiv = 270;
374 lpcll = (1 << 26);
375 break;
376 default:
377 return;
378 }
379
380 /* Set LPCLL_CTL CD Clock Frequency Select */
381 gtt_rmw(0x130040, 0xf3ffffff, lpcll);
382
383 /* ULX: Inform power controller of selected frequency */
384 if (gpu_is_ulx) {
385 if (cdclk == GT_CDCLK_450)
386 gtt_write(0x138128, 0x00000000); /* 450MHz */
387 else
388 gtt_write(0x138128, 0x00000001); /* 337.5MHz */
389 gtt_write(0x13812c, 0x00000000);
390 gtt_write(0x138124, 0x80000017);
391 }
392
393 /* Set CPU DP AUX 2X bit clock dividers */
394 gtt_rmw(0x64010, 0xfffff800, dpdiv);
395 gtt_rmw(0x64810, 0xfffff800, dpdiv);
396}
397
398static void igd_cdclk_init_broadwell(struct device *dev)
399{
400 config_t *conf = dev->chip_info;
401 int cdclk = conf->cdclk;
402 u32 dpdiv, lpcll, pwctl, cdset;
403
404 /* Inform power controller of upcoming frequency change */
405 gtt_write(0x138128, 0);
406 gtt_write(0x13812c, 0);
407 gtt_write(0x138124, 0x80000018);
408
409 /* Poll GT driver mailbox for run/busy clear */
410 if (!gtt_poll(0x138124, (1 << 31), (0 << 31)))
411 cdclk = GT_CDCLK_450;
412
413 if (gtt_read(0x42014) & 0x1000000) {
414 /* If CD clock is fixed then set to 450MHz */
415 cdclk = GT_CDCLK_450;
416 } else {
417 /* Program CD clock to highest supported freq */
418 if (cpu_is_ult())
419 cdclk = GT_CDCLK_540;
420 else
421 cdclk = GT_CDCLK_675;
422 }
423
424 /* CD clock frequency 675MHz not supported on ULT */
425 if (cpu_is_ult() && cdclk == GT_CDCLK_675)
426 cdclk = GT_CDCLK_540;
427
428 /* Set variables based on CD Clock setting */
429 switch (cdclk) {
430 case GT_CDCLK_337:
431 cdset = 337;
432 lpcll = (1 << 27);
433 pwctl = 2;
434 dpdiv = 169;
435 break;
436 case GT_CDCLK_450:
437 cdset = 449;
438 lpcll = 0;
439 pwctl = 0;
440 dpdiv = 225;
441 break;
442 case GT_CDCLK_540:
443 cdset = 539;
444 lpcll = (1 << 26);
445 pwctl = 1;
446 dpdiv = 270;
447 break;
448 case GT_CDCLK_675:
449 cdset = 674;
450 lpcll = (1 << 26) | (1 << 27);
451 pwctl = 3;
452 dpdiv = 338;
453 default:
454 return;
455 }
456
457 /* Set LPCLL_CTL CD Clock Frequency Select */
458 gtt_rmw(0x130040, 0xf3ffffff, lpcll);
459
460 /* Inform power controller of selected frequency */
461 gtt_write(0x138128, pwctl);
462 gtt_write(0x13812c, 0);
463 gtt_write(0x138124, 0x80000017);
464
465 /* Program CD Clock Frequency */
466 gtt_rmw(0x46200, 0xfffffc00, cdset);
467
468 /* Set CPU DP AUX 2X bit clock dividers */
469 gtt_rmw(0x64010, 0xfffff800, dpdiv);
470 gtt_rmw(0x64810, 0xfffff800, dpdiv);
471}
472
473static void igd_init(struct device *dev)
474{
475 int is_broadwell = !!(cpu_family_model() == BROADWELL_FAMILY_ULT);
476 u32 rp1_gfx_freq;
477
478 /* IGD needs to be Bus Master */
479 u32 reg32 = pci_read_config32(dev, PCI_COMMAND);
480 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
481 pci_write_config32(dev, PCI_COMMAND, reg32);
482
483 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
484 if (!gtt_res || !gtt_res->base)
485 return;
486
487 /* Wait for any configured pre-graphics delay */
Kyösti Mälkki1ec23c92015-05-29 06:18:18 +0300488 if (!acpi_is_wakeup_s3()) {
Duncan Laurieb8a7b712014-11-10 13:00:27 -0800489#if IS_ENABLED(CONFIG_CHROMEOS)
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700490 if (display_init_required() || vboot_wants_oprom())
Duncan Laurie1e6b5912015-01-30 16:33:43 -0800491 mdelay(CONFIG_PRE_GRAPHICS_DELAY);
Duncan Laurieb8a7b712014-11-10 13:00:27 -0800492#else
Duncan Laurie1e6b5912015-01-30 16:33:43 -0800493 mdelay(CONFIG_PRE_GRAPHICS_DELAY);
Duncan Laurieb8a7b712014-11-10 13:00:27 -0800494#endif
Duncan Laurie1e6b5912015-01-30 16:33:43 -0800495 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700496
497 /* Early init steps */
498 if (is_broadwell) {
499 reg_script_run_on_dev(dev, broadwell_early_init_script);
Duncan Laurie84b9cf42014-07-31 10:46:57 -0700500
501 /* Set GFXPAUSE based on stepping */
502 if (cpu_stepping() <= (CPUID_BROADWELL_E0 & 0xf) &&
503 systemagent_revision() <= 9) {
504 gtt_write(0xa000, 0x300ff);
505 } else {
506 gtt_write(0xa000, 0x30020);
507 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700508 } else {
509 reg_script_run_on_dev(dev, haswell_early_init_script);
510 }
511
512 /* Set RP1 graphics frequency */
513 rp1_gfx_freq = (MCHBAR32(0x5998) >> 8) & 0xff;
514 gtt_write(0xa008, rp1_gfx_freq << 24);
515
516 /* Post VBIOS panel setup */
517 igd_setup_panel(dev);
518
519 /* Initialize PCI device, load/execute BIOS Option ROM */
520 pci_dev_init(dev);
521
522 /* Late init steps */
523 if (is_broadwell) {
524 igd_cdclk_init_broadwell(dev);
525 reg_script_run_on_dev(dev, broadwell_late_init_script);
526 } else {
527 igd_cdclk_init_haswell(dev);
528 reg_script_run_on_dev(dev, haswell_late_init_script);
529 }
Duncan Laurie61680272014-05-05 12:42:35 -0500530
Duncan Laurie49efaf22014-10-09 16:13:24 -0700531 if (gfx_get_init_done()) {
532 /*
533 * Work around VBIOS issue that is not clearing first 64
534 * bytes of the framebuffer during VBE mode set.
535 */
536 struct resource *fb = find_resource(dev, PCI_BASE_ADDRESS_2);
537 memset((void *)((u32)fb->base), 0, 64);
538 }
539
Kyösti Mälkki1ec23c92015-05-29 06:18:18 +0300540 if (!gfx_get_init_done() && !acpi_is_wakeup_s3()) {
Duncan Laurie61680272014-05-05 12:42:35 -0500541 /*
542 * Enable DDI-A if the Option ROM did not execute:
543 *
544 * bit 0: Display detected (RO)
545 * bit 4: DDI A supports 4 lanes and DDI E is not used
546 * bit 7: DDI buffer is idle
547 */
548 gtt_write(DDI_BUF_CTL_A, DDI_BUF_IS_IDLE | DDI_A_4_LANES |
549 DDI_INIT_DISPLAY_DETECTED);
550 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700551}
552
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700553static struct device_operations igd_ops = {
Marc Jonesa6354a12014-12-26 22:11:14 -0700554 .read_resources = &pci_dev_read_resources,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700555 .set_resources = &pci_dev_set_resources,
556 .enable_resources = &pci_dev_enable_resources,
557 .init = &igd_init,
558 .ops_pci = &broadwell_pci_ops,
559};
560
561static const unsigned short pci_device_ids[] = {
562 IGD_HASWELL_ULT_GT1,
563 IGD_HASWELL_ULT_GT2,
564 IGD_HASWELL_ULT_GT3,
565 IGD_BROADWELL_U_GT1,
566 IGD_BROADWELL_U_GT2,
567 IGD_BROADWELL_U_GT3_15W,
568 IGD_BROADWELL_U_GT3_28W,
569 IGD_BROADWELL_Y_GT2,
570 IGD_BROADWELL_H_GT2,
571 IGD_BROADWELL_H_GT3,
572 0,
573};
574
575static const struct pci_driver igd_driver __pci_driver = {
576 .ops = &igd_ops,
577 .vendor = PCI_VENDOR_ID_INTEL,
578 .devices = pci_device_ids,
579};