From: Hartmut Knaack <knaack.h@gmx.de>
To: Vlad Dogaru <vlad.dogaru@intel.com>,
jic23@kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH v3 1/3] iio: sx9500: optimize power usage
Date: Fri, 26 Jun 2015 13:01:42 +0200 [thread overview]
Message-ID: <558D3116.5060906@gmx.de> (raw)
In-Reply-To: <1428858561-27994-2-git-send-email-vlad.dogaru@intel.com>
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?
> +
> + 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?
Thanks,
Hartmut
> + if (ret < 0)
> + return ret;
> +
> + for (i = 10; i >= 0; i--) {
> + usleep_range(10000, 20000);
> + ret = regmap_read(data->regmap, SX9500_REG_STAT, &val);
> + if (ret < 0)
> + goto out;
> + if (!(val & SX9500_COMPSTAT_MASK))
> + break;
> + }
> +
> + if (i < 0) {
> + dev_err(&data->client->dev, "initial compensation timed out");
> + ret = -ETIMEDOUT;
> + }
> +
> +out:
> + regmap_update_bits(data->regmap, SX9500_REG_PROX_CTRL0,
> + GENMASK(SX9500_NUM_CHANNELS, 0), 0);
> + return ret;
> +}
> +
next prev parent reply other threads:[~2015-06-26 11:01 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 [this message]
2015-06-29 7:42 ` Vlad Dogaru
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=558D3116.5060906@gmx.de \
--to=knaack.h@gmx.de \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=vlad.dogaru@intel.com \
/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