Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2013 Google Inc. |
| 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. |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
| 17 | #include <console/console.h> |
| 18 | #include <delay.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
Matt DeVillier | be33a67 | 2018-03-11 22:44:41 -0500 | [diff] [blame^] | 22 | #include <drivers/intel/gma/opregion.h> |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 23 | #include <reg_script.h> |
Patrick Georgi | 04f68c1 | 2014-11-17 08:45:02 +0100 | [diff] [blame] | 24 | #include <stdlib.h> |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 25 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 26 | #include <soc/gfx.h> |
| 27 | #include <soc/iosf.h> |
Matt DeVillier | be33a67 | 2018-03-11 22:44:41 -0500 | [diff] [blame^] | 28 | #include <soc/nvs.h> |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 29 | #include <soc/pci_devs.h> |
| 30 | #include <soc/ramstage.h> |
Matt DeVillier | be33a67 | 2018-03-11 22:44:41 -0500 | [diff] [blame^] | 31 | #include <cbmem.h> |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 32 | |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 33 | #include "chip.h" |
| 34 | |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 35 | #define GFX_TIMEOUT 100000 /* 100ms */ |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Lock Power Context Base Register to point to a 24KB block |
| 39 | * of memory in GSM. Power context save data is stored here. |
| 40 | */ |
| 41 | static void gfx_lock_pcbase(device_t dev) |
| 42 | { |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 43 | struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0); |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 44 | const u16 gms_size_map[17] = { 0,32,64,96,128,160,192,224,256, |
| 45 | 288,320,352,384,416,448,480,512 }; |
| 46 | u32 pcsize = 24 << 10; /* 24KB */ |
| 47 | u32 wopcmsz = 0x100000; /* PAVP offset */ |
| 48 | u32 gms, gmsize, pcbase; |
| 49 | |
| 50 | gms = pci_read_config32(dev, GGC) & GGC_GSM_SIZE_MASK; |
| 51 | gms >>= 3; |
Patrick Georgi | 04f68c1 | 2014-11-17 08:45:02 +0100 | [diff] [blame] | 52 | if (gms > ARRAY_SIZE(gms_size_map)) |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 53 | return; |
| 54 | gmsize = gms_size_map[gms]; |
| 55 | |
| 56 | /* PcBase = BDSM + GMS Size - WOPCMSZ - PowerContextSize */ |
| 57 | pcbase = pci_read_config32(dev, GSM_BASE) & 0xfff00000; |
| 58 | pcbase += (gmsize-1) * wopcmsz - pcsize; |
| 59 | pcbase |= 1; /* Lock */ |
| 60 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 61 | write32((u32 *)(uintptr_t)(res->base + 0x182120), pcbase); |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static const struct reg_script gfx_init_script[] = { |
| 65 | /* Allow-Wake render/media wells */ |
| 66 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x130090, ~1, 1), |
| 67 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x130094, 1, 1, GFX_TIMEOUT), |
| 68 | /* Render Force-Wake */ |
| 69 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1300b0, 0x80008000), |
| 70 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x1300b4, 0x8000, 0x8000, |
| 71 | GFX_TIMEOUT), |
| 72 | /* Media Force-Wake */ |
| 73 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1300b8, 0x80008000), |
| 74 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x1300bc, 0x8000, 0x8000, |
| 75 | GFX_TIMEOUT), |
| 76 | /* Workaround - X0:261954/A0:261955 */ |
| 77 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x182060, ~0xf, 1), |
| 78 | |
| 79 | /* |
| 80 | * PowerMeter Weights |
| 81 | */ |
| 82 | |
| 83 | /* SET1 */ |
| 84 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA800, 0x00000000), |
| 85 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA804, 0x00000000), |
| 86 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA808, 0x0000ff0A), |
| 87 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA80C, 0x1D000000), |
| 88 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA810, 0xAC004900), |
| 89 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA814, 0x000F0000), |
| 90 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA818, 0x5A000000), |
| 91 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA81C, 0x2600001F), |
| 92 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA820, 0x00090000), |
| 93 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA824, 0x2000ff00), |
| 94 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA828, 0xff090016), |
| 95 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA82C, 0x00000000), |
| 96 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA830, 0x00000100), |
| 97 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA834, 0x00A00F51), |
| 98 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA838, 0x000B0000), |
| 99 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA83C, 0xcb7D3307), |
| 100 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA840, 0x003C0000), |
| 101 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA844, 0xFFFF0000), |
| 102 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA848, 0x00220000), |
| 103 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA84c, 0x43000000), |
| 104 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA850, 0x00000800), |
| 105 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA854, 0x00000F00), |
| 106 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA858, 0x00000021), |
| 107 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA85c, 0x00000000), |
| 108 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA860, 0x00190000), |
| 109 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xAA80, 0x00FF00FF), |
| 110 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xAA84, 0x00000000), |
| 111 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x1300A4, 0x00000000), |
| 112 | /* SET2 */ |
| 113 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA900, 0x00000000), |
| 114 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA904, 0x00000000), |
| 115 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA908, 0x00000000), |
| 116 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa90c, 0x1D000000), |
| 117 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa910, 0xAC005000), |
| 118 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa914, 0x000F0000), |
| 119 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa918, 0x5A000000), |
| 120 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa91c, 0x2600001F), |
| 121 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa920, 0x00090000), |
| 122 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa924, 0x2000ff00), |
| 123 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa928, 0xff090016), |
| 124 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa92c, 0x00000000), |
| 125 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa930, 0x00000100), |
| 126 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa934, 0x00A00F51), |
| 127 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa938, 0x000B0000), |
| 128 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA93C, 0xcb7D3307), |
| 129 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA940, 0x003C0000), |
| 130 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA944, 0xFFFF0000), |
| 131 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA948, 0x00220000), |
| 132 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA94C, 0x43000000), |
| 133 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA950, 0x00000800), |
| 134 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA954, 0x00000000), |
| 135 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA960, 0x00000000), |
| 136 | /* SET3 */ |
| 137 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xaa3c, 0x00000000), |
| 138 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xaa54, 0x00000000), |
| 139 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xaa60, 0x00000000), |
| 140 | /* Enable PowerMeter Counters */ |
| 141 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA248, 0x00000058), |
| 142 | |
| 143 | /* Program PUNIT_GPU_EC_VIRUS based on DPTF SDP */ |
| 144 | /* SDP Profile 4 == 0x11940, others 0xcf08 */ |
Shawn Nematbakhsh | 51d787a | 2014-01-16 17:52:21 -0800 | [diff] [blame] | 145 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_GPU_EC_VIRUS, 0xcf08), |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 146 | |
| 147 | /* GfxPause */ |
| 148 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa000, 0x00071388), |
| 149 | |
| 150 | /* Dynamic EU Control Settings */ |
| 151 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa080, 0x00000004), |
| 152 | |
| 153 | /* Lock ECO Bit Settings */ |
| 154 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa180, 0x80000000), |
| 155 | |
| 156 | /* DOP Clock Gating */ |
| 157 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9424, 0x00000001), |
| 158 | |
| 159 | /* MBCunit will send the VCR (Fuse) writes as NP-W */ |
| 160 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x907c, 0xfffeffff, 0x00010000), |
| 161 | |
| 162 | /* |
| 163 | * RC6 Settings |
| 164 | */ |
| 165 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA090, 0x00000000), |
| 166 | /* RC1e - RC6/6p - RC6pp Wake Rate Limits */ |
| 167 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA09C, 0x00280000), |
| 168 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA0A8, 0x0001E848), |
| 169 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA0AC, 0x00000019), |
| 170 | /* RC Sleep / RCx Thresholds */ |
| 171 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA0B0, 0x00000000), |
| 172 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA0B8, 0x00000557), |
| 173 | |
| 174 | /* |
| 175 | * Turbo Settings |
| 176 | */ |
| 177 | |
| 178 | /* Render/Video/Blitter Idle Max Count */ |
| 179 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x2054, 0x0000000A), |
| 180 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x12054, 0x0000000A), |
| 181 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x22054, 0x0000000A), |
| 182 | /* RP Down Timeout */ |
| 183 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA010, 0x000F4240), |
| 184 | |
| 185 | /* |
| 186 | * Turbo Control Settings |
| 187 | */ |
| 188 | |
| 189 | /* RP Up/Down Threshold */ |
| 190 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA02C, 0x0000E8E8), |
| 191 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA030, 0x0003BD08), |
| 192 | /* RP Up/Down EI */ |
| 193 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA068, 0x000101D0), |
| 194 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA06C, 0x00055730), |
| 195 | |
| 196 | /* RP Idle Hysteresis */ |
| 197 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa070, 0x0000000a), |
| 198 | |
| 199 | /* HW RC6 Control Settings */ |
| 200 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa090, 0x11000000), |
| 201 | |
| 202 | /* RP Control */ |
| 203 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa024, 0x00000592), |
| 204 | |
| 205 | /* Enable PM Interrupts */ |
| 206 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x44024, 0x03000000), |
| 207 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x4402c, 0x03000076), |
| 208 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa168, 0x0000007e), |
| 209 | |
| 210 | /* Aggressive Clock Gating */ |
| 211 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9400, 0), |
| 212 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9404, 0), |
| 213 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9408, 0), |
| 214 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x940c, 0), |
Aaron Durbin | 3549462 | 2014-01-15 11:59:10 -0600 | [diff] [blame] | 215 | |
| 216 | /* Enable Gfx Turbo. */ |
| 217 | REG_IOSF_RMW(IOSF_PORT_PMC, SB_BIOS_CONFIG, |
| 218 | ~SB_BIOS_CONFIG_GFX_TURBO_DIS, 0), |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 219 | REG_SCRIPT_END |
| 220 | }; |
| 221 | |
| 222 | static const struct reg_script gpu_pre_vbios_script[] = { |
| 223 | /* Make sure GFX is bus master with MMIO access */ |
| 224 | REG_PCI_OR32(PCI_COMMAND, PCI_COMMAND_MASTER|PCI_COMMAND_MEMORY), |
| 225 | /* Display */ |
| 226 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xc0), |
| 227 | REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xc0, 0xc0, |
| 228 | GFX_TIMEOUT), |
| 229 | /* Tx/Rx Lanes */ |
| 230 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xfff0c0), |
| 231 | REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xfff0c0, 0xfff0c0, |
| 232 | GFX_TIMEOUT), |
| 233 | /* Common Lane */ |
| 234 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xfffcc0), |
| 235 | REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xfffcc0, 0xfffcc0, |
| 236 | GFX_TIMEOUT), |
| 237 | /* Ungating Tx only */ |
| 238 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xf00cc0), |
| 239 | REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xfffcc0, 0xf00cc0, |
| 240 | GFX_TIMEOUT), |
| 241 | /* Ungating Common Lane only */ |
| 242 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xf000c0), |
| 243 | REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xffffc0, 0xf000c0, |
| 244 | GFX_TIMEOUT), |
| 245 | /* Ungating Display */ |
| 246 | REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xf00000), |
| 247 | REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xfffff0, 0xf00000, |
| 248 | GFX_TIMEOUT), |
| 249 | REG_SCRIPT_END |
| 250 | }; |
| 251 | |
| 252 | static const struct reg_script gfx_post_vbios_script[] = { |
| 253 | /* Deassert Render Force-Wake */ |
| 254 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1300b0, 0x80000000), |
| 255 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x1300b4, 0x8000, 0, GFX_TIMEOUT), |
| 256 | /* Deassert Media Force-Wake */ |
| 257 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1300b8, 0x80000000), |
| 258 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x1300bc, 0x8000, 0, GFX_TIMEOUT), |
| 259 | /* Set Lock bits */ |
| 260 | REG_PCI_RMW32(GGC, 0xffffffff, 1), |
| 261 | REG_PCI_RMW32(GSM_BASE, 0xffffffff, 1), |
| 262 | REG_PCI_RMW32(GTT_BASE, 0xffffffff, 1), |
| 263 | REG_SCRIPT_END |
| 264 | }; |
| 265 | |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 266 | static inline void gfx_run_script(device_t dev, const struct reg_script *ops) |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 267 | { |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 268 | reg_script_run_on_dev(dev, ops); |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static void gfx_pre_vbios_init(device_t dev) |
| 272 | { |
| 273 | printk(BIOS_INFO, "GFX: Pre VBIOS Init\n"); |
| 274 | gfx_run_script(dev, gpu_pre_vbios_script); |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static void gfx_pm_init(device_t dev) |
| 278 | { |
| 279 | printk(BIOS_INFO, "GFX: Power Management Init\n"); |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 280 | gfx_run_script(dev, gfx_init_script); |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 281 | |
| 282 | /* Lock power context base */ |
| 283 | gfx_lock_pcbase(dev); |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static void gfx_post_vbios_init(device_t dev) |
| 287 | { |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 288 | printk(BIOS_INFO, "GFX: Post VBIOS Init\n"); |
| 289 | gfx_run_script(dev, gfx_post_vbios_script); |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Aaron Durbin | 59e209a | 2014-04-24 11:35:28 -0500 | [diff] [blame] | 292 | static void set_backlight_pwm(device_t dev, uint32_t bklt_reg, int req_hz) |
| 293 | { |
| 294 | int divider; |
| 295 | struct resource *res; |
| 296 | |
| 297 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 298 | |
| 299 | if (res == NULL) |
| 300 | return; |
| 301 | |
| 302 | /* Default to 200 Hz if nothing is set. */ |
| 303 | if (req_hz == 0) |
| 304 | req_hz = 200; |
| 305 | |
| 306 | /* Base clock is 25MHz */ |
| 307 | divider = 25 * 1000 * 1000 / (16 * req_hz); |
| 308 | |
| 309 | /* Do not set duty cycle (lower 16 bits). Just set the divider. */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 310 | write32((u32 *)(uintptr_t)(res->base + bklt_reg), divider << 16); |
Aaron Durbin | 59e209a | 2014-04-24 11:35:28 -0500 | [diff] [blame] | 311 | } |
| 312 | |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 313 | static void gfx_panel_setup(device_t dev) |
| 314 | { |
| 315 | struct soc_intel_baytrail_config *config = dev->chip_info; |
| 316 | struct reg_script gfx_pipea_init[] = { |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 317 | /* CONTROL */ |
| 318 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEA_REG(PP_CONTROL), |
| 319 | PP_CONTROL_UNLOCK | PP_CONTROL_EDP_FORCE_VDD), |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 320 | /* POWER ON */ |
| 321 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEA_REG(PP_ON_DELAYS), |
| 322 | (config->gpu_pipea_port_select << 30 | |
| 323 | config->gpu_pipea_power_on_delay << 16 | |
| 324 | config->gpu_pipea_light_on_delay)), |
| 325 | /* POWER OFF */ |
| 326 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEA_REG(PP_OFF_DELAYS), |
| 327 | (config->gpu_pipea_power_off_delay << 16 | |
| 328 | config->gpu_pipea_light_off_delay)), |
| 329 | /* DIVISOR */ |
| 330 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, PIPEA_REG(PP_DIVISOR), |
| 331 | ~0x1f, config->gpu_pipea_power_cycle_delay), |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 332 | REG_SCRIPT_END |
| 333 | }; |
| 334 | struct reg_script gfx_pipeb_init[] = { |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 335 | /* CONTROL */ |
| 336 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEB_REG(PP_CONTROL), |
| 337 | PP_CONTROL_UNLOCK | PP_CONTROL_EDP_FORCE_VDD), |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 338 | /* POWER ON */ |
| 339 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEB_REG(PP_ON_DELAYS), |
| 340 | (config->gpu_pipeb_port_select << 30 | |
| 341 | config->gpu_pipeb_power_on_delay << 16 | |
| 342 | config->gpu_pipeb_light_on_delay)), |
| 343 | /* POWER OFF */ |
| 344 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEB_REG(PP_OFF_DELAYS), |
| 345 | (config->gpu_pipeb_power_off_delay << 16 | |
| 346 | config->gpu_pipeb_light_off_delay)), |
| 347 | /* DIVISOR */ |
| 348 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, PIPEB_REG(PP_DIVISOR), |
| 349 | ~0x1f, config->gpu_pipeb_power_cycle_delay), |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 350 | REG_SCRIPT_END |
| 351 | }; |
| 352 | |
| 353 | if (config->gpu_pipea_port_select) { |
| 354 | printk(BIOS_INFO, "GFX: Initialize PIPEA\n"); |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 355 | reg_script_run_on_dev(dev, gfx_pipea_init); |
Aaron Durbin | 59e209a | 2014-04-24 11:35:28 -0500 | [diff] [blame] | 356 | set_backlight_pwm(dev, PIPEA_REG(BACKLIGHT_CTL), |
| 357 | config->gpu_pipea_pwm_freq_hz); |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | if (config->gpu_pipeb_port_select) { |
| 361 | printk(BIOS_INFO, "GFX: Initialize PIPEB\n"); |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 362 | reg_script_run_on_dev(dev, gfx_pipeb_init); |
Aaron Durbin | 59e209a | 2014-04-24 11:35:28 -0500 | [diff] [blame] | 363 | set_backlight_pwm(dev, PIPEB_REG(BACKLIGHT_CTL), |
| 364 | config->gpu_pipeb_pwm_freq_hz); |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Matt DeVillier | be33a67 | 2018-03-11 22:44:41 -0500 | [diff] [blame^] | 368 | uintptr_t gma_get_gnvs_aslb(const void *gnvs) |
| 369 | { |
| 370 | const global_nvs_t *gnvs_ptr = gnvs; |
| 371 | return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0); |
| 372 | } |
| 373 | |
| 374 | void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb) |
| 375 | { |
| 376 | global_nvs_t *gnvs_ptr = gnvs; |
| 377 | if (gnvs_ptr) |
| 378 | gnvs_ptr->aslb = aslb; |
| 379 | } |
| 380 | |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 381 | static void gfx_init(device_t dev) |
| 382 | { |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 383 | /* Pre VBIOS Init */ |
| 384 | gfx_pre_vbios_init(dev); |
Duncan Laurie | 223d4a4f | 2013-10-31 08:27:29 -0700 | [diff] [blame] | 385 | |
| 386 | /* Power Management Init */ |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 387 | gfx_pm_init(dev); |
| 388 | |
Duncan Laurie | b40e444 | 2013-12-09 14:38:57 -0800 | [diff] [blame] | 389 | gfx_panel_setup(dev); |
| 390 | |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 391 | /* Run VBIOS */ |
| 392 | pci_dev_init(dev); |
| 393 | |
| 394 | /* Post VBIOS Init */ |
| 395 | gfx_post_vbios_init(dev); |
Matt DeVillier | be33a67 | 2018-03-11 22:44:41 -0500 | [diff] [blame^] | 396 | |
| 397 | /* Restore opregion on S3 resume */ |
| 398 | intel_gma_restore_opregion(); |
| 399 | } |
| 400 | |
| 401 | static unsigned long |
| 402 | gma_write_acpi_tables(struct device *const dev, |
| 403 | unsigned long current, |
| 404 | struct acpi_rsdp *const rsdp) |
| 405 | { |
| 406 | igd_opregion_t *opregion = (igd_opregion_t *)current; |
| 407 | global_nvs_t *gnvs; |
| 408 | |
| 409 | if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS) |
| 410 | return current; |
| 411 | |
| 412 | current += sizeof(igd_opregion_t); |
| 413 | |
| 414 | /* GNVS has been already set up */ |
| 415 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 416 | if (gnvs) { |
| 417 | /* IGD OpRegion Base Address */ |
| 418 | gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion); |
| 419 | } else { |
| 420 | printk(BIOS_ERR, "Error: GNVS table not found.\n"); |
| 421 | } |
| 422 | |
| 423 | current = acpi_align_current(current); |
| 424 | return current; |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | static struct device_operations gfx_device_ops = { |
| 428 | .read_resources = pci_dev_read_resources, |
| 429 | .set_resources = pci_dev_set_resources, |
| 430 | .enable_resources = pci_dev_enable_resources, |
| 431 | .init = gfx_init, |
| 432 | .ops_pci = &soc_pci_ops, |
Matt DeVillier | be33a67 | 2018-03-11 22:44:41 -0500 | [diff] [blame^] | 433 | .write_acpi_tables = gma_write_acpi_tables, |
Duncan Laurie | e3f75f8 | 2013-10-28 15:49:34 -0700 | [diff] [blame] | 434 | }; |
| 435 | |
| 436 | static const struct pci_driver gfx_driver __pci_driver = { |
| 437 | .ops = &gfx_device_ops, |
| 438 | .vendor = PCI_VENDOR_ID_INTEL, |
| 439 | .device = GFX_DEVID, |
| 440 | }; |