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

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: tas2770: Fix order of operations for temperature calculation

The order of operations to derive the temperature from the temp
register values was wrong, since 1000 / 16 is not an integer. This
resulted in the calculated temperature value deviating from the
value represented by the registers slightly, which was most obvious
when the registers were zeroed (-92.265 *C vs the expected -93.000 *C).

Scale the reading before dividing the whole thing by 16 to correct
this.

Fixes: ff73e2780169 ("ASoC: tas2770: expose die temp to hwmon")
Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
Link: https://patch.msgid.link/20260425-tas27xx-hwmon-fixes-v1-3-83c13b8e8f54@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

James Calligeros and committed by
Mark Brown
c7ecb6a6 4cfb5971

+2 -2
+2 -2
sound/soc/codecs/tas2770.c
··· 624 624 /* 625 625 * As per datasheet: divide register by 16 and subtract 93 to get 626 626 * degrees Celsius. hwmon requires millidegrees. Let's avoid rounding 627 - * errors by subtracting 93 * 16 then multiplying by 1000 / 16. 627 + * errors by subtracting 93 * 16 and scaling before dividing. 628 628 * 629 629 * NOTE: The ADC registers are initialised to 0 on reset. This means 630 630 * that the temperature will read -93 *C until the chip is brought out ··· 633 633 * value read back from its registers will be the last value sampled 634 634 * before entering software shutdown. 635 635 */ 636 - *result = (reading - (93 * 16)) * (1000 / 16); 636 + *result = (reading - (93 * 16)) * 1000 / 16; 637 637 return 0; 638 638 } 639 639