Commit 584c81fb authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

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: default avatarJonathan Cameron <jic23@cam.ac.uk>
Acked-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 037bad9a
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
#include "../iio.h" #include "../iio.h"
#include "../sysfs.h" #include "../sysfs.h"
#include "gyro.h"
#include "../adc/adc.h"
#define ADIS16080_DIN_GYRO (0 << 10) /* Gyroscope output */ #define ADIS16080_DIN_GYRO (0 << 10) /* Gyroscope output */
#define ADIS16080_DIN_TEMP (1 << 10) /* Temperature output */ #define ADIS16080_DIN_TEMP (1 << 10) /* Temperature output */
...@@ -44,11 +42,10 @@ struct adis16080_state { ...@@ -44,11 +42,10 @@ struct adis16080_state {
u8 buf[2] ____cacheline_aligned; 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) u16 val)
{ {
int ret; int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adis16080_state *st = iio_priv(indio_dev); struct adis16080_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
...@@ -61,11 +58,10 @@ static int adis16080_spi_write(struct device *dev, ...@@ -61,11 +58,10 @@ static int adis16080_spi_write(struct device *dev,
return ret; return ret;
} }
static int adis16080_spi_read(struct device *dev, static int adis16080_spi_read(struct iio_dev *indio_dev,
u16 *val) u16 *val)
{ {
int ret; int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adis16080_state *st = iio_priv(indio_dev); struct adis16080_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
...@@ -79,50 +75,62 @@ static int adis16080_spi_read(struct device *dev, ...@@ -79,50 +75,62 @@ static int adis16080_spi_read(struct device *dev,
return ret; return ret;
} }
static ssize_t adis16080_read(struct device *dev, static int adis16080_read_raw(struct iio_dev *indio_dev,
struct device_attribute *attr, struct iio_chan_spec const *chan,
char *buf) int *val,
int *val2,
long mask)
{ {
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int ret = -EINVAL;
struct iio_dev *indio_dev = dev_get_drvdata(dev); u16 ut;
u16 val = 0;
ssize_t ret;
/* Take the iio_dev status lock */ /* Take the iio_dev status lock */
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
ret = adis16080_spi_write(dev, switch (mask) {
this_attr->address | ADIS16080_DIN_WRITE); case 0:
if (ret < 0) ret = adis16080_spi_write(indio_dev,
goto error_ret; chan->address |
ret = adis16080_spi_read(dev, &val); ADIS16080_DIN_WRITE);
error_ret: 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); mutex_unlock(&indio_dev->mlock);
if (ret == 0) return ret;
return sprintf(buf, "%d\n", val);
else
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 = { static const struct iio_chan_spec adis16080_channels[] = {
.attrs = adis16080_attributes, {
.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 = { static const struct iio_info adis16080_info = {
.attrs = &adis16080_attribute_group, .read_raw = &adis16080_read_raw,
.driver_module = THIS_MODULE, .driver_module = THIS_MODULE,
}; };
...@@ -147,6 +155,8 @@ static int __devinit adis16080_probe(struct spi_device *spi) ...@@ -147,6 +155,8 @@ static int __devinit adis16080_probe(struct spi_device *spi)
mutex_init(&st->buf_lock); mutex_init(&st->buf_lock);
indio_dev->name = spi->dev.driver->name; 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->dev.parent = &spi->dev;
indio_dev->info = &adis16080_info; indio_dev->info = &adis16080_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
......
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