Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) #ifndef _IIO_UTILS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #define _IIO_UTILS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) /* IIO - useful set of util functionality
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Copyright (c) 2008 Jonathan Cameron
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /* Made up value to limit allocation sizes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define IIO_MAX_NAME_LENGTH 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define FORMAT_TYPE_FILE "%s_type"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) extern const char *iio_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)  * struct iio_channel_info - information about a given channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  * @name: channel name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  * @generic_name: general name for channel type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  * @scale: scale factor to be applied for conversion to si units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  * @offset: offset to be applied for conversion to si units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)  * @index: the channel index in the buffer output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)  * @bytes: number of bytes occupied in buffer output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)  * @bits_used: number of valid bits of data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)  * @shift: amount of bits to shift right data before applying bit mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)  * @mask: a bit mask for the raw output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)  * @be: flag if data is big endian
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)  * @is_signed: is the raw value stored signed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)  * @location: data offset for this channel inside the buffer (in bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct iio_channel_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	char *generic_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	float scale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	float offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	unsigned index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	unsigned bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	unsigned bits_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	unsigned shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	uint64_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	unsigned be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	unsigned is_signed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	unsigned location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static inline int iioutils_check_suffix(const char *str, const char *suffix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	return strlen(str) >= strlen(suffix) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		strncmp(str+strlen(str)-strlen(suffix),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 			suffix, strlen(suffix)) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int iioutils_break_up_name(const char *full_name, char **generic_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		      unsigned *shift, uint64_t *mask, unsigned *be,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		      const char *device_dir, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 		      const char *generic_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int iioutils_get_param_float(float *output, const char *param_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 			     const char *device_dir, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 			     const char *generic_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int build_channel_array(const char *device_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 			struct iio_channel_info **ci_array, int *counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int find_type_by_name(const char *name, const char *type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int write_sysfs_int(const char *filename, const char *basedir, int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int write_sysfs_int_and_verify(const char *filename, const char *basedir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 			       int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int write_sysfs_string_and_verify(const char *filename, const char *basedir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 				  const char *val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int write_sysfs_string(const char *filename, const char *basedir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		       const char *val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int read_sysfs_posint(const char *filename, const char *basedir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int read_sysfs_float(const char *filename, const char *basedir, float *val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int read_sysfs_string(const char *filename, const char *basedir, char *str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #endif /* _IIO_UTILS_H_ */