blob: a8dfa31d9a5229a81767d2feee4cf9d8c54fbdd9 [file] [log] [blame]
Martin Rothe899e512012-12-05 16:07:11 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Sage Electronic Engineering, LLC
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.
Martin Rothe899e512012-12-05 16:07:11 -070014 */
15
16#include <southbridge/amd/cimx/cimx_util.h>
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020017#include <device/device.h>
Martin Rothe899e512012-12-05 16:07:11 -070018#include <device/pci.h> /* device_operations */
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Martin Rothe899e512012-12-05 16:07:11 -070020#include "SBPLATFORM.h"
21#include "sb_cimx.h"
22#include "chip.h" /* struct southbridge_amd_cimx_sb800_config */
23#include "fan.h"
24
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020025void init_sb800_MANUAL_fans(struct device *dev)
Martin Rothe899e512012-12-05 16:07:11 -070026{
27 int i;
28 struct southbridge_amd_cimx_sb800_config *sb_chip =
29 (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info);
30
31 /* Init Fan 0 */
32 if (sb_chip->fan0_enabled)
33 for (i = 0; i < FAN_REGISTER_COUNT; i++)
34 pm2_iowrite(FAN_0_OFFSET + i, sb_chip->fan0_config_vals[i]);
35
36 /* Init Fan 1 */
37 if (sb_chip->fan1_enabled)
38 for (i = 0; i < FAN_REGISTER_COUNT; i++)
39 pm2_iowrite(FAN_1_OFFSET + i, sb_chip->fan1_config_vals[i]);
40
41 /* Init Fan 2 */
42 if (sb_chip->fan2_enabled)
43 for (i = 0; i < FAN_REGISTER_COUNT; i++)
44 pm2_iowrite(FAN_2_OFFSET + i, sb_chip->fan2_config_vals[i]);
45
46 /* Init Fan 3 */
47 if (sb_chip->fan3_enabled)
48 for (i = 0; i < FAN_REGISTER_COUNT; i++)
49 pm2_iowrite(FAN_3_OFFSET + i, sb_chip->fan3_config_vals[i]);
50
51 /* Init Fan 4 */
52 if (sb_chip->fan4_enabled)
53 for (i = 0; i < FAN_REGISTER_COUNT; i++)
54 pm2_iowrite(FAN_4_OFFSET + i, sb_chip->fan4_config_vals[i]);
55
56}
57
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020058void init_sb800_IMC_fans(struct device *dev)
Martin Rothe899e512012-12-05 16:07:11 -070059{
60
61 AMDSBCFG sb_config;
62 unsigned char *message_ptr;
63 int i;
64 struct southbridge_amd_cimx_sb800_config *sb_chip =
65 (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info);
66
67 /*
68 * The default I/O address of the IMC configuration register index
69 * port is 0x6E. Change the IMC Config port I/O Address if it
70 * conflicts with other components in the system.
71 *
72 * Device 20, Function 3, Reg 0xA4
73 * [0]: if 1, the address specified in IMC_PortAddress is used.
Elyes HAOUASa342f392018-10-17 10:56:26 +020074 * [15:1] IMC_PortAddress bits 15:1 (0x17 - address 0x2E)
Martin Rothe899e512012-12-05 16:07:11 -070075 */
76
77 pci_write_config16(dev, 0xA4, sb_chip->imc_port_address | 0x01);
78
79
80 /*
81 * Do an initial manual setup of the fans for things like polarity
82 * and frequency.
83 */
84 init_sb800_MANUAL_fans(dev);
85
86 /*
87 * FLAG for Func 81/83/85/89 support (1=On,0=Off)
88 * Bit0-3 = Func 81 Zone0-Zone3
89 * Bit4-7 = Func 83 Zone0-Zone3
90 * Bit8-11 = Func 85 Zone0-Zone3
91 * Bit12-15 = Func 89 Tempin Channel0-Channel3
92 */
93 sb_config.Pecstruct.IMCFUNSupportBitMap = 0;
94
95/*
96 ********** Zone 0 **********
97 */
98if (sb_chip->imc_fan_zone0_enabled) {
99
100 sb_config.Pecstruct.IMCFUNSupportBitMap |= IMC_ENABLE_ZONE0;
101
102 /* EC LDN9 function 81 zone 0 */
103 sb_config.Pecstruct.MSGFun81zone0MSGREG0 = 0x00;
104 sb_config.Pecstruct.MSGFun81zone0MSGREG1 = IMC_ZONE0;
105 message_ptr = &sb_config.Pecstruct.MSGFun81zone0MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200106 for (i = 0; i < IMC_FAN_CONFIG_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700107 *(message_ptr + i) = sb_chip->imc_zone0_config_vals[i];
108
109 /* EC LDN9 function 83 zone 0 - Temperature Thresholds */
110 sb_config.Pecstruct.MSGFun83zone0MSGREG0 = 0x00;
111 sb_config.Pecstruct.MSGFun83zone0MSGREG1 = IMC_ZONE0;
112 sb_config.Pecstruct.MSGFun83zone0MSGREGB = 0x00;
113 message_ptr = &sb_config.Pecstruct.MSGFun83zone0MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200114 for (i = 0; i < IMC_FAN_THRESHOLD_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700115 *(message_ptr + i) = sb_chip->imc_zone0_thresholds[i];
116
117 /*EC LDN9 function 85 zone 0 - Fan Speeds */
118 sb_config.Pecstruct.MSGFun85zone0MSGREG0 = 0x00;
119 sb_config.Pecstruct.MSGFun85zone0MSGREG1 = IMC_ZONE0;
120 message_ptr = &sb_config.Pecstruct.MSGFun85zone0MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200121 for (i = 0; i < IMC_FAN_SPEED_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700122 *(message_ptr + i) = sb_chip->imc_zone0_fanspeeds[i];
123
124}
125
126/*
127 ********** Zone 1 **********
128 */
129if (sb_chip->imc_fan_zone1_enabled) {
130
131 sb_config.Pecstruct.IMCFUNSupportBitMap |= IMC_ENABLE_ZONE1;
132
133 /* EC LDN9 function 81 zone 1 */
134 sb_config.Pecstruct.MSGFun81zone1MSGREG0 = 0x00;
135 sb_config.Pecstruct.MSGFun81zone1MSGREG1 = IMC_ZONE1;
136 message_ptr = &sb_config.Pecstruct.MSGFun81zone1MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200137 for (i = 0; i < IMC_FAN_CONFIG_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700138 *(message_ptr + i) = sb_chip->imc_zone1_config_vals[i];
139
140 /* EC LDN9 function 83 zone 1 - Temperature Thresholds */
141 sb_config.Pecstruct.MSGFun83zone1MSGREG0 = 0x00;
142 sb_config.Pecstruct.MSGFun83zone1MSGREG1 = IMC_ZONE1;
143 sb_config.Pecstruct.MSGFun83zone1MSGREGB = 0x00;
144 message_ptr = &sb_config.Pecstruct.MSGFun83zone1MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200145 for (i = 0; i < IMC_FAN_THRESHOLD_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700146 *(message_ptr + i) = sb_chip->imc_zone1_thresholds[i];
147
148 /* EC LDN9 function 85 zone 1 - Fan Speeds */
149 sb_config.Pecstruct.MSGFun85zone1MSGREG0 = 0x00;
150 sb_config.Pecstruct.MSGFun85zone1MSGREG1 = IMC_ZONE1;
151 message_ptr = &sb_config.Pecstruct.MSGFun85zone1MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200152 for (i = 0; i < IMC_FAN_SPEED_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700153 *(message_ptr + i) = sb_chip->imc_zone1_fanspeeds[i];
154
155}
156
157
158/*
159 ********** Zone 2 **********
160 */
161if (sb_chip->imc_fan_zone2_enabled) {
162
163 sb_config.Pecstruct.IMCFUNSupportBitMap |= IMC_ENABLE_ZONE2;
164
165 /* EC LDN9 function 81 zone 2 */
166 sb_config.Pecstruct.MSGFun81zone2MSGREG0 = 0x00;
167 sb_config.Pecstruct.MSGFun81zone2MSGREG1 = IMC_ZONE2;
168 message_ptr = &sb_config.Pecstruct.MSGFun81zone2MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200169 for (i = 0; i < IMC_FAN_CONFIG_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700170 *(message_ptr + i) = sb_chip->imc_zone2_config_vals[i];
171
172 /* EC LDN9 function 83 zone 2 */
173 sb_config.Pecstruct.MSGFun83zone2MSGREG0 = 0x00;
174 sb_config.Pecstruct.MSGFun83zone2MSGREG1 = IMC_ZONE2;
175 sb_config.Pecstruct.MSGFun83zone2MSGREGB = 0x00;
176 message_ptr = &sb_config.Pecstruct.MSGFun83zone2MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200177 for (i = 0; i < IMC_FAN_THRESHOLD_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700178 *(message_ptr + i) = sb_chip->imc_zone2_thresholds[i];
179
180 /* EC LDN9 function 85 zone 2 */
181 sb_config.Pecstruct.MSGFun85zone2MSGREG0 = 0x00;
182 sb_config.Pecstruct.MSGFun85zone2MSGREG1 = IMC_ZONE2;
183 message_ptr = &sb_config.Pecstruct.MSGFun85zone2MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200184 for (i = 0; i < IMC_FAN_SPEED_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700185 *(message_ptr + i) = sb_chip->imc_zone2_fanspeeds[i];
186
187}
188
189/*
190 ********** Zone 3 **********
191 */
192
193if (sb_chip->imc_fan_zone3_enabled) {
194
195 sb_config.Pecstruct.IMCFUNSupportBitMap |= IMC_ENABLE_ZONE3;
196
197 /* EC LDN9 function 81 zone 3 */
198 sb_config.Pecstruct.MSGFun81zone3MSGREG0 = 0x00;
199 sb_config.Pecstruct.MSGFun81zone3MSGREG1 = IMC_ZONE3;
200 message_ptr = &sb_config.Pecstruct.MSGFun81zone3MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200201 for (i = 0; i < IMC_FAN_CONFIG_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700202 *(message_ptr + i) = sb_chip->imc_zone3_config_vals[i];
203
204 /* EC LDN9 function 83 zone 3 */
205 sb_config.Pecstruct.MSGFun83zone3MSGREG0 = 0x00;
206 sb_config.Pecstruct.MSGFun83zone3MSGREG1 = IMC_ZONE3;
207 sb_config.Pecstruct.MSGFun83zone3MSGREGB = 0x00;
208 message_ptr = &sb_config.Pecstruct.MSGFun83zone3MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200209 for (i = 0; i < IMC_FAN_THRESHOLD_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700210 *(message_ptr + i) = sb_chip->imc_zone3_thresholds[i];
211
212 /* EC LDN9 function 85 zone 3 */
213 sb_config.Pecstruct.MSGFun85zone3MSGREG0 = 0x00;
214 sb_config.Pecstruct.MSGFun85zone3MSGREG1 = IMC_ZONE3;
215 message_ptr = &sb_config.Pecstruct.MSGFun85zone3MSGREG2;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200216 for (i = 0; i < IMC_FAN_SPEED_COUNT; i++)
Martin Rothe899e512012-12-05 16:07:11 -0700217 *(message_ptr + i) = sb_chip->imc_zone3_fanspeeds[i];
218
219}
220
221 /*
Martin Roth3c3a50c2014-12-16 20:50:26 -0700222 * EC LDN9 function 89 - Set HWM TEMPIN Temperature Calculation Parameters
Martin Rothe899e512012-12-05 16:07:11 -0700223 * This function provides the critical parameters of the HWM TempIn
224 * sensors, IMC would not perform temperature measurement using those
225 * sensors until the parameters are provided.
226 */
227
228if (sb_chip->imc_tempin0_enabled) {
229
230 sb_config.Pecstruct.IMCFUNSupportBitMap |= IMC_ENABLE_TEMPIN0;
231
Martin Roth3c3a50c2014-12-16 20:50:26 -0700232 /* EC LDN9 function 89 TEMPIN channel 0 */
Martin Rothe899e512012-12-05 16:07:11 -0700233 sb_config.Pecstruct.MSGFun89zone0MSGREG0 = 0x00;
234 sb_config.Pecstruct.MSGFun89zone0MSGREG1 = 0x00;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200235 sb_config.Pecstruct.MSGFun89zone0MSGREG2 = (sb_chip->imc_tempin0_at & 0xff);
Martin Rothe899e512012-12-05 16:07:11 -0700236 sb_config.Pecstruct.MSGFun89zone0MSGREG3 = ((sb_chip->imc_tempin0_at >> 8) & 0xff);
237 sb_config.Pecstruct.MSGFun89zone0MSGREG4 = ((sb_chip->imc_tempin0_at >> 16) & 0xff);
238 sb_config.Pecstruct.MSGFun89zone0MSGREG5 = ((sb_chip->imc_tempin0_at >> 24) & 0xff);
Elyes HAOUASa342f392018-10-17 10:56:26 +0200239 sb_config.Pecstruct.MSGFun89zone0MSGREG6 = (sb_chip->imc_tempin0_ct & 0xff);
Martin Rothe899e512012-12-05 16:07:11 -0700240 sb_config.Pecstruct.MSGFun89zone0MSGREG7 = ((sb_chip->imc_tempin0_ct >> 8) & 0xff);
241 sb_config.Pecstruct.MSGFun89zone0MSGREG8 = ((sb_chip->imc_tempin0_ct >> 16) & 0xff);
242 sb_config.Pecstruct.MSGFun89zone0MSGREG9 = ((sb_chip->imc_tempin0_ct >> 24) & 0xff);
243 sb_config.Pecstruct.MSGFun89zone0MSGREGA = sb_chip->imc_tempin0_tuning_param;
244}
245
246if (sb_chip->imc_tempin1_enabled) {
247
248 sb_config.Pecstruct.IMCFUNSupportBitMap |= IMC_ENABLE_TEMPIN1;
249
Martin Roth3c3a50c2014-12-16 20:50:26 -0700250 /* EC LDN9 function 89 TEMPIN channel 1 */
Martin Rothe899e512012-12-05 16:07:11 -0700251 sb_config.Pecstruct.MSGFun89zone1MSGREG0 = 0x00;
252 sb_config.Pecstruct.MSGFun89zone1MSGREG1 = 0x01;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200253 sb_config.Pecstruct.MSGFun89zone1MSGREG2 = (sb_chip->imc_tempin1_at & 0xff);
Martin Rothe899e512012-12-05 16:07:11 -0700254 sb_config.Pecstruct.MSGFun89zone1MSGREG3 = ((sb_chip->imc_tempin1_at >> 8) & 0xff);
255 sb_config.Pecstruct.MSGFun89zone1MSGREG4 = ((sb_chip->imc_tempin1_at >> 16) & 0xff);
256 sb_config.Pecstruct.MSGFun89zone1MSGREG5 = ((sb_chip->imc_tempin1_at >> 24) & 0xff);
Elyes HAOUASa342f392018-10-17 10:56:26 +0200257 sb_config.Pecstruct.MSGFun89zone1MSGREG6 = (sb_chip->imc_tempin1_ct & 0xff);
Martin Rothe899e512012-12-05 16:07:11 -0700258 sb_config.Pecstruct.MSGFun89zone1MSGREG7 = ((sb_chip->imc_tempin1_ct >> 8) & 0xff);
259 sb_config.Pecstruct.MSGFun89zone1MSGREG8 = ((sb_chip->imc_tempin1_ct >> 16) & 0xff);
260 sb_config.Pecstruct.MSGFun89zone1MSGREG9 = ((sb_chip->imc_tempin1_ct >> 24) & 0xff);
261 sb_config.Pecstruct.MSGFun89zone1MSGREGA = sb_chip->imc_tempin1_tuning_param;
262}
263
264if (sb_chip->imc_tempin2_enabled) {
265
266 sb_config.Pecstruct.IMCFUNSupportBitMap |= IMC_ENABLE_TEMPIN2;
267
Martin Roth3c3a50c2014-12-16 20:50:26 -0700268 /* EC LDN9 function 89 TEMPIN channel 2 */
Martin Rothe899e512012-12-05 16:07:11 -0700269 sb_config.Pecstruct.MSGFun89zone2MSGREG0 = 0x00;
270 sb_config.Pecstruct.MSGFun89zone2MSGREG1 = 0x02;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200271 sb_config.Pecstruct.MSGFun89zone2MSGREG2 = (sb_chip->imc_tempin2_at & 0xff);
Martin Rothe899e512012-12-05 16:07:11 -0700272 sb_config.Pecstruct.MSGFun89zone2MSGREG3 = ((sb_chip->imc_tempin2_at >> 8) & 0xff);
273 sb_config.Pecstruct.MSGFun89zone2MSGREG4 = ((sb_chip->imc_tempin2_at >> 16) & 0xff);
274 sb_config.Pecstruct.MSGFun89zone2MSGREG5 = ((sb_chip->imc_tempin2_at >> 24) & 0xff);
Elyes HAOUASa342f392018-10-17 10:56:26 +0200275 sb_config.Pecstruct.MSGFun89zone2MSGREG6 = (sb_chip->imc_tempin2_ct & 0xff);
Martin Rothe899e512012-12-05 16:07:11 -0700276 sb_config.Pecstruct.MSGFun89zone2MSGREG7 = ((sb_chip->imc_tempin2_ct >> 8) & 0xff);
277 sb_config.Pecstruct.MSGFun89zone2MSGREG8 = ((sb_chip->imc_tempin2_ct >> 16) & 0xff);
278 sb_config.Pecstruct.MSGFun89zone2MSGREG9 = ((sb_chip->imc_tempin2_ct >> 24) & 0xff);
279 sb_config.Pecstruct.MSGFun89zone2MSGREGA = sb_chip->imc_tempin2_tuning_param;
280}
281
282if (sb_chip->imc_tempin3_enabled) {
283
284 sb_config.Pecstruct.IMCFUNSupportBitMap |= IMC_ENABLE_TEMPIN3;
285
Martin Roth3c3a50c2014-12-16 20:50:26 -0700286 /* EC LDN9 function 89 TEMPIN channel 3 */
Martin Rothe899e512012-12-05 16:07:11 -0700287 sb_config.Pecstruct.MSGFun89zone3MSGREG0 = 0x00;
288 sb_config.Pecstruct.MSGFun89zone3MSGREG1 = 0x03;
Elyes HAOUASa342f392018-10-17 10:56:26 +0200289 sb_config.Pecstruct.MSGFun89zone3MSGREG2 = (sb_chip->imc_tempin3_at & 0xff);
Martin Rothe899e512012-12-05 16:07:11 -0700290 sb_config.Pecstruct.MSGFun89zone3MSGREG3 = ((sb_chip->imc_tempin3_at >> 8) & 0xff);
291 sb_config.Pecstruct.MSGFun89zone3MSGREG4 = ((sb_chip->imc_tempin3_at >> 16) & 0xff);
292 sb_config.Pecstruct.MSGFun89zone3MSGREG5 = ((sb_chip->imc_tempin3_at >> 24) & 0xff);
Elyes HAOUASa342f392018-10-17 10:56:26 +0200293 sb_config.Pecstruct.MSGFun89zone3MSGREG6 = (sb_chip->imc_tempin3_ct & 0xff);
Martin Rothe899e512012-12-05 16:07:11 -0700294 sb_config.Pecstruct.MSGFun89zone3MSGREG7 = ((sb_chip->imc_tempin3_ct >> 8) & 0xff);
295 sb_config.Pecstruct.MSGFun89zone3MSGREG8 = ((sb_chip->imc_tempin3_ct >> 16) & 0xff);
296 sb_config.Pecstruct.MSGFun89zone3MSGREG9 = ((sb_chip->imc_tempin3_ct >> 24) & 0xff);
297 sb_config.Pecstruct.MSGFun89zone3MSGREGA = sb_chip->imc_tempin3_tuning_param;
298}
299
300 /* Set up the sb_config structure for the fan control initialization */
301 sb_config.StdHeader.Func = SB_EC_FANCONTROL;
302
303 AmdSbDispatcher(&sb_config);
304
305 return;
306}