Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3407885pxb; Mon, 24 Jan 2022 08:58:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzq0MIY2bfrahU2gSRox3GtnEnQ08nlB2zqsaiV2z1xyD85tIzWS8NxwjvAe41lKXs1S1ow X-Received: by 2002:a17:90b:1949:: with SMTP id nk9mr2741237pjb.219.1643043531457; Mon, 24 Jan 2022 08:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643043531; cv=none; d=google.com; s=arc-20160816; b=Acnw/prhNNR1/AIPUoE/OLsx8/nO1f6RVteYEe2UBWsGx4YPVoh9jthbMoxLXvmr8i PNxX+GXkJr+m6d5sMxxiwpRov27FwTUZl0uvx4h0/61wyDzJfH/SZPLz2sspbgXW+BLV hHPh2TJhGkX8xGQUeLkaWwF0HxPENDBvJTrPM9/VWBouYwTw5t3pvsAFujlAmVphaHPu Q5am7bgRqGOmqRA15q0yqwkIIEqEgd0yEuhp0MzLsKj0XDkIapmO0gS08b36mqSzEHGu U9jCfFMyfDZoqECVFxTkRrijFzUY+IkOVwExikcsB3o4RQ6fN+GlTJurDvy0AGcMNSj4 8izA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=02jKCSFUrWcNdgliBGzyvoi3mQqWkLT055iJwDV45LQ=; b=H2Q+0WcldvzjbEujwc+eSjlNxTE8EQlKzdXjfRMPNGMQuVjGwJYzmappxDNe1DAhaD mPPuBTW5Ghx25m3JcPh9gqR3bCiSjO3ZD2ZLBXHPCwjkxM1LOruCeucxVWIE4KfMUEwo 77uDFzUQqpGRkuqxZLiZf2YagkarDt4BaXHqXxDMZeE3SLH8m3E+BDQe/xosNlhnHLqI EAgi1OtAF23qYzS3YFDfpYqlpGdPY4GphlkR3fsTpWBWRMRY7AfSMBNmP2vmA9sDFOPc 30cmB9fLMTPGyuU+qVBmnOrX/iwMZZ71L82Yd9rCPzaakMuq5HGKkGGbyafhYq6gyNXF uTjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=F06kob4j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si13263161pje.58.2022.01.24.08.58.38; Mon, 24 Jan 2022 08:58:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@quicinc.com header.s=qcdkim header.b=F06kob4j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241358AbiAXEYN (ORCPT + 99 others); Sun, 23 Jan 2022 23:24:13 -0500 Received: from alexa-out-sd-01.qualcomm.com ([199.106.114.38]:56173 "EHLO alexa-out-sd-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241355AbiAXEYE (ORCPT ); Sun, 23 Jan 2022 23:24:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1642998244; x=1674534244; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=02jKCSFUrWcNdgliBGzyvoi3mQqWkLT055iJwDV45LQ=; b=F06kob4jFrhYfV2K43vf072Xaty4AhTByVcBXr8+h1vqs7aCNWXdb7Ms OeEiqFThbfJH5FExqBUvBqVq8OstFJpiWNRpb+kwbgJP2SOxcJOfJr6Hg dqtqACFmF+co0Hhk6H3CZAwC0fjoByhAj+qh3U11ewL2eW6dNK0sG9G0p M=; Received: from unknown (HELO ironmsg05-sd.qualcomm.com) ([10.53.140.145]) by alexa-out-sd-01.qualcomm.com with ESMTP; 23 Jan 2022 20:24:02 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg05-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2022 20:24:02 -0800 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Sun, 23 Jan 2022 20:24:01 -0800 Received: from jprakash-linux.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Sun, 23 Jan 2022 20:23:53 -0800 From: Jishnu Prakash To: , , , , , , , , , , , , , , , , , , Jishnu Prakash , , , CC: , Subject: [PATCH V4 2/4] iio: adc: qcom-vadc-common: add reverse scaling for PMIC5 Gen2 ADC_TM Date: Mon, 24 Jan 2022 09:53:12 +0530 Message-ID: <1642998194-12899-3-git-send-email-quic_jprakash@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1642998194-12899-1-git-send-email-quic_jprakash@quicinc.com> References: <1642998194-12899-1-git-send-email-quic_jprakash@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add reverse scaling function for PMIC5 Gen2 ADC_TM, to convert temperature to raw ADC code, for setting thresholds for thermistor channels. Signed-off-by: Jishnu Prakash Acked-by: Jonathan Cameron --- drivers/iio/adc/qcom-vadc-common.c | 11 +++++++++++ include/linux/iio/adc/qcom-vadc-common.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c index 1472389..194d7c3 100644 --- a/drivers/iio/adc/qcom-vadc-common.c +++ b/drivers/iio/adc/qcom-vadc-common.c @@ -677,6 +677,17 @@ u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio, } EXPORT_SYMBOL(qcom_adc_tm5_temp_volt_scale); +u16 qcom_adc_tm5_gen2_temp_res_scale(int temp) +{ + int64_t resistance; + + resistance = qcom_vadc_map_temp_voltage(adcmap7_100k, + ARRAY_SIZE(adcmap7_100k), temp); + + return div64_s64(resistance * RATIO_MAX_ADC7, resistance + R_PU_100K); +} +EXPORT_SYMBOL(qcom_adc_tm5_gen2_temp_res_scale); + int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype, unsigned int prescale_ratio, const struct adc5_data *data, diff --git a/include/linux/iio/adc/qcom-vadc-common.h b/include/linux/iio/adc/qcom-vadc-common.h index 33f60f4..598a5d2 100644 --- a/include/linux/iio/adc/qcom-vadc-common.h +++ b/include/linux/iio/adc/qcom-vadc-common.h @@ -161,6 +161,8 @@ int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype, u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio, u32 full_scale_code_volt, int temp); +u16 qcom_adc_tm5_gen2_temp_res_scale(int temp); + int qcom_adc5_prescaling_from_dt(u32 num, u32 den); int qcom_adc5_hw_settle_time_from_dt(u32 value, const unsigned int *hw_settle); -- 2.7.4