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

staging:iio:imu:adis16400 avoid allocating rx, tx, and state separately from iio_dev.

Uses the iio_allocate_device parameter to set aside space for adis16400_state and
____cacheline_aligned buffers for tx and rx to avoid separatel allocating them.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 59c85e82
...@@ -141,7 +141,6 @@ struct adis16400_chip_info { ...@@ -141,7 +141,6 @@ struct adis16400_chip_info {
/** /**
* struct adis16400_state - device instance specific data * struct adis16400_state - device instance specific data
* @us: actual spi_device * @us: actual spi_device
* @indio_dev: industrial I/O device structure
* @trig: data ready trigger registered with iio * @trig: data ready trigger registered with iio
* @tx: transmit buffer * @tx: transmit buffer
* @rx: receive buffer * @rx: receive buffer
...@@ -149,12 +148,12 @@ struct adis16400_chip_info { ...@@ -149,12 +148,12 @@ struct adis16400_chip_info {
**/ **/
struct adis16400_state { struct adis16400_state {
struct spi_device *us; struct spi_device *us;
struct iio_dev *indio_dev;
struct iio_trigger *trig; struct iio_trigger *trig;
u8 *tx;
u8 *rx;
struct mutex buf_lock; struct mutex buf_lock;
struct adis16400_chip_info *variant; struct adis16400_chip_info *variant;
u8 tx[ADIS16400_MAX_TX] ____cacheline_aligned;
u8 rx[ADIS16400_MAX_RX] ____cacheline_aligned;
}; };
int adis16400_set_irq(struct iio_dev *indio_dev, bool enable); int adis16400_set_irq(struct iio_dev *indio_dev, bool enable);
......
...@@ -66,7 +66,7 @@ static int adis16400_spi_write_reg_8(struct iio_dev *indio_dev, ...@@ -66,7 +66,7 @@ static int adis16400_spi_write_reg_8(struct iio_dev *indio_dev,
u8 val) u8 val)
{ {
int ret; int ret;
struct adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
st->tx[0] = ADIS16400_WRITE_REG(reg_address); st->tx[0] = ADIS16400_WRITE_REG(reg_address);
...@@ -91,7 +91,7 @@ static int adis16400_spi_write_reg_16(struct iio_dev *indio_dev, ...@@ -91,7 +91,7 @@ static int adis16400_spi_write_reg_16(struct iio_dev *indio_dev,
{ {
int ret; int ret;
struct spi_message msg; struct spi_message msg;
struct adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
struct spi_transfer xfers[] = { struct spi_transfer xfers[] = {
{ {
.tx_buf = st->tx, .tx_buf = st->tx,
...@@ -132,7 +132,7 @@ static int adis16400_spi_read_reg_16(struct iio_dev *indio_dev, ...@@ -132,7 +132,7 @@ static int adis16400_spi_read_reg_16(struct iio_dev *indio_dev,
u16 *val) u16 *val)
{ {
struct spi_message msg; struct spi_message msg;
struct adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
int ret; int ret;
struct spi_transfer xfers[] = { struct spi_transfer xfers[] = {
{ {
...@@ -195,7 +195,7 @@ static ssize_t adis16400_write_frequency(struct device *dev, ...@@ -195,7 +195,7 @@ static ssize_t adis16400_write_frequency(struct device *dev,
size_t len) size_t len)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
long val; long val;
int ret; int ret;
u8 t; u8 t;
...@@ -356,11 +356,12 @@ static int adis16400_check_status(struct iio_dev *indio_dev) ...@@ -356,11 +356,12 @@ static int adis16400_check_status(struct iio_dev *indio_dev)
return ret; return ret;
} }
static int adis16400_initial_setup(struct adis16400_state *st) static int adis16400_initial_setup(struct iio_dev *indio_dev)
{ {
int ret; int ret;
u16 prod_id, smp_prd; u16 prod_id, smp_prd;
struct device *dev = &st->indio_dev->dev; struct device *dev = &indio_dev->dev;
struct adis16400_state *st = iio_priv(indio_dev);
/* use low spi speed for init */ /* use low spi speed for init */
st->us->max_speed_hz = ADIS16400_SPI_SLOW; st->us->max_speed_hz = ADIS16400_SPI_SLOW;
...@@ -368,33 +369,33 @@ static int adis16400_initial_setup(struct adis16400_state *st) ...@@ -368,33 +369,33 @@ static int adis16400_initial_setup(struct adis16400_state *st)
spi_setup(st->us); spi_setup(st->us);
/* Disable IRQ */ /* Disable IRQ */
ret = adis16400_set_irq(st->indio_dev, false); ret = adis16400_set_irq(indio_dev, false);
if (ret) { if (ret) {
dev_err(dev, "disable irq failed"); dev_err(dev, "disable irq failed");
goto err_ret; goto err_ret;
} }
/* Do self test */ /* Do self test */
ret = adis16400_self_test(st->indio_dev); ret = adis16400_self_test(indio_dev);
if (ret) { if (ret) {
dev_err(dev, "self test failure"); dev_err(dev, "self test failure");
goto err_ret; goto err_ret;
} }
/* Read status register to check the result */ /* Read status register to check the result */
ret = adis16400_check_status(st->indio_dev); ret = adis16400_check_status(indio_dev);
if (ret) { if (ret) {
adis16400_reset(st->indio_dev); adis16400_reset(indio_dev);
dev_err(dev, "device not playing ball -> reset"); dev_err(dev, "device not playing ball -> reset");
msleep(ADIS16400_STARTUP_DELAY); msleep(ADIS16400_STARTUP_DELAY);
ret = adis16400_check_status(st->indio_dev); ret = adis16400_check_status(indio_dev);
if (ret) { if (ret) {
dev_err(dev, "giving up"); dev_err(dev, "giving up");
goto err_ret; goto err_ret;
} }
} }
if (st->variant->flags & ADIS16400_HAS_PROD_ID) { if (st->variant->flags & ADIS16400_HAS_PROD_ID) {
ret = adis16400_spi_read_reg_16(st->indio_dev, ret = adis16400_spi_read_reg_16(indio_dev,
ADIS16400_PRODUCT_ID, &prod_id); ADIS16400_PRODUCT_ID, &prod_id);
if (ret) if (ret)
goto err_ret; goto err_ret;
...@@ -406,7 +407,7 @@ static int adis16400_initial_setup(struct adis16400_state *st) ...@@ -406,7 +407,7 @@ static int adis16400_initial_setup(struct adis16400_state *st)
prod_id, st->us->chip_select, st->us->irq); prod_id, st->us->chip_select, st->us->irq);
} }
/* use high spi speed if possible */ /* use high spi speed if possible */
ret = adis16400_spi_read_reg_16(st->indio_dev, ret = adis16400_spi_read_reg_16(indio_dev,
ADIS16400_SMPL_PRD, &smp_prd); ADIS16400_SMPL_PRD, &smp_prd);
if (!ret && (smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) { if (!ret && (smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) {
st->us->max_speed_hz = ADIS16400_SPI_SLOW; st->us->max_speed_hz = ADIS16400_SPI_SLOW;
...@@ -487,7 +488,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev, ...@@ -487,7 +488,7 @@ static int adis16400_read_raw(struct iio_dev *indio_dev,
int *val2, int *val2,
long mask) long mask)
{ {
struct adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
int ret; int ret;
s16 val16; s16 val16;
int shift; int shift;
...@@ -774,55 +775,41 @@ static struct adis16400_chip_info adis16400_chips[] = { ...@@ -774,55 +775,41 @@ static struct adis16400_chip_info adis16400_chips[] = {
static int __devinit adis16400_probe(struct spi_device *spi) static int __devinit adis16400_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret, regdone = 0;
struct adis16400_state *st = kzalloc(sizeof *st, GFP_KERNEL); struct adis16400_state *st;
if (!st) { struct iio_dev *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 */
st->rx = kzalloc(sizeof(*st->rx)*ADIS16400_MAX_RX, GFP_KERNEL);
if (st->rx == NULL) {
ret = -ENOMEM;
goto error_free_st;
}
st->tx = kzalloc(sizeof(*st->tx)*ADIS16400_MAX_TX, GFP_KERNEL);
if (st->tx == NULL) {
ret = -ENOMEM;
goto error_free_rx;
}
st->us = spi; st->us = spi;
mutex_init(&st->buf_lock); mutex_init(&st->buf_lock);
/* setup the industrialio driver allocated elements */ /* 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->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data]; st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data];
st->indio_dev->dev.parent = &spi->dev; indio_dev->dev.parent = &spi->dev;
st->indio_dev->name = spi_get_device_id(spi)->name; indio_dev->name = spi_get_device_id(spi)->name;
st->indio_dev->attrs = &adis16400_attribute_group; indio_dev->attrs = &adis16400_attribute_group;
st->indio_dev->channels = st->variant->channels; indio_dev->channels = st->variant->channels;
st->indio_dev->num_channels = st->variant->num_channels; indio_dev->num_channels = st->variant->num_channels;
st->indio_dev->read_raw = &adis16400_read_raw; indio_dev->read_raw = &adis16400_read_raw;
st->indio_dev->write_raw = &adis16400_write_raw; indio_dev->write_raw = &adis16400_write_raw;
st->indio_dev->dev_data = (void *)(st); indio_dev->driver_module = THIS_MODULE;
st->indio_dev->driver_module = THIS_MODULE; indio_dev->modes = INDIO_DIRECT_MODE;
st->indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis16400_configure_ring(indio_dev);
ret = adis16400_configure_ring(st->indio_dev);
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(st->indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_unreg_ring_funcs; goto error_unreg_ring_funcs;
regdone = 1; regdone = 1;
ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0, ret = iio_ring_buffer_register_ex(indio_dev->ring, 0,
st->variant->channels, st->variant->channels,
st->variant->num_channels); st->variant->num_channels);
if (ret) { if (ret) {
...@@ -831,35 +818,29 @@ static int __devinit adis16400_probe(struct spi_device *spi) ...@@ -831,35 +818,29 @@ static int __devinit adis16400_probe(struct spi_device *spi)
} }
if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) { if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
ret = adis16400_probe_trigger(st->indio_dev); ret = adis16400_probe_trigger(indio_dev);
if (ret) if (ret)
goto error_uninitialize_ring; goto error_uninitialize_ring;
} }
/* Get the device into a sane initial state */ /* Get the device into a sane initial state */
ret = adis16400_initial_setup(st); ret = adis16400_initial_setup(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
if (st->indio_dev->modes & INDIO_RING_TRIGGERED) if (indio_dev->modes & INDIO_RING_TRIGGERED)
adis16400_remove_trigger(st->indio_dev); adis16400_remove_trigger(indio_dev);
error_uninitialize_ring: error_uninitialize_ring:
iio_ring_buffer_unregister(st->indio_dev->ring); iio_ring_buffer_unregister(indio_dev->ring);
error_unreg_ring_funcs: error_unreg_ring_funcs:
adis16400_unconfigure_ring(st->indio_dev); adis16400_unconfigure_ring(indio_dev);
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;
} }
...@@ -868,22 +849,17 @@ static int __devinit adis16400_probe(struct spi_device *spi) ...@@ -868,22 +849,17 @@ static int __devinit adis16400_probe(struct spi_device *spi)
static int adis16400_remove(struct spi_device *spi) static int adis16400_remove(struct spi_device *spi)
{ {
int ret; int ret;
struct adis16400_state *st = spi_get_drvdata(spi); struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct iio_dev *indio_dev = st->indio_dev;
ret = adis16400_stop_device(indio_dev); ret = adis16400_stop_device(indio_dev);
if (ret) if (ret)
goto err_ret; goto err_ret;
adis16400_remove_trigger(indio_dev); adis16400_remove_trigger(indio_dev);
iio_ring_buffer_unregister(st->indio_dev->ring); iio_ring_buffer_unregister(indio_dev->ring);
adis16400_unconfigure_ring(indio_dev); adis16400_unconfigure_ring(indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
kfree(st->tx);
kfree(st->rx);
kfree(st);
return 0; return 0;
err_ret: err_ret:
......
...@@ -27,7 +27,7 @@ static int adis16400_spi_read_burst(struct device *dev, u8 *rx) ...@@ -27,7 +27,7 @@ static int adis16400_spi_read_burst(struct device *dev, u8 *rx)
{ {
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 adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
u32 old_speed_hz = st->us->max_speed_hz; u32 old_speed_hz = st->us->max_speed_hz;
int ret; int ret;
...@@ -81,20 +81,19 @@ static const u16 read_all_tx_array[] = { ...@@ -81,20 +81,19 @@ static const u16 read_all_tx_array[] = {
static int adis16350_spi_read_all(struct device *dev, u8 *rx) static int adis16350_spi_read_all(struct device *dev, u8 *rx)
{ {
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
struct spi_message msg; struct spi_message msg;
int i, j = 0, ret; int i, j = 0, ret;
struct spi_transfer *xfers; struct spi_transfer *xfers;
xfers = kzalloc(sizeof(*xfers)* xfers = kzalloc(sizeof(*xfers)*indio_dev->ring->scan_count + 1,
st->indio_dev->ring->scan_count + 1,
GFP_KERNEL); GFP_KERNEL);
if (xfers == NULL) if (xfers == NULL)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < ARRAY_SIZE(read_all_tx_array); i++) for (i = 0; i < ARRAY_SIZE(read_all_tx_array); i++)
if (st->indio_dev->ring->scan_mask & (1 << i)) { if (indio_dev->ring->scan_mask & (1 << i)) {
xfers[j].tx_buf = &read_all_tx_array[i]; xfers[j].tx_buf = &read_all_tx_array[i];
xfers[j].bits_per_word = 16; xfers[j].bits_per_word = 16;
xfers[j].len = 2; xfers[j].len = 2;
...@@ -105,7 +104,7 @@ static int adis16350_spi_read_all(struct device *dev, u8 *rx) ...@@ -105,7 +104,7 @@ static int adis16350_spi_read_all(struct device *dev, u8 *rx)
xfers[j].len = 2; xfers[j].len = 2;
spi_message_init(&msg); spi_message_init(&msg);
for (j = 0; j < st->indio_dev->ring->scan_count + 1; j++) for (j = 0; j < indio_dev->ring->scan_count + 1; j++)
spi_message_add_tail(&xfers[j], &msg); spi_message_add_tail(&xfers[j], &msg);
ret = spi_sync(st->us, &msg); ret = spi_sync(st->us, &msg);
...@@ -121,7 +120,7 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p) ...@@ -121,7 +120,7 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
{ {
struct iio_poll_func *pf = p; struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->private_data; struct iio_dev *indio_dev = pf->private_data;
struct adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
struct iio_ring_buffer *ring = indio_dev->ring; struct iio_ring_buffer *ring = indio_dev->ring;
int i = 0, j, ret = 0; int i = 0, j, ret = 0;
s16 *data; s16 *data;
...@@ -174,7 +173,7 @@ void adis16400_unconfigure_ring(struct iio_dev *indio_dev) ...@@ -174,7 +173,7 @@ void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
int adis16400_configure_ring(struct iio_dev *indio_dev) int adis16400_configure_ring(struct iio_dev *indio_dev)
{ {
int ret = 0; int ret = 0;
struct adis16400_state *st = iio_dev_get_devdata(indio_dev); struct adis16400_state *st = iio_priv(indio_dev);
struct iio_ring_buffer *ring; struct iio_ring_buffer *ring;
ring = iio_sw_rb_allocate(indio_dev); ring = iio_sw_rb_allocate(indio_dev);
......
...@@ -18,17 +18,16 @@ ...@@ -18,17 +18,16 @@
static int adis16400_data_rdy_trigger_set_state(struct iio_trigger *trig, static int adis16400_data_rdy_trigger_set_state(struct iio_trigger *trig,
bool state) bool state)
{ {
struct adis16400_state *st = trig->private_data; struct iio_dev *indio_dev = trig->private_data;
struct iio_dev *indio_dev = st->indio_dev;
dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
return adis16400_set_irq(st->indio_dev, state); return adis16400_set_irq(indio_dev, state);
} }
int adis16400_probe_trigger(struct iio_dev *indio_dev) int adis16400_probe_trigger(struct iio_dev *indio_dev)
{ {
int ret; int ret;
struct adis16400_state *st = indio_dev->dev_data; struct adis16400_state *st = iio_priv(indio_dev);
st->trig = iio_allocate_trigger("%s-dev%d", st->trig = iio_allocate_trigger("%s-dev%d",
spi_get_device_id(st->us)->name, spi_get_device_id(st->us)->name,
...@@ -47,7 +46,7 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev) ...@@ -47,7 +46,7 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev)
goto error_free_trig; goto error_free_trig;
st->trig->dev.parent = &st->us->dev; st->trig->dev.parent = &st->us->dev;
st->trig->owner = THIS_MODULE; st->trig->owner = THIS_MODULE;
st->trig->private_data = st; st->trig->private_data = indio_dev;
st->trig->set_trigger_state = &adis16400_data_rdy_trigger_set_state; st->trig->set_trigger_state = &adis16400_data_rdy_trigger_set_state;
ret = iio_trigger_register(st->trig); ret = iio_trigger_register(st->trig);
...@@ -68,9 +67,9 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev) ...@@ -68,9 +67,9 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev)
void adis16400_remove_trigger(struct iio_dev *indio_dev) void adis16400_remove_trigger(struct iio_dev *indio_dev)
{ {
struct adis16400_state *state = indio_dev->dev_data; struct adis16400_state *st = iio_priv(indio_dev);
iio_trigger_unregister(state->trig); iio_trigger_unregister(st->trig);
free_irq(state->us->irq, state->trig); free_irq(st->us->irq, st->trig);
iio_free_trigger(state->trig); iio_free_trigger(st->trig);
} }
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