Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp372022rdb; Sat, 30 Sep 2023 07:43:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOm/r8elnoBrMNHLDuWisDx4ON4Iks9mRhuy4XDHvk2o6BypO9vZ8Au3AA2jdO1ryQ+FFP X-Received: by 2002:a05:6a20:5b15:b0:15e:96d3:a31b with SMTP id kl21-20020a056a205b1500b0015e96d3a31bmr6423816pzb.39.1696084992866; Sat, 30 Sep 2023 07:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696084992; cv=none; d=google.com; s=arc-20160816; b=ctsCTfErmH0C6dONoYhWS5ykBSDiE2tJ1usoZThbDRT2kHNpWGwD1OnYQTkNSMCbf0 eM/KfnWsyEsOfL0ybox3/Q5GuRYzXdK7jpkfEizLTkklyKQ4l6hcI4xnrWOdgk6LCkVT iov7TP+pBA330rQk6Vx1T4T+UKgMgKZCLDu9J8xO23kms/HEGmIhf22BmnBImcEgP3sG 6RjxzEtkzF98MKB4jXV8JmOP580PAYuKHNb9d0BS4rxMEtQf6AYEBHACv+0e19+jjhyF u3QcbSO/fdphshzJtei5+HFTILjfCyHjXJSnqwDzf8qejHfAjaEgUi3JIdJlm7ino8bH fDAQ== 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=6tNl260KhB/6CeYL7F74xuiYy1ecKN8rgLTIbhVGF/8=; fh=e9lXfbAZmLMG/YSSxlbXRgGopMc52ojan+iACBc5a/Y=; b=F4EPp0q40xVt2VQRRGdZkTIIUOwimpiYhcEorMtMcCT2Xh7DwwmpE5mNH/pwee1bSp pvh2oIeCSDUKDrizX1D4zUvKy3T38PIyhJHR/ffhPT1lT4k0jRVgvgGNiYefjN0iHFHe msoGhCNhK/u755SdFzG9CsblGTB345CUADAa+iO11ujIout1k0KxMDUGdmCe8DzeAmf4 l466Y3ijnFjCB4/PeyBDBtnFKS7h76YwI+GLpsLkbyy8KMEo/NgEI1oL415NZKn1PKL1 tuQdDBlL5wtmpiROCOEAsrAhOoyR3R24iB/k0xBtKucP/OqXxB/U9KnpbmM1rLbYvjTM BxNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DuLwmxsE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id h24-20020a17090acf1800b0027782fd462esi3619566pju.5.2023.09.30.07.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 07:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DuLwmxsE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 07E8080E65A3; Sat, 30 Sep 2023 07:41:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234298AbjI3OlU (ORCPT + 99 others); Sat, 30 Sep 2023 10:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234202AbjI3OlT (ORCPT ); Sat, 30 Sep 2023 10:41:19 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBE7CB7; Sat, 30 Sep 2023 07:41:17 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3EEEC433C7; Sat, 30 Sep 2023 14:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696084877; bh=Q/SSlLwnEG93mS+peUVA+bm/lwHeSP3DeLhQ0SjVwVg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DuLwmxsEhBwVUGDNMF7910VE7CNwzlMCX08ANjRzjn7w0tTk29ugCIi0qwqBCwzkO FGxoJcm7nTQxzyzP+MPich6bayxPjpwG5+VErt1hKoLJNJoxy2SNETjByqxeAkL9EI aECJysPt0AgVQMJF6OLHfK+MGo3+M7oT9B2s/3OnhY1G9RFAKaC3IC5wTNzERl/Y/0 USaWZ6gMhFkQ1zX8S31FrD8tIFJmruSmMbwHpnLPnaLWKpGSDTzB42ULQNgjpXr3wt k08i0rc+tchp6L9a/GzWcILNh0moI6uagkmg5nDd4SKPlS1Mx6H3VD0hO7+o2crD/f 0E+FPPjpIR+Sg== Date: Sat, 30 Sep 2023 15:41:15 +0100 From: Jonathan Cameron To: David Lechner Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-staging@lists.linux.dev, David Lechner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , Nuno =?UTF-8?B?U8Oh?= , Axel Haslam , Philip Molloy , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 07/27] staging: iio: resolver: ad2s1210: always use 16-bit value for raw read Message-ID: <20230930154115.3a6e3fea@jic23-huawei> In-Reply-To: <20230929-ad2s1210-mainline-v3-7-fa4364281745@baylibre.com> References: <20230929-ad2s1210-mainline-v3-0-fa4364281745@baylibre.com> <20230929-ad2s1210-mainline-v3-7-fa4364281745@baylibre.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 30 Sep 2023 07:41:28 -0700 (PDT) On Fri, 29 Sep 2023 12:23:12 -0500 David Lechner wrote: > From: David Lechner > > From: David Lechner > > This removes the special handling for resolutions lower than 16 bits. > This will allow us to use a fixed scale independent of the resolution. > > A new sample field is added to store the raw data instead of reusing > the config mode rx buffer so that we don't have to do a cast or worry > about unaligned access. > > Also, for the record, according to the datasheet, the logic for the > special handling based on hysteresis that was removed was incorrect. > > Signed-off-by: David Lechner LGTM Applied. Thanks, Jonathan > --- > > v3 changes: > * Added __be16 sample field to state struct and use instead of rx buffer. > > drivers/staging/iio/resolver/ad2s1210.c | 24 ++++++++---------------- > 1 file changed, 8 insertions(+), 16 deletions(-) > > diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c > index 832f86bf15e5..f9774dff2df4 100644 > --- a/drivers/staging/iio/resolver/ad2s1210.c > +++ b/drivers/staging/iio/resolver/ad2s1210.c > @@ -95,7 +95,11 @@ struct ad2s1210_state { > bool hysteresis; > u8 resolution; > enum ad2s1210_mode mode; > - u8 rx[2] __aligned(IIO_DMA_MINALIGN); > + /** For reading raw sample value via SPI. */ > + __be16 sample __aligned(IIO_DMA_MINALIGN); > + /** SPI transmit buffer. */ > + u8 rx[2]; > + /** SPI receive buffer. */ > u8 tx[2]; > }; > > @@ -464,10 +468,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, > long m) > { > struct ad2s1210_state *st = iio_priv(indio_dev); > - u16 negative; > int ret = 0; > - u16 pos; > - s16 vel; > > mutex_lock(&st->lock); > gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); > @@ -487,26 +488,17 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, > } > if (ret < 0) > goto error_ret; > - ret = spi_read(st->sdev, st->rx, 2); > + ret = spi_read(st->sdev, &st->sample, 2); > if (ret < 0) > goto error_ret; > > switch (chan->type) { > case IIO_ANGL: > - pos = be16_to_cpup((__be16 *)st->rx); > - if (st->hysteresis) > - pos >>= 16 - st->resolution; > - *val = pos; > + *val = be16_to_cpu(st->sample); > ret = IIO_VAL_INT; > break; > case IIO_ANGL_VEL: > - vel = be16_to_cpup((__be16 *)st->rx); > - vel >>= 16 - st->resolution; > - if (vel & 0x8000) { > - negative = (0xffff >> st->resolution) << st->resolution; > - vel |= negative; > - } > - *val = vel; > + *val = (s16)be16_to_cpu(st->sample); > ret = IIO_VAL_INT; > break; > default: >