From patchwork Mon Mar 12 18:21:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10276971 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 C431960211 for ; Mon, 12 Mar 2018 18:22:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC1D628AF1 for ; Mon, 12 Mar 2018 18:22:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A09A728B00; Mon, 12 Mar 2018 18:22:01 +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=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 1925E28AF1 for ; Mon, 12 Mar 2018 18:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751754AbeCLSWA (ORCPT ); Mon, 12 Mar 2018 14:22:00 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:45559 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751616AbeCLSV6 (ORCPT ); Mon, 12 Mar 2018 14:21:58 -0400 Received: by mail-qt0-f193.google.com with SMTP id v90so19858095qte.12; Mon, 12 Mar 2018 11:21:57 -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=S0GzSq6AzqX3a4F0EwN3rI+QG8eb3aZRiZCLqoulXnQ=; b=pEfaZPlsC+F2yEtASTKMkJ3L6ybTic9Q//j57hv6A06WabUaXRN4A8wZztsZteT4u0 bzyN4f/nOBZGs/+07E8timwd/8HiErtEKneeYwwz0YfPrENBoZGD1Qr9ahhdfNlEqwsk 9lbFsNDQnX7jtWTIYWE7xj25GqX0r76L77i1JBE/hiop34v7v/C3DSsh5YsvNEujqv/c YfeN/tHZ1Zhj1dN+k21HYY62LEAntKLzIr2JlE9Nu826ZmyShbeI4dGJ/tKZvGBlAEet WvcfbMf4AuFZi/KMmJJ8sWeefWbmhF7kdv7mtyMgER4DNfaVOWPA9WLN9h1VEz4A4x89 KZlw== 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=S0GzSq6AzqX3a4F0EwN3rI+QG8eb3aZRiZCLqoulXnQ=; b=omvgyTi1kMefeXEe2GBDxWxoQIHmbefVmVoux+xIJSqF3WDANalN+ftg5/iLzoM6C6 I9PBGWmXmepWsxlHhdSq/qbgVKWIUzN6oRTKQ+Umq7tCGuUzh7gIM69ef3XNPrhhD4TH /pTbSFEhEDlqenpHzQlrBriA4IbLVr/JRvpIL3Dr8uML+QiuAmUyfNgLbEXw2cP0yp3T MpOaoHe8YOZiGFdYSxWv+poB6b2WabTTAGZ/ohDDa8WlJq9RI/ZmPRZedIIpFaAul6JG /qygCHC1DsoLMFlH8brtQCLJd3zxaptpu/F1mqT5mBx6O9cdhozKXHupf6XTYkEgg//2 QSeQ== X-Gm-Message-State: AElRT7EyGATGDCeewPYp3gumLjh2NYxmuOsbqdKxKJ+KfOINTK3s60Jp WZm0gugVdVbvR6velRQyBFQ= X-Google-Smtp-Source: AG47ELsGurStcvBLnwt1J/zd3pvR72+W7VcvJTvG2RKFbBRSwwvZELyg11qrYqM84+A0am+lwCd7Og== X-Received: by 10.200.54.151 with SMTP id a23mr13366128qtc.123.1520878917237; Mon, 12 Mar 2018 11:21:57 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id y124sm5442471qke.40.2018.03.12.11.21.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Mar 2018 11:21:56 -0700 (PDT) Date: Mon, 12 Mar 2018 15:21:52 -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 3/3] staging:iio:ad2s1210: Add write_raw to handle frequency Message-ID: 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 --- drivers/staging/iio/resolver/ad2s1210.c | 117 +++++++++++++++----------------- 1 file changed, 55 insertions(+), 62 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 27a42ed10fcd..ea6ade4e563c 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -60,6 +60,8 @@ #define AD2S1210_DEF_EXCIT 10000 +#define ERROR_MESSAGE "ad2s1210: %s out of range\n" + enum ad2s1210_mode { MOD_POS = 0, MOD_VEL, @@ -210,64 +212,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 +489,58 @@ 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; + + switch (mask) { + case IIO_CHAN_INFO_FREQUENCY: + switch (chan->channel) { + case FCLKIN: + if (clk < AD2S1210_MIN_CLKIN || + clk > AD2S1210_MAX_CLKIN) { + dev_err(&indio_dev->dev, ERROR_MESSAGE, + "fclkin"); + ret = -EINVAL; + goto error_ret; + } + mutex_lock(&st->lock); + st->fclkin = clk; + break; + case FEXCIT: + if (clk < AD2S1210_MIN_EXCIT || + clk > AD2S1210_MAX_EXCIT) { + dev_err(&indio_dev->dev, ERROR_MESSAGE, + "excitation frequency"); + ret = -EINVAL; + goto error_ret; + } + mutex_lock(&st->lock); + st->fexcit = clk; + break; + default: + ret = -EINVAL; + goto error_ret; + } + break; + default: + ret = -EINVAL; + goto error_ret; + } + 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); +error_ret: + return ret; +} + static IIO_DEVICE_ATTR(control, 0644, ad2s1210_show_control, ad2s1210_store_control, 0); static IIO_DEVICE_ATTR(bits, 0644, @@ -577,8 +571,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 +627,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, };