From patchwork Wed Apr 12 12:27:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13209120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81CD4C7619A for ; Wed, 12 Apr 2023 12:28:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjDLM1k (ORCPT ); Wed, 12 Apr 2023 08:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231643AbjDLM1g (ORCPT ); Wed, 12 Apr 2023 08:27:36 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5017030EE; Wed, 12 Apr 2023 05:27:26 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id t20so14439552lfd.5; Wed, 12 Apr 2023 05:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681302444; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sgOwPu+FboPmTEq+F0N4Fog/45+TxGJHI0yCy72fcPY=; b=bUGFSLOHSf8IOPs0vBg4h3142MTO/Uar2S7LbKDhUcqBXArUyeIogzmCBzqZpLXbOv 6LEcsgmaK5Iz536y7HqVscXtUbwLtyt6isKczHv7M851ZqYxFF2C1PLxawMExL1/rJtx cXQJ1wkeyR4oiJNPQX/aoYi5FapO4QAG/EyARlWXGnLD5ZUrUe9jOznW2cmp7hVS1u7A g+dZaNUjXBPvbBlef8wczMA5/f7iyn0hByjFS4Yw+aeL2O6vt3I/VBiQHPdJ06vbJv7n UJprE3rDrj7y9Ud3K/iJDpBQ/NGBuzJtbkyPoutOGfEePpFB9DeLjzsmIW0y7dHDflxU e8/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681302444; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sgOwPu+FboPmTEq+F0N4Fog/45+TxGJHI0yCy72fcPY=; b=TS5j7l6NxcNnqz7+K/xK1agVy9J4dTwwwwTjmylQyXSAhk6npRxGPNdhrx8jSaSCCp thfYXXYHqeufASOMljDSVHz7vrAZniuXhNXxyQBZAiV7CTcbuv9dSWHAUJyYiwPmN2Cm NfVl5aRVFEDLJDBrcHvGEnojVemmRB1Uq/7+hyOBq/T2YwY5mJnNxlWNHaCqDDOyqmxn f3+O5NPGsRkk3dXGRBHrm82EjFCFipmknU3I/OwctaQiX7vrk0bXqPappjodRS5x452G e1No0WMoT6T2fQudhCiSBOclc9uZviIPPViBZjV7x9Ymd4K9mKj7bsmuPRsQkSs7+fWc hC2w== X-Gm-Message-State: AAQBX9cGY4msQ/gspEF4jkcUs1KFw6f0jbUhXAOGg5Eue6rexyrJys/w 6WupzRcNq/2H95rZM9LQkuc= X-Google-Smtp-Source: AKy350aBtZqbgVz7RlRlx7n4YpwLva9wu/Kfqr4nf7VKOrm3wlO+oRyizn3t5nCyVXo4+TKAfWEffw== X-Received: by 2002:ac2:44a3:0:b0:4e9:bf52:7898 with SMTP id c3-20020ac244a3000000b004e9bf527898mr566918lfm.37.1681302444438; Wed, 12 Apr 2023 05:27:24 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::1]) by smtp.gmail.com with ESMTPSA id z20-20020ac25df4000000b004d85895d7e0sm2984411lfq.147.2023.04.12.05.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 05:27:23 -0700 (PDT) Date: Wed, 12 Apr 2023 15:27:14 +0300 From: Matti Vaittinen To: Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Matti Vaittinen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] iio: core: add IIO_VAL_INT_MICRO Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org There are a few cases like light sensor integration times, where values returned from *_available() and read_raw() are smaller than 1 and often in the units of micro. (Like micro second scale integration times, always smaller than 1 second). Currently those are often handled using IIO_VAL_INT_PLUS_MICRO, which requires drivers to initialize the integer part to zero. Furthermore, using IIO_VAL_INT_PLUS_MICRO in iio lists requires one to always allocate the 'dummy' integer part too. Introduce IIO_VAL_INT_MICRO which allows omitting the always zero integer. Signed-off-by: Matti Vaittinen --- drivers/iio/industrialio-core.c | 4 ++++ include/linux/iio/types.h | 1 + 2 files changed, 5 insertions(+) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index c117f50d0cf3..c5ae965e9961 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -628,6 +628,8 @@ static ssize_t __iio_format_value(char *buf, size_t offset, unsigned int type, switch (type) { case IIO_VAL_INT: return sysfs_emit_at(buf, offset, "%d", vals[0]); + case IIO_VAL_INT_MICRO: + return sysfs_emit_at(buf, offset, "0.%06u", vals[0]); case IIO_VAL_INT_PLUS_MICRO_DB: scale_db = true; fallthrough; @@ -758,6 +760,7 @@ static ssize_t iio_format_list(char *buf, const int *vals, int type, int length, switch (type) { case IIO_VAL_INT: + case IIO_VAL_INT_MICRO: stride = 1; break; default: @@ -952,6 +955,7 @@ static ssize_t iio_write_channel_info(struct device *dev, case IIO_VAL_INT_PLUS_MICRO_DB: scale_db = true; fallthrough; + case IIO_VAL_INT_MICRO: case IIO_VAL_INT_PLUS_MICRO: fract_mult = 100000; break; diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h index 82faa98c719a..b4e316172c7f 100644 --- a/include/linux/iio/types.h +++ b/include/linux/iio/types.h @@ -30,6 +30,7 @@ enum iio_event_info { #define IIO_VAL_FRACTIONAL 10 #define IIO_VAL_FRACTIONAL_LOG2 11 #define IIO_VAL_CHAR 12 +#define IIO_VAL_INT_MICRO 13 /* val is micro . Integer part is 0 */ enum iio_available_type { IIO_AVAIL_LIST, From patchwork Wed Apr 12 12:28:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13209121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 535ADC77B6E for ; Wed, 12 Apr 2023 12:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbjDLM2o (ORCPT ); Wed, 12 Apr 2023 08:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbjDLM2V (ORCPT ); Wed, 12 Apr 2023 08:28:21 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EFFC7DA4; Wed, 12 Apr 2023 05:28:15 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id z26so14352055lfj.11; Wed, 12 Apr 2023 05:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681302493; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=al7GXfMDGfT+oOFD5mcLnTwf/FCNkfbn6/XvAyYGbNM=; b=F68RVGygYIxaiSFdCw685GZFm1tpH6RU9psgboEvf8dKwKjcoPQ0IO+OMjz9jk7Fkr 7SBHD3BKv5rEXKvagymp+uIoXhjJrWFmBQOf1uvKRs51ThlSNqYu0bc9DzAjRqLadtrg 6mjBFNYV2h+j6bDNV0EWPFqcC9vWBc6U2VjFSPXuY5+cm44TIKb+izuPX9aTHBCWkTs/ JOkQ7KRdlpwwH7yrdyDCzZY22Y33JSjhmwgaVbuRqmt3qNvwQjpks8BzOC047W/Qfq/T YSjTF3ITK+IeSlSnV8eeV7PytpxBNzfpZyuzBFVwN6phCxJmre9Q+FWcQ0r0QKzzsoxJ IOXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681302493; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=al7GXfMDGfT+oOFD5mcLnTwf/FCNkfbn6/XvAyYGbNM=; b=3D7cDRVTDe/pahytxFoQ+m+JrGTpvtadrp9ECQwk/KfUHMPeaOkR7Y4RB7IHTNvMRv j/V4Ftp64LAmQDBJ+Y06DlpP/aSQdF4JUlsrQIeQxni4XwJ2N/73g96Rv9CFyGqg9tX3 W9tYPbE/ezGHer6eh+IeMyMPQfPhByyIyE8zo1Im2XAUUPPx9gR9L+lZWtXTYOqXcum2 N4/G7/7VbzWuf7YXWh8OMq6OKPCTF0PZpimsJc7wbGC9dxB2rwDk7YjPxZC7uw3jlSB5 FIkBoJpS1fxFAMzoHwoNhmhdO0rjZcOh2eSxAyUvb/USXnXiUHQbj6cWeDSUel2qFeNi zgaQ== X-Gm-Message-State: AAQBX9ettLyiEoatLq8nIv3RI+rgT6vKYnq4BgWtB5QDefN6f7Dywan/ 65DaJJL6B3aL+mu6CPJJYiGgZFGGa80= X-Google-Smtp-Source: AKy350bbARqUjS6vcur1SvBsBCp0y5P6v7JHPM1dFVoX0IJcLowld7JWyBlk937m8RZ9B3gz7aNQ6g== X-Received: by 2002:ac2:518f:0:b0:4e9:bdd0:b667 with SMTP id u15-20020ac2518f000000b004e9bdd0b667mr1589508lfi.0.1681302493642; Wed, 12 Apr 2023 05:28:13 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::1]) by smtp.gmail.com with ESMTPSA id t13-20020ac24c0d000000b004e95a1aca1bsm2989037lfq.87.2023.04.12.05.28.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 05:28:12 -0700 (PDT) Date: Wed, 12 Apr 2023 15:28:03 +0300 From: Matti Vaittinen To: Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Matti Vaittinen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] iio: gts: fix units of available integration times Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The available integration times should be in the units of seconds, not micro seconds. Use the new IIO_VAL_INT_MICRO to return times in seconds Signed-off-by: Matti Vaittinen --- drivers/iio/industrialio-gts-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/industrialio-gts-helper.c b/drivers/iio/industrialio-gts-helper.c index 8bb68975b259..e242d0eb8b94 100644 --- a/drivers/iio/industrialio-gts-helper.c +++ b/drivers/iio/industrialio-gts-helper.c @@ -683,7 +683,7 @@ int iio_gts_avail_times(struct iio_gts *gts, const int **vals, int *type, return -EINVAL; *vals = gts->avail_time_tables; - *type = IIO_VAL_INT; + *type = IIO_VAL_INT_MICRO; *length = gts->num_avail_time_tables; return IIO_AVAIL_LIST; From patchwork Wed Apr 12 12:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13209122 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34277C77B6E for ; Wed, 12 Apr 2023 12:30:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231560AbjDLM37 (ORCPT ); Wed, 12 Apr 2023 08:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbjDLM3t (ORCPT ); Wed, 12 Apr 2023 08:29:49 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FC9E72B1; Wed, 12 Apr 2023 05:29:12 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id q26so2275942lfe.9; Wed, 12 Apr 2023 05:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681302551; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=siCdH4i793Fr0Wj+21nPqmHI0RDFnIElDQrnU73xJYE=; b=VQeCgQHI1EcjcFspsDA0zh1lWNC/OCP9F8kU/YlAwXgU5fTRTIXy7bmnnl4+N7zA+p 6IA34k911R6zsbWb73+5Z4Q/6GHydO4fCAqHpV0/Vpq3c7U5RY1EGSlvGUR7Td3fpzwi TSD63KOFu/GsWRmacMpazKGJzQxEX64GgltaFsMgj3n+2RrUATCwS252Xo1Cz3H0i7S6 X888/cR9bclHvDmJjkuF7XVHguwYS+fBrPjh0zUvagF0HYfVVHO58kbujExExX8VuoJS CLTAZq0aEhmDsLfXXuzLoph0kIexzAwKXQ+Vce3NidURTMIYEBGNE65nAtIIOHuEFPWX 4phg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681302551; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=siCdH4i793Fr0Wj+21nPqmHI0RDFnIElDQrnU73xJYE=; b=q2BUy0mMUhev7NcibrK6zz0D7cQtZuwjYE0nedHdDrh6oIA2U9nfi1QCNSAfLQ0CiI P490+4BDmL+Ukf/hD8awsZSgtK0YCoKpRIvUj99fLz1bMbWY0L2Rj1eiMYfKP2vwdIm9 GfVZT5s2xfG87vb9OVQy8CWthbVXf00G1G5cBHFOIq0LGQZGZkrY2HYgSSWR3Dlqumpy 5itpweHUXno53HXitFyFJ6J9BD4xpAoKnLLq55yn4t0cJWe5WKo669Xxc4uZnkGuT1py dzYGL1VdQOINiIANz3oy7zZiUp7QBLterlUhTzLVgB+pQzXqPPONmZ6cYKanlaqWMH1B j7QQ== X-Gm-Message-State: AAQBX9c8OTWAspTe3e9++XDqmYQe857n1KjV1VAz5sYqe4aRskDuLvv3 jayQ/BTqk6U9ZYulWU8gdJ0= X-Google-Smtp-Source: AKy350YoQXSzO91Dyj+lPCb5tSWpcCDLY/OAJLAUkM8P1zlP2mEfymzfXSK3UmKtyEid6KjzXadmhw== X-Received: by 2002:a05:6512:203:b0:4e9:d158:d56b with SMTP id a3-20020a056512020300b004e9d158d56bmr512162lfo.62.1681302550783; Wed, 12 Apr 2023 05:29:10 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::1]) by smtp.gmail.com with ESMTPSA id n12-20020a19550c000000b004e7d6eb9cbfsm2973522lfe.190.2023.04.12.05.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 05:29:10 -0700 (PDT) Date: Wed, 12 Apr 2023 15:29:01 +0300 From: Matti Vaittinen To: Matti Vaittinen Cc: Jonathan Cameron , Lars-Peter Clausen , Matti Vaittinen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] iio: bu27034: Fix integration time units Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The integration time was presented by BU27034 in micro seconds. The ABI documentation says this should be in seconds. Fix integration time to be in seconds. Signed-off-by: Matti Vaittinen --- drivers/iio/light/rohm-bu27034.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/iio/light/rohm-bu27034.c b/drivers/iio/light/rohm-bu27034.c index e486dcf35eba..6044db52abfa 100644 --- a/drivers/iio/light/rohm-bu27034.c +++ b/drivers/iio/light/rohm-bu27034.c @@ -1171,7 +1171,7 @@ static int bu27034_read_raw(struct iio_dev *idev, if (*val < 0) return *val; - return IIO_VAL_INT; + return IIO_VAL_INT_MICRO; case IIO_CHAN_INFO_SCALE: return bu27034_get_scale(data, chan->channel, val, val2); @@ -1229,7 +1229,10 @@ static int bu27034_write_raw(struct iio_dev *idev, ret = bu27034_set_scale(data, chan->channel, val, val2); break; case IIO_CHAN_INFO_INT_TIME: - ret = bu27034_try_set_int_time(data, val); + if (val) + return -EINVAL; + + ret = bu27034_try_set_int_time(data, val2); break; default: ret = -EINVAL;