summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Zhang <Ryan.Zhang@quantatw.com>2016-05-16 10:31:29 +0800
committerchrome-bot <chrome-bot@chromium.org>2016-05-18 19:44:11 -0700
commit35d534dfb37185118a735afccec5dc78d93fbc33 (patch)
treec5ef8933980abbce5049b406920d5a9252a0248c
parentf817140c3e38d00d6d967e56ca366e05e64dfdfc (diff)
downloadchrome-ec-35d534dfb37185118a735afccec5dc78d93fbc33.tar.gz
COMMON: Add extend function for tmp432 IC
+ create interface to set ALERT# pin as THERM mode and set high limit for a selected channel BUG=None BRANCH=master TEST=`make -j runtests` Change-Id: I7325eb9ddfcaca3ea873e1ee71da74258d7bec72 Signed-off-by: Ryan Zhang <Ryan.Zhang@quantatw.com> Reviewed-on: https://chromium-review.googlesource.com/344435 Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--driver/temp_sensor/tmp432.c59
-rw-r--r--driver/temp_sensor/tmp432.h31
2 files changed, 90 insertions, 0 deletions
diff --git a/driver/temp_sensor/tmp432.c b/driver/temp_sensor/tmp432.c
index 144a28a9ee..ea49fcb28b 100644
--- a/driver/temp_sensor/tmp432.c
+++ b/driver/temp_sensor/tmp432.c
@@ -117,6 +117,65 @@ static int tmp432_shutdown(uint8_t want_shutdown)
return ret;
}
+static int tmp432_set_therm_mode(void)
+{
+ int ret = 0;
+ int data = 0;
+
+ ret = raw_read8(TMP432_CONFIGURATION1_R, &data);
+ if (ret)
+ return EC_ERROR_UNKNOWN;
+
+ data |= TMP432_CONFIG1_MODE;
+ ret = raw_write8(TMP432_CONFIGURATION1_W, data);
+ if (ret)
+ return EC_ERROR_UNKNOWN;
+
+ return EC_SUCCESS;
+}
+
+int tmp432_set_therm_limit(int channel, int limit_c, int hysteresis)
+{
+ int ret = 0;
+ int reg = 0;
+
+ if (channel >= TMP432_CHANNEL_COUNT)
+ return EC_ERROR_INVAL;
+
+ if (hysteresis > TMP432_HYSTERESIS_HIGH_LIMIT ||
+ hysteresis < TMP432_HYSTERESIS_LOW_LIMIT)
+ return EC_ERROR_INVAL;
+
+ /* hysteresis must be less than high limit */
+ if (hysteresis > limit_c)
+ return EC_ERROR_INVAL;
+
+ if (tmp432_set_therm_mode() != EC_SUCCESS)
+ return EC_ERROR_UNKNOWN;
+
+ switch (channel) {
+ case TMP432_CHANNEL_LOCAL:
+ reg = TMP432_LOCAL_HIGH_LIMIT_W;
+ break;
+ case TMP432_CHANNEL_REMOTE1:
+ reg = TMP432_REMOTE1_HIGH_LIMIT_W;
+ break;
+ case TMP432_CHANNEL_REMOTE2:
+ reg = TMP432_REMOTE2_HIGH_LIMIT_W;
+ break;
+ }
+
+ ret = raw_write8(reg, limit_c);
+ if (ret)
+ return EC_ERROR_UNKNOWN;
+
+ ret = raw_write8(TMP432_THERM_HYSTERESIS, hysteresis);
+ if (ret)
+ return EC_ERROR_UNKNOWN;
+
+ return EC_SUCCESS;
+}
+
static void temp_sensor_poll(void)
{
int temp_c;
diff --git a/driver/temp_sensor/tmp432.h b/driver/temp_sensor/tmp432.h
index 2aae435dd5..ea6f3286c6 100644
--- a/driver/temp_sensor/tmp432.h
+++ b/driver/temp_sensor/tmp432.h
@@ -67,6 +67,7 @@
/* Config register bits */
#define TMP432_CONFIG1_TEMP_RANGE (1 << 2)
+/* TMP432_CONFIG1_MODE bit is use to enable THERM mode */
#define TMP432_CONFIG1_MODE (1 << 5)
#define TMP432_CONFIG1_RUN_L (1 << 6)
#define TMP432_CONFIG1_ALERT_MASK_L (1 << 7)
@@ -82,12 +83,24 @@
#define TMP432_STATUS_TEMP_HIGH_ALARM (1 << 4)
#define TMP432_STATUS_BUSY (1 << 7)
+/* Limintaions */
+#define TMP432_HYSTERESIS_HIGH_LIMIT 255
+#define TMP432_HYSTERESIS_LOW_LIMIT 0
+
enum tmp432_power_state {
TMP432_POWER_OFF = 0,
TMP432_POWER_ON,
TMP432_POWER_COUNT
};
+enum tmp432_channel_id {
+ TMP432_CHANNEL_LOCAL,
+ TMP432_CHANNEL_REMOTE1,
+ TMP432_CHANNEL_REMOTE2,
+
+ TMP432_CHANNEL_COUNT
+};
+
/**
* Get the last polled value of a sensor.
*
@@ -108,4 +121,22 @@ int tmp432_get_val(int idx, int *temp_ptr);
* @return EC_SUCCESS if successful, non-zero if error.
*/
int tmp432_set_power(enum tmp432_power_state power_on);
+
+/*
+ * Set TMP432 ALERT#/THERM2# pin to THERM mode, and give a limit
+ * for a specific channel.
+ *
+ * @param channel specific a channel
+ *
+ * @param limit_c High limit temperature, default: 85C
+ *
+ * @param hysteresis Hysteresis temperature, default: 10C
+ * All channels share the same hysteresis
+ *
+ * In THERM mode, ALERT# pin will trigger(Low) by itself when any
+ * channel's temperature is greater( >= )than channel's limit_c,
+ * and release(High) by itself when channel's temperature is lower
+ * than (limit_c - hysteresis)
+ */
+int tmp432_set_therm_limit(int channel, int limit_c, int hysteresis);
#endif /* __CROS_EC_TMP432_H */