Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
fork
Configure Feed
Select the types of activity you want to include in your feed.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2#ifndef _IIO_BACKEND_H_
3#define _IIO_BACKEND_H_
4
5#include <linux/types.h>
6
7struct iio_chan_spec;
8struct fwnode_handle;
9struct iio_backend;
10struct device;
11struct iio_dev;
12
13enum iio_backend_data_type {
14 IIO_BACKEND_TWOS_COMPLEMENT,
15 IIO_BACKEND_OFFSET_BINARY,
16 IIO_BACKEND_DATA_TYPE_MAX
17};
18
19enum iio_backend_data_source {
20 IIO_BACKEND_INTERNAL_CONTINUOS_WAVE,
21 IIO_BACKEND_EXTERNAL,
22 IIO_BACKEND_DATA_SOURCE_MAX
23};
24
25/**
26 * IIO_BACKEND_EX_INFO - Helper for an IIO extended channel attribute
27 * @_name: Attribute name
28 * @_shared: Whether the attribute is shared between all channels
29 * @_what: Data private to the driver
30 */
31#define IIO_BACKEND_EX_INFO(_name, _shared, _what) { \
32 .name = (_name), \
33 .shared = (_shared), \
34 .read = iio_backend_ext_info_get, \
35 .write = iio_backend_ext_info_set, \
36 .private = (_what), \
37}
38
39/**
40 * struct iio_backend_data_fmt - Backend data format
41 * @type: Data type.
42 * @sign_extend: Bool to tell if the data is sign extended.
43 * @enable: Enable/Disable the data format module. If disabled,
44 * not formatting will happen.
45 */
46struct iio_backend_data_fmt {
47 enum iio_backend_data_type type;
48 bool sign_extend;
49 bool enable;
50};
51
52/* vendor specific from 32 */
53enum iio_backend_test_pattern {
54 IIO_BACKEND_NO_TEST_PATTERN,
55 /* modified prbs9 */
56 IIO_BACKEND_ADI_PRBS_9A = 32,
57 IIO_BACKEND_TEST_PATTERN_MAX
58};
59
60enum iio_backend_sample_trigger {
61 IIO_BACKEND_SAMPLE_TRIGGER_EDGE_FALLING,
62 IIO_BACKEND_SAMPLE_TRIGGER_EDGE_RISING,
63 IIO_BACKEND_SAMPLE_TRIGGER_MAX
64};
65
66/**
67 * struct iio_backend_ops - operations structure for an iio_backend
68 * @enable: Enable backend.
69 * @disable: Disable backend.
70 * @chan_enable: Enable one channel.
71 * @chan_disable: Disable one channel.
72 * @data_format_set: Configure the data format for a specific channel.
73 * @data_source_set: Configure the data source for a specific channel.
74 * @set_sample_rate: Configure the sampling rate for a specific channel.
75 * @test_pattern_set: Configure a test pattern.
76 * @chan_status: Get the channel status.
77 * @iodelay_set: Set digital I/O delay.
78 * @data_sample_trigger: Control when to sample data.
79 * @request_buffer: Request an IIO buffer.
80 * @free_buffer: Free an IIO buffer.
81 * @extend_chan_spec: Extend an IIO channel.
82 * @ext_info_set: Extended info setter.
83 * @ext_info_get: Extended info getter.
84 **/
85struct iio_backend_ops {
86 int (*enable)(struct iio_backend *back);
87 void (*disable)(struct iio_backend *back);
88 int (*chan_enable)(struct iio_backend *back, unsigned int chan);
89 int (*chan_disable)(struct iio_backend *back, unsigned int chan);
90 int (*data_format_set)(struct iio_backend *back, unsigned int chan,
91 const struct iio_backend_data_fmt *data);
92 int (*data_source_set)(struct iio_backend *back, unsigned int chan,
93 enum iio_backend_data_source data);
94 int (*set_sample_rate)(struct iio_backend *back, unsigned int chan,
95 u64 sample_rate_hz);
96 int (*test_pattern_set)(struct iio_backend *back,
97 unsigned int chan,
98 enum iio_backend_test_pattern pattern);
99 int (*chan_status)(struct iio_backend *back, unsigned int chan,
100 bool *error);
101 int (*iodelay_set)(struct iio_backend *back, unsigned int chan,
102 unsigned int taps);
103 int (*data_sample_trigger)(struct iio_backend *back,
104 enum iio_backend_sample_trigger trigger);
105 struct iio_buffer *(*request_buffer)(struct iio_backend *back,
106 struct iio_dev *indio_dev);
107 void (*free_buffer)(struct iio_backend *back,
108 struct iio_buffer *buffer);
109 int (*extend_chan_spec)(struct iio_backend *back,
110 struct iio_chan_spec *chan);
111 int (*ext_info_set)(struct iio_backend *back, uintptr_t private,
112 const struct iio_chan_spec *chan,
113 const char *buf, size_t len);
114 int (*ext_info_get)(struct iio_backend *back, uintptr_t private,
115 const struct iio_chan_spec *chan, char *buf);
116};
117
118int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan);
119int iio_backend_chan_disable(struct iio_backend *back, unsigned int chan);
120int devm_iio_backend_enable(struct device *dev, struct iio_backend *back);
121int iio_backend_data_format_set(struct iio_backend *back, unsigned int chan,
122 const struct iio_backend_data_fmt *data);
123int iio_backend_data_source_set(struct iio_backend *back, unsigned int chan,
124 enum iio_backend_data_source data);
125int iio_backend_set_sampling_freq(struct iio_backend *back, unsigned int chan,
126 u64 sample_rate_hz);
127int iio_backend_test_pattern_set(struct iio_backend *back,
128 unsigned int chan,
129 enum iio_backend_test_pattern pattern);
130int iio_backend_chan_status(struct iio_backend *back, unsigned int chan,
131 bool *error);
132int iio_backend_iodelay_set(struct iio_backend *back, unsigned int lane,
133 unsigned int taps);
134int iio_backend_data_sample_trigger(struct iio_backend *back,
135 enum iio_backend_sample_trigger trigger);
136int devm_iio_backend_request_buffer(struct device *dev,
137 struct iio_backend *back,
138 struct iio_dev *indio_dev);
139ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private,
140 const struct iio_chan_spec *chan,
141 const char *buf, size_t len);
142ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private,
143 const struct iio_chan_spec *chan, char *buf);
144
145int iio_backend_extend_chan_spec(struct iio_dev *indio_dev,
146 struct iio_backend *back,
147 struct iio_chan_spec *chan);
148void *iio_backend_get_priv(const struct iio_backend *conv);
149struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name);
150struct iio_backend *
151__devm_iio_backend_get_from_fwnode_lookup(struct device *dev,
152 struct fwnode_handle *fwnode);
153
154int devm_iio_backend_register(struct device *dev,
155 const struct iio_backend_ops *ops, void *priv);
156
157#endif