summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/i2c/Kconfig1
-rw-r--r--src/drivers/i2c/Makefile.inc1
-rw-r--r--src/drivers/i2c/w83793/Kconfig2
-rw-r--r--src/drivers/i2c/w83793/Makefile.inc1
-rw-r--r--src/drivers/i2c/w83793/chip.h21
-rw-r--r--src/drivers/i2c/w83793/w83793.c242
-rw-r--r--src/drivers/i2c/w83793/w83793.h23
7 files changed, 291 insertions, 0 deletions
diff --git a/src/drivers/i2c/Kconfig b/src/drivers/i2c/Kconfig
index 09c306b1e6..4eb3f3f1f3 100644
--- a/src/drivers/i2c/Kconfig
+++ b/src/drivers/i2c/Kconfig
@@ -5,3 +5,4 @@ source src/drivers/i2c/i2cmux/Kconfig
source src/drivers/i2c/i2cmux2/Kconfig
source src/drivers/i2c/lm63/Kconfig
source src/drivers/i2c/w83795/Kconfig
+source src/drivers/i2c/w83793/Kconfig
diff --git a/src/drivers/i2c/Makefile.inc b/src/drivers/i2c/Makefile.inc
index 97e9729957..331b26c135 100644
--- a/src/drivers/i2c/Makefile.inc
+++ b/src/drivers/i2c/Makefile.inc
@@ -5,3 +5,4 @@ subdirs-y += i2cmux
subdirs-y += i2cmux2
subdirs-y += lm63
subdirs-y += w83795
+subdirs-y += w83793
diff --git a/src/drivers/i2c/w83793/Kconfig b/src/drivers/i2c/w83793/Kconfig
new file mode 100644
index 0000000000..d7f8cd1fe1
--- /dev/null
+++ b/src/drivers/i2c/w83793/Kconfig
@@ -0,0 +1,2 @@
+config DRIVERS_I2C_W83793
+ bool
diff --git a/src/drivers/i2c/w83793/Makefile.inc b/src/drivers/i2c/w83793/Makefile.inc
new file mode 100644
index 0000000000..c25ddd5f98
--- /dev/null
+++ b/src/drivers/i2c/w83793/Makefile.inc
@@ -0,0 +1 @@
+driver-$(CONFIG_DRIVERS_I2C_W83793) += w83793.c
diff --git a/src/drivers/i2c/w83793/chip.h b/src/drivers/i2c/w83793/chip.h
new file mode 100644
index 0000000000..dc3cd7500f
--- /dev/null
+++ b/src/drivers/i2c/w83793/chip.h
@@ -0,0 +1,21 @@
+extern struct chip_operations drivers_i2c_w83793_ops;
+
+struct drivers_i2c_w83793_config {
+ u8 mfc;
+ u8 fanin;
+ u8 peci_agent_conf;
+ u8 tcase0;
+ u8 tcase1;
+ u8 tcase2;
+ u8 tcase3;
+ u8 tr_enable;
+ u8 critical_temperature;
+
+ u8 td1_fan_select;
+ u8 td2_fan_select;
+ u8 td3_fan_select;
+ u8 td4_fan_select;
+
+ u8 tr1_fan_select;
+ u8 tr2_fan_select;
+};
diff --git a/src/drivers/i2c/w83793/w83793.c b/src/drivers/i2c/w83793/w83793.c
new file mode 100644
index 0000000000..c2ed53dd8a
--- /dev/null
+++ b/src/drivers/i2c/w83793/w83793.c
@@ -0,0 +1,242 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2012 Advanced Micro Devices, Inc.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdint.h>
+#include <arch/cpu.h>
+#include <console/console.h>
+#include <device/device.h>
+#include "w83793.h"
+#include <device/smbus.h>
+#include "chip.h"
+
+static int w83793_fan_limit(device_t dev, int fan, uint16_t limit)
+{
+ return smbus_write_byte(dev, 0x90 + fan * 2, limit >> 8) ||
+ smbus_write_byte(dev, 0x91 + fan * 2, limit & 0xff);
+}
+
+static int w83793_bank(device_t dev, int bank)
+{
+ return smbus_write_byte(dev, 0, bank);
+}
+
+static int w83793_td_level(device_t dev, int fan, const char *level)
+{
+ fan *= 0x10;
+
+ smbus_write_byte(dev, 0x30 + fan, level[0]);
+ smbus_write_byte(dev, 0x31 + fan, level[1]);
+ smbus_write_byte(dev, 0x32 + fan, level[2]);
+ smbus_write_byte(dev, 0x33 + fan, level[3]);
+ smbus_write_byte(dev, 0x34 + fan, level[4]);
+ smbus_write_byte(dev, 0x35 + fan, level[5]);
+ smbus_write_byte(dev, 0x36 + fan, level[6]);
+ return 0;
+}
+
+static int w83793_tr_level(device_t dev, int fan, const char *level)
+{
+ fan *= 0x10;
+
+ smbus_write_byte(dev, 0x70 + fan, level[0]);
+ smbus_write_byte(dev, 0x71 + fan, level[1]);
+ smbus_write_byte(dev, 0x72 + fan, level[2]);
+ smbus_write_byte(dev, 0x73 + fan, level[3]);
+ smbus_write_byte(dev, 0x74 + fan, level[4]);
+ smbus_write_byte(dev, 0x75 + fan, level[5]);
+ smbus_write_byte(dev, 0x76 + fan, level[6]);
+ return 0;
+}
+
+
+static int w83793_td_fan_level(device_t dev, int fan, const char *level)
+{
+ fan *= 0x10;
+
+ smbus_write_byte(dev, 0x38 + fan, level[0]);
+ smbus_write_byte(dev, 0x39 + fan, level[1]);
+ smbus_write_byte(dev, 0x3a + fan, level[2]);
+ smbus_write_byte(dev, 0x3b + fan, level[3]);
+ smbus_write_byte(dev, 0x3c + fan, level[4]);
+ smbus_write_byte(dev, 0x3d + fan, level[5]);
+ smbus_write_byte(dev, 0x3e + fan, level[6]);
+ return 0;
+}
+
+static int w83793_tr_fan_level(device_t dev, int fan, const char *level)
+{
+ fan *= 0x10;
+
+ smbus_write_byte(dev, 0x78 + fan, level[0]);
+ smbus_write_byte(dev, 0x79 + fan, level[1]);
+ smbus_write_byte(dev, 0x7a + fan, level[2]);
+ smbus_write_byte(dev, 0x7b + fan, level[3]);
+ smbus_write_byte(dev, 0x7c + fan, level[4]);
+ smbus_write_byte(dev, 0x7d + fan, level[5]);
+ smbus_write_byte(dev, 0x7e + fan, level[6]);
+ return 0;
+}
+
+
+static void w83793_init(device_t dev)
+{
+ struct drivers_i2c_w83793_config *config = dev->chip_info;
+ uint16_t id;
+ int i;
+
+ if (w83793_bank(dev, 0))
+ printk(BIOS_ERR, "%s: failed\n", __func__);
+
+ if (!config)
+ return;
+
+ id = smbus_read_byte(dev, 0x0d);
+ w83793_bank(dev, 0x80);
+ id |= smbus_read_byte(dev, 0x0d) << 8;
+ printk(BIOS_ERR, "ID: %04x\n", id);
+
+ /* reset configuration */
+ smbus_write_byte(dev, 0x40, 0x80);
+ smbus_write_byte(dev, 0x51, 0x06);
+
+ /* Multi function control */
+ smbus_write_byte(dev, 0x58, config->mfc);
+
+ /* FANIN_Ctrl */
+ smbus_write_byte(dev, 0x5c, config->fanin);
+
+ /* Temperature reported by PECI */
+ smbus_write_byte(dev, 0x5e, 0xff);
+ /* TR monitor enable */
+ smbus_write_byte(dev, 0x5f, config->tr_enable);
+ /* PECI Agent configuration */
+ smbus_write_byte(dev, 0xd0, config->peci_agent_conf);
+ /* TCase */
+ smbus_write_byte(dev, 0xd1, config->tcase0);
+ smbus_write_byte(dev, 0xd2, config->tcase1);
+ smbus_write_byte(dev, 0xd3, config->tcase2);
+ smbus_write_byte(dev, 0xd4, config->tcase3);
+ /* PECI Reportstyle */
+ smbus_write_byte(dev, 0xd5, 0x00);
+
+ for (i = 0; i < 9; i++)
+ w83793_fan_limit(dev, i, 0x768);
+
+ /* Fan output style control */
+ smbus_write_byte(dev, 0xb0, 0x00);
+ smbus_write_byte(dev, 0xb1, 0x00);
+
+ /* FAN Uptime */
+ smbus_write_byte(dev, 0xc3, 0x02);
+
+ /* FAN downtime */
+ smbus_write_byte(dev, 0xc4, 0x03);
+
+ /* ALL FAN critical temperature */
+ smbus_write_byte(dev, 0xc5, config->critical_temperature);
+
+ /* Temperature offset */
+ smbus_write_byte(dev, 0xa8, 0xf9);
+ smbus_write_byte(dev, 0xa9, 0xf9);
+ smbus_write_byte(dev, 0xaa, 0xf9);
+ smbus_write_byte(dev, 0xab, 0xf9);
+
+ /* BANK 2 */
+ smbus_write_byte(dev, 0x00, 0x02);
+
+ /* TD FAN select */
+ smbus_write_byte(dev, 0x01, config->td1_fan_select);
+ smbus_write_byte(dev, 0x02, config->td2_fan_select);
+ smbus_write_byte(dev, 0x03, config->td3_fan_select);
+ smbus_write_byte(dev, 0x04, config->td4_fan_select);
+
+ smbus_write_byte(dev, 0x05, config->tr1_fan_select);
+ smbus_write_byte(dev, 0x06, config->tr2_fan_select);
+
+ /* FAN control mode */
+ smbus_write_byte(dev, 0x07, 0x00);
+
+ /* hysteresis tolerance */
+ smbus_write_byte(dev, 0x08, 0xaa);
+ smbus_write_byte(dev, 0x09, 0xaa);
+
+ /* FanNonStop */
+ smbus_write_byte(dev, 0x18, 0x1d);
+ smbus_write_byte(dev, 0x19, 0x04);
+ smbus_write_byte(dev, 0x1a, 0x04);
+ smbus_write_byte(dev, 0x1b, 0x04);
+ smbus_write_byte(dev, 0x1c, 0x04);
+ smbus_write_byte(dev, 0x1d, 0x04);
+ smbus_write_byte(dev, 0x1e, 0x04);
+ smbus_write_byte(dev, 0x1f, 0x04);
+
+ /* FanStart */
+ smbus_write_byte(dev, 0x20, 0x08);
+ smbus_write_byte(dev, 0x21, 0x08);
+ smbus_write_byte(dev, 0x22, 0x08);
+ smbus_write_byte(dev, 0x23, 0x08);
+ smbus_write_byte(dev, 0x24, 0x08);
+ smbus_write_byte(dev, 0x25, 0x08);
+ smbus_write_byte(dev, 0x26, 0x08);
+ smbus_write_byte(dev, 0x27, 0x08);
+
+ for (i = 0; i < 4; i++)
+ w83793_td_level(dev, i, (const char[]){ 0x32, 0x32, 0x32, 0x32, 0x37, 0x41, 0x4b });
+
+ for (i = 0; i < 2; i++)
+ w83793_tr_level(dev, i, (const char[]){ 0x1e, 0x23, 0x28, 0x2d, 0x32, 0x37, 0x3c });
+
+ for (i = 0; i < 4; i++)
+ w83793_td_fan_level(dev, i, (const char[]){ 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x26 });
+
+ for (i = 0; i < 2; i++)
+ w83793_tr_fan_level(dev, i, (const char[]){ 0x08, 0x0c, 0x10, 0x18, 0x20, 0x30, 0x38 });
+
+
+ smbus_write_byte(dev, 0x00, 0x00);
+
+ /* Fan output style */
+ smbus_write_byte(dev, 0xb4, 0x00);
+ smbus_write_byte(dev, 0xb5, 0x00);
+
+ /* start monitoring operation */
+ smbus_write_byte(dev, 0x40, 0x09);
+
+}
+
+static void w83793_noop(device_t dummy)
+{
+}
+
+static struct device_operations w83793_operations = {
+ .read_resources = w83793_noop,
+ .set_resources = w83793_noop,
+ .enable_resources = w83793_noop,
+ .init = w83793_init,
+};
+
+static void enable_dev(device_t dev)
+{
+ dev->ops = &w83793_operations;
+}
+
+struct chip_operations drivers_i2c_w83793_ops = {
+ CHIP_NAME("Nuvoton W83793 Hardware Monitor")
+ .enable_dev = enable_dev,
+};
diff --git a/src/drivers/i2c/w83793/w83793.h b/src/drivers/i2c/w83793/w83793.h
new file mode 100644
index 0000000000..561342126c
--- /dev/null
+++ b/src/drivers/i2c/w83793/w83793.h
@@ -0,0 +1,23 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2012 Advanced Micro Devices, Inc.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef W83793_H
+#define W83793_H
+
+#endif