aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/i2c/nct7802y/nct7802y_peci.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_peci.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_peci.c')
-rw-r--r--src/drivers/i2c/nct7802y/nct7802y_peci.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/drivers/i2c/nct7802y/nct7802y_peci.c b/src/drivers/i2c/nct7802y/nct7802y_peci.c
new file mode 100644
index 0000000000..26e62a3f09
--- /dev/null
+++ b/src/drivers/i2c/nct7802y/nct7802y_peci.c
@@ -0,0 +1,87 @@
+/*
+ * 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"
+
+void nct7802y_init_peci(struct device *const dev)
+{
+ const struct drivers_i2c_nct7802y_config *const config = dev->chip_info;
+ unsigned int i, all_off = 1;
+
+ /* Bank 1 can only be written to if PECI reading is enabled */
+ if (nct7802y_select_bank(dev, 0) != CB_SUCCESS)
+ return;
+ nct7802y_update(dev, PECI_ENABLE, 0, PECI_ENABLE_AGENTx(0));
+
+ if (nct7802y_select_bank(dev, 1) != CB_SUCCESS)
+ return;
+
+ for (i = 0; i < NCT7802Y_PECI_CNT; ++i) {
+ if (config->peci[i].mode != PECI_DISABLED) {
+ u8 ctrl3 = 0, style = 0;
+ switch (config->peci[i].mode) {
+ case PECI_DOMAIN_0:
+ ctrl3 = PECI_CTRL_3_EN_AGENTx(i);
+ style = PECI_TEMP_STYLE_DOM0_AGENTx(i) |
+ PECI_TEMP_STYLE_SINGLE;
+ break;
+ case PECI_DOMAIN_1:
+ ctrl3 = PECI_CTRL_3_EN_AGENTx(i) |
+ PECI_CTRL_3_HAS_DOM1_AGENTx(i);
+ style = PECI_TEMP_STYLE_DOM1_AGENTx(i) |
+ PECI_TEMP_STYLE_SINGLE;
+ break;
+ case PECI_HIGHEST:
+ ctrl3 = PECI_CTRL_3_EN_AGENTx(i) |
+ PECI_CTRL_3_HAS_DOM1_AGENTx(i);
+ style = PECI_TEMP_STYLE_HIGHEST;
+ break;
+ default:
+ break;
+ }
+ nct7802y_update(dev, PECI_CTRL_1,
+ PECI_CTRL_1_MANUAL_EN,
+ PECI_CTRL_1_EN |
+ PECI_CTRL_1_ROUTINE_EN);
+ nct7802y_update(dev, PECI_CTRL_3,
+ PECI_CTRL_3_HAS_DOM1_AGENTx(i), ctrl3);
+ nct7802y_update(dev, PECI_REPORT_TEMP_STYLE,
+ PECI_TEMP_STYLE_DOM1_AGENTx(i) |
+ PECI_TEMP_STYLE_HIGHEST,
+ style);
+ nct7802y_write(dev, PECI_BASE_TEMP_AGENT(i),
+ config->peci[i].base_temp);
+ all_off = 0;
+ } else {
+ nct7802y_update(dev, PECI_CTRL_3,
+ PECI_CTRL_3_EN_AGENTx(i), 0);
+ }
+ }
+
+ if (all_off)
+ nct7802y_update(dev, PECI_CTRL_1, PECI_CTRL_1_EN, 0);
+
+ /* Disable PECI #0 reading if we only enabled it to access bank 1 */
+ if (config->peci[0].mode == PECI_DISABLED) {
+ if (nct7802y_select_bank(dev, 0) != CB_SUCCESS)
+ return;
+
+ nct7802y_update(dev, PECI_ENABLE, PECI_ENABLE_AGENTx(0), 0);
+ }
+}