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