From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Jonathan Cameron <jic23@cam.ac.uk>, linux-iio@vger.kernel.org
Subject: Re: [PATCH 7/7] staging:iio:ad7291: Rework regulator handling
Date: Fri, 14 Jun 2013 21:55:08 +0100 [thread overview]
Message-ID: <51BB832C.1060403@kernel.org> (raw)
In-Reply-To: <1371225508-32190-7-git-send-email-lars@metafoo.de>
On 06/14/2013 04:58 PM, Lars-Peter Clausen wrote:
> Add platform_data for the driver which allows to specify whether an external
> reference voltage is used or not. It is not possible to use the return value of
> regulator_get() for this since the regulator framework is able to return a dummy
> regulator in case no regulator has been specified. In this case the driver will
> always get a valid regulator, no matter if it has been specified or not. Also
> make the regulator non-optional if platform_data states that an external
> reference voltage should be used.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the togreg branch of iio.git
> ---
> drivers/staging/iio/adc/ad7291.c | 38 +++++++++++++++++++++++---------------
> drivers/staging/iio/adc/ad7291.h | 12 ++++++++++++
> 2 files changed, 35 insertions(+), 15 deletions(-)
> create mode 100644 drivers/staging/iio/adc/ad7291.h
>
> diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
> index c2709d6..3fc79e5 100644
> --- a/drivers/staging/iio/adc/ad7291.c
> +++ b/drivers/staging/iio/adc/ad7291.c
> @@ -21,6 +21,8 @@
> #include <linux/iio/sysfs.h>
> #include <linux/iio/events.h>
>
> +#include "ad7291.h"
> +
> /*
> * Simplified handling
> *
> @@ -76,7 +78,6 @@
> struct ad7291_chip_info {
> struct i2c_client *client;
> struct regulator *reg;
> - u16 int_vref_mv;
> u16 command;
> u16 c_mask; /* Active voltage channels for events */
> struct mutex state_lock;
> @@ -445,7 +446,15 @@ static int ad7291_read_raw(struct iio_dev *indio_dev,
> case IIO_CHAN_INFO_SCALE:
> switch (chan->type) {
> case IIO_VOLTAGE:
> - *val = chip->int_vref_mv;
> + if (chip->reg) {
> + int vref;
> + vref = regulator_get_voltage(chip->reg);
> + if (vref < 0)
> + return vref;
> + *val = vref / 1000;
> + } else {
> + *val = 2500;
> + }
> *val2 = AD7291_BITS;
> return IIO_VAL_FRACTIONAL_LOG2;
> case IIO_TEMP:
> @@ -513,9 +522,10 @@ static const struct iio_info ad7291_info = {
> static int ad7291_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> + struct ad7291_platform_data *pdata = client->dev.platform_data;
> struct ad7291_chip_info *chip;
> struct iio_dev *indio_dev;
> - int ret = 0, voltage_uv = 0;
> + int ret = 0;
>
> indio_dev = iio_device_alloc(sizeof(*chip));
> if (indio_dev == NULL) {
> @@ -524,12 +534,14 @@ static int ad7291_probe(struct i2c_client *client,
> }
> chip = iio_priv(indio_dev);
>
> - chip->reg = regulator_get(&client->dev, "vcc");
> - if (!IS_ERR(chip->reg)) {
> + if (pdata && pdata->use_external_ref) {
> + chip->reg = regulator_get(&client->dev, "vref");
> + if (IS_ERR(chip->reg))
> + goto error_free;
> +
> ret = regulator_enable(chip->reg);
> if (ret)
> goto error_put_reg;
> - voltage_uv = regulator_get_voltage(chip->reg);
> }
>
> mutex_init(&chip->state_lock);
> @@ -542,12 +554,8 @@ static int ad7291_probe(struct i2c_client *client,
> AD7291_T_SENSE_MASK | /* Tsense always enabled */
> AD7291_ALERT_POLARITY; /* set irq polarity low level */
>
> - if (voltage_uv) {
> - chip->int_vref_mv = voltage_uv / 1000;
> + if (pdata && pdata->use_external_ref)
> chip->command |= AD7291_EXT_REF;
> - } else {
> - chip->int_vref_mv = 2500; /* Build-in ref */
> - }
>
> indio_dev->name = id->name;
> indio_dev->channels = ad7291_channels;
> @@ -590,12 +598,12 @@ error_unreg_irq:
> if (client->irq)
> free_irq(client->irq, indio_dev);
> error_disable_reg:
> - if (!IS_ERR(chip->reg))
> + if (chip->reg)
> regulator_disable(chip->reg);
> error_put_reg:
> - if (!IS_ERR(chip->reg))
> + if (chip->reg)
> regulator_put(chip->reg);
> -
> +error_free:
> iio_device_free(indio_dev);
> error_ret:
> return ret;
> @@ -611,7 +619,7 @@ static int ad7291_remove(struct i2c_client *client)
> if (client->irq)
> free_irq(client->irq, indio_dev);
>
> - if (!IS_ERR(chip->reg)) {
> + if (chip->reg) {
> regulator_disable(chip->reg);
> regulator_put(chip->reg);
> }
> diff --git a/drivers/staging/iio/adc/ad7291.h b/drivers/staging/iio/adc/ad7291.h
> new file mode 100644
> index 0000000..bbd89fa
> --- /dev/null
> +++ b/drivers/staging/iio/adc/ad7291.h
> @@ -0,0 +1,12 @@
> +#ifndef __IIO_AD7291_H__
> +#define __IIO_AD7291_H__
> +
> +/**
> + * struct ad7291_platform_data - AD7291 platform data
> + * @use_external_ref: Whether to use an external or internal reference voltage
> + */
> +struct ad7291_platform_data {
> + bool use_external_ref;
> +};
> +
> +#endif
>
next prev parent reply other threads:[~2013-06-15 9:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-14 15:58 [PATCH 1/7] staging:iio:ad7291: Use IIO_VAL_FRACTIONAL_LOG2 Lars-Peter Clausen
2013-06-14 15:58 ` [PATCH 2/7] staging:iio:ad7291: Remove userspace reset Lars-Peter Clausen
2013-06-14 20:51 ` Jonathan Cameron
2013-06-14 15:58 ` [PATCH 3/7] staging:iio:ad7291: Remove unnecessary dev_info() from probe() Lars-Peter Clausen
2013-06-14 15:58 ` [PATCH 4/7] staging:iio:ad7291: Simplify threshold register lookup Lars-Peter Clausen
2013-06-14 15:58 ` [PATCH 5/7] staging:iio:ad7291: Use i2c_smbus_{read,write}_word_swapped instead of open-coding it Lars-Peter Clausen
2013-06-14 15:58 ` [PATCH 6/7] staging:iio:ad7291: Use sign_extend32 " Lars-Peter Clausen
2013-06-14 20:54 ` Jonathan Cameron
2013-06-14 15:58 ` [PATCH 7/7] staging:iio:ad7291: Rework regulator handling Lars-Peter Clausen
2013-06-14 20:55 ` Jonathan Cameron [this message]
2013-06-14 20:50 ` [PATCH 1/7] staging:iio:ad7291: Use IIO_VAL_FRACTIONAL_LOG2 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=51BB832C.1060403@kernel.org \
--to=jic23@kernel.org \
--cc=jic23@cam.ac.uk \
--cc=lars@metafoo.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