From patchwork Sat Mar 16 15:06:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Schmitt X-Patchwork-Id: 10855895 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 E32281390 for ; Sat, 16 Mar 2019 15:06:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C754229CFF for ; Sat, 16 Mar 2019 15:06:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA5FF2A13D; Sat, 16 Mar 2019 15:06:25 +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 9598529CFF for ; Sat, 16 Mar 2019 15:06:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbfCPPGY (ORCPT ); Sat, 16 Mar 2019 11:06:24 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:45855 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbfCPPGX (ORCPT ); Sat, 16 Mar 2019 11:06:23 -0400 Received: by mail-qt1-f193.google.com with SMTP id v20so13374778qtv.12; Sat, 16 Mar 2019 08:06:23 -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:mime-version:content-disposition :user-agent; bh=lobLDAlrnYC0TAuM5nbXmB+CxrZAEtQnGAufgWBeZPs=; b=A0HcPPTY9nSf2kf92LaO44Wk5LS/NaXQJPvFvX6LEM1CYZF1W6AAPMqQP5TqQ0T56n Ba3cVWtIoIYwR+uOxb3I5q6tecAepOADeUDg037Zcn418cI7O/6Z5gdBvK5a6cl1E6x+ fEUo2lx4D0Y8C+x+C2Kn1RkSmsv651e9pFTrl9w+rSD8WVyHyocSWRtYvbPdoYVcDyRL E3/9V2ZhFDMULUU/tQiR8TztOq7MgNeUa8sqG8eLb0CHvBQ0AJpDQtRKLX0ncmddWzQ/ ttahoWStDTyUrEh6Xrlf64Dh21WrCiSThCVo9h5yx0h/ITx8rAIrsjzwWP6ryVRKLX91 gBkg== 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:mime-version :content-disposition:user-agent; bh=lobLDAlrnYC0TAuM5nbXmB+CxrZAEtQnGAufgWBeZPs=; b=eLeKlTTwF0uG/TlOu7e/8Lsjki2g5rXl9dHUpMS8Jv0mOK/jqwEGu9G7MtnyJS7lLI aFyBjUVhlZ2t8G5pII2V4JzaLjpMfNKdWWiN4X4PgSCzQxRW0e9A8hKZLMkQd3mOYymF 4Opp5DQ7FvquZvxQk6nh7NL2Hy5YO2reBZlkNSLTML5yM7BEzCkTCRoAl4PcAQLnE6Y8 G1J8TmPQBMurgL/wlWVsl3MKswCIyjEgjlKf8ttE4HK1oJX+5wW3zYOLKxq+503pGUEU 8NHfp2hkvyZNFr4cJDjQIkfTij8gfo/FJBiNDZnUMaEM3P0biBKN2wokDPDDPBd8lLrp UaZA== X-Gm-Message-State: APjAAAU/zOWClOi+jGRbv4TxMs4SznSJ2R8gQDgI4+iDAk2LcHmh0wPh pES8gqdj481zjE0mi5DJd4s= X-Google-Smtp-Source: APXvYqxxmy9a7+1TnoFm/IMgrF3Pe4MpfTZtjzNmJz4xkMhgLnG3qHzPKx+tIOR5mVxKBjdzcwGHOg== X-Received: by 2002:a0c:9e2d:: with SMTP id p45mr6632266qve.28.1552748782613; Sat, 16 Mar 2019 08:06:22 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id 55sm3550738qtq.25.2019.03.16.08.06.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 16 Mar 2019 08:06:22 -0700 (PDT) Date: Sat, 16 Mar 2019 12:06:18 -0300 From: Marcelo Schmitt To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com Subject: [PATCH v4 1/7] staging: iio: ad5933: change multi-line comment style Message-ID: <20190316150618.7g6hxbmadvxe623o@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline 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 Make multi-line comments compliant with the preferred code style. Signed-off-by: Marcelo Schmitt --- drivers/staging/iio/impedance-analyzer/ad5933.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index 3134295f014f..05e2185bfdae 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -474,7 +474,8 @@ static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644, ad5933_store, AD5933_OUT_SETTLING_CYCLES); -/* note: +/* + * note: * ideally we would handle the scale attributes via the iio_info * (read|write)_raw methods, however this part is a untypical since we * don't create dedicated sysfs channel attributes for out0 and in0. @@ -572,7 +573,8 @@ static int ad5933_ring_postenable(struct iio_dev *indio_dev) { struct ad5933_state *st = iio_priv(indio_dev); - /* AD5933_CTRL_INIT_START_FREQ: + /* + * AD5933_CTRL_INIT_START_FREQ: * High Q complex circuits require a long time to reach steady state. * To facilitate the measurement of such impedances, this mode allows * the user full control of the settling time requirement before @@ -663,7 +665,8 @@ static void ad5933_work(struct work_struct *work) } if (status & AD5933_STAT_SWEEP_DONE) { - /* last sample received - power down do + /* + * last sample received - power down do * nothing until the ring enable is toggled */ ad5933_cmd(st, AD5933_CTRL_POWER_DOWN); From patchwork Sat Mar 16 15:06:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Schmitt X-Patchwork-Id: 10855897 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 3060714DE for ; Sat, 16 Mar 2019 15:06:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16B8B29CFB for ; Sat, 16 Mar 2019 15:06:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AC6529D0E; Sat, 16 Mar 2019 15:06:57 +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 B11CF29CFB for ; Sat, 16 Mar 2019 15:06:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbfCPPG4 (ORCPT ); Sat, 16 Mar 2019 11:06:56 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:37731 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbfCPPG4 (ORCPT ); Sat, 16 Mar 2019 11:06:56 -0400 Received: by mail-qt1-f195.google.com with SMTP id z17so13395024qtn.4; Sat, 16 Mar 2019 08:06:55 -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:mime-version:content-disposition :user-agent; bh=Na8cn6ZpM3g5SgVUX/cLn0sa0oxjd9imZV6NYEIWFu0=; b=rWsM9vkGbErKLWYlT9ac3rJiTrPhJEx+wjb8dPH7c/guY04HPLEzqxxm6C3yQbeN7B 6ZskU0zUR5G50c+VUsDKsAvvNCo8n9AQZzWk184N96yvRyYVqLEp/sQLqmDYEFoS/00X h8PUMZ93f/gZblr6Q9wlA+znA6nrPEJeFo6bwqdE7Lg1HdEnWbhmmAsols45Eax2dkXY GeORVMDvnjUBx/wC0AprTAvJfewsAJmO+3JzFTjGYBpUA2Uq246bn4WlylRWbyv4JG4J T2WWZcQVrXKcXFExtLP+rW64fjPlIQwd0mxn1Vl+6aEL7Ea3E8BUTOaM71Cjmk5+gvP4 Z8DQ== 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:mime-version :content-disposition:user-agent; bh=Na8cn6ZpM3g5SgVUX/cLn0sa0oxjd9imZV6NYEIWFu0=; b=h8t5AF2Xx8pXT6g6/ztNcJaL4XqA7IdzkAneYrROT2vyu7RLx8q49GRbrxNywr2Aw7 1Y+ypVDSV6wNhIfFtut0JEBUB/7kUOGPjs7w8O8g7Qevkd66IFQuxv6g7iODPiOBaitm QSV+ea3nVp3JSpgMn/p/ZhyZ2uo8dFRtMMf9WlfDlF7tBVmACMWXy8H7+PqJKf16Mnvj o2WzSP/U24sHFG+8P72YP5802V9PzdV40JTilakjJzzBhycg8+JLKtYDQ2eBwlWCuyw2 saMAltMomx3JCTxn6Q6MErSfpNvYOz5lXNuKrrkV+BUr1LOR210aInF7N4a1DHioEfmR Umlw== X-Gm-Message-State: APjAAAWPZ9MZaADnbwqyivpdoxjc4cWZfbNdNhrIhjszUDTgLR1DILCK i5RaWrcrtjQpohEOdfVBeJI= X-Google-Smtp-Source: APXvYqydL90L10MqKKh/QNjvHnfXTJFjnbSza0Xvt264zJmh8wdaNa7T62Y/XnaiB4T4NA8rw90Juw== X-Received: by 2002:a0c:afef:: with SMTP id t44mr6651774qvc.59.1552748815061; Sat, 16 Mar 2019 08:06:55 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id r17sm2739703qkm.17.2019.03.16.08.06.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 16 Mar 2019 08:06:54 -0700 (PDT) Date: Sat, 16 Mar 2019 12:06:50 -0300 From: Marcelo Schmitt To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com Subject: [PATCH v4 2/7] staging: iio: ad5933: organize includes Message-ID: <20190316150650.jke4uqgnf5w6s3cv@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline 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 Organize includes to list them in lexicographic order. Signed-off-by: Marcelo Schmitt --- .../staging/iio/impedance-analyzer/ad5933.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index 05e2185bfdae..c2a7a59e469c 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -6,22 +6,22 @@ * Licensed under the GPL-2. */ -#include +#include +#include #include -#include -#include +#include #include +#include +#include +#include #include +#include #include -#include -#include -#include -#include -#include -#include #include +#include #include +#include /* AD5933/AD5934 Registers */ #define AD5933_REG_CONTROL_HB 0x80 /* R/W, 1 byte */ From patchwork Sat Mar 16 15:07:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Schmitt X-Patchwork-Id: 10855899 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 AEBE914DE for ; Sat, 16 Mar 2019 15:07:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9529929CFF for ; Sat, 16 Mar 2019 15:07:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8946E2A263; Sat, 16 Mar 2019 15:07:09 +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 32E1529CFF for ; Sat, 16 Mar 2019 15:07:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727028AbfCPPHI (ORCPT ); Sat, 16 Mar 2019 11:07:08 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:42359 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbfCPPHI (ORCPT ); Sat, 16 Mar 2019 11:07:08 -0400 Received: by mail-qt1-f194.google.com with SMTP id u7so13354075qtg.9; Sat, 16 Mar 2019 08:07:07 -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:mime-version:content-disposition :user-agent; bh=Et0COeORfa9jig2CdFxD5Z1J1otj4MFOV8zBbjVTkA0=; b=k3CuVYUpC3B/tWCCDXapS7Xr2vWcyyo/f5vX8rJ0JdEcZTpJ9igVsKmKM6EdJ9d+Lg 6jTygfzmMczRvDBloE7TE2//8VN98shnidOb10/8NnY/YjTpkxIRK6rYG1/rVtDnsbpc CTuCJM4g001s2/iGbQMNC57igYoAYDzU3o5/s365k+fE/mEQef8N7UQOXWTFjDzAwmKb eqnwzDabw24UVIMvLmSK312Bqi7ITZH7G2ianW2f43lCsSw+BFBlYoV+2AVQjCYi4zj6 A1Er2U4kDLLD4DI9DY8lV81VpdviStPUP9/OwoMBhUlXUJkxq5WZtV4YB7REgOQo1FtD vQMg== 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:mime-version :content-disposition:user-agent; bh=Et0COeORfa9jig2CdFxD5Z1J1otj4MFOV8zBbjVTkA0=; b=RB2wfOBDI/ysNwfDOOFtrCYquKlYdzYYstkuMeBIsa8fQXImjOKZx53Iyn2IEzqgYC /FYc2R2wZjOXbMJ15uvKSUeFKmEg/eQUkzVqs1LO4BQ/SZ7gxT2N3g4m24k0as/N2l2y 4NEQc/j305BYjvhkDJZhwr9N83ckTQ7WBS5R5J1uGbemtphcR4mDgiH2QPsyyyGZnasV dWSjIidp3Ko76BLxc7sDtxZcLohAVFprnzz/Rb49VWhhunLHxXQrZ+I95KrUXceLtvxM 8Di6lIzKAe2FCYtdz4MDaKn8ALt0dLkEdYm0zXRXHk+oxrWwLoVMZQZCF5WVq+fPU9Ea vG9A== X-Gm-Message-State: APjAAAXrobctH12b7zYv3UTUMnbmXTVocSQuVMmY960KhqQ3crndtwSC ZvbkXhBuVXm+k7pux8StA+c= X-Google-Smtp-Source: APXvYqzvdDb6+Q5e86VCxE3ljRk35hcONgVtymzfpHoeKOLkFumPJyy1q4pkI/pmmLiL3/XAlYtyIw== X-Received: by 2002:ac8:23f7:: with SMTP id r52mr6926405qtr.378.1552748827513; Sat, 16 Mar 2019 08:07:07 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id x33sm3491302qth.7.2019.03.16.08.07.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 16 Mar 2019 08:07:07 -0700 (PDT) Date: Sat, 16 Mar 2019 12:07:03 -0300 From: Marcelo Schmitt To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com Subject: [PATCH v4 3/7] staging: iio: ad5933: add SPDX identifier Message-ID: <20190316150703.n3nlcjl4a32fakb6@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline 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 of GPL-2.0 for the ad5933 driver. Signed-off-by: Marcelo Schmitt --- drivers/staging/iio/impedance-analyzer/ad5933.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index c2a7a59e469c..d75bdfbf93de 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -1,9 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * AD5933 AD5934 Impedance Converter, Network Analyzer * * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. */ #include From patchwork Sat Mar 16 15:07:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Schmitt X-Patchwork-Id: 10855901 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 E4A6A1390 for ; Sat, 16 Mar 2019 15:07:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC5FB29CFB for ; Sat, 16 Mar 2019 15:07:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C04DD2A13D; Sat, 16 Mar 2019 15:07:24 +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 6A9F229CFB for ; Sat, 16 Mar 2019 15:07:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726954AbfCPPHX (ORCPT ); Sat, 16 Mar 2019 11:07:23 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:37775 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbfCPPHX (ORCPT ); Sat, 16 Mar 2019 11:07:23 -0400 Received: by mail-qt1-f194.google.com with SMTP id z17so13395878qtn.4; Sat, 16 Mar 2019 08:07:23 -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:mime-version:content-disposition :user-agent; bh=1dWlSdF/VUs9/9K5esBtgLKSgLb9YgXrY3lBZ+V781M=; b=aVStcTXfRFOtIitxJBmh9/c0oFo8swTRvIb168aqAhp4nqlR8WbtGM0h3GLeuQH0Se GiufrL6Yep7FgfBCcb7o3BhRmfjQK7Ow1YqtZLm+kJvdCdhi6uvzkCKsDLvzqLybBQTy AXw3l4iqk0qKoShzTLseNRkr1gT3hho4poJaW1LiC8dY1hNZnphYuLJIXCzTH/sdISgC W8E4oVz6ZZRw5SVTXBMN3sgq+FMI+3Z3ZSAcat5xVLD+rFP2MdVYHS71WzQORBywpEdF +Qj8qMG3ttVzyXzdjQZhpRqfjVjXp6QjRqa1vI5k8bDoI6C/cKM/xJFYigdTx015aRDP of7w== 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:mime-version :content-disposition:user-agent; bh=1dWlSdF/VUs9/9K5esBtgLKSgLb9YgXrY3lBZ+V781M=; b=QwvDQi0xr33FuLxyOZALJsFOE6lKFMtWoQKCbqL6AxScPsDQ9jnV425shBXBlnhEiR iK2bnMW/8PzklMCfITdhmjsGdLgY0hvdfVVIOd0Zf5jJDavcp0RtA38BorOliY+VZCno prQ2TiIwHe4TBkocNLgjkTcnrfipjNWOASoXwaFooPcMbcWVlrGR26zER+gtuxowwGwB J4TELDWWvAfHTOBQizIHNEXJ6+od7H0bdLW30zg7T7w59awbNbfUfMiMqfLzZY1Z+nYg tZbkmnZEiSmoL6f46WQEadoE6zPfOroQ0ISgzN0ICFUVeCXuiMzCMHLJJomquUWOLZRU sOWg== X-Gm-Message-State: APjAAAVLRn/TejHlCwzGe0lXqTiEoZgd4WPs6wpOd2/x/z8VBikJ6NGX vICo4MwAiNe/q/VjAgOV5KM= X-Google-Smtp-Source: APXvYqzGBjUqoR56Kdgr+abVQOcBBgk5bl/OXDV7hcyyNIBqoUDd60D743oqTD6boIwuEJDHXgvgYA== X-Received: by 2002:ac8:325c:: with SMTP id y28mr1642288qta.40.1552748842600; Sat, 16 Mar 2019 08:07:22 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id f6sm3606968qtf.66.2019.03.16.08.07.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 16 Mar 2019 08:07:22 -0700 (PDT) Date: Sat, 16 Mar 2019 12:07:18 -0300 From: Marcelo Schmitt To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com Subject: [PATCH v4 4/7] staging: iio: ad5933: change help rule message Message-ID: <20190316150718.kl27r5vqendxj3mw@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline 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 Remove the previous comment about direct access via sysfs which would lead one think ad5933 driver has limitations it actually doesn't. Signed-off-by: Marcelo Schmitt --- drivers/staging/iio/impedance-analyzer/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig b/drivers/staging/iio/impedance-analyzer/Kconfig index dd97b6bb3fd0..b9a679cdd146 100644 --- a/drivers/staging/iio/impedance-analyzer/Kconfig +++ b/drivers/staging/iio/impedance-analyzer/Kconfig @@ -10,7 +10,7 @@ config AD5933 select IIO_KFIFO_BUF help Say yes here to build support for Analog Devices Impedance Converter, - Network Analyzer, AD5933/4, provides direct access via sysfs. + Network Analyzer, AD5933/4. To compile this driver as a module, choose M here: the module will be called ad5933. From patchwork Sat Mar 16 15:07:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Schmitt X-Patchwork-Id: 10855903 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 0047114DE for ; Sat, 16 Mar 2019 15:07:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D897229CFB for ; Sat, 16 Mar 2019 15:07:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCF922A13D; Sat, 16 Mar 2019 15:07:42 +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 5BA3F29CFB for ; Sat, 16 Mar 2019 15:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727201AbfCPPHh (ORCPT ); Sat, 16 Mar 2019 11:07:37 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:45848 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726952AbfCPPHh (ORCPT ); Sat, 16 Mar 2019 11:07:37 -0400 Received: by mail-qk1-f195.google.com with SMTP id z76so7274071qkb.12; Sat, 16 Mar 2019 08:07:36 -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:mime-version:content-disposition :user-agent; bh=teRvH1G/SSs/cdMOyCk2l/NDhqU3BfU90tIYKAgSs+U=; b=N5k+RklAnPNQAvM/TrNx+2h7yhAQ4jXqy/Iukq81uMyL/axB3aAGt2rrL6qGMJLPts zm4SBSccPxBPRdjm9HEYl/7FRx8VsqhOlmRX1H+OcA7oWPXqegyZbjt7W6RyZw9Hndgs O4M37+jFi63dRbTTGrqwYPi3WJCIGLwueS+RN17Zi/gWUjEvW0g6njYz45V50kRohrLf yZICe6QQtoNB1tJrd8Jr3xK4v5RhfqvcI68lEGyTbvms+j0l7o5cbV6POYUhh+KOwSdS vC1fQFhuz/DVlJOCFLkPlJZocFh44GcxmhEUmci31GOjtUNar177CEYG7Bmpc4hEqfP+ RQTA== 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:mime-version :content-disposition:user-agent; bh=teRvH1G/SSs/cdMOyCk2l/NDhqU3BfU90tIYKAgSs+U=; b=M9CmPzWp92j3JWslTi8zemg4d/Xw8l5GiJgGQubDrEsNzq9VxxLNC4TBY0mzQz5C+N itC0zghNujAaO45nBS3vxjV8Vkq4ZMuurrqFofy2aejREiIMD7pSkj2wvRfsX+BnPqSs 3IkUXDtzxoidXfN7J3PVpgUKttLKbTdE6zcDraGdCsqPdy2TvTSTeL9e5IcaPExykJBx umkT+qE8Fe3Wnx3iA4s9UHNXlp1858p/iWTuP02ckFFQgIGk3aMroh2aDlK4ucGsPhyH fpKN/CvHVSr1XJ429C9W1qd0uSS/8o1L4r0X9DRb9u7WwMmGBB8FveH16jj5hYhH3yHI aAaw== X-Gm-Message-State: APjAAAUjIwTKChvzJO4v8ZOoRvSb1jXMctBYJkCbhZd+/ldkYgQCgBHU GIo65EiXZg/fYvCQ/Ijn0h4= X-Google-Smtp-Source: APXvYqzuQ4Nw66cHQIeJASrxV39PB+QIK0Jz+nX0F0bho8vuU9tftC+kivgzRhAR1iq/mvmUchWHmA== X-Received: by 2002:a37:a94c:: with SMTP id s73mr2912794qke.76.1552748856540; Sat, 16 Mar 2019 08:07:36 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id d20sm2754273qto.32.2019.03.16.08.07.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 16 Mar 2019 08:07:36 -0700 (PDT) Date: Sat, 16 Mar 2019 12:07:32 -0300 From: Marcelo Schmitt To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com Subject: [PATCH v4 5/7] staging: iio: ad5933: add ABI documentation Message-ID: <20190316150732.umr64uwhi2j4qi7k@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline 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 an ABI documentation for the ad5933 driver. Signed-off-by: Marcelo Schmitt --- .../sysfs-bus-iio-impedance-analyzer-ad5933 | 35 +++++++++++++++++++ .../sysfs-bus-iio-impedance-analyzer-ad5933 | 30 ---------------- 2 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933 delete mode 100644 drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 diff --git a/Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933 b/Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933 new file mode 100644 index 000000000000..a50aada68e1e --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-iio-impedance-analyzer-ad5933 @@ -0,0 +1,35 @@ +What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency_start +Date: March 2019 +KernelVersion: 3.1.0 +Contact: linux-iio@vger.kernel.org +Description: + Frequency sweep start frequency in Hz. + +What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency_increment +Date: March 2019 +KernelVersion: 3.1.0 +Contact: linux-iio@vger.kernel.org +Description: + Frequency increment in Hz (step size) between consecutive + frequency points along the sweep. + +What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_frequency_points +Date: March 2019 +KernelVersion: 3.1.0 +Contact: linux-iio@vger.kernel.org +Description: + Number of frequency points (steps) in the frequency sweep. + This value, in conjunction with the + out_altvoltageY_frequency_start and the + out_altvoltageY_frequency_increment, determines the frequency + sweep range for the sweep operation. + +What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_settling_cycles +Date: March 2019 +KernelVersion: 3.1.0 +Contact: linux-iio@vger.kernel.org +Description: + Number of output excitation cycles (settling time cycles) + that are allowed to pass through the unknown impedance, + after each frequency increment, and before the ADC is triggered + to perform a conversion sequence of the response signal. diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 b/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 deleted file mode 100644 index 79c7e88c64cd..000000000000 --- a/drivers/staging/iio/Documentation/sysfs-bus-iio-impedance-analyzer-ad5933 +++ /dev/null @@ -1,30 +0,0 @@ -What: /sys/bus/iio/devices/iio:deviceX/outY_freq_start -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - Frequency sweep start frequency in Hz. - -What: /sys/bus/iio/devices/iio:deviceX/outY_freq_increment -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - Frequency increment in Hz (step size) between consecutive - frequency points along the sweep. - -What: /sys/bus/iio/devices/iio:deviceX/outY_freq_points -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - Number of frequency points (steps) in the frequency sweep. - This value, in conjunction with the outY_freq_start and the - outY_freq_increment, determines the frequency sweep range - for the sweep operation. - -What: /sys/bus/iio/devices/iio:deviceX/outY_settling_cycles -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - Number of output excitation cycles (settling time cycles) - that are allowed to pass through the unknown impedance, - after each frequency increment, and before the ADC is triggered - to perform a conversion sequence of the response signal. From patchwork Sat Mar 16 15:07:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Schmitt X-Patchwork-Id: 10855905 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 CB38B1390 for ; Sat, 16 Mar 2019 15:08:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD24629CFB for ; Sat, 16 Mar 2019 15:08:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E4032A13D; Sat, 16 Mar 2019 15:08: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=-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 4435029CFB for ; Sat, 16 Mar 2019 15:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726842AbfCPPIA (ORCPT ); Sat, 16 Mar 2019 11:08:00 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:39382 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbfCPPIA (ORCPT ); Sat, 16 Mar 2019 11:08:00 -0400 Received: by mail-qt1-f196.google.com with SMTP id t28so13412264qte.6; Sat, 16 Mar 2019 08:07:59 -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:mime-version:content-disposition :user-agent; bh=QkDsX000mXzOHA9rU2Q24MGpb1izllLv6AOyp5o6NNk=; b=WAAydMNDZnQwzu7/BaYj2bSbl1yQnmurKptfGRP4rj1kR3PKJgwiQ8Yq7eZ9Rg9qtF dPypkZ0pogNAUSYUTdgOwnV4RLb8gMvMf3j9zd+c2tX0WVDAhdhf7i0jiwcrS5SgWral CgJPu+xvUxuAE8TwOAcOrV4xL9RIV5JMxidD2/yLjQkKB8JfY4EUjHT8v7k3vbL7uoKz /0DNUZ763RSkEY/z9ERGDktjDR+ntXInSZxpAFoUHdw/QQziuj25txFai59BZsl7+b+a zPg7cPezgrkmKQd/7/Q8RF3p23Yg9PBlaKbku2WA8YI01WZ49SN0vp3k8IHOYsO5M6Oz vCKg== 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:mime-version :content-disposition:user-agent; bh=QkDsX000mXzOHA9rU2Q24MGpb1izllLv6AOyp5o6NNk=; b=iD4GCCaMp+9K5ffFiBkcSmDuK7Y/g+Wm12BPD3mVggYwPDF5GMlWugMAuTqFh2BtLL 5tCiBwc7dOwy2lc0ORCveoIr0IBDMIef1eBRjNp1N1NclOXYOWfjFfU3Mw7AdrneTpjz BsvJN+cy+PC6FPfyVVguARB7kEm8m22vgGJ6P54yY14t9vBVr6rBd6cwrcEg2DwYoO/P V7uX6ujkvgVOZkA5DHDtjtMzRqiUJtRb4eq6LldH/1LLDT4RaTfSB9Y1RVh9A4Ojm1L1 4DylXajQyzWQPnLTvteBAEbrSGQ9kpYSsc9PA8Rk+6mXaw7fvc0QVQq2bi8d37VUfwMj HrQw== X-Gm-Message-State: APjAAAW1ydQMJeOYLhjV9Qvrhn0joOAqpH+6R8DKDADW7NojinAHcw4s k1ycEdmfmz2m6cYcWGPfIlA= X-Google-Smtp-Source: APXvYqzkAqmdb1Wmn2qDMCtKzm0cEsqd6ykyG5ybKjiRUIf927eYm6l8o7h1SD/fdUVlgRZW0B/bIw== X-Received: by 2002:ac8:28a8:: with SMTP id i37mr7274393qti.215.1552748879200; Sat, 16 Mar 2019 08:07:59 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id d17sm358360qtl.43.2019.03.16.08.07.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 16 Mar 2019 08:07:58 -0700 (PDT) Date: Sat, 16 Mar 2019 12:07:55 -0300 From: Marcelo Schmitt To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com Subject: [PATCH v4 6/7] staging: iio: ad5933: change attributes to match ABI Message-ID: <20190316150755.ssqh5b2f55ln4fq5@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline 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 Change device attributes' names to match ABI documentation. Names were chosen such that they tend to be similar to existing ABI so it should be easier to standardize them when necessary. Signed-off-by: Marcelo Schmitt --- .../staging/iio/impedance-analyzer/ad5933.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index d75bdfbf93de..262415bc659d 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -315,12 +315,12 @@ static ssize_t ad5933_store_frequency(struct device *dev, return ret ? ret : len; } -static IIO_DEVICE_ATTR(out_voltage0_freq_start, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_start, 0644, ad5933_show_frequency, ad5933_store_frequency, AD5933_REG_FREQ_START); -static IIO_DEVICE_ATTR(out_voltage0_freq_increment, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_increment, 0644, ad5933_show_frequency, ad5933_store_frequency, AD5933_REG_FREQ_INC); @@ -463,12 +463,12 @@ static IIO_DEVICE_ATTR(in_voltage0_scale_available, 0444, NULL, AD5933_IN_PGA_GAIN_AVAIL); -static IIO_DEVICE_ATTR(out_voltage0_freq_points, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_points, 0644, ad5933_show, ad5933_store, AD5933_FREQ_POINTS); -static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644, +static IIO_DEVICE_ATTR(out_altvoltage0_settling_cycles, 0644, ad5933_show, ad5933_store, AD5933_OUT_SETTLING_CYCLES); @@ -480,12 +480,12 @@ static IIO_DEVICE_ATTR(out_voltage0_settling_cycles, 0644, * don't create dedicated sysfs channel attributes for out0 and in0. */ static struct attribute *ad5933_attributes[] = { - &iio_dev_attr_out_voltage0_scale.dev_attr.attr, - &iio_dev_attr_out_voltage0_scale_available.dev_attr.attr, - &iio_dev_attr_out_voltage0_freq_start.dev_attr.attr, - &iio_dev_attr_out_voltage0_freq_increment.dev_attr.attr, - &iio_dev_attr_out_voltage0_freq_points.dev_attr.attr, - &iio_dev_attr_out_voltage0_settling_cycles.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_raw.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_scale_available.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_start.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_increment.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_points.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_settling_cycles.dev_attr.attr, &iio_dev_attr_in_voltage0_scale.dev_attr.attr, &iio_dev_attr_in_voltage0_scale_available.dev_attr.attr, NULL From patchwork Sat Mar 16 15:08:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Schmitt X-Patchwork-Id: 10855907 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 568341390 for ; Sat, 16 Mar 2019 15:08:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2887929CFB for ; Sat, 16 Mar 2019 15:08:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 197A52A13D; Sat, 16 Mar 2019 15:08:22 +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 96CB929CFB for ; Sat, 16 Mar 2019 15:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726713AbfCPPIT (ORCPT ); Sat, 16 Mar 2019 11:08:19 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:46041 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726064AbfCPPIS (ORCPT ); Sat, 16 Mar 2019 11:08:18 -0400 Received: by mail-qt1-f193.google.com with SMTP id v20so13378211qtv.12; Sat, 16 Mar 2019 08:08:17 -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:mime-version:content-disposition :user-agent; bh=kG27szAh2fUA7KcYee5cRJAUMyM8i9ciOPg4nW6iLfE=; b=kkAZpReEjBx3SQov7syRZd3q+7BgLjOVfchIK6tdjueYR4bb++XcDkZP0xj6phsiHt kX1aCXdWAb6iORbvUrkvxno1uIx0nyI6xiVFhzvujD/RhUlAGOhsKdvmefZ8NRbhy1Cj 8x0HqdWn6GdFGFfzDRv5aVYLN4CLVVsuGotd6pJy7+rV3kdR7J+XqM0/OlO3yhPzwMFb qhnDYGg8F/8+Ltxf+ySNHYUcOtvYi/u/6CR4bQREIdZBq4teXxqGMOuy04rndhMsvHFi C4UkOUZlpPNrvxHP9f1+ruuZCErX4KZnGxvmkfilnGEzPElnE19ffC3Kv8DrWYKpCEWS QwUA== 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:mime-version :content-disposition:user-agent; bh=kG27szAh2fUA7KcYee5cRJAUMyM8i9ciOPg4nW6iLfE=; b=qh7+5Ls6o5ef7U47rV9bKlhoL9tlR6Jh6J5arnUD1SlGQeUIc5EBiwoZ2C+tjai9G7 FtHO2O2j5H2qJaByP0w2xme3KZK5/dgYbGDWw8VkbUowfTNwPDltTDaU8pJhCfAdoxBY qVU7/QMw+4fPUlDYg7dUb4OzPg8APbjrBINNapbU8oL8Rf/0NwWxqKFUYuJPPRROKgGw 6QjJEKg1tKnBLKRC0caXMdXOS5xJmNFd4/uRck4YflXJPvB4NkoAIech9Pz2xjWSzSlN /bD/XKKYhAt0aFGQGjWqxZmZeSF7QP+EsTjSxAwDKwMouVh4xFP7+0ymoyvymWMMYyUq MBnQ== X-Gm-Message-State: APjAAAWi+e2Ex6U9fUXoI3LHmeYdX2xjLAoXJsfF7zILJ5jPwCUhmMiJ 3MSdbF1S+3QvjZyqd5sPxfE= X-Google-Smtp-Source: APXvYqxAcI73GAcXhzTw7dr4p3l3Tbai5umn4vkEyBtHfNPXGCfY917+jTPWyNphwuGcu2Iv96rMtg== X-Received: by 2002:a0c:9e45:: with SMTP id z5mr6662673qve.57.1552748896120; Sat, 16 Mar 2019 08:08:16 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id y21sm3797438qth.90.2019.03.16.08.08.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 16 Mar 2019 08:08:15 -0700 (PDT) Date: Sat, 16 Mar 2019 12:08:11 -0300 From: Marcelo Schmitt To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com Subject: [PATCH v4 7/7] staging: iio: ad5933: move out of staging Message-ID: <20190316150811.hlwvltiplloywkng@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline 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 ad5933 impedance-analyzer driver from staging to mainline. The ad5933 is a high precision impedance converter system solution that combines an on-board frequency generator with an analog-to-digital converter (ADC). This driver was designed to be compatible with both ad5933 and ad5934 chips. Signed-off-by: Marcelo Schmitt --- drivers/iio/impedance-analyzer/Kconfig | 18 + drivers/iio/impedance-analyzer/Makefile | 5 + drivers/iio/impedance-analyzer/ad5933.c | 811 ++++++++++++++++++ .../staging/iio/impedance-analyzer/Kconfig | 18 - .../staging/iio/impedance-analyzer/Makefile | 5 - .../staging/iio/impedance-analyzer/ad5933.c | 811 ------------------ 6 files changed, 834 insertions(+), 834 deletions(-) create mode 100644 drivers/iio/impedance-analyzer/Kconfig create mode 100644 drivers/iio/impedance-analyzer/Makefile create mode 100644 drivers/iio/impedance-analyzer/ad5933.c delete mode 100644 drivers/staging/iio/impedance-analyzer/Kconfig delete mode 100644 drivers/staging/iio/impedance-analyzer/Makefile delete mode 100644 drivers/staging/iio/impedance-analyzer/ad5933.c diff --git a/drivers/iio/impedance-analyzer/Kconfig b/drivers/iio/impedance-analyzer/Kconfig new file mode 100644 index 000000000000..b9a679cdd146 --- /dev/null +++ b/drivers/iio/impedance-analyzer/Kconfig @@ -0,0 +1,18 @@ +# +# Impedance Converter, Network Analyzer drivers +# +menu "Network Analyzer, Impedance Converters" + +config AD5933 + tristate "Analog Devices AD5933, AD5934 driver" + depends on I2C + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Say yes here to build support for Analog Devices Impedance Converter, + Network Analyzer, AD5933/4. + + To compile this driver as a module, choose M here: the + module will be called ad5933. + +endmenu diff --git a/drivers/iio/impedance-analyzer/Makefile b/drivers/iio/impedance-analyzer/Makefile new file mode 100644 index 000000000000..7604d786583e --- /dev/null +++ b/drivers/iio/impedance-analyzer/Makefile @@ -0,0 +1,5 @@ +# +# Makefile for Impedance Converter, Network Analyzer drivers +# + +obj-$(CONFIG_AD5933) += ad5933.o diff --git a/drivers/iio/impedance-analyzer/ad5933.c b/drivers/iio/impedance-analyzer/ad5933.c new file mode 100644 index 000000000000..262415bc659d --- /dev/null +++ b/drivers/iio/impedance-analyzer/ad5933.c @@ -0,0 +1,811 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AD5933 AD5934 Impedance Converter, Network Analyzer + * + * Copyright 2011 Analog Devices Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* AD5933/AD5934 Registers */ +#define AD5933_REG_CONTROL_HB 0x80 /* R/W, 1 byte */ +#define AD5933_REG_CONTROL_LB 0x81 /* R/W, 1 byte */ +#define AD5933_REG_FREQ_START 0x82 /* R/W, 3 bytes */ +#define AD5933_REG_FREQ_INC 0x85 /* R/W, 3 bytes */ +#define AD5933_REG_INC_NUM 0x88 /* R/W, 2 bytes, 9 bit */ +#define AD5933_REG_SETTLING_CYCLES 0x8A /* R/W, 2 bytes */ +#define AD5933_REG_STATUS 0x8F /* R, 1 byte */ +#define AD5933_REG_TEMP_DATA 0x92 /* R, 2 bytes*/ +#define AD5933_REG_REAL_DATA 0x94 /* R, 2 bytes*/ +#define AD5933_REG_IMAG_DATA 0x96 /* R, 2 bytes*/ + +/* AD5933_REG_CONTROL_HB Bits */ +#define AD5933_CTRL_INIT_START_FREQ (0x1 << 4) +#define AD5933_CTRL_START_SWEEP (0x2 << 4) +#define AD5933_CTRL_INC_FREQ (0x3 << 4) +#define AD5933_CTRL_REPEAT_FREQ (0x4 << 4) +#define AD5933_CTRL_MEASURE_TEMP (0x9 << 4) +#define AD5933_CTRL_POWER_DOWN (0xA << 4) +#define AD5933_CTRL_STANDBY (0xB << 4) + +#define AD5933_CTRL_RANGE_2000mVpp (0x0 << 1) +#define AD5933_CTRL_RANGE_200mVpp (0x1 << 1) +#define AD5933_CTRL_RANGE_400mVpp (0x2 << 1) +#define AD5933_CTRL_RANGE_1000mVpp (0x3 << 1) +#define AD5933_CTRL_RANGE(x) ((x) << 1) + +#define AD5933_CTRL_PGA_GAIN_1 (0x1 << 0) +#define AD5933_CTRL_PGA_GAIN_5 (0x0 << 0) + +/* AD5933_REG_CONTROL_LB Bits */ +#define AD5933_CTRL_RESET (0x1 << 4) +#define AD5933_CTRL_INT_SYSCLK (0x0 << 3) +#define AD5933_CTRL_EXT_SYSCLK (0x1 << 3) + +/* AD5933_REG_STATUS Bits */ +#define AD5933_STAT_TEMP_VALID (0x1 << 0) +#define AD5933_STAT_DATA_VALID (0x1 << 1) +#define AD5933_STAT_SWEEP_DONE (0x1 << 2) + +/* I2C Block Commands */ +#define AD5933_I2C_BLOCK_WRITE 0xA0 +#define AD5933_I2C_BLOCK_READ 0xA1 +#define AD5933_I2C_ADDR_POINTER 0xB0 + +/* Device Specs */ +#define AD5933_INT_OSC_FREQ_Hz 16776000 +#define AD5933_MAX_OUTPUT_FREQ_Hz 100000 +#define AD5933_MAX_RETRIES 100 + +#define AD5933_OUT_RANGE 1 +#define AD5933_OUT_RANGE_AVAIL 2 +#define AD5933_OUT_SETTLING_CYCLES 3 +#define AD5933_IN_PGA_GAIN 4 +#define AD5933_IN_PGA_GAIN_AVAIL 5 +#define AD5933_FREQ_POINTS 6 + +#define AD5933_POLL_TIME_ms 10 +#define AD5933_INIT_EXCITATION_TIME_ms 100 + +struct ad5933_state { + struct i2c_client *client; + struct regulator *reg; + struct clk *mclk; + struct delayed_work work; + struct mutex lock; /* Protect sensor state */ + unsigned long mclk_hz; + unsigned char ctrl_hb; + unsigned char ctrl_lb; + unsigned int range_avail[4]; + unsigned short vref_mv; + unsigned short settling_cycles; + unsigned short freq_points; + unsigned int freq_start; + unsigned int freq_inc; + unsigned int state; + unsigned int poll_time_jiffies; +}; + +#define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \ + _scan_index, _realbits) { \ + .type = (_type), \ + .extend_name = (_extend_name), \ + .info_mask_separate = (_info_mask_separate), \ + .address = (_address), \ + .scan_index = (_scan_index), \ + .scan_type = { \ + .sign = 's', \ + .realbits = (_realbits), \ + .storagebits = 16, \ + }, \ +} + +static const struct iio_chan_spec ad5933_channels[] = { + AD5933_CHANNEL(IIO_TEMP, NULL, BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), AD5933_REG_TEMP_DATA, -1, 14), + /* Ring Channels */ + AD5933_CHANNEL(IIO_VOLTAGE, "real", 0, AD5933_REG_REAL_DATA, 0, 16), + AD5933_CHANNEL(IIO_VOLTAGE, "imag", 0, AD5933_REG_IMAG_DATA, 1, 16), +}; + +static int ad5933_i2c_write(struct i2c_client *client, u8 reg, u8 len, u8 *data) +{ + int ret; + + while (len--) { + ret = i2c_smbus_write_byte_data(client, reg++, *data++); + if (ret < 0) { + dev_err(&client->dev, "I2C write error\n"); + return ret; + } + } + return 0; +} + +static int ad5933_i2c_read(struct i2c_client *client, u8 reg, u8 len, u8 *data) +{ + int ret; + + while (len--) { + ret = i2c_smbus_read_byte_data(client, reg++); + if (ret < 0) { + dev_err(&client->dev, "I2C read error\n"); + return ret; + } + *data++ = ret; + } + return 0; +} + +static int ad5933_cmd(struct ad5933_state *st, unsigned char cmd) +{ + unsigned char dat = st->ctrl_hb | cmd; + + return ad5933_i2c_write(st->client, + AD5933_REG_CONTROL_HB, 1, &dat); +} + +static int ad5933_reset(struct ad5933_state *st) +{ + unsigned char dat = st->ctrl_lb | AD5933_CTRL_RESET; + + return ad5933_i2c_write(st->client, + AD5933_REG_CONTROL_LB, 1, &dat); +} + +static int ad5933_wait_busy(struct ad5933_state *st, unsigned char event) +{ + unsigned char val, timeout = AD5933_MAX_RETRIES; + int ret; + + while (timeout--) { + ret = ad5933_i2c_read(st->client, AD5933_REG_STATUS, 1, &val); + if (ret < 0) + return ret; + if (val & event) + return val; + cpu_relax(); + mdelay(1); + } + + return -EAGAIN; +} + +static int ad5933_set_freq(struct ad5933_state *st, + unsigned int reg, unsigned long freq) +{ + unsigned long long freqreg; + union { + __be32 d32; + u8 d8[4]; + } dat; + + freqreg = (u64)freq * (u64)(1 << 27); + do_div(freqreg, st->mclk_hz / 4); + + switch (reg) { + case AD5933_REG_FREQ_START: + st->freq_start = freq; + break; + case AD5933_REG_FREQ_INC: + st->freq_inc = freq; + break; + default: + return -EINVAL; + } + + dat.d32 = cpu_to_be32(freqreg); + return ad5933_i2c_write(st->client, reg, 3, &dat.d8[1]); +} + +static int ad5933_setup(struct ad5933_state *st) +{ + __be16 dat; + int ret; + + ret = ad5933_reset(st); + if (ret < 0) + return ret; + + ret = ad5933_set_freq(st, AD5933_REG_FREQ_START, 10000); + if (ret < 0) + return ret; + + ret = ad5933_set_freq(st, AD5933_REG_FREQ_INC, 200); + if (ret < 0) + return ret; + + st->settling_cycles = 10; + dat = cpu_to_be16(st->settling_cycles); + + ret = ad5933_i2c_write(st->client, + AD5933_REG_SETTLING_CYCLES, + 2, (u8 *)&dat); + if (ret < 0) + return ret; + + st->freq_points = 100; + dat = cpu_to_be16(st->freq_points); + + return ad5933_i2c_write(st->client, AD5933_REG_INC_NUM, 2, (u8 *)&dat); +} + +static void ad5933_calc_out_ranges(struct ad5933_state *st) +{ + int i; + unsigned int normalized_3v3[4] = {1980, 198, 383, 970}; + + for (i = 0; i < 4; i++) + st->range_avail[i] = normalized_3v3[i] * st->vref_mv / 3300; +} + +/* + * handles: AD5933_REG_FREQ_START and AD5933_REG_FREQ_INC + */ + +static ssize_t ad5933_show_frequency(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ad5933_state *st = iio_priv(indio_dev); + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + int ret; + unsigned long long freqreg; + union { + __be32 d32; + u8 d8[4]; + } dat; + + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + ret = ad5933_i2c_read(st->client, this_attr->address, 3, &dat.d8[1]); + iio_device_release_direct_mode(indio_dev); + if (ret < 0) + return ret; + + freqreg = be32_to_cpu(dat.d32) & 0xFFFFFF; + + freqreg = (u64)freqreg * (u64)(st->mclk_hz / 4); + do_div(freqreg, 1 << 27); + + return sprintf(buf, "%d\n", (int)freqreg); +} + +static ssize_t ad5933_store_frequency(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ad5933_state *st = iio_priv(indio_dev); + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + unsigned long val; + int ret; + + ret = kstrtoul(buf, 10, &val); + if (ret) + return ret; + + if (val > AD5933_MAX_OUTPUT_FREQ_Hz) + return -EINVAL; + + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + ret = ad5933_set_freq(st, this_attr->address, val); + iio_device_release_direct_mode(indio_dev); + + return ret ? ret : len; +} + +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_start, 0644, + ad5933_show_frequency, + ad5933_store_frequency, + AD5933_REG_FREQ_START); + +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_increment, 0644, + ad5933_show_frequency, + ad5933_store_frequency, + AD5933_REG_FREQ_INC); + +static ssize_t ad5933_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ad5933_state *st = iio_priv(indio_dev); + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + int ret = 0, len = 0; + + mutex_lock(&st->lock); + switch ((u32)this_attr->address) { + case AD5933_OUT_RANGE: + len = sprintf(buf, "%u\n", + st->range_avail[(st->ctrl_hb >> 1) & 0x3]); + break; + case AD5933_OUT_RANGE_AVAIL: + len = sprintf(buf, "%u %u %u %u\n", st->range_avail[0], + st->range_avail[3], st->range_avail[2], + st->range_avail[1]); + break; + case AD5933_OUT_SETTLING_CYCLES: + len = sprintf(buf, "%d\n", st->settling_cycles); + break; + case AD5933_IN_PGA_GAIN: + len = sprintf(buf, "%s\n", + (st->ctrl_hb & AD5933_CTRL_PGA_GAIN_1) ? + "1" : "0.2"); + break; + case AD5933_IN_PGA_GAIN_AVAIL: + len = sprintf(buf, "1 0.2\n"); + break; + case AD5933_FREQ_POINTS: + len = sprintf(buf, "%d\n", st->freq_points); + break; + default: + ret = -EINVAL; + } + + mutex_unlock(&st->lock); + return ret ? ret : len; +} + +static ssize_t ad5933_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct ad5933_state *st = iio_priv(indio_dev); + struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); + u16 val; + int i, ret = 0; + __be16 dat; + + if (this_attr->address != AD5933_IN_PGA_GAIN) { + ret = kstrtou16(buf, 10, &val); + if (ret) + return ret; + } + + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + mutex_lock(&st->lock); + switch ((u32)this_attr->address) { + case AD5933_OUT_RANGE: + ret = -EINVAL; + for (i = 0; i < 4; i++) + if (val == st->range_avail[i]) { + st->ctrl_hb &= ~AD5933_CTRL_RANGE(0x3); + st->ctrl_hb |= AD5933_CTRL_RANGE(i); + ret = ad5933_cmd(st, 0); + break; + } + break; + case AD5933_IN_PGA_GAIN: + if (sysfs_streq(buf, "1")) { + st->ctrl_hb |= AD5933_CTRL_PGA_GAIN_1; + } else if (sysfs_streq(buf, "0.2")) { + st->ctrl_hb &= ~AD5933_CTRL_PGA_GAIN_1; + } else { + ret = -EINVAL; + break; + } + ret = ad5933_cmd(st, 0); + break; + case AD5933_OUT_SETTLING_CYCLES: + val = clamp(val, (u16)0, (u16)0x7FF); + st->settling_cycles = val; + + /* 2x, 4x handling, see datasheet */ + if (val > 1022) + val = (val >> 2) | (3 << 9); + else if (val > 511) + val = (val >> 1) | (1 << 9); + + dat = cpu_to_be16(val); + ret = ad5933_i2c_write(st->client, + AD5933_REG_SETTLING_CYCLES, + 2, (u8 *)&dat); + break; + case AD5933_FREQ_POINTS: + val = clamp(val, (u16)0, (u16)511); + st->freq_points = val; + + dat = cpu_to_be16(val); + ret = ad5933_i2c_write(st->client, AD5933_REG_INC_NUM, 2, + (u8 *)&dat); + break; + default: + ret = -EINVAL; + } + + mutex_unlock(&st->lock); + iio_device_release_direct_mode(indio_dev); + return ret ? ret : len; +} + +static IIO_DEVICE_ATTR(out_voltage0_scale, 0644, + ad5933_show, + ad5933_store, + AD5933_OUT_RANGE); + +static IIO_DEVICE_ATTR(out_voltage0_scale_available, 0444, + ad5933_show, + NULL, + AD5933_OUT_RANGE_AVAIL); + +static IIO_DEVICE_ATTR(in_voltage0_scale, 0644, + ad5933_show, + ad5933_store, + AD5933_IN_PGA_GAIN); + +static IIO_DEVICE_ATTR(in_voltage0_scale_available, 0444, + ad5933_show, + NULL, + AD5933_IN_PGA_GAIN_AVAIL); + +static IIO_DEVICE_ATTR(out_altvoltage0_frequency_points, 0644, + ad5933_show, + ad5933_store, + AD5933_FREQ_POINTS); + +static IIO_DEVICE_ATTR(out_altvoltage0_settling_cycles, 0644, + ad5933_show, + ad5933_store, + AD5933_OUT_SETTLING_CYCLES); + +/* + * note: + * ideally we would handle the scale attributes via the iio_info + * (read|write)_raw methods, however this part is a untypical since we + * don't create dedicated sysfs channel attributes for out0 and in0. + */ +static struct attribute *ad5933_attributes[] = { + &iio_dev_attr_out_altvoltage0_raw.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_scale_available.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_start.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_increment.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_frequency_points.dev_attr.attr, + &iio_dev_attr_out_altvoltage0_settling_cycles.dev_attr.attr, + &iio_dev_attr_in_voltage0_scale.dev_attr.attr, + &iio_dev_attr_in_voltage0_scale_available.dev_attr.attr, + NULL +}; + +static const struct attribute_group ad5933_attribute_group = { + .attrs = ad5933_attributes, +}; + +static int ad5933_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long m) +{ + struct ad5933_state *st = iio_priv(indio_dev); + __be16 dat; + int ret; + + switch (m) { + case IIO_CHAN_INFO_RAW: + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + ret = ad5933_cmd(st, AD5933_CTRL_MEASURE_TEMP); + if (ret < 0) + goto out; + ret = ad5933_wait_busy(st, AD5933_STAT_TEMP_VALID); + if (ret < 0) + goto out; + + ret = ad5933_i2c_read(st->client, + AD5933_REG_TEMP_DATA, + 2, (u8 *)&dat); + if (ret < 0) + goto out; + iio_device_release_direct_mode(indio_dev); + *val = sign_extend32(be16_to_cpu(dat), 13); + + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 1000; + *val2 = 5; + return IIO_VAL_FRACTIONAL_LOG2; + } + + return -EINVAL; +out: + iio_device_release_direct_mode(indio_dev); + return ret; +} + +static const struct iio_info ad5933_info = { + .read_raw = ad5933_read_raw, + .attrs = &ad5933_attribute_group, +}; + +static int ad5933_ring_preenable(struct iio_dev *indio_dev) +{ + struct ad5933_state *st = iio_priv(indio_dev); + int ret; + + if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) + return -EINVAL; + + ret = ad5933_reset(st); + if (ret < 0) + return ret; + + ret = ad5933_cmd(st, AD5933_CTRL_STANDBY); + if (ret < 0) + return ret; + + ret = ad5933_cmd(st, AD5933_CTRL_INIT_START_FREQ); + if (ret < 0) + return ret; + + st->state = AD5933_CTRL_INIT_START_FREQ; + + return 0; +} + +static int ad5933_ring_postenable(struct iio_dev *indio_dev) +{ + struct ad5933_state *st = iio_priv(indio_dev); + + /* + * AD5933_CTRL_INIT_START_FREQ: + * High Q complex circuits require a long time to reach steady state. + * To facilitate the measurement of such impedances, this mode allows + * the user full control of the settling time requirement before + * entering start frequency sweep mode where the impedance measurement + * takes place. In this mode the impedance is excited with the + * programmed start frequency (ad5933_ring_preenable), + * but no measurement takes place. + */ + + schedule_delayed_work(&st->work, + msecs_to_jiffies(AD5933_INIT_EXCITATION_TIME_ms)); + return 0; +} + +static int ad5933_ring_postdisable(struct iio_dev *indio_dev) +{ + struct ad5933_state *st = iio_priv(indio_dev); + + cancel_delayed_work_sync(&st->work); + return ad5933_cmd(st, AD5933_CTRL_POWER_DOWN); +} + +static const struct iio_buffer_setup_ops ad5933_ring_setup_ops = { + .preenable = ad5933_ring_preenable, + .postenable = ad5933_ring_postenable, + .postdisable = ad5933_ring_postdisable, +}; + +static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev) +{ + struct iio_buffer *buffer; + + buffer = iio_kfifo_allocate(); + if (!buffer) + return -ENOMEM; + + iio_device_attach_buffer(indio_dev, buffer); + + /* Ring buffer functions - here trigger setup related */ + indio_dev->setup_ops = &ad5933_ring_setup_ops; + + return 0; +} + +static void ad5933_work(struct work_struct *work) +{ + struct ad5933_state *st = container_of(work, + struct ad5933_state, work.work); + struct iio_dev *indio_dev = i2c_get_clientdata(st->client); + __be16 buf[2]; + int val[2]; + unsigned char status; + int ret; + + if (st->state == AD5933_CTRL_INIT_START_FREQ) { + /* start sweep */ + ad5933_cmd(st, AD5933_CTRL_START_SWEEP); + st->state = AD5933_CTRL_START_SWEEP; + schedule_delayed_work(&st->work, st->poll_time_jiffies); + return; + } + + ret = ad5933_i2c_read(st->client, AD5933_REG_STATUS, 1, &status); + if (ret) + return; + + if (status & AD5933_STAT_DATA_VALID) { + int scan_count = bitmap_weight(indio_dev->active_scan_mask, + indio_dev->masklength); + ret = ad5933_i2c_read(st->client, + test_bit(1, indio_dev->active_scan_mask) ? + AD5933_REG_REAL_DATA : AD5933_REG_IMAG_DATA, + scan_count * 2, (u8 *)buf); + if (ret) + return; + + if (scan_count == 2) { + val[0] = be16_to_cpu(buf[0]); + val[1] = be16_to_cpu(buf[1]); + } else { + val[0] = be16_to_cpu(buf[0]); + } + iio_push_to_buffers(indio_dev, val); + } else { + /* no data available - try again later */ + schedule_delayed_work(&st->work, st->poll_time_jiffies); + return; + } + + if (status & AD5933_STAT_SWEEP_DONE) { + /* + * last sample received - power down do + * nothing until the ring enable is toggled + */ + ad5933_cmd(st, AD5933_CTRL_POWER_DOWN); + } else { + /* we just received a valid datum, move on to the next */ + ad5933_cmd(st, AD5933_CTRL_INC_FREQ); + schedule_delayed_work(&st->work, st->poll_time_jiffies); + } +} + +static int ad5933_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int ret; + struct ad5933_state *st; + struct iio_dev *indio_dev; + unsigned long ext_clk_hz = 0; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); + if (!indio_dev) + return -ENOMEM; + + st = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + st->client = client; + + mutex_init(&st->lock); + + st->reg = devm_regulator_get(&client->dev, "vdd"); + if (IS_ERR(st->reg)) + return PTR_ERR(st->reg); + + ret = regulator_enable(st->reg); + if (ret) { + dev_err(&client->dev, "Failed to enable specified VDD supply\n"); + return ret; + } + ret = regulator_get_voltage(st->reg); + + if (ret < 0) + goto error_disable_reg; + + st->vref_mv = ret / 1000; + + st->mclk = devm_clk_get(&client->dev, "mclk"); + if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT) { + ret = PTR_ERR(st->mclk); + goto error_disable_reg; + } + + if (!IS_ERR(st->mclk)) { + ret = clk_prepare_enable(st->mclk); + if (ret < 0) + goto error_disable_reg; + ext_clk_hz = clk_get_rate(st->mclk); + } + + if (ext_clk_hz) { + st->mclk_hz = ext_clk_hz; + st->ctrl_lb = AD5933_CTRL_EXT_SYSCLK; + } else { + st->mclk_hz = AD5933_INT_OSC_FREQ_Hz; + st->ctrl_lb = AD5933_CTRL_INT_SYSCLK; + } + + ad5933_calc_out_ranges(st); + INIT_DELAYED_WORK(&st->work, ad5933_work); + st->poll_time_jiffies = msecs_to_jiffies(AD5933_POLL_TIME_ms); + + indio_dev->dev.parent = &client->dev; + indio_dev->info = &ad5933_info; + indio_dev->name = id->name; + indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); + indio_dev->channels = ad5933_channels; + indio_dev->num_channels = ARRAY_SIZE(ad5933_channels); + + ret = ad5933_register_ring_funcs_and_init(indio_dev); + if (ret) + goto error_disable_mclk; + + ret = ad5933_setup(st); + if (ret) + goto error_unreg_ring; + + ret = iio_device_register(indio_dev); + if (ret) + goto error_unreg_ring; + + return 0; + +error_unreg_ring: + iio_kfifo_free(indio_dev->buffer); +error_disable_mclk: + clk_disable_unprepare(st->mclk); +error_disable_reg: + regulator_disable(st->reg); + + return ret; +} + +static int ad5933_remove(struct i2c_client *client) +{ + struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct ad5933_state *st = iio_priv(indio_dev); + + iio_device_unregister(indio_dev); + iio_kfifo_free(indio_dev->buffer); + regulator_disable(st->reg); + clk_disable_unprepare(st->mclk); + + return 0; +} + +static const struct i2c_device_id ad5933_id[] = { + { "ad5933", 0 }, + { "ad5934", 0 }, + {} +}; + +MODULE_DEVICE_TABLE(i2c, ad5933_id); + +static const struct of_device_id ad5933_of_match[] = { + { .compatible = "adi,ad5933" }, + { .compatible = "adi,ad5934" }, + { }, +}; + +MODULE_DEVICE_TABLE(of, ad5933_of_match); + +static struct i2c_driver ad5933_driver = { + .driver = { + .name = "ad5933", + .of_match_table = ad5933_of_match, + }, + .probe = ad5933_probe, + .remove = ad5933_remove, + .id_table = ad5933_id, +}; +module_i2c_driver(ad5933_driver); + +MODULE_AUTHOR("Michael Hennerich "); +MODULE_DESCRIPTION("Analog Devices AD5933 Impedance Conv. Network Analyzer"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig b/drivers/staging/iio/impedance-analyzer/Kconfig deleted file mode 100644 index b9a679cdd146..000000000000 --- a/drivers/staging/iio/impedance-analyzer/Kconfig +++ /dev/null @@ -1,18 +0,0 @@ -# -# Impedance Converter, Network Analyzer drivers -# -menu "Network Analyzer, Impedance Converters" - -config AD5933 - tristate "Analog Devices AD5933, AD5934 driver" - depends on I2C - select IIO_BUFFER - select IIO_KFIFO_BUF - help - Say yes here to build support for Analog Devices Impedance Converter, - Network Analyzer, AD5933/4. - - To compile this driver as a module, choose M here: the - module will be called ad5933. - -endmenu diff --git a/drivers/staging/iio/impedance-analyzer/Makefile b/drivers/staging/iio/impedance-analyzer/Makefile deleted file mode 100644 index 7604d786583e..000000000000 --- a/drivers/staging/iio/impedance-analyzer/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# -# Makefile for Impedance Converter, Network Analyzer drivers -# - -obj-$(CONFIG_AD5933) += ad5933.o diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c deleted file mode 100644 index 262415bc659d..000000000000 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ /dev/null @@ -1,811 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * AD5933 AD5934 Impedance Converter, Network Analyzer - * - * Copyright 2011 Analog Devices Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -/* AD5933/AD5934 Registers */ -#define AD5933_REG_CONTROL_HB 0x80 /* R/W, 1 byte */ -#define AD5933_REG_CONTROL_LB 0x81 /* R/W, 1 byte */ -#define AD5933_REG_FREQ_START 0x82 /* R/W, 3 bytes */ -#define AD5933_REG_FREQ_INC 0x85 /* R/W, 3 bytes */ -#define AD5933_REG_INC_NUM 0x88 /* R/W, 2 bytes, 9 bit */ -#define AD5933_REG_SETTLING_CYCLES 0x8A /* R/W, 2 bytes */ -#define AD5933_REG_STATUS 0x8F /* R, 1 byte */ -#define AD5933_REG_TEMP_DATA 0x92 /* R, 2 bytes*/ -#define AD5933_REG_REAL_DATA 0x94 /* R, 2 bytes*/ -#define AD5933_REG_IMAG_DATA 0x96 /* R, 2 bytes*/ - -/* AD5933_REG_CONTROL_HB Bits */ -#define AD5933_CTRL_INIT_START_FREQ (0x1 << 4) -#define AD5933_CTRL_START_SWEEP (0x2 << 4) -#define AD5933_CTRL_INC_FREQ (0x3 << 4) -#define AD5933_CTRL_REPEAT_FREQ (0x4 << 4) -#define AD5933_CTRL_MEASURE_TEMP (0x9 << 4) -#define AD5933_CTRL_POWER_DOWN (0xA << 4) -#define AD5933_CTRL_STANDBY (0xB << 4) - -#define AD5933_CTRL_RANGE_2000mVpp (0x0 << 1) -#define AD5933_CTRL_RANGE_200mVpp (0x1 << 1) -#define AD5933_CTRL_RANGE_400mVpp (0x2 << 1) -#define AD5933_CTRL_RANGE_1000mVpp (0x3 << 1) -#define AD5933_CTRL_RANGE(x) ((x) << 1) - -#define AD5933_CTRL_PGA_GAIN_1 (0x1 << 0) -#define AD5933_CTRL_PGA_GAIN_5 (0x0 << 0) - -/* AD5933_REG_CONTROL_LB Bits */ -#define AD5933_CTRL_RESET (0x1 << 4) -#define AD5933_CTRL_INT_SYSCLK (0x0 << 3) -#define AD5933_CTRL_EXT_SYSCLK (0x1 << 3) - -/* AD5933_REG_STATUS Bits */ -#define AD5933_STAT_TEMP_VALID (0x1 << 0) -#define AD5933_STAT_DATA_VALID (0x1 << 1) -#define AD5933_STAT_SWEEP_DONE (0x1 << 2) - -/* I2C Block Commands */ -#define AD5933_I2C_BLOCK_WRITE 0xA0 -#define AD5933_I2C_BLOCK_READ 0xA1 -#define AD5933_I2C_ADDR_POINTER 0xB0 - -/* Device Specs */ -#define AD5933_INT_OSC_FREQ_Hz 16776000 -#define AD5933_MAX_OUTPUT_FREQ_Hz 100000 -#define AD5933_MAX_RETRIES 100 - -#define AD5933_OUT_RANGE 1 -#define AD5933_OUT_RANGE_AVAIL 2 -#define AD5933_OUT_SETTLING_CYCLES 3 -#define AD5933_IN_PGA_GAIN 4 -#define AD5933_IN_PGA_GAIN_AVAIL 5 -#define AD5933_FREQ_POINTS 6 - -#define AD5933_POLL_TIME_ms 10 -#define AD5933_INIT_EXCITATION_TIME_ms 100 - -struct ad5933_state { - struct i2c_client *client; - struct regulator *reg; - struct clk *mclk; - struct delayed_work work; - struct mutex lock; /* Protect sensor state */ - unsigned long mclk_hz; - unsigned char ctrl_hb; - unsigned char ctrl_lb; - unsigned int range_avail[4]; - unsigned short vref_mv; - unsigned short settling_cycles; - unsigned short freq_points; - unsigned int freq_start; - unsigned int freq_inc; - unsigned int state; - unsigned int poll_time_jiffies; -}; - -#define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \ - _scan_index, _realbits) { \ - .type = (_type), \ - .extend_name = (_extend_name), \ - .info_mask_separate = (_info_mask_separate), \ - .address = (_address), \ - .scan_index = (_scan_index), \ - .scan_type = { \ - .sign = 's', \ - .realbits = (_realbits), \ - .storagebits = 16, \ - }, \ -} - -static const struct iio_chan_spec ad5933_channels[] = { - AD5933_CHANNEL(IIO_TEMP, NULL, BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_SCALE), AD5933_REG_TEMP_DATA, -1, 14), - /* Ring Channels */ - AD5933_CHANNEL(IIO_VOLTAGE, "real", 0, AD5933_REG_REAL_DATA, 0, 16), - AD5933_CHANNEL(IIO_VOLTAGE, "imag", 0, AD5933_REG_IMAG_DATA, 1, 16), -}; - -static int ad5933_i2c_write(struct i2c_client *client, u8 reg, u8 len, u8 *data) -{ - int ret; - - while (len--) { - ret = i2c_smbus_write_byte_data(client, reg++, *data++); - if (ret < 0) { - dev_err(&client->dev, "I2C write error\n"); - return ret; - } - } - return 0; -} - -static int ad5933_i2c_read(struct i2c_client *client, u8 reg, u8 len, u8 *data) -{ - int ret; - - while (len--) { - ret = i2c_smbus_read_byte_data(client, reg++); - if (ret < 0) { - dev_err(&client->dev, "I2C read error\n"); - return ret; - } - *data++ = ret; - } - return 0; -} - -static int ad5933_cmd(struct ad5933_state *st, unsigned char cmd) -{ - unsigned char dat = st->ctrl_hb | cmd; - - return ad5933_i2c_write(st->client, - AD5933_REG_CONTROL_HB, 1, &dat); -} - -static int ad5933_reset(struct ad5933_state *st) -{ - unsigned char dat = st->ctrl_lb | AD5933_CTRL_RESET; - - return ad5933_i2c_write(st->client, - AD5933_REG_CONTROL_LB, 1, &dat); -} - -static int ad5933_wait_busy(struct ad5933_state *st, unsigned char event) -{ - unsigned char val, timeout = AD5933_MAX_RETRIES; - int ret; - - while (timeout--) { - ret = ad5933_i2c_read(st->client, AD5933_REG_STATUS, 1, &val); - if (ret < 0) - return ret; - if (val & event) - return val; - cpu_relax(); - mdelay(1); - } - - return -EAGAIN; -} - -static int ad5933_set_freq(struct ad5933_state *st, - unsigned int reg, unsigned long freq) -{ - unsigned long long freqreg; - union { - __be32 d32; - u8 d8[4]; - } dat; - - freqreg = (u64)freq * (u64)(1 << 27); - do_div(freqreg, st->mclk_hz / 4); - - switch (reg) { - case AD5933_REG_FREQ_START: - st->freq_start = freq; - break; - case AD5933_REG_FREQ_INC: - st->freq_inc = freq; - break; - default: - return -EINVAL; - } - - dat.d32 = cpu_to_be32(freqreg); - return ad5933_i2c_write(st->client, reg, 3, &dat.d8[1]); -} - -static int ad5933_setup(struct ad5933_state *st) -{ - __be16 dat; - int ret; - - ret = ad5933_reset(st); - if (ret < 0) - return ret; - - ret = ad5933_set_freq(st, AD5933_REG_FREQ_START, 10000); - if (ret < 0) - return ret; - - ret = ad5933_set_freq(st, AD5933_REG_FREQ_INC, 200); - if (ret < 0) - return ret; - - st->settling_cycles = 10; - dat = cpu_to_be16(st->settling_cycles); - - ret = ad5933_i2c_write(st->client, - AD5933_REG_SETTLING_CYCLES, - 2, (u8 *)&dat); - if (ret < 0) - return ret; - - st->freq_points = 100; - dat = cpu_to_be16(st->freq_points); - - return ad5933_i2c_write(st->client, AD5933_REG_INC_NUM, 2, (u8 *)&dat); -} - -static void ad5933_calc_out_ranges(struct ad5933_state *st) -{ - int i; - unsigned int normalized_3v3[4] = {1980, 198, 383, 970}; - - for (i = 0; i < 4; i++) - st->range_avail[i] = normalized_3v3[i] * st->vref_mv / 3300; -} - -/* - * handles: AD5933_REG_FREQ_START and AD5933_REG_FREQ_INC - */ - -static ssize_t ad5933_show_frequency(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad5933_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - int ret; - unsigned long long freqreg; - union { - __be32 d32; - u8 d8[4]; - } dat; - - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - ret = ad5933_i2c_read(st->client, this_attr->address, 3, &dat.d8[1]); - iio_device_release_direct_mode(indio_dev); - if (ret < 0) - return ret; - - freqreg = be32_to_cpu(dat.d32) & 0xFFFFFF; - - freqreg = (u64)freqreg * (u64)(st->mclk_hz / 4); - do_div(freqreg, 1 << 27); - - return sprintf(buf, "%d\n", (int)freqreg); -} - -static ssize_t ad5933_store_frequency(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad5933_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - unsigned long val; - int ret; - - ret = kstrtoul(buf, 10, &val); - if (ret) - return ret; - - if (val > AD5933_MAX_OUTPUT_FREQ_Hz) - return -EINVAL; - - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - ret = ad5933_set_freq(st, this_attr->address, val); - iio_device_release_direct_mode(indio_dev); - - return ret ? ret : len; -} - -static IIO_DEVICE_ATTR(out_altvoltage0_frequency_start, 0644, - ad5933_show_frequency, - ad5933_store_frequency, - AD5933_REG_FREQ_START); - -static IIO_DEVICE_ATTR(out_altvoltage0_frequency_increment, 0644, - ad5933_show_frequency, - ad5933_store_frequency, - AD5933_REG_FREQ_INC); - -static ssize_t ad5933_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad5933_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - int ret = 0, len = 0; - - mutex_lock(&st->lock); - switch ((u32)this_attr->address) { - case AD5933_OUT_RANGE: - len = sprintf(buf, "%u\n", - st->range_avail[(st->ctrl_hb >> 1) & 0x3]); - break; - case AD5933_OUT_RANGE_AVAIL: - len = sprintf(buf, "%u %u %u %u\n", st->range_avail[0], - st->range_avail[3], st->range_avail[2], - st->range_avail[1]); - break; - case AD5933_OUT_SETTLING_CYCLES: - len = sprintf(buf, "%d\n", st->settling_cycles); - break; - case AD5933_IN_PGA_GAIN: - len = sprintf(buf, "%s\n", - (st->ctrl_hb & AD5933_CTRL_PGA_GAIN_1) ? - "1" : "0.2"); - break; - case AD5933_IN_PGA_GAIN_AVAIL: - len = sprintf(buf, "1 0.2\n"); - break; - case AD5933_FREQ_POINTS: - len = sprintf(buf, "%d\n", st->freq_points); - break; - default: - ret = -EINVAL; - } - - mutex_unlock(&st->lock); - return ret ? ret : len; -} - -static ssize_t ad5933_store(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad5933_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - u16 val; - int i, ret = 0; - __be16 dat; - - if (this_attr->address != AD5933_IN_PGA_GAIN) { - ret = kstrtou16(buf, 10, &val); - if (ret) - return ret; - } - - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - mutex_lock(&st->lock); - switch ((u32)this_attr->address) { - case AD5933_OUT_RANGE: - ret = -EINVAL; - for (i = 0; i < 4; i++) - if (val == st->range_avail[i]) { - st->ctrl_hb &= ~AD5933_CTRL_RANGE(0x3); - st->ctrl_hb |= AD5933_CTRL_RANGE(i); - ret = ad5933_cmd(st, 0); - break; - } - break; - case AD5933_IN_PGA_GAIN: - if (sysfs_streq(buf, "1")) { - st->ctrl_hb |= AD5933_CTRL_PGA_GAIN_1; - } else if (sysfs_streq(buf, "0.2")) { - st->ctrl_hb &= ~AD5933_CTRL_PGA_GAIN_1; - } else { - ret = -EINVAL; - break; - } - ret = ad5933_cmd(st, 0); - break; - case AD5933_OUT_SETTLING_CYCLES: - val = clamp(val, (u16)0, (u16)0x7FF); - st->settling_cycles = val; - - /* 2x, 4x handling, see datasheet */ - if (val > 1022) - val = (val >> 2) | (3 << 9); - else if (val > 511) - val = (val >> 1) | (1 << 9); - - dat = cpu_to_be16(val); - ret = ad5933_i2c_write(st->client, - AD5933_REG_SETTLING_CYCLES, - 2, (u8 *)&dat); - break; - case AD5933_FREQ_POINTS: - val = clamp(val, (u16)0, (u16)511); - st->freq_points = val; - - dat = cpu_to_be16(val); - ret = ad5933_i2c_write(st->client, AD5933_REG_INC_NUM, 2, - (u8 *)&dat); - break; - default: - ret = -EINVAL; - } - - mutex_unlock(&st->lock); - iio_device_release_direct_mode(indio_dev); - return ret ? ret : len; -} - -static IIO_DEVICE_ATTR(out_voltage0_scale, 0644, - ad5933_show, - ad5933_store, - AD5933_OUT_RANGE); - -static IIO_DEVICE_ATTR(out_voltage0_scale_available, 0444, - ad5933_show, - NULL, - AD5933_OUT_RANGE_AVAIL); - -static IIO_DEVICE_ATTR(in_voltage0_scale, 0644, - ad5933_show, - ad5933_store, - AD5933_IN_PGA_GAIN); - -static IIO_DEVICE_ATTR(in_voltage0_scale_available, 0444, - ad5933_show, - NULL, - AD5933_IN_PGA_GAIN_AVAIL); - -static IIO_DEVICE_ATTR(out_altvoltage0_frequency_points, 0644, - ad5933_show, - ad5933_store, - AD5933_FREQ_POINTS); - -static IIO_DEVICE_ATTR(out_altvoltage0_settling_cycles, 0644, - ad5933_show, - ad5933_store, - AD5933_OUT_SETTLING_CYCLES); - -/* - * note: - * ideally we would handle the scale attributes via the iio_info - * (read|write)_raw methods, however this part is a untypical since we - * don't create dedicated sysfs channel attributes for out0 and in0. - */ -static struct attribute *ad5933_attributes[] = { - &iio_dev_attr_out_altvoltage0_raw.dev_attr.attr, - &iio_dev_attr_out_altvoltage0_scale_available.dev_attr.attr, - &iio_dev_attr_out_altvoltage0_frequency_start.dev_attr.attr, - &iio_dev_attr_out_altvoltage0_frequency_increment.dev_attr.attr, - &iio_dev_attr_out_altvoltage0_frequency_points.dev_attr.attr, - &iio_dev_attr_out_altvoltage0_settling_cycles.dev_attr.attr, - &iio_dev_attr_in_voltage0_scale.dev_attr.attr, - &iio_dev_attr_in_voltage0_scale_available.dev_attr.attr, - NULL -}; - -static const struct attribute_group ad5933_attribute_group = { - .attrs = ad5933_attributes, -}; - -static int ad5933_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - struct ad5933_state *st = iio_priv(indio_dev); - __be16 dat; - int ret; - - switch (m) { - case IIO_CHAN_INFO_RAW: - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - ret = ad5933_cmd(st, AD5933_CTRL_MEASURE_TEMP); - if (ret < 0) - goto out; - ret = ad5933_wait_busy(st, AD5933_STAT_TEMP_VALID); - if (ret < 0) - goto out; - - ret = ad5933_i2c_read(st->client, - AD5933_REG_TEMP_DATA, - 2, (u8 *)&dat); - if (ret < 0) - goto out; - iio_device_release_direct_mode(indio_dev); - *val = sign_extend32(be16_to_cpu(dat), 13); - - return IIO_VAL_INT; - case IIO_CHAN_INFO_SCALE: - *val = 1000; - *val2 = 5; - return IIO_VAL_FRACTIONAL_LOG2; - } - - return -EINVAL; -out: - iio_device_release_direct_mode(indio_dev); - return ret; -} - -static const struct iio_info ad5933_info = { - .read_raw = ad5933_read_raw, - .attrs = &ad5933_attribute_group, -}; - -static int ad5933_ring_preenable(struct iio_dev *indio_dev) -{ - struct ad5933_state *st = iio_priv(indio_dev); - int ret; - - if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) - return -EINVAL; - - ret = ad5933_reset(st); - if (ret < 0) - return ret; - - ret = ad5933_cmd(st, AD5933_CTRL_STANDBY); - if (ret < 0) - return ret; - - ret = ad5933_cmd(st, AD5933_CTRL_INIT_START_FREQ); - if (ret < 0) - return ret; - - st->state = AD5933_CTRL_INIT_START_FREQ; - - return 0; -} - -static int ad5933_ring_postenable(struct iio_dev *indio_dev) -{ - struct ad5933_state *st = iio_priv(indio_dev); - - /* - * AD5933_CTRL_INIT_START_FREQ: - * High Q complex circuits require a long time to reach steady state. - * To facilitate the measurement of such impedances, this mode allows - * the user full control of the settling time requirement before - * entering start frequency sweep mode where the impedance measurement - * takes place. In this mode the impedance is excited with the - * programmed start frequency (ad5933_ring_preenable), - * but no measurement takes place. - */ - - schedule_delayed_work(&st->work, - msecs_to_jiffies(AD5933_INIT_EXCITATION_TIME_ms)); - return 0; -} - -static int ad5933_ring_postdisable(struct iio_dev *indio_dev) -{ - struct ad5933_state *st = iio_priv(indio_dev); - - cancel_delayed_work_sync(&st->work); - return ad5933_cmd(st, AD5933_CTRL_POWER_DOWN); -} - -static const struct iio_buffer_setup_ops ad5933_ring_setup_ops = { - .preenable = ad5933_ring_preenable, - .postenable = ad5933_ring_postenable, - .postdisable = ad5933_ring_postdisable, -}; - -static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev) -{ - struct iio_buffer *buffer; - - buffer = iio_kfifo_allocate(); - if (!buffer) - return -ENOMEM; - - iio_device_attach_buffer(indio_dev, buffer); - - /* Ring buffer functions - here trigger setup related */ - indio_dev->setup_ops = &ad5933_ring_setup_ops; - - return 0; -} - -static void ad5933_work(struct work_struct *work) -{ - struct ad5933_state *st = container_of(work, - struct ad5933_state, work.work); - struct iio_dev *indio_dev = i2c_get_clientdata(st->client); - __be16 buf[2]; - int val[2]; - unsigned char status; - int ret; - - if (st->state == AD5933_CTRL_INIT_START_FREQ) { - /* start sweep */ - ad5933_cmd(st, AD5933_CTRL_START_SWEEP); - st->state = AD5933_CTRL_START_SWEEP; - schedule_delayed_work(&st->work, st->poll_time_jiffies); - return; - } - - ret = ad5933_i2c_read(st->client, AD5933_REG_STATUS, 1, &status); - if (ret) - return; - - if (status & AD5933_STAT_DATA_VALID) { - int scan_count = bitmap_weight(indio_dev->active_scan_mask, - indio_dev->masklength); - ret = ad5933_i2c_read(st->client, - test_bit(1, indio_dev->active_scan_mask) ? - AD5933_REG_REAL_DATA : AD5933_REG_IMAG_DATA, - scan_count * 2, (u8 *)buf); - if (ret) - return; - - if (scan_count == 2) { - val[0] = be16_to_cpu(buf[0]); - val[1] = be16_to_cpu(buf[1]); - } else { - val[0] = be16_to_cpu(buf[0]); - } - iio_push_to_buffers(indio_dev, val); - } else { - /* no data available - try again later */ - schedule_delayed_work(&st->work, st->poll_time_jiffies); - return; - } - - if (status & AD5933_STAT_SWEEP_DONE) { - /* - * last sample received - power down do - * nothing until the ring enable is toggled - */ - ad5933_cmd(st, AD5933_CTRL_POWER_DOWN); - } else { - /* we just received a valid datum, move on to the next */ - ad5933_cmd(st, AD5933_CTRL_INC_FREQ); - schedule_delayed_work(&st->work, st->poll_time_jiffies); - } -} - -static int ad5933_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - int ret; - struct ad5933_state *st; - struct iio_dev *indio_dev; - unsigned long ext_clk_hz = 0; - - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st)); - if (!indio_dev) - return -ENOMEM; - - st = iio_priv(indio_dev); - i2c_set_clientdata(client, indio_dev); - st->client = client; - - mutex_init(&st->lock); - - st->reg = devm_regulator_get(&client->dev, "vdd"); - if (IS_ERR(st->reg)) - return PTR_ERR(st->reg); - - ret = regulator_enable(st->reg); - if (ret) { - dev_err(&client->dev, "Failed to enable specified VDD supply\n"); - return ret; - } - ret = regulator_get_voltage(st->reg); - - if (ret < 0) - goto error_disable_reg; - - st->vref_mv = ret / 1000; - - st->mclk = devm_clk_get(&client->dev, "mclk"); - if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT) { - ret = PTR_ERR(st->mclk); - goto error_disable_reg; - } - - if (!IS_ERR(st->mclk)) { - ret = clk_prepare_enable(st->mclk); - if (ret < 0) - goto error_disable_reg; - ext_clk_hz = clk_get_rate(st->mclk); - } - - if (ext_clk_hz) { - st->mclk_hz = ext_clk_hz; - st->ctrl_lb = AD5933_CTRL_EXT_SYSCLK; - } else { - st->mclk_hz = AD5933_INT_OSC_FREQ_Hz; - st->ctrl_lb = AD5933_CTRL_INT_SYSCLK; - } - - ad5933_calc_out_ranges(st); - INIT_DELAYED_WORK(&st->work, ad5933_work); - st->poll_time_jiffies = msecs_to_jiffies(AD5933_POLL_TIME_ms); - - indio_dev->dev.parent = &client->dev; - indio_dev->info = &ad5933_info; - indio_dev->name = id->name; - indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE); - indio_dev->channels = ad5933_channels; - indio_dev->num_channels = ARRAY_SIZE(ad5933_channels); - - ret = ad5933_register_ring_funcs_and_init(indio_dev); - if (ret) - goto error_disable_mclk; - - ret = ad5933_setup(st); - if (ret) - goto error_unreg_ring; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_unreg_ring; - - return 0; - -error_unreg_ring: - iio_kfifo_free(indio_dev->buffer); -error_disable_mclk: - clk_disable_unprepare(st->mclk); -error_disable_reg: - regulator_disable(st->reg); - - return ret; -} - -static int ad5933_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - struct ad5933_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - iio_kfifo_free(indio_dev->buffer); - regulator_disable(st->reg); - clk_disable_unprepare(st->mclk); - - return 0; -} - -static const struct i2c_device_id ad5933_id[] = { - { "ad5933", 0 }, - { "ad5934", 0 }, - {} -}; - -MODULE_DEVICE_TABLE(i2c, ad5933_id); - -static const struct of_device_id ad5933_of_match[] = { - { .compatible = "adi,ad5933" }, - { .compatible = "adi,ad5934" }, - { }, -}; - -MODULE_DEVICE_TABLE(of, ad5933_of_match); - -static struct i2c_driver ad5933_driver = { - .driver = { - .name = "ad5933", - .of_match_table = ad5933_of_match, - }, - .probe = ad5933_probe, - .remove = ad5933_remove, - .id_table = ad5933_id, -}; -module_i2c_driver(ad5933_driver); - -MODULE_AUTHOR("Michael Hennerich "); -MODULE_DESCRIPTION("Analog Devices AD5933 Impedance Conv. Network Analyzer"); -MODULE_LICENSE("GPL v2");