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