Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
df9c1c42 JC |
2 | /* The industrial I/O core function defs. |
3 | * | |
4 | * Copyright (c) 2008 Jonathan Cameron | |
5 | * | |
cecfb931 | 6 | * These definitions are meant for use only within the IIO core, not individual |
df9c1c42 JC |
7 | * drivers. |
8 | */ | |
9 | ||
1aa04278 JC |
10 | #ifndef _IIO_CORE_H_ |
11 | #define _IIO_CORE_H_ | |
ef97d421 JC |
12 | #include <linux/kernel.h> |
13 | #include <linux/device.h> | |
14 | ||
3e3d11b2 | 15 | struct iio_buffer; |
ef97d421 JC |
16 | struct iio_chan_spec; |
17 | struct iio_dev; | |
18 | ||
3c33b7b8 | 19 | extern const struct device_type iio_device_type; |
1aa04278 | 20 | |
be24dcb1 AA |
21 | struct iio_dev_buffer_pair { |
22 | struct iio_dev *indio_dev; | |
23 | struct iio_buffer *buffer; | |
24 | }; | |
25 | ||
8dedcc3e AA |
26 | #define IIO_IOCTL_UNHANDLED 1 |
27 | struct 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 | ||
33 | long iio_device_ioctl(struct iio_dev *indio_dev, struct file *filp, | |
34 | unsigned int cmd, unsigned long arg); | |
35 | ||
36 | void iio_device_ioctl_handler_register(struct iio_dev *indio_dev, | |
37 | struct iio_ioctl_handler *h); | |
38 | void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h); | |
39 | ||
df9c1c42 | 40 | int __iio_add_chan_devattr(const char *postfix, |
df9c1c42 JC |
41 | struct iio_chan_spec const *chan, |
42 | ssize_t (*func)(struct device *dev, | |
43 | struct device_attribute *attr, | |
44 | char *buf), | |
45 | ssize_t (*writefunc)(struct device *dev, | |
46 | struct device_attribute *attr, | |
47 | const char *buf, | |
48 | size_t len), | |
e614a54b | 49 | u64 mask, |
3704432f | 50 | enum iio_shared_by shared_by, |
df9c1c42 | 51 | struct device *dev, |
3e3d11b2 | 52 | struct iio_buffer *buffer, |
df9c1c42 | 53 | struct list_head *attr_list); |
84088ebd | 54 | void iio_free_chan_devattr_list(struct list_head *attr_list); |
df9c1c42 | 55 | |
32f17172 AA |
56 | int iio_device_register_sysfs_group(struct iio_dev *indio_dev, |
57 | const struct attribute_group *group); | |
58 | ||
9fbfb4b3 | 59 | ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals); |
3661f3f5 | 60 | |
df9c1c42 JC |
61 | /* Event interface flags */ |
62 | #define IIO_BUSY_BIT_POS 1 | |
1aa04278 | 63 | |
f2a96245 | 64 | #ifdef CONFIG_IIO_BUFFER |
1aa04278 JC |
65 | struct poll_table_struct; |
66 | ||
f73f7f4d AA |
67 | __poll_t iio_buffer_poll_wrapper(struct file *filp, |
68 | struct poll_table_struct *wait); | |
69 | ssize_t iio_buffer_read_wrapper(struct file *filp, char __user *buf, | |
70 | size_t n, loff_t *f_ps); | |
9eeee3b0 MC |
71 | ssize_t iio_buffer_write_wrapper(struct file *filp, const char __user *buf, |
72 | size_t n, loff_t *f_ps); | |
1aa04278 | 73 | |
ee708e6b AA |
74 | int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev); |
75 | void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev); | |
1aa04278 | 76 | |
f73f7f4d AA |
77 | #define iio_buffer_poll_addr (&iio_buffer_poll_wrapper) |
78 | #define iio_buffer_read_outer_addr (&iio_buffer_read_wrapper) | |
9eeee3b0 | 79 | #define iio_buffer_write_outer_addr (&iio_buffer_write_wrapper) |
1aa04278 | 80 | |
a87c82e4 | 81 | void iio_disable_all_buffers(struct iio_dev *indio_dev); |
d2f0a48f | 82 | void iio_buffer_wakeup_poll(struct iio_dev *indio_dev); |
218bc53d | 83 | void iio_device_detach_buffers(struct iio_dev *indio_dev); |
a87c82e4 | 84 | |
1aa04278 JC |
85 | #else |
86 | ||
14555b14 | 87 | #define iio_buffer_poll_addr NULL |
f6d4033d | 88 | #define iio_buffer_read_outer_addr NULL |
9eeee3b0 | 89 | #define iio_buffer_write_outer_addr NULL |
1aa04278 | 90 | |
ee708e6b | 91 | static inline int iio_buffers_alloc_sysfs_and_mask(struct iio_dev *indio_dev) |
3e1b6c95 LPC |
92 | { |
93 | return 0; | |
94 | } | |
95 | ||
ee708e6b | 96 | static inline void iio_buffers_free_sysfs_and_mask(struct iio_dev *indio_dev) {} |
3e1b6c95 | 97 | |
a87c82e4 | 98 | static inline void iio_disable_all_buffers(struct iio_dev *indio_dev) {} |
d2f0a48f | 99 | static inline void iio_buffer_wakeup_poll(struct iio_dev *indio_dev) {} |
218bc53d | 100 | static inline void iio_device_detach_buffers(struct iio_dev *indio_dev) {} |
a87c82e4 | 101 | |
1aa04278 JC |
102 | #endif |
103 | ||
0a769a95 LPC |
104 | int iio_device_register_eventset(struct iio_dev *indio_dev); |
105 | void iio_device_unregister_eventset(struct iio_dev *indio_dev); | |
d2f0a48f | 106 | void iio_device_wakeup_eventset(struct iio_dev *indio_dev); |
0a769a95 | 107 | |
bc2b7dab GB |
108 | struct iio_event_interface; |
109 | bool iio_event_enabled(const struct iio_event_interface *ev_int); | |
110 | ||
1aa04278 | 111 | #endif |