This source file includes following definitions.
- iio_simple_dummy_trigger_h
- iio_simple_dummy_configure_buffer
- iio_simple_dummy_unconfigure_buffer
1
2
3
4
5
6
7
8
9
10
11 #include <linux/kernel.h>
12 #include <linux/export.h>
13 #include <linux/slab.h>
14 #include <linux/interrupt.h>
15 #include <linux/irq.h>
16 #include <linux/bitmap.h>
17
18 #include <linux/iio/iio.h>
19 #include <linux/iio/trigger_consumer.h>
20 #include <linux/iio/buffer.h>
21 #include <linux/iio/kfifo_buf.h>
22
23 #include "iio_simple_dummy.h"
24
25
26
27 static const s16 fakedata[] = {
28 [DUMMY_INDEX_VOLTAGE_0] = 7,
29 [DUMMY_INDEX_DIFFVOLTAGE_1M2] = -33,
30 [DUMMY_INDEX_DIFFVOLTAGE_3M4] = -2,
31 [DUMMY_INDEX_ACCELX] = 344,
32 };
33
34
35
36
37
38
39
40
41
42
43
44 static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
45 {
46 struct iio_poll_func *pf = p;
47 struct iio_dev *indio_dev = pf->indio_dev;
48 int len = 0;
49 u16 *data;
50
51 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
52 if (!data)
53 goto done;
54
55 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) {
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 int i, j;
73
74 for (i = 0, j = 0;
75 i < bitmap_weight(indio_dev->active_scan_mask,
76 indio_dev->masklength);
77 i++, j++) {
78 j = find_next_bit(indio_dev->active_scan_mask,
79 indio_dev->masklength, j);
80
81 data[i] = fakedata[j];
82 len += 2;
83 }
84 }
85
86 iio_push_to_buffers_with_timestamp(indio_dev, data,
87 iio_get_time_ns(indio_dev));
88
89 kfree(data);
90
91 done:
92
93
94
95
96 iio_trigger_notify_done(indio_dev->trig);
97
98 return IRQ_HANDLED;
99 }
100
101 static const struct iio_buffer_setup_ops iio_simple_dummy_buffer_setup_ops = {
102
103
104
105
106
107
108 .postenable = &iio_triggered_buffer_postenable,
109
110
111
112
113
114
115 .predisable = &iio_triggered_buffer_predisable,
116 };
117
118 int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
119 {
120 int ret;
121 struct iio_buffer *buffer;
122
123
124 buffer = iio_kfifo_allocate();
125 if (!buffer) {
126 ret = -ENOMEM;
127 goto error_ret;
128 }
129
130 iio_device_attach_buffer(indio_dev, buffer);
131
132
133
134
135
136 indio_dev->setup_ops = &iio_simple_dummy_buffer_setup_ops;
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
155 &iio_simple_dummy_trigger_h,
156 IRQF_ONESHOT,
157 indio_dev,
158 "iio_simple_dummy_consumer%d",
159 indio_dev->id);
160
161 if (!indio_dev->pollfunc) {
162 ret = -ENOMEM;
163 goto error_free_buffer;
164 }
165
166
167
168
169
170 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
171
172 return 0;
173
174 error_free_buffer:
175 iio_kfifo_free(indio_dev->buffer);
176 error_ret:
177 return ret;
178 }
179
180
181
182
183
184 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
185 {
186 iio_dealloc_pollfunc(indio_dev->pollfunc);
187 iio_kfifo_free(indio_dev->buffer);
188 }