Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3618747pxa; Sun, 9 Aug 2020 06:15:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNX8QTu3lTru9zFdlh7M+EckTyI4LAslV0vqQ8jigjOoglfl4bxqOCQUh7JR9Owm+Wkyyf X-Received: by 2002:a17:906:95d4:: with SMTP id n20mr18657678ejy.485.1596978912350; Sun, 09 Aug 2020 06:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596978912; cv=none; d=google.com; s=arc-20160816; b=Ca1rsRdbx4j9nq6ZS12t4qcba3E8WtoYZKP2cvYGKvMnT+6AL+d1qsFzrp32NNPNcw bwXWv1WUxMOsL+eqv0rXnxmjurq+P2GCjRpBJJ2TaK0XHUeZS5NQb1XiEWhLc0e7/aF+ N9K5mAZurcKAE0BhB4LBZUKcUIGV7wzwVuSBW+V8I6ccdIxZcbWjbSQOaAPOdi//8SZp Fb2hmOVa+81JPaVZO6BQs5nLfD7G9Kt4Q4r+8adzT5hZ+5T36XqoUcu++W/Zlq4UIR0R yJFe5BV5e7OqOnsg5fK3tUPzOhyM/xzc1C1/faO3XZ2/x5CTiRZQUA4uTJDUn5ClttLT 15qQ== 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=0pzubSUK0JQKBYqjFog/VxZXj6JdDPOh513oUEIQYb4=; b=wJv9MF6I2KcR/xZ0MEhtUEpeA4VMIcBp7CDEzHJmnHqJPnf+IUsHDZNTnnllnQ+brZ MGdj6AtLKnFDGMX87Zpzs/OB/hIjGiV1HqTe3eA5EuXjG/IexgVfVrfgr4fukKW3hCLK nowDh8c++OcC5eGtFZ8THuOVPwKy+6LehvqAE9JhT3daswWJl1EZJcXsu/5MpN9QE/MR hApHUMdqkWzHQwLmnvj/AeqrV00grAOQtmYNHLrSBBH2FiEW+uegxA6VFTNHQhtQTkwh VzyQtPtd1htDKfaQXkXvw9F2J3mf/cWRx8enygzwq/rdIjdB9j/Othk6Tbh6xnxv8FSF nAVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nqGWlrx0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id q22si8935658ejn.410.2020.08.09.06.14.46; Sun, 09 Aug 2020 06:15:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nqGWlrx0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726296AbgHINL3 (ORCPT + 99 others); Sun, 9 Aug 2020 09:11:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:39918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726009AbgHINL3 (ORCPT ); Sun, 9 Aug 2020 09:11:29 -0400 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 AFA90206B2; Sun, 9 Aug 2020 13:11:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596978688; bh=aP0hY9bkhbgRPx2mfyyskgRknbTRhqk2sfjNWJgD8Es=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nqGWlrx0HWvaCMZjCoUt27D5lQeTJyRLBtcJxNOVRKsshq7bHcpmL+1uzYBk1+HdT 9webwVzi/PWPIsCln8voZow9K1gW2XF5jkycXtPhdQad3Qh3G7kTiSvP9Scc4gi0/9 cJSTsHMVzJbYdiMpxM/ftgJf3MFjIWCuePIpVSFM= Date: Sun, 9 Aug 2020 14:11:24 +0100 From: Jonathan Cameron To: Cc: , Subject: Re: [PATCH v4 1/3] iio: accel: adxl372: Add support for FIFO peak mode Message-ID: <20200809141124.2d2dba56@archlinux> In-Reply-To: <20200803172219.33911-2-alexandru.tachici@analog.com> References: <20200803172219.33911-1-alexandru.tachici@analog.com> <20200803172219.33911-2-alexandru.tachici@analog.com> X-Mailer: Claws Mail 3.17.6 (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 Mon, 3 Aug 2020 20:22:17 +0300 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. When pushing to iio buffer we push only enabled > axis data. > > Signed-off-by: Stefan Popa Hi Stefan, A few things inline I missed on previous reads. Jonathan > --- > drivers/iio/accel/adxl372.c | 72 +++++++++++++++++++++++++++++++++++-- > 1 file changed, 70 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c > index 67b8817995c0..cce25cde6252 100644 > --- a/drivers/iio/accel/adxl372.c > +++ b/drivers/iio/accel/adxl372.c > @@ -133,6 +133,9 @@ > > /* The ADXL372 includes a deep, 512 sample FIFO buffer */ > #define ADXL372_FIFO_SIZE 512 > +#define ADXL372_X_AXIS_EN(x) (((x) >> 0) & 0x1) I hadn't noticed this before, but this is a slightly odd construct. Would be more normal to check against the mask directly, so something like... ((x) & BIT(0)) ((x) & BIT(1)) > +#define ADXL372_Y_AXIS_EN(x) (((x) >> 1) & 0x1) > +#define ADXL372_Z_AXIS_EN(x) (((x) >> 2) & 0x1) > > /* > * At +/- 200g with 12-bit resolution, scale is computed as: > @@ -251,8 +254,10 @@ struct adxl372_state { > struct device *dev; > struct regmap *regmap; > struct iio_trigger *dready_trig; > + struct iio_trigger *peak_datardy_trig; > enum adxl372_fifo_mode fifo_mode; > enum adxl372_fifo_format fifo_format; > + unsigned int fifo_axis_mask; > enum adxl372_op_mode op_mode; > enum adxl372_act_proc_mode act_proc_mode; > enum adxl372_odr odr; > @@ -264,6 +269,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[] = { > @@ -522,6 +528,22 @@ static int adxl372_get_status(struct adxl372_state *st, > return ret; > } > > +static void adxl372_arrange_axis_data(struct adxl372_state *st, __be16 *sample) > +{ > + __be16 axis_sample[3]; > + int i = 0; > + > + memset(axis_sample, 0, 3 * sizeof(__be16)); > + if (ADXL372_X_AXIS_EN(st->fifo_axis_mask)) > + axis_sample[i++] = sample[0]; > + if (ADXL372_Y_AXIS_EN(st->fifo_axis_mask)) > + axis_sample[i++] = sample[1]; > + if (ADXL372_Z_AXIS_EN(st->fifo_axis_mask)) > + axis_sample[i++] = sample[2]; > + > + memcpy(sample, axis_sample, 3 * sizeof(__be16)); > +} > + > static irqreturn_t adxl372_trigger_handler(int irq, void *p) > { > struct iio_poll_func *pf = p; > @@ -553,8 +575,12 @@ static irqreturn_t adxl372_trigger_handler(int irq, void *p) > goto err; > > /* Each sample is 2 bytes */ > - for (i = 0; i < fifo_entries; i += st->fifo_set_size) > + for (i = 0; i < fifo_entries; i += st->fifo_set_size) { > + /* filter peak detection data */ > + if (st->peak_fifo_mode_en) > + adxl372_arrange_axis_data(st, &st->fifo_buf[i]); > iio_push_to_buffers(indio_dev, &st->fifo_buf[i]); > + } > } > err: > iio_trigger_notify_done(indio_dev->trig); > @@ -815,13 +841,22 @@ static int adxl372_buffer_postenable(struct iio_dev *indio_dev) > } > > st->fifo_format = adxl372_axis_lookup_table[i].fifo_format; > + st->fifo_axis_mask = adxl372_axis_lookup_table[i].bits; > 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_set_size = 3; > + st->fifo_format = ADXL372_XYZ_PEAK_FIFO; > + } > + > /* > * 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); > @@ -876,7 +911,7 @@ static int adxl372_validate_trigger(struct iio_dev *indio_dev, > { > struct adxl372_state *st = iio_priv(indio_dev); > > - if (st->dready_trig != trig) > + if (st->dready_trig != trig && st->peak_datardy_trig != trig) > return -EINVAL; > > return 0; > @@ -887,6 +922,25 @@ static const struct iio_trigger_ops adxl372_trigger_ops = { > .set_trigger_state = adxl372_dready_trig_set_state, > }; > > +static int adxl372_peak_dready_trig_set_state(struct iio_trigger *trig, > + bool state) > +{ > + struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); > + struct adxl372_state *st = iio_priv(indio_dev); > + > + if (state) > + st->int1_bitmask |= ADXL372_INT1_MAP_FIFO_FULL_MSK; The original driver usage of int1_bitmask seems rather odd. There is a state variable for it, but it's not ever used. Here we seem to set this bit, but it is never cleared anywhere. If we don't actually need to store it globally, perhaps drop the variable in st? > + > + st->peak_fifo_mode_en = state; > + > + return adxl372_set_interrupts(st, st->int1_bitmask, 0); > +} > + > +static const struct iio_trigger_ops adxl372_peak_data_trigger_ops = { > + .validate_device = &iio_trigger_validate_own_device, > + .set_trigger_state = adxl372_peak_dready_trig_set_state, > +}; > + > static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("400 800 1600 3200 6400"); > static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available, > 0444, adxl372_show_filter_freq_avail, NULL, 0); > @@ -965,13 +1019,27 @@ int adxl372_probe(struct device *dev, struct regmap *regmap, > if (st->dready_trig == NULL) > return -ENOMEM; > > + st->peak_datardy_trig = devm_iio_trigger_alloc(dev, > + "%s-dev%d-peak", > + indio_dev->name, > + indio_dev->id); > + if (!st->peak_datardy_trig) > + return -ENOMEM; > + > st->dready_trig->ops = &adxl372_trigger_ops; > + st->peak_datardy_trig->ops = &adxl372_peak_data_trigger_ops; > st->dready_trig->dev.parent = dev; > + st->peak_datardy_trig->dev.parent = dev; > iio_trigger_set_drvdata(st->dready_trig, indio_dev); > + iio_trigger_set_drvdata(st->peak_datardy_trig, indio_dev); > ret = devm_iio_trigger_register(dev, st->dready_trig); > if (ret < 0) > return ret; > > + ret = devm_iio_trigger_register(dev, st->peak_datardy_trig); > + if (ret < 0) > + return ret; > + > indio_dev->trig = iio_trigger_get(st->dready_trig); > > ret = devm_request_threaded_irq(dev, st->irq,