Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 338008
b: refs/heads/master
c: 01a10e0
h: refs/heads/master
v: v3
  • Loading branch information
Lars-Peter Clausen authored and Jonathan Cameron committed Nov 19, 2012
1 parent 5cb2283 commit 010b67f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 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: 2e334600989384a11ed7ae0dc0e0ca0486ebfaaa
refs/heads/master: 01a10e04f8e099fea3212a70df0b25a8ffd9275f
51 changes: 23 additions & 28 deletions trunk/drivers/staging/iio/adc/ad7298_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ static const struct iio_chan_spec ad7298_channels[] = {
.indexed = 1,
.channel = 0,
.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
.address = AD7298_CH_TEMP,
.scan_index = -1,
.scan_type = {
Expand Down Expand Up @@ -80,7 +81,7 @@ static int ad7298_scan_direct(struct ad7298_state *st, unsigned ch)

static int ad7298_scan_temp(struct ad7298_state *st, int *val)
{
int tmp, ret;
int ret;
__be16 buf;

buf = cpu_to_be16(AD7298_WRITE | AD7298_TSENSE |
Expand All @@ -102,24 +103,24 @@ static int ad7298_scan_temp(struct ad7298_state *st, int *val)
if (ret)
return ret;

tmp = be16_to_cpu(buf) & RES_MASK(AD7298_BITS);
*val = sign_extend32(be16_to_cpu(buf), 11);

/*
* One LSB of the ADC corresponds to 0.25 deg C.
* The temperature reading is in 12-bit twos complement format
*/
return 0;
}

static int ad7298_get_ref_voltage(struct ad7298_state *st)
{
int vref;

if (tmp & (1 << (AD7298_BITS - 1))) {
tmp = (4096 - tmp) * 250;
tmp -= (2 * tmp);
if (st->ext_ref) {
vref = regulator_get_voltage(st->reg);
if (vref < 0)
return vref;

return vref / 1000;
} else {
tmp *= 250; /* temperature in milli degrees Celsius */
return AD7298_INTREF_mV;
}

*val = tmp;

return 0;
}

static int ad7298_read_raw(struct iio_dev *indio_dev,
Expand All @@ -130,7 +131,6 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
{
int ret;
struct ad7298_state *st = iio_priv(indio_dev);
int scale_mv;

switch (m) {
case IIO_CHAN_INFO_RAW:
Expand All @@ -155,24 +155,19 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_VOLTAGE:
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;
*val = ad7298_get_ref_voltage(st);
*val2 = chan->scan_type.realbits;
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_TEMP:
*val = 1;
*val2 = 0;
return IIO_VAL_INT_PLUS_MICRO;
*val = ad7298_get_ref_voltage(st);
*val2 = 10;
return IIO_VAL_FRACTIONAL;
default:
return -EINVAL;
}
case IIO_CHAN_INFO_OFFSET:
*val = 1093 - 2732500 / ad7298_get_ref_voltage(st);
return IIO_VAL_INT;
}
return -EINVAL;
}
Expand Down

0 comments on commit 010b67f

Please sign in to comment.