public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Teodora Baluta <teodora.baluta@intel.com>
To: Peter Meerwald <pmeerw@pmeerw.net>
Cc: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de,
	daniel.baluta@intel.com, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] iio: mxc4005: add triggered buffer mode for mxc4005
Date: Wed, 5 Aug 2015 12:24:18 +0300	[thread overview]
Message-ID: <20150805092418.GA20023@hard-bop> (raw)
In-Reply-To: <alpine.DEB.2.02.1507311834190.12658@pmeerw.net>

On Fri, Jul 31, 2015 at 06:43:57PM +0200, Peter Meerwald wrote:
> On Fri, 31 Jul 2015, Teodora Baluta wrote:
> 
> > This patch adds support for buffered readings for the 3-axis
> > accelerometer mxc4005.
> 
> some comments below

Thanks for the review, Peter. I will send a version 2 patch set as soon
as possible to address the comments.

Teodora

>  
> > Signed-off-by: Teodora Baluta <teodora.baluta@intel.com>
> > ---
> >  drivers/iio/accel/Kconfig   |  2 ++
> >  drivers/iio/accel/mxc4005.c | 75 ++++++++++++++++++++++++++++++++++++++++++---
> >  2 files changed, 73 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
> > index 7f534a3..e8d135e 100644
> > --- a/drivers/iio/accel/Kconfig
> > +++ b/drivers/iio/accel/Kconfig
> > @@ -140,6 +140,8 @@ config MMA9553
> >  config MXC4005
> >  	tristate "Memsic MXC4005XC 3-Axis Accelerometer Driver"
> >  	depends on I2C
> > +	select IIO_BUFFER
> > +	select IIO_TRIGGERED_BUFFER
> >  	select REGMAP_I2C
> >  	help
> >  	  Say yes here to build support for the Memsic MXC4005XC 3-axis
> > diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
> > index 0f0410c..114c14d 100644
> > --- a/drivers/iio/accel/mxc4005.c
> > +++ b/drivers/iio/accel/mxc4005.c
> > @@ -19,6 +19,9 @@
> >  #include <linux/acpi.h>
> >  #include <linux/regmap.h>
> >  #include <linux/iio/sysfs.h>
> > +#include <linux/iio/buffer.h>
> > +#include <linux/iio/triggered_buffer.h>
> > +#include <linux/iio/trigger_consumer.h>
> >  
> >  #define MXC4005_DRV_NAME		"mxc4005"
> >  #define MXC4005_REGMAP_NAME		"mxc4005_regmap"
> > @@ -54,6 +57,7 @@ struct mxc4005_data {
> >  	struct i2c_client *client;
> >  	struct mutex mutex;
> >  	struct regmap *regmap;
> > +	s16 buffer[8];
> 
> be16 buffer[3]; ?!
> 
> >  };
> >  
> >  /*
> > @@ -125,6 +129,20 @@ static const struct regmap_config mxc4005_regmap_config = {
> >  	.writeable_reg = mxc4005_is_writeable_reg,
> >  };
> >  
> > +static int mxc4005_read_xyz(struct mxc4005_data *data)
> > +{
> > +	int ret;
> > +
> > +	ret = regmap_bulk_read(data->regmap, MXC4005_REG_XOUT_UPPER,
> > +			       (u8 *) data->buffer, sizeof(data->buffer));
> 
> sizeof(data->buffer) == sizeof(s16) * 8 == 16 bytes, but actually the 
> sensor data is just 6 bytes!?
> 
> > +	if (ret < 0) {
> > +		dev_err(&data->client->dev, "failed to read axes\n");
> > +		return ret;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  static int mxc4005_read_axis(struct mxc4005_data *data,
> >  			     int axis)
> >  {
> > @@ -190,6 +208,7 @@ static int mxc4005_read_raw(struct iio_dev *indio_dev,
> >  			    int *val, int *val2, long mask)
> >  {
> >  	struct mxc4005_data *data = iio_priv(indio_dev);
> > +	int axis = chan->scan_index;
> 
> why?
> BTW w.r.t the initial patch: chan->address could store the register 
> address directly, so MXC4005_AXIS_TO_REG() could be dropped
> 
> >  	int ret;
> >  
> >  	switch (mask) {
> > @@ -200,12 +219,13 @@ static int mxc4005_read_raw(struct iio_dev *indio_dev,
> >  				return -EBUSY;
> >  
> >  			mutex_lock(&data->mutex);
> > -			ret = mxc4005_read_axis(data, chan->address);
> > +			ret = mxc4005_read_axis(data, axis);
> >  			mutex_unlock(&data->mutex);
> >  			if (ret < 0)
> >  				return ret;
> >  			ret = be16_to_cpu(ret);
> > -			*val = sign_extend32(ret >> 4, 11);
> > +			*val = sign_extend32(ret >> chan->scan_type.shift,
> > +					     chan->scan_type.realbits - 1);
> >  			return IIO_VAL_INT;
> >  		default:
> >  			return -EINVAL;
> > @@ -259,17 +279,47 @@ static const struct iio_info mxc4005_info = {
> >  	.type = IIO_ACCEL,					\
> >  	.modified = 1,						\
> >  	.channel2 = IIO_MOD_##_axis,				\
> > -	.address = AXIS_##_axis,				\
> >  	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
> >  	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),	\
> > +	.scan_index = AXIS_##_axis,				\
> > +	.scan_type = {						\
> > +		.sign = 's',					\
> > +		.realbits = 12,					\
> > +		.storagebits = 16,				\
> > +		.shift = 4,					\
> > +		.endianness = IIO_BE,				\
> > +	},							\
> >  }
> >  
> >  static const struct iio_chan_spec mxc4005_channels[] = {
> >  	MXC4005_CHANNEL(X),
> >  	MXC4005_CHANNEL(Y),
> >  	MXC4005_CHANNEL(Z),
> > +	IIO_CHAN_SOFT_TIMESTAMP(3),
> >  };
> >  
> > +static irqreturn_t mxc4005_trigger_handler(int irq, void *private)
> > +{
> > +	struct iio_poll_func *pf = private;
> > +	struct iio_dev *indio_dev = pf->indio_dev;
> > +	struct mxc4005_data *data = iio_priv(indio_dev);
> > +	int ret;
> > +
> > +	mutex_lock(&data->mutex);
> > +	ret = mxc4005_read_xyz(data);
> 
> this always reads all channels, what if only one channel is enabled by the 
> user? use available_scan_masks...
> 
> > +	mutex_unlock(&data->mutex);
> > +	if (ret < 0)
> > +		goto err;
> > +
> > +	iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
> > +					   iio_get_time_ns());
> > +
> > +err:
> > +	iio_trigger_notify_done(indio_dev->trig);
> > +
> > +	return IRQ_HANDLED;
> > +}
> > +
> >  static int mxc4005_chip_init(struct mxc4005_data *data)
> >  {
> >  	int ret;
> > @@ -324,14 +374,29 @@ static int mxc4005_probe(struct i2c_client *client,
> >  	indio_dev->modes = INDIO_DIRECT_MODE;
> >  	indio_dev->info = &mxc4005_info;
> >  
> > +	ret = iio_triggered_buffer_setup(indio_dev,
> > +					 &iio_pollfunc_store_time,
> > +					 mxc4005_trigger_handler,
> > +					 NULL);
> > +	if (ret < 0) {
> > +		dev_err(&client->dev,
> > +			"failed to setup iio triggered buffer\n");
> > +		return ret;
> > +	}
> > +
> >  	ret = iio_device_register(indio_dev);
> >  	if (ret < 0) {
> >  		dev_err(&client->dev,
> >  			"unable to register iio device %d\n", ret);
> > -		return ret;
> > +		goto err_buffer_cleanup;
> >  	}
> >  
> >  	return 0;
> > +
> > +err_buffer_cleanup:
> > +	iio_triggered_buffer_cleanup(indio_dev);
> > +
> > +	return ret;
> >  }
> >  
> >  static int mxc4005_remove(struct i2c_client *client)
> > @@ -340,6 +405,8 @@ static int mxc4005_remove(struct i2c_client *client)
> >  
> >  	iio_device_unregister(indio_dev);
> >  
> > +	iio_triggered_buffer_cleanup(indio_dev);
> > +
> >  	return 0;
> >  }
> >  
> > 
> 
> -- 
> 
> Peter Meerwald
> +43-664-2444418 (mobile)

  reply	other threads:[~2015-08-05  9:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-31 15:25 [PATCH 0/3] iio: accel: add support for Memsic MXC4005 Teodora Baluta
2015-07-31 15:25 ` [PATCH 1/3] iio: accel: add support for mxc4005 accelerometer Teodora Baluta
2015-07-31 16:33   ` Peter Meerwald
2015-07-31 15:25 ` [PATCH 2/3] iio: mxc4005: add triggered buffer mode for mxc4005 Teodora Baluta
2015-07-31 16:43   ` Peter Meerwald
2015-08-05  9:24     ` Teodora Baluta [this message]
2015-07-31 15:25 ` [PATCH 3/3] iio: mxc4005: add data ready trigger " Teodora Baluta

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=20150805092418.GA20023@hard-bop \
    --to=teodora.baluta@intel.com \
    --cc=daniel.baluta@intel.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.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