Received: by 10.223.164.202 with SMTP id h10csp5338458wrb; Tue, 21 Nov 2017 08:13:48 -0800 (PST) X-Google-Smtp-Source: AGs4zMZNccs47bUwG3qVK8Sg6uOMGnA5GU6VukF2vtx8mGdw0UQHgZNKXVUeCBSjS94D8hHSjNoq X-Received: by 10.84.194.131 with SMTP id h3mr10233091pld.325.1511280828165; Tue, 21 Nov 2017 08:13:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511280828; cv=none; d=google.com; s=arc-20160816; b=NVuy8tZPBSA6zPr4ddyBi5lC1ppG8tqR/UIQlgEuO5KTwJtnp0P1TXLHo0/9RVt6hn ZNabhKH5otRLuux5glZ85JhlUEi/LQjY/QLfQr5baPkbFDEiCBrDMdbUuLycQLjzvoH5 nwPkHzoVrVmwHnv3MSazHbhzNt+fRuZNv6RuaacSiFIj/11K0Wp1ys4jlIUj2jMKUJjs uZ/yduOBsrMEymjujTASeqqhTWybrkt+S0YPGe5ijsj/7S+CFviYkoI+eAMNQ3DSy5I/ gxlJMqO3TtcrJHTYTFnIHbNa0tL0xkV4aQ01Dkm5SX3fO9FQfXAUGiSVsPtxnVSdbT0x tnzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :date:cc:to:from:subject:message-id:dkim-signature :arc-authentication-results; bh=b27TGt+Hn8NrfLXSKNSDHXzQuDrzaODyPS80YYWdBgo=; b=PyNncMTzjeWUX2Vxvf1sEoN+U7z46uzXmZp7M17qj+yxxHQd9vg7/u3FdbkXGlo7TQ P/niUVghXytJngCD04Jp8j6jrSeCokQfhjH0QOICyz1y7QIqjNbX9a3cPv4qh8LsVz42 LA5jL/sNarXxinUGSAU6myZtLqFCfpH6U01nbBVcBmMuPxXAmxTRIWcu1vfm/RFUr12d yUCcXFDWiKBwgkLVyShXX9f9baiUU62Zkl5MAZHm3iH/hhJhePMWm255fPNYgS1WN6FE 3ve9imurRicJ1gSbdonjBQ/rdQLrNXP0Mt9G180NpjtvSJp9aAVkQpZi2ZgmfHTai5nd QuJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@elementarea-net.20150623.gappssmtp.com header.s=20150623 header.b=s11cJFHY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si9970023ple.656.2017.11.21.08.13.36; Tue, 21 Nov 2017 08:13:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@elementarea-net.20150623.gappssmtp.com header.s=20150623 header.b=s11cJFHY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751602AbdKUQMp (ORCPT + 76 others); Tue, 21 Nov 2017 11:12:45 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:44255 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751388AbdKUQLb (ORCPT ); Tue, 21 Nov 2017 11:11:31 -0500 Received: by mail-wm0-f66.google.com with SMTP id r68so4567495wmr.3 for ; Tue, 21 Nov 2017 08:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elementarea-net.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=b27TGt+Hn8NrfLXSKNSDHXzQuDrzaODyPS80YYWdBgo=; b=s11cJFHYzB/tKb6rRnTyp5n8/wbUZ/osf5b9ZiJ18mT2w6t/ypEc07yBj6wzixwYoM 9/rZxEQoc5r4GPvwoknFO9rjLaI8pCcy2oCc/SzqHvLwLpJS1mlWSJO3BtBODJmWrBv0 xNBccL2KB0gw4HKne6DO3HLPR9VHD1SeEZfAt0p32mxX7t6oTNU9+wziMnP1eGX3L7Os PCeIFvmvOI7qslAFVfmhJARyi0iyKLPhF0+GNTDiYyBkRlSQY8e2UmjjrImeAU6HW2Fu PGnIlQ+E9XGJy4/1kD3PBfdsk+U1WpX9YLG+ZAMTkTxsWrHfd7FTKAhBGkM+YIMOvd7k 95YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=b27TGt+Hn8NrfLXSKNSDHXzQuDrzaODyPS80YYWdBgo=; b=Qvch7ca1NpR2/7wWp3kkoehFkhHmI1nuSHtmUqfYFdJe8pMN3HtRXJeev3UaIFKkQe xFXnjUpyMHrJ+mT3vCkR2wu1+i24XJIvwzTZ+WhJTY2aD7UV0LXByAcGk8ktHbA6IuDB 5h5RYSmv95c5ASK49RPzgrOH8TkqNHfo9wxECYR6hwYFiq50ZW/cTcChYNnhq2ZDQETh TupEPv/YXKEtuxVR7c6Ds3/vQfpz49a/lnwemPibQLTN6LPRPVc8pIuA564LVYZ94XmJ rLcobNe9GEgb3PWaZmoFU9oCbCpWMblJITfb4wO9R5A74yG0CD0k4KWuJNRaHMUHERYC YuaQ== X-Gm-Message-State: AJaThX5QBXDlmvaPE47x/nlbgzfVRehkSjW6/ptz22z9ytY2MZ/0bUVl 9OgEwMQ1CueT+xjxuF10mU2yfw== X-Received: by 10.80.135.26 with SMTP id i26mr25208311edb.31.1511280690386; Tue, 21 Nov 2017 08:11:30 -0800 (PST) Received: from ch-sta-l-li0012 (mail.sensirion.com. [212.243.229.186]) by smtp.gmail.com with ESMTPSA id h16sm9377666edj.33.2017.11.21.08.11.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Nov 2017 08:11:29 -0800 (PST) Message-ID: <1511280689.12439.36.camel@elementarea.net> Subject: [PATCH 2/2] iio: chemical: sgpxx: triggered buffer support From: Andreas Brauchli To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 21 Nov 2017 17:11:29 +0100 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support triggered buffer for use with e.g. hrtimer for automated polling to ensure that the sensor's internal baseline is correctly updated independently of the use-case. Triggered buffer support is only enabled when IIO_BUFFER is set. Signed-off-by: Andreas Brauchli --- drivers/iio/chemical/Kconfig | 3 +++ drivers/iio/chemical/sgpxx.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig index 4574dd687513..6710fbfc6451 100644 --- a/drivers/iio/chemical/Kconfig +++ b/drivers/iio/chemical/Kconfig @@ -42,12 +42,15 @@ config SENSIRION_SGPXX tristate "Sensirion SGPxx gas sensors" depends on I2C select CRC8 + select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) help Say Y here to build I2C interface support for the following Sensirion SGP gas sensors: * SGP30 gas sensor * SGPC3 gas sensor + Also select IIO_BUFFER to enable triggered buffers. + To compile this driver as module, choose M here: the module will be called sgpxx. diff --git a/drivers/iio/chemical/sgpxx.c b/drivers/iio/chemical/sgpxx.c index aea55e41d4cc..025206448f73 100644 --- a/drivers/iio/chemical/sgpxx.c +++ b/drivers/iio/chemical/sgpxx.c @@ -27,6 +27,10 @@ #include #include #include +#ifdef CONFIG_IIO_BUFFER +#include +#include +#endif /* CONFIG_IIO_BUFFER */ #include #define SGP_WORD_LEN 2 @@ -789,6 +793,26 @@ static const struct of_device_id sgp_dt_ids[] = { { } }; +#ifdef CONFIG_IIO_BUFFER +static irqreturn_t sgp_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct sgp_data *data = iio_priv(indio_dev); + int ret; + + ret = sgp_get_measurement(data, data->measure_iaq_cmd, + SGP_MEASURE_MODE_IAQ); + if (!ret) + iio_push_to_buffers_with_timestamp(indio_dev, + &data->buffer.start, + pf->timestamp); + + iio_trigger_notify_done(indio_dev->trig); + return IRQ_HANDLED; +} +#endif /* CONFIG_IIO_BUFFER */ + static int sgp_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -846,6 +870,17 @@ static int sgp_probe(struct i2c_client *client, indio_dev->channels = chip->channels; indio_dev->num_channels = chip->num_channels; +#ifdef CONFIG_IIO_BUFFER + ret = iio_triggered_buffer_setup(indio_dev, + iio_pollfunc_store_time, + sgp_trigger_handler, + NULL); + if (ret) { + dev_err(&client->dev, "failed to setup iio triggered buffer\n"); + goto fail_free; + } +#endif /* CONFIG_IIO_BUFFER */ + ret = devm_iio_device_register(&client->dev, indio_dev); if (!ret) return ret; @@ -863,6 +898,9 @@ static int sgp_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); +#ifdef CONFIG_IIO_BUFFER + iio_triggered_buffer_cleanup(indio_dev); +#endif /* CONFIG_IIO_BUFFER */ devm_iio_device_unregister(&client->dev, indio_dev); return 0; } -- 2.14.1 From 1584957820886584484@xxx Fri Nov 24 14:26:06 +0000 2017 X-GM-THRID: 1584956522808870473 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread