Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 325354
b: refs/heads/master
c: cb093e4
h: refs/heads/master
v: v3
  • Loading branch information
Lars-Peter Clausen authored and Jonathan Cameron committed Sep 15, 2012
1 parent 458e19d commit fdd83e9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 43 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: 93e33d703030fe0348c1ff9d8f40bc6c2d82dc30
refs/heads/master: cb093e444fede72c1ee31265dac475dc87ff321b
11 changes: 1 addition & 10 deletions trunk/drivers/staging/iio/adc/ad7476.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,15 @@

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

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

struct ad7476_platform_data {
u16 vref_mv;
};

struct ad7476_chip_info {
u16 int_vref_mv;
unsigned int int_vref_uv;
struct iio_chan_spec channel[2];
};

struct ad7476_state {
struct spi_device *spi;
const struct ad7476_chip_info *chip_info;
struct regulator *reg;
u16 int_vref_mv;
struct spi_transfer xfer;
struct spi_message msg;
/*
Expand Down
59 changes: 27 additions & 32 deletions trunk/drivers/staging/iio/adc/ad7476_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
{
int ret;
struct ad7476_state *st = iio_priv(indio_dev);
unsigned int scale_uv;
int scale_uv;

switch (m) {
case IIO_CHAN_INFO_RAW:
Expand All @@ -57,10 +57,16 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
RES_MASK(st->chip_info->channel[0].scan_type.realbits);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
scale_uv = (st->int_vref_mv * 1000)
>> st->chip_info->channel[0].scan_type.realbits;
*val = scale_uv/1000;
*val2 = (scale_uv%1000)*1000;
if (!st->chip_info->int_vref_uv) {
scale_uv = regulator_get_voltage(st->reg);
if (scale_uv < 0)
return scale_uv;
} else {
scale_uv = st->chip_info->int_vref_uv;
}
scale_uv >>= chan->scan_type.realbits;
*val = scale_uv / 1000;
*val2 = (scale_uv % 1000) * 1000;
return IIO_VAL_INT_PLUS_MICRO;
}
return -EINVAL;
Expand Down Expand Up @@ -96,7 +102,7 @@ static const struct ad7476_chip_info ad7476_chip_info_tbl[] = {
[ID_AD7495] = {
.channel[0] = AD7476_CHAN(12),
.channel[1] = IIO_CHAN_SOFT_TIMESTAMP(1),
.int_vref_mv = 2500,
.int_vref_uv = 2500000,
},
};

Expand All @@ -107,36 +113,28 @@ static const struct iio_info ad7476_info = {

static int __devinit ad7476_probe(struct spi_device *spi)
{
struct ad7476_platform_data *pdata = spi->dev.platform_data;
struct ad7476_state *st;
struct iio_dev *indio_dev;
int ret, voltage_uv = 0;
int ret;

indio_dev = iio_device_alloc(sizeof(*st));
if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_ret;
}
st = iio_priv(indio_dev);
st->reg = regulator_get(&spi->dev, "vcc");
if (!IS_ERR(st->reg)) {
ret = regulator_enable(st->reg);
if (ret)
goto error_put_reg;

voltage_uv = regulator_get_voltage(st->reg);
}
st->chip_info =
&ad7476_chip_info_tbl[spi_get_device_id(spi)->driver_data];

if (st->chip_info->int_vref_mv)
st->int_vref_mv = st->chip_info->int_vref_mv;
else if (pdata && pdata->vref_mv)
st->int_vref_mv = pdata->vref_mv;
else if (voltage_uv)
st->int_vref_mv = voltage_uv / 1000;
else
dev_warn(&spi->dev, "reference voltage unspecified\n");
st->reg = regulator_get(&spi->dev, "vcc");
if (IS_ERR(st->reg)) {
ret = PTR_ERR(st->reg);
goto error_free_dev;
}

ret = regulator_enable(st->reg);
if (ret)
goto error_put_reg;

spi_set_drvdata(spi, indio_dev);

Expand Down Expand Up @@ -169,11 +167,10 @@ static int __devinit ad7476_probe(struct spi_device *spi)
error_ring_unregister:
ad7476_ring_cleanup(indio_dev);
error_disable_reg:
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
regulator_disable(st->reg);
error_put_reg:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
regulator_put(st->reg);
error_free_dev:
iio_device_free(indio_dev);

error_ret:
Expand All @@ -187,10 +184,8 @@ static int __devexit ad7476_remove(struct spi_device *spi)

iio_device_unregister(indio_dev);
ad7476_ring_cleanup(indio_dev);
if (!IS_ERR(st->reg)) {
regulator_disable(st->reg);
regulator_put(st->reg);
}
regulator_disable(st->reg);
regulator_put(st->reg);
iio_device_free(indio_dev);

return 0;
Expand Down

0 comments on commit fdd83e9

Please sign in to comment.