* [PATCH]staging:iio:ad799x use regulator for vref
@ 2014-02-16 12:02 Hartmut Knaack
2014-02-16 18:57 ` Lars-Peter Clausen
0 siblings, 1 reply; 3+ messages in thread
From: Hartmut Knaack @ 2014-02-16 12:02 UTC (permalink / raw)
To: linux-iio
Switch the ad799x driver to use the regulator framework and add binding for reference voltage.
Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
---
diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
index a591aa6..fc8c852 100644
--- a/drivers/staging/iio/adc/ad799x.h
+++ b/drivers/staging/iio/adc/ad799x.h
@@ -95,7 +95,7 @@ struct ad799x_state {
struct i2c_client *client;
const struct ad799x_chip_info *chip_info;
struct regulator *reg;
- u16 int_vref_mv;
+ struct regulator *vref;
unsigned id;
u16 config;
@@ -103,14 +103,6 @@ struct ad799x_state {
unsigned int transfer_size;
};
-/*
- * TODO: struct ad799x_platform_data needs to go into include/linux/iio
- */
-
-struct ad799x_platform_data {
- u16 vref_mv;
-};
-
#ifdef CONFIG_AD799X_RING_BUFFER
int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
void ad799x_ring_cleanup(struct iio_dev *indio_dev);
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 570c594..747d1da 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -179,7 +179,10 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
RES_MASK(chan->scan_type.realbits);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
- *val = st->int_vref_mv;
+ ret = regulator_get_voltage(st->vref);
+ if (ret < 0)
+ return ret;
+ *val = ret / 1000;
*val2 = chan->scan_type.realbits;
return IIO_VAL_FRACTIONAL_LOG2;
}
@@ -527,7 +530,6 @@ static int ad799x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int ret;
- struct ad799x_platform_data *pdata = client->dev.platform_data;
struct ad799x_state *st;
struct iio_dev *indio_dev;
@@ -545,17 +547,21 @@ static int ad799x_probe(struct i2c_client *client,
/* TODO: Add pdata options for filtering and bit delay */
- if (!pdata)
- return -EINVAL;
-
- st->int_vref_mv = pdata->vref_mv;
-
st->reg = devm_regulator_get(&client->dev, "vcc");
- if (!IS_ERR(st->reg)) {
- ret = regulator_enable(st->reg);
- if (ret)
- return ret;
+ if (IS_ERR(st->reg))
+ return PTR_ERR(st->reg);
+ ret = regulator_enable(st->reg);
+ if (ret)
+ return ret;
+ st->vref = devm_regulator_get(&client->dev, "vref");
+ if (IS_ERR(st->vref)) {
+ ret = PTR_ERR(st->vref);
+ goto error_disable_reg;
}
+ ret = regulator_enable(st->vref);
+ if (ret)
+ goto error_disable_reg;
+
st->client = client;
indio_dev->dev.parent = &client->dev;
@@ -592,6 +598,8 @@ error_free_irq:
error_cleanup_ring:
ad799x_ring_cleanup(indio_dev);
error_disable_reg:
+ if (!IS_ERR(st->vref))
+ regulator_disable(st->vref);
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
@@ -608,6 +616,8 @@ static int ad799x_remove(struct i2c_client *client)
free_irq(client->irq, indio_dev);
ad799x_ring_cleanup(indio_dev);
+ if (!IS_ERR(st->vref))
+ regulator_disable(st->vref);
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
kfree(st->rx_buf);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH]staging:iio:ad799x use regulator for vref
2014-02-16 12:02 [PATCH]staging:iio:ad799x use regulator for vref Hartmut Knaack
@ 2014-02-16 18:57 ` Lars-Peter Clausen
2014-02-18 8:41 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2014-02-16 18:57 UTC (permalink / raw)
To: Hartmut Knaack; +Cc: linux-iio
On 02/16/2014 01:02 PM, Hartmut Knaack wrote:
> Switch the ad799x driver to use the regulator framework and add binding for reference voltage.
>
> Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
> diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
> index a591aa6..fc8c852 100644
> --- a/drivers/staging/iio/adc/ad799x.h
> +++ b/drivers/staging/iio/adc/ad799x.h
> @@ -95,7 +95,7 @@ struct ad799x_state {
> struct i2c_client *client;
> const struct ad799x_chip_info *chip_info;
> struct regulator *reg;
> - u16 int_vref_mv;
> + struct regulator *vref;
> unsigned id;
> u16 config;
>
> @@ -103,14 +103,6 @@ struct ad799x_state {
> unsigned int transfer_size;
> };
>
> -/*
> - * TODO: struct ad799x_platform_data needs to go into include/linux/iio
> - */
> -
> -struct ad799x_platform_data {
> - u16 vref_mv;
> -};
> -
> #ifdef CONFIG_AD799X_RING_BUFFER
> int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
> void ad799x_ring_cleanup(struct iio_dev *indio_dev);
> diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
> index 570c594..747d1da 100644
> --- a/drivers/staging/iio/adc/ad799x_core.c
> +++ b/drivers/staging/iio/adc/ad799x_core.c
> @@ -179,7 +179,10 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
> RES_MASK(chan->scan_type.realbits);
> return IIO_VAL_INT;
> case IIO_CHAN_INFO_SCALE:
> - *val = st->int_vref_mv;
> + ret = regulator_get_voltage(st->vref);
> + if (ret < 0)
> + return ret;
> + *val = ret / 1000;
> *val2 = chan->scan_type.realbits;
> return IIO_VAL_FRACTIONAL_LOG2;
> }
> @@ -527,7 +530,6 @@ static int ad799x_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> int ret;
> - struct ad799x_platform_data *pdata = client->dev.platform_data;
> struct ad799x_state *st;
> struct iio_dev *indio_dev;
>
> @@ -545,17 +547,21 @@ static int ad799x_probe(struct i2c_client *client,
>
> /* TODO: Add pdata options for filtering and bit delay */
>
> - if (!pdata)
> - return -EINVAL;
> -
> - st->int_vref_mv = pdata->vref_mv;
> -
> st->reg = devm_regulator_get(&client->dev, "vcc");
> - if (!IS_ERR(st->reg)) {
> - ret = regulator_enable(st->reg);
> - if (ret)
> - return ret;
> + if (IS_ERR(st->reg))
> + return PTR_ERR(st->reg);
> + ret = regulator_enable(st->reg);
> + if (ret)
> + return ret;
> + st->vref = devm_regulator_get(&client->dev, "vref");
> + if (IS_ERR(st->vref)) {
> + ret = PTR_ERR(st->vref);
> + goto error_disable_reg;
> }
> + ret = regulator_enable(st->vref);
> + if (ret)
> + goto error_disable_reg;
> +
> st->client = client;
>
> indio_dev->dev.parent = &client->dev;
> @@ -592,6 +598,8 @@ error_free_irq:
> error_cleanup_ring:
> ad799x_ring_cleanup(indio_dev);
> error_disable_reg:
> + if (!IS_ERR(st->vref))
> + regulator_disable(st->vref);
> if (!IS_ERR(st->reg))
> regulator_disable(st->reg);
>
> @@ -608,6 +616,8 @@ static int ad799x_remove(struct i2c_client *client)
> free_irq(client->irq, indio_dev);
>
> ad799x_ring_cleanup(indio_dev);
> + if (!IS_ERR(st->vref))
> + regulator_disable(st->vref);
> if (!IS_ERR(st->reg))
> regulator_disable(st->reg);
> kfree(st->rx_buf);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH]staging:iio:ad799x use regulator for vref
2014-02-16 18:57 ` Lars-Peter Clausen
@ 2014-02-18 8:41 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2014-02-18 8:41 UTC (permalink / raw)
To: Lars-Peter Clausen, Hartmut Knaack; +Cc: linux-iio
On 16/02/14 18:57, Lars-Peter Clausen wrote:
> On 02/16/2014 01:02 PM, Hartmut Knaack wrote:
>> Switch the ad799x driver to use the regulator framework and add binding for reference voltage.
>>
>> Signed-off-by: Hartmut Knaack <knaack.h@gmx.de>
>
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Applied with a little fuzz to the togreg branch of iio.git
This will go out as testing initially for the autobuilders to play.
>
>> ---
>> diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
>> index a591aa6..fc8c852 100644
>> --- a/drivers/staging/iio/adc/ad799x.h
>> +++ b/drivers/staging/iio/adc/ad799x.h
>> @@ -95,7 +95,7 @@ struct ad799x_state {
>> struct i2c_client *client;
>> const struct ad799x_chip_info *chip_info;
>> struct regulator *reg;
>> - u16 int_vref_mv;
>> + struct regulator *vref;
>> unsigned id;
>> u16 config;
>>
>> @@ -103,14 +103,6 @@ struct ad799x_state {
>> unsigned int transfer_size;
>> };
>>
>> -/*
>> - * TODO: struct ad799x_platform_data needs to go into include/linux/iio
>> - */
>> -
>> -struct ad799x_platform_data {
>> - u16 vref_mv;
>> -};
>> -
>> #ifdef CONFIG_AD799X_RING_BUFFER
>> int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
>> void ad799x_ring_cleanup(struct iio_dev *indio_dev);
>> diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
>> index 570c594..747d1da 100644
>> --- a/drivers/staging/iio/adc/ad799x_core.c
>> +++ b/drivers/staging/iio/adc/ad799x_core.c
>> @@ -179,7 +179,10 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
>> RES_MASK(chan->scan_type.realbits);
>> return IIO_VAL_INT;
>> case IIO_CHAN_INFO_SCALE:
>> - *val = st->int_vref_mv;
>> + ret = regulator_get_voltage(st->vref);
>> + if (ret < 0)
>> + return ret;
>> + *val = ret / 1000;
>> *val2 = chan->scan_type.realbits;
>> return IIO_VAL_FRACTIONAL_LOG2;
>> }
>> @@ -527,7 +530,6 @@ static int ad799x_probe(struct i2c_client *client,
>> const struct i2c_device_id *id)
>> {
>> int ret;
>> - struct ad799x_platform_data *pdata = client->dev.platform_data;
>> struct ad799x_state *st;
>> struct iio_dev *indio_dev;
>>
>> @@ -545,17 +547,21 @@ static int ad799x_probe(struct i2c_client *client,
>>
>> /* TODO: Add pdata options for filtering and bit delay */
>>
>> - if (!pdata)
>> - return -EINVAL;
>> -
>> - st->int_vref_mv = pdata->vref_mv;
>> -
>> st->reg = devm_regulator_get(&client->dev, "vcc");
>> - if (!IS_ERR(st->reg)) {
>> - ret = regulator_enable(st->reg);
>> - if (ret)
>> - return ret;
>> + if (IS_ERR(st->reg))
>> + return PTR_ERR(st->reg);
>> + ret = regulator_enable(st->reg);
>> + if (ret)
>> + return ret;
>> + st->vref = devm_regulator_get(&client->dev, "vref");
>> + if (IS_ERR(st->vref)) {
>> + ret = PTR_ERR(st->vref);
>> + goto error_disable_reg;
>> }
>> + ret = regulator_enable(st->vref);
>> + if (ret)
>> + goto error_disable_reg;
>> +
>> st->client = client;
>>
>> indio_dev->dev.parent = &client->dev;
>> @@ -592,6 +598,8 @@ error_free_irq:
>> error_cleanup_ring:
>> ad799x_ring_cleanup(indio_dev);
>> error_disable_reg:
>> + if (!IS_ERR(st->vref))
>> + regulator_disable(st->vref);
>> if (!IS_ERR(st->reg))
>> regulator_disable(st->reg);
>>
>> @@ -608,6 +616,8 @@ static int ad799x_remove(struct i2c_client *client)
>> free_irq(client->irq, indio_dev);
>>
>> ad799x_ring_cleanup(indio_dev);
>> + if (!IS_ERR(st->vref))
>> + regulator_disable(st->vref);
>> if (!IS_ERR(st->reg))
>> regulator_disable(st->reg);
>> kfree(st->rx_buf);
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-02-18 8:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-16 12:02 [PATCH]staging:iio:ad799x use regulator for vref Hartmut Knaack
2014-02-16 18:57 ` Lars-Peter Clausen
2014-02-18 8:41 ` Jonathan Cameron
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).