linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Dmitry Rokosov <DDRokosov@sberdevices.ru>
Cc: "robh+dt@kernel.org" <robh+dt@kernel.org>,
	"stano.jakubek@gmail.com" <stano.jakubek@gmail.com>,
	"shawnguo@kernel.org" <shawnguo@kernel.org>,
	"lars@metafoo.de" <lars@metafoo.de>,
	"andy.shevchenko@gmail.com" <andy.shevchenko@gmail.com>,
	"stephan@gerhold.net" <stephan@gerhold.net>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	kernel <kernel@sberdevices.ru>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/3] iio: add MEMSensing MSA311 3-axis accelerometer driver
Date: Sat, 16 Jul 2022 16:51:21 +0100	[thread overview]
Message-ID: <20220716165121.3f0120df@jic23-huawei> (raw)
In-Reply-To: <20220701134734.nfc6xa4q7rhfi3r7@CAB-WSD-L081021.sigma.sbrf.ru>

On Fri, 1 Jul 2022 13:49:10 +0000
Dmitry Rokosov <DDRokosov@sberdevices.ru> wrote:

> Hello Jonathan,
> 
> Sorry for the delayed response.
> 
> On Sun, Jun 19, 2022 at 01:27:03PM +0100, Jonathan Cameron wrote:
> > On Thu, 16 Jun 2022 10:42:14 +0000
> > Dmitry Rokosov <DDRokosov@sberdevices.ru> wrote:
> >   
> > > MSA311 is a tri-axial, low-g accelerometer with I2C digital output for
> > > sensitivity consumer applications. It has dynamical user selectable full
> > > scales range of +-2g/+-4g/+-8g/+-16g and allows acceleration measurements
> > > with output data rates from 1Hz to 1000Hz.
> > > 
> > > Datasheet can be found at following URL:
> > > https://cdn-shop.adafruit.com/product-files/5309/MSA311-V1.1-ENG.pdf
> > > 
> > > This driver supports following MSA311 features:
> > >     - IIO interface
> > >     - Different power modes: NORMAL and SUSPEND (using pm_runtime)
> > >     - ODR (Output Data Rate) selection
> > >     - Scale and samp_freq selection
> > >     - IIO triggered buffer, IIO reg access
> > >     - NEW_DATA interrupt + trigger
> > > 
> > > Below features to be done:
> > >     - Motion Events: ACTIVE, TAP, ORIENT, FREEFALL
> > >     - Low Power mode
> > > 
> > > Signed-off-by: Dmitry Rokosov <ddrokosov@sberdevices.ru>  
> > Hi Dmitry,
> > 
> > A few things I missed before + I'm still not happy with the runtime
> > pm handling.  One case that isn't covered well is !CONFIG_RUNTIME_PM
> > 
> > Thanks,
> > 
> > Jonathan
> >   
> 
> ...
> 
> > > +static irqreturn_t msa311_buffer_thread(int irq, void *p)
> > > +{
> > > +	struct iio_poll_func *pf = p;
> > > +	struct iio_dev *indio_dev = pf->indio_dev;
> > > +	struct msa311_priv *msa311 = iio_priv(indio_dev);
> > > +	struct device *dev = &msa311->i2c->dev;
> > > +	const struct iio_chan_spec *chan;
> > > +	__le16 axis;
> > > +	int bit = 0, err, i = 0;
> > > +
> > > +	/* Ensure correct alignment of time stamp when present */
> > > +	struct {
> > > +		__le16 channels[MSA311_SI_Z + 1];
> > > +		s64 ts __aligned(8);
> > > +	} buf;
> > > +
> > > +	memset(&buf, 0, sizeof(buf));
> > > +
> > > +	mutex_lock(&msa311->lock);
> > > +
> > > +	for_each_set_bit(bit, indio_dev->active_scan_mask,
> > > +			 indio_dev->masklength) {
> > > +		chan = &msa311_channels[bit];  
> > 
> > Nothing to do with your driver, but feels like it's worth
> > exploring a
> > 	for_each_chan_in_iio_scan(struct iio_chan_spec, struct iio_dev) macro.
> > 
> > I'll add that to my todo list.
> >   
> 
> If you don't mind, I can prepare such a patch.

I had a look at this whilst travelling and it's a lot more complex than I
thought it would be because of gaps in the scan_index in some drivers (not
all channels have scan indexes and not all scan indexes are used)

If we write such a thing we need to resolve that in the core and I suspect
it will require creation of an indirection structure that lets us
do scan_index based look up of channels.  Whilst that works in many drivers
because there is a nice 1 to 1 mapping, there are exceptions.
Hence I think we would be looking at:

1) Check at registration time on whether scan_index == location in
iio_dev->channels, if so set another pointer say iio_dev->channels_linear =
iio_dev->channels.
2) If not, create a lookup table and make iio_dev->channels_linear
point to that.
3) Finally introduce a macro that uses channels_linear.

What fun ;)

Jonathan
 



  reply	other threads:[~2022-07-16 15:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-16 10:42 [PATCH v3 0/3] iio: accel: add MSA311 accelerometer driver Dmitry Rokosov
2022-06-16 10:42 ` [PATCH v3 1/3] dt-bindings: vendor-prefixes: add MEMSensing Microsystems Co., Ltd Dmitry Rokosov
2022-06-16 10:42 ` [PATCH v3 2/3] iio: add MEMSensing MSA311 3-axis accelerometer driver Dmitry Rokosov
2022-06-16 12:18   ` Andy Shevchenko
2022-06-16 17:02     ` Dmitry Rokosov
2022-06-16 18:38       ` Andy Shevchenko
2022-06-17 14:22         ` Dmitry Rokosov
2022-06-17 16:54           ` Andy Shevchenko
2022-06-19 12:31       ` Jonathan Cameron
2022-07-01 13:06         ` Dmitry Rokosov
2022-06-19 12:27   ` Jonathan Cameron
2022-07-01 13:49     ` Dmitry Rokosov
2022-07-16 15:51       ` Jonathan Cameron [this message]
2022-07-18 10:01         ` Dmitry Rokosov
2022-06-16 10:42 ` [PATCH v3 3/3] dt-bindings: iio: accel: add dt-binding schema for msa311 accel driver Dmitry Rokosov
2022-06-19 11:40   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220716165121.3f0120df@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=DDRokosov@sberdevices.ru \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@sberdevices.ru \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=stano.jakubek@gmail.com \
    --cc=stephan@gerhold.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).