From patchwork Thu Jul 15 03:12:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 477627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF604C1B08C for ; Thu, 15 Jul 2021 03:12:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98AFF613A9 for ; Thu, 15 Jul 2021 03:12:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233066AbhGODPc (ORCPT ); Wed, 14 Jul 2021 23:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232770AbhGODPb (ORCPT ); Wed, 14 Jul 2021 23:15:31 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56624C06175F; Wed, 14 Jul 2021 20:12:38 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id 201so3809957qkj.13; Wed, 14 Jul 2021 20:12:38 -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=aLIjEv3Y3XGxT5C/sRBa0wIugXh2Hwubx4IA7LHkqcs=; b=SXLG1AME+jZDiQqShuO4lpIRMS9uk2FqeRX8KwMynZa6qHxraMumJPtoE+KOcoEP27 NRfaF7avW9GRpi8uoPHBWsBXJSWkVnbzh38md12tnZkYiFFZ0iL39lb4BJMmqds7ZGXi ZMK9MKhO9oLyO4TCmN2+gqGPfzG/8OGOUhm/6RFPwtUpvdANj1ybGpU63OttTGhWq1B4 bHBXcTL3u9YoHJxYCV+21PEq8pYW4vEhCeFpCT2GYFp86f5s4MhCK5iuXBlTkPyhsGq3 zliP96Y36O0OL+3YOfSkt3eCoWvnwo+++ctA9DHqbMrWkBRSByCFdYqmfDyB1OFzm3+h eZWw== 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=aLIjEv3Y3XGxT5C/sRBa0wIugXh2Hwubx4IA7LHkqcs=; b=hFZXwBxRWmsXJQkXmnuvusTVp6sSdQOoInID5hteDy5LfCLJ4cTEdTbquD5IntXiUk PRFpPEBD5duzRYtHfGB0ULQjAAsG5r01YhJTE0fQ6wLyzSXh+jtskDS1tfWNFHIHaKKd Xj42vGh6RUmJRAsIQrrXzJlG+vOTlEZYgCkwdrASeyYhGmDgJ4fpSPLBCzkXvWI4DQfR 5HyFtcJqsJOge2j0mnxhkHk23wUcyEJGzCMAFO4MyPXs117MABnC82CeNgchP4QVCD5e wVvu7Agh8FMETMRaP4PtKCc86OJLuc+gZK9MXFk/zm+Nx/c1KyLbtQOmKN3EMGgLohwx ZXqw== X-Gm-Message-State: AOAM530TU6BN4qoIrLKhJSnPSGw1TUv0LOGtSUeR0zr2FqekH3BiOvk9 9LCtL/ore6fnKpsZ783tzTE= X-Google-Smtp-Source: ABdhPJw4L1G9mU41qAAtvtnmbgrKFIwht/EEvVq66G/8c7BnBFneE+CvHdRnYhVkpVQRk03F0KcXqw== X-Received: by 2002:a37:b983:: with SMTP id j125mr1435238qkf.482.1626318757409; Wed, 14 Jul 2021 20:12:37 -0700 (PDT) Received: from shaak.. (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id t125sm1932847qkf.41.2021.07.14.20.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 20:12:37 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v5 01/10] iio: inkern: apply consumer scale on IIO_VAL_INT cases Date: Wed, 14 Jul 2021 23:12:06 -0400 Message-Id: <20210715031215.1534938-2-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210715031215.1534938-1-liambeguin@gmail.com> References: <20210715031215.1534938-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Liam Beguin When a consumer calls iio_read_channel_processed() and the channel has an integer scale, the scale channel scale is applied and the processed value is returned as expected. On the other hand, if the consumer calls iio_convert_raw_to_processed() the scaling factor requested by the consumer is not applied. This for example causes the consumer to process mV when expecting uV. Make sure to always apply the scaling factor requested by the consumer. Fixes: 48e44ce0f881 ("iio:inkern: Add function to read the processed value") Signed-off-by: Liam Beguin --- drivers/iio/inkern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index 391a3380a1d1..b752fe5818e7 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -599,7 +599,7 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, switch (scale_type) { case IIO_VAL_INT: - *processed = raw64 * scale_val; + *processed = raw64 * scale_val * scale; break; case IIO_VAL_INT_PLUS_MICRO: if (scale_val2 < 0) From patchwork Thu Jul 15 03:12:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 477626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9560C12002 for ; Thu, 15 Jul 2021 03:12:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 94F6B613BF for ; Thu, 15 Jul 2021 03:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233196AbhGODPe (ORCPT ); Wed, 14 Jul 2021 23:15:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233203AbhGODPe (ORCPT ); Wed, 14 Jul 2021 23:15:34 -0400 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 320B8C061762; Wed, 14 Jul 2021 20:12:40 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id i4so2147996qvq.10; Wed, 14 Jul 2021 20:12:40 -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=zhQeMelYWNMHpFAMGtlyl1sUbg34IFFWmo4FOYtEzaY=; b=ktixEYDEVNnbF74lVxjv9jgUdBZOLbrHEfbaIXe+S9yjG0+RMCXjpopBCzHmDxq+6R Dj4c+QK0cQtwkV6/ZV8sPSZILtTLZhP3I6SUxzjiRsGgGTz5kxfmQ98IlJbfAboD73OK owzBT9PM9wsTNlLdKyLSDa1/kqLWr1jVNNp1Y9K+6bGERaA/I9RaGF4ERnBmdM5l1Jca FrGwtJktm08v2gmdEJO9Q+bVY6emN4jU2B4igq+HUKHWqftSMZLq1vLUxHZCGkAbjYFx lU/6qWidSu+UTMtSz3pJwg95vXnZpAMCS43ZBjQQaY/pGzp9veUh9hSfcRUFsyMRm7F4 Cvqg== 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=zhQeMelYWNMHpFAMGtlyl1sUbg34IFFWmo4FOYtEzaY=; b=ASmFYITtJ/CPlyzSFvO6llvfygHsXMPfLjj4g9136rBS59ahfkl+tZBGDwVETFBb0R t7IahSX/RCTJrFXiroZggYCq7ojS6vV76BvTZOUbjgNhIZuOmKuO+5EZrh/jsD3fVTwD hkaqjR95crbk71zXZEzj07JU8thSa6lKKRFZkrJKdXW+lKd5VPghuOdiF5PN9qeYt7Ze WXJ9WAnokCTg9o/NJng2bfSWCGX5GRKWmtns0Vv1TyZb7OQlSm+8v5wsRAk9/cYLg1TF pBy2P1z2WC58pIanHOiu3AE6/FmPR7S21JofzDWXr6CkjIiPu1YPtwU89Mrh2y/GoBWf iQFA== X-Gm-Message-State: AOAM531/EnRiIft81cH4Hpeu1b/SZGfnElOF8akZ3bYsJzqgLNOOuj+L STEd6Fhn/I7+IheO2QuWj6s= X-Google-Smtp-Source: ABdhPJzIMh0zeoSBwJFrjf+LAo5y5X5Bp0wecd1qRUmjTxiQne/KjylzYcrTCoO/vvCTPM0RQZZfiQ== X-Received: by 2002:ad4:5ca6:: with SMTP id q6mr1604863qvh.23.1626318759467; Wed, 14 Jul 2021 20:12:39 -0700 (PDT) Received: from shaak.. (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id t125sm1932847qkf.41.2021.07.14.20.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 20:12:39 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v5 03/10] iio: inkern: make a best effort on offset calculation Date: Wed, 14 Jul 2021 23:12:08 -0400 Message-Id: <20210715031215.1534938-4-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210715031215.1534938-1-liambeguin@gmail.com> References: <20210715031215.1534938-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Liam Beguin iio_convert_raw_to_processed_unlocked() assumes the offset is an integer. Make a best effort to get a valid offset value for fractional cases without breaking implicit truncations. Fixes: 48e44ce0f881 ("iio:inkern: Add function to read the processed value") Signed-off-by: Liam Beguin --- drivers/iio/inkern.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index b69027690ed5..5e74d8983874 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -578,13 +578,35 @@ EXPORT_SYMBOL_GPL(iio_read_channel_average_raw); static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, int raw, int *processed, unsigned int scale) { - int scale_type, scale_val, scale_val2, offset; + int scale_type, scale_val, scale_val2; + int offset_type, offset_val, offset_val2; s64 raw64 = raw; - int ret; - ret = iio_channel_read(chan, &offset, NULL, IIO_CHAN_INFO_OFFSET); - if (ret >= 0) - raw64 += offset; + offset_type = iio_channel_read(chan, &offset_val, &offset_val2, + IIO_CHAN_INFO_OFFSET); + if (offset_type >= 0) { + switch (offset_type) { + case IIO_VAL_INT: + break; + case IIO_VAL_INT_PLUS_MICRO: + case IIO_VAL_INT_PLUS_NANO: + /* + * Both IIO_VAL_INT_PLUS_MICRO and IIO_VAL_INT_PLUS_NANO + * implicitely truncate the offset to it's integer form. + */ + break; + case IIO_VAL_FRACTIONAL: + offset_val /= offset_val2; + break; + case IIO_VAL_FRACTIONAL_LOG2: + offset_val /= (1 << offset_val2); + break; + default: + return -EINVAL; + } + + raw64 += offset_val; + } scale_type = iio_channel_read(chan, &scale_val, &scale_val2, IIO_CHAN_INFO_SCALE); From patchwork Thu Jul 15 03:12:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 477625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEF58C47E4E for ; Thu, 15 Jul 2021 03:12:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6724613BA for ; Thu, 15 Jul 2021 03:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233350AbhGODPh (ORCPT ); Wed, 14 Jul 2021 23:15:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233228AbhGODPf (ORCPT ); Wed, 14 Jul 2021 23:15:35 -0400 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52F53C061760; Wed, 14 Jul 2021 20:12:42 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id g8so3556201qtj.1; Wed, 14 Jul 2021 20:12:42 -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=WLWy0WK3+ERUVTzvLsLdoDiohksSvGaMH/lm8OdurSg=; b=fJiKfBdFQonXOMJ2QOZC9NrQf65f+pBqU/sjEOoUx2qPRgqTzs7TAtA6gB5p5yyi8m MVhrGXTJhaedinyYqEI6XP9wKi/+xIjvP58GNDLBSoFcf7wo2fcsBrUJgc77uVaVY4Tu V/YgvhdfWD9mOqmpptgxPVkMK0ZIPFxRpXRX/F5fpQzflvCVc/siRrjVFHJGwsiDRTZK d0Azlgpdnz9dOLwjwplRYM3Pg+8sLmCnOMLuj3/PM21l4S4rlaOFpF/ojCs+5XbsUAZz ORpjArA1kaqgYps88mr3k5k1i9vImAR5EMNeeMDcv67WJvXEpRNpHD4kg2smsRLsSUNE gc6g== 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=WLWy0WK3+ERUVTzvLsLdoDiohksSvGaMH/lm8OdurSg=; b=oJaoukPxFyOptxBWK7QnNmYyGsXGfc74V14d9oJEneux9i/xdZE73ljjICqiEddArb 9MqKCg6CpEM5TPUG2cbU86+76ckBCgYG68Q7rLAmn+FVOHEFAT6lD05ZRA7UFLEFAFcT 2/fewjBo1MjixLzr7924gt65ubxh8YBnL5f1abq6SpUeD5grr4AkkAmxC9oglKVqIFrm bvBA6X3dQ27F3X8VvFBgl2df1Ljh31kAZnnYBKDIK/YnTk4jZ8ZsdnCrv9snPgL679Jd 78p4HjSXi4ExG5vUf2Mijkmd2k351qG+pe+Fe5kJFgr/SlfgRftIYo7XfRKC0ZUEoJ6f Cxcw== X-Gm-Message-State: AOAM532dIJYnHStEbobGj+VH4Uge2DqYCqFxt4YDlYX1TzD+4lrPmnLW aHvCzuSIUbdfg8NDg5uPEUw= X-Google-Smtp-Source: ABdhPJx+5UrwYVMjlXUdPd3/akPUbcWCZSBNSi02lW/icOsZlzzssGlJ+2+tVPp/4tkmU8/u4NxlOA== X-Received: by 2002:ac8:7fd6:: with SMTP id b22mr788094qtk.235.1626318761533; Wed, 14 Jul 2021 20:12:41 -0700 (PDT) Received: from shaak.. (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id t125sm1932847qkf.41.2021.07.14.20.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 20:12:41 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v5 05/10] iio: afe: rescale: add INT_PLUS_{MICRO, NANO} support Date: Wed, 14 Jul 2021 23:12:10 -0400 Message-Id: <20210715031215.1534938-6-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210715031215.1534938-1-liambeguin@gmail.com> References: <20210715031215.1534938-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Liam Beguin Some ADCs use IIO_VAL_INT_PLUS_{NANO,MICRO} scale types. Add support for these to allow using the iio-rescaler with them. Signed-off-by: Liam Beguin --- drivers/iio/afe/iio-rescale.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 4c3cfd4d5181..a2b220b5ba86 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -92,7 +92,22 @@ static int rescale_read_raw(struct iio_dev *indio_dev, do_div(tmp, 1000000000LL); *val = tmp; return ret; + case IIO_VAL_INT_PLUS_NANO: + tmp = ((s64)*val * 1000000000LL + *val2) * rescale->numerator; + do_div(tmp, rescale->denominator); + + *val = div_s64(tmp, 1000000000LL); + *val2 = tmp - *val * 1000000000LL; + return ret; + case IIO_VAL_INT_PLUS_MICRO: + tmp = ((s64)*val * 1000000LL + *val2) * rescale->numerator; + do_div(tmp, rescale->denominator); + + *val = div_s64(tmp, 1000000LL); + *val2 = tmp - *val * 1000000LL; + return ret; default: + dev_err(&indio_dev->dev, "unsupported type %d\n", ret); return -EOPNOTSUPP; } default: From patchwork Thu Jul 15 03:12:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 477624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EE15C47E4B for ; Thu, 15 Jul 2021 03:12:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C3EE613A9 for ; Thu, 15 Jul 2021 03:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233434AbhGODPj (ORCPT ); Wed, 14 Jul 2021 23:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233416AbhGODPi (ORCPT ); Wed, 14 Jul 2021 23:15:38 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D4C6C061767; Wed, 14 Jul 2021 20:12:45 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id x24so3510293qts.11; Wed, 14 Jul 2021 20:12:45 -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=iG9doMSkOjGbuRC6SLDooD1hmJaLMt+b8S+uRbwt3Gs=; b=pLISMormbjm2qrxlnj+b6/aOoaQsHPIRQ94TSugwqMuhT11+1SJXlbnPzv7WC/vAQA K90IBO6+hBJuy2TVxq16p9lYBpyVX7lEQrTiwYOuLpa0Vmh3TrBA6KSDnwADq+cPtSFv SIPjpiuOG13TgDAi/9CXV/sL0DC+V+FH+dVx6cfpsjK1cLxOYp/PXaMsuVoeeNlTAo4K /LMKRfc7auXtDoXyV3RGBxkW99eLBhyL/C7cWn4oLonU4ON3rENly7Vyp/DZnTJYi3p3 qBWmf//pSTETXekyln8t0ArqREmkV7T1wB2bcG6DF+gGDod+yGeDxdO+5xF9OaULL8m3 82kg== 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=iG9doMSkOjGbuRC6SLDooD1hmJaLMt+b8S+uRbwt3Gs=; b=JdfkhNbsqD2fjWDUx0aUN6+HBEvAU94L3aSB3OPWimrNH8UhZBritH4Cc3qAAi+Wzp zYw0Zb2Wgq4UH1co7KQR4gv7rlF2gWez4Ub1VIHFCOgyjlIyixjYsV1681uPAvIKOn5P sDIfGqlJvMakj7rR69ekSJkUUV4+6iO0p5yo0zuVcOZ2CjxQ3WMuOjfC6k1N/R+/1tKD g5qbq78YULIrM1sIgaqxVDKEgJJ/aidfozbjnrN2CNzwk8YApJOq+YtmGgF1aVKSNQcL SKwGdD6quy39gZnXbxIpSWuZMf8SDxfWVo0wrequ7/KyDhsU+9/PR8PKZrf+xW7qiYrE 4IyQ== X-Gm-Message-State: AOAM532t1RrmhR8iQ0UK+JkDP4qx2kEndTJhnLHOAnUKnPu24m4W7j4y 7w2euEbXrssAeT/xPpxv1xg= X-Google-Smtp-Source: ABdhPJwon8CRGlIixWaw59adLEzkn7nOwC2lXLvSvQ3CsmICZFdFnnQyfEn+W0j9K3sZX839jzfQyA== X-Received: by 2002:ac8:dc9:: with SMTP id t9mr1572776qti.293.1626318764633; Wed, 14 Jul 2021 20:12:44 -0700 (PDT) Received: from shaak.. (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id t125sm1932847qkf.41.2021.07.14.20.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 20:12:44 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v5 08/10] iio: afe: rescale: add temperature transducers Date: Wed, 14 Jul 2021 23:12:13 -0400 Message-Id: <20210715031215.1534938-9-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210715031215.1534938-1-liambeguin@gmail.com> References: <20210715031215.1534938-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Liam Beguin A temperature transducer is a device that converts a thermal quantity into any other physical quantity. This patch add support for temperature to voltage (like the LTC2997) and temperature to current (like the AD590) linear transducers. In both cases these are assumed to be connected to a voltage ADC. Signed-off-by: Liam Beguin --- drivers/iio/afe/iio-rescale.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c index 055f6b7c9869..4b3b5e9bbe40 100644 --- a/drivers/iio/afe/iio-rescale.c +++ b/drivers/iio/afe/iio-rescale.c @@ -397,11 +397,38 @@ static int rescale_temp_sense_rtd_props(struct device *dev, return 0; } +static int rescale_temp_transducer_props(struct device *dev, + struct rescale *rescale) +{ + s32 offset = 0; + s32 sense = 1; + s32 alpha; + s64 tmp; + int ret; + + device_property_read_u32(dev, "sense-offset-millicelsius", &offset); + device_property_read_u32(dev, "sense-resistor-ohms", &sense); + 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; + } + + rescale->numerator = 1000000; + rescale->denominator = alpha * sense; + + tmp = (s64)offset * (s64)alpha * (s64)sense; + rescale->offset = div_s64(tmp, (s32)1000000); + + return 0; +} + enum rescale_variant { CURRENT_SENSE_AMPLIFIER, CURRENT_SENSE_SHUNT, VOLTAGE_DIVIDER, TEMP_SENSE_RTD, + TEMP_TRANSDUCER, }; static const struct rescale_cfg rescale_cfg[] = { @@ -421,6 +448,10 @@ static const struct rescale_cfg rescale_cfg[] = { .type = IIO_TEMP, .props = rescale_temp_sense_rtd_props, }, + [TEMP_TRANSDUCER] = { + .type = IIO_TEMP, + .props = rescale_temp_transducer_props, + }, }; static const struct of_device_id rescale_match[] = { @@ -432,6 +463,8 @@ static const struct of_device_id rescale_match[] = { .data = &rescale_cfg[VOLTAGE_DIVIDER], }, { .compatible = "temperature-sense-rtd", .data = &rescale_cfg[TEMP_SENSE_RTD], }, + { .compatible = "temperature-transducer", + .data = &rescale_cfg[TEMP_TRANSDUCER], }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, rescale_match); From patchwork Thu Jul 15 03:12:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Beguin X-Patchwork-Id: 477623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE00BC47E48 for ; Thu, 15 Jul 2021 03:12:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AACC2613D8 for ; Thu, 15 Jul 2021 03:12:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233643AbhGODPm (ORCPT ); Wed, 14 Jul 2021 23:15:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233529AbhGODPk (ORCPT ); Wed, 14 Jul 2021 23:15:40 -0400 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86524C06175F; Wed, 14 Jul 2021 20:12:46 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id k3so3527361qtq.7; Wed, 14 Jul 2021 20:12:46 -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=F9vLD4GPyVlyvHJVO/zwQSRJTRKTzhxUyD5QpwjJ88Q=; b=BcHcrgBA9jlXJxHDrhGi3xf1uNZUgp218E0NjIAHAA8H2fYiuwQpoyOcUwqGG0wYfx yhbwXAF6coyVu4Zhn948cg0Xjqn44eiAgVx41xoSxYlvUFcD1bqcbdNgSlJvK1pbRXWz vtls9BdFE5NkIF6Eg5BjYzR0g5Jc+HGzZp+9ZBTEzCbwvJsegiLZco3YdIhMvhxFzNpb xmB/rcJYr+rbsVnUlcCqSxi1bTV47DkccPkq0HoHHYVL/tucuxy2+QM39tnn1blv/LZO NI+OYdV2LwTJyNmplC5GaBmuR1MHpMZcCjORw90i5o/BzMu5FHv5MpXoWcGGH6CpGJCo P3ZQ== 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=F9vLD4GPyVlyvHJVO/zwQSRJTRKTzhxUyD5QpwjJ88Q=; b=FH1ssBLB65+KouMr0HzT6Jx1F7m2WqaNu5jl0PDFcFKzG7BcMrSHkWP+Dctjz7tb0r C3hlOVkLWAoeONtW59pw8M673rqbYPsy4J0SprKy4mszRvlbT1ckSGVXBUD2jSXerhQB uNDF2AW9TwglkP/cf67QOlfphlVIzMhfHONwV3A4iXISNS3tA52lB7xDdbwtfKiGYbkb q2/KSGZ/tuBodKgEL3jEeGe7kUu9UQCgnJlJUd2vlu77uTJvvc3ToTJORj24BzJV4vGh jmjosr7aiAXBkNGjbx38Keb4qZHK1EuKIoHb3r3rNpjT+0AWC82rb3zHNkSt1S7tmLDF 5NwQ== X-Gm-Message-State: AOAM5334Wn7l/ABA4dqhr6/G0Yzbktz6C32x38jW+QoOwK0bA0uDb+gQ FAmL9ZX+sA2Qw9WAUPPzopo= X-Google-Smtp-Source: ABdhPJxR2eb1fELMTVHNRvaUMDi0VjVTMTXZRpslXndzVJN5q+Yl8JPniWg1s92/dUuxCzkFeZxZfQ== X-Received: by 2002:ac8:5704:: with SMTP id 4mr1688880qtw.306.1626318765765; Wed, 14 Jul 2021 20:12:45 -0700 (PDT) Received: from shaak.. (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id t125sm1932847qkf.41.2021.07.14.20.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 20:12:45 -0700 (PDT) From: Liam Beguin To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org Subject: [PATCH v5 09/10] dt-bindings: iio: afe: add bindings for temperature-sense-rtd Date: Wed, 14 Jul 2021 23:12:14 -0400 Message-Id: <20210715031215.1534938-10-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210715031215.1534938-1-liambeguin@gmail.com> References: <20210715031215.1534938-1-liambeguin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Liam Beguin An ADC is often used to measure other quantities indirectly. This binding describe one case, the measurement of a temperature through the voltage across an RTD resistor such as a PT1000. Signed-off-by: Liam Beguin Reviewed-by: Rob Herring --- .../iio/afe/temperature-sense-rtd.yaml | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/afe/temperature-sense-rtd.yaml diff --git a/Documentation/devicetree/bindings/iio/afe/temperature-sense-rtd.yaml b/Documentation/devicetree/bindings/iio/afe/temperature-sense-rtd.yaml new file mode 100644 index 000000000000..11a3d4bd3065 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/afe/temperature-sense-rtd.yaml @@ -0,0 +1,101 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/afe/temperature-sense-rtd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Temperature Sense RTD + +maintainers: + - Liam Beguin + +description: | + RTDs (Resistance Temperature Detectors) are a kind of temperature sensors + used to get a linear voltage to temperature reading within a give range + (usually 0 to 100 degrees Celsius). + + When an io-channel measures the output voltage across an RTD such as a + PT1000, the interesting measurement is almost always the corresponding + temperature, not the voltage output. This binding describes such a circuit. + + The general transfer function here is (using SI units) + + V = R(T) * iexc + R(T) = r0 * (1 + alpha * T) + T = 1 / (alpha * r0 * iexc) * (V - r0 * iexc) + + The following circuit matches what's in the examples section. + + 5V0 + ----- + | + +---+----+ + | R 5k | + +---+----+ + | + V 1mA + | + +---- Vout + | + +---+----+ + | PT1000 | + +---+----+ + | + ----- + GND + +properties: + compatible: + const: temperature-sense-rtd + + io-channels: + maxItems: 1 + description: | + Channel node of a voltage io-channel. + + '#io-channel-cells': + const: 0 + + excitation-current-microamp: + description: The current fed through the RTD sensor. + + alpha-ppm-per-celsius: + description: | + alpha can also be expressed in micro-ohms per ohm Celsius. It's a linear + approximation of the resistance versus temperature relationship + between 0 and 100 degrees Celsius. + + alpha = (R_100 - R_0) / (100 * R_0) + + Where, R_100 is the resistance of the sensor at 100 degrees Celsius, and + R_0 (or r-naught-ohms) is the resistance of the sensor at 0 degrees + Celsius. + + Pure platinum has an alpha of 3925. Industry standards such as IEC60751 + and ASTM E-1137 specify an alpha of 3850. + + r-naught-ohms: + description: | + Resistance of the sensor at 0 degrees Celsius. + Common values are 100 for PT100, 500 for PT500, and 1000 for PT1000 + +additionalProperties: false +required: + - compatible + - io-channels + - excitation-current-microamp + - alpha-ppm-per-celsius + - r-naught-ohms + +examples: + - | + pt1000_1: temperature-sensor0 { + compatible = "temperature-sense-rtd"; + #io-channel-cells = <0>; + io-channels = <&temp_adc1 0>; + + excitation-current-microamp = <1000>; /* i = U/R = 5 / 5000 */ + alpha-ppm-per-celsius = <3908>; + r-naught-ohms = <1000>; + }; +...