{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
+ struct ade7758_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7758_WRITE_REG(reg_address);
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
+ struct ade7758_state *st = iio_priv(indio_dev);
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
+ struct ade7758_state *st = iio_priv(indio_dev);
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
+ struct ade7758_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
+ struct ade7758_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
+ struct ade7758_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
return ret;
}
-static int ade7758_initial_setup(struct ade7758_state *st)
+static int ade7758_initial_setup(struct iio_dev *indio_dev)
{
+ struct ade7758_state *st = iio_priv(indio_dev);
+ struct device *dev = &indio_dev->dev;
int ret;
- struct device *dev = &st->indio_dev->dev;
/* use low spi speed for init */
st->us->mode = SPI_MODE_1;
static int __devinit ade7758_probe(struct spi_device *spi)
{
int i, ret, regdone = 0;
- struct ade7758_state *st = kzalloc(sizeof *st, GFP_KERNEL);
- if (!st) {
- ret = -ENOMEM;
+ struct ade7758_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)*ADE7758_MAX_RX, GFP_KERNEL);
if (st->rx == NULL) {
ret = -ENOMEM;
- goto error_free_st;
+ goto error_free_dev;
}
st->tx = kzalloc(sizeof(*st->tx)*ADE7758_MAX_TX, GFP_KERNEL);
if (st->tx == NULL) {
st->us = spi;
st->ade7758_ring_channels = &ade7758_channels[0];
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->attrs = &ade7758_attribute_group;
- st->indio_dev->dev_data = (void *)(st);
- st->indio_dev->driver_module = THIS_MODULE;
- st->indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->name = spi->dev.driver->name;
+ indio_dev->dev.parent = &spi->dev;
+ indio_dev->attrs = &ade7758_attribute_group;
+ indio_dev->driver_module = THIS_MODULE;
+ indio_dev->modes = INDIO_DIRECT_MODE;
for (i = 0; i < AD7758_NUM_WAVESRC; i++)
st->available_scan_masks[i] = 1 << i;
- st->indio_dev->available_scan_masks = st->available_scan_masks;
+ indio_dev->available_scan_masks = st->available_scan_masks;
- ret = ade7758_configure_ring(st->indio_dev);
+ ret = ade7758_configure_ring(indio_dev);
if (ret)
- goto error_free_dev;
+ goto error_free_tx;
- 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,
&ade7758_channels[0],
ARRAY_SIZE(ade7758_channels));
if (ret) {
}
/* Get the device into a sane initial state */
- ret = ade7758_initial_setup(st);
+ ret = ade7758_initial_setup(indio_dev);
if (ret)
goto error_uninitialize_ring;
if (spi->irq) {
- ret = ade7758_probe_trigger(st->indio_dev);
+ ret = ade7758_probe_trigger(indio_dev);
if (ret)
goto error_remove_trigger;
}
return 0;
error_remove_trigger:
- if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
- ade7758_remove_trigger(st->indio_dev);
+ if (indio_dev->modes & INDIO_RING_TRIGGERED)
+ ade7758_remove_trigger(indio_dev);
error_uninitialize_ring:
- ade7758_uninitialize_ring(st->indio_dev->ring);
+ ade7758_uninitialize_ring(indio_dev->ring);
error_unreg_ring_funcs:
- ade7758_unconfigure_ring(st->indio_dev);
-error_free_dev:
- if (regdone)
- iio_device_unregister(st->indio_dev);
- else
- iio_free_device(st->indio_dev);
+ ade7758_unconfigure_ring(indio_dev);
error_free_tx:
kfree(st->tx);
error_free_rx:
kfree(st->rx);
-error_free_st:
- kfree(st);
+error_free_dev:
+ if (regdone)
+ iio_device_unregister(indio_dev);
+ else
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
static int ade7758_remove(struct spi_device *spi)
{
+ struct iio_dev *indio_dev = spi_get_drvdata(spi);
+ struct ade7758_state *st = iio_priv(indio_dev);
int ret;
- struct ade7758_state *st = spi_get_drvdata(spi);
- struct iio_dev *indio_dev = st->indio_dev;
- ret = ade7758_stop_device(&(indio_dev->dev));
+ ret = ade7758_stop_device(&indio_dev->dev);
if (ret)
goto err_ret;
ade7758_remove_trigger(indio_dev);
ade7758_uninitialize_ring(indio_dev->ring);
- iio_device_unregister(indio_dev);
ade7758_unconfigure_ring(indio_dev);
kfree(st->tx);
kfree(st->rx);
- kfree(st);
+ iio_device_unregister(indio_dev);
return 0;
-
err_ret:
return ret;
}
static int ade7758_spi_read_burst(struct device *dev)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
+ struct ade7758_state *st = iio_priv(indio_dev);
int ret;
ret = spi_sync(st->us, &st->ring_msg);
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->private_data;
struct iio_ring_buffer *ring = indio_dev->ring;
- struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
+ struct ade7758_state *st = iio_priv(indio_dev);
s64 dat64[2];
u32 *dat32 = (u32 *)dat64;
if (ring->scan_count)
- if (ade7758_spi_read_burst(&st->indio_dev->dev) >= 0)
+ if (ade7758_spi_read_burst(&indio_dev->dev) >= 0)
*dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF;
/* Guaranteed to be aligned with 8 byte boundary */
ring->access->store_to(ring, (u8 *)dat64, pf->timestamp);
- iio_trigger_notify_done(st->indio_dev->trig);
+ iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
}
**/
static int ade7758_ring_preenable(struct iio_dev *indio_dev)
{
- struct ade7758_state *st = indio_dev->dev_data;
+ struct ade7758_state *st = iio_priv(indio_dev);
struct iio_ring_buffer *ring = indio_dev->ring;
size_t d_size;
unsigned channel;
int ade7758_configure_ring(struct iio_dev *indio_dev)
{
- struct ade7758_state *st = indio_dev->dev_data;
+ struct ade7758_state *st = iio_priv(indio_dev);
int ret = 0;
indio_dev->ring = iio_sw_rb_allocate(indio_dev);
static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
bool state)
{
- struct ade7758_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 ade7758_set_irq(&indio_dev->dev, state);
**/
static int ade7758_trig_try_reen(struct iio_trigger *trig)
{
- struct ade7758_state *st = trig->private_data;
+ struct iio_dev *indio_dev = trig->private_data;
+ struct ade7758_state *st = iio_priv(indio_dev);
enable_irq(st->us->irq);
/* irq reenabled so success! */
int ade7758_probe_trigger(struct iio_dev *indio_dev)
{
+ struct ade7758_state *st = iio_priv(indio_dev);
int ret;
- struct ade7758_state *st = indio_dev->dev_data;
st->trig = iio_allocate_trigger("%s-dev%d",
spi_get_device_id(st->us)->name,
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 = &ade7758_data_rdy_trigger_set_state;
st->trig->try_reenable = &ade7758_trig_try_reen;
ret = iio_trigger_register(st->trig);
void ade7758_remove_trigger(struct iio_dev *indio_dev)
{
- struct ade7758_state *state = indio_dev->dev_data;
+ struct ade7758_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);
}