1
2
3
4
5
6
7
8
9#include <linux/interrupt.h>
10#include <linux/kernel.h>
11#include <linux/spi/spi.h>
12#include <linux/export.h>
13
14#include <linux/iio/iio.h>
15#include <linux/iio/trigger.h>
16#include <linux/iio/imu/adis.h>
17
18static int adis_data_rdy_trigger_set_state(struct iio_trigger *trig,
19 bool state)
20{
21 struct adis *adis = iio_trigger_get_drvdata(trig);
22
23 return adis_enable_irq(adis, state);
24}
25
26static const struct iio_trigger_ops adis_trigger_ops = {
27 .set_trigger_state = &adis_data_rdy_trigger_set_state,
28};
29
30
31
32
33
34
35
36
37
38
39int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
40{
41 int ret;
42
43 adis->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name,
44 indio_dev->id);
45 if (adis->trig == NULL)
46 return -ENOMEM;
47
48 adis->trig->dev.parent = &adis->spi->dev;
49 adis->trig->ops = &adis_trigger_ops;
50 iio_trigger_set_drvdata(adis->trig, adis);
51
52 ret = request_irq(adis->spi->irq,
53 &iio_trigger_generic_data_rdy_poll,
54 IRQF_TRIGGER_RISING,
55 indio_dev->name,
56 adis->trig);
57 if (ret)
58 goto error_free_trig;
59
60 ret = iio_trigger_register(adis->trig);
61
62 indio_dev->trig = iio_trigger_get(adis->trig);
63 if (ret)
64 goto error_free_irq;
65
66 return 0;
67
68error_free_irq:
69 free_irq(adis->spi->irq, adis->trig);
70error_free_trig:
71 iio_trigger_free(adis->trig);
72 return ret;
73}
74EXPORT_SYMBOL_GPL(adis_probe_trigger);
75
76
77
78
79
80
81
82void adis_remove_trigger(struct adis *adis)
83{
84 iio_trigger_unregister(adis->trig);
85 free_irq(adis->spi->irq, adis->trig);
86 iio_trigger_free(adis->trig);
87}
88EXPORT_SYMBOL_GPL(adis_remove_trigger);
89