aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/i2c/nct7802y/nct7802y_fan.c
diff options
context:
space:
mode:
authorNico Huber <nico.huber@secunet.com>2017-08-23 16:53:31 +0200
committerNico Huber <nico.h@gmx.de>2019-03-14 18:28:11 +0000
commita3f643a3c0b350703d2531bb54530b102fe68caf (patch)
treea85e69d4d21f939602d1e2aa1192ed4dbd2aae7c /src/drivers/i2c/nct7802y/nct7802y_fan.c
parent9421727c708e6b30831a24c190938ea2951a771b (diff)
drivers/i2c/nct7802y: Add new hardware-monitoring IC
Just another hardware-monitoring chip. Only limited fan control and PECI configuration is implemented. Change-Id: I35ea79e12941804e398c6304a08170a776f4ca76 Signed-off-by: Nico Huber <nico.huber@secunet.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/29475 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
Diffstat (limited to 'src/drivers/i2c/nct7802y/nct7802y_fan.c')
-rw-r--r--src/drivers/i2c/nct7802y/nct7802y_fan.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/drivers/i2c/nct7802y/nct7802y_fan.c b/src/drivers/i2c/nct7802y/nct7802y_fan.c
new file mode 100644
index 0000000000..f0f3a3ced8
--- /dev/null
+++ b/src/drivers/i2c/nct7802y/nct7802y_fan.c
@@ -0,0 +1,111 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2017 secunet Security Networks AG
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <types.h>
+#include <device/device.h>
+
+#include "nct7802y.h"
+#include "chip.h"
+
+static void init_fan(struct device *const dev,
+ const struct nct7802y_fan_config *const config,
+ const unsigned int fan)
+{
+ unsigned int temp;
+ unsigned int i;
+
+ nct7802y_update(dev, FAN_ENABLE, 0, FANx_ENABLE(fan));
+
+ /* By default, do not map any temperature control to the fan. */
+ for (temp = 0; temp < NCT7802Y_FAN_CNT; ++temp) {
+ nct7802y_update(dev, TEMP_TO_FAN_MAP(temp),
+ TEMPx_TO_FANy_MAP(temp, fan), 0);
+ }
+
+ if (config->mode == FAN_MANUAL) {
+ nct7802y_write(dev, FAN_CTRL(fan), config->duty_cycle);
+ } else {
+ u8 set = 0, div, mul;
+ if (config->smart.mode == SMART_FAN_RPM) {
+ set |= CLOSE_LOOP_FANx_EN(fan);
+ div = 50;
+ if (config->smart.speed == FAN_SPPED_HIGHSPEED) {
+ set |= CLOSE_LOOP_FANx_HIGH_RPM(fan);
+ div = 100;
+ }
+ mul = 1;
+ } else {
+ /* SMART_FAN_DUTY is given in %, 100% == 255. */
+ div = 100;
+ mul = 255;
+ }
+ nct7802y_update(dev, CLOSE_LOOP_FAN_RPM_CTRL,
+ CLOSE_LOOP_FANx_EN(fan) |
+ CLOSE_LOOP_FANx_HIGH_RPM(fan),
+ set);
+
+ /* Map TEMPx to FANx to make things simple */
+ nct7802y_update(dev, TEMP_TO_FAN_MAP(fan),
+ TEMPx_TO_FAN_MAP_MASK(fan),
+ TEMPx_TO_FANy_MAP(fan, fan));
+
+ nct7802y_update(dev, FAN_CTRL_TEMP_SRC(fan),
+ FAN_CTRL_TEMPx_SRC_MASK(fan),
+ FAN_CTRL_TEMPx_SRCy(
+ fan, config->smart.tempsrc));
+
+ for (i = 0; i < ARRAY_SIZE(config->smart.table); ++i) {
+ nct7802y_write(dev, TABLEx_TEMP_POINTy(fan, i),
+ config->smart.table[i].temp);
+ nct7802y_write(dev, TABLEx_TARGET_POINTy(fan, i),
+ (config->smart.table[i].target * mul) / div);
+ }
+ nct7802y_write(dev, TABLEx_TEMP_POINTy(fan, 4),
+ config->smart.critical_temp);
+ }
+}
+
+void nct7802y_init_fan(struct device *const dev)
+{
+ const struct drivers_i2c_nct7802y_config *const config = dev->chip_info;
+ unsigned int i;
+ u8 set;
+
+ if (nct7802y_select_bank(dev, 0) != CB_SUCCESS)
+ return;
+
+ for (i = 0; i < NCT7802Y_FAN_CNT; ++i) {
+ if (config->fan[i].mode != FAN_IGNORE)
+ init_fan(dev, &config->fan[i], i);
+ }
+
+ switch (config->on_pecierror) {
+ case PECI_ERROR_KEEP:
+ set = CLOSE_LOOP_FAN_PECI_ERR_CURR;
+ break;
+ case PECI_ERROR_VALUE:
+ set = CLOSE_LOOP_FAN_PECI_ERR_VALUE;
+ break;
+ case PECI_ERROR_FULLSPEED:
+ set = CLOSE_LOOP_FAN_PECI_ERR_MAX;
+ break;
+ default:
+ set = 0;
+ break;
+ }
+ nct7802y_update(dev, CLOSE_LOOP_FAN_RPM_CTRL,
+ CLOSE_LOOP_FAN_PECI_ERR_MASK, set);
+ nct7802y_write(dev, FAN_DUTY_ON_PECI_ERROR, config->pecierror_minduty);
+}