Commit 4f2ca080 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:gyro:adis16060 convert to iio_chan_spec

Still a very odd driver. This patch has the side effect of changing
it's name slightly.
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 ae0b4bdd
...@@ -14,11 +14,8 @@ ...@@ -14,11 +14,8 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include "../iio.h" #include "../iio.h"
#include "../sysfs.h" #include "../sysfs.h"
#include "gyro.h"
#include "../adc/adc.h"
#define ADIS16060_GYRO 0x20 /* Measure Angular Rate (Gyro) */ #define ADIS16060_GYRO 0x20 /* Measure Angular Rate (Gyro) */
#define ADIS16060_TEMP_OUT 0x10 /* Measure Temperature */ #define ADIS16060_TEMP_OUT 0x10 /* Measure Temperature */
...@@ -42,11 +39,9 @@ struct adis16060_state { ...@@ -42,11 +39,9 @@ struct adis16060_state {
static struct iio_dev *adis16060_iio_dev; static struct iio_dev *adis16060_iio_dev;
static int adis16060_spi_write(struct device *dev, static int adis16060_spi_write(struct iio_dev *indio_dev, u8 val)
u8 val)
{ {
int ret; int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adis16060_state *st = iio_priv(indio_dev); struct adis16060_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
...@@ -57,11 +52,9 @@ static int adis16060_spi_write(struct device *dev, ...@@ -57,11 +52,9 @@ static int adis16060_spi_write(struct device *dev,
return ret; return ret;
} }
static int adis16060_spi_read(struct device *dev, static int adis16060_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 adis16060_state *st = iio_priv(indio_dev); struct adis16060_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
...@@ -82,60 +75,71 @@ static int adis16060_spi_read(struct device *dev, ...@@ -82,60 +75,71 @@ static int adis16060_spi_read(struct device *dev,
return ret; return ret;
} }
static ssize_t adis16060_read(struct device *dev, static int adis16060_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); u16 tval = 0;
struct iio_dev *indio_dev = dev_get_drvdata(dev); int ret;
u16 val = 0;
ssize_t ret;
switch (mask) {
case 0:
/* Take the iio_dev status lock */ /* Take the iio_dev status lock */
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
ret = adis16060_spi_write(indio_dev, chan->address);
ret = adis16060_spi_write(dev, this_attr->address); if (ret < 0) {
if (ret < 0)
goto error_ret;
ret = adis16060_spi_read(dev, &val);
error_ret:
mutex_unlock(&indio_dev->mlock); mutex_unlock(&indio_dev->mlock);
if (ret == 0)
return sprintf(buf, "%d\n", val);
else
return ret; return ret;
} }
ret = adis16060_spi_read(indio_dev, &tval);
static IIO_DEV_ATTR_GYRO_Z(adis16060_read, ADIS16060_GYRO); mutex_unlock(&indio_dev->mlock);
static IIO_DEVICE_ATTR(temp_raw, S_IRUGO, adis16060_read, NULL, *val = tval;
ADIS16060_TEMP_OUT); return IIO_VAL_INT;
static IIO_CONST_ATTR_TEMP_SCALE("34"); /* Milli degrees C */ case (1 << IIO_CHAN_INFO_OFFSET_SEPARATE):
static IIO_CONST_ATTR_TEMP_OFFSET("-7461.117"); /* Milli degrees C */ *val = -7;
static IIO_DEV_ATTR_IN_RAW(0, adis16060_read, ADIS16060_AIN1); *val2 = 461117;
static IIO_DEV_ATTR_IN_RAW(1, adis16060_read, ADIS16060_AIN2); return IIO_VAL_INT_PLUS_MICRO;
static IIO_CONST_ATTR(name, "adis16060"); case (1 << IIO_CHAN_INFO_SCALE_SEPARATE):
*val = 0;
static struct attribute *adis16060_attributes[] = { *val2 = 34000;
&iio_dev_attr_gyro_z_raw.dev_attr.attr, return IIO_VAL_INT_PLUS_MICRO;
&iio_dev_attr_temp_raw.dev_attr.attr, }
&iio_const_attr_temp_scale.dev_attr.attr,
&iio_const_attr_temp_offset.dev_attr.attr,
&iio_dev_attr_in0_raw.dev_attr.attr,
&iio_dev_attr_in1_raw.dev_attr.attr,
&iio_const_attr_name.dev_attr.attr,
NULL
};
static const struct attribute_group adis16060_attribute_group = { return -EINVAL;
.attrs = adis16060_attributes, }
};
static const struct iio_info adis16060_info = { static const struct iio_info adis16060_info = {
.attrs = &adis16060_attribute_group, .read_raw = &adis16060_read_raw,
.driver_module = THIS_MODULE, .driver_module = THIS_MODULE,
}; };
static const struct iio_chan_spec adis16060_channels[] = {
{
.type = IIO_GYRO,
.modified = 1,
.channel2 = IIO_MOD_Z,
.address = ADIS16060_GYRO,
}, {
.type = IIO_IN,
.indexed = 1,
.channel = 0,
.address = ADIS16060_AIN1,
}, {
.type = IIO_IN,
.indexed = 1,
.channel = 1,
.address = ADIS16060_AIN2,
}, {
.type = IIO_TEMP,
.indexed = 1,
.channel = 0,
.info_mask = (1 << IIO_CHAN_INFO_OFFSET_SEPARATE) |
(1 << IIO_CHAN_INFO_SCALE_SEPARATE),
.address = ADIS16060_TEMP_OUT,
}
};
static int __devinit adis16060_r_probe(struct spi_device *spi) static int __devinit adis16060_r_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret, regdone = 0;
...@@ -154,9 +158,12 @@ static int __devinit adis16060_r_probe(struct spi_device *spi) ...@@ -154,9 +158,12 @@ static int __devinit adis16060_r_probe(struct spi_device *spi)
st->us_r = spi; st->us_r = spi;
mutex_init(&st->buf_lock); mutex_init(&st->buf_lock);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev; indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16060_info; indio_dev->info = &adis16060_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = adis16060_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16060_channels);
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
......
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