From patchwork Tue Mar 13 16:06:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10279777 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 3D133602BD for ; Tue, 13 Mar 2018 16:06:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 291FF29010 for ; Tue, 13 Mar 2018 16:06:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19AE6290D4; Tue, 13 Mar 2018 16:06:36 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 9BA4329010 for ; Tue, 13 Mar 2018 16:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933764AbeCMQGY (ORCPT ); Tue, 13 Mar 2018 12:06:24 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:42576 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934286AbeCMQGL (ORCPT ); Tue, 13 Mar 2018 12:06:11 -0400 Received: by mail-qt0-f193.google.com with SMTP id t6so128813qtn.9; Tue, 13 Mar 2018 09:06:11 -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=5ta6KFdFhn/Be8LQMHsm+84jedIufy63xhZWjDtXGIc=; b=mNBOiBojQjqSY3naQIN1CRT1GZQYHH9FCQy3M0+cuPZnDxqGfuCx+pPEIiISEWp7MN r2GRg+VJs7vPCksaEqGOApLhQNXxsvIxgU/QhaKCuYcJdLFZwM7r8uEtc3LFSxV/3ntn cPSVTQLCP+8i/a0hUjPnGJAHQdOyrDs+Ys516k24tjdBU7LSiVHvCYQwd865b1CNRnrw sTF7EFxWQmKrGtDcaT1ulN/Q3fZz5Q5ITOu7/Ghyj0mdY0kC+ISdm2gFQMBsnV6+250Z KUW2Zl/mSA43RHDaj2DvnQK74IiFYdS/WakoXwMQKDTPn/aINowJigO/owgyWuQTDeAG VlDQ== 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=5ta6KFdFhn/Be8LQMHsm+84jedIufy63xhZWjDtXGIc=; b=fPlhtl+pVKoFhv6Zt/KWOjWZELx6x76zP2/tGgdyDhbEx/jI9t2cWy7yTsAG/oqqPW QngnC5TPq5S1mOUIf9Zur6HezCDjkbXTaJIWxZvJnR2Y94iubPT9trFqKmJz2jP1VpzM u6UaH9pP1HyhotiEtV6wkBGlhZCVR5aRIC7eg1keeZuNg/+fCSzG2rcwHKGV1UGiGySm r6ZFnBX7vYvtQiesubAFIMCjUWkIX6cLLjT6BR2gO5axPujp46Fseac/sn1DELutyRqW /2fBnPWnH8PpDOjM4TZE8kf0HJYHC5Evwk5Sh1W1vSbzVdH0ackWNfAeIDe/wDusMbGf /MFA== X-Gm-Message-State: AElRT7FSnwxUcv8HZKsG2PMt/QI2aA+AwkZxivQCS58Bb+/FQTHEHyqO idvcLhTlM5yRikqoWvPAnccpUYs3 X-Google-Smtp-Source: AG47ELtpzkOioYQHowmFKfNkxBtn+1l/qUs3Vfm2KO0qK84DqUoIrifiBI/jFViMf696YzRmqr5EVw== X-Received: by 10.237.50.162 with SMTP id z31mr1777874qtd.146.1520957170409; Tue, 13 Mar 2018 09:06:10 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id r62sm10889qkc.56.2018.03.13.09.06.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Mar 2018 09:06:09 -0700 (PDT) Date: Tue, 13 Mar 2018 13:06:05 -0300 From: Rodrigo Siqueira To: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Hartmut Knaack , Peter Meerwald-Stadler , Greg Kroah-Hartman , Graff Yang Cc: daniel.baluta@nxp.com, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] staging:iio:ad2s1210: Add write_raw to handle frequency Message-ID: <8eaa05b021f1be0f1c8666b0030ba36abc98195e.1520956563.git.rodrigosiqueiramelo@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 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 write interface of AD2S1210 utilizes IIO_DEVICE_ATTR, which violate the official IIO ABI. This patch, add the write_raw function responsible for handling the fclkin and fexcit channel; also it removes the use of IIO_DEVICE_ATTR for fclkin and fexcit. Signed-off-by: Rodrigo Siqueira --- Changes in v2: - Removes unnecessary switch case in the write_raw function. - Replaces the use of goto for direct return. - Removes definition with string. - Removes unecessary label. drivers/staging/iio/resolver/ad2s1210.c | 107 ++++++++++++++------------------ 1 file changed, 45 insertions(+), 62 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 27a42ed10fcd..001ddca92e8f 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -210,64 +210,6 @@ static inline int ad2s1210_soft_reset(struct ad2s1210_state *st) return ad2s1210_config_write(st, 0x0); } -static ssize_t ad2s1210_store_fclkin(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - unsigned int fclkin; - int ret; - - ret = kstrtouint(buf, 10, &fclkin); - if (ret) - return ret; - if (fclkin < AD2S1210_MIN_CLKIN || fclkin > AD2S1210_MAX_CLKIN) { - dev_err(dev, "ad2s1210: fclkin out of range\n"); - return -EINVAL; - } - - mutex_lock(&st->lock); - st->fclkin = fclkin; - - ret = ad2s1210_update_frequency_control_word(st); - if (ret < 0) - goto error_ret; - ret = ad2s1210_soft_reset(st); -error_ret: - mutex_unlock(&st->lock); - - return ret < 0 ? ret : len; -} - -static ssize_t ad2s1210_store_fexcit(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct ad2s1210_state *st = iio_priv(dev_to_iio_dev(dev)); - unsigned int fexcit; - int ret; - - ret = kstrtouint(buf, 10, &fexcit); - if (ret < 0) - return ret; - if (fexcit < AD2S1210_MIN_EXCIT || fexcit > AD2S1210_MAX_EXCIT) { - dev_err(dev, - "ad2s1210: excitation frequency out of range\n"); - return -EINVAL; - } - mutex_lock(&st->lock); - st->fexcit = fexcit; - ret = ad2s1210_update_frequency_control_word(st); - if (ret < 0) - goto error_ret; - ret = ad2s1210_soft_reset(st); -error_ret: - mutex_unlock(&st->lock); - - return ret < 0 ? ret : len; -} - static ssize_t ad2s1210_show_control(struct device *dev, struct device_attribute *attr, char *buf) @@ -545,8 +487,50 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, return ret; } -static IIO_DEVICE_ATTR(fclkin, 0644, NULL, ad2s1210_store_fclkin, 0); -static IIO_DEVICE_ATTR(fexcit, 0644, NULL, ad2s1210_store_fexcit, 0); +static int ad2s1210_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, + int val2, long mask) +{ + struct ad2s1210_state *st = iio_priv(indio_dev); + unsigned int clk = val; + int ret; + + if (mask != IIO_CHAN_INFO_FREQUENCY) + return -EINVAL; + + switch (chan->channel) { + case FCLKIN: + if (clk < AD2S1210_MIN_CLKIN || + clk > AD2S1210_MAX_CLKIN) { + dev_err(&indio_dev->dev, + "ad2s1210: fclkin out of range\n"); + return -EINVAL; + } + mutex_lock(&st->lock); + st->fclkin = clk; + break; + case FEXCIT: + if (clk < AD2S1210_MIN_EXCIT || + clk > AD2S1210_MAX_EXCIT) { + dev_err(&indio_dev->dev, + "ad2s1210: excitation frequency out of range\n"); + return -EINVAL; + } + mutex_lock(&st->lock); + st->fexcit = clk; + break; + default: + return -EINVAL; + } + ret = ad2s1210_update_frequency_control_word(st); + if (ret < 0) + goto error_unlock_mutex; + ret = ad2s1210_soft_reset(st); +error_unlock_mutex: + mutex_unlock(&st->lock); + return ret; +} + static IIO_DEVICE_ATTR(control, 0644, ad2s1210_show_control, ad2s1210_store_control, 0); static IIO_DEVICE_ATTR(bits, 0644, @@ -577,8 +561,6 @@ static IIO_DEVICE_ATTR(lot_low_thrd, 0644, AD2S1210_REG_LOT_LOW_THRD); static struct attribute *ad2s1210_attributes[] = { - &iio_dev_attr_fclkin.dev_attr.attr, - &iio_dev_attr_fexcit.dev_attr.attr, &iio_dev_attr_control.dev_attr.attr, &iio_dev_attr_bits.dev_attr.attr, &iio_dev_attr_fault.dev_attr.attr, @@ -635,6 +617,7 @@ static int ad2s1210_initial(struct ad2s1210_state *st) static const struct iio_info ad2s1210_info = { .read_raw = ad2s1210_read_raw, + .write_raw = ad2s1210_write_raw, .attrs = &ad2s1210_attribute_group, };