blob: 48a0ba54c7358e92e0cf9f537e659552f35798c1 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
Nico Huberc2e46422020-03-23 01:22:49 +01003#include <commonlib/helpers.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05004#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05007#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +02008#include <bootmode.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05009#include <delay.h>
10#include <device/device.h>
11#include <device/pci.h>
12#include <device/pci_ids.h>
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -070013#include <drivers/intel/gma/i915_reg.h>
Furquan Shaikh77f48cd2013-08-19 10:16:50 -070014#include <drivers/intel/gma/i915.h>
Nico Huber18228162017-06-08 16:31:57 +020015#include <drivers/intel/gma/libgfxinit.h>
Duncan Laurie356833d2013-07-09 15:40:27 -070016#include <cpu/intel/haswell/haswell.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050017#include <drivers/intel/gma/opregion.h>
Angel Ponse2ec60f2021-01-26 19:18:09 +010018#include <southbridge/intel/lynxpoint/pch.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020019#include <types.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050020
21#include "chip.h"
22#include "haswell.h"
23
Duncan Laurie356833d2013-07-09 15:40:27 -070024struct gt_reg {
25 u32 reg;
26 u32 andmask;
27 u32 ormask;
28};
29
30static const struct gt_reg haswell_gt_setup[] = {
31 /* Enable Counters */
32 { 0x0a248, 0x00000000, 0x00000016 },
33 { 0x0a000, 0x00000000, 0x00070020 },
34 { 0x0a180, 0xff3fffff, 0x15000000 },
35 /* Enable DOP Clock Gating */
36 { 0x09424, 0x00000000, 0x000003fd },
37 /* Enable Unit Level Clock Gating */
38 { 0x09400, 0x00000000, 0x00000080 },
39 { 0x09404, 0x00000000, 0x40401000 },
40 { 0x09408, 0x00000000, 0x00000000 },
41 { 0x0940c, 0x00000000, 0x02000001 },
42 { 0x0a008, 0x00000000, 0x08000000 },
43 /* Wake Rate Limits */
44 { 0x0a090, 0xffffffff, 0x00000000 },
45 { 0x0a098, 0xffffffff, 0x03e80000 },
46 { 0x0a09c, 0xffffffff, 0x00280000 },
47 { 0x0a0a8, 0xffffffff, 0x0001e848 },
48 { 0x0a0ac, 0xffffffff, 0x00000019 },
49 /* Render/Video/Blitter Idle Max Count */
50 { 0x02054, 0x00000000, 0x0000000a },
51 { 0x12054, 0x00000000, 0x0000000a },
52 { 0x22054, 0x00000000, 0x0000000a },
53 /* RC Sleep / RCx Thresholds */
54 { 0x0a0b0, 0xffffffff, 0x00000000 },
55 { 0x0a0b4, 0xffffffff, 0x000003e8 },
56 { 0x0a0b8, 0xffffffff, 0x0000c350 },
57 /* RP Settings */
58 { 0x0a010, 0xffffffff, 0x000f4240 },
59 { 0x0a014, 0xffffffff, 0x12060000 },
60 { 0x0a02c, 0xffffffff, 0x0000e808 },
61 { 0x0a030, 0xffffffff, 0x0003bd08 },
62 { 0x0a068, 0xffffffff, 0x000101d0 },
63 { 0x0a06c, 0xffffffff, 0x00055730 },
64 { 0x0a070, 0xffffffff, 0x0000000a },
65 /* RP Control */
66 { 0x0a024, 0x00000000, 0x00000b92 },
67 /* HW RC6 Control */
68 { 0x0a090, 0x00000000, 0x88040000 },
69 /* Video Frequency Request */
70 { 0x0a00c, 0x00000000, 0x08000000 },
71 { 0 },
72};
73
74static const struct gt_reg haswell_gt_lock[] = {
75 { 0x0a248, 0xffffffff, 0x80000000 },
76 { 0x0a004, 0xffffffff, 0x00000010 },
77 { 0x0a080, 0xffffffff, 0x00000004 },
78 { 0x0a180, 0xffffffff, 0x80000000 },
79 { 0 },
80};
81
Angel Pons1db5bc72020-01-15 00:49:03 +010082/*
83 * Some VGA option roms are used for several chipsets but they only have one PCI ID in their
84 * header. If we encounter such an option rom, we need to do the mapping ourselves.
Aaron Durbin76c37002012-10-30 09:03:43 -050085 */
86
87u32 map_oprom_vendev(u32 vendev)
88{
Elyes HAOUAS69d658f2016-09-17 20:32:07 +020089 u32 new_vendev = vendev;
Aaron Durbin76c37002012-10-30 09:03:43 -050090
91 switch (vendev) {
Aaron Durbin71161292012-12-13 16:43:32 -060092 case 0x80860402: /* GT1 Desktop */
93 case 0x80860406: /* GT1 Mobile */
94 case 0x8086040a: /* GT1 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -080095 case 0x80860a06: /* GT1 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -060096
97 case 0x80860412: /* GT2 Desktop */
98 case 0x80860416: /* GT2 Mobile */
99 case 0x8086041a: /* GT2 Server */
Mate Kukri29bc6242021-06-05 01:30:27 +0100100 case 0x8086041e: /* GT1.5 Desktop */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800101 case 0x80860a16: /* GT2 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600102
103 case 0x80860422: /* GT3 Desktop */
104 case 0x80860426: /* GT3 Mobile */
105 case 0x8086042a: /* GT3 Server */
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800106 case 0x80860a26: /* GT3 ULT */
Aaron Durbin71161292012-12-13 16:43:32 -0600107
Iru Cai12a13e12020-05-22 22:57:03 +0800108 case 0x80860d22: /* GT3e Desktop */
109 case 0x80860d16: /* GT1 Mobile 4+3 */
110 case 0x80860d26: /* GT2 Mobile 4+3, GT3e Mobile */
111 case 0x80860d36: /* GT3 Mobile 4+3 */
112
Elyes HAOUAS69d658f2016-09-17 20:32:07 +0200113 new_vendev = 0x80860406; /* GT1 Mobile */
Aaron Durbin76c37002012-10-30 09:03:43 -0500114 break;
115 }
116
117 return new_vendev;
118}
119
120static struct resource *gtt_res = NULL;
121
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700122u32 gtt_read(u32 reg)
Aaron Durbin76c37002012-10-30 09:03:43 -0500123{
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700124 u32 val;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800125 val = read32(res2mmio(gtt_res, reg, 0));
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700126 return val;
127
Aaron Durbin76c37002012-10-30 09:03:43 -0500128}
129
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700130void gtt_write(u32 reg, u32 data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500131{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800132 write32(res2mmio(gtt_res, reg, 0), data);
Aaron Durbin76c37002012-10-30 09:03:43 -0500133}
134
Duncan Laurie356833d2013-07-09 15:40:27 -0700135static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask)
136{
137 u32 val = gtt_read(reg);
138 val &= andmask;
139 val |= ormask;
140 gtt_write(reg, val);
141}
142
143static inline void gtt_write_regs(const struct gt_reg *gt)
144{
145 for (; gt && gt->reg; gt++) {
146 if (gt->andmask)
147 gtt_rmw(gt->reg, gt->andmask, gt->ormask);
148 else
149 gtt_write(gt->reg, gt->ormask);
150 }
151}
152
Aaron Durbin76c37002012-10-30 09:03:43 -0500153#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700154int gtt_poll(u32 reg, u32 mask, u32 value)
Aaron Durbin76c37002012-10-30 09:03:43 -0500155{
Martin Roth468d02c2019-10-23 21:44:42 -0600156 unsigned int try = GTT_RETRY;
Aaron Durbin76c37002012-10-30 09:03:43 -0500157 u32 data;
158
159 while (try--) {
160 data = gtt_read(reg);
161 if ((data & mask) == value)
162 return 1;
Angel Pons1db5bc72020-01-15 00:49:03 +0100163
Aaron Durbin76c37002012-10-30 09:03:43 -0500164 udelay(10);
165 }
166
167 printk(BIOS_ERR, "GT init timeout\n");
168 return 0;
169}
170
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700171static void power_well_enable(void)
172{
173 gtt_write(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_ENABLE);
174 gtt_poll(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_STATE, HSW_PWR_WELL_STATE);
175}
176
Aaron Durbin76c37002012-10-30 09:03:43 -0500177static void gma_pm_init_pre_vbios(struct device *dev)
178{
Aaron Durbin76c37002012-10-30 09:03:43 -0500179 printk(BIOS_DEBUG, "GT Power Management Init\n");
180
Angel Pons536d36a2021-11-03 13:13:00 +0100181 gtt_res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500182 if (!gtt_res || !gtt_res->base)
183 return;
184
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700185 power_well_enable();
186
Duncan Laurie67113e92013-01-10 13:23:04 -0800187 /*
188 * Enable RC6
189 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500190
Duncan Laurie67113e92013-01-10 13:23:04 -0800191 /* Enable Force Wake */
192 gtt_write(0x0a180, 1 << 5);
193 gtt_write(0x0a188, 0x00010001);
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100194 gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 1 << 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500195
Duncan Laurie356833d2013-07-09 15:40:27 -0700196 /* GT Settings */
197 gtt_write_regs(haswell_gt_setup);
Aaron Durbin76c37002012-10-30 09:03:43 -0500198
Duncan Laurie356833d2013-07-09 15:40:27 -0700199 /* Wait for Mailbox Ready */
Angel Ponsf5dd7b62020-10-24 12:24:19 +0200200 gtt_poll(0x138124, (1 << 31), (0 << 31));
Angel Pons1db5bc72020-01-15 00:49:03 +0100201
Duncan Laurie356833d2013-07-09 15:40:27 -0700202 /* Mailbox Data - RC6 VIDS */
203 gtt_write(0x138128, 0x00000000);
Angel Pons1db5bc72020-01-15 00:49:03 +0100204
Duncan Laurie356833d2013-07-09 15:40:27 -0700205 /* Mailbox Command */
206 gtt_write(0x138124, 0x80000004);
Angel Pons1db5bc72020-01-15 00:49:03 +0100207
Duncan Laurie356833d2013-07-09 15:40:27 -0700208 /* Wait for Mailbox Ready */
Angel Ponsf5dd7b62020-10-24 12:24:19 +0200209 gtt_poll(0x138124, (1 << 31), (0 << 31));
Aaron Durbin76c37002012-10-30 09:03:43 -0500210
Duncan Laurie356833d2013-07-09 15:40:27 -0700211 /* Enable PM Interrupts */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700212 gtt_write(GEN6_PMIER, GEN6_PM_MBOX_EVENT | GEN6_PM_THERMAL_EVENT |
213 GEN6_PM_RP_DOWN_TIMEOUT | GEN6_PM_RP_UP_THRESHOLD |
214 GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_UP_EI_EXPIRED |
215 GEN6_PM_RP_DOWN_EI_EXPIRED);
Aaron Durbin76c37002012-10-30 09:03:43 -0500216
Duncan Laurie67113e92013-01-10 13:23:04 -0800217 /* Enable RC6 in idle */
218 gtt_write(0x0a094, 0x00040000);
Duncan Laurie356833d2013-07-09 15:40:27 -0700219
220 /* PM Lock Settings */
221 gtt_write_regs(haswell_gt_lock);
Aaron Durbin76c37002012-10-30 09:03:43 -0500222}
223
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700224static void init_display_planes(void)
225{
226 int pipe, plane;
227
228 /* Disable cursor mode */
229 for (pipe = PIPE_A; pipe <= PIPE_C; pipe++) {
230 gtt_write(CURCNTR_IVB(pipe), CURSOR_MODE_DISABLE);
231 gtt_write(CURBASE_IVB(pipe), 0x00000000);
232 }
233
Angel Pons1db5bc72020-01-15 00:49:03 +0100234 /* Disable primary plane and set surface base address */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700235 for (plane = PLANE_A; plane <= PLANE_C; plane++) {
236 gtt_write(DSPCNTR(plane), DISPLAY_PLANE_DISABLE);
237 gtt_write(DSPSURF(plane), 0x00000000);
238 }
239
240 /* Disable VGA display */
241 gtt_write(CPU_VGACNTRL, CPU_VGA_DISABLE);
242}
243
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700244static void gma_setup_panel(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500245{
Angel Ponse153a352020-10-23 14:53:59 +0200246 struct northbridge_intel_haswell_config *conf = config_of(dev);
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100247 const struct i915_gpu_panel_config *panel_cfg = &conf->panel_cfg;
Aaron Durbin76c37002012-10-30 09:03:43 -0500248 u32 reg32;
249
Aaron Durbin76c37002012-10-30 09:03:43 -0500250 /* Setup Digital Port Hotplug */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700251 reg32 = gtt_read(PCH_PORT_HOTPLUG);
Aaron Durbin76c37002012-10-30 09:03:43 -0500252 if (!reg32) {
253 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
254 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
255 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700256 gtt_write(PCH_PORT_HOTPLUG, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500257 }
258
259 /* Setup Panel Power On Delays */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700260 reg32 = gtt_read(PCH_PP_ON_DELAYS);
Aaron Durbin76c37002012-10-30 09:03:43 -0500261 if (!reg32) {
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100262 reg32 |= ((panel_cfg->up_delay_ms * 10) & 0x1fff) << 16;
263 reg32 |= (panel_cfg->backlight_on_delay_ms * 10) & 0x1fff;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700264 gtt_write(PCH_PP_ON_DELAYS, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500265 }
266
267 /* Setup Panel Power Off Delays */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700268 reg32 = gtt_read(PCH_PP_OFF_DELAYS);
Aaron Durbin76c37002012-10-30 09:03:43 -0500269 if (!reg32) {
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100270 reg32 = ((panel_cfg->down_delay_ms * 10) & 0x1fff) << 16;
271 reg32 |= (panel_cfg->backlight_off_delay_ms * 10) & 0x1fff;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700272 gtt_write(PCH_PP_OFF_DELAYS, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500273 }
274
275 /* Setup Panel Power Cycle Delay */
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100276 if (panel_cfg->cycle_delay_ms) {
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700277 reg32 = gtt_read(PCH_PP_DIVISOR);
Michael Niewöhner3054a192020-12-28 15:00:39 +0100278 reg32 &= ~0x1f;
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100279 reg32 |= (DIV_ROUND_UP(panel_cfg->cycle_delay_ms, 100) + 1) & 0x1f;
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700280 gtt_write(PCH_PP_DIVISOR, reg32);
Aaron Durbin76c37002012-10-30 09:03:43 -0500281 }
282
Nico Huberc2e46422020-03-23 01:22:49 +0100283 /* Enforce the PCH PWM function, as so does Linux.
284 The CPU PWM controls are disabled after reset. */
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100285 if (panel_cfg->backlight_pwm_hz) {
Nico Huberc2e46422020-03-23 01:22:49 +0100286 /* Reference clock is either 24MHz or 135MHz. We can choose
287 either a 16 or a 128 step increment. Use 16 if we would
288 have less than 100 steps otherwise. */
289 const unsigned int refclock = CONFIG(INTEL_LYNXPOINT_LP) ? 24*MHz : 135*MHz;
290 const unsigned int hz_limit = refclock / 128 / 100;
291 unsigned int pwm_increment, pwm_period;
292 u32 south_chicken2;
293
294 south_chicken2 = gtt_read(SOUTH_CHICKEN2);
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100295 if (panel_cfg->backlight_pwm_hz > hz_limit) {
Nico Huberc2e46422020-03-23 01:22:49 +0100296 pwm_increment = 16;
297 south_chicken2 |= LPT_PWM_GRANULARITY;
298 } else {
299 pwm_increment = 128;
300 south_chicken2 &= ~LPT_PWM_GRANULARITY;
301 }
302 gtt_write(SOUTH_CHICKEN2, south_chicken2);
303
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100304 pwm_period = refclock / pwm_increment / panel_cfg->backlight_pwm_hz;
Nico Huberc2e46422020-03-23 01:22:49 +0100305 printk(BIOS_INFO,
306 "GMA: Setting backlight PWM frequency to %uMHz / %u / %u = %uHz\n",
307 refclock / MHz, pwm_increment, pwm_period,
308 DIV_ROUND_CLOSEST(refclock, pwm_increment * pwm_period));
309
310 /* Start with a 50% duty cycle. */
311 gtt_write(BLC_PWM_PCH_CTL2, pwm_period << 16 | pwm_period / 2);
312
313 gtt_write(BLC_PWM_PCH_CTL1,
Michael Niewöhner97e21d32020-12-28 00:49:33 +0100314 (panel_cfg->backlight_polarity == GPU_BACKLIGHT_POLARITY_LOW) << 29 |
Nico Huberc2e46422020-03-23 01:22:49 +0100315 BLM_PCH_OVERRIDE_ENABLE | BLM_PCH_PWM_ENABLE);
Aaron Durbin76c37002012-10-30 09:03:43 -0500316 }
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700317
318 /* Get display,pipeline,and DDI registers into a basic sane state */
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700319 power_well_enable();
320
321 init_display_planes();
322
Angel Pons1db5bc72020-01-15 00:49:03 +0100323 /*
324 * DDI-A params set:
325 * bit 0: Display detected (RO)
326 * bit 4: DDI A supports 4 lanes and DDI E is not used
327 * bit 7: DDI buffer is idle
328 */
Tristan Corrick1a73eb02018-10-31 02:27:29 +1300329 reg32 = DDI_BUF_IS_IDLE | DDI_INIT_DISPLAY_DETECTED;
330 if (!conf->gpu_ddi_e_connected)
331 reg32 |= DDI_A_4_LANES;
332 gtt_write(DDI_BUF_CTL_A, reg32);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700333
334 /* Set FDI registers - is this required? */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700335 gtt_write(_FDI_RXA_MISC, 0x00200090);
336 gtt_write(_FDI_RXA_MISC, 0x0a000000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700337
338 /* Enable the handshake with PCH display when processing reset */
339 gtt_write(NDE_RSTWRN_OPT, RST_PCH_HNDSHK_EN);
340
Angel Pons1db5bc72020-01-15 00:49:03 +0100341 /* Undocumented */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700342 gtt_write(0x42090, 0x04000000);
Angel Pons1db5bc72020-01-15 00:49:03 +0100343 gtt_write(0x9840, 0x00000000);
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700344 gtt_write(0x42090, 0xa4000000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700345
346 gtt_write(SOUTH_DSPCLK_GATE_D, PCH_LP_PARTITION_LEVEL_DISABLE);
347
Angel Pons1db5bc72020-01-15 00:49:03 +0100348 /* Undocumented */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700349 gtt_write(0x42080, 0x00004000);
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700350
351 /* Prepare DDI buffers for DP and FDI */
352 intel_prepare_ddi();
353
354 /* Hot plug detect buffer enabled for port A */
355 gtt_write(DIGITAL_PORT_HOTPLUG_CNTRL, DIGITAL_PORTA_HOTPLUG_ENABLE);
356
357 /* Enable HPD buffer for digital port D and B */
358 gtt_write(PCH_PORT_HOTPLUG, PORTD_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE);
359
Angel Pons1db5bc72020-01-15 00:49:03 +0100360 /*
361 * Bits 4:0 - Power cycle delay (default 0x6 --> 500ms)
362 * Bits 31:8 - Reference divider (0x0004af ----> 24MHz)
363 */
Ronald G. Minnich5bcca7e2013-06-25 15:56:46 -0700364 gtt_write(PCH_PP_DIVISOR, 0x0004af06);
Aaron Durbin76c37002012-10-30 09:03:43 -0500365}
366
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700367static void gma_pm_init_post_vbios(struct device *dev)
368{
Duncan Laurie356833d2013-07-09 15:40:27 -0700369 int cdclk = 0;
370 int devid = pci_read_config16(dev, PCI_DEVICE_ID);
371 int gpu_is_ulx = 0;
372
373 if (devid == 0x0a0e || devid == 0x0a1e)
374 gpu_is_ulx = 1;
375
376 /* CD Frequency */
Duncan Laurie3106d0f2013-08-12 13:51:22 -0700377 if ((gtt_read(0x42014) & 0x1000000) || gpu_is_ulx || haswell_is_ult())
378 cdclk = 0; /* fixed frequency */
379 else
380 cdclk = 2; /* variable frequency */
Duncan Laurie356833d2013-07-09 15:40:27 -0700381
Duncan Laurie356833d2013-07-09 15:40:27 -0700382 if (gpu_is_ulx || cdclk != 0)
383 gtt_rmw(0x130040, 0xf7ffffff, 0x04000000);
384 else
385 gtt_rmw(0x130040, 0xf3ffffff, 0x00000000);
386
387 /* More magic */
388 if (haswell_is_ult() || gpu_is_ulx) {
Duncan Laurie3106d0f2013-08-12 13:51:22 -0700389 if (!gpu_is_ulx)
Duncan Laurie356833d2013-07-09 15:40:27 -0700390 gtt_write(0x138128, 0x00000000);
391 else
392 gtt_write(0x138128, 0x00000001);
393 gtt_write(0x13812c, 0x00000000);
394 gtt_write(0x138124, 0x80000017);
395 }
396
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700397 /* Disable Force Wake */
398 gtt_write(0x0a188, 0x00010000);
Edward O'Callaghan986e85c2014-10-29 12:15:34 +1100399 gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 0 << 0);
Duncan Laurie356833d2013-07-09 15:40:27 -0700400 gtt_write(0x0a188, 0x00000001);
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700401}
402
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200403/* Enable SCI to ACPI _GPE._L06 */
404static void gma_enable_swsci(void)
405{
406 u16 reg16;
407
Angel Pons1db5bc72020-01-15 00:49:03 +0100408 /* Clear DMISCI status */
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200409 reg16 = inw(get_pmbase() + TCO1_STS);
410 reg16 &= DMISCI_STS;
Kyösti Mälkkiac435b42022-11-15 14:00:22 +0200411 outw(reg16, get_pmbase() + TCO1_STS);
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200412
Angel Pons1db5bc72020-01-15 00:49:03 +0100413 /* Clear and enable ACPI TCO SCI */
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200414 enable_tco_sci();
415}
416
Aaron Durbin76c37002012-10-30 09:03:43 -0500417static void gma_func0_init(struct device *dev)
418{
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700419 int lightup_ok = 0;
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500420
Nico Huberf2a0be22020-04-26 17:01:25 +0200421 intel_gma_init_igd_opregion();
422
Aaron Durbin76c37002012-10-30 09:03:43 -0500423 /* Init graphics power management */
424 gma_pm_init_pre_vbios(dev);
425
Matt DeVillier6955b9c2017-04-16 01:42:44 -0500426 /* Pre panel init */
Duncan Lauriec7f2ab72013-05-28 07:49:09 -0700427 gma_setup_panel(dev);
428
Nico Huberdd597622020-04-26 19:46:35 +0200429 if (!CONFIG(NO_GFX_INIT))
430 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
431
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200432 int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1;
433
Julius Wernercd49cce2019-03-05 16:53:33 -0800434 if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200435 if (vga_disable) {
436 printk(BIOS_INFO,
437 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
438 } else {
439 printk(BIOS_SPEW, "NATIVE graphics, run native enable\n");
440 gma_gfxinit(&lightup_ok);
441 gfx_set_init_done(1);
442 }
Arthur Heymans23cda3472016-12-18 16:03:52 +0100443 }
444
Angel Ponsda59ca92020-10-23 14:59:37 +0200445 if (!lightup_ok) {
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700446 printk(BIOS_SPEW, "FUI did not run; using VBIOS\n");
447 pci_dev_init(dev);
448 }
449
Angel Ponsdb3047c2020-10-23 14:56:19 +0200450 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
451
Ronald G. Minnich4f78b182013-04-17 16:57:30 -0700452 gma_pm_init_post_vbios(dev);
Patrick Rudolph89f3a602017-06-20 18:25:22 +0200453
454 gma_enable_swsci();
Aaron Durbin76c37002012-10-30 09:03:43 -0500455}
456
Furquan Shaikh7536a392020-04-24 21:59:21 -0700457static void gma_generate_ssdt(const struct device *dev)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100458{
Matt DeVillier41c4eb52020-03-30 19:20:54 -0500459 const struct northbridge_intel_haswell_config *chip = dev->chip_info;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100460
Matt DeVillier41c4eb52020-03-30 19:20:54 -0500461 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100462}
463
Leah Rowe1e282182024-02-23 13:33:31 +0000464static void gma_func0_disable(struct device *dev)
465{
466 /* Disable VGA decode */
467 pci_or_config16(pcidev_on_root(0, 0), GGC, 1 << 1);
468}
469
Aaron Durbin76c37002012-10-30 09:03:43 -0500470static struct device_operations gma_func0_ops = {
Matt DeVillier41c4eb52020-03-30 19:20:54 -0500471 .read_resources = pci_dev_read_resources,
472 .set_resources = pci_dev_set_resources,
473 .enable_resources = pci_dev_enable_resources,
474 .init = gma_func0_init,
475 .acpi_fill_ssdt = gma_generate_ssdt,
Leah Rowe1e282182024-02-23 13:33:31 +0000476 .vga_disable = gma_func0_disable,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200477 .ops_pci = &pci_dev_ops_pci,
Aaron Durbin76c37002012-10-30 09:03:43 -0500478};
479
Duncan Lauriedf7be712012-12-17 11:22:57 -0800480static const unsigned short pci_device_ids[] = {
481 0x0402, /* Desktop GT1 */
482 0x0412, /* Desktop GT2 */
Mate Kukri29bc6242021-06-05 01:30:27 +0100483 0x041e, /* Desktop GT1.5 */
Duncan Lauriedf7be712012-12-17 11:22:57 -0800484 0x0422, /* Desktop GT3 */
Iru Cai12a13e12020-05-22 22:57:03 +0800485 0x0d22, /* Desktop GT3e */
Duncan Lauriedf7be712012-12-17 11:22:57 -0800486 0x0406, /* Mobile GT1 */
487 0x0416, /* Mobile GT2 */
488 0x0426, /* Mobile GT3 */
489 0x0d16, /* Mobile 4+3 GT1 */
Iru Cai12a13e12020-05-22 22:57:03 +0800490 0x0d26, /* Mobile 4+3 GT2, Mobile GT3e */
Duncan Lauriedf7be712012-12-17 11:22:57 -0800491 0x0d36, /* Mobile 4+3 GT3 */
492 0x0a06, /* ULT GT1 */
493 0x0a16, /* ULT GT2 */
494 0x0a26, /* ULT GT3 */
Angel Ponsbc049972021-01-29 18:07:01 +0100495 0x0a0e, /* ULX GT1 */
496 0x0a1e, /* ULX GT2 */
Duncan Lauriedf7be712012-12-17 11:22:57 -0800497 0,
498};
Aaron Durbin76c37002012-10-30 09:03:43 -0500499
500static const struct pci_driver pch_lpc __pci_driver = {
Angel Pons1db5bc72020-01-15 00:49:03 +0100501 .ops = &gma_func0_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100502 .vendor = PCI_VID_INTEL,
Aaron Durbin76c37002012-10-30 09:03:43 -0500503 .devices = pci_device_ids,
504};