Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Chromium OS Authors |
| 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 | |
| 20 | #include <arch/io.h> |
| 21 | #include <console/console.h> |
| 22 | #include <delay.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
| 26 | |
| 27 | #include "chip.h" |
| 28 | #include "sandybridge.h" |
| 29 | |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 30 | struct gt_powermeter { |
| 31 | u16 reg; |
| 32 | u32 value; |
| 33 | }; |
| 34 | |
| 35 | struct gt_powermeter snb_pm_gt1[] = { |
| 36 | { 0xa200, 0xcc000000 }, |
| 37 | { 0xa204, 0x07000040 }, |
| 38 | { 0xa208, 0x0000fe00 }, |
| 39 | { 0xa20c, 0x00000000 }, |
| 40 | { 0xa210, 0x17000000 }, |
| 41 | { 0xa214, 0x00000021 }, |
| 42 | { 0xa218, 0x0817fe19 }, |
| 43 | { 0xa21c, 0x00000000 }, |
| 44 | { 0xa220, 0x00000000 }, |
| 45 | { 0xa224, 0xcc000000 }, |
| 46 | { 0xa228, 0x07000040 }, |
| 47 | { 0xa22c, 0x0000fe00 }, |
| 48 | { 0xa230, 0x00000000 }, |
| 49 | { 0xa234, 0x17000000 }, |
| 50 | { 0xa238, 0x00000021 }, |
| 51 | { 0xa23c, 0x0817fe19 }, |
| 52 | { 0xa240, 0x00000000 }, |
| 53 | { 0xa244, 0x00000000 }, |
| 54 | { 0xa248, 0x8000421e }, |
| 55 | { 0 } |
| 56 | }; |
| 57 | |
| 58 | struct gt_powermeter snb_pm_gt2[] = { |
| 59 | { 0xa200, 0x330000a6 }, |
| 60 | { 0xa204, 0x402d0031 }, |
| 61 | { 0xa208, 0x00165f83 }, |
| 62 | { 0xa20c, 0xf1000000 }, |
| 63 | { 0xa210, 0x00000000 }, |
| 64 | { 0xa214, 0x00160016 }, |
| 65 | { 0xa218, 0x002a002b }, |
| 66 | { 0xa21c, 0x00000000 }, |
| 67 | { 0xa220, 0x00000000 }, |
| 68 | { 0xa224, 0x330000a6 }, |
| 69 | { 0xa228, 0x402d0031 }, |
| 70 | { 0xa22c, 0x00165f83 }, |
| 71 | { 0xa230, 0xf1000000 }, |
| 72 | { 0xa234, 0x00000000 }, |
| 73 | { 0xa238, 0x00160016 }, |
| 74 | { 0xa23c, 0x002a002b }, |
| 75 | { 0xa240, 0x00000000 }, |
| 76 | { 0xa244, 0x00000000 }, |
| 77 | { 0xa248, 0x8000421e }, |
| 78 | { 0 } |
| 79 | }; |
| 80 | |
| 81 | struct gt_powermeter ivb_pm_gt1[] = { |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 82 | { 0xa800, 0x00000000 }, |
| 83 | { 0xa804, 0x00021c00 }, |
| 84 | { 0xa808, 0x00000403 }, |
| 85 | { 0xa80c, 0x02001700 }, |
| 86 | { 0xa810, 0x05000200 }, |
| 87 | { 0xa814, 0x00000000 }, |
| 88 | { 0xa818, 0x00690500 }, |
| 89 | { 0xa81c, 0x0000007f }, |
| 90 | { 0xa820, 0x01002501 }, |
| 91 | { 0xa824, 0x00000300 }, |
| 92 | { 0xa828, 0x01000331 }, |
| 93 | { 0xa82c, 0x0000000c }, |
| 94 | { 0xa830, 0x00010016 }, |
| 95 | { 0xa834, 0x01100101 }, |
| 96 | { 0xa838, 0x00010103 }, |
| 97 | { 0xa83c, 0x00041300 }, |
| 98 | { 0xa840, 0x00000b30 }, |
| 99 | { 0xa844, 0x00000000 }, |
| 100 | { 0xa848, 0x7f000000 }, |
| 101 | { 0xa84c, 0x05000008 }, |
| 102 | { 0xa850, 0x00000001 }, |
| 103 | { 0xa854, 0x00000004 }, |
| 104 | { 0xa858, 0x00000007 }, |
| 105 | { 0xa85c, 0x00000000 }, |
| 106 | { 0xa860, 0x00010000 }, |
| 107 | { 0xa248, 0x0000221e }, |
| 108 | { 0xa900, 0x00000000 }, |
| 109 | { 0xa904, 0x00001c00 }, |
| 110 | { 0xa908, 0x00000000 }, |
| 111 | { 0xa90c, 0x06000000 }, |
| 112 | { 0xa910, 0x09000200 }, |
| 113 | { 0xa914, 0x00000000 }, |
| 114 | { 0xa918, 0x00590000 }, |
| 115 | { 0xa91c, 0x00000000 }, |
| 116 | { 0xa920, 0x04002501 }, |
| 117 | { 0xa924, 0x00000100 }, |
| 118 | { 0xa928, 0x03000410 }, |
| 119 | { 0xa92c, 0x00000000 }, |
| 120 | { 0xa930, 0x00020000 }, |
| 121 | { 0xa934, 0x02070106 }, |
| 122 | { 0xa938, 0x00010100 }, |
| 123 | { 0xa93c, 0x00401c00 }, |
| 124 | { 0xa940, 0x00000000 }, |
| 125 | { 0xa944, 0x00000000 }, |
| 126 | { 0xa948, 0x10000e00 }, |
| 127 | { 0xa94c, 0x02000004 }, |
| 128 | { 0xa950, 0x00000001 }, |
| 129 | { 0xa954, 0x00000004 }, |
| 130 | { 0xa960, 0x00060000 }, |
| 131 | { 0xaa3c, 0x00001c00 }, |
| 132 | { 0xaa54, 0x00000004 }, |
| 133 | { 0xaa60, 0x00060000 }, |
| 134 | { 0 } |
| 135 | }; |
| 136 | |
| 137 | struct gt_powermeter ivb_pm_gt2[] = { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 138 | { 0xa800, 0x10000000 }, |
| 139 | { 0xa804, 0x00033800 }, |
| 140 | { 0xa808, 0x00000902 }, |
| 141 | { 0xa80c, 0x0c002f00 }, |
| 142 | { 0xa810, 0x12000400 }, |
| 143 | { 0xa814, 0x00000000 }, |
| 144 | { 0xa818, 0x00d20800 }, |
| 145 | { 0xa81c, 0x00000002 }, |
| 146 | { 0xa820, 0x03004b02 }, |
| 147 | { 0xa824, 0x00000600 }, |
| 148 | { 0xa828, 0x07000773 }, |
| 149 | { 0xa82c, 0x00000000 }, |
| 150 | { 0xa830, 0x00010032 }, |
| 151 | { 0xa834, 0x1520040d }, |
| 152 | { 0xa838, 0x00020105 }, |
| 153 | { 0xa83c, 0x00083700 }, |
| 154 | { 0xa840, 0x0000151d }, |
| 155 | { 0xa844, 0x00000000 }, |
| 156 | { 0xa848, 0x20001b00 }, |
| 157 | { 0xa84c, 0x0a000010 }, |
| 158 | { 0xa850, 0x00000000 }, |
| 159 | { 0xa854, 0x00000008 }, |
| 160 | { 0xa858, 0x00000008 }, |
| 161 | { 0xa85c, 0x00000000 }, |
| 162 | { 0xa860, 0x00020000 }, |
| 163 | { 0xa248, 0x0000221e }, |
| 164 | { 0xa900, 0x00000000 }, |
| 165 | { 0xa904, 0x00003500 }, |
| 166 | { 0xa908, 0x00000000 }, |
| 167 | { 0xa90c, 0x0c000000 }, |
| 168 | { 0xa910, 0x12000500 }, |
| 169 | { 0xa914, 0x00000000 }, |
| 170 | { 0xa918, 0x00b20000 }, |
| 171 | { 0xa91c, 0x00000000 }, |
| 172 | { 0xa920, 0x08004b02 }, |
| 173 | { 0xa924, 0x00000200 }, |
| 174 | { 0xa928, 0x07000820 }, |
| 175 | { 0xa92c, 0x00000000 }, |
| 176 | { 0xa930, 0x00030000 }, |
| 177 | { 0xa934, 0x050f020d }, |
| 178 | { 0xa938, 0x00020300 }, |
| 179 | { 0xa93c, 0x00903900 }, |
| 180 | { 0xa940, 0x00000000 }, |
| 181 | { 0xa944, 0x00000000 }, |
| 182 | { 0xa948, 0x20001b00 }, |
| 183 | { 0xa94c, 0x0a000010 }, |
| 184 | { 0xa950, 0x00000000 }, |
| 185 | { 0xa954, 0x00000008 }, |
| 186 | { 0xa960, 0x00110000 }, |
| 187 | { 0xaa3c, 0x00003900 }, |
| 188 | { 0xaa54, 0x00000008 }, |
| 189 | { 0xaa60, 0x00110000 }, |
| 190 | { 0 } |
| 191 | }; |
| 192 | |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 193 | struct gt_powermeter ivb_pm_gt2_17w[] = { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 194 | { 0xa800, 0x20000000 }, |
| 195 | { 0xa804, 0x000e3800 }, |
| 196 | { 0xa808, 0x00000806 }, |
| 197 | { 0xa80c, 0x0c002f00 }, |
| 198 | { 0xa810, 0x0c000800 }, |
| 199 | { 0xa814, 0x00000000 }, |
| 200 | { 0xa818, 0x00d20d00 }, |
| 201 | { 0xa81c, 0x000000ff }, |
| 202 | { 0xa820, 0x03004b02 }, |
| 203 | { 0xa824, 0x00000600 }, |
| 204 | { 0xa828, 0x07000773 }, |
| 205 | { 0xa82c, 0x00000000 }, |
| 206 | { 0xa830, 0x00020032 }, |
| 207 | { 0xa834, 0x1520040d }, |
| 208 | { 0xa838, 0x00020105 }, |
| 209 | { 0xa83c, 0x00083700 }, |
| 210 | { 0xa840, 0x000016ff }, |
| 211 | { 0xa844, 0x00000000 }, |
| 212 | { 0xa848, 0xff000000 }, |
| 213 | { 0xa84c, 0x0a000010 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 214 | { 0xa850, 0x00000002 }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 215 | { 0xa854, 0x00000008 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 216 | { 0xa858, 0x0000000f }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 217 | { 0xa85c, 0x00000000 }, |
| 218 | { 0xa860, 0x00020000 }, |
| 219 | { 0xa248, 0x0000221e }, |
| 220 | { 0xa900, 0x00000000 }, |
| 221 | { 0xa904, 0x00003800 }, |
| 222 | { 0xa908, 0x00000000 }, |
| 223 | { 0xa90c, 0x0c000000 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 224 | { 0xa910, 0x12000800 }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 225 | { 0xa914, 0x00000000 }, |
| 226 | { 0xa918, 0x00b20000 }, |
| 227 | { 0xa91c, 0x00000000 }, |
| 228 | { 0xa920, 0x08004b02 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 229 | { 0xa924, 0x00000300 }, |
| 230 | { 0xa928, 0x01000820 }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 231 | { 0xa92c, 0x00000000 }, |
| 232 | { 0xa930, 0x00030000 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 233 | { 0xa934, 0x15150406 }, |
| 234 | { 0xa938, 0x00020300 }, |
| 235 | { 0xa93c, 0x00903900 }, |
| 236 | { 0xa940, 0x00000000 }, |
| 237 | { 0xa944, 0x00000000 }, |
| 238 | { 0xa948, 0x20001b00 }, |
| 239 | { 0xa94c, 0x0a000010 }, |
| 240 | { 0xa950, 0x00000000 }, |
| 241 | { 0xa954, 0x00000008 }, |
| 242 | { 0xa960, 0x00110000 }, |
| 243 | { 0xaa3c, 0x00003900 }, |
| 244 | { 0xaa54, 0x00000008 }, |
| 245 | { 0xaa60, 0x00110000 }, |
| 246 | { 0 } |
| 247 | }; |
| 248 | |
| 249 | struct gt_powermeter ivb_pm_gt2_35w[] = { |
| 250 | { 0xa800, 0x00000000 }, |
| 251 | { 0xa804, 0x00030400 }, |
| 252 | { 0xa808, 0x00000806 }, |
| 253 | { 0xa80c, 0x0c002f00 }, |
| 254 | { 0xa810, 0x0c000300 }, |
| 255 | { 0xa814, 0x00000000 }, |
| 256 | { 0xa818, 0x00d20d00 }, |
| 257 | { 0xa81c, 0x000000ff }, |
| 258 | { 0xa820, 0x03004b02 }, |
| 259 | { 0xa824, 0x00000600 }, |
| 260 | { 0xa828, 0x07000773 }, |
| 261 | { 0xa82c, 0x00000000 }, |
| 262 | { 0xa830, 0x00020032 }, |
| 263 | { 0xa834, 0x1520040d }, |
| 264 | { 0xa838, 0x00020105 }, |
| 265 | { 0xa83c, 0x00083700 }, |
| 266 | { 0xa840, 0x000016ff }, |
| 267 | { 0xa844, 0x00000000 }, |
| 268 | { 0xa848, 0xff000000 }, |
| 269 | { 0xa84c, 0x0a000010 }, |
| 270 | { 0xa850, 0x00000001 }, |
| 271 | { 0xa854, 0x00000008 }, |
| 272 | { 0xa858, 0x00000008 }, |
| 273 | { 0xa85c, 0x00000000 }, |
| 274 | { 0xa860, 0x00020000 }, |
| 275 | { 0xa248, 0x0000221e }, |
| 276 | { 0xa900, 0x00000000 }, |
| 277 | { 0xa904, 0x00003800 }, |
| 278 | { 0xa908, 0x00000000 }, |
| 279 | { 0xa90c, 0x0c000000 }, |
| 280 | { 0xa910, 0x12000800 }, |
| 281 | { 0xa914, 0x00000000 }, |
| 282 | { 0xa918, 0x00b20000 }, |
| 283 | { 0xa91c, 0x00000000 }, |
| 284 | { 0xa920, 0x08004b02 }, |
| 285 | { 0xa924, 0x00000300 }, |
| 286 | { 0xa928, 0x01000820 }, |
| 287 | { 0xa92c, 0x00000000 }, |
| 288 | { 0xa930, 0x00030000 }, |
| 289 | { 0xa934, 0x15150406 }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 290 | { 0xa938, 0x00020300 }, |
| 291 | { 0xa93c, 0x00903900 }, |
| 292 | { 0xa940, 0x00000000 }, |
| 293 | { 0xa944, 0x00000000 }, |
| 294 | { 0xa948, 0x20001b00 }, |
| 295 | { 0xa94c, 0x0a000010 }, |
| 296 | { 0xa950, 0x00000000 }, |
| 297 | { 0xa954, 0x00000008 }, |
| 298 | { 0xa960, 0x00110000 }, |
| 299 | { 0xaa3c, 0x00003900 }, |
| 300 | { 0xaa54, 0x00000008 }, |
| 301 | { 0xaa60, 0x00110000 }, |
| 302 | { 0 } |
| 303 | }; |
| 304 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 305 | /* some vga option roms are used for several chipsets but they only have one |
| 306 | * PCI ID in their header. If we encounter such an option rom, we need to do |
| 307 | * the mapping ourselfes |
| 308 | */ |
| 309 | |
| 310 | u32 map_oprom_vendev(u32 vendev) |
| 311 | { |
| 312 | u32 new_vendev=vendev; |
| 313 | |
| 314 | switch (vendev) { |
Martin Roth | e9dfdd9 | 2012-04-26 16:04:18 -0600 | [diff] [blame] | 315 | case 0x80860102: /* GT1 Desktop */ |
| 316 | case 0x8086010a: /* GT1 Server */ |
| 317 | case 0x80860112: /* GT2 Desktop */ |
| 318 | case 0x80860116: /* GT2 Mobile */ |
| 319 | case 0x80860122: /* GT2 Desktop >=1.3GHz */ |
| 320 | case 0x80860126: /* GT2 Mobile >=1.3GHz */ |
| 321 | case 0x80860166: /* IVB */ |
| 322 | new_vendev=0x80860106; /* GT1 Mobile */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 323 | break; |
| 324 | } |
| 325 | |
| 326 | return new_vendev; |
| 327 | } |
| 328 | |
| 329 | static struct resource *gtt_res = NULL; |
| 330 | |
| 331 | static inline u32 gtt_read(u32 reg) |
| 332 | { |
| 333 | return read32(gtt_res->base + reg); |
| 334 | } |
| 335 | |
| 336 | static inline void gtt_write(u32 reg, u32 data) |
| 337 | { |
| 338 | write32(gtt_res->base + reg, data); |
| 339 | } |
| 340 | |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 341 | static inline void gtt_write_powermeter(struct gt_powermeter *pm) |
| 342 | { |
| 343 | for (; pm && pm->reg; pm++) |
| 344 | gtt_write(pm->reg, pm->value); |
| 345 | } |
| 346 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 347 | #define GTT_RETRY 1000 |
| 348 | static int gtt_poll(u32 reg, u32 mask, u32 value) |
| 349 | { |
| 350 | unsigned try = GTT_RETRY; |
| 351 | u32 data; |
| 352 | |
| 353 | while (try--) { |
| 354 | data = gtt_read(reg); |
| 355 | if ((data & mask) == value) |
| 356 | return 1; |
| 357 | udelay(10); |
| 358 | } |
| 359 | |
| 360 | printk(BIOS_ERR, "GT init timeout\n"); |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static void gma_pm_init_pre_vbios(struct device *dev) |
| 365 | { |
| 366 | u32 reg32; |
| 367 | |
| 368 | printk(BIOS_DEBUG, "GT Power Management Init\n"); |
| 369 | |
| 370 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 371 | if (!gtt_res || !gtt_res->base) |
| 372 | return; |
| 373 | |
| 374 | if (bridge_silicon_revision() < IVB_STEP_C0) { |
| 375 | /* 1: Enable force wake */ |
| 376 | gtt_write(0xa18c, 0x00000001); |
| 377 | if (!gtt_poll(0x130090, (1 << 0), (1 << 0))) |
| 378 | return; |
| 379 | } else { |
| 380 | gtt_write(0xa180, 1 << 5); |
| 381 | gtt_write(0xa188, 0xffff0001); |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 382 | if (!gtt_poll(0x130040, (1 << 0), (1 << 0))) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 383 | return; |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 384 | /* |
| 385 | * HACK: also poll on 0x130090, for some reason graphics does |
| 386 | * not work on all SKUs unless this register is polled at boot. |
| 387 | */ |
| 388 | if (!gtt_poll(0x130090, (1 << 0), (1 << 0))) |
| 389 | return; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
| 393 | /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */ |
| 394 | reg32 = gtt_read(0x42004); |
| 395 | reg32 |= (1 << 14) | (1 << 15); |
| 396 | gtt_write(0x42004, reg32); |
| 397 | } |
| 398 | |
| 399 | if (bridge_silicon_revision() >= IVB_STEP_A0) { |
| 400 | /* Display Reset Acknowledge Settings */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 401 | reg32 = gtt_read(0x45010); |
| 402 | reg32 |= (1 << 1) | (1 << 0); |
| 403 | gtt_write(0x45010, reg32); |
| 404 | } |
| 405 | |
| 406 | /* 2: Get GT SKU from GTT+0x911c[13] */ |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 407 | reg32 = gtt_read(0x911c); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 408 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 409 | if (reg32 & (1 << 13)) { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 410 | printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n"); |
| 411 | gtt_write_powermeter(snb_pm_gt1); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 412 | } else { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 413 | printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n"); |
| 414 | gtt_write_powermeter(snb_pm_gt2); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 415 | } |
| 416 | } else { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 417 | u32 unit = MCHBAR32(0x5938) & 0xf; |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 418 | |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 419 | if (reg32 & (1 << 13)) { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 420 | /* GT1 SKU */ |
| 421 | printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n"); |
| 422 | gtt_write_powermeter(ivb_pm_gt1); |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 423 | } else { |
| 424 | /* GT2 SKU */ |
| 425 | u32 tdp = MCHBAR32(0x5930) & 0x7fff; |
| 426 | tdp /= (1 << unit); |
| 427 | |
| 428 | if (tdp <= 17) { |
| 429 | /* <=17W ULV */ |
| 430 | printk(BIOS_DEBUG, "IVB GT2 17W " |
| 431 | "Power Meter Weights\n"); |
| 432 | gtt_write_powermeter(ivb_pm_gt2_17w); |
| 433 | } else if ((tdp >= 25) && (tdp <= 35)) { |
| 434 | /* 25W-35W */ |
| 435 | printk(BIOS_DEBUG, "IVB GT2 35W " |
| 436 | "Power Meter Weights\n"); |
| 437 | gtt_write_powermeter(ivb_pm_gt2_35w); |
| 438 | } else { |
| 439 | /* All others */ |
| 440 | printk(BIOS_DEBUG, "IVB GT2 35W " |
| 441 | "Power Meter Weights\n"); |
| 442 | gtt_write_powermeter(ivb_pm_gt2_35w); |
| 443 | } |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 444 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* 3: Gear ratio map */ |
| 448 | gtt_write(0xa004, 0x00000010); |
| 449 | |
| 450 | /* 4: GFXPAUSE */ |
| 451 | gtt_write(0xa000, 0x00070020); |
| 452 | |
| 453 | /* 5: Dynamic EU trip control */ |
| 454 | gtt_write(0xa080, 0x00000004); |
| 455 | |
| 456 | /* 6: ECO bits */ |
| 457 | reg32 = gtt_read(0xa180); |
| 458 | reg32 |= (1 << 26) | (1 << 31); |
| 459 | /* (bit 20=1 for SNB step D1+ / IVB A0+) */ |
| 460 | if (bridge_silicon_revision() >= SNB_STEP_D1) |
| 461 | reg32 |= (1 << 20); |
| 462 | gtt_write(0xa180, reg32); |
| 463 | |
| 464 | /* 6a: for SnB step D2+ only */ |
| 465 | if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) && |
| 466 | (bridge_silicon_revision() >= SNB_STEP_D2)) { |
| 467 | reg32 = gtt_read(0x9400); |
| 468 | reg32 |= (1 << 7); |
| 469 | gtt_write(0x9400, reg32); |
| 470 | |
| 471 | reg32 = gtt_read(0x941c); |
| 472 | reg32 &= 0xf; |
| 473 | reg32 |= (1 << 1); |
| 474 | gtt_write(0x941c, reg32); |
| 475 | if (!gtt_poll(0x941c, (1 << 1), (0 << 1))) |
| 476 | return; |
| 477 | } |
| 478 | |
| 479 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) { |
| 480 | reg32 = gtt_read(0x907c); |
| 481 | reg32 |= (1 << 16); |
| 482 | gtt_write(0x907c, reg32); |
| 483 | |
| 484 | /* 6b: Clocking reset controls */ |
| 485 | gtt_write(0x9424, 0x00000001); |
| 486 | } else { |
| 487 | /* 6b: Clocking reset controls */ |
| 488 | gtt_write(0x9424, 0x00000000); |
| 489 | } |
| 490 | |
| 491 | /* 7 */ |
| 492 | if (!gtt_poll(0x138124, (1 << 31), (0 << 31))) |
| 493 | return; |
| 494 | gtt_write(0x138128, 0x00000029); /* Mailbox Data */ |
| 495 | gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */ |
| 496 | if (!gtt_poll(0x138124, (1 << 31), (0 << 31))) |
| 497 | return; |
| 498 | gtt_write(0x138124, 0x8000000a); /* Mailbox Cmd to clear RC6 count */ |
| 499 | if (!gtt_poll(0x138124, (1 << 31), (0 << 31))) |
| 500 | return; |
| 501 | |
| 502 | /* 8 */ |
| 503 | gtt_write(0xa090, 0x00000000); /* RC Control */ |
| 504 | gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */ |
| 505 | gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */ |
| 506 | gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */ |
| 507 | gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */ |
| 508 | gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */ |
| 509 | |
| 510 | /* 9 */ |
| 511 | gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */ |
| 512 | gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */ |
| 513 | gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */ |
| 514 | |
| 515 | /* 10 */ |
| 516 | gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */ |
| 517 | gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */ |
| 518 | gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */ |
| 519 | gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */ |
| 520 | gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */ |
| 521 | |
| 522 | /* 11 */ |
| 523 | gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */ |
| 524 | gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */ |
| 525 | gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */ |
| 526 | gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */ |
| 527 | gtt_write(0xa068, 0x000186a0); /* RP Up EI */ |
| 528 | gtt_write(0xa06c, 0x000493e0); /* RP Down EI */ |
| 529 | gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */ |
| 530 | |
| 531 | /* 11a: Enable Render Standby (RC6) */ |
| 532 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) { |
| 533 | /* on IVB: also enable DeepRenderStandby */ |
| 534 | gtt_write(0xa090, 0x88060000); /* HW RC Control */ |
| 535 | } else { |
| 536 | gtt_write(0xa090, 0x88040000); /* HW RC Control */ |
| 537 | } |
| 538 | |
| 539 | /* 12: Normal Frequency Request */ |
| 540 | /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */ |
| 541 | reg32 = MCHBAR32(0x5998); |
| 542 | reg32 >>= 16; |
| 543 | reg32 &= 0xef; |
| 544 | reg32 <<= 25; |
| 545 | gtt_write(0xa008, reg32); |
| 546 | |
| 547 | /* 13: RP Control */ |
| 548 | gtt_write(0xa024, 0x00000592); |
| 549 | |
| 550 | /* 14: Enable PM Interrupts */ |
| 551 | gtt_write(0x4402c, 0x03000076); |
| 552 | |
| 553 | /* Clear 0x6c024 [8:6] */ |
| 554 | reg32 = gtt_read(0x6c024); |
| 555 | reg32 &= ~0x000001c0; |
| 556 | gtt_write(0x6c024, reg32); |
| 557 | } |
| 558 | |
| 559 | static void gma_pm_init_post_vbios(struct device *dev) |
| 560 | { |
| 561 | struct northbridge_intel_sandybridge_config *conf = dev->chip_info; |
| 562 | u32 reg32; |
| 563 | |
| 564 | printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n"); |
| 565 | |
| 566 | /* 15: Deassert Force Wake */ |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 567 | if (bridge_silicon_revision() < IVB_STEP_C0) { |
| 568 | gtt_write(0xa18c, gtt_read(0xa18c) & ~1); |
| 569 | if (!gtt_poll(0x130090, (1 << 0), (0 << 0))) { |
| 570 | return; |
| 571 | } |
| 572 | } else { |
| 573 | gtt_write(0xa188, 0x1fffe); |
| 574 | if (!gtt_poll(0x130040, (1 << 0), (0 << 0))) { |
| 575 | return; |
| 576 | } |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame^] | 577 | /* |
| 578 | * HACK: also poll on 0x130090, for some reason graphics does |
| 579 | * not work on all SKUs unless this register is polled at boot. |
| 580 | */ |
| 581 | if (!gtt_poll(0x130090, (1 << 0), (0 << 0))) { |
| 582 | return; |
| 583 | } |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 584 | gtt_write(0xa188, gtt_read(0xa188) | 1); |
| 585 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 586 | |
| 587 | /* 16: SW RC Control */ |
| 588 | gtt_write(0xa094, 0x00060000); |
| 589 | |
| 590 | /* Setup Digital Port Hotplug */ |
| 591 | reg32 = gtt_read(0xc4030); |
| 592 | if (!reg32) { |
| 593 | reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 594 | reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 595 | reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
| 596 | gtt_write(0xc4030, reg32); |
| 597 | } |
| 598 | |
| 599 | /* Setup Panel Power On Delays */ |
| 600 | reg32 = gtt_read(0xc7208); |
| 601 | if (!reg32) { |
| 602 | reg32 = (conf->gpu_panel_port_select & 0x3) << 30; |
| 603 | reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 604 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
| 605 | gtt_write(0xc7208, reg32); |
| 606 | } |
| 607 | |
| 608 | /* Setup Panel Power Off Delays */ |
| 609 | reg32 = gtt_read(0xc720c); |
| 610 | if (!reg32) { |
| 611 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 612 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
| 613 | gtt_write(0xc720c, reg32); |
| 614 | } |
| 615 | |
| 616 | /* Setup Panel Power Cycle Delay */ |
| 617 | if (conf->gpu_panel_power_cycle_delay) { |
| 618 | reg32 = gtt_read(0xc7210); |
| 619 | reg32 &= ~0xff; |
| 620 | reg32 |= conf->gpu_panel_power_cycle_delay & 0xff; |
| 621 | gtt_write(0xc7210, reg32); |
| 622 | } |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 623 | |
| 624 | /* Enable Backlight if needed */ |
| 625 | if (conf->gpu_cpu_backlight) { |
| 626 | gtt_write(0x48250, (1 << 31)); |
| 627 | gtt_write(0x48254, conf->gpu_cpu_backlight); |
| 628 | } |
| 629 | if (conf->gpu_pch_backlight) { |
| 630 | gtt_write(0xc8250, (1 << 31)); |
| 631 | gtt_write(0xc8254, conf->gpu_pch_backlight); |
| 632 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | static void gma_func0_init(struct device *dev) |
| 636 | { |
| 637 | u32 reg32; |
| 638 | |
| 639 | /* IGD needs to be Bus Master */ |
| 640 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 641 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 642 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 643 | |
| 644 | /* Init graphics power management */ |
| 645 | gma_pm_init_pre_vbios(dev); |
| 646 | |
| 647 | /* PCI Init, will run VBIOS */ |
| 648 | pci_dev_init(dev); |
| 649 | |
| 650 | /* Post VBIOS init */ |
| 651 | gma_pm_init_post_vbios(dev); |
| 652 | } |
| 653 | |
| 654 | static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 655 | { |
| 656 | if (!vendor || !device) { |
| 657 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 658 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 659 | } else { |
| 660 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 661 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | static struct pci_operations gma_pci_ops = { |
| 666 | .set_subsystem = gma_set_subsystem, |
| 667 | }; |
| 668 | |
| 669 | static struct device_operations gma_func0_ops = { |
| 670 | .read_resources = pci_dev_read_resources, |
| 671 | .set_resources = pci_dev_set_resources, |
| 672 | .enable_resources = pci_dev_enable_resources, |
| 673 | .init = gma_func0_init, |
| 674 | .scan_bus = 0, |
| 675 | .enable = 0, |
| 676 | .ops_pci = &gma_pci_ops, |
| 677 | }; |
| 678 | |
| 679 | static const struct pci_driver gma_gt1_desktop __pci_driver = { |
| 680 | .ops = &gma_func0_ops, |
| 681 | .vendor = PCI_VENDOR_ID_INTEL, |
| 682 | .device = 0x0102, |
| 683 | }; |
| 684 | |
| 685 | static const struct pci_driver gma_gt1_mobile __pci_driver = { |
| 686 | .ops = &gma_func0_ops, |
| 687 | .vendor = PCI_VENDOR_ID_INTEL, |
| 688 | .device = 0x0106, |
| 689 | }; |
| 690 | |
| 691 | static const struct pci_driver gma_gt1_server __pci_driver = { |
| 692 | .ops = &gma_func0_ops, |
| 693 | .vendor = PCI_VENDOR_ID_INTEL, |
| 694 | .device = 0x010a, |
| 695 | }; |
| 696 | |
| 697 | static const struct pci_driver gma_gt2_desktop __pci_driver = { |
| 698 | .ops = &gma_func0_ops, |
| 699 | .vendor = PCI_VENDOR_ID_INTEL, |
| 700 | .device = 0x0112, |
| 701 | }; |
| 702 | |
| 703 | static const struct pci_driver gma_gt2_mobile __pci_driver = { |
| 704 | .ops = &gma_func0_ops, |
| 705 | .vendor = PCI_VENDOR_ID_INTEL, |
| 706 | .device = 0x0116, |
| 707 | }; |
| 708 | |
| 709 | static const struct pci_driver gma_gt2_desktop_fast __pci_driver = { |
| 710 | .ops = &gma_func0_ops, |
| 711 | .vendor = PCI_VENDOR_ID_INTEL, |
| 712 | .device = 0x0122, |
| 713 | }; |
| 714 | |
| 715 | static const struct pci_driver gma_gt2_mobile_fast __pci_driver = { |
| 716 | .ops = &gma_func0_ops, |
| 717 | .vendor = PCI_VENDOR_ID_INTEL, |
| 718 | .device = 0x0126, |
| 719 | }; |
| 720 | |
| 721 | static const struct pci_driver gma_func0_driver_3 __pci_driver = { |
| 722 | .ops = &gma_func0_ops, |
| 723 | .vendor = PCI_VENDOR_ID_INTEL, |
| 724 | .device = 0x0166, |
| 725 | }; |