blob: 5264d48efb076cb24c64145ae28bf5cec14887f2 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi2efc8802012-11-06 11:03:53 +01002
3#include <stdint.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01004#include <device/pci_def.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01005#include <spd.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01006
Elyes HAOUASa1e22b82019-03-18 22:49:36 +01007#include "delay.h"
Patrick Georgi2efc8802012-11-06 11:03:53 +01008#include "gm45.h"
9
10void raminit_thermal(const sysinfo_t *sysinfo)
11{
12 const mem_clock_t freq = sysinfo->selected_timings.mem_clock;
13 int x;
14 FOR_EACH_POPULATED_CHANNEL(sysinfo->dimms, x) {
15 const chip_width_t width = sysinfo->dimms[x].chip_width;
16 const chip_capacity_t size = sysinfo->dimms[x].chip_capacity;
17 if ((freq == MEM_CLOCK_1067MT) && (width == CHIP_WIDTH_x16)) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010018 mchbar_write32(CxDTPEW(x), 0x0d0b0403);
19 mchbar_write32(CxDTPEW(x) + 4, 0x060d);
20 mchbar_write32(CxDTAEW(x), 0x2d0b221a);
21 mchbar_write32(CxDTAEW(x) + 4, 0xc779956e);
Patrick Georgi2efc8802012-11-06 11:03:53 +010022 } else
23 if ((freq == MEM_CLOCK_1067MT) && (width == CHIP_WIDTH_x8)) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010024 mchbar_write32(CxDTPEW(x), 0x06040101);
25 mchbar_write32(CxDTPEW(x) + 4, 0x0506);
Patrick Georgi2efc8802012-11-06 11:03:53 +010026 if (size == CHIP_CAP_2G)
Angel Pons3f1f8ef2021-03-27 13:52:43 +010027 mchbar_write32(CxDTAEW(x), 0xa1071416);
Patrick Georgi2efc8802012-11-06 11:03:53 +010028 else
Angel Pons3f1f8ef2021-03-27 13:52:43 +010029 mchbar_write32(CxDTAEW(x), 0x1a071416);
30 mchbar_write32(CxDTAEW(x) + 4, 0x7246643f);
Patrick Georgi2efc8802012-11-06 11:03:53 +010031 } else
32 if ((freq == MEM_CLOCK_800MT) && (width == CHIP_WIDTH_x16)) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010033 mchbar_write32(CxDTPEW(x), 0x06030100);
34 mchbar_write32(CxDTPEW(x) + 4, 0x0506);
35 mchbar_write32(CxDTAEW(x), 0x3e081714);
36 mchbar_write32(CxDTAEW(x) + 4, 0xbb79a171);
Patrick Georgi2efc8802012-11-06 11:03:53 +010037 } else
38 if ((freq == MEM_CLOCK_800MT) && (width == CHIP_WIDTH_x8)) {
39 if (size <= CHIP_CAP_512M)
Angel Pons3f1f8ef2021-03-27 13:52:43 +010040 mchbar_write32(CxDTPEW(x), 0x05050101);
Patrick Georgi2efc8802012-11-06 11:03:53 +010041 else
Angel Pons3f1f8ef2021-03-27 13:52:43 +010042 mchbar_write32(CxDTPEW(x), 0x05060101);
43 mchbar_write32(CxDTPEW(x) + 4, 0x0503);
Patrick Georgi2efc8802012-11-06 11:03:53 +010044 if (size == CHIP_CAP_2G) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010045 mchbar_write32(CxDTAEW(x), 0x57051010);
46 mchbar_write32(CxDTAEW(x) + 4, 0x5fd15dde);
Patrick Georgi2efc8802012-11-06 11:03:53 +010047 } else
48 if (size == CHIP_CAP_1G) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010049 mchbar_write32(CxDTAEW(x), 0x3306130e);
50 mchbar_write32(CxDTAEW(x) + 4, 0x5763485d);
Patrick Georgi2efc8802012-11-06 11:03:53 +010051 } else
52 if (size <= CHIP_CAP_512M) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010053 mchbar_write32(CxDTAEW(x), 0x1e08170d);
54 mchbar_write32(CxDTAEW(x) + 4, 0x502f3827);
Patrick Georgi2efc8802012-11-06 11:03:53 +010055 }
56 } else
57 if ((freq == MEM_CLOCK_667MT) && (width == CHIP_WIDTH_x16)) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010058 mchbar_write32(CxDTPEW(x), 0x02000000);
59 mchbar_write32(CxDTPEW(x) + 4, 0x0402);
60 mchbar_write32(CxDTAEW(x), 0x46061111);
61 mchbar_write32(CxDTAEW(x) + 4, 0xb579a772);
Patrick Georgi2efc8802012-11-06 11:03:53 +010062 } else
63 if ((freq == MEM_CLOCK_667MT) && (width == CHIP_WIDTH_x8)) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010064 mchbar_write32(CxDTPEW(x), 0x04070101);
65 mchbar_write32(CxDTPEW(x) + 4, 0x0501);
Patrick Georgi2efc8802012-11-06 11:03:53 +010066 if (size == CHIP_CAP_2G) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010067 mchbar_write32(CxDTAEW(x), 0x32040e0d);
68 mchbar_write32(CxDTAEW(x) + 4, 0x55ff59ff);
Patrick Georgi2efc8802012-11-06 11:03:53 +010069 } else
70 if (size == CHIP_CAP_1G) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010071 mchbar_write32(CxDTAEW(x), 0x3f05120a);
72 mchbar_write32(CxDTAEW(x) + 4, 0x49713a6c);
Patrick Georgi2efc8802012-11-06 11:03:53 +010073 } else
74 if (size <= CHIP_CAP_512M) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010075 mchbar_write32(CxDTAEW(x), 0x20081808);
76 mchbar_write32(CxDTAEW(x) + 4, 0x3f23221b);
Patrick Georgi2efc8802012-11-06 11:03:53 +010077 }
78 }
79
80 /* also L-Shaped */
81 if (sysinfo->selected_timings.channel_mode ==
82 CHANNEL_MODE_DUAL_INTERLEAVED) {
83 if (freq == MEM_CLOCK_1067MT) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010084 mchbar_write32(CxGTEW(x), 0xc8f81717);
Patrick Georgi2efc8802012-11-06 11:03:53 +010085 } else
86 if (freq == MEM_CLOCK_800MT) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010087 mchbar_write32(CxGTEW(x), 0x96ba1717);
Patrick Georgi2efc8802012-11-06 11:03:53 +010088 } else
89 if (freq == MEM_CLOCK_667MT) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010090 mchbar_write32(CxGTEW(x), 0x7d9b1717);
Patrick Georgi2efc8802012-11-06 11:03:53 +010091 }
92 } else {
93 if (freq == MEM_CLOCK_1067MT) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010094 mchbar_write32(CxGTEW(x), 0x53661717);
Patrick Georgi2efc8802012-11-06 11:03:53 +010095 } else
96 if (freq == MEM_CLOCK_800MT) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +010097 mchbar_write32(CxGTEW(x), 0x886e1717);
Patrick Georgi2efc8802012-11-06 11:03:53 +010098 } else
99 if (freq == MEM_CLOCK_667MT) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100100 mchbar_write32(CxGTEW(x), 0x38621717);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100101 }
102 }
103 }
104
105 // always?
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100106 mchbar_write32(CxDTC(0), 0x00004020);
107 mchbar_write32(CxDTC(1), 0x00004020);
108 mchbar_write32(CxGTC(0), 0x00304848);
109 mchbar_write32(CxGTC(1), 0x00304848);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100110
111 /* enable thermal sensors */
112 u32 tmp;
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100113 tmp = mchbar_read32(0x1290) & 0xfff8;
114 mchbar_write32(0x1290, tmp | 0xa4810007);
115 tmp = mchbar_read32(0x1390) & 0xfff8;
116 mchbar_write32(0x1390, tmp | 0xa4810007);
117 tmp = mchbar_read32(0x12b4) & 0xfff8;
118 mchbar_write32(0x12b4, tmp | 0xa2810007);
119 tmp = mchbar_read32(0x13b4) & 0xfff8;
120 mchbar_write32(0x13b4, tmp | 0xa2810007);
121 mchbar_write8(0x1070, 1);
122 mchbar_write8(0x1080, 6);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100123 if (sysinfo->gfx_type == GMCH_PM45) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100124 mchbar_write16(0x1001, 0);
125 mchbar_write8(0x1007, 0);
126 mchbar_write32(0x1010, 0);
127 mchbar_write32(0x1014, 0);
128 mchbar_write8(0x101c, 0x98);
129 mchbar_write16(0x1041, 0x9200);
130 mchbar_write8(0x1047, 0);
131 mchbar_write32(0x1050, 0x2309);
132 mchbar_write32(0x1054, 0);
133 mchbar_write8(0x105c, 0x98);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100134 } else {
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100135 mchbar_write16(0x1001, 0x9200);
136 mchbar_write8(0x1007, 0);
137 mchbar_write32(0x1010, 0x2309);
138 mchbar_write32(0x1014, 0);
139 mchbar_write8(0x101c, 0x98);
140 mchbar_write16(0x1041, 0);
141 mchbar_write8(0x1047, 0);
142 mchbar_write32(0x1050, 0);
143 mchbar_write32(0x1054, 0);
144 mchbar_write8(0x105c, 0x98);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100145 }
146
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100147 mchbar_setbits32(0x1010, 1 << 31);
148 mchbar_setbits32(0x1050, 1 << 31);
149 mchbar_setbits32(CxGTC(0), 1 << 31);
150 mchbar_setbits32(CxGTC(1), 1 << 31);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100151
152 if (sysinfo->gs45_low_power_mode) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100153 mchbar_write32(0x11b0, 0xa000083a);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100154 } else if (sysinfo->gfx_type == GMCH_GM49) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100155 mchbar_write32(0x11b0, 0x2000383a);
156 mchbar_clrbits16(0x1190, 1 << 15);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100157 } else if ((sysinfo->gfx_type != GMCH_PM45) &&
158 (sysinfo->gfx_type != GMCH_UNKNOWN)) {
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100159 mchbar_write32(0x11b0, 0xa000383a);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100160 }
161
162 switch (sysinfo->selected_timings.fsb_clock) {
Felix Singer893d77e2023-12-08 11:00:26 +0100163 case FSB_CLOCK_667MHz:
164 mchbar_write32(0x11d0, 0x0fd88000);
165 break;
166 case FSB_CLOCK_800MHz:
167 mchbar_write32(0x11d0, 0x1303c000);
168 break;
169 case FSB_CLOCK_1067MHz:
170 mchbar_write32(0x11d0, 0x194a0000);
171 break;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100172 }
Angel Pons3f1f8ef2021-03-27 13:52:43 +0100173 tmp = mchbar_read32(0x11d4) & ~0x1f;
174 mchbar_write32(0x11d4, tmp | 4);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100175}