thermal: generic-adc: Fix adc to temp interpolation
authorBjorn Andersson <bjorn.andersson@linaro.org>
Mon, 24 Dec 2018 07:26:44 +0000 (23:26 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Feb 2019 18:46:09 +0000 (19:46 +0100)
commit919fc06bf18b4e26d8d68f249f968b36c2e45dea
tree5a6d698cab2c7c6b9d1caa945f5896e3d5b5b925
parenta67a554d53d627cd12232c15ef2b159808410ccb
thermal: generic-adc: Fix adc to temp interpolation

[ Upstream commit 9d216211fded20fff301d0317af3238d8383634c ]

First correct the edge case to return the last element if we're
outside the range, rather than at the last element, so that
interpolation is not omitted for points between the two last entries in
the table.

Then correct the formula to perform linear interpolation based the two
points surrounding the read ADC value. The indices for temp are kept as
"hi" and "lo" to pair with the adc indices, but there's no requirement
that the temperature is provided in descendent order. mult_frac() is
used to prevent issues with overflowing the int.

Cc: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/thermal/thermal-generic-adc.c