Commit 9f8632d7 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:gyro:adis16130: allocate chip state with iio_dev and use iio_priv to access it.

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 1dd9290a
...@@ -41,14 +41,12 @@ ...@@ -41,14 +41,12 @@
/** /**
* struct adis16130_state - device instance specific data * struct adis16130_state - device instance specific data
* @us: actual spi_device to write data * @us: actual spi_device to write data
* @indio_dev: industrial I/O device structure
* @mode: 24 bits (1) or 16 bits (0) * @mode: 24 bits (1) or 16 bits (0)
* @buf_lock: mutex to protect tx and rx * @buf_lock: mutex to protect tx and rx
* @buf: unified tx/rx buffer * @buf: unified tx/rx buffer
**/ **/
struct adis16130_state { struct adis16130_state {
struct spi_device *us; struct spi_device *us;
struct iio_dev *indio_dev;
u32 mode; u32 mode;
struct mutex buf_lock; struct mutex buf_lock;
u8 buf[4] ____cacheline_aligned; u8 buf[4] ____cacheline_aligned;
...@@ -59,7 +57,7 @@ static int adis16130_spi_write(struct device *dev, u8 reg_addr, ...@@ -59,7 +57,7 @@ static int adis16130_spi_write(struct device *dev, u8 reg_addr,
{ {
int ret; int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adis16130_state *st = iio_dev_get_devdata(indio_dev); struct adis16130_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
st->buf[0] = reg_addr; st->buf[0] = reg_addr;
...@@ -76,7 +74,7 @@ static int adis16130_spi_read(struct device *dev, u8 reg_addr, ...@@ -76,7 +74,7 @@ static int adis16130_spi_read(struct device *dev, u8 reg_addr,
{ {
int ret; int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adis16130_state *st = iio_dev_get_devdata(indio_dev); struct adis16130_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
...@@ -125,7 +123,7 @@ static ssize_t adis16130_bitsmode_read(struct device *dev, ...@@ -125,7 +123,7 @@ static ssize_t adis16130_bitsmode_read(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adis16130_state *st = iio_dev_get_devdata(indio_dev); struct adis16130_state *st = iio_priv(indio_dev);
if (st->mode == 1) if (st->mode == 1)
return sprintf(buf, "s24\n"); return sprintf(buf, "s24\n");
...@@ -183,39 +181,35 @@ static const struct iio_info adis16130_info = { ...@@ -183,39 +181,35 @@ static const struct iio_info adis16130_info = {
static int __devinit adis16130_probe(struct spi_device *spi) static int __devinit adis16130_probe(struct spi_device *spi)
{ {
int ret; int ret;
struct adis16130_state *st = kzalloc(sizeof *st, GFP_KERNEL); struct adis16130_state *st;
if (!st) { struct iio_dev *indio_dev;
ret = -ENOMEM;
/* setup the industrialio driver allocated elements */
indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_ret; goto error_ret;
} }
st = iio_priv(indio_dev);
/* this is only used for removal purposes */ /* this is only used for removal purposes */
spi_set_drvdata(spi, st); spi_set_drvdata(spi, indio_dev);
st->us = spi; st->us = spi;
mutex_init(&st->buf_lock); mutex_init(&st->buf_lock);
/* setup the industrialio driver allocated elements */ indio_dev->name = spi->dev.driver->name;
st->indio_dev = iio_allocate_device(0); indio_dev->dev.parent = &spi->dev;
if (st->indio_dev == NULL) { indio_dev->info = &adis16130_info;
ret = -ENOMEM; indio_dev->modes = INDIO_DIRECT_MODE;
goto error_free_st;
}
st->indio_dev->name = spi->dev.driver->name;
st->indio_dev->dev.parent = &spi->dev;
st->indio_dev->info = &adis16130_info;
st->indio_dev->dev_data = (void *)(st);
st->indio_dev->modes = INDIO_DIRECT_MODE;
st->mode = 1; st->mode = 1;
ret = iio_device_register(st->indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
return 0; return 0;
error_free_dev: error_free_dev:
iio_free_device(st->indio_dev); iio_free_device(indio_dev);
error_free_st:
kfree(st);
error_ret: error_ret:
return ret; return ret;
} }
...@@ -223,11 +217,7 @@ static int __devinit adis16130_probe(struct spi_device *spi) ...@@ -223,11 +217,7 @@ static int __devinit adis16130_probe(struct spi_device *spi)
/* fixme, confirm ordering in this function */ /* fixme, confirm ordering in this function */
static int adis16130_remove(struct spi_device *spi) static int adis16130_remove(struct spi_device *spi)
{ {
struct adis16130_state *st = spi_get_drvdata(spi); iio_device_unregister(spi_get_drvdata(spi));
struct iio_dev *indio_dev = st->indio_dev;
iio_device_unregister(indio_dev);
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