]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/iio/iio_utils.h
media: dvb_ca_en50221: prevent using slot_info for Spectre attacs
[mirror_ubuntu-bionic-kernel.git] / tools / iio / iio_utils.h
CommitLineData
bdcb31d0
RD
1#ifndef _IIO_UTILS_H_
2#define _IIO_UTILS_H_
3
c57f1ba7
JC
4/* IIO - useful set of util functionality
5 *
6 * Copyright (c) 2008 Jonathan Cameron
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
11 */
12
e58537cc 13#include <stdint.h>
9d8ae6c8 14
b42f2a0c 15/* Made up value to limit allocation sizes */
f80ac400 16#define IIO_MAX_NAME_LENGTH 64
9d8ae6c8 17
1aa04278 18#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
e58537cc 19#define FORMAT_TYPE_FILE "%s_type"
c57f1ba7 20
34cbea19
CO
21#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
22
bdcb31d0 23extern const char *iio_dir;
e58537cc
JC
24
25/**
26 * struct iio_channel_info - information about a given channel
27 * @name: channel name
28 * @generic_name: general name for channel type
29 * @scale: scale factor to be applied for conversion to si units
30 * @offset: offset to be applied for conversion to si units
31 * @index: the channel index in the buffer output
32 * @bytes: number of bytes occupied in buffer output
5dc65d79
HK
33 * @bits_used: number of valid bits of data
34 * @shift: amount of bits to shift right data before applying bit mask
e58537cc 35 * @mask: a bit mask for the raw output
5dc65d79 36 * @be: flag if data is big endian
e58537cc 37 * @is_signed: is the raw value stored signed
5dc65d79 38 * @location: data offset for this channel inside the buffer (in bytes)
e58537cc
JC
39 **/
40struct iio_channel_info {
41 char *name;
42 char *generic_name;
43 float scale;
44 float offset;
45 unsigned index;
46 unsigned bytes;
47 unsigned bits_used;
52615d47 48 unsigned shift;
e58537cc 49 uint64_t mask;
117cf8b7 50 unsigned be;
e58537cc 51 unsigned is_signed;
e58537cc
JC
52 unsigned location;
53};
54
5f991a92
LW
55static inline int iioutils_check_suffix(const char *str, const char *suffix)
56{
57 return strlen(str) >= strlen(suffix) &&
58 strncmp(str+strlen(str)-strlen(suffix),
59 suffix, strlen(suffix)) == 0;
60}
61
bdcb31d0 62int iioutils_break_up_name(const char *full_name, char **generic_name);
7663a4aa
HK
63int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
64 unsigned *shift, uint64_t *mask, unsigned *be,
65 const char *device_dir, const char *name,
66 const char *generic_name);
bdcb31d0 67int iioutils_get_param_float(float *output, const char *param_name,
7663a4aa
HK
68 const char *device_dir, const char *name,
69 const char *generic_name);
95ddd3f4 70void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
bdcb31d0 71int build_channel_array(const char *device_dir,
7663a4aa 72 struct iio_channel_info **ci_array, int *counter);
bdcb31d0 73int find_type_by_name(const char *name, const char *type);
9d475254
HK
74int write_sysfs_int(const char *filename, const char *basedir, int val);
75int write_sysfs_int_and_verify(const char *filename, const char *basedir,
76 int val);
77int write_sysfs_string_and_verify(const char *filename, const char *basedir,
78 const char *val);
79int write_sysfs_string(const char *filename, const char *basedir,
80 const char *val);
81int read_sysfs_posint(const char *filename, const char *basedir);
82int read_sysfs_float(const char *filename, const char *basedir, float *val);
bdcb31d0
RD
83int read_sysfs_string(const char *filename, const char *basedir, char *str);
84
85#endif /* _IIO_UTILS_H_ */