mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
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>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user