From patchwork Mon Nov 2 17:49:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 320355 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp3922797ilc; Mon, 2 Nov 2020 09:50:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGPUwAcrADC/ZI2eewclYwVze8Qf4yjEcENMpZrfbc63ElEjdLxcSwfm1vftk2qY5ZBCgs X-Received: by 2002:a17:906:35da:: with SMTP id p26mr4904188ejb.256.1604339424296; Mon, 02 Nov 2020 09:50:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604339424; cv=none; d=google.com; s=arc-20160816; b=PceZWzM7m1ZrfW3d3Fg5zIQzw8pYQl42VFNHBppFsgWqJ1ZB2IvOj3WXMyqmuG2MTD 7EvyybQaxDeW8jBKQI0wb7zycmAVkoVtzbNhsz85NVpQtSfyTAD/ZWpXNwVYy7GvpHYm 6A3j8/uLsQSZccGzVUgmp2A+M3WsC4YaMefVKYhoONiSAJXnXLZDs2n0a8/Po77z2sTG DRuCQfNDejEq5X30/iG8uiLNbxs6WW99PyUu97rsuhSZeRfkSRQAxjGNElQG91E0KtFF aGhkL9q5EwrPxLs76CeftOoRm4s2W+pl5LyNhQDLOF3zIUoj2/noo2BSGq8ORIIeLpIG cd+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DRpprZ4tbXfA6U6lcH14beZQwE//DZQqeCLuljQcmow=; b=Ox1ZqyercYnhukjqmw1ySMv34MW4v4lM8roX7SbMvuiWojBwkYt+py1PiiMmBFZ+Da P8reR8cl49VueSL8msYWAQRpNVhmqkHIEAF+VcXCXx+xFlcScpdNxilfZckH05aAOtAF 9ZG6O9KXlD6GPzxWTjA91ZlUZcltogRAYmU2eOTSaZFrS5jM4wtIRHq+yhl0I+Lxfq7m +Qn+G/TTq0p2JPuQUppQQo5b9LlKw1PlgqGBaogTF/9d/+upCpocDCN+mHQxNuf4+HK/ /Or1xVWGtUMm8KPdgAHEnfZRw3nOp6aSXm/bdgh+Qx06JWkePBlK4zUsC1w2WShn3eDi NSfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C0nQIBG+; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e2si11572092edc.604.2020.11.02.09.50.24; Mon, 02 Nov 2020 09:50:24 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C0nQIBG+; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726181AbgKBRuX (ORCPT + 6 others); Mon, 2 Nov 2020 12:50:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbgKBRuX (ORCPT ); Mon, 2 Nov 2020 12:50:23 -0500 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCF87C061A04 for ; Mon, 2 Nov 2020 09:50:22 -0800 (PST) Received: by mail-lj1-x244.google.com with SMTP id i2so16011895ljg.4 for ; Mon, 02 Nov 2020 09:50:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DRpprZ4tbXfA6U6lcH14beZQwE//DZQqeCLuljQcmow=; b=C0nQIBG+KxAvOOJxn3TdLY3FLFXyLpNt8AyQCsSm6Zpo43fK1d9m8wudva4spJqfKv 9ir6uBFG1VqMF67yYTxo1/LRs0/o9aVm1pdlTeVpXieQi7wYT3//psqlYmvYeV7WQTyo 0VZMYB3hrBk+hnz3YnaWQf4DDQsL40y88qA9qr7jdZ+ijJUFmNUq4VSHoC+oR8Dh7SU5 uezs8W0T50VZv9HNA7g5T8qyh7QKr0y2fibEHxQfU3Zq1l4UtzjHTo0NdgdkceMuIj06 pHDFnXwIESia+FImtZk6uF8nSBW4U/l6IRT53f4te9vWwwH+Ggy3lbHsV1PZk2isPNL6 B/bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DRpprZ4tbXfA6U6lcH14beZQwE//DZQqeCLuljQcmow=; b=bv4iwn/nb88j/jw7Uqe0usFqcD7N41e4sXzTJyQiReuO+E5GeRX5323ycZq4A0OW0+ f8WQCLwshI5HDxwLFHB8y4ePSSvJSJJ0QxtOG6Oaj+FUhm9fE1AMy5Vzq8nDpsAdSQqZ 51iS+CX48uq86HamJuR/Q6OoR0Gpxcjlx7wAjSm2k7e1WD2z1TqVW/fNjd/pqESxo2jl r0PX4YYqrkkRfmc+eCEu9EbzAOvq9hIgXVn/JDZ6M/EL1Lnz1iDdph4p82nRUG1gasB/ WOzNbb0b+iUHF9PrpeHEoq6TqtHVFZ4J8UJF+usdO0eUEoG/RUyOfQ4Q9bV/Dkq19yuk NMYw== X-Gm-Message-State: AOAM532MyGgINuoNPiR9NHzJJjtt3RunCR/LFsCogWx6eBIkM9y5d9NP 5JKwA2CiX0FaVDN6/JZB277AJDZgQYDVCXDZ X-Received: by 2002:a05:651c:484:: with SMTP id s4mr7364990ljc.272.1604339421423; Mon, 02 Nov 2020 09:50:21 -0800 (PST) Received: from eriador.lan ([94.25.229.254]) by smtp.gmail.com with ESMTPSA id r7sm2516163lfc.206.2020.11.02.09.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 09:50:20 -0800 (PST) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , Rob Herring , Zhang Rui , Daniel Lezcano , Amit Kucheria , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Manivannan Sadhasivam , Jishnu Prakash Subject: [PATCH v9 10/15] iio: adc: qcom-vadc-common: simplify qcom_vadc_map_voltage_temp Date: Mon, 2 Nov 2020 20:49:45 +0300 Message-Id: <20201102174950.1148498-11-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102174950.1148498-1-dmitry.baryshkov@linaro.org> References: <20201102174950.1148498-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 --- drivers/iio/adc/qcom-vadc-common.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) -- 2.28.0 diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c index 0c705bb473fe..441843827f05 100644 --- a/drivers/iio/adc/qcom-vadc-common.c +++ b/drivers/iio/adc/qcom-vadc-common.c @@ -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, u32 tablesize, s32 input, int *output) { - bool descending = 1; u32 i = 0; if (!pts) return -EINVAL; - /* Check if table is descending or ascending */ - 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; - } + while (i < tablesize && pts[i].x > input) i++; - } if (i == 0) { *output = pts[0].y; } else if (i == tablesize) { *output = pts[tablesize - 1].y; } else { - /* result is between search_index and search_index-1 */ /* interpolate linearly */ *output = fixp_linear_interpolate(pts[i - 1].x, pts[i - 1].y, pts[i].x, pts[i].y,