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

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

staging:iio:gyro:adis16080: allocate chip state with iio_dev

parent 3a5952f9
Loading
Loading
Loading
Loading
+19 −29
Original line number Original line Diff line number Diff line
@@ -34,13 +34,11 @@
/**
/**
 * struct adis16080_state - device instance specific data
 * struct adis16080_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
 * @buf:		transmit or receive buffer
 * @buf:		transmit or receive buffer
 * @buf_lock:		mutex to protect tx and rx
 * @buf_lock:		mutex to protect tx and rx
 **/
 **/
struct adis16080_state {
struct adis16080_state {
	struct spi_device		*us;
	struct spi_device		*us;
	struct iio_dev			*indio_dev;
	struct mutex			buf_lock;
	struct mutex			buf_lock;


	u8 buf[2] ____cacheline_aligned;
	u8 buf[2] ____cacheline_aligned;
@@ -51,7 +49,7 @@ static int adis16080_spi_write(struct device *dev,
{
{
	int ret;
	int ret;
	struct iio_dev *indio_dev = dev_get_drvdata(dev);
	struct iio_dev *indio_dev = dev_get_drvdata(dev);
	struct adis16080_state *st = iio_dev_get_devdata(indio_dev);
	struct adis16080_state *st = iio_priv(indio_dev);


	mutex_lock(&st->buf_lock);
	mutex_lock(&st->buf_lock);
	st->buf[0] = val >> 8;
	st->buf[0] = val >> 8;
@@ -68,7 +66,7 @@ static int adis16080_spi_read(struct device *dev,
{
{
	int ret;
	int ret;
	struct iio_dev *indio_dev = dev_get_drvdata(dev);
	struct iio_dev *indio_dev = dev_get_drvdata(dev);
	struct adis16080_state *st = iio_dev_get_devdata(indio_dev);
	struct adis16080_state *st = iio_priv(indio_dev);


	mutex_lock(&st->buf_lock);
	mutex_lock(&st->buf_lock);


@@ -131,31 +129,29 @@ static const struct iio_info adis16080_info = {
static int __devinit adis16080_probe(struct spi_device *spi)
static int __devinit adis16080_probe(struct spi_device *spi)
{
{
	int ret, regdone = 0;
	int ret, regdone = 0;
	struct adis16080_state *st = kzalloc(sizeof *st, GFP_KERNEL);
	struct adis16080_state *st;
	if (!st) {
	struct iio_dev *indio_dev;

	/* setup the industrialio driver allocated elements */
	indio_dev = iio_allocate_device(sizeof(*st));
	if (indio_dev == NULL) {
		ret = -ENOMEM;
		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);


	/* Allocate the comms buffers */
	/* Allocate the comms buffers */
	st->us = spi;
	st->us = spi;
	mutex_init(&st->buf_lock);
	mutex_init(&st->buf_lock);
	/* setup the industrialio driver allocated elements */
	st->indio_dev = iio_allocate_device(0);
	if (st->indio_dev == NULL) {
		ret = -ENOMEM;
		goto error_free_st;
	}


	st->indio_dev->name = spi->dev.driver->name;
	indio_dev->name = spi->dev.driver->name;
	st->indio_dev->dev.parent = &spi->dev;
	indio_dev->dev.parent = &spi->dev;
	st->indio_dev->info = &adis16080_info;
	indio_dev->info = &adis16080_info;
	st->indio_dev->dev_data = (void *)(st);
	indio_dev->modes = INDIO_DIRECT_MODE;
	st->indio_dev->modes = INDIO_DIRECT_MODE;


	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;
	regdone = 1;
	regdone = 1;
@@ -164,11 +160,9 @@ static int __devinit adis16080_probe(struct spi_device *spi)


error_free_dev:
error_free_dev:
	if (regdone)
	if (regdone)
		iio_device_unregister(st->indio_dev);
		iio_device_unregister(indio_dev);
	else
	else
		iio_free_device(st->indio_dev);
		iio_free_device(indio_dev);
error_free_st:
	kfree(st);
error_ret:
error_ret:
	return ret;
	return ret;
}
}
@@ -176,11 +170,7 @@ static int __devinit adis16080_probe(struct spi_device *spi)
/* fixme, confirm ordering in this function */
/* fixme, confirm ordering in this function */
static int adis16080_remove(struct spi_device *spi)
static int adis16080_remove(struct spi_device *spi)
{
{
	struct adis16080_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;
}
}