Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1725134pxb; Fri, 20 Aug 2021 12:20:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/z6Z8FQx1VXPpfoREOoAy9G75O9iuerNc0HNl9IhJ126fJEGgdOwCBQakM2uznPr4VTq7 X-Received: by 2002:a50:cc0b:: with SMTP id m11mr23654556edi.96.1629487254278; Fri, 20 Aug 2021 12:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629487254; cv=none; d=google.com; s=arc-20160816; b=FGJNVmPF/plkJ6l0xyKPtwiuiwmAbXTqjbYGzZKSvm775bnE8GFDvNt+GdHmIM1oIS Vnc/HeVGKaZzo/24kPaV9g+ZPFU50xxwJw1RCF4RdHtLdNKHF4qhecgHGn9D3hx3dIzP MfgfHlIJ0MqmkGNSdMJzsupb8xv975ImWCUmt3jdpna8LUr62OipVrur2RUvMlR6O6qJ 26IE1+FcfkoPMFItGLvGbqv9UQ0u9vCobUykhnLkQl6/bse8Li8GaG4MUTsurlSmeqlg 0ZTOkhxegozPZpTvFojayTvH3TujUrQmh2uOPQ3BQ0//ETBf4rJXTpIaW79YWOXnn1Sm FUtA== 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=+eLtC7JNuGxTnORcSm7E5kaYd0kc5jriuJPklML6vkM=; b=DiswEbAwjv3XQ3O7j65oDSzhZJZeWYJc81wyCcFCbx7GiIoSZlUmRJfC42ZvIX/uK/ UwRwROkL5Uuvd1t+LVIQ6DhMYyH67ebV8tbCU9XG80qSN42VPmFyZmPObmU/K9PQHUz6 dHXgDKof6mp93doPg6P6G8ulW6qSbw97tlIvXTaSkMGJ6NcLPQurVSDlr5OzwiI5FzA9 N/mEezwQLdtZ1o2GZXlyfcHKsEIPHaQ8nxD6yc7vLd6BRm72E1WK1PODVt3pKqO7IYyO S8yMd3Z5CZm46qtc/9qX0WD0EHTxFsZifOjyk3D2rewZAJ60TSKmFEYQmBq+QjZ7avka r6vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=io06IjKI; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jy1si7098156ejc.140.2021.08.20.12.20.30; Fri, 20 Aug 2021 12:20:54 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=io06IjKI; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240150AbhHTTTD (ORCPT + 99 others); Fri, 20 Aug 2021 15:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238723AbhHTTSp (ORCPT ); Fri, 20 Aug 2021 15:18:45 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F4E5C061575; Fri, 20 Aug 2021 12:18:04 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id 14so11953696qkc.4; Fri, 20 Aug 2021 12:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+eLtC7JNuGxTnORcSm7E5kaYd0kc5jriuJPklML6vkM=; b=io06IjKIAKAV/u574Zq+DnR6x/4Cxf/C7zpEFPJEjFo6o0RhuVKBYaY+rTML5h9HfY UcoyrN2K5aIGIBIBcC8/c8Wrtl4Z4ggZPhtHMmz0fjmatLRAWC91FavgDLRFz4eqI8wc Jju53yYDf7y1NDgysa3HrnVG4KWZrriWRz+JbV44F6Zxob8/90y8quazYsSUbyW0WZ10 meNwopX1kXJygTJHNDplPWUSprBXTeGgFOOGPtvNcOu8JsyWMoz/IbQbtYDfkMeX2ngG /I7qoWd6yIOAnQyF2bozwhwdNOHx7SB7MQv4uvGUQB/NUYzlZUPntyHTyTmq4TLNn7Yg VU/w== 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=+eLtC7JNuGxTnORcSm7E5kaYd0kc5jriuJPklML6vkM=; b=q25iRXGJ4jQ4vRCdVU/+u7cigAMOGjR4I695uHL5bvSUxs/0JaCH6o24K8iItrHbg0 qM/wvc38CQTlgaKx2ZRiyPxllXZohf5fZ2J4Fqsg/KppPxDPccn0d6hw6wW6PNWlk/RG qHKPYE/FmRfr5RyLBoaCKbGjixQq09zSSepGwKXNEtPPC0CclGWYeFXDt8nt9FuuEUnw qAYEfXbL/kAYZdB4PjSIUa5CfpZxZjsrKGR4RAoBdywwPKKU6rBagTYPb42/VCxrdJ6Y 6UkDtMhV+Zt9XaifWpt62AOAujlmsdOfo9/KIjtFaWGNlIfDZ7lbFdEtBpTeaG69jwDE sPCQ== X-Gm-Message-State: AOAM53306KeJm9rRbqHGrxuOTZZfGyE6ZjhSDkvJyr+nfdO80YSx/gOC y91plRWoitskIHbiPYtOBCXdgWL36dY= X-Received: by 2002:a37:a60f:: with SMTP id p15mr10120471qke.377.1629487083584; Fri, 20 Aug 2021 12:18:03 -0700 (PDT) Received: from shaak.xiphos.ca (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id o6sm3603869qkp.111.2021.08.20.12.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 12:18:03 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v8 11/14] iio: afe: rescale: add RTD temperature sensor support Date: Fri, 20 Aug 2021 15:17:11 -0400 Message-Id: <20210820191714.69898-12-liambeguin@gmail.com> X-Mailer: git-send-email 2.32.0.452.g940fe202adcb In-Reply-To: <20210820191714.69898-1-liambeguin@gmail.com> References: <20210820191714.69898-1-liambeguin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liam Beguin 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 --- 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 7304306c9806..8cdcb6ffb563 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -386,10 +386,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[] = { @@ -405,6 +447,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[] = { @@ -414,6 +460,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.32.0.452.g940fe202adcb