Skip to content

Commit caae66e

Browse files
vantomanvbajs
authored andcommitted
power: supply: ln8000: Fix die temperature handling
- Fixed die temperature conversion logic to correctly handle the ADC value and log the current temperature. - Added temperature clamping to ensure the die temperature stays within the range of -25°C to 160°C. - Triggered standby mode to prevent over heating. Signed-off-by: Yahya Wessam <yahyawessam2002@gmail.com>
1 parent b3fa3b5 commit caae66e

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

drivers/power/supply/ti/ln8000_charger.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ do { \
8585
#define LN8000_ROLE(info) (LN8000_IS_PRIMARY(info) ? "prim" : "sec ")
8686
#define LN8000_USE_GPIO(pdata) ((pdata != NULL) && (!IS_ERR_OR_NULL(pdata->irq_gpio)))
8787
#define LN8000_STATUS(val, mask) ((val & mask) ? true : false)
88+
static int ln8000_change_opmode(struct ln8000_info *info, unsigned int target_mode);
8889

8990
/**
9091
* I2C control functions : when occurred I2C tranfer fault, we
@@ -469,14 +470,27 @@ static void ln8000_convert_adc_code(struct ln8000_info *info, unsigned int ch, u
469470
adc_raw = ((sts[1] & 0x03)<<8) | (sts[0] & 0xFF);
470471
adc_final = adc_raw * LN8000_ADC_IIN_STEP;//uA
471472
break;
472-
case LN8000_ADC_CH_DIETEMP:
473-
adc_raw = ((sts[1] & 0x0F)<<6) | ((sts[0] & 0xFC)>>2);
474-
adc_final = (935 - adc_raw) * LN8000_ADC_DIETEMP_STEP / LN8000_ADC_DIETEMP_DENOM;//dC
475-
if (adc_final > LN8000_ADC_DIETEMP_MAX)
476-
adc_final = LN8000_ADC_DIETEMP_MAX;
477-
else if (adc_final < LN8000_ADC_DIETEMP_MIN)
478-
adc_final = LN8000_ADC_DIETEMP_MIN;
479-
break;
473+
case LN8000_ADC_CH_DIETEMP: {
474+
int temp_dc;
475+
adc_raw = ((sts[1] & 0x0F) << 6) | ((sts[0] & 0xFC) >> 2);
476+
ln_info("Raw ADC bytes: sts[0]=0x%02X, sts[1]=0x%02X\n", sts[0], sts[1]);
477+
ln_info("Raw ADC value for die temperature: 0x%04X\n", adc_raw);
478+
479+
adc_final = (adc_raw * LN8000_ADC_DIETEMP_STEP) / LN8000_ADC_DIETEMP_DENOM; // dC
480+
temp_dc = adc_final / 10;
481+
482+
ln_info("Current die temperature: %d°C\n", temp_dc);
483+
484+
if (temp_dc > 1600) {
485+
temp_dc = 1600;
486+
ln_err("Die temperature exceeds maximum limit: %d°C\n", temp_dc);
487+
ln8000_change_opmode(info, LN8000_OPMODE_STANDBY);
488+
} else if (temp_dc < -250) {
489+
temp_dc = -250;
490+
}
491+
*result = temp_dc;
492+
break;
493+
}
480494
case LN8000_ADC_CH_TSBAT:
481495
adc_raw = ((sts[1] & 0x3F)<<4) | ((sts[0] & 0xF0)>>4);
482496
adc_final = adc_raw * LN8000_ADC_NTCV_STEP;//(NTC) uV

0 commit comments

Comments
 (0)