Commit 643ea260 authored by Michael Hennerich's avatar Michael Hennerich Committed by Greg Kroah-Hartman

staging:iio:adc:AD7780: Convert to new channel registration method

Convert to new channel registration method
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Acked-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 44039a67
...@@ -36,9 +36,7 @@ ...@@ -36,9 +36,7 @@
#define AD7780_PAT0 (1 << 0) #define AD7780_PAT0 (1 << 0)
struct ad7780_chip_info { struct ad7780_chip_info {
u8 bits; struct iio_chan_spec channel;
u8 storagebits;
u8 res_shift;
}; };
struct ad7780_state { struct ad7780_state {
...@@ -88,70 +86,59 @@ static int ad7780_read(struct ad7780_state *st, int *val) ...@@ -88,70 +86,59 @@ static int ad7780_read(struct ad7780_state *st, int *val)
return ret; return ret;
} }
static ssize_t ad7780_scan(struct device *dev, static int ad7780_read_raw(struct iio_dev *indio_dev,
struct device_attribute *attr, struct iio_chan_spec const *chan,
char *buf) int *val,
int *val2,
long m)
{ {
struct iio_dev *dev_info = dev_get_drvdata(dev); int ret, smpl;
struct ad7780_state *st = dev_info->dev_data; struct ad7780_state *st = indio_dev->dev_data;
int ret, val, smpl; unsigned int scale_uv;
mutex_lock(&dev_info->mlock); switch (m) {
ret = ad7780_read(st, &smpl); case 0:
mutex_unlock(&dev_info->mlock); mutex_lock(&indio_dev->mlock);
ret = ad7780_read(st, &smpl);
if (ret < 0) mutex_unlock(&indio_dev->mlock);
return ret;
if (ret < 0)
if ((smpl & AD7780_ERR) || return ret;
!((smpl & AD7780_PAT0) && !(smpl & AD7780_PAT1)))
return -EIO; if ((smpl & AD7780_ERR) ||
!((smpl & AD7780_PAT0) && !(smpl & AD7780_PAT1)))
val = (smpl >> st->chip_info->res_shift) & return -EIO;
((1 << (st->chip_info->bits)) - 1);
val -= (1 << (st->chip_info->bits - 1)); *val = (smpl >> st->chip_info->channel.scan_type.shift) &
((1 << (st->chip_info->channel.scan_type.realbits))
if (!(smpl & AD7780_GAIN)) - 1);
val *= 128; *val -= (1 << (st->chip_info->channel.scan_type.realbits
- 1));
return sprintf(buf, "%d\n", val);
} if (!(smpl & AD7780_GAIN))
static IIO_DEV_ATTR_IN_RAW(0, ad7780_scan, 0); *val *= 128;
static ssize_t ad7780_show_scale(struct device *dev, return IIO_VAL_INT;
struct device_attribute *attr, case (1 << IIO_CHAN_INFO_SCALE_SHARED):
char *buf) scale_uv = (st->int_vref_mv * 100000)
{ >> (st->chip_info->channel.scan_type.realbits - 1);
struct iio_dev *dev_info = dev_get_drvdata(dev); *val = scale_uv / 100000;
struct ad7780_state *st = iio_dev_get_devdata(dev_info); *val2 = (scale_uv % 100000) * 10;
/* Corresponds to Vref / 2^(bits-1) */ return IIO_VAL_INT_PLUS_MICRO;
unsigned int scale = (st->int_vref_mv * 100000) >> }
(st->chip_info->bits - 1); return -EINVAL;
return sprintf(buf, "%d.%05d\n", scale / 100000, scale % 100000);
} }
static IIO_DEVICE_ATTR(in_scale, S_IRUGO, ad7780_show_scale, NULL, 0);
static struct attribute *ad7780_attributes[] = {
&iio_dev_attr_in0_raw.dev_attr.attr,
&iio_dev_attr_in_scale.dev_attr.attr,
NULL,
};
static const struct attribute_group ad7780_attribute_group = {
.attrs = ad7780_attributes,
};
static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { static const struct ad7780_chip_info ad7780_chip_info_tbl[] = {
[ID_AD7780] = { [ID_AD7780] = {
.bits = 24, .channel = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0,
.storagebits = 32, (1 << IIO_CHAN_INFO_SCALE_SHARED),
.res_shift = 8, 0, 0, IIO_ST('s', 24, 32, 8), 0),
}, },
[ID_AD7781] = { [ID_AD7781] = {
.bits = 20, .channel = IIO_CHAN(IIO_IN, 0, 1, 0, NULL, 0, 0,
.storagebits = 32, (1 << IIO_CHAN_INFO_SCALE_SHARED),
.res_shift = 12, 0, 0, IIO_ST('s', 20, 32, 12), 0),
}, },
}; };
...@@ -218,17 +205,19 @@ static int __devinit ad7780_probe(struct spi_device *spi) ...@@ -218,17 +205,19 @@ static int __devinit ad7780_probe(struct spi_device *spi)
/* Establish that the iio_dev is a child of the spi device */ /* Establish that the iio_dev is a child of the spi device */
st->indio_dev->dev.parent = &spi->dev; st->indio_dev->dev.parent = &spi->dev;
st->indio_dev->name = spi_get_device_id(spi)->name; st->indio_dev->name = spi_get_device_id(spi)->name;
st->indio_dev->attrs = &ad7780_attribute_group;
st->indio_dev->dev_data = (void *)(st); st->indio_dev->dev_data = (void *)(st);
st->indio_dev->driver_module = THIS_MODULE; st->indio_dev->driver_module = THIS_MODULE;
st->indio_dev->modes = INDIO_DIRECT_MODE; st->indio_dev->modes = INDIO_DIRECT_MODE;
st->indio_dev->channels = &st->chip_info->channel;
st->indio_dev->num_channels = 1;
st->indio_dev->read_raw = &ad7780_read_raw;
init_waitqueue_head(&st->wq_data_avail); init_waitqueue_head(&st->wq_data_avail);
/* Setup default message */ /* Setup default message */
st->xfer.rx_buf = &st->data; st->xfer.rx_buf = &st->data;
st->xfer.len = st->chip_info->storagebits / 8; st->xfer.len = st->chip_info->channel.scan_type.storagebits / 8;
spi_message_init(&st->msg); spi_message_init(&st->msg);
spi_message_add_tail(&st->xfer, &st->msg); spi_message_add_tail(&st->xfer, &st->msg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment