Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: bq25890: add POWER_SUPPLY_PROP_TEMP

Add the POWER_SUPPLY_PROP_TEMP and a NTC 10K percent VREGN to degrees LUT.

Make sure that a conversion is forced when the power supply is offline so
the temperature is valid.

Signed-off-by: Angus Ainslie <angus@akkea.ca>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Angus Ainslie and committed by
Sebastian Reichel
9652c024 0838a3bf

+36 -1
+36 -1
drivers/power/supply/bq25890_charger.c
··· 266 266 /* lookup tables */ 267 267 TBL_TREG, 268 268 TBL_BOOSTI, 269 + TBL_TSPCT, 269 270 }; 270 271 271 272 /* Thermal Regulation Threshold lookup table, in degrees Celsius */ ··· 280 279 }; 281 280 282 281 #define BQ25890_BOOSTI_TBL_SIZE ARRAY_SIZE(bq25890_boosti_tbl) 282 + 283 + /* NTC 10K temperature lookup table in tenths of a degree */ 284 + static const u32 bq25890_tspct_tbl[] = { 285 + 850, 840, 830, 820, 810, 800, 790, 780, 286 + 770, 760, 750, 740, 730, 720, 710, 700, 287 + 690, 685, 680, 675, 670, 660, 650, 645, 288 + 640, 630, 620, 615, 610, 600, 590, 585, 289 + 580, 570, 565, 560, 550, 540, 535, 530, 290 + 520, 515, 510, 500, 495, 490, 480, 475, 291 + 470, 460, 455, 450, 440, 435, 430, 425, 292 + 420, 410, 405, 400, 390, 385, 380, 370, 293 + 365, 360, 355, 350, 340, 335, 330, 320, 294 + 310, 305, 300, 290, 285, 280, 275, 270, 295 + 260, 250, 245, 240, 230, 225, 220, 210, 296 + 205, 200, 190, 180, 175, 170, 160, 150, 297 + 145, 140, 130, 120, 115, 110, 100, 90, 298 + 80, 70, 60, 50, 40, 30, 20, 10, 299 + 0, -10, -20, -30, -40, -60, -70, -80, 300 + -90, -10, -120, -140, -150, -170, -190, -210, 301 + }; 302 + 303 + #define BQ25890_TSPCT_TBL_SIZE ARRAY_SIZE(bq25890_tspct_tbl) 283 304 284 305 struct bq25890_range { 285 306 u32 min; ··· 331 308 332 309 /* lookup tables */ 333 310 [TBL_TREG] = { .lt = {bq25890_treg_tbl, BQ25890_TREG_TBL_SIZE} }, 334 - [TBL_BOOSTI] = { .lt = {bq25890_boosti_tbl, BQ25890_BOOSTI_TBL_SIZE} } 311 + [TBL_BOOSTI] = { .lt = {bq25890_boosti_tbl, BQ25890_BOOSTI_TBL_SIZE} }, 312 + [TBL_TSPCT] = { .lt = {bq25890_tspct_tbl, BQ25890_TSPCT_TBL_SIZE} } 335 313 }; 336 314 337 315 static int bq25890_field_read(struct bq25890_device *bq, ··· 412 388 switch (psp) { 413 389 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 414 390 case POWER_SUPPLY_PROP_CURRENT_NOW: 391 + case POWER_SUPPLY_PROP_TEMP: 415 392 return true; 416 393 417 394 default: ··· 551 526 552 527 /* converted_val = ADC_val * 50mA (table 10.3.19) */ 553 528 val->intval = ret * -50000; 529 + break; 530 + 531 + case POWER_SUPPLY_PROP_TEMP: 532 + ret = bq25890_field_read(bq, F_TSPCT); 533 + if (ret < 0) 534 + return ret; 535 + 536 + /* convert TS percentage into rough temperature */ 537 + val->intval = bq25890_find_val(ret, TBL_TSPCT); 554 538 break; 555 539 556 540 default: ··· 747 713 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, 748 714 POWER_SUPPLY_PROP_VOLTAGE_NOW, 749 715 POWER_SUPPLY_PROP_CURRENT_NOW, 716 + POWER_SUPPLY_PROP_TEMP, 750 717 }; 751 718 752 719 static char *bq25890_charger_supplied_to[] = {