Message ID | 20230929-ad2s1210-mainline-v3-7-fa4364281745@baylibre.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp133169vqb; Fri, 29 Sep 2023 18:04:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+LKOkaDPn4nz6DMiIoqXctVyWrmtDB5RLKCQ8fRJ6wtJHb+ffgOy4dnOGixNICFDfNLve X-Received: by 2002:a05:6358:7e07:b0:142:fba8:dcfc with SMTP id o7-20020a0563587e0700b00142fba8dcfcmr7087411rwm.16.1696035886851; Fri, 29 Sep 2023 18:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696035886; cv=none; d=google.com; s=arc-20160816; b=EtFbMKFCdXFJMHlxLJW3uy6+r5KW3eoOh4bN3qNA12DUquREy7Pzg66a+yi1Fez+oT ydQkeuOWt8cz8Jv28CfnIFxnb14qgTiqGn/G4gXxH4OccDyk0y3vx+NSHjJKo8fMaN/a y6nbsGXJb/Gv9Z3DGAhiV6k0vk1nMp1kMXdbSCZPYqLI5vrMAPiUjLosX7AaHgsvrLut +TQUj1tvoSEWyst3W4cW+QkmiEzCig6rhClVeALqx2PG/B3EdadLxWI1HgmGCvs8cHpk e6m8Fei3AudB3FI5VPxP9voquPjLpPKAElRFovrQA1r3XfXmniv+SHd/EPw06mZIFt77 Az2g== 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:date:subject:cc:to:from :dkim-signature; bh=3mVPfJvq9odcQF/rUfj3o/6NyMJOAJ6+IQlyYMebtjw=; fh=/JQ89VrFJ6cddpMA/8uKU4hR6LyRWF8O9dzD336qQ7I=; b=rF1Vzx1M97vzflBHXM08t/Dyq5D9Kfu3ReYqeyRqT7dnEjnMsgySbUimpelFXIaZOi k8+z+WQ6mDhP3+4Dvs0AiwfaAOxlOdnSmoXCiNn3mZFsoIZH6sH/Hj2sRdjoF6sP93Vr mGMjXlRhJwvd6VKjfBWya7L9mpT3viC2azG0vBzsR1p8qEHqi3f0QIuyBJRFlpa0hjlq siEGTwW0PcFWUHO1MHTfijh977Yn6rAAx/hpredoSWvJQE2nYroEwp6UXSxvxtZti6R1 nZNPFET+iMvHeJEbh2B4FaUWzZewPPDWKgi6p4BPsLy4f0Krltp1cHI8WpAkBUEeTxr3 LM2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=gSv16dBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l192-20020a6391c9000000b005859cea158fsi2835685pge.207.2023.09.29.18.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 18:04:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=gSv16dBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DC7208028A5C; Fri, 29 Sep 2023 10:27:01 -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 S233753AbjI2R0P (ORCPT <rfc822;pwkd43@gmail.com> + 19 others); Fri, 29 Sep 2023 13:26:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233353AbjI2RZ4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 29 Sep 2023 13:25:56 -0400 Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBFD11BC for <linux-kernel@vger.kernel.org>; Fri, 29 Sep 2023 10:25:53 -0700 (PDT) Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-57e3c2adbf0so288984eaf.2 for <linux-kernel@vger.kernel.org>; Fri, 29 Sep 2023 10:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1696008353; x=1696613153; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3mVPfJvq9odcQF/rUfj3o/6NyMJOAJ6+IQlyYMebtjw=; b=gSv16dBX8P/ZsC7lNkev8mTFmIzBYdjV2+cIC1qQuR/Kzz9xMY5dqmOtvX1fKuxgES DMG+CuptnuOCrvdsyGJWBA7eIvHB7YTZAB4CnxZ2XJF08a352MfxQpsp0jqVOq5HTVzt jk4qanpJE/1wglGCIWTu8Wl485W5WpbUY594/g/0Ji6xMN2DjDU0TpFkJJKRtWf698rV k6l7zdqT/f/NsnS7seNJ9b9xPA+OyFwdO5fQzJC1LteezW3WQfBLuD73cFxpo2cKb99c n+WeAvRYIqa8ddmnI3l2mGPTrX7ArSG5sD6u2CtsovwRZLvdkglmHNx6ozm2GGwaJYwj RfDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696008353; x=1696613153; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3mVPfJvq9odcQF/rUfj3o/6NyMJOAJ6+IQlyYMebtjw=; b=f4lusNVK1/DuNIVOMDCmBNxV/A1+XJ8gctzRHsGbbpEJ46xGmqFdywdHSqmMOC6fzr lWt4Zxs54csWRNf/Z8adx8urZjHUB3hBEzpemMT2aCBPmZC/4fKeyeTIUddYppLPGEYt gjJFyEXe3qcun1ImwX5GwdCUxiRKZyZEL3RLgdFwWQpekPQ1iuZ47lvTeZUnOq6IDSan n5A/7p6YFAXQobGJHu1OpEmKYVNOCp1fbnyb/Dua4PWdZrYwOV/isrsaWM6q3sXb+sP/ iCzBpCF9W70PFZar1P2Z7r8LApR5hPOaQOxYgjCytPMqNSwVIN99PeS9g7fuKPlLJVxU bmuQ== X-Gm-Message-State: AOJu0Ywy+fKgUujz4I51d8FiV5xCgEn0Zy7M7n0tkmJ1SGpk6LxnfCFW kdIoQjKkAOYPTJ0oxTwTco0eFg== X-Received: by 2002:a4a:9d14:0:b0:57b:8c6b:c99b with SMTP id w20-20020a4a9d14000000b0057b8c6bc99bmr4828635ooj.9.1696008353269; Fri, 29 Sep 2023 10:25:53 -0700 (PDT) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id f128-20020a4a5886000000b0057bb326cad4sm2272915oob.33.2023.09.29.10.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 10:25:52 -0700 (PDT) From: David Lechner <dlechner@baylibre.com> To: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-staging@lists.linux.dev Cc: David Lechner <david@lechnology.com>, Jonathan Cameron <jic23@kernel.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Michael Hennerich <Michael.Hennerich@analog.com>, =?utf-8?q?Nuno_S=C3=A1?= <nuno.sa@analog.com>, Axel Haslam <ahaslam@baylibre.com>, Philip Molloy <pmolloy@baylibre.com>, linux-kernel@vger.kernel.org, David Lechner <dlechner@baylibre.com> Subject: [PATCH v3 07/27] staging: iio: resolver: ad2s1210: always use 16-bit value for raw read Date: Fri, 29 Sep 2023 12:23:12 -0500 Message-ID: <20230929-ad2s1210-mainline-v3-7-fa4364281745@baylibre.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230929-ad2s1210-mainline-v3-0-fa4364281745@baylibre.com> References: <20230929-ad2s1210-mainline-v3-0-fa4364281745@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.3 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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: <linux-kernel.vger.kernel.org> 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]); Fri, 29 Sep 2023 10:27:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778422526349924778 X-GMAIL-MSGID: 1778422526349924778 |
Series |
iio: resolver: move ad2s1210 out of staging
|
|
Commit Message
David Lechner
Sept. 29, 2023, 5:23 p.m. UTC
From: David Lechner <david@lechnology.com> From: David Lechner <dlechner@baylibre.com> 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 <dlechner@baylibre.com> --- 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(-)
Comments
On Fri, 29 Sep 2023 12:23:12 -0500 David Lechner <dlechner@baylibre.com> wrote: > From: David Lechner <david@lechnology.com> > > From: David Lechner <dlechner@baylibre.com> > > 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 <dlechner@baylibre.com> 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: >
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: