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

staging:iio:resolver:ad2s90 general cleanup

Very simple driver, so not much to do.
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 8f2bd836
...@@ -24,29 +24,19 @@ struct ad2s90_state { ...@@ -24,29 +24,19 @@ struct ad2s90_state {
struct mutex lock; struct mutex lock;
struct iio_dev *idev; struct iio_dev *idev;
struct spi_device *sdev; struct spi_device *sdev;
u8 rx[2]; u8 rx[2] ____cacheline_aligned;
u8 tx[2];
}; };
static ssize_t ad2s90_show_angular(struct device *dev, static ssize_t ad2s90_show_angular(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct spi_message msg;
struct spi_transfer xfer;
int ret; int ret;
ssize_t len = 0; ssize_t len = 0;
u16 val; u16 val;
struct iio_dev *idev = dev_get_drvdata(dev); struct ad2s90_state *st = iio_priv(dev_get_drvdata(dev));
struct ad2s90_state *st = idev->dev_data;
xfer.len = 1;
xfer.tx_buf = st->tx;
xfer.rx_buf = st->rx;
mutex_lock(&st->lock); mutex_lock(&st->lock);
ret = spi_read(st->sdev, st->rx, 2);
spi_message_init(&msg);
spi_message_add_tail(&xfer, &msg);
ret = spi_sync(st->sdev, &msg);
if (ret) if (ret)
goto error_ret; goto error_ret;
val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4); val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
...@@ -60,12 +50,9 @@ static ssize_t ad2s90_show_angular(struct device *dev, ...@@ -60,12 +50,9 @@ static ssize_t ad2s90_show_angular(struct device *dev,
#define IIO_DEV_ATTR_SIMPLE_RESOLVER(_show) \ #define IIO_DEV_ATTR_SIMPLE_RESOLVER(_show) \
IIO_DEVICE_ATTR(angular, S_IRUGO, _show, NULL, 0) IIO_DEVICE_ATTR(angular, S_IRUGO, _show, NULL, 0)
static IIO_CONST_ATTR(description,
"Low Cost, Complete 12-Bit Resolver-to-Digital Converter");
static IIO_DEV_ATTR_SIMPLE_RESOLVER(ad2s90_show_angular); static IIO_DEV_ATTR_SIMPLE_RESOLVER(ad2s90_show_angular);
static struct attribute *ad2s90_attributes[] = { static struct attribute *ad2s90_attributes[] = {
&iio_const_attr_description.dev_attr.attr,
&iio_dev_attr_angular.dev_attr.attr, &iio_dev_attr_angular.dev_attr.attr,
NULL, NULL,
}; };
...@@ -82,29 +69,23 @@ static const struct iio_info ad2s90_info = { ...@@ -82,29 +69,23 @@ static const struct iio_info ad2s90_info = {
static int __devinit ad2s90_probe(struct spi_device *spi) static int __devinit ad2s90_probe(struct spi_device *spi)
{ {
struct iio_dev *indio_dev;
struct ad2s90_state *st; struct ad2s90_state *st;
int ret = 0; int ret = 0;
st = kzalloc(sizeof(*st), GFP_KERNEL); indio_dev = iio_allocate_device(sizeof(*st));
if (st == NULL) { if (indio_dev == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_ret; goto error_ret;
} }
spi_set_drvdata(spi, st); st = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);
mutex_init(&st->lock); mutex_init(&st->lock);
st->sdev = spi; st->sdev = spi;
indio_dev->dev.parent = &spi->dev;
st->idev = iio_allocate_device(0); indio_dev->info = &ad2s90_info;
if (st->idev == NULL) { indio_dev->modes = INDIO_DIRECT_MODE;
ret = -ENOMEM;
goto error_free_st;
}
st->idev->dev.parent = &spi->dev;
st->idev->info = &ad2s90_info;
st->idev->dev_data = (void *)(st);
st->idev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(st->idev); ret = iio_device_register(st->idev);
if (ret) if (ret)
...@@ -119,18 +100,13 @@ static int __devinit ad2s90_probe(struct spi_device *spi) ...@@ -119,18 +100,13 @@ static int __devinit ad2s90_probe(struct spi_device *spi)
error_free_dev: error_free_dev:
iio_free_device(st->idev); iio_free_device(st->idev);
error_free_st:
kfree(st);
error_ret: error_ret:
return ret; return ret;
} }
static int __devexit ad2s90_remove(struct spi_device *spi) static int __devexit ad2s90_remove(struct spi_device *spi)
{ {
struct ad2s90_state *st = spi_get_drvdata(spi); iio_device_unregister(spi_get_drvdata(spi));
iio_device_unregister(st->idev);
kfree(st);
return 0; return 0;
} }
......
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