Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 1 | /* |
| 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 Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 17 | #include <bootmode.h> |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 18 | #include <delay.h> |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 22 | #include <pc80/mc146818rtc.h> |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 23 | #include <edid.h> |
| 24 | #include <drivers/intel/gma/edid.h> |
| 25 | #include <drivers/intel/gma/i915.h> |
| 26 | #include <string.h> |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 27 | #include <pc80/vga.h> |
| 28 | #include <pc80/vga_io.h> |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 29 | #include <commonlib/helpers.h> |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 30 | |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 31 | #include "i945.h" |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 32 | #include "chip.h" |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 33 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 34 | #define GDRST 0xc0 |
Arthur Heymans | c057a061 | 2016-10-22 14:16:48 +0200 | [diff] [blame] | 35 | #define MSAC 0x62 /* Multi Size Aperture Control */ |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 36 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 37 | #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 Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 48 | #define BASE_FREQUENCY 100000 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 49 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 50 | static int gtt_setup(u8 *mmiobase) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 51 | { |
| 52 | unsigned long PGETBL_save; |
Paul Menzel | cc95f18 | 2014-06-05 22:45:35 +0200 | [diff] [blame] | 53 | unsigned long tom; // top of memory |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 54 | |
Paul Menzel | cc95f18 | 2014-06-05 22:45:35 +0200 | [diff] [blame] | 55 | /* |
| 56 | * The Video BIOS places the GTT right below top of memory. |
Denis 'GNUtoo' Carikli | 16110e7 | 2014-10-14 07:33:53 +0200 | [diff] [blame] | 57 | */ |
Paul Menzel | cc95f18 | 2014-06-05 22:45:35 +0200 | [diff] [blame] | 58 | tom = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), TOLUD) << 24; |
| 59 | PGETBL_save = tom - 256 * KiB; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 60 | PGETBL_save |= PGETBL_ENABLED; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 61 | 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 Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 79 | static int intel_gma_init_lvds(struct northbridge_intel_i945_config *conf, |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 80 | unsigned int pphysbase, unsigned int piobase, |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 81 | u8 *mmiobase, unsigned int pgfx) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 82 | { |
| 83 | struct edid edid; |
Mono | 2e4f83b | 2015-09-07 21:15:26 +0200 | [diff] [blame] | 84 | struct edid_mode *mode; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 85 | u8 edid_data[128]; |
| 86 | unsigned long temp; |
| 87 | int hpolarity, vpolarity; |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 88 | u32 smallest_err = 0xffffffff; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 89 | u32 target_frequency; |
| 90 | u32 pixel_p1 = 1; |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 91 | u32 pixel_p2; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 92 | 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 Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 101 | printk(BIOS_SPEW, |
Francis Rowe | 71512b2 | 2015-03-16 05:31:40 +0000 | [diff] [blame] | 102 | "i915lightup: graphics %p mmio %p addrport %04x physbase %08x\n", |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 103 | (void *)pgfx, mmiobase, piobase, pphysbase); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 104 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 105 | intel_gmbus_read_edid(mmiobase + GMBUS0, 3, 0x50, edid_data, |
Arthur Heymans | 7141ff3 | 2016-10-10 17:49:00 +0200 | [diff] [blame] | 106 | sizeof(edid_data)); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 107 | decode_edid(edid_data, sizeof(edid_data), &edid); |
Mono | 2e4f83b | 2015-09-07 21:15:26 +0200 | [diff] [blame] | 108 | mode = &edid.mode; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 109 | |
Mono | 2e4f83b | 2015-09-07 21:15:26 +0200 | [diff] [blame] | 110 | hpolarity = (mode->phsync == '-'); |
| 111 | vpolarity = (mode->pvsync == '-'); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 112 | hactive = edid.x_resolution; |
| 113 | vactive = edid.y_resolution; |
Mono | 2e4f83b | 2015-09-07 21:15:26 +0200 | [diff] [blame] | 114 | 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 Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 122 | |
| 123 | for (i = 0; i < 2; i++) |
| 124 | for (j = 0; j < 0x100; j++) |
Elyes HAOUAS | 0a15fe9 | 2016-09-17 19:12:27 +0200 | [diff] [blame] | 125 | /* R = j, G = j, B = j. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 126 | write32(mmiobase + PALETTE(i) + 4 * j, 0x10101 * j); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 127 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 128 | write32(mmiobase + PCH_PP_CONTROL, PANEL_UNLOCK_REGS |
| 129 | | (read32(mmiobase + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK)); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 130 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 131 | write32(mmiobase + MI_ARB_STATE, MI_ARB_C3_LP_WRITE_ENABLE | (1 << 27)); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 132 | /* Clean registers. */ |
| 133 | for (i = 0; i < 0x20; i += 4) |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 134 | write32(mmiobase + RENDER_RING_BASE + i, 0); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 135 | for (i = 0; i < 0x20; i += 4) |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 136 | write32(mmiobase + FENCE_REG_965_0 + i, 0); |
| 137 | write32(mmiobase + PP_ON_DELAYS, 0); |
| 138 | write32(mmiobase + PP_OFF_DELAYS, 0); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 139 | |
| 140 | /* Disable VGA. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 141 | write32(mmiobase + VGACNTRL, VGA_DISP_DISABLE); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 142 | |
| 143 | /* Disable pipes. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 144 | write32(mmiobase + PIPECONF(0), 0); |
| 145 | write32(mmiobase + PIPECONF(1), 0); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 146 | |
| 147 | /* Init PRB0. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 148 | 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 Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 154 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 155 | write32(mmiobase + D_STATE, DSTATE_PLL_D3_OFF |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 156 | | DSTATE_GFX_CLOCK_GATING | DSTATE_DOT_CLOCK_GATING); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 157 | 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 Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 161 | |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 162 | /* 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 Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 166 | |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 167 | /* 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 Heymans | 75f9131 | 2016-10-12 01:04:28 +0200 | [diff] [blame] | 179 | u32 this_err = MAX(dot, target_frequency) - |
| 180 | MIN(dot, target_frequency); |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 181 | 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 Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 195 | if (smallest_err == 0xffffffff) { |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 196 | 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 Serbinenko | 551cff0 | 2015-10-10 23:58:08 +0200 | [diff] [blame] | 209 | printk(BIOS_DEBUG, (mode->lvds_dual_channel |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 210 | ? "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 Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 217 | BASE_FREQUENCY * (5 * (pixel_m1 + 2) + (pixel_m2 + 2)) / |
| 218 | (pixel_n + 2) / (pixel_p1 * pixel_p2)); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 219 | |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 220 | if (IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)) { |
| 221 | /* Disable panel fitter (we're in native resolution). */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 222 | 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 Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 227 | } else { |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 228 | 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 Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 232 | | (1 << PFIT_PIPE_SHIFT) | HORIZ_AUTO_SCALE |
| 233 | | VERT_AUTO_SCALE); |
| 234 | } |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 235 | |
| 236 | mdelay(1); |
| 237 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 238 | write32(mmiobase + DSPCNTR(0), DISPPLANE_BGRX888 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 239 | | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE); |
| 240 | |
| 241 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 242 | write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS |
| 243 | | (read32(mmiobase + PP_CONTROL) & ~PANEL_UNLOCK_MASK)); |
| 244 | write32(mmiobase + FP0(1), |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 245 | (pixel_n << 16) |
| 246 | | (pixel_m1 << 8) | pixel_m2); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 247 | write32(mmiobase + DPLL(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 248 | DPLL_VGA_MODE_DIS | |
| 249 | DPLL_VCO_ENABLE | DPLLB_MODE_LVDS |
Vladimir Serbinenko | 551cff0 | 2015-10-10 23:58:08 +0200 | [diff] [blame] | 250 | | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 251 | : 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 Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 255 | | (0x10000 << (pixel_p1 - 1))); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 256 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 257 | write32(mmiobase + DPLL(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 258 | DPLL_VGA_MODE_DIS | |
| 259 | DPLL_VCO_ENABLE | DPLLB_MODE_LVDS |
Vladimir Serbinenko | 551cff0 | 2015-10-10 23:58:08 +0200 | [diff] [blame] | 260 | | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 261 | : DPLLB_LVDS_P2_CLOCK_DIV_14) |
| 262 | | ((conf->gpu_lvds_use_spread_spectrum_clock ? 3 : 0) << 13) |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 263 | | (0x10000 << (pixel_p1 - 1))); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 264 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 265 | write32(mmiobase + HTOTAL(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 266 | ((hactive + right_border + hblank - 1) << 16) |
| 267 | | (hactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 268 | write32(mmiobase + HBLANK(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 269 | ((hactive + right_border + hblank - 1) << 16) |
| 270 | | (hactive + right_border - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 271 | write32(mmiobase + HSYNC(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 272 | ((hactive + right_border + hfront_porch + hsync - 1) << 16) |
| 273 | | (hactive + right_border + hfront_porch - 1)); |
| 274 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 275 | write32(mmiobase + VTOTAL(1), ((vactive + bottom_border + vblank - 1) << 16) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 276 | | (vactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 277 | write32(mmiobase + VBLANK(1), ((vactive + bottom_border + vblank - 1) << 16) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 278 | | (vactive + bottom_border - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 279 | write32(mmiobase + VSYNC(1), |
Arthur Heymans | c8c73a6 | 2016-10-13 14:12:45 +0200 | [diff] [blame] | 280 | ((vactive + bottom_border + vfront_porch + vsync - 1) << 16) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 281 | | (vactive + bottom_border + vfront_porch - 1)); |
| 282 | |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 283 | if (IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)) { |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 284 | write32(mmiobase + PIPESRC(1), ((hactive - 1) << 16) |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 285 | | (vactive - 1)); |
| 286 | } else { |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 287 | write32(mmiobase + PIPESRC(1), (639 << 16) | 399); |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 288 | } |
| 289 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 290 | mdelay(1); |
| 291 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 292 | write32(mmiobase + DSPSIZE(0), (hactive - 1) | ((vactive - 1) << 16)); |
| 293 | write32(mmiobase + DSPPOS(0), 0); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 294 | |
| 295 | /* Backlight init. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 296 | write32(mmiobase + BLC_PWM_CTL, conf->gpu_backlight); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 297 | |
| 298 | edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63; |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 299 | 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 Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 303 | | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE); |
| 304 | mdelay(1); |
| 305 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 306 | write32(mmiobase + PIPECONF(1), PIPECONF_ENABLE); |
| 307 | write32(mmiobase + LVDS, LVDS_ON |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 308 | | (hpolarity << 20) | (vpolarity << 21) |
Vladimir Serbinenko | 551cff0 | 2015-10-10 23:58:08 +0200 | [diff] [blame] | 309 | | (mode->lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 310 | | LVDS_CLOCK_BOTH_POWERUP_ALL : 0) |
| 311 | | LVDS_CLOCK_A_POWERUP_ALL |
| 312 | | LVDS_PIPE(1)); |
| 313 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 314 | write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); |
| 315 | write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 316 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 317 | write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 318 | | PANEL_POWER_ON | PANEL_POWER_RESET); |
| 319 | |
| 320 | printk (BIOS_DEBUG, "waiting for panel powerup\n"); |
| 321 | while (1) { |
| 322 | u32 reg32; |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 323 | reg32 = read32(mmiobase + PP_STATUS); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 324 | if ((reg32 & PP_SEQUENCE_MASK) == PP_SEQUENCE_NONE) |
| 325 | break; |
| 326 | } |
| 327 | printk (BIOS_DEBUG, "panel powered up\n"); |
| 328 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 329 | write32(mmiobase + PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 330 | |
| 331 | /* Clear interrupts. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 332 | 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 Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 337 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 338 | if (gtt_setup(mmiobase)) { |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 339 | 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 Heymans | 874a8f9 | 2016-05-19 16:06:09 +0200 | [diff] [blame] | 348 | uma_size = decode_igd_memory_size((reg16 >> 4) & 7); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 349 | printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10); |
| 350 | } |
| 351 | |
Vladimir Serbinenko | 055fe03 | 2014-08-19 23:59:27 +0200 | [diff] [blame] | 352 | for (i = 0; i < (uma_size - 256) / 4; i++) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 353 | { |
| 354 | outl((i << 2) | 1, piobase); |
| 355 | outl(pphysbase + (i << 12) + 1, piobase + 4); |
| 356 | } |
| 357 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 358 | temp = read32(mmiobase + PGETBL_CTL); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 359 | 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 Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 366 | 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 Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 370 | |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 371 | set_vbe_mode_info_valid(&edid, pgfx); |
| 372 | } else { |
| 373 | vga_misc_write(0x67); |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 374 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 375 | write32(mmiobase + DSPCNTR(0), DISPPLANE_SEL_PIPE_B); |
| 376 | write32(mmiobase + VGACNTRL, 0x02c4008e |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 377 | | VGA_PIPE_B_SELECT); |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 378 | |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 379 | vga_textmode_init(); |
| 380 | } |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 381 | return 0; |
| 382 | } |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 383 | |
| 384 | static int intel_gma_init_vga(struct northbridge_intel_i945_config *conf, |
| 385 | unsigned int pphysbase, unsigned int piobase, |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 386 | u8 *mmiobase, unsigned int pgfx) |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 387 | { |
| 388 | int i; |
| 389 | u32 hactive, vactive; |
| 390 | u16 reg16; |
| 391 | u32 uma_size; |
| 392 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 393 | printk(BIOS_SPEW, "mmiobase %x addrport %x physbase %x\n", |
| 394 | (u32)mmiobase, piobase, pphysbase); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 395 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 396 | gtt_setup(mmiobase); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 397 | |
| 398 | /* Disable VGA. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 399 | write32(mmiobase + VGACNTRL, VGA_DISP_DISABLE); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 400 | |
| 401 | /* Disable pipes. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 402 | write32(mmiobase + PIPECONF(0), 0); |
| 403 | write32(mmiobase + PIPECONF(1), 0); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 404 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 405 | write32(mmiobase + INSTPM, 0x800); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 406 | |
| 407 | vga_gr_write(0x18, 0); |
| 408 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 409 | write32(mmiobase + VGA0, 0x200074); |
| 410 | write32(mmiobase + VGA1, 0x200074); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 411 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 412 | 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 Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 416 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 417 | write32(mmiobase + ADPA, ADPA_DAC_ENABLE |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 418 | | 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 Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 425 | write32(mmiobase + 0x7041c, 0x0); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 426 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 427 | 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 Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 431 | |
| 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 Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 449 | write32(mmiobase + DPLL(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 450 | 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 Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 456 | write32(mmiobase + DPLL(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 457 | 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 Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 463 | write32(mmiobase + ADPA, ADPA_DAC_ENABLE |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 464 | | 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 Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 471 | write32(mmiobase + HTOTAL(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 472 | ((hactive - 1) << 16) |
| 473 | | (hactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 474 | write32(mmiobase + HBLANK(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 475 | ((hactive - 1) << 16) |
| 476 | | (hactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 477 | write32(mmiobase + HSYNC(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 478 | ((hactive - 1) << 16) |
| 479 | | (hactive - 1)); |
| 480 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 481 | write32(mmiobase + VTOTAL(0), ((vactive - 1) << 16) |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 482 | | (vactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 483 | write32(mmiobase + VBLANK(0), ((vactive - 1) << 16) |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 484 | | (vactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 485 | write32(mmiobase + VSYNC(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 486 | ((vactive - 1) << 16) |
| 487 | | (vactive - 1)); |
| 488 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 489 | write32(mmiobase + PF_WIN_POS(0), 0); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 490 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 491 | 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 Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 495 | |
| 496 | mdelay(1); |
| 497 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 498 | write32(mmiobase + FDI_RX_CTL(0), 0x00002040); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 499 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 500 | write32(mmiobase + FDI_RX_CTL(0), 0x80002050); |
| 501 | write32(mmiobase + FDI_TX_CTL(0), 0x00044000); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 502 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 503 | write32(mmiobase + FDI_TX_CTL(0), 0x80044000); |
| 504 | write32(mmiobase + PIPECONF(0), PIPECONF_ENABLE | PIPECONF_BPP_6 | PIPECONF_DITHER_EN); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 505 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 506 | write32(mmiobase + VGACNTRL, 0x0); |
| 507 | write32(mmiobase + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 508 | mdelay(1); |
| 509 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 510 | write32(mmiobase + ADPA, ADPA_DAC_ENABLE |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 511 | | 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 Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 518 | 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 Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 522 | |
| 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 Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 539 | 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 Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 544 | |
| 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 Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 556 | static int probe_edid(u8 *mmiobase, u8 slave) |
Arthur Heymans | 62f4dad | 2016-09-06 23:53:32 +0200 | [diff] [blame] | 557 | { |
Paul Menzel | 533a385 | 2016-11-27 22:17:44 +0100 | [diff] [blame] | 558 | int i; |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 559 | u8 vga_edid[128]; |
| 560 | u8 header[8] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}; |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 561 | intel_gmbus_read_edid(mmiobase + GMBUS0, slave, 0x50, vga_edid, 128); |
| 562 | intel_gmbus_stop(mmiobase + GMBUS0); |
Paul Menzel | 533a385 | 2016-11-27 22:17:44 +0100 | [diff] [blame] | 563 | for (i = 0; i < 8; i++) { |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 564 | if (vga_edid[i] != header[i]) { |
Arthur Heymans | 62f4dad | 2016-09-06 23:53:32 +0200 | [diff] [blame] | 565 | printk(BIOS_DEBUG, "No display connected on slave %d\n", |
| 566 | slave); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | } |
Arthur Heymans | 62f4dad | 2016-09-06 23:53:32 +0200 | [diff] [blame] | 570 | printk(BIOS_SPEW, "Found a display on slave %d\n", slave); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 571 | return 1; |
| 572 | } |
| 573 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 574 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 575 | static void gma_func0_init(struct device *dev) |
| 576 | { |
| 577 | u32 reg32; |
| 578 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 579 | /* 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 Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 586 | /* IGD needs to be Bus Master */ |
| 587 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 588 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER |
| 589 | | PCI_COMMAND_IO | PCI_COMMAND_MEMORY); |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 590 | |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 591 | 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 Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 608 | /* probe if VGA is connected and always run */ |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 609 | /* 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 Heymans | f3f4bea | 2016-10-20 20:44:54 +0200 | [diff] [blame] | 629 | } else { |
| 630 | /* PCI Init, will run VBIOS */ |
| 631 | pci_dev_init(dev); |
Arthur Heymans | 333176e | 2016-09-07 22:10:57 +0200 | [diff] [blame] | 632 | } |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 635 | /* This doesn't reclaim stolen UMA memory, but IGD could still |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 636 | be re-enabled later. */ |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 637 | static 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 Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 651 | static void gma_func1_init(struct device *dev) |
| 652 | { |
| 653 | u32 reg32; |
Alexander Couzens | c7a1a3e | 2016-03-09 10:42:58 +0100 | [diff] [blame] | 654 | u8 val; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 655 | |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 656 | /* IGD needs to be Bus Master, also enable IO access */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 657 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 658 | pci_write_config32(dev, PCI_COMMAND, reg32 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 659 | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 660 | |
Alexander Couzens | c7a1a3e | 2016-03-09 10:42:58 +0100 | [diff] [blame] | 661 | 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 Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | static 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 Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 678 | const struct i915_gpu_controller_info * |
| 679 | intel_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 Georgi | 54e227e | 2015-08-08 22:02:12 +0200 | [diff] [blame] | 686 | if (!chip) { |
| 687 | return NULL; |
| 688 | } |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 689 | return &chip->gfx; |
| 690 | } |
| 691 | |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame] | 692 | static void gma_ssdt(device_t device) |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 693 | { |
| 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 Heymans | c057a061 | 2016-10-22 14:16:48 +0200 | [diff] [blame] | 702 | static 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 Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 715 | static struct pci_operations gma_pci_ops = { |
| 716 | .set_subsystem = gma_set_subsystem, |
| 717 | }; |
| 718 | |
| 719 | static struct device_operations gma_func0_ops = { |
Arthur Heymans | c057a061 | 2016-10-22 14:16:48 +0200 | [diff] [blame] | 720 | .read_resources = gma_func0_read_resources, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 721 | .set_resources = pci_dev_set_resources, |
| 722 | .enable_resources = pci_dev_enable_resources, |
| 723 | .init = gma_func0_init, |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 724 | .acpi_fill_ssdt_generator = gma_ssdt, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 725 | .scan_bus = 0, |
| 726 | .enable = 0, |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 727 | .disable = gma_func0_disable, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 728 | .ops_pci = &gma_pci_ops, |
| 729 | }; |
| 730 | |
| 731 | |
| 732 | static 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 HAOUAS | a299345 | 2016-10-28 10:56:59 +0200 | [diff] [blame] | 742 | static 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 | |
| 749 | static const unsigned short i945_gma_func1_ids[] = { |
| 750 | 0x27a6, /* Mobile 945GM/GMS/GME Express Integrated Graphics Controller */ |
| 751 | 0 |
| 752 | }; |
Vladimir Serbinenko | 10dd0e3 | 2014-11-17 00:07:12 +0100 | [diff] [blame] | 753 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 754 | static const struct pci_driver i945_gma_func0_driver __pci_driver = { |
| 755 | .ops = &gma_func0_ops, |
| 756 | .vendor = PCI_VENDOR_ID_INTEL, |
Elyes HAOUAS | a299345 | 2016-10-28 10:56:59 +0200 | [diff] [blame] | 757 | .devices = i945_gma_func0_ids, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 758 | }; |
| 759 | |
| 760 | static const struct pci_driver i945_gma_func1_driver __pci_driver = { |
| 761 | .ops = &gma_func1_ops, |
| 762 | .vendor = PCI_VENDOR_ID_INTEL, |
Elyes HAOUAS | a299345 | 2016-10-28 10:56:59 +0200 | [diff] [blame] | 763 | .devices = i945_gma_func1_ids, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 764 | }; |