From patchwork Sat Mar 16 02:12:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 306C714DE for ; Sat, 16 Mar 2019 02:12:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16D452AC71 for ; Sat, 16 Mar 2019 02:12:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ADEC2AC88; Sat, 16 Mar 2019 02:12:41 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E4B452AC71 for ; Sat, 16 Mar 2019 02:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726465AbfCPCMd (ORCPT ); Fri, 15 Mar 2019 22:12:33 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:44079 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726444AbfCPCMd (ORCPT ); Fri, 15 Mar 2019 22:12:33 -0400 Received: by mail-yw1-f65.google.com with SMTP id c4so8774548ywa.11; Fri, 15 Mar 2019 19:12:32 -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=JHBZKH3Jy7ARadEyMRlSjyeitnQMzq6bw+SZjLu97T4=; b=cvZjHPzL+ZpMXLZHfshjz+WcEKjG8JIs8iUsnlyf6KaFo/+NROx0+dvSdXcj8n3oBE OHNwsRBK5jmZ1jWcbkhUnXu2EsAoeQizFYd5j740JffadIxgLrgu5w8gUL3gD0nYtgsm tH5VD0OpEWyP0RnP9+Rqss60a9vBL43L49mjtNyByLNK7ESCW81VHXlvjEYq0Cu+Y7Yj aj18QO1QINDgCxZGkk20E4irozODjFR7Akdr8e1YeBeNxGVaqiZl5zDmPLfQAjxcpNI1 kwSb8Dko6+iDDoPbn0p2w7RavnBmrSm5Q4M39iO5f0QSQFLxjtOFKBE6dULFPXOSj8dz +AZg== 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=JHBZKH3Jy7ARadEyMRlSjyeitnQMzq6bw+SZjLu97T4=; b=XlOoYC5f6aJUvmOCSNQWxK1G7hD01VfAdq1hnakojdbRqZSfUbZXIG6YH1ov6HA0uF gaOOmexXCKV9ZW4nnuhekEknlaQNKRWGQSDChxOfVn0VXmPii5NpVVH1Gn/ZfgUgjfpt vHiDV3P8vk8Plw1gDsbvixW0qNELsnw58UACguO9NHI9VUh/XQtyhcdx4tBsxDhFs/hw g5ZxwbphUxfepevDZcnY0/reaHmgprLzpnw4HEuGUpizf6lxYHv36ohF7ogtIrk2iqey 6zi5wRTy+/x93jZVnVQG3KyeS6BqZ68Nh1IhznKEIbPYbcN1jLdUjhzPD3UIj8diqrHO eeRA== X-Gm-Message-State: APjAAAUBRKEXWkaBWdhlmhRTqzS0Tl5xZRVKUZnsHAJXnZJcpYsDy+Ut gAEklmPk9zCDEtiyYCecBZU= X-Google-Smtp-Source: APXvYqwrKZ0+G79bqGBoiLSrXosi3ON5wsxx77xjUiM7inF6o6KLFG4ImqEmXHtkujRsTqqeQMQnYA== X-Received: by 2002:a0d:eec3:: with SMTP id x186mr5567903ywe.264.1552702352187; Fri, 15 Mar 2019 19:12:32 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id l123sm1408447ywb.59.2019.03.15.19.12.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:12:31 -0700 (PDT) Date: Fri, 15 Mar 2019 23:12:27 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 01/11] staging: iio: ad7780: add gain & filter gpio support Message-ID: <2687836c5b442990ee50d4efe787a3927c750bbc.1552700652.git.renatogeh@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 Previously, the AD7780 driver only supported gpio for the 'powerdown' pin. This commit adds suppport for the 'gain' and 'filter' pin. Signed-off-by: Renato Lui Geh Signed-off-by: Giuliano Belinassi Co-developed-by: Giuliano Belinassi --- Changes in v3: - Renamed ad7780_chip_info's filter to odr - Renamed ad778x_filter to ad778x_odr_avail - Changed vref variable from unsigned int to unsigned long long to avoid overflow - Removed unnecessary AD_SD_CHANNEL macro Changes in v4: - Removed useless macro - Added default case for switch to suppress warning - Removed chunks belonging to filter reading, adding these as a patch for itself Changes in v5: - ad778x_odr_avail moved to filter patch - Split gain reading to its own patch - Init GPIOs in a separate function drivers/staging/iio/adc/ad7780.c | 114 ++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 18 deletions(-) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index c4a85789c2db..07e5e35c92a3 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -39,6 +39,9 @@ #define AD7170_PATTERN (AD7780_PAT0 | AD7170_PAT2) #define AD7170_PATTERN_MASK (AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2) +#define AD7780_GAIN_MIDPOINT 64 +#define AD7780_FILTER_MIDPOINT 13350 + struct ad7780_chip_info { struct iio_chan_spec channel; unsigned int pattern_mask; @@ -50,7 +53,10 @@ struct ad7780_state { const struct ad7780_chip_info *chip_info; struct regulator *reg; struct gpio_desc *powerdown_gpio; - unsigned int gain; + struct gpio_desc *gain_gpio; + struct gpio_desc *filter_gpio; + unsigned int gain; + unsigned int int_vref_mv; struct ad_sigma_delta sd; }; @@ -104,8 +110,10 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, voltage_uv = regulator_get_voltage(st->reg); if (voltage_uv < 0) return voltage_uv; - *val = (voltage_uv / 1000) * st->gain; + voltage_uv /= 1000; + *val = voltage_uv * st->gain; *val2 = chan->scan_type.realbits - 1; + st->int_vref_mv = voltage_uv; return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_OFFSET: *val = -(1 << (chan->scan_type.realbits - 1)); @@ -115,6 +123,50 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int ad7780_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, + int val2, + long m) +{ + struct ad7780_state *st = iio_priv(indio_dev); + const struct ad7780_chip_info *chip_info = st->chip_info; + unsigned long long vref; + unsigned int full_scale, gain; + + if (!chip_info->is_ad778x) + return -EINVAL; + + switch (m) { + case IIO_CHAN_INFO_SCALE: + if (val != 0) + return -EINVAL; + + vref = st->int_vref_mv * 1000000LL; + full_scale = 1 << (chip_info->channel.scan_type.realbits - 1); + gain = DIV_ROUND_CLOSEST(vref, full_scale); + gain = DIV_ROUND_CLOSEST(gain, val2); + st->gain = gain; + if (gain < AD7780_GAIN_MIDPOINT) + gain = 0; + else + gain = 1; + gpiod_set_value(st->gain_gpio, gain); + break; + case IIO_CHAN_INFO_SAMP_FREQ: + if (1000*val + val2/1000 < AD7780_FILTER_MIDPOINT) + val = 0; + else + val = 1; + gpiod_set_value(st->filter_gpio, val); + break; + default: + break; + } + + return 0; +} + static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta, unsigned int raw_sample) { @@ -125,13 +177,6 @@ static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta, ((raw_sample & chip_info->pattern_mask) != chip_info->pattern)) return -EIO; - if (chip_info->is_ad778x) { - if (raw_sample & AD7780_GAIN) - st->gain = 1; - else - st->gain = 128; - } - return 0; } @@ -173,8 +218,47 @@ static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { static const struct iio_info ad7780_info = { .read_raw = ad7780_read_raw, + .write_raw = ad7780_write_raw, }; +static int ad7780_init_gpios(struct device *dev, struct ad7780_state *st) +{ + int ret; + + st->powerdown_gpio = devm_gpiod_get_optional(dev, + "powerdown", + GPIOD_OUT_LOW); + if (IS_ERR(st->powerdown_gpio)) { + ret = PTR_ERR(st->powerdown_gpio); + dev_err(dev, "Failed to request powerdown GPIO: %d\n", ret); + return ret; + } + + if (!st->chip_info->is_ad778x) + return 0; + + + st->gain_gpio = devm_gpiod_get_optional(dev, + "adi,gain", + GPIOD_OUT_HIGH); + if (IS_ERR(st->gain_gpio)) { + ret = PTR_ERR(st->gain_gpio); + dev_err(dev, "Failed to request gain GPIO: %d\n", ret); + return ret; + } + + st->filter_gpio = devm_gpiod_get_optional(dev, + "adi,filter", + GPIOD_OUT_HIGH); + if (IS_ERR(st->filter_gpio)) { + ret = PTR_ERR(st->filter_gpio); + dev_err(dev, "Failed to request filter GPIO: %d\n", ret); + return ret; + } + + return 0; +} + static int ad7780_probe(struct spi_device *spi) { struct ad7780_state *st; @@ -212,15 +296,9 @@ static int ad7780_probe(struct spi_device *spi) indio_dev->num_channels = 1; indio_dev->info = &ad7780_info; - st->powerdown_gpio = devm_gpiod_get_optional(&spi->dev, - "powerdown", - GPIOD_OUT_LOW); - if (IS_ERR(st->powerdown_gpio)) { - ret = PTR_ERR(st->powerdown_gpio); - dev_err(&spi->dev, "Failed to request powerdown GPIO: %d\n", - ret); - goto error_disable_reg; - } + ret = ad7780_init_gpios(&spi->dev, st); + if (ret) + goto error_cleanup_buffer_and_trigger; ret = ad_sd_setup_buffer_and_trigger(indio_dev); if (ret) From patchwork Sat Mar 16 02:12:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F23B915AC for ; Sat, 16 Mar 2019 02:12:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D671A2AC71 for ; Sat, 16 Mar 2019 02:12:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C85142AC88; Sat, 16 Mar 2019 02:12:59 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 820962AC71 for ; Sat, 16 Mar 2019 02:12:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726664AbfCPCM7 (ORCPT ); Fri, 15 Mar 2019 22:12:59 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:41735 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726444AbfCPCM6 (ORCPT ); Fri, 15 Mar 2019 22:12:58 -0400 Received: by mail-yw1-f67.google.com with SMTP id q128so8779051ywg.8; Fri, 15 Mar 2019 19:12:58 -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=dEu8li9eItBxKNy+6G3jWEsYP5zwyb5Jqapt02O8WUQ=; b=Pg5kgU/sEUk1NP+/ox6wOZmmCOy4b+dzMtveZE7jZJKiKu9DL7TOhd1DPQVV5kLHs3 J3A9bvy2xJPFWkHuJ8C4M0Ob82rhkH2J5cObp8H0sCSQedtRAFvwfjbJExzdFGRZH/X1 zsRL88JngKkTDjtBB4eCRjfWSmIrWU7cf8X7GpBFyK0i/YgrkEYLbsYqA9nOZQZfTTwQ 97dcuPvcWgZf8X+XRhwsPeq7Tg3NXlsKTmnJLWBtsZrvQrNVuJXz/UOSo/z+3I/R3xoB Nwowm8h8TUrNVNH8xsf0VfmAaatYZGck5ZVKu7Wh7AvHVdicx3jD7QlcTW9jzpfshgyW XdrQ== 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=dEu8li9eItBxKNy+6G3jWEsYP5zwyb5Jqapt02O8WUQ=; b=R/gtlaiOweG5NXjlUTYMOhPg6Nchs66BmJjLfT9nfd13qYypJZp1Wxqf7gxmhQgYT7 EqG9bygdNz3+Qhzna6fn/eFpfdLI6TjYaUYc80Li6Lx49biaCjDEkx/hiJhGrvh9psId u+Xn814YyPkMI3p6XMhMPNUpeb9j7LZVSHXPXJPxEHKBsa1881q8UnxHHAyYSTfA2lqE szjE0i4Ni89elOAmYgUB3+pMu9kpdaCrsnmSr7uhAkhD69hXHkBVRP7YUmYhSePHZu3w mgvA6u2CHCRCWeYYIEtdlvC3yxvdBJXiFw6vZfnbOMFz29prP0+jaFARj6I7iq3zK5iF EQZw== X-Gm-Message-State: APjAAAURSEdeyxHnUH9zdaMlKub1xsAJtVgncbus8Bd+GH9V500ulZl6 dhbbmpOQzbQqxaB6RYlLans= X-Google-Smtp-Source: APXvYqyDHN2a44MmPWfBs/tl37SUreiHypp6YEggfmZkcsVYgH4VyQLAJII9E3D63HBMsXm6k8gdnw== X-Received: by 2002:a25:b28e:: with SMTP id k14mr5842910ybj.501.1552702377848; Fri, 15 Mar 2019 19:12:57 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id t205sm934119ywa.34.2019.03.15.19.12.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:12:57 -0700 (PDT) Date: Fri, 15 Mar 2019 23:12:53 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 02/11] staging: iio: ad7780: add missing switch default case Message-ID: <84375be9b21a30dde736e47a7e2f72c1aedf7e92.1552700652.git.renatogeh@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 This patch simply adds a missing switch default case in read_raw. Signed-off-by: Renato Lui Geh --- drivers/staging/iio/adc/ad7780.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 07e5e35c92a3..f4cd7bc3e02f 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -118,6 +118,8 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_OFFSET: *val = -(1 << (chan->scan_type.realbits - 1)); return IIO_VAL_INT; + default: + break; } return -EINVAL; From patchwork Sat Mar 16 02:13:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ADD8015AC for ; Sat, 16 Mar 2019 02:13:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 966FF2AC71 for ; Sat, 16 Mar 2019 02:13:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 886882AC88; Sat, 16 Mar 2019 02:13:21 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 3B2752AC71 for ; Sat, 16 Mar 2019 02:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbfCPCNU (ORCPT ); Fri, 15 Mar 2019 22:13:20 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:41820 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726444AbfCPCNU (ORCPT ); Fri, 15 Mar 2019 22:13:20 -0400 Received: by mail-qt1-f193.google.com with SMTP id w30so6969033qta.8; Fri, 15 Mar 2019 19:13:19 -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=EW53I3tp34rqtQ/MxyH8jsvT9bUM1N0O3iRAvZzkV/I=; b=Z31pZ43v3zmFMa+52uuvPtWcEq5rQS55LJv3qM8rd3Pnm24SU5/dHfU/n4QegNmJCV R5j/FKnQo8Z5g7iyV6a7ziYPdKODmyrgKzxG+I9jVeYqSJAt6f7TD4U3mJq/2DjGJxtk bd0qBTnZVB9+DhE8byT2Qb+cFboXZF1i54EzLnVB61qq8rUrL9c7sih8AN1FJGHKYnpZ LQEXPOKXMzo5lft5CjYRLr1eRHd+HArLD/BgBKijHVkwfVvIOGQkonW5maBI8AkID4Sn Vcyk7n03MiCJ+BrbMBlxP5QYfyWqeY+GD+5J8LdkvduiM1FYlkS78K+uRW6AgIdP23cZ ciyw== 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=EW53I3tp34rqtQ/MxyH8jsvT9bUM1N0O3iRAvZzkV/I=; b=c4TMo/SHcgiB5wWFQru5/VF+ahxhKkxBA5eB+wCzV6slU2nx4qe8gZmrxZVXMwrmIF NTXYKx4pt76MCvwivxNh5EdsKkYmfRPK7n5mqQSL9Xu+AtwORsdJTMgtCXxfVca/NmwZ rvBrNizEugktc0bDT2PEGozAMfViWnhJFJqEnl/E3/PDgJaraK9o/C0jV7UKyhYTn+HX SQ5/5S8tiaRbYpyacyqVl455aBDkm0oZB7275kJkL+bJWgG7eqlUuPs5Bs2bgXGfI1IA q6SZaqOTpWn9yisHWXK5YgAJWtldWqEF2A+rOShfZdWFO7MqzZKNgYi9WC+PPcefU87y avYA== X-Gm-Message-State: APjAAAX5KEGtRnfWpWwx2kQWsUfv+lNsbGo/nFcJPxnYGx5D+ftLE+tP vYzd7q1Hs7cvKP6ekue0xK4= X-Google-Smtp-Source: APXvYqzC3y/u8oW7CZ5EAA75ZsRiDj9ppDu78YognyI5EIZQkNWrlxnP+dp00F4TD7prq+S3r4ip0Q== X-Received: by 2002:ac8:1bc6:: with SMTP id m6mr5104987qtk.8.1552702399222; Fri, 15 Mar 2019 19:13:19 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id d8sm1774846qtp.50.2019.03.15.19.13.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:13:19 -0700 (PDT) Date: Fri, 15 Mar 2019 23:13:13 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 03/11] staging: iio: ad7780: add gain reading to ad778x Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 This patch adds a new functionality of reading gain values from the ad778x chips. This value is stored in the chip's state struct and is updated whenever a read or write call is performed on the driver. Signed-off-by: Renato Lui Geh --- drivers/staging/iio/adc/ad7780.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index f4cd7bc3e02f..fbcc0d3345ca 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -42,6 +42,8 @@ #define AD7780_GAIN_MIDPOINT 64 #define AD7780_FILTER_MIDPOINT 13350 +static const unsigned int ad778x_gain[2] = { 1, 128 }; + struct ad7780_chip_info { struct iio_chan_spec channel; unsigned int pattern_mask; @@ -179,6 +181,9 @@ static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta, ((raw_sample & chip_info->pattern_mask) != chip_info->pattern)) return -EIO; + if (chip_info->is_ad778x) + st->gain = ad778x_gain[raw_sample & AD7780_GAIN]; + return 0; } From patchwork Sat Mar 16 02:13:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A3EA414DE for ; Sat, 16 Mar 2019 02:13:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AF172AC71 for ; Sat, 16 Mar 2019 02:13:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D8F42AC88; Sat, 16 Mar 2019 02:13:49 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 110BD2AC71 for ; Sat, 16 Mar 2019 02:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726808AbfCPCNs (ORCPT ); Fri, 15 Mar 2019 22:13:48 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:36310 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726444AbfCPCNs (ORCPT ); Fri, 15 Mar 2019 22:13:48 -0400 Received: by mail-yw1-f67.google.com with SMTP id 189so8791551ywi.3; Fri, 15 Mar 2019 19:13:47 -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=KLZPRW9sZ24hszIQNiooOpJkNmFR+cHuvBsoqhX5Hio=; b=mrQH3ss3o0+iovsUjQ/eaTz6a679tfYwhAXvM5FylQIcH7HFEGEKjPzZoGy7cVhE2k /PONIvjSK2rZA5e68R2u0ZDDLSKqyPjlttyxLZ7U5ZNzGToeEWIGd2EYcynvT5btj6T6 mby9QqCLmIVnk5/wuACXWu/BJ5p1K+7SHAkIfRCTyBTgGeDaEsKqvxc+xxbg4e0XxS3c TNemPBFhFeXV93dlQVAuXsu+np8couaSVlCiycsp9P55PVQ3d6yBrfuH3EH5bLLxsWn7 ZTb0Mj9qlRtNyUvnADJcOoqyzOVV7X86E3OeJ+9MBhnC5hlIUP1vcE+6zV93aAfTMOt7 Ty7Q== 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=KLZPRW9sZ24hszIQNiooOpJkNmFR+cHuvBsoqhX5Hio=; b=K0asUc3sgiI4hDrFORim5f1GUanHRUC8rNs4tkBT2ZJvYSOhTjRJytpgfSBCcXzV8u x7h6+QHjbuMFqIO5bTveOiwIXbQ8M1hLo8qtkrWcX5Zadl204uIBppbjl+KmGm6wrblZ iojNJJBZfNCSCWKYouIxpuQZcWrDllkK8E1Mtevf4bS9/O9UUy1+VuPG8hcS8qdvhyrY mKMVw/H/1yVooSPUioD04l6761Qgbn0N3skh0QrPKOuUWX+XJjS9gBnn6VuCxRSWCFz+ ARaN631QGpd659zjXmLOPypqglxxp6V436uSjLgH8MtZeJz968eVlVHGcSR6tW8vaguY z7Zg== X-Gm-Message-State: APjAAAX4EKSydXsDPCVIe04r28+GnZERzOZGHEqktC9kXgOzru0atSxy LLrEpPZHXtkxeS5yHDLzfIc= X-Google-Smtp-Source: APXvYqxZcpDG9/0VlXAGmLgJUP9mAsAcVwD36uM7Utp6D4f1Tuf0Ck9oFdfN5rUA83MLt5aYVcQyug== X-Received: by 2002:a81:34a:: with SMTP id 71mr5493588ywd.303.1552702427064; Fri, 15 Mar 2019 19:13:47 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id v198sm1291657ywv.24.2019.03.15.19.13.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:13:46 -0700 (PDT) Date: Fri, 15 Mar 2019 23:13:42 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 04/11] staging: iio: ad7780: add filter reading to ad778x Message-ID: <66a914ed7d1512f5aedfc5a0c6cbae38f5588e35.1552700652.git.renatogeh@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 This patch adds the new feature of reading the filter odr value for ad778x chips. This value is stored in the chip's state struct whenever a read or write call is performed on the chip's driver. This feature requires sharing SAMP_FREQ. Since the ad717x does not have a filter option, the driver only shares the relevant info mask for the ad778x family. Signed-off-by: Renato Lui Geh --- Changes in v4: - As mentioned in the previous patch, this was originally as part of the 'add gain & filter gpio support' patch Changes in v5: - Moved ad778x_odr_avail declaration from GPIO patch to this one drivers/staging/iio/adc/ad7780.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index fbcc0d3345ca..8ff74427d975 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -42,7 +42,8 @@ #define AD7780_GAIN_MIDPOINT 64 #define AD7780_FILTER_MIDPOINT 13350 -static const unsigned int ad778x_gain[2] = { 1, 128 }; +static const unsigned int ad778x_gain[2] = { 1, 128 }; +static const unsigned int ad778x_odr_avail[2] = { 10000, 16700 }; struct ad7780_chip_info { struct iio_chan_spec channel; @@ -58,6 +59,7 @@ struct ad7780_state { struct gpio_desc *gain_gpio; struct gpio_desc *filter_gpio; unsigned int gain; + unsigned int odr; unsigned int int_vref_mv; struct ad_sigma_delta sd; @@ -120,6 +122,9 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_OFFSET: *val = -(1 << (chan->scan_type.realbits - 1)); return IIO_VAL_INT; + case IIO_CHAN_INFO_SAMP_FREQ: + *val = st->odr; + return IIO_VAL_INT; default: break; } @@ -162,6 +167,7 @@ static int ad7780_write_raw(struct iio_dev *indio_dev, val = 0; else val = 1; + st->odr = ad778x_odr_avail[val]; gpiod_set_value(st->filter_gpio, val); break; default: @@ -181,8 +187,10 @@ static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta, ((raw_sample & chip_info->pattern_mask) != chip_info->pattern)) return -EIO; - if (chip_info->is_ad778x) + if (chip_info->is_ad778x) { st->gain = ad778x_gain[raw_sample & AD7780_GAIN]; + st->odr = ad778x_odr_avail[raw_sample & AD7780_FILTER]; + } return 0; } @@ -194,17 +202,19 @@ static const struct ad_sigma_delta_info ad7780_sigma_delta_info = { }; #define AD7780_CHANNEL(bits, wordsize) \ + AD_SD_CHANNEL(1, 0, 0, bits, 32, wordsize - bits) +#define AD7170_CHANNEL(bits, wordsize) \ AD_SD_CHANNEL_NO_SAMP_FREQ(1, 0, 0, bits, 32, wordsize - bits) static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { [ID_AD7170] = { - .channel = AD7780_CHANNEL(12, 24), + .channel = AD7170_CHANNEL(12, 24), .pattern = AD7170_PATTERN, .pattern_mask = AD7170_PATTERN_MASK, .is_ad778x = false, }, [ID_AD7171] = { - .channel = AD7780_CHANNEL(16, 24), + .channel = AD7170_CHANNEL(16, 24), .pattern = AD7170_PATTERN, .pattern_mask = AD7170_PATTERN_MASK, .is_ad778x = false, From patchwork Sat Mar 16 02:14:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B742514DE for ; Sat, 16 Mar 2019 02:14:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E72828B5D for ; Sat, 16 Mar 2019 02:14:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9203428C6B; Sat, 16 Mar 2019 02:14:21 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 375BF28C37 for ; Sat, 16 Mar 2019 02:14:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726773AbfCPCOU (ORCPT ); Fri, 15 Mar 2019 22:14:20 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:35805 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726549AbfCPCOU (ORCPT ); Fri, 15 Mar 2019 22:14:20 -0400 Received: by mail-yw1-f65.google.com with SMTP id s204so8798753ywg.2; Fri, 15 Mar 2019 19:14:19 -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=K7rpJweAAGHYDLxUgHuYBBCV1Z5B+8lu4Xx1IvGDggs=; b=KGlXCbvPZi+107ZGogED0LEqNuaW+UAg2H5EZke83UAJ8TNJUEFOnwKKHmBZIkg39k QTsshGnSSWe7z9sEBT0NmCmwSP9JdKQDf/Q4/Lwavuy95l9WeIoy87oKxIbwDyUCFdhc 2X3eXLgRj0UCoJpUUrnOMLZnWFQljg3G4mcT8rusgSfb05wYgSHeyhBSiqRiki+97389 G7fFxjnbV9temwIV1HLkCIvyv4tkG04ZYYYj1ABGBfPetLAvRoZ0qKP2xMypXEIkh3Kg /ZRlqZ+pSaosSQlfc0G+750b/TQA2DxywpoZYH745pFvdoZWofYtbqTml9/kSEE4DW2v db5A== 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=K7rpJweAAGHYDLxUgHuYBBCV1Z5B+8lu4Xx1IvGDggs=; b=en/wLu/6zjiO8WhKjL18M5x4oGEscvwWzusfDaSA5CLo7bVxgVUt5Y/jwLRbJv4Xi7 dYHoS425uzGFMMmb/Mag0hOfPea7swYsjLvmUVJm6GYYWhEvCIjXdZVTHdOHG8OMBhP7 NJges59QIxu0tN9WWIQMV4hqhA9yB1wBeXuCO/kB85Uz4pW4FFsSaqdjJBTJ03ZxWXP1 Nhm3RJwo3P44GZBi3ZtD2QkmIua3rHBQXidB47CpviF6CXHTLmUzpifyymiJh1R6jTTS Pu7NE/uH5riWqd99SOyZshOAiyVIxjfZubz73jxuqwGzXNL0CnSX/cbDzmi+ROcBTP1T BTkQ== X-Gm-Message-State: APjAAAUZRzebLFC1q/Z/l8Kotun/EoafHn4a6rbuaO87wh8xoJThPHnK Nt6ZRl/OXYEXdZV4d586ChQ= X-Google-Smtp-Source: APXvYqyxkJTKkuAzUuKSAJY0rRqbSq1G/Xg+v3bSSLxqB5kHX9E9ea92Ki/rh6YQ/O+Hw8ibKSwwyA== X-Received: by 2002:a0d:fe84:: with SMTP id o126mr5296386ywf.203.1552702459260; Fri, 15 Mar 2019 19:14:19 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id l143sm1307100ywc.50.2019.03.15.19.14.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:14:18 -0700 (PDT) Date: Fri, 15 Mar 2019 23:14:14 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 05/11] staging: iio: ad7780: set pattern values and masks directly Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 AD7780 driver contains status pattern bits designed for checking whether serial transfers have been correctly performed. Pattern macros were previously generated through bit fields. This patch sets good pattern values directly and masks through GENMASK. Signed-off-by: Renato Lui Geh --- drivers/staging/iio/adc/ad7780.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 8ff74427d975..94cb60c327d0 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -28,16 +29,13 @@ #define AD7780_ID1 BIT(4) #define AD7780_ID0 BIT(3) #define AD7780_GAIN BIT(2) -#define AD7780_PAT1 BIT(1) -#define AD7780_PAT0 BIT(0) -#define AD7780_PATTERN (AD7780_PAT0) -#define AD7780_PATTERN_MASK (AD7780_PAT0 | AD7780_PAT1) -#define AD7170_PAT2 BIT(2) +#define AD7780_PATTERN_GOOD 1 +#define AD7780_PATTERN_MASK GENMASK(1, 0) -#define AD7170_PATTERN (AD7780_PAT0 | AD7170_PAT2) -#define AD7170_PATTERN_MASK (AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2) +#define AD7170_PATTERN_GOOD 5 +#define AD7170_PATTERN_MASK GENMASK(2, 0) #define AD7780_GAIN_MIDPOINT 64 #define AD7780_FILTER_MIDPOINT 13350 @@ -209,25 +207,25 @@ static const struct ad_sigma_delta_info ad7780_sigma_delta_info = { static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { [ID_AD7170] = { .channel = AD7170_CHANNEL(12, 24), - .pattern = AD7170_PATTERN, + .pattern = AD7170_PATTERN_GOOD, .pattern_mask = AD7170_PATTERN_MASK, .is_ad778x = false, }, [ID_AD7171] = { .channel = AD7170_CHANNEL(16, 24), - .pattern = AD7170_PATTERN, + .pattern = AD7170_PATTERN_GOOD, .pattern_mask = AD7170_PATTERN_MASK, .is_ad778x = false, }, [ID_AD7780] = { .channel = AD7780_CHANNEL(24, 32), - .pattern = AD7780_PATTERN, + .pattern = AD7780_PATTERN_GOOD, .pattern_mask = AD7780_PATTERN_MASK, .is_ad778x = true, }, [ID_AD7781] = { .channel = AD7780_CHANNEL(20, 32), - .pattern = AD7780_PATTERN, + .pattern = AD7780_PATTERN_GOOD, .pattern_mask = AD7780_PATTERN_MASK, .is_ad778x = true, }, From patchwork Sat Mar 16 02:14:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68F8215AC for ; Sat, 16 Mar 2019 02:14:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 511092A788 for ; Sat, 16 Mar 2019 02:14:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44D2E299BB; Sat, 16 Mar 2019 02:14:35 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 DCD86299BB for ; Sat, 16 Mar 2019 02:14:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726803AbfCPCOe (ORCPT ); Fri, 15 Mar 2019 22:14:34 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:43876 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726549AbfCPCOe (ORCPT ); Fri, 15 Mar 2019 22:14:34 -0400 Received: by mail-qt1-f196.google.com with SMTP id v32so12267582qtc.10; Fri, 15 Mar 2019 19:14:33 -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=UyV0RQ6Ay3hRInLPzMBULAGnAUWrot2JtsvIp1TAUNg=; b=A+yeRwMu/MaA68qjpPiqy+MMCUUPoiIt9YS8Ha5CBEbfs4Gpl88XIC3WtdCaS1Pht4 6NAi+YwULeePYD846LZ7LGSzD0MCTWjFUA13ggtEwiEYae6huVb/mBQTMzba+ImYy7OO jjzfIIImriQbhIt4rOOrFWDBHlhyVyPmaftMXYBIta0NdJHrc5schiEE51DCDPpoVmmT J0OwPxta9rRnR2CELrlIfKbYXe2unrjZ/Pkp7k76xE7kCZMmHRBNaDa9z072dE2Kne7H YM7oLtBZP7Le4f7ReT/7Jo3OhR2YoB/gcgP4QWXOci6/6CUC0ExA9gobn6s7JuObE7Ze Uu2w== 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=UyV0RQ6Ay3hRInLPzMBULAGnAUWrot2JtsvIp1TAUNg=; b=JcotAjWbdyu/w906BzUGNRby1fePPDv5MJU2D+5FkFlnyYwH99PyZto0xuzC/vkJdu wfUKrA+8ewrstkXdlUGxzD9lP0ss116RcihPGVud2ZKG9fG3iWdDmWaxGy/cx8eUJP5m HnkZaViYvl6tn8M/IR9zIltN72TnU6+4Krmo5D471VjQpTbnxUI20EXdsJrCaLljuAMz uhfHGDWxdrV5JMrqsx7wWanTlBtY7nblMecRrtAXltCP0LZn6T9RpM7UDEKy3TKx3yuJ /tPPzmscx1myXTu8jmud4+aWeWkrn1ROxJ3YQ1bN60Gb4ajdU/t3mVIW+ihipaXH7fqy o39A== X-Gm-Message-State: APjAAAWkVrJeDZmxgJsCC5QOes/0wWqkfUZGNksY2ON6bGPzSaSL26QW 3mNogpggb/NyCaj6buB4IBU= X-Google-Smtp-Source: APXvYqzZmdW4ebM1mZpK4ieK/sE/Vh5ok8DEgcL1GQisBAGDs1APtkDahJeVOLTU8jkdCK6PHMCkdg== X-Received: by 2002:aed:2507:: with SMTP id v7mr5406022qtc.131.1552702473093; Fri, 15 Mar 2019 19:14:33 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id d4sm1240583qth.45.2019.03.15.19.14.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:14:32 -0700 (PDT) Date: Fri, 15 Mar 2019 23:14:27 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 06/11] staging:iio:ad7780: add chip ID values and mask Message-ID: <8154410f6c1b6cdde21cfb781dbc2088f5c91d21.1552700652.git.renatogeh@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 ad7780 supports both the ad778x and ad717x families. Each chip has a corresponding ID. This patch provides a mask for extracting ID values from the status bits and also macros for the correct values for the ad7170, ad7171, ad7780 and ad7781. Signed-off-by: Renato Lui Geh --- Changes in v5: - Put AD7780_ID{0,1} back drivers/staging/iio/adc/ad7780.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 94cb60c327d0..977b381c1260 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -30,6 +30,12 @@ #define AD7780_ID0 BIT(3) #define AD7780_GAIN BIT(2) +#define AD7170_ID 0 +#define AD7171_ID 1 +#define AD7780_ID 1 +#define AD7781_ID 0 + +#define AD7780_ID_MASK (AD7780_ID0 | AD7780_ID1) #define AD7780_PATTERN_GOOD 1 #define AD7780_PATTERN_MASK GENMASK(1, 0) From patchwork Sat Mar 16 02:14:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E25E15AC for ; Sat, 16 Mar 2019 02:15:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17336299BB for ; Sat, 16 Mar 2019 02:15:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B8912ABB6; Sat, 16 Mar 2019 02:15:12 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 AD1CE299BB for ; Sat, 16 Mar 2019 02:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726571AbfCPCPG (ORCPT ); Fri, 15 Mar 2019 22:15:06 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:35978 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfCPCPF (ORCPT ); Fri, 15 Mar 2019 22:15:05 -0400 Received: by mail-qk1-f196.google.com with SMTP id k130so6705074qke.3; Fri, 15 Mar 2019 19:15:05 -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=E79KXUnhP4o02hGiR6DT9/4NVN8LNyEneSndXO0JIsw=; b=h0D+aQ2Ju6xSelONwMt6gNSu83Ys9FhLReo4hICCKjL+UQ9ydsWlbygDpNdGSOfC0U VKAt9sU/H9olMbyHo3NGXjr0c5oEOOdLLO8NFhh4x3Gftc58BSZWZg5WXUe7uJPL+Xbm rx03bL92k1Csc96suTMEWzMt/CXiz9Cxyycp2oXOstvHXKM9NmtK+KF5v9EVHPPRLZLa e/oNHZkhygqNsP4Pn86IvzLvsI19tc/+gyeVrW1ZevdRwr3cxJiAa2sx4QGS3dltMKCF dFp0NsERGarU7YQJgR5S7GryVrkC0EzUqUSSB5AnqV29taGlpcvrDOikNgaYiKNx2BOv XMUg== 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=E79KXUnhP4o02hGiR6DT9/4NVN8LNyEneSndXO0JIsw=; b=UOS9JXCpywBk3jzo4cXBghTs5z9H8bPi6IRZ5iuYz6/nk3LUXrxp+ukp82UMA7erwQ Vdt1Y1jEFTpKIC6CKTNWXdwbaN8TeCcWZFZmtUOCFgqWHm1lv8cEoxU5v/b8fykt656F /WINF7wtLAhniRu2RBfTlThFrZ5mlerclmkgSE3f8Ts3uMBsHUIhupE+bPNMm+VHKIIR pOLOxbTVqhvO+qpynRgMirmIpYeb0KKB4etScvZYDP0DSnL0qOJ4Ij6DUgTmpa+WpQrb Mu0xGCAnv1PN2R4qHBYLdM2bShDBWhMvyxyMeelyL7bOLrQfr+dZ1rR7+nodnLYy81Ox oZiw== X-Gm-Message-State: APjAAAUWaP3PkyQkv6921iy8VNq0XmOdO/sGJs4RgSdYKwPD4xtYREWI NCM8fH7heqUEVSRCvvQdzJI= X-Google-Smtp-Source: APXvYqxP6ldzgL1QfU4MzvsvoDUfkPWls0uA7OzJnTDyjpcEKIlMLkYnA8jYowvHpih9+KfFCc2cyQ== X-Received: by 2002:a37:d6ce:: with SMTP id p75mr5100559qkl.286.1552702504574; Fri, 15 Mar 2019 19:15:04 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id v131sm2132489qka.95.2019.03.15.19.15.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:15:04 -0700 (PDT) Date: Fri, 15 Mar 2019 23:14:59 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 07/11] staging: iio: ad7780: move regulator to after GPIO init Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 To maintain consistency between ad7780_probe and ad7780_remove orders, regulator initialization has been moved to after GPIO initializations. Signed-off-by: Renato Lui Geh --- drivers/staging/iio/adc/ad7780.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 977b381c1260..568c5b4472ff 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -295,16 +295,6 @@ static int ad7780_probe(struct spi_device *spi) ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info); - st->reg = devm_regulator_get(&spi->dev, "avdd"); - if (IS_ERR(st->reg)) - return PTR_ERR(st->reg); - - ret = regulator_enable(st->reg); - if (ret) { - dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); - return ret; - } - st->chip_info = &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data]; @@ -321,6 +311,16 @@ static int ad7780_probe(struct spi_device *spi) if (ret) goto error_cleanup_buffer_and_trigger; + st->reg = devm_regulator_get(&spi->dev, "avdd"); + if (IS_ERR(st->reg)) + return PTR_ERR(st->reg); + + ret = regulator_enable(st->reg); + if (ret) { + dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); + return ret; + } + ret = ad_sd_setup_buffer_and_trigger(indio_dev); if (ret) goto error_disable_reg; From patchwork Sat Mar 16 02:15:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C086415AC for ; Sat, 16 Mar 2019 02:15:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8F91299BB for ; Sat, 16 Mar 2019 02:15:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D15E2ABB6; Sat, 16 Mar 2019 02:15:19 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 5617C299BB for ; Sat, 16 Mar 2019 02:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726733AbfCPCPS (ORCPT ); Fri, 15 Mar 2019 22:15:18 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:37612 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfCPCPS (ORCPT ); Fri, 15 Mar 2019 22:15:18 -0400 Received: by mail-yw1-f67.google.com with SMTP id w66so8793620ywd.4; Fri, 15 Mar 2019 19:15:18 -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=YABxWF8N5gKqZyrr+QQvSqXEL3zrKIE1jEQuPoWCy1Q=; b=cet6jNR+ipeGlcnATcbW0MeDv4xaNeXSalsdWVj9sf2YnfbkEFLZdRY+rNss7G+pt0 Mz91Xeb6+yQor28767Ghc5jM02rkxsEGQmH2oBh+1ws/0xSkvzp+NhJgzfWMCpxasfXR JKDayQHrNrv4BNeRlL7c7ZrGMb2ZJdX02v9jTjswXK5Epa1nBSm+zgjoSH16GNEhm8Iq K+TAoXJSEAViWHBdAXaR7RP5+q264tVVS3/3ftzjXmkAh/zZZR/JfqRgEiae3u4PJORb 3MsObXw+E1v1HUfsUuM/8oYJ5cc9PRbegD2O2aLY6/U6p0RaeiTXaYOMMQwfcLigWp4L iazg== 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=YABxWF8N5gKqZyrr+QQvSqXEL3zrKIE1jEQuPoWCy1Q=; b=Ve32Migz+N/v/MUFU/i8czYjdq5gHh7RO0caW5hyCbfhvE00t2eWC8+7PZbVQN9Rk9 yjDFMUyYjI6v20ZgbJ9V59hro2Jr8qtEU/q+IyM87uu0K9YVvPWtcExSuJmBIbAqCXa8 qJwQMDIOjewt9vh6Wwn5ZynMxrCNh26B+sfLJxGda6Mt9hQV/YxGtiF2mY1roMAj7VsN rRjfwwLhXj5PNJn+XeZI+iceyBUL6omssdyoLE0k2/eBxb99MScHShyMDbn2dOVXZAyE 5lu0D5fGiOlyarkrIYjgJiWD8GdyjtpB1H0zr/hmYg4kmk7o8ufgFC/zSe/NlK40COKY TQmg== X-Gm-Message-State: APjAAAV/YTpuMLDkl7yZzaeN4tO/3AJpbqpeabWYo9tv6SZqLk0lA5q1 dsfrvs2TqLc+tyZailF54p8= X-Google-Smtp-Source: APXvYqz7yVcv04KxXw6i/E21J7YxLbo6ulOycTUIK6nr82TVf26O7FeInGiLG9lmXMlVS726PvB0yA== X-Received: by 2002:a81:47c1:: with SMTP id u184mr5582507ywa.406.1552702517766; Fri, 15 Mar 2019 19:15:17 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id 136sm1323995ywl.109.2019.03.15.19.15.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:15:17 -0700 (PDT) Date: Fri, 15 Mar 2019 23:15:13 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 08/11] staging: iio: ad7780: add SPDX identifier Message-ID: <4344b002e730538b737e576b7d262687ab62473c.1552700652.git.renatogeh@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 Add SPDX identifier (GPL-2.0) to the AD7780 driver. Signed-off-by: Renato Lui Geh --- drivers/staging/iio/adc/ad7780.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 568c5b4472ff..ff61ffa0da9f 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -1,9 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver * * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. */ #include From patchwork Sat Mar 16 02:15:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF8C31515 for ; Sat, 16 Mar 2019 02:15:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D74292ABB6 for ; Sat, 16 Mar 2019 02:15:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA2792AC71; Sat, 16 Mar 2019 02:15:38 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 789CA2ABB6 for ; Sat, 16 Mar 2019 02:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbfCPCPd (ORCPT ); Fri, 15 Mar 2019 22:15:33 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:40827 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfCPCPd (ORCPT ); Fri, 15 Mar 2019 22:15:33 -0400 Received: by mail-qt1-f194.google.com with SMTP id f11so12265441qti.7; Fri, 15 Mar 2019 19:15:32 -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=Eh+Z/o9WjtJXIcms4JIRAPXm9p+hCYRVJC9mwEl1kVc=; b=WJSk46+S5D4zyDQ5RTYjae2QI0kYg1/uuuZFVXkOzunF9IF5201ZyPcGSgtIdk7KO8 fql3T7kvasotBuhALC/Bv9fLx4aob9VgUuzXI0S7zd+4GYcvQgT+S05HiH7K/5vHT4Eb LMJcUlO2y4i6DoUbs53+uojDn88u2Vbz2pZtbhb2IuMruqZayP/GLTHcbIp76WIlGOfS xJjjhxs86gRau7H4xd3KHdItQfKFKdCXSC2/juRjQ8Z23kPDQ4jAPS4o3fktJhUsjgDY xK9+S51hB8kePuZM39NHnDntNV9Skrc6rCtDWrbej9WPFhSIgX9iiGoGLHlW1tYb+DJ0 3ohg== 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=Eh+Z/o9WjtJXIcms4JIRAPXm9p+hCYRVJC9mwEl1kVc=; b=qmG6uYesRdB+8KIaPf3jdjb5c4tbd4SegOqAoDkczYAby8mkfYF+x2zSRCPpJo1eZs C6K+njYMIKMAe0Xh9f1X5t/9d2xbxraWHNsrecC5jviwBXiVpPBmNyJrjW7A4QauR1bx z8iFoyVQRCS7Eozf3+y6yvt90OBIaTxwEmulZmOB2sfCi+i6xTnoU/hHhs9YljmS0H8s SfLiqLXZlRPZtZHmEc6AAEFAIji3zyeQGieSiI8b4gOAdBeEOpJH8YiKz02BSRr3Zcm0 JQJ46SqVKinN1x4UsaLLO2VW4OYpLno6Mhp/yADh1uR0BVB6hLeHmFHHso86SPJUvkfo saxQ== X-Gm-Message-State: APjAAAXAbctm1jogYqTTujd60gplYsFf1PZW4dyZrUIRtVOQccf0woxH 5U9AlPGE8Ey77StZHI90yY4= X-Google-Smtp-Source: APXvYqwBsBlG9dItbWdejfNVxwT63Ih7nGAZs5uYnC6MyJttlG5SsgmETsoc29jAX39mCqZ5/23eSQ== X-Received: by 2002:a0c:f681:: with SMTP id p1mr4786101qvn.177.1552702531982; Fri, 15 Mar 2019 19:15:31 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id l22sm1699994qkk.83.2019.03.15.19.15.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:15:31 -0700 (PDT) Date: Fri, 15 Mar 2019 23:15:26 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 09/11] staging: iio: ad7780: add new copyright holder Message-ID: <7cfb577d4e07b00a820b35dc56c58809120f8f39.1552700652.git.renatogeh@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 This patch adds a new copyright holder to the ad7780 driver. Signed-off-by: Renato Lui Geh --- drivers/staging/iio/adc/ad7780.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index ff61ffa0da9f..23b731a92e32 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -3,6 +3,7 @@ * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver * * Copyright 2011 Analog Devices Inc. + * Copyright 2019 Renato Lui Geh */ #include From patchwork Sat Mar 16 02:15:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D6FCD15AC for ; Sat, 16 Mar 2019 02:16:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0D4C2ABB6 for ; Sat, 16 Mar 2019 02:16:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3BE02AC88; Sat, 16 Mar 2019 02:16:05 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 3D1172ABB6 for ; Sat, 16 Mar 2019 02:16:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726767AbfCPCQD (ORCPT ); Fri, 15 Mar 2019 22:16:03 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:40875 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfCPCQD (ORCPT ); Fri, 15 Mar 2019 22:16:03 -0400 Received: by mail-qt1-f196.google.com with SMTP id f11so12266150qti.7; Fri, 15 Mar 2019 19:16:01 -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=dKCEsrSpumTi289jXlihCQLWqMFpZA5S6DOb5XT8GHE=; b=XISrygxY+bi91Q09Uq31I/I4cRCXBUFFX0YO/JrFM+7xgfqu5LKUDJZ1R7RwdLb6/W vSj41GttidBFd/2rO3e/QGT0FQge/l/rK0TeZVZZ90owyztAutSCFajqJlc9l6JNIQGM eLHSia0J9zmmBFvZpHQFzll4soEGW4J1UJZ9aTMFH5ybllMrZBNU+m5KZodOdiPsho5w paN34/0Bt8H3PlCvGDgdeuXATMumP3Yy/DrKZZx6PA4LMpHr2qWFQJJyNueYXSDyviZG WvjTeQqkLZMobzgthYtRPJw4yP58f6pZuBcipfLX6+/HPM2H2jNFERSgnLfS3ehTIMe2 Vwuw== 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=dKCEsrSpumTi289jXlihCQLWqMFpZA5S6DOb5XT8GHE=; b=ckDyBaU23kmspF3FHB2lGNoElenpnNjcc+VktRI5ofnnRbV7+2al/K3Oe+GW1bsDlI 09Ecgn7qPbthRwXF8Sqvovi04ILVebxBtM4LD/XYmIhdOr/eJDDaBw1A6ODAs8Oy9i29 +P8xNdDAc9Kw3jQeFLT5kkEfhDi8Uv4bDN1dECi11F7Si5CHDGTAyoFsI3kOjcLlxqFq WtB1XN7QYficxTEDIHuaSTgLMOmUKK2owJq1BRf5HEXRjic+BTRolp/DXDtJY65jsOQ9 gQU7U3CtFLYFe3kSnUm+8i99QxRXzTDTpzIvJUvw8ZD7LprlgitSi16P8rJ1vbkFxX/n xLzw== X-Gm-Message-State: APjAAAUW4BfasY7m3+45fwYMFzo4NPziBHMVFLl6fXbIoFvvOV+wuKF9 A1R7xfPuRGXbiwzdUTbrkNY= X-Google-Smtp-Source: APXvYqwpL2wiYePUZek3ClmSJXTjSde0gQYHSmpZq960Tf7hXuyoV8PQXJOmyL9LaeYgEJBMJZm12Q== X-Received: by 2002:a0c:ad90:: with SMTP id w16mr4966855qvc.53.1552702561127; Fri, 15 Mar 2019 19:16:01 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id y2sm2979363qty.63.2019.03.15.19.15.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:16:00 -0700 (PDT) Date: Fri, 15 Mar 2019 23:15:55 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 10/11] staging: iio: ad7780: moving ad7780 out of staging Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 Move ad7780 ADC driver out of staging and into the mainline. The ad7780 is a sigma-delta analog to digital converter. This driver provides reading voltage values and status bits from both the ad778x and ad717x series. Its interface also allows writing on the FILTER and GAIN GPIO pins on the ad778x. Signed-off-by: Renato Lui Geh Signed-off-by: Giuliano Belinassi Co-developed-by: Giuliano Belinassi --- Changes in v3: - Changes unrelated to moving the driver to main tree were resent as individual patches Changes in v4: - Removed line warning it was safe to build the ad7780 driver by default drivers/iio/adc/Kconfig | 12 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ad7780.c | 376 +++++++++++++++++++++++++++++++ drivers/staging/iio/adc/Kconfig | 13 -- drivers/staging/iio/adc/Makefile | 1 - drivers/staging/iio/adc/ad7780.c | 376 ------------------------------- 6 files changed, 389 insertions(+), 390 deletions(-) create mode 100644 drivers/iio/adc/ad7780.c delete mode 100644 drivers/staging/iio/adc/ad7780.c diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index f3cc7a31bce5..6b36a45bd09f 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -108,6 +108,18 @@ config AD7766 To compile this driver as a module, choose M here: the module will be called ad7766. +config AD7780 + tristate "Analog Devices AD7780 and similar ADCs driver" + depends on SPI + depends on GPIOLIB || COMPILE_TEST + select AD_SIGMA_DELTA + help + Say yes here to build support for Analog Devices AD7170, AD7171, + AD7780 and AD7781 SPI analog to digital converters (ADC). + + To compile this driver as a module, choose M here: the + module will be called ad7780. + config AD7791 tristate "Analog Devices AD7791 ADC driver" depends on SPI diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile index ea5031348052..b48852157115 100644 --- a/drivers/iio/adc/Makefile +++ b/drivers/iio/adc/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_AD7606_IFACE_PARALLEL) += ad7606_par.o obj-$(CONFIG_AD7606_IFACE_SPI) += ad7606_spi.o obj-$(CONFIG_AD7606) += ad7606.o obj-$(CONFIG_AD7766) += ad7766.o +obj-$(CONFIG_AD7780) += ad7780.o obj-$(CONFIG_AD7791) += ad7791.o obj-$(CONFIG_AD7793) += ad7793.o obj-$(CONFIG_AD7887) += ad7887.o diff --git a/drivers/iio/adc/ad7780.c b/drivers/iio/adc/ad7780.c new file mode 100644 index 000000000000..23b731a92e32 --- /dev/null +++ b/drivers/iio/adc/ad7780.c @@ -0,0 +1,376 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver + * + * Copyright 2011 Analog Devices Inc. + * Copyright 2019 Renato Lui Geh + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define AD7780_RDY BIT(7) +#define AD7780_FILTER BIT(6) +#define AD7780_ERR BIT(5) +#define AD7780_ID1 BIT(4) +#define AD7780_ID0 BIT(3) +#define AD7780_GAIN BIT(2) + +#define AD7170_ID 0 +#define AD7171_ID 1 +#define AD7780_ID 1 +#define AD7781_ID 0 + +#define AD7780_ID_MASK (AD7780_ID0 | AD7780_ID1) + +#define AD7780_PATTERN_GOOD 1 +#define AD7780_PATTERN_MASK GENMASK(1, 0) + +#define AD7170_PATTERN_GOOD 5 +#define AD7170_PATTERN_MASK GENMASK(2, 0) + +#define AD7780_GAIN_MIDPOINT 64 +#define AD7780_FILTER_MIDPOINT 13350 + +static const unsigned int ad778x_gain[2] = { 1, 128 }; +static const unsigned int ad778x_odr_avail[2] = { 10000, 16700 }; + +struct ad7780_chip_info { + struct iio_chan_spec channel; + unsigned int pattern_mask; + unsigned int pattern; + bool is_ad778x; +}; + +struct ad7780_state { + const struct ad7780_chip_info *chip_info; + struct regulator *reg; + struct gpio_desc *powerdown_gpio; + struct gpio_desc *gain_gpio; + struct gpio_desc *filter_gpio; + unsigned int gain; + unsigned int odr; + unsigned int int_vref_mv; + + struct ad_sigma_delta sd; +}; + +enum ad7780_supported_device_ids { + ID_AD7170, + ID_AD7171, + ID_AD7780, + ID_AD7781, +}; + +static struct ad7780_state *ad_sigma_delta_to_ad7780(struct ad_sigma_delta *sd) +{ + return container_of(sd, struct ad7780_state, sd); +} + +static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta, + enum ad_sigma_delta_mode mode) +{ + struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta); + unsigned int val; + + switch (mode) { + case AD_SD_MODE_SINGLE: + case AD_SD_MODE_CONTINUOUS: + val = 1; + break; + default: + val = 0; + break; + } + + gpiod_set_value(st->powerdown_gpio, val); + + return 0; +} + +static int ad7780_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long m) +{ + struct ad7780_state *st = iio_priv(indio_dev); + int voltage_uv; + + switch (m) { + case IIO_CHAN_INFO_RAW: + return ad_sigma_delta_single_conversion(indio_dev, chan, val); + case IIO_CHAN_INFO_SCALE: + voltage_uv = regulator_get_voltage(st->reg); + if (voltage_uv < 0) + return voltage_uv; + voltage_uv /= 1000; + *val = voltage_uv * st->gain; + *val2 = chan->scan_type.realbits - 1; + st->int_vref_mv = voltage_uv; + return IIO_VAL_FRACTIONAL_LOG2; + case IIO_CHAN_INFO_OFFSET: + *val = -(1 << (chan->scan_type.realbits - 1)); + return IIO_VAL_INT; + case IIO_CHAN_INFO_SAMP_FREQ: + *val = st->odr; + return IIO_VAL_INT; + default: + break; + } + + return -EINVAL; +} + +static int ad7780_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, + int val2, + long m) +{ + struct ad7780_state *st = iio_priv(indio_dev); + const struct ad7780_chip_info *chip_info = st->chip_info; + unsigned long long vref; + unsigned int full_scale, gain; + + if (!chip_info->is_ad778x) + return -EINVAL; + + switch (m) { + case IIO_CHAN_INFO_SCALE: + if (val != 0) + return -EINVAL; + + vref = st->int_vref_mv * 1000000LL; + full_scale = 1 << (chip_info->channel.scan_type.realbits - 1); + gain = DIV_ROUND_CLOSEST(vref, full_scale); + gain = DIV_ROUND_CLOSEST(gain, val2); + st->gain = gain; + if (gain < AD7780_GAIN_MIDPOINT) + gain = 0; + else + gain = 1; + gpiod_set_value(st->gain_gpio, gain); + break; + case IIO_CHAN_INFO_SAMP_FREQ: + if (1000*val + val2/1000 < AD7780_FILTER_MIDPOINT) + val = 0; + else + val = 1; + st->odr = ad778x_odr_avail[val]; + gpiod_set_value(st->filter_gpio, val); + break; + default: + break; + } + + return 0; +} + +static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta, + unsigned int raw_sample) +{ + struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta); + const struct ad7780_chip_info *chip_info = st->chip_info; + + if ((raw_sample & AD7780_ERR) || + ((raw_sample & chip_info->pattern_mask) != chip_info->pattern)) + return -EIO; + + if (chip_info->is_ad778x) { + st->gain = ad778x_gain[raw_sample & AD7780_GAIN]; + st->odr = ad778x_odr_avail[raw_sample & AD7780_FILTER]; + } + + return 0; +} + +static const struct ad_sigma_delta_info ad7780_sigma_delta_info = { + .set_mode = ad7780_set_mode, + .postprocess_sample = ad7780_postprocess_sample, + .has_registers = false, +}; + +#define AD7780_CHANNEL(bits, wordsize) \ + AD_SD_CHANNEL(1, 0, 0, bits, 32, wordsize - bits) +#define AD7170_CHANNEL(bits, wordsize) \ + AD_SD_CHANNEL_NO_SAMP_FREQ(1, 0, 0, bits, 32, wordsize - bits) + +static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { + [ID_AD7170] = { + .channel = AD7170_CHANNEL(12, 24), + .pattern = AD7170_PATTERN_GOOD, + .pattern_mask = AD7170_PATTERN_MASK, + .is_ad778x = false, + }, + [ID_AD7171] = { + .channel = AD7170_CHANNEL(16, 24), + .pattern = AD7170_PATTERN_GOOD, + .pattern_mask = AD7170_PATTERN_MASK, + .is_ad778x = false, + }, + [ID_AD7780] = { + .channel = AD7780_CHANNEL(24, 32), + .pattern = AD7780_PATTERN_GOOD, + .pattern_mask = AD7780_PATTERN_MASK, + .is_ad778x = true, + }, + [ID_AD7781] = { + .channel = AD7780_CHANNEL(20, 32), + .pattern = AD7780_PATTERN_GOOD, + .pattern_mask = AD7780_PATTERN_MASK, + .is_ad778x = true, + }, +}; + +static const struct iio_info ad7780_info = { + .read_raw = ad7780_read_raw, + .write_raw = ad7780_write_raw, +}; + +static int ad7780_init_gpios(struct device *dev, struct ad7780_state *st) +{ + int ret; + + st->powerdown_gpio = devm_gpiod_get_optional(dev, + "powerdown", + GPIOD_OUT_LOW); + if (IS_ERR(st->powerdown_gpio)) { + ret = PTR_ERR(st->powerdown_gpio); + dev_err(dev, "Failed to request powerdown GPIO: %d\n", ret); + return ret; + } + + if (!st->chip_info->is_ad778x) + return 0; + + + st->gain_gpio = devm_gpiod_get_optional(dev, + "adi,gain", + GPIOD_OUT_HIGH); + if (IS_ERR(st->gain_gpio)) { + ret = PTR_ERR(st->gain_gpio); + dev_err(dev, "Failed to request gain GPIO: %d\n", ret); + return ret; + } + + st->filter_gpio = devm_gpiod_get_optional(dev, + "adi,filter", + GPIOD_OUT_HIGH); + if (IS_ERR(st->filter_gpio)) { + ret = PTR_ERR(st->filter_gpio); + dev_err(dev, "Failed to request filter GPIO: %d\n", ret); + return ret; + } + + return 0; +} + +static int ad7780_probe(struct spi_device *spi) +{ + struct ad7780_state *st; + struct iio_dev *indio_dev; + int ret; + + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); + if (!indio_dev) + return -ENOMEM; + + st = iio_priv(indio_dev); + st->gain = 1; + + ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info); + + st->chip_info = + &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data]; + + spi_set_drvdata(spi, indio_dev); + + indio_dev->dev.parent = &spi->dev; + indio_dev->name = spi_get_device_id(spi)->name; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = &st->chip_info->channel; + indio_dev->num_channels = 1; + indio_dev->info = &ad7780_info; + + ret = ad7780_init_gpios(&spi->dev, st); + if (ret) + goto error_cleanup_buffer_and_trigger; + + st->reg = devm_regulator_get(&spi->dev, "avdd"); + if (IS_ERR(st->reg)) + return PTR_ERR(st->reg); + + ret = regulator_enable(st->reg); + if (ret) { + dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); + return ret; + } + + ret = ad_sd_setup_buffer_and_trigger(indio_dev); + if (ret) + goto error_disable_reg; + + ret = iio_device_register(indio_dev); + if (ret) + goto error_cleanup_buffer_and_trigger; + + return 0; + +error_cleanup_buffer_and_trigger: + ad_sd_cleanup_buffer_and_trigger(indio_dev); +error_disable_reg: + regulator_disable(st->reg); + + return ret; +} + +static int ad7780_remove(struct spi_device *spi) +{ + struct iio_dev *indio_dev = spi_get_drvdata(spi); + struct ad7780_state *st = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + ad_sd_cleanup_buffer_and_trigger(indio_dev); + + regulator_disable(st->reg); + + return 0; +} + +static const struct spi_device_id ad7780_id[] = { + {"ad7170", ID_AD7170}, + {"ad7171", ID_AD7171}, + {"ad7780", ID_AD7780}, + {"ad7781", ID_AD7781}, + {} +}; +MODULE_DEVICE_TABLE(spi, ad7780_id); + +static struct spi_driver ad7780_driver = { + .driver = { + .name = "ad7780", + }, + .probe = ad7780_probe, + .remove = ad7780_remove, + .id_table = ad7780_id, +}; +module_spi_driver(ad7780_driver); + +MODULE_AUTHOR("Michael Hennerich "); +MODULE_DESCRIPTION("Analog Devices AD7780 and similar ADCs"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig index 7a93d3a5c113..404a53c743a6 100644 --- a/drivers/staging/iio/adc/Kconfig +++ b/drivers/staging/iio/adc/Kconfig @@ -3,19 +3,6 @@ # menu "Analog to digital converters" -config AD7780 - tristate "Analog Devices AD7780 and similar ADCs driver" - depends on SPI - depends on GPIOLIB || COMPILE_TEST - select AD_SIGMA_DELTA - help - Say yes here to build support for Analog Devices AD7170, AD7171, - AD7780 and AD7781 SPI analog to digital converters (ADC). - If unsure, say N (but it's safe to say "Y"). - - To compile this driver as a module, choose M here: the - module will be called ad7780. - config AD7816 tristate "Analog Devices AD7816/7/8 temperature sensor and ADC driver" depends on SPI diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile index 7a421088ff82..4b76769b32bc 100644 --- a/drivers/staging/iio/adc/Makefile +++ b/drivers/staging/iio/adc/Makefile @@ -3,7 +3,6 @@ # Makefile for industrial I/O ADC drivers # -obj-$(CONFIG_AD7780) += ad7780.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_AD7192) += ad7192.o obj-$(CONFIG_AD7280) += ad7280a.o diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c deleted file mode 100644 index 23b731a92e32..000000000000 --- a/drivers/staging/iio/adc/ad7780.c +++ /dev/null @@ -1,376 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * AD7170/AD7171 and AD7780/AD7781 SPI ADC driver - * - * Copyright 2011 Analog Devices Inc. - * Copyright 2019 Renato Lui Geh - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#define AD7780_RDY BIT(7) -#define AD7780_FILTER BIT(6) -#define AD7780_ERR BIT(5) -#define AD7780_ID1 BIT(4) -#define AD7780_ID0 BIT(3) -#define AD7780_GAIN BIT(2) - -#define AD7170_ID 0 -#define AD7171_ID 1 -#define AD7780_ID 1 -#define AD7781_ID 0 - -#define AD7780_ID_MASK (AD7780_ID0 | AD7780_ID1) - -#define AD7780_PATTERN_GOOD 1 -#define AD7780_PATTERN_MASK GENMASK(1, 0) - -#define AD7170_PATTERN_GOOD 5 -#define AD7170_PATTERN_MASK GENMASK(2, 0) - -#define AD7780_GAIN_MIDPOINT 64 -#define AD7780_FILTER_MIDPOINT 13350 - -static const unsigned int ad778x_gain[2] = { 1, 128 }; -static const unsigned int ad778x_odr_avail[2] = { 10000, 16700 }; - -struct ad7780_chip_info { - struct iio_chan_spec channel; - unsigned int pattern_mask; - unsigned int pattern; - bool is_ad778x; -}; - -struct ad7780_state { - const struct ad7780_chip_info *chip_info; - struct regulator *reg; - struct gpio_desc *powerdown_gpio; - struct gpio_desc *gain_gpio; - struct gpio_desc *filter_gpio; - unsigned int gain; - unsigned int odr; - unsigned int int_vref_mv; - - struct ad_sigma_delta sd; -}; - -enum ad7780_supported_device_ids { - ID_AD7170, - ID_AD7171, - ID_AD7780, - ID_AD7781, -}; - -static struct ad7780_state *ad_sigma_delta_to_ad7780(struct ad_sigma_delta *sd) -{ - return container_of(sd, struct ad7780_state, sd); -} - -static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta, - enum ad_sigma_delta_mode mode) -{ - struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta); - unsigned int val; - - switch (mode) { - case AD_SD_MODE_SINGLE: - case AD_SD_MODE_CONTINUOUS: - val = 1; - break; - default: - val = 0; - break; - } - - gpiod_set_value(st->powerdown_gpio, val); - - return 0; -} - -static int ad7780_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - struct ad7780_state *st = iio_priv(indio_dev); - int voltage_uv; - - switch (m) { - case IIO_CHAN_INFO_RAW: - return ad_sigma_delta_single_conversion(indio_dev, chan, val); - case IIO_CHAN_INFO_SCALE: - voltage_uv = regulator_get_voltage(st->reg); - if (voltage_uv < 0) - return voltage_uv; - voltage_uv /= 1000; - *val = voltage_uv * st->gain; - *val2 = chan->scan_type.realbits - 1; - st->int_vref_mv = voltage_uv; - return IIO_VAL_FRACTIONAL_LOG2; - case IIO_CHAN_INFO_OFFSET: - *val = -(1 << (chan->scan_type.realbits - 1)); - return IIO_VAL_INT; - case IIO_CHAN_INFO_SAMP_FREQ: - *val = st->odr; - return IIO_VAL_INT; - default: - break; - } - - return -EINVAL; -} - -static int ad7780_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long m) -{ - struct ad7780_state *st = iio_priv(indio_dev); - const struct ad7780_chip_info *chip_info = st->chip_info; - unsigned long long vref; - unsigned int full_scale, gain; - - if (!chip_info->is_ad778x) - return -EINVAL; - - switch (m) { - case IIO_CHAN_INFO_SCALE: - if (val != 0) - return -EINVAL; - - vref = st->int_vref_mv * 1000000LL; - full_scale = 1 << (chip_info->channel.scan_type.realbits - 1); - gain = DIV_ROUND_CLOSEST(vref, full_scale); - gain = DIV_ROUND_CLOSEST(gain, val2); - st->gain = gain; - if (gain < AD7780_GAIN_MIDPOINT) - gain = 0; - else - gain = 1; - gpiod_set_value(st->gain_gpio, gain); - break; - case IIO_CHAN_INFO_SAMP_FREQ: - if (1000*val + val2/1000 < AD7780_FILTER_MIDPOINT) - val = 0; - else - val = 1; - st->odr = ad778x_odr_avail[val]; - gpiod_set_value(st->filter_gpio, val); - break; - default: - break; - } - - return 0; -} - -static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta, - unsigned int raw_sample) -{ - struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta); - const struct ad7780_chip_info *chip_info = st->chip_info; - - if ((raw_sample & AD7780_ERR) || - ((raw_sample & chip_info->pattern_mask) != chip_info->pattern)) - return -EIO; - - if (chip_info->is_ad778x) { - st->gain = ad778x_gain[raw_sample & AD7780_GAIN]; - st->odr = ad778x_odr_avail[raw_sample & AD7780_FILTER]; - } - - return 0; -} - -static const struct ad_sigma_delta_info ad7780_sigma_delta_info = { - .set_mode = ad7780_set_mode, - .postprocess_sample = ad7780_postprocess_sample, - .has_registers = false, -}; - -#define AD7780_CHANNEL(bits, wordsize) \ - AD_SD_CHANNEL(1, 0, 0, bits, 32, wordsize - bits) -#define AD7170_CHANNEL(bits, wordsize) \ - AD_SD_CHANNEL_NO_SAMP_FREQ(1, 0, 0, bits, 32, wordsize - bits) - -static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { - [ID_AD7170] = { - .channel = AD7170_CHANNEL(12, 24), - .pattern = AD7170_PATTERN_GOOD, - .pattern_mask = AD7170_PATTERN_MASK, - .is_ad778x = false, - }, - [ID_AD7171] = { - .channel = AD7170_CHANNEL(16, 24), - .pattern = AD7170_PATTERN_GOOD, - .pattern_mask = AD7170_PATTERN_MASK, - .is_ad778x = false, - }, - [ID_AD7780] = { - .channel = AD7780_CHANNEL(24, 32), - .pattern = AD7780_PATTERN_GOOD, - .pattern_mask = AD7780_PATTERN_MASK, - .is_ad778x = true, - }, - [ID_AD7781] = { - .channel = AD7780_CHANNEL(20, 32), - .pattern = AD7780_PATTERN_GOOD, - .pattern_mask = AD7780_PATTERN_MASK, - .is_ad778x = true, - }, -}; - -static const struct iio_info ad7780_info = { - .read_raw = ad7780_read_raw, - .write_raw = ad7780_write_raw, -}; - -static int ad7780_init_gpios(struct device *dev, struct ad7780_state *st) -{ - int ret; - - st->powerdown_gpio = devm_gpiod_get_optional(dev, - "powerdown", - GPIOD_OUT_LOW); - if (IS_ERR(st->powerdown_gpio)) { - ret = PTR_ERR(st->powerdown_gpio); - dev_err(dev, "Failed to request powerdown GPIO: %d\n", ret); - return ret; - } - - if (!st->chip_info->is_ad778x) - return 0; - - - st->gain_gpio = devm_gpiod_get_optional(dev, - "adi,gain", - GPIOD_OUT_HIGH); - if (IS_ERR(st->gain_gpio)) { - ret = PTR_ERR(st->gain_gpio); - dev_err(dev, "Failed to request gain GPIO: %d\n", ret); - return ret; - } - - st->filter_gpio = devm_gpiod_get_optional(dev, - "adi,filter", - GPIOD_OUT_HIGH); - if (IS_ERR(st->filter_gpio)) { - ret = PTR_ERR(st->filter_gpio); - dev_err(dev, "Failed to request filter GPIO: %d\n", ret); - return ret; - } - - return 0; -} - -static int ad7780_probe(struct spi_device *spi) -{ - struct ad7780_state *st; - struct iio_dev *indio_dev; - int ret; - - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); - if (!indio_dev) - return -ENOMEM; - - st = iio_priv(indio_dev); - st->gain = 1; - - ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info); - - st->chip_info = - &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - - spi_set_drvdata(spi, indio_dev); - - indio_dev->dev.parent = &spi->dev; - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->modes = INDIO_DIRECT_MODE; - indio_dev->channels = &st->chip_info->channel; - indio_dev->num_channels = 1; - indio_dev->info = &ad7780_info; - - ret = ad7780_init_gpios(&spi->dev, st); - if (ret) - goto error_cleanup_buffer_and_trigger; - - st->reg = devm_regulator_get(&spi->dev, "avdd"); - if (IS_ERR(st->reg)) - return PTR_ERR(st->reg); - - ret = regulator_enable(st->reg); - if (ret) { - dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); - return ret; - } - - ret = ad_sd_setup_buffer_and_trigger(indio_dev); - if (ret) - goto error_disable_reg; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_cleanup_buffer_and_trigger; - - return 0; - -error_cleanup_buffer_and_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_reg: - regulator_disable(st->reg); - - return ret; -} - -static int ad7780_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7780_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - regulator_disable(st->reg); - - return 0; -} - -static const struct spi_device_id ad7780_id[] = { - {"ad7170", ID_AD7170}, - {"ad7171", ID_AD7171}, - {"ad7780", ID_AD7780}, - {"ad7781", ID_AD7781}, - {} -}; -MODULE_DEVICE_TABLE(spi, ad7780_id); - -static struct spi_driver ad7780_driver = { - .driver = { - .name = "ad7780", - }, - .probe = ad7780_probe, - .remove = ad7780_remove, - .id_table = ad7780_id, -}; -module_spi_driver(ad7780_driver); - -MODULE_AUTHOR("Michael Hennerich "); -MODULE_DESCRIPTION("Analog Devices AD7780 and similar ADCs"); -MODULE_LICENSE("GPL v2"); From patchwork Sat Mar 16 02:16:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Renato Lui Geh X-Patchwork-Id: 10855711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6EAE01515 for ; Sat, 16 Mar 2019 02:16:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 566F72AC5D for ; Sat, 16 Mar 2019 02:16:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A1742AC71; Sat, 16 Mar 2019 02:16:20 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 DC3922AC8B for ; Sat, 16 Mar 2019 02:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726360AbfCPCQT (ORCPT ); Fri, 15 Mar 2019 22:16:19 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:37685 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726549AbfCPCQT (ORCPT ); Fri, 15 Mar 2019 22:16:19 -0400 Received: by mail-yw1-f68.google.com with SMTP id w66so8794591ywd.4; Fri, 15 Mar 2019 19:16:18 -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=NMeP2IkzSEftRMF6nNz8Vv+P/xn7p6xmxsCj+g6jPfw=; b=K9qAjoSo/ugPBviM2sPkOLrP1WIBlXl9ECbxx1e76dDter/U9dYMomQnZv0uOG7zdV Ho2vyDwxSBqfblUY3XODtKilw1P35MYgcr9SymW/W6E365RkgNwgUS7/jDozmpvByWSe cI6NvX0SnBZtbTbQGEfdJlyzpLBOF2eDDHqmLTA/UpumlmC0S0FMJYq8hymZjcQUU1Eh JupIiSuiAfM0ZgHciI2ANf5B+Qs6kE5njuD4wT4Jjip7Ys035GZvs8E87aEbaSaK8IQQ XKBjY4Kse3kq6KxRFQnXELJYwDYQRmDvLD/gsSU3nGtvvCCRb1dU79yHOC1S7kV8+s3I A2Dw== 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=NMeP2IkzSEftRMF6nNz8Vv+P/xn7p6xmxsCj+g6jPfw=; b=jePbO0lqCimqfUZKpIlGOPigSVZm9Qt6t6kOa7g7VT603e5nXsi334dKqNRH9gUH8B vL4keul0cRFmTq/RaE/9aXLz3z0mo4+3vWIJKPWfL2zpeBveDbx9kYCDY6pf82RLAA3A PH3zcYLVHIFRzk9YWsUVm3ChTPTXeHwTYx+wXSx7vBnsGwVHgt5N8/GqCKCWDZvg1gyX xy7qETTSPtxd/rWDwZbkk/E+mXYiGdEHr1GhgwomoHFwZOzWXPPXW8hAy0S097eJYkZn LzSVUHl5qBHZo1SCabImAmYvFK9kpW1FzcbLRFkvZs4IVhsmNyItuTj66EU3FQtgC7ox Imgw== X-Gm-Message-State: APjAAAWPb1sIeNIf/3hSb+qdm5ZjMaRBu470JHspPAGUGicgZpT+WXDf iMCyTAtkD9rwXgbJiYOxT+c= X-Google-Smtp-Source: APXvYqxOniiMVtEoj8kEZ3Narq4Ag3pwHJWHmjta2JzJj7IK2x/GoqVK82sOvjqn2LTTd3jchkN+vA== X-Received: by 2002:a81:77d7:: with SMTP id s206mr5400460ywc.30.1552702578195; Fri, 15 Mar 2019 19:16:18 -0700 (PDT) Received: from renatolg ([186.220.21.102]) by smtp.gmail.com with ESMTPSA id q9sm1729785ywq.88.2019.03.15.19.16.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 19:16:18 -0700 (PDT) Date: Fri, 15 Mar 2019 23:16:13 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, stefan.popa@analog.com, alexandru.Ardelean@analog.com, giuliano.belinassi@usp.br, robh+dt@kernel.org, mark.rutland@arm.com Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, devicetree@vger.kernel.org Subject: [PATCH v5 11/11] staging: iio: ad7780: add device tree binding Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 Adds a device tree binding for the ad7780 driver. Signed-off-by: Renato Lui Geh --- .../bindings/iio/adc/adi,ad7780.txt | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt b/Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt new file mode 100644 index 000000000000..440e52555349 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7780.txt @@ -0,0 +1,48 @@ +* Analog Devices AD7170/AD7171/AD7780/AD7781 + +Data sheets: + +- AD7170: + * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7170.pdf +- AD7171: + * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7171.pdf +- AD7780: + * https://www.analog.com/media/en/technical-documentation/data-sheets/ad7780.pdf +- AD7781: + * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7781.pdf + +Required properties: + +- compatible: should be one of + * "adi,ad7170" + * "adi,ad7171" + * "adi,ad7780" + * "adi,ad7781" +- reg: spi chip select number for the device +- vref-supply: the regulator supply for the ADC reference voltage + +Optional properties: + +- powerdown-gpios: must be the device tree identifier of the PDRST pin. If + specified, it will be asserted during driver probe. As the + line is active high, it should be marked GPIO_ACTIVE_HIGH. +- adi,gain-gpios: must be the device tree identifier of the GAIN pin. Only for + the ad778x chips. If specified, it will be asserted during + driver probe. As the line is active low, it should be marked + GPIO_ACTIVE_LOW. +- adi,filter-gpios: must be the device tree identifier of the FILTER pin. Only + for the ad778x chips. If specified, it will be asserted + during driver probe. As the line is active low, it should be + marked GPIO_ACTIVE_LOW. + +Example: + +adc@0 { + compatible = "adi,ad7780"; + reg = <0>; + vref-supply = <&vdd_supply> + + powerdown-gpios = <&gpio 12 GPIO_ACTIVE_HIGH>; + adi,gain-gpios = <&gpio 5 GPIO_ACTIVE_LOW>; + adi,filter-gpios = <&gpio 15 GPIO_ACTIVE_LOW>; +};