blob: f4cec68c06fc39d1159059d5db69e8c0753049d9 [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>
Matt DeVillier7c789702017-06-16 23:36:46 -050017#include <cbmem.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050018#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020019#include <bootmode.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050020#include <delay.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -070024#include <drivers/intel/gma/i915_reg.h>
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070025#include <drivers/intel/gma/i915.h>
Nico Huber18228162017-06-08 16:31:57 +020026#include <drivers/intel/gma/libgfxinit.h>
Duncan Laurie356833d2013-07-09 15:40:27 -070027#include <cpu/intel/haswell/haswell.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050028#include <drivers/intel/gma/opregion.h>
Matt DeVillier7c789702017-06-16 23:36:46 -050029#include <southbridge/intel/lynxpoint/nvs.h>
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070030#include <stdlib.h>
Ronald G. Minnich9518b562013-09-19 16:45:22 -070031#include <string.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050032
33#include "chip.h"
34#include "haswell.h"
35
Martin Roth33232602017-06-24 14:48:50 -060036#if IS_ENABLED(CONFIG_CHROMEOS)
Furquan Shaikhcb61ea72013-08-15 15:23:58 -070037#include <vendorcode/google/chromeos/chromeos.h>
38#endif
39
Duncan Laurie356833d2013-07-09 15:40:27 -070040struct gt_reg {
41 u32 reg;
42 u32 andmask;
43 u32 ormask;
44};
45
46static const struct gt_reg haswell_gt_setup[] = {
47 /* Enable Counters */
48 { 0x0a248, 0x00000000, 0x00000016 },
49 { 0x0a000, 0x00000000, 0x00070020 },
50 { 0x0a180, 0xff3fffff, 0x15000000 },
51 /* Enable DOP Clock Gating */
52 { 0x09424, 0x00000000, 0x000003fd },
53 /* Enable Unit Level Clock Gating */
54 { 0x09400, 0x00000000, 0x00000080 },
55 { 0x09404, 0x00000000, 0x40401000 },
56 { 0x09408, 0x00000000, 0x00000000 },
57 { 0x0940c, 0x00000000, 0x02000001 },
58 { 0x0a008, 0x00000000, 0x08000000 },
59 /* Wake Rate Limits */
60 { 0x0a090, 0xffffffff, 0x00000000 },
61 { 0x0a098, 0xffffffff, 0x03e80000 },
62 { 0x0a09c, 0xffffffff, 0x00280000 },
63 { 0x0a0a8, 0xffffffff, 0x0001e848 },
64 { 0x0a0ac, 0xffffffff, 0x00000019 },
65 /* Render/Video/Blitter Idle Max Count */
66 { 0x02054, 0x00000000, 0x0000000a },
67 { 0x12054, 0x00000000, 0x0000000a },
68 { 0x22054, 0x00000000, 0x0000000a },
69 /* RC Sleep / RCx Thresholds */
70 { 0x0a0b0, 0xffffffff, 0x00000000 },
71 { 0x0a0b4, 0xffffffff, 0x000003e8 },
72 { 0x0a0b8, 0xffffffff, 0x0000c350 },
73 /* RP Settings */
74 { 0x0a010, 0xffffffff, 0x000f4240 },
75 { 0x0a014, 0xffffffff, 0x12060000 },
76 { 0x0a02c, 0xffffffff, 0x0000e808 },
77 { 0x0a030, 0xffffffff, 0x0003bd08 },
78 { 0x0a068, 0xffffffff, 0x000101d0 },
79 { 0x0a06c, 0xffffffff, 0x00055730 },
80 { 0x0a070, 0xffffffff, 0x0000000a },
81 /* RP Control */
82 { 0x0a024, 0x00000000, 0x00000b92 },
83 /* HW RC6 Control */
84 { 0x0a090, 0x00000000, 0x88040000 },
85 /* Video Frequency Request */
86 { 0x0a00c, 0x00000000, 0x08000000 },
87 { 0 },
88};
89
90static const struct gt_reg haswell_gt_lock[] = {
91 { 0x0a248, 0xffffffff, 0x80000000 },
92 { 0x0a004, 0xffffffff, 0x00000010 },
93 { 0x0a080, 0xffffffff, 0x00000004 },
94 { 0x0a180, 0xffffffff, 0x80000000 },
95 { 0 },
96};
97
Aaron Durbin76c37002012-10-30 09:03:43 -050098/* some vga option roms are used for several chipsets but they only have one
99 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -0700100 * the mapping ourselves
Aaron Durbin76c37002012-10-30 09:03:43 -0500101 */
102
103u32 map_oprom_vendev(u32 vendev)
104{
Elyes HAOUAS69d658f2016-09-17 20:32:07 +0200105 u32 new_vendev = vendev;
Aaron Durbin76c37002012-10-30 09:03:43 -0500106
107 switch (vendev) {
Aaron Durbin71161292012-12-13 16:43:32 -0600108 case 0x80860402: /* GT1 Desktop */
109 case 0x80860406: /* GT1 Mobile */
110 case 0x8086040a: /* GT1 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800111 case 0x80860a06: /* GT1 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600112
113 case 0x80860412: /* GT2 Desktop */
114 case 0x80860416: /* GT2 Mobile */
115 case 0x8086041a: /* GT2 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800116 case 0x80860a16: /* GT2 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600117
118 case 0x80860422: /* GT3 Desktop */
119 case 0x80860426: /* GT3 Mobile */
120 case 0x8086042a: /* GT3 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800121 case 0x80860a26: /* GT3 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600122
Elyes HAOUAS69d658f2016-09-17 20:32:07 +0200123 new_vendev = 0x80860406; /* GT1 Mobile */
Aaron Durbin76c37002012-10-30 09:03:43 -0500124 break;
125 }
126
127 return new_vendev;
128}
129
Ronald G. Minnich4c8465c2013-09-30 15:57:21 -0700130/* GTT is the Global Translation Table for the graphics pipeline.
131 * It is used to translate graphics addresses to physical
132 * memory addresses. As in the CPU, GTTs map 4K pages.
133 * The setgtt function adds a further bit of flexibility:
134 * it allows you to set a range (the first two parameters) to point
135 * to a physical address (third parameter);the physical address is
136 * incremented by a count (fourth parameter) for each GTT in the
137 * range.
138 * Why do it this way? For ultrafast startup,
139 * we can point all the GTT entries to point to one page,
140 * and set that page to 0s:
141 * memset(physbase, 0, 4096);
142 * setgtt(0, 4250, physbase, 0);
143 * this takes about 2 ms, and is a win because zeroing
144 * the page takes a up to 200 ms.
145 * This call sets the GTT to point to a linear range of pages
146 * starting at physbase.
147 */
148
149#define GTT_PTE_BASE (2 << 20)
150
151void
152set_translation_table(int start, int end, u64 base, int inc)
153{
154 int i;
155
Elyes HAOUAS12df9502016-08-23 21:29:48 +0200156 for (i = start; i < end; i++){
Ronald G. Minnich4c8465c2013-09-30 15:57:21 -0700157 u64 physical_address = base + i*inc;
158 /* swizzle the 32:39 bits to 4:11 */
159 u32 word = physical_address | ((physical_address >> 28) & 0xff0) | 1;
160 /* note: we've confirmed by checking
161 * the values that mrc does no
162 * useful setup before we run this.
163 */
164 gtt_write(GTT_PTE_BASE + i * 4, word);
165 gtt_read(GTT_PTE_BASE + i * 4);
166 }
167}
168
Aaron Durbin76c37002012-10-30 09:03:43 -0500169static struct resource *gtt_res = NULL;
170
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700171u32 gtt_read(u32 reg)
Aaron Durbin76c37002012-10-30 09:03:43 -0500172{
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700173 u32 val;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800174 val = read32(res2mmio(gtt_res, reg, 0));
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700175 return val;
176
Aaron Durbin76c37002012-10-30 09:03:43 -0500177}
178
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700179void gtt_write(u32 reg, u32 data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500180{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800181 write32(res2mmio(gtt_res, reg, 0), data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500182}
183
Duncan Laurie356833d2013-07-09 15:40:27 -0700184static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask)
185{
186 u32 val = gtt_read(reg);
187 val &= andmask;
188 val |= ormask;
189 gtt_write(reg, val);
190}
191
192static inline void gtt_write_regs(const struct gt_reg *gt)
193{
194 for (; gt && gt->reg; gt++) {
195 if (gt->andmask)
196 gtt_rmw(gt->reg, gt->andmask, gt->ormask);
197 else
198 gtt_write(gt->reg, gt->ormask);
199 }
200}
201
Aaron Durbin76c37002012-10-30 09:03:43 -0500202#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700203int gtt_poll(u32 reg, u32 mask, u32 value)
Aaron Durbin76c37002012-10-30 09:03:43 -0500204{
205 unsigned try = GTT_RETRY;
206 u32 data;
207
208 while (try--) {
209 data = gtt_read(reg);
210 if ((data & mask) == value)
211 return 1;
212 udelay(10);
213 }
214
215 printk(BIOS_ERR, "GT init timeout\n");
216 return 0;
217}
218
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200219uintptr_t gma_get_gnvs_aslb(const void *gnvs)
220{
221 const global_nvs_t *gnvs_ptr = gnvs;
222 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
223}
224
225void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
226{
227 global_nvs_t *gnvs_ptr = gnvs;
228 if (gnvs_ptr)
229 gnvs_ptr->aslb = aslb;
230}
231
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700232static void power_well_enable(void)
233{
234 gtt_write(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_ENABLE);
235 gtt_poll(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_STATE, HSW_PWR_WELL_STATE);
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500236
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700237 /* In the native graphics case, we've got about 20 ms.
238 * after we power up the the AUX channel until we can talk to it.
239 * So get that going right now. We can't turn on the panel, yet, just VDD.
240 */
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500241 if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) {
242 gtt_write(PCH_PP_CONTROL, PCH_PP_UNLOCK| EDP_FORCE_VDD | PANEL_POWER_RESET);
243 }
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700244}
245
Aaron Durbin76c37002012-10-30 09:03:43 -0500246static void gma_pm_init_pre_vbios(struct device *dev)
247{
Aaron Durbin76c37002012-10-30 09:03:43 -0500248 printk(BIOS_DEBUG, "GT Power Management Init\n");
249
250 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
251 if (!gtt_res || !gtt_res->base)
252 return;
253
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700254 power_well_enable();
255
Duncan Laurie67113e92013-01-10 13:23:04 -0800256 /*
257 * Enable RC6
258 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500259
Duncan Laurie67113e92013-01-10 13:23:04 -0800260 /* Enable Force Wake */
261 gtt_write(0x0a180, 1 << 5);
262 gtt_write(0x0a188, 0x00010001);
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100263 gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 1 << 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500264
Duncan Laurie356833d2013-07-09 15:40:27 -0700265 /* GT Settings */
266 gtt_write_regs(haswell_gt_setup);
Aaron Durbin76c37002012-10-30 09:03:43 -0500267
Duncan Laurie356833d2013-07-09 15:40:27 -0700268 /* Wait for Mailbox Ready */
Ryan Salsamendifa0725d2017-06-30 17:29:37 -0700269 gtt_poll(0x138124, (1UL << 31), (0UL << 31));
Duncan Laurie356833d2013-07-09 15:40:27 -0700270 /* Mailbox Data - RC6 VIDS */
271 gtt_write(0x138128, 0x00000000);
272 /* Mailbox Command */
273 gtt_write(0x138124, 0x80000004);
274 /* Wait for Mailbox Ready */
Ryan Salsamendifa0725d2017-06-30 17:29:37 -0700275 gtt_poll(0x138124, (1UL << 31), (0UL << 31));
Aaron Durbin76c37002012-10-30 09:03:43 -0500276
Duncan Laurie356833d2013-07-09 15:40:27 -0700277 /* Enable PM Interrupts */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700278 gtt_write(GEN6_PMIER, GEN6_PM_MBOX_EVENT | GEN6_PM_THERMAL_EVENT |
279 GEN6_PM_RP_DOWN_TIMEOUT | GEN6_PM_RP_UP_THRESHOLD |
280 GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_UP_EI_EXPIRED |
281 GEN6_PM_RP_DOWN_EI_EXPIRED);
Aaron Durbin76c37002012-10-30 09:03:43 -0500282
Duncan Laurie67113e92013-01-10 13:23:04 -0800283 /* Enable RC6 in idle */
284 gtt_write(0x0a094, 0x00040000);
Duncan Laurie356833d2013-07-09 15:40:27 -0700285
286 /* PM Lock Settings */
287 gtt_write_regs(haswell_gt_lock);
Aaron Durbin76c37002012-10-30 09:03:43 -0500288}
289
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700290static void init_display_planes(void)
291{
292 int pipe, plane;
293
294 /* Disable cursor mode */
295 for (pipe = PIPE_A; pipe <= PIPE_C; pipe++) {
296 gtt_write(CURCNTR_IVB(pipe), CURSOR_MODE_DISABLE);
297 gtt_write(CURBASE_IVB(pipe), 0x00000000);
298 }
299
300 /* Disable primary plane and set surface base address*/
301 for (plane = PLANE_A; plane <= PLANE_C; plane++) {
302 gtt_write(DSPCNTR(plane), DISPLAY_PLANE_DISABLE);
303 gtt_write(DSPSURF(plane), 0x00000000);
304 }
305
306 /* Disable VGA display */
307 gtt_write(CPU_VGACNTRL, CPU_VGA_DISABLE);
308}
309
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700310static void gma_setup_panel(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500311{
312 struct northbridge_intel_haswell_config *conf = dev->chip_info;
313 u32 reg32;
314
315 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
316
Aaron Durbin76c37002012-10-30 09:03:43 -0500317 /* Setup Digital Port Hotplug */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700318 reg32 = gtt_read(PCH_PORT_HOTPLUG);
Aaron Durbin76c37002012-10-30 09:03:43 -0500319 if (!reg32) {
320 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
321 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
322 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700323 gtt_write(PCH_PORT_HOTPLUG, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500324 }
325
326 /* Setup Panel Power On Delays */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700327 reg32 = gtt_read(PCH_PP_ON_DELAYS);
Aaron Durbin76c37002012-10-30 09:03:43 -0500328 if (!reg32) {
329 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
330 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
331 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700332 gtt_write(PCH_PP_ON_DELAYS, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500333 }
334
335 /* Setup Panel Power Off Delays */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700336 reg32 = gtt_read(PCH_PP_OFF_DELAYS);
Aaron Durbin76c37002012-10-30 09:03:43 -0500337 if (!reg32) {
338 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
339 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700340 gtt_write(PCH_PP_OFF_DELAYS, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500341 }
342
343 /* Setup Panel Power Cycle Delay */
344 if (conf->gpu_panel_power_cycle_delay) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700345 reg32 = gtt_read(PCH_PP_DIVISOR);
Aaron Durbin76c37002012-10-30 09:03:43 -0500346 reg32 &= ~0xff;
347 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700348 gtt_write(PCH_PP_DIVISOR, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500349 }
350
351 /* Enable Backlight if needed */
352 if (conf->gpu_cpu_backlight) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700353 gtt_write(BLC_PWM_CPU_CTL2, BLC_PWM2_ENABLE);
354 gtt_write(BLC_PWM_CPU_CTL, conf->gpu_cpu_backlight);
Aaron Durbin76c37002012-10-30 09:03:43 -0500355 }
356 if (conf->gpu_pch_backlight) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700357 gtt_write(BLC_PWM_PCH_CTL1, BLM_PCH_PWM_ENABLE);
358 gtt_write(BLC_PWM_PCH_CTL2, conf->gpu_pch_backlight);
Aaron Durbin76c37002012-10-30 09:03:43 -0500359 }
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700360
361 /* Get display,pipeline,and DDI registers into a basic sane state */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700362 power_well_enable();
363
364 init_display_planes();
365
366 /* DDI-A params set:
367 bit 0: Display detected (RO)
368 bit 4: DDI A supports 4 lanes and DDI E is not used
369 bit 7: DDI buffer is idle
370 */
Tristan Corrick1a73eb02018-10-31 02:27:29 +1300371 reg32 = DDI_BUF_IS_IDLE | DDI_INIT_DISPLAY_DETECTED;
372 if (!conf->gpu_ddi_e_connected)
373 reg32 |= DDI_A_4_LANES;
374 gtt_write(DDI_BUF_CTL_A, reg32);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700375
376 /* Set FDI registers - is this required? */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700377 gtt_write(_FDI_RXA_MISC, 0x00200090);
378 gtt_write(_FDI_RXA_MISC, 0x0a000000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700379
380 /* Enable the handshake with PCH display when processing reset */
381 gtt_write(NDE_RSTWRN_OPT, RST_PCH_HNDSHK_EN);
382
383 /* undocumented */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700384 gtt_write(0x42090, 0x04000000);
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700385 gtt_write(0x9840, 0x00000000);
386 gtt_write(0x42090, 0xa4000000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700387
388 gtt_write(SOUTH_DSPCLK_GATE_D, PCH_LP_PARTITION_LEVEL_DISABLE);
389
390 /* undocumented */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700391 gtt_write(0x42080, 0x00004000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700392
393 /* Prepare DDI buffers for DP and FDI */
394 intel_prepare_ddi();
395
396 /* Hot plug detect buffer enabled for port A */
397 gtt_write(DIGITAL_PORT_HOTPLUG_CNTRL, DIGITAL_PORTA_HOTPLUG_ENABLE);
398
399 /* Enable HPD buffer for digital port D and B */
400 gtt_write(PCH_PORT_HOTPLUG, PORTD_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE);
401
402 /* Bits 4:0 - Power cycle delay (default 0x6 --> 500ms)
403 Bits 31:8 - Reference divider (0x0004af ----> 24MHz)
404 */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700405 gtt_write(PCH_PP_DIVISOR, 0x0004af06);
Aaron Durbin76c37002012-10-30 09:03:43 -0500406}
407
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700408static void gma_pm_init_post_vbios(struct device *dev)
409{
Duncan Laurie356833d2013-07-09 15:40:27 -0700410 int cdclk = 0;
411 int devid = pci_read_config16(dev, PCI_DEVICE_ID);
412 int gpu_is_ulx = 0;
413
414 if (devid == 0x0a0e || devid == 0x0a1e)
415 gpu_is_ulx = 1;
416
417 /* CD Frequency */
Duncan Laurie3106d0f2013-08-12 13:51:22 -0700418 if ((gtt_read(0x42014) & 0x1000000) || gpu_is_ulx || haswell_is_ult())
419 cdclk = 0; /* fixed frequency */
420 else
421 cdclk = 2; /* variable frequency */
Duncan Laurie356833d2013-07-09 15:40:27 -0700422
Duncan Laurie356833d2013-07-09 15:40:27 -0700423 if (gpu_is_ulx || cdclk != 0)
424 gtt_rmw(0x130040, 0xf7ffffff, 0x04000000);
425 else
426 gtt_rmw(0x130040, 0xf3ffffff, 0x00000000);
427
428 /* More magic */
429 if (haswell_is_ult() || gpu_is_ulx) {
Duncan Laurie3106d0f2013-08-12 13:51:22 -0700430 if (!gpu_is_ulx)
Duncan Laurie356833d2013-07-09 15:40:27 -0700431 gtt_write(0x138128, 0x00000000);
432 else
433 gtt_write(0x138128, 0x00000001);
434 gtt_write(0x13812c, 0x00000000);
435 gtt_write(0x138124, 0x80000017);
436 }
437
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700438 /* Disable Force Wake */
439 gtt_write(0x0a188, 0x00010000);
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100440 gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 0 << 0);
Duncan Laurie356833d2013-07-09 15:40:27 -0700441 gtt_write(0x0a188, 0x00000001);
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700442}
443
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200444/* Enable SCI to ACPI _GPE._L06 */
445static void gma_enable_swsci(void)
446{
447 u16 reg16;
448
449 /* clear DMISCI status */
450 reg16 = inw(get_pmbase() + TCO1_STS);
451 reg16 &= DMISCI_STS;
452 outw(get_pmbase() + TCO1_STS, reg16);
453
454 /* clear and enable ACPI TCO SCI */
455 enable_tco_sci();
456}
457
Aaron Durbin76c37002012-10-30 09:03:43 -0500458static void gma_func0_init(struct device *dev)
459{
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700460 int lightup_ok = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500461 u32 reg32;
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500462
Aaron Durbin76c37002012-10-30 09:03:43 -0500463 /* IGD needs to be Bus Master */
464 reg32 = pci_read_config32(dev, PCI_COMMAND);
465 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
466 pci_write_config32(dev, PCI_COMMAND, reg32);
467
468 /* Init graphics power management */
469 gma_pm_init_pre_vbios(dev);
470
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500471 /* Pre panel init */
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700472 gma_setup_panel(dev);
473
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200474 int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1;
475
Nico Huberd4ebeaf2017-05-22 13:49:22 +0200476 if (IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200477 if (vga_disable) {
478 printk(BIOS_INFO,
479 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
480 } else {
481 printk(BIOS_SPEW, "NATIVE graphics, run native enable\n");
482 gma_gfxinit(&lightup_ok);
483 gfx_set_init_done(1);
484 }
Arthur Heymans23cda3472016-12-18 16:03:52 +0100485 }
486
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700487 if (! lightup_ok) {
488 printk(BIOS_SPEW, "FUI did not run; using VBIOS\n");
Stefan Reinauerf1aabec2014-01-22 15:16:30 -0800489 mdelay(CONFIG_PRE_GRAPHICS_DELAY);
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700490 pci_dev_init(dev);
491 }
492
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500493 /* Post panel init */
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700494 gma_pm_init_post_vbios(dev);
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200495
496 gma_enable_swsci();
497 intel_gma_restore_opregion();
Aaron Durbin76c37002012-10-30 09:03:43 -0500498}
499
Elyes HAOUASb60920d2018-09-20 17:38:38 +0200500static void gma_set_subsystem(struct device *dev, unsigned int vendor,
501 unsigned int device)
Aaron Durbin76c37002012-10-30 09:03:43 -0500502{
503 if (!vendor || !device) {
504 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
505 pci_read_config32(dev, PCI_VENDOR_ID));
506 } else {
507 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
508 ((device & 0xffff) << 16) | (vendor & 0xffff));
509 }
510}
511
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100512const struct i915_gpu_controller_info *
513intel_gma_get_controller_info(void)
514{
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200515 struct device *dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100516 if (!dev) {
517 return NULL;
518 }
519 struct northbridge_intel_haswell_config *chip = dev->chip_info;
520 return &chip->gfx;
521}
522
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200523static void gma_ssdt(struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100524{
525 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
526 if (!gfx) {
527 return;
528 }
529
530 drivers_intel_gma_displays_ssdt_generate(gfx);
531}
532
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200533static unsigned long
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200534gma_write_acpi_tables(struct device *const dev, unsigned long current,
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200535 struct acpi_rsdp *const rsdp)
536{
537 igd_opregion_t *opregion = (igd_opregion_t *)current;
Matt DeVillier7c789702017-06-16 23:36:46 -0500538 global_nvs_t *gnvs;
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200539
Matt DeVillierebe08e02017-07-14 13:28:42 -0500540 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200541 return current;
542
543 current += sizeof(igd_opregion_t);
544
Matt DeVillier7c789702017-06-16 23:36:46 -0500545 /* GNVS has been already set up */
546 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
547 if (gnvs) {
548 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200549 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Matt DeVillier7c789702017-06-16 23:36:46 -0500550 } else {
551 printk(BIOS_ERR, "Error: GNVS table not found.\n");
552 }
553
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200554 current = acpi_align_current(current);
555 return current;
556}
557
Aaron Durbin76c37002012-10-30 09:03:43 -0500558static struct pci_operations gma_pci_ops = {
559 .set_subsystem = gma_set_subsystem,
560};
561
562static struct device_operations gma_func0_ops = {
Vladimir Serbinenko30fe6122014-02-05 23:25:28 +0100563 .read_resources = pci_dev_read_resources,
Aaron Durbin76c37002012-10-30 09:03:43 -0500564 .set_resources = pci_dev_set_resources,
565 .enable_resources = pci_dev_enable_resources,
566 .init = gma_func0_init,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100567 .acpi_fill_ssdt_generator = gma_ssdt,
Aaron Durbin76c37002012-10-30 09:03:43 -0500568 .scan_bus = 0,
569 .enable = 0,
570 .ops_pci = &gma_pci_ops,
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200571 .write_acpi_tables = gma_write_acpi_tables,
Aaron Durbin76c37002012-10-30 09:03:43 -0500572};
573
Duncan Lauriedf7be712012-12-17 11:22:57 -0800574static const unsigned short pci_device_ids[] = {
575 0x0402, /* Desktop GT1 */
576 0x0412, /* Desktop GT2 */
577 0x0422, /* Desktop GT3 */
578 0x0406, /* Mobile GT1 */
579 0x0416, /* Mobile GT2 */
580 0x0426, /* Mobile GT3 */
581 0x0d16, /* Mobile 4+3 GT1 */
582 0x0d26, /* Mobile 4+3 GT2 */
583 0x0d36, /* Mobile 4+3 GT3 */
584 0x0a06, /* ULT GT1 */
585 0x0a16, /* ULT GT2 */
586 0x0a26, /* ULT GT3 */
587 0,
588};
Aaron Durbin76c37002012-10-30 09:03:43 -0500589
590static const struct pci_driver pch_lpc __pci_driver = {
591 .ops = &gma_func0_ops,
592 .vendor = PCI_VENDOR_ID_INTEL,
593 .devices = pci_device_ids,
594};