Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 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 | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Duncan Laurie | e86ac7e | 2014-10-07 15:19:54 -0700 | [diff] [blame] | 16 | #include <arch/acpi.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 17 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 18 | #include <device/pci_ops.h> |
Marc Jones | a6354a1 | 2014-12-26 22:11:14 -0700 | [diff] [blame] | 19 | #include <bootmode.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <delay.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <reg_script.h> |
Matt DeVillier | 773488f | 2017-10-18 12:27:25 -0500 | [diff] [blame] | 28 | #include <cbmem.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | #include <drivers/intel/gma/i915_reg.h> |
Matt DeVillier | 773488f | 2017-10-18 12:27:25 -0500 | [diff] [blame] | 30 | #include <drivers/intel/gma/opregion.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 31 | #include <soc/cpu.h> |
Matt DeVillier | 773488f | 2017-10-18 12:27:25 -0500 | [diff] [blame] | 32 | #include <soc/nvs.h> |
Duncan Laurie | 1e6b591 | 2015-01-30 16:33:43 -0800 | [diff] [blame] | 33 | #include <soc/pm.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 34 | #include <soc/ramstage.h> |
| 35 | #include <soc/systemagent.h> |
| 36 | #include <soc/intel/broadwell/chip.h> |
Philipp Deppenwiese | fea2429 | 2017-10-17 17:02:29 +0200 | [diff] [blame] | 37 | #include <security/vboot/vbnv.h> |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 38 | #include <soc/igd.h> |
Elyes HAOUAS | 27d02d8 | 2019-05-15 21:11:39 +0200 | [diff] [blame] | 39 | #include <types.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 40 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 41 | #define GT_RETRY 1000 |
| 42 | enum { |
| 43 | GT_CDCLK_DEFAULT = 0, |
| 44 | GT_CDCLK_337, |
| 45 | GT_CDCLK_450, |
| 46 | GT_CDCLK_540, |
| 47 | GT_CDCLK_675, |
| 48 | }; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 49 | |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 50 | static u32 reg_em4; |
| 51 | static u32 reg_em5; |
| 52 | |
| 53 | u32 igd_get_reg_em4(void) { return reg_em4; } |
| 54 | u32 igd_get_reg_em5(void) { return reg_em5; } |
| 55 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 56 | struct reg_script haswell_early_init_script[] = { |
| 57 | /* Enable Force Wake */ |
| 58 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa180, 0x00000020), |
| 59 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010001), |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 60 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 1, GT_RETRY), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 61 | |
| 62 | /* Enable Counters */ |
| 63 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa248, 0x00000016), |
| 64 | |
| 65 | /* GFXPAUSE settings */ |
| 66 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa000, 0x00070020), |
| 67 | |
| 68 | /* ECO Settings */ |
| 69 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0xa180, 0xff3fffff, 0x15000000), |
| 70 | |
| 71 | /* Enable DOP Clock Gating */ |
| 72 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9424, 0x000003fd), |
| 73 | |
| 74 | /* Enable Unit Level Clock Gating */ |
| 75 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9400, 0x00000080), |
| 76 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9404, 0x40401000), |
| 77 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9408, 0x00000000), |
| 78 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x940c, 0x02000001), |
| 79 | |
| 80 | /* |
| 81 | * RC6 Settings |
| 82 | */ |
| 83 | |
| 84 | /* Wake Rate Limits */ |
| 85 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa090, 0x00000000), |
| 86 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa098, 0x03e80000), |
| 87 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa09c, 0x00280000), |
| 88 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0a8, 0x0001e848), |
| 89 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0ac, 0x00000019), |
| 90 | |
| 91 | /* Render/Video/Blitter Idle Max Count */ |
| 92 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x02054, 0x0000000a), |
| 93 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x12054, 0x0000000a), |
| 94 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x22054, 0x0000000a), |
| 95 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1a054, 0x0000000a), |
| 96 | |
| 97 | /* RC Sleep / RCx Thresholds */ |
| 98 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b0, 0x00000000), |
| 99 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b4, 0x000003e8), |
| 100 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa0b8, 0x0000c350), |
| 101 | |
| 102 | /* RP Settings */ |
| 103 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa010, 0x000f4240), |
| 104 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa014, 0x12060000), |
| 105 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa02c, 0x0000e808), |
| 106 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa030, 0x0003bd08), |
| 107 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa068, 0x000101d0), |
| 108 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa06c, 0x00055730), |
| 109 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa070, 0x0000000a), |
| 110 | |
| 111 | /* RP Control */ |
| 112 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa024, 0x00000b92), |
| 113 | |
| 114 | /* HW RC6 Control */ |
| 115 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa090, 0x88040000), |
| 116 | |
| 117 | /* Video Frequency Request */ |
| 118 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa00c, 0x08000000), |
| 119 | |
| 120 | /* Set RC6 VIDs */ |
| 121 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY), |
| 122 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138128, 0), |
| 123 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138124, 0x80000004), |
| 124 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY), |
| 125 | |
| 126 | /* Enable PM Interrupts */ |
| 127 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x4402c, 0x03000076), |
| 128 | |
| 129 | /* Enable RC6 in idle */ |
| 130 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa094, 0x00040000), |
| 131 | |
| 132 | REG_SCRIPT_END |
| 133 | }; |
| 134 | |
| 135 | static const struct reg_script haswell_late_init_script[] = { |
| 136 | /* Lock settings */ |
| 137 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a248, (1 << 31)), |
| 138 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a004, (1 << 4)), |
| 139 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a080, (1 << 2)), |
| 140 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a180, (1 << 31)), |
| 141 | |
| 142 | /* Disable Force Wake */ |
| 143 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010000), |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 144 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 0, GT_RETRY), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 145 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00000001), |
| 146 | |
| 147 | /* Enable power well for DP and Audio */ |
| 148 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x45400, (1 << 31)), |
| 149 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x45400, |
| 150 | (1 << 30), (1 << 30), GT_RETRY), |
| 151 | |
| 152 | REG_SCRIPT_END |
| 153 | }; |
| 154 | |
| 155 | static const struct reg_script broadwell_early_init_script[] = { |
| 156 | /* Enable Force Wake */ |
| 157 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010001), |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 158 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 1, GT_RETRY), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 159 | |
| 160 | /* Enable push bus metric control and shift */ |
| 161 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa248, 0x00000004), |
| 162 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa250, 0x000000ff), |
| 163 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa25c, 0x00000010), |
| 164 | |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 165 | /* GFXPAUSE settings (set based on stepping) */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 166 | |
| 167 | /* ECO Settings */ |
| 168 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa180, 0x45200000), |
| 169 | |
| 170 | /* Enable DOP Clock Gating */ |
| 171 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9424, 0x000000fd), |
| 172 | |
| 173 | /* Enable Unit Level Clock Gating */ |
| 174 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9400, 0x00000000), |
| 175 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9404, 0x40401000), |
| 176 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9408, 0x00000000), |
| 177 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x940c, 0x02000001), |
| 178 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1a054, 0x0000000a), |
| 179 | |
| 180 | /* Video Frequency Request */ |
| 181 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa00c, 0x08000000), |
| 182 | |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 183 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138158, 0x00000009), |
| 184 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x13815c, 0x0000000d), |
| 185 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 186 | /* |
| 187 | * RC6 Settings |
| 188 | */ |
| 189 | |
| 190 | /* Wake Rate Limits */ |
| 191 | REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x0a090, 0, 0), |
| 192 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a098, 0x03e80000), |
| 193 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a09c, 0x00280000), |
| 194 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0a8, 0x0001e848), |
| 195 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0ac, 0x00000019), |
| 196 | |
| 197 | /* Render/Video/Blitter Idle Max Count */ |
| 198 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x02054, 0x0000000a), |
| 199 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x12054, 0x0000000a), |
| 200 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x22054, 0x0000000a), |
| 201 | |
| 202 | /* RC Sleep / RCx Thresholds */ |
| 203 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0b0, 0x00000000), |
| 204 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a0b8, 0x00000271), |
| 205 | |
| 206 | /* RP Settings */ |
| 207 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a010, 0x000f4240), |
| 208 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a014, 0x12060000), |
| 209 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a02c, 0x0000e808), |
| 210 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a030, 0x0003bd08), |
| 211 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a068, 0x000101d0), |
| 212 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a06c, 0x00055730), |
| 213 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a070, 0x0000000a), |
| 214 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a168, 0x00000006), |
| 215 | |
| 216 | /* RP Control */ |
| 217 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa024, 0x00000b92), |
| 218 | |
| 219 | /* HW RC6 Control */ |
| 220 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa090, 0x90040000), |
| 221 | |
| 222 | /* Set RC6 VIDs */ |
| 223 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY), |
| 224 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138128, 0), |
| 225 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x138124, 0x80000004), |
| 226 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x138124, (1 << 31), 0, GT_RETRY), |
| 227 | |
| 228 | /* Enable PM Interrupts */ |
| 229 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x4402c, 0x03000076), |
| 230 | |
| 231 | /* Enable RC6 in idle */ |
| 232 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa094, 0x00040000), |
| 233 | |
| 234 | REG_SCRIPT_END |
| 235 | }; |
| 236 | |
| 237 | static const struct reg_script broadwell_late_init_script[] = { |
| 238 | /* Lock settings */ |
| 239 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a248, (1 << 31)), |
| 240 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a000, (1 << 18)), |
| 241 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x0a180, (1 << 31)), |
| 242 | |
| 243 | /* Disable Force Wake */ |
| 244 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa188, 0x00010000), |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 245 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, FORCEWAKE_ACK_HSW, 1, 0, GT_RETRY), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 246 | |
| 247 | /* Enable power well for DP and Audio */ |
| 248 | REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x45400, (1 << 31)), |
| 249 | REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x45400, |
| 250 | (1 << 30), (1 << 30), GT_RETRY), |
| 251 | |
| 252 | REG_SCRIPT_END |
| 253 | }; |
| 254 | |
| 255 | u32 map_oprom_vendev(u32 vendev) |
| 256 | { |
| 257 | return SA_IGD_OPROM_VENDEV; |
| 258 | } |
| 259 | |
| 260 | static struct resource *gtt_res = NULL; |
| 261 | |
| 262 | static unsigned long gtt_read(unsigned long reg) |
| 263 | { |
| 264 | u32 val; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 265 | val = read32(res2mmio(gtt_res, reg, 0)); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 266 | return val; |
| 267 | |
| 268 | } |
| 269 | |
| 270 | static void gtt_write(unsigned long reg, unsigned long data) |
| 271 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 272 | write32(res2mmio(gtt_res, reg, 0), data); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask) |
| 276 | { |
| 277 | u32 val = gtt_read(reg); |
| 278 | val &= andmask; |
| 279 | val |= ormask; |
| 280 | gtt_write(reg, val); |
| 281 | } |
| 282 | |
| 283 | static int gtt_poll(u32 reg, u32 mask, u32 value) |
| 284 | { |
Lee Leahy | 23602df | 2017-03-16 19:00:37 -0700 | [diff] [blame] | 285 | unsigned int try = GT_RETRY; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 286 | u32 data; |
| 287 | |
| 288 | while (try--) { |
| 289 | data = gtt_read(reg); |
| 290 | if ((data & mask) == value) |
| 291 | return 1; |
| 292 | udelay(10); |
| 293 | } |
| 294 | |
| 295 | printk(BIOS_ERR, "GT init timeout\n"); |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | static void igd_setup_panel(struct device *dev) |
| 300 | { |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame^] | 301 | config_t *conf = config_of(dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 302 | u32 reg32; |
| 303 | |
| 304 | /* Setup Digital Port Hotplug */ |
| 305 | reg32 = gtt_read(PCH_PORT_HOTPLUG); |
| 306 | if (!reg32) { |
| 307 | reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 308 | reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 309 | reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
| 310 | gtt_write(PCH_PORT_HOTPLUG, reg32); |
| 311 | } |
| 312 | |
| 313 | /* Setup Panel Power On Delays */ |
| 314 | reg32 = gtt_read(PCH_PP_ON_DELAYS); |
| 315 | if (!reg32) { |
| 316 | reg32 = (conf->gpu_panel_port_select & 0x3) << 30; |
| 317 | reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 318 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
| 319 | gtt_write(PCH_PP_ON_DELAYS, reg32); |
| 320 | } |
| 321 | |
| 322 | /* Setup Panel Power Off Delays */ |
| 323 | reg32 = gtt_read(PCH_PP_OFF_DELAYS); |
| 324 | if (!reg32) { |
| 325 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 326 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
| 327 | gtt_write(PCH_PP_OFF_DELAYS, reg32); |
| 328 | } |
| 329 | |
| 330 | /* Setup Panel Power Cycle Delay */ |
| 331 | if (conf->gpu_panel_power_cycle_delay) { |
| 332 | reg32 = gtt_read(PCH_PP_DIVISOR); |
| 333 | reg32 &= ~0xff; |
| 334 | reg32 |= conf->gpu_panel_power_cycle_delay & 0xff; |
| 335 | gtt_write(PCH_PP_DIVISOR, reg32); |
| 336 | } |
| 337 | |
| 338 | /* Enable Backlight if needed */ |
| 339 | if (conf->gpu_cpu_backlight) { |
| 340 | gtt_write(BLC_PWM_CPU_CTL2, BLC_PWM2_ENABLE); |
| 341 | gtt_write(BLC_PWM_CPU_CTL, conf->gpu_cpu_backlight); |
| 342 | } |
| 343 | if (conf->gpu_pch_backlight) { |
| 344 | gtt_write(BLC_PWM_PCH_CTL1, BLM_PCH_PWM_ENABLE); |
| 345 | gtt_write(BLC_PWM_PCH_CTL2, conf->gpu_pch_backlight); |
| 346 | } |
| 347 | } |
| 348 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 349 | static int igd_get_cdclk_haswell(u32 *const cdsel, int *const inform_pc, |
| 350 | struct device *const dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 351 | { |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame^] | 352 | const config_t *const conf = config_of(dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 353 | int cdclk = conf->cdclk; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 354 | |
| 355 | /* Check for ULX GT1 or GT2 */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 356 | const int devid = pci_read_config16(dev, PCI_DEVICE_ID); |
| 357 | const int gpu_is_ulx = devid == IGD_HASWELL_ULX_GT1 || |
| 358 | devid == IGD_HASWELL_ULX_GT2; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 359 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 360 | /* Check for fixed fused clock */ |
| 361 | if (gtt_read(0x42014) & 1 << 24) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 362 | cdclk = GT_CDCLK_450; |
| 363 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 364 | /* |
| 365 | * ULX defaults to 337MHz with possible override for 450MHz |
| 366 | * ULT is fixed at 450MHz |
| 367 | * others default to 540MHz with possible override for 450MHz |
| 368 | */ |
| 369 | if (gpu_is_ulx && cdclk <= GT_CDCLK_337) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 370 | cdclk = GT_CDCLK_337; |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 371 | else if (gpu_is_ulx || cpu_is_ult() || |
| 372 | cdclk == GT_CDCLK_337 || cdclk == GT_CDCLK_450) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 373 | cdclk = GT_CDCLK_450; |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 374 | else |
| 375 | cdclk = GT_CDCLK_540; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 376 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 377 | *cdsel = cdclk != GT_CDCLK_450; |
| 378 | *inform_pc = gpu_is_ulx; |
| 379 | return cdclk; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 382 | static int igd_get_cdclk_broadwell(u32 *const cdsel, int *const inform_pc, |
| 383 | struct device *const dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 384 | { |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 385 | static const u32 cdsel_by_cdclk[] = { 0, 2, 0, 1, 3 }; |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame^] | 386 | const config_t *const conf = config_of(dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 387 | int cdclk = conf->cdclk; |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 388 | |
| 389 | /* Check for ULX */ |
| 390 | const int devid = pci_read_config16(dev, PCI_DEVICE_ID); |
| 391 | const int gpu_is_ulx = devid == IGD_BROADWELL_Y_GT2; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 392 | |
| 393 | /* Inform power controller of upcoming frequency change */ |
| 394 | gtt_write(0x138128, 0); |
| 395 | gtt_write(0x13812c, 0); |
| 396 | gtt_write(0x138124, 0x80000018); |
| 397 | |
| 398 | /* Poll GT driver mailbox for run/busy clear */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 399 | if (gtt_poll(0x138124, (1 << 31), (0 << 31))) { |
| 400 | *inform_pc = 1; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 401 | } else { |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 402 | cdclk = GT_CDCLK_450; |
| 403 | *inform_pc = 0; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 406 | /* Check for fixed fused clock */ |
| 407 | if (gtt_read(0x42014) & 1 << 24) |
| 408 | cdclk = GT_CDCLK_450; |
| 409 | |
| 410 | /* |
| 411 | * ULX defaults to 450MHz with possible override up to 540MHz |
| 412 | * ULT defaults to 540MHz with possible override up to 675MHz |
| 413 | * others default to 675MHz with possible override for lower freqs |
| 414 | */ |
| 415 | if (cdclk == GT_CDCLK_337) |
| 416 | cdclk = GT_CDCLK_337; |
| 417 | else if (cdclk == GT_CDCLK_450 || |
| 418 | (gpu_is_ulx && cdclk == GT_CDCLK_DEFAULT)) |
| 419 | cdclk = GT_CDCLK_450; |
| 420 | else if (cdclk == GT_CDCLK_540 || gpu_is_ulx || |
| 421 | (cpu_is_ult() && cdclk == GT_CDCLK_DEFAULT)) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 422 | cdclk = GT_CDCLK_540; |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 423 | else |
| 424 | cdclk = GT_CDCLK_675; |
| 425 | |
| 426 | *cdsel = cdsel_by_cdclk[cdclk]; |
| 427 | return cdclk; |
| 428 | } |
| 429 | |
| 430 | static void igd_cdclk_init(struct device *dev, const int is_broadwell) |
| 431 | { |
| 432 | u32 dpdiv, cdsel, cdval; |
| 433 | int cdclk, inform_pc; |
| 434 | |
| 435 | if (is_broadwell) |
| 436 | cdclk = igd_get_cdclk_broadwell(&cdsel, &inform_pc, dev); |
| 437 | else |
| 438 | cdclk = igd_get_cdclk_haswell(&cdsel, &inform_pc, dev); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 439 | |
| 440 | /* Set variables based on CD Clock setting */ |
| 441 | switch (cdclk) { |
| 442 | case GT_CDCLK_337: |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 443 | cdval = 337; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 444 | dpdiv = 169; |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 445 | reg_em4 = 16; |
| 446 | reg_em5 = 225; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 447 | break; |
| 448 | case GT_CDCLK_450: |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 449 | cdval = 449; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 450 | dpdiv = 225; |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 451 | reg_em4 = 4; |
| 452 | reg_em5 = 75; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 453 | break; |
| 454 | case GT_CDCLK_540: |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 455 | cdval = 539; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 456 | dpdiv = 270; |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 457 | reg_em4 = 4; |
| 458 | reg_em5 = 90; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 459 | break; |
| 460 | case GT_CDCLK_675: |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 461 | cdval = 674; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 462 | dpdiv = 338; |
Matt DeVillier | f8960a6 | 2016-11-16 23:37:43 -0600 | [diff] [blame] | 463 | reg_em4 = 8; |
| 464 | reg_em5 = 225; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 465 | default: |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | /* Set LPCLL_CTL CD Clock Frequency Select */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 470 | gtt_rmw(0x130040, 0xf3ffffff, cdsel << 26); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 471 | |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 472 | if (inform_pc) { |
| 473 | /* Inform power controller of selected frequency */ |
| 474 | gtt_write(0x138128, cdsel); |
| 475 | gtt_write(0x13812c, 0); |
| 476 | gtt_write(0x138124, 0x80000017); |
| 477 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 478 | |
| 479 | /* Program CD Clock Frequency */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 480 | gtt_rmw(0x46200, 0xfffffc00, cdval); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 481 | |
| 482 | /* Set CPU DP AUX 2X bit clock dividers */ |
| 483 | gtt_rmw(0x64010, 0xfffff800, dpdiv); |
| 484 | gtt_rmw(0x64810, 0xfffff800, dpdiv); |
| 485 | } |
| 486 | |
Matt DeVillier | 773488f | 2017-10-18 12:27:25 -0500 | [diff] [blame] | 487 | uintptr_t gma_get_gnvs_aslb(const void *gnvs) |
| 488 | { |
| 489 | const global_nvs_t *gnvs_ptr = gnvs; |
| 490 | return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0); |
| 491 | } |
| 492 | |
| 493 | void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb) |
| 494 | { |
| 495 | global_nvs_t *gnvs_ptr = gnvs; |
| 496 | if (gnvs_ptr) |
| 497 | gnvs_ptr->aslb = aslb; |
| 498 | } |
| 499 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 500 | static void igd_init(struct device *dev) |
| 501 | { |
| 502 | int is_broadwell = !!(cpu_family_model() == BROADWELL_FAMILY_ULT); |
| 503 | u32 rp1_gfx_freq; |
| 504 | |
| 505 | /* IGD needs to be Bus Master */ |
| 506 | u32 reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 507 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 508 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 509 | |
| 510 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 511 | if (!gtt_res || !gtt_res->base) |
| 512 | return; |
| 513 | |
| 514 | /* Wait for any configured pre-graphics delay */ |
Kyösti Mälkki | 1ec23c9 | 2015-05-29 06:18:18 +0300 | [diff] [blame] | 515 | if (!acpi_is_wakeup_s3()) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 516 | #if CONFIG(CHROMEOS) |
Joel Kitching | 807803a | 2019-05-10 12:58:53 +0800 | [diff] [blame] | 517 | if (display_init_required()) |
Duncan Laurie | 1e6b591 | 2015-01-30 16:33:43 -0800 | [diff] [blame] | 518 | mdelay(CONFIG_PRE_GRAPHICS_DELAY); |
Duncan Laurie | b8a7b71 | 2014-11-10 13:00:27 -0800 | [diff] [blame] | 519 | #else |
Duncan Laurie | 1e6b591 | 2015-01-30 16:33:43 -0800 | [diff] [blame] | 520 | mdelay(CONFIG_PRE_GRAPHICS_DELAY); |
Duncan Laurie | b8a7b71 | 2014-11-10 13:00:27 -0800 | [diff] [blame] | 521 | #endif |
Duncan Laurie | 1e6b591 | 2015-01-30 16:33:43 -0800 | [diff] [blame] | 522 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 523 | |
| 524 | /* Early init steps */ |
| 525 | if (is_broadwell) { |
| 526 | reg_script_run_on_dev(dev, broadwell_early_init_script); |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 527 | |
| 528 | /* Set GFXPAUSE based on stepping */ |
| 529 | if (cpu_stepping() <= (CPUID_BROADWELL_E0 & 0xf) && |
| 530 | systemagent_revision() <= 9) { |
| 531 | gtt_write(0xa000, 0x300ff); |
| 532 | } else { |
| 533 | gtt_write(0xa000, 0x30020); |
| 534 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 535 | } else { |
| 536 | reg_script_run_on_dev(dev, haswell_early_init_script); |
| 537 | } |
| 538 | |
| 539 | /* Set RP1 graphics frequency */ |
| 540 | rp1_gfx_freq = (MCHBAR32(0x5998) >> 8) & 0xff; |
| 541 | gtt_write(0xa008, rp1_gfx_freq << 24); |
| 542 | |
| 543 | /* Post VBIOS panel setup */ |
| 544 | igd_setup_panel(dev); |
| 545 | |
| 546 | /* Initialize PCI device, load/execute BIOS Option ROM */ |
| 547 | pci_dev_init(dev); |
| 548 | |
| 549 | /* Late init steps */ |
Nico Huber | e392f41 | 2016-12-07 19:29:08 +0100 | [diff] [blame] | 550 | igd_cdclk_init(dev, is_broadwell); |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 551 | if (is_broadwell) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 552 | reg_script_run_on_dev(dev, broadwell_late_init_script); |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 553 | else |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 554 | reg_script_run_on_dev(dev, haswell_late_init_script); |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 555 | |
Duncan Laurie | 49efaf2 | 2014-10-09 16:13:24 -0700 | [diff] [blame] | 556 | if (gfx_get_init_done()) { |
| 557 | /* |
| 558 | * Work around VBIOS issue that is not clearing first 64 |
| 559 | * bytes of the framebuffer during VBE mode set. |
| 560 | */ |
| 561 | struct resource *fb = find_resource(dev, PCI_BASE_ADDRESS_2); |
| 562 | memset((void *)((u32)fb->base), 0, 64); |
| 563 | } |
| 564 | |
Kyösti Mälkki | 1ec23c9 | 2015-05-29 06:18:18 +0300 | [diff] [blame] | 565 | if (!gfx_get_init_done() && !acpi_is_wakeup_s3()) { |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 566 | /* |
| 567 | * Enable DDI-A if the Option ROM did not execute: |
| 568 | * |
| 569 | * bit 0: Display detected (RO) |
| 570 | * bit 4: DDI A supports 4 lanes and DDI E is not used |
| 571 | * bit 7: DDI buffer is idle |
| 572 | */ |
| 573 | gtt_write(DDI_BUF_CTL_A, DDI_BUF_IS_IDLE | DDI_A_4_LANES | |
| 574 | DDI_INIT_DISPLAY_DETECTED); |
| 575 | } |
Matt DeVillier | 773488f | 2017-10-18 12:27:25 -0500 | [diff] [blame] | 576 | |
| 577 | intel_gma_restore_opregion(); |
| 578 | } |
| 579 | |
| 580 | static unsigned long |
| 581 | gma_write_acpi_tables(struct device *const dev, unsigned long current, |
| 582 | struct acpi_rsdp *const rsdp) |
| 583 | { |
| 584 | igd_opregion_t *opregion = (igd_opregion_t *)current; |
| 585 | global_nvs_t *gnvs; |
| 586 | |
| 587 | if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS) |
| 588 | return current; |
| 589 | |
| 590 | current += sizeof(igd_opregion_t); |
| 591 | |
| 592 | /* GNVS has been already set up */ |
| 593 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 594 | if (gnvs) { |
| 595 | /* IGD OpRegion Base Address */ |
| 596 | gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion); |
| 597 | } else { |
| 598 | printk(BIOS_ERR, "Error: GNVS table not found.\n"); |
| 599 | } |
| 600 | |
| 601 | current = acpi_align_current(current); |
| 602 | return current; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 605 | static struct device_operations igd_ops = { |
Marc Jones | a6354a1 | 2014-12-26 22:11:14 -0700 | [diff] [blame] | 606 | .read_resources = &pci_dev_read_resources, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 607 | .set_resources = &pci_dev_set_resources, |
| 608 | .enable_resources = &pci_dev_enable_resources, |
| 609 | .init = &igd_init, |
| 610 | .ops_pci = &broadwell_pci_ops, |
Matt DeVillier | 773488f | 2017-10-18 12:27:25 -0500 | [diff] [blame] | 611 | .write_acpi_tables = gma_write_acpi_tables, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 612 | }; |
| 613 | |
| 614 | static const unsigned short pci_device_ids[] = { |
| 615 | IGD_HASWELL_ULT_GT1, |
| 616 | IGD_HASWELL_ULT_GT2, |
| 617 | IGD_HASWELL_ULT_GT3, |
| 618 | IGD_BROADWELL_U_GT1, |
| 619 | IGD_BROADWELL_U_GT2, |
| 620 | IGD_BROADWELL_U_GT3_15W, |
| 621 | IGD_BROADWELL_U_GT3_28W, |
| 622 | IGD_BROADWELL_Y_GT2, |
| 623 | IGD_BROADWELL_H_GT2, |
| 624 | IGD_BROADWELL_H_GT3, |
| 625 | 0, |
| 626 | }; |
| 627 | |
| 628 | static const struct pci_driver igd_driver __pci_driver = { |
| 629 | .ops = &igd_ops, |
| 630 | .vendor = PCI_VENDOR_ID_INTEL, |
| 631 | .devices = pci_device_ids, |
| 632 | }; |