r8152: fix tx packets accounting
[linux/fpc-iii.git] / drivers / iio / imu / adis_trigger.c
blob93b99bd93738fab6cf2e9c2f8f0d14bf752bb31d
1 /*
2 * Common library for ADIS16XXX devices
4 * Copyright 2012 Analog Devices Inc.
5 * Author: Lars-Peter Clausen <lars@metafoo.de>
7 * Licensed under the GPL-2 or later.
8 */
10 #include <linux/interrupt.h>
11 #include <linux/kernel.h>
12 #include <linux/spi/spi.h>
13 #include <linux/export.h>
15 #include <linux/iio/iio.h>
16 #include <linux/iio/trigger.h>
17 #include <linux/iio/imu/adis.h>
19 static int adis_data_rdy_trigger_set_state(struct iio_trigger *trig,
20 bool state)
22 struct adis *adis = iio_trigger_get_drvdata(trig);
24 return adis_enable_irq(adis, state);
27 static const struct iio_trigger_ops adis_trigger_ops = {
28 .owner = THIS_MODULE,
29 .set_trigger_state = &adis_data_rdy_trigger_set_state,
32 /**
33 * adis_probe_trigger() - Sets up trigger for a adis device
34 * @adis: The adis device
35 * @indio_dev: The IIO device
37 * Returns 0 on success or a negative error code
39 * adis_remove_trigger() should be used to free the trigger.
41 int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
43 int ret;
45 adis->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name,
46 indio_dev->id);
47 if (adis->trig == NULL)
48 return -ENOMEM;
50 adis->trig->dev.parent = &adis->spi->dev;
51 adis->trig->ops = &adis_trigger_ops;
52 iio_trigger_set_drvdata(adis->trig, adis);
54 ret = request_irq(adis->spi->irq,
55 &iio_trigger_generic_data_rdy_poll,
56 IRQF_TRIGGER_RISING,
57 indio_dev->name,
58 adis->trig);
59 if (ret)
60 goto error_free_trig;
62 ret = iio_trigger_register(adis->trig);
64 indio_dev->trig = iio_trigger_get(adis->trig);
65 if (ret)
66 goto error_free_irq;
68 return 0;
70 error_free_irq:
71 free_irq(adis->spi->irq, adis->trig);
72 error_free_trig:
73 iio_trigger_free(adis->trig);
74 return ret;
76 EXPORT_SYMBOL_GPL(adis_probe_trigger);
78 /**
79 * adis_remove_trigger() - Remove trigger for a adis devices
80 * @adis: The adis device
82 * Removes the trigger previously registered with adis_probe_trigger().
84 void adis_remove_trigger(struct adis *adis)
86 iio_trigger_unregister(adis->trig);
87 free_irq(adis->spi->irq, adis->trig);
88 iio_trigger_free(adis->trig);
90 EXPORT_SYMBOL_GPL(adis_remove_trigger);