u8 val)
{
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);
st->tx[0] = ADIS16400_WRITE_REG(reg_address);
{
int ret;
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[] = {
{
.tx_buf = st->tx,
u16 *val)
{
struct spi_message msg;
- struct adis16400_state *st = iio_dev_get_devdata(indio_dev);
+ struct adis16400_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
size_t len)
{
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;
int ret;
u8 t;
return ret;
}
-static int adis16400_initial_setup(struct adis16400_state *st)
+static int adis16400_initial_setup(struct iio_dev *indio_dev)
{
int ret;
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 */
st->us->max_speed_hz = ADIS16400_SPI_SLOW;
spi_setup(st->us);
/* Disable IRQ */
- ret = adis16400_set_irq(st->indio_dev, false);
+ ret = adis16400_set_irq(indio_dev, false);
if (ret) {
dev_err(dev, "disable irq failed");
goto err_ret;
}
/* Do self test */
- ret = adis16400_self_test(st->indio_dev);
+ ret = adis16400_self_test(indio_dev);
if (ret) {
dev_err(dev, "self test failure");
goto err_ret;
}
/* Read status register to check the result */
- ret = adis16400_check_status(st->indio_dev);
+ ret = adis16400_check_status(indio_dev);
if (ret) {
- adis16400_reset(st->indio_dev);
+ adis16400_reset(indio_dev);
dev_err(dev, "device not playing ball -> reset");
msleep(ADIS16400_STARTUP_DELAY);
- ret = adis16400_check_status(st->indio_dev);
+ ret = adis16400_check_status(indio_dev);
if (ret) {
dev_err(dev, "giving up");
goto err_ret;
}
}
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);
if (ret)
goto err_ret;
prod_id, st->us->chip_select, st->us->irq);
}
/* 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);
if (!ret && (smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) {
st->us->max_speed_hz = ADIS16400_SPI_SLOW;
int *val2,
long mask)
{
- struct adis16400_state *st = iio_dev_get_devdata(indio_dev);
+ struct adis16400_state *st = iio_priv(indio_dev);
int ret;
s16 val16;
int shift;
static int __devinit adis16400_probe(struct spi_device *spi)
{
int ret, regdone = 0;
- struct adis16400_state *st = kzalloc(sizeof *st, GFP_KERNEL);
- if (!st) {
+ struct adis16400_state *st;
+ struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
+ if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_ret;
}
+ st = iio_priv(indio_dev);
/* 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;
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->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data];
- st->indio_dev->dev.parent = &spi->dev;
- st->indio_dev->name = spi_get_device_id(spi)->name;
- st->indio_dev->attrs = &adis16400_attribute_group;
- st->indio_dev->channels = st->variant->channels;
- st->indio_dev->num_channels = st->variant->num_channels;
- st->indio_dev->read_raw = &adis16400_read_raw;
- st->indio_dev->write_raw = &adis16400_write_raw;
- st->indio_dev->dev_data = (void *)(st);
- st->indio_dev->driver_module = THIS_MODULE;
- st->indio_dev->modes = INDIO_DIRECT_MODE;
-
- ret = adis16400_configure_ring(st->indio_dev);
+ indio_dev->dev.parent = &spi->dev;
+ indio_dev->name = spi_get_device_id(spi)->name;
+ indio_dev->attrs = &adis16400_attribute_group;
+ indio_dev->channels = st->variant->channels;
+ indio_dev->num_channels = st->variant->num_channels;
+ indio_dev->read_raw = &adis16400_read_raw;
+ indio_dev->write_raw = &adis16400_write_raw;
+ indio_dev->driver_module = THIS_MODULE;
+ indio_dev->modes = INDIO_DIRECT_MODE;
+
+ ret = adis16400_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,
st->variant->channels,
st->variant->num_channels);
if (ret) {
}
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)
goto error_uninitialize_ring;
}
/* Get the device into a sane initial state */
- ret = adis16400_initial_setup(st);
+ ret = adis16400_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
return 0;
error_remove_trigger:
- if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
- adis16400_remove_trigger(st->indio_dev);
+ if (indio_dev->modes & INDIO_RING_TRIGGERED)
+ adis16400_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:
- adis16400_unconfigure_ring(st->indio_dev);
+ adis16400_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 adis16400_remove(struct spi_device *spi)
{
int ret;
- struct adis16400_state *st = spi_get_drvdata(spi);
- struct iio_dev *indio_dev = st->indio_dev;
+ struct iio_dev *indio_dev = spi_get_drvdata(spi);
ret = adis16400_stop_device(indio_dev);
if (ret)
goto err_ret;
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);
iio_device_unregister(indio_dev);
- kfree(st->tx);
- kfree(st->rx);
- kfree(st);
-
return 0;
err_ret:
{
struct spi_message msg;
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;
int ret;
static int adis16350_spi_read_all(struct device *dev, u8 *rx)
{
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;
int i, j = 0, ret;
struct spi_transfer *xfers;
- xfers = kzalloc(sizeof(*xfers)*
- st->indio_dev->ring->scan_count + 1,
- GFP_KERNEL);
+ xfers = kzalloc(sizeof(*xfers)*indio_dev->ring->scan_count + 1,
+ GFP_KERNEL);
if (xfers == NULL)
return -ENOMEM;
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].bits_per_word = 16;
xfers[j].len = 2;
xfers[j].len = 2;
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);
ret = spi_sync(st->us, &msg);
{
struct iio_poll_func *pf = p;
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;
int i = 0, j, ret = 0;
s16 *data;
int adis16400_configure_ring(struct iio_dev *indio_dev)
{
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;
ring = iio_sw_rb_allocate(indio_dev);
static int adis16400_data_rdy_trigger_set_state(struct iio_trigger *trig,
bool state)
{
- struct adis16400_state *st = trig->private_data;
- struct iio_dev *indio_dev = st->indio_dev;
+ struct iio_dev *indio_dev = trig->private_data;
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 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",
spi_get_device_id(st->us)->name,
goto error_free_trig;
st->trig->dev.parent = &st->us->dev;
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;
ret = iio_trigger_register(st->trig);
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);
- free_irq(state->us->irq, state->trig);
- iio_free_trigger(state->trig);
+ iio_trigger_unregister(st->trig);
+ free_irq(st->us->irq, st->trig);
+ iio_free_trigger(st->trig);
}