From patchwork Mon Mar 12 12:06:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Ardelean X-Patchwork-Id: 10276085 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 4A1756038F for ; Mon, 12 Mar 2018 12:07:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F1C628D16 for ; Mon, 12 Mar 2018 12:07:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3384D28D78; Mon, 12 Mar 2018 12:07:13 +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_SIGNED, 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 A35B228D16 for ; Mon, 12 Mar 2018 12:07:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751280AbeCLMHM (ORCPT ); Mon, 12 Mar 2018 08:07:12 -0400 Received: from mail-by2nam03on0048.outbound.protection.outlook.com ([104.47.42.48]:12577 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751229AbeCLMHL (ORCPT ); Mon, 12 Mar 2018 08:07:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.onmicrosoft.com; s=selector1-analog-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=v0mm0xIeEb1elI29s/tjunCwqweCA+fTqmIlbnryDxM=; b=apRWj8c7oYaE2QBfLME3pXnUpBbiaiNIbN2cZ9lF5+NLtq7dALOSixsQXQ/A8Jpy4LqBzN7apuFVd14JbUs+qKn6FfPStwFOVgVM1b0DX3twFC0QCahwlk989dUUnCGTZ2voz1TlEdUTI4k/a+SIIRMcq1asRkJoFCQ70caM/FM= Received: from DM5PR03CA0044.namprd03.prod.outlook.com (2603:10b6:4:3b::33) by CY1PR03MB1485.namprd03.prod.outlook.com (2a01:111:e400:58ec::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.567.14; Mon, 12 Mar 2018 12:07:09 +0000 Received: from BL2FFO11OLC002.protection.gbl (2a01:111:f400:7c09::134) by DM5PR03CA0044.outlook.office365.com (2603:10b6:4:3b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.567.14 via Frontend Transport; Mon, 12 Mar 2018 12:07:09 +0000 Authentication-Results: spf=pass (sender IP is 137.71.25.55) smtp.mailfrom=analog.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=bestguesspass action=none header.from=analog.com; Received-SPF: Pass (protection.outlook.com: domain of analog.com designates 137.71.25.55 as permitted sender) receiver=protection.outlook.com; client-ip=137.71.25.55; helo=nwd2mta1.analog.com; Received: from nwd2mta1.analog.com (137.71.25.55) by BL2FFO11OLC002.mail.protection.outlook.com (10.173.161.186) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.527.18 via Frontend Transport; Mon, 12 Mar 2018 12:07:07 +0000 Received: from NWD2HUBCAS9.ad.analog.com (nwd2hubcas9.ad.analog.com [10.64.69.109]) by nwd2mta1.analog.com (8.13.8/8.13.8) with ESMTP id w2CC76VC007404 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Mon, 12 Mar 2018 05:07:06 -0700 Received: from zeus.spd.analog.com (10.64.82.11) by NWD2HUBCAS9.ad.analog.com (10.64.69.109) with Microsoft SMTP Server id 14.3.210.2; Mon, 12 Mar 2018 08:07:06 -0400 Received: from saturn.analog.com ([10.50.1.244]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id w2CC71YD026433; Mon, 12 Mar 2018 08:07:05 -0400 From: Alexandru Ardelean To: CC: , , , Alexandru Ardelean Subject: [PATCH 2/2] iio: adc: ad7791: implement IIO_CHAN_INFO_SAMP_FREQ Date: Mon, 12 Mar 2018 14:06:54 +0200 Message-ID: <20180312120654.1806-2-alexandru.ardelean@analog.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180312120654.1806-1-alexandru.ardelean@analog.com> References: <20180312120654.1806-1-alexandru.ardelean@analog.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:137.71.25.55; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(346002)(39380400002)(396003)(376002)(39860400002)(2980300002)(438002)(189003)(199004)(54906003)(356003)(5660300001)(106002)(7636002)(305945005)(36756003)(6666003)(6916009)(2950100002)(8936002)(47776003)(478600001)(50226002)(2351001)(16586007)(106466001)(53416004)(246002)(50466002)(8676002)(48376002)(575784001)(86362001)(4326008)(1076002)(76176011)(77096007)(2906002)(51416003)(26005)(7696005)(59450400001)(336012)(186003)(316002)(107886003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB1485; H:nwd2mta1.analog.com; FPR:; SPF:Pass; PTR:nwd2mail10.analog.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC002; 1:PbRi4ysho/IZs2ojmTtVeoxpmbGHi4D9Y+aH45Rx0A7Z/5hR0/on43ifVp2LEL0r/XFGZ58zxsMn288t577HTHYKR9yqtxx9ITwkTi599EGHGZudwdTGMzUEKX4Vcza9 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b65796cb-b1f6-474f-dc2c-08d58811c783 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4608076)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060); SRVR:CY1PR03MB1485; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1485; 3:+Gp8wfw7TXdeo1smmW1eWUIa1Y4cIX0o3D1tcwhh7e/KUsK8jRX5bSpGjKQh1RPXf4qSSXU86/ouLgBjCbWc42yvlSBqPZ7p9pL2ZV/MJSLHtEciWiC1AICkREDJBzBEw7Xpy7gukHMSZc8Ak9y4YkgErDJs/kPBQdW7W562mric/gWAOHlaC2xbR9ZQAID0/shZ7K4reOdBMUxFlLIUQlIt9FiAVr4BeMmuLTDsoqMLJvsYZfl0QoocSdwB/z685s5Miq4uxM/9J0BX4V5LMvpctEQx2Xdb4tmuZk7T5YAHZwLXD8h/5Nc0dkQPdytSRBtWtp5qppd+WwyDWqoDkd7BzlYhckjtHKADxNr+caM=; 25:i+9ymvM91mJRYgHFn/uDxqYXVnEqjQuivzFL104TpjM6yru7bnyZ5wvgNYENKw21ZDpkL4NOQ3U0iQAlQkWyZ10PfoVSKPU/1KqILR4GDgw0ZSes3H7mewLYcBPmbX6DGMlsAFH8C6MwCiL7kZl4pwc42VVeSbBiVOHDyGW3PfKCCtIZqN5GX007AERmyTcq5/UYEa+hk8bqfIMKruwPCX6/zdO0y89hjXJMUSmxueLUskzmjONLbqCCDWMN913S5chc3UNR0Rz85yuxpijkCv46Kvogy77egcxAY4mthZ9fOnnorpM/7yP8PSEN8d5rhOnrd5cixIpI4gXGOtUzijWzfTMtoOQkd/d7T7Cyr38= X-MS-TrafficTypeDiagnostic: CY1PR03MB1485: X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1485; 31:ZxXqVf1L+FCe5mPr7aSG7Ptl/MDoI8/u+jwXgxYuYkdfLAjDsEGpLSjmda80UsYKdp0FzhEoYtvqtQW+tZxcHCfbpWs4DAMcWHuPly+4jWhpg8xKm1NmNj5kYpCFgtaj6ZLK0PFwVnAbspsSX0PDmA2pHBGygIniG0gC4r5MWQf3H9Vl9tVk/P+pblAsS9DRihYq+lh2MiD32Q9KcPpMKh6aULc02r9tqKMYo30RQNA=; 20:M2OYGOp2LQsmGvbTeJQ5TIsmoRBnUUw0dsAIKm0j853cWTx8LhjPhhEus+fI6aBV5pCdYLqYpnHpqeBYJ+29M28Ssk8Z9gIaJyKjq/oH0HYLxWvTd3c7w8Coh6gXTO0o9B4caPcF1jQuIalAJrDQFUu1sgRD042ywdgII0ak1WXp4fzxKiIzcbEbncXK4SuOTrknB7AwwMg8xik454ea0JOhjZwupe4vciIq1JOOm1/o5olEhLRzPfaRAaweGPHNM2rrgKqWWuAxBZZ6HNO887dJfgaSQdJqQg2mRZ5ubmBzCjOo0gTGJY3yPFBGoZ8B1YXzLxNHz4WK/wfcO+daOjGWPPxQxGXBAGG3VQTfAqWO9aDOtFEUPCljWVY/v/RDBswWM+hR1B+P1IvAx6ASGUVZyI0dzviITnh1m5BjhdWvTAG3rUqOM0sfVecPOuBgQN4BjM6Cvy8+HArB4UvmL6BdP8oNfk9Vq6PPdv4i26UWK9JWQHyDEWT59NRNDf57 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(232431446821674); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93004095)(3002001)(3231220)(944501244)(52105095)(10201501046)(6055026)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123564045)(6072148)(201708071742011); SRVR:CY1PR03MB1485; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB1485; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1485; 4:Th5BdWVyZQ0/J58m9LebKXIkxCl+iIQyC0g9RraIzLXDJjJ8KHV9D7hiesuExOVbChjGbR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Li3evtd656JAFpeTNzISpcT9tEKvJsnk?= =?us-ascii?Q?r79byJL8Y4cm103/5uqmMZMjlylRHqVtJtBhdpwMKkw+PXH4bCYQb9n0DKbE?= =?us-ascii?Q?sSOqXLB03yvabrRRFt1kWK1sWyBijMZy/PNLa7fObkuocdK8SbY3FXYhjDfE?= =?us-ascii?Q?6KCWNmrk0eQH3jYlmHTbrd/Ate/RZHPnMYLadtPFqepzGehfP9ZbUjA3BUpg?= =?us-ascii?Q?ngzvRRbYtVNDX00Wsh7nmeKQdM86E3KKU0bZk1FPMsqgnwgQIjRK2RmAyl+9?= =?us-ascii?Q?yyhadaZd4+ASpjFXK0btnBDPgCBuVr6F5Xr8JCjYFEADCUuHAngpQeKt4FKp?= =?us-ascii?Q?2G0XItsF8tEECkdXliSVLEOLo/ezILvxkmy3eprZWyobW3jn6FrNV7cW6Zbj?= =?us-ascii?Q?Od8XZV2vF9Z8/MklTMs6cu0HCXvZBPhx04YAjULXmtE9q3wSDKrDgcqYqxa6?= =?us-ascii?Q?uyo8fc=3D?= X-Microsoft-Antispam-Message-Info: fRzEda3GLAmkJDdTtumr+ZD51+MtixOnGZhl1m/BJZpL6mpoV1AO2ou5FKNumMU9VdJutRjc7H+g4eWN1m025emG4XUsgpsXbBKFLbSIdFmKW1R+3kf1UOoBy13OVuOO8Yow6UbsiSlTtvjr+1pxL9xs7M2cHkL4phfMiu9Kwcm/4QlUyzv8fLeRKb2IXSvS X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1485; 6:HDL1e1nYsWRJJSi8wKSxv8jPm3kMUJHaNZY/WUuL6RC2ECmG7cnhtuzRsJtU4BG0P2jstnGhGHcadSERizWu1envFSlWQw8AyhM1u3zw6eGZeAdQ+6dEtJROLAyTAt80TkTcCQx+5SHWRn6carNEwQyq24y+WUOqXuWUMNghwZC7D/lfvTrEAxeMjK7poqVjbuDQznvCf+V0IcDj0XUFd7Pb1eouX389dFo6eXhh79X0SatfzQlVQ4Ywv7bELKaWAX9hJUhpmsG3gQQdOmXm5ET3UwE5RZdynyZ6Vc91cFZxE0kGw5ZGVOvB+qQj3CRXJsCPynvagJ2dqmueyLEYeduZS5fFhwiD47g/9sCDsfM=; 5:E+w2tQi2H2QIA6MoS4phC34NWvqTUPgxT68BgGAc+2K4mw2mSzLYLYaXAyZGnHt/kjM9PijJKoym/TBb9SB2opi5GlfAzO8MUBnA703fJUgraGEuxrZ8Q5gtL9s6lmymTTWIjbbg5YtlHAMUqZqxO47KAIZVcnxMFIF+QEqKu9g=; 24:+NvzwSwZ9ndyez22qvhYfm4tXBrmeBFRe+zE1wwZvEnabu+IKteqFW8V4Av7wE2DyXql0qEmbrIYP3KiEjWkludM2Y5hUdUjxgNFbLGV1Pk=; 7:DdfoHjfjiZwWFEF5ectZiHY0yJCzGsMzm4uUaurCRLVLXw8sCdkrSXrIaQqcO15W4PYx1vJCPPmLwcSf58Z/SnFwUIzYZv1Kb8WdlchBvhU2Q7oMAuTK7PUYuM7V/PD8SZsCT4HRN03zEUpjcPZyrYuznxnYj9SfIfXzNWaA8iwleX+EZOULUnECNnqNi9wWHleJ9lj7g+/RSzQwEK5//9wHJFbkXmEsf6KwIMwwPZrZa1WdHKOgVM9VNBbVypDw SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: analog.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2018 12:07:07.4690 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b65796cb-b1f6-474f-dc2c-08d58811c783 X-MS-Exchange-CrossTenant-Id: eaa689b4-8f87-40e0-9c6f-7228de4d754a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=eaa689b4-8f87-40e0-9c6f-7228de4d754a; Ip=[137.71.25.55]; Helo=[nwd2mta1.analog.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB1485 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 Now that the old read/write frequency sysfs attrs have been removed, we have a clean slate to implement IIO_CHAN_INFO_SAMP_FREQ. This driver also pre-dates IIO_CHAN_INFO_SAMP_FREQ, and this change implements this behavior. The `ad7791_write_raw` would have overlapped quite a bit with the old read/write frequency functions, making things a bit harder to follow. Fixes: a13e831fcaa7 ("staging: iio: ad7192: implement IIO_CHAN_INFO_SAMP_FREQ") Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7791.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c index 03a5f7d6cb0c..a9ff0695ddf7 100644 --- a/drivers/iio/adc/ad7791.c +++ b/drivers/iio/adc/ad7791.c @@ -153,6 +153,17 @@ struct ad7791_state { const struct ad7791_chip_info *info; }; +static const int ad7791_sample_freq_avail[8][2] = { + [AD7791_FILTER_RATE_120] = { 120, 0 }, + [AD7791_FILTER_RATE_100] = { 100, 0 }, + [AD7791_FILTER_RATE_33_3] = { 33, 300000 }, + [AD7791_FILTER_RATE_20] = { 20, 0 }, + [AD7791_FILTER_RATE_16_6] = { 16, 600000 }, + [AD7791_FILTER_RATE_16_7] = { 16, 700000 }, + [AD7791_FILTER_RATE_13_3] = { 13, 300000 }, + [AD7791_FILTER_RATE_9_5] = { 9, 500000 }, +}; + static struct ad7791_state *ad_sigma_delta_to_ad7791(struct ad_sigma_delta *sd) { return container_of(sd, struct ad7791_state, sd); @@ -202,6 +213,7 @@ static int ad7791_read_raw(struct iio_dev *indio_dev, { struct ad7791_state *st = iio_priv(indio_dev); bool unipolar = !!(st->mode & AD7791_MODE_UNIPOLAR); + unsigned int rate; switch (info) { case IIO_CHAN_INFO_RAW: @@ -239,11 +251,53 @@ static int ad7791_read_raw(struct iio_dev *indio_dev, *val2 = chan->scan_type.realbits - 1; return IIO_VAL_FRACTIONAL_LOG2; + case IIO_CHAN_INFO_SAMP_FREQ: + rate = st->filter & AD7791_FILTER_RATE_MASK; + *val = ad7791_sample_freq_avail[rate][0]; + *val2 = ad7791_sample_freq_avail[rate][1]; + return IIO_VAL_INT_PLUS_MICRO; } return -EINVAL; } +static int ad7791_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, int val2, long mask) +{ + struct ad7791_state *st = iio_priv(indio_dev); + int ret, i; + + ret = iio_device_claim_direct_mode(indio_dev); + if (ret) + return ret; + + switch (mask) { + case IIO_CHAN_INFO_SAMP_FREQ: + for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++) { + if (ad7791_sample_freq_avail[i][0] == val && + ad7791_sample_freq_avail[i][1] == val2) + break; + } + + if (i == ARRAY_SIZE(ad7791_sample_freq_avail)) { + ret = -EINVAL; + break; + } + + st->filter &= ~AD7791_FILTER_RATE_MASK; + st->filter |= i; + ad_sd_write_reg(&st->sd, AD7791_REG_FILTER, + sizeof(st->filter), + st->filter); + break; + default: + ret = -EINVAL; + } + + iio_device_release_direct_mode(indio_dev); + return ret; +} + static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("120 100 33.3 20 16.7 16.6 13.3 9.5"); static struct attribute *ad7791_attributes[] = { @@ -257,12 +311,14 @@ static const struct attribute_group ad7791_attribute_group = { static const struct iio_info ad7791_info = { .read_raw = &ad7791_read_raw, + .write_raw = &ad7791_write_raw, .attrs = &ad7791_attribute_group, .validate_trigger = ad_sd_validate_trigger, }; static const struct iio_info ad7791_no_filter_info = { .read_raw = &ad7791_read_raw, + .write_raw = &ad7791_write_raw, .validate_trigger = ad_sd_validate_trigger, };