1 #include <linux/interrupt.h>
2 #include <linux/kernel.h>
3 #include <linux/spi/spi.h>
4 #include <linux/export.h>
5
6 #include "../iio.h"
7 #include "../trigger.h"
8 #include "adis16209.h"
9
10 /**
11 * adis16209_data_rdy_trig_poll() the event handler for the data rdy trig
12 **/
adis16209_data_rdy_trig_poll(int irq,void * trig)13 static irqreturn_t adis16209_data_rdy_trig_poll(int irq, void *trig)
14 {
15 iio_trigger_poll(trig, iio_get_time_ns());
16 return IRQ_HANDLED;
17 }
18
19 /**
20 * adis16209_data_rdy_trigger_set_state() set datardy interrupt state
21 **/
adis16209_data_rdy_trigger_set_state(struct iio_trigger * trig,bool state)22 static int adis16209_data_rdy_trigger_set_state(struct iio_trigger *trig,
23 bool state)
24 {
25 struct iio_dev *indio_dev = trig->private_data;
26
27 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
28 return adis16209_set_irq(indio_dev, state);
29 }
30
31 static const struct iio_trigger_ops adis16209_trigger_ops = {
32 .owner = THIS_MODULE,
33 .set_trigger_state = &adis16209_data_rdy_trigger_set_state,
34 };
35
adis16209_probe_trigger(struct iio_dev * indio_dev)36 int adis16209_probe_trigger(struct iio_dev *indio_dev)
37 {
38 int ret;
39 struct adis16209_state *st = iio_priv(indio_dev);
40
41 st->trig = iio_allocate_trigger("adis16209-dev%d", indio_dev->id);
42 if (st->trig == NULL) {
43 ret = -ENOMEM;
44 goto error_ret;
45 }
46
47 ret = request_irq(st->us->irq,
48 adis16209_data_rdy_trig_poll,
49 IRQF_TRIGGER_RISING,
50 "adis16209",
51 st->trig);
52 if (ret)
53 goto error_free_trig;
54 st->trig->dev.parent = &st->us->dev;
55 st->trig->ops = &adis16209_trigger_ops;
56 st->trig->private_data = indio_dev;
57 ret = iio_trigger_register(st->trig);
58
59 /* select default trigger */
60 indio_dev->trig = st->trig;
61 if (ret)
62 goto error_free_irq;
63
64 return 0;
65
66 error_free_irq:
67 free_irq(st->us->irq, st->trig);
68 error_free_trig:
69 iio_free_trigger(st->trig);
70 error_ret:
71 return ret;
72 }
73
adis16209_remove_trigger(struct iio_dev * indio_dev)74 void adis16209_remove_trigger(struct iio_dev *indio_dev)
75 {
76 struct adis16209_state *st = iio_priv(indio_dev);
77
78 iio_trigger_unregister(st->trig);
79 free_irq(st->us->irq, st->trig);
80 iio_free_trigger(st->trig);
81 }
82