Skip to content

Commit 48d2e2f

Browse files
lumagjic23
authored andcommitted
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>
1 parent 3bd0ceb commit 48d2e2f

1 file changed

Lines changed: 1 addition & 20 deletions

File tree

drivers/iio/adc/qcom-vadc-common.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -346,38 +346,19 @@ static struct qcom_adc5_scale_type scale_adc5_fn[] = {
346346
static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
347347
u32 tablesize, s32 input, int *output)
348348
{
349-
bool descending = 1;
350349
u32 i = 0;
351350

352351
if (!pts)
353352
return -EINVAL;
354353

355-
/* Check if table is descending or ascending */
356-
if (tablesize > 1) {
357-
if (pts[0].x < pts[1].x)
358-
descending = 0;
359-
}
360-
361-
while (i < tablesize) {
362-
if ((descending) && (pts[i].x < input)) {
363-
/* table entry is less than measured*/
364-
/* value and table is descending, stop */
365-
break;
366-
} else if ((!descending) &&
367-
(pts[i].x > input)) {
368-
/* table entry is greater than measured*/
369-
/*value and table is ascending, stop */
370-
break;
371-
}
354+
while (i < tablesize && pts[i].x > input)
372355
i++;
373-
}
374356

375357
if (i == 0) {
376358
*output = pts[0].y;
377359
} else if (i == tablesize) {
378360
*output = pts[tablesize - 1].y;
379361
} else {
380-
/* result is between search_index and search_index-1 */
381362
/* interpolate linearly */
382363
*output = fixp_linear_interpolate(pts[i - 1].x, pts[i - 1].y,
383364
pts[i].x, pts[i].y,

0 commit comments

Comments
 (0)