From patchwork Fri Dec 4 02:55:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 337713 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp818590ilb; Thu, 3 Dec 2020 18:58:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbfgKyiaBo8vBa/eUKmQ/zWsLwemhFG0faUbdVpPIfdH3QxXTNTeaVVdQ34gkBVxMSWAS/ X-Received: by 2002:a17:907:41e3:: with SMTP id nb3mr5352151ejb.378.1607050701387; Thu, 03 Dec 2020 18:58:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607050701; cv=none; d=google.com; s=arc-20160816; b=rh19rYx9GooJhPRUppKslKZywvRRwd090rsefm6lfQTb8xoeejgQgn9/XxZFelEwj2 wCuR1CQxgJtlXR92xJTVGJ2tcIj5ZXcy9a+oQPwnKBuQNOt9upyWEpeaV84d4zTBtkUD V3JX8C6vZqfjycMIruvYnj2N0Pd0J1pn+RKQpbS0HEMYvsyaiOUja4x+m8WGqNgA/wL4 //R+cZCDCXEIUHLAKrZuZRmGDrTOs13swi+mE6+bSPxFpQEiNXd67YaBqmPnC72v3aIE hqH2XEcgEra1umSeqCozG+/HIuUNX2wDNUZCSZjHdtO6ZMQRPWRNklRDNfMZf1OVNy5H X5vg== 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=ZSgtsld/jErWqUbZ6AQEllOU8y9wlhXnzPgaFJHrUyg=; b=rXnYHi792GNN8m7+BmLcV9vJMyPxorKO8xv+tV/E3VU3AC5yPh3fpe/lmtPOWxOAph dqxMfvTeU7P16LrH9T9uMsn8lp+I6B2ecZrn723vCEMka3QzjscFdsRSH5z1XS8Gqize BvOyZavWookgARr9i7r2MotLlxfZo76bXdUcweipYZSlRwH4A3sLJYqzrpip+QkJ4mjh /WgzwNahggm5xa3oT0Tsdq6ICmltZTHyTp4gHYTdJfUikmJs0xjOY9LwP/3RWyQN2Yp5 9G6RvUaRBdl19ug1Bu41U4shAH1gNohAa3KyNWU+ab5Lg/IAmN3N21kcEYTVxiEACZlF 8Dcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFJXFKor; 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 i19si558396ejr.557.2020.12.03.18.58.21; Thu, 03 Dec 2020 18:58:21 -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=CFJXFKor; 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 S1727219AbgLDC5P (ORCPT + 6 others); Thu, 3 Dec 2020 21:57:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbgLDC5P (ORCPT ); Thu, 3 Dec 2020 21:57:15 -0500 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D13B6C094259 for ; Thu, 3 Dec 2020 18:55:38 -0800 (PST) Received: by mail-lf1-x142.google.com with SMTP id d20so5688516lfe.11 for ; Thu, 03 Dec 2020 18:55:38 -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=ZSgtsld/jErWqUbZ6AQEllOU8y9wlhXnzPgaFJHrUyg=; b=CFJXFKorX1v57fHzUaPjeI/66wq4W2kEMc672Dw8tjexqJqLVT3ImUJm3kAcbHe8m8 akXngp4ulHCvjIUrNVIk4SsuHPPv/CbNrplb0Pq+1SHHt4of9kjuIJ9jiwhFq+FIWdb0 6oEhC51GLZhMofQw/i79ZXK1NVXZtX9Uaoe4j/M76xYTVWLoZy/T7+e3OPM2G5YG0/Y9 Kb7UARn0KIYJcuNYddrap/1ZerX1s6K4LsagsbdXIBVSJkSSvho2w2yK5UGZCRz6J+ym VemqSWQ1pqg6+DYj1UDMVpgMv2+R/AcB8gR+aLJp4ehSBLOyXkxOyEqiY44zIQnPggx4 yZEQ== 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=ZSgtsld/jErWqUbZ6AQEllOU8y9wlhXnzPgaFJHrUyg=; b=mcryULwv57IhfWPETbCLjY5K4hFaUzavxqPgBU9xWitZtS6w+TBqizoPlmsK03kEBc hgXF+e4kM2g6wtRcvqnI/BpXtbqFLE3nDbYQpqvuMX6J/ojfBVEhLWryEMV2m8WWofee QgpIxVM5PwGh+kBEvT5IjDJJzFRCvuFCjBq8G4aaqrefYOKuF6IMmoetwl0ybC+4KZ2h iwT+tzvRwyHHel9Ho9NQ7FWvWCluuP8rdeVUcblvdCPx8RumsWMfGMbhTNrp3CvSA++j YIK2RVj3vevczsCSMpoHRsu43Ikj8bJJDrEail+NHvVWzGs/r3Sw2Sp541iYUFoWS8Q4 cvHA== X-Gm-Message-State: AOAM531Wg+gaLkmMkGCxbRkLHxI4aJHZWQZNp34o9p+Ai8Rjv9gYV6vo 0jGX1KKIN97Ff+wJ0mw+0AtwzA== X-Received: by 2002:a19:e04c:: with SMTP id g12mr2496970lfj.261.1607050537378; Thu, 03 Dec 2020 18:55:37 -0800 (PST) Received: from eriador.lumag.spb.ru ([188.162.64.117]) by smtp.gmail.com with ESMTPSA id b8sm1131667ljo.68.2020.12.03.18.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 18:55:36 -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 v10 09/15] iio: adc: qcom-vadc-common: rewrite vadc7 die temp calculation Date: Fri, 4 Dec 2020 05:55:03 +0300 Message-Id: <20201204025509.1075506-10-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201204025509.1075506-1-dmitry.baryshkov@linaro.org> References: <20201204025509.1075506-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org qcom_vadc7_scale_hw_calib_die_temp() uses a table format different from the rest of volt/temp conversion functions in this file. Also the conversion functions results in non-monothonic values conversion, which seems wrong. Rewrite qcom_vadc7_scale_hw_calib_die_temp() to use qcom_vadc_map_voltage_temp() directly, like the rest of conversion functions do. Signed-off-by: Dmitry Baryshkov --- drivers/iio/adc/qcom-vadc-common.c | 50 +++++++----------------- include/linux/iio/adc/qcom-vadc-common.h | 5 --- 2 files changed, 15 insertions(+), 40 deletions(-) -- 2.29.2 diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c index 45a38602f66a..0c705bb473fe 100644 --- a/drivers/iio/adc/qcom-vadc-common.c +++ b/drivers/iio/adc/qcom-vadc-common.c @@ -101,18 +101,18 @@ static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = { }; static const struct vadc_map_pt adcmap7_die_temp[] = { - { 433700, 1967}, - { 473100, 1964}, - { 512400, 1957}, - { 551500, 1949}, - { 590500, 1940}, - { 629300, 1930}, - { 667900, 1921}, - { 706400, 1910}, - { 744600, 1896}, - { 782500, 1878}, - { 820100, 1859}, - { 857300, 0}, + { 857300, 160000 }, + { 820100, 140000 }, + { 782500, 120000 }, + { 744600, 100000 }, + { 706400, 80000 }, + { 667900, 60000 }, + { 629300, 40000 }, + { 590500, 20000 }, + { 551500, 0 }, + { 512400, -20000 }, + { 473100, -40000 }, + { 433700, -60000 }, }; /* @@ -585,33 +585,13 @@ static int qcom_vadc7_scale_hw_calib_die_temp( u16 adc_code, int *result_mdec) { - int voltage, vtemp0, temp, i; + int voltage; voltage = qcom_vadc_scale_code_voltage_factor(adc_code, prescale, data, 1); - if (adcmap7_die_temp[0].x > voltage) { - *result_mdec = DIE_TEMP_ADC7_SCALE_1; - return 0; - } - - if (adcmap7_die_temp[ARRAY_SIZE(adcmap7_die_temp) - 1].x <= voltage) { - *result_mdec = DIE_TEMP_ADC7_MAX; - return 0; - } - - for (i = 0; i < ARRAY_SIZE(adcmap7_die_temp); i++) - if (adcmap7_die_temp[i].x > voltage) - break; - - vtemp0 = adcmap7_die_temp[i - 1].x; - voltage = voltage - vtemp0; - temp = div64_s64(voltage * DIE_TEMP_ADC7_SCALE_FACTOR, - adcmap7_die_temp[i - 1].y); - temp += DIE_TEMP_ADC7_SCALE_1 + (DIE_TEMP_ADC7_SCALE_2 * (i - 1)); - *result_mdec = temp; - - return 0; + return qcom_vadc_map_voltage_temp(adcmap7_die_temp, ARRAY_SIZE(adcmap7_die_temp), + voltage, result_mdec); } static int qcom_vadc_scale_hw_smb_temp( diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h index 1d337dd9e3dc..58216124d89d 100644 --- a/include/linux/iio/adc/qcom-vadc-common.h +++ b/include/linux/iio/adc/qcom-vadc-common.h @@ -54,11 +54,6 @@ #define R_PU_100K 100000 #define RATIO_MAX_ADC7 BIT(14) -#define DIE_TEMP_ADC7_SCALE_1 -60000 -#define DIE_TEMP_ADC7_SCALE_2 20000 -#define DIE_TEMP_ADC7_SCALE_FACTOR 1000 -#define DIE_TEMP_ADC7_MAX 160000 - /* * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels. * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for