Commit 8b7163a5 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:ad9834: allocate chip state with iio_dev and use iio_priv to access.

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 39f3b32e
...@@ -66,7 +66,7 @@ static ssize_t ad9834_write(struct device *dev, ...@@ -66,7 +66,7 @@ static ssize_t ad9834_write(struct device *dev,
size_t len) size_t len)
{ {
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad9834_state *st = dev_info->dev_data; struct ad9834_state *st = iio_priv(dev_info);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int ret; int ret;
long val; long val;
...@@ -145,7 +145,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev, ...@@ -145,7 +145,7 @@ static ssize_t ad9834_store_wavetype(struct device *dev,
size_t len) size_t len)
{ {
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad9834_state *st = dev_info->dev_data; struct ad9834_state *st = iio_priv(dev_info);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
int ret = 0; int ret = 0;
bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837); bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837);
...@@ -203,7 +203,7 @@ static ssize_t ad9834_show_out0_wavetype_available(struct device *dev, ...@@ -203,7 +203,7 @@ static ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad9834_state *st = iio_dev_get_devdata(dev_info); struct ad9834_state *st = iio_priv(dev_info);
char *str; char *str;
if ((st->devid == ID_AD9833) || (st->devid == ID_AD9837)) if ((st->devid == ID_AD9833) || (st->devid == ID_AD9837))
...@@ -225,7 +225,7 @@ static ssize_t ad9834_show_out1_wavetype_available(struct device *dev, ...@@ -225,7 +225,7 @@ static ssize_t ad9834_show_out1_wavetype_available(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad9834_state *st = iio_dev_get_devdata(dev_info); struct ad9834_state *st = iio_priv(dev_info);
char *str; char *str;
if (st->control & AD9834_MODE) if (st->control & AD9834_MODE)
...@@ -285,7 +285,7 @@ static mode_t ad9834_attr_is_visible(struct kobject *kobj, ...@@ -285,7 +285,7 @@ static mode_t ad9834_attr_is_visible(struct kobject *kobj,
{ {
struct device *dev = container_of(kobj, struct device, kobj); struct device *dev = container_of(kobj, struct device, kobj);
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad9834_state *st = iio_dev_get_devdata(dev_info); struct ad9834_state *st = iio_priv(dev_info);
mode_t mode = attr->mode; mode_t mode = attr->mode;
...@@ -314,6 +314,8 @@ static int __devinit ad9834_probe(struct spi_device *spi) ...@@ -314,6 +314,8 @@ static int __devinit ad9834_probe(struct spi_device *spi)
{ {
struct ad9834_platform_data *pdata = spi->dev.platform_data; struct ad9834_platform_data *pdata = spi->dev.platform_data;
struct ad9834_state *st; struct ad9834_state *st;
struct iio_dev *indio_dev;
struct regulator *reg;
int ret; int ret;
if (!pdata) { if (!pdata) {
...@@ -321,37 +323,28 @@ static int __devinit ad9834_probe(struct spi_device *spi) ...@@ -321,37 +323,28 @@ static int __devinit ad9834_probe(struct spi_device *spi)
return -ENODEV; return -ENODEV;
} }
st = kzalloc(sizeof(*st), GFP_KERNEL); reg = regulator_get(&spi->dev, "vcc");
if (st == NULL) { if (!IS_ERR(reg)) {
ret = -ENOMEM; ret = regulator_enable(reg);
goto error_ret;
}
st->reg = regulator_get(&spi->dev, "vcc");
if (!IS_ERR(st->reg)) {
ret = regulator_enable(st->reg);
if (ret) if (ret)
goto error_put_reg; goto error_put_reg;
} }
st->mclk = pdata->mclk; indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) {
spi_set_drvdata(spi, st);
st->spi = spi;
st->devid = spi_get_device_id(spi)->driver_data;
st->indio_dev = iio_allocate_device(0);
if (st->indio_dev == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_disable_reg; goto error_disable_reg;
} }
spi_set_drvdata(spi, indio_dev);
st->indio_dev->dev.parent = &spi->dev; st = iio_priv(indio_dev);
st->indio_dev->name = spi_get_device_id(spi)->name; st->mclk = pdata->mclk;
st->indio_dev->info = &ad9834_info; st->spi = spi;
st->indio_dev->dev_data = (void *) st; st->devid = spi_get_device_id(spi)->driver_data;
st->indio_dev->modes = INDIO_DIRECT_MODE; st->reg = reg;
indio_dev->dev.parent = &spi->dev;
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->info = &ad9834_info;
indio_dev->modes = INDIO_DIRECT_MODE;
/* Setup default messages */ /* Setup default messages */
...@@ -402,35 +395,35 @@ static int __devinit ad9834_probe(struct spi_device *spi) ...@@ -402,35 +395,35 @@ static int __devinit ad9834_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_device; goto error_free_device;
ret = iio_device_register(st->indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_free_device; goto error_free_device;
return 0; return 0;
error_free_device: error_free_device:
iio_free_device(st->indio_dev); iio_free_device(indio_dev);
error_disable_reg: error_disable_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(reg))
regulator_disable(st->reg); regulator_disable(reg);
error_put_reg: error_put_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(reg))
regulator_put(st->reg); regulator_put(reg);
kfree(st);
error_ret:
return ret; return ret;
} }
static int __devexit ad9834_remove(struct spi_device *spi) static int __devexit ad9834_remove(struct spi_device *spi)
{ {
struct ad9834_state *st = spi_get_drvdata(spi); struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct ad9834_state *st = iio_priv(indio_dev);
iio_device_unregister(st->indio_dev); struct regulator *reg = st->reg;
if (!IS_ERR(st->reg)) {
regulator_disable(st->reg); iio_device_unregister(indio_dev);
regulator_put(st->reg); if (!IS_ERR(reg)) {
regulator_disable(reg);
regulator_put(reg);
} }
kfree(st);
return 0; return 0;
} }
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
/** /**
* struct ad9834_state - driver instance specific data * struct ad9834_state - driver instance specific data
* @indio_dev: the industrial I/O device
* @spi: spi_device * @spi: spi_device
* @reg: supply regulator * @reg: supply regulator
* @mclk: external master clock * @mclk: external master clock
...@@ -52,7 +51,6 @@ ...@@ -52,7 +51,6 @@
*/ */
struct ad9834_state { struct ad9834_state {
struct iio_dev *indio_dev;
struct spi_device *spi; struct spi_device *spi;
struct regulator *reg; struct regulator *reg;
unsigned int mclk; unsigned int mclk;
......
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