Received: by 2002:ab2:5d18:0:b0:1ef:7a0f:c32d with SMTP id j24csp299482lqk; Sat, 9 Mar 2024 10:29:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWswbwFj8ZWMENPt1BSB/+Fz9MRA6OMAHELP0rf5IwznQBHlnKSXlsvAZ0iJSX7nB9qW4VXxea1zWYrQMImR4cGvnJWi5hgsievXPfRbA== X-Google-Smtp-Source: AGHT+IFCPtleqfF8tzFOZpDWDln/hfl9crzRzGv8raA3+Cgfir0ZgYxlYFBxn4jd+3zvH5rlgcD0 X-Received: by 2002:a05:6a20:d39a:b0:1a1:87c7:2d03 with SMTP id iq26-20020a056a20d39a00b001a187c72d03mr1255355pzb.33.1710008943729; Sat, 09 Mar 2024 10:29:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1710008943; cv=pass; d=google.com; s=arc-20160816; b=RqZTIEtn8+v4K+elUVHIZ9fY015sCerK1CLzM9x8b8MCnle0gmiv5Jn+H4+81S7LZ2 d9qE8+vcTr+mx0dZzZpFUxH2VLPHR9zZGLfRhQHUVyNs3oXdcdzDYnbBWJS6MgGkNmlS DKgoccoLe/abhnhrj019uE0SOe/pUd+LKil80ky7AjYg9rQQzXEm7VRE/eEzosjOlcf4 EFxCoU4wJK1DgVyOR4FDsvdOFW/50L9+oc3g1c9eGZzPbo7OleepBohE46hTLDlrbNJk hIxw1x8D7yPbEULSsFQuSmkNCVFjg5VFCkSjD6fx5WG16VfaBk6DQ8uFVklP1kcIcyZD dyXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=o7OaRO0TakI3FvYwTldYBqqWJqaGPBPBUky/yktm7sE=; fh=Gxre2JxzGoUEgxMa3YHfK6aGZnjXPx/WDnJ+wNqcp9A=; b=YKbB/ukD9amP3lCwsETuPKdc3AKahD4m7Qmt0WadSaRc6U6saFkRkHh2pOJkiXGii0 ga1sbZCC/nsbhLKfKo8bA0RGzdihRyVhVjYvwyXmk3ZZ8TEs4V/aIK6sTRQEEoBpcNDv F/SKVsk2CBZXYoad8QvREtPGXGoINTtFJPCcTVoJxXxhLgiGoz0R+EUieHnbDrjMeKkT Je0EKvvjh0gkWzpnRPQ9oj21HqBVySoRhsmcli80d5rMcFy5Ov7tbo6vGgI9A+6e0RgV hcW4wvKBl+zUvyWGkEQwT2/5xIXow9NmGNHRjYkDnu169H2xGK7t5EP1YD2Tw7Wkr7gz FaVg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n3fYRFtY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-98007-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98007-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id pc18-20020a17090b3b9200b0029ac01b0281si6229915pjb.180.2024.03.09.10.29.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 10:29:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98007-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n3fYRFtY; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-98007-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98007-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 66B5C281E2F for ; Sat, 9 Mar 2024 18:29:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA7103770D; Sat, 9 Mar 2024 18:28:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n3fYRFtY" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F403E22F1E; Sat, 9 Mar 2024 18:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710008935; cv=none; b=FwmaMfWi+oifl0gieK+uyRpoQx2r15Ls7Qfy++6FX4zV8yIWLiayBfDn/59CCsIFuLV1N14Mmj8TARdfjrRF918avoPh9BybnJGgOLA9gaD3D8aMng5I6maQi4CBjYXkErboTbEfROXG0yGCyVZo3sYy1oIw79E22s6XEeypvp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710008935; c=relaxed/simple; bh=L2wcmhVQaFqLWuk8FiLWZYZW1meGlQie24CMyuszByI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=phDDZpgVRSET+Qdjmqx3q1BzqJS1x8PfjJq6iZdWhdHNjNfWUh1ukRyo89JdLT1hSzvIBcB0h0dCa3ELI6kOYW+RaSGSaNRA9qRUMqJC8eHb69P/0lZl+hLtElfKF+/9HEsu5KMV3x7rp5VJ5b49UjODk+zGbE4qMqfEeSuH0mM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n3fYRFtY; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4050DC433C7; Sat, 9 Mar 2024 18:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710008934; bh=L2wcmhVQaFqLWuk8FiLWZYZW1meGlQie24CMyuszByI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=n3fYRFtY6B2ykMQMKc9V0O7oABQikIpa+P9sEEvHOGogTe3xbIXXpT/uKMWrQmZgQ 1/CpoQ51vCvShNX8nNhR1xdJmogVPWALnL+eJK75/jPXNlitKE+mPzR9RpHk+9CQPF AbnT7bYe3G8tJquv3MCZ/+wSoLzJkXJ1SUOXKKOW/EndG8vFEpNamIK7pkj6nEkwIp QZPBid9T0Pg2TFXhUW6aQR/iePxZqWAKR+WSXcPAN677PI/tmo/3BVpPXDlRo2OwmU dPiP59qQFUr5rAkOKbQV65fkZLBApwMO0IOV+/3xSjJYTmXzwl6ge122pP4Xsuy/8F GhJQR+jbFx1gQ== Date: Sat, 9 Mar 2024 18:28:42 +0000 From: Jonathan Cameron To: Vasileios Amoiridis Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, phil@raspberrypi.com, 579lpy@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] iio: pressure: Add scale value for channels Message-ID: <20240309182842.1fc7b676@jic23-huawei> In-Reply-To: <20240303165300.468011-3-vassilisamir@gmail.com> References: <20240303165300.468011-1-vassilisamir@gmail.com> <20240303165300.468011-3-vassilisamir@gmail.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 3 Mar 2024 17:52:58 +0100 Vasileios Amoiridis wrote: > Add extra IIO_CHAN_INFO_SCALE in order to be able to have the scales > for the values in userspace. Can be used for triggered buffers. > > Signed-off-by: Vasileios Amoiridis So providing scale and processed is a mess. With hindsight this should have always provided raw + scale, but too late :( This retrofitting buffered code onto a drive that does processed channels is one of the few reasons I'll let through channels that do both processed and raw. So add raw as well. Hopefully raw * scale always equals processed. The reason is that for a channel doing processed only - assumption is normally that the buffer is processed as well. We can't remove processed as that would be ABI breakage, but we can add raw. Jonathan > --- > drivers/iio/pressure/bmp280-core.c | 70 ++++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) > > diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c > index 29a8b7195076..acdf6138d317 100644 > --- a/drivers/iio/pressure/bmp280-core.c > +++ b/drivers/iio/pressure/bmp280-core.c > @@ -138,16 +138,19 @@ static const struct iio_chan_spec bmp280_channels[] = { > { > .type = IIO_PRESSURE, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > }, > { > .type = IIO_TEMP, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > }, > { > .type = IIO_HUMIDITYRELATIVE, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > }, > }; > @@ -156,6 +159,7 @@ static const struct iio_chan_spec bmp380_channels[] = { > { > .type = IIO_PRESSURE, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | > BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), > @@ -163,6 +167,7 @@ static const struct iio_chan_spec bmp380_channels[] = { > { > .type = IIO_TEMP, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | > BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), > @@ -170,6 +175,7 @@ static const struct iio_chan_spec bmp380_channels[] = { > { > .type = IIO_HUMIDITYRELATIVE, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | > BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), > @@ -487,6 +493,70 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, > break; > } > break; > + case IIO_CHAN_INFO_SCALE: > + switch (chan->type) { > + case IIO_HUMIDITYRELATIVE: > + if (!strcmp(indio_dev->name, "bme280")) { > + *val = 1000; > + *val2 = 1024; > + ret = IIO_VAL_FRACTIONAL; > + } else { > + ret = -EINVAL; > + } > + break; > + case IIO_PRESSURE: > + if ((!strcmp(indio_dev->name, "bmp085")) || > + (!strcmp(indio_dev->name, "bmp180")) || > + (!strcmp(indio_dev->name, "bmp181"))) { > + *val = 1; > + *val2 = 1000; > + ret = IIO_VAL_FRACTIONAL; > + } else if ((!strcmp(indio_dev->name, "bmp280")) || > + (!strcmp(indio_dev->name, "bme280"))) { > + *val = 1; > + *val2 = 256000; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp380")) { > + *val = 1; > + *val2 = 100000; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp580")) { > + *val = 1; > + *val2 = 64000; > + ret = IIO_VAL_FRACTIONAL; > + } else { > + ret = -EINVAL; > + } > + break; > + case IIO_TEMP: > + if ((!strcmp(indio_dev->name, "bmp085")) || > + (!strcmp(indio_dev->name, "bmp180")) || > + (!strcmp(indio_dev->name, "bmp181"))) { > + *val = 100; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if ((!strcmp(indio_dev->name, "bmp280")) || > + (!strcmp(indio_dev->name, "bme280"))) { > + *val = 10; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp380")) { > + *val = 10; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp580")) { > + *val = 1000; > + *val2 = 16; > + ret = IIO_VAL_FRACTIONAL_LOG2; > + } else { > + ret = -EINVAL; > + } > + break; > + default: > + ret = -EINVAL; > + break; > + } > + break; > case IIO_CHAN_INFO_OVERSAMPLING_RATIO: > switch (chan->type) { > case IIO_HUMIDITYRELATIVE: