Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp521579ybh; Sat, 7 Mar 2020 04:03:41 -0800 (PST) X-Google-Smtp-Source: ADFU+vvOElYpdg67qVIE9stdAbLoN0vbH1VDrb6cOR7eVeA3mSbKkhkXOH2JGeB1IHtNEkm0b66c X-Received: by 2002:aca:cf48:: with SMTP id f69mr5313084oig.122.1583582621537; Sat, 07 Mar 2020 04:03:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583582621; cv=none; d=google.com; s=arc-20160816; b=YHqWDQEEJ0cMDTG+W4NyddgJY2BOkEUK9YGNKXVpHDqssMta7zZWN+KZ+ZOa+8thn1 j41E1gbHxTvQaH4h1jYxOXRHp31mDdh3rzSExADobHzJQpid71m5Fs0xAhzJw/RmjjvL sm7QmKgZj/YXiYt5FbcpO3PKW1mdEjSuw/65hsBdZiZNbMV9xiVA2MtA0cVTogDoz+r9 2Rte4KDZDdNZzAyRHc2M1AFSSW6BwFkqSjntnk9Y09mACENcpvtFgFgVnKjPUrQWNfKA GK5xx4PAdlWLKv88J8KuN7eey1XYRSvY85O02f1iKGVUrC6I6hBO9l3t+n85h0CBx6EC 9uyw== 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:message-id:subject:cc:to:from:date :dkim-signature; bh=48dx16WJYm8vG3Qk1v3o1Re9cFN1rerWjwdvEnegq9Q=; b=NadrRcYGhA6VIBphZiD/dBBlnvDbBYLWyB68Vmx3ZKNpXrVrm4b5KfXLwDmmd7zXZC oKqlzYAT87Y/AiV6cNyWUZ3k06iFVwvxsTifBEB5FCwPaA/SKPSxZuR+gxMPw239LNTk Cj5Ht7H3VWyyLXggAgKR1jkifvPqbRCzLR5uPSpGfHWAJQFsai+9CvAxpdZFr1E+RWs4 dok6ScwGwarq7ncO7VEIJoR9IM2Lgn1I74NIi2m3lPAGeaC4W9+cQl1wbNa4efmN0K9q xTxVAvs71Ux9DJo+5LA1QzrjirUvl9LVsnAnRPKxMw3u4XY93ahr+zuVsLyzxSFZ3CHV xDzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I6UAesuH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z24si2985508otq.201.2020.03.07.04.03.27; Sat, 07 Mar 2020 04:03:41 -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=@kernel.org header.s=default header.b=I6UAesuH; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726109AbgCGMCp (ORCPT + 99 others); Sat, 7 Mar 2020 07:02:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:51614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726017AbgCGMCp (ORCPT ); Sat, 7 Mar 2020 07:02:45 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4049C2075A; Sat, 7 Mar 2020 12:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583582564; bh=h4LZiNlY3M3sfJcyIUQooDL+8Nx54UuhSZVLawI2IaQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=I6UAesuHdH6qF8zX7LQ0XU5iEMsIHKT9nMdjZGlwPHWOG2EfHZTgIAOcA6ku2QDOP IbKT75AAckhh6mPgGlCBkb3baDr+9x2CtSx3Esey7qWu/mWMHQ32rNBdwCl0leH5SL tOMLAvaMLI/oSxgvhxF14mlNkBlnx1Dk6KV5BiKc= Date: Sat, 7 Mar 2020 12:02:41 +0000 From: Jonathan Cameron To: Alexandru Tachici Cc: , Subject: Re: [PATCH v2 1/6] iio: accel: adxl372: Add support for FIFO peak mode Message-ID: <20200307120241.7bee0dc8@archlinux> In-Reply-To: <20200225120909.12629-2-alexandru.tachici@analog.com> References: <20200225120909.12629-1-alexandru.tachici@analog.com> <20200225120909.12629-2-alexandru.tachici@analog.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Feb 2020 14:09:04 +0200 Alexandru Tachici wrote: > From: Stefan Popa > > By default, if all three channels (x, y, z) are enabled, sample sets of > concurrent 3-axis data is stored in the FIFO. This patch adds the option > to configure the FIFO to store peak acceleration (x, y and z) of every > over-threshold event. Since we cannot store 1 or 2 axis peak acceleration > data in the FIFO, then all three axis need to be enabled in order for this > mode to work. > > Signed-off-by: Stefan Popa First apologies this was one of the sets that I didn't get to last week. This is a bit of an odd one, but I suppose the general approach is fine. A few questions on specifics inline. > --- > drivers/iio/accel/adxl372.c | 46 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 46 insertions(+) > > diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c > index 67b8817995c0..ed93534f8dba 100644 > --- a/drivers/iio/accel/adxl372.c > +++ b/drivers/iio/accel/adxl372.c > @@ -264,6 +264,7 @@ struct adxl372_state { > u8 int2_bitmask; > u16 watermark; > __be16 fifo_buf[ADXL372_FIFO_SIZE]; > + bool peak_fifo_mode_en; > }; > > static const unsigned long adxl372_channel_masks[] = { > @@ -722,6 +723,40 @@ static int adxl372_write_raw(struct iio_dev *indio_dev, > } > } > > +static ssize_t adxl372_peak_fifo_en_get(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + struct adxl372_state *st = iio_priv(dev_to_iio_dev(dev)); > + > + return sprintf(buf, "%d\n", st->peak_fifo_mode_en); > +} > + > +static ssize_t adxl372_peak_fifo_en_set(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t len) > +{ > + struct iio_dev *indio_dev = dev_to_iio_dev(dev); > + struct adxl372_state *st = iio_priv(indio_dev); > + bool val; > + int ret; > + > + if (iio_buffer_enabled(indio_dev)) > + return -EBUSY; Prefer if you use the iio_claim_direct_mode to ensure we are in non buffered mode until we reach a consistent state. Then set the variable and release direct mode. Otherwise you might have a race between a write to this and enabling the buffered mode. > + > + ret = kstrtobool(buf, &val); > + if (ret) > + return ret; > + > + st->peak_fifo_mode_en = val; > + > + return len; > +} > + > +static IIO_DEVICE_ATTR(buffer_peak_mode_enable, 0644, > + adxl372_peak_fifo_en_get, > + adxl372_peak_fifo_en_set, 0); > + > static ssize_t adxl372_show_filter_freq_avail(struct device *dev, > struct device_attribute *attr, > char *buf) > @@ -817,11 +852,21 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev) > st->fifo_format = adxl372_axis_lookup_table[i].fifo_format; > st->fifo_set_size = bitmap_weight(indio_dev->active_scan_mask, > indio_dev->masklength); > + > + /* Configure the FIFO to store sets of impact event peak. */ > + if (st->peak_fifo_mode_en) { > + st->fifo_format = ADXL372_XYZ_PEAK_FIFO; > + if (st->fifo_set_size != 3) > + dev_warn(&indio_dev->dev, > + "All axis must be enabled in peak mode."); What happens otherwise? Real question is should this just be an error and result in us dropping out of buffered mode again? How would a userspace program that had hit this know there was an issue? > + } > + > /* > * The 512 FIFO samples can be allotted in several ways, such as: > * 170 sample sets of concurrent 3-axis data > * 256 sample sets of concurrent 2-axis data (user selectable) > * 512 sample sets of single-axis data > + * 170 sets of impact event peak (x, y, z) > */ > if ((st->watermark * st->fifo_set_size) > ADXL372_FIFO_SIZE) > st->watermark = (ADXL372_FIFO_SIZE / st->fifo_set_size); > @@ -894,6 +939,7 @@ static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available, > static struct attribute *adxl372_attributes[] = { > &iio_const_attr_sampling_frequency_available.dev_attr.attr, > &iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr, > + &iio_dev_attr_buffer_peak_mode_enable.dev_attr.attr, > NULL, > }; >