From patchwork Wed May 30 21:18:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Sean_Nyekj=C3=A6r?= X-Patchwork-Id: 10439933 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 C623F601D3 for ; Wed, 30 May 2018 21:19:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B90AB29613 for ; Wed, 30 May 2018 21:19:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABF9D2961C; Wed, 30 May 2018 21:19:02 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 EC84029613 for ; Wed, 30 May 2018 21:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932268AbeE3VTB (ORCPT ); Wed, 30 May 2018 17:19:01 -0400 Received: from mail-eopbgr40129.outbound.protection.outlook.com ([40.107.4.129]:5539 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932065AbeE3VTA (ORCPT ); Wed, 30 May 2018 17:19:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevasonline.onmicrosoft.com; s=selector1-prevas-dk; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O6Gmbs2z91SGSuHTaePggWSVmvdvfUJbAenBclUf3Rs=; b=KBIu0TUPrcElc98AKnbOqEQvLSFkF4Ia9PDSGYGzIy1F8a611IybfSzYsr7Ib90GGXVF5fqTo0XUJ+Q0iLIU0r10Q/LWoFY2uClwjR+ypntqovK3nMg4PXt6rzc0lDrWA18zApa5OiLEbbAu/RPH18wriCjxlaVhDRKz/vzKYDQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Sean.Nyekjaer@prevas.dk; Received: from skn.prevas.se (81.216.59.226) by AM4PR1001MB1394.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:200:99::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.11; Wed, 30 May 2018 21:18:56 +0000 From: Sean Nyekjaer To: jic23@kernel.org Cc: Sean Nyekjaer , pmeerw@pmeerw.net, linux-iio@vger.kernel.org Subject: [PATCH] iio: adc: ti-ads8688: use the auto sequence feature Date: Wed, 30 May 2018 23:18:21 +0200 Message-Id: <20180530211821.8496-1-sean.nyekjaer@prevas.dk> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 X-Originating-IP: [81.216.59.226] X-ClientProxiedBy: HE1P190CA0021.EURP190.PROD.OUTLOOK.COM (2603:10a6:3:bc::31) To AM4PR1001MB1394.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:200:99::19) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:AM4PR1001MB1394; X-Microsoft-Exchange-Diagnostics: 1; AM4PR1001MB1394; 3:mLmJdX/pETKN607uc0d5kxJ9e8nDO1MCzmOPWhhU59P0Rvm+Sk7TZADwsd/HP3UIMY3gxdIL44/Nq6MxMwPlfBklKWLxd+7+bTi2DBQIkP6jAF2vZf+m4Q7/BlycVdjraCNBvqUNAnAXRpx0Bu6kXdtH823LsEq635Vnl1kGgh26Fs3M054PN2OQhJucrk68Wf1nH8XiW2kaC53CYVjqBUGQ9pMJGEfHFtHLacBQHxEE9mdZhWlVPxuJ1W/iixWH; 25:9VVqhg0RLW1ALJORE/ilTt11Kxf+CEGljsS3GNubl9zTiSSDzbUk4VYfT7LgmIejytcJN8HYyLlqcKHRLiptGqg1Jam6LjF70IVKlpnqdUFXEFZYPqqXJ8VvfVr8hJLNa0XQwHyvOSzSTO7riAzk9r9rIlYfscxCGrJbDTwAG6lGHXZ9Sy7qDGZ/msz/uBva4zJxzAY/UoRA7Nytx5nP7KoUiZ12SRkiqIVp8GXxiFzeqObJMMMwLipPHFcLiYjCJAwxEYBptUaw1KGFNl6LNpWSnZnOz70P7URX2U/fhk3mSRUUZK7kLUhvDaN5OQvwL/UE8jVLDK1mjlshXAx9mA==; 31:x9JWsY0vc/nZ/BvPcQ0kU5PQDB/auDyGwCoFS/eDPzf6Zp8/JQi5SyA0xdXpB75hvqBflM22mBoPJoFlaNFpZXPRm5qfPlDK7fMZy0QrFo4EcC9Pg8buqpbqb1JOZS4VMoEW1T2z3jnGXhJGWOb+FDfe7sGMEx3NL+NfqjV+wrFqdAYaG8nMNTW9+RivyGrWLryJGY8Za3UnXwtSrcrGmsR9Q0TBnXhzLKWnydNC2Ws= X-MS-TrafficTypeDiagnostic: AM4PR1001MB1394: X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:AM4PR1001MB1394; BCL:0; PCL:0; RULEID:; SRVR:AM4PR1001MB1394; X-Microsoft-Exchange-Diagnostics: 1; AM4PR1001MB1394; 4:ofTj1XcsRarmsegWBW4U6W4ierZLMuYoTtMOxVoRw3k/UBvlEb36hJcSaOme8J6oAXcFeF+G2xZj9475D4MOiuooq02mO3bZtj0j+l5AUihdyQ48Y12Uh+encGEutI/T7F6g+bA8FPA4VayvQPbsmJ2So8XO0XQJnMXfw0TUXDUqCX/0MmWAOZEYn0tlkpE71YCdg2GEVi++W26cXRgY7rpN0KyvAEwPcVuEwfWIbL5MCQrc7u4E/JCtURhQZwLr/x0ExKVCLdPq31bYmsZBOA== X-Forefront-PRVS: 0688BF9B46 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(376002)(346002)(366004)(39380400002)(39850400004)(396003)(199004)(189003)(956004)(5660300001)(2616005)(476003)(81166006)(81156014)(53936002)(59450400001)(486006)(72206003)(74482002)(16586007)(44832011)(7736002)(1857600001)(51416003)(6506007)(386003)(478600001)(48376002)(52116002)(6116002)(47776003)(26005)(186003)(3846002)(8976002)(16526019)(1076002)(50226002)(6512007)(69596002)(50466002)(36756003)(316002)(6916009)(575784001)(86362001)(66066001)(2906002)(2361001)(8936002)(4326008)(68736007)(6486002)(305945005)(25786009)(8676002)(6666003)(2351001)(97736004)(106356001)(53416004)(105586002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM4PR1001MB1394; H:skn.prevas.se; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: prevas.dk does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR1001MB1394; 23:EZG8n3Ww6OjEgKBTNt5ubgIwrjBnha+NgUhFzFG?= =?us-ascii?Q?XsRdqpPszgwhpdeCgT360I4L9lzsmmVbRJ9ksE3tSZ3qyLBnsuQqdR0E6Jl/?= =?us-ascii?Q?qSjwR1spLSBIT50wp2mhpq2+yTbq1U+H4Ad3u1DZx9ibaU9Kf+rqSnSwvH8p?= =?us-ascii?Q?EBnO1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Jr6I9?= =?us-ascii?Q?ybQrbFexBlu12B/Mvtpy0ahTvhgYTbIxx/g0Wh8NUQiOrHx6v8D0QloOIkus?= =?us-ascii?Q?HtImtvgRlFV5B44ByFU5yPrMYyZ4luFFF1xKSOm5pLkVWADMElW4035/Gied?= =?us-ascii?Q?iFSDqDcpkUPnocN5bp3g3rTCerJrNXUVHrNWXI9bjaJMSN03F7KpnbRC/LlB?= =?us-ascii?Q?sdJMMhjq1B04hc7W8HTlbbpTdykWKmjKNDhe7olhl51mGoXibuUH3aUDnyuA?= =?us-ascii?Q?2UnYmNOL1WdTx7ChXA+xkmoiYKsmtr6spit/7BHt76RnM91Fb6ZSzmi/Ahbr?= =?us-ascii?Q?GMpKOnoyz2yj3rN9Cbi75O68HUXw=3D?= X-Microsoft-Antispam-Message-Info: g0xTvbBw7YMjGX6S3pRZIEH0cKt0g26nsChIHB7TIZyTaemQMGtrTicEIcF3tvKHRrczOFMzU7U0cWexUVXfFMMU8zsmqnt7apgcgPw5y68rRo75vXTqAK2jpIW07PPn8guuOfZvOQMBDn5WYLH4OhtRqpK8bEulpsM0qxEfwahcyW4YxIACGWqUZSthyKip X-Microsoft-Exchange-Diagnostics: 1; AM4PR1001MB1394; 6:+owMLij5Kn8licws9WEhQCnUCeeo6+tFLBwjlqhCDjqFLwDOd+LyXM0RtR3atM5vRrosUEIfN+FElhjh4i5U9PuBmvxmdRY8b9iDI6m8eyVU4TGfXNcQwDBUPfZGvWXfnaPr0G5pWmXDw5+EhhUef8oWB3p8io2Jj9H1bLRY/MavYasegq2nI8sZsc1VEypF7kHSaZQQ1tQkfs8l09mPsWgSXc5DE07Nye3jquTlLmczPud9e6KJLsJa6uYrRRzggSkSKz9aJjMlK5rA/vTUvJ/wLtxqddmYDs4S0JFIWO49HajTerAY3Be2HGJWKJusDbidV3OJC2RV0Ux7/ZOPlEpwQ3E7scyX7/gTNf3iL/OS56kwSri2TRupo0Xhc0vaDoeBNgubJlU/Xmfpfu0JoEM20JjiC2CVslx4U8w/+aHyu5WrPVXZPiufyLLTU+xuHLkx1IJzfvMAEqerhzRcxQ==; 5:7X6kTpLwgMbn1DLmdXAY4uLs5fxBhrdyRpvMeWD8rLUOR+67qrfHzgv+Gs3g8g3MhKQtFeH9/HWVn4zKVWr9wn+Zwv0NZ8JrX9dVBrk24Ist1uvT93iWq0+iH//qsDdqrNlMjQHGuarjmwSMyzy2kR1bHZwpoTt4mP6KxJTslHY=; 24:z60+G476dse1xsUNk8/CCWWDZRbOKYN1fi+zrT3rZVmyKhu1tYWc5IAlk3H1RtBcZWthJ0hfzwwEq+8LrcVtjei+/5XROPzvXx0I36HoJ2c= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR1001MB1394; 7:3cAvlaaFh5stQ83Q5m6sdOyPRX4FSryn6YA8NhGpYakLtxMjjliyhRMvdrbk4V10OgoNiWmNQitG+HcuNK79Mo/+aCls0QWL1ZCacdKvVn2PJFp9u8Xs3wvyXeRtJgZxnOuNFLyprYLzRCzxAZuMtZ2qEXgN3LqvFbP0cC57vxqf1aRISExTSLYvxheoh01ThlLpy31TUSpgD7KnB8VDZrYTXlcBFyC/7FYBNbJfB2FdYfLBFgpe2vLmkaSosZWI X-MS-Office365-Filtering-Correlation-Id: ff48c510-7b1f-4b2c-1f7a-08d5c672f473 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2018 21:18:56.8955 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff48c510-7b1f-4b2c-1f7a-08d5c672f473 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR1001MB1394 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The TI ADS8688 have a auto sequence feature that allows to continuesly reading new values from the chosen channels. Lets enable it and we will be able to sample at the double speed vs the old implementation Signed-off-by: Sean Nyekjaer --- drivers/iio/adc/ti-ads8688.c | 60 +++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c index 184d686ebd99..8e18c0caa1d7 100644 --- a/drivers/iio/adc/ti-ads8688.c +++ b/drivers/iio/adc/ti-ads8688.c @@ -25,10 +25,12 @@ #define ADS8688_CMD_REG(x) (x << 8) #define ADS8688_CMD_REG_NOOP 0x00 #define ADS8688_CMD_REG_RST 0x85 +#define ADS8688_CMD_REG_AUTO_RST 0xA0 #define ADS8688_CMD_REG_MAN_CH(chan) (0xC0 | (4 * chan)) #define ADS8688_CMD_DONT_CARE_BITS 16 #define ADS8688_PROG_REG(x) (x << 9) +#define ADS8688_AUTO_SEQ_EN 0x01 #define ADS8688_PROG_REG_RANGE_CH(chan) (0x05 + chan) #define ADS8688_PROG_WR_BIT BIT(8) #define ADS8688_PROG_DONT_CARE_BITS 8 @@ -210,6 +212,39 @@ static int ads8688_reset(struct iio_dev *indio_dev) return spi_write(st->spi, &st->data[0].d8[0], 4); } +static int ads8688_start_autoseq(struct iio_dev *indio_dev) +{ + struct ads8688_state *st = iio_priv(indio_dev); + u32 tmp; + + tmp = ADS8688_CMD_REG(ADS8688_CMD_REG_AUTO_RST); + tmp <<= ADS8688_CMD_DONT_CARE_BITS; + st->data[0].d32 = cpu_to_be32(tmp); + + return spi_write(st->spi, &st->data[0].d8[0], 4); +} + +static int ads8688_read_autoseq(struct iio_dev *indio_dev) +{ + struct ads8688_state *st = iio_priv(indio_dev); + int ret; + u32 tmp; + struct spi_transfer t = { + .tx_buf = &st->data[0].d8[0], + .len = 4, + }; + + tmp = ADS8688_CMD_REG(ADS8688_CMD_REG_NOOP); + tmp <<= ADS8688_CMD_DONT_CARE_BITS; + st->data[0].d32 = cpu_to_be32(tmp); + + ret = spi_sync_transfer(st->spi, &t, 1); + if (ret < 0) + return ret; + + return be32_to_cpu(st->data[0].d32) & 0xffff; +} + static int ads8688_read(struct iio_dev *indio_dev, unsigned int chan) { struct ads8688_state *st = iio_priv(indio_dev); @@ -251,6 +286,10 @@ static int ads8688_read_raw(struct iio_dev *indio_dev, struct ads8688_state *st = iio_priv(indio_dev); + /* Block raw reading when in triggered mode */ + if (iio_buffer_enabled(indio_dev)) + return -EBUSY; + mutex_lock(&st->lock); switch (m) { case IIO_CHAN_INFO_RAW: @@ -299,6 +338,10 @@ static int ads8688_write_raw(struct iio_dev *indio_dev, unsigned int scale = 0; int ret = -EINVAL, i, offset = 0; + /* Block setup when in triggered mode */ + if (iio_buffer_enabled(indio_dev)) + return -EBUSY; + mutex_lock(&st->lock); switch (mask) { case IIO_CHAN_INFO_SCALE: @@ -374,10 +417,25 @@ static int ads8688_write_raw_get_fmt(struct iio_dev *indio_dev, return -EINVAL; } +static int ads8688_update_scan_mode(struct iio_dev *indio_dev, + const unsigned long *active_scan_mask) +{ + int scan_count; + + scan_count = bitmap_weight(active_scan_mask, indio_dev->masklength); + + ads8688_prog_write(indio_dev, ADS8688_AUTO_SEQ_EN, (int)active_scan_mask); + + ads8688_start_autoseq(indio_dev); + + return 0; +} + static const struct iio_info ads8688_info = { .read_raw = &ads8688_read_raw, .write_raw = &ads8688_write_raw, .write_raw_get_fmt = &ads8688_write_raw_get_fmt, + .update_scan_mode = ads8688_update_scan_mode, .attrs = &ads8688_attribute_group, }; @@ -391,7 +449,7 @@ static irqreturn_t ads8688_trigger_handler(int irq, void *p) for (i = 0; i < indio_dev->masklength; i++) { if (!test_bit(i, indio_dev->active_scan_mask)) continue; - buffer[j] = ads8688_read(indio_dev, i); + buffer[j] = ads8688_read_autoseq(indio_dev); j++; }