Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp112169pxv; Wed, 14 Jul 2021 20:15:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfKZmoKZNea3wPf7f7AVcRB3TW737IEf46FPDZdRXrUcXtdZV10Mp/R4mBmd3ZAywHJlXk X-Received: by 2002:a50:fd1a:: with SMTP id i26mr2885825eds.372.1626318946309; Wed, 14 Jul 2021 20:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626318946; cv=none; d=google.com; s=arc-20160816; b=mp8BmIZR7MSHnZngzEIFnrDgqqMjWUnpiRBMimUwilYhqFb7sEMn7z1x2d/6zvFRl5 NyTi68Y1JLBnyS8gxrkC22PdFPd6VzImstU6Yq9qPbcHybevlPOsaXDpcWwSlInIlwgQ qyZBMvoR/8z9uZku4v1K/tvTcy6lLIEOxyfEweM4X4jbRYH+JLmfzVuYLj1uuUfmyDqP KTokMkyPg7knr5HuTZP48JeJ5WP0gkeNBmUaZu2sMbYXab4klglsMSRZny5v9LiaTVdn GYeDbK5kc1YNqTYl7K5sewHMPb1DT1O4O7VL/68bEYi9NpmfcOQPaf+NsbByyvKRqK7K i9aw== 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=aLIjEv3Y3XGxT5C/sRBa0wIugXh2Hwubx4IA7LHkqcs=; b=NF4uJpWfJ0xWC5DVMl7y1fjVe0FyNPgFm/zP51p4xBpRPvQzEMXk6Uxa8AXFbWgSy+ Ced3RA3keazlJbpzfbRDm+WqCOU9+dtwECZiw6rs/P5L6bblntkUdWL2f2tiyqG+95pQ Fb/y7I+EEaGooE2HFQf3Eo7vGOrez1kSPhIiExcg0x2Nc/eMYinZWZuX6KVZF3sWb41t xlbSTsjTh8zoRtOLEUFK/8nvmxe/jGoTd+bG4rITHY8HHDW+LSly985gx/c0P7xWw5IM vmMWbGlrTTVlbJnOGc5S+idXicQvUcRTtrR+TqJm7qk2hI0h852pXVV/RsYg3tFjgugD Ovag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SXLG1AME; 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 l26si5537690edq.393.2021.07.14.20.15.23; Wed, 14 Jul 2021 20:15:46 -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=SXLG1AME; 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 S233114AbhGODPd (ORCPT + 99 others); Wed, 14 Jul 2021 23:15:33 -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-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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) -- 2.30.1.489.g328c10930387