Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 337695
b: refs/heads/master
c: bf5d261
h: refs/heads/master
i:
  337693: 372949d
  337691: 89e1925
  337687: 12b5edd
  337679: 3adc549
  337663: 574af93
v: v3
  • Loading branch information
Lars-Peter Clausen authored and Jonathan Cameron committed Nov 5, 2012
1 parent 155a669 commit 032b026
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 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: bd6880477a3d73270edead88f4b806504998e5d8
refs/heads/master: bf5d2613c9083b8d4f4e98f5b25553fc938b50c6
3 changes: 0 additions & 3 deletions trunk/drivers/staging/iio/adc/ad7887.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ enum ad7887_channels {
*/

struct ad7887_platform_data {
/* External Vref voltage applied */
u16 vref_mv;
/*
* AD7887:
* In single channel mode en_dual = flase, AIN1/Vref pins assumes its
Expand Down Expand Up @@ -63,7 +61,6 @@ struct ad7887_state {
struct spi_device *spi;
const struct ad7887_chip_info *chip_info;
struct regulator *reg;
u16 int_vref_mv;
struct spi_transfer xfer[4];
struct spi_message msg[3];
struct spi_message *ring_msg;
Expand Down
52 changes: 24 additions & 28 deletions trunk/drivers/staging/iio/adc/ad7887_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
{
int ret;
struct ad7887_state *st = iio_priv(indio_dev);
unsigned int scale_uv;

switch (m) {
case IIO_CHAN_INFO_RAW:
Expand All @@ -56,11 +55,18 @@ static int ad7887_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;
return IIO_VAL_INT_PLUS_MICRO;
if (st->reg) {
*val = regulator_get_voltage(st->reg);
if (*val < 0)
return *val;
*val /= 1000;
} else {
*val = st->chip_info->int_vref_mv;
}

*val2 = st->chip_info->channel[0].scan_type.realbits;

return IIO_VAL_FRACTIONAL_LOG2;
}
return -EINVAL;
}
Expand Down Expand Up @@ -105,21 +111,24 @@ static int __devinit ad7887_probe(struct spi_device *spi)
{
struct ad7887_platform_data *pdata = spi->dev.platform_data;
struct ad7887_state *st;
int ret, voltage_uv = 0;
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->use_onchip_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;

voltage_uv = regulator_get_voltage(st->reg);
}

st->chip_info =
Expand Down Expand Up @@ -176,23 +185,9 @@ static int __devinit ad7887_probe(struct spi_device *spi)
spi_message_init(&st->msg[AD7887_CH1]);
spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]);

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");

indio_dev->channels = st->chip_info->channel;
indio_dev->num_channels = 3;
} else {
if (pdata && pdata->vref_mv)
st->int_vref_mv = pdata->vref_mv;
else if (pdata && pdata->use_onchip_ref)
st->int_vref_mv = st->chip_info->int_vref_mv;
else
dev_warn(&spi->dev, "reference voltage unspecified\n");

indio_dev->channels = &st->chip_info->channel[1];
indio_dev->num_channels = 2;
}
Expand All @@ -209,11 +204,12 @@ static int __devinit ad7887_probe(struct spi_device *spi)
error_unregister_ring:
ad7887_ring_cleanup(indio_dev);
error_disable_reg:
if (!IS_ERR(st->reg))
if (st->reg)
regulator_disable(st->reg);
error_put_reg:
if (!IS_ERR(st->reg))
if (st->reg)
regulator_put(st->reg);
error_free:
iio_device_free(indio_dev);

return ret;
Expand All @@ -226,7 +222,7 @@ static int __devexit ad7887_remove(struct spi_device *spi)

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

0 comments on commit 032b026

Please sign in to comment.