{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
mutex_lock(&st->lock);
ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_STATUS, 1);
{
int len = 0, ret;
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct sca3000_state *st = dev_info->dev_data;
+ struct sca3000_state *st = iio_priv(dev_info);
mutex_lock(&st->lock);
ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_REVID, 1);
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct sca3000_state *st = dev_info->dev_data;
+ struct sca3000_state *st = iio_priv(dev_info);
int len = 0;
len += sprintf(buf + len, "0 - normal mode");
char *buf)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct sca3000_state *st = dev_info->dev_data;
+ struct sca3000_state *st = iio_priv(dev_info);
int len = 0, ret;
mutex_lock(&st->lock);
size_t len)
{
struct iio_dev *dev_info = dev_get_drvdata(dev);
- struct sca3000_state *st = dev_info->dev_data;
+ struct sca3000_state *st = iio_priv(dev_info);
int ret;
int mask = 0x03;
long val;
int *val2,
long mask)
{
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret;
u8 address;
char *buf)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int len = 0, ret, val;
mutex_lock(&st->lock);
char *buf)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret, len = 0, base_freq = 0, val;
mutex_lock(&st->lock);
size_t len)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret, base_freq = 0;
int ctrlval;
long val;
char *buf)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret;
int val;
ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_TEMP_MSB, 2);
int *val)
{
int ret, i;
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int num = IIO_EVENT_CODE_EXTRACT_MODIFIER(e);
mutex_lock(&st->lock);
ret = sca3000_read_ctrl_reg(st, sca3000_addresses[num][1]);
int e,
int val)
{
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int num = IIO_EVENT_CODE_EXTRACT_MODIFIER(e);
int ret;
int i;
static irqreturn_t sca3000_event_handler(int irq, void *private)
{
struct iio_dev *indio_dev = private;
- struct sca3000_state *st;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret, val;
s64 last_timestamp = iio_get_time_ns();
- st = indio_dev->dev_data;
/* Could lead if badly timed to an extra read of status reg,
* but ensures no interrupt is missed.
*/
if (ret)
goto done;
- sca3000_ring_int_process(val, st->indio_dev->ring);
+ sca3000_ring_int_process(val, indio_dev->ring);
if (val & SCA3000_INT_STATUS_FREE_FALL)
- iio_push_event(st->indio_dev, 0,
+ iio_push_event(indio_dev, 0,
IIO_MOD_EVENT_CODE(IIO_EV_CLASS_ACCEL,
0,
IIO_EV_MOD_X_AND_Y_AND_Z,
last_timestamp);
if (val & SCA3000_INT_STATUS_Y_TRIGGER)
- iio_push_event(st->indio_dev, 0,
+ iio_push_event(indio_dev, 0,
IIO_MOD_EVENT_CODE(IIO_EV_CLASS_ACCEL,
0,
IIO_EV_MOD_Y,
last_timestamp);
if (val & SCA3000_INT_STATUS_X_TRIGGER)
- iio_push_event(st->indio_dev, 0,
+ iio_push_event(indio_dev, 0,
IIO_MOD_EVENT_CODE(IIO_EV_CLASS_ACCEL,
0,
IIO_EV_MOD_X,
last_timestamp);
if (val & SCA3000_INT_STATUS_Z_TRIGGER)
- iio_push_event(st->indio_dev, 0,
+ iio_push_event(indio_dev, 0,
IIO_MOD_EVENT_CODE(IIO_EV_CLASS_ACCEL,
0,
IIO_EV_MOD_Z,
static int sca3000_read_event_config(struct iio_dev *indio_dev,
int e)
{
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret;
u8 protect_mask = 0x03;
int num = IIO_EVENT_CODE_EXTRACT_MODIFIER(e);
{
int ret, len;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int val;
mutex_lock(&st->lock);
size_t len)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
long val;
int ret;
u8 protect_mask = SCA3000_FREE_FALL_DETECT;
int e,
int state)
{
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret, ctrlval;
u8 protect_mask = 0x03;
int num = IIO_EVENT_CODE_EXTRACT_MODIFIER(e);
{
int ret, regdone = 0;
struct sca3000_state *st;
+ struct iio_dev *indio_dev;
- st = kzalloc(sizeof(struct sca3000_state), GFP_KERNEL);
- if (st == NULL) {
+ indio_dev = iio_allocate_device(sizeof(*st));
+ if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_ret;
}
- spi_set_drvdata(spi, st);
+ spi_set_drvdata(spi, indio_dev);
st->us = spi;
mutex_init(&st->lock);
st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)
->driver_data];
- st->indio_dev = iio_allocate_device(0);
- if (st->indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_clear_st;
- }
- st->indio_dev->dev.parent = &spi->dev;
- st->indio_dev->name = spi_get_device_id(spi)->name;
+ indio_dev->dev.parent = &spi->dev;
+ indio_dev->name = spi_get_device_id(spi)->name;
if (st->info->temp_output)
- st->indio_dev->info = &sca3000_info_with_temp;
+ indio_dev->info = &sca3000_info_with_temp;
else {
- st->indio_dev->info = &sca3000_info;
- st->indio_dev->channels = sca3000_channels;
- st->indio_dev->num_channels = ARRAY_SIZE(sca3000_channels);
+ indio_dev->info = &sca3000_info;
+ indio_dev->channels = sca3000_channels;
+ indio_dev->num_channels = ARRAY_SIZE(sca3000_channels);
}
- st->indio_dev->dev_data = (void *)(st);
- st->indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->modes = INDIO_DIRECT_MODE;
- sca3000_configure_ring(st->indio_dev);
- ret = iio_device_register(st->indio_dev);
+ sca3000_configure_ring(indio_dev);
+ ret = iio_device_register(indio_dev);
if (ret < 0)
goto error_free_dev;
regdone = 1;
- ret = iio_ring_buffer_register_ex(st->indio_dev->ring, 0,
+ ret = iio_ring_buffer_register_ex(indio_dev->ring, 0,
sca3000_channels,
ARRAY_SIZE(sca3000_channels));
if (ret < 0)
&sca3000_event_handler,
IRQF_TRIGGER_FALLING,
"sca3000",
- st->indio_dev);
+ indio_dev);
if (ret)
goto error_unregister_ring;
}
- sca3000_register_ring_funcs(st->indio_dev);
+ sca3000_register_ring_funcs(indio_dev);
ret = sca3000_clean_setup(st);
if (ret)
goto error_free_irq;
error_free_irq:
if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
- free_irq(spi->irq, st->indio_dev);
+ free_irq(spi->irq, indio_dev);
error_unregister_ring:
- iio_ring_buffer_unregister(st->indio_dev->ring);
+ iio_ring_buffer_unregister(indio_dev->ring);
error_unregister_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_clear_st:
- kfree(st);
+ iio_free_device(indio_dev);
+
error_ret:
return ret;
}
static int sca3000_remove(struct spi_device *spi)
{
- struct sca3000_state *st = spi_get_drvdata(spi);
- struct iio_dev *indio_dev = st->indio_dev;
+ struct iio_dev *indio_dev = spi_get_drvdata(spi);
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret;
/* Must ensure no interrupts can be generated after this!*/
ret = sca3000_stop_all_interrupts(st);
sca3000_unconfigure_ring(indio_dev);
iio_device_unregister(indio_dev);
- kfree(st);
-
return 0;
}
{
struct iio_hw_ring_buffer *hw_ring = iio_to_hw_ring_buf(r);
struct iio_dev *indio_dev = hw_ring->private;
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
u8 *rx;
int ret, i, num_available, num_read = 0;
int bytes_per_sample = 1;
int ret, val;
struct iio_ring_buffer *ring = dev_get_drvdata(dev);
struct iio_dev *indio_dev = ring->indio_dev;
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
mutex_lock(&st->lock);
ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_INT_MASK, 1);
{
struct iio_ring_buffer *ring = dev_get_drvdata(dev);
struct iio_dev *indio_dev = ring->indio_dev;
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
long val;
int ret;
int len = 0, ret;
struct iio_ring_buffer *ring = dev_get_drvdata(dev);
struct iio_dev *indio_dev = ring->indio_dev;
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
mutex_lock(&st->lock);
ret = sca3000_read_data_short(st, SCA3000_REG_ADDR_MODE, 1);
{
struct iio_ring_buffer *ring = dev_get_drvdata(dev);
struct iio_dev *indio_dev = ring->indio_dev;
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret;
mutex_lock(&st->lock);
{
struct iio_ring_buffer *ring = dev_get_drvdata(dev);
struct iio_dev *indio_dev = ring->indio_dev;
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
return sprintf(buf, "0.%06d\n", 4*st->info->scale);
}
static inline
int __sca3000_hw_ring_state_set(struct iio_dev *indio_dev, bool state)
{
- struct sca3000_state *st = indio_dev->dev_data;
+ struct sca3000_state *st = iio_priv(indio_dev);
int ret;
mutex_lock(&st->lock);