Skip to content

Commit 82ef1a7

Browse files
Josh-Tsaiamstan
authored andcommitted
fwk: sb_tsi: poll to update the cpu die temperature
There are three functions call the temp_sensor_read(). This change creates the function to update the cpu die temperature once per second. BRANCH=fwk-dogwood-27111 BUG=None TEST=use ec console command "i2ctrace enable 3 0x4c" to check that ec reads the temperature once per second. Signed-off-by: Josh Tsai <Josh_Tsai@compal.com>
1 parent 0253cd7 commit 82ef1a7

3 files changed

Lines changed: 50 additions & 8 deletions

File tree

driver/temp_sensor/sb_tsi.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,58 @@
1717
#include "temp_sensor/sb_tsi.h"
1818
#include "util.h"
1919

20+
static int temp;
21+
2022
static int raw_read8(const int offset, int *data_ptr)
2123
{
2224
return i2c_read8(I2C_PORT_THERMAL_AP, SB_TSI_I2C_ADDR_FLAGS, offset,
2325
data_ptr);
2426
}
2527

26-
int sb_tsi_get_val(int idx, int *temp_ptr)
28+
#ifndef CONFIG_ZEPHYR
29+
static void sb_tsi_poll(void)
30+
{
31+
int data, ret;
32+
33+
/* FT4 SB-TSI sensor only powered in S0 */
34+
if (!chipset_in_state(CHIPSET_STATE_ON) || chipset_in_low_power_mode())
35+
return;
36+
37+
/* Read the value over I2C */
38+
ret = raw_read8(SB_TSI_TEMP_H, &data);
39+
40+
if (ret)
41+
return;
42+
43+
temp = C_TO_K(data);
44+
}
45+
DECLARE_HOOK(HOOK_SECOND, sb_tsi_poll, HOOK_PRIO_TEMP_SENSOR);
46+
#else
47+
void sb_tsi_update_temperature(int idx)
2748
{
28-
int ret;
49+
int data, ret;
50+
2951
/* There is only one temp sensor on the FT4 */
3052
if (idx != 0)
31-
return EC_ERROR_PARAM1;
53+
return;
3254
/* FT4 SB-TSI sensor only powered in S0 */
3355
if (!chipset_in_state(CHIPSET_STATE_ON) || chipset_in_low_power_mode())
34-
return EC_ERROR_NOT_POWERED;
56+
return;
3557
/* Read the value over I2C */
36-
ret = raw_read8(SB_TSI_TEMP_H, temp_ptr);
58+
ret = raw_read8(SB_TSI_TEMP_H, &data);
3759
if (ret)
38-
return ret;
39-
*temp_ptr = C_TO_K(*temp_ptr);
60+
return;
61+
temp = C_TO_K(data);
62+
}
63+
#endif /* CONFIG_ZEPHYR */
64+
65+
66+
int sb_tsi_get_val(int idx, int *temp_ptr)
67+
{
68+
/* There is only one temp sensor on the FT4 */
69+
if (idx != 0)
70+
return EC_ERROR_PARAM1;
71+
72+
*temp_ptr = temp;
4073
return EC_SUCCESS;
4174
}

include/driver/temp_sensor/sb_tsi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
#define SB_TSI_MANUFACTURE_ID 0xFE
3434
#define SB_TSI_REVISION 0xFF
3535

36+
#ifdef CONFIG_ZEPHYR
37+
/**
38+
* Polling to read the sensor value
39+
*
40+
* @param idx Index to read. Only 0 is valid for sb_tsi.
41+
*/
42+
void sb_tsi_update_temperature(int idx);
43+
#endif /* CONFIG_ZEPHYR */
44+
3645
/**
3746
* Get the value of a sensor in K.
3847
*

zephyr/shim/src/temp_sensors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ __maybe_unused static int sb_tsi_get_temp(const struct temp_sensor_t *sensor,
177177
#define GET_ZEPHYR_TEMP_SENSOR_SB_TSI(named_id) \
178178
(&(const struct zephyr_temp_sensor){ .read = &sb_tsi_get_temp, \
179179
.thermistor = NULL, \
180-
.update_temperature = NULL, \
180+
.update_temperature = sb_tsi_update_temperature, \
181181
FILL_POWER_GOOD(named_id) })
182182

183183
#define TEMP_SB_TSI(named_id, sensor_id) \

0 commit comments

Comments
 (0)