mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
iio: adc: qcom-vadc-common: simplify qcom_vadc_map_voltage_temp
All volt-temp tables here are sorted in descending order. There is no need to accout for (unused) ascending table sorting case, so simplify the conversion function. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Link: https://lore.kernel.org/r/20201204025509.1075506-11-dmitry.baryshkov@linaro.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
3bd0ceb566
commit
48d2e2ff85
@@ -346,38 +346,19 @@ static struct qcom_adc5_scale_type scale_adc5_fn[] = {
|
|||||||
static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
|
static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
|
||||||
u32 tablesize, s32 input, int *output)
|
u32 tablesize, s32 input, int *output)
|
||||||
{
|
{
|
||||||
bool descending = 1;
|
|
||||||
u32 i = 0;
|
u32 i = 0;
|
||||||
|
|
||||||
if (!pts)
|
if (!pts)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* Check if table is descending or ascending */
|
while (i < tablesize && pts[i].x > input)
|
||||||
if (tablesize > 1) {
|
|
||||||
if (pts[0].x < pts[1].x)
|
|
||||||
descending = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (i < tablesize) {
|
|
||||||
if ((descending) && (pts[i].x < input)) {
|
|
||||||
/* table entry is less than measured*/
|
|
||||||
/* value and table is descending, stop */
|
|
||||||
break;
|
|
||||||
} else if ((!descending) &&
|
|
||||||
(pts[i].x > input)) {
|
|
||||||
/* table entry is greater than measured*/
|
|
||||||
/*value and table is ascending, stop */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
i++;
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
*output = pts[0].y;
|
*output = pts[0].y;
|
||||||
} else if (i == tablesize) {
|
} else if (i == tablesize) {
|
||||||
*output = pts[tablesize - 1].y;
|
*output = pts[tablesize - 1].y;
|
||||||
} else {
|
} else {
|
||||||
/* result is between search_index and search_index-1 */
|
|
||||||
/* interpolate linearly */
|
/* interpolate linearly */
|
||||||
*output = fixp_linear_interpolate(pts[i - 1].x, pts[i - 1].y,
|
*output = fixp_linear_interpolate(pts[i - 1].x, pts[i - 1].y,
|
||||||
pts[i].x, pts[i].y,
|
pts[i].x, pts[i].y,
|
||||||
|
Reference in New Issue
Block a user