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

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

Use private data space from iio_allocate_device
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 5565a450
...@@ -36,7 +36,6 @@ struct ad7298_platform_data { ...@@ -36,7 +36,6 @@ struct ad7298_platform_data {
}; };
struct ad7298_state { struct ad7298_state {
struct iio_dev *indio_dev;
struct spi_device *spi; struct spi_device *spi;
struct regulator *reg; struct regulator *reg;
size_t d_size; size_t d_size;
...@@ -55,11 +54,11 @@ struct ad7298_state { ...@@ -55,11 +54,11 @@ struct ad7298_state {
}; };
#ifdef CONFIG_IIO_RING_BUFFER #ifdef CONFIG_IIO_RING_BUFFER
int ad7298_scan_from_ring(struct ad7298_state *st, long ch); int ad7298_scan_from_ring(struct iio_dev *indio_dev, long ch);
int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev); int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev);
void ad7298_ring_cleanup(struct iio_dev *indio_dev); void ad7298_ring_cleanup(struct iio_dev *indio_dev);
#else /* CONFIG_IIO_RING_BUFFER */ #else /* CONFIG_IIO_RING_BUFFER */
static inline int ad7298_scan_from_ring(struct ad7298_state *st, long ch) static inline int ad7298_scan_from_ring(struct iio_dev *indio_dev, long ch)
{ {
return 0; return 0;
} }
......
...@@ -116,7 +116,7 @@ static int ad7298_read_raw(struct iio_dev *dev_info, ...@@ -116,7 +116,7 @@ static int ad7298_read_raw(struct iio_dev *dev_info,
long m) long m)
{ {
int ret; int ret;
struct ad7298_state *st = dev_info->dev_data; struct ad7298_state *st = iio_priv(dev_info);
unsigned int scale_uv; unsigned int scale_uv;
switch (m) { switch (m) {
...@@ -126,7 +126,8 @@ static int ad7298_read_raw(struct iio_dev *dev_info, ...@@ -126,7 +126,8 @@ static int ad7298_read_raw(struct iio_dev *dev_info,
if (chan->address == AD7298_CH_TEMP) if (chan->address == AD7298_CH_TEMP)
ret = -ENODEV; ret = -ENODEV;
else else
ret = ad7298_scan_from_ring(st, chan->address); ret = ad7298_scan_from_ring(dev_info,
chan->address);
} else { } else {
if (chan->address == AD7298_CH_TEMP) if (chan->address == AD7298_CH_TEMP)
ret = ad7298_scan_temp(st, val); ret = ad7298_scan_temp(st, val);
...@@ -159,13 +160,13 @@ static int __devinit ad7298_probe(struct spi_device *spi) ...@@ -159,13 +160,13 @@ static int __devinit ad7298_probe(struct spi_device *spi)
{ {
struct ad7298_platform_data *pdata = spi->dev.platform_data; struct ad7298_platform_data *pdata = spi->dev.platform_data;
struct ad7298_state *st; struct ad7298_state *st;
int ret; int ret, 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)) {
...@@ -174,24 +175,17 @@ static int __devinit ad7298_probe(struct spi_device *spi) ...@@ -174,24 +175,17 @@ static int __devinit ad7298_probe(struct spi_device *spi)
goto error_put_reg; goto error_put_reg;
} }
spi_set_drvdata(spi, st); spi_set_drvdata(spi, indio_dev);
st->spi = spi; st->spi = spi;
st->indio_dev = iio_allocate_device(0); indio_dev->name = spi_get_device_id(spi)->name;
if (st->indio_dev == NULL) { indio_dev->dev.parent = &spi->dev;
ret = -ENOMEM; indio_dev->driver_module = THIS_MODULE;
goto error_disable_reg; indio_dev->modes = INDIO_DIRECT_MODE;
} indio_dev->channels = ad7298_channels;
indio_dev->num_channels = ARRAY_SIZE(ad7298_channels);
st->indio_dev->name = spi_get_device_id(spi)->name; indio_dev->read_raw = &ad7298_read_raw;
st->indio_dev->dev.parent = &spi->dev;
st->indio_dev->dev_data = (void *)(st);
st->indio_dev->driver_module = THIS_MODULE;
st->indio_dev->modes = INDIO_DIRECT_MODE;
st->indio_dev->channels = ad7298_channels;
st->indio_dev->num_channels = ARRAY_SIZE(ad7298_channels);
st->indio_dev->read_raw = &ad7298_read_raw;
/* Setup default message */ /* Setup default message */
...@@ -216,41 +210,44 @@ static int __devinit ad7298_probe(struct spi_device *spi) ...@@ -216,41 +210,44 @@ static int __devinit ad7298_probe(struct spi_device *spi)
st->int_vref_mv = AD7298_INTREF_mV; st->int_vref_mv = AD7298_INTREF_mV;
} }
ret = ad7298_register_ring_funcs_and_init(st->indio_dev); ret = ad7298_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,
&ad7298_channels[1], /* skip temp0 */ &ad7298_channels[1], /* skip temp0 */
ARRAY_SIZE(ad7298_channels) - 1); ARRAY_SIZE(ad7298_channels) - 1);
if (ret) if (ret)
goto error_cleanup_ring; goto error_cleanup_ring;
return 0; return 0;
error_cleanup_ring: error_cleanup_ring:
ad7298_ring_cleanup(st->indio_dev); ad7298_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);
error_ret: if (regdone)
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
return ret; return ret;
} }
static int __devexit ad7298_remove(struct spi_device *spi) static int __devexit ad7298_remove(struct spi_device *spi)
{ {
struct ad7298_state *st = spi_get_drvdata(spi); struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct iio_dev *indio_dev = st->indio_dev; struct ad7298_state *st = iio_priv(indio_dev);
iio_ring_buffer_unregister(indio_dev->ring); iio_ring_buffer_unregister(indio_dev->ring);
ad7298_ring_cleanup(indio_dev); ad7298_ring_cleanup(indio_dev);
...@@ -259,7 +256,8 @@ static int __devexit ad7298_remove(struct spi_device *spi) ...@@ -259,7 +256,8 @@ static int __devexit ad7298_remove(struct spi_device *spi)
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;
} }
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
#include "ad7298.h" #include "ad7298.h"
int ad7298_scan_from_ring(struct ad7298_state *st, long ch) int ad7298_scan_from_ring(struct iio_dev *dev_info, long ch)
{ {
struct iio_ring_buffer *ring = st->indio_dev->ring; struct iio_ring_buffer *ring = dev_info->ring;
int ret; int ret;
u16 *ring_data; u16 *ring_data;
...@@ -59,7 +59,7 @@ int ad7298_scan_from_ring(struct ad7298_state *st, long ch) ...@@ -59,7 +59,7 @@ int ad7298_scan_from_ring(struct ad7298_state *st, long ch)
**/ **/
static int ad7298_ring_preenable(struct iio_dev *indio_dev) static int ad7298_ring_preenable(struct iio_dev *indio_dev)
{ {
struct ad7298_state *st = indio_dev->dev_data; struct ad7298_state *st = iio_priv(indio_dev);
struct iio_ring_buffer *ring = indio_dev->ring; struct iio_ring_buffer *ring = indio_dev->ring;
size_t d_size; size_t d_size;
int i, m; int i, m;
...@@ -121,7 +121,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p) ...@@ -121,7 +121,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
{ {
struct iio_poll_func *pf = p; struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->private_data; struct iio_dev *indio_dev = pf->private_data;
struct ad7298_state *st = iio_dev_get_devdata(indio_dev); struct ad7298_state *st = iio_priv(indio_dev);
struct iio_ring_buffer *ring = indio_dev->ring; struct iio_ring_buffer *ring = indio_dev->ring;
s64 time_ns; s64 time_ns;
__u16 buf[16]; __u16 buf[16];
......
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