Skip to content

Commit b326391

Browse files
Josh-TsaiJohnAZoidberg
authored andcommitted
fwk: isl9241: add the function to read the charger temperature
This change add the isl9241 temperature yaml file and function to read the isl9241 charger temperature. BRANCH=fwk-sunflower-26784 BUG=https://app.clickup.com/t/86et2rz87 TEST=use the console command "charger dump" to check the 0x82 register value and calculate the value to Celsius and then check the value is the same as the "temps". Signed-off-by: Josh Tsai <Josh_Tsai@compal.com>
1 parent 71b53d2 commit b326391

5 files changed

Lines changed: 66 additions & 0 deletions

File tree

driver/charger/isl9241.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,3 +1464,20 @@ const struct charger_drv isl9241_drv = {
14641464
.dump_prochot = &isl9241_dump_prochot_status,
14651465
#endif
14661466
};
1467+
1468+
int isl9241_get_temperature_val(int idx, int *temp_ptr)
1469+
{
1470+
int data;
1471+
uint32_t temp;
1472+
1473+
if (idx != 0)
1474+
return EC_ERROR_PARAM1;
1475+
1476+
RETURN_ERROR(isl9241_read(idx, ISL9241_REG_TJ_ADC_RESULTS, &data));
1477+
1478+
/* Section 6.5.4 ADC Operation describes the algorithm */
1479+
temp = 10000 * (252 - data) / 6154;
1480+
*temp_ptr = C_TO_K(temp);
1481+
1482+
return EC_SUCCESS;
1483+
}

driver/charger/isl9241.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,14 @@
205205
*/
206206
int isl9241_set_csin_discharge_fet(int chgnum, bool enable);
207207

208+
/**
209+
* Use this function to get the charger ISL9241 temperature.
210+
*
211+
* @param idx: sensor index
212+
* @param temp_ptr: temperature value from charger
213+
*
214+
* @result EC_SUCCESS if gets the vlaue
215+
*/
216+
int isl9241_get_temperature_val(int idx, int *temp_ptr);
217+
208218
#endif /* __CROS_EC_ISL9241_H */
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2023 The ChromiumOS Authors
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
description: >
6+
Get the last polled charger isl9241 temperature.
7+
8+
compatible: "cros-ec,temp-sensor-isl9241"
9+
10+
include: i2c-device.yaml

zephyr/shim/include/temp_sensor/temp_sensor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern "C" {
2222
#define F75303_COMPAT cros_ec_temp_sensor_f75303
2323
#define F75397_COMPAT cros_ec_temp_sensor_f75397
2424
#define BATTERY_COMPAT cros_ec_temp_sensor_battery
25+
#define ISL9241_COMPAT cros_ec_temp_sensor_isl9241
2526
#define SB_TSI_COMPAT cros_ec_temp_sensor_sb_tsi
2627
#define THERMISTOR_COMPAT cros_ec_temp_sensor_thermistor
2728
#define TEMP_SENSORS_COMPAT cros_ec_temp_sensors
@@ -39,6 +40,7 @@ extern "C" {
3940
DT_FOREACH_STATUS_OKAY(F75303_COMPAT, fn) \
4041
DT_FOREACH_STATUS_OKAY(F75397_COMPAT, fn) \
4142
DT_FOREACH_STATUS_OKAY(BATTERY_COMPAT, fn) \
43+
DT_FOREACH_STATUS_OKAY(ISL9241_COMPAT, fn) \
4244
DT_FOREACH_STATUS_OKAY(AMDR23M_COMPAT, fn) \
4345
DT_FOREACH_STATUS_OKAY(PECI_COMPAT, fn) \
4446
DT_FOREACH_STATUS_OKAY_VARGS(RT9490_CHG_COMPAT, TEMP_RT9490_FN, fn) \

zephyr/shim/src/temp_sensors.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "charge_state.h"
1414
#include "charger/chg_rt9490.h"
1515
#include "driver/charger/rt9490.h"
16+
#include "driver/charger/isl9241.h"
1617
#include "hooks.h"
1718
#include "peci.h"
1819
#include "temp_sensor.h"
@@ -320,6 +321,31 @@ __maybe_unused static int battery_get_temp(const struct temp_sensor_t *sensor,
320321
.zephyr_info = GET_ZEPHYR_TEMP_SENSOR_BATTERY(named_id), \
321322
}
322323

324+
325+
#if DT_HAS_COMPAT_STATUS_OKAY(ISL9241_COMPAT)
326+
__maybe_unused static int isl9241_get_temp(const struct temp_sensor_t *sensor,
327+
int *temp_ptr)
328+
{
329+
return isl9241_get_temperature_val(sensor->idx, temp_ptr);
330+
}
331+
#endif /* BATTERY_COMPAT */
332+
333+
#define GET_ZEPHYR_TEMP_SENSOR_ISL9241(named_id) \
334+
(&(const struct zephyr_temp_sensor){ \
335+
.read = &isl9241_get_temp, \
336+
.thermistor = NULL, \
337+
.update_temperature = NULL, \
338+
FILL_POWER_GOOD(named_id) })
339+
340+
#define TEMP_ISL9241(named_id, sensor_id) \
341+
[TEMP_SENSOR_ID(named_id)] = { \
342+
.name = DT_NODE_FULL_NAME(sensor_id), \
343+
.idx = 0, \
344+
.type = TEMP_SENSOR_TYPE_BOARD, \
345+
.zephyr_info = GET_ZEPHYR_TEMP_SENSOR_ISL9241(named_id), \
346+
}
347+
348+
323349
#ifdef CONFIG_PLATFORM_EC_CUSTOMIZED_DESIGN
324350
#if DT_HAS_COMPAT_STATUS_OKAY(AMDR23M_COMPAT)
325351
/* The function maybe unused because a temperature sensor can be added to dts
@@ -422,6 +448,7 @@ __maybe_unused static int peci_get_temp(const struct temp_sensor_t *sensor,
422448
CHECK_COMPAT(F75303_COMPAT, named_id, sensor_id, TEMP_F75303) \
423449
CHECK_COMPAT(F75397_COMPAT, named_id, sensor_id, TEMP_F75397) \
424450
CHECK_COMPAT(BATTERY_COMPAT, named_id, sensor_id, TEMP_BATTERY) \
451+
CHECK_COMPAT(ISL9241_COMPAT, named_id, sensor_id, TEMP_ISL9241) \
425452
CHECK_COMPAT(AMDR23M_COMPAT, named_id, sensor_id, TEMP_AMDR23M) \
426453
CHECK_COMPAT(PECI_COMPAT, named_id, sensor_id, TEMP_PECI)
427454

0 commit comments

Comments
 (0)