Commit f39e086a authored by Michael Hennerich's avatar Michael Hennerich Committed by Greg Kroah-Hartman

staging:iio:adc:ad7887: Use private data space from iio_allocate_device

Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Acked-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 596d0609
...@@ -60,7 +60,6 @@ struct ad7887_chip_info { ...@@ -60,7 +60,6 @@ struct ad7887_chip_info {
}; };
struct ad7887_state { struct ad7887_state {
struct iio_dev *indio_dev;
struct spi_device *spi; struct spi_device *spi;
const struct ad7887_chip_info *chip_info; const struct ad7887_chip_info *chip_info;
struct regulator *reg; struct regulator *reg;
......
...@@ -6,13 +6,10 @@ ...@@ -6,13 +6,10 @@
* Licensed under the GPL-2. * Licensed under the GPL-2.
*/ */
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/list.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -90,13 +87,13 @@ static int __devinit ad7887_probe(struct spi_device *spi) ...@@ -90,13 +87,13 @@ static int __devinit ad7887_probe(struct spi_device *spi)
{ {
struct ad7887_platform_data *pdata = spi->dev.platform_data; struct ad7887_platform_data *pdata = spi->dev.platform_data;
struct ad7887_state *st; struct ad7887_state *st;
int ret, voltage_uv = 0; int ret, voltage_uv = 0, regdone = 0;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
st = kzalloc(sizeof(*st), GFP_KERNEL); if (indio_dev == NULL)
if (st == NULL) { return -ENOMEM;
ret = -ENOMEM;
goto error_ret; st = iio_priv(indio_dev);
}
st->reg = regulator_get(&spi->dev, "vcc"); st->reg = regulator_get(&spi->dev, "vcc");
if (!IS_ERR(st->reg)) { if (!IS_ERR(st->reg)) {
...@@ -110,26 +107,16 @@ static int __devinit ad7887_probe(struct spi_device *spi) ...@@ -110,26 +107,16 @@ static int __devinit ad7887_probe(struct spi_device *spi)
st->chip_info = st->chip_info =
&ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data]; &ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data];
spi_set_drvdata(spi, st); spi_set_drvdata(spi, indio_dev);
st->spi = spi; st->spi = spi;
st->indio_dev = iio_allocate_device(0);
if (st->indio_dev == NULL) {
ret = -ENOMEM;
goto error_disable_reg;
}
/* Estabilish that the iio_dev is a child of the spi device */ /* Estabilish that the iio_dev is a child of the spi device */
st->indio_dev->dev.parent = &spi->dev; indio_dev->dev.parent = &spi->dev;
st->indio_dev->name = spi_get_device_id(spi)->name; indio_dev->name = spi_get_device_id(spi)->name;
st->indio_dev->dev_data = (void *)(st); indio_dev->dev_data = (void *)(st);
st->indio_dev->channels = st->chip_info->channel; indio_dev->read_raw = &ad7887_read_raw;
st->indio_dev->num_channels = 3; indio_dev->driver_module = THIS_MODULE;
st->indio_dev->read_raw = &ad7887_read_raw; indio_dev->modes = INDIO_DIRECT_MODE;
st->indio_dev->driver_module = THIS_MODULE;
st->indio_dev->modes = INDIO_DIRECT_MODE;
/* Setup default message */ /* Setup default message */
...@@ -180,8 +167,8 @@ static int __devinit ad7887_probe(struct spi_device *spi) ...@@ -180,8 +167,8 @@ static int __devinit ad7887_probe(struct spi_device *spi)
else else
dev_warn(&spi->dev, "reference voltage unspecified\n"); dev_warn(&spi->dev, "reference voltage unspecified\n");
st->indio_dev->channels = st->chip_info->channel; indio_dev->channels = st->chip_info->channel;
st->indio_dev->num_channels = 3; indio_dev->num_channels = 3;
} else { } else {
if (pdata && pdata->vref_mv) if (pdata && pdata->vref_mv)
st->int_vref_mv = pdata->vref_mv; st->int_vref_mv = pdata->vref_mv;
...@@ -190,53 +177,55 @@ static int __devinit ad7887_probe(struct spi_device *spi) ...@@ -190,53 +177,55 @@ static int __devinit ad7887_probe(struct spi_device *spi)
else else
dev_warn(&spi->dev, "reference voltage unspecified\n"); dev_warn(&spi->dev, "reference voltage unspecified\n");
st->indio_dev->channels = &st->chip_info->channel[1]; indio_dev->channels = &st->chip_info->channel[1];
st->indio_dev->num_channels = 2; indio_dev->num_channels = 2;
} }
ret = ad7887_register_ring_funcs_and_init(st->indio_dev); ret = ad7887_register_ring_funcs_and_init(indio_dev);
if (ret) if (ret)
goto error_free_device; goto error_disable_reg;
ret = iio_device_register(st->indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_free_device; goto error_disable_reg;
regdone = 1;
ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0, ret = iio_ring_buffer_register_ex(indio_dev->ring, 0,
st->indio_dev->channels, indio_dev->channels,
st->indio_dev->num_channels); indio_dev->num_channels);
if (ret) if (ret)
goto error_cleanup_ring; goto error_cleanup_ring;
return 0; return 0;
error_cleanup_ring: error_cleanup_ring:
ad7887_ring_cleanup(st->indio_dev); ad7887_ring_cleanup(indio_dev);
iio_device_unregister(st->indio_dev);
error_free_device:
iio_free_device(st->indio_dev);
error_disable_reg: error_disable_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_disable(st->reg); regulator_disable(st->reg);
error_put_reg: error_put_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
kfree(st); if (regdone)
error_ret: iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
return ret; return ret;
} }
static int ad7887_remove(struct spi_device *spi) static int ad7887_remove(struct spi_device *spi)
{ {
struct ad7887_state *st = spi_get_drvdata(spi); struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct iio_dev *indio_dev = st->indio_dev; struct ad7887_state *st = iio_priv(indio_dev);
iio_ring_buffer_unregister(indio_dev->ring); iio_ring_buffer_unregister(indio_dev->ring);
ad7887_ring_cleanup(indio_dev); ad7887_ring_cleanup(indio_dev);
iio_device_unregister(indio_dev);
if (!IS_ERR(st->reg)) { if (!IS_ERR(st->reg)) {
regulator_disable(st->reg); regulator_disable(st->reg);
regulator_put(st->reg); regulator_put(st->reg);
} }
kfree(st); iio_device_unregister(indio_dev);
return 0; return 0;
} }
......
...@@ -8,13 +8,10 @@ ...@@ -8,13 +8,10 @@
*/ */
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/workqueue.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/list.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include "../iio.h" #include "../iio.h"
...@@ -27,7 +24,7 @@ ...@@ -27,7 +24,7 @@
int ad7887_scan_from_ring(struct ad7887_state *st, long mask) int ad7887_scan_from_ring(struct ad7887_state *st, long mask)
{ {
struct iio_ring_buffer *ring = st->indio_dev->ring; struct iio_ring_buffer *ring = iio_priv_to_dev(st)->ring;
int count = 0, ret; int count = 0, ret;
u16 *ring_data; u16 *ring_data;
......
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