diff options
author | Jonathan Cameron <jic23@cam.ac.uk> | 2011-08-12 17:47:57 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-08-23 13:32:47 -0700 |
commit | 584c81fbee8d549d68679e42fa56540cc74148da (patch) | |
tree | 400ce266175faadb77de240eb7e659dcada0c3f0 /drivers/staging | |
parent | 037bad9a7228c9009b5f4f6e63ad5c7012b8f659 (diff) | |
download | linux-stable-584c81fbee8d549d68679e42fa56540cc74148da.tar.gz linux-stable-584c81fbee8d549d68679e42fa56540cc74148da.tar.bz2 linux-stable-584c81fbee8d549d68679e42fa56540cc74148da.zip |
staging:iio:gyro:adis16080 convert to iio_chan_spec.
This is a rare driver that is so simple it actually gets longer
as a result of this conversion. Oh well, swings and roundabouts.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/iio/gyro/adis16080_core.c | 92 |
1 files changed, 51 insertions, 41 deletions
diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c index ad2db4d723df..bd3eb1019867 100644 --- a/drivers/staging/iio/gyro/adis16080_core.c +++ b/drivers/staging/iio/gyro/adis16080_core.c @@ -16,8 +16,6 @@ #include "../iio.h" #include "../sysfs.h" -#include "gyro.h" -#include "../adc/adc.h" #define ADIS16080_DIN_GYRO (0 << 10) /* Gyroscope output */ #define ADIS16080_DIN_TEMP (1 << 10) /* Temperature output */ @@ -44,11 +42,10 @@ struct adis16080_state { u8 buf[2] ____cacheline_aligned; }; -static int adis16080_spi_write(struct device *dev, +static int adis16080_spi_write(struct iio_dev *indio_dev, u16 val) { int ret; - struct iio_dev *indio_dev = dev_get_drvdata(dev); struct adis16080_state *st = iio_priv(indio_dev); mutex_lock(&st->buf_lock); @@ -61,11 +58,10 @@ static int adis16080_spi_write(struct device *dev, return ret; } -static int adis16080_spi_read(struct device *dev, - u16 *val) +static int adis16080_spi_read(struct iio_dev *indio_dev, + u16 *val) { int ret; - struct iio_dev *indio_dev = dev_get_drvdata(dev); struct adis16080_state *st = iio_priv(indio_dev); mutex_lock(&st->buf_lock); @@ -79,50 +75,62 @@ static int adis16080_spi_read(struct device *dev, return ret; } -static ssize_t adis16080_read(struct device *dev, - struct device_attribute *attr, - char *buf) +static int adis16080_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, + int *val2, + long mask) { - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - struct iio_dev *indio_dev = dev_get_drvdata(dev); - u16 val = 0; - ssize_t ret; - + int ret = -EINVAL; + u16 ut; /* Take the iio_dev status lock */ + mutex_lock(&indio_dev->mlock); - ret = adis16080_spi_write(dev, - this_attr->address | ADIS16080_DIN_WRITE); - if (ret < 0) - goto error_ret; - ret = adis16080_spi_read(dev, &val); -error_ret: + switch (mask) { + case 0: + ret = adis16080_spi_write(indio_dev, + chan->address | + ADIS16080_DIN_WRITE); + if (ret < 0) + break; + ret = adis16080_spi_read(indio_dev, &ut); + if (ret < 0) + break; + *val = ut; + ret = IIO_VAL_INT; + break; + } mutex_unlock(&indio_dev->mlock); - if (ret == 0) - return sprintf(buf, "%d\n", val); - else - return ret; + return ret; } -static IIO_DEV_ATTR_GYRO_Z(adis16080_read, ADIS16080_DIN_GYRO); -static IIO_DEVICE_ATTR(temp_raw, S_IRUGO, adis16080_read, NULL, - ADIS16080_DIN_TEMP); -static IIO_DEV_ATTR_IN_RAW(0, adis16080_read, ADIS16080_DIN_AIN1); -static IIO_DEV_ATTR_IN_RAW(1, adis16080_read, ADIS16080_DIN_AIN2); - -static struct attribute *adis16080_attributes[] = { - &iio_dev_attr_gyro_z_raw.dev_attr.attr, - &iio_dev_attr_temp_raw.dev_attr.attr, - &iio_dev_attr_in0_raw.dev_attr.attr, - &iio_dev_attr_in1_raw.dev_attr.attr, - NULL -}; -static const struct attribute_group adis16080_attribute_group = { - .attrs = adis16080_attributes, +static const struct iio_chan_spec adis16080_channels[] = { + { + .type = IIO_GYRO, + .modified = 1, + .channel2 = IIO_MOD_Z, + .address = ADIS16080_DIN_GYRO, + }, { + .type = IIO_IN, + .indexed = 1, + .channel = 0, + .address = ADIS16080_DIN_AIN1, + }, { + .type = IIO_IN, + .indexed = 1, + .channel = 1, + .address = ADIS16080_DIN_AIN2, + }, { + .type = IIO_TEMP, + .indexed = 1, + .channel = 0, + .address = ADIS16080_DIN_TEMP, + } }; static const struct iio_info adis16080_info = { - .attrs = &adis16080_attribute_group, + .read_raw = &adis16080_read_raw, .driver_module = THIS_MODULE, }; @@ -147,6 +155,8 @@ static int __devinit adis16080_probe(struct spi_device *spi) mutex_init(&st->buf_lock); indio_dev->name = spi->dev.driver->name; + indio_dev->channels = adis16080_channels; + indio_dev->num_channels = ARRAY_SIZE(adis16080_channels); indio_dev->dev.parent = &spi->dev; indio_dev->info = &adis16080_info; indio_dev->modes = INDIO_DIRECT_MODE; |