1
2
3
4
5
6#include <linux/irq.h>
7#include <linux/module.h>
8#include <linux/atomic.h>
9
10#ifndef _IIO_TRIGGER_H_
11#define _IIO_TRIGGER_H_
12
13#ifdef CONFIG_IIO_TRIGGER
14struct iio_subirq {
15 bool enabled;
16};
17
18struct iio_dev;
19struct iio_trigger;
20
21
22
23
24
25
26
27
28
29
30
31
32struct iio_trigger_ops {
33 int (*set_trigger_state)(struct iio_trigger *trig, bool state);
34 int (*try_reenable)(struct iio_trigger *trig);
35 int (*validate_device)(struct iio_trigger *trig,
36 struct iio_dev *indio_dev);
37};
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59struct iio_trigger {
60 const struct iio_trigger_ops *ops;
61 struct module *owner;
62 int id;
63 const char *name;
64 struct device dev;
65
66 struct list_head list;
67 struct list_head alloc_list;
68 atomic_t use_count;
69
70 struct irq_chip subirq_chip;
71 int subirq_base;
72
73 struct iio_subirq subirqs[CONFIG_IIO_CONSUMERS_PER_TRIGGER];
74 unsigned long pool[BITS_TO_LONGS(CONFIG_IIO_CONSUMERS_PER_TRIGGER)];
75 struct mutex pool_lock;
76 bool attached_own_device;
77};
78
79
80static inline struct iio_trigger *to_iio_trigger(struct device *d)
81{
82 return container_of(d, struct iio_trigger, dev);
83}
84
85static inline void iio_trigger_put(struct iio_trigger *trig)
86{
87 module_put(trig->owner);
88 put_device(&trig->dev);
89}
90
91static inline struct iio_trigger *iio_trigger_get(struct iio_trigger *trig)
92{
93 get_device(&trig->dev);
94 __module_get(trig->owner);
95
96 return trig;
97}
98
99
100
101
102
103
104
105
106
107static inline void iio_trigger_set_drvdata(struct iio_trigger *trig, void *data)
108{
109 dev_set_drvdata(&trig->dev, data);
110}
111
112
113
114
115
116
117
118static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig)
119{
120 return dev_get_drvdata(&trig->dev);
121}
122
123
124
125
126
127#define iio_trigger_register(trig_info) \
128 __iio_trigger_register((trig_info), THIS_MODULE)
129int __iio_trigger_register(struct iio_trigger *trig_info,
130 struct module *this_mod);
131
132#define devm_iio_trigger_register(dev, trig_info) \
133 __devm_iio_trigger_register((dev), (trig_info), THIS_MODULE)
134int __devm_iio_trigger_register(struct device *dev,
135 struct iio_trigger *trig_info,
136 struct module *this_mod);
137
138
139
140
141
142void iio_trigger_unregister(struct iio_trigger *trig_info);
143
144void devm_iio_trigger_unregister(struct device *dev,
145 struct iio_trigger *trig_info);
146
147
148
149
150
151
152
153
154int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig);
155
156
157
158
159
160
161
162void iio_trigger_poll(struct iio_trigger *trig);
163void iio_trigger_poll_chained(struct iio_trigger *trig);
164
165irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
166
167__printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...);
168void iio_trigger_free(struct iio_trigger *trig);
169
170
171
172
173
174bool iio_trigger_using_own(struct iio_dev *indio_dev);
175
176int iio_trigger_validate_own_device(struct iio_trigger *trig,
177 struct iio_dev *indio_dev);
178
179#else
180struct iio_trigger;
181struct iio_trigger_ops;
182#endif
183#endif
184