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> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 18 | #include <device/mmio.h> |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 19 | #include <delay.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 20 | #include <arch/io.h> |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 23 | #include <device/pci_ops.h> |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 24 | #include <device/pci_ids.h> |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 25 | #include <pc80/mc146818rtc.h> |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 26 | #include <edid.h> |
| 27 | #include <drivers/intel/gma/edid.h> |
| 28 | #include <drivers/intel/gma/i915.h> |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 29 | #include <drivers/intel/gma/opregion.h> |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 30 | #include <string.h> |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 31 | #include <pc80/vga.h> |
| 32 | #include <pc80/vga_io.h> |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 33 | #include <commonlib/helpers.h> |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 34 | #include <cbmem.h> |
| 35 | #include <southbridge/intel/i82801gx/nvs.h> |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 36 | |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 37 | #include "i945.h" |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 38 | #include "chip.h" |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 39 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 40 | #define GDRST 0xc0 |
Arthur Heymans | c057a061 | 2016-10-22 14:16:48 +0200 | [diff] [blame] | 41 | #define MSAC 0x62 /* Multi Size Aperture Control */ |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 42 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 43 | #define LVDS_CLOCK_A_POWERUP_ALL (3 << 8) |
| 44 | #define LVDS_CLOCK_B_POWERUP_ALL (3 << 4) |
| 45 | #define LVDS_CLOCK_BOTH_POWERUP_ALL (3 << 2) |
Elyes HAOUAS | 8868fc6 | 2017-06-28 20:41:53 +0200 | [diff] [blame] | 46 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 47 | #define DPLLB_LVDS_P2_CLOCK_DIV_7 (1 << 24) /* i915 */ |
| 48 | |
Elyes HAOUAS | 692e7df | 2017-06-28 20:44:41 +0200 | [diff] [blame] | 49 | #define DPLL_INTEGRATED_CRI_CLK_VLV (1 << 14) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 50 | |
| 51 | #define PGETBL_CTL 0x2020 |
| 52 | #define PGETBL_ENABLED 0x00000001 |
| 53 | |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 54 | #define BASE_FREQUENCY 100000 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 55 | |
Arthur Heymans | 8e07900 | 2017-01-14 22:31:54 +0100 | [diff] [blame] | 56 | #define DEFAULT_BLC_PWM 180 |
| 57 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 58 | uintptr_t gma_get_gnvs_aslb(const void *gnvs) |
| 59 | { |
| 60 | const global_nvs_t *gnvs_ptr = gnvs; |
| 61 | return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0); |
| 62 | } |
| 63 | |
| 64 | void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb) |
| 65 | { |
| 66 | global_nvs_t *gnvs_ptr = gnvs; |
| 67 | if (gnvs_ptr) |
| 68 | gnvs_ptr->aslb = aslb; |
| 69 | } |
| 70 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 71 | static int gtt_setup(u8 *mmiobase) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 72 | { |
| 73 | unsigned long PGETBL_save; |
Paul Menzel | cc95f18 | 2014-06-05 22:45:35 +0200 | [diff] [blame] | 74 | unsigned long tom; // top of memory |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 75 | |
Paul Menzel | cc95f18 | 2014-06-05 22:45:35 +0200 | [diff] [blame] | 76 | /* |
| 77 | * The Video BIOS places the GTT right below top of memory. |
Denis 'GNUtoo' Carikli | 16110e7 | 2014-10-14 07:33:53 +0200 | [diff] [blame] | 78 | */ |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 79 | tom = pci_read_config8(pcidev_on_root(0, 0), TOLUD) << 24; |
Paul Menzel | cc95f18 | 2014-06-05 22:45:35 +0200 | [diff] [blame] | 80 | PGETBL_save = tom - 256 * KiB; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 81 | PGETBL_save |= PGETBL_ENABLED; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 82 | PGETBL_save |= 2; /* set GTT to 256kb */ |
| 83 | |
| 84 | write32(mmiobase + GFX_FLSH_CNTL, 0); |
| 85 | |
| 86 | write32(mmiobase + PGETBL_CTL, PGETBL_save); |
| 87 | |
| 88 | /* verify */ |
| 89 | if (read32(mmiobase + PGETBL_CTL) & PGETBL_ENABLED) { |
| 90 | printk(BIOS_DEBUG, "gtt_setup is enabled.\n"); |
| 91 | } else { |
| 92 | printk(BIOS_DEBUG, "gtt_setup failed!!!\n"); |
| 93 | return 1; |
| 94 | } |
| 95 | write32(mmiobase + GFX_FLSH_CNTL, 0); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 100 | static int intel_gma_init_lvds(struct northbridge_intel_i945_config *conf, |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 101 | unsigned int pphysbase, unsigned int piobase, |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 102 | u8 *mmiobase, unsigned int pgfx) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 103 | { |
| 104 | struct edid edid; |
Mono | 2e4f83b | 2015-09-07 21:15:26 +0200 | [diff] [blame] | 105 | struct edid_mode *mode; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 106 | u8 edid_data[128]; |
| 107 | unsigned long temp; |
| 108 | int hpolarity, vpolarity; |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 109 | u32 smallest_err = 0xffffffff; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 110 | u32 target_frequency; |
| 111 | u32 pixel_p1 = 1; |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 112 | u32 pixel_p2; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 113 | u32 pixel_n = 1; |
| 114 | u32 pixel_m1 = 1; |
| 115 | u32 pixel_m2 = 1; |
| 116 | u32 hactive, vactive, right_border, bottom_border; |
| 117 | u32 vsync, hsync, vblank, hblank, hfront_porch, vfront_porch; |
| 118 | u32 i, j; |
| 119 | u32 uma_size; |
| 120 | u16 reg16; |
| 121 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 122 | printk(BIOS_SPEW, |
Francis Rowe | 71512b2 | 2015-03-16 05:31:40 +0000 | [diff] [blame] | 123 | "i915lightup: graphics %p mmio %p addrport %04x physbase %08x\n", |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 124 | (void *)pgfx, mmiobase, piobase, pphysbase); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 125 | |
Arthur Heymans | 8da2286 | 2017-08-06 15:56:30 +0200 | [diff] [blame] | 126 | intel_gmbus_read_edid(mmiobase + GMBUS0, GMBUS_PORT_PANEL, 0x50, |
| 127 | edid_data, sizeof(edid_data)); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 128 | decode_edid(edid_data, sizeof(edid_data), &edid); |
Mono | 2e4f83b | 2015-09-07 21:15:26 +0200 | [diff] [blame] | 129 | mode = &edid.mode; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 130 | |
Mono | 2e4f83b | 2015-09-07 21:15:26 +0200 | [diff] [blame] | 131 | hpolarity = (mode->phsync == '-'); |
| 132 | vpolarity = (mode->pvsync == '-'); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 133 | hactive = edid.x_resolution; |
| 134 | vactive = edid.y_resolution; |
Mono | 2e4f83b | 2015-09-07 21:15:26 +0200 | [diff] [blame] | 135 | right_border = mode->hborder; |
| 136 | bottom_border = mode->vborder; |
| 137 | vblank = mode->vbl; |
| 138 | hblank = mode->hbl; |
| 139 | vsync = mode->vspw; |
| 140 | hsync = mode->hspw; |
| 141 | hfront_porch = mode->hso; |
| 142 | vfront_porch = mode->vso; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 143 | |
| 144 | for (i = 0; i < 2; i++) |
| 145 | for (j = 0; j < 0x100; j++) |
Elyes HAOUAS | 0a15fe9 | 2016-09-17 19:12:27 +0200 | [diff] [blame] | 146 | /* R = j, G = j, B = j. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 147 | write32(mmiobase + PALETTE(i) + 4 * j, 0x10101 * j); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 148 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 149 | write32(mmiobase + PCH_PP_CONTROL, PANEL_UNLOCK_REGS |
| 150 | | (read32(mmiobase + PCH_PP_CONTROL) & ~PANEL_UNLOCK_MASK)); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 151 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 152 | 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] | 153 | /* Clean registers. */ |
| 154 | for (i = 0; i < 0x20; i += 4) |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 155 | write32(mmiobase + RENDER_RING_BASE + i, 0); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 156 | for (i = 0; i < 0x20; i += 4) |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 157 | write32(mmiobase + FENCE_REG_965_0 + i, 0); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 158 | |
| 159 | /* Disable VGA. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 160 | write32(mmiobase + VGACNTRL, VGA_DISP_DISABLE); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 161 | |
| 162 | /* Disable pipes. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 163 | write32(mmiobase + PIPECONF(0), 0); |
| 164 | write32(mmiobase + PIPECONF(1), 0); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 165 | |
| 166 | /* Init PRB0. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 167 | write32(mmiobase + HWS_PGA, 0x352d2000); |
| 168 | write32(mmiobase + PRB0_CTL, 0); |
| 169 | write32(mmiobase + PRB0_HEAD, 0); |
| 170 | write32(mmiobase + PRB0_TAIL, 0); |
| 171 | write32(mmiobase + PRB0_START, 0); |
| 172 | write32(mmiobase + PRB0_CTL, 0x0001f001); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 173 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 174 | write32(mmiobase + D_STATE, DSTATE_PLL_D3_OFF |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 175 | | DSTATE_GFX_CLOCK_GATING | DSTATE_DOT_CLOCK_GATING); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 176 | write32(mmiobase + ECOSKPD, 0x00010000); |
| 177 | write32(mmiobase + HWSTAM, 0xeffe); |
| 178 | write32(mmiobase + PORT_HOTPLUG_EN, conf->gpu_hotplug); |
| 179 | write32(mmiobase + INSTPM, 0x08000000 | INSTPM_AGPBUSY_DIS); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 180 | |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 181 | /* p2 divisor must 7 for dual channel LVDS */ |
| 182 | /* and 14 for single channel LVDS */ |
| 183 | pixel_p2 = mode->lvds_dual_channel ? 7 : 14; |
| 184 | target_frequency = mode->pixel_clock; |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 185 | |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 186 | /* Find suitable divisors, m1, m2, p1, n. */ |
| 187 | /* refclock * (5 * (m1 + 2) + (m1 + 2)) / (n + 2) / p1 / p2 */ |
| 188 | /* should be closest to target frequency as possible */ |
| 189 | u32 candn, candm1, candm2, candp1; |
| 190 | for (candm1 = 8; candm1 <= 18; candm1++) { |
| 191 | for (candm2 = 3; candm2 <= 7; candm2++) { |
| 192 | for (candn = 1; candn <= 6; candn++) { |
| 193 | for (candp1 = 1; candp1 <= 8; candp1++) { |
| 194 | u32 m = 5 * (candm1 + 2) + (candm2 + 2); |
| 195 | u32 p = candp1 * pixel_p2; |
| 196 | u32 vco = DIV_ROUND_CLOSEST(BASE_FREQUENCY * m, candn + 2); |
| 197 | u32 dot = DIV_ROUND_CLOSEST(vco, p); |
Arthur Heymans | 75f9131 | 2016-10-12 01:04:28 +0200 | [diff] [blame] | 198 | u32 this_err = MAX(dot, target_frequency) - |
| 199 | MIN(dot, target_frequency); |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 200 | if ((m < 70) || (m > 120)) |
| 201 | continue; |
| 202 | if (this_err < smallest_err) { |
| 203 | smallest_err = this_err; |
| 204 | pixel_n = candn; |
| 205 | pixel_m1 = candm1; |
| 206 | pixel_m2 = candm2; |
| 207 | pixel_p1 = candp1; |
| 208 | } |
| 209 | } |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 214 | if (smallest_err == 0xffffffff) { |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 215 | printk(BIOS_ERR, "Couldn't find GFX clock divisors\n"); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 216 | return -1; |
| 217 | } |
| 218 | |
| 219 | printk(BIOS_INFO, "bringing up panel at resolution %d x %d\n", |
| 220 | hactive, vactive); |
| 221 | printk(BIOS_DEBUG, "Borders %d x %d\n", right_border, bottom_border); |
| 222 | printk(BIOS_DEBUG, "Blank %d x %d\n", hblank, vblank); |
| 223 | printk(BIOS_DEBUG, "Sync %d x %d\n", hsync, vsync); |
| 224 | printk(BIOS_DEBUG, "Front porch %d x %d\n", hfront_porch, vfront_porch); |
| 225 | printk(BIOS_DEBUG, (conf->gpu_lvds_use_spread_spectrum_clock |
| 226 | ? "Spread spectrum clock\n" |
| 227 | : "DREF clock\n")); |
Vladimir Serbinenko | 551cff0 | 2015-10-10 23:58:08 +0200 | [diff] [blame] | 228 | printk(BIOS_DEBUG, (mode->lvds_dual_channel |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 229 | ? "Dual channel\n" |
| 230 | : "Single channel\n")); |
| 231 | printk(BIOS_DEBUG, "Polarities %d, %d\n", |
| 232 | hpolarity, vpolarity); |
| 233 | printk(BIOS_DEBUG, "Pixel N=%d, M1=%d, M2=%d, P1=%d\n", |
| 234 | pixel_n, pixel_m1, pixel_m2, pixel_p1); |
| 235 | printk(BIOS_DEBUG, "Pixel clock %d kHz\n", |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 236 | BASE_FREQUENCY * (5 * (pixel_m1 + 2) + (pixel_m2 + 2)) / |
| 237 | (pixel_n + 2) / (pixel_p1 * pixel_p2)); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 238 | |
Paul Menzel | bcf9a0a | 2018-02-18 10:05:53 +0100 | [diff] [blame] | 239 | printk(BIOS_INFO, "VGA mode: %s\n", IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER) ? |
| 240 | "Linear framebuffer" : "text"); |
Nico Huber | 6d8266b | 2017-05-20 16:46:01 +0200 | [diff] [blame] | 241 | if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) { |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 242 | /* Disable panel fitter (we're in native resolution). */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 243 | write32(mmiobase + PF_CTL(0), 0); |
| 244 | write32(mmiobase + PF_WIN_SZ(0), 0); |
| 245 | write32(mmiobase + PF_WIN_POS(0), 0); |
| 246 | write32(mmiobase + PFIT_PGM_RATIOS, 0); |
| 247 | write32(mmiobase + PFIT_CONTROL, 0); |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 248 | } else { |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 249 | write32(mmiobase + PF_WIN_SZ(0), vactive | (hactive << 16)); |
| 250 | write32(mmiobase + PF_WIN_POS(0), 0); |
| 251 | write32(mmiobase + PF_CTL(0), PF_ENABLE | PF_FILTER_MED_3x3); |
| 252 | write32(mmiobase + PFIT_CONTROL, PFIT_ENABLE |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 253 | | (1 << PFIT_PIPE_SHIFT) | HORIZ_AUTO_SCALE |
| 254 | | VERT_AUTO_SCALE); |
| 255 | } |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 256 | |
| 257 | mdelay(1); |
| 258 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 259 | write32(mmiobase + DSPCNTR(0), DISPPLANE_BGRX888 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 260 | | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE); |
| 261 | |
| 262 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 263 | write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS |
| 264 | | (read32(mmiobase + PP_CONTROL) & ~PANEL_UNLOCK_MASK)); |
| 265 | write32(mmiobase + FP0(1), |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 266 | (pixel_n << 16) |
| 267 | | (pixel_m1 << 8) | pixel_m2); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 268 | write32(mmiobase + DPLL(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 269 | DPLL_VGA_MODE_DIS | |
| 270 | DPLL_VCO_ENABLE | DPLLB_MODE_LVDS |
Vladimir Serbinenko | 551cff0 | 2015-10-10 23:58:08 +0200 | [diff] [blame] | 271 | | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 272 | : DPLLB_LVDS_P2_CLOCK_DIV_14) |
| 273 | | (conf->gpu_lvds_use_spread_spectrum_clock |
| 274 | ? DPLL_INTEGRATED_CLOCK_VLV | DPLL_INTEGRATED_CRI_CLK_VLV |
| 275 | : 0) |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 276 | | (0x10000 << (pixel_p1 - 1))); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 277 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 278 | write32(mmiobase + DPLL(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 279 | DPLL_VGA_MODE_DIS | |
| 280 | DPLL_VCO_ENABLE | DPLLB_MODE_LVDS |
Vladimir Serbinenko | 551cff0 | 2015-10-10 23:58:08 +0200 | [diff] [blame] | 281 | | (mode->lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 282 | : DPLLB_LVDS_P2_CLOCK_DIV_14) |
| 283 | | ((conf->gpu_lvds_use_spread_spectrum_clock ? 3 : 0) << 13) |
Arthur Heymans | 7dfc8a5 | 2016-09-02 22:35:32 +0200 | [diff] [blame] | 284 | | (0x10000 << (pixel_p1 - 1))); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 285 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 286 | write32(mmiobase + HTOTAL(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 287 | ((hactive + right_border + hblank - 1) << 16) |
| 288 | | (hactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 289 | write32(mmiobase + HBLANK(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 290 | ((hactive + right_border + hblank - 1) << 16) |
| 291 | | (hactive + right_border - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 292 | write32(mmiobase + HSYNC(1), |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 293 | ((hactive + right_border + hfront_porch + hsync - 1) << 16) |
| 294 | | (hactive + right_border + hfront_porch - 1)); |
| 295 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 296 | write32(mmiobase + VTOTAL(1), ((vactive + bottom_border + vblank - 1) << 16) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 297 | | (vactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 298 | write32(mmiobase + VBLANK(1), ((vactive + bottom_border + vblank - 1) << 16) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 299 | | (vactive + bottom_border - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 300 | write32(mmiobase + VSYNC(1), |
Arthur Heymans | c8c73a6 | 2016-10-13 14:12:45 +0200 | [diff] [blame] | 301 | ((vactive + bottom_border + vfront_porch + vsync - 1) << 16) |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 302 | | (vactive + bottom_border + vfront_porch - 1)); |
| 303 | |
Nico Huber | 6d8266b | 2017-05-20 16:46:01 +0200 | [diff] [blame] | 304 | if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) { |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 305 | write32(mmiobase + PIPESRC(1), ((hactive - 1) << 16) |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 306 | | (vactive - 1)); |
| 307 | } else { |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 308 | write32(mmiobase + PIPESRC(1), (639 << 16) | 399); |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 311 | mdelay(1); |
| 312 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 313 | write32(mmiobase + DSPSIZE(0), (hactive - 1) | ((vactive - 1) << 16)); |
| 314 | write32(mmiobase + DSPPOS(0), 0); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 315 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 316 | edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63; |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 317 | write32(mmiobase + DSPADDR(0), 0); |
| 318 | write32(mmiobase + DSPSURF(0), 0); |
| 319 | write32(mmiobase + DSPSTRIDE(0), edid.bytes_per_line); |
| 320 | write32(mmiobase + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888 |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 321 | | DISPPLANE_SEL_PIPE_B | DISPPLANE_GAMMA_ENABLE); |
| 322 | mdelay(1); |
| 323 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 324 | write32(mmiobase + PIPECONF(1), PIPECONF_ENABLE); |
| 325 | write32(mmiobase + LVDS, LVDS_ON |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 326 | | (hpolarity << 20) | (vpolarity << 21) |
Vladimir Serbinenko | 551cff0 | 2015-10-10 23:58:08 +0200 | [diff] [blame] | 327 | | (mode->lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 328 | | LVDS_CLOCK_BOTH_POWERUP_ALL : 0) |
| 329 | | LVDS_CLOCK_A_POWERUP_ALL |
| 330 | | LVDS_PIPE(1)); |
| 331 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 332 | write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF); |
| 333 | write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 334 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 335 | write32(mmiobase + PP_CONTROL, PANEL_UNLOCK_REGS |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 336 | | PANEL_POWER_ON | PANEL_POWER_RESET); |
| 337 | |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 338 | printk(BIOS_DEBUG, "waiting for panel powerup\n"); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 339 | while (1) { |
| 340 | u32 reg32; |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 341 | reg32 = read32(mmiobase + PP_STATUS); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 342 | if ((reg32 & PP_SEQUENCE_MASK) == PP_SEQUENCE_NONE) |
| 343 | break; |
| 344 | } |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 345 | printk(BIOS_DEBUG, "panel powered up\n"); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 346 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 347 | write32(mmiobase + PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 348 | |
| 349 | /* Clear interrupts. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 350 | write32(mmiobase + DEIIR, 0xffffffff); |
| 351 | write32(mmiobase + SDEIIR, 0xffffffff); |
| 352 | write32(mmiobase + IIR, 0xffffffff); |
| 353 | write32(mmiobase + IMR, 0xffffffff); |
| 354 | write32(mmiobase + EIR, 0xffffffff); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 355 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 356 | if (gtt_setup(mmiobase)) { |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 357 | printk(BIOS_ERR, "ERROR: GTT Setup Failed!!!\n"); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | /* Setup GTT. */ |
| 362 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 363 | reg16 = pci_read_config16(pcidev_on_root(0, 0), GGC); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 364 | uma_size = 0; |
| 365 | if (!(reg16 & 2)) { |
Arthur Heymans | 874a8f9 | 2016-05-19 16:06:09 +0200 | [diff] [blame] | 366 | uma_size = decode_igd_memory_size((reg16 >> 4) & 7); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 367 | printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10); |
| 368 | } |
| 369 | |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 370 | for (i = 0; i < (uma_size - 256) / 4; i++) { |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 371 | outl((i << 2) | 1, piobase); |
| 372 | outl(pphysbase + (i << 12) + 1, piobase + 4); |
| 373 | } |
| 374 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 375 | temp = read32(mmiobase + PGETBL_CTL); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 376 | printk(BIOS_INFO, "GTT PGETBL_CTL register: 0x%lx\n", temp); |
| 377 | |
| 378 | if (temp & 1) |
| 379 | printk(BIOS_INFO, "GTT Enabled\n"); |
| 380 | else |
| 381 | printk(BIOS_ERR, "ERROR: GTT is still Disabled!!!\n"); |
| 382 | |
Nico Huber | 6d8266b | 2017-05-20 16:46:01 +0200 | [diff] [blame] | 383 | if (IS_ENABLED(CONFIG_LINEAR_FRAMEBUFFER)) { |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 384 | printk(BIOS_SPEW, "memset %p to 0x00 for %d bytes\n", |
| 385 | (void *)pgfx, hactive * vactive * 4); |
| 386 | memset((void *)pgfx, 0x00, hactive * vactive * 4); |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 387 | |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 388 | set_vbe_mode_info_valid(&edid, pgfx); |
| 389 | } else { |
| 390 | vga_misc_write(0x67); |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 391 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 392 | write32(mmiobase + DSPCNTR(0), DISPPLANE_SEL_PIPE_B); |
| 393 | write32(mmiobase + VGACNTRL, 0x02c4008e |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 394 | | VGA_PIPE_B_SELECT); |
Vladimir Serbinenko | 0092c99 | 2014-08-21 01:06:53 +0200 | [diff] [blame] | 395 | |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 396 | vga_textmode_init(); |
| 397 | } |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 398 | return 0; |
| 399 | } |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 400 | |
| 401 | static int intel_gma_init_vga(struct northbridge_intel_i945_config *conf, |
| 402 | unsigned int pphysbase, unsigned int piobase, |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 403 | u8 *mmiobase, unsigned int pgfx) |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 404 | { |
| 405 | int i; |
| 406 | u32 hactive, vactive; |
| 407 | u16 reg16; |
| 408 | u32 uma_size; |
| 409 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 410 | printk(BIOS_SPEW, "mmiobase %x addrport %x physbase %x\n", |
| 411 | (u32)mmiobase, piobase, pphysbase); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 412 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 413 | gtt_setup(mmiobase); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 414 | |
| 415 | /* Disable VGA. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 416 | write32(mmiobase + VGACNTRL, VGA_DISP_DISABLE); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 417 | |
| 418 | /* Disable pipes. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 419 | write32(mmiobase + PIPECONF(0), 0); |
| 420 | write32(mmiobase + PIPECONF(1), 0); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 421 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 422 | write32(mmiobase + INSTPM, 0x800); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 423 | |
| 424 | vga_gr_write(0x18, 0); |
| 425 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 426 | write32(mmiobase + VGA0, 0x200074); |
| 427 | write32(mmiobase + VGA1, 0x200074); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 428 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 429 | write32(mmiobase + DSPFW3, 0x7f3f00c1 & ~PINEVIEW_SELF_REFRESH_EN); |
| 430 | write32(mmiobase + DSPCLK_GATE_D, 0); |
| 431 | write32(mmiobase + FW_BLC, 0x03060106); |
| 432 | write32(mmiobase + FW_BLC2, 0x00000306); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 433 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 434 | write32(mmiobase + ADPA, ADPA_DAC_ENABLE |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 435 | | ADPA_PIPE_A_SELECT |
| 436 | | ADPA_USE_VGA_HVPOLARITY |
| 437 | | ADPA_VSYNC_CNTL_ENABLE |
| 438 | | ADPA_HSYNC_CNTL_ENABLE |
| 439 | | ADPA_DPMS_ON |
| 440 | ); |
| 441 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 442 | write32(mmiobase + 0x7041c, 0x0); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 443 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 444 | write32(mmiobase + DPLL_MD(0), 0x3); |
| 445 | write32(mmiobase + DPLL_MD(1), 0x3); |
| 446 | write32(mmiobase + DSPCNTR(1), 0x1000000); |
| 447 | write32(mmiobase + PIPESRC(1), 0x027f01df); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 448 | |
| 449 | vga_misc_write(0x67); |
| 450 | const u8 cr[] = { 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f, |
| 451 | 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, |
| 452 | 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3, |
| 453 | 0xff |
| 454 | }; |
| 455 | vga_cr_write(0x11, 0); |
| 456 | |
| 457 | for (i = 0; i <= 0x18; i++) |
| 458 | vga_cr_write(i, cr[i]); |
| 459 | |
| 460 | // Disable screen memory to prevent garbage from appearing. |
| 461 | vga_sr_write(1, vga_sr_read(1) | 0x20); |
| 462 | hactive = 640; |
| 463 | vactive = 400; |
| 464 | |
| 465 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 466 | write32(mmiobase + DPLL(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 467 | DPLL_VCO_ENABLE | DPLLB_MODE_DAC_SERIAL |
| 468 | | DPLL_VGA_MODE_DIS |
| 469 | | DPLL_DAC_SERIAL_P2_CLOCK_DIV_10 |
| 470 | | 0x400601 |
| 471 | ); |
| 472 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 473 | write32(mmiobase + DPLL(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 474 | DPLL_VCO_ENABLE | DPLLB_MODE_DAC_SERIAL |
| 475 | | DPLL_VGA_MODE_DIS |
| 476 | | DPLL_DAC_SERIAL_P2_CLOCK_DIV_10 |
| 477 | | 0x400601 |
| 478 | ); |
| 479 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 480 | write32(mmiobase + ADPA, ADPA_DAC_ENABLE |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 481 | | ADPA_PIPE_A_SELECT |
| 482 | | ADPA_USE_VGA_HVPOLARITY |
| 483 | | ADPA_VSYNC_CNTL_ENABLE |
| 484 | | ADPA_HSYNC_CNTL_ENABLE |
| 485 | | ADPA_DPMS_ON |
| 486 | ); |
| 487 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 488 | write32(mmiobase + HTOTAL(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 489 | ((hactive - 1) << 16) |
| 490 | | (hactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 491 | write32(mmiobase + HBLANK(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 492 | ((hactive - 1) << 16) |
| 493 | | (hactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 494 | write32(mmiobase + HSYNC(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 495 | ((hactive - 1) << 16) |
| 496 | | (hactive - 1)); |
| 497 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 498 | write32(mmiobase + VTOTAL(0), ((vactive - 1) << 16) |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 499 | | (vactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 500 | write32(mmiobase + VBLANK(0), ((vactive - 1) << 16) |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 501 | | (vactive - 1)); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 502 | write32(mmiobase + VSYNC(0), |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 503 | ((vactive - 1) << 16) |
| 504 | | (vactive - 1)); |
| 505 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 506 | write32(mmiobase + PF_WIN_POS(0), 0); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 507 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 508 | write32(mmiobase + PIPESRC(0), (639 << 16) | 399); |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 509 | write32(mmiobase + PF_CTL(0), PF_ENABLE | PF_FILTER_MED_3x3); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 510 | write32(mmiobase + PF_WIN_SZ(0), vactive | (hactive << 16)); |
| 511 | write32(mmiobase + PFIT_CONTROL, 0x0); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 512 | |
| 513 | mdelay(1); |
| 514 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 515 | write32(mmiobase + FDI_RX_CTL(0), 0x00002040); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 516 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 517 | write32(mmiobase + FDI_RX_CTL(0), 0x80002050); |
| 518 | write32(mmiobase + FDI_TX_CTL(0), 0x00044000); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 519 | mdelay(1); |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 520 | write32(mmiobase + FDI_TX_CTL(0), 0x80044000); |
| 521 | write32(mmiobase + PIPECONF(0), PIPECONF_ENABLE | PIPECONF_BPP_6 | PIPECONF_DITHER_EN); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 522 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 523 | write32(mmiobase + VGACNTRL, 0x0); |
| 524 | write32(mmiobase + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 525 | mdelay(1); |
| 526 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 527 | write32(mmiobase + ADPA, ADPA_DAC_ENABLE |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 528 | | ADPA_PIPE_A_SELECT |
| 529 | | ADPA_USE_VGA_HVPOLARITY |
| 530 | | ADPA_VSYNC_CNTL_ENABLE |
| 531 | | ADPA_HSYNC_CNTL_ENABLE |
| 532 | | ADPA_DPMS_ON |
| 533 | ); |
| 534 | |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 535 | write32(mmiobase + DSPFW3, 0x7f3f00c1); |
| 536 | write32(mmiobase + MI_MODE, 0x200 | VS_TIMER_DISPATCH); |
| 537 | write32(mmiobase + CACHE_MODE_0, (0x6820 | (1 << 9)) & ~(1 << 5)); |
| 538 | write32(mmiobase + CACHE_MODE_1, 0x380 & ~(1 << 9)); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 539 | |
| 540 | /* Set up GTT. */ |
| 541 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 542 | reg16 = pci_read_config16(pcidev_on_root(0, 0), GGC); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 543 | uma_size = 0; |
| 544 | if (!(reg16 & 2)) { |
| 545 | uma_size = decode_igd_memory_size((reg16 >> 4) & 7); |
| 546 | printk(BIOS_DEBUG, "%dM UMA\n", uma_size >> 10); |
| 547 | } |
| 548 | |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 549 | for (i = 0; i < (uma_size - 256) / 4; i++) { |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 550 | outl((i << 2) | 1, piobase); |
| 551 | outl(pphysbase + (i << 12) + 1, piobase + 4); |
| 552 | } |
| 553 | |
| 554 | /* Clear interrupts. */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 555 | write32(mmiobase + DEIIR, 0xffffffff); |
| 556 | write32(mmiobase + SDEIIR, 0xffffffff); |
| 557 | write32(mmiobase + IIR, 0xffffffff); |
| 558 | write32(mmiobase + IMR, 0xffffffff); |
| 559 | write32(mmiobase + EIR, 0xffffffff); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 560 | |
| 561 | vga_textmode_init(); |
| 562 | |
| 563 | /* Enable screen memory. */ |
| 564 | vga_sr_write(1, vga_sr_read(1) & ~0x20); |
| 565 | |
| 566 | return 0; |
| 567 | |
| 568 | } |
| 569 | |
| 570 | /* compare the header of the vga edid header */ |
| 571 | /* if vga is not connected it should have a correct header */ |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 572 | static int probe_edid(u8 *mmiobase, u8 slave) |
Arthur Heymans | 62f4dad | 2016-09-06 23:53:32 +0200 | [diff] [blame] | 573 | { |
Paul Menzel | 533a385 | 2016-11-27 22:17:44 +0100 | [diff] [blame] | 574 | int i; |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 575 | u8 vga_edid[128]; |
| 576 | u8 header[8] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}; |
Arthur Heymans | 85cfddb | 2017-02-06 13:47:21 +0100 | [diff] [blame] | 577 | intel_gmbus_read_edid(mmiobase + GMBUS0, slave, 0x50, vga_edid, 128); |
| 578 | intel_gmbus_stop(mmiobase + GMBUS0); |
Paul Menzel | 533a385 | 2016-11-27 22:17:44 +0100 | [diff] [blame] | 579 | for (i = 0; i < 8; i++) { |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 580 | if (vga_edid[i] != header[i]) { |
Arthur Heymans | 62f4dad | 2016-09-06 23:53:32 +0200 | [diff] [blame] | 581 | printk(BIOS_DEBUG, "No display connected on slave %d\n", |
| 582 | slave); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | } |
Arthur Heymans | 62f4dad | 2016-09-06 23:53:32 +0200 | [diff] [blame] | 586 | printk(BIOS_SPEW, "Found a display on slave %d\n", slave); |
Arthur Heymans | b59bcb2 | 2016-09-05 22:46:11 +0200 | [diff] [blame] | 587 | return 1; |
| 588 | } |
| 589 | |
Arthur Heymans | 8e07900 | 2017-01-14 22:31:54 +0100 | [diff] [blame] | 590 | static u32 get_cdclk(struct device *const dev) |
| 591 | { |
| 592 | u16 gcfgc = pci_read_config16(dev, GCFGC); |
| 593 | |
Elyes HAOUAS | 2a1c430 | 2018-10-25 10:41:27 +0200 | [diff] [blame] | 594 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Arthur Heymans | 8e07900 | 2017-01-14 22:31:54 +0100 | [diff] [blame] | 595 | return 133333333; |
Elyes HAOUAS | 2a1c430 | 2018-10-25 10:41:27 +0200 | [diff] [blame] | 596 | |
| 597 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 598 | case GC_DISPLAY_CLOCK_333_320_MHZ: |
| 599 | return 320000000; |
| 600 | default: |
| 601 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 602 | return 200000000; |
Arthur Heymans | 8e07900 | 2017-01-14 22:31:54 +0100 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | static u32 freq_to_blc_pwm_ctl(struct device *const dev, u16 pwm_freq) |
| 607 | { |
| 608 | u32 blc_mod; |
| 609 | |
| 610 | /* Set duty cycle to 100% due to use of legacy backlight control */ |
| 611 | blc_mod = get_cdclk(dev) / (32 * pwm_freq); |
| 612 | return BLM_LEGACY_MODE | ((blc_mod / 2) << 17) | ((blc_mod / 2) << 1); |
| 613 | } |
| 614 | |
| 615 | |
| 616 | static void panel_setup(u8 *mmiobase, struct device *const dev) |
| 617 | { |
| 618 | const struct northbridge_intel_i945_config *const conf = dev->chip_info; |
| 619 | |
| 620 | u32 reg32; |
| 621 | |
| 622 | /* Set up Panel Power On Delays */ |
| 623 | reg32 = (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 624 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
| 625 | write32(mmiobase + PP_ON_DELAYS, reg32); |
| 626 | |
| 627 | /* Set up Panel Power Off Delays */ |
| 628 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 629 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
| 630 | write32(mmiobase + PP_OFF_DELAYS, reg32); |
| 631 | |
| 632 | /* Set up Panel Power Cycle Delay */ |
| 633 | reg32 = (get_cdclk(dev) / 20000 - 1) << PP_REFERENCE_DIVIDER_SHIFT; |
| 634 | reg32 |= conf->gpu_panel_power_cycle_delay & 0x1f; |
| 635 | write32(mmiobase + PP_DIVISOR, reg32); |
| 636 | |
| 637 | /* Backlight init. */ |
| 638 | if (conf->pwm_freq) |
| 639 | write32(mmiobase + BLC_PWM_CTL, freq_to_blc_pwm_ctl(dev, |
| 640 | conf->pwm_freq)); |
| 641 | else |
| 642 | write32(mmiobase + BLC_PWM_CTL, freq_to_blc_pwm_ctl(dev, |
| 643 | DEFAULT_BLC_PWM)); |
| 644 | } |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 645 | |
Paul Menzel | b23833f | 2018-04-26 19:53:31 +0200 | [diff] [blame] | 646 | static void gma_ngi(struct device *const dev) |
| 647 | { |
| 648 | /* This should probably run before post VBIOS init. */ |
| 649 | printk(BIOS_INFO, "Initializing VGA without OPROM.\n"); |
| 650 | void *mmiobase; |
| 651 | u32 iobase, graphics_base; |
| 652 | struct northbridge_intel_i945_config *conf = dev->chip_info; |
| 653 | |
| 654 | iobase = dev->resource_list[1].base; |
| 655 | mmiobase = (void *)(uintptr_t)dev->resource_list[0].base; |
| 656 | graphics_base = dev->resource_list[2].base; |
| 657 | |
| 658 | printk(BIOS_SPEW, "GMADR = 0x%08x GTTADR = 0x%08x\n", |
| 659 | pci_read_config32(dev, GMADR), pci_read_config32(dev, GTTADR)); |
| 660 | |
| 661 | int err; |
| 662 | |
| 663 | if (IS_ENABLED(CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM)) |
| 664 | panel_setup(mmiobase, dev); |
| 665 | |
| 666 | /* probe if VGA is connected and always run */ |
| 667 | /* VGA init if no LVDS is connected */ |
| 668 | if (!probe_edid(mmiobase, GMBUS_PORT_PANEL) || |
| 669 | probe_edid(mmiobase, GMBUS_PORT_VGADDC)) |
| 670 | err = intel_gma_init_vga(conf, |
| 671 | pci_read_config32(dev, 0x5c) & ~0xf, |
| 672 | iobase, mmiobase, graphics_base); |
| 673 | else |
| 674 | err = intel_gma_init_lvds(conf, |
| 675 | pci_read_config32(dev, 0x5c) & ~0xf, |
| 676 | iobase, mmiobase, graphics_base); |
| 677 | if (err == 0) |
| 678 | gfx_set_init_done(1); |
| 679 | /* Linux relies on VBT for panel info. */ |
| 680 | if (CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM) { |
| 681 | generate_fake_intel_oprom(&conf->gfx, dev, "$VBT CALISTOGA"); |
| 682 | } |
| 683 | if (CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GC) { |
| 684 | generate_fake_intel_oprom(&conf->gfx, dev, "$VBT LAKEPORT-G"); |
| 685 | } |
| 686 | } |
| 687 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 688 | static void gma_func0_init(struct device *dev) |
| 689 | { |
| 690 | u32 reg32; |
| 691 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 692 | /* Unconditionally reset graphics */ |
| 693 | pci_write_config8(dev, GDRST, 1); |
| 694 | udelay(50); |
| 695 | pci_write_config8(dev, GDRST, 0); |
| 696 | /* wait for device to finish */ |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 697 | while (pci_read_config8(dev, GDRST) & 1) |
| 698 | ; |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 699 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 700 | /* IGD needs to be Bus Master */ |
| 701 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 702 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER |
| 703 | | PCI_COMMAND_IO | PCI_COMMAND_MEMORY); |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 704 | |
Arthur Heymans | e6c8f7e | 2018-08-09 11:31:51 +0200 | [diff] [blame] | 705 | int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1; |
| 706 | |
Arthur Heymans | 9c5fc62 | 2016-10-18 02:15:44 +0200 | [diff] [blame] | 707 | if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) { |
Arthur Heymans | e6c8f7e | 2018-08-09 11:31:51 +0200 | [diff] [blame] | 708 | if (acpi_is_wakeup_s3()) { |
Paul Menzel | 5e7ad65 | 2018-04-14 20:08:54 +0200 | [diff] [blame] | 709 | printk(BIOS_INFO, |
| 710 | "Skipping native VGA initialization when resuming from ACPI S3.\n"); |
Arthur Heymans | e6c8f7e | 2018-08-09 11:31:51 +0200 | [diff] [blame] | 711 | } else { |
| 712 | if (vga_disable) { |
| 713 | printk(BIOS_INFO, |
| 714 | "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n"); |
| 715 | } else { |
| 716 | gma_ngi(dev); |
| 717 | } |
| 718 | } |
Arthur Heymans | f3f4bea | 2016-10-20 20:44:54 +0200 | [diff] [blame] | 719 | } else { |
| 720 | /* PCI Init, will run VBIOS */ |
| 721 | pci_dev_init(dev); |
Arthur Heymans | 333176e | 2016-09-07 22:10:57 +0200 | [diff] [blame] | 722 | } |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 723 | |
| 724 | intel_gma_restore_opregion(); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 727 | /* This doesn't reclaim stolen UMA memory, but IGD could still |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 728 | be re-enabled later. */ |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 729 | static void gma_func0_disable(struct device *dev) |
| 730 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 731 | struct device *dev_host = pcidev_on_root(0x0, 0); |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 732 | |
| 733 | pci_write_config16(dev, GCFC, 0xa00); |
| 734 | pci_write_config16(dev_host, GGC, (1 << 1)); |
| 735 | |
| 736 | unsigned int reg32 = pci_read_config32(dev_host, DEVEN); |
| 737 | reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1); |
| 738 | pci_write_config32(dev_host, DEVEN, reg32); |
| 739 | |
| 740 | dev->enabled = 0; |
| 741 | } |
| 742 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 743 | static void gma_func1_init(struct device *dev) |
| 744 | { |
| 745 | u32 reg32; |
Alexander Couzens | c7a1a3e | 2016-03-09 10:42:58 +0100 | [diff] [blame] | 746 | u8 val; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 747 | |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 748 | /* IGD needs to be Bus Master, also enable IO access */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 749 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 750 | pci_write_config32(dev, PCI_COMMAND, reg32 | |
Vladimir Serbinenko | 26ca08c | 2014-06-01 00:24:05 +0200 | [diff] [blame] | 751 | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 752 | |
Alexander Couzens | c7a1a3e | 2016-03-09 10:42:58 +0100 | [diff] [blame] | 753 | if (get_option(&val, "tft_brightness") == CB_SUCCESS) |
| 754 | pci_write_config8(dev, 0xf4, val); |
| 755 | else |
| 756 | pci_write_config8(dev, 0xf4, 0xff); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Elyes HAOUAS | 658a934 | 2018-02-08 14:46:22 +0100 | [diff] [blame] | 759 | static void gma_set_subsystem(struct device *dev, unsigned int vendor, |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 760 | unsigned int device) |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 761 | { |
| 762 | if (!vendor || !device) { |
| 763 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 764 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 765 | } else { |
| 766 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 767 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 768 | } |
| 769 | } |
| 770 | |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 771 | const struct i915_gpu_controller_info * |
| 772 | intel_gma_get_controller_info(void) |
| 773 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 774 | struct device *dev = pcidev_on_root(0x2, 0); |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 775 | if (!dev) |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 776 | return NULL; |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 777 | struct northbridge_intel_i945_config *chip = dev->chip_info; |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 778 | if (!chip) |
Patrick Georgi | 54e227e | 2015-08-08 22:02:12 +0200 | [diff] [blame] | 779 | return NULL; |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 780 | return &chip->gfx; |
| 781 | } |
| 782 | |
Elyes HAOUAS | 658a934 | 2018-02-08 14:46:22 +0100 | [diff] [blame] | 783 | static void gma_ssdt(struct device *device) |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 784 | { |
| 785 | const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info(); |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 786 | if (!gfx) |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 787 | return; |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 788 | |
| 789 | drivers_intel_gma_displays_ssdt_generate(gfx); |
| 790 | } |
| 791 | |
Elyes HAOUAS | 658a934 | 2018-02-08 14:46:22 +0100 | [diff] [blame] | 792 | static void gma_func0_read_resources(struct device *dev) |
Arthur Heymans | c057a061 | 2016-10-22 14:16:48 +0200 | [diff] [blame] | 793 | { |
| 794 | u8 reg8; |
| 795 | |
| 796 | /* Set Untrusted Aperture Size to 256mb */ |
| 797 | reg8 = pci_read_config8(dev, MSAC); |
| 798 | reg8 &= ~0x3; |
| 799 | reg8 |= 0x2; |
| 800 | pci_write_config8(dev, MSAC, reg8); |
| 801 | |
| 802 | pci_dev_read_resources(dev); |
| 803 | } |
| 804 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 805 | static unsigned long |
| 806 | gma_write_acpi_tables(struct device *const dev, |
| 807 | unsigned long current, |
| 808 | struct acpi_rsdp *const rsdp) |
| 809 | { |
| 810 | igd_opregion_t *opregion = (igd_opregion_t *)current; |
| 811 | global_nvs_t *gnvs; |
| 812 | |
| 813 | if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS) |
| 814 | return current; |
| 815 | |
| 816 | current += sizeof(igd_opregion_t); |
| 817 | |
| 818 | /* GNVS has been already set up */ |
| 819 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 820 | if (gnvs) { |
| 821 | /* IGD OpRegion Base Address */ |
| 822 | gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion); |
| 823 | } else { |
| 824 | printk(BIOS_ERR, "Error: GNVS table not found.\n"); |
| 825 | } |
| 826 | |
| 827 | current = acpi_align_current(current); |
| 828 | return current; |
| 829 | } |
| 830 | |
| 831 | static const char *gma_acpi_name(const struct device *dev) |
| 832 | { |
| 833 | return "GFX0"; |
| 834 | } |
| 835 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 836 | static struct pci_operations gma_pci_ops = { |
| 837 | .set_subsystem = gma_set_subsystem, |
| 838 | }; |
| 839 | |
| 840 | static struct device_operations gma_func0_ops = { |
Arthur Heymans | c057a061 | 2016-10-22 14:16:48 +0200 | [diff] [blame] | 841 | .read_resources = gma_func0_read_resources, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 842 | .set_resources = pci_dev_set_resources, |
| 843 | .enable_resources = pci_dev_enable_resources, |
| 844 | .init = gma_func0_init, |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 845 | .acpi_fill_ssdt_generator = gma_ssdt, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 846 | .scan_bus = 0, |
| 847 | .enable = 0, |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 848 | .disable = gma_func0_disable, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 849 | .ops_pci = &gma_pci_ops, |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 850 | .acpi_name = gma_acpi_name, |
| 851 | .write_acpi_tables = gma_write_acpi_tables, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 852 | }; |
| 853 | |
| 854 | |
| 855 | static struct device_operations gma_func1_ops = { |
| 856 | .read_resources = pci_dev_read_resources, |
| 857 | .set_resources = pci_dev_set_resources, |
| 858 | .enable_resources = pci_dev_enable_resources, |
| 859 | .init = gma_func1_init, |
| 860 | .scan_bus = 0, |
| 861 | .enable = 0, |
| 862 | .ops_pci = &gma_pci_ops, |
| 863 | }; |
| 864 | |
Elyes HAOUAS | a299345 | 2016-10-28 10:56:59 +0200 | [diff] [blame] | 865 | static const unsigned short i945_gma_func0_ids[] = { |
| 866 | 0x2772, /* 82945G/GZ Integrated Graphics Controller */ |
| 867 | 0x27a2, /* Mobile 945GM/GMS Express Integrated Graphics Controller*/ |
| 868 | 0x27ae, /* Mobile 945GSE Express Integrated Graphics Controller */ |
| 869 | 0 |
| 870 | }; |
| 871 | |
| 872 | static const unsigned short i945_gma_func1_ids[] = { |
| 873 | 0x27a6, /* Mobile 945GM/GMS/GME Express Integrated Graphics Controller */ |
| 874 | 0 |
| 875 | }; |
Vladimir Serbinenko | 10dd0e3 | 2014-11-17 00:07:12 +0100 | [diff] [blame] | 876 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 877 | static const struct pci_driver i945_gma_func0_driver __pci_driver = { |
Paul Menzel | 82683c0 | 2018-04-14 19:56:46 +0200 | [diff] [blame] | 878 | .ops = &gma_func0_ops, |
| 879 | .vendor = PCI_VENDOR_ID_INTEL, |
Elyes HAOUAS | a299345 | 2016-10-28 10:56:59 +0200 | [diff] [blame] | 880 | .devices = i945_gma_func0_ids, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 881 | }; |
| 882 | |
| 883 | static const struct pci_driver i945_gma_func1_driver __pci_driver = { |
Paul Menzel | 82683c0 | 2018-04-14 19:56:46 +0200 | [diff] [blame] | 884 | .ops = &gma_func1_ops, |
| 885 | .vendor = PCI_VENDOR_ID_INTEL, |
Elyes HAOUAS | a299345 | 2016-10-28 10:56:59 +0200 | [diff] [blame] | 886 | .devices = i945_gma_func1_ids, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 887 | }; |