Merge tag 'block-6.13-20242901' of git://git.kernel.dk/linux
[drm/drm-misc.git] / include / linux / iio / backend.h
blob10be00f3b1206e8a58ddf4f0267c8bcb05269f33
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _IIO_BACKEND_H_
3 #define _IIO_BACKEND_H_
5 #include <linux/types.h>
6 #include <linux/iio/iio.h>
8 struct iio_chan_spec;
9 struct fwnode_handle;
10 struct iio_backend;
11 struct device;
12 struct iio_dev;
14 enum iio_backend_data_type {
15 IIO_BACKEND_TWOS_COMPLEMENT,
16 IIO_BACKEND_OFFSET_BINARY,
17 IIO_BACKEND_DATA_UNSIGNED,
18 IIO_BACKEND_DATA_TYPE_MAX
21 enum iio_backend_data_source {
22 IIO_BACKEND_INTERNAL_CONTINUOUS_WAVE,
23 IIO_BACKEND_EXTERNAL,
24 IIO_BACKEND_INTERNAL_RAMP_16BIT,
25 IIO_BACKEND_DATA_SOURCE_MAX
28 #define iio_backend_debugfs_ptr(ptr) PTR_IF(IS_ENABLED(CONFIG_DEBUG_FS), ptr)
30 /**
31 * IIO_BACKEND_EX_INFO - Helper for an IIO extended channel attribute
32 * @_name: Attribute name
33 * @_shared: Whether the attribute is shared between all channels
34 * @_what: Data private to the driver
36 #define IIO_BACKEND_EX_INFO(_name, _shared, _what) { \
37 .name = (_name), \
38 .shared = (_shared), \
39 .read = iio_backend_ext_info_get, \
40 .write = iio_backend_ext_info_set, \
41 .private = (_what), \
44 /**
45 * struct iio_backend_data_fmt - Backend data format
46 * @type: Data type.
47 * @sign_extend: Bool to tell if the data is sign extended.
48 * @enable: Enable/Disable the data format module. If disabled,
49 * not formatting will happen.
51 struct iio_backend_data_fmt {
52 enum iio_backend_data_type type;
53 bool sign_extend;
54 bool enable;
57 /* vendor specific from 32 */
58 enum iio_backend_test_pattern {
59 IIO_BACKEND_NO_TEST_PATTERN,
60 /* modified prbs9 */
61 IIO_BACKEND_ADI_PRBS_9A = 32,
62 /* modified prbs23 */
63 IIO_BACKEND_ADI_PRBS_23A,
64 IIO_BACKEND_TEST_PATTERN_MAX
67 enum iio_backend_sample_trigger {
68 IIO_BACKEND_SAMPLE_TRIGGER_EDGE_FALLING,
69 IIO_BACKEND_SAMPLE_TRIGGER_EDGE_RISING,
70 IIO_BACKEND_SAMPLE_TRIGGER_MAX
73 /**
74 * struct iio_backend_ops - operations structure for an iio_backend
75 * @enable: Enable backend.
76 * @disable: Disable backend.
77 * @chan_enable: Enable one channel.
78 * @chan_disable: Disable one channel.
79 * @data_format_set: Configure the data format for a specific channel.
80 * @data_source_set: Configure the data source for a specific channel.
81 * @set_sample_rate: Configure the sampling rate for a specific channel.
82 * @test_pattern_set: Configure a test pattern.
83 * @chan_status: Get the channel status.
84 * @iodelay_set: Set digital I/O delay.
85 * @data_sample_trigger: Control when to sample data.
86 * @request_buffer: Request an IIO buffer.
87 * @free_buffer: Free an IIO buffer.
88 * @extend_chan_spec: Extend an IIO channel.
89 * @ext_info_set: Extended info setter.
90 * @ext_info_get: Extended info getter.
91 * @read_raw: Read a channel attribute from a backend device
92 * @debugfs_print_chan_status: Print channel status into a buffer.
93 * @debugfs_reg_access: Read or write register value of backend.
94 * @ddr_enable: Enable interface DDR (Double Data Rate) mode.
95 * @ddr_disable: Disable interface DDR (Double Data Rate) mode.
96 * @data_stream_enable: Enable data stream.
97 * @data_stream_disable: Disable data stream.
98 * @data_transfer_addr: Set data address.
99 **/
100 struct iio_backend_ops {
101 int (*enable)(struct iio_backend *back);
102 void (*disable)(struct iio_backend *back);
103 int (*chan_enable)(struct iio_backend *back, unsigned int chan);
104 int (*chan_disable)(struct iio_backend *back, unsigned int chan);
105 int (*data_format_set)(struct iio_backend *back, unsigned int chan,
106 const struct iio_backend_data_fmt *data);
107 int (*data_source_set)(struct iio_backend *back, unsigned int chan,
108 enum iio_backend_data_source data);
109 int (*set_sample_rate)(struct iio_backend *back, unsigned int chan,
110 u64 sample_rate_hz);
111 int (*test_pattern_set)(struct iio_backend *back,
112 unsigned int chan,
113 enum iio_backend_test_pattern pattern);
114 int (*chan_status)(struct iio_backend *back, unsigned int chan,
115 bool *error);
116 int (*iodelay_set)(struct iio_backend *back, unsigned int chan,
117 unsigned int taps);
118 int (*data_sample_trigger)(struct iio_backend *back,
119 enum iio_backend_sample_trigger trigger);
120 struct iio_buffer *(*request_buffer)(struct iio_backend *back,
121 struct iio_dev *indio_dev);
122 void (*free_buffer)(struct iio_backend *back,
123 struct iio_buffer *buffer);
124 int (*extend_chan_spec)(struct iio_backend *back,
125 struct iio_chan_spec *chan);
126 int (*ext_info_set)(struct iio_backend *back, uintptr_t private,
127 const struct iio_chan_spec *chan,
128 const char *buf, size_t len);
129 int (*ext_info_get)(struct iio_backend *back, uintptr_t private,
130 const struct iio_chan_spec *chan, char *buf);
131 int (*read_raw)(struct iio_backend *back,
132 struct iio_chan_spec const *chan, int *val, int *val2,
133 long mask);
134 int (*debugfs_print_chan_status)(struct iio_backend *back,
135 unsigned int chan, char *buf,
136 size_t len);
137 int (*debugfs_reg_access)(struct iio_backend *back, unsigned int reg,
138 unsigned int writeval, unsigned int *readval);
139 int (*ddr_enable)(struct iio_backend *back);
140 int (*ddr_disable)(struct iio_backend *back);
141 int (*data_stream_enable)(struct iio_backend *back);
142 int (*data_stream_disable)(struct iio_backend *back);
143 int (*data_transfer_addr)(struct iio_backend *back, u32 address);
147 * struct iio_backend_info - info structure for an iio_backend
148 * @name: Backend name.
149 * @ops: Backend operations.
151 struct iio_backend_info {
152 const char *name;
153 const struct iio_backend_ops *ops;
156 int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan);
157 int iio_backend_chan_disable(struct iio_backend *back, unsigned int chan);
158 int devm_iio_backend_enable(struct device *dev, struct iio_backend *back);
159 int iio_backend_enable(struct iio_backend *back);
160 void iio_backend_disable(struct iio_backend *back);
161 int iio_backend_data_format_set(struct iio_backend *back, unsigned int chan,
162 const struct iio_backend_data_fmt *data);
163 int iio_backend_data_source_set(struct iio_backend *back, unsigned int chan,
164 enum iio_backend_data_source data);
165 int iio_backend_set_sampling_freq(struct iio_backend *back, unsigned int chan,
166 u64 sample_rate_hz);
167 int iio_backend_test_pattern_set(struct iio_backend *back,
168 unsigned int chan,
169 enum iio_backend_test_pattern pattern);
170 int iio_backend_chan_status(struct iio_backend *back, unsigned int chan,
171 bool *error);
172 int iio_backend_iodelay_set(struct iio_backend *back, unsigned int lane,
173 unsigned int taps);
174 int iio_backend_data_sample_trigger(struct iio_backend *back,
175 enum iio_backend_sample_trigger trigger);
176 int devm_iio_backend_request_buffer(struct device *dev,
177 struct iio_backend *back,
178 struct iio_dev *indio_dev);
179 int iio_backend_ddr_enable(struct iio_backend *back);
180 int iio_backend_ddr_disable(struct iio_backend *back);
181 int iio_backend_data_stream_enable(struct iio_backend *back);
182 int iio_backend_data_stream_disable(struct iio_backend *back);
183 int iio_backend_data_transfer_addr(struct iio_backend *back, u32 address);
184 ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private,
185 const struct iio_chan_spec *chan,
186 const char *buf, size_t len);
187 ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private,
188 const struct iio_chan_spec *chan, char *buf);
189 int iio_backend_read_raw(struct iio_backend *back,
190 struct iio_chan_spec const *chan, int *val, int *val2,
191 long mask);
192 int iio_backend_extend_chan_spec(struct iio_backend *back,
193 struct iio_chan_spec *chan);
194 void *iio_backend_get_priv(const struct iio_backend *conv);
195 struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name);
196 struct iio_backend *devm_iio_backend_fwnode_get(struct device *dev,
197 const char *name,
198 struct fwnode_handle *fwnode);
199 struct iio_backend *
200 __devm_iio_backend_get_from_fwnode_lookup(struct device *dev,
201 struct fwnode_handle *fwnode);
203 int devm_iio_backend_register(struct device *dev,
204 const struct iio_backend_info *info, void *priv);
206 static inline int iio_backend_read_scale(struct iio_backend *back,
207 struct iio_chan_spec const *chan,
208 int *val, int *val2)
210 return iio_backend_read_raw(back, chan, val, val2, IIO_CHAN_INFO_SCALE);
213 static inline int iio_backend_read_offset(struct iio_backend *back,
214 struct iio_chan_spec const *chan,
215 int *val, int *val2)
217 return iio_backend_read_raw(back, chan, val, val2,
218 IIO_CHAN_INFO_OFFSET);
221 ssize_t iio_backend_debugfs_print_chan_status(struct iio_backend *back,
222 unsigned int chan, char *buf,
223 size_t len);
224 void iio_backend_debugfs_add(struct iio_backend *back,
225 struct iio_dev *indio_dev);
226 #endif