diff options
author | Jonathan Cameron <jic23@cam.ac.uk> | 2011-06-27 12:07:13 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-06-28 21:39:35 (GMT) |
commit | 35212dfa6b13ab9a53f919d9ef22dd6ed363d485 (patch) | |
tree | a11ccbfcbff7ab62c66b66a9ea9a2e00f563848b /drivers/staging/iio/accel/adis16209_core.c | |
parent | 4de66bbb3eb1099a76e1bbf87e376c7a31dc30d5 (diff) | |
download | linux-35212dfa6b13ab9a53f919d9ef22dd6ed363d485.tar.xz |
staging:iio:accel:adis16209 allocate tx and rx in state plus state via iio_priv
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/iio/accel/adis16209_core.c')
-rw-r--r-- | drivers/staging/iio/accel/adis16209_core.c | 82 |
1 files changed, 29 insertions, 53 deletions
diff --git a/drivers/staging/iio/accel/adis16209_core.c b/drivers/staging/iio/accel/adis16209_core.c index c423cc9..55f3a7b 100644 --- a/drivers/staging/iio/accel/adis16209_core.c +++ b/drivers/staging/iio/accel/adis16209_core.c @@ -37,7 +37,7 @@ static int adis16209_spi_write_reg_8(struct iio_dev *indio_dev, u8 val) { int ret; - struct adis16209_state *st = iio_dev_get_devdata(indio_dev); + struct adis16209_state *st = iio_priv(indio_dev); mutex_lock(&st->buf_lock); st->tx[0] = ADIS16209_WRITE_REG(reg_address); @@ -62,7 +62,7 @@ static int adis16209_spi_write_reg_16(struct iio_dev *indio_dev, { int ret; struct spi_message msg; - struct adis16209_state *st = iio_dev_get_devdata(indio_dev); + struct adis16209_state *st = iio_priv(indio_dev); struct spi_transfer xfers[] = { { .tx_buf = st->tx, @@ -105,7 +105,7 @@ static int adis16209_spi_read_reg_16(struct iio_dev *indio_dev, u16 *val) { struct spi_message msg; - struct adis16209_state *st = iio_dev_get_devdata(indio_dev); + struct adis16209_state *st = iio_priv(indio_dev); int ret; struct spi_transfer xfers[] = { { @@ -466,52 +466,38 @@ static const struct iio_info adis16209_info = { static int __devinit adis16209_probe(struct spi_device *spi) { int ret, regdone = 0; - struct adis16209_state *st = kzalloc(sizeof *st, GFP_KERNEL); - if (!st) { - ret = -ENOMEM; - goto error_ret; - } - /* this is only used for removal purposes */ - spi_set_drvdata(spi, st); + struct adis16209_state *st; + struct iio_dev *indio_dev; - /* Allocate the comms buffers */ - st->rx = kzalloc(sizeof(*st->rx)*ADIS16209_MAX_RX, GFP_KERNEL); - if (st->rx == NULL) { - ret = -ENOMEM; - goto error_free_st; - } - st->tx = kzalloc(sizeof(*st->tx)*ADIS16209_MAX_TX, GFP_KERNEL); - if (st->tx == NULL) { + /* setup the industrialio driver allocated elements */ + indio_dev = iio_allocate_device(sizeof(*st)); + if (indio_dev == NULL) { ret = -ENOMEM; - goto error_free_rx; + goto error_ret; } + st = iio_priv(indio_dev); + /* this is only used for removal purposes */ + spi_set_drvdata(spi, indio_dev); st->us = spi; 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_tx; - } - st->indio_dev->name = spi->dev.driver->name; - st->indio_dev->dev.parent = &spi->dev; - st->indio_dev->info = &adis16209_info; - st->indio_dev->channels = adis16209_channels; - st->indio_dev->num_channels = ARRAY_SIZE(adis16209_channels); - st->indio_dev->dev_data = (void *)(st); - st->indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->name = spi->dev.driver->name; + indio_dev->dev.parent = &spi->dev; + indio_dev->info = &adis16209_info; + indio_dev->channels = adis16209_channels; + indio_dev->num_channels = ARRAY_SIZE(adis16209_channels); + indio_dev->modes = INDIO_DIRECT_MODE; - ret = adis16209_configure_ring(st->indio_dev); + ret = adis16209_configure_ring(indio_dev); if (ret) goto error_free_dev; - ret = iio_device_register(st->indio_dev); + ret = iio_device_register(indio_dev); if (ret) goto error_unreg_ring_funcs; regdone = 1; - ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0, + ret = iio_ring_buffer_register_ex(indio_dev->ring, 0, adis16209_channels, ARRAY_SIZE(adis16209_channels)); if (ret) { @@ -520,42 +506,35 @@ static int __devinit adis16209_probe(struct spi_device *spi) } if (spi->irq) { - ret = adis16209_probe_trigger(st->indio_dev); + ret = adis16209_probe_trigger(indio_dev); if (ret) goto error_uninitialize_ring; } /* Get the device into a sane initial state */ - ret = adis16209_initial_setup(st->indio_dev); + ret = adis16209_initial_setup(indio_dev); if (ret) goto error_remove_trigger; return 0; error_remove_trigger: - adis16209_remove_trigger(st->indio_dev); + adis16209_remove_trigger(indio_dev); error_uninitialize_ring: - iio_ring_buffer_unregister(st->indio_dev->ring); + iio_ring_buffer_unregister(indio_dev->ring); error_unreg_ring_funcs: - adis16209_unconfigure_ring(st->indio_dev); + adis16209_unconfigure_ring(indio_dev); error_free_dev: if (regdone) - iio_device_unregister(st->indio_dev); + iio_device_unregister(indio_dev); else - iio_free_device(st->indio_dev); -error_free_tx: - kfree(st->tx); -error_free_rx: - kfree(st->rx); -error_free_st: - kfree(st); + iio_free_device(indio_dev); error_ret: return ret; } static int adis16209_remove(struct spi_device *spi) { - struct adis16209_state *st = spi_get_drvdata(spi); - struct iio_dev *indio_dev = st->indio_dev; + struct iio_dev *indio_dev = spi_get_drvdata(spi); flush_scheduled_work(); @@ -563,9 +542,6 @@ static int adis16209_remove(struct spi_device *spi) iio_ring_buffer_unregister(indio_dev->ring); iio_device_unregister(indio_dev); adis16209_unconfigure_ring(indio_dev); - kfree(st->tx); - kfree(st->rx); - kfree(st); return 0; } |