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