Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 4 | * Copyright 2012 Google Inc. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 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. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
| 17 | #include <console/console.h> |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 18 | #include <bootmode.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 19 | #include <delay.h> |
| 20 | #include <device/device.h> |
| 21 | #include <device/pci.h> |
| 22 | #include <device/pci_ids.h> |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 23 | #include <drivers/intel/gma/i915_reg.h> |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 24 | #include <drivers/intel/gma/i915.h> |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 25 | #include <cpu/intel/haswell/haswell.h> |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 26 | #include <stdlib.h> |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 27 | #include <string.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 28 | |
| 29 | #include "chip.h" |
| 30 | #include "haswell.h" |
| 31 | |
Furquan Shaikh | cb61ea7 | 2013-08-15 15:23:58 -0700 | [diff] [blame] | 32 | #if CONFIG_CHROMEOS |
| 33 | #include <vendorcode/google/chromeos/chromeos.h> |
| 34 | #endif |
| 35 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 36 | struct gt_reg { |
| 37 | u32 reg; |
| 38 | u32 andmask; |
| 39 | u32 ormask; |
| 40 | }; |
| 41 | |
| 42 | static const struct gt_reg haswell_gt_setup[] = { |
| 43 | /* Enable Counters */ |
| 44 | { 0x0a248, 0x00000000, 0x00000016 }, |
| 45 | { 0x0a000, 0x00000000, 0x00070020 }, |
| 46 | { 0x0a180, 0xff3fffff, 0x15000000 }, |
| 47 | /* Enable DOP Clock Gating */ |
| 48 | { 0x09424, 0x00000000, 0x000003fd }, |
| 49 | /* Enable Unit Level Clock Gating */ |
| 50 | { 0x09400, 0x00000000, 0x00000080 }, |
| 51 | { 0x09404, 0x00000000, 0x40401000 }, |
| 52 | { 0x09408, 0x00000000, 0x00000000 }, |
| 53 | { 0x0940c, 0x00000000, 0x02000001 }, |
| 54 | { 0x0a008, 0x00000000, 0x08000000 }, |
| 55 | /* Wake Rate Limits */ |
| 56 | { 0x0a090, 0xffffffff, 0x00000000 }, |
| 57 | { 0x0a098, 0xffffffff, 0x03e80000 }, |
| 58 | { 0x0a09c, 0xffffffff, 0x00280000 }, |
| 59 | { 0x0a0a8, 0xffffffff, 0x0001e848 }, |
| 60 | { 0x0a0ac, 0xffffffff, 0x00000019 }, |
| 61 | /* Render/Video/Blitter Idle Max Count */ |
| 62 | { 0x02054, 0x00000000, 0x0000000a }, |
| 63 | { 0x12054, 0x00000000, 0x0000000a }, |
| 64 | { 0x22054, 0x00000000, 0x0000000a }, |
| 65 | /* RC Sleep / RCx Thresholds */ |
| 66 | { 0x0a0b0, 0xffffffff, 0x00000000 }, |
| 67 | { 0x0a0b4, 0xffffffff, 0x000003e8 }, |
| 68 | { 0x0a0b8, 0xffffffff, 0x0000c350 }, |
| 69 | /* RP Settings */ |
| 70 | { 0x0a010, 0xffffffff, 0x000f4240 }, |
| 71 | { 0x0a014, 0xffffffff, 0x12060000 }, |
| 72 | { 0x0a02c, 0xffffffff, 0x0000e808 }, |
| 73 | { 0x0a030, 0xffffffff, 0x0003bd08 }, |
| 74 | { 0x0a068, 0xffffffff, 0x000101d0 }, |
| 75 | { 0x0a06c, 0xffffffff, 0x00055730 }, |
| 76 | { 0x0a070, 0xffffffff, 0x0000000a }, |
| 77 | /* RP Control */ |
| 78 | { 0x0a024, 0x00000000, 0x00000b92 }, |
| 79 | /* HW RC6 Control */ |
| 80 | { 0x0a090, 0x00000000, 0x88040000 }, |
| 81 | /* Video Frequency Request */ |
| 82 | { 0x0a00c, 0x00000000, 0x08000000 }, |
| 83 | { 0 }, |
| 84 | }; |
| 85 | |
| 86 | static const struct gt_reg haswell_gt_lock[] = { |
| 87 | { 0x0a248, 0xffffffff, 0x80000000 }, |
| 88 | { 0x0a004, 0xffffffff, 0x00000010 }, |
| 89 | { 0x0a080, 0xffffffff, 0x00000004 }, |
| 90 | { 0x0a180, 0xffffffff, 0x80000000 }, |
| 91 | { 0 }, |
| 92 | }; |
| 93 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 94 | /* some vga option roms are used for several chipsets but they only have one |
| 95 | * PCI ID in their header. If we encounter such an option rom, we need to do |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 96 | * the mapping ourselves |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 97 | */ |
| 98 | |
| 99 | u32 map_oprom_vendev(u32 vendev) |
| 100 | { |
Elyes HAOUAS | 69d658f | 2016-09-17 20:32:07 +0200 | [diff] [blame] | 101 | u32 new_vendev = vendev; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 102 | |
| 103 | switch (vendev) { |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 104 | case 0x80860402: /* GT1 Desktop */ |
| 105 | case 0x80860406: /* GT1 Mobile */ |
| 106 | case 0x8086040a: /* GT1 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 107 | case 0x80860a06: /* GT1 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 108 | |
| 109 | case 0x80860412: /* GT2 Desktop */ |
| 110 | case 0x80860416: /* GT2 Mobile */ |
| 111 | case 0x8086041a: /* GT2 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 112 | case 0x80860a16: /* GT2 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 113 | |
| 114 | case 0x80860422: /* GT3 Desktop */ |
| 115 | case 0x80860426: /* GT3 Mobile */ |
| 116 | case 0x8086042a: /* GT3 Server */ |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 117 | case 0x80860a26: /* GT3 ULT */ |
Aaron Durbin | 7116129 | 2012-12-13 16:43:32 -0600 | [diff] [blame] | 118 | |
Elyes HAOUAS | 69d658f | 2016-09-17 20:32:07 +0200 | [diff] [blame] | 119 | new_vendev = 0x80860406; /* GT1 Mobile */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 120 | break; |
| 121 | } |
| 122 | |
| 123 | return new_vendev; |
| 124 | } |
| 125 | |
Ronald G. Minnich | 4c8465c | 2013-09-30 15:57:21 -0700 | [diff] [blame] | 126 | /* GTT is the Global Translation Table for the graphics pipeline. |
| 127 | * It is used to translate graphics addresses to physical |
| 128 | * memory addresses. As in the CPU, GTTs map 4K pages. |
| 129 | * The setgtt function adds a further bit of flexibility: |
| 130 | * it allows you to set a range (the first two parameters) to point |
| 131 | * to a physical address (third parameter);the physical address is |
| 132 | * incremented by a count (fourth parameter) for each GTT in the |
| 133 | * range. |
| 134 | * Why do it this way? For ultrafast startup, |
| 135 | * we can point all the GTT entries to point to one page, |
| 136 | * and set that page to 0s: |
| 137 | * memset(physbase, 0, 4096); |
| 138 | * setgtt(0, 4250, physbase, 0); |
| 139 | * this takes about 2 ms, and is a win because zeroing |
| 140 | * the page takes a up to 200 ms. |
| 141 | * This call sets the GTT to point to a linear range of pages |
| 142 | * starting at physbase. |
| 143 | */ |
| 144 | |
| 145 | #define GTT_PTE_BASE (2 << 20) |
| 146 | |
| 147 | void |
| 148 | set_translation_table(int start, int end, u64 base, int inc) |
| 149 | { |
| 150 | int i; |
| 151 | |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 152 | for (i = start; i < end; i++){ |
Ronald G. Minnich | 4c8465c | 2013-09-30 15:57:21 -0700 | [diff] [blame] | 153 | u64 physical_address = base + i*inc; |
| 154 | /* swizzle the 32:39 bits to 4:11 */ |
| 155 | u32 word = physical_address | ((physical_address >> 28) & 0xff0) | 1; |
| 156 | /* note: we've confirmed by checking |
| 157 | * the values that mrc does no |
| 158 | * useful setup before we run this. |
| 159 | */ |
| 160 | gtt_write(GTT_PTE_BASE + i * 4, word); |
| 161 | gtt_read(GTT_PTE_BASE + i * 4); |
| 162 | } |
| 163 | } |
| 164 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 165 | static struct resource *gtt_res = NULL; |
| 166 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 167 | u32 gtt_read(u32 reg) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 168 | { |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 169 | u32 val; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 170 | val = read32(res2mmio(gtt_res, reg, 0)); |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 171 | return val; |
| 172 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 175 | void gtt_write(u32 reg, u32 data) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 176 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 177 | write32(res2mmio(gtt_res, reg, 0), data); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 178 | } |
| 179 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 180 | static inline void gtt_rmw(u32 reg, u32 andmask, u32 ormask) |
| 181 | { |
| 182 | u32 val = gtt_read(reg); |
| 183 | val &= andmask; |
| 184 | val |= ormask; |
| 185 | gtt_write(reg, val); |
| 186 | } |
| 187 | |
| 188 | static inline void gtt_write_regs(const struct gt_reg *gt) |
| 189 | { |
| 190 | for (; gt && gt->reg; gt++) { |
| 191 | if (gt->andmask) |
| 192 | gtt_rmw(gt->reg, gt->andmask, gt->ormask); |
| 193 | else |
| 194 | gtt_write(gt->reg, gt->ormask); |
| 195 | } |
| 196 | } |
| 197 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 198 | #define GTT_RETRY 1000 |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 199 | int gtt_poll(u32 reg, u32 mask, u32 value) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 200 | { |
| 201 | unsigned try = GTT_RETRY; |
| 202 | u32 data; |
| 203 | |
| 204 | while (try--) { |
| 205 | data = gtt_read(reg); |
| 206 | if ((data & mask) == value) |
| 207 | return 1; |
| 208 | udelay(10); |
| 209 | } |
| 210 | |
| 211 | printk(BIOS_ERR, "GT init timeout\n"); |
| 212 | return 0; |
| 213 | } |
| 214 | |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 215 | static void power_well_enable(void) |
| 216 | { |
| 217 | gtt_write(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_ENABLE); |
| 218 | gtt_poll(HSW_PWR_WELL_CTL1, HSW_PWR_WELL_STATE, HSW_PWR_WELL_STATE); |
Matt DeVillier | 6955b9c | 2017-04-16 01:42:44 -0500 | [diff] [blame] | 219 | |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 220 | /* In the native graphics case, we've got about 20 ms. |
| 221 | * after we power up the the AUX channel until we can talk to it. |
| 222 | * So get that going right now. We can't turn on the panel, yet, just VDD. |
| 223 | */ |
Matt DeVillier | 6955b9c | 2017-04-16 01:42:44 -0500 | [diff] [blame] | 224 | if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) { |
| 225 | gtt_write(PCH_PP_CONTROL, PCH_PP_UNLOCK| EDP_FORCE_VDD | PANEL_POWER_RESET); |
| 226 | } |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 229 | static void gma_pm_init_pre_vbios(struct device *dev) |
| 230 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 231 | printk(BIOS_DEBUG, "GT Power Management Init\n"); |
| 232 | |
| 233 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 234 | if (!gtt_res || !gtt_res->base) |
| 235 | return; |
| 236 | |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 237 | power_well_enable(); |
| 238 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 239 | /* |
| 240 | * Enable RC6 |
| 241 | */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 242 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 243 | /* Enable Force Wake */ |
| 244 | gtt_write(0x0a180, 1 << 5); |
| 245 | gtt_write(0x0a188, 0x00010001); |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 246 | gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 1 << 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 247 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 248 | /* GT Settings */ |
| 249 | gtt_write_regs(haswell_gt_setup); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 250 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 251 | /* Wait for Mailbox Ready */ |
| 252 | gtt_poll(0x138124, (1 << 31), (0 << 31)); |
| 253 | /* Mailbox Data - RC6 VIDS */ |
| 254 | gtt_write(0x138128, 0x00000000); |
| 255 | /* Mailbox Command */ |
| 256 | gtt_write(0x138124, 0x80000004); |
| 257 | /* Wait for Mailbox Ready */ |
| 258 | gtt_poll(0x138124, (1 << 31), (0 << 31)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 259 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 260 | /* Enable PM Interrupts */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 261 | gtt_write(GEN6_PMIER, GEN6_PM_MBOX_EVENT | GEN6_PM_THERMAL_EVENT | |
| 262 | GEN6_PM_RP_DOWN_TIMEOUT | GEN6_PM_RP_UP_THRESHOLD | |
| 263 | GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_UP_EI_EXPIRED | |
| 264 | GEN6_PM_RP_DOWN_EI_EXPIRED); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 265 | |
Duncan Laurie | 67113e9 | 2013-01-10 13:23:04 -0800 | [diff] [blame] | 266 | /* Enable RC6 in idle */ |
| 267 | gtt_write(0x0a094, 0x00040000); |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 268 | |
| 269 | /* PM Lock Settings */ |
| 270 | gtt_write_regs(haswell_gt_lock); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 271 | } |
| 272 | |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 273 | static void init_display_planes(void) |
| 274 | { |
| 275 | int pipe, plane; |
| 276 | |
| 277 | /* Disable cursor mode */ |
| 278 | for (pipe = PIPE_A; pipe <= PIPE_C; pipe++) { |
| 279 | gtt_write(CURCNTR_IVB(pipe), CURSOR_MODE_DISABLE); |
| 280 | gtt_write(CURBASE_IVB(pipe), 0x00000000); |
| 281 | } |
| 282 | |
| 283 | /* Disable primary plane and set surface base address*/ |
| 284 | for (plane = PLANE_A; plane <= PLANE_C; plane++) { |
| 285 | gtt_write(DSPCNTR(plane), DISPLAY_PLANE_DISABLE); |
| 286 | gtt_write(DSPSURF(plane), 0x00000000); |
| 287 | } |
| 288 | |
| 289 | /* Disable VGA display */ |
| 290 | gtt_write(CPU_VGACNTRL, CPU_VGA_DISABLE); |
| 291 | } |
| 292 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 293 | static void gma_setup_panel(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 294 | { |
| 295 | struct northbridge_intel_haswell_config *conf = dev->chip_info; |
| 296 | u32 reg32; |
| 297 | |
| 298 | printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n"); |
| 299 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 300 | /* Setup Digital Port Hotplug */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 301 | reg32 = gtt_read(PCH_PORT_HOTPLUG); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 302 | if (!reg32) { |
| 303 | reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 304 | reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 305 | reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 306 | gtt_write(PCH_PORT_HOTPLUG, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /* Setup Panel Power On Delays */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 310 | reg32 = gtt_read(PCH_PP_ON_DELAYS); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 311 | if (!reg32) { |
| 312 | reg32 = (conf->gpu_panel_port_select & 0x3) << 30; |
| 313 | reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 314 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 315 | gtt_write(PCH_PP_ON_DELAYS, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /* Setup Panel Power Off Delays */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 319 | reg32 = gtt_read(PCH_PP_OFF_DELAYS); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 320 | if (!reg32) { |
| 321 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 322 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 323 | gtt_write(PCH_PP_OFF_DELAYS, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* Setup Panel Power Cycle Delay */ |
| 327 | if (conf->gpu_panel_power_cycle_delay) { |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 328 | reg32 = gtt_read(PCH_PP_DIVISOR); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 329 | reg32 &= ~0xff; |
| 330 | reg32 |= conf->gpu_panel_power_cycle_delay & 0xff; |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 331 | gtt_write(PCH_PP_DIVISOR, reg32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* Enable Backlight if needed */ |
| 335 | if (conf->gpu_cpu_backlight) { |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 336 | gtt_write(BLC_PWM_CPU_CTL2, BLC_PWM2_ENABLE); |
| 337 | gtt_write(BLC_PWM_CPU_CTL, conf->gpu_cpu_backlight); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 338 | } |
| 339 | if (conf->gpu_pch_backlight) { |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 340 | gtt_write(BLC_PWM_PCH_CTL1, BLM_PCH_PWM_ENABLE); |
| 341 | gtt_write(BLC_PWM_PCH_CTL2, conf->gpu_pch_backlight); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 342 | } |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 343 | |
| 344 | /* Get display,pipeline,and DDI registers into a basic sane state */ |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 345 | power_well_enable(); |
| 346 | |
| 347 | init_display_planes(); |
| 348 | |
| 349 | /* DDI-A params set: |
| 350 | bit 0: Display detected (RO) |
| 351 | bit 4: DDI A supports 4 lanes and DDI E is not used |
| 352 | bit 7: DDI buffer is idle |
| 353 | */ |
| 354 | gtt_write(DDI_BUF_CTL_A, DDI_BUF_IS_IDLE | DDI_A_4_LANES | DDI_INIT_DISPLAY_DETECTED); |
| 355 | |
| 356 | /* Set FDI registers - is this required? */ |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 357 | gtt_write(_FDI_RXA_MISC, 0x00200090); |
| 358 | gtt_write(_FDI_RXA_MISC, 0x0a000000); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 359 | |
| 360 | /* Enable the handshake with PCH display when processing reset */ |
| 361 | gtt_write(NDE_RSTWRN_OPT, RST_PCH_HNDSHK_EN); |
| 362 | |
| 363 | /* undocumented */ |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 364 | gtt_write(0x42090, 0x04000000); |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 365 | gtt_write(0x9840, 0x00000000); |
| 366 | gtt_write(0x42090, 0xa4000000); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 367 | |
| 368 | gtt_write(SOUTH_DSPCLK_GATE_D, PCH_LP_PARTITION_LEVEL_DISABLE); |
| 369 | |
| 370 | /* undocumented */ |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 371 | gtt_write(0x42080, 0x00004000); |
Furquan Shaikh | 77f48cd | 2013-08-19 10:16:50 -0700 | [diff] [blame] | 372 | |
| 373 | /* Prepare DDI buffers for DP and FDI */ |
| 374 | intel_prepare_ddi(); |
| 375 | |
| 376 | /* Hot plug detect buffer enabled for port A */ |
| 377 | gtt_write(DIGITAL_PORT_HOTPLUG_CNTRL, DIGITAL_PORTA_HOTPLUG_ENABLE); |
| 378 | |
| 379 | /* Enable HPD buffer for digital port D and B */ |
| 380 | gtt_write(PCH_PORT_HOTPLUG, PORTD_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE); |
| 381 | |
| 382 | /* Bits 4:0 - Power cycle delay (default 0x6 --> 500ms) |
| 383 | Bits 31:8 - Reference divider (0x0004af ----> 24MHz) |
| 384 | */ |
Ronald G. Minnich | 5bcca7e | 2013-06-25 15:56:46 -0700 | [diff] [blame] | 385 | gtt_write(PCH_PP_DIVISOR, 0x0004af06); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 386 | } |
| 387 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 388 | static void gma_pm_init_post_vbios(struct device *dev) |
| 389 | { |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 390 | int cdclk = 0; |
| 391 | int devid = pci_read_config16(dev, PCI_DEVICE_ID); |
| 392 | int gpu_is_ulx = 0; |
| 393 | |
| 394 | if (devid == 0x0a0e || devid == 0x0a1e) |
| 395 | gpu_is_ulx = 1; |
| 396 | |
| 397 | /* CD Frequency */ |
Duncan Laurie | 3106d0f | 2013-08-12 13:51:22 -0700 | [diff] [blame] | 398 | if ((gtt_read(0x42014) & 0x1000000) || gpu_is_ulx || haswell_is_ult()) |
| 399 | cdclk = 0; /* fixed frequency */ |
| 400 | else |
| 401 | cdclk = 2; /* variable frequency */ |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 402 | |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 403 | if (gpu_is_ulx || cdclk != 0) |
| 404 | gtt_rmw(0x130040, 0xf7ffffff, 0x04000000); |
| 405 | else |
| 406 | gtt_rmw(0x130040, 0xf3ffffff, 0x00000000); |
| 407 | |
| 408 | /* More magic */ |
| 409 | if (haswell_is_ult() || gpu_is_ulx) { |
Duncan Laurie | 3106d0f | 2013-08-12 13:51:22 -0700 | [diff] [blame] | 410 | if (!gpu_is_ulx) |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 411 | gtt_write(0x138128, 0x00000000); |
| 412 | else |
| 413 | gtt_write(0x138128, 0x00000001); |
| 414 | gtt_write(0x13812c, 0x00000000); |
| 415 | gtt_write(0x138124, 0x80000017); |
| 416 | } |
| 417 | |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 418 | /* Disable Force Wake */ |
| 419 | gtt_write(0x0a188, 0x00010000); |
Edward O'Callaghan | 986e85c | 2014-10-29 12:15:34 +1100 | [diff] [blame] | 420 | gtt_poll(FORCEWAKE_ACK_HSW, 1 << 0, 0 << 0); |
Duncan Laurie | 356833d | 2013-07-09 15:40:27 -0700 | [diff] [blame] | 421 | gtt_write(0x0a188, 0x00000001); |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 424 | static void gma_func0_init(struct device *dev) |
| 425 | { |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 426 | int lightup_ok = 0; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 427 | u32 reg32; |
Matt DeVillier | 6955b9c | 2017-04-16 01:42:44 -0500 | [diff] [blame] | 428 | u64 physbase; |
| 429 | const struct resource *const linearfb_res = |
| 430 | find_resource(dev, PCI_BASE_ADDRESS_2); |
| 431 | |
| 432 | if (!linearfb_res || !linearfb_res->base) |
Nico Huber | 0df9a01 | 2017-05-20 02:26:12 +0200 | [diff] [blame] | 433 | return; |
Matt DeVillier | 6955b9c | 2017-04-16 01:42:44 -0500 | [diff] [blame] | 434 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 435 | /* IGD needs to be Bus Master */ |
| 436 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 437 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 438 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 439 | |
| 440 | /* Init graphics power management */ |
| 441 | gma_pm_init_pre_vbios(dev); |
| 442 | |
Matt DeVillier | 6955b9c | 2017-04-16 01:42:44 -0500 | [diff] [blame] | 443 | /* Pre panel init */ |
Duncan Laurie | c7f2ab7 | 2013-05-28 07:49:09 -0700 | [diff] [blame] | 444 | gma_setup_panel(dev); |
| 445 | |
Matt DeVillier | 6955b9c | 2017-04-16 01:42:44 -0500 | [diff] [blame] | 446 | if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) { |
| 447 | printk(BIOS_SPEW, "NATIVE graphics, run native enable\n"); |
| 448 | physbase = pci_read_config32(dev, 0x5c) & ~0xf; |
| 449 | gma_gfxinit(gtt_res->base, linearfb_res->base, |
| 450 | physbase, &lightup_ok); |
| 451 | gfx_set_init_done(1); |
Arthur Heymans | 23cda347 | 2016-12-18 16:03:52 +0100 | [diff] [blame] | 452 | } |
| 453 | |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 454 | if (! lightup_ok) { |
| 455 | printk(BIOS_SPEW, "FUI did not run; using VBIOS\n"); |
Stefan Reinauer | f1aabec | 2014-01-22 15:16:30 -0800 | [diff] [blame] | 456 | mdelay(CONFIG_PRE_GRAPHICS_DELAY); |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 457 | pci_dev_init(dev); |
| 458 | } |
| 459 | |
Matt DeVillier | 6955b9c | 2017-04-16 01:42:44 -0500 | [diff] [blame] | 460 | /* Post panel init */ |
Ronald G. Minnich | 4f78b18 | 2013-04-17 16:57:30 -0700 | [diff] [blame] | 461 | gma_pm_init_post_vbios(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 465 | { |
| 466 | if (!vendor || !device) { |
| 467 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 468 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 469 | } else { |
| 470 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 471 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 472 | } |
| 473 | } |
| 474 | |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 475 | const struct i915_gpu_controller_info * |
| 476 | intel_gma_get_controller_info(void) |
| 477 | { |
| 478 | device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0)); |
| 479 | if (!dev) { |
| 480 | return NULL; |
| 481 | } |
| 482 | struct northbridge_intel_haswell_config *chip = dev->chip_info; |
| 483 | return &chip->gfx; |
| 484 | } |
| 485 | |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame] | 486 | static void gma_ssdt(device_t device) |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 487 | { |
| 488 | const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info(); |
| 489 | if (!gfx) { |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | drivers_intel_gma_displays_ssdt_generate(gfx); |
| 494 | } |
| 495 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 496 | static struct pci_operations gma_pci_ops = { |
| 497 | .set_subsystem = gma_set_subsystem, |
| 498 | }; |
| 499 | |
| 500 | static struct device_operations gma_func0_ops = { |
Vladimir Serbinenko | 30fe612 | 2014-02-05 23:25:28 +0100 | [diff] [blame] | 501 | .read_resources = pci_dev_read_resources, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 502 | .set_resources = pci_dev_set_resources, |
| 503 | .enable_resources = pci_dev_enable_resources, |
| 504 | .init = gma_func0_init, |
Vladimir Serbinenko | dd2bc3f | 2014-10-31 09:16:31 +0100 | [diff] [blame] | 505 | .acpi_fill_ssdt_generator = gma_ssdt, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 506 | .scan_bus = 0, |
| 507 | .enable = 0, |
| 508 | .ops_pci = &gma_pci_ops, |
| 509 | }; |
| 510 | |
Duncan Laurie | df7be71 | 2012-12-17 11:22:57 -0800 | [diff] [blame] | 511 | static const unsigned short pci_device_ids[] = { |
| 512 | 0x0402, /* Desktop GT1 */ |
| 513 | 0x0412, /* Desktop GT2 */ |
| 514 | 0x0422, /* Desktop GT3 */ |
| 515 | 0x0406, /* Mobile GT1 */ |
| 516 | 0x0416, /* Mobile GT2 */ |
| 517 | 0x0426, /* Mobile GT3 */ |
| 518 | 0x0d16, /* Mobile 4+3 GT1 */ |
| 519 | 0x0d26, /* Mobile 4+3 GT2 */ |
| 520 | 0x0d36, /* Mobile 4+3 GT3 */ |
| 521 | 0x0a06, /* ULT GT1 */ |
| 522 | 0x0a16, /* ULT GT2 */ |
| 523 | 0x0a26, /* ULT GT3 */ |
| 524 | 0, |
| 525 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 526 | |
| 527 | static const struct pci_driver pch_lpc __pci_driver = { |
| 528 | .ops = &gma_func0_ops, |
| 529 | .vendor = PCI_VENDOR_ID_INTEL, |
| 530 | .devices = pci_device_ids, |
| 531 | }; |