blob: 0fd0228268c4da3b59e69827765c5955095328bf [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>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020017#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020018#include <device/pci_ops.h>
Matt DeVillier7c789702017-06-16 23:36:46 -050019#include <cbmem.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050020#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020021#include <bootmode.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050022#include <delay.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -070026#include <drivers/intel/gma/i915_reg.h>
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070027#include <drivers/intel/gma/i915.h>
Nico Huber18228162017-06-08 16:31:57 +020028#include <drivers/intel/gma/libgfxinit.h>
Duncan Laurie356833d2013-07-09 15:40:27 -070029#include <cpu/intel/haswell/haswell.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050030#include <drivers/intel/gma/opregion.h>
Matt DeVillier7c789702017-06-16 23:36:46 -050031#include <southbridge/intel/lynxpoint/nvs.h>
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070032#include <stdlib.h>
Ronald G. Minnich9518b562013-09-19 16:45:22 -070033#include <string.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050034
35#include "chip.h"
36#include "haswell.h"
37
Julius Wernercd49cce2019-03-05 16:53:33 -080038#if CONFIG(CHROMEOS)
Furquan Shaikhcb61ea72013-08-15 15:23:58 -070039#include <vendorcode/google/chromeos/chromeos.h>
40#endif
41
Duncan Laurie356833d2013-07-09 15:40:27 -070042struct gt_reg {
43 u32 reg;
44 u32 andmask;
45 u32 ormask;
46};
47
48static const struct gt_reg haswell_gt_setup[] = {
49 /* Enable Counters */
50 { 0x0a248, 0x00000000, 0x00000016 },
51 { 0x0a000, 0x00000000, 0x00070020 },
52 { 0x0a180, 0xff3fffff, 0x15000000 },
53 /* Enable DOP Clock Gating */
54 { 0x09424, 0x00000000, 0x000003fd },
55 /* Enable Unit Level Clock Gating */
56 { 0x09400, 0x00000000, 0x00000080 },
57 { 0x09404, 0x00000000, 0x40401000 },
58 { 0x09408, 0x00000000, 0x00000000 },
59 { 0x0940c, 0x00000000, 0x02000001 },
60 { 0x0a008, 0x00000000, 0x08000000 },
61 /* Wake Rate Limits */
62 { 0x0a090, 0xffffffff, 0x00000000 },
63 { 0x0a098, 0xffffffff, 0x03e80000 },
64 { 0x0a09c, 0xffffffff, 0x00280000 },
65 { 0x0a0a8, 0xffffffff, 0x0001e848 },
66 { 0x0a0ac, 0xffffffff, 0x00000019 },
67 /* Render/Video/Blitter Idle Max Count */
68 { 0x02054, 0x00000000, 0x0000000a },
69 { 0x12054, 0x00000000, 0x0000000a },
70 { 0x22054, 0x00000000, 0x0000000a },
71 /* RC Sleep / RCx Thresholds */
72 { 0x0a0b0, 0xffffffff, 0x00000000 },
73 { 0x0a0b4, 0xffffffff, 0x000003e8 },
74 { 0x0a0b8, 0xffffffff, 0x0000c350 },
75 /* RP Settings */
76 { 0x0a010, 0xffffffff, 0x000f4240 },
77 { 0x0a014, 0xffffffff, 0x12060000 },
78 { 0x0a02c, 0xffffffff, 0x0000e808 },
79 { 0x0a030, 0xffffffff, 0x0003bd08 },
80 { 0x0a068, 0xffffffff, 0x000101d0 },
81 { 0x0a06c, 0xffffffff, 0x00055730 },
82 { 0x0a070, 0xffffffff, 0x0000000a },
83 /* RP Control */
84 { 0x0a024, 0x00000000, 0x00000b92 },
85 /* HW RC6 Control */
86 { 0x0a090, 0x00000000, 0x88040000 },
87 /* Video Frequency Request */
88 { 0x0a00c, 0x00000000, 0x08000000 },
89 { 0 },
90};
91
92static const struct gt_reg haswell_gt_lock[] = {
93 { 0x0a248, 0xffffffff, 0x80000000 },
94 { 0x0a004, 0xffffffff, 0x00000010 },
95 { 0x0a080, 0xffffffff, 0x00000004 },
96 { 0x0a180, 0xffffffff, 0x80000000 },
97 { 0 },
98};
99
Aaron Durbin76c37002012-10-30 09:03:43 -0500100/* some vga option roms are used for several chipsets but they only have one
101 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -0700102 * the mapping ourselves
Aaron Durbin76c37002012-10-30 09:03:43 -0500103 */
104
105u32 map_oprom_vendev(u32 vendev)
106{
Elyes HAOUAS69d658f2016-09-17 20:32:07 +0200107 u32 new_vendev = vendev;
Aaron Durbin76c37002012-10-30 09:03:43 -0500108
109 switch (vendev) {
Aaron Durbin71161292012-12-13 16:43:32 -0600110 case 0x80860402: /* GT1 Desktop */
111 case 0x80860406: /* GT1 Mobile */
112 case 0x8086040a: /* GT1 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800113 case 0x80860a06: /* GT1 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600114
115 case 0x80860412: /* GT2 Desktop */
116 case 0x80860416: /* GT2 Mobile */
117 case 0x8086041a: /* GT2 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800118 case 0x80860a16: /* GT2 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600119
120 case 0x80860422: /* GT3 Desktop */
121 case 0x80860426: /* GT3 Mobile */
122 case 0x8086042a: /* GT3 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800123 case 0x80860a26: /* GT3 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600124
Elyes HAOUAS69d658f2016-09-17 20:32:07 +0200125 new_vendev = 0x80860406; /* GT1 Mobile */
Aaron Durbin76c37002012-10-30 09:03:43 -0500126 break;
127 }
128
129 return new_vendev;
130}
131
Ronald G. Minnich4c8465c2013-09-30 15:57:21 -0700132/* GTT is the Global Translation Table for the graphics pipeline.
133 * It is used to translate graphics addresses to physical
134 * memory addresses. As in the CPU, GTTs map 4K pages.
135 * The setgtt function adds a further bit of flexibility:
136 * it allows you to set a range (the first two parameters) to point
137 * to a physical address (third parameter);the physical address is
138 * incremented by a count (fourth parameter) for each GTT in the
139 * range.
140 * Why do it this way? For ultrafast startup,
141 * we can point all the GTT entries to point to one page,
142 * and set that page to 0s:
143 * memset(physbase, 0, 4096);
144 * setgtt(0, 4250, physbase, 0);
145 * this takes about 2 ms, and is a win because zeroing
146 * the page takes a up to 200 ms.
147 * This call sets the GTT to point to a linear range of pages
148 * starting at physbase.
149 */
150
151#define GTT_PTE_BASE (2 << 20)
152
153void
154set_translation_table(int start, int end, u64 base, int inc)
155{
156 int i;
157
Elyes HAOUAS12df9502016-08-23 21:29:48 +0200158 for (i = start; i < end; i++){
Ronald G. Minnich4c8465c2013-09-30 15:57:21 -0700159 u64 physical_address = base + i*inc;
160 /* swizzle the 32:39 bits to 4:11 */
161 u32 word = physical_address | ((physical_address >> 28) & 0xff0) | 1;
162 /* note: we've confirmed by checking
163 * the values that mrc does no
164 * useful setup before we run this.
165 */
166 gtt_write(GTT_PTE_BASE + i * 4, word);
167 gtt_read(GTT_PTE_BASE + i * 4);
168 }
169}
170
Aaron Durbin76c37002012-10-30 09:03:43 -0500171static struct resource *gtt_res = NULL;
172
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700173u32 gtt_read(u32 reg)
Aaron Durbin76c37002012-10-30 09:03:43 -0500174{
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700175 u32 val;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800176 val = read32(res2mmio(gtt_res, reg, 0));
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700177 return val;
178
Aaron Durbin76c37002012-10-30 09:03:43 -0500179}
180
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700181void gtt_write(u32 reg, u32 data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500182{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800183 write32(res2mmio(gtt_res, reg, 0), data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500184}
185
Duncan Laurie356833d2013-07-09 15:40:27 -0700186static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask)
187{
188 u32 val = gtt_read(reg);
189 val &= andmask;
190 val |= ormask;
191 gtt_write(reg, val);
192}
193
194static inline void gtt_write_regs(const struct gt_reg *gt)
195{
196 for (; gt && gt->reg; gt++) {
197 if (gt->andmask)
198 gtt_rmw(gt->reg, gt->andmask, gt->ormask);
199 else
200 gtt_write(gt->reg, gt->ormask);
201 }
202}
203
Aaron Durbin76c37002012-10-30 09:03:43 -0500204#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700205int gtt_poll(u32 reg, u32 mask, u32 value)
Aaron Durbin76c37002012-10-30 09:03:43 -0500206{
207 unsigned try = GTT_RETRY;
208 u32 data;
209
210 while (try--) {
211 data = gtt_read(reg);
212 if ((data & mask) == value)
213 return 1;
214 udelay(10);
215 }
216
217 printk(BIOS_ERR, "GT init timeout\n");
218 return 0;
219}
220
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200221uintptr_t gma_get_gnvs_aslb(const void *gnvs)
222{
223 const global_nvs_t *gnvs_ptr = gnvs;
224 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
225}
226
227void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
228{
229 global_nvs_t *gnvs_ptr = gnvs;
230 if (gnvs_ptr)
231 gnvs_ptr->aslb = aslb;
232}
233
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700234static void power_well_enable(void)
235{
236 gtt_write(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_ENABLE);
237 gtt_poll(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_STATE, HSW_PWR_WELL_STATE);
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500238
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700239 /* In the native graphics case, we've got about 20 ms.
Jonathan Neuschäfer45e6c822018-12-11 17:53:07 +0100240 * after we power up the AUX channel until we can talk to it.
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700241 * So get that going right now. We can't turn on the panel, yet, just VDD.
242 */
Julius Wernercd49cce2019-03-05 16:53:33 -0800243 if (CONFIG(MAINBOARD_DO_NATIVE_VGA_INIT)) {
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500244 gtt_write(PCH_PP_CONTROL, PCH_PP_UNLOCK| EDP_FORCE_VDD | PANEL_POWER_RESET);
245 }
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700246}
247
Aaron Durbin76c37002012-10-30 09:03:43 -0500248static void gma_pm_init_pre_vbios(struct device *dev)
249{
Aaron Durbin76c37002012-10-30 09:03:43 -0500250 printk(BIOS_DEBUG, "GT Power Management Init\n");
251
252 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
253 if (!gtt_res || !gtt_res->base)
254 return;
255
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700256 power_well_enable();
257
Duncan Laurie67113e92013-01-10 13:23:04 -0800258 /*
259 * Enable RC6
260 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500261
Duncan Laurie67113e92013-01-10 13:23:04 -0800262 /* Enable Force Wake */
263 gtt_write(0x0a180, 1 << 5);
264 gtt_write(0x0a188, 0x00010001);
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100265 gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 1 << 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500266
Duncan Laurie356833d2013-07-09 15:40:27 -0700267 /* GT Settings */
268 gtt_write_regs(haswell_gt_setup);
Aaron Durbin76c37002012-10-30 09:03:43 -0500269
Duncan Laurie356833d2013-07-09 15:40:27 -0700270 /* Wait for Mailbox Ready */
Ryan Salsamendifa0725d2017-06-30 17:29:37 -0700271 gtt_poll(0x138124, (1UL << 31), (0UL << 31));
Duncan Laurie356833d2013-07-09 15:40:27 -0700272 /* Mailbox Data - RC6 VIDS */
273 gtt_write(0x138128, 0x00000000);
274 /* Mailbox Command */
275 gtt_write(0x138124, 0x80000004);
276 /* Wait for Mailbox Ready */
Ryan Salsamendifa0725d2017-06-30 17:29:37 -0700277 gtt_poll(0x138124, (1UL << 31), (0UL << 31));
Aaron Durbin76c37002012-10-30 09:03:43 -0500278
Duncan Laurie356833d2013-07-09 15:40:27 -0700279 /* Enable PM Interrupts */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700280 gtt_write(GEN6_PMIER, GEN6_PM_MBOX_EVENT | GEN6_PM_THERMAL_EVENT |
281 GEN6_PM_RP_DOWN_TIMEOUT | GEN6_PM_RP_UP_THRESHOLD |
282 GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_UP_EI_EXPIRED |
283 GEN6_PM_RP_DOWN_EI_EXPIRED);
Aaron Durbin76c37002012-10-30 09:03:43 -0500284
Duncan Laurie67113e92013-01-10 13:23:04 -0800285 /* Enable RC6 in idle */
286 gtt_write(0x0a094, 0x00040000);
Duncan Laurie356833d2013-07-09 15:40:27 -0700287
288 /* PM Lock Settings */
289 gtt_write_regs(haswell_gt_lock);
Aaron Durbin76c37002012-10-30 09:03:43 -0500290}
291
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700292static void init_display_planes(void)
293{
294 int pipe, plane;
295
296 /* Disable cursor mode */
297 for (pipe = PIPE_A; pipe <= PIPE_C; pipe++) {
298 gtt_write(CURCNTR_IVB(pipe), CURSOR_MODE_DISABLE);
299 gtt_write(CURBASE_IVB(pipe), 0x00000000);
300 }
301
302 /* Disable primary plane and set surface base address*/
303 for (plane = PLANE_A; plane <= PLANE_C; plane++) {
304 gtt_write(DSPCNTR(plane), DISPLAY_PLANE_DISABLE);
305 gtt_write(DSPSURF(plane), 0x00000000);
306 }
307
308 /* Disable VGA display */
309 gtt_write(CPU_VGACNTRL, CPU_VGA_DISABLE);
310}
311
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700312static void gma_setup_panel(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500313{
314 struct northbridge_intel_haswell_config *conf = dev->chip_info;
315 u32 reg32;
316
317 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
318
Aaron Durbin76c37002012-10-30 09:03:43 -0500319 /* Setup Digital Port Hotplug */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700320 reg32 = gtt_read(PCH_PORT_HOTPLUG);
Aaron Durbin76c37002012-10-30 09:03:43 -0500321 if (!reg32) {
322 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
323 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
324 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700325 gtt_write(PCH_PORT_HOTPLUG, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500326 }
327
328 /* Setup Panel Power On Delays */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700329 reg32 = gtt_read(PCH_PP_ON_DELAYS);
Aaron Durbin76c37002012-10-30 09:03:43 -0500330 if (!reg32) {
331 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
332 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
333 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700334 gtt_write(PCH_PP_ON_DELAYS, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500335 }
336
337 /* Setup Panel Power Off Delays */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700338 reg32 = gtt_read(PCH_PP_OFF_DELAYS);
Aaron Durbin76c37002012-10-30 09:03:43 -0500339 if (!reg32) {
340 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
341 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700342 gtt_write(PCH_PP_OFF_DELAYS, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500343 }
344
345 /* Setup Panel Power Cycle Delay */
346 if (conf->gpu_panel_power_cycle_delay) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700347 reg32 = gtt_read(PCH_PP_DIVISOR);
Aaron Durbin76c37002012-10-30 09:03:43 -0500348 reg32 &= ~0xff;
349 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700350 gtt_write(PCH_PP_DIVISOR, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500351 }
352
353 /* Enable Backlight if needed */
354 if (conf->gpu_cpu_backlight) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700355 gtt_write(BLC_PWM_CPU_CTL2, BLC_PWM2_ENABLE);
356 gtt_write(BLC_PWM_CPU_CTL, conf->gpu_cpu_backlight);
Aaron Durbin76c37002012-10-30 09:03:43 -0500357 }
358 if (conf->gpu_pch_backlight) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700359 gtt_write(BLC_PWM_PCH_CTL1, BLM_PCH_PWM_ENABLE);
360 gtt_write(BLC_PWM_PCH_CTL2, conf->gpu_pch_backlight);
Aaron Durbin76c37002012-10-30 09:03:43 -0500361 }
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700362
363 /* Get display,pipeline,and DDI registers into a basic sane state */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700364 power_well_enable();
365
366 init_display_planes();
367
368 /* DDI-A params set:
369 bit 0: Display detected (RO)
370 bit 4: DDI A supports 4 lanes and DDI E is not used
371 bit 7: DDI buffer is idle
372 */
Tristan Corrick1a73eb02018-10-31 02:27:29 +1300373 reg32 = DDI_BUF_IS_IDLE | DDI_INIT_DISPLAY_DETECTED;
374 if (!conf->gpu_ddi_e_connected)
375 reg32 |= DDI_A_4_LANES;
376 gtt_write(DDI_BUF_CTL_A, reg32);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700377
378 /* Set FDI registers - is this required? */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700379 gtt_write(_FDI_RXA_MISC, 0x00200090);
380 gtt_write(_FDI_RXA_MISC, 0x0a000000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700381
382 /* Enable the handshake with PCH display when processing reset */
383 gtt_write(NDE_RSTWRN_OPT, RST_PCH_HNDSHK_EN);
384
385 /* undocumented */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700386 gtt_write(0x42090, 0x04000000);
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700387 gtt_write(0x9840, 0x00000000);
388 gtt_write(0x42090, 0xa4000000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700389
390 gtt_write(SOUTH_DSPCLK_GATE_D, PCH_LP_PARTITION_LEVEL_DISABLE);
391
392 /* undocumented */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700393 gtt_write(0x42080, 0x00004000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700394
395 /* Prepare DDI buffers for DP and FDI */
396 intel_prepare_ddi();
397
398 /* Hot plug detect buffer enabled for port A */
399 gtt_write(DIGITAL_PORT_HOTPLUG_CNTRL, DIGITAL_PORTA_HOTPLUG_ENABLE);
400
401 /* Enable HPD buffer for digital port D and B */
402 gtt_write(PCH_PORT_HOTPLUG, PORTD_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE);
403
404 /* Bits 4:0 - Power cycle delay (default 0x6 --> 500ms)
405 Bits 31:8 - Reference divider (0x0004af ----> 24MHz)
406 */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700407 gtt_write(PCH_PP_DIVISOR, 0x0004af06);
Aaron Durbin76c37002012-10-30 09:03:43 -0500408}
409
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700410static void gma_pm_init_post_vbios(struct device *dev)
411{
Duncan Laurie356833d2013-07-09 15:40:27 -0700412 int cdclk = 0;
413 int devid = pci_read_config16(dev, PCI_DEVICE_ID);
414 int gpu_is_ulx = 0;
415
416 if (devid == 0x0a0e || devid == 0x0a1e)
417 gpu_is_ulx = 1;
418
419 /* CD Frequency */
Duncan Laurie3106d0f2013-08-12 13:51:22 -0700420 if ((gtt_read(0x42014) & 0x1000000) || gpu_is_ulx || haswell_is_ult())
421 cdclk = 0; /* fixed frequency */
422 else
423 cdclk = 2; /* variable frequency */
Duncan Laurie356833d2013-07-09 15:40:27 -0700424
Duncan Laurie356833d2013-07-09 15:40:27 -0700425 if (gpu_is_ulx || cdclk != 0)
426 gtt_rmw(0x130040, 0xf7ffffff, 0x04000000);
427 else
428 gtt_rmw(0x130040, 0xf3ffffff, 0x00000000);
429
430 /* More magic */
431 if (haswell_is_ult() || gpu_is_ulx) {
Duncan Laurie3106d0f2013-08-12 13:51:22 -0700432 if (!gpu_is_ulx)
Duncan Laurie356833d2013-07-09 15:40:27 -0700433 gtt_write(0x138128, 0x00000000);
434 else
435 gtt_write(0x138128, 0x00000001);
436 gtt_write(0x13812c, 0x00000000);
437 gtt_write(0x138124, 0x80000017);
438 }
439
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700440 /* Disable Force Wake */
441 gtt_write(0x0a188, 0x00010000);
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100442 gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 0 << 0);
Duncan Laurie356833d2013-07-09 15:40:27 -0700443 gtt_write(0x0a188, 0x00000001);
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700444}
445
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200446/* Enable SCI to ACPI _GPE._L06 */
447static void gma_enable_swsci(void)
448{
449 u16 reg16;
450
451 /* clear DMISCI status */
452 reg16 = inw(get_pmbase() + TCO1_STS);
453 reg16 &= DMISCI_STS;
454 outw(get_pmbase() + TCO1_STS, reg16);
455
456 /* clear and enable ACPI TCO SCI */
457 enable_tco_sci();
458}
459
Aaron Durbin76c37002012-10-30 09:03:43 -0500460static void gma_func0_init(struct device *dev)
461{
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700462 int lightup_ok = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500463 u32 reg32;
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500464
Aaron Durbin76c37002012-10-30 09:03:43 -0500465 /* IGD needs to be Bus Master */
466 reg32 = pci_read_config32(dev, PCI_COMMAND);
467 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
468 pci_write_config32(dev, PCI_COMMAND, reg32);
469
470 /* Init graphics power management */
471 gma_pm_init_pre_vbios(dev);
472
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500473 /* Pre panel init */
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700474 gma_setup_panel(dev);
475
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200476 int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1;
477
Julius Wernercd49cce2019-03-05 16:53:33 -0800478 if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200479 if (vga_disable) {
480 printk(BIOS_INFO,
481 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
482 } else {
483 printk(BIOS_SPEW, "NATIVE graphics, run native enable\n");
484 gma_gfxinit(&lightup_ok);
485 gfx_set_init_done(1);
486 }
Arthur Heymans23cda3472016-12-18 16:03:52 +0100487 }
488
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700489 if (! lightup_ok) {
490 printk(BIOS_SPEW, "FUI did not run; using VBIOS\n");
Stefan Reinauerf1aabec2014-01-22 15:16:30 -0800491 mdelay(CONFIG_PRE_GRAPHICS_DELAY);
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700492 pci_dev_init(dev);
493 }
494
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500495 /* Post panel init */
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700496 gma_pm_init_post_vbios(dev);
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200497
498 gma_enable_swsci();
499 intel_gma_restore_opregion();
Aaron Durbin76c37002012-10-30 09:03:43 -0500500}
501
Elyes HAOUASb60920d2018-09-20 17:38:38 +0200502static void gma_set_subsystem(struct device *dev, unsigned int vendor,
503 unsigned int device)
Aaron Durbin76c37002012-10-30 09:03:43 -0500504{
505 if (!vendor || !device) {
506 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
507 pci_read_config32(dev, PCI_VENDOR_ID));
508 } else {
509 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
510 ((device & 0xffff) << 16) | (vendor & 0xffff));
511 }
512}
513
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100514const struct i915_gpu_controller_info *
515intel_gma_get_controller_info(void)
516{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300517 struct device *dev = pcidev_on_root(0x2, 0);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100518 if (!dev) {
519 return NULL;
520 }
521 struct northbridge_intel_haswell_config *chip = dev->chip_info;
522 return &chip->gfx;
523}
524
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200525static void gma_ssdt(struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100526{
527 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
528 if (!gfx) {
529 return;
530 }
531
532 drivers_intel_gma_displays_ssdt_generate(gfx);
533}
534
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200535static unsigned long
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200536gma_write_acpi_tables(struct device *const dev, unsigned long current,
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200537 struct acpi_rsdp *const rsdp)
538{
539 igd_opregion_t *opregion = (igd_opregion_t *)current;
Matt DeVillier7c789702017-06-16 23:36:46 -0500540 global_nvs_t *gnvs;
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200541
Matt DeVillierebe08e02017-07-14 13:28:42 -0500542 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200543 return current;
544
545 current += sizeof(igd_opregion_t);
546
Matt DeVillier7c789702017-06-16 23:36:46 -0500547 /* GNVS has been already set up */
548 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
549 if (gnvs) {
550 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200551 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Matt DeVillier7c789702017-06-16 23:36:46 -0500552 } else {
553 printk(BIOS_ERR, "Error: GNVS table not found.\n");
554 }
555
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200556 current = acpi_align_current(current);
557 return current;
558}
559
Aaron Durbin76c37002012-10-30 09:03:43 -0500560static struct pci_operations gma_pci_ops = {
561 .set_subsystem = gma_set_subsystem,
562};
563
564static struct device_operations gma_func0_ops = {
Vladimir Serbinenko30fe6122014-02-05 23:25:28 +0100565 .read_resources = pci_dev_read_resources,
Aaron Durbin76c37002012-10-30 09:03:43 -0500566 .set_resources = pci_dev_set_resources,
567 .enable_resources = pci_dev_enable_resources,
568 .init = gma_func0_init,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100569 .acpi_fill_ssdt_generator = gma_ssdt,
Aaron Durbin76c37002012-10-30 09:03:43 -0500570 .scan_bus = 0,
571 .enable = 0,
572 .ops_pci = &gma_pci_ops,
Patrick Rudolphee14ccc2017-05-20 11:46:06 +0200573 .write_acpi_tables = gma_write_acpi_tables,
Aaron Durbin76c37002012-10-30 09:03:43 -0500574};
575
Duncan Lauriedf7be712012-12-17 11:22:57 -0800576static const unsigned short pci_device_ids[] = {
577 0x0402, /* Desktop GT1 */
578 0x0412, /* Desktop GT2 */
579 0x0422, /* Desktop GT3 */
580 0x0406, /* Mobile GT1 */
581 0x0416, /* Mobile GT2 */
582 0x0426, /* Mobile GT3 */
583 0x0d16, /* Mobile 4+3 GT1 */
584 0x0d26, /* Mobile 4+3 GT2 */
585 0x0d36, /* Mobile 4+3 GT3 */
586 0x0a06, /* ULT GT1 */
587 0x0a16, /* ULT GT2 */
588 0x0a26, /* ULT GT3 */
589 0,
590};
Aaron Durbin76c37002012-10-30 09:03:43 -0500591
592static const struct pci_driver pch_lpc __pci_driver = {
593 .ops = &gma_func0_ops,
594 .vendor = PCI_VENDOR_ID_INTEL,
595 .devices = pci_device_ids,
596};