From patchwork Wed May 9 18:17:18 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: 10390599 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 E774860236 for ; Wed, 9 May 2018 18:17:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D661027DCD for ; Wed, 9 May 2018 18:17:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CADD827F82; Wed, 9 May 2018 18:17:58 +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 F268027DCD for ; Wed, 9 May 2018 18:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935272AbeEISR5 (ORCPT ); Wed, 9 May 2018 14:17:57 -0400 Received: from mail-eopbgr20113.outbound.protection.outlook.com ([40.107.2.113]:38016 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933577AbeEISRz (ORCPT ); Wed, 9 May 2018 14:17:55 -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; bh=PlhL/RTz20CPUcrIY1WUbpKBjqakSK+7McIEpO5KI8U=; b=AhnvTvCIeWY3FIWo8teZ6ek64zOw6jeaj1TJcFbwr5gY8+JINkgSikwgr+cmMlMiBl07RoOepuEmDPBFldLTpZG2/4s92z8SGahntR942ufXjCK4rUHaFwqItecblqA9ZF/byf5o5fiH2Rj3rThQhzNZxzcI85qqw95sNwQLm14= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Sean.Nyekjaer@prevas.dk; Received: from skn.prevas.se (81.216.59.226) by VI1PR10MB0240.EURPRD10.PROD.OUTLOOK.COM (2a01:111:e400:c54c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Wed, 9 May 2018 18:17:52 +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: add trigger and buffer support Date: Wed, 9 May 2018 20:17:18 +0200 Message-Id: <20180509181718.10451-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: HE1PR09CA0045.eurprd09.prod.outlook.com (2603:10a6:7:3c::13) To VI1PR10MB0240.EURPRD10.PROD.OUTLOOK.COM (2a01:111:e400:c54c::10) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020); SRVR:VI1PR10MB0240; X-Microsoft-Exchange-Diagnostics: 1; VI1PR10MB0240; 3:EEOIiAG2IAusFVv2YGAJQ4tk1OGkfo67EpBl4cNh1nOPr3bWQmqT9WsF/ofggQt2W/851I2sAXxikQa9NU+CeSIbEPgbMdG0LmDxVJO1pl7WIIGq3tUyRQp2VW2FVlxIeDTk/o7ucuWCDVtj3P1oLkybVFVtH9K4HnFkf22XVYfAvQU24L9cCxE/VdcqY9WaMKUmqMM49HwUaUCpofG+DEgfVSZo0sFKSBAGRN4bCOzXu1JKkYltlewhy/BlIsC+; 25:NbHtHwki4uHF1Z1CiRcksjfilMf3XSBRRwUcymhJcbuZbbU4rAfgkOq5VPjEYoBD2hF4MHQKKrqRBcUEfiS7dHEJSma10in4PRhkiTQy1rXYz4nhIuR3wa/qbv+GOa9oL93byEPQ/m6Cv4D6a0UJbjQszHgXcqrjP0ySGnzS2XVczuR69PDXITYguDR9IX8DVa5tjSZsCRd7OndddG5gQhpBtHclkBw7SnqVsAm4Ne+KHKg+9U7jqH1h3Qt+qdLd/+bAfyyGWllYpTNHYzuTrobdp3MuLhe4rbPhgosAjU3ns1ZedlrUmZvsRnuPclMvAJrajVKIHF9MYmday/0GRg==; 31:W3N/KX/ECWvqjWCC7QYhDwPeo1dq0neKcjxgOq9swoaJhoYemwWdiavl2YYZT8nly8iAnP9XM+GZ/cSLAg4KZw7D6KDdzm3ckDXBAigdro19WvIAr3aXR0TBxpJdGPfkL/Lv3oxFpS1oxn1gApxarQ8ei+DUUgiwFeY0QtK9AYGKv0oHt7cFO2zmjpcmluuNoHAmi87DL8+us5GiwlP4SFQIgYO6zOljzqr3rnwlC7g= X-MS-TrafficTypeDiagnostic: VI1PR10MB0240: 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)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:VI1PR10MB0240; BCL:0; PCL:0; RULEID:; SRVR:VI1PR10MB0240; X-Microsoft-Exchange-Diagnostics: 1; VI1PR10MB0240; 4:rDkcWfV6gtiw8jD6eSmi34x2qZiEmPGLXt6P/moE6iUIxLgRtawwYLjOYd7wBxIquBEQGL2FikX/FlW8CNHP1CdQhXyyoV1PLccusrOWAjdLGckbMP35EDQKAyBLNgMI7kDvvUd0UZuADJVKzasdBj6MOjXrREf7ELVB8bNhoeCJrSiJGvfO+6pDK5DVMlAd//ILDDjrkwkNKfR+CZXg7MPZmCnbggq/b5JZYCGbT+1OSquSO6OFGs3jbhcrZy2aYrutE4DI6P4uhupgbeFE5w== X-Forefront-PRVS: 0667289FF8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(396003)(366004)(39380400002)(39850400004)(346002)(376002)(199004)(189003)(4326008)(6512007)(50466002)(97736004)(48376002)(52116002)(53416004)(53936002)(51416003)(68736007)(16586007)(106356001)(6666003)(478600001)(2351001)(105586002)(16526019)(81156014)(2906002)(72206003)(316002)(36756003)(6916009)(3846002)(6486002)(186003)(26005)(44832011)(6116002)(1857600001)(5660300001)(69596002)(2361001)(486006)(1076002)(7736002)(305945005)(74482002)(476003)(2616005)(956004)(47776003)(8676002)(81166006)(8976002)(59450400001)(25786009)(50226002)(6506007)(86362001)(386003)(8936002)(66066001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR10MB0240; 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; VI1PR10MB0240; 23:kcd+9GkzpVt6rw9l8ISE1256iFDrWx+e7cuOv6/2T?= =?us-ascii?Q?hilkrfNc7YBv0s5wHrX3Xu4UToHJ7VnbmmrgTORz+Z6qbMif7uybtMRmmt5l?= =?us-ascii?Q?pYa+ZxMy4ZvodX8aTuLPtSTMp/1pvLa8KybEJXr/8VqnlCnZ099L+c8kyPAv?= =?us-ascii?Q?d/AKbi05MpeH+DZ8AojwryQ373twCSpQscvioAjrm4gNY93vQrLU/rTpYeuk?= =?us-ascii?Q?xykvvp6kLN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f?= =?us-ascii?Q?x6021P+2gZ4/P6y06h7f2eiYclgo/kgEZ7nE/aue4VbOKccZ6fOCMdusxmOv?= =?us-ascii?Q?WYGqsypxcGWKBFwh/XdQP5c2CWdzxNhySMe98DncYLJCfdGXq7kLGU+iECix?= =?us-ascii?Q?RHNb9f7DBFL8GoflIrrWe4uJrHhr2bY3bhIYEj6Va5Np1zowOQEDYpaISgx9?= =?us-ascii?Q?ZDx2KXkDz9dCX3Ym6oNqXYRTyUSBrBsEU5g1y3QNqiwsW1ujtShZktUvxeKI?= =?us-ascii?Q?b9boQ=3D=3D?= X-Microsoft-Antispam-Message-Info: lTD9+R+wIcw8PuZ6eycEHKTIznezGq+rdqVWnBpIPhpgKMSYrLuz4J31AFFkoavwx22w89JYMuJhykBSZz3FABuAspzmoTuLa3Dsvi573fsuoe2gh5AvKJf9oeT6CTPkx3RJhoatw07TOe8KSpk23IyHAnqchkj0mGslbYd8fs0MFQlruE6my7ZaDrXjqmyd X-Microsoft-Exchange-Diagnostics: 1; VI1PR10MB0240; 6:7eOf4BnX8rcIEP2w7+n99B3NPeBy04q0hIFjo058+H8sBB3fnqjVsRaT+li9+gctqa/vIdE49wtqmJwKlPKZ7cX+LmekWzZIk0o0RUBwCOV0mVw84lUrLBsTbLUm2l67nSzXl4m6Y5vwO15lcNmeC6u/0cGCKgJuPOqxZXDYu1v9EQorGox4ftdLhYLC5KHvIGZdNO+MLPy9+I6X+1gOQ5sADUkEtxJHyJpOMrIBImT92FNvSyLtI7VWXxEzcAe6A8KfrY4Wck/Dhcdwnt1CbmQ0/aO4I1Ja+M84mf8yHEoib1cd2OncvLL8SAH6JurKtzIvbZtgLBja3BQTGPTtMlCUq4DDsKDHckioAR4PfgT597Nb2QO04HQk4oDY1mO6u0ODOV2OJ9Sx8/VhrWyjiqeejMzKcj6yl1IIVv9JmeilukZEiZWSY741hQ768+//WZVN7EuSJ+IjTF8KO4zNGA==; 5:/PsbmPrGq2sfd65dXR4fqM/GTVXEDSjRl3UBhdmcncp3QXD4iXqqhmiVD/+KMjQ1TvDCiejN9H2CzkJIPRA9Sf+H2p5si8dKtr5k7o13puQMTF6cp/KiRx7jmpZoHDYCQX2TgItIFTnm4PUUXiwwQlIZy8GcvRafw0zYLLydHZg=; 24:k42tOzLfWhCmldd2o+HKxm8x5syOsU4luXXqrVcyEhJq3GJdM/4UvF0Oj9sk2cZ04DUD3wIg4XhS2Zi4JY8NPcLVuu1HeEOeoaXqhic99Uc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR10MB0240; 7:Dmjy0pd1yuLlDwz6whg4RW4RQF3sZzABF6uX2b+BXdrELptQV/NbAMKvlLzDT+7vbgIu0LAmo1zcZ5tmLlSwVFjZ1GupX5+yNgw5uRacvhxTHKiA4frtgEilB89U2mxN0zqUoA9ja8xUYSz6/Viekw0HGdQ9VsNJeiNXicHyHp2jBOytAXWcRQG+Zng+ZHF0Cid0lvjm1Rpab+X+xPQNU1kA0pif5CnjcJQU7Fbbd974EXiCRXg3aGzkkQR8Cyp2 X-MS-Office365-Filtering-Correlation-Id: fae19e35-ca4d-4434-2727-08d5b5d92de7 X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2018 18:17:52.1228 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fae19e35-ca4d-4434-2727-08d5b5d92de7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB0240 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 Signed-off-by: Sean Nyekjaer --- I'm looking at enabling the ADC's auto sequencing feature to enabled an even greater performance. But this is also useful as is :-) drivers/iio/adc/ti-ads8688.c | 48 +++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/ti-ads8688.c b/drivers/iio/adc/ti-ads8688.c index 079f133144b0..184d686ebd99 100644 --- a/drivers/iio/adc/ti-ads8688.c +++ b/drivers/iio/adc/ti-ads8688.c @@ -17,6 +17,9 @@ #include #include +#include +#include +#include #include #define ADS8688_CMD_REG(x) (x << 8) @@ -155,6 +158,13 @@ static const struct attribute_group ads8688_attribute_group = { .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) \ | BIT(IIO_CHAN_INFO_SCALE) \ | BIT(IIO_CHAN_INFO_OFFSET), \ + .scan_index = index, \ + .scan_type = { \ + .sign = 'u', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_BE, \ + }, \ } static const struct iio_chan_spec ads8684_channels[] = { @@ -371,6 +381,28 @@ static const struct iio_info ads8688_info = { .attrs = &ads8688_attribute_group, }; +static irqreturn_t ads8688_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + u16 buffer[8]; + int i, j = 0; + + 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); + j++; + } + + iio_push_to_buffers_with_timestamp(indio_dev, buffer, + pf->timestamp); + + iio_trigger_notify_done(indio_dev->trig); + + return IRQ_HANDLED; +} + static const struct ads8688_chip_info ads8688_chip_info_tbl[] = { [ID_ADS8684] = { .channels = ads8684_channels, @@ -402,7 +434,7 @@ static int ads8688_probe(struct spi_device *spi) ret = regulator_get_voltage(st->reg); if (ret < 0) - goto error_out; + goto err_regulator_disable; st->vref_mv = ret / 1000; } else { @@ -430,13 +462,22 @@ static int ads8688_probe(struct spi_device *spi) mutex_init(&st->lock); + ret = iio_triggered_buffer_setup(indio_dev, NULL, ads8688_trigger_handler, NULL); + if (ret < 0) { + dev_err(&spi->dev, "iio triggered buffer setup failed\n"); + goto err_regulator_disable; + } + ret = iio_device_register(indio_dev); if (ret) - goto error_out; + goto err_buffer_cleanup; return 0; -error_out: +err_buffer_cleanup: + iio_triggered_buffer_cleanup(indio_dev); + +err_regulator_disable: if (!IS_ERR(st->reg)) regulator_disable(st->reg); @@ -449,6 +490,7 @@ static int ads8688_remove(struct spi_device *spi) struct ads8688_state *st = iio_priv(indio_dev); iio_device_unregister(indio_dev); + iio_triggered_buffer_cleanup(indio_dev); if (!IS_ERR(st->reg)) regulator_disable(st->reg);