Received: by 10.192.245.15 with SMTP id i15csp944384imn; Sat, 10 Mar 2018 14:07:32 -0800 (PST) X-Google-Smtp-Source: AG47ELvsF9wm7s4DHeZ/bI1ogzHI6fmYt+Wkp/g65NBGz7OwRAhy4YJjmJc7he4NC4wSncs/LCid X-Received: by 10.98.63.147 with SMTP id z19mr3028966pfj.221.1520719651976; Sat, 10 Mar 2018 14:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520719651; cv=none; d=google.com; s=arc-20160816; b=SUMiZkZtmuzHglqvPfdpFbUQM1SYkFiltJb8LWUvnWMGq+hme3cL0e+iIZwU5eGgm2 iDGCCPgRy6x429lz/RpJU6DYz4O25+dYS2qBB7AkT8rvwVWXt16Lvq2XzRayn8wRcFEy WFJzXsq10Nihe/VF4h0EPj+3CoQ2mUtwrMUZikFvWw1KPGbQuT21KOrBYDPcg3zb77fw SdfgWmsffMwvbjwT5NF58xVL94+cisJfsqRHvUJEZiJGx4YVfUFrOB7GCJ8qmvOQ8Uhq IxQEN41BSYwcvBwYhZI3XtBopOm2N8Tdn457OfwhwODaM+awyZ6NvMFskwIhyzcBfYEU 9L8A== 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 :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature:arc-authentication-results; bh=P56LR9DDlpuJNPWTopJpJve3P/Sf1xV2AwOmBlo++HU=; b=NHBWUaToVINSdSmb5hdwbxVvZhYI/leratC9MRH6VmN+WIlLHNR1ar1Hmk6UPz1Uya 5FM+YAPLkRXygJQELAvstbCyZy3iHntA0t9r4leTKmJ17XZcbK8Ncl/0OzSaaHzC+R2G 8Zs5ONmV49hPFh1K59p7+FIWaKAhZmQ/pqlyrJjyo5HcDYl48b8QJyyVXPcCRVRwNfOk pTSZYXCy3gfseo/WHNSSTwBfXi06MxTxC8hN+pVipov4wHS8m9c7BBDSmxY0768Ah2KD 7cLyh495XhZcH1CinvkCgn3GyQISfBa9en8Zkgj5G71zTZ9ZE88yA/3J1smVgInDmjDA v9Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@elementarea-net.20150623.gappssmtp.com header.s=20150623 header.b=2OVMMJJ1; 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 g86si3263968pfk.94.2018.03.10.14.07.17; Sat, 10 Mar 2018 14:07:31 -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=2OVMMJJ1; 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 S1751234AbeCJWGT (ORCPT + 99 others); Sat, 10 Mar 2018 17:06:19 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:39811 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751151AbeCJWGR (ORCPT ); Sat, 10 Mar 2018 17:06:17 -0500 Received: by mail-wm0-f68.google.com with SMTP id i3so9643068wmi.4 for ; Sat, 10 Mar 2018 14:06:16 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=P56LR9DDlpuJNPWTopJpJve3P/Sf1xV2AwOmBlo++HU=; b=2OVMMJJ1WUP6HahlLC7Sfu3DyeMKd2l0l5nC6MJGTgwrQ33VTUM/uTpX3nqbFItQxh wJBWRRcquNc449Rd0/KwRxm5TIN5elNxv2vOH81k7xzDBMcCF8oC4qD7TFloFvgCjqMT +z+6RZThEnBQVq9dLkRZPGK7tM3hlrk3Qrr6JdZ2CHVkq+OFQVanfLWFJeT3ycaE4C82 iIwcS+QJbdG8LR5P2eulsGURQJkY+0K7KGvSP+5hobnuUdFKC28oTmB36nEkQKrEUR03 7w9a7JWJhumJx5TR/dI7XMahGV1VEd6xrN+emSXXgWy2Wy8fqC/ejcC2y5KSMe55iPOs w3Ng== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=P56LR9DDlpuJNPWTopJpJve3P/Sf1xV2AwOmBlo++HU=; b=ksZU5FgVs/uTz+uP5I9hGdTMMpc9q+EufmKKxiykLfqMyqE+C0tuQ8TMKT42M49XwH W+JrJQx6lSEsSnZBDg5Y7AJekKuu506ojfFYBnx971Xzj9FXyWWJFrlqeiHXxe2TLGX3 fDKChrSLqD6hWOgy0iPplB8wFWsreceOw+9Agq5Kn5j+VYkAldwCsAjOLARNosJtjOXG WEpjkG13eOw20gP8DKyta5z5LsiuhALBwyZ+26mElcNgOs7E/2g9+EkM2X+AWUqLjxYB r0A8oaRtmaBkkT5LIaSJNOrWk4llSybt7C+icA4ZgOUetYB2Ueqj9SjZRW7s4vv2CsLR gnuw== X-Gm-Message-State: AElRT7FENbAa9fJaBaRq//5CTndpAWoVMJrFOgCLAmC5ZRtUfOEVWCzz JwO+JvkIHngt1Augye6EIfqrQQ== X-Received: by 10.28.106.18 with SMTP id f18mr1946151wmc.51.1520719576205; Sat, 10 Mar 2018 14:06:16 -0800 (PST) Received: from ch-sta-l-li0012 (84-74-221-84.dclient.hispeed.ch. [84.74.221.84]) by smtp.gmail.com with ESMTPSA id 96sm5018639wrk.54.2018.03.10.14.06.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 10 Mar 2018 14:06:15 -0800 (PST) Message-ID: <084b2bfbc9bf88ff000609d7bc0dace985790d1f.camel@elementarea.net> Subject: Re: [PATCH 2/2] iio: chemical: sgpxx: triggered buffer support From: Andreas Brauchli To: Jonathan Cameron Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sat, 10 Mar 2018 23:06:14 +0100 In-Reply-To: <20171125174848.2d3d5b74@archlinux> References: <1511280689.12439.36.camel@elementarea.net> <20171125174848.2d3d5b74@archlinux> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.27.90-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 On Sat, 2017-11-25 at 17:48 +0000, Jonathan Cameron wrote: > On Tue, 21 Nov 2017 17:11:29 +0100 > Andreas Brauchli wrote: > > > 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. > > Given the really strict timing requirements for this device and slow > read rates, I wouldn't involve a triggered buffer at all, but > actually > do it with a thread / timer within the initial driver. The > sysfs interface is more than adequate for a 1Hz device so using > the buffered option is just adding unnecessary complexity... Thanks for the suggestions, I went with that in v2. > > I reviewed the code anyway. Key thing is though the file would be > small, there should be a separate .c file for the buffered support > if you are going to make it optional. That way we don't get ifdefs > in the c file, but rather stubs provided in the header. FWIW, I learned a few things > You could decide to add stubs to include/linux/iio/triggered_buffer.h > /buffer.h > > and then use __maybe_unusued to mark your trigger function. > The compiler would drop it anyway and this would suppress build > warnings. > > However, I don't think this device wants to be supported via the > buffered interfaces at all. More smartness needed in the core > driver to maintain the timing etc. > > Jonathan > > > > 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 > > All this ifdef fun is rather messy. > Split it out to a separate file like most other drivers with > optional buffer support. > > General rule (more or less) of kernel drivers is that > any optional ifdef stuff should be in headers to provide stubs > when code isn't available, not down in the drivers making them > harder to read. > > > +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 */ > > I would prefer stubs being added to the header for this case to > having > ifdefs in here. > > > devm_iio_device_unregister(&client->dev, indio_dev); > > return 0; > > } > >