Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1476952rwl; Wed, 12 Apr 2023 13:33:09 -0700 (PDT) X-Google-Smtp-Source: AKy350ZcZ3qG1nt+y8pBYeva2/krTrEhaLL58LgbqyZ5BT0BCjnTkDTVxK/6lIdNTbujFWfRAS2h X-Received: by 2002:a17:906:d923:b0:94a:93cf:6b11 with SMTP id rn3-20020a170906d92300b0094a93cf6b11mr3459845ejb.27.1681331589293; Wed, 12 Apr 2023 13:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681331589; cv=none; d=google.com; s=arc-20160816; b=lEsnKhjryZLdHvNuqAWBNNgT+t2anF+BZc039UyUdS5zov4vQRbZed2KmRGfsigUVx E6/a7PF8qqmKG7kY8fjAN++oBk/akSN02E0WJCRduboLRdzWRrK5p0zEUHtiJipkwzX2 qqVp0YwjVzRHkQ3ao7T2q2RzPMckrwxCowpf6kHoOfjTyk5RGDku0RKyZpMVJ4rokNPj qMxApZORpWxABNayq554RDwotDtcXz2UduzhQ3mLuHJo8AKR0lhzds+8gHzigPw3VyfG 07l/+ih7T1+nZ2hZkeYl443QtDZT7t+sCzfmLvpU6Gv/X7bDFPVd3nE58iT5BRio58yB oPoA== 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:subject:cc:to:from:date :dkim-signature; bh=CF6JiDTbgwFBtxP/rAVHVqTcJwOkQo+ImWX+OxvnsGQ=; b=LmsHmoMgshGQbXnt2teC+vYc96lkLn1Ys4MvArrH58HtVYBgKp2O8WWW/jgoIbi3c3 C+Vv2yByMrJreuiilKoBqctoTrCmyjGPbohs4jVoC5uS7r0EO21VoTfF0i1xfvHuEbDL SjTxmwaHWUqnIqEKcECLy50APpzYTDSUPyBWTvEXP/2Yj5QKAmbDdz+CqyB6TnT0AokE 59bOFDc/7+ionwk47S+/3pGeUmCkXf73cuGAqTphLT1hE1aEP+ZFhAL+M2y0vFOabXir 1V91zgoAhFC+v3P+z5apBe3kAHS9bpKMWYJAK0y/HHMhK0J6Qzs8CBfIojSUygqsU3/c O/3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MUKiIP+6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p8-20020a170906a00800b0092f3407f862si10348898ejy.428.2023.04.12.13.32.44; Wed, 12 Apr 2023 13:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MUKiIP+6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbjDLUcQ (ORCPT + 99 others); Wed, 12 Apr 2023 16:32:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbjDLUcO (ORCPT ); Wed, 12 Apr 2023 16:32:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2505A114; Wed, 12 Apr 2023 13:32:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B449161276; Wed, 12 Apr 2023 20:32:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28CF8C433D2; Wed, 12 Apr 2023 20:32:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681331531; bh=ctATQ9F/PpnQBemPYBeJi6C1TXpCodJZt2hgX/it3mc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MUKiIP+6s1IURZPrk33z4pClWJXPrMWh47zmSrhxOF1Yx/oBbGNqCx4S+nhTWbOQy xaqSygHxkXx6NAgjFRGkhWwHgc9Noc+yy0gBnhTvJ5VEBsnaxbVqsgRuoME1KzBofQ EEPrpKNWt7qIqsGJknf1K6Ka3z4NOpvK8sMUzdNIY/fJiWqqvaZ/ZxyPbKlH+WKtu6 7ATQOI3BBRBIgBKeRFu0i2HBs12Rf2BLBzWL6UtcZJsSSYomjPHeqHFcVLZBdTLVpM D5mKZsIKf2OynvoTlg4wO5SQ6ZP5gY4FK246NO3ekbFAb3rekMB+67z90Pbgfj7NAf D9P8GINHhCeXg== Date: Wed, 12 Apr 2023 21:32:08 +0100 From: Jonathan Cameron To: Matti Vaittinen Cc: Matti Vaittinen , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] iio: core: add IIO_VAL_INT_MICRO Message-ID: <20230412213208.49912897@jic23-huawei> In-Reply-To: References: X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 12 Apr 2023 15:27:14 +0300 Matti Vaittinen wrote: > 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 Hi Matti, I'm not keen on adding yet another case just to avoid having to have the integer part for IIO_VAL_INT_PLUS_MICRO. Seems like the wrong trade off of maintainability vs ease of use. Jonathan > --- > 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,