blob: fa4dec91e290b8d82194628b7d92209252da365a [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
Ronald G. Minnich4f78b182013-04-17 16:57:30 -07004 * Copyright 2012 Google Inc.
Aaron Durbin76c37002012-10-30 09:03:43 -05005 *
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.
Aaron Durbin76c37002012-10-30 09:03:43 -050014 */
15
16#include <arch/io.h>
17#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020018#include <bootmode.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050019#include <delay.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -070023#include <drivers/intel/gma/i915_reg.h>
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070024#include <drivers/intel/gma/i915.h>
Duncan Laurie356833d2013-07-09 15:40:27 -070025#include <cpu/intel/haswell/haswell.h>
Patrick Rudolph9aca6432017-05-20 11:49:22 +020026#include <northbridge/intel/common/gma_opregion.h>
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070027#include <stdlib.h>
Ronald G. Minnich9518b562013-09-19 16:45:22 -070028#include <string.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050029
30#include "chip.h"
31#include "haswell.h"
32
Furquan Shaikhcb61ea72013-08-15 15:23:58 -070033#if CONFIG_CHROMEOS
34#include <vendorcode/google/chromeos/chromeos.h>
35#endif
36
Duncan Laurie356833d2013-07-09 15:40:27 -070037struct gt_reg {
38 u32 reg;
39 u32 andmask;
40 u32 ormask;
41};
42
43static const struct gt_reg haswell_gt_setup[] = {
44 /* Enable Counters */
45 { 0x0a248, 0x00000000, 0x00000016 },
46 { 0x0a000, 0x00000000, 0x00070020 },
47 { 0x0a180, 0xff3fffff, 0x15000000 },
48 /* Enable DOP Clock Gating */
49 { 0x09424, 0x00000000, 0x000003fd },
50 /* Enable Unit Level Clock Gating */
51 { 0x09400, 0x00000000, 0x00000080 },
52 { 0x09404, 0x00000000, 0x40401000 },
53 { 0x09408, 0x00000000, 0x00000000 },
54 { 0x0940c, 0x00000000, 0x02000001 },
55 { 0x0a008, 0x00000000, 0x08000000 },
56 /* Wake Rate Limits */
57 { 0x0a090, 0xffffffff, 0x00000000 },
58 { 0x0a098, 0xffffffff, 0x03e80000 },
59 { 0x0a09c, 0xffffffff, 0x00280000 },
60 { 0x0a0a8, 0xffffffff, 0x0001e848 },
61 { 0x0a0ac, 0xffffffff, 0x00000019 },
62 /* Render/Video/Blitter Idle Max Count */
63 { 0x02054, 0x00000000, 0x0000000a },
64 { 0x12054, 0x00000000, 0x0000000a },
65 { 0x22054, 0x00000000, 0x0000000a },
66 /* RC Sleep / RCx Thresholds */
67 { 0x0a0b0, 0xffffffff, 0x00000000 },
68 { 0x0a0b4, 0xffffffff, 0x000003e8 },
69 { 0x0a0b8, 0xffffffff, 0x0000c350 },
70 /* RP Settings */
71 { 0x0a010, 0xffffffff, 0x000f4240 },
72 { 0x0a014, 0xffffffff, 0x12060000 },
73 { 0x0a02c, 0xffffffff, 0x0000e808 },
74 { 0x0a030, 0xffffffff, 0x0003bd08 },
75 { 0x0a068, 0xffffffff, 0x000101d0 },
76 { 0x0a06c, 0xffffffff, 0x00055730 },
77 { 0x0a070, 0xffffffff, 0x0000000a },
78 /* RP Control */
79 { 0x0a024, 0x00000000, 0x00000b92 },
80 /* HW RC6 Control */
81 { 0x0a090, 0x00000000, 0x88040000 },
82 /* Video Frequency Request */
83 { 0x0a00c, 0x00000000, 0x08000000 },
84 { 0 },
85};
86
87static const struct gt_reg haswell_gt_lock[] = {
88 { 0x0a248, 0xffffffff, 0x80000000 },
89 { 0x0a004, 0xffffffff, 0x00000010 },
90 { 0x0a080, 0xffffffff, 0x00000004 },
91 { 0x0a180, 0xffffffff, 0x80000000 },
92 { 0 },
93};
94
Aaron Durbin76c37002012-10-30 09:03:43 -050095/* some vga option roms are used for several chipsets but they only have one
96 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -070097 * the mapping ourselves
Aaron Durbin76c37002012-10-30 09:03:43 -050098 */
99
100u32 map_oprom_vendev(u32 vendev)
101{
Elyes HAOUAS69d658f2016-09-17 20:32:07 +0200102 u32 new_vendev = vendev;
Aaron Durbin76c37002012-10-30 09:03:43 -0500103
104 switch (vendev) {
Aaron Durbin71161292012-12-13 16:43:32 -0600105 case 0x80860402: /* GT1 Desktop */
106 case 0x80860406: /* GT1 Mobile */
107 case 0x8086040a: /* GT1 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800108 case 0x80860a06: /* GT1 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600109
110 case 0x80860412: /* GT2 Desktop */
111 case 0x80860416: /* GT2 Mobile */
112 case 0x8086041a: /* GT2 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800113 case 0x80860a16: /* GT2 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600114
115 case 0x80860422: /* GT3 Desktop */
116 case 0x80860426: /* GT3 Mobile */
117 case 0x8086042a: /* GT3 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800118 case 0x80860a26: /* GT3 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600119
Elyes HAOUAS69d658f2016-09-17 20:32:07 +0200120 new_vendev = 0x80860406; /* GT1 Mobile */
Aaron Durbin76c37002012-10-30 09:03:43 -0500121 break;
122 }
123
124 return new_vendev;
125}
126
Ronald G. Minnich4c8465c2013-09-30 15:57:21 -0700127/* GTT is the Global Translation Table for the graphics pipeline.
128 * It is used to translate graphics addresses to physical
129 * memory addresses. As in the CPU, GTTs map 4K pages.
130 * The setgtt function adds a further bit of flexibility:
131 * it allows you to set a range (the first two parameters) to point
132 * to a physical address (third parameter);the physical address is
133 * incremented by a count (fourth parameter) for each GTT in the
134 * range.
135 * Why do it this way? For ultrafast startup,
136 * we can point all the GTT entries to point to one page,
137 * and set that page to 0s:
138 * memset(physbase, 0, 4096);
139 * setgtt(0, 4250, physbase, 0);
140 * this takes about 2 ms, and is a win because zeroing
141 * the page takes a up to 200 ms.
142 * This call sets the GTT to point to a linear range of pages
143 * starting at physbase.
144 */
145
146#define GTT_PTE_BASE (2 << 20)
147
148void
149set_translation_table(int start, int end, u64 base, int inc)
150{
151 int i;
152
Elyes HAOUAS12df9502016-08-23 21:29:48 +0200153 for (i = start; i < end; i++){
Ronald G. Minnich4c8465c2013-09-30 15:57:21 -0700154 u64 physical_address = base + i*inc;
155 /* swizzle the 32:39 bits to 4:11 */
156 u32 word = physical_address | ((physical_address >> 28) & 0xff0) | 1;
157 /* note: we've confirmed by checking
158 * the values that mrc does no
159 * useful setup before we run this.
160 */
161 gtt_write(GTT_PTE_BASE + i * 4, word);
162 gtt_read(GTT_PTE_BASE + i * 4);
163 }
164}
165
Aaron Durbin76c37002012-10-30 09:03:43 -0500166static struct resource *gtt_res = NULL;
167
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700168u32 gtt_read(u32 reg)
Aaron Durbin76c37002012-10-30 09:03:43 -0500169{
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700170 u32 val;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800171 val = read32(res2mmio(gtt_res, reg, 0));
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700172 return val;
173
Aaron Durbin76c37002012-10-30 09:03:43 -0500174}
175
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700176void gtt_write(u32 reg, u32 data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500177{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800178 write32(res2mmio(gtt_res, reg, 0), data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500179}
180
Duncan Laurie356833d2013-07-09 15:40:27 -0700181static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask)
182{
183 u32 val = gtt_read(reg);
184 val &= andmask;
185 val |= ormask;
186 gtt_write(reg, val);
187}
188
189static inline void gtt_write_regs(const struct gt_reg *gt)
190{
191 for (; gt && gt->reg; gt++) {
192 if (gt->andmask)
193 gtt_rmw(gt->reg, gt->andmask, gt->ormask);
194 else
195 gtt_write(gt->reg, gt->ormask);
196 }
197}
198
Aaron Durbin76c37002012-10-30 09:03:43 -0500199#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700200int gtt_poll(u32 reg, u32 mask, u32 value)
Aaron Durbin76c37002012-10-30 09:03:43 -0500201{
202 unsigned try = GTT_RETRY;
203 u32 data;
204
205 while (try--) {
206 data = gtt_read(reg);
207 if ((data & mask) == value)
208 return 1;
209 udelay(10);
210 }
211
212 printk(BIOS_ERR, "GT init timeout\n");
213 return 0;
214}
215
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700216static void power_well_enable(void)
217{
218 gtt_write(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_ENABLE);
219 gtt_poll(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_STATE, HSW_PWR_WELL_STATE);
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500220
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700221 /* In the native graphics case, we've got about 20 ms.
222 * after we power up the the AUX channel until we can talk to it.
223 * So get that going right now. We can't turn on the panel, yet, just VDD.
224 */
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500225 if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) {
226 gtt_write(PCH_PP_CONTROL, PCH_PP_UNLOCK| EDP_FORCE_VDD | PANEL_POWER_RESET);
227 }
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700228}
229
Aaron Durbin76c37002012-10-30 09:03:43 -0500230static void gma_pm_init_pre_vbios(struct device *dev)
231{
Aaron Durbin76c37002012-10-30 09:03:43 -0500232 printk(BIOS_DEBUG, "GT Power Management Init\n");
233
234 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
235 if (!gtt_res || !gtt_res->base)
236 return;
237
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700238 power_well_enable();
239
Duncan Laurie67113e92013-01-10 13:23:04 -0800240 /*
241 * Enable RC6
242 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500243
Duncan Laurie67113e92013-01-10 13:23:04 -0800244 /* Enable Force Wake */
245 gtt_write(0x0a180, 1 << 5);
246 gtt_write(0x0a188, 0x00010001);
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100247 gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 1 << 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500248
Duncan Laurie356833d2013-07-09 15:40:27 -0700249 /* GT Settings */
250 gtt_write_regs(haswell_gt_setup);
Aaron Durbin76c37002012-10-30 09:03:43 -0500251
Duncan Laurie356833d2013-07-09 15:40:27 -0700252 /* Wait for Mailbox Ready */
253 gtt_poll(0x138124, (1 << 31), (0 << 31));
254 /* Mailbox Data - RC6 VIDS */
255 gtt_write(0x138128, 0x00000000);
256 /* Mailbox Command */
257 gtt_write(0x138124, 0x80000004);
258 /* Wait for Mailbox Ready */
259 gtt_poll(0x138124, (1 << 31), (0 << 31));
Aaron Durbin76c37002012-10-30 09:03:43 -0500260
Duncan Laurie356833d2013-07-09 15:40:27 -0700261 /* Enable PM Interrupts */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700262 gtt_write(GEN6_PMIER, GEN6_PM_MBOX_EVENT | GEN6_PM_THERMAL_EVENT |
263 GEN6_PM_RP_DOWN_TIMEOUT | GEN6_PM_RP_UP_THRESHOLD |
264 GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_UP_EI_EXPIRED |
265 GEN6_PM_RP_DOWN_EI_EXPIRED);
Aaron Durbin76c37002012-10-30 09:03:43 -0500266
Duncan Laurie67113e92013-01-10 13:23:04 -0800267 /* Enable RC6 in idle */
268 gtt_write(0x0a094, 0x00040000);
Duncan Laurie356833d2013-07-09 15:40:27 -0700269
270 /* PM Lock Settings */
271 gtt_write_regs(haswell_gt_lock);
Aaron Durbin76c37002012-10-30 09:03:43 -0500272}
273
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700274static void init_display_planes(void)
275{
276 int pipe, plane;
277
278 /* Disable cursor mode */
279 for (pipe = PIPE_A; pipe <= PIPE_C; pipe++) {
280 gtt_write(CURCNTR_IVB(pipe), CURSOR_MODE_DISABLE);
281 gtt_write(CURBASE_IVB(pipe), 0x00000000);
282 }
283
284 /* Disable primary plane and set surface base address*/
285 for (plane = PLANE_A; plane <= PLANE_C; plane++) {
286 gtt_write(DSPCNTR(plane), DISPLAY_PLANE_DISABLE);
287 gtt_write(DSPSURF(plane), 0x00000000);
288 }
289
290 /* Disable VGA display */
291 gtt_write(CPU_VGACNTRL, CPU_VGA_DISABLE);
292}
293
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700294static void gma_setup_panel(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500295{
296 struct northbridge_intel_haswell_config *conf = dev->chip_info;
297 u32 reg32;
298
299 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
300
Aaron Durbin76c37002012-10-30 09:03:43 -0500301 /* Setup Digital Port Hotplug */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700302 reg32 = gtt_read(PCH_PORT_HOTPLUG);
Aaron Durbin76c37002012-10-30 09:03:43 -0500303 if (!reg32) {
304 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
305 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
306 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700307 gtt_write(PCH_PORT_HOTPLUG, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500308 }
309
310 /* Setup Panel Power On Delays */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700311 reg32 = gtt_read(PCH_PP_ON_DELAYS);
Aaron Durbin76c37002012-10-30 09:03:43 -0500312 if (!reg32) {
313 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
314 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
315 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700316 gtt_write(PCH_PP_ON_DELAYS, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500317 }
318
319 /* Setup Panel Power Off Delays */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700320 reg32 = gtt_read(PCH_PP_OFF_DELAYS);
Aaron Durbin76c37002012-10-30 09:03:43 -0500321 if (!reg32) {
322 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
323 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700324 gtt_write(PCH_PP_OFF_DELAYS, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500325 }
326
327 /* Setup Panel Power Cycle Delay */
328 if (conf->gpu_panel_power_cycle_delay) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700329 reg32 = gtt_read(PCH_PP_DIVISOR);
Aaron Durbin76c37002012-10-30 09:03:43 -0500330 reg32 &= ~0xff;
331 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700332 gtt_write(PCH_PP_DIVISOR, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500333 }
334
335 /* Enable Backlight if needed */
336 if (conf->gpu_cpu_backlight) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700337 gtt_write(BLC_PWM_CPU_CTL2, BLC_PWM2_ENABLE);
338 gtt_write(BLC_PWM_CPU_CTL, conf->gpu_cpu_backlight);
Aaron Durbin76c37002012-10-30 09:03:43 -0500339 }
340 if (conf->gpu_pch_backlight) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700341 gtt_write(BLC_PWM_PCH_CTL1, BLM_PCH_PWM_ENABLE);
342 gtt_write(BLC_PWM_PCH_CTL2, conf->gpu_pch_backlight);
Aaron Durbin76c37002012-10-30 09:03:43 -0500343 }
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700344
345 /* Get display,pipeline,and DDI registers into a basic sane state */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700346 power_well_enable();
347
348 init_display_planes();
349
350 /* DDI-A params set:
351 bit 0: Display detected (RO)
352 bit 4: DDI A supports 4 lanes and DDI E is not used
353 bit 7: DDI buffer is idle
354 */
355 gtt_write(DDI_BUF_CTL_A, DDI_BUF_IS_IDLE | DDI_A_4_LANES | DDI_INIT_DISPLAY_DETECTED);
356
357 /* Set FDI registers - is this required? */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700358 gtt_write(_FDI_RXA_MISC, 0x00200090);
359 gtt_write(_FDI_RXA_MISC, 0x0a000000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700360
361 /* Enable the handshake with PCH display when processing reset */
362 gtt_write(NDE_RSTWRN_OPT, RST_PCH_HNDSHK_EN);
363
364 /* undocumented */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700365 gtt_write(0x42090, 0x04000000);
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700366 gtt_write(0x9840, 0x00000000);
367 gtt_write(0x42090, 0xa4000000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700368
369 gtt_write(SOUTH_DSPCLK_GATE_D, PCH_LP_PARTITION_LEVEL_DISABLE);
370
371 /* undocumented */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700372 gtt_write(0x42080, 0x00004000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700373
374 /* Prepare DDI buffers for DP and FDI */
375 intel_prepare_ddi();
376
377 /* Hot plug detect buffer enabled for port A */
378 gtt_write(DIGITAL_PORT_HOTPLUG_CNTRL, DIGITAL_PORTA_HOTPLUG_ENABLE);
379
380 /* Enable HPD buffer for digital port D and B */
381 gtt_write(PCH_PORT_HOTPLUG, PORTD_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE);
382
383 /* Bits 4:0 - Power cycle delay (default 0x6 --> 500ms)
384 Bits 31:8 - Reference divider (0x0004af ----> 24MHz)
385 */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700386 gtt_write(PCH_PP_DIVISOR, 0x0004af06);
Aaron Durbin76c37002012-10-30 09:03:43 -0500387}
388
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700389static void gma_pm_init_post_vbios(struct device *dev)
390{
Duncan Laurie356833d2013-07-09 15:40:27 -0700391 int cdclk = 0;
392 int devid = pci_read_config16(dev, PCI_DEVICE_ID);
393 int gpu_is_ulx = 0;
394
395 if (devid == 0x0a0e || devid == 0x0a1e)
396 gpu_is_ulx = 1;
397
398 /* CD Frequency */
Duncan Laurie3106d0f2013-08-12 13:51:22 -0700399 if ((gtt_read(0x42014) & 0x1000000) || gpu_is_ulx || haswell_is_ult())
400 cdclk = 0; /* fixed frequency */
401 else
402 cdclk = 2; /* variable frequency */
Duncan Laurie356833d2013-07-09 15:40:27 -0700403
Duncan Laurie356833d2013-07-09 15:40:27 -0700404 if (gpu_is_ulx || cdclk != 0)
405 gtt_rmw(0x130040, 0xf7ffffff, 0x04000000);
406 else
407 gtt_rmw(0x130040, 0xf3ffffff, 0x00000000);
408
409 /* More magic */
410 if (haswell_is_ult() || gpu_is_ulx) {
Duncan Laurie3106d0f2013-08-12 13:51:22 -0700411 if (!gpu_is_ulx)
Duncan Laurie356833d2013-07-09 15:40:27 -0700412 gtt_write(0x138128, 0x00000000);
413 else
414 gtt_write(0x138128, 0x00000001);
415 gtt_write(0x13812c, 0x00000000);
416 gtt_write(0x138124, 0x80000017);
417 }
418
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700419 /* Disable Force Wake */
420 gtt_write(0x0a188, 0x00010000);
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100421 gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 0 << 0);
Duncan Laurie356833d2013-07-09 15:40:27 -0700422 gtt_write(0x0a188, 0x00000001);
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700423}
424
Aaron Durbin76c37002012-10-30 09:03:43 -0500425static void gma_func0_init(struct device *dev)
426{
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700427 int lightup_ok = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500428 u32 reg32;
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500429 u64 physbase;
430 const struct resource *const linearfb_res =
431 find_resource(dev, PCI_BASE_ADDRESS_2);
432
433 if (!linearfb_res || !linearfb_res->base)
Nico Huber0df9a012017-05-20 02:26:12 +0200434 return;
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500435
Aaron Durbin76c37002012-10-30 09:03:43 -0500436 /* IGD needs to be Bus Master */
437 reg32 = pci_read_config32(dev, PCI_COMMAND);
438 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
439 pci_write_config32(dev, PCI_COMMAND, reg32);
440
441 /* Init graphics power management */
442 gma_pm_init_pre_vbios(dev);
443
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500444 /* Pre panel init */
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700445 gma_setup_panel(dev);
446
Nico Huberd4ebeaf2017-05-22 13:49:22 +0200447 if (IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) {
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500448 printk(BIOS_SPEW, "NATIVE graphics, run native enable\n");
449 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
450 gma_gfxinit(gtt_res->base, linearfb_res->base,
451 physbase, &lightup_ok);
452 gfx_set_init_done(1);
Arthur Heymans23cda3472016-12-18 16:03:52 +0100453 }
454
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700455 if (! lightup_ok) {
456 printk(BIOS_SPEW, "FUI did not run; using VBIOS\n");
Stefan Reinauerf1aabec2014-01-22 15:16:30 -0800457 mdelay(CONFIG_PRE_GRAPHICS_DELAY);
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700458 pci_dev_init(dev);
459 }
460
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500461 /* Post panel init */
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700462 gma_pm_init_post_vbios(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500463}
464
465static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
466{
467 if (!vendor || !device) {
468 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
469 pci_read_config32(dev, PCI_VENDOR_ID));
470 } else {
471 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
472 ((device & 0xffff) << 16) | (vendor & 0xffff));
473 }
474}
475
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100476const struct i915_gpu_controller_info *
477intel_gma_get_controller_info(void)
478{
479 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
480 if (!dev) {
481 return NULL;
482 }
483 struct northbridge_intel_haswell_config *chip = dev->chip_info;
484 return &chip->gfx;
485}
486
Alexander Couzens5eea4582015-04-12 22:18:55 +0200487static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100488{
489 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
490 if (!gfx) {
491 return;
492 }
493
494 drivers_intel_gma_displays_ssdt_generate(gfx);
495}
496
Patrick Rudolph9aca6432017-05-20 11:49:22 +0200497/* Enable SCI to ACPI _GPE._L06 */
498static void gma_enable_swsci(void)
499{
500 u16 reg16;
501
502 /* clear DMISCI status */
503 reg16 = inw(get_pmbase() + TCO1_STS);
504 reg16 &= DMISCI_STS;
505 outw(get_pmbase() + TCO1_STS, reg16);
506
507 /* clear and enable ACPI TCO SCI */
508 enable_tco_sci();
509}
510
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200511static unsigned long
512gma_write_acpi_tables(struct device *const dev,
513 unsigned long current,
514 struct acpi_rsdp *const rsdp)
515{
516 igd_opregion_t *opregion = (igd_opregion_t *)current;
517
Patrick Rudolph9aca6432017-05-20 11:49:22 +0200518 if (init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200519 return current;
520
521 current += sizeof(igd_opregion_t);
522
Patrick Rudolph9aca6432017-05-20 11:49:22 +0200523 gma_enable_swsci();
524
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200525 current = acpi_align_current(current);
526 return current;
527}
528
Aaron Durbin76c37002012-10-30 09:03:43 -0500529static struct pci_operations gma_pci_ops = {
530 .set_subsystem = gma_set_subsystem,
531};
532
533static struct device_operations gma_func0_ops = {
Vladimir Serbinenko30fe6122014-02-05 23:25:28 +0100534 .read_resources = pci_dev_read_resources,
Aaron Durbin76c37002012-10-30 09:03:43 -0500535 .set_resources = pci_dev_set_resources,
536 .enable_resources = pci_dev_enable_resources,
537 .init = gma_func0_init,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100538 .acpi_fill_ssdt_generator = gma_ssdt,
Aaron Durbin76c37002012-10-30 09:03:43 -0500539 .scan_bus = 0,
540 .enable = 0,
541 .ops_pci = &gma_pci_ops,
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200542 .write_acpi_tables = gma_write_acpi_tables,
Aaron Durbin76c37002012-10-30 09:03:43 -0500543};
544
Duncan Lauriedf7be712012-12-17 11:22:57 -0800545static const unsigned short pci_device_ids[] = {
546 0x0402, /* Desktop GT1 */
547 0x0412, /* Desktop GT2 */
548 0x0422, /* Desktop GT3 */
549 0x0406, /* Mobile GT1 */
550 0x0416, /* Mobile GT2 */
551 0x0426, /* Mobile GT3 */
552 0x0d16, /* Mobile 4+3 GT1 */
553 0x0d26, /* Mobile 4+3 GT2 */
554 0x0d36, /* Mobile 4+3 GT3 */
555 0x0a06, /* ULT GT1 */
556 0x0a16, /* ULT GT2 */
557 0x0a26, /* ULT GT3 */
558 0,
559};
Aaron Durbin76c37002012-10-30 09:03:43 -0500560
561static const struct pci_driver pch_lpc __pci_driver = {
562 .ops = &gma_func0_ops,
563 .vendor = PCI_VENDOR_ID_INTEL,
564 .devices = pci_device_ids,
565};