Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3403319rwi; Wed, 12 Oct 2022 01:11:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5/1GtTVQg8F6LauAXlUnEPx8ml6Svc5fv2F8RdgDBVo7jkxY+KsIwJavqXyPUj6xX1THPa X-Received: by 2002:a05:6402:548f:b0:457:ed40:5f58 with SMTP id fg15-20020a056402548f00b00457ed405f58mr26133403edb.408.1665562268194; Wed, 12 Oct 2022 01:11:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665562268; cv=none; d=google.com; s=arc-20160816; b=HrmZyRNZ7J1OdxyvO7gS4mUAUuGjbYiSpVHMJKPOju/GczI4KYcUV5yBAmK5uSkuSC gDZcXuhsyCf27UOVBZ/fFj/QS9WqzmaIKiMYMozp+MyKuBTXcZt1IE9mz5FcvPUtu+NS 5sb3e8z7D5LpKljd30A+YectcGXEsSOOTv022e4xse069qnXjud/W860RRWVXztjXxHq jnmCXy/anO9c1aRKYl0Z6Qe2lte+5HYJoZararjgyu7E6RjwjnHbqR85S2PouHgFf/7M 7POc9w+IHwQt0BdCwVB2LPKA/HyfeN6mPHkHkAWpIeo0tbhxllyUPQFbxYS4NielRWNN Cftg== 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:subject :from:content-language:references:cc:to:user-agent:mime-version:date :message-id:dkim-signature; bh=a+IYmi8tEOzQZXwBg2WQPAuUHlGeEUS5FrkTkjk+8r4=; b=yOZUS7HS6XNotoYJ7RzhNXJvBgFKvQ3XHpfJzfx/NjzdgqhPRcmMWwiaXGQvjNks/b YbUNgJtJji26mExTqO5Dh582Hsj+FjjAy1FCRc2t6E9laANpKSN8o6JLOmXcWFHiB3UZ Jeali5JpAeSPJ54CahvLii/F2dwhioc0e9HmI87POIXiz6zYyjq+SUHEB6OrM/mJDa/4 Hm2d3IkiccaOKml1mvhaL/Xfwt3QwvWZJt6aSsS/xmY4iaFU/zE46s9XpAoAOJp9oU9Y 8hOdCh6MM7mvV/rSHYJMo3H5yG0E1eeKQZ1LpyQXdZC98aDaNTmEUSMqgWuzIF+kfbiC nLmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FOPJ9nrj; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p9-20020a170906228900b00783afe864c6si11996560eja.124.2022.10.12.01.10.41; Wed, 12 Oct 2022 01:11:08 -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=@gmail.com header.s=20210112 header.b=FOPJ9nrj; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229583AbiJLHks (ORCPT + 99 others); Wed, 12 Oct 2022 03:40:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiJLHkq (ORCPT ); Wed, 12 Oct 2022 03:40:46 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D6595AFD; Wed, 12 Oct 2022 00:40:41 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id r22so18342788ljn.10; Wed, 12 Oct 2022 00:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:content-language :references:cc:to:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=a+IYmi8tEOzQZXwBg2WQPAuUHlGeEUS5FrkTkjk+8r4=; b=FOPJ9nrj9y5QZ8FojeBTK5zlj/pB+V9L1nBdMphMqh/X69LUfrnDyKffKpTkvzRrya WzDqax1bXpZ2azImvJwrIYIvQYnBcWOIsYWkTsRjbun2XkRQuJkqKgJRUew5W5EPh2W6 d3U4QXHAZQBoL9JQhWBgCHu+MSeBqd4UPq8MBUN+/zdxEVD8yv4nhjJmoALtj75UaI3t S5kN5E2o5yj8bdKj2HyKPnIMigQuYenZFsCdd3D65xq4s6LtPn2Lcp+OwoaL6FIR9FAR Frs6oVs3IVlxKQR6VRPXwHvnzHfP3vtfqA9LFpFloSSnw9mC/Sd3Tic5EYrTEXxnBttE uetQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:content-language :references:cc:to:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a+IYmi8tEOzQZXwBg2WQPAuUHlGeEUS5FrkTkjk+8r4=; b=wpVnqnKr41o7y9lVFeh0zt4xdI3JO+9aF1pPkpPnPGFQzkguvNCC4uJRQr1sBbALIu D5K/pTeUImfcsQM78nBfCxXKhOr0dzwu0J5wrd0bi52H2JxxbB7voAcCotBu1/lvS2zM Oey48ViV9hfxsZiHOubZnhtR9MROrGXA1OZDhZuCehaPmpuVUDgzEWUmLMPXkPwMHiJL FBDBIGFrqv1slib3q5EAsLBqP5F6wzSRbW/tdz2favQrhHPJ3OKah3GGHzuUxbHfu4+2 1dCKYvjRns1J8B2Qh+5msTZmh7HA1Vz0ljKieD/9pX+0qtQPHiebQp0OZRKTh1NukZfR Y1Hg== X-Gm-Message-State: ACrzQf35r6d8GcMVBJSSDH7FO2BeAw3aCI/oap3oQR2Rlzn3JNLdWMxE +Ah/nNnMtvgKv2gR7wssKLg= X-Received: by 2002:a2e:a54d:0:b0:26c:64ae:236a with SMTP id e13-20020a2ea54d000000b0026c64ae236amr10808580ljn.207.1665560440059; Wed, 12 Oct 2022 00:40:40 -0700 (PDT) Received: from ?IPV6:2001:14ba:16f3:4a00::4? (dc75zzyyyyyyyyyyyyycy-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::4]) by smtp.gmail.com with ESMTPSA id dt11-20020a0565122a8b00b00497c3fdf995sm2183545lfb.152.2022.10.12.00.40.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Oct 2022 00:40:39 -0700 (PDT) Message-ID: Date: Wed, 12 Oct 2022 10:40:38 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 To: "Vaittinen, Matti" , Andy Shevchenko Cc: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Jagath Jog J , Nikita Yushchenko , Cosmin Tanislav , "linux-iio@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <88e24b01da9f44ebf5fcd8344ded0b75ff742fbf.1665066397.git.mazziesaccount@gmail.com> <98b59ad5-8c29-be41-4da1-a961db67827c@gmail.com> <19a6db0f-40a8-dacf-4583-cdb9d74e1243@fi.rohmeurope.com> Content-Language: en-US From: Matti Vaittinen Subject: Re: [RFC PATCH v2 4/5] iio: accel: Support Kionix/ROHM KX022A accelerometer In-Reply-To: <19a6db0f-40a8-dacf-4583-cdb9d74e1243@fi.rohmeurope.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,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 10/10/22 16:20, Vaittinen, Matti wrote: > On 10/10/22 14:58, Andy Shevchenko wrote: >> On Mon, Oct 10, 2022 at 12:12:34PM +0300, Matti Vaittinen wrote: >> ... >> >>>>> + ret = regmap_bulk_read(data->regmap, chan->address, &data->buffer, >>>>> + sizeof(s16)); >> >>>> No endianess awareness (sizeof __le16 / __be16) >> >>>>> + if (ret) >>>>> + return ret; >>>>> + >>>>> + *val = data->buffer[0]; >>>> >>>> Ditto (get_unaligned_be16/le16 / le16/be16_to_cpup()). >>> >>> I have probably misunderstood something but I don't see why we should use >>> 'endianess awareness' in drivers? I thought the IIO framework code takes >>> care of the endianes conversions based on scan_type so each individual >>> driver does not need to do that. That however has been just my assumption. I >>> will need to check this. Thanks for pointing it out. >> >> The IIO core uses endianness field only once in iio_show_fixed_type() AFAICS. Following is some hand waving and speculation after my quick code read. So, I may be utterly wrong in which case please do correct me... Anyways, it seems to me that you're correct. The endianness field is only used by the IIO to build the channel information for user-space so that applications reading data can parse it. As far as I understand, the driver does not need to do the conversions for user-space, but the user-space tools should inspect the type information and do the conversion. I think it makes sense as user-space applications may be better equipped to do some maths. It also may be some applications do not want to spend cycles doing the conversion but the conversions can be done later "offline" for the captured raw data. So omitting conversion in the IIO driver kind of makes sense to me. I haven't thoroughly looked (and I have never used) the in-kernel IIO APIs for getting the data. A quick look at the include/linux/iio/consumer.h allows me to assume the iio_chan_spec can be obtained by the consumer drivers. This should make the endianess information available for the consumer drivers as well. So, again, consumer drivers can parse the raw-format data themself. I have this far only used the sysfs and iio_generic_buffer on a little-endian machine so I have had no issues with the little-endian data and I have only observed the code. Hence I can not really say if my reasoning is correct - or if it is how IIO has been designed to operate. But based on my quick study I don't see a need for the IIO driver to do endianess conversion to any other format but what is indicated by scan_type. Specifically for KX022A, the data is already 16B LE when read from the sensor. This is also advertised by scan_type so no conversion should be needed (unless, of course, I am mistaken :]). >> And it does nothing with it. Maybe Jonathan can shed a light what is it for >> (I mean the field)? >> I agree. It'd be great to listen to someone who actually knows what he is talking about and is not just guessing as I am ^_^; Yours, -- Matti -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~