Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 secunet Security Networks AG |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 19 | * MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <stddef.h> |
| 24 | #include <string.h> |
| 25 | #include <arch/io.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 26 | #include <device/pci_def.h> |
| 27 | #include <device/pnp_def.h> |
| 28 | #include <console/console.h> |
| 29 | #include <cpu/x86/msr.h> |
| 30 | |
| 31 | #include "gm45.h" |
| 32 | |
| 33 | static int sku_freq_index(const gmch_gfx_t sku, const int low_power_mode) |
| 34 | { |
| 35 | if (low_power_mode) |
| 36 | return 1; |
| 37 | switch (sku) { |
| 38 | case GMCH_GM45: |
| 39 | case GMCH_GE45: |
| 40 | case GMCH_GS45: |
| 41 | return 0; |
| 42 | case GMCH_GM47: |
| 43 | return 2; |
| 44 | case GMCH_GM49: |
| 45 | return 3; |
| 46 | default: |
| 47 | return 0; |
| 48 | } |
| 49 | } |
| 50 | static void init_freq_scaling(const gmch_gfx_t sku, const int low_power_mode) |
| 51 | { |
| 52 | int i; |
| 53 | |
| 54 | MCHBAR32(0x11cc) = (MCHBAR32(0x11cc) & ~(0x1f)) | 0x17; |
| 55 | switch (sku) { |
| 56 | case GMCH_GM45: |
| 57 | case GMCH_GE45: |
| 58 | case GMCH_GS45: |
| 59 | case GMCH_GM47: |
| 60 | case GMCH_GM49: |
| 61 | break; |
| 62 | default: |
| 63 | /* No more to be done for the others. */ |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | static const u32 voltage_mask = |
| 68 | (0x1f << 24) | (0x1f << 16) | (0x1f << 8) | 0x1f; |
| 69 | MCHBAR32(0x1120) = (MCHBAR32(0x1120) & ~voltage_mask) | 0x10111213; |
| 70 | MCHBAR32(0x1124) = (MCHBAR32(0x1124) & ~voltage_mask) | 0x14151617; |
| 71 | MCHBAR32(0x1128) = (MCHBAR32(0x1128) & ~voltage_mask) | 0x18191a1b; |
| 72 | MCHBAR32(0x112c) = (MCHBAR32(0x112c) & ~voltage_mask) | 0x1c1d1e1f; |
| 73 | MCHBAR32(0x1130) = (MCHBAR32(0x1130) & ~voltage_mask) | 0x00010203; |
| 74 | MCHBAR32(0x1134) = (MCHBAR32(0x1134) & ~voltage_mask) | 0x04050607; |
| 75 | MCHBAR32(0x1138) = (MCHBAR32(0x1138) & ~voltage_mask) | 0x08090a0b; |
| 76 | MCHBAR32(0x113c) = (MCHBAR32(0x113c) & ~voltage_mask) | 0x0c0d0e0f; |
| 77 | |
| 78 | /* Program frequencies. */ |
| 79 | static const u32 frequencies_from_sku_vco[][4][8] = { |
| 80 | /* GM45/GE45/GS45_perf */ { |
| 81 | /* VCO 2666 */ { 0xcd, 0xbc, 0x9b, 0x8a, 0x79, 0x78, 0x67, 0x56 }, |
| 82 | /* VCO 3200 */ { 0xcd, 0xac, 0x9b, 0x8a, 0x89, 0x78, 0x67, 0x56 }, |
| 83 | /* VCO 4000 */ { 0xac, 0x9b, 0x9a, 0x89, 0x89, 0x68, 0x56, 0x45 }, |
| 84 | /* VCO 5333 */ { 0xab, 0x9a, 0x79, 0x68, 0x57, 0x56, 0x45, 0x34 }, |
| 85 | }, |
| 86 | /* GS45_low_power */ { |
| 87 | /* VCO 2666 */ { 0xcd, 0x8a }, |
| 88 | /* VCO 3200 */ { 0xcd, 0x89 }, |
| 89 | /* VCO 4000 */ { 0xac, 0x89 }, |
| 90 | /* VCO 5333 */ { 0xab, 0x68 }, |
| 91 | }, |
| 92 | /* GM47 */ { |
| 93 | /* VCO 2666 */ { 0xcd, 0xcd, 0xbc, 0x9b, 0x79, 0x78, 0x67, 0x56 }, |
| 94 | /* VCO 3200 */ { 0xde, 0xcd, 0xac, 0x9b, 0x89, 0x78, 0x67, 0x56 }, |
| 95 | /* VCO 4000 */ { 0xcd, 0xac, 0x9b, 0x9a, 0x89, 0x68, 0x56, 0x45 }, |
| 96 | /* VCO 5333 */ { 0xac, 0xab, 0x9a, 0x79, 0x68, 0x56, 0x45, 0x34 }, |
| 97 | }, |
| 98 | /* GM49 */ { |
| 99 | /* VCO 2666 */ { }, |
| 100 | /* VCO 3200 */ { 0xef, 0xde, 0xcd, 0xac, 0x89, 0x78, 0x67, 0x56 }, |
| 101 | /* VCO 4000 */ { 0xef, 0xde, 0xac, 0x9b, 0x89, 0x68, 0x56, 0x45 }, |
| 102 | /* VCO 5333 */ { 0xce, 0xbd, 0xab, 0x9a, 0x68, 0x57, 0x45, 0x34 }, |
| 103 | }}; |
| 104 | const int sku_index = sku_freq_index(sku, low_power_mode); |
| 105 | const int vco_index = raminit_read_vco_index(); |
| 106 | const int reg_limit = low_power_mode ? 1 : 4; |
| 107 | if (sku == GMCH_GM49) |
| 108 | MCHBAR8(0x1110+3) = 0x1b; |
| 109 | else |
| 110 | MCHBAR8(0x1110+3) = 0x17; |
| 111 | MCHBAR8(0x1110+1) = 0x17; |
| 112 | if (!low_power_mode) { |
| 113 | MCHBAR8(0x1114+3) = 0x17; |
| 114 | MCHBAR8(0x1114+1) = 0x17; |
| 115 | MCHBAR8(0x1118+3) = 0x17; |
| 116 | MCHBAR8(0x1118+1) = 0x17; |
| 117 | MCHBAR8(0x111c+3) = 0x17; |
| 118 | MCHBAR8(0x111c+1) = 0x17; |
| 119 | } |
| 120 | for (i = 0; i < reg_limit; ++i) { |
| 121 | const int mchbar = 0x1110 + (i * 4); |
| 122 | MCHBAR8(mchbar + 2) = frequencies_from_sku_vco |
| 123 | [sku_index][vco_index][i * 2 + 0]; |
| 124 | MCHBAR8(mchbar + 0) = frequencies_from_sku_vco |
| 125 | [sku_index][vco_index][i * 2 + 1]; |
| 126 | } |
| 127 | |
| 128 | if (low_power_mode) { |
| 129 | MCHBAR16(0x1190) = |
| 130 | (MCHBAR16(0x1190) & ~((7 << 8) | (7 << 4) | 7)) | |
| 131 | (1 << 8) | (1 << 4) | 1; |
| 132 | } else { |
| 133 | MCHBAR16(0x1190) = |
| 134 | (MCHBAR16(0x1190) & ~((7 << 8) | (7 << 4))) | 7; |
| 135 | if (sku == GMCH_GS45) /* performance mode */ |
| 136 | MCHBAR32(0x0ffc) &= ~(1 << 31); |
| 137 | } |
| 138 | |
| 139 | MCHBAR16(0x0fc0) |= (1 << 11); |
| 140 | MCHBAR16(0x11b8) = 0x333c; |
| 141 | MCHBAR16(0x11c0 + 2) = 0x0303; |
| 142 | MCHBAR32(0x11c4) = 0x0a030a03; |
| 143 | MCHBAR16(0x1100) = (MCHBAR16(0x1100) & ~(0x1f << 8)) | (3 << 8); |
| 144 | MCHBAR16(0x11b8 + 2) = 0x4000; |
| 145 | } |
| 146 | |
Vladimir Serbinenko | 020dc0e | 2014-08-12 22:50:40 +0200 | [diff] [blame^] | 147 | void init_pm(const sysinfo_t *const sysinfo, int do_freq_scaling_cfg) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 148 | { |
| 149 | const stepping_t stepping = sysinfo->stepping; |
| 150 | const fsb_clock_t fsb = sysinfo->selected_timings.fsb_clock; |
| 151 | const mem_clock_t memclk = sysinfo->selected_timings.mem_clock; |
| 152 | |
| 153 | MCHBAR16(0xc14) = 0; |
| 154 | MCHBAR16(0xc20) = 0; |
| 155 | MCHBAR32(0xfc0) = 0x001f00fd; |
| 156 | MCHBAR32(0xfc0) |= 3 << 25; |
| 157 | MCHBAR32(0xfc0) |= 1 << 11; |
| 158 | MCHBAR8(0xfb0) = 3; |
| 159 | MCHBAR8(0xf10) |= 1 << 1; |
| 160 | if (fsb == FSB_CLOCK_667MHz) { |
| 161 | MCHBAR16(0xc3a) = 0xea6; |
| 162 | MCHBAR8(0xc16) = (MCHBAR8(0xc16) & 0x80) | 0x0e; |
| 163 | } else if (fsb == FSB_CLOCK_800MHz) { |
| 164 | MCHBAR16(0xc3a) = 0x1194; |
| 165 | MCHBAR8(0xc16) = (MCHBAR8(0xc16) & 0x80) | 0x10; |
| 166 | } else if (fsb == FSB_CLOCK_1067MHz) { |
| 167 | MCHBAR16(0xc3a) = 0x1777; |
| 168 | MCHBAR8(0xc16) = (MCHBAR8(0xc16) & 0x80) | 0x15; |
| 169 | } |
| 170 | MCHBAR8(0xfb8) = 3; |
| 171 | if (fsb == FSB_CLOCK_667MHz) |
| 172 | MCHBAR16(0xc38) = 0x0ea6; |
| 173 | else if (fsb == FSB_CLOCK_800MHz) |
| 174 | MCHBAR16(0xc38) = 0x1194; |
| 175 | else if (fsb == FSB_CLOCK_1067MHz) |
| 176 | MCHBAR16(0xc38) = 0x1777; |
| 177 | MCHBAR8(0xf10) |= 1 << 5; |
| 178 | MCHBAR16(0xc16) |= 3 << 12; |
| 179 | MCHBAR32(0xf60) = 0x01030419; |
| 180 | if (fsb == FSB_CLOCK_667MHz) { |
| 181 | MCHBAR32(0xf00) = 0x00000600; |
| 182 | MCHBAR32(0xf04) = 0x00001d80; |
| 183 | } else if (fsb == FSB_CLOCK_800MHz) { |
| 184 | MCHBAR32(0xf00) = 0x00000700; |
| 185 | MCHBAR32(0xf04) = 0x00002380; |
| 186 | } else if (fsb == FSB_CLOCK_1067MHz) { |
| 187 | MCHBAR32(0xf00) = 0x00000900; |
| 188 | MCHBAR32(0xf04) = 0x00002e80; |
| 189 | } |
| 190 | MCHBAR16(0xf08) = 0x730f; |
| 191 | if (fsb == FSB_CLOCK_667MHz) |
| 192 | MCHBAR16(0xf0c) = 0x0b96; |
| 193 | else if (fsb == FSB_CLOCK_800MHz) |
| 194 | MCHBAR16(0xf0c) = 0x0c99; |
| 195 | else if (fsb == FSB_CLOCK_1067MHz) |
| 196 | MCHBAR16(0xf0c) = 0x10a4; |
| 197 | MCHBAR32(0xf80) |= 1 << 31; |
| 198 | |
| 199 | MCHBAR32(0x40) = (MCHBAR32(0x40) & ~(0x3f << 24)) | |
| 200 | (sysinfo->cores == 4) ? (1 << 24) : 0; |
| 201 | |
| 202 | MCHBAR32(0x40) &= ~(1 << 19); |
| 203 | MCHBAR32(0x40) |= 1 << 13; |
| 204 | MCHBAR32(0x40) |= 1 << 21; |
| 205 | MCHBAR32(0x40) |= 1 << 9; |
| 206 | if (stepping > STEPPING_B1) { |
| 207 | if (fsb != FSB_CLOCK_1067MHz) { |
| 208 | MCHBAR32(0x70) |= 1 << 30; |
| 209 | } else { |
| 210 | MCHBAR32(0x70) &= ~(1 << 30); |
| 211 | } |
| 212 | } |
| 213 | if (stepping < STEPPING_B1) |
| 214 | MCHBAR32(0x70) |= 1 << 29; |
| 215 | else |
| 216 | MCHBAR32(0x70) &= ~(1 << 29); |
| 217 | if (stepping > STEPPING_B1) { |
| 218 | MCHBAR32(0x70) |= 1 << 28; |
| 219 | MCHBAR32(0x70) |= 1 << 25; |
| 220 | } |
| 221 | if (stepping > STEPPING_B0) { |
| 222 | if (fsb != FSB_CLOCK_667MHz) |
| 223 | MCHBAR32(0x70) = (MCHBAR32(0x70) & ~(3<<21)) | (1 << 21); |
| 224 | else |
| 225 | MCHBAR32(0x70) = (MCHBAR32(0x70) & ~(3<<21)); |
| 226 | } |
| 227 | if (stepping > STEPPING_B2) |
| 228 | MCHBAR32(0x44) |= 1 << 30; |
| 229 | MCHBAR32(0x44) |= 1 << 31; |
| 230 | if (sysinfo->cores == 2) |
| 231 | MCHBAR32(0x44) |= 1 << 26; |
| 232 | MCHBAR32(0x44) |= 1 << 21; |
| 233 | MCHBAR32(0x44) = (MCHBAR32(0x44) & ~(3 << 24)) | (2 << 24); |
| 234 | MCHBAR32(0x44) |= 1 << 5; |
| 235 | MCHBAR32(0x44) |= 1 << 4; |
| 236 | MCHBAR32(0x90) = (MCHBAR32(0x90) & ~7) | 4; |
| 237 | MCHBAR32(0x94) |= 1 << 29; |
| 238 | MCHBAR32(0x94) |= 1 << 11; |
| 239 | if (stepping < STEPPING_B0) |
| 240 | MCHBAR32(0x94) = (MCHBAR32(0x94) & ~(3 << 19)) | (2 << 19); |
| 241 | if (stepping > STEPPING_B2) |
| 242 | MCHBAR32(0x94) |= 1 << 21; |
| 243 | MCHBAR8(0xb00) &= ~1; |
| 244 | MCHBAR8(0xb00) |= 1 << 7; |
| 245 | if (fsb != FSB_CLOCK_1067MHz) |
| 246 | MCHBAR8(0x75) |= 1 << 6; |
| 247 | else |
| 248 | MCHBAR8(0x75) &= 1 << 1; |
| 249 | MCHBAR8(0x77) |= 3; |
| 250 | if (stepping >= STEPPING_B1) |
| 251 | MCHBAR8(0x77) |= 1 << 2; |
| 252 | if (stepping > STEPPING_B2) |
| 253 | MCHBAR8(0x77) |= 1 << 4; |
| 254 | if (MCHBAR16(0x90) & 0x100) |
| 255 | MCHBAR8(0x90) &= ~(7 << 4); |
| 256 | if (stepping >= STEPPING_B0) |
| 257 | MCHBAR8(0xd0) |= 1 << 1; |
| 258 | MCHBAR8(0xbd8) |= 3 << 2; |
| 259 | if (stepping >= STEPPING_B3) |
| 260 | MCHBAR32(0x70) |= 1 << 0; |
| 261 | MCHBAR32(0x70) |= 1 << 3; |
| 262 | if (stepping >= STEPPING_B0) |
| 263 | MCHBAR32(0x70) &= ~(1 << 16); |
| 264 | else |
| 265 | MCHBAR32(0x70) |= 1 << 16; |
| 266 | if (stepping >= STEPPING_B3) |
| 267 | MCHBAR8(0xc14) |= 1 << 1; |
| 268 | if (stepping >= STEPPING_B1) |
| 269 | MCHBAR16(0xffc) = (MCHBAR16(0xffc) & ~0x7ff) | 0x7c0; |
| 270 | MCHBAR16(0x48) = (MCHBAR16(0x48) & ~(0xff << 2)) | (0xaa << 2); |
| 271 | if (stepping == STEPPING_CONVERSION_A1) { |
| 272 | MCHBAR16(0x40) |= 1 << 12; |
| 273 | MCHBAR32(0x94) |= 3 << 22; |
| 274 | } |
| 275 | |
| 276 | const int cpu_supports_super_lfm = rdmsr(0xee).lo & (1 << 27); |
| 277 | if ((stepping >= STEPPING_B0) && cpu_supports_super_lfm) { |
| 278 | MCHBAR16(CLKCFG_MCHBAR) &= ~(1 << 7); |
| 279 | MCHBAR16(CLKCFG_MCHBAR) |= 1 << 14; |
| 280 | } else { |
| 281 | MCHBAR16(CLKCFG_MCHBAR) &= ~(1 << 14); |
| 282 | MCHBAR16(CLKCFG_MCHBAR) |= 1 << 7; |
| 283 | MCHBAR32(0x44) &= ~(1 << 31); /* Was set above. */ |
| 284 | } |
| 285 | |
Vladimir Serbinenko | 020dc0e | 2014-08-12 22:50:40 +0200 | [diff] [blame^] | 286 | if ((sysinfo->gfx_type != GMCH_PM45) && do_freq_scaling_cfg && |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 287 | (sysinfo->gfx_type != GMCH_UNKNOWN)) |
| 288 | init_freq_scaling(sysinfo->gfx_type, |
| 289 | sysinfo->gs45_low_power_mode); |
| 290 | |
| 291 | /* This has to be the last write to CLKCFG. */ |
| 292 | if ((fsb == FSB_CLOCK_1067MHz) && (memclk == MEM_CLOCK_667MT)) |
| 293 | MCHBAR32(CLKCFG_MCHBAR) &= ~(1 << 17); |
| 294 | } |