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