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