13 #include <linux/device.h>
15 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/poll.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
22 #include <linux/wait.h>
58 copied =
kfifo_put(&ev_int->det_events, &ev);
71 static unsigned int iio_event_poll(
struct file *filep,
77 poll_wait(filep, &ev_int->
wait, wait);
87 static ssize_t iio_event_chrdev_read(
struct file *filep,
113 ret =
kfifo_to_user(&ev_int->det_events, buf, count, &copied);
118 return ret ? ret : copied;
121 static int iio_event_chrdev_release(
struct inode *
inode,
struct file *filep)
139 .read = iio_event_chrdev_read,
140 .poll = iio_event_poll,
141 .release = iio_event_chrdev_release,
161 &iio_event_chrdev_fileops, ev_int,
O_RDONLY);
170 static const char *
const iio_ev_type_text[] = {
178 static const char *
const iio_ev_dir_text[] = {
189 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
198 ret = indio_dev->
info->write_event_config(indio_dev,
201 return (ret < 0) ? ret : len;
208 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
210 int val = indio_dev->
info->read_event_config(indio_dev,
216 return sprintf(buf,
"%d\n", val);
223 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
227 ret = indio_dev->
info->read_event_value(indio_dev,
232 return sprintf(buf,
"%d\n", val);
240 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
245 if (!indio_dev->
info->write_event_value)
252 ret = indio_dev->
info->write_event_value(indio_dev, this_attr->
address,
260 static int iio_device_add_event_sysfs(
struct iio_dev *indio_dev,
263 int ret = 0,
i, attrcount = 0;
273 if (postfix ==
NULL) {
311 if (postfix ==
NULL) {
333 static inline void __iio_remove_event_config_attrs(
struct iio_dev *indio_dev)
344 static inline int __iio_add_event_config_attrs(
struct iio_dev *indio_dev)
346 int j,
ret, attrcount = 0;
350 ret = iio_device_add_event_sysfs(indio_dev,
353 goto error_clear_attrs;
359 __iio_remove_event_config_attrs(indio_dev);
364 static bool iio_check_for_dynamic_events(
struct iio_dev *indio_dev)
369 if (indio_dev->
channels[j].event_mask != 0)
380 static const char *iio_event_group_name =
"events";
384 int ret = 0, attrcount_orig = 0, attrcount, attrn;
387 if (!(indio_dev->
info->event_attrs ||
388 iio_check_for_dynamic_events(indio_dev)))
401 if (indio_dev->
info->event_attrs !=
NULL) {
402 attr = indio_dev->
info->event_attrs->attrs;
403 while (*attr++ !=
NULL)
406 attrcount = attrcount_orig;
408 ret = __iio_add_event_config_attrs(indio_dev);
410 goto error_free_setup_event_lines;
420 goto error_free_setup_event_lines;
422 if (indio_dev->
info->event_attrs)
424 indio_dev->
info->event_attrs->attrs,
427 attrn = attrcount_orig;
439 error_free_setup_event_lines:
440 __iio_remove_event_config_attrs(indio_dev);
451 __iio_remove_event_config_attrs(indio_dev);