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