summaryrefslogtreecommitdiff
path: root/common/temp_sensor_g781.c
diff options
context:
space:
mode:
authorDave Parker <dparker@chromium.org>2013-06-25 14:57:38 -0700
committerChromeBot <chrome-bot@google.com>2013-07-11 22:32:52 -0700
commitb2bc8aaa20479a87261aed8611367f11cf33c909 (patch)
tree6455c210351740621c86af9f43e40eae618f278c /common/temp_sensor_g781.c
parenteb8920c93921122e19c1ccf682b76d45a0bda7fd (diff)
downloadchrome-ec-b2bc8aaa20479a87261aed8611367f11cf33c909.tar.gz
Basic G781 temp sensor support for Falco and Peppy.
This lets us read the internal and external temp values. More functionality to come once we figure out what is needed. BUG=chrome-os-partner:20432 BRANCH=falco,peppy TEST=run ec 'temps' command on Falco and Peppy. Signed-off-by: Dave Parker <dparker@chromium.org> Change-Id: I4f452f438e0a158dc8b34901e3faad3ce36d28b2 Reviewed-on: https://gerrit.chromium.org/gerrit/60145 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Commit-Queue: Dave Parker <dparker@chromium.org> Tested-by: Dave Parker <dparker@chromium.org>
Diffstat (limited to 'common/temp_sensor_g781.c')
-rw-r--r--common/temp_sensor_g781.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/common/temp_sensor_g781.c b/common/temp_sensor_g781.c
new file mode 100644
index 0000000000..32f29e72f5
--- /dev/null
+++ b/common/temp_sensor_g781.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* G781 temperature sensor module for Chrome EC */
+
+#include "board.h"
+#include "common.h"
+#include "console.h"
+#include "i2c.h"
+#include "temp_sensor_g781.h"
+
+int g781_get_val(int idx, int *temp_ptr)
+{
+ int command;
+ int rv;
+ int temp_raw = 0;
+
+ if (!board_g781_has_power())
+ return EC_ERROR_NOT_POWERED;
+
+ switch (idx) {
+ case 0:
+ command = G781_TEMP_LOCAL;
+ break;
+ case 1:
+ command = G781_TEMP_REMOTE;
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+
+ rv = i2c_read8(I2C_PORT_THERMAL, G781_I2C_ADDR, command, &temp_raw);
+
+ if (rv < 0)
+ return rv;
+
+ /* Negative numbers are 2's compliment with sign bit 7 */
+ if (temp_raw & (1 << 7))
+ temp_raw = ~(~temp_raw & 0xff) + 1;
+
+ /* Temperature from sensor is in degrees Celsius */
+ *temp_ptr = temp_raw + 273;
+ return EC_SUCCESS;
+}