Skip to content

Commit 8fd6762

Browse files
aasinclairfabiobaltieri
authored andcommitted
drivers: sensor: npm1300_charger: die temp threshold configuration
Added configuration of die temperature stop/resume thresholds Signed-off-by: Andy Sinclair <[email protected]>
1 parent 93a8ec4 commit 8fd6762

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

drivers/sensor/npm1300_charger/npm1300_charger.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct npm1300_charger_config {
2020
int32_t dischg_limit_microamp;
2121
int32_t vbus_limit_microamp;
2222
int32_t temp_thresholds[4U];
23+
int32_t dietemp_thresholds[2U];
2324
uint32_t thermistor_ohms;
2425
uint16_t thermistor_beta;
2526
uint8_t thermistor_idx;
@@ -57,6 +58,7 @@ struct npm1300_charger_data {
5758
#define CHGR_OFFSET_TRICKLE_SEL 0x0EU
5859
#define CHGR_OFFSET_ITERM_SEL 0x0FU
5960
#define CHGR_OFFSET_NTC_TEMPS 0x10U
61+
#define CHGR_OFFSET_DIE_TEMPS 0x18U
6062
#define CHGR_OFFSET_CHG_STAT 0x34U
6163
#define CHGR_OFFSET_ERR_REASON 0x36U
6264
#define CHGR_OFFSET_VBATLOW_EN 0x50U
@@ -108,11 +110,20 @@ struct adc_results_t {
108110
#define NTCTEMP_MSB_SHIFT 2U
109111
#define NTCTEMP_LSB_MASK 0x03U
110112

113+
/* dietemp masks */
114+
#define DIETEMP_MSB_SHIFT 2U
115+
#define DIETEMP_LSB_MASK 0x03U
116+
111117
/* VBUS masks */
112118
#define DETECT_HI_MASK 0x0AU
113119
#define DETECT_HI_CURRENT 1500000
114120
#define DETECT_LO_CURRENT 500000
115121

122+
/* Dietemp calculation constants */
123+
#define DIETEMP_OFFSET_MDEGC 394670
124+
#define DIETEMP_FACTOR_MUL 3963000
125+
#define DIETEMP_FACTOR_DIV 5000
126+
116127
/* Linear range for charger terminal voltage */
117128
static const struct linear_range charger_volt_ranges[] = {
118129
LINEAR_RANGE_INIT(3500000, 50000, 0U, 3U), LINEAR_RANGE_INIT(4000000, 50000, 4U, 13U)};
@@ -299,6 +310,29 @@ static int set_ntc_thresholds(const struct npm1300_charger_config *const config)
299310
return 0;
300311
}
301312

313+
static int set_dietemp_thresholds(const struct npm1300_charger_config *const config)
314+
{
315+
for (uint8_t idx = 0U; idx < 2U; idx++) {
316+
if (config->dietemp_thresholds[idx] < INT32_MAX) {
317+
/* Ref: Datasheet section 6.2.6: Charger thermal regulation */
318+
int32_t numerator =
319+
(DIETEMP_OFFSET_MDEGC - config->dietemp_thresholds[idx]) *
320+
DIETEMP_FACTOR_DIV;
321+
uint16_t code = DIV_ROUND_CLOSEST(numerator, DIETEMP_FACTOR_MUL);
322+
323+
int ret = mfd_npm1300_reg_write2(
324+
config->mfd, CHGR_BASE, CHGR_OFFSET_DIE_TEMPS + (idx * 2U),
325+
code >> DIETEMP_MSB_SHIFT, code & DIETEMP_LSB_MASK);
326+
327+
if (ret != 0) {
328+
return ret;
329+
}
330+
}
331+
}
332+
333+
return 0;
334+
}
335+
302336
static int npm1300_charger_attr_get(const struct device *dev, enum sensor_channel chan,
303337
enum sensor_attribute attr, struct sensor_value *val)
304338
{
@@ -410,7 +444,7 @@ int npm1300_charger_init(const struct device *dev)
410444
return -ENODEV;
411445
}
412446

413-
/* Configure thermistor */
447+
/* Configure temperature thresholds */
414448
ret = mfd_npm1300_reg_write(config->mfd, ADC_BASE, ADC_OFFSET_NTCR_SEL,
415449
config->thermistor_idx + 1U);
416450
if (ret != 0) {
@@ -422,6 +456,11 @@ int npm1300_charger_init(const struct device *dev)
422456
return ret;
423457
}
424458

459+
ret = set_dietemp_thresholds(config);
460+
if (ret != 0) {
461+
return ret;
462+
}
463+
425464
/* Configure termination voltages */
426465
ret = linear_range_group_get_win_index(charger_volt_ranges, ARRAY_SIZE(charger_volt_ranges),
427466
config->term_microvolt, config->term_microvolt,
@@ -576,6 +615,9 @@ static const struct sensor_driver_api npm1300_charger_battery_driver_api = {
576615
.iterm_sel = DT_INST_ENUM_IDX(n, term_current_percent), \
577616
.vbatlow_charge_enable = DT_INST_PROP(n, vbatlow_charge_enable), \
578617
.disable_recharge = DT_INST_PROP(n, disable_recharge), \
618+
.dietemp_thresholds = {DT_INST_PROP_OR(n, dietemp_stop_millidegrees, INT32_MAX), \
619+
DT_INST_PROP_OR(n, dietemp_resume_millidegrees, \
620+
INT32_MAX)}, \
579621
.temp_thresholds = {DT_INST_PROP_OR(n, thermistor_cold_millidegrees, INT32_MAX), \
580622
DT_INST_PROP_OR(n, thermistor_cool_millidegrees, INT32_MAX), \
581623
DT_INST_PROP_OR(n, thermistor_warm_millidegrees, INT32_MAX), \

dts/bindings/sensor/nordic,npm1300-charger.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,15 @@ properties:
114114
type: boolean
115115
description: |
116116
Disable automatic recharge.
117+
118+
dietemp-stop-millidegrees:
119+
type: int
120+
description: |
121+
Die temperature halt threshold in milli-degrees.
122+
When die temperature exceeds this threshold, charging will be inhibited.
123+
124+
dietemp-resume-millidegrees:
125+
type: int
126+
description: |
127+
Die temperature resume threshold in milli-degrees.
128+
When die temperature falls below this threshold, charging will be permitted.

0 commit comments

Comments
 (0)