Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5573891pxb; Mon, 14 Feb 2022 02:20:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJznoqG3NbR2CjREl8KPYHi5fiE0r/8yyGojUxkdZGCtxbVGtj1Hj/RsmeDXbyEGAyb3pXEF X-Received: by 2002:a17:902:9a01:: with SMTP id v1mr13582190plp.56.1644834034292; Mon, 14 Feb 2022 02:20:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644834034; cv=none; d=google.com; s=arc-20160816; b=NkTI/DH8QTBPUvWwPJlk245zgQopjpYZ/BFJ4mwDZCQOQh1yUYjik394LJKTxL7pCK xQOqoiUY5vJSboPp7Lo14m0A6Q9TmLn+QdmL8Ld3tOU2/HyPOTrqcXiWU9YlOocxikbo QRy6meRGw2QyTQT3ussnvdTqN4Bm1cBF655wcEXjKvUcmAvar/CJ0pmO8SPa+EWi5Z/f KFRT1VAkO4BM+rqWxjBbTkVSNJS/c+m0j6rz1YcZQ+w2BUHCkF//Dzhq972TkiLQPgMR i4A0N7ab2HS2VLvKe9oeDsB3sXpqQt0gobV9n99y6bw7yTwHWrpUF4Bi/S4yTBk6nmVQ 1HJA== 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=gWGMuENIp5ABdPGYrwRx0hXXLgJxcdaH5muPkebQTU0ED8BP8OEas1sqj5kAAeZOYV IuT7r2T0xlG8N4WxpY7zhcdwWEcvQn1xtT8c7V2cdn5tSfJfi7SLcxNnyjxrNqvKoC4U yKiZkZbAxkh6Du5+YqX4tVCuytGBL5rko6AxNUoibLsxp+fImOggSbREyTe8nkqeOsl5 uxmdtB2wWeHj6JHsYuD98o/OO+jfLX/8mLTT6Q7nPa1ljYnnmOCqwwSG+MWd2PxA2pZj PvaPuo7m+mbe7XYpbJg91ifac9Le96P1qHED2MQoO/LTY99BbLP2hHHRkEzX2ldvvxhm mM6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=cghM2ktt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y5si17298291pgy.290.2022.02.14.02.20.19; Mon, 14 Feb 2022 02:20:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=cghM2ktt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234425AbiBMIeI (ORCPT + 99 others); Sun, 13 Feb 2022 03:34:08 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234459AbiBMIeH (ORCPT ); Sun, 13 Feb 2022 03:34:07 -0500 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56DE45EDDD; Sun, 13 Feb 2022 00:34:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1644741241; x=1676277241; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=02jKCSFUrWcNdgliBGzyvoi3mQqWkLT055iJwDV45LQ=; b=cghM2kttYxZ964enDYNn82MsS9mPLMOSLEoVgO+iJDRfw31WwUmww1qf 7zbVtiBVI91+YBY5mIM4O2VKQ1yILys5ljY4AHJTq+Hm8vaZas32+0FrB bIV0lysgFcFTX9G7NGBmEizPIP7YWCfsE8PnPfXEJ7R/VHzmK58QMDFgy 4=; Received: from unknown (HELO ironmsg02-sd.qualcomm.com) ([10.53.140.142]) by alexa-out-sd-01.qualcomm.com with ESMTP; 13 Feb 2022 00:34:00 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg02-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 00:34:00 -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.986.15; Sun, 13 Feb 2022 00:34:00 -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, 13 Feb 2022 00:33:52 -0800 From: Jishnu Prakash To: , , , , , , , , , , , , , , , , , , Jishnu Prakash , , , CC: , Subject: [PATCH V5 2/4] iio: adc: qcom-vadc-common: add reverse scaling for PMIC5 Gen2 ADC_TM Date: Sun, 13 Feb 2022 14:03:09 +0530 Message-ID: <1644741191-12039-3-git-send-email-quic_jprakash@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1644741191-12039-1-git-send-email-quic_jprakash@quicinc.com> References: <1644741191-12039-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) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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