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