blob: 8d60bc91fca928e13003fe074e56f7a9d33191a2 [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>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020026#include <drivers/intel/gma/opregion.h>
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020027#include <string.h>
Vladimir Serbinenko0092c992014-08-21 01:06:53 +020028#include <pc80/vga.h>
29#include <pc80/vga_io.h>
Arthur Heymans7dfc8a52016-09-02 22:35:32 +020030#include <commonlib/helpers.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020031#include <cbmem.h>
32#include <southbridge/intel/i82801gx/nvs.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
Arthur Heymansc057a0612016-10-22 14:16:48 +020038#define MSAC 0x62 /* Multi Size Aperture Control */
Patrick Georgi6444bd42012-07-06 11:31:39 +020039
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020040#define LVDS_CLOCK_A_POWERUP_ALL (3 << 8)
41#define LVDS_CLOCK_B_POWERUP_ALL (3 << 4)
42#define LVDS_CLOCK_BOTH_POWERUP_ALL (3 << 2)
Elyes HAOUAS8868fc62017-06-28 20:41:53 +020043
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020044#define DPLLB_LVDS_P2_CLOCK_DIV_7 (1 << 24) /* i915 */
45
Elyes HAOUAS692e7df2017-06-28 20:44:41 +020046#define DPLL_INTEGRATED_CRI_CLK_VLV (1 << 14)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020047
48#define PGETBL_CTL 0x2020
49#define PGETBL_ENABLED 0x00000001
50
Arthur Heymans7dfc8a52016-09-02 22:35:32 +020051#define BASE_FREQUENCY 100000
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020052
Arthur Heymans8e079002017-01-14 22:31:54 +010053#define DEFAULT_BLC_PWM 180
54
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020055uintptr_t gma_get_gnvs_aslb(const void *gnvs)
56{
57 const global_nvs_t *gnvs_ptr = gnvs;
58 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
59}
60
61void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
62{
63 global_nvs_t *gnvs_ptr = gnvs;
64 if (gnvs_ptr)
65 gnvs_ptr->aslb = aslb;
66}
67
Arthur Heymans85cfddb2017-02-06 13:47:21 +010068static int gtt_setup(u8 *mmiobase)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020069{
70 unsigned long PGETBL_save;
Paul Menzelcc95f182014-06-05 22:45:35 +020071 unsigned long tom; // top of memory
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020072
Paul Menzelcc95f182014-06-05 22:45:35 +020073 /*
74 * The Video BIOS places the GTT right below top of memory.
Denis 'GNUtoo' Carikli16110e72014-10-14 07:33:53 +020075 */
Paul Menzelcc95f182014-06-05 22:45:35 +020076 tom = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), TOLUD) << 24;
77 PGETBL_save = tom - 256 * KiB;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020078 PGETBL_save |= PGETBL_ENABLED;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020079 PGETBL_save |= 2; /* set GTT to 256kb */
80
81 write32(mmiobase + GFX_FLSH_CNTL, 0);
82
83 write32(mmiobase + PGETBL_CTL, PGETBL_save);
84
85 /* verify */
86 if (read32(mmiobase + PGETBL_CTL) & PGETBL_ENABLED) {
87 printk(BIOS_DEBUG, "gtt_setup is enabled.\n");
88 } else {
89 printk(BIOS_DEBUG, "gtt_setup failed!!!\n");
90 return 1;
91 }
92 write32(mmiobase + GFX_FLSH_CNTL, 0);
93
94 return 0;
95}
96
Arthur Heymansb59bcb22016-09-05 22:46:11 +020097static int intel_gma_init_lvds(struct northbridge_intel_i945_config *conf,
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +020098 unsigned int pphysbase, unsigned int piobase,
Arthur Heymans85cfddb2017-02-06 13:47:21 +010099 u8 *mmiobase, unsigned int pgfx)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200100{
101 struct edid edid;
Mono2e4f83b2015-09-07 21:15:26 +0200102 struct edid_mode *mode;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200103 u8 edid_data[128];
104 unsigned long temp;
105 int hpolarity, vpolarity;
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200106 u32 smallest_err = 0xffffffff;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200107 u32 target_frequency;
108 u32 pixel_p1 = 1;
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200109 u32 pixel_p2;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200110 u32 pixel_n = 1;
111 u32 pixel_m1 = 1;
112 u32 pixel_m2 = 1;
113 u32 hactive, vactive, right_border, bottom_border;
114 u32 vsync, hsync, vblank, hblank, hfront_porch, vfront_porch;
115 u32 i, j;
116 u32 uma_size;
117 u16 reg16;
118
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200119 printk(BIOS_SPEW,
Francis Rowe71512b22015-03-16 05:31:40 +0000120 "i915lightup: graphics %p mmio %p addrport %04x physbase %08x\n",
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100121 (void *)pgfx, mmiobase, piobase, pphysbase);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200122
Arthur Heymans8da22862017-08-06 15:56:30 +0200123 intel_gmbus_read_edid(mmiobase + GMBUS0, GMBUS_PORT_PANEL, 0x50,
124 edid_data, sizeof(edid_data));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200125 decode_edid(edid_data, sizeof(edid_data), &edid);
Mono2e4f83b2015-09-07 21:15:26 +0200126 mode = &edid.mode;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200127
Mono2e4f83b2015-09-07 21:15:26 +0200128 hpolarity = (mode->phsync == '-');
129 vpolarity = (mode->pvsync == '-');
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200130 hactive = edid.x_resolution;
131 vactive = edid.y_resolution;
Mono2e4f83b2015-09-07 21:15:26 +0200132 right_border = mode->hborder;
133 bottom_border = mode->vborder;
134 vblank = mode->vbl;
135 hblank = mode->hbl;
136 vsync = mode->vspw;
137 hsync = mode->hspw;
138 hfront_porch = mode->hso;
139 vfront_porch = mode->vso;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200140
141 for (i = 0; i < 2; i++)
142 for (j = 0; j < 0x100; j++)
Elyes HAOUAS0a15fe92016-09-17 19:12:27 +0200143 /* R = j, G = j, B = j. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100144 write32(mmiobase + PALETTE(i) + 4 * j, 0x10101 * j);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200145
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100146 write32(mmiobase + PCH_PP_CONTROL, PANEL_UNLOCK_REGS
147 | (read32(mmiobase + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200148
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100149 write32(mmiobase + MI_ARB_STATE, MI_ARB_C3_LP_WRITE_ENABLE | (1 << 27));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200150 /* Clean registers. */
151 for (i = 0; i < 0x20; i += 4)
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100152 write32(mmiobase + RENDER_RING_BASE + i, 0);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200153 for (i = 0; i < 0x20; i += 4)
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100154 write32(mmiobase + FENCE_REG_965_0 + i, 0);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200155
156 /* Disable VGA. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100157 write32(mmiobase + VGACNTRL, VGA_DISP_DISABLE);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200158
159 /* Disable pipes. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100160 write32(mmiobase + PIPECONF(0), 0);
161 write32(mmiobase + PIPECONF(1), 0);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200162
163 /* Init PRB0. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100164 write32(mmiobase + HWS_PGA, 0x352d2000);
165 write32(mmiobase + PRB0_CTL, 0);
166 write32(mmiobase + PRB0_HEAD, 0);
167 write32(mmiobase + PRB0_TAIL, 0);
168 write32(mmiobase + PRB0_START, 0);
169 write32(mmiobase + PRB0_CTL, 0x0001f001);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200170
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100171 write32(mmiobase + D_STATE, DSTATE_PLL_D3_OFF
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200172 | DSTATE_GFX_CLOCK_GATING | DSTATE_DOT_CLOCK_GATING);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100173 write32(mmiobase + ECOSKPD, 0x00010000);
174 write32(mmiobase + HWSTAM, 0xeffe);
175 write32(mmiobase + PORT_HOTPLUG_EN, conf->gpu_hotplug);
176 write32(mmiobase + INSTPM, 0x08000000 | INSTPM_AGPBUSY_DIS);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200177
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200178 /* p2 divisor must 7 for dual channel LVDS */
179 /* and 14 for single channel LVDS */
180 pixel_p2 = mode->lvds_dual_channel ? 7 : 14;
181 target_frequency = mode->pixel_clock;
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200182
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200183 /* Find suitable divisors, m1, m2, p1, n. */
184 /* refclock * (5 * (m1 + 2) + (m1 + 2)) / (n + 2) / p1 / p2 */
185 /* should be closest to target frequency as possible */
186 u32 candn, candm1, candm2, candp1;
187 for (candm1 = 8; candm1 <= 18; candm1++) {
188 for (candm2 = 3; candm2 <= 7; candm2++) {
189 for (candn = 1; candn <= 6; candn++) {
190 for (candp1 = 1; candp1 <= 8; candp1++) {
191 u32 m = 5 * (candm1 + 2) + (candm2 + 2);
192 u32 p = candp1 * pixel_p2;
193 u32 vco = DIV_ROUND_CLOSEST(BASE_FREQUENCY * m, candn + 2);
194 u32 dot = DIV_ROUND_CLOSEST(vco, p);
Arthur Heymans75f91312016-10-12 01:04:28 +0200195 u32 this_err = MAX(dot, target_frequency) -
196 MIN(dot, target_frequency);
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200197 if ((m < 70) || (m > 120))
198 continue;
199 if (this_err < smallest_err) {
200 smallest_err = this_err;
201 pixel_n = candn;
202 pixel_m1 = candm1;
203 pixel_m2 = candm2;
204 pixel_p1 = candp1;
205 }
206 }
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200207 }
208 }
209 }
210
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200211 if (smallest_err == 0xffffffff) {
Arthur Heymans70a8e342017-03-09 11:30:23 +0100212 printk(BIOS_ERR, "Couldn't find GFX clock divisors\n");
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200213 return -1;
214 }
215
216 printk(BIOS_INFO, "bringing up panel at resolution %d x %d\n",
217 hactive, vactive);
218 printk(BIOS_DEBUG, "Borders %d x %d\n", right_border, bottom_border);
219 printk(BIOS_DEBUG, "Blank %d x %d\n", hblank, vblank);
220 printk(BIOS_DEBUG, "Sync %d x %d\n", hsync, vsync);
221 printk(BIOS_DEBUG, "Front porch %d x %d\n", hfront_porch, vfront_porch);
222 printk(BIOS_DEBUG, (conf->gpu_lvds_use_spread_spectrum_clock
223 ? "Spread spectrum clock\n"
224 : "DREF clock\n"));
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200225 printk(BIOS_DEBUG, (mode->lvds_dual_channel
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200226 ? "Dual channel\n"
227 : "Single channel\n"));
228 printk(BIOS_DEBUG, "Polarities %d, %d\n",
229 hpolarity, vpolarity);
230 printk(BIOS_DEBUG, "Pixel N=%d, M1=%d, M2=%d, P1=%d\n",
231 pixel_n, pixel_m1, pixel_m2, pixel_p1);
232 printk(BIOS_DEBUG, "Pixel clock %d kHz\n",
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200233 BASE_FREQUENCY * (5 * (pixel_m1 + 2) + (pixel_m2 + 2)) /
234 (pixel_n + 2) / (pixel_p1 * pixel_p2));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200235
Nico Huber6d8266b2017-05-20 16:46:01 +0200236 if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) {
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200237 /* Disable panel fitter (we're in native resolution). */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100238 write32(mmiobase + PF_CTL(0), 0);
239 write32(mmiobase + PF_WIN_SZ(0), 0);
240 write32(mmiobase + PF_WIN_POS(0), 0);
241 write32(mmiobase + PFIT_PGM_RATIOS, 0);
242 write32(mmiobase + PFIT_CONTROL, 0);
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200243 } else {
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100244 write32(mmiobase + PF_WIN_SZ(0), vactive | (hactive << 16));
245 write32(mmiobase + PF_WIN_POS(0), 0);
246 write32(mmiobase + PF_CTL(0), PF_ENABLE | PF_FILTER_MED_3x3);
247 write32(mmiobase + PFIT_CONTROL, PFIT_ENABLE
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200248 | (1 << PFIT_PIPE_SHIFT) | HORIZ_AUTO_SCALE
249 | VERT_AUTO_SCALE);
250 }
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200251
252 mdelay(1);
253
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100254 write32(mmiobase + DSPCNTR(0), DISPPLANE_BGRX888
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200255 | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE);
256
257 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100258 write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS
259 | (read32(mmiobase + PP_CONTROL) & ~PANEL_UNLOCK_MASK));
260 write32(mmiobase + FP0(1),
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200261 (pixel_n << 16)
262 | (pixel_m1 << 8) | pixel_m2);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100263 write32(mmiobase + DPLL(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200264 DPLL_VGA_MODE_DIS |
265 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200266 | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200267 : DPLLB_LVDS_P2_CLOCK_DIV_14)
268 | (conf->gpu_lvds_use_spread_spectrum_clock
269 ? DPLL_INTEGRATED_CLOCK_VLV | DPLL_INTEGRATED_CRI_CLK_VLV
270 : 0)
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200271 | (0x10000 << (pixel_p1 - 1)));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200272 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100273 write32(mmiobase + DPLL(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200274 DPLL_VGA_MODE_DIS |
275 DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200276 | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200277 : DPLLB_LVDS_P2_CLOCK_DIV_14)
278 | ((conf->gpu_lvds_use_spread_spectrum_clock ? 3 : 0) << 13)
Arthur Heymans7dfc8a52016-09-02 22:35:32 +0200279 | (0x10000 << (pixel_p1 - 1)));
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200280 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100281 write32(mmiobase + HTOTAL(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200282 ((hactive + right_border + hblank - 1) << 16)
283 | (hactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100284 write32(mmiobase + HBLANK(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200285 ((hactive + right_border + hblank - 1) << 16)
286 | (hactive + right_border - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100287 write32(mmiobase + HSYNC(1),
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200288 ((hactive + right_border + hfront_porch + hsync - 1) << 16)
289 | (hactive + right_border + hfront_porch - 1));
290
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100291 write32(mmiobase + VTOTAL(1), ((vactive + bottom_border + vblank - 1) << 16)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200292 | (vactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100293 write32(mmiobase + VBLANK(1), ((vactive + bottom_border + vblank - 1) << 16)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200294 | (vactive + bottom_border - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100295 write32(mmiobase + VSYNC(1),
Arthur Heymansc8c73a62016-10-13 14:12:45 +0200296 ((vactive + bottom_border + vfront_porch + vsync - 1) << 16)
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200297 | (vactive + bottom_border + vfront_porch - 1));
298
Nico Huber6d8266b2017-05-20 16:46:01 +0200299 if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) {
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100300 write32(mmiobase + PIPESRC(1), ((hactive - 1) << 16)
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200301 | (vactive - 1));
302 } else {
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100303 write32(mmiobase + PIPESRC(1), (639 << 16) | 399);
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200304 }
305
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200306 mdelay(1);
307
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100308 write32(mmiobase + DSPSIZE(0), (hactive - 1) | ((vactive - 1) << 16));
309 write32(mmiobase + DSPPOS(0), 0);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200310
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200311 edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63;
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100312 write32(mmiobase + DSPADDR(0), 0);
313 write32(mmiobase + DSPSURF(0), 0);
314 write32(mmiobase + DSPSTRIDE(0), edid.bytes_per_line);
315 write32(mmiobase + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200316 | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE);
317 mdelay(1);
318
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100319 write32(mmiobase + PIPECONF(1), PIPECONF_ENABLE);
320 write32(mmiobase + LVDS, LVDS_ON
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200321 | (hpolarity << 20) | (vpolarity << 21)
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200322 | (mode->lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200323 | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
324 | LVDS_CLOCK_A_POWERUP_ALL
325 | LVDS_PIPE(1));
326
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100327 write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
328 write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200329 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100330 write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200331 | PANEL_POWER_ON | PANEL_POWER_RESET);
332
Arthur Heymans70a8e342017-03-09 11:30:23 +0100333 printk(BIOS_DEBUG, "waiting for panel powerup\n");
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200334 while (1) {
335 u32 reg32;
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100336 reg32 = read32(mmiobase + PP_STATUS);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200337 if ((reg32 & PP_SEQUENCE_MASK) == PP_SEQUENCE_NONE)
338 break;
339 }
Arthur Heymans70a8e342017-03-09 11:30:23 +0100340 printk(BIOS_DEBUG, "panel powered up\n");
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200341
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100342 write32(mmiobase + PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200343
344 /* Clear interrupts. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100345 write32(mmiobase + DEIIR, 0xffffffff);
346 write32(mmiobase + SDEIIR, 0xffffffff);
347 write32(mmiobase + IIR, 0xffffffff);
348 write32(mmiobase + IMR, 0xffffffff);
349 write32(mmiobase + EIR, 0xffffffff);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200350
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100351 if (gtt_setup(mmiobase)) {
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200352 printk(BIOS_ERR, "ERROR: GTT Setup Failed!!!\n");
353 return 0;
354 }
355
356 /* Setup GTT. */
357
358 reg16 = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), GGC);
359 uma_size = 0;
360 if (!(reg16 & 2)) {
Arthur Heymans874a8f92016-05-19 16:06:09 +0200361 uma_size = decode_igd_memory_size((reg16 >> 4) & 7);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200362 printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10);
363 }
364
Arthur Heymans70a8e342017-03-09 11:30:23 +0100365 for (i = 0; i < (uma_size - 256) / 4; i++) {
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200366 outl((i << 2) | 1, piobase);
367 outl(pphysbase + (i << 12) + 1, piobase + 4);
368 }
369
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100370 temp = read32(mmiobase + PGETBL_CTL);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200371 printk(BIOS_INFO, "GTT PGETBL_CTL register: 0x%lx\n", temp);
372
373 if (temp & 1)
374 printk(BIOS_INFO, "GTT Enabled\n");
375 else
376 printk(BIOS_ERR, "ERROR: GTT is still Disabled!!!\n");
377
Nico Huber6d8266b2017-05-20 16:46:01 +0200378 if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) {
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200379 printk(BIOS_SPEW, "memset %p to 0x00 for %d bytes\n",
380 (void *)pgfx, hactive * vactive * 4);
381 memset((void *)pgfx, 0x00, hactive * vactive * 4);
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200382
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200383 set_vbe_mode_info_valid(&edid, pgfx);
384 } else {
385 vga_misc_write(0x67);
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200386
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100387 write32(mmiobase + DSPCNTR(0), DISPPLANE_SEL_PIPE_B);
388 write32(mmiobase + VGACNTRL, 0x02c4008e
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200389 | VGA_PIPE_B_SELECT);
Vladimir Serbinenko0092c992014-08-21 01:06:53 +0200390
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200391 vga_textmode_init();
392 }
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200393 return 0;
394}
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200395
396static int intel_gma_init_vga(struct northbridge_intel_i945_config *conf,
397 unsigned int pphysbase, unsigned int piobase,
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100398 u8 *mmiobase, unsigned int pgfx)
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200399{
400 int i;
401 u32 hactive, vactive;
402 u16 reg16;
403 u32 uma_size;
404
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100405 printk(BIOS_SPEW, "mmiobase %x addrport %x physbase %x\n",
406 (u32)mmiobase, piobase, pphysbase);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200407
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100408 gtt_setup(mmiobase);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200409
410 /* Disable VGA. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100411 write32(mmiobase + VGACNTRL, VGA_DISP_DISABLE);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200412
413 /* Disable pipes. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100414 write32(mmiobase + PIPECONF(0), 0);
415 write32(mmiobase + PIPECONF(1), 0);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200416
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100417 write32(mmiobase + INSTPM, 0x800);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200418
419 vga_gr_write(0x18, 0);
420
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100421 write32(mmiobase + VGA0, 0x200074);
422 write32(mmiobase + VGA1, 0x200074);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200423
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100424 write32(mmiobase + DSPFW3, 0x7f3f00c1 & ~PINEVIEW_SELF_REFRESH_EN);
425 write32(mmiobase + DSPCLK_GATE_D, 0);
426 write32(mmiobase + FW_BLC, 0x03060106);
427 write32(mmiobase + FW_BLC2, 0x00000306);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200428
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100429 write32(mmiobase + ADPA, ADPA_DAC_ENABLE
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200430 | ADPA_PIPE_A_SELECT
431 | ADPA_USE_VGA_HVPOLARITY
432 | ADPA_VSYNC_CNTL_ENABLE
433 | ADPA_HSYNC_CNTL_ENABLE
434 | ADPA_DPMS_ON
435 );
436
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100437 write32(mmiobase + 0x7041c, 0x0);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200438
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100439 write32(mmiobase + DPLL_MD(0), 0x3);
440 write32(mmiobase + DPLL_MD(1), 0x3);
441 write32(mmiobase + DSPCNTR(1), 0x1000000);
442 write32(mmiobase + PIPESRC(1), 0x027f01df);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200443
444 vga_misc_write(0x67);
445 const u8 cr[] = { 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
446 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
447 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
448 0xff
449 };
450 vga_cr_write(0x11, 0);
451
452 for (i = 0; i <= 0x18; i++)
453 vga_cr_write(i, cr[i]);
454
455 // Disable screen memory to prevent garbage from appearing.
456 vga_sr_write(1, vga_sr_read(1) | 0x20);
457 hactive = 640;
458 vactive = 400;
459
460 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100461 write32(mmiobase + DPLL(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200462 DPLL_VCO_ENABLE | DPLLB_MODE_DAC_SERIAL
463 | DPLL_VGA_MODE_DIS
464 | DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
465 | 0x400601
466 );
467 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100468 write32(mmiobase + DPLL(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200469 DPLL_VCO_ENABLE | DPLLB_MODE_DAC_SERIAL
470 | DPLL_VGA_MODE_DIS
471 | DPLL_DAC_SERIAL_P2_CLOCK_DIV_10
472 | 0x400601
473 );
474
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100475 write32(mmiobase + ADPA, ADPA_DAC_ENABLE
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200476 | ADPA_PIPE_A_SELECT
477 | ADPA_USE_VGA_HVPOLARITY
478 | ADPA_VSYNC_CNTL_ENABLE
479 | ADPA_HSYNC_CNTL_ENABLE
480 | ADPA_DPMS_ON
481 );
482
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100483 write32(mmiobase + HTOTAL(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200484 ((hactive - 1) << 16)
485 | (hactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100486 write32(mmiobase + HBLANK(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200487 ((hactive - 1) << 16)
488 | (hactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100489 write32(mmiobase + HSYNC(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200490 ((hactive - 1) << 16)
491 | (hactive - 1));
492
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100493 write32(mmiobase + VTOTAL(0), ((vactive - 1) << 16)
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200494 | (vactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100495 write32(mmiobase + VBLANK(0), ((vactive - 1) << 16)
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200496 | (vactive - 1));
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100497 write32(mmiobase + VSYNC(0),
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200498 ((vactive - 1) << 16)
499 | (vactive - 1));
500
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100501 write32(mmiobase + PF_WIN_POS(0), 0);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200502
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100503 write32(mmiobase + PIPESRC(0), (639 << 16) | 399);
Arthur Heymans70a8e342017-03-09 11:30:23 +0100504 write32(mmiobase + PF_CTL(0), PF_ENABLE | PF_FILTER_MED_3x3);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100505 write32(mmiobase + PF_WIN_SZ(0), vactive | (hactive << 16));
506 write32(mmiobase + PFIT_CONTROL, 0x0);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200507
508 mdelay(1);
509
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100510 write32(mmiobase + FDI_RX_CTL(0), 0x00002040);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200511 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100512 write32(mmiobase + FDI_RX_CTL(0), 0x80002050);
513 write32(mmiobase + FDI_TX_CTL(0), 0x00044000);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200514 mdelay(1);
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100515 write32(mmiobase + FDI_TX_CTL(0), 0x80044000);
516 write32(mmiobase + PIPECONF(0), PIPECONF_ENABLE | PIPECONF_BPP_6 | PIPECONF_DITHER_EN);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200517
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100518 write32(mmiobase + VGACNTRL, 0x0);
519 write32(mmiobase + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200520 mdelay(1);
521
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100522 write32(mmiobase + ADPA, ADPA_DAC_ENABLE
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200523 | ADPA_PIPE_A_SELECT
524 | ADPA_USE_VGA_HVPOLARITY
525 | ADPA_VSYNC_CNTL_ENABLE
526 | ADPA_HSYNC_CNTL_ENABLE
527 | ADPA_DPMS_ON
528 );
529
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100530 write32(mmiobase + DSPFW3, 0x7f3f00c1);
531 write32(mmiobase + MI_MODE, 0x200 | VS_TIMER_DISPATCH);
532 write32(mmiobase + CACHE_MODE_0, (0x6820 | (1 << 9)) & ~(1 << 5));
533 write32(mmiobase + CACHE_MODE_1, 0x380 & ~(1 << 9));
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200534
535 /* Set up GTT. */
536
537 reg16 = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), GGC);
538 uma_size = 0;
539 if (!(reg16 & 2)) {
540 uma_size = decode_igd_memory_size((reg16 >> 4) & 7);
541 printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10);
542 }
543
Arthur Heymans70a8e342017-03-09 11:30:23 +0100544 for (i = 0; i < (uma_size - 256) / 4; i++) {
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200545 outl((i << 2) | 1, piobase);
546 outl(pphysbase + (i << 12) + 1, piobase + 4);
547 }
548
549 /* Clear interrupts. */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100550 write32(mmiobase + DEIIR, 0xffffffff);
551 write32(mmiobase + SDEIIR, 0xffffffff);
552 write32(mmiobase + IIR, 0xffffffff);
553 write32(mmiobase + IMR, 0xffffffff);
554 write32(mmiobase + EIR, 0xffffffff);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200555
556 vga_textmode_init();
557
558 /* Enable screen memory. */
559 vga_sr_write(1, vga_sr_read(1) & ~0x20);
560
561 return 0;
562
563}
564
565/* compare the header of the vga edid header */
566/* if vga is not connected it should have a correct header */
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100567static int probe_edid(u8 *mmiobase, u8 slave)
Arthur Heymans62f4dad2016-09-06 23:53:32 +0200568{
Paul Menzel533a3852016-11-27 22:17:44 +0100569 int i;
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200570 u8 vga_edid[128];
571 u8 header[8] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
Arthur Heymans85cfddb2017-02-06 13:47:21 +0100572 intel_gmbus_read_edid(mmiobase + GMBUS0, slave, 0x50, vga_edid, 128);
573 intel_gmbus_stop(mmiobase + GMBUS0);
Paul Menzel533a3852016-11-27 22:17:44 +0100574 for (i = 0; i < 8; i++) {
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200575 if (vga_edid[i] != header[i]) {
Arthur Heymans62f4dad2016-09-06 23:53:32 +0200576 printk(BIOS_DEBUG, "No display connected on slave %d\n",
577 slave);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200578 return 0;
579 }
580 }
Arthur Heymans62f4dad2016-09-06 23:53:32 +0200581 printk(BIOS_SPEW, "Found a display on slave %d\n", slave);
Arthur Heymansb59bcb22016-09-05 22:46:11 +0200582 return 1;
583}
584
Arthur Heymans8e079002017-01-14 22:31:54 +0100585static u32 get_cdclk(struct device *const dev)
586{
587 u16 gcfgc = pci_read_config16(dev, GCFGC);
588
589 if (gcfgc & GC_LOW_FREQUENCY_ENABLE) {
590 return 133333333;
591 } else {
592 switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
593 case GC_DISPLAY_CLOCK_333_320_MHZ:
594 return 320000000;
595 default:
596 case GC_DISPLAY_CLOCK_190_200_MHZ:
597 return 200000000;
598 }
599 }
600}
601
602static u32 freq_to_blc_pwm_ctl(struct device *const dev, u16 pwm_freq)
603{
604 u32 blc_mod;
605
606 /* Set duty cycle to 100% due to use of legacy backlight control */
607 blc_mod = get_cdclk(dev) / (32 * pwm_freq);
608 return BLM_LEGACY_MODE | ((blc_mod / 2) << 17) | ((blc_mod / 2) << 1);
609}
610
611
612static void panel_setup(u8 *mmiobase, struct device *const dev)
613{
614 const struct northbridge_intel_i945_config *const conf = dev->chip_info;
615
616 u32 reg32;
617
618 /* Set up Panel Power On Delays */
619 reg32 = (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
620 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
621 write32(mmiobase + PP_ON_DELAYS, reg32);
622
623 /* Set up Panel Power Off Delays */
624 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
625 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
626 write32(mmiobase + PP_OFF_DELAYS, reg32);
627
628 /* Set up Panel Power Cycle Delay */
629 reg32 = (get_cdclk(dev) / 20000 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
630 reg32 |= conf->gpu_panel_power_cycle_delay & 0x1f;
631 write32(mmiobase + PP_DIVISOR, reg32);
632
633 /* Backlight init. */
634 if (conf->pwm_freq)
635 write32(mmiobase + BLC_PWM_CTL, freq_to_blc_pwm_ctl(dev,
636 conf->pwm_freq));
637 else
638 write32(mmiobase + BLC_PWM_CTL, freq_to_blc_pwm_ctl(dev,
639 DEFAULT_BLC_PWM));
640}
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200641
Stefan Reinauer30140a52009-03-11 16:20:39 +0000642static void gma_func0_init(struct device *dev)
643{
644 u32 reg32;
645
Patrick Georgi6444bd42012-07-06 11:31:39 +0200646 /* Unconditionally reset graphics */
647 pci_write_config8(dev, GDRST, 1);
648 udelay(50);
649 pci_write_config8(dev, GDRST, 0);
650 /* wait for device to finish */
Arthur Heymans70a8e342017-03-09 11:30:23 +0100651 while (pci_read_config8(dev, GDRST) & 1)
652 ;
Patrick Georgi6444bd42012-07-06 11:31:39 +0200653
Stefan Reinauer30140a52009-03-11 16:20:39 +0000654 /* IGD needs to be Bus Master */
655 reg32 = pci_read_config32(dev, PCI_COMMAND);
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200656 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER
657 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
Denis 'GNUtoo' Cariklied7e29e2013-02-24 12:01:44 +0100658
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200659 if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) {
660 /* This should probably run before post VBIOS init. */
661 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
662 void *mmiobase;
663 u32 iobase, graphics_base;
664 struct northbridge_intel_i945_config *conf = dev->chip_info;
665
666 iobase = dev->resource_list[1].base;
667 mmiobase = (void *)(uintptr_t)dev->resource_list[0].base;
668 graphics_base = dev->resource_list[2].base;
669
670 printk(BIOS_SPEW, "GMADR = 0x%08x GTTADR = 0x%08x\n",
671 pci_read_config32(dev, GMADR),
672 pci_read_config32(dev, GTTADR)
673 );
674
675 int err;
Arthur Heymans8e079002017-01-14 22:31:54 +0100676
677 if (IS_ENABLED(CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM))
678 panel_setup(mmiobase, dev);
679
Martin Roth128c1042016-11-18 09:29:03 -0700680 /* probe if VGA is connected and always run */
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200681 /* VGA init if no LVDS is connected */
Arthur Heymans8da22862017-08-06 15:56:30 +0200682 if (!probe_edid(mmiobase, GMBUS_PORT_PANEL) ||
683 probe_edid(mmiobase, GMBUS_PORT_VGADDC))
Arthur Heymans9c5fc622016-10-18 02:15:44 +0200684 err = intel_gma_init_vga(conf,
685 pci_read_config32(dev, 0x5c) & ~0xf,
686 iobase, mmiobase, graphics_base);
687 else
688 err = intel_gma_init_lvds(conf,
689 pci_read_config32(dev, 0x5c) & ~0xf,
690 iobase, mmiobase, graphics_base);
691 if (err == 0)
692 gfx_set_init_done(1);
693 /* Linux relies on VBT for panel info. */
694 if (CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM) {
695 generate_fake_intel_oprom(&conf->gfx, dev,
696 "$VBT CALISTOGA");
697 }
698 if (CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GC) {
699 generate_fake_intel_oprom(&conf->gfx, dev,
700 "$VBT LAKEPORT-G");
701 }
Arthur Heymansf3f4bea2016-10-20 20:44:54 +0200702 } else {
703 /* PCI Init, will run VBIOS */
704 pci_dev_init(dev);
Arthur Heymans333176e2016-09-07 22:10:57 +0200705 }
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200706
707 intel_gma_restore_opregion();
Stefan Reinauer30140a52009-03-11 16:20:39 +0000708}
709
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200710/* This doesn't reclaim stolen UMA memory, but IGD could still
Martin Roth128c1042016-11-18 09:29:03 -0700711 be re-enabled later. */
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200712static void gma_func0_disable(struct device *dev)
713{
714 struct device *dev_host = dev_find_slot(0, PCI_DEVFN(0x0, 0));
715
716 pci_write_config16(dev, GCFC, 0xa00);
717 pci_write_config16(dev_host, GGC, (1 << 1));
718
719 unsigned int reg32 = pci_read_config32(dev_host, DEVEN);
720 reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1);
721 pci_write_config32(dev_host, DEVEN, reg32);
722
723 dev->enabled = 0;
724}
725
Stefan Reinauer30140a52009-03-11 16:20:39 +0000726static void gma_func1_init(struct device *dev)
727{
728 u32 reg32;
Alexander Couzensc7a1a3e2016-03-09 10:42:58 +0100729 u8 val;
Stefan Reinauer30140a52009-03-11 16:20:39 +0000730
Martin Roth128c1042016-11-18 09:29:03 -0700731 /* IGD needs to be Bus Master, also enable IO access */
Stefan Reinauer30140a52009-03-11 16:20:39 +0000732 reg32 = pci_read_config32(dev, PCI_COMMAND);
Stefan Reinauer109ab312009-08-12 16:08:05 +0000733 pci_write_config32(dev, PCI_COMMAND, reg32 |
Vladimir Serbinenko26ca08c2014-06-01 00:24:05 +0200734 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Sven Schnelleb629d142011-06-12 14:30:10 +0200735
Alexander Couzensc7a1a3e2016-03-09 10:42:58 +0100736 if (get_option(&val, "tft_brightness") == CB_SUCCESS)
737 pci_write_config8(dev, 0xf4, val);
738 else
739 pci_write_config8(dev, 0xf4, 0xff);
Stefan Reinauer30140a52009-03-11 16:20:39 +0000740}
741
Arthur Heymans70a8e342017-03-09 11:30:23 +0100742static void gma_set_subsystem(device_t dev, unsigned int vendor,
743 unsigned int device)
Stefan Reinauer30140a52009-03-11 16:20:39 +0000744{
745 if (!vendor || !device) {
746 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
747 pci_read_config32(dev, PCI_VENDOR_ID));
748 } else {
749 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
750 ((device & 0xffff) << 16) | (vendor & 0xffff));
751 }
752}
753
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100754const struct i915_gpu_controller_info *
755intel_gma_get_controller_info(void)
756{
Arthur Heymans70a8e342017-03-09 11:30:23 +0100757 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2, 0));
758 if (!dev)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100759 return NULL;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100760 struct northbridge_intel_i945_config *chip = dev->chip_info;
Arthur Heymans70a8e342017-03-09 11:30:23 +0100761 if (!chip)
Patrick Georgi54e227e2015-08-08 22:02:12 +0200762 return NULL;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100763 return &chip->gfx;
764}
765
Alexander Couzens5eea4582015-04-12 22:18:55 +0200766static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100767{
768 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
Arthur Heymans70a8e342017-03-09 11:30:23 +0100769 if (!gfx)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100770 return;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100771
772 drivers_intel_gma_displays_ssdt_generate(gfx);
773}
774
Arthur Heymansc057a0612016-10-22 14:16:48 +0200775static void gma_func0_read_resources(device_t dev)
776{
777 u8 reg8;
778
779 /* Set Untrusted Aperture Size to 256mb */
780 reg8 = pci_read_config8(dev, MSAC);
781 reg8 &= ~0x3;
782 reg8 |= 0x2;
783 pci_write_config8(dev, MSAC, reg8);
784
785 pci_dev_read_resources(dev);
786}
787
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200788static unsigned long
789gma_write_acpi_tables(struct device *const dev,
790 unsigned long current,
791 struct acpi_rsdp *const rsdp)
792{
793 igd_opregion_t *opregion = (igd_opregion_t *)current;
794 global_nvs_t *gnvs;
795
796 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
797 return current;
798
799 current += sizeof(igd_opregion_t);
800
801 /* GNVS has been already set up */
802 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
803 if (gnvs) {
804 /* IGD OpRegion Base Address */
805 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
806 } else {
807 printk(BIOS_ERR, "Error: GNVS table not found.\n");
808 }
809
810 current = acpi_align_current(current);
811 return current;
812}
813
814static const char *gma_acpi_name(const struct device *dev)
815{
816 return "GFX0";
817}
818
Stefan Reinauer30140a52009-03-11 16:20:39 +0000819static struct pci_operations gma_pci_ops = {
820 .set_subsystem = gma_set_subsystem,
821};
822
823static struct device_operations gma_func0_ops = {
Arthur Heymansc057a0612016-10-22 14:16:48 +0200824 .read_resources = gma_func0_read_resources,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000825 .set_resources = pci_dev_set_resources,
826 .enable_resources = pci_dev_enable_resources,
827 .init = gma_func0_init,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100828 .acpi_fill_ssdt_generator = gma_ssdt,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000829 .scan_bus = 0,
830 .enable = 0,
Patrick Georgice6e9fe2012-07-20 12:37:06 +0200831 .disable = gma_func0_disable,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000832 .ops_pci = &gma_pci_ops,
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200833 .acpi_name = gma_acpi_name,
834 .write_acpi_tables = gma_write_acpi_tables,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000835};
836
837
838static struct device_operations gma_func1_ops = {
839 .read_resources = pci_dev_read_resources,
840 .set_resources = pci_dev_set_resources,
841 .enable_resources = pci_dev_enable_resources,
842 .init = gma_func1_init,
843 .scan_bus = 0,
844 .enable = 0,
845 .ops_pci = &gma_pci_ops,
846};
847
Elyes HAOUASa2993452016-10-28 10:56:59 +0200848static const unsigned short i945_gma_func0_ids[] = {
849 0x2772, /* 82945G/GZ Integrated Graphics Controller */
850 0x27a2, /* Mobile 945GM/GMS Express Integrated Graphics Controller*/
851 0x27ae, /* Mobile 945GSE Express Integrated Graphics Controller */
852 0
853};
854
855static const unsigned short i945_gma_func1_ids[] = {
856 0x27a6, /* Mobile 945GM/GMS/GME Express Integrated Graphics Controller */
857 0
858};
Vladimir Serbinenko10dd0e32014-11-17 00:07:12 +0100859
Stefan Reinauer30140a52009-03-11 16:20:39 +0000860static const struct pci_driver i945_gma_func0_driver __pci_driver = {
861 .ops = &gma_func0_ops,
862 .vendor = PCI_VENDOR_ID_INTEL,
Elyes HAOUASa2993452016-10-28 10:56:59 +0200863 .devices = i945_gma_func0_ids,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000864};
865
866static const struct pci_driver i945_gma_func1_driver __pci_driver = {
867 .ops = &gma_func1_ops,
868 .vendor = PCI_VENDOR_ID_INTEL,
Elyes HAOUASa2993452016-10-28 10:56:59 +0200869 .devices = i945_gma_func1_ids,
Stefan Reinauer30140a52009-03-11 16:20:39 +0000870};