Linux IIO development
 help / color / mirror / Atom feed
From: Vlad Dogaru <vlad.dogaru@intel.com>
To: Hartmut Knaack <knaack.h@gmx.de>
Cc: jic23@kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH v3 1/3] iio: sx9500: optimize power usage
Date: Mon, 29 Jun 2015 10:42:35 +0300	[thread overview]
Message-ID: <20150629074235.GD12017@vdogaru> (raw)
In-Reply-To: <558D3116.5060906@gmx.de>

On Fri, Jun 26, 2015 at 01:01:42PM +0200, Hartmut Knaack wrote:
> Vlad Dogaru schrieb am 12.04.2015 um 19:09:
> > In the interest of lowering power usage, we only activate the proximity
> > channels and interrupts that we are currently using.
> > 
> > For raw reads, we activate the corresponding channel and the data ready
> > interrupt and wait for the interrupt to trigger.  If no interrupt is
> > available, we wait for the documented scan period, as specified in the
> > datasheet.
> > 
> 
> Hi,
> I have a question inline, and also spotted a bug.
> 
> <...>
> 
> > +static int sx9500_read_proximity(struct sx9500_data *data,
> > +				 const struct iio_chan_spec *chan,
> > +				 int *val)
> > +{
> > +	int ret;
> > +
> > +	mutex_lock(&data->mutex);
> > +
> > +	ret = sx9500_inc_chan_users(data, chan->channel);
> > +	if (ret < 0)
> > +		goto out;
> > +
> > +	ret = sx9500_inc_data_rdy_users(data);
> > +	if (ret < 0)
> > +		goto out_dec_chan;
> > +
> > +	mutex_unlock(&data->mutex);
> > +
> > +	if (data->client->irq > 0)
> > +		ret = wait_for_completion_interruptible(&data->completion);
> > +	else
> > +		ret = sx9500_wait_for_sample(data);
> > +
> > +	if (ret < 0)
> > +		return ret;
> 
> If an error is encountered from here on, the device won't be able to enter
> a low power mode again, since you don't decrease the chan_users[chan] and
> data_rdy_users elements of sx9500_data. Is this intended?

No, I didn't intend that.

> 
> > +
> > +	mutex_lock(&data->mutex);
> > +
> > +	ret = sx9500_read_prox_data(data, chan, val);
> > +	if (ret < 0)
> > +		goto out;
> > +
> > +	ret = sx9500_dec_chan_users(data, chan->channel);
> > +	if (ret < 0)
> > +		goto out;
> > +
> > +	ret = sx9500_dec_data_rdy_users(data);
> > +	if (ret < 0)
> > +		goto out;
> > +
> > +	ret = IIO_VAL_INT;
> > +
> > +	goto out;
> > +
> > +out_dec_chan:
> > +	sx9500_dec_chan_users(data, chan->channel);
> > +out:
> > +	mutex_unlock(&data->mutex);
> > +	reinit_completion(&data->completion);
> > +
> > +	return ret;
> >  }
> 
> <...>
> 
>   
> > +/* Activate all channels and perform an initial compensation. */
> > +static int sx9500_init_compensation(struct iio_dev *indio_dev)
> > +{
> > +	struct sx9500_data *data = iio_priv(indio_dev);
> > +	int i, ret;
> > +	unsigned int val;
> > +
> > +	ret = regmap_update_bits(data->regmap, SX9500_REG_PROX_CTRL0,
> > +				 GENMASK(SX9500_NUM_CHANNELS, 0),
> > +				 GENMASK(SX9500_NUM_CHANNELS, 0));
> 
> This mask should just reach until SX9500_NUM_CHANNELS - 1. Right now it 
> messes with the lowest bit of SCANPERIOD. Why not define the channel mask
> with all other definitions and use a catchy name here?

You are correct, thanks for pointing this out.  Will send patches for
both shortly.

Thanks,
Vlad

  reply	other threads:[~2015-06-29  7:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-12 17:09 [PATCH v3 0/3] iio: sx9500: power usage and gpio changes Vlad Dogaru
2015-04-12 17:09 ` [PATCH v3 1/3] iio: sx9500: optimize power usage Vlad Dogaru
2015-04-18 19:12   ` Jonathan Cameron
2015-06-26 11:01   ` Hartmut Knaack
2015-06-29  7:42     ` Vlad Dogaru [this message]
2015-04-12 17:09 ` [PATCH v3 2/3] iio: sx9500: refactor GPIO interrupt code Vlad Dogaru
2015-04-18 19:14   ` Jonathan Cameron
2015-04-12 17:09 ` [PATCH v3 3/3] iio: sx9500: add GPIO reset pin Vlad Dogaru
2015-04-18 19:16   ` 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=20150629074235.GD12017@vdogaru \
    --to=vlad.dogaru@intel.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=linux-iio@vger.kernel.org \
    /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