blob: a2e51636dbd7344b8db3d26541acb0f8d415e2ab [file] [log] [blame]
Stefan Reinauer30140a52009-03-11 16:20:39 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Stefan Reinauer30140a52009-03-11 16:20:39 +000018 */
19
20#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020021#include <bootmode.h>
Patrick Georgi6444bd42012-07-06 11:31:39 +020022#include <delay.h>
Stefan Reinauer30140a52009-03-11 16:20:39 +000023#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
Sven Schnelleb629d142011-06-12 14:30:10 +020026#include <pc80/mc146818rtc.h>
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020027#include <edid.h>
28#include <drivers/intel/gma/edid.h>
29#include <drivers/intel/gma/i915.h>
30#include <string.h>
Vladimir Serbinenko0092c992014-08-21 01:06:53 +020031#include <pc80/vga.h>
32#include <pc80/vga_io.h>
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020033
Patrick Georgice6e9fe2012-07-20 12:37:06 +020034#include "i945.h"
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020035#include "chip.h"
Stefan Reinauer30140a52009-03-11 16:20:39 +000036
Patrick Georgi6444bd42012-07-06 11:31:39 +020037#define GDRST 0xc0
38
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020039#define LVDS_CLOCK_A_POWERUP_ALL (3 << 8)
40#define LVDS_CLOCK_B_POWERUP_ALL (3 << 4)
41#define LVDS_CLOCK_BOTH_POWERUP_ALL (3 << 2)
42#define DISPPLANE_BGRX888 (0x6<<26)
43#define DPLLB_LVDS_P2_CLOCK_DIV_7 (1 << 24) /* i915 */
44
45#define DPLL_INTEGRATED_CRI_CLK_VLV (1<<14)
46
47#define PGETBL_CTL 0x2020
48#define PGETBL_ENABLED 0x00000001
49
50#define BASE_FREQUENCY 120000
51
52#if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
53
Francis Rowe71512b22015-03-16 05:31:40 +000054static int gtt_setup(void *mmiobase)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020055{
56 unsigned long PGETBL_save;
Paul Menzelcc95f182014-06-05 22:45:35 +020057 unsigned long tom; // top of memory
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020058
Paul Menzelcc95f182014-06-05 22:45:35 +020059 /*
60 * The Video BIOS places the GTT right below top of memory.
Denis 'GNUtoo' Carikli16110e72014-10-14 07:33:53 +020061 */
Paul Menzelcc95f182014-06-05 22:45:35 +020062 tom = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), TOLUD) << 24;
63 PGETBL_save = tom - 256 * KiB;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020064 PGETBL_save |= PGETBL_ENABLED;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020065 PGETBL_save |= 2; /* set GTT to 256kb */
66
67 write32(mmiobase + GFX_FLSH_CNTL, 0);
68
69 write32(mmiobase + PGETBL_CTL, PGETBL_save);
70
71 /* verify */
72 if (read32(mmiobase + PGETBL_CTL) & PGETBL_ENABLED) {
73 printk(BIOS_DEBUG, "gtt_setup is enabled.\n");
74 } else {
75 printk(BIOS_DEBUG, "gtt_setup failed!!!\n");
76 return 1;
77 }
78 write32(mmiobase + GFX_FLSH_CNTL, 0);
79
80 return 0;
81}
82
83static int intel_gma_init(struct northbridge_intel_i945_config *conf,
84 unsigned int pphysbase, unsigned int piobase,
Francis Rowe71512b22015-03-16 05:31:40 +000085 void *pmmio, unsigned int pgfx)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020086{
87 struct edid edid;
88 u8 edid_data[128];
89 unsigned long temp;
90 int hpolarity, vpolarity;
91 u32 candp1, candn;
92 u32 best_delta = 0xffffffff;
93 u32 target_frequency;
94 u32 pixel_p1 = 1;
95 u32 pixel_n = 1;
96 u32 pixel_m1 = 1;
97 u32 pixel_m2 = 1;
98 u32 hactive, vactive, right_border, bottom_border;
99 u32 vsync, hsync, vblank, hblank, hfront_porch, vfront_porch;
100 u32 i, j;
101 u32 uma_size;
102 u16 reg16;
103
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200104 printk(BIOS_SPEW,
Francis Rowe71512b22015-03-16 05:31:40 +0000105 "i915lightup: graphics %p mmio %p addrport %04x physbase %08x\n",
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200106 (void *)pgfx, pmmio, piobase, pphysbase);
107
108 intel_gmbus_read_edid(pmmio + GMBUS0, 3, 0x50, edid_data, 128);
109 decode_edid(edid_data, sizeof(edid_data), &edid);
110
111 hpolarity = (edid.phsync == '-');
112 vpolarity = (edid.pvsync == '-');
113 hactive = edid.x_resolution;
114 vactive = edid.y_resolution;
115 right_border = edid.hborder;
116 bottom_border = edid.vborder;
117 vblank = edid.vbl;
118 hblank = edid.hbl;
119 vsync = edid.vspw;
120 hsync = edid.hspw;
121 hfront_porch = edid.hso;
122 vfront_porch = edid.vso;
123
124 for (i = 0; i < 2; i++)
125 for (j = 0; j < 0x100; j++)
126 /* R=j, G=j, B=j. */
127 write32(pmmio + PALETTE(i) + 4 * j, 0x10101 * j);
128
129 write32(pmmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS
130 | (read32(pmmio + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK));
131
132 write32(pmmio + MI_ARB_STATE, MI_ARB_C3_LP_WRITE_ENABLE | (1 << 27));
133 /* Clean registers. */
134 for (i = 0; i < 0x20; i += 4)
135 write32(pmmio + RENDER_RING_BASE + i, 0);
136 for (i = 0; i < 0x20; i += 4)
137 write32(pmmio + FENCE_REG_965_0 + i, 0);
138 write32(pmmio + PP_ON_DELAYS, 0);
139 write32(pmmio + PP_OFF_DELAYS, 0);
140
141 /* Disable VGA. */
142 write32(pmmio + VGACNTRL, VGA_DISP_DISABLE);
143
144 /* Disable pipes. */
145 write32(pmmio + PIPECONF(0), 0);
146 write32(pmmio + PIPECONF(1), 0);
147
148 /* Init PRB0. */
149 write32(pmmio + HWS_PGA, 0x352d2000);
150 write32(pmmio + PRB0_CTL, 0);
151 write32(pmmio + PRB0_HEAD, 0);
152 write32(pmmio + PRB0_TAIL, 0);
153 write32(pmmio + PRB0_START, 0);
154 write32(pmmio + PRB0_CTL, 0x0001f001);
155
156 write32(pmmio + D_STATE, DSTATE_PLL_D3_OFF
157 | DSTATE_GFX_CLOCK_GATING | DSTATE_DOT_CLOCK_GATING);
158 write32(pmmio + ECOSKPD, 0x00010000);
159 write32(pmmio + HWSTAM, 0xeffe);
160 write32(pmmio + PORT_HOTPLUG_EN, conf->gpu_hotplug);
161 write32(pmmio + INSTPM, 0x08000000 | INSTPM_AGPBUSY_DIS);
162
163 target_frequency = conf->gpu_lvds_is_dual_channel ? edid.pixel_clock
164 : (2 * edid.pixel_clock);
165
166 /* Find suitable divisors. */
167 for (candp1 = 1; candp1 <= 8; candp1++) {
168 for (candn = 5; candn <= 10; candn++) {
169 u32 cur_frequency;
170 u32 m; /* 77 - 131. */
171 u32 denom; /* 35 - 560. */
172 u32 current_delta;
173
174 denom = candn * candp1 * 7;
175 /* Doesnt overflow for up to
176 5000000 kHz = 5 GHz. */
177 m = (target_frequency * denom
178 + BASE_FREQUENCY / 2) / BASE_FREQUENCY;
179
180 if (m < 77 || m > 131)
181 continue;
182
183 cur_frequency = (BASE_FREQUENCY * m) / denom;
184 if (target_frequency > cur_frequency)
185 current_delta = target_frequency - cur_frequency;
186 else
187 current_delta = cur_frequency - target_frequency;
188
189 if (best_delta > current_delta) {
190 best_delta = current_delta;
191 pixel_n = candn;
192 pixel_p1 = candp1;
193 pixel_m2 = ((m + 3) % 5) + 7;
194 pixel_m1 = (m - pixel_m2) / 5;
195 }
196 }
197 }
198
199 if (best_delta == 0xffffffff) {
200 printk (BIOS_ERR, "Couldn't find GFX clock divisors\n");
201 return -1;
202 }
203
204 printk(BIOS_INFO, "bringing up panel at resolution %d x %d\n",
205 hactive, vactive);
206 printk(BIOS_DEBUG, "Borders %d x %d\n", right_border, bottom_border);
207 printk(BIOS_DEBUG, "Blank %d x %d\n", hblank, vblank);
208 printk(BIOS_DEBUG, "Sync %d x %d\n", hsync, vsync);
209 printk(BIOS_DEBUG, "Front porch %d x %d\n", hfront_porch, vfront_porch);
210 printk(BIOS_DEBUG, (conf->gpu_lvds_use_spread_spectrum_clock
211 ? "Spread spectrum clock\n"
212 : "DREF clock\n"));
213 printk(BIOS_DEBUG, (conf->gpu_lvds_is_dual_channel
214 ? "Dual channel\n"
215 : "Single channel\n"));
216 printk(BIOS_DEBUG, "Polarities %d, %d\n",
217 hpolarity, vpolarity);
218 printk(BIOS_DEBUG, "Pixel N=%d, M1=%d, M2=%d, P1=%d\n",
219 pixel_n, pixel_m1, pixel_m2, pixel_p1);
220 printk(BIOS_DEBUG, "Pixel clock %d kHz\n",
221 BASE_FREQUENCY * (5 * pixel_m1 + pixel_m2) / pixel_n
222 / (pixel_p1 * 7));
223
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200224#if !IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
225 write32(pmmio + PF_WIN_SZ(0), vactive | (hactive << 16));
226 write32(pmmio + PF_WIN_POS(0), 0);
227 write32(pmmio + PF_CTL(0),PF_ENABLE | PF_FILTER_MED_3x3);
228 write32(pmmio + PFIT_CONTROL, PFIT_ENABLE | (1 << PFIT_PIPE_SHIFT) | HORIZ_AUTO_SCALE | VERT_AUTO_SCALE);
229#else
230 /* Disable panel fitter (we're in native resolution). */
231 write32(pmmio + PF_CTL(0), 0);
232 write32(pmmio + PF_WIN_SZ(0), 0);
233 write32(pmmio + PF_WIN_POS(0), 0);
234 write32(pmmio + PFIT_PGM_RATIOS, 0);
235 write32(pmmio + PFIT_CONTROL, 0);
236#endif
237
238 mdelay(1);
239
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200240 write32(pmmio + DSPCNTR(0), DISPPLANE_BGRX888
241 | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE);
242
243 mdelay(1);
244 write32(pmmio + PP_CONTROL, PANEL_UNLOCK_REGS
245 | (read32(pmmio + PP_CONTROL) & ~PANEL_UNLOCK_MASK));
246 write32(pmmio + FP0(1),
247 ((pixel_n - 2) << 16)
248 | ((pixel_m1 - 2) << 8) | pixel_m2);
249 write32(pmmio + DPLL(1),
250 DPLL_VGA_MODE_DIS |
251 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
252 | (conf->gpu_lvds_is_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
253 : DPLLB_LVDS_P2_CLOCK_DIV_14)
254 | (conf->gpu_lvds_use_spread_spectrum_clock
255 ? DPLL_INTEGRATED_CLOCK_VLV | DPLL_INTEGRATED_CRI_CLK_VLV
256 : 0)
257 | (pixel_p1 << 16)
258 | (pixel_p1));
259 mdelay(1);
260 write32(pmmio + DPLL(1),
261 DPLL_VGA_MODE_DIS |
262 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
263 | (conf->gpu_lvds_is_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
264 : DPLLB_LVDS_P2_CLOCK_DIV_14)
265 | ((conf->gpu_lvds_use_spread_spectrum_clock ? 3 : 0) << 13)
266 | (pixel_p1 << 16)
267 | (pixel_p1));
268 mdelay(1);
269 write32(pmmio + HTOTAL(1),
270 ((hactive + right_border + hblank - 1) << 16)
271 | (hactive - 1));
272 write32(pmmio + HBLANK(1),
273 ((hactive + right_border + hblank - 1) << 16)
274 | (hactive + right_border - 1));
275 write32(pmmio + HSYNC(1),
276 ((hactive + right_border + hfront_porch + hsync - 1) << 16)
277 | (hactive + right_border + hfront_porch - 1));
278
279 write32(pmmio + VTOTAL(1), ((vactive + bottom_border + vblank - 1) << 16)
280 | (vactive - 1));
281 write32(pmmio + VBLANK(1), ((vactive + bottom_border + vblank - 1) << 16)
282 | (vactive + bottom_border - 1));
283 write32(pmmio + VSYNC(1),
284 (vactive + bottom_border + vfront_porch + vsync - 1)
285 | (vactive + bottom_border + vfront_porch - 1));
286
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200287#if !IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
288 write32(pmmio + PIPESRC(1), (639 << 16) | 399);
289#else
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200290 write32(pmmio + PIPESRC(1), ((hactive - 1) << 16) | (vactive - 1));
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200291#endif
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200292 mdelay(1);
293
294 write32(pmmio + DSPSIZE(0), (hactive - 1) | ((vactive - 1) << 16));
295 write32(pmmio + DSPPOS(0), 0);
296
297 /* Backlight init. */
298 write32(pmmio + FW_BLC_SELF, FW_BLC_SELF_EN_MASK);
299 write32(pmmio + FW_BLC, 0x011d011a);
300 write32(pmmio + FW_BLC2, 0x00000102);
301 write32(pmmio + FW_BLC_SELF, FW_BLC_SELF_EN_MASK);
302 write32(pmmio + FW_BLC_SELF, 0x0001003f);
303 write32(pmmio + FW_BLC, 0x011d0109);
304 write32(pmmio + FW_BLC2, 0x00000102);
305 write32(pmmio + FW_BLC_SELF, FW_BLC_SELF_EN_MASK);
306 write32(pmmio + BLC_PWM_CTL, conf->gpu_backlight);
307
308 edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63;
309 write32(pmmio + DSPADDR(0), 0);
310 write32(pmmio + DSPSURF(0), 0);
311 write32(pmmio + DSPSTRIDE(0), edid.bytes_per_line);
312 write32(pmmio + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888
313 | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE);
314 mdelay(1);
315
316 write32(pmmio + PIPECONF(1), PIPECONF_ENABLE);
317 write32(pmmio + LVDS, LVDS_ON
318 | (hpolarity << 20) | (vpolarity << 21)
319 | (conf->gpu_lvds_is_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
320 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
321 | LVDS_CLOCK_A_POWERUP_ALL
322 | LVDS_PIPE(1));
323
324 write32(pmmio + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
325 write32(pmmio + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET);
326 mdelay(1);
327 write32(pmmio + PP_CONTROL, PANEL_UNLOCK_REGS
328 | PANEL_POWER_ON | PANEL_POWER_RESET);
329
330 printk (BIOS_DEBUG, "waiting for panel powerup\n");
331 while (1) {
332 u32 reg32;
333 reg32 = read32(pmmio + PP_STATUS);
334 if ((reg32 & PP_SEQUENCE_MASK) == PP_SEQUENCE_NONE)
335 break;
336 }
337 printk (BIOS_DEBUG, "panel powered up\n");
338
339 write32(pmmio + PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET);
340
341 /* Clear interrupts. */
342 write32(pmmio + DEIIR, 0xffffffff);
343 write32(pmmio + SDEIIR, 0xffffffff);
344 write32(pmmio + IIR, 0xffffffff);
345 write32(pmmio + IMR, 0xffffffff);
346 write32(pmmio + EIR, 0xffffffff);
347
348 if (gtt_setup(pmmio)) {
349 printk(BIOS_ERR, "ERROR: GTT Setup Failed!!!\n");
350 return 0;
351 }
352
353 /* Setup GTT. */
354
355 reg16 = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), GGC);
356 uma_size = 0;
357 if (!(reg16 & 2)) {
358 reg16 >>= 4;
359 reg16 &= 7;
360 switch (reg16) {
361 case 1:
362 uma_size = 1024;
363 break;
364 case 3:
365 uma_size = 8192;
366 break;
367 }
368
369 printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10);
370 }
371
Vladimir Serbinenko055fe032014-08-19 23:59:27 +0200372 for (i = 0; i < (uma_size - 256) / 4; i++)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200373 {
374 outl((i << 2) | 1, piobase);
375 outl(pphysbase + (i << 12) + 1, piobase + 4);
376 }
377
378 temp = read32(pmmio + PGETBL_CTL);
379 printk(BIOS_INFO, "GTT PGETBL_CTL register: 0x%lx\n", temp);
380
381 if (temp & 1)
382 printk(BIOS_INFO, "GTT Enabled\n");
383 else
384 printk(BIOS_ERR, "ERROR: GTT is still Disabled!!!\n");
385
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200386#if !IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
387 vga_misc_write(0x67);
388
389 write32(pmmio + DSPCNTR(0), DISPPLANE_SEL_PIPE_B);
390
391 write32(pmmio + VGACNTRL, 0x02c4008e | VGA_PIPE_B_SELECT);
392
393 vga_textmode_init();
394#else
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200395 printk(BIOS_SPEW, "memset %p to 0x00 for %d bytes\n",
396 (void *)pgfx, hactive * vactive * 4);
397 memset((void *)pgfx, 0x00, hactive * vactive * 4);
398
399 set_vbe_mode_info_valid(&edid, pgfx);
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200400#endif
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200401 return 0;
402}
403#endif
404
Stefan Reinauer30140a52009-03-11 16:20:39 +0000405static void gma_func0_init(struct device *dev)
406{
407 u32 reg32;
408
Patrick Georgi6444bd42012-07-06 11:31:39 +0200409 /* Unconditionally reset graphics */
410 pci_write_config8(dev, GDRST, 1);
411 udelay(50);
412 pci_write_config8(dev, GDRST, 0);
413 /* wait for device to finish */
414 while (pci_read_config8(dev, GDRST) & 1) { };
415
Stefan Reinauer30140a52009-03-11 16:20:39 +0000416 /* IGD needs to be Bus Master */
417 reg32 = pci_read_config32(dev, PCI_COMMAND);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200418 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER
419 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100420
421#if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
422 /* PCI Init, will run VBIOS */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000423 pci_dev_init(dev);
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100424#endif
425
426
427#if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
428 /* This should probably run before post VBIOS init. */
429 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
Francis Rowe71512b22015-03-16 05:31:40 +0000430 void *mmiobase;
431 u32 iobase, graphics_base;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200432 struct northbridge_intel_i945_config *conf = dev->chip_info;
433
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100434 iobase = dev->resource_list[1].base;
Francis Rowe71512b22015-03-16 05:31:40 +0000435 mmiobase = (void *)(uintptr_t)dev->resource_list[0].base;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200436 graphics_base = dev->resource_list[2].base;
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100437
Peter Stugec6f09972013-06-08 01:31:44 +0200438 printk(BIOS_SPEW, "GMADR=0x%08x GTTADR=0x%08x\n",
Paul Menzeld235da12014-06-03 00:15:30 +0200439 pci_read_config32(dev, GMADR),
440 pci_read_config32(dev, GTTADR)
Peter Stugec6f09972013-06-08 01:31:44 +0200441 );
442
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200443 int err;
444 err = intel_gma_init(conf, pci_read_config32(dev, 0x5c) & ~0xf,
445 iobase, mmiobase, graphics_base);
446 if (err == 0)
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +0200447 gfx_set_init_done(1);
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100448#endif
Stefan Reinauer30140a52009-03-11 16:20:39 +0000449}
450
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200451/* This doesn't reclaim stolen UMA memory, but IGD could still
452 be reenabled later. */
453static void gma_func0_disable(struct device *dev)
454{
455 struct device *dev_host = dev_find_slot(0, PCI_DEVFN(0x0, 0));
456
457 pci_write_config16(dev, GCFC, 0xa00);
458 pci_write_config16(dev_host, GGC, (1 << 1));
459
460 unsigned int reg32 = pci_read_config32(dev_host, DEVEN);
461 reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1);
462 pci_write_config32(dev_host, DEVEN, reg32);
463
464 dev->enabled = 0;
465}
466
Stefan Reinauer30140a52009-03-11 16:20:39 +0000467static void gma_func1_init(struct device *dev)
468{
469 u32 reg32;
470
471 /* IGD needs to be Bus Master, also enable IO accesss */
472 reg32 = pci_read_config32(dev, PCI_COMMAND);
Stefan Reinauer109ab312009-08-12 16:08:05 +0000473 pci_write_config32(dev, PCI_COMMAND, reg32 |
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200474 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Sven Schnelleb629d142011-06-12 14:30:10 +0200475
Francis Rowe71512b22015-03-16 05:31:40 +0000476 /* Permanently set tft_brightness to 0xff. Ignore nvramtool configuration */
477 pci_write_config8(dev, 0xf4, 0xff);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000478}
479
480static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
481{
482 if (!vendor || !device) {
483 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
484 pci_read_config32(dev, PCI_VENDOR_ID));
485 } else {
486 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
487 ((device & 0xffff) << 16) | (vendor & 0xffff));
488 }
489}
490
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100491const struct i915_gpu_controller_info *
492intel_gma_get_controller_info(void)
493{
494 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
495 if (!dev) {
496 return NULL;
497 }
498 struct northbridge_intel_i945_config *chip = dev->chip_info;
499 return &chip->gfx;
500}
501
Alexander Couzens5eea4582015-04-12 22:18:55 +0200502static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100503{
504 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
505 if (!gfx) {
506 return;
507 }
508
509 drivers_intel_gma_displays_ssdt_generate(gfx);
510}
511
Stefan Reinauer30140a52009-03-11 16:20:39 +0000512static struct pci_operations gma_pci_ops = {
513 .set_subsystem = gma_set_subsystem,
514};
515
516static struct device_operations gma_func0_ops = {
517 .read_resources = pci_dev_read_resources,
518 .set_resources = pci_dev_set_resources,
519 .enable_resources = pci_dev_enable_resources,
520 .init = gma_func0_init,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100521 .acpi_fill_ssdt_generator = gma_ssdt,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000522 .scan_bus = 0,
523 .enable = 0,
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200524 .disable = gma_func0_disable,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000525 .ops_pci = &gma_pci_ops,
526};
527
528
529static struct device_operations gma_func1_ops = {
530 .read_resources = pci_dev_read_resources,
531 .set_resources = pci_dev_set_resources,
532 .enable_resources = pci_dev_enable_resources,
533 .init = gma_func1_init,
534 .scan_bus = 0,
535 .enable = 0,
536 .ops_pci = &gma_pci_ops,
537};
538
Vladimir Serbinenko10dd0e32014-11-17 00:07:12 +0100539static const unsigned short pci_device_ids[] = { 0x27a2, 0x27ae, 0 };
540
Stefan Reinauer30140a52009-03-11 16:20:39 +0000541static const struct pci_driver i945_gma_func0_driver __pci_driver = {
542 .ops = &gma_func0_ops,
543 .vendor = PCI_VENDOR_ID_INTEL,
Vladimir Serbinenko10dd0e32014-11-17 00:07:12 +0100544 .devices = pci_device_ids,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000545};
546
547static const struct pci_driver i945_gma_func1_driver __pci_driver = {
548 .ops = &gma_func1_ops,
549 .vendor = PCI_VENDOR_ID_INTEL,
550 .device = 0x27a6,
551};