Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3392792rdg; Tue, 17 Oct 2023 13:17:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKseVb//3PQW+edOcq4/4Feko8tv4Tq3soUAiDe3ti+w5Sd/+gPo58wuM+e+kghqj9j4s5 X-Received: by 2002:a05:6808:6141:b0:3a7:26fd:b229 with SMTP id dl1-20020a056808614100b003a726fdb229mr3245864oib.48.1697573866332; Tue, 17 Oct 2023 13:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697573866; cv=none; d=google.com; s=arc-20160816; b=HsvkG2pqMVzv2umnux2A/J5ZqvD02W0SHjTzeS3tunAKGJyQjO3uXXk8oe3WXw7zNi D3HKQLgnH6EdMBsYhYAsLNp5lx+YiQaQ2qLoFLSNp4/udz4b82UDFbjUmLflzhR0E87/ E56UdZXWxg41ig3o9nmId0r4RPtvdeOdl4xaodK7MZvXAMFHfnjPKuqVINzn+W6YiB9M YH0UW1TMYcjT1Ibv8cYG2zkYdRUFG2ihpNxlgxa/NjKw2SY4xObVkEJsc6DqH6xlOHlN eCCGqCwc2++pTgOnuIAOobb4HmJt+DnOdxkGdhl+8f3K/amhccykv4fg/EvpMfpPeh+5 w0Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=DAg++LrW3itK5V1WlKpiZ2b/nQX2LkLJrp9r6Hg+m/U=; fh=uBsBY8e9q12IP0W/nvEYgpf7tRcAZEFTuJZ/7rYZ+Mo=; b=wxXN1xR9tws6up9Ng8tfnSi9+Sz1aFLsu+SDQXfcmxErAVmz5OVv894xjf0ipLZI26 hQuMXpiDL02sSSCazYEN9D5xptMlQOX68usJK3P/epaX9p1iycfuu0zXRy2ZdpLKlPz0 5LKpsxiElzAZU3ivFx1lhixZDtdhu+S/JryJU3BjPScotEevyvMh6p5CCHExS1PerlmZ YxLROzhJNs9Wk1Wrum/HMdqmJZ8cqAlxpuaLxv5iRdBgsYAuipdcX2ExrBZvNwiddgZs nXb5mE8rDMzqx+mlA9qIb3GRgHC4Ni+VFO2TfW2FpgpgoOjzMoq0Y5z/+jT+AMi4k9/M aZIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fyla5S4O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id ck22-20020a056a02091600b00577a519621bsi595516pgb.231.2023.10.17.13.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:17:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fyla5S4O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 41B47801B89E; Tue, 17 Oct 2023 13:17:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235205AbjJQURg (ORCPT + 99 others); Tue, 17 Oct 2023 16:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235197AbjJQURZ (ORCPT ); Tue, 17 Oct 2023 16:17:25 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AB5E6EAB; Tue, 17 Oct 2023 13:07:26 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-507b18cf2e1so3139907e87.3; Tue, 17 Oct 2023 13:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697573245; x=1698178045; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DAg++LrW3itK5V1WlKpiZ2b/nQX2LkLJrp9r6Hg+m/U=; b=fyla5S4OvCipJM/zDK1s9UNIRpBC7Mjb63FEuf2qgq0w3eZv54ii8U42n1acRtFlSw yq7k00GwzCMKz4jmt+KiJkYiSeUE/4cmbNDHSYktDKIdlWGDYIgNhcs0DFWG1Jl56MPo uo6VDd30BbtIAiX3au4GT4clz9qYZ4VUaSb7GVary8cdy8mjgcBsXph+n7+UvIUE7AoH 7mi5/PZBMvos2gTshF8dLYuXvkjs29nNkgprcGMwjmduhikymaPHRKGLQSYw/ppFrHSb /HoLYon3T3DmFb9hMflTuH3GBB7EBwfTrBPnNSWY58le9XUVTjeEAky+5tYHtIxK8GAw wmpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697573245; x=1698178045; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DAg++LrW3itK5V1WlKpiZ2b/nQX2LkLJrp9r6Hg+m/U=; b=HtHe4gpvG1/Y25iUr/McroqkQAACDbn8l4UYVUY+3hpxnmYhm+zFKLGcxrWWSIf9tj 5e0xZcVmweCm1OB3ljG7Mz2/tKBA3elFabB1LcfC5ALm3RNKWq9dg28ZkZWiiepYB1pq 2HIwyQybQgh8EBu0ntTy1jkfMkc8lMiz+iiaWi27T9mML+bZ62hdh1cNfSGlkYrLCOOY mkgXJ2/LVHcu9Hx9yqTzOn4nluo2YmE2CcJVYi47k1o2S1NtrrgN18lZ2o89zOBzRU6r pGhmd1VbMuY6cK31IHvaKcXW0Yy4RPtbgcm9GixbVWGycwt0/duMt9Pm8rzOgq/LuEhE rZ6w== X-Gm-Message-State: AOJu0Yx4Pt1zgTrZSevJIRBWWt7tA9ZRqc9ycdsQ2Vh4naix6XvSDelp EYxx/1w0ICTi/SKl2XyuqWDik/mHPSq4Kdg9csY= X-Received: by 2002:ac2:4827:0:b0:507:9f4c:efc8 with SMTP id 7-20020ac24827000000b005079f4cefc8mr2339662lft.14.1697573244534; Tue, 17 Oct 2023 13:07:24 -0700 (PDT) MIME-Version: 1.0 References: <758b00d6aea0a6431a5a3a78d557d449c113b21e.1666614295.git.mazziesaccount@gmail.com> In-Reply-To: <758b00d6aea0a6431a5a3a78d557d449c113b21e.1666614295.git.mazziesaccount@gmail.com> From: Jagath Jog J Date: Wed, 18 Oct 2023 01:37:12 +0530 Message-ID: Subject: Re: [PATCH v5 2/3] iio: accel: Support Kionix/ROHM KX022A accelerometer To: Matti Vaittinen Cc: Matti Vaittinen , Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Dmitry Rokosov , Cosmin Tanislav , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:17:44 -0700 (PDT) Hi Matti, On Mon, Oct 24, 2022 at 6:10=E2=80=AFPM Matti Vaittinen wrote: > > KX022A is a 3-axis accelerometer from ROHM/Kionix. The sensor features > include variable ODRs, I2C and SPI control, FIFO/LIFO with watermark IRQ, > tap/motion detection, wake-up & back-to-sleep events, four acceleration > ranges (2, 4, 8 and 16g), and probably some other cool features. This is a nice driver, and I found it very helpful as a reference. One question regarding scale please see below. > + * range is typically +-2G/4G/8G/16G, distributed over the amount of bit= s. > + * The scale table can be calculated using > + * (range / 2^bits) * g =3D (range / 2^bits) * 9.80665 m/s^2 > + * =3D> KX022A uses 16 bit (HiRes mode - assume the low 8 bits are z= eroed > + * in low-power mode(?) ) > + * =3D> +/-2G =3D> 4 / 2^16 * 9,80665 * 10^6 (to scale to micro) > + * =3D> +/-2G - 598.550415 > + * +/-4G - 1197.10083 > + * +/-8G - 2394.20166 > + * +/-16G - 4788.40332 > + */ > +static const int kx022a_scale_table[][2] =3D { > + { 598, 550415 }, > + { 1197, 100830 }, > + { 2394, 201660 }, > + { 4788, 403320 }, > +}; Given that the integer part is non-zero, and IIO_VAL_INT_PLUS_MICRO is returned for read_scale, As raw value will never be fractional how does this correspond to a reading of 9.8 m/s=C2=B2 for the Z-axis? > + > +static int kx022a_read_avail(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + const int **vals, int *type, int *length, > + long mask) > +{ > + switch (mask) { > + case IIO_CHAN_INFO_SAMP_FREQ: > + *vals =3D (const int *)kx022a_accel_samp_freq_table; > + *length =3D ARRAY_SIZE(kx022a_accel_samp_freq_table) * > + ARRAY_SIZE(kx022a_accel_samp_freq_table[0]); > + *type =3D IIO_VAL_INT_PLUS_MICRO; > + return IIO_AVAIL_LIST; > + case IIO_CHAN_INFO_SCALE: > + *vals =3D (const int *)kx022a_scale_table; > + *length =3D ARRAY_SIZE(kx022a_scale_table) * > + ARRAY_SIZE(kx022a_scale_table[0]); > + *type =3D IIO_VAL_INT_PLUS_MICRO; > + return IIO_AVAIL_LIST; > + default: > + return -EINVAL; > + } > +} Regards Jagath