Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 338007
b: refs/heads/master
c: 2e33460
h: refs/heads/master
i:
  338005: 4afa730
  338003: aa0dc47
  337999: 31fed06
v: v3
  • Loading branch information
Lars-Peter Clausen authored and Jonathan Cameron committed Nov 19, 2012
1 parent ee14fad commit 5cb2283
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ca654638f2b4b00f948d2126dd544d2e35d2b880
refs/heads/master: 2e334600989384a11ed7ae0dc0e0ca0486ebfaaa
12 changes: 5 additions & 7 deletions trunk/drivers/staging/iio/adc/ad7298.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@

#define RES_MASK(bits) ((1 << (bits)) - 1)

/*
* TODO: struct ad7298_platform_data needs to go into include/linux/iio
*/

/**
* struct ad7298_platform_data - Platform data for the ad7298 ADC driver
* @ext_ref: Whether to use an external reference voltage.
**/
struct ad7298_platform_data {
/* External Vref voltage applied */
u16 vref_mv;
bool ext_ref;
};

struct ad7298_state {
struct spi_device *spi;
struct regulator *reg;
u16 int_vref_mv;
unsigned ext_ref;
struct spi_transfer ring_xfer[10];
struct spi_transfer scan_single_xfer[3];
Expand Down
44 changes: 26 additions & 18 deletions trunk/drivers/staging/iio/adc/ad7298_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
{
int ret;
struct ad7298_state *st = iio_priv(indio_dev);
unsigned int scale_uv;
int scale_mv;

switch (m) {
case IIO_CHAN_INFO_RAW:
Expand All @@ -155,10 +155,17 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_VOLTAGE:
scale_uv = (st->int_vref_mv * 1000) >> AD7298_BITS;
*val = scale_uv / 1000;
*val2 = (scale_uv % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO;
if (st->ext_ref) {
scale_mv = regulator_get_voltage(st->reg);
if (scale_mv < 0)
return scale_mv;
scale_mv /= 1000;
} else {
scale_mv = AD7298_INTREF_mV;
}
*val = scale_mv;
*val2 = chan->scan_type.realbits;
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_TEMP:
*val = 1;
*val2 = 0;
Expand All @@ -180,16 +187,23 @@ static int __devinit ad7298_probe(struct spi_device *spi)
{
struct ad7298_platform_data *pdata = spi->dev.platform_data;
struct ad7298_state *st;
int ret;
struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
int ret;

if (indio_dev == NULL)
return -ENOMEM;

st = iio_priv(indio_dev);

st->reg = regulator_get(&spi->dev, "vcc");
if (!IS_ERR(st->reg)) {
if (pdata && pdata->ext_ref)
st->ext_ref = AD7298_EXTREF;

if (st->ext_ref) {
st->reg = regulator_get(&spi->dev, "vref");
if (IS_ERR(st->reg)) {
ret = PTR_ERR(st->reg);
goto error_free;
}
ret = regulator_enable(st->reg);
if (ret)
goto error_put_reg;
Expand Down Expand Up @@ -222,13 +236,6 @@ static int __devinit ad7298_probe(struct spi_device *spi)
spi_message_add_tail(&st->scan_single_xfer[1], &st->scan_single_msg);
spi_message_add_tail(&st->scan_single_xfer[2], &st->scan_single_msg);

if (pdata && pdata->vref_mv) {
st->int_vref_mv = pdata->vref_mv;
st->ext_ref = AD7298_EXTREF;
} else {
st->int_vref_mv = AD7298_INTREF_mV;
}

ret = ad7298_register_ring_funcs_and_init(indio_dev);
if (ret)
goto error_disable_reg;
Expand All @@ -242,11 +249,12 @@ static int __devinit ad7298_probe(struct spi_device *spi)
error_cleanup_ring:
ad7298_ring_cleanup(indio_dev);
error_disable_reg:
if (!IS_ERR(st->reg))
if (st->ext_ref)
regulator_disable(st->reg);
error_put_reg:
if (!IS_ERR(st->reg))
if (st->ext_ref)
regulator_put(st->reg);
error_free:
iio_device_free(indio_dev);

return ret;
Expand All @@ -259,7 +267,7 @@ static int __devexit ad7298_remove(struct spi_device *spi)

iio_device_unregister(indio_dev);
ad7298_ring_cleanup(indio_dev);
if (!IS_ERR(st->reg)) {
if (st->ext_ref) {
regulator_disable(st->reg);
regulator_put(st->reg);
}
Expand Down

0 comments on commit 5cb2283

Please sign in to comment.