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 7 struct iio_chan_spec; 8 struct fwnode_handle; 9 struct iio_backend; 10 struct device; 11 struct iio_dev; 12 13 enum iio_backend_data_type { 14 IIO_BACKEND_TWOS_COMPLEMENT, 15 IIO_BACKEND_OFFSET_BINARY, 16 IIO_BACKEND_DATA_TYPE_MAX 17 }; 18 19 enum 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 */ 46 struct iio_backend_data_fmt { 47 enum iio_backend_data_type type; 48 bool sign_extend; 49 bool enable; 50 }; 51 52 /** 53 * struct iio_backend_ops - operations structure for an iio_backend 54 * @enable: Enable backend. 55 * @disable: Disable backend. 56 * @chan_enable: Enable one channel. 57 * @chan_disable: Disable one channel. 58 * @data_format_set: Configure the data format for a specific channel. 59 * @data_source_set: Configure the data source for a specific channel. 60 * @set_sample_rate: Configure the sampling rate for a specific channel. 61 * @request_buffer: Request an IIO buffer. 62 * @free_buffer: Free an IIO buffer. 63 * @extend_chan_spec: Extend an IIO channel. 64 * @ext_info_set: Extended info setter. 65 * @ext_info_get: Extended info getter. 66 **/ 67 struct iio_backend_ops { 68 int (*enable)(struct iio_backend *back); 69 void (*disable)(struct iio_backend *back); 70 int (*chan_enable)(struct iio_backend *back, unsigned int chan); 71 int (*chan_disable)(struct iio_backend *back, unsigned int chan); 72 int (*data_format_set)(struct iio_backend *back, unsigned int chan, 73 const struct iio_backend_data_fmt *data); 74 int (*data_source_set)(struct iio_backend *back, unsigned int chan, 75 enum iio_backend_data_source data); 76 int (*set_sample_rate)(struct iio_backend *back, unsigned int chan, 77 u64 sample_rate_hz); 78 struct iio_buffer *(*request_buffer)(struct iio_backend *back, 79 struct iio_dev *indio_dev); 80 void (*free_buffer)(struct iio_backend *back, 81 struct iio_buffer *buffer); 82 int (*extend_chan_spec)(struct iio_backend *back, 83 struct iio_chan_spec *chan); 84 int (*ext_info_set)(struct iio_backend *back, uintptr_t private, 85 const struct iio_chan_spec *chan, 86 const char *buf, size_t len); 87 int (*ext_info_get)(struct iio_backend *back, uintptr_t private, 88 const struct iio_chan_spec *chan, char *buf); 89 }; 90 91 int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan); 92 int iio_backend_chan_disable(struct iio_backend *back, unsigned int chan); 93 int devm_iio_backend_enable(struct device *dev, struct iio_backend *back); 94 int iio_backend_data_format_set(struct iio_backend *back, unsigned int chan, 95 const struct iio_backend_data_fmt *data); 96 int iio_backend_data_source_set(struct iio_backend *back, unsigned int chan, 97 enum iio_backend_data_source data); 98 int iio_backend_set_sampling_freq(struct iio_backend *back, unsigned int chan, 99 u64 sample_rate_hz); 100 int devm_iio_backend_request_buffer(struct device *dev, 101 struct iio_backend *back, 102 struct iio_dev *indio_dev); 103 ssize_t iio_backend_ext_info_set(struct iio_dev *indio_dev, uintptr_t private, 104 const struct iio_chan_spec *chan, 105 const char *buf, size_t len); 106 ssize_t iio_backend_ext_info_get(struct iio_dev *indio_dev, uintptr_t private, 107 const struct iio_chan_spec *chan, char *buf); 108 109 int iio_backend_extend_chan_spec(struct iio_dev *indio_dev, 110 struct iio_backend *back, 111 struct iio_chan_spec *chan); 112 void *iio_backend_get_priv(const struct iio_backend *conv); 113 struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name); 114 struct iio_backend * 115 __devm_iio_backend_get_from_fwnode_lookup(struct device *dev, 116 struct fwnode_handle *fwnode); 117 118 int devm_iio_backend_register(struct device *dev, 119 const struct iio_backend_ops *ops, void *priv); 120 121 #endif 122