1 #include <linux/kernel.h>
2 #include <linux/slab.h>
4 #include <linux/export.h>
5 #include <linux/iio/buffer.h>
6 #include <linux/iio/consumer.h>
9 struct iio_buffer buffer
;
10 int (*cb
)(u8
*data
, void *private);
12 struct iio_channel
*channels
;
15 static int iio_buffer_cb_store_to(struct iio_buffer
*buffer
, u8
*data
)
17 struct iio_cb_buffer
*cb_buff
= container_of(buffer
,
21 return cb_buff
->cb(data
, cb_buff
->private);
24 static struct iio_buffer_access_funcs iio_cb_access
= {
25 .store_to
= &iio_buffer_cb_store_to
,
28 struct iio_cb_buffer
*iio_channel_get_all_cb(const char *name
,
34 struct iio_cb_buffer
*cb_buff
;
35 struct iio_dev
*indio_dev
;
36 struct iio_channel
*chan
;
38 cb_buff
= kzalloc(sizeof(*cb_buff
), GFP_KERNEL
);
39 if (cb_buff
== NULL
) {
44 cb_buff
->private = private;
46 cb_buff
->buffer
.access
= &iio_cb_access
;
47 INIT_LIST_HEAD(&cb_buff
->buffer
.demux_list
);
49 cb_buff
->channels
= iio_channel_get_all(name
);
50 if (IS_ERR(cb_buff
->channels
)) {
51 ret
= PTR_ERR(cb_buff
->channels
);
52 goto error_free_cb_buff
;
55 indio_dev
= cb_buff
->channels
[0].indio_dev
;
56 cb_buff
->buffer
.scan_mask
57 = kcalloc(BITS_TO_LONGS(indio_dev
->masklength
), sizeof(long),
59 if (cb_buff
->buffer
.scan_mask
== NULL
) {
61 goto error_release_channels
;
63 chan
= &cb_buff
->channels
[0];
64 while (chan
->indio_dev
) {
65 if (chan
->indio_dev
!= indio_dev
) {
67 goto error_release_channels
;
69 set_bit(chan
->channel
->scan_index
,
70 cb_buff
->buffer
.scan_mask
);
76 error_release_channels
:
77 iio_channel_release_all(cb_buff
->channels
);
83 EXPORT_SYMBOL_GPL(iio_channel_get_all_cb
);
85 int iio_channel_start_all_cb(struct iio_cb_buffer
*cb_buff
)
87 return iio_update_buffers(cb_buff
->channels
[0].indio_dev
,
91 EXPORT_SYMBOL_GPL(iio_channel_start_all_cb
);
93 void iio_channel_stop_all_cb(struct iio_cb_buffer
*cb_buff
)
95 iio_update_buffers(cb_buff
->channels
[0].indio_dev
,
99 EXPORT_SYMBOL_GPL(iio_channel_stop_all_cb
);
101 void iio_channel_release_all_cb(struct iio_cb_buffer
*cb_buff
)
103 iio_channel_release_all(cb_buff
->channels
);
106 EXPORT_SYMBOL_GPL(iio_channel_release_all_cb
);
109 *iio_channel_cb_get_channels(const struct iio_cb_buffer
*cb_buffer
)
111 return cb_buffer
->channels
;
113 EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels
);