Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp141823rdb; Wed, 18 Oct 2023 22:54:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXWkKvo6H6uBcmmQrunEDtuB8OwTF5Dv3d+Jnb9+jl7ILsSGfhPvmaU3dKh6eWZQG3QkSR X-Received: by 2002:a17:902:e742:b0:1c7:7e00:8075 with SMTP id p2-20020a170902e74200b001c77e008075mr1598277plf.66.1697694841716; Wed, 18 Oct 2023 22:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697694841; cv=none; d=google.com; s=arc-20160816; b=n4+UKnX9+ttnR9TGhZRO4vlUJHuDg4UjiFlBs1JpUSu607K/V+SdpXPIcdUbS2KP64 ehR7XYaXpuDLZfnZeE49vLva822sSNk8Il4AnKLXKq6XEfQLCb+IKB2Fy8RXi3lFDwvo A1xSeOiXEjH5Yk9KqetipnIXvijPfM5WtnuofpJ9HbDO7eUybPxITfDdvn4EKQ7+PaW3 WLdL/hKuf8Mg7eTr6uTHdcVOLvDjU9KZpE6cubiIw/dEOggPrKjtBBXIX/3myNbNeJpe etY2okLEMvZen5RXHRXr3cyEw2OE6I8djWrsBXKWyxGGeCRweildb+vNj3ZZG8yGwWLE a2zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=XObVuaWXr/rmZ3JntkdvlKmSVs/dr+MV+e6w2yjEeN0=; fh=r3FwCKmEaPoIxP61oKUSw8/GHfjI0UP4lt3ET8sJdBs=; b=TFcFsmYkPBJ+JeD+9U3W2m4jKZFFrWRceXaA5O+370sg+4j5/+52JmA4t1jQ/IeEsi gCLT0CR+2FSFpLnuJi/ugttk5gRK1km5mcNic2bBFUGbrBk85yn5QTJkEht4JEG4T6RB DKD1kAodtgPUJhYym+Hry+C5GNlWwLIl0J0lqr8+gwa0bGXCa6HUd59YCpDrgtsZmdC7 LGhIYnfq4VMszAkspGF2vrpGe296WDfXzjboxjVe3c/8kED0F3Wa9Srm0Zwb0Uh2bLFY qCuwPGZGr+BhQjWqETF2BfwOOZKJyZ8BZA8sh9cSdlkgUd+/lKhtO+o0i9PT7WgDQVlZ 9FMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iWLlOD+Z; 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 jo23-20020a170903055700b001c9c076668esi1378348plb.42.2023.10.18.22.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 22:54:01 -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=iWLlOD+Z; 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 1EABE825B484; Wed, 18 Oct 2023 22:53:59 -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 S231284AbjJSFxt (ORCPT + 99 others); Thu, 19 Oct 2023 01:53:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjJSFxs (ORCPT ); Thu, 19 Oct 2023 01:53:48 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AE59B6; Wed, 18 Oct 2023 22:53:46 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2c5087d19a6so82482091fa.0; Wed, 18 Oct 2023 22:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697694824; x=1698299624; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=XObVuaWXr/rmZ3JntkdvlKmSVs/dr+MV+e6w2yjEeN0=; b=iWLlOD+ZFhg7GXu2M8lbBlZCsoYupI2z7tOq2I5xpfLBYizKIfyc8YjPvrDa63xzDv Tb+3kfuCcY5pwxZIVkDSDos0zqGpzQDYVlqMes2klr7ULYUlnx+ugB4woAoyK32Cxnrg qisB/nuZESzE63C+8iMtJP0ftDVZrm3NQueGJqI+L0Mwc+E40yTP4uIhMxVijjJUSyhw eNq/z5O3a4fv3I5o8NB0WoJzSV125dqfi+cjS6Blarko9fVRWi4pbKOWpG2TFEwVeeqO pgsJkN8JskIRZ4ldeJunpp0O3uR5sRzYSSW/v2uDqTsTGkrv73FvXi0sXJudIzbKmYqg v28Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697694824; x=1698299624; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XObVuaWXr/rmZ3JntkdvlKmSVs/dr+MV+e6w2yjEeN0=; b=h8XLRidEr8BmbWkbjwl44f/0pHNLljLhE/VzmUJv/rmlaXba0NT1j9hChLVpjlA0ub FDloQDYWb3JfSDoemsE6hQtHXRm+2DcmkQ5jw2ETR0WDYg5A42w2lfUWmJI/Fq00uMfW WfApRCgIzhBuP/4palZKXK3jTio823/SpjBOFhdwq5pUCdk7ti7p8BQcR16ZIFDEoJdT +hfu/j736rNPATXeeTTPOlWtQ+cpLMNMgmbvEbL8yX7WnZe7U8H2499hyyLnSsJGtqTz nx7rHVuvMWkvjmUiEw4uS4ds2K13bDjw34h1MzbbBwEe5SMIKKHa0t6eKlXEMCIa4pO8 zvLw== X-Gm-Message-State: AOJu0YxW03YS1TV8qN5CfHSqZIW7T2065yo/vjT4MFWTBzfQ6KNSCoF9 a7wwXe76w/+n518/trg3cfE= X-Received: by 2002:a05:651c:1058:b0:2c5:13e8:d54e with SMTP id x24-20020a05651c105800b002c513e8d54emr648637ljm.38.1697694823867; Wed, 18 Oct 2023 22:53:43 -0700 (PDT) Received: from ?IPV6:2001:14ba:16f8:1500::7? (dc78bmyyyyyyyyyyyyydt-3.rev.dnainternet.fi. [2001:14ba:16f8:1500::7]) by smtp.gmail.com with ESMTPSA id z16-20020a2e8e90000000b002c0414c3b6csm966928ljk.121.2023.10.18.22.53.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Oct 2023 22:53:42 -0700 (PDT) Message-ID: Date: Thu, 19 Oct 2023 08:53:31 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 2/3] iio: accel: Support Kionix/ROHM KX022A accelerometer To: Jonathan Cameron , Jagath Jog J Cc: Matti Vaittinen , 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, Mehdi Djait References: <758b00d6aea0a6431a5a3a78d557d449c113b21e.1666614295.git.mazziesaccount@gmail.com> <20231018203423.06f20a6c@jic23-huawei> Content-Language: en-US, en-GB From: Matti Vaittinen In-Reply-To: <20231018203423.06f20a6c@jic23-huawei> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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]); Wed, 18 Oct 2023 22:53:59 -0700 (PDT) On 10/18/23 22:34, Jonathan Cameron wrote: > On Wed, 18 Oct 2023 01:37:12 +0530 > Jagath Jog J wrote: Hi Jagath - and thanks! >> Hi Matti, >> >> On Mon, Oct 24, 2022 at 6:10 PM 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 bits. >>> + * The scale table can be calculated using >>> + * (range / 2^bits) * g = (range / 2^bits) * 9.80665 m/s^2 >>> + * => KX022A uses 16 bit (HiRes mode - assume the low 8 bits are zeroed >>> + * in low-power mode(?) ) >>> + * => +/-2G => 4 / 2^16 * 9,80665 * 10^6 (to scale to micro) >>> + * => +/-2G - 598.550415 >>> + * +/-4G - 1197.10083 >>> + * +/-8G - 2394.20166 >>> + * +/-16G - 4788.40332 >>> + */ >>> +static const int kx022a_scale_table[][2] = { >>> + { 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² for the Z-axis? > > Definitely suspicious as should be in m/s^2 for an acceleration and > it should be > > 9.8*16/2^bits > > So I think these are out by a factor of 10^6 I think you are right. Looks like I misinterpreted the meaning of IIO_VAL_INT_PLUS_MICRO when I took my first tour in the IIO with this driver. The comment above the scale table does support that assumption ... 10^6 would match such a brainfart. (This is my first thought. I will take better look at this later today and see if I can come up with a fix if no-one else has sent a patch already). I CC'd Mehdi who has also been working on this driver. Regarding the KX022A - I am not aware of upstream users of this IC (yet). May be you're the first lucky one :) Hence, I am tempted to just fixing the driver - but it's Jonathan who will take the splatters when **** hits the fan - so it's his call to decide whether we can still fix this. _If_ there are users who have adapted to this buggy scale (users I am not aware of) then fix will break their apps. Mehdi, do you know any users of this upstream driver? I will ping the HQ guy who has contacts to those who might be using the driver in a downstream repository and ask him to inform potential users. It'd be very nice to get this fixed. Sorry and thanks! Yours, -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~