Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/* The industrial I/O core function defs.
3 *
4 * Copyright (c) 2008 Jonathan Cameron
5 *
6 * These definitions are meant for use only within the IIO core, not individual
7 * drivers.
8 */
9
10#ifndef _IIO_CORE_H_
11#define _IIO_CORE_H_
12#include <linux/kernel.h>
13#include <linux/device.h>
14
15struct iio_buffer;
16struct iio_chan_spec;
17struct iio_dev;
18
19extern const struct device_type iio_device_type;
20
21struct iio_dev_buffer_pair {
22 struct iio_dev *indio_dev;
23 struct iio_buffer *buffer;
24};
25
26#define IIO_IOCTL_UNHANDLED 1
27struct iio_ioctl_handler {
28 struct list_head entry;
29 long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
30 unsigned int cmd, unsigned long arg);
31};
32
33void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
34 struct iio_ioctl_handler *h);
35void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h);
36
37int __iio_add_chan_devattr(const char *postfix,
38 struct iio_chan_spec const *chan,
39 ssize_t (*func)(struct device *dev,
40 struct device_attribute *attr,
41 char *buf),
42 ssize_t (*writefunc)(struct device *dev,
43 struct device_attribute *attr,
44 const char *buf,
45 size_t len),
46 u64 mask,
47 enum iio_shared_by shared_by,
48 struct device *dev,
49 struct iio_buffer *buffer,
50 struct list_head *attr_list);
51void iio_free_chan_devattr_list(struct list_head *attr_list);
52
53int iio_device_register_sysfs_group(struct iio_dev *indio_dev,
54 const struct attribute_group *group);
55
56ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals);
57
58/* Event interface flags */
59#define IIO_BUSY_BIT_POS 1
60
61#ifdef CONFIG_IIO_BUFFER
62struct poll_table_struct;
63
64__poll_t iio_buffer_poll_wrapper(struct file *filp,
65 struct poll_table_struct *wait);
66ssize_t iio_buffer_read_wrapper(struct file *filp, char __user *buf,
67 size_t n, loff_t *f_ps);
68ssize_t iio_buffer_write_wrapper(struct file *filp, const char __user *buf,
69 size_t n, loff_t *f_ps);
70
71int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev);
72void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev);
73
74#define iio_buffer_poll_addr (&iio_buffer_poll_wrapper)
75#define iio_buffer_read_outer_addr (&iio_buffer_read_wrapper)
76#define iio_buffer_write_outer_addr (&iio_buffer_write_wrapper)
77
78void iio_disable_all_buffers(struct iio_dev *indio_dev);
79void iio_buffer_wakeup_poll(struct iio_dev *indio_dev);
80void iio_device_detach_buffers(struct iio_dev *indio_dev);
81
82#else
83
84#define iio_buffer_poll_addr NULL
85#define iio_buffer_read_outer_addr NULL
86#define iio_buffer_write_outer_addr NULL
87
88static inline int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
89{
90 return 0;
91}
92
93static inline void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev) {}
94
95static inline void iio_disable_all_buffers(struct iio_dev *indio_dev) {}
96static inline void iio_buffer_wakeup_poll(struct iio_dev *indio_dev) {}
97static inline void iio_device_detach_buffers(struct iio_dev *indio_dev) {}
98
99#endif
100
101int iio_device_register_eventset(struct iio_dev *indio_dev);
102void iio_device_unregister_eventset(struct iio_dev *indio_dev);
103void iio_device_wakeup_eventset(struct iio_dev *indio_dev);
104
105struct iio_event_interface;
106bool iio_event_enabled(const struct iio_event_interface *ev_int);
107
108#endif
1/* The industrial I/O core function defs.
2 *
3 * Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * These definitions are meant for use only within the IIO core, not individual
10 * drivers.
11 */
12
13#ifndef _IIO_CORE_H_
14#define _IIO_CORE_H_
15#include <linux/kernel.h>
16#include <linux/device.h>
17
18struct iio_chan_spec;
19struct iio_dev;
20
21
22int __iio_add_chan_devattr(const char *postfix,
23 struct iio_chan_spec const *chan,
24 ssize_t (*func)(struct device *dev,
25 struct device_attribute *attr,
26 char *buf),
27 ssize_t (*writefunc)(struct device *dev,
28 struct device_attribute *attr,
29 const char *buf,
30 size_t len),
31 u64 mask,
32 bool generic,
33 struct device *dev,
34 struct list_head *attr_list);
35
36/* Event interface flags */
37#define IIO_BUSY_BIT_POS 1
38
39#ifdef CONFIG_IIO_BUFFER
40struct poll_table_struct;
41
42unsigned int iio_buffer_poll(struct file *filp,
43 struct poll_table_struct *wait);
44ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
45 size_t n, loff_t *f_ps);
46
47
48#define iio_buffer_poll_addr (&iio_buffer_poll)
49#define iio_buffer_read_first_n_outer_addr (&iio_buffer_read_first_n_outer)
50
51#else
52
53#define iio_buffer_poll_addr NULL
54#define iio_buffer_read_first_n_outer_addr NULL
55
56#endif
57
58int iio_device_register_eventset(struct iio_dev *indio_dev);
59void iio_device_unregister_eventset(struct iio_dev *indio_dev);
60int iio_event_getfd(struct iio_dev *indio_dev);
61
62#endif