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