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 "adis16203.h"
9
10 /**
11 * adis16203_data_rdy_trigger_set_state() set datardy interrupt state
12 **/
adis16203_data_rdy_trigger_set_state(struct iio_trigger * trig,bool state)13 static int adis16203_data_rdy_trigger_set_state(struct iio_trigger *trig,
14 bool state)
15 {
16 struct iio_dev *indio_dev = trig->private_data;
17
18 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
19 return adis16203_set_irq(indio_dev, state);
20 }
21
22 static const struct iio_trigger_ops adis16203_trigger_ops = {
23 .owner = THIS_MODULE,
24 .set_trigger_state = &adis16203_data_rdy_trigger_set_state,
25 };
26
adis16203_probe_trigger(struct iio_dev * indio_dev)27 int adis16203_probe_trigger(struct iio_dev *indio_dev)
28 {
29 int ret;
30 struct adis16203_state *st = iio_priv(indio_dev);
31
32 st->trig = iio_allocate_trigger("adis16203-dev%d", indio_dev->id);
33 if (st->trig == NULL) {
34 ret = -ENOMEM;
35 goto error_ret;
36 }
37
38 ret = request_irq(st->us->irq,
39 &iio_trigger_generic_data_rdy_poll,
40 IRQF_TRIGGER_RISING,
41 "adis16203",
42 st->trig);
43 if (ret)
44 goto error_free_trig;
45
46 st->trig->dev.parent = &st->us->dev;
47 st->trig->ops = &adis16203_trigger_ops;
48 st->trig->private_data = indio_dev;
49 ret = iio_trigger_register(st->trig);
50
51 /* select default trigger */
52 indio_dev->trig = st->trig;
53 if (ret)
54 goto error_free_irq;
55
56 return 0;
57
58 error_free_irq:
59 free_irq(st->us->irq, st->trig);
60 error_free_trig:
61 iio_free_trigger(st->trig);
62 error_ret:
63 return ret;
64 }
65
adis16203_remove_trigger(struct iio_dev * indio_dev)66 void adis16203_remove_trigger(struct iio_dev *indio_dev)
67 {
68 struct adis16203_state *st = iio_priv(indio_dev);
69
70 iio_trigger_unregister(st->trig);
71 free_irq(st->us->irq, st->trig);
72 iio_free_trigger(st->trig);
73 }
74