From patchwork Fri May 18 18:23:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Veenstra X-Patchwork-Id: 10411805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A502D602C2 for ; Fri, 18 May 2018 18:23:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9355D28707 for ; Fri, 18 May 2018 18:23:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84F0B287C1; Fri, 18 May 2018 18:23:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20C0728707 for ; Fri, 18 May 2018 18:23:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751506AbeERSXG (ORCPT ); Fri, 18 May 2018 14:23:06 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:52224 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751298AbeERSXF (ORCPT ); Fri, 18 May 2018 14:23:05 -0400 Received: by mail-wm0-f66.google.com with SMTP id w194-v6so15483278wmf.2; Fri, 18 May 2018 11:23:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HH538xI0hCMoX8wmVdzcKoLP6DIBXQGLZR+nUEIYjXc=; b=kS5xtmRXF3+WG1eYBgnD7FffuTrl3xEE6fVil8LGvsxa1SaHwrat3wIqEtk1ow/zmq WX/2epsAaNl/BA6ziOTWowXaPI/zbX8CbT5ZVi4WHjF0xj9DwRcSYDtuwYVOppyWh4Mo g31Drlc6GKp78yaO6opMjeo4BpMmBeJWPIvTubrHW09sqrw/IRlwTBqWZBv5PhzkBciS H2k3NUSxtvS4nI1Kz0wQsvn4zK9XXlUzNXsKwwO1OqLddMJ74IGAHF0G7i/sb2QEhwBl rwiFcHn50pygAdzVSmP1w0O5mrol1MphGTYJ+AFx2WGX/71Ckj97u8SkKRY9EuJwdtic hg8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HH538xI0hCMoX8wmVdzcKoLP6DIBXQGLZR+nUEIYjXc=; b=PjzCXeQCvwTmNzANKjv49hjyO+IzOd0O1Ketf1hJY6V/nx21b+UXv8UVBkp9nIsonJ OSsjvN5sSr1P/2yw7QPC+rgI+ANFWP4jYz0X/wLG+o8p3hNY0/fe1nOnBfVywPRihVyb ppGa+EfWvVHEWymThBkQ+A+qjqUYytzdXAS6u815bfGtOFSGP+pcB3XIIphU3uc4S27u gd+RiB7A5b0P69nO8sgB9qzk4KIwKAkSCiGLJnLYwVfxk9lA5MQy00UlXUi6XN3D5JNO eUW6OHfI/zov58qCCq0jZYDsSCeFIBeATtorGJ0byOrWwAvfDkDVm90uRA0oIBko1TTy a3MA== X-Gm-Message-State: ALKqPwc5eKaGHaD/m3LJfi9pO9sqljdDp2IY5FiKAh07htlK+7ArxpMC wDsBZqVSCyf+JWvnFqwW1oY= X-Google-Smtp-Source: AB8JxZpKorGGuk9axpDh3TRLiT2mCS05OREC9gALgBEUBAWxHhF418PSG4/4IKdzOCAvJNLeOP/5VQ== X-Received: by 2002:a50:f695:: with SMTP id d21-v6mr12725580edn.142.1526667784147; Fri, 18 May 2018 11:23:04 -0700 (PDT) Received: from zenbook-arch (s559434a1.adsl.online.nl. [85.148.52.161]) by smtp.gmail.com with ESMTPSA id f11-v6sm4137371edf.68.2018.05.18.11.23.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 11:23:03 -0700 (PDT) Date: Fri, 18 May 2018 20:23:01 +0200 From: David Veenstra To: jic23@kernel.org, lars@metafoo.de, pmeerw@pmeerw.net, robh+dt@kernel.org Cc: Michael.Hennerich@analog.com, knaack.h@gmx.de, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, devicetree@vger.kernel.org Subject: [PATCH v4 09/12] staging: iio: ad2s1200: Add scaling factor for angular velocity channel Message-ID: <6d616883c8431021cdfd0eaa551790e41d80a664.1526667118.git.davidjulianveenstra@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The sysfs iio ABI states radians per second is expected as the unit for angular velocity, but the 12-bit angular velocity register has revolution per seconds as its unit. So a scaling factor of approximately 2 * Pi is added to the angular velocity channel. Signed-off-by: David Veenstra --- Changes in v4: - Changed rps to revolutions per second in commit message to prevent confusion. drivers/staging/iio/resolver/ad2s1200.c | 71 ++++++++++++++++--------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1200.c b/drivers/staging/iio/resolver/ad2s1200.c index 67d9747f88a6..7b8af558e921 100644 --- a/drivers/staging/iio/resolver/ad2s1200.c +++ b/drivers/staging/iio/resolver/ad2s1200.c @@ -55,37 +55,55 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev, struct ad2s1200_state *st = iio_priv(indio_dev); int ret; - mutex_lock(&st->lock); - gpiod_set_value(st->sample, 0); - - /* delay (6 * AD2S1200_TSCLK + 20) nano seconds */ - udelay(1); - gpiod_set_value(st->sample, 1); - gpiod_set_value(st->rdvel, !!(chan->type == IIO_ANGL)); - - ret = spi_read(st->sdev, &st->rx, 2); - if (ret < 0) { + switch (m) { + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_ANGL_VEL: + /* 2 * Pi ~= 6.283185 */ + *val = 6; + *val2 = 283185; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } + break; + case IIO_CHAN_INFO_RAW: + mutex_lock(&st->lock); + gpiod_set_value(st->sample, 0); + + /* delay (6 * AD2S1200_TSCLK + 20) nano seconds */ + udelay(1); + gpiod_set_value(st->sample, 1); + gpiod_set_value(st->rdvel, !!(chan->type == IIO_ANGL)); + + ret = spi_read(st->sdev, &st->rx, 2); + if (ret < 0) { + mutex_unlock(&st->lock); + return ret; + } + + switch (chan->type) { + case IIO_ANGL: + *val = be16_to_cpup(&st->rx) >> 4; + break; + case IIO_ANGL_VEL: + *val = sign_extend32(be16_to_cpup(&st->rx) >> 4, 11); + break; + default: + mutex_unlock(&st->lock); + return -EINVAL; + } + + /* delay (2 * AD2S1200_TSCLK + 20) ns for sample pulse */ + udelay(1); mutex_unlock(&st->lock); - return ret; - } - switch (chan->type) { - case IIO_ANGL: - *val = be16_to_cpup(&st->rx) >> 4; - break; - case IIO_ANGL_VEL: - *val = sign_extend32(be16_to_cpup(&st->rx) >> 4, 11); - break; + return IIO_VAL_INT; default: - mutex_unlock(&st->lock); - return -EINVAL; + break; } - /* delay (2 * AD2S1200_TSCLK + 20) ns for sample pulse */ - udelay(1); - mutex_unlock(&st->lock); - - return IIO_VAL_INT; + return -EINVAL; } static const struct iio_chan_spec ad2s1200_channels[] = { @@ -99,6 +117,7 @@ static const struct iio_chan_spec ad2s1200_channels[] = { .indexed = 1, .channel = 0, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), } };