Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2464048pxt; Mon, 9 Aug 2021 00:50:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRIzMjp9S9Q6QTeVbrclq2sytC8BdOFMOAVZskFTTrvr+cpDGCXZenwFHTgTBsp+nAyBV9 X-Received: by 2002:a17:906:56ca:: with SMTP id an10mr21609153ejc.90.1628495441932; Mon, 09 Aug 2021 00:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628495441; cv=none; d=google.com; s=arc-20160816; b=rQvApldKwKbFQhTJ9Be01eKoi1c1HvzPCach0CnYtQO+v5G5zcKx8ZwRuABamsvN4H Sp4uihcVnGcp2EpPx7OacmbqQ0N7szU0RjkFst4t/MgvDj1H9VNwwwtQ6HDGsNZQMWSX AQ+RgwRvVdc2K4FgMpnKmlyqx3H31WiyjWN9tMs6xtr0EPxRiIsvAhGmoqWWtZpjWfnM 3r7YnBEbDV7qEvsW4MtwY3asdSNdf5L6jnkHaqD0q71658EGmI9YaL5918kEXkOTUvIT I1tTb5PaxWuJUzdN7VlwPJQhckzFM4lSTdiV4Lfb/XVOpJ3B9h30717LDHu0dcFafKtg OgYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=95DgjYsJqVmq4MdhlTcH4MrWr0NBdjqbFECgPrk7ymQ=; b=bBQEKXBSfP4/XTSCNJgAcZrswLO6oXTA5lNeMbJpbhQUviVffRkj3TmXE+c51S1hxW rew/SPPAzu7dBPhuEvdhdW2vDC4ctunnllyGWkKtUmkE0WsxGaM3DPB+HYLm2ercKSpq sglBcrp8ywl5mrvQ8aSfmXFFLr0Nok85dX5qMW/U3b4daL+lrpSMYcTmFVwgK/Y9OwtM BCsGQS0KyTr8IB2wWWRllfPsw1AtsyGPFJG262B5Zb3dwPJo1wc2+qMpSrKF/TlD8od4 rxoIzOUdjajEGVj/z42NUPIg1LKJdy7fKsZtSXdXS63E1y0dTKthxFNXbaxA5DswDw/g JJFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SDJQMlcI; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ew1si16626023ejb.614.2021.08.09.00.50.18; Mon, 09 Aug 2021 00:50:41 -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=@gmail.com header.s=20161025 header.b=SDJQMlcI; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233599AbhHIHrc (ORCPT + 99 others); Mon, 9 Aug 2021 03:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233568AbhHIHrb (ORCPT ); Mon, 9 Aug 2021 03:47:31 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85365C0613CF; Mon, 9 Aug 2021 00:47:11 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id c24so5294240lfi.11; Mon, 09 Aug 2021 00:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=95DgjYsJqVmq4MdhlTcH4MrWr0NBdjqbFECgPrk7ymQ=; b=SDJQMlcIPwtsV0R2J0lnm8o9sH35K6pblpzZGX72WJip4axoCpqRd3b60UCxYRAKfi fmGqGqvgJ3oSIifJhUuXhtSTuNyZtGlL5bBNtoGZtjblLI0U5Ii+f5dtVU0Xz3B58gRy l/9VXKsDRPJz4r+p+Ga3CQhwe2AK97VuHEm1s8L85lpowKmQ/AHsdp7uDntptQ49RKqo /9Y4QaWwLl9PiexCobD+clm1AwirUkV844CE/Hiax+VHIemEcJVAO76kFeRuMBQO7L5F Vj76QSGHDiIvAGG8eIkIfqP6J9+eZ7LAI27DdNy1AhG5o+Re+xk+FadV+5+Oe/99HLjn YWVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=95DgjYsJqVmq4MdhlTcH4MrWr0NBdjqbFECgPrk7ymQ=; b=nMtBQ6FKt0stYWgAbZfvjmr1x2qsAfmJcmrulKfqsA61ELS+bVT5WiFj2bQ/UByp7L rzClAGN3arCoVM5GMQpRIo9bGuGVg1IQa4NJTtkY6mI6upm5qY2Wx07zLMfb1iD6dgY6 gSxuWV3KlxVW8wIUPjsfM5IQEXafOQnHmyD27gx82piFqK7t5APPhD2Vf/R52wHGkp01 wuMaEVmw6o1UB1qLDSIQL8e2Td6ez6+Cd2tjc1UGmiU+EWqnYbSO4H1XDT+fiYHerphU scaQNovM9IhbzvrkqMlQrVNN6kXIM21DEyLSyt/P6m2bAPljVjlc3w4oP6oyeAsw43Tm iGeQ== X-Gm-Message-State: AOAM531Z4LCEFAqwZcH38cs9s9se0D+4TeXHAZaNRUuaagAk+ytSYgH7 Z+6V5VjNJknZiNt9p7qu8D00WljjW3ewWRbnFWA= X-Received: by 2002:ac2:4c13:: with SMTP id t19mr16578544lfq.450.1628495229877; Mon, 09 Aug 2021 00:47:09 -0700 (PDT) MIME-Version: 1.0 References: <20210809074512.34757-1-puranjay12@gmail.com> <20210809074512.34757-3-puranjay12@gmail.com> In-Reply-To: <20210809074512.34757-3-puranjay12@gmail.com> From: Puranjay Mohan Date: Mon, 9 Aug 2021 13:16:58 +0530 Message-ID: Subject: Re: [PATCH v9 2/2] iio: accel: adxl355: Add triggered buffer support To: "Hennerich, Michael" , Jonathan Cameron , devicetree , linux-iio , Linux Kernel Mailing List , Lars-Peter Clausen , "Bogdan, Dragos" , "Berghe, Darius" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Please ignore this patch. It was sent by mistake, it is not supposed to be a part of this series. On Mon, Aug 9, 2021 at 1:15 PM Puranjay Mohan wrote: > > Provide a way for continuous data capture by setting up buffer support. The > data ready signal exposed at the DRDY pin of the ADXL355 is exploited as > a hardware interrupt which triggers to fill the buffer. > > Signed-off-by: Puranjay Mohan > --- > drivers/iio/accel/Kconfig | 4 ++ > drivers/iio/accel/adxl355.h | 2 +- > drivers/iio/accel/adxl355_core.c | 102 ++++++++++++++++++++++++++++++- > drivers/iio/accel/adxl355_i2c.c | 3 +- > drivers/iio/accel/adxl355_spi.c | 2 +- > 5 files changed, 108 insertions(+), 5 deletions(-) > > diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig > index d0c45c809..9c16c1841 100644 > --- a/drivers/iio/accel/Kconfig > +++ b/drivers/iio/accel/Kconfig > @@ -69,6 +69,8 @@ config ADXL355_I2C > depends on I2C > select ADXL355 > select REGMAP_I2C > + select IIO_BUFFER > + select IIO_TRIGGERED_BUFFER > help > Say Y here if you want to build i2c support for the Analog Devices > ADXL355 3-axis digital accelerometer. > @@ -82,6 +84,8 @@ config ADXL355_SPI > depends on SPI > select ADXL355 > select REGMAP_SPI > + select IIO_BUFFER > + select IIO_TRIGGERED_BUFFER > help > Say Y here if you want to build spi support for the Analog Devices > ADXL355 3-axis digital accelerometer. > diff --git a/drivers/iio/accel/adxl355.h b/drivers/iio/accel/adxl355.h > index 322b0abb8..f0a376e6d 100644 > --- a/drivers/iio/accel/adxl355.h > +++ b/drivers/iio/accel/adxl355.h > @@ -15,5 +15,5 @@ extern const struct regmap_access_table adxl355_readable_regs_tbl; > extern const struct regmap_access_table adxl355_writeable_regs_tbl; > > int adxl355_core_probe(struct device *dev, struct regmap *regmap, > - const char *name); > + const char *name, int irq); > #endif /* _ADXL355_H_ */ > diff --git a/drivers/iio/accel/adxl355_core.c b/drivers/iio/accel/adxl355_core.c > index d1163cde1..45397dcce 100644 > --- a/drivers/iio/accel/adxl355_core.c > +++ b/drivers/iio/accel/adxl355_core.c > @@ -9,6 +9,10 @@ > > #include > #include > +#include > +#include > +#include > +#include > #include > #include > #include > @@ -153,6 +157,7 @@ static const struct adxl355_chan_info adxl355_chans[] = { > }; > > struct adxl355_data { > + int irq; > struct regmap *regmap; > struct device *dev; > struct mutex lock; /* lock to protect op_mode */ > @@ -162,6 +167,12 @@ struct adxl355_data { > int calibbias[3]; > int adxl355_hpf_3db_table[7][2]; > u8 transf_buf[3] ____cacheline_aligned; > + struct iio_trigger *dready_trig; > + /* Ensure correct alignment of timestamp when present */ > + struct { > + __be32 channels[3]; > + s64 ts; > + } buffer ____cacheline_aligned; > }; > > static int adxl355_set_op_mode(struct adxl355_data *data, > @@ -493,12 +504,46 @@ static int adxl355_read_avail(struct iio_dev *indio_dev, > } > } > > +static const unsigned long adxl355_avail_scan_masks[] = { > + GENMASK(3, 0), > + 0 > +}; > + > static const struct iio_info adxl355_info = { > .read_raw = adxl355_read_raw, > .write_raw = adxl355_write_raw, > .read_avail = &adxl355_read_avail > }; > > +static const struct iio_trigger_ops adxl355_trigger_ops = { > + .validate_device = &iio_trigger_validate_own_device, > +}; > + > +static irqreturn_t adxl355_trigger_handler(int irq, void *p) > +{ > + struct iio_poll_func *pf = p; > + struct iio_dev *indio_dev = pf->indio_dev; > + struct adxl355_data *data = iio_priv(indio_dev); > + int ret; > + > + mutex_lock(&data->lock); > + > + ret = regmap_bulk_read(data->regmap, ADXL355_XDATA3_REG, > + data->buffer.channels, > + 9); > + if (ret) > + goto out_unlock_notify; > + > + iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, > + pf->timestamp); > + > +out_unlock_notify: > + mutex_unlock(&data->lock); > + iio_trigger_notify_done(indio_dev->trig); > + > + return IRQ_HANDLED; > +} > + > #define ADXL355_ACCEL_CHANNEL(index, reg, axis) { \ > .type = IIO_ACCEL, \ > .address = reg, \ > @@ -512,6 +557,7 @@ static const struct iio_info adxl355_info = { > .info_mask_shared_by_type_available = \ > BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ > BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \ > + .scan_index = index, \ > .scan_type = { \ > .sign = 's', \ > .realbits = 20, \ > @@ -531,17 +577,56 @@ static const struct iio_chan_spec adxl355_channels[] = { > .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | > BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OFFSET), > + .scan_index = 3, > .scan_type = { > .sign = 's', > .realbits = 12, > .storagebits = 16, > .endianness = IIO_BE, > }, > - } > + }, > + IIO_CHAN_SOFT_TIMESTAMP(4) > }; > > +static int adxl355_probe_trigger(struct iio_dev *indio_dev) > +{ > + struct adxl355_data *data = iio_priv(indio_dev); > + int ret; > + > + if (!data->irq) { > + dev_info(data->dev, "no irq, using polling\n"); > + return 0; > + } > + > + data->dready_trig = devm_iio_trigger_alloc(data->dev, "%s-dev%d", > + indio_dev->name, > + indio_dev->id); > + if (!data->dready_trig) > + return -ENOMEM; > + > + data->dready_trig->ops = &adxl355_trigger_ops; > + iio_trigger_set_drvdata(data->dready_trig, indio_dev); > + > + ret = devm_request_irq(data->dev, data->irq, > + &iio_trigger_generic_data_rdy_poll, > + IRQF_ONESHOT, "adxl355_irq", data->dready_trig); > + if (ret < 0) > + return dev_err_probe(data->dev, ret, "request irq %d failed\n", > + data->irq); > + > + ret = devm_iio_trigger_register(data->dev, data->dready_trig); > + if (ret) { > + dev_err(data->dev, "iio trigger register failed\n"); > + return ret; > + } > + > + indio_dev->trig = iio_trigger_get(data->dready_trig); > + > + return 0; > +} > + > int adxl355_core_probe(struct device *dev, struct regmap *regmap, > - const char *name) > + const char *name, int irq) > { > struct adxl355_data *data; > struct iio_dev *indio_dev; > @@ -554,6 +639,7 @@ int adxl355_core_probe(struct device *dev, struct regmap *regmap, > data = iio_priv(indio_dev); > data->regmap = regmap; > data->dev = dev; > + data->irq = irq; > data->op_mode = ADXL355_STANDBY; > mutex_init(&data->lock); > > @@ -562,6 +648,7 @@ int adxl355_core_probe(struct device *dev, struct regmap *regmap, > indio_dev->modes = INDIO_DIRECT_MODE; > indio_dev->channels = adxl355_channels; > indio_dev->num_channels = ARRAY_SIZE(adxl355_channels); > + indio_dev->available_scan_masks = adxl355_avail_scan_masks; > > ret = adxl355_setup(data); > if (ret < 0) { > @@ -569,6 +656,17 @@ int adxl355_core_probe(struct device *dev, struct regmap *regmap, > return ret; > } > > + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, > + &iio_pollfunc_store_time, > + &adxl355_trigger_handler, NULL); > + if (ret < 0) > + return dev_err_probe(dev, ret, > + "iio triggered buffer setup failed\n"); > + > + ret = adxl355_probe_trigger(indio_dev); > + if (ret < 0) > + return ret; > + > return devm_iio_device_register(dev, indio_dev); > } > EXPORT_SYMBOL_GPL(adxl355_core_probe); > diff --git a/drivers/iio/accel/adxl355_i2c.c b/drivers/iio/accel/adxl355_i2c.c > index e3070ee81..c18521819 100644 > --- a/drivers/iio/accel/adxl355_i2c.c > +++ b/drivers/iio/accel/adxl355_i2c.c > @@ -31,7 +31,8 @@ static int adxl355_i2c_probe(struct i2c_client *client) > return PTR_ERR(regmap); > } > > - return adxl355_core_probe(&client->dev, regmap, client->name); > + return adxl355_core_probe(&client->dev, regmap, client->name, > + client->irq); > } > > static const struct i2c_device_id adxl355_i2c_id[] = { > diff --git a/drivers/iio/accel/adxl355_spi.c b/drivers/iio/accel/adxl355_spi.c > index a16bd1407..f9ba153f6 100644 > --- a/drivers/iio/accel/adxl355_spi.c > +++ b/drivers/iio/accel/adxl355_spi.c > @@ -34,7 +34,7 @@ static int adxl355_spi_probe(struct spi_device *spi) > return PTR_ERR(regmap); > } > > - return adxl355_core_probe(&spi->dev, regmap, id->name); > + return adxl355_core_probe(&spi->dev, regmap, id->name, spi->irq); > } > > static const struct spi_device_id adxl355_spi_id[] = { > -- > 2.30.1 > -- Thanks and Regards Yours Truly, Puranjay Mohan