Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5561100pxb; Mon, 14 Feb 2022 01:58:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSRbBfIVL5UiJcPIxBar0ADQ+9adDGgevEJtGbQXLhqnbd0fVRdTrBX8BiHQbX0U0pzNzm X-Received: by 2002:a05:6402:2927:: with SMTP id ee39mr6043264edb.252.1644832732851; Mon, 14 Feb 2022 01:58:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644832732; cv=none; d=google.com; s=arc-20160816; b=IRLaUaEzsuHoLNOVmqPyEi3iGe/mIdjjxs82xQnOF6i4wcYWHSMgh4hhdF9ZZPAi0o Y76MuzCDK4KiwiyfSPsEH6o4A2fxX6khmMnPv2AfzcHA4JNsT3ECkLmjycVQonT7KLMF pRBYubgJdRhdB7tCmB+9z2xy81Ru3nmi/faIwTua81yciKEEmX2wPmTP8OoET73/WOS9 pXvnIcV/pZpXRjftj32Qf7cWVfksZ9QG3wpCJjOQ71BfjrFhG7ck1VkZW/euL3jSfvjj 1G9FbwHfbcTG7JaPZJkAkuGAyTaDJ1Q+fM5RioDNEFGB9opimaXo7mO2hrlK38yWBvK9 q8UQ== 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=c2beK8Xo7ZUA6pwRUqGcFRI5SxTB6l8oXZqr26ObJoM=; b=uwpPF+/Lx4EA49GRyrO3dPdLv6c+pdy2izy/O7UScPdKGMnj54tv/2sBBbTdAJjDG6 +tgz6S7fo1OOx1exB1eVRuuHDevMcktPMGJfIve/M89Isae+dhklXfcVoDiS3ma4L09z svBfeagTm4M/RQLWZ/moIOET/nX745xvHVEgkvZuI6iAEL3HzooYBMi3XQO/6C2IPQFT sLE0YfTvWE2U0UfAcH/pD2QXMOvx7Rddtuy1h1mJDmoSSpet156HQoQiHLOk4HAU46C6 QKWiI7zNojU4mZ9a7g4OYYsd98FjNcrlw8lFROQmwaZ6D9I+RLAtivXjKBp6cdlwHOS3 mLVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ldiF86Xq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp4si21150548ejc.140.2022.02.14.01.58.29; Mon, 14 Feb 2022 01:58:52 -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=@gmail.com header.s=20210112 header.b=ldiF86Xq; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233314AbiBMC6L (ORCPT + 99 others); Sat, 12 Feb 2022 21:58:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233132AbiBMC6C (ORCPT ); Sat, 12 Feb 2022 21:58:02 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA9E8606E8; Sat, 12 Feb 2022 18:57:52 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id r9so1396839qta.1; Sat, 12 Feb 2022 18:57:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c2beK8Xo7ZUA6pwRUqGcFRI5SxTB6l8oXZqr26ObJoM=; b=ldiF86Xq0Wu7iIPYZCMAovUvu+QjlvhE/Cj4J1nLDTbJB+U47EHmIXtJEYAeMNddlu 0jhdoobRVdoo29yXKqWma+mmCT176Q6xcxZSv6+ExlMGwlFy96mOyE/bRTxdVdN+5RLo m41BzXcSfTqJiUyPg8eF4CjzfCbKdTq25R2VxD2ROaRh+I4guWhmB2oYhpmNs9ZbJ1uI JXCLn5FKhl5pEMAmHaQ0pWX2VtvDH6wEAbibaDzOlaDofPZrhNuFqYI4gf72BXoU4AqW XcmdgfwG83/Uqv5ccsvpYqCI/3F4ykFCEDrTChoPuAQO2qLx47m5zD+2W/0t9ddyRADX Jn6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c2beK8Xo7ZUA6pwRUqGcFRI5SxTB6l8oXZqr26ObJoM=; b=58oRt1HIvfpU3j74rmZRFmUzpUQUIMsg85EtzdFaCm61LmaPfbhXUam8mMcd1dJkkT sJ+AKvpDZUElZtnDQ2z4XbHPvmC9WxxMWkeBqvT41GCoNlH2/Pl6ipkZQov3OUB4Wuor f0JNJevG99K+FQLiVnhUXqwnS6BYg0mEudm2w8cE9Ho1GoaING4rGtF/S4dGHe0N/LCU Nxq9Xw5Iktm+3CUyu+7dKccChgmJZLWk/QwsjyfWMkGu3Vpk5UFa8Ag4xcPfwM8/via/ 5UE8eZyi9rdgoSQyZIeNrd7A0yiYfGTIA/EguNxVouANifHQ6Jm8Hce0KtfoDeWfyyBE oSZg== X-Gm-Message-State: AOAM530LgRiiJgPqaAv5i7QEqNQvsKFSKOCpfjrxYa7UVIOGsf/+w87h TVhZ8DqFuqQ/AtL2s3pvkqM= X-Received: by 2002:ac8:5b8a:: with SMTP id a10mr5604208qta.469.1644721072056; Sat, 12 Feb 2022 18:57:52 -0800 (PST) Received: from shaak.. (modemcable055.92-163-184.mc.videotron.ca. [184.163.92.55]) by smtp.gmail.com with ESMTPSA id y15sm14551106qkp.22.2022.02.12.18.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 18:57:51 -0800 (PST) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, andy.shevchenko@gmail.com, lars@metafoo.de Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v15 07/10] iio: afe: rescale: add RTD temperature sensor support Date: Sat, 12 Feb 2022 21:57:36 -0500 Message-Id: <20220213025739.2561834-8-liambeguin@gmail.com> X-Mailer: git-send-email 2.35.1.4.g5d01301f2b86 In-Reply-To: <20220213025739.2561834-1-liambeguin@gmail.com> References: <20220213025739.2561834-1-liambeguin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 An RTD (Resistance Temperature Detector) is a kind of temperature sensor used to get a linear voltage to temperature reading within a give range (usually 0 to 100 degrees Celsius). Common types of RTDs include PT100, PT500, and PT1000. Signed-off-by: Liam Beguin Reviewed-by: Peter Rosin --- drivers/iio/afe/iio-rescale.c | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 46947c68d3a9..e31a93435536 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -394,10 +394,52 @@ static int rescale_voltage_divider_props(struct device *dev, return 0; } +static int rescale_temp_sense_rtd_props(struct device *dev, + struct rescale *rescale) +{ + u32 factor; + u32 alpha; + u32 iexc; + u32 tmp; + int ret; + u32 r0; + + ret = device_property_read_u32(dev, "excitation-current-microamp", + &iexc); + if (ret) { + dev_err(dev, "failed to read excitation-current-microamp: %d\n", + ret); + return ret; + } + + ret = device_property_read_u32(dev, "alpha-ppm-per-celsius", &alpha); + if (ret) { + dev_err(dev, "failed to read alpha-ppm-per-celsius: %d\n", + ret); + return ret; + } + + ret = device_property_read_u32(dev, "r-naught-ohms", &r0); + if (ret) { + dev_err(dev, "failed to read r-naught-ohms: %d\n", ret); + return ret; + } + + tmp = r0 * iexc * alpha / 1000000; + factor = gcd(tmp, 1000000); + rescale->numerator = 1000000 / factor; + rescale->denominator = tmp / factor; + + rescale->offset = -1 * ((r0 * iexc) / 1000); + + return 0; +} + enum rescale_variant { CURRENT_SENSE_AMPLIFIER, CURRENT_SENSE_SHUNT, VOLTAGE_DIVIDER, + TEMP_SENSE_RTD, }; static const struct rescale_cfg rescale_cfg[] = { @@ -413,6 +455,10 @@ static const struct rescale_cfg rescale_cfg[] = { .type = IIO_VOLTAGE, .props = rescale_voltage_divider_props, }, + [TEMP_SENSE_RTD] = { + .type = IIO_TEMP, + .props = rescale_temp_sense_rtd_props, + }, }; static const struct of_device_id rescale_match[] = { @@ -422,6 +468,8 @@ static const struct of_device_id rescale_match[] = { .data = &rescale_cfg[CURRENT_SENSE_SHUNT], }, { .compatible = "voltage-divider", .data = &rescale_cfg[VOLTAGE_DIVIDER], }, + { .compatible = "temperature-sense-rtd", + .data = &rescale_cfg[TEMP_SENSE_RTD], }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, rescale_match); -- 2.35.1.4.g5d01301f2b86