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