| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <delay.h> |
| 5 |
|
| 6 |
#include "chip.h" |
| 7 |
#include "nct6687d_hwm.h" |
| 8 |
|
| 9 |
uint16_t nct6687d_hwm_base = 0; |
| 10 |
|
| 11 |
static bool check_cond(const bool cond, const char *error) |
| 12 |
{ |
| 13 |
if (!cond) |
| 14 |
printk(BIOS_ERR, "NCT6687D: %s\n", error); |
| 15 |
|
| 16 |
return !cond; |
| 17 |
} |
| 18 |
|
| 19 |
static inline void print_status_bit(const char *status, const bool cond) |
| 20 |
{ |
| 21 |
printk(BIOS_DEBUG, "\t%-45s: %s\n", status, cond ? "yes" : "no"); |
| 22 |
} |
| 23 |
|
| 24 |
static void print_fan_engine_status(void) |
| 25 |
{ |
| 26 |
uint8_t fan_eng_sts = hwm_reg_read(FAN_ENGINE_STS_REG); |
| 27 |
|
| 28 |
printk(BIOS_DEBUG, "NCT6687D: Fan Engine Status:\n"); |
| 29 |
print_status_bit("PECI configuration adjusted", fan_eng_sts & FAN_PECI_CFG_ADJUSTED); |
| 30 |
print_status_bit("All enabled fan channels processed", |
| 31 |
fan_eng_sts & FAN_UNFINISHED_FLAG); |
| 32 |
print_status_bit("Configuration phase", fan_eng_sts & FAN_CFG_PHASE); |
| 33 |
print_status_bit("Configuration invalid", fan_eng_sts & FAN_CFG_INVALID); |
| 34 |
print_status_bit("Configuration check done", fan_eng_sts & FAN_CFG_CHECK_DONE); |
| 35 |
print_status_bit("Configuration locked", fan_eng_sts & FAN_CFG_LOCK); |
| 36 |
printk(BIOS_DEBUG, "Fans in automatic mode driven by %s register\n", |
| 37 |
(fan_eng_sts & FAN_DRIVE_BY_DEFAULT_VAL) ? "DEFAULT_VAL" : "MOD_SEL"); |
| 38 |
} |
| 39 |
|
| 40 |
static bool unlock_fan_register_set(void) |
| 41 |
{ |
| 42 |
uint8_t fan_eng_sts; |
| 43 |
bool done = false; |
| 44 |
unsigned int i; |
| 45 |
|
| 46 |
fan_eng_sts = hwm_reg_read(FAN_ENGINE_STS_REG); |
| 47 |
|
| 48 |
if (!(fan_eng_sts & FAN_CFG_LOCK) && (fan_eng_sts & FAN_CFG_PHASE)) |
| 49 |
return true; |
| 50 |
|
| 51 |
for (i = 1000; i > 0; i--) { |
| 52 |
|
| 53 |
if ((hwm_reg_read(FAN_ENGINE_STS_REG) & FAN_CFG_PHASE) == 0 && |
| 54 |
(hwm_reg_read(FAN_CFG_CTRL_REG) & FAN_CFG_REQUEST) == 0) { |
| 55 |
done = true; |
| 56 |
break; |
| 57 |
} |
| 58 |
mdelay(1); |
| 59 |
} |
| 60 |
|
| 61 |
if (!done) { |
| 62 |
printk(BIOS_WARNING, "Timeout waiting for EC to exit config phase or clear" |
| 63 |
"config request\n"); |
| 64 |
print_fan_engine_status(); |
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
done = false; |
| 69 |
|
| 70 |
hwm_reg_write(FAN_CFG_CTRL_REG, FAN_CFG_REQUEST); |
| 71 |
|
| 72 |
for (i = 1000; i > 0; i--) { |
| 73 |
|
| 74 |
if ((hwm_reg_read(FAN_ENGINE_STS_REG) & FAN_CFG_LOCK) == 0) { |
| 75 |
done = true; |
| 76 |
break; |
| 77 |
} |
| 78 |
mdelay(1); |
| 79 |
} |
| 80 |
|
| 81 |
if (!done) { |
| 82 |
printk(BIOS_WARNING, "Timeout waiting for EC to unlock the fan registers\n"); |
| 83 |
print_fan_engine_status(); |
| 84 |
return false; |
| 85 |
} |
| 86 |
|
| 87 |
return true; |
| 88 |
} |
| 89 |
|
| 90 |
static void print_last_err(uint8_t error_code) |
| 91 |
{ |
| 92 |
uint8_t debug_level = BIOS_WARNING; |
| 93 |
uint8_t last_err_code = hwm_reg_read(FAN_LAST_ERROR_CODE_REG); |
| 94 |
|
| 95 |
if (last_err_code == FAN_NO_ERROR) { |
| 96 |
printk(BIOS_DEBUG, "No error occurred.\n"); |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
if (last_err_code == error_code) |
| 102 |
debug_level = BIOS_ERR; |
| 103 |
|
| 104 |
switch (last_err_code) { |
| 105 |
case FAN_ERR_MODE_SELECT: |
| 106 |
printk(debug_level, "Mode Select invalid configuration\n"); |
| 107 |
break; |
| 108 |
case FAN_ERR_CRIT_TEMP_PROTECT: |
| 109 |
printk(debug_level, "Critical Temperature Protection invalid configuration\n"); |
| 110 |
break; |
| 111 |
case FAN_ERR_ITL_FAN_CONTROL: |
| 112 |
printk(debug_level, "Intel DTS Sensor invalid configuration\n"); |
| 113 |
break; |
| 114 |
case FAN_ERR_SMART_TRACKING: |
| 115 |
printk(debug_level, "Smart Tracking invalid configuration\n"); |
| 116 |
break; |
| 117 |
case FAN_ERR_THERMAL_CRUISE: |
| 118 |
printk(debug_level, "Thermal Cruise invalid configuration\n"); |
| 119 |
break; |
| 120 |
case FAN_ERR_SPEED_CRUISE: |
| 121 |
printk(debug_level, "Speed Cruise invalid configuration\n"); |
| 122 |
break; |
| 123 |
case FAN_ERR_SMART_FAN_IV: |
| 124 |
printk(debug_level, "Smart Fan IV invalid configuration\n"); |
| 125 |
break; |
| 126 |
case FAN_ERR_PID_CONTROL: |
| 127 |
printk(debug_level, "PID control invalid configuration\n"); |
| 128 |
break; |
| 129 |
default: |
| 130 |
printk(debug_level, "Unknown fan configuration error %02x\n", last_err_code); |
| 131 |
break; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
static void lock_fan_register_set_and_check(uint8_t error_code) |
| 136 |
{ |
| 137 |
uint8_t fan_eng_sts; |
| 138 |
bool done = false; |
| 139 |
unsigned int i; |
| 140 |
|
| 141 |
fan_eng_sts = hwm_reg_read(FAN_ENGINE_STS_REG); |
| 142 |
|
| 143 |
if (fan_eng_sts & FAN_CFG_LOCK || !(fan_eng_sts & FAN_CFG_PHASE)) { |
| 144 |
printk(BIOS_DEBUG, "Fan register set already locked or not in config phase\n"); |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
hwm_reg_write(FAN_CFG_CTRL_REG, FAN_CFG_DONE); |
| 149 |
|
| 150 |
for (i = 1000; i > 0; i--) { |
| 151 |
fan_eng_sts = hwm_reg_read(FAN_ENGINE_STS_REG); |
| 152 |
|
| 153 |
if (fan_eng_sts & FAN_CFG_CHECK_DONE) { |
| 154 |
done = true; |
| 155 |
break; |
| 156 |
} |
| 157 |
mdelay(1); |
| 158 |
} |
| 159 |
|
| 160 |
if (!done) { |
| 161 |
printk(BIOS_WARNING, "Timeout waiting for configuration check done\n"); |
| 162 |
print_fan_engine_status(); |
| 163 |
return; |
| 164 |
} |
| 165 |
|
| 166 |
fan_eng_sts = hwm_reg_read(FAN_ENGINE_STS_REG); |
| 167 |
|
| 168 |
if (fan_eng_sts & FAN_CFG_INVALID) { |
| 169 |
printk(BIOS_WARNING, "NCT6687D: Configuration error ocurred\n"); |
| 170 |
print_last_err(error_code); |
| 171 |
} |
| 172 |
|
| 173 |
if (!(fan_eng_sts & FAN_CFG_LOCK)) { |
| 174 |
printk(BIOS_WARNING, "NCT6687D: Configuration registers did not lock\n"); |
| 175 |
print_fan_engine_status(); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
static void init_pch_smbus_sensor(const struct nct6687d_pch_smbus_sensor *smbus_sensor) |
| 180 |
{ |
| 181 |
if (!smbus_sensor->sensor_addr || !smbus_sensor->sensor_cmd) { |
| 182 |
printk(BIOS_ERR, "NCT6687D SMBus sensor CMD or ADDR missing!\n"); |
| 183 |
return; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
hwm_reg_write(SMBUS_MASTER_CFG2_REG, 0x04); |
| 188 |
hwm_reg_write(SMBUS_MASTER_BAUD_RATE_SEL_REG, SMB_MASTER_BAUD_100K); |
| 189 |
hwm_reg_set_bits(SMBUS_MASTER_CFG1_REG, SMB_MASTER_EN); |
| 190 |
|
| 191 |
hwm_reg_and_or(PCH_THERMAL_DATA_CFG_REG, ~PCH_BAUD_SEL_MASK, |
| 192 |
smbus_sensor->baud_rate & PCH_BAUD_SEL_MASK); |
| 193 |
hwm_reg_and_or(PCH_THERMAL_DATA_CFG_REG, ~PCH_PORT_SEL_MASK, |
| 194 |
PCH_THERMAL_PORT(smbus_sensor->port_sel) & PCH_PORT_SEL_MASK); |
| 195 |
|
| 196 |
if (smbus_sensor->report_one_byte) |
| 197 |
hwm_reg_set_bits(PCH_THERMAL_DATA_CFG_REG, PCH_ONE_BYTE_REPORT); |
| 198 |
else |
| 199 |
hwm_reg_and_or(PCH_THERMAL_DATA_CFG_REG, ~PCH_ONE_BYTE_REPORT & 0xff, 0); |
| 200 |
|
| 201 |
|
| 202 |
hwm_reg_write(PCH_DEVICE_ADDR_REG, smbus_sensor->sensor_addr); |
| 203 |
hwm_reg_write(PCH_THERMAL_CMD_REG, smbus_sensor->sensor_cmd); |
| 204 |
} |
| 205 |
|
| 206 |
static void init_sensors(const struct superio_nuvoton_nct6687d_config *conf) |
| 207 |
{ |
| 208 |
unsigned int i; |
| 209 |
bool peci_en = false; |
| 210 |
const enum nct6687d_sensor_src_select *sensors = conf->sensors; |
| 211 |
|
| 212 |
if (!unlock_fan_register_set()) { |
| 213 |
printk(BIOS_ERR, "NCT6687D failed to unlock registers, " |
| 214 |
"skipping sensors programming\n"); |
| 215 |
return; |
| 216 |
} |
| 217 |
|
| 218 |
printk(BIOS_DEBUG, "NCT6687D programming sensors\n"); |
| 219 |
|
| 220 |
hwm_reg_set_bits(HWM_CONFIG_REG, HWM_EN); |
| 221 |
|
| 222 |
for (i = 0; i < MAX_NUM_SENSORS; i++) { |
| 223 |
hwm_reg_write(SENSOR_CFG_REG(i), sensors[i] & SENSOR_SRC_SEL_MASK); |
| 224 |
|
| 225 |
if (sensors[i] >= PECI_AGENT0_DOMAIN0 && |
| 226 |
sensors[i] <= PECI_AGENT3_DOMAIN1) { |
| 227 |
hwm_reg_and_or(PECI_AGENT_EN_REG, ~PECI_AGENT_EN_MASK, |
| 228 |
PECI_AGENT_EN(sensors[i] & 0x3)); |
| 229 |
peci_en = true; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
if (sensors[i] >= PCH_CPU && sensors[i] <= PCH_DIMM3 && |
| 234 |
i == conf->smbus_sensor.sensor_idx && |
| 235 |
conf->smbus_sensor.sensor_en) { |
| 236 |
init_pch_smbus_sensor(&conf->smbus_sensor); |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
if (peci_en) { |
| 241 |
hwm_reg_and_or(PECI_CFG_REG, PECI_SPEED_SEL_MASK, |
| 242 |
conf->peci_speed & PECI_SPEED_SEL_MASK); |
| 243 |
hwm_reg_set_bits(PECI_CFG_REG, PECI_AGENT_INIT | PECI_EN); |
| 244 |
} |
| 245 |
|
| 246 |
lock_fan_register_set_and_check(FAN_NO_ERROR); |
| 247 |
} |
| 248 |
|
| 249 |
static bool intel_dts_sensor_control_point_check(const struct nct6687d_dts_sensor_config *dts, |
| 250 |
unsigned int i) |
| 251 |
{ |
| 252 |
bool failure = false; |
| 253 |
|
| 254 |
failure |= check_cond(dts->ambient_temp[i] <= 127, |
| 255 |
"DTS Sensor Ambient Temperature Levels should be <= 127"); |
| 256 |
|
| 257 |
if (i < MAX_DTS_CTL_POINTS - 1) { |
| 258 |
failure |= check_cond(dts->ambient_temp[i + 1] >= dts->ambient_temp[i], |
| 259 |
"DTS Sensor next Ambient Temperature Level must be " |
| 260 |
"higher or equal to previous Ambient Temperature Level"); |
| 261 |
failure |= check_cond(dts->rpm_start_point[i + 1] > dts->rpm_start_point[i], |
| 262 |
"DTS Sensor next RPM Start Point must be higher than " |
| 263 |
"previous RPM Start Point"); |
| 264 |
failure |= check_cond(dts->rpm_end_point[i + 1] > dts->rpm_end_point[i], |
| 265 |
"DTS Sensor next RPM End Point must be higher than " |
| 266 |
"previous RPM End Point"); |
| 267 |
} |
| 268 |
|
| 269 |
failure |= check_cond(dts->rpm_end_point[i] > dts->rpm_start_point[i], |
| 270 |
"DTS Sensor RPM End Point must be higher than corresponding RPM " |
| 271 |
"Start Point"); |
| 272 |
|
| 273 |
return failure; |
| 274 |
} |
| 275 |
|
| 276 |
static bool intel_dts_sensor_config_check(const struct nct6687d_dts_sensor_config *dts) |
| 277 |
{ |
| 278 |
bool failure = false; |
| 279 |
unsigned int i; |
| 280 |
|
| 281 |
failure |= check_cond(dts->temp_end > dts->temp_start, |
| 282 |
"DTS Sensor Temperature End Point should be > " |
| 283 |
"Temperature End Point"); |
| 284 |
failure |= check_cond(dts->temp_start <= 127, |
| 285 |
"DTS Sensor Temperature Start Point should be <= 127"); |
| 286 |
failure |= check_cond(dts->temp_end <= 127, |
| 287 |
"DTS Sensor Temperature End Point should be <= 127"); |
| 288 |
|
| 289 |
if (dts->peci_adjust) { |
| 290 |
failure |= check_cond(dts->peci_agent_idx < 8, |
| 291 |
"DTS Sensor PECI Agent Index should be < 8"); |
| 292 |
} |
| 293 |
|
| 294 |
for (i = 0; i < MAX_DTS_CTL_POINTS; i++) |
| 295 |
failure |= intel_dts_sensor_control_point_check(dts, i); |
| 296 |
|
| 297 |
return failure; |
| 298 |
} |
| 299 |
|
| 300 |
static void init_intel_dts_sensor(const struct nct6687d_dts_sensor_config *dts) |
| 301 |
{ |
| 302 |
static int init_once = 0; |
| 303 |
unsigned int i; |
| 304 |
|
| 305 |
if (init_once) |
| 306 |
return; |
| 307 |
|
| 308 |
if (intel_dts_sensor_config_check(dts)) { |
| 309 |
printk(BIOS_ERR, "NCT6687D DTS Sensor invalid config, " |
| 310 |
"skipping sensor programming\n"); |
| 311 |
return; |
| 312 |
} |
| 313 |
|
| 314 |
printk(BIOS_DEBUG, "NCT6687D programming DTS sensor\n"); |
| 315 |
|
| 316 |
hwm_reg_write(ITL_TEMP_START_POINT_REG, dts->temp_start); |
| 317 |
hwm_reg_write(ITL_TEMP_END_POINT_REG, dts->temp_end); |
| 318 |
|
| 319 |
hwm_reg_write(ITL_RPM_MAX_SPEED_HI_REG, dts->max_speed >> 8); |
| 320 |
hwm_reg_write(ITL_RPM_MAX_SPEED_LO_REG, dts->max_speed & 0xff); |
| 321 |
|
| 322 |
for (i = 0; i < MAX_DTS_CTL_POINTS; i++) { |
| 323 |
hwm_reg_write(ITL_AMB_TEMP_START_POINT_REG(i), dts->ambient_temp[i]); |
| 324 |
hwm_reg_write(ITL_RPM_START_POINT_HI_REG(i), dts->rpm_start_point[i] >> 8); |
| 325 |
hwm_reg_write(ITL_RPM_START_POINT_LO_REG(i), dts->rpm_start_point[i] & 0xff); |
| 326 |
hwm_reg_write(ITL_RPM_END_POINT_HI_REG(i), dts->rpm_end_point[i] >> 8); |
| 327 |
hwm_reg_write(ITL_RPM_END_POINT_LO_REG(i), dts->rpm_end_point[i] & 0xff); |
| 328 |
} |
| 329 |
|
| 330 |
if (dts->peci_adjust) { |
| 331 |
hwm_reg_and_or(ITL_DTS_CFG_REG, ~ITL_DTS_PECI_AGENT_IDX_SEL_MASK, |
| 332 |
dts->peci_agent_idx & ITL_DTS_PECI_AGENT_IDX_SEL_MASK); |
| 333 |
hwm_reg_set_bits(ITL_DTS_CFG_REG, ITL_DTS_PECI_CFG_ADJUSTMENT); |
| 334 |
} |
| 335 |
|
| 336 |
init_once = 1; |
| 337 |
} |
| 338 |
|
| 339 |
static void init_intel_dts2_sensor(const struct nct6687d_dts2_sensor_config *dts2) |
| 340 |
{ |
| 341 |
static int init_once = 0; |
| 342 |
|
| 343 |
if (init_once) |
| 344 |
return; |
| 345 |
|
| 346 |
printk(BIOS_DEBUG, "NCT6687D programming DTS2 sensor\n"); |
| 347 |
|
| 348 |
hwm_reg_write(DTS2_TARGET_MARGIN_REG, (uint8_t)dts2->target_margin); |
| 349 |
hwm_reg_write(DTS2_TCONTROL_REG, (uint8_t)dts2->t_control); |
| 350 |
hwm_reg_write(DTS2_TCONTROL_OFFSET_REG, (uint8_t)dts2->t_control_offset); |
| 351 |
hwm_reg_write(DTS2_TARGET_TOLERANCE_REG, dts2->target_margin_tolerance); |
| 352 |
|
| 353 |
hwm_reg_write(DTS2_STEP_SPEED_HI_REG, dts2->step_speed >> 8); |
| 354 |
hwm_reg_write(DTS2_STEP_SPEED_LO_REG, dts2->step_speed & 0xff); |
| 355 |
hwm_reg_write(DTS2_MIN_SPEED_HI_REG, dts2->min_speed >> 8); |
| 356 |
hwm_reg_write(DTS2_MIN_SPEED_LO_REG, dts2->min_speed & 0xff); |
| 357 |
|
| 358 |
hwm_reg_write(DTS2_DELAY_TIME_COUNTER_REG, dts2->delay_time); |
| 359 |
hwm_reg_write(DTS2_DIVISOR_REG, dts2->divisor); |
| 360 |
|
| 361 |
init_once = 1; |
| 362 |
} |
| 363 |
|
| 364 |
static void lock_sensor_config(void) |
| 365 |
{ |
| 366 |
if (!unlock_fan_register_set()) { |
| 367 |
printk(BIOS_ERR, "NCT6687D failed to unlock registers, " |
| 368 |
"skipping misc fan config programming\n"); |
| 369 |
return; |
| 370 |
} |
| 371 |
hwm_reg_set_bits(HWM_CONFIG_REG, LOCK_SENSOR_CFG); |
| 372 |
lock_fan_register_set_and_check(FAN_NO_ERROR); |
| 373 |
} |
| 374 |
|
| 375 |
static void init_ambient_floor_alg(const struct superio_nuvoton_nct6687d_config *conf, |
| 376 |
unsigned int idx) |
| 377 |
{ |
| 378 |
static int init_once = 0; |
| 379 |
const struct nct6687d_ambient_floor_fan_config *amb_floor_fan; |
| 380 |
const struct nct6687d_ambient_floor_config *amb_floor_cfg = &conf->ambient_floor; |
| 381 |
|
| 382 |
amb_floor_fan = &conf->fans[idx - 1].amb_floor_fan_cfg; |
| 383 |
|
| 384 |
printk(BIOS_DEBUG, "NCT6687D initializing ambient floor algorithm\n"); |
| 385 |
|
| 386 |
if (!init_once) { |
| 387 |
hwm_reg_write(AMBIENT_FLOOR_TEMP_START_POINT_REG, amb_floor_cfg->temp_start); |
| 388 |
hwm_reg_write(AMBIENT_FLOOR_TEMP_END_POINT_REG, amb_floor_cfg->temp_end); |
| 389 |
init_once = 1; |
| 390 |
} |
| 391 |
|
| 392 |
hwm_reg_write(FAN_AMB_FLOOR_MIN_OUT_START_REG(idx), |
| 393 |
FAN_AMB_FLOOR_RPM_TO_REG(amb_floor_fan->minout_start)); |
| 394 |
hwm_reg_write(FAN_AMB_FLOOR_MIN_OUT_END_REG(idx), |
| 395 |
FAN_AMB_FLOOR_RPM_TO_REG(amb_floor_fan->minout_end)); |
| 396 |
hwm_reg_write(FAN_AMB_FLOOR_MAX_OUT_REG(idx), |
| 397 |
FAN_AMB_FLOOR_RPM_TO_REG(amb_floor_fan->minout_max)); |
| 398 |
} |
| 399 |
|
| 400 |
static void init_smart_tracking_alg(const struct superio_nuvoton_nct6687d_config *conf, |
| 401 |
unsigned int idx) |
| 402 |
{ |
| 403 |
static int init_once = 0; |
| 404 |
const struct nct6687d_fan_config *fan = &conf->fans[idx - 1]; |
| 405 |
const struct nct6687d_smart_tracking_config *smart_track = &conf->smart_tracking; |
| 406 |
|
| 407 |
printk(BIOS_DEBUG, "NCT6687D initializing smart tracking algorithm\n"); |
| 408 |
|
| 409 |
if (!init_once) { |
| 410 |
hwm_reg_write(FAN_LOW_RPM_SPEED_BOUNDARY_HI_REG, |
| 411 |
smart_track->speed_boundary_low >> 8); |
| 412 |
hwm_reg_write(FAN_LOW_RPM_SPEED_BOUNDARY_LO_REG, |
| 413 |
smart_track->speed_boundary_low & 0xff); |
| 414 |
hwm_reg_write(FAN_HIGH_RPM_SPEED_BOUNDARY_HI_REG, |
| 415 |
smart_track->speed_boundary_high >> 8); |
| 416 |
hwm_reg_write(FAN_HIGH_RPM_SPEED_BOUNDARY_LO_REG, |
| 417 |
smart_track->speed_boundary_high & 0xff); |
| 418 |
hwm_reg_write(FAN_LOW_RPM_TOLERANCE_REG, smart_track->rpm_tolerance_low); |
| 419 |
hwm_reg_write(FAN_MID_RPM_TOLERANCE_REG, smart_track->rpm_tolerance_mid); |
| 420 |
hwm_reg_write(FAN_HIGH_RPM_TOLERANCE_REG, smart_track->rpm_tolerance_high); |
| 421 |
|
| 422 |
hwm_reg_write(FAN_TRACKING_STEP_REG, ((smart_track->step_up & 0xf) << 4) | |
| 423 |
(smart_track->step_down & 0xf)); |
| 424 |
|
| 425 |
hwm_reg_write(FAN_FAST_TRACK_TEMP_BOUNDARY_REG, smart_track->temp_boundary); |
| 426 |
|
| 427 |
hwm_reg_write(FAN_LOW_RPM_FAST_TRACK_WEIGHT_REG, |
| 428 |
((smart_track->weight_up_low & 7) << 4) | |
| 429 |
(smart_track->weight_down_low & 7)); |
| 430 |
hwm_reg_write(FAN_MID_RPM_FAST_TRACK_WEIGHT_REG, |
| 431 |
((smart_track->weight_up_mid & 7) << 4) | |
| 432 |
(smart_track->weight_down_mid & 7)); |
| 433 |
hwm_reg_write(FAN_HIGH_RPM_FAST_TRACK_WEIGHT_REG, |
| 434 |
((smart_track->weight_up_high & 7) << 4) | |
| 435 |
(smart_track->weight_down_high & 7)); |
| 436 |
|
| 437 |
hwm_reg_write(FAN_LOW_RPM_FAST_TRACK_DUTY_STEP_REG, |
| 438 |
smart_track->duty_step_low & 0xf); |
| 439 |
hwm_reg_write(FAN_MID_RPM_FAST_TRACK_DUTY_STEP_REG, |
| 440 |
smart_track->duty_step_mid & 0xf); |
| 441 |
hwm_reg_write(FAN_HIGH_RPM_FAST_TRACK_DUTY_STEP_REG, |
| 442 |
smart_track->duty_step_high & 0xf); |
| 443 |
|
| 444 |
hwm_reg_write(FAN_MARKUP_TRACK_AMB_TEMP_BOUNDARY_REG, |
| 445 |
smart_track->ambient_temp_boundary); |
| 446 |
|
| 447 |
hwm_reg_write(FAN_MARKUP_TRACK_WEIGHT_REG, smart_track->weight_val & 7); |
| 448 |
|
| 449 |
init_once = 1; |
| 450 |
} |
| 451 |
|
| 452 |
if (fan->fast_tracking_en) |
| 453 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_FAST_TRACK_EN); |
| 454 |
|
| 455 |
|
| 456 |
if (fan->markup_tracking_en) |
| 457 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_MARKUP_TRACK_EN); |
| 458 |
} |
| 459 |
|
| 460 |
static void misc_fan_config(const struct superio_nuvoton_nct6687d_config *conf, |
| 461 |
unsigned int idx) |
| 462 |
{ |
| 463 |
const struct nct6687d_fan_config *fan = &conf->fans[idx - 1]; |
| 464 |
|
| 465 |
if (!unlock_fan_register_set()) { |
| 466 |
printk(BIOS_ERR, "NCT6687D failed to unlock registers, " |
| 467 |
"skipping misc fan config programming\n"); |
| 468 |
return; |
| 469 |
} |
| 470 |
|
| 471 |
if (fan->fan_alg_weight) { |
| 472 |
printk(BIOS_DEBUG, "Programming algorithm weight for FAN%d\n", idx); |
| 473 |
hwm_reg_and_or(FAN_ALG_ENGINE_WEIGHT_VAL_REG(idx), |
| 474 |
~FAN_ALG_ENGINE_WEIGHT_MASK(idx), |
| 475 |
(fan->fan_alg_weight & 0xf) << |
| 476 |
FAN_ALG_ENGINE_WEIGHT_SHIFT(idx)); |
| 477 |
hwm_reg_set_bits(FAN_ALG_ENGINE_WEIGHT_EN_REG(idx), |
| 478 |
FAN_ALG_ENGINE_WEIGHT_CHANNEL_EN(idx)); |
| 479 |
hwm_reg_set_bits(FAN_ALG_FUNCTRL_REG(idx), FAN_ALG_FUNCTRL_ALG_EN); |
| 480 |
} |
| 481 |
|
| 482 |
if (fan->crit_temp) { |
| 483 |
if (!check_cond(fan->crit_temp >= fan->crit_temp_tolerance, |
| 484 |
"Fan Critical Temperature should be >= " |
| 485 |
"Critical Temperature Tolerance")) { |
| 486 |
printk(BIOS_DEBUG, "Enabling critical temperature for FAN%d\n", idx); |
| 487 |
hwm_reg_write(FAN_CRIT_TEMP_CFG_REG(idx), fan->crit_temp & 0x7f); |
| 488 |
if (fan->crit_temp_tolerance) |
| 489 |
hwm_reg_write(FAN_CRIT_TEMP_TOLERANCE_REG(idx), |
| 490 |
fan->crit_temp_tolerance & 0xf); |
| 491 |
|
| 492 |
hwm_reg_set_bits(FAN_ALG_FUNCTRL_REG(idx), |
| 493 |
FAN_ALG_FUNCTRL_CRIT_TEMP_EN); |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
if (fan->temp_err_duty) { |
| 498 |
hwm_reg_write(FAN_TEMP_ERR_DUTY_VAL_REG(idx), fan->temp_err_duty); |
| 499 |
hwm_reg_set_bits(FAN_ALG_FUNCTRL_REG(idx), FAN_ALG_FUNCTRL_TEMP_ERR); |
| 500 |
} |
| 501 |
|
| 502 |
if (fan->dts1_en && fan->dts2_en) { |
| 503 |
printk(BIOS_ERR, "DTS and DTS2 sensors can't coexist!\n"); |
| 504 |
printk(BIOS_ERR, "Skipping DTS configuration\n"); |
| 505 |
} else { |
| 506 |
if (fan->dts1_en) { |
| 507 |
init_intel_dts_sensor(&conf->dts_sensor); |
| 508 |
hwm_reg_set_bits(FAN_ALG_FUNCTRL_REG(idx), FAN_ALG_FUNCTRL_DTS1_EN); |
| 509 |
} |
| 510 |
|
| 511 |
if (fan->dts2_en) { |
| 512 |
init_intel_dts2_sensor(&conf->dts2_sensor); |
| 513 |
hwm_reg_set_bits(FAN_ALG_FUNCTRL_REG(idx), FAN_ALG_FUNCTRL_DTS2_EN); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
if (fan->dts_ub_en) |
| 518 |
hwm_reg_set_bits(FAN_ALG_FUNCTRL_REG(idx), FAN_ALG_FUNCTRL_DTS_UB_EN); |
| 519 |
|
| 520 |
|
| 521 |
if (fan->smart_tracking_en) { |
| 522 |
init_smart_tracking_alg(conf, idx); |
| 523 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_SMART_TRACK_EN); |
| 524 |
} |
| 525 |
|
| 526 |
if (conf->fan_default_val && conf->fan_default_val <= 100) |
| 527 |
hwm_reg_write(FAN_DEFAULT_VAL_REG, |
| 528 |
FAN_PWM_PERCENT_TO_HEX(conf->fan_default_val)); |
| 529 |
|
| 530 |
|
| 531 |
if (idx > 8) { |
| 532 |
lock_fan_register_set_and_check(FAN_NO_ERROR); |
| 533 |
return; |
| 534 |
} |
| 535 |
|
| 536 |
if (fan->ambient_floor_en) { |
| 537 |
init_ambient_floor_alg(conf, idx); |
| 538 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_AMBIENT_FLOOR_EN); |
| 539 |
} |
| 540 |
|
| 541 |
if (fan->startup_duty && fan->startup_duty <= 100) { |
| 542 |
hwm_reg_write(FAN_STARTUP_DUTY_REG(idx), |
| 543 |
FAN_PWM_PERCENT_TO_HEX(fan->startup_duty)); |
| 544 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_STARTUP_EN); |
| 545 |
} |
| 546 |
|
| 547 |
if (fan->manual_offset) { |
| 548 |
hwm_reg_write(FAN_MANUAL_OFFSET_REG(idx), fan->manual_offset); |
| 549 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_MANUAL_OFFSET_EN); |
| 550 |
} |
| 551 |
|
| 552 |
if (fan->min_duty && fan->min_duty <= 100) { |
| 553 |
hwm_reg_write(FAN_MIN_DUTY_REG(idx), FAN_PWM_PERCENT_TO_HEX(fan->min_duty)); |
| 554 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_MINDUTY_EN); |
| 555 |
} |
| 556 |
|
| 557 |
lock_fan_register_set_and_check(FAN_NO_ERROR); |
| 558 |
} |
| 559 |
|
| 560 |
static void set_fan_pins_and_mode(const struct nct6687d_fan_config *fan, unsigned int idx) |
| 561 |
{ |
| 562 |
enum nct6687d_fan_mode mode = fan->mode; |
| 563 |
|
| 564 |
|
| 565 |
if (mode == FAN_MODE_MANUAL) |
| 566 |
mode = 0; |
| 567 |
|
| 568 |
hwm_reg_and_or(FAN_MODE_SEL_REG(idx), ~FAN_MODE_SEL_MASK, mode & FAN_MODE_SEL_MASK); |
| 569 |
hwm_reg_and_or(FANIN_CFG_REG(idx), ~FANIN_PIN_SEL_MASK, |
| 570 |
fan->fanin_sel & FANIN_PIN_SEL_MASK); |
| 571 |
hwm_reg_set_bits(FANIN_CFG_REG(idx), FANIN_MONITOR_EN); |
| 572 |
|
| 573 |
hwm_reg_and_or(FANOUT_CFG_REG(idx), ~FANOUT_PIN_SEL_MASK, |
| 574 |
fan->fanout_sel & FANOUT_PIN_SEL_MASK); |
| 575 |
hwm_reg_set_bits(FANOUT_CFG_REG(idx), FANOUT_EN); |
| 576 |
} |
| 577 |
|
| 578 |
static bool smart_fan_level_check(const struct nct6687d_fan_config *fan, |
| 579 |
const struct nct6687d_smart_fan_iv_config *s_fan, |
| 580 |
int i) |
| 581 |
{ |
| 582 |
bool failure = false; |
| 583 |
|
| 584 |
failure |= check_cond(s_fan->temp_levels[i] <= 127, |
| 585 |
"Smart Fan IV Temperature Levels should be <= 127"); |
| 586 |
if (i < MAX_TEMP_SPEED_LEVELS - 1) { |
| 587 |
failure |= check_cond(s_fan->temp_levels[i + 1] >= s_fan->temp_levels[i], |
| 588 |
"Smart Fan IV next Temperature Level must be higher" |
| 589 |
" or equal to previous Temperature Level"); |
| 590 |
failure |= check_cond(s_fan->speed_levels[i + 1] >= s_fan->speed_levels[i], |
| 591 |
"Smart Fan IV next Speed Level must be higher or " |
| 592 |
"equal to previous Speed Level"); |
| 593 |
} |
| 594 |
|
| 595 |
if (fan->unit_sel == FAN_PWM) { |
| 596 |
failure |= check_cond(s_fan->speed_levels[i] <= 100, |
| 597 |
"Smart Fan IV PWM Speed Levels should be <= 100"); |
| 598 |
} else if (fan->unit_sel == FAN_RPM) { |
| 599 |
failure |= check_cond(s_fan->speed_levels[i] <= 0x3fff, |
| 600 |
"Smart Fan IV RPM Speed Levels should be" |
| 601 |
"<= 16383 RPM"); |
| 602 |
} else { |
| 603 |
failure |= check_cond(false, "Smart Fan IV invalid Fan Unit Selection"); |
| 604 |
} |
| 605 |
|
| 606 |
return failure; |
| 607 |
|
| 608 |
} |
| 609 |
|
| 610 |
static bool smart_fan_config_check(const struct nct6687d_fan_config *fan, |
| 611 |
const struct nct6687d_smart_fan_iv_config *s_fan) |
| 612 |
{ |
| 613 |
bool failure = false; |
| 614 |
unsigned int i; |
| 615 |
|
| 616 |
for (i = 0; i < MAX_TEMP_SPEED_LEVELS; i++) |
| 617 |
failure |= smart_fan_level_check(fan, s_fan, i); |
| 618 |
|
| 619 |
failure |= check_cond(s_fan->temp_levels[0] >= s_fan->temp_cut_off, |
| 620 |
"Smart Fan IV Temperature Level 1 should be >= " |
| 621 |
"Temperature Cut Off"); |
| 622 |
failure |= check_cond(s_fan->temp_levels[0] >= |
| 623 |
(s_fan->temp_cut_off + s_fan->temp_hystheresis), |
| 624 |
"Smart Fan IV Temperature Level 1 should be >= " |
| 625 |
"Temperature Cut Off + Temperature Hysteresis"); |
| 626 |
|
| 627 |
return failure; |
| 628 |
} |
| 629 |
|
| 630 |
static void init_smart_fan(const struct superio_nuvoton_nct6687d_config *conf, unsigned int idx) |
| 631 |
{ |
| 632 |
unsigned int i; |
| 633 |
const struct nct6687d_fan_config *fan = &conf->fans[idx - 1]; |
| 634 |
const struct nct6687d_smart_fan_iv_config *sfan = &fan->smart_fan; |
| 635 |
|
| 636 |
if (smart_fan_config_check(fan, sfan)) { |
| 637 |
printk(BIOS_ERR, "NCT6687D Smart Fan IV invalid config, " |
| 638 |
"skipping fan programming\n"); |
| 639 |
return; |
| 640 |
} |
| 641 |
|
| 642 |
if (!unlock_fan_register_set()) { |
| 643 |
printk(BIOS_ERR, "NCT6687D failed to unlock registers, " |
| 644 |
"skipping Smart Fan IV config programming\n"); |
| 645 |
return; |
| 646 |
} |
| 647 |
|
| 648 |
set_fan_pins_and_mode(fan, idx); |
| 649 |
|
| 650 |
if (fan->unit_sel == FAN_PWM) |
| 651 |
hwm_reg_and_or(FAN_FUNCTION_CTRL(idx), ~FAN_FUN_UNIT_RPM & 0xff, |
| 652 |
FAN_FUN_UNIT_PWM_DUTY); |
| 653 |
else if (fan->unit_sel == FAN_RPM) |
| 654 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_UNIT_RPM); |
| 655 |
|
| 656 |
|
| 657 |
for (i = 0; i < MAX_TEMP_SRC; i++) { |
| 658 |
hwm_reg_write(FAN_MTZ_DCS_DATA_REG(MAX_TEMP_SRC - 1 - i, idx), |
| 659 |
sfan->temp_src[i]); |
| 660 |
} |
| 661 |
|
| 662 |
for (i = 0; i < MAX_TEMP_SPEED_LEVELS; i++) { |
| 663 |
if (sfan->temp_levels[i]) |
| 664 |
hwm_reg_write(FAN_SF4_TEMP_LVL_REG(idx, i), |
| 665 |
sfan->temp_levels[i]); |
| 666 |
if (sfan->speed_levels[i]) { |
| 667 |
if (fan->unit_sel == FAN_PWM) { |
| 668 |
hwm_reg_write(FAN_SF4_PWM_RPM_LVL_HI_REG(idx, i), 0); |
| 669 |
hwm_reg_write(FAN_SF4_PWM_RPM_LVL_LO_REG(idx, i), |
| 670 |
FAN_PWM_PERCENT_TO_HEX(sfan->speed_levels[i])); |
| 671 |
} |
| 672 |
|
| 673 |
if (fan->unit_sel == FAN_RPM) { |
| 674 |
hwm_reg_write(FAN_SF4_PWM_RPM_LVL_HI_REG(idx, i), |
| 675 |
sfan->speed_levels[i] >> 8); |
| 676 |
hwm_reg_write(FAN_SF4_PWM_RPM_LVL_LO_REG(idx, i), |
| 677 |
sfan->speed_levels[i] & 0xff); |
| 678 |
} |
| 679 |
} |
| 680 |
} |
| 681 |
|
| 682 |
hwm_reg_write(FAN_SF4_TEMP_OFF_HYSTHERESIS_REG(idx), sfan->temp_hystheresis); |
| 683 |
hwm_reg_write(FAN_SF4_TEMP_CUT_OFF_REG(idx), sfan->temp_cut_off); |
| 684 |
hwm_reg_write(FAN_SF4_TEMP_OFF_DELAY_REG(idx), sfan->cut_off_delay); |
| 685 |
|
| 686 |
hwm_reg_write(FAN_STEP_UP_TIME_REG(idx), sfan->step_up_time); |
| 687 |
hwm_reg_write(FAN_STEP_DOWN_TIME_REG(idx), sfan->step_down_time); |
| 688 |
|
| 689 |
|
| 690 |
hwm_reg_and_or(FAN_MANUAL_EN_REG(idx), ~FAN_MANUAL_EN(idx), 0x00); |
| 691 |
|
| 692 |
hwm_reg_set_bits(FAN_CHANNEL_EN_REG(idx), FAN_CHANNEL_EN(idx)); |
| 693 |
|
| 694 |
lock_fan_register_set_and_check(FAN_ERR_SMART_FAN_IV); |
| 695 |
|
| 696 |
misc_fan_config(conf, idx); |
| 697 |
} |
| 698 |
|
| 699 |
static void init_manual_fan(const struct superio_nuvoton_nct6687d_config *conf, |
| 700 |
unsigned int idx) |
| 701 |
{ |
| 702 |
const struct nct6687d_fan_config *fan = &conf->fans[idx - 1]; |
| 703 |
const struct nct6687d_manual_fan_config *manual_fan = &fan->manual_fan; |
| 704 |
|
| 705 |
if (manual_fan->manual_duty || manual_fan->manual_duty > 100) { |
| 706 |
printk(BIOS_ERR, "NCT6687D: invalid duty cycle for manual fan mode\n"); |
| 707 |
return; |
| 708 |
} |
| 709 |
|
| 710 |
if (!unlock_fan_register_set()) { |
| 711 |
printk(BIOS_ERR, "NCT6687D failed to unlock registers, " |
| 712 |
"skipping manual fan config programming\n"); |
| 713 |
return; |
| 714 |
} |
| 715 |
|
| 716 |
set_fan_pins_and_mode(fan, idx); |
| 717 |
|
| 718 |
if (fan->unit_sel == FAN_PWM) |
| 719 |
hwm_reg_and_or(FAN_FUNCTION_CTRL(idx), ~FAN_FUN_UNIT_RPM & 0xff, |
| 720 |
FAN_FUN_UNIT_PWM_DUTY); |
| 721 |
else if (fan->unit_sel == FAN_RPM) |
| 722 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_UNIT_RPM); |
| 723 |
|
| 724 |
hwm_reg_write(FAN_MANUAL_VALUE_REG(idx), |
| 725 |
FAN_PWM_PERCENT_TO_HEX(manual_fan->manual_duty)); |
| 726 |
|
| 727 |
hwm_reg_set_bits(FAN_MANUAL_EN_REG(idx), FAN_MANUAL_EN(idx)); |
| 728 |
|
| 729 |
hwm_reg_set_bits(FAN_CHANNEL_EN_REG(idx), FAN_CHANNEL_EN(idx)); |
| 730 |
|
| 731 |
lock_fan_register_set_and_check(FAN_NO_ERROR); |
| 732 |
|
| 733 |
misc_fan_config(conf, idx); |
| 734 |
} |
| 735 |
|
| 736 |
static bool thermal_cruise_config_check(const struct nct6687d_fan_thermal_cruise_config *tc_fan) |
| 737 |
{ |
| 738 |
bool failure = false; |
| 739 |
|
| 740 |
failure |= check_cond(tc_fan->step_down_time > 0, |
| 741 |
"Thermal Cruise Step-Down Time should be > 0"); |
| 742 |
failure |= check_cond(tc_fan->step_up_time > 0, |
| 743 |
"Thermal Cruise Step-Up Time should be > 0"); |
| 744 |
failure |= check_cond(tc_fan->initial_value > tc_fan->stop_value, |
| 745 |
"Thermal Cruise Initial value should be > Stop Value"); |
| 746 |
failure |= check_cond(tc_fan->target_temp >= tc_fan->temp_tolerance, |
| 747 |
"Thermal Cruise Target Temperature should be" |
| 748 |
" >= Temperature Tolerance"); |
| 749 |
if (tc_fan->keep_min_fan_output) { |
| 750 |
failure |= check_cond(tc_fan->stop_value > 0, |
| 751 |
"Thermal Cruise Stop Value should be > 0"); |
| 752 |
} else { |
| 753 |
failure |= check_cond(tc_fan->stop_time > 0, |
| 754 |
"Thermal Cruise Stop Time should be > 0"); |
| 755 |
} |
| 756 |
|
| 757 |
return failure; |
| 758 |
} |
| 759 |
|
| 760 |
static void init_thermal_cruise_fan(const struct superio_nuvoton_nct6687d_config *conf, |
| 761 |
unsigned int idx) |
| 762 |
{ |
| 763 |
const struct nct6687d_fan_config *fan = &conf->fans[idx - 1]; |
| 764 |
const struct nct6687d_fan_thermal_cruise_config *tc_fan = &fan->thermal_cruise_fan; |
| 765 |
|
| 766 |
if (thermal_cruise_config_check(tc_fan)) { |
| 767 |
printk(BIOS_ERR, "NCT6687D Thermal Cruise invalid config, " |
| 768 |
"skipping fan programming\n"); |
| 769 |
return; |
| 770 |
} |
| 771 |
|
| 772 |
if (!unlock_fan_register_set()) { |
| 773 |
printk(BIOS_ERR, "NCT6687D failed to unlock registers, " |
| 774 |
"skipping Thermal Cruise fan config programming\n"); |
| 775 |
return; |
| 776 |
} |
| 777 |
|
| 778 |
set_fan_pins_and_mode(fan, idx); |
| 779 |
|
| 780 |
hwm_reg_write(FAN_TC_TARGET_TEMP_REG(idx), |
| 781 |
tc_fan->target_temp & FAN_TC_TARGET_TEMP_MASK); |
| 782 |
|
| 783 |
if (tc_fan->keep_min_fan_output) { |
| 784 |
hwm_reg_set_bits(FAN_TC_TARGET_TEMP_REG(idx), FAN_TC_KEEP_MIN_OUTPUT); |
| 785 |
hwm_reg_write(FAN_TC_STOP_VALUE_REG(idx), tc_fan->stop_value); |
| 786 |
} |
| 787 |
|
| 788 |
hwm_reg_write(FAN_TC_TARGET_TEMP_TOLERANCE_REG(idx), |
| 789 |
tc_fan->temp_tolerance & FAN_TC_TEMP_TOLERANCE_MASK); |
| 790 |
|
| 791 |
hwm_reg_write(FAN_INITIAL_VALUE_REG(idx), tc_fan->initial_value); |
| 792 |
|
| 793 |
hwm_reg_write(FAN_TC_STOP_TIME_REG(idx), tc_fan->stop_time); |
| 794 |
hwm_reg_write(FAN_TC_STEP_DOWN_TIME_REG(idx), tc_fan->step_up_time); |
| 795 |
hwm_reg_write(FAN_TC_STEP_UP_TIME_REG(idx), tc_fan->step_down_time); |
| 796 |
|
| 797 |
|
| 798 |
hwm_reg_and_or(FAN_MANUAL_EN_REG(idx), ~FAN_MANUAL_EN(idx), 0); |
| 799 |
|
| 800 |
hwm_reg_set_bits(FAN_CHANNEL_EN_REG(idx), FAN_CHANNEL_EN(idx)); |
| 801 |
|
| 802 |
lock_fan_register_set_and_check(FAN_ERR_THERMAL_CRUISE); |
| 803 |
|
| 804 |
misc_fan_config(conf, idx); |
| 805 |
} |
| 806 |
|
| 807 |
static bool speed_cruise_config_check(const struct nct6687d_fan_speed_cruise_config *sc_fan) |
| 808 |
{ |
| 809 |
bool failure = false; |
| 810 |
|
| 811 |
failure |= check_cond(sc_fan->target_rpm <= 0x3fff, |
| 812 |
"Speed Cruise Target RPM should be <= 16838 RPM"); |
| 813 |
failure |= check_cond(sc_fan->target_rpm >= sc_fan->rpm_tolerance, |
| 814 |
"Speed Cruise Target RPM should be >= RPM Tolerance"); |
| 815 |
failure |= check_cond(sc_fan->step_down_time > 0, |
| 816 |
"Speed Cruise Step-Down Time should be > 0"); |
| 817 |
failure |= check_cond(sc_fan->step_up_time > 0, |
| 818 |
"Speed Cruise Step-Up Time should be > 0"); |
| 819 |
|
| 820 |
return failure; |
| 821 |
} |
| 822 |
|
| 823 |
static void init_speed_cruise_fan(const struct superio_nuvoton_nct6687d_config *conf, |
| 824 |
unsigned int idx) |
| 825 |
{ |
| 826 |
const struct nct6687d_fan_config *fan = &conf->fans[idx - 1]; |
| 827 |
const struct nct6687d_fan_speed_cruise_config *sc_fan = &fan->speed_cruise_fan; |
| 828 |
|
| 829 |
if (speed_cruise_config_check(sc_fan)) { |
| 830 |
printk(BIOS_ERR, "NCT6687D Speed Cruise invalid config, " |
| 831 |
"skipping fan programming\n"); |
| 832 |
return; |
| 833 |
} |
| 834 |
|
| 835 |
if (!unlock_fan_register_set()) { |
| 836 |
printk(BIOS_ERR, "NCT6687D failed to unlock registers, " |
| 837 |
"skipping Speed Cruise fan config programming\n"); |
| 838 |
return; |
| 839 |
} |
| 840 |
|
| 841 |
set_fan_pins_and_mode(fan, idx); |
| 842 |
|
| 843 |
|
| 844 |
hwm_reg_set_bits(FAN_FUNCTION_CTRL(idx), FAN_FUN_UNIT_RPM); |
| 845 |
|
| 846 |
hwm_reg_write(FAN_SC_TARGET_RPM_HI_REG(idx), sc_fan->target_rpm >> 8); |
| 847 |
hwm_reg_write(FAN_SC_TARGET_RPM_LO_REG(idx), sc_fan->target_rpm & 0xff); |
| 848 |
|
| 849 |
hwm_reg_write(FAN_SC_TARGET_RPM_TOLERANCE_HI_REG(idx), sc_fan->rpm_tolerance >> 8); |
| 850 |
hwm_reg_write(FAN_SC_TARGET_RPM_TOLERANCE_LO_REG(idx), sc_fan->rpm_tolerance & 0xff); |
| 851 |
|
| 852 |
hwm_reg_write(FAN_SC_STEP_DOWN_TIME_REG(idx), sc_fan->step_up_time); |
| 853 |
hwm_reg_write(FAN_SC_STEP_UP_TIME_REG(idx), sc_fan->step_down_time); |
| 854 |
|
| 855 |
|
| 856 |
hwm_reg_and_or(FAN_MANUAL_EN_REG(idx), ~FAN_MANUAL_EN(idx), 0x00); |
| 857 |
|
| 858 |
hwm_reg_set_bits(FAN_CHANNEL_EN_REG(idx), FAN_CHANNEL_EN(idx)); |
| 859 |
|
| 860 |
lock_fan_register_set_and_check(FAN_ERR_SPEED_CRUISE); |
| 861 |
|
| 862 |
misc_fan_config(conf, idx); |
| 863 |
}; |
| 864 |
|
| 865 |
static void init_one_fan(const struct superio_nuvoton_nct6687d_config *conf, unsigned int idx) |
| 866 |
{ |
| 867 |
const struct nct6687d_fan_config *fan = &conf->fans[idx - 1]; |
| 868 |
|
| 869 |
switch (fan->mode) { |
| 870 |
case FAN_THERMAL_CRUISE: |
| 871 |
printk(BIOS_DEBUG, "Initializing Thermal Cruise for FAN%d\n", idx); |
| 872 |
init_thermal_cruise_fan(conf, idx); |
| 873 |
break; |
| 874 |
case FAN_SPEED_CRUISE: |
| 875 |
printk(BIOS_DEBUG, "Initializing Speed Cruise for FAN%d\n", idx); |
| 876 |
init_speed_cruise_fan(conf, idx); |
| 877 |
break; |
| 878 |
case FAN_SMART_FAN_IV: |
| 879 |
printk(BIOS_DEBUG, "Initializing Smart FAN IV for FAN%d\n", idx); |
| 880 |
init_smart_fan(conf, idx); |
| 881 |
break; |
| 882 |
case FAN_PID_CONTROL: |
| 883 |
printk(BIOS_WARNING, "NCT6687D: PID Control fan mode not yet supported\n"); |
| 884 |
break; |
| 885 |
case FAN_MODE_MANUAL: |
| 886 |
printk(BIOS_DEBUG, "Initializing manual fan mode for FAN%d\n", idx); |
| 887 |
init_manual_fan(conf, idx); |
| 888 |
break; |
| 889 |
default: |
| 890 |
printk(BIOS_ERR, "NCT6687D: unknown fan mode detected!\n"); |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
static void init_fans(const struct superio_nuvoton_nct6687d_config *conf) |
| 895 |
{ |
| 896 |
unsigned int i; |
| 897 |
const struct nct6687d_fan_config *fans = conf->fans; |
| 898 |
|
| 899 |
for (i = 1; i <= MAX_NUM_FANS; i++) { |
| 900 |
if (fans[i - 1].mode == FAN_IGNORE) |
| 901 |
continue; |
| 902 |
|
| 903 |
init_one_fan(conf, i); |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
static void report_ec_info(void) |
| 908 |
{ |
| 909 |
unsigned int i; |
| 910 |
|
| 911 |
printk(BIOS_DEBUG, "NCT6687D EC info:\n"); |
| 912 |
printk(BIOS_DEBUG, "\tChip ID: %04x\n", |
| 913 |
(uint16_t)hwm_reg_read(CHIP_ID0_REG) | |
| 914 |
(uint16_t)(hwm_reg_read(CHIP_ID1_REG) << 8)); |
| 915 |
printk(BIOS_DEBUG, "\tCustomer ID: %04x\n", |
| 916 |
(uint16_t)hwm_reg_read(CUSTOMER_ID0_REG) | |
| 917 |
(uint16_t)(hwm_reg_read(CUSTOMER_ID1_REG) << 8)); |
| 918 |
printk(BIOS_DEBUG, "\tFW build date: %02d/%02d/20%02d\n", |
| 919 |
hwm_reg_read(FW_BUILD_DAY_REG), |
| 920 |
hwm_reg_read(FW_BUILD_MONTH_REG), |
| 921 |
hwm_reg_read(FW_BUILD_YEAR_REG)); |
| 922 |
printk(BIOS_DEBUG, "\tFW build serial number: %d\n", |
| 923 |
hwm_reg_read(FW_BUILD_SERIALNUM_REG)); |
| 924 |
printk(BIOS_DEBUG, "\tFW version: %d.%d\n", |
| 925 |
hwm_reg_read(FW_VER0_REG), |
| 926 |
hwm_reg_read(FW_VER1_REG)); |
| 927 |
printk(BIOS_DEBUG, "\tProfile version: %d\n", |
| 928 |
hwm_reg_read(PROFILE_VER_REG)); |
| 929 |
printk(BIOS_DEBUG, "\tROM version: %d.%d.%d.%d\n", |
| 930 |
hwm_reg_read(ROM_VER0_REG), hwm_reg_read(ROM_VER1_REG), |
| 931 |
hwm_reg_read(ROM_VER2_REG), hwm_reg_read(ROM_VER3_REG)); |
| 932 |
printk(BIOS_DEBUG, "\tISP build date: %02d/%02d/20%02d\n", |
| 933 |
hwm_reg_read(ISP_BUILD_DAY_REG), |
| 934 |
hwm_reg_read(ISP_BUILD_MONTH_REG), |
| 935 |
hwm_reg_read(ISP_BUILD_YEAR_REG)); |
| 936 |
printk(BIOS_DEBUG, "\tISP build serial number: %d\n", |
| 937 |
hwm_reg_read(ISP_BUILD_SERIALNUM_REG)); |
| 938 |
printk(BIOS_DEBUG, "\tISP version: %d.%d\n", |
| 939 |
hwm_reg_read(ISP_VER0_REG), |
| 940 |
hwm_reg_read(ISP_VER1_REG)); |
| 941 |
printk(BIOS_DEBUG, "\tOEM version:"); |
| 942 |
|
| 943 |
for (i = 0; i < OEM_VER_LEN; i++) |
| 944 |
printk(BIOS_DEBUG, "%02x", hwm_reg_read(OEM_VER_REG + i)); |
| 945 |
|
| 946 |
printk(BIOS_DEBUG, "\n"); |
| 947 |
} |
| 948 |
|
| 949 |
void nct6687d_hwm_init(uint16_t hwm_base, const struct superio_nuvoton_nct6687d_config *conf) |
| 950 |
{ |
| 951 |
nct6687d_hwm_base = hwm_base; |
| 952 |
|
| 953 |
report_ec_info(); |
| 954 |
|
| 955 |
init_sensors(conf); |
| 956 |
init_fans(conf); |
| 957 |
|
| 958 |
lock_sensor_config(); |
| 959 |
print_fan_engine_status(); |
| 960 |
} |