| 1 |
|
| 2 |
|
| 3 |
#include <commonlib/helpers.h> |
| 4 |
#include <arch/io.h> |
| 5 |
#include <device/mmio.h> |
| 6 |
#include <device/pci_ops.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <bootmode.h> |
| 9 |
#include <delay.h> |
| 10 |
#include <device/device.h> |
| 11 |
#include <device/pci.h> |
| 12 |
#include <device/pci_ids.h> |
| 13 |
#include <drivers/intel/gma/i915_reg.h> |
| 14 |
#include <drivers/intel/gma/i915.h> |
| 15 |
#include <drivers/intel/gma/libgfxinit.h> |
| 16 |
#include <cpu/intel/haswell/haswell.h> |
| 17 |
#include <drivers/intel/gma/opregion.h> |
| 18 |
#include <southbridge/intel/lynxpoint/pch.h> |
| 19 |
#include <types.h> |
| 20 |
|
| 21 |
#include "chip.h" |
| 22 |
#include "haswell.h" |
| 23 |
|
| 24 |
struct gt_reg { |
| 25 |
u32 reg; |
| 26 |
u32 andmask; |
| 27 |
u32 ormask; |
| 28 |
}; |
| 29 |
|
| 30 |
static const struct gt_reg haswell_gt_setup[] = { |
| 31 |
|
| 32 |
{ 0x0a248, 0x00000000, 0x00000016 }, |
| 33 |
{ 0x0a000, 0x00000000, 0x00070020 }, |
| 34 |
{ 0x0a180, 0xff3fffff, 0x15000000 }, |
| 35 |
|
| 36 |
{ 0x09424, 0x00000000, 0x000003fd }, |
| 37 |
|
| 38 |
{ 0x09400, 0x00000000, 0x00000080 }, |
| 39 |
{ 0x09404, 0x00000000, 0x40401000 }, |
| 40 |
{ 0x09408, 0x00000000, 0x00000000 }, |
| 41 |
{ 0x0940c, 0x00000000, 0x02000001 }, |
| 42 |
{ 0x0a008, 0x00000000, 0x08000000 }, |
| 43 |
|
| 44 |
{ 0x0a090, 0xffffffff, 0x00000000 }, |
| 45 |
{ 0x0a098, 0xffffffff, 0x03e80000 }, |
| 46 |
{ 0x0a09c, 0xffffffff, 0x00280000 }, |
| 47 |
{ 0x0a0a8, 0xffffffff, 0x0001e848 }, |
| 48 |
{ 0x0a0ac, 0xffffffff, 0x00000019 }, |
| 49 |
|
| 50 |
{ 0x02054, 0x00000000, 0x0000000a }, |
| 51 |
{ 0x12054, 0x00000000, 0x0000000a }, |
| 52 |
{ 0x22054, 0x00000000, 0x0000000a }, |
| 53 |
|
| 54 |
{ 0x0a0b0, 0xffffffff, 0x00000000 }, |
| 55 |
{ 0x0a0b4, 0xffffffff, 0x000003e8 }, |
| 56 |
{ 0x0a0b8, 0xffffffff, 0x0000c350 }, |
| 57 |
|
| 58 |
{ 0x0a010, 0xffffffff, 0x000f4240 }, |
| 59 |
{ 0x0a014, 0xffffffff, 0x12060000 }, |
| 60 |
{ 0x0a02c, 0xffffffff, 0x0000e808 }, |
| 61 |
{ 0x0a030, 0xffffffff, 0x0003bd08 }, |
| 62 |
{ 0x0a068, 0xffffffff, 0x000101d0 }, |
| 63 |
{ 0x0a06c, 0xffffffff, 0x00055730 }, |
| 64 |
{ 0x0a070, 0xffffffff, 0x0000000a }, |
| 65 |
|
| 66 |
{ 0x0a024, 0x00000000, 0x00000b92 }, |
| 67 |
|
| 68 |
{ 0x0a090, 0x00000000, 0x88040000 }, |
| 69 |
|
| 70 |
{ 0x0a00c, 0x00000000, 0x08000000 }, |
| 71 |
{ 0 }, |
| 72 |
}; |
| 73 |
|
| 74 |
static const struct gt_reg haswell_gt_lock[] = { |
| 75 |
{ 0x0a248, 0xffffffff, 0x80000000 }, |
| 76 |
{ 0x0a004, 0xffffffff, 0x00000010 }, |
| 77 |
{ 0x0a080, 0xffffffff, 0x00000004 }, |
| 78 |
{ 0x0a180, 0xffffffff, 0x80000000 }, |
| 79 |
{ 0 }, |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
u32 map_oprom_vendev(u32 vendev) |
| 88 |
{ |
| 89 |
u32 new_vendev = vendev; |
| 90 |
|
| 91 |
switch (vendev) { |
| 92 |
case 0x80860402: |
| 93 |
case 0x80860406: |
| 94 |
case 0x8086040a: |
| 95 |
case 0x80860a06: |
| 96 |
case 0x80860a0e: |
| 97 |
|
| 98 |
case 0x80860412: |
| 99 |
case 0x80860416: |
| 100 |
case 0x8086041a: |
| 101 |
case 0x8086041e: |
| 102 |
case 0x80860a16: |
| 103 |
case 0x80860a1e: |
| 104 |
|
| 105 |
case 0x80860422: |
| 106 |
case 0x80860426: |
| 107 |
case 0x8086042a: |
| 108 |
case 0x80860a26: |
| 109 |
|
| 110 |
case 0x80860d22: |
| 111 |
case 0x80860d16: |
| 112 |
case 0x80860d26: |
| 113 |
case 0x80860d36: |
| 114 |
|
| 115 |
new_vendev = 0x80860406; |
| 116 |
break; |
| 117 |
} |
| 118 |
|
| 119 |
return new_vendev; |
| 120 |
} |
| 121 |
|
| 122 |
static struct resource *gtt_res = NULL; |
| 123 |
|
| 124 |
u32 gtt_read(u32 reg) |
| 125 |
{ |
| 126 |
u32 val; |
| 127 |
val = read32(res2mmio(gtt_res, reg, 0)); |
| 128 |
return val; |
| 129 |
} |
| 130 |
|
| 131 |
void gtt_write(u32 reg, u32 data) |
| 132 |
{ |
| 133 |
write32(res2mmio(gtt_res, reg, 0), data); |
| 134 |
} |
| 135 |
|
| 136 |
static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask) |
| 137 |
{ |
| 138 |
u32 val = gtt_read(reg); |
| 139 |
val &= andmask; |
| 140 |
val |= ormask; |
| 141 |
gtt_write(reg, val); |
| 142 |
} |
| 143 |
|
| 144 |
static inline void gtt_write_regs(const struct gt_reg *gt) |
| 145 |
{ |
| 146 |
for (; gt && gt->reg; gt++) { |
| 147 |
if (gt->andmask) |
| 148 |
gtt_rmw(gt->reg, gt->andmask, gt->ormask); |
| 149 |
else |
| 150 |
gtt_write(gt->reg, gt->ormask); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
#define GTT_RETRY 1000 |
| 155 |
int gtt_poll(u32 reg, u32 mask, u32 value) |
| 156 |
{ |
| 157 |
unsigned int try = GTT_RETRY; |
| 158 |
u32 data; |
| 159 |
|
| 160 |
while (try--) { |
| 161 |
data = gtt_read(reg); |
| 162 |
if ((data & mask) == value) |
| 163 |
return 1; |
| 164 |
|
| 165 |
udelay(10); |
| 166 |
} |
| 167 |
|
| 168 |
printk(BIOS_ERR, "GT init timeout\n"); |
| 169 |
return 0; |
| 170 |
} |
| 171 |
|
| 172 |
static void power_well_enable(void) |
| 173 |
{ |
| 174 |
gtt_write(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_ENABLE); |
| 175 |
gtt_poll(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_STATE, HSW_PWR_WELL_STATE); |
| 176 |
} |
| 177 |
|
| 178 |
static void gma_pm_init_pre_vbios(struct device *dev) |
| 179 |
{ |
| 180 |
printk(BIOS_DEBUG, "GT Power Management Init\n"); |
| 181 |
|
| 182 |
gtt_res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
| 183 |
if (!gtt_res || !gtt_res->base) |
| 184 |
return; |
| 185 |
|
| 186 |
power_well_enable(); |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
gtt_write(0x0a180, 1 << 5); |
| 194 |
gtt_write(0x0a188, 0x00010001); |
| 195 |
gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 1 << 0); |
| 196 |
|
| 197 |
|
| 198 |
gtt_write_regs(haswell_gt_setup); |
| 199 |
|
| 200 |
|
| 201 |
gtt_poll(0x138124, (1 << 31), (0 << 31)); |
| 202 |
|
| 203 |
|
| 204 |
gtt_write(0x138128, 0x00000000); |
| 205 |
|
| 206 |
|
| 207 |
gtt_write(0x138124, 0x80000004); |
| 208 |
|
| 209 |
|
| 210 |
gtt_poll(0x138124, (1 << 31), (0 << 31)); |
| 211 |
|
| 212 |
|
| 213 |
gtt_write(GEN6_PMIER, GEN6_PM_MBOX_EVENT | GEN6_PM_THERMAL_EVENT | |
| 214 |
GEN6_PM_RP_DOWN_TIMEOUT | GEN6_PM_RP_UP_THRESHOLD | |
| 215 |
GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_UP_EI_EXPIRED | |
| 216 |
GEN6_PM_RP_DOWN_EI_EXPIRED); |
| 217 |
|
| 218 |
|
| 219 |
gtt_write(0x0a094, 0x00040000); |
| 220 |
|
| 221 |
|
| 222 |
gtt_write_regs(haswell_gt_lock); |
| 223 |
} |
| 224 |
|
| 225 |
static void init_display_planes(void) |
| 226 |
{ |
| 227 |
int pipe, plane; |
| 228 |
|
| 229 |
|
| 230 |
for (pipe = PIPE_A; pipe <= PIPE_C; pipe++) { |
| 231 |
gtt_write(CURCNTR_IVB(pipe), CURSOR_MODE_DISABLE); |
| 232 |
gtt_write(CURBASE_IVB(pipe), 0x00000000); |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
for (plane = PLANE_A; plane <= PLANE_C; plane++) { |
| 237 |
gtt_write(DSPCNTR(plane), DISPLAY_PLANE_DISABLE); |
| 238 |
gtt_write(DSPSURF(plane), 0x00000000); |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
gtt_write(CPU_VGACNTRL, CPU_VGA_DISABLE); |
| 243 |
} |
| 244 |
|
| 245 |
static void gma_setup_panel(struct device *dev) |
| 246 |
{ |
| 247 |
struct northbridge_intel_haswell_config *conf = config_of(dev); |
| 248 |
const struct i915_gpu_panel_config *panel_cfg = &conf->panel_cfg; |
| 249 |
u32 reg32; |
| 250 |
|
| 251 |
|
| 252 |
reg32 = gtt_read(PCH_PORT_HOTPLUG); |
| 253 |
if (!reg32) { |
| 254 |
reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 255 |
reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 256 |
reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
| 257 |
gtt_write(PCH_PORT_HOTPLUG, reg32); |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
reg32 = gtt_read(PCH_PP_ON_DELAYS); |
| 262 |
if (!reg32) { |
| 263 |
reg32 |= ((panel_cfg->up_delay_ms * 10) & 0x1fff) << 16; |
| 264 |
reg32 |= (panel_cfg->backlight_on_delay_ms * 10) & 0x1fff; |
| 265 |
gtt_write(PCH_PP_ON_DELAYS, reg32); |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
reg32 = gtt_read(PCH_PP_OFF_DELAYS); |
| 270 |
if (!reg32) { |
| 271 |
reg32 = ((panel_cfg->down_delay_ms * 10) & 0x1fff) << 16; |
| 272 |
reg32 |= (panel_cfg->backlight_off_delay_ms * 10) & 0x1fff; |
| 273 |
gtt_write(PCH_PP_OFF_DELAYS, reg32); |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
if (panel_cfg->cycle_delay_ms) { |
| 278 |
reg32 = gtt_read(PCH_PP_DIVISOR); |
| 279 |
reg32 &= ~0x1f; |
| 280 |
reg32 |= (DIV_ROUND_UP(panel_cfg->cycle_delay_ms, 100) + 1) & 0x1f; |
| 281 |
gtt_write(PCH_PP_DIVISOR, reg32); |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
if (panel_cfg->backlight_pwm_hz) { |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
const unsigned int refclock = CONFIG(INTEL_LYNXPOINT_LP) ? 24*MHz : 135*MHz; |
| 291 |
const unsigned int hz_limit = refclock / 128 / 100; |
| 292 |
unsigned int pwm_increment, pwm_period; |
| 293 |
u32 south_chicken2; |
| 294 |
|
| 295 |
south_chicken2 = gtt_read(SOUTH_CHICKEN2); |
| 296 |
if (panel_cfg->backlight_pwm_hz > hz_limit) { |
| 297 |
pwm_increment = 16; |
| 298 |
south_chicken2 |= LPT_PWM_GRANULARITY; |
| 299 |
} else { |
| 300 |
pwm_increment = 128; |
| 301 |
south_chicken2 &= ~LPT_PWM_GRANULARITY; |
| 302 |
} |
| 303 |
gtt_write(SOUTH_CHICKEN2, south_chicken2); |
| 304 |
|
| 305 |
pwm_period = refclock / pwm_increment / panel_cfg->backlight_pwm_hz; |
| 306 |
printk(BIOS_INFO, |
| 307 |
"GMA: Setting backlight PWM frequency to %uMHz / %u / %u = %uHz\n", |
| 308 |
refclock / MHz, pwm_increment, pwm_period, |
| 309 |
DIV_ROUND_CLOSEST(refclock, pwm_increment * pwm_period)); |
| 310 |
|
| 311 |
|
| 312 |
gtt_write(BLC_PWM_PCH_CTL2, pwm_period << 16 | pwm_period / 2); |
| 313 |
|
| 314 |
gtt_write(BLC_PWM_PCH_CTL1, |
| 315 |
(panel_cfg->backlight_polarity == GPU_BACKLIGHT_POLARITY_LOW) << 29 | |
| 316 |
BLM_PCH_OVERRIDE_ENABLE | BLM_PCH_PWM_ENABLE); |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
power_well_enable(); |
| 321 |
|
| 322 |
init_display_planes(); |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
reg32 = DDI_BUF_IS_IDLE | DDI_INIT_DISPLAY_DETECTED; |
| 331 |
if (!conf->gpu_ddi_e_connected) |
| 332 |
reg32 |= DDI_A_4_LANES; |
| 333 |
gtt_write(DDI_BUF_CTL_A, reg32); |
| 334 |
|
| 335 |
|
| 336 |
gtt_write(_FDI_RXA_MISC, 0x00200090); |
| 337 |
gtt_write(_FDI_RXA_MISC, 0x0a000000); |
| 338 |
|
| 339 |
|
| 340 |
gtt_write(NDE_RSTWRN_OPT, RST_PCH_HNDSHK_EN); |
| 341 |
|
| 342 |
|
| 343 |
gtt_write(0x42090, 0x04000000); |
| 344 |
gtt_write(0x9840, 0x00000000); |
| 345 |
gtt_write(0x42090, 0xa4000000); |
| 346 |
|
| 347 |
gtt_write(SOUTH_DSPCLK_GATE_D, PCH_LP_PARTITION_LEVEL_DISABLE); |
| 348 |
|
| 349 |
|
| 350 |
gtt_write(0x42080, 0x00004000); |
| 351 |
|
| 352 |
|
| 353 |
intel_prepare_ddi(); |
| 354 |
|
| 355 |
|
| 356 |
gtt_write(DIGITAL_PORT_HOTPLUG_CNTRL, DIGITAL_PORTA_HOTPLUG_ENABLE); |
| 357 |
|
| 358 |
|
| 359 |
gtt_write(PCH_PORT_HOTPLUG, PORTD_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE); |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
gtt_write(PCH_PP_DIVISOR, 0x0004af06); |
| 366 |
} |
| 367 |
|
| 368 |
static void gma_pm_init_post_vbios(struct device *dev) |
| 369 |
{ |
| 370 |
int cdclk = 0; |
| 371 |
int devid = pci_read_config16(dev, PCI_DEVICE_ID); |
| 372 |
int gpu_is_ulx = 0; |
| 373 |
|
| 374 |
if (devid == 0x0a0e || devid == 0x0a1e) |
| 375 |
gpu_is_ulx = 1; |
| 376 |
|
| 377 |
|
| 378 |
if ((gtt_read(0x42014) & 0x1000000) || gpu_is_ulx || haswell_is_ult()) |
| 379 |
cdclk = 0; |
| 380 |
else |
| 381 |
cdclk = 2; |
| 382 |
|
| 383 |
if (gpu_is_ulx || cdclk != 0) |
| 384 |
gtt_rmw(0x130040, 0xf7ffffff, 0x04000000); |
| 385 |
else |
| 386 |
gtt_rmw(0x130040, 0xf3ffffff, 0x00000000); |
| 387 |
|
| 388 |
|
| 389 |
if (haswell_is_ult() || gpu_is_ulx) { |
| 390 |
if (!gpu_is_ulx) |
| 391 |
gtt_write(0x138128, 0x00000000); |
| 392 |
else |
| 393 |
gtt_write(0x138128, 0x00000001); |
| 394 |
gtt_write(0x13812c, 0x00000000); |
| 395 |
gtt_write(0x138124, 0x80000017); |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
gtt_write(0x0a188, 0x00010000); |
| 400 |
gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 0 << 0); |
| 401 |
gtt_write(0x0a188, 0x00000001); |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
static void gma_enable_swsci(void) |
| 406 |
{ |
| 407 |
u16 reg16; |
| 408 |
|
| 409 |
|
| 410 |
reg16 = inw(get_pmbase() + TCO1_STS); |
| 411 |
reg16 &= DMISCI_STS; |
| 412 |
outw(reg16, get_pmbase() + TCO1_STS); |
| 413 |
|
| 414 |
|
| 415 |
enable_tco_sci(); |
| 416 |
} |
| 417 |
|
| 418 |
static void gma_func0_init(struct device *dev) |
| 419 |
{ |
| 420 |
int lightup_ok = 0; |
| 421 |
|
| 422 |
intel_gma_init_igd_opregion(); |
| 423 |
|
| 424 |
|
| 425 |
gma_pm_init_pre_vbios(dev); |
| 426 |
|
| 427 |
|
| 428 |
gma_setup_panel(dev); |
| 429 |
|
| 430 |
if (!CONFIG(NO_GFX_INIT)) |
| 431 |
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 432 |
|
| 433 |
int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1; |
| 434 |
|
| 435 |
if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) { |
| 436 |
if (vga_disable) { |
| 437 |
printk(BIOS_INFO, |
| 438 |
"IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n"); |
| 439 |
} else { |
| 440 |
printk(BIOS_SPEW, "NATIVE graphics, run native enable\n"); |
| 441 |
gma_gfxinit(&lightup_ok); |
| 442 |
gfx_set_init_done(1); |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
if (!lightup_ok) { |
| 447 |
printk(BIOS_SPEW, "FUI did not run; using VBIOS\n"); |
| 448 |
pci_dev_init(dev); |
| 449 |
} |
| 450 |
|
| 451 |
printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n"); |
| 452 |
|
| 453 |
gma_pm_init_post_vbios(dev); |
| 454 |
|
| 455 |
gma_enable_swsci(); |
| 456 |
} |
| 457 |
|
| 458 |
static void gma_generate_ssdt(const struct device *dev) |
| 459 |
{ |
| 460 |
const struct northbridge_intel_haswell_config *chip = dev->chip_info; |
| 461 |
|
| 462 |
drivers_intel_gma_displays_ssdt_generate(&chip->gfx); |
| 463 |
} |
| 464 |
|
| 465 |
static void gma_func0_disable(struct device *dev) |
| 466 |
{ |
| 467 |
|
| 468 |
pci_or_config16(pcidev_on_root(0, 0), GGC, 1 << 1); |
| 469 |
} |
| 470 |
|
| 471 |
static struct device_operations gma_func0_ops = { |
| 472 |
.read_resources = pci_dev_read_resources, |
| 473 |
.set_resources = pci_dev_set_resources, |
| 474 |
.enable_resources = pci_dev_enable_resources, |
| 475 |
.init = gma_func0_init, |
| 476 |
.acpi_fill_ssdt = gma_generate_ssdt, |
| 477 |
.vga_disable = gma_func0_disable, |
| 478 |
.ops_pci = &pci_dev_ops_pci, |
| 479 |
}; |
| 480 |
|
| 481 |
static const unsigned short pci_device_ids[] = { |
| 482 |
0x0402, |
| 483 |
0x0412, |
| 484 |
0x041e, |
| 485 |
0x0422, |
| 486 |
0x0d22, |
| 487 |
0x0406, |
| 488 |
0x0416, |
| 489 |
0x0426, |
| 490 |
0x040a, |
| 491 |
0x041a, |
| 492 |
0x042a, |
| 493 |
0x0d16, |
| 494 |
0x0d26, |
| 495 |
0x0d36, |
| 496 |
0x0a06, |
| 497 |
0x0a16, |
| 498 |
0x0a26, |
| 499 |
0x0a0e, |
| 500 |
0x0a1e, |
| 501 |
0, |
| 502 |
}; |
| 503 |
|
| 504 |
static const struct pci_driver pch_lpc __pci_driver = { |
| 505 |
.ops = &gma_func0_ops, |
| 506 |
.vendor = PCI_VID_INTEL, |
| 507 |
.devices = pci_device_ids, |
| 508 |
}; |