Commit 58ea7784 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:gyro:adxrs450 move to iio_chan_spec registration

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 7d438178
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "../iio.h" #include "../iio.h"
#include "../sysfs.h" #include "../sysfs.h"
#include "gyro.h"
#include "../adc/adc.h" #include "../adc/adc.h"
#include "adxrs450.h" #include "adxrs450.h"
...@@ -32,12 +31,11 @@ ...@@ -32,12 +31,11 @@
* Second register's address is reg_address + 1. * Second register's address is reg_address + 1.
* @val: somewhere to pass back the value read * @val: somewhere to pass back the value read
**/ **/
static int adxrs450_spi_read_reg_16(struct device *dev, static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,
u8 reg_address, u8 reg_address,
u16 *val) u16 *val)
{ {
struct spi_message msg; struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adxrs450_state *st = iio_priv(indio_dev); struct adxrs450_state *st = iio_priv(indio_dev);
int ret; int ret;
struct spi_transfer xfers[] = { struct spi_transfer xfers[] = {
...@@ -86,12 +84,11 @@ static int adxrs450_spi_read_reg_16(struct device *dev, ...@@ -86,12 +84,11 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
* Second register's address is reg_address + 1. * Second register's address is reg_address + 1.
* @val: value to be written. * @val: value to be written.
**/ **/
static int adxrs450_spi_write_reg_16(struct device *dev, static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,
u8 reg_address, u8 reg_address,
u16 val) u16 val)
{ {
struct spi_message msg; struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adxrs450_state *st = iio_priv(indio_dev); struct adxrs450_state *st = iio_priv(indio_dev);
int ret; int ret;
struct spi_transfer xfers = { struct spi_transfer xfers = {
...@@ -126,10 +123,9 @@ static int adxrs450_spi_write_reg_16(struct device *dev, ...@@ -126,10 +123,9 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
* @dev: device associated with child of actual iio_dev * @dev: device associated with child of actual iio_dev
* @val: somewhere to pass back the value read * @val: somewhere to pass back the value read
**/ **/
static int adxrs450_spi_sensor_data(struct device *dev, s16 *val) static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val)
{ {
struct spi_message msg; struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adxrs450_state *st = iio_priv(indio_dev); struct adxrs450_state *st = iio_priv(indio_dev);
int ret; int ret;
struct spi_transfer xfers[] = { struct spi_transfer xfers[] = {
...@@ -206,64 +202,39 @@ static int adxrs450_spi_initial(struct adxrs450_state *st, ...@@ -206,64 +202,39 @@ static int adxrs450_spi_initial(struct adxrs450_state *st,
return ret; return ret;
} }
static ssize_t adxrs450_read_temp(struct device *dev, static int adxrs450_read_temp(struct iio_dev *indio_dev, int *val)
struct device_attribute *attr,
char *buf)
{ {
int ret; int ret;
u16 t; u16 t;
ret = adxrs450_spi_read_reg_16(dev, ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_TEMP1, &t);
ADXRS450_TEMP1,
&t);
if (ret) if (ret)
return ret; return ret;
return sprintf(buf, "%d\n", t >> 7); *val = t;
return 0;
} }
static ssize_t adxrs450_read_quad(struct device *dev, static int adxrs450_read_quad(struct iio_dev *indio_dev, int *val)
struct device_attribute *attr,
char *buf)
{ {
int ret; int ret;
s16 t; s16 t;
ret = adxrs450_spi_read_reg_16(dev, ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_QUAD1, &t);
ADXRS450_QUAD1,
&t);
if (ret) if (ret)
return ret; return ret;
return sprintf(buf, "%d\n", t); *val = t;
} return 0;
static ssize_t adxrs450_write_dnc(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t len)
{
int ret;
long val;
ret = strict_strtol(buf, 10, &val);
if (ret)
goto error_ret;
ret = adxrs450_spi_write_reg_16(dev,
ADXRS450_DNC1,
val & 0x3FF);
error_ret:
return ret ? ret : len;
} }
static ssize_t adxrs450_read_sensor_data(struct device *dev, static int adxrs450_read_sensor_data(struct iio_dev *indio_dev, int *val)
struct device_attribute *attr,
char *buf)
{ {
int ret; int ret;
s16 t; s16 t;
ret = adxrs450_spi_sensor_data(dev, &t); ret = adxrs450_spi_sensor_data(indio_dev, &t);
if (ret) if (ret)
return ret; return ret;
return sprintf(buf, "%d\n", t); *val = t;
return 0;
} }
/* Recommended Startup Sequence by spec */ /* Recommended Startup Sequence by spec */
...@@ -272,7 +243,6 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev) ...@@ -272,7 +243,6 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev)
u32 t; u32 t;
u16 data; u16 data;
int ret; int ret;
struct device *dev = &indio_dev->dev;
struct adxrs450_state *st = iio_priv(indio_dev); struct adxrs450_state *st = iio_priv(indio_dev);
msleep(ADXRS450_STARTUP_DELAY*2); msleep(ADXRS450_STARTUP_DELAY*2);
...@@ -305,23 +275,23 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev) ...@@ -305,23 +275,23 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev)
return -EIO; return -EIO;
} }
ret = adxrs450_spi_read_reg_16(dev, ADXRS450_FAULT1, &data); ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_FAULT1, &data);
if (ret) if (ret)
return ret; return ret;
if (data & 0x0fff) { if (data & 0x0fff) {
dev_err(&st->us->dev, "The device is not in normal status!\n"); dev_err(&st->us->dev, "The device is not in normal status!\n");
return -EINVAL; return -EINVAL;
} }
ret = adxrs450_spi_read_reg_16(dev, ADXRS450_PID1, &data); ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_PID1, &data);
if (ret) if (ret)
return ret; return ret;
dev_info(&st->us->dev, "The Part ID is 0x%x\n", data); dev_info(&st->us->dev, "The Part ID is 0x%x\n", data);
ret = adxrs450_spi_read_reg_16(dev, ADXRS450_SNL, &data); ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_SNL, &data);
if (ret) if (ret)
return ret; return ret;
t = data; t = data;
ret = adxrs450_spi_read_reg_16(dev, ADXRS450_SNH, &data); ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_SNH, &data);
if (ret) if (ret)
return ret; return ret;
t |= data << 16; t |= data << 16;
...@@ -330,29 +300,88 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev) ...@@ -330,29 +300,88 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev)
return 0; return 0;
} }
static IIO_DEV_ATTR_GYRO_Z(adxrs450_read_sensor_data, 0); static int adxrs450_write_raw(struct iio_dev *indio_dev,
static IIO_DEV_ATTR_TEMP_RAW(adxrs450_read_temp); struct iio_chan_spec const *chan,
static IIO_DEV_ATTR_GYRO_Z_QUADRATURE_CORRECTION(adxrs450_read_quad, 0); int val,
static IIO_DEV_ATTR_GYRO_Z_CALIBBIAS(S_IWUSR, int val2,
NULL, adxrs450_write_dnc, 0); long mask)
static IIO_CONST_ATTR(name, "adxrs450"); {
int ret;
static struct attribute *adxrs450_attributes[] = { switch (mask) {
&iio_dev_attr_gyro_z_raw.dev_attr.attr, case (1 << IIO_CHAN_INFO_CALIBBIAS_SEPARATE):
&iio_dev_attr_temp_raw.dev_attr.attr, ret = adxrs450_spi_write_reg_16(indio_dev,
&iio_dev_attr_gyro_z_quadrature_correction_raw.dev_attr.attr, ADXRS450_DNC1,
&iio_dev_attr_gyro_z_calibbias.dev_attr.attr, val & 0x3FF);
&iio_const_attr_name.dev_attr.attr, break;
NULL default:
}; ret = -EINVAL;
break;
}
return ret;
}
static int adxrs450_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long mask)
{
int ret;
switch (mask) {
case 0:
switch (chan->type) {
case IIO_GYRO:
ret = adxrs450_read_sensor_data(indio_dev, val);
if (ret < 0)
break;
*val = ret;
ret = IIO_VAL_INT;
break;
case IIO_TEMP:
ret = adxrs450_read_temp(indio_dev, val);
if (ret < 0)
break;
*val = ret;
ret = IIO_VAL_INT;
break;
default:
ret = -EINVAL;
break;
}
break;
case (1 << IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE):
ret = adxrs450_read_quad(indio_dev, val);
if (ret < 0)
break;
*val = ret;
ret = IIO_VAL_INT;
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static const struct attribute_group adxrs450_attribute_group = { static const struct iio_chan_spec adxrs450_channels[] = {
.attrs = adxrs450_attributes, {
.type = IIO_GYRO,
.modified = 1,
.channel2 = IIO_MOD_Z,
.info_mask = (1 << IIO_CHAN_INFO_CALIBBIAS_SEPARATE) |
(1 << IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE)
}, {
.type = IIO_TEMP,
.indexed = 1,
.channel = 0,
}
}; };
static const struct iio_info adxrs450_info = { static const struct iio_info adxrs450_info = {
.attrs = &adxrs450_attribute_group,
.driver_module = THIS_MODULE, .driver_module = THIS_MODULE,
.read_raw = &adxrs450_read_raw,
.write_raw = &adxrs450_write_raw,
}; };
static int __devinit adxrs450_probe(struct spi_device *spi) static int __devinit adxrs450_probe(struct spi_device *spi)
...@@ -376,6 +405,9 @@ static int __devinit adxrs450_probe(struct spi_device *spi) ...@@ -376,6 +405,9 @@ static int __devinit adxrs450_probe(struct spi_device *spi)
indio_dev->dev.parent = &spi->dev; indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adxrs450_info; indio_dev->info = &adxrs450_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = adxrs450_channels;
indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels);
indio_dev->name = spi->dev.driver->name;
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