xref: /openbmc/linux/include/linux/iio/backend.h (revision 5fc4f0c0)
15fc4f0c0SNuno Sa /* SPDX-License-Identifier: GPL-2.0-or-later */
25fc4f0c0SNuno Sa #ifndef _IIO_BACKEND_H_
35fc4f0c0SNuno Sa #define _IIO_BACKEND_H_
45fc4f0c0SNuno Sa 
55fc4f0c0SNuno Sa #include <linux/types.h>
65fc4f0c0SNuno Sa 
75fc4f0c0SNuno Sa struct fwnode_handle;
85fc4f0c0SNuno Sa struct iio_backend;
95fc4f0c0SNuno Sa struct device;
105fc4f0c0SNuno Sa struct iio_dev;
115fc4f0c0SNuno Sa 
125fc4f0c0SNuno Sa enum iio_backend_data_type {
135fc4f0c0SNuno Sa 	IIO_BACKEND_TWOS_COMPLEMENT,
145fc4f0c0SNuno Sa 	IIO_BACKEND_OFFSET_BINARY,
155fc4f0c0SNuno Sa 	IIO_BACKEND_DATA_TYPE_MAX
165fc4f0c0SNuno Sa };
175fc4f0c0SNuno Sa 
185fc4f0c0SNuno Sa /**
195fc4f0c0SNuno Sa  * struct iio_backend_data_fmt - Backend data format
205fc4f0c0SNuno Sa  * @type:		Data type.
215fc4f0c0SNuno Sa  * @sign_extend:	Bool to tell if the data is sign extended.
225fc4f0c0SNuno Sa  * @enable:		Enable/Disable the data format module. If disabled,
235fc4f0c0SNuno Sa  *			not formatting will happen.
245fc4f0c0SNuno Sa  */
255fc4f0c0SNuno Sa struct iio_backend_data_fmt {
265fc4f0c0SNuno Sa 	enum iio_backend_data_type type;
275fc4f0c0SNuno Sa 	bool sign_extend;
285fc4f0c0SNuno Sa 	bool enable;
295fc4f0c0SNuno Sa };
305fc4f0c0SNuno Sa 
315fc4f0c0SNuno Sa /**
325fc4f0c0SNuno Sa  * struct iio_backend_ops - operations structure for an iio_backend
335fc4f0c0SNuno Sa  * @enable:		Enable backend.
345fc4f0c0SNuno Sa  * @disable:		Disable backend.
355fc4f0c0SNuno Sa  * @chan_enable:	Enable one channel.
365fc4f0c0SNuno Sa  * @chan_disable:	Disable one channel.
375fc4f0c0SNuno Sa  * @data_format_set:	Configure the data format for a specific channel.
385fc4f0c0SNuno Sa  * @request_buffer:	Request an IIO buffer.
395fc4f0c0SNuno Sa  * @free_buffer:	Free an IIO buffer.
405fc4f0c0SNuno Sa  **/
415fc4f0c0SNuno Sa struct iio_backend_ops {
425fc4f0c0SNuno Sa 	int (*enable)(struct iio_backend *back);
435fc4f0c0SNuno Sa 	void (*disable)(struct iio_backend *back);
445fc4f0c0SNuno Sa 	int (*chan_enable)(struct iio_backend *back, unsigned int chan);
455fc4f0c0SNuno Sa 	int (*chan_disable)(struct iio_backend *back, unsigned int chan);
465fc4f0c0SNuno Sa 	int (*data_format_set)(struct iio_backend *back, unsigned int chan,
475fc4f0c0SNuno Sa 			       const struct iio_backend_data_fmt *data);
485fc4f0c0SNuno Sa 	struct iio_buffer *(*request_buffer)(struct iio_backend *back,
495fc4f0c0SNuno Sa 					     struct iio_dev *indio_dev);
505fc4f0c0SNuno Sa 	void (*free_buffer)(struct iio_backend *back,
515fc4f0c0SNuno Sa 			    struct iio_buffer *buffer);
525fc4f0c0SNuno Sa };
535fc4f0c0SNuno Sa 
545fc4f0c0SNuno Sa int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan);
555fc4f0c0SNuno Sa int iio_backend_chan_disable(struct iio_backend *back, unsigned int chan);
565fc4f0c0SNuno Sa int devm_iio_backend_enable(struct device *dev, struct iio_backend *back);
575fc4f0c0SNuno Sa int iio_backend_data_format_set(struct iio_backend *back, unsigned int chan,
585fc4f0c0SNuno Sa 				const struct iio_backend_data_fmt *data);
595fc4f0c0SNuno Sa int devm_iio_backend_request_buffer(struct device *dev,
605fc4f0c0SNuno Sa 				    struct iio_backend *back,
615fc4f0c0SNuno Sa 				    struct iio_dev *indio_dev);
625fc4f0c0SNuno Sa 
635fc4f0c0SNuno Sa void *iio_backend_get_priv(const struct iio_backend *conv);
645fc4f0c0SNuno Sa struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name);
655fc4f0c0SNuno Sa struct iio_backend *
665fc4f0c0SNuno Sa __devm_iio_backend_get_from_fwnode_lookup(struct device *dev,
675fc4f0c0SNuno Sa 					  struct fwnode_handle *fwnode);
685fc4f0c0SNuno Sa 
695fc4f0c0SNuno Sa int devm_iio_backend_register(struct device *dev,
705fc4f0c0SNuno Sa 			      const struct iio_backend_ops *ops, void *priv);
715fc4f0c0SNuno Sa 
725fc4f0c0SNuno Sa #endif
73