blob: eac8717cdec134ba51a3b1220f71558189d80fae [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.
Stefan Reinauer30140a52009-03-11 16:20:39 +000014 */
15
16#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020017#include <bootmode.h>
Patrick Georgi6444bd42012-07-06 11:31:39 +020018#include <delay.h>
Stefan Reinauer30140a52009-03-11 16:20:39 +000019#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
Sven Schnelleb629d142011-06-12 14:30:10 +020022#include <pc80/mc146818rtc.h>
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020023#include <edid.h>
24#include <drivers/intel/gma/edid.h>
25#include <drivers/intel/gma/i915.h>
26#include <string.h>
Vladimir Serbinenko0092c992014-08-21 01:06:53 +020027#include <pc80/vga.h>
28#include <pc80/vga_io.h>
Arthur Heymans7dfc8a52016-09-02 22:35:32 +020029#include <commonlib/helpers.h>
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020030
Patrick Georgice6e9fe2012-07-20 12:37:06 +020031#include "i945.h"
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020032#include "chip.h"
Stefan Reinauer30140a52009-03-11 16:20:39 +000033
Patrick Georgi6444bd42012-07-06 11:31:39 +020034#define GDRST 0xc0
Arthur Heymansc057a0612016-10-22 14:16:48 +020035#define MSAC 0x62 /* Multi Size Aperture Control */
Patrick Georgi6444bd42012-07-06 11:31:39 +020036
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020037#define LVDS_CLOCK_A_POWERUP_ALL (3 << 8)
38#define LVDS_CLOCK_B_POWERUP_ALL (3 << 4)
39#define LVDS_CLOCK_BOTH_POWERUP_ALL (3 << 2)
40#define DISPPLANE_BGRX888 (0x6<<26)
41#define DPLLB_LVDS_P2_CLOCK_DIV_7 (1 << 24) /* i915 */
42
43#define DPLL_INTEGRATED_CRI_CLK_VLV (1<<14)
44
45#define PGETBL_CTL 0x2020
46#define PGETBL_ENABLED 0x00000001
47
Arthur Heymans7dfc8a52016-09-02 22:35:32 +020048#define BASE_FREQUENCY 100000
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020049
Arthur Heymans85cfddb2017-02-06 13:47:21 +010050static int gtt_setup(u8 *mmiobase)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020051{
52 unsigned long PGETBL_save;
Paul Menzelcc95f182014-06-05 22:45:35 +020053 unsigned long tom; // top of memory
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020054
Paul Menzelcc95f182014-06-05 22:45:35 +020055 /*
56 * The Video BIOS places the GTT right below top of memory.
Denis 'GNUtoo' Carikli16110e72014-10-14 07:33:53 +020057 */
Paul Menzelcc95f182014-06-05 22:45:35 +020058 tom = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), TOLUD) << 24;
59 PGETBL_save = tom - 256 * KiB;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020060 PGETBL_save |= PGETBL_ENABLED;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020061 PGETBL_save |= 2; /* set GTT to 256kb */
62
63 write32(mmiobase + GFX_FLSH_CNTL, 0);
64
65 write32(mmiobase + PGETBL_CTL, PGETBL_save);
66
67 /* verify */
68 if (read32(mmiobase + PGETBL_CTL) & PGETBL_ENABLED) {
69 printk(BIOS_DEBUG, "gtt_setup is enabled.\n");
70 } else {
71 printk(BIOS_DEBUG, "gtt_setup failed!!!\n");
72 return 1;
73 }
74 write32(mmiobase + GFX_FLSH_CNTL, 0);
75
76 return 0;
77}
78
Arthur Heymansb59bcb22016-09-05 22:46:11 +020079static int intel_gma_init_lvds(struct northbridge_intel_i945_config *conf,
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020080 unsigned int pphysbase, unsigned int piobase,
Arthur Heymans85cfddb2017-02-06 13:47:21 +010081 u8 *mmiobase, unsigned int pgfx)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020082{
83 struct edid edid;
Mono2e4f83b2015-09-07 21:15:26 +020084 struct edid_mode *mode;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020085 u8 edid_data[128];
86 unsigned long temp;
87 int hpolarity, vpolarity;
Arthur Heymans7dfc8a52016-09-02 22:35:32 +020088 u32 smallest_err = 0xffffffff;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020089 u32 target_frequency;
90 u32 pixel_p1 = 1;
Arthur Heymans7dfc8a52016-09-02 22:35:32 +020091 u32 pixel_p2;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020092 u32 pixel_n = 1;
93 u32 pixel_m1 = 1;
94 u32 pixel_m2 = 1;
95 u32 hactive, vactive, right_border, bottom_border;
96 u32 vsync, hsync, vblank, hblank, hfront_porch, vfront_porch;
97 u32 i, j;
98 u32 uma_size;
99 u16 reg16;
100
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200101 printk(BIOS_SPEW,
Francis Rowe71512b22015-03-16 05:31:40 +0000102 "i915lightup: graphics %p mmio %p addrport %04x physbase %08x\n",
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100103 (void *)pgfx, mmiobase, piobase, pphysbase);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200104
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100105 intel_gmbus_read_edid(mmiobase + GMBUS0, 3, 0x50, edid_data,
Arthur Heymans7141ff32016-10-10 17:49:00 +0200106 sizeof(edid_data));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200107 decode_edid(edid_data, sizeof(edid_data), &edid);
Mono2e4f83b2015-09-07 21:15:26 +0200108 mode = &edid.mode;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200109
Mono2e4f83b2015-09-07 21:15:26 +0200110 hpolarity = (mode->phsync == '-');
111 vpolarity = (mode->pvsync == '-');
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200112 hactive = edid.x_resolution;
113 vactive = edid.y_resolution;
Mono2e4f83b2015-09-07 21:15:26 +0200114 right_border = mode->hborder;
115 bottom_border = mode->vborder;
116 vblank = mode->vbl;
117 hblank = mode->hbl;
118 vsync = mode->vspw;
119 hsync = mode->hspw;
120 hfront_porch = mode->hso;
121 vfront_porch = mode->vso;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200122
123 for (i = 0; i < 2; i++)
124 for (j = 0; j < 0x100; j++)
Elyes HAOUAS0a15fe92016-09-17 19:12:27 +0200125 /* R = j, G = j, B = j. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100126 write32(mmiobase + PALETTE(i) + 4 * j, 0x10101 * j);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200127
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100128 write32(mmiobase + PCH_PP_CONTROL, PANEL_UNLOCK_REGS
129 | (read32(mmiobase + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200130
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100131 write32(mmiobase + MI_ARB_STATE, MI_ARB_C3_LP_WRITE_ENABLE | (1 << 27));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200132 /* Clean registers. */
133 for (i = 0; i < 0x20; i += 4)
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100134 write32(mmiobase + RENDER_RING_BASE + i, 0);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200135 for (i = 0; i < 0x20; i += 4)
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100136 write32(mmiobase + FENCE_REG_965_0 + i, 0);
137 write32(mmiobase + PP_ON_DELAYS, 0);
138 write32(mmiobase + PP_OFF_DELAYS, 0);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200139
140 /* Disable VGA. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100141 write32(mmiobase + VGACNTRL, VGA_DISP_DISABLE);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200142
143 /* Disable pipes. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100144 write32(mmiobase + PIPECONF(0), 0);
145 write32(mmiobase + PIPECONF(1), 0);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200146
147 /* Init PRB0. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100148 write32(mmiobase + HWS_PGA, 0x352d2000);
149 write32(mmiobase + PRB0_CTL, 0);
150 write32(mmiobase + PRB0_HEAD, 0);
151 write32(mmiobase + PRB0_TAIL, 0);
152 write32(mmiobase + PRB0_START, 0);
153 write32(mmiobase + PRB0_CTL, 0x0001f001);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200154
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100155 write32(mmiobase + D_STATE, DSTATE_PLL_D3_OFF
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200156 | DSTATE_GFX_CLOCK_GATING | DSTATE_DOT_CLOCK_GATING);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100157 write32(mmiobase + ECOSKPD, 0x00010000);
158 write32(mmiobase + HWSTAM, 0xeffe);
159 write32(mmiobase + PORT_HOTPLUG_EN, conf->gpu_hotplug);
160 write32(mmiobase + INSTPM, 0x08000000 | INSTPM_AGPBUSY_DIS);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200161
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200162 /* p2 divisor must 7 for dual channel LVDS */
163 /* and 14 for single channel LVDS */
164 pixel_p2 = mode->lvds_dual_channel ? 7 : 14;
165 target_frequency = mode->pixel_clock;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200166
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200167 /* Find suitable divisors, m1, m2, p1, n. */
168 /* refclock * (5 * (m1 + 2) + (m1 + 2)) / (n + 2) / p1 / p2 */
169 /* should be closest to target frequency as possible */
170 u32 candn, candm1, candm2, candp1;
171 for (candm1 = 8; candm1 <= 18; candm1++) {
172 for (candm2 = 3; candm2 <= 7; candm2++) {
173 for (candn = 1; candn <= 6; candn++) {
174 for (candp1 = 1; candp1 <= 8; candp1++) {
175 u32 m = 5 * (candm1 + 2) + (candm2 + 2);
176 u32 p = candp1 * pixel_p2;
177 u32 vco = DIV_ROUND_CLOSEST(BASE_FREQUENCY * m, candn + 2);
178 u32 dot = DIV_ROUND_CLOSEST(vco, p);
Arthur Heymans75f91312016-10-12 01:04:28 +0200179 u32 this_err = MAX(dot, target_frequency) -
180 MIN(dot, target_frequency);
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200181 if ((m < 70) || (m > 120))
182 continue;
183 if (this_err < smallest_err) {
184 smallest_err = this_err;
185 pixel_n = candn;
186 pixel_m1 = candm1;
187 pixel_m2 = candm2;
188 pixel_p1 = candp1;
189 }
190 }
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200191 }
192 }
193 }
194
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200195 if (smallest_err == 0xffffffff) {
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200196 printk (BIOS_ERR, "Couldn't find GFX clock divisors\n");
197 return -1;
198 }
199
200 printk(BIOS_INFO, "bringing up panel at resolution %d x %d\n",
201 hactive, vactive);
202 printk(BIOS_DEBUG, "Borders %d x %d\n", right_border, bottom_border);
203 printk(BIOS_DEBUG, "Blank %d x %d\n", hblank, vblank);
204 printk(BIOS_DEBUG, "Sync %d x %d\n", hsync, vsync);
205 printk(BIOS_DEBUG, "Front porch %d x %d\n", hfront_porch, vfront_porch);
206 printk(BIOS_DEBUG, (conf->gpu_lvds_use_spread_spectrum_clock
207 ? "Spread spectrum clock\n"
208 : "DREF clock\n"));
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200209 printk(BIOS_DEBUG, (mode->lvds_dual_channel
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200210 ? "Dual channel\n"
211 : "Single channel\n"));
212 printk(BIOS_DEBUG, "Polarities %d, %d\n",
213 hpolarity, vpolarity);
214 printk(BIOS_DEBUG, "Pixel N=%d, M1=%d, M2=%d, P1=%d\n",
215 pixel_n, pixel_m1, pixel_m2, pixel_p1);
216 printk(BIOS_DEBUG, "Pixel clock %d kHz\n",
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200217 BASE_FREQUENCY * (5 * (pixel_m1 + 2) + (pixel_m2 + 2)) /
218 (pixel_n + 2) / (pixel_p1 * pixel_p2));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200219
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200220 if (IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)) {
221 /* Disable panel fitter (we're in native resolution). */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100222 write32(mmiobase + PF_CTL(0), 0);
223 write32(mmiobase + PF_WIN_SZ(0), 0);
224 write32(mmiobase + PF_WIN_POS(0), 0);
225 write32(mmiobase + PFIT_PGM_RATIOS, 0);
226 write32(mmiobase + PFIT_CONTROL, 0);
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200227 } else {
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100228 write32(mmiobase + PF_WIN_SZ(0), vactive | (hactive << 16));
229 write32(mmiobase + PF_WIN_POS(0), 0);
230 write32(mmiobase + PF_CTL(0), PF_ENABLE | PF_FILTER_MED_3x3);
231 write32(mmiobase + PFIT_CONTROL, PFIT_ENABLE
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200232 | (1 << PFIT_PIPE_SHIFT) | HORIZ_AUTO_SCALE
233 | VERT_AUTO_SCALE);
234 }
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200235
236 mdelay(1);
237
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100238 write32(mmiobase + DSPCNTR(0), DISPPLANE_BGRX888
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200239 | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE);
240
241 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100242 write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS
243 | (read32(mmiobase + PP_CONTROL) & ~PANEL_UNLOCK_MASK));
244 write32(mmiobase + FP0(1),
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200245 (pixel_n << 16)
246 | (pixel_m1 << 8) | pixel_m2);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100247 write32(mmiobase + DPLL(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200248 DPLL_VGA_MODE_DIS |
249 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200250 | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200251 : DPLLB_LVDS_P2_CLOCK_DIV_14)
252 | (conf->gpu_lvds_use_spread_spectrum_clock
253 ? DPLL_INTEGRATED_CLOCK_VLV | DPLL_INTEGRATED_CRI_CLK_VLV
254 : 0)
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200255 | (0x10000 << (pixel_p1 - 1)));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200256 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100257 write32(mmiobase + DPLL(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200258 DPLL_VGA_MODE_DIS |
259 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200260 | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200261 : DPLLB_LVDS_P2_CLOCK_DIV_14)
262 | ((conf->gpu_lvds_use_spread_spectrum_clock ? 3 : 0) << 13)
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200263 | (0x10000 << (pixel_p1 - 1)));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200264 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100265 write32(mmiobase + HTOTAL(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200266 ((hactive + right_border + hblank - 1) << 16)
267 | (hactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100268 write32(mmiobase + HBLANK(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200269 ((hactive + right_border + hblank - 1) << 16)
270 | (hactive + right_border - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100271 write32(mmiobase + HSYNC(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200272 ((hactive + right_border + hfront_porch + hsync - 1) << 16)
273 | (hactive + right_border + hfront_porch - 1));
274
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100275 write32(mmiobase + VTOTAL(1), ((vactive + bottom_border + vblank - 1) << 16)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200276 | (vactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100277 write32(mmiobase + VBLANK(1), ((vactive + bottom_border + vblank - 1) << 16)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200278 | (vactive + bottom_border - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100279 write32(mmiobase + VSYNC(1),
Arthur Heymansc8c73a62016-10-13 14:12:45 +0200280 ((vactive + bottom_border + vfront_porch + vsync - 1) << 16)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200281 | (vactive + bottom_border + vfront_porch - 1));
282
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200283 if (IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)) {
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100284 write32(mmiobase + PIPESRC(1), ((hactive - 1) << 16)
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200285 | (vactive - 1));
286 } else {
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100287 write32(mmiobase + PIPESRC(1), (639 << 16) | 399);
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200288 }
289
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200290 mdelay(1);
291
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100292 write32(mmiobase + DSPSIZE(0), (hactive - 1) | ((vactive - 1) << 16));
293 write32(mmiobase + DSPPOS(0), 0);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200294
295 /* Backlight init. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100296 write32(mmiobase + BLC_PWM_CTL, conf->gpu_backlight);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200297
298 edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63;
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100299 write32(mmiobase + DSPADDR(0), 0);
300 write32(mmiobase + DSPSURF(0), 0);
301 write32(mmiobase + DSPSTRIDE(0), edid.bytes_per_line);
302 write32(mmiobase + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200303 | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE);
304 mdelay(1);
305
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100306 write32(mmiobase + PIPECONF(1), PIPECONF_ENABLE);
307 write32(mmiobase + LVDS, LVDS_ON
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200308 | (hpolarity << 20) | (vpolarity << 21)
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200309 | (mode->lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200310 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
311 | LVDS_CLOCK_A_POWERUP_ALL
312 | LVDS_PIPE(1));
313
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100314 write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
315 write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200316 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100317 write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200318 | PANEL_POWER_ON | PANEL_POWER_RESET);
319
320 printk (BIOS_DEBUG, "waiting for panel powerup\n");
321 while (1) {
322 u32 reg32;
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100323 reg32 = read32(mmiobase + PP_STATUS);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200324 if ((reg32 & PP_SEQUENCE_MASK) == PP_SEQUENCE_NONE)
325 break;
326 }
327 printk (BIOS_DEBUG, "panel powered up\n");
328
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100329 write32(mmiobase + PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200330
331 /* Clear interrupts. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100332 write32(mmiobase + DEIIR, 0xffffffff);
333 write32(mmiobase + SDEIIR, 0xffffffff);
334 write32(mmiobase + IIR, 0xffffffff);
335 write32(mmiobase + IMR, 0xffffffff);
336 write32(mmiobase + EIR, 0xffffffff);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200337
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100338 if (gtt_setup(mmiobase)) {
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200339 printk(BIOS_ERR, "ERROR: GTT Setup Failed!!!\n");
340 return 0;
341 }
342
343 /* Setup GTT. */
344
345 reg16 = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), GGC);
346 uma_size = 0;
347 if (!(reg16 & 2)) {
Arthur Heymans874a8f92016-05-19 16:06:09 +0200348 uma_size = decode_igd_memory_size((reg16 >> 4) & 7);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200349 printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10);
350 }
351
Vladimir Serbinenko055fe032014-08-19 23:59:27 +0200352 for (i = 0; i < (uma_size - 256) / 4; i++)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200353 {
354 outl((i << 2) | 1, piobase);
355 outl(pphysbase + (i << 12) + 1, piobase + 4);
356 }
357
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100358 temp = read32(mmiobase + PGETBL_CTL);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200359 printk(BIOS_INFO, "GTT PGETBL_CTL register: 0x%lx\n", temp);
360
361 if (temp & 1)
362 printk(BIOS_INFO, "GTT Enabled\n");
363 else
364 printk(BIOS_ERR, "ERROR: GTT is still Disabled!!!\n");
365
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200366 if (IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)) {
367 printk(BIOS_SPEW, "memset %p to 0x00 for %d bytes\n",
368 (void *)pgfx, hactive * vactive * 4);
369 memset((void *)pgfx, 0x00, hactive * vactive * 4);
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200370
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200371 set_vbe_mode_info_valid(&edid, pgfx);
372 } else {
373 vga_misc_write(0x67);
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200374
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100375 write32(mmiobase + DSPCNTR(0), DISPPLANE_SEL_PIPE_B);
376 write32(mmiobase + VGACNTRL, 0x02c4008e
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200377 | VGA_PIPE_B_SELECT);
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200378
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200379 vga_textmode_init();
380 }
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200381 return 0;
382}
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200383
384static int intel_gma_init_vga(struct northbridge_intel_i945_config *conf,
385 unsigned int pphysbase, unsigned int piobase,
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100386 u8 *mmiobase, unsigned int pgfx)
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200387{
388 int i;
389 u32 hactive, vactive;
390 u16 reg16;
391 u32 uma_size;
392
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100393 printk(BIOS_SPEW, "mmiobase %x addrport %x physbase %x\n",
394 (u32)mmiobase, piobase, pphysbase);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200395
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100396 gtt_setup(mmiobase);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200397
398 /* Disable VGA. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100399 write32(mmiobase + VGACNTRL, VGA_DISP_DISABLE);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200400
401 /* Disable pipes. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100402 write32(mmiobase + PIPECONF(0), 0);
403 write32(mmiobase + PIPECONF(1), 0);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200404
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100405 write32(mmiobase + INSTPM, 0x800);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200406
407 vga_gr_write(0x18, 0);
408
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100409 write32(mmiobase + VGA0, 0x200074);
410 write32(mmiobase + VGA1, 0x200074);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200411
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100412 write32(mmiobase + DSPFW3, 0x7f3f00c1 & ~PINEVIEW_SELF_REFRESH_EN);
413 write32(mmiobase + DSPCLK_GATE_D, 0);
414 write32(mmiobase + FW_BLC, 0x03060106);
415 write32(mmiobase + FW_BLC2, 0x00000306);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200416
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100417 write32(mmiobase + ADPA, ADPA_DAC_ENABLE
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200418 | ADPA_PIPE_A_SELECT
419 | ADPA_USE_VGA_HVPOLARITY
420 | ADPA_VSYNC_CNTL_ENABLE
421 | ADPA_HSYNC_CNTL_ENABLE
422 | ADPA_DPMS_ON
423 );
424
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100425 write32(mmiobase + 0x7041c, 0x0);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200426
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100427 write32(mmiobase + DPLL_MD(0), 0x3);
428 write32(mmiobase + DPLL_MD(1), 0x3);
429 write32(mmiobase + DSPCNTR(1), 0x1000000);
430 write32(mmiobase + PIPESRC(1), 0x027f01df);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200431
432 vga_misc_write(0x67);
433 const u8 cr[] = { 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
434 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
435 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
436 0xff
437 };
438 vga_cr_write(0x11, 0);
439
440 for (i = 0; i <= 0x18; i++)
441 vga_cr_write(i, cr[i]);
442
443 // Disable screen memory to prevent garbage from appearing.
444 vga_sr_write(1, vga_sr_read(1) | 0x20);
445 hactive = 640;
446 vactive = 400;
447
448 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100449 write32(mmiobase + DPLL(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200450 DPLL_VCO_ENABLE | DPLLB_MODE_DAC_SERIAL
451 | DPLL_VGA_MODE_DIS
452 | DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
453 | 0x400601
454 );
455 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100456 write32(mmiobase + DPLL(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200457 DPLL_VCO_ENABLE | DPLLB_MODE_DAC_SERIAL
458 | DPLL_VGA_MODE_DIS
459 | DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
460 | 0x400601
461 );
462
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100463 write32(mmiobase + ADPA, ADPA_DAC_ENABLE
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200464 | ADPA_PIPE_A_SELECT
465 | ADPA_USE_VGA_HVPOLARITY
466 | ADPA_VSYNC_CNTL_ENABLE
467 | ADPA_HSYNC_CNTL_ENABLE
468 | ADPA_DPMS_ON
469 );
470
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100471 write32(mmiobase + HTOTAL(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200472 ((hactive - 1) << 16)
473 | (hactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100474 write32(mmiobase + HBLANK(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200475 ((hactive - 1) << 16)
476 | (hactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100477 write32(mmiobase + HSYNC(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200478 ((hactive - 1) << 16)
479 | (hactive - 1));
480
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100481 write32(mmiobase + VTOTAL(0), ((vactive - 1) << 16)
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200482 | (vactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100483 write32(mmiobase + VBLANK(0), ((vactive - 1) << 16)
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200484 | (vactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100485 write32(mmiobase + VSYNC(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200486 ((vactive - 1) << 16)
487 | (vactive - 1));
488
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100489 write32(mmiobase + PF_WIN_POS(0), 0);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200490
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100491 write32(mmiobase + PIPESRC(0), (639 << 16) | 399);
492 write32(mmiobase + PF_CTL(0),PF_ENABLE | PF_FILTER_MED_3x3);
493 write32(mmiobase + PF_WIN_SZ(0), vactive | (hactive << 16));
494 write32(mmiobase + PFIT_CONTROL, 0x0);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200495
496 mdelay(1);
497
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100498 write32(mmiobase + FDI_RX_CTL(0), 0x00002040);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200499 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100500 write32(mmiobase + FDI_RX_CTL(0), 0x80002050);
501 write32(mmiobase + FDI_TX_CTL(0), 0x00044000);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200502 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100503 write32(mmiobase + FDI_TX_CTL(0), 0x80044000);
504 write32(mmiobase + PIPECONF(0), PIPECONF_ENABLE | PIPECONF_BPP_6 | PIPECONF_DITHER_EN);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200505
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100506 write32(mmiobase + VGACNTRL, 0x0);
507 write32(mmiobase + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200508 mdelay(1);
509
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100510 write32(mmiobase + ADPA, ADPA_DAC_ENABLE
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200511 | ADPA_PIPE_A_SELECT
512 | ADPA_USE_VGA_HVPOLARITY
513 | ADPA_VSYNC_CNTL_ENABLE
514 | ADPA_HSYNC_CNTL_ENABLE
515 | ADPA_DPMS_ON
516 );
517
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100518 write32(mmiobase + DSPFW3, 0x7f3f00c1);
519 write32(mmiobase + MI_MODE, 0x200 | VS_TIMER_DISPATCH);
520 write32(mmiobase + CACHE_MODE_0, (0x6820 | (1 << 9)) & ~(1 << 5));
521 write32(mmiobase + CACHE_MODE_1, 0x380 & ~(1 << 9));
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200522
523 /* Set up GTT. */
524
525 reg16 = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), GGC);
526 uma_size = 0;
527 if (!(reg16 & 2)) {
528 uma_size = decode_igd_memory_size((reg16 >> 4) & 7);
529 printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10);
530 }
531
532 for (i = 0; i < (uma_size - 256) / 4; i++)
533 {
534 outl((i << 2) | 1, piobase);
535 outl(pphysbase + (i << 12) + 1, piobase + 4);
536 }
537
538 /* Clear interrupts. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100539 write32(mmiobase + DEIIR, 0xffffffff);
540 write32(mmiobase + SDEIIR, 0xffffffff);
541 write32(mmiobase + IIR, 0xffffffff);
542 write32(mmiobase + IMR, 0xffffffff);
543 write32(mmiobase + EIR, 0xffffffff);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200544
545 vga_textmode_init();
546
547 /* Enable screen memory. */
548 vga_sr_write(1, vga_sr_read(1) & ~0x20);
549
550 return 0;
551
552}
553
554/* compare the header of the vga edid header */
555/* if vga is not connected it should have a correct header */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100556static int probe_edid(u8 *mmiobase, u8 slave)
Arthur Heymans62f4dad2016-09-06 23:53:32 +0200557{
Paul Menzel533a3852016-11-27 22:17:44 +0100558 int i;
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200559 u8 vga_edid[128];
560 u8 header[8] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100561 intel_gmbus_read_edid(mmiobase + GMBUS0, slave, 0x50, vga_edid, 128);
562 intel_gmbus_stop(mmiobase + GMBUS0);
Paul Menzel533a3852016-11-27 22:17:44 +0100563 for (i = 0; i < 8; i++) {
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200564 if (vga_edid[i] != header[i]) {
Arthur Heymans62f4dad2016-09-06 23:53:32 +0200565 printk(BIOS_DEBUG, "No display connected on slave %d\n",
566 slave);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200567 return 0;
568 }
569 }
Arthur Heymans62f4dad2016-09-06 23:53:32 +0200570 printk(BIOS_SPEW, "Found a display on slave %d\n", slave);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200571 return 1;
572}
573
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200574
Stefan Reinauer30140a52009-03-11 16:20:39 +0000575static void gma_func0_init(struct device *dev)
576{
577 u32 reg32;
578
Patrick Georgi6444bd42012-07-06 11:31:39 +0200579 /* Unconditionally reset graphics */
580 pci_write_config8(dev, GDRST, 1);
581 udelay(50);
582 pci_write_config8(dev, GDRST, 0);
583 /* wait for device to finish */
584 while (pci_read_config8(dev, GDRST) & 1) { };
585
Stefan Reinauer30140a52009-03-11 16:20:39 +0000586 /* IGD needs to be Bus Master */
587 reg32 = pci_read_config32(dev, PCI_COMMAND);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200588 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER
589 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100590
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200591 if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) {
592 /* This should probably run before post VBIOS init. */
593 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
594 void *mmiobase;
595 u32 iobase, graphics_base;
596 struct northbridge_intel_i945_config *conf = dev->chip_info;
597
598 iobase = dev->resource_list[1].base;
599 mmiobase = (void *)(uintptr_t)dev->resource_list[0].base;
600 graphics_base = dev->resource_list[2].base;
601
602 printk(BIOS_SPEW, "GMADR = 0x%08x GTTADR = 0x%08x\n",
603 pci_read_config32(dev, GMADR),
604 pci_read_config32(dev, GTTADR)
605 );
606
607 int err;
Martin Roth128c1042016-11-18 09:29:03 -0700608 /* probe if VGA is connected and always run */
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200609 /* VGA init if no LVDS is connected */
610 if (!probe_edid(mmiobase, 3) || probe_edid(mmiobase, 2))
611 err = intel_gma_init_vga(conf,
612 pci_read_config32(dev, 0x5c) & ~0xf,
613 iobase, mmiobase, graphics_base);
614 else
615 err = intel_gma_init_lvds(conf,
616 pci_read_config32(dev, 0x5c) & ~0xf,
617 iobase, mmiobase, graphics_base);
618 if (err == 0)
619 gfx_set_init_done(1);
620 /* Linux relies on VBT for panel info. */
621 if (CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM) {
622 generate_fake_intel_oprom(&conf->gfx, dev,
623 "$VBT CALISTOGA");
624 }
625 if (CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GC) {
626 generate_fake_intel_oprom(&conf->gfx, dev,
627 "$VBT LAKEPORT-G");
628 }
Arthur Heymansf3f4bea2016-10-20 20:44:54 +0200629 } else {
630 /* PCI Init, will run VBIOS */
631 pci_dev_init(dev);
Arthur Heymans333176e2016-09-07 22:10:57 +0200632 }
Stefan Reinauer30140a52009-03-11 16:20:39 +0000633}
634
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200635/* This doesn't reclaim stolen UMA memory, but IGD could still
Martin Roth128c1042016-11-18 09:29:03 -0700636 be re-enabled later. */
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200637static void gma_func0_disable(struct device *dev)
638{
639 struct device *dev_host = dev_find_slot(0, PCI_DEVFN(0x0, 0));
640
641 pci_write_config16(dev, GCFC, 0xa00);
642 pci_write_config16(dev_host, GGC, (1 << 1));
643
644 unsigned int reg32 = pci_read_config32(dev_host, DEVEN);
645 reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1);
646 pci_write_config32(dev_host, DEVEN, reg32);
647
648 dev->enabled = 0;
649}
650
Stefan Reinauer30140a52009-03-11 16:20:39 +0000651static void gma_func1_init(struct device *dev)
652{
653 u32 reg32;
Alexander Couzensc7a1a3e2016-03-09 10:42:58 +0100654 u8 val;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000655
Martin Roth128c1042016-11-18 09:29:03 -0700656 /* IGD needs to be Bus Master, also enable IO access */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000657 reg32 = pci_read_config32(dev, PCI_COMMAND);
Stefan Reinauer109ab312009-08-12 16:08:05 +0000658 pci_write_config32(dev, PCI_COMMAND, reg32 |
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200659 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Sven Schnelleb629d142011-06-12 14:30:10 +0200660
Alexander Couzensc7a1a3e2016-03-09 10:42:58 +0100661 if (get_option(&val, "tft_brightness") == CB_SUCCESS)
662 pci_write_config8(dev, 0xf4, val);
663 else
664 pci_write_config8(dev, 0xf4, 0xff);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000665}
666
667static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
668{
669 if (!vendor || !device) {
670 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
671 pci_read_config32(dev, PCI_VENDOR_ID));
672 } else {
673 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
674 ((device & 0xffff) << 16) | (vendor & 0xffff));
675 }
676}
677
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100678const struct i915_gpu_controller_info *
679intel_gma_get_controller_info(void)
680{
681 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
682 if (!dev) {
683 return NULL;
684 }
685 struct northbridge_intel_i945_config *chip = dev->chip_info;
Patrick Georgi54e227e2015-08-08 22:02:12 +0200686 if (!chip) {
687 return NULL;
688 }
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100689 return &chip->gfx;
690}
691
Alexander Couzens5eea4582015-04-12 22:18:55 +0200692static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100693{
694 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
695 if (!gfx) {
696 return;
697 }
698
699 drivers_intel_gma_displays_ssdt_generate(gfx);
700}
701
Arthur Heymansc057a0612016-10-22 14:16:48 +0200702static void gma_func0_read_resources(device_t dev)
703{
704 u8 reg8;
705
706 /* Set Untrusted Aperture Size to 256mb */
707 reg8 = pci_read_config8(dev, MSAC);
708 reg8 &= ~0x3;
709 reg8 |= 0x2;
710 pci_write_config8(dev, MSAC, reg8);
711
712 pci_dev_read_resources(dev);
713}
714
Stefan Reinauer30140a52009-03-11 16:20:39 +0000715static struct pci_operations gma_pci_ops = {
716 .set_subsystem = gma_set_subsystem,
717};
718
719static struct device_operations gma_func0_ops = {
Arthur Heymansc057a0612016-10-22 14:16:48 +0200720 .read_resources = gma_func0_read_resources,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000721 .set_resources = pci_dev_set_resources,
722 .enable_resources = pci_dev_enable_resources,
723 .init = gma_func0_init,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100724 .acpi_fill_ssdt_generator = gma_ssdt,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000725 .scan_bus = 0,
726 .enable = 0,
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200727 .disable = gma_func0_disable,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000728 .ops_pci = &gma_pci_ops,
729};
730
731
732static struct device_operations gma_func1_ops = {
733 .read_resources = pci_dev_read_resources,
734 .set_resources = pci_dev_set_resources,
735 .enable_resources = pci_dev_enable_resources,
736 .init = gma_func1_init,
737 .scan_bus = 0,
738 .enable = 0,
739 .ops_pci = &gma_pci_ops,
740};
741
Elyes HAOUASa2993452016-10-28 10:56:59 +0200742static const unsigned short i945_gma_func0_ids[] = {
743 0x2772, /* 82945G/GZ Integrated Graphics Controller */
744 0x27a2, /* Mobile 945GM/GMS Express Integrated Graphics Controller*/
745 0x27ae, /* Mobile 945GSE Express Integrated Graphics Controller */
746 0
747};
748
749static const unsigned short i945_gma_func1_ids[] = {
750 0x27a6, /* Mobile 945GM/GMS/GME Express Integrated Graphics Controller */
751 0
752};
Vladimir Serbinenko10dd0e32014-11-17 00:07:12 +0100753
Stefan Reinauer30140a52009-03-11 16:20:39 +0000754static const struct pci_driver i945_gma_func0_driver __pci_driver = {
755 .ops = &gma_func0_ops,
756 .vendor = PCI_VENDOR_ID_INTEL,
Elyes HAOUASa2993452016-10-28 10:56:59 +0200757 .devices = i945_gma_func0_ids,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000758};
759
760static const struct pci_driver i945_gma_func1_driver __pci_driver = {
761 .ops = &gma_func1_ops,
762 .vendor = PCI_VENDOR_ID_INTEL,
Elyes HAOUASa2993452016-10-28 10:56:59 +0200763 .devices = i945_gma_func1_ids,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000764};