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