iio_core.h 2.9 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0-only */
2 3 4 5
/* The industrial I/O core function defs.
 *
 * Copyright (c) 2008 Jonathan Cameron
 *
M
Michael Hennerich 已提交
6
 * These definitions are meant for use only within the IIO core, not individual
7 8 9
 * drivers.
 */

10 11
#ifndef _IIO_CORE_H_
#define _IIO_CORE_H_
12 13 14
#include <linux/kernel.h>
#include <linux/device.h>

15
struct iio_buffer;
16 17 18
struct iio_chan_spec;
struct iio_dev;

G
Guenter Roeck 已提交
19
extern struct device_type iio_device_type;
20

21 22 23 24 25 26 27 28 29 30 31 32 33 34
#define IIO_IOCTL_UNHANDLED	1
struct iio_ioctl_handler {
	struct list_head entry;
	long (*ioctl)(struct iio_dev *indio_dev, struct file *filp,
		      unsigned int cmd, unsigned long arg);
};

long iio_device_ioctl(struct iio_dev *indio_dev, struct file *filp,
		      unsigned int cmd, unsigned long arg);

void iio_device_ioctl_handler_register(struct iio_dev *indio_dev,
				       struct iio_ioctl_handler *h);
void iio_device_ioctl_handler_unregister(struct iio_ioctl_handler *h);

35 36 37 38 39 40 41 42 43
int __iio_add_chan_devattr(const char *postfix,
			   struct iio_chan_spec const *chan,
			   ssize_t (*func)(struct device *dev,
					   struct device_attribute *attr,
					   char *buf),
			   ssize_t (*writefunc)(struct device *dev,
						struct device_attribute *attr,
						const char *buf,
						size_t len),
44
			   u64 mask,
45
			   enum iio_shared_by shared_by,
46
			   struct device *dev,
47
			   struct iio_buffer *buffer,
48
			   struct list_head *attr_list);
49
void iio_free_chan_devattr_list(struct list_head *attr_list);
50

51 52 53
int iio_device_register_sysfs_group(struct iio_dev *indio_dev,
				    const struct attribute_group *group);

54
ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals);
55

56 57
/* Event interface flags */
#define IIO_BUSY_BIT_POS 1
58

59
#ifdef CONFIG_IIO_BUFFER
60 61
struct poll_table_struct;

62
__poll_t iio_buffer_poll(struct file *filp,
63
			     struct poll_table_struct *wait);
64 65
ssize_t iio_buffer_read_outer(struct file *filp, char __user *buf,
			      size_t n, loff_t *f_ps);
66

67 68
int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev);
void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev);
69

70
#define iio_buffer_poll_addr (&iio_buffer_poll)
71
#define iio_buffer_read_outer_addr (&iio_buffer_read_outer)
72

73
void iio_disable_all_buffers(struct iio_dev *indio_dev);
74
void iio_buffer_wakeup_poll(struct iio_dev *indio_dev);
75

76 77
#else

78
#define iio_buffer_poll_addr NULL
79
#define iio_buffer_read_outer_addr NULL
80

81 82 83 84 85 86 87
static inline int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)
{
	return 0;
}

static inline void iio_buffer_free_sysfs_and_mask(struct iio_dev *indio_dev) {}

88
static inline void iio_disable_all_buffers(struct iio_dev *indio_dev) {}
89
static inline void iio_buffer_wakeup_poll(struct iio_dev *indio_dev) {}
90

91 92
#endif

93 94
int iio_device_register_eventset(struct iio_dev *indio_dev);
void iio_device_unregister_eventset(struct iio_dev *indio_dev);
95
void iio_device_wakeup_eventset(struct iio_dev *indio_dev);
96

97 98 99
struct iio_event_interface;
bool iio_event_enabled(const struct iio_event_interface *ev_int);

100
#endif