Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp762050rdh; Sun, 24 Sep 2023 10:32:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3p6nFxsxxblOUtRkUZMwcBEXqII8zKBDn7CMr7UBG8WaiDYhrmCsYdfLeIYl9ZOWxqYVN X-Received: by 2002:a05:6a00:24d3:b0:690:fe13:1d28 with SMTP id d19-20020a056a0024d300b00690fe131d28mr6823011pfv.33.1695576745790; Sun, 24 Sep 2023 10:32:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695576745; cv=none; d=google.com; s=arc-20160816; b=DXIFZFAkil1LPCJTiapw2+DWb326+K1LF9jSJ7sAMlDpkePQzKMW734X7tf7ZghurT muDGzPSlOIDW46T7IYTPqlD9yKbR1APS15HKYAHx1uD0XJNj36ahfYt5CSj3MRXiz5HK YHtjn19YWLi3KRkzKbIm8GPNayb3iT9FVCNUFwFZNDKXe1qb+JAmqf09D5kCEJVCqCky 9KGh+Cb76FKFA7p8SkYKwfQYeBiR1iLo725C9Q/vmGuIsSlbZtWaqOyKllnbZieqsEJW 8bPTCd3g2gAEwoa2kARzFLBxb6SVtOljxBQofa55GUR3oGIxs5vMydTLxylUPBBBnMi5 1wFA== 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=/dErIW4dngrQU2v2XxBeCSKNSyBOpQEBQeiWc5axVFM=; fh=J/aQ3VQ1usFn2OiUKgsoebtsI6yr0VQFLqFjqmvpq44=; b=XnMS+XcGd5qTy9fJgEqvIkJr7HGFnqRwNLpoZRe8FOQieCCyIJeEnPpTvLjn1HHByj SzEMEvU7bHdsLEoPHpA/7TWiIQh/NSdVPQlojqY1JPssDwXFSgeVSr1megQ6tQ/zEtY5 JZW7gr1BJx76eVIgTSZ7u226FQD8yQEbEa/OYLIxaDB56EeywY1DfK91Bjpp73OgdYMW zrzpAkXdRgP4TJba2qwaC3s5h1Z3QQZ21/OD0TaQf0R3TawamJvDZxp8/pCo0ANC1WEJ UNufEHujCU+H+aA3q9hu4Zrhc8LOd9EiiOcmS6XNKTjRtSxZryg5qhccIBnHeubzXKCc DUEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XWm8Tw+i; 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 dw27-20020a056a00369b00b0068beea8071esi8189605pfb.221.2023.09.24.10.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 10:32:25 -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=XWm8Tw+i; 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 C18F8804390B; Sun, 24 Sep 2023 10:31:53 -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 S230136AbjIXRbw (ORCPT + 99 others); Sun, 24 Sep 2023 13:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbjIXRbu (ORCPT ); Sun, 24 Sep 2023 13:31:50 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5F8AFA; Sun, 24 Sep 2023 10:31:44 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2EDAC433C7; Sun, 24 Sep 2023 17:31:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695576704; bh=SBcRy7SqvEDiW3tVYGnfs39BvMV4QV8Nn93/BBiEIN8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XWm8Tw+issldt4e3+QjrdZXt6ac9d9MNE0oU363n7DtvPjibXiIj/07JSYsPsY82b RocWDo9ien25IUJ/XQwiXN39ET3ao1CuTT0J4XRm0EfviFLdBmvzr/QEkrGeJyXZKQ YbnPc4pywXAHHUvZVl1J+OP1uD8RxPOlwryIzo4zvPe8Ho+SQ46aYVnK7aeFvR1Tk5 6nI5bBMrMjScxOGevjGsd6Gg6T2HiPP0wK1nhBGx9P6H/m1NFJkfT3ztWTCYtzPs9L xr57qphFW/0RUVR+H0+CGYC7BwxDU0LhNOVqwPHFdKTlVJTb0lGKcQNIxoqTEfLCMs ZTUHnlgcr6UIQ== Date: Sun, 24 Sep 2023 18:31:36 +0100 From: Jonathan Cameron To: David Lechner Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Hennerich , Nuno =?UTF-8?B?U8Oh?= , Axel Haslam , Philip Molloy Subject: Re: [PATCH v2 06/19] staging: iio: resolver: ad2s1210: always use 16-bit value for raw read Message-ID: <20230924183136.25112830@jic23-huawei> In-Reply-To: <20230921144400.62380-7-dlechner@baylibre.com> References: <20230921144400.62380-1-dlechner@baylibre.com> <20230921144400.62380-7-dlechner@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]); Sun, 24 Sep 2023 10:31:53 -0700 (PDT) On Thu, 21 Sep 2023 09:43:47 -0500 David Lechner wrote: > This removes the special handling for resolutions lower than 16 bits. > This will allow us to use a fixed scale independent of the resolution. > > 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 This looks fine to me, but a potential improvement would be to just use a __be16 element in st in the first place have the type explicitly marked all the way through. Jonathan > --- > drivers/staging/iio/resolver/ad2s1210.c | 16 ++-------------- > 1 file changed, 2 insertions(+), 14 deletions(-) > > diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c > index 9c7f76114360..985b8fecd65a 100644 > --- a/drivers/staging/iio/resolver/ad2s1210.c > +++ b/drivers/staging/iio/resolver/ad2s1210.c > @@ -465,10 +465,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); > @@ -494,20 +491,11 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, > > 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_cpup((__be16 *)st->rx); Could be made more obvious still by adding as suitable __be16 to read into in the first place. > 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_cpup((__be16 *)st->rx); > ret = IIO_VAL_INT; > break; > default: