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

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

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 d088ab83
...@@ -42,17 +42,16 @@ ...@@ -42,17 +42,16 @@
/** /**
* struct adxrs450_state - device instance specific data * struct adxrs450_state - device instance specific data
* @us: actual spi_device * @us: actual spi_device
* @indio_dev: industrial I/O device structure * @buf_lock: mutex to protect tx and rx
* @tx: transmit buffer * @tx: transmit buffer
* @rx: recieve buffer * @rx: recieve buffer
* @buf_lock: mutex to protect tx and rx
**/ **/
struct adxrs450_state { struct adxrs450_state {
struct spi_device *us; struct spi_device *us;
struct iio_dev *indio_dev; struct mutex buf_lock;
u8 *tx; u8 tx[ADXRS450_MAX_RX] ____cacheline_aligned;
u8 *rx; u8 rx[ADXRS450_MAX_TX];
struct mutex buf_lock;
}; };
#endif /* SPI_ADXRS450_H_ */ #endif /* SPI_ADXRS450_H_ */
...@@ -38,7 +38,7 @@ static int adxrs450_spi_read_reg_16(struct device *dev, ...@@ -38,7 +38,7 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
{ {
struct spi_message msg; struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adxrs450_state *st = iio_dev_get_devdata(indio_dev); struct adxrs450_state *st = iio_priv(indio_dev);
int ret; int ret;
struct spi_transfer xfers[] = { struct spi_transfer xfers[] = {
{ {
...@@ -92,7 +92,7 @@ static int adxrs450_spi_write_reg_16(struct device *dev, ...@@ -92,7 +92,7 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
{ {
struct spi_message msg; struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adxrs450_state *st = iio_dev_get_devdata(indio_dev); struct adxrs450_state *st = iio_priv(indio_dev);
int ret; int ret;
struct spi_transfer xfers = { struct spi_transfer xfers = {
.tx_buf = st->tx, .tx_buf = st->tx,
...@@ -130,7 +130,7 @@ static int adxrs450_spi_sensor_data(struct device *dev, s16 *val) ...@@ -130,7 +130,7 @@ static int adxrs450_spi_sensor_data(struct device *dev, s16 *val)
{ {
struct spi_message msg; struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adxrs450_state *st = iio_dev_get_devdata(indio_dev); struct adxrs450_state *st = iio_priv(indio_dev);
int ret; int ret;
struct spi_transfer xfers[] = { struct spi_transfer xfers[] = {
{ {
...@@ -267,12 +267,13 @@ static ssize_t adxrs450_read_sensor_data(struct device *dev, ...@@ -267,12 +267,13 @@ static ssize_t adxrs450_read_sensor_data(struct device *dev,
} }
/* Recommended Startup Sequence by spec */ /* Recommended Startup Sequence by spec */
static int adxrs450_initial_setup(struct adxrs450_state *st) static int adxrs450_initial_setup(struct iio_dev *indio_dev)
{ {
u32 t; u32 t;
u16 data; u16 data;
int ret; int ret;
struct device *dev = &st->indio_dev->dev; struct device *dev = &indio_dev->dev;
struct adxrs450_state *st = iio_priv(indio_dev);
msleep(ADXRS450_STARTUP_DELAY*2); msleep(ADXRS450_STARTUP_DELAY*2);
ret = adxrs450_spi_initial(st, &t, 1); ret = adxrs450_spi_initial(st, &t, 1);
...@@ -357,46 +358,32 @@ static const struct iio_info adxrs450_info = { ...@@ -357,46 +358,32 @@ static const struct iio_info adxrs450_info = {
static int __devinit adxrs450_probe(struct spi_device *spi) static int __devinit adxrs450_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret, regdone = 0;
struct adxrs450_state *st = kzalloc(sizeof *st, GFP_KERNEL); struct adxrs450_state *st;
if (!st) { struct iio_dev *indio_dev;
ret = -ENOMEM;
goto error_ret;
}
/* This is only used for removal purposes */
spi_set_drvdata(spi, st);
/* Allocate the comms buffers */ /* setup the industrialio driver allocated elements */
st->rx = kzalloc(sizeof(*st->rx)*ADXRS450_MAX_RX, GFP_KERNEL); indio_dev = iio_allocate_device(sizeof(*st));
if (st->rx == NULL) { if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_free_st;
}
st->tx = kzalloc(sizeof(*st->tx)*ADXRS450_MAX_TX, GFP_KERNEL);
if (st->tx == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_free_rx; goto error_ret;
} }
st = iio_priv(indio_dev);
st->us = spi; st->us = spi;
mutex_init(&st->buf_lock); mutex_init(&st->buf_lock);
/* setup the industrialio driver allocated elements */ /* This is only used for removal purposes */
st->indio_dev = iio_allocate_device(0); spi_set_drvdata(spi, indio_dev);
if (st->indio_dev == NULL) {
ret = -ENOMEM;
goto error_free_tx;
}
st->indio_dev->dev.parent = &spi->dev; indio_dev->dev.parent = &spi->dev;
st->indio_dev->info = &adxrs450_info; indio_dev->info = &adxrs450_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;
/* Get the device into a sane initial state */ /* Get the device into a sane initial state */
ret = adxrs450_initial_setup(st); ret = adxrs450_initial_setup(indio_dev);
if (ret) if (ret)
goto error_initial; goto error_initial;
return 0; return 0;
...@@ -404,27 +391,17 @@ static int __devinit adxrs450_probe(struct spi_device *spi) ...@@ -404,27 +391,17 @@ static int __devinit adxrs450_probe(struct spi_device *spi)
error_initial: error_initial:
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_tx:
kfree(st->tx);
error_free_rx:
kfree(st->rx);
error_free_st:
kfree(st);
error_ret: error_ret:
return ret; return ret;
} }
static int adxrs450_remove(struct spi_device *spi) static int adxrs450_remove(struct spi_device *spi)
{ {
struct adxrs450_state *st = spi_get_drvdata(spi); iio_device_unregister(spi_get_drvdata(spi));
iio_device_unregister(st->indio_dev);
kfree(st->tx);
kfree(st->rx);
kfree(st);
return 0; return 0;
} }
......
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