blob: 8b70e55cf2f312ccc2cf903ffa06ff0a9da1db8d [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;
Mono2e4f83b2015-09-07 21:15:26 +020088 struct edid_mode *mode;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020089 u8 edid_data[128];
90 unsigned long temp;
91 int hpolarity, vpolarity;
92 u32 candp1, candn;
93 u32 best_delta = 0xffffffff;
94 u32 target_frequency;
95 u32 pixel_p1 = 1;
96 u32 pixel_n = 1;
97 u32 pixel_m1 = 1;
98 u32 pixel_m2 = 1;
99 u32 hactive, vactive, right_border, bottom_border;
100 u32 vsync, hsync, vblank, hblank, hfront_porch, vfront_porch;
101 u32 i, j;
102 u32 uma_size;
103 u16 reg16;
104
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200105 printk(BIOS_SPEW,
Francis Rowe71512b22015-03-16 05:31:40 +0000106 "i915lightup: graphics %p mmio %p addrport %04x physbase %08x\n",
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200107 (void *)pgfx, pmmio, piobase, pphysbase);
108
109 intel_gmbus_read_edid(pmmio + GMBUS0, 3, 0x50, edid_data, 128);
110 decode_edid(edid_data, sizeof(edid_data), &edid);
Mono2e4f83b2015-09-07 21:15:26 +0200111 mode = &edid.mode;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200112
Mono2e4f83b2015-09-07 21:15:26 +0200113 hpolarity = (mode->phsync == '-');
114 vpolarity = (mode->pvsync == '-');
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200115 hactive = edid.x_resolution;
116 vactive = edid.y_resolution;
Mono2e4f83b2015-09-07 21:15:26 +0200117 right_border = mode->hborder;
118 bottom_border = mode->vborder;
119 vblank = mode->vbl;
120 hblank = mode->hbl;
121 vsync = mode->vspw;
122 hsync = mode->hspw;
123 hfront_porch = mode->hso;
124 vfront_porch = mode->vso;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200125
126 for (i = 0; i < 2; i++)
127 for (j = 0; j < 0x100; j++)
128 /* R=j, G=j, B=j. */
129 write32(pmmio + PALETTE(i) + 4 * j, 0x10101 * j);
130
131 write32(pmmio + PCH_PP_CONTROL, PANEL_UNLOCK_REGS
132 | (read32(pmmio + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK));
133
134 write32(pmmio + MI_ARB_STATE, MI_ARB_C3_LP_WRITE_ENABLE | (1 << 27));
135 /* Clean registers. */
136 for (i = 0; i < 0x20; i += 4)
137 write32(pmmio + RENDER_RING_BASE + i, 0);
138 for (i = 0; i < 0x20; i += 4)
139 write32(pmmio + FENCE_REG_965_0 + i, 0);
140 write32(pmmio + PP_ON_DELAYS, 0);
141 write32(pmmio + PP_OFF_DELAYS, 0);
142
143 /* Disable VGA. */
144 write32(pmmio + VGACNTRL, VGA_DISP_DISABLE);
145
146 /* Disable pipes. */
147 write32(pmmio + PIPECONF(0), 0);
148 write32(pmmio + PIPECONF(1), 0);
149
150 /* Init PRB0. */
151 write32(pmmio + HWS_PGA, 0x352d2000);
152 write32(pmmio + PRB0_CTL, 0);
153 write32(pmmio + PRB0_HEAD, 0);
154 write32(pmmio + PRB0_TAIL, 0);
155 write32(pmmio + PRB0_START, 0);
156 write32(pmmio + PRB0_CTL, 0x0001f001);
157
158 write32(pmmio + D_STATE, DSTATE_PLL_D3_OFF
159 | DSTATE_GFX_CLOCK_GATING | DSTATE_DOT_CLOCK_GATING);
160 write32(pmmio + ECOSKPD, 0x00010000);
161 write32(pmmio + HWSTAM, 0xeffe);
162 write32(pmmio + PORT_HOTPLUG_EN, conf->gpu_hotplug);
163 write32(pmmio + INSTPM, 0x08000000 | INSTPM_AGPBUSY_DIS);
164
Mono2e4f83b2015-09-07 21:15:26 +0200165 target_frequency = conf->gpu_lvds_is_dual_channel ? mode->pixel_clock
166 : (2 * mode->pixel_clock);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200167
168 /* Find suitable divisors. */
169 for (candp1 = 1; candp1 <= 8; candp1++) {
170 for (candn = 5; candn <= 10; candn++) {
171 u32 cur_frequency;
172 u32 m; /* 77 - 131. */
173 u32 denom; /* 35 - 560. */
174 u32 current_delta;
175
176 denom = candn * candp1 * 7;
177 /* Doesnt overflow for up to
178 5000000 kHz = 5 GHz. */
179 m = (target_frequency * denom
180 + BASE_FREQUENCY / 2) / BASE_FREQUENCY;
181
182 if (m < 77 || m > 131)
183 continue;
184
185 cur_frequency = (BASE_FREQUENCY * m) / denom;
186 if (target_frequency > cur_frequency)
187 current_delta = target_frequency - cur_frequency;
188 else
189 current_delta = cur_frequency - target_frequency;
190
191 if (best_delta > current_delta) {
192 best_delta = current_delta;
193 pixel_n = candn;
194 pixel_p1 = candp1;
195 pixel_m2 = ((m + 3) % 5) + 7;
196 pixel_m1 = (m - pixel_m2) / 5;
197 }
198 }
199 }
200
201 if (best_delta == 0xffffffff) {
202 printk (BIOS_ERR, "Couldn't find GFX clock divisors\n");
203 return -1;
204 }
205
206 printk(BIOS_INFO, "bringing up panel at resolution %d x %d\n",
207 hactive, vactive);
208 printk(BIOS_DEBUG, "Borders %d x %d\n", right_border, bottom_border);
209 printk(BIOS_DEBUG, "Blank %d x %d\n", hblank, vblank);
210 printk(BIOS_DEBUG, "Sync %d x %d\n", hsync, vsync);
211 printk(BIOS_DEBUG, "Front porch %d x %d\n", hfront_porch, vfront_porch);
212 printk(BIOS_DEBUG, (conf->gpu_lvds_use_spread_spectrum_clock
213 ? "Spread spectrum clock\n"
214 : "DREF clock\n"));
215 printk(BIOS_DEBUG, (conf->gpu_lvds_is_dual_channel
216 ? "Dual channel\n"
217 : "Single channel\n"));
218 printk(BIOS_DEBUG, "Polarities %d, %d\n",
219 hpolarity, vpolarity);
220 printk(BIOS_DEBUG, "Pixel N=%d, M1=%d, M2=%d, P1=%d\n",
221 pixel_n, pixel_m1, pixel_m2, pixel_p1);
222 printk(BIOS_DEBUG, "Pixel clock %d kHz\n",
223 BASE_FREQUENCY * (5 * pixel_m1 + pixel_m2) / pixel_n
224 / (pixel_p1 * 7));
225
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200226#if !IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
227 write32(pmmio + PF_WIN_SZ(0), vactive | (hactive << 16));
228 write32(pmmio + PF_WIN_POS(0), 0);
229 write32(pmmio + PF_CTL(0),PF_ENABLE | PF_FILTER_MED_3x3);
230 write32(pmmio + PFIT_CONTROL, PFIT_ENABLE | (1 << PFIT_PIPE_SHIFT) | HORIZ_AUTO_SCALE | VERT_AUTO_SCALE);
231#else
232 /* Disable panel fitter (we're in native resolution). */
233 write32(pmmio + PF_CTL(0), 0);
234 write32(pmmio + PF_WIN_SZ(0), 0);
235 write32(pmmio + PF_WIN_POS(0), 0);
236 write32(pmmio + PFIT_PGM_RATIOS, 0);
237 write32(pmmio + PFIT_CONTROL, 0);
238#endif
239
240 mdelay(1);
241
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200242 write32(pmmio + DSPCNTR(0), DISPPLANE_BGRX888
243 | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE);
244
245 mdelay(1);
246 write32(pmmio + PP_CONTROL, PANEL_UNLOCK_REGS
247 | (read32(pmmio + PP_CONTROL) & ~PANEL_UNLOCK_MASK));
248 write32(pmmio + FP0(1),
249 ((pixel_n - 2) << 16)
250 | ((pixel_m1 - 2) << 8) | pixel_m2);
251 write32(pmmio + DPLL(1),
252 DPLL_VGA_MODE_DIS |
253 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
254 | (conf->gpu_lvds_is_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
255 : DPLLB_LVDS_P2_CLOCK_DIV_14)
256 | (conf->gpu_lvds_use_spread_spectrum_clock
257 ? DPLL_INTEGRATED_CLOCK_VLV | DPLL_INTEGRATED_CRI_CLK_VLV
258 : 0)
259 | (pixel_p1 << 16)
260 | (pixel_p1));
261 mdelay(1);
262 write32(pmmio + DPLL(1),
263 DPLL_VGA_MODE_DIS |
264 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
265 | (conf->gpu_lvds_is_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
266 : DPLLB_LVDS_P2_CLOCK_DIV_14)
267 | ((conf->gpu_lvds_use_spread_spectrum_clock ? 3 : 0) << 13)
268 | (pixel_p1 << 16)
269 | (pixel_p1));
270 mdelay(1);
271 write32(pmmio + HTOTAL(1),
272 ((hactive + right_border + hblank - 1) << 16)
273 | (hactive - 1));
274 write32(pmmio + HBLANK(1),
275 ((hactive + right_border + hblank - 1) << 16)
276 | (hactive + right_border - 1));
277 write32(pmmio + HSYNC(1),
278 ((hactive + right_border + hfront_porch + hsync - 1) << 16)
279 | (hactive + right_border + hfront_porch - 1));
280
281 write32(pmmio + VTOTAL(1), ((vactive + bottom_border + vblank - 1) << 16)
282 | (vactive - 1));
283 write32(pmmio + VBLANK(1), ((vactive + bottom_border + vblank - 1) << 16)
284 | (vactive + bottom_border - 1));
285 write32(pmmio + VSYNC(1),
286 (vactive + bottom_border + vfront_porch + vsync - 1)
287 | (vactive + bottom_border + vfront_porch - 1));
288
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200289#if !IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
290 write32(pmmio + PIPESRC(1), (639 << 16) | 399);
291#else
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200292 write32(pmmio + PIPESRC(1), ((hactive - 1) << 16) | (vactive - 1));
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200293#endif
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200294 mdelay(1);
295
296 write32(pmmio + DSPSIZE(0), (hactive - 1) | ((vactive - 1) << 16));
297 write32(pmmio + DSPPOS(0), 0);
298
299 /* Backlight init. */
300 write32(pmmio + FW_BLC_SELF, FW_BLC_SELF_EN_MASK);
301 write32(pmmio + FW_BLC, 0x011d011a);
302 write32(pmmio + FW_BLC2, 0x00000102);
303 write32(pmmio + FW_BLC_SELF, FW_BLC_SELF_EN_MASK);
304 write32(pmmio + FW_BLC_SELF, 0x0001003f);
305 write32(pmmio + FW_BLC, 0x011d0109);
306 write32(pmmio + FW_BLC2, 0x00000102);
307 write32(pmmio + FW_BLC_SELF, FW_BLC_SELF_EN_MASK);
308 write32(pmmio + BLC_PWM_CTL, conf->gpu_backlight);
309
310 edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63;
311 write32(pmmio + DSPADDR(0), 0);
312 write32(pmmio + DSPSURF(0), 0);
313 write32(pmmio + DSPSTRIDE(0), edid.bytes_per_line);
314 write32(pmmio + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888
315 | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE);
316 mdelay(1);
317
318 write32(pmmio + PIPECONF(1), PIPECONF_ENABLE);
319 write32(pmmio + LVDS, LVDS_ON
320 | (hpolarity << 20) | (vpolarity << 21)
321 | (conf->gpu_lvds_is_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
322 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
323 | LVDS_CLOCK_A_POWERUP_ALL
324 | LVDS_PIPE(1));
325
326 write32(pmmio + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
327 write32(pmmio + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET);
328 mdelay(1);
329 write32(pmmio + PP_CONTROL, PANEL_UNLOCK_REGS
330 | PANEL_POWER_ON | PANEL_POWER_RESET);
331
332 printk (BIOS_DEBUG, "waiting for panel powerup\n");
333 while (1) {
334 u32 reg32;
335 reg32 = read32(pmmio + PP_STATUS);
336 if ((reg32 & PP_SEQUENCE_MASK) == PP_SEQUENCE_NONE)
337 break;
338 }
339 printk (BIOS_DEBUG, "panel powered up\n");
340
341 write32(pmmio + PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET);
342
343 /* Clear interrupts. */
344 write32(pmmio + DEIIR, 0xffffffff);
345 write32(pmmio + SDEIIR, 0xffffffff);
346 write32(pmmio + IIR, 0xffffffff);
347 write32(pmmio + IMR, 0xffffffff);
348 write32(pmmio + EIR, 0xffffffff);
349
350 if (gtt_setup(pmmio)) {
351 printk(BIOS_ERR, "ERROR: GTT Setup Failed!!!\n");
352 return 0;
353 }
354
355 /* Setup GTT. */
356
357 reg16 = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), GGC);
358 uma_size = 0;
359 if (!(reg16 & 2)) {
360 reg16 >>= 4;
361 reg16 &= 7;
362 switch (reg16) {
363 case 1:
364 uma_size = 1024;
365 break;
366 case 3:
367 uma_size = 8192;
368 break;
369 }
370
371 printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10);
372 }
373
Vladimir Serbinenko055fe032014-08-19 23:59:27 +0200374 for (i = 0; i < (uma_size - 256) / 4; i++)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200375 {
376 outl((i << 2) | 1, piobase);
377 outl(pphysbase + (i << 12) + 1, piobase + 4);
378 }
379
380 temp = read32(pmmio + PGETBL_CTL);
381 printk(BIOS_INFO, "GTT PGETBL_CTL register: 0x%lx\n", temp);
382
383 if (temp & 1)
384 printk(BIOS_INFO, "GTT Enabled\n");
385 else
386 printk(BIOS_ERR, "ERROR: GTT is still Disabled!!!\n");
387
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200388#if !IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
389 vga_misc_write(0x67);
390
391 write32(pmmio + DSPCNTR(0), DISPPLANE_SEL_PIPE_B);
392
393 write32(pmmio + VGACNTRL, 0x02c4008e | VGA_PIPE_B_SELECT);
394
395 vga_textmode_init();
396#else
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200397 printk(BIOS_SPEW, "memset %p to 0x00 for %d bytes\n",
398 (void *)pgfx, hactive * vactive * 4);
399 memset((void *)pgfx, 0x00, hactive * vactive * 4);
400
401 set_vbe_mode_info_valid(&edid, pgfx);
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200402#endif
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200403 return 0;
404}
405#endif
406
Stefan Reinauer30140a52009-03-11 16:20:39 +0000407static void gma_func0_init(struct device *dev)
408{
409 u32 reg32;
410
Patrick Georgi6444bd42012-07-06 11:31:39 +0200411 /* Unconditionally reset graphics */
412 pci_write_config8(dev, GDRST, 1);
413 udelay(50);
414 pci_write_config8(dev, GDRST, 0);
415 /* wait for device to finish */
416 while (pci_read_config8(dev, GDRST) & 1) { };
417
Stefan Reinauer30140a52009-03-11 16:20:39 +0000418 /* IGD needs to be Bus Master */
419 reg32 = pci_read_config32(dev, PCI_COMMAND);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200420 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER
421 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100422
423#if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
424 /* PCI Init, will run VBIOS */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000425 pci_dev_init(dev);
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100426#endif
427
428
429#if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
430 /* This should probably run before post VBIOS init. */
431 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
Francis Rowe71512b22015-03-16 05:31:40 +0000432 void *mmiobase;
433 u32 iobase, graphics_base;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200434 struct northbridge_intel_i945_config *conf = dev->chip_info;
435
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100436 iobase = dev->resource_list[1].base;
Francis Rowe71512b22015-03-16 05:31:40 +0000437 mmiobase = (void *)(uintptr_t)dev->resource_list[0].base;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200438 graphics_base = dev->resource_list[2].base;
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100439
Peter Stugec6f09972013-06-08 01:31:44 +0200440 printk(BIOS_SPEW, "GMADR=0x%08x GTTADR=0x%08x\n",
Paul Menzeld235da12014-06-03 00:15:30 +0200441 pci_read_config32(dev, GMADR),
442 pci_read_config32(dev, GTTADR)
Peter Stugec6f09972013-06-08 01:31:44 +0200443 );
444
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200445 int err;
446 err = intel_gma_init(conf, pci_read_config32(dev, 0x5c) & ~0xf,
447 iobase, mmiobase, graphics_base);
448 if (err == 0)
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +0200449 gfx_set_init_done(1);
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100450#endif
Stefan Reinauer30140a52009-03-11 16:20:39 +0000451}
452
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200453/* This doesn't reclaim stolen UMA memory, but IGD could still
454 be reenabled later. */
455static void gma_func0_disable(struct device *dev)
456{
457 struct device *dev_host = dev_find_slot(0, PCI_DEVFN(0x0, 0));
458
459 pci_write_config16(dev, GCFC, 0xa00);
460 pci_write_config16(dev_host, GGC, (1 << 1));
461
462 unsigned int reg32 = pci_read_config32(dev_host, DEVEN);
463 reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1);
464 pci_write_config32(dev_host, DEVEN, reg32);
465
466 dev->enabled = 0;
467}
468
Stefan Reinauer30140a52009-03-11 16:20:39 +0000469static void gma_func1_init(struct device *dev)
470{
471 u32 reg32;
472
473 /* IGD needs to be Bus Master, also enable IO accesss */
474 reg32 = pci_read_config32(dev, PCI_COMMAND);
Stefan Reinauer109ab312009-08-12 16:08:05 +0000475 pci_write_config32(dev, PCI_COMMAND, reg32 |
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200476 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Sven Schnelleb629d142011-06-12 14:30:10 +0200477
Francis Rowe71512b22015-03-16 05:31:40 +0000478 /* Permanently set tft_brightness to 0xff. Ignore nvramtool configuration */
479 pci_write_config8(dev, 0xf4, 0xff);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000480}
481
482static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
483{
484 if (!vendor || !device) {
485 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
486 pci_read_config32(dev, PCI_VENDOR_ID));
487 } else {
488 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
489 ((device & 0xffff) << 16) | (vendor & 0xffff));
490 }
491}
492
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100493const struct i915_gpu_controller_info *
494intel_gma_get_controller_info(void)
495{
496 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
497 if (!dev) {
498 return NULL;
499 }
500 struct northbridge_intel_i945_config *chip = dev->chip_info;
Patrick Georgi54e227e2015-08-08 22:02:12 +0200501 if (!chip) {
502 return NULL;
503 }
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100504 return &chip->gfx;
505}
506
Alexander Couzens5eea4582015-04-12 22:18:55 +0200507static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100508{
509 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
510 if (!gfx) {
511 return;
512 }
513
514 drivers_intel_gma_displays_ssdt_generate(gfx);
515}
516
Stefan Reinauer30140a52009-03-11 16:20:39 +0000517static struct pci_operations gma_pci_ops = {
518 .set_subsystem = gma_set_subsystem,
519};
520
521static struct device_operations gma_func0_ops = {
522 .read_resources = pci_dev_read_resources,
523 .set_resources = pci_dev_set_resources,
524 .enable_resources = pci_dev_enable_resources,
525 .init = gma_func0_init,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100526 .acpi_fill_ssdt_generator = gma_ssdt,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000527 .scan_bus = 0,
528 .enable = 0,
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200529 .disable = gma_func0_disable,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000530 .ops_pci = &gma_pci_ops,
531};
532
533
534static struct device_operations gma_func1_ops = {
535 .read_resources = pci_dev_read_resources,
536 .set_resources = pci_dev_set_resources,
537 .enable_resources = pci_dev_enable_resources,
538 .init = gma_func1_init,
539 .scan_bus = 0,
540 .enable = 0,
541 .ops_pci = &gma_pci_ops,
542};
543
Vladimir Serbinenko10dd0e32014-11-17 00:07:12 +0100544static const unsigned short pci_device_ids[] = { 0x27a2, 0x27ae, 0 };
545
Stefan Reinauer30140a52009-03-11 16:20:39 +0000546static const struct pci_driver i945_gma_func0_driver __pci_driver = {
547 .ops = &gma_func0_ops,
548 .vendor = PCI_VENDOR_ID_INTEL,
Vladimir Serbinenko10dd0e32014-11-17 00:07:12 +0100549 .devices = pci_device_ids,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000550};
551
552static const struct pci_driver i945_gma_func1_driver __pci_driver = {
553 .ops = &gma_func1_ops,
554 .vendor = PCI_VENDOR_ID_INTEL,
555 .device = 0x27a6,
556};