Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5116948pxv; Tue, 20 Jul 2021 20:14:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjBJh2+LwVIw70yru3YCmaO96OmW1j//QqVXL6iQ7HYA4Ajw7lzX+NO1XKtRm5SFYBUYIw X-Received: by 2002:a05:6402:615:: with SMTP id n21mr46269729edv.139.1626837291517; Tue, 20 Jul 2021 20:14:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626837291; cv=none; d=google.com; s=arc-20160816; b=KuSOczMmosIHk/FdeXaDOi4GgGWxcrGn/I0wd24mg6PTwqFuaCJJ5j6bOHfhSvaaga Ur3pwx7NjgBOk785yOX4RNXssKufid52757KwfWZnTPKeSg3mdsM5FOtrZb66C08BGWu 80MPcyAEyYKV5fv1pWNgdbkrVGNxM4teKYzupEvOvRLd35BXwoZ5Xm/hQx9BuVZKmI++ XbwWlu3PoWJa4J8zza4qOrbyRI2R9Ql1P7wvafxHIzy6ElPF81qpDuDz7jhsFvsWGNJx GF0wwzEsMGg2cxNOp71BVe1An12GR/i2bokIY/u2OjyGYdDzgDTsCgLZnShefP2/7SKm xC8A== 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=OKwbA7CkZ/dV0H/nAmt5zTOn4ixRO23QkLcRozVJn9c=; b=bsqXZdPegsFsXoSZES578Tv0ZC+SdROuH4xEgnffMlnUBvuGSSk+0M9j8Ku/iW+8X5 XO6U94LQATanknad3KK+S6DoV8dLvm7lqTvD63+Ugm/WDv1dDi43U/slSX9/0q89e7HP MEmusu0fWWMfD4jbCKa3mvH4Ar0aFtIi+t4Ef8zlgkYTrp5EGHXueuNs85UjeSU18Xi+ JXSzzgFa5tQUu3XTTO1/2bP/Y4SeoPlgP4a6JZQPxC34hu9shBPez7QiSNxhJEiCPl1G wqpKj9UaaCbCuC2STTxlKfh7g88y2emLkxi1NtsxMop834mOcR+35p1kcINIQ7N7ONsW ccNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tpT0Bo0s; 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 v16si4377611edc.281.2021.07.20.20.14.28; Tue, 20 Jul 2021 20:14:51 -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=tpT0Bo0s; 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 S231426AbhGUC2u (ORCPT + 99 others); Tue, 20 Jul 2021 22:28:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231359AbhGUC0Z (ORCPT ); Tue, 20 Jul 2021 22:26:25 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 743DEC061574; Tue, 20 Jul 2021 20:07:02 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id q15so1065099qtp.0; Tue, 20 Jul 2021 20:07:02 -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=OKwbA7CkZ/dV0H/nAmt5zTOn4ixRO23QkLcRozVJn9c=; b=tpT0Bo0saWDiswje5emv5emtlmtpDKJqhEw32Dm+/AqpGcCMns0YWXgNkSEDaFyJ6s gCyTU23DQt4+eAz8NiDnjC4qQ5wecJYrpnyj7oc1jUsGlNPYA+AtRw4Nmb4ZSq2l3EnR nXCDjzNAajq1GziHbTokT4iHxAmF0hzDFJT2CkpXnojc0anOxsQqTaofChO+mfEGZQPs d0fZBuACGXNQhEsE2tCh5hHgfAAXliCY3iqAvxzvuR4tSLjFTWKUp7jAao1KIkUNY8Jy /wckLOYCx3bu+GSUPKdZpWfyIDTWlPkZHeFh+/yevuANDyndr3e8Ml5Ctab+AnLSprn/ FJtA== 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=OKwbA7CkZ/dV0H/nAmt5zTOn4ixRO23QkLcRozVJn9c=; b=OTmKuD7IM7aKX4JxA0C2GJUiQ4q0EgJmYObKA/iMrb581FOHsdzLGNF9d87Y65lZ7j p3dEDY1EcAYGQL4CcxcyOUXiw8hN1On+6Mlz9ZafYdxIZHXHDj8OZbNpjPYfV4ppS0S+ 6LHipblJQJCHiD8Z1GdSoRFyFr+EkQS4LBIjKOSvVHEkEgQrQ1zDhgNnJ2KFbZaaZRdg Jlvv2GAK3N8lDika5NzcPDtaxzL0HI3n24a/MdrEqXnLNl1xEyMnFvBHS8TpSu+zb1h+ AT7230CUCuSBja2LD0g4D8hYKENVpPF8gDy4mtyWIVXpQL6O8TIksE9q9QD4Xlj38vs3 Uuxw== X-Gm-Message-State: AOAM530hHEM0yIS3Zhk4d6CIilLohIMro82gWxhRmpcSbRN+5a1lTgUa 7+NRWPhNtkYNvHU8RhurOSE= X-Received: by 2002:a05:622a:d5:: with SMTP id p21mr3817934qtw.75.1626836821656; Tue, 20 Jul 2021 20:07:01 -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 g76sm10561024qke.127.2021.07.20.20.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 20:07:01 -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 v6 02/13] iio: inkern: apply consumer scale when no channel scale is available Date: Tue, 20 Jul 2021 23:06:02 -0400 Message-Id: <20210721030613.3105327-3-liambeguin@gmail.com> X-Mailer: git-send-email 2.30.1.489.g328c10930387 In-Reply-To: <20210721030613.3105327-1-liambeguin@gmail.com> References: <20210721030613.3105327-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 no channel scale is available, it's assumed that the scale is one and the raw 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: adc8ec5ff183 ("iio: inkern: pass through raw values if no scaling") Signed-off-by: Liam Beguin --- drivers/iio/inkern.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c index b752fe5818e7..b69027690ed5 100644 --- a/drivers/iio/inkern.c +++ b/drivers/iio/inkern.c @@ -590,10 +590,10 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, IIO_CHAN_INFO_SCALE); if (scale_type < 0) { /* - * Just pass raw values as processed if no scaling is - * available. + * If no channel scaling is available apply consumer scale to + * raw value and return. */ - *processed = raw; + *processed = raw * scale; return 0; } -- 2.30.1.489.g328c10930387