Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2829911 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman
Browse files

staging:iio:dds:ad9810: allocate chip state with iio_dev and use iio_priv for access.

parent 7be94372
Loading
Loading
Loading
Loading
+14 −24
Original line number Original line Diff line number Diff line
@@ -58,7 +58,6 @@ struct ad9852_config {


struct ad9852_state {
struct ad9852_state {
	struct mutex lock;
	struct mutex lock;
	struct iio_dev *idev;
	struct spi_device *sdev;
	struct spi_device *sdev;
};
};


@@ -72,7 +71,7 @@ static ssize_t ad9852_set_parameter(struct device *dev,
	int ret;
	int ret;
	struct ad9852_config *config = (struct ad9852_config *)buf;
	struct ad9852_config *config = (struct ad9852_config *)buf;
	struct iio_dev *idev = dev_get_drvdata(dev);
	struct iio_dev *idev = dev_get_drvdata(dev);
	struct ad9852_state *st = idev->dev_data;
	struct ad9852_state *st = iio_priv(idev);


	xfer.len = 3;
	xfer.len = 3;
	xfer.tx_buf = &config->phajst0[0];
	xfer.tx_buf = &config->phajst0[0];
@@ -230,30 +229,24 @@ static const struct iio_info ad9852_info = {
static int __devinit ad9852_probe(struct spi_device *spi)
static int __devinit ad9852_probe(struct spi_device *spi)
{
{
	struct ad9852_state *st;
	struct ad9852_state *st;
	struct iio_dev *idev;
	int ret = 0;
	int ret = 0;


	st = kzalloc(sizeof(*st), GFP_KERNEL);
	idev = iio_allocate_device(sizeof(*st));
	if (st == NULL) {
	if (idev == NULL) {
		ret = -ENOMEM;
		ret = -ENOMEM;
		goto error_ret;
		goto error_ret;
	}
	}
	spi_set_drvdata(spi, st);
	st = iio_priv(idev);

	spi_set_drvdata(spi, idev);
	mutex_init(&st->lock);
	mutex_init(&st->lock);
	st->sdev = spi;
	st->sdev = spi;


	st->idev = iio_allocate_device(0);
	idev->dev.parent = &spi->dev;
	if (st->idev == NULL) {
	idev->info = &ad9852_info;
		ret = -ENOMEM;
	idev->modes = INDIO_DIRECT_MODE;
		goto error_free_st;
	}
	st->idev->dev.parent = &spi->dev;


	st->idev->info = &ad9852_info;
	ret = iio_device_register(idev);
	st->idev->dev_data = (void *)(st);
	st->idev->modes = INDIO_DIRECT_MODE;

	ret = iio_device_register(st->idev);
	if (ret)
	if (ret)
		goto error_free_dev;
		goto error_free_dev;
	spi->max_speed_hz = 2000000;
	spi->max_speed_hz = 2000000;
@@ -261,22 +254,19 @@ static int __devinit ad9852_probe(struct spi_device *spi)
	spi->bits_per_word = 8;
	spi->bits_per_word = 8;
	spi_setup(spi);
	spi_setup(spi);
	ad9852_init(st);
	ad9852_init(st);

	return 0;
	return 0;


error_free_dev:
error_free_dev:
	iio_free_device(st->idev);
	iio_free_device(idev);
error_free_st:

	kfree(st);
error_ret:
error_ret:
	return ret;
	return ret;
}
}


static int __devexit ad9852_remove(struct spi_device *spi)
static int __devexit ad9852_remove(struct spi_device *spi)
{
{
	struct ad9852_state *st = spi_get_drvdata(spi);
	iio_device_unregister(spi_get_drvdata(spi));

	iio_device_unregister(st->idev);
	kfree(st);


	return 0;
	return 0;
}
}