核心元素¶
工业 I/O 核心为编写用于许多不同类型的嵌入式传感器的驱动程序提供了一个统一的框架,并为操作传感器的用户空间应用程序提供了一个标准接口。 该实现可以在 drivers/iio/industrialio-*
下找到
工业 I/O 设备¶
struct iio_dev
- 工业 I/O 设备iio_device_alloc()
- 从驱动程序分配一个iio_dev
iio_device_free()
- 从驱动程序释放一个iio_dev
iio_device_register()
- 向 IIO 子系统注册一个设备iio_device_unregister()
- 从 IIO 子系统注销一个设备
IIO 设备通常对应于单个硬件传感器,它提供驱动程序处理设备所需的所有信息。 让我们首先看一下嵌入在 IIO 设备中的功能,然后我们将展示设备驱动程序如何使用 IIO 设备。
用户空间应用程序可以通过两种方式与 IIO 驱动程序进行交互。
/sys/bus/iio/devices/iio:deviceX/
,这表示一个硬件传感器,并将同一芯片的数据通道组合在一起。/dev/iio:deviceX
,字符设备节点接口,用于缓冲数据传输和事件信息检索。
典型的 IIO 驱动程序将自己注册为 I2C 或 SPI 驱动程序,并将创建两个例程,probe 和 remove。
在 probe 中
调用
iio_device_alloc()
,它为 IIO 设备分配内存。使用驱动程序特定信息(例如设备名称、设备通道)初始化 IIO 设备字段。
调用
iio_device_register()
,这会将设备注册到 IIO 核心。 调用此函数后,设备已准备好接受来自用户空间应用程序的请求。
在 remove 中,我们以相反的顺序释放 probe 中分配的资源
iio_device_unregister()
,从 IIO 核心注销设备。iio_device_free()
,释放为 IIO 设备分配的内存。
IIO 设备 sysfs 接口¶
属性是 sysfs 文件,用于公开芯片信息,并允许应用程序设置各种配置参数。 对于索引为 X 的设备,属性可以在 /sys/bus/iio/devices/iio:deviceX/ 目录下找到。 常见属性有
name
,物理芯片的描述。dev
,显示与/dev/iio:deviceX
节点关联的主设备号:次设备号对。sampling_frequency_available
,设备可用的离散采样频率值集。IIO 设备的可用标准属性在 Linux 内核源代码的 :file:Documentation/ABI/testing/sysfs-bus-iio 文件中进行了描述。
IIO 设备通道¶
struct iio_chan_spec
- 单个通道的规范
IIO 设备通道是数据通道的表示。 一个 IIO 设备可以有一个或多个通道。 例如
温度计传感器有一个通道,表示温度测量。
带有两个通道的光传感器,指示可见光谱和红外光谱中的测量值。
加速度计最多可以有 3 个通道,表示 X、Y 和 Z 轴上的加速度。
IIO 通道由 struct iio_chan_spec
描述。 上面示例中温度传感器的温度计驱动程序必须按如下方式描述其通道
static const struct iio_chan_spec temp_channel[] = {
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
},
};
暴露给用户空间的通道 sysfs 属性以位掩码的形式指定。 根据它们的共享信息,可以在以下掩码之一中设置属性
info_mask_separate,属性将特定于此通道
info_mask_shared_by_type,属性由同一类型的所有通道共享
info_mask_shared_by_dir,属性由同一方向的所有通道共享
info_mask_shared_by_all,属性由所有通道共享
当每个通道类型有多个数据通道时,我们有两种方法来区分它们
将
iio_chan_spec
的 .modified 字段设置为 1。 修饰符使用同一iio_chan_spec
结构的 .channel2 字段指定,并用于指示通道的物理唯一特征,例如其方向或光谱响应。 例如,光传感器可以有两个通道,一个用于红外光,一个用于红外光和可见光。将
iio_chan_spec
的 .indexed 字段设置为 1。 在这种情况下,通道只是另一个实例,其索引由 .channel 字段指定。
以下是如何使用通道的修饰符
static const struct iio_chan_spec light_channels[] = {
{
.type = IIO_INTENSITY,
.modified = 1,
.channel2 = IIO_MOD_LIGHT_IR,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
{
.type = IIO_INTENSITY,
.modified = 1,
.channel2 = IIO_MOD_LIGHT_BOTH,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
.info_mask_shared = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
}
此通道的定义将生成两个单独的 sysfs 文件,用于原始数据检索
/sys/bus/iio/devices/iio:deviceX/in_intensity_ir_raw
/sys/bus/iio/devices/iio:deviceX/in_intensity_both_raw
一个用于处理的数据的文件
/sys/bus/iio/devices/iio:deviceX/in_illuminance_input
一个用于采样频率的共享 sysfs 文件
/sys/bus/iio/devices/iio:deviceX/sampling_frequency
.
以下是如何使用通道的索引
static const struct iio_chan_spec light_channels[] = {
{
.type = IIO_VOLTAGE,
.indexed = 1,
.channel = 0,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
},
{
.type = IIO_VOLTAGE,
.indexed = 1,
.channel = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
},
}
这将生成两个单独的属性文件,用于原始数据检索
/sys/bus/iio/devices/iio:deviceX/in_voltage0_raw
,表示通道 0 的电压测量。/sys/bus/iio/devices/iio:deviceX/in_voltage1_raw
,表示通道 1 的电压测量。
更多详细信息¶
-
struct iio_chan_spec_ext_info¶
扩展通道信息属性
定义:
struct iio_chan_spec_ext_info {
const char *name;
enum iio_shared_by shared;
ssize_t (*read)(struct iio_dev *, uintptr_t private, struct iio_chan_spec const *, char *buf);
ssize_t (*write)(struct iio_dev *, uintptr_t private,struct iio_chan_spec const *, const char *buf, size_t len);
uintptr_t private;
};
成员
name
信息属性名称
shared
此属性是否在所有通道之间共享。
read
此信息属性的读取回调,可以为 NULL。
write
此信息属性的写入回调,可以为 NULL。
private
驱动程序私有的数据。
-
struct iio_enum¶
枚举通道信息属性
定义:
struct iio_enum {
const char * const *items;
unsigned int num_items;
int (*set)(struct iio_dev *, const struct iio_chan_spec *, unsigned int);
int (*get)(struct iio_dev *, const struct iio_chan_spec *);
};
成员
items
一个字符串数组。
num_items
项目数组的长度。
set
设置回调函数,可以为 NULL。
get
获取回调函数,可以为 NULL。
描述
iio_enum 结构可用于实现枚举样式的通道属性。 枚举样式属性是指具有一组映射到无符号整数值的字符串的属性。 IIO 枚举辅助代码负责在值和字符串之间进行映射,以及生成一个包含所有可用项目列表的 “_available” 文件。 当属性更新时,将调用设置回调。 最后一个参数是新激活的项目的索引。 获取回调将用于查询当前活动的项目,并应返回其索引。
-
IIO_ENUM¶
IIO_ENUM (_name, _shared, _e)
初始化枚举扩展通道属性
-
IIO_ENUM_AVAILABLE¶
IIO_ENUM_AVAILABLE (_name, _shared, _e)
初始化枚举可用扩展通道属性
参数
_name
属性名称(“_available” 将附加到该名称)
_shared
属性是否在所有通道之间共享
_e
指向 iio_enum 结构的指针
描述
创建一个只读属性,该属性以空格分隔的列表形式列出所有可用的枚举项。 这通常应与 IIO_ENUM()
一起使用
-
struct iio_mount_matrix¶
iio 安装矩阵
定义:
struct iio_mount_matrix {
const char *rotation[9];
};
成员
rotation
定义传感器与主硬件对齐方式的 3 维空间旋转矩阵
-
IIO_MOUNT_MATRIX¶
IIO_MOUNT_MATRIX (_shared, _get)
初始化安装矩阵扩展通道属性
参数
_shared
属性是否在所有通道之间共享
_get
指向 iio_get_mount_matrix_t 访问器的指针
-
struct iio_event_spec¶
通道事件的规范
定义:
struct iio_event_spec {
enum iio_event_type type;
enum iio_event_direction dir;
unsigned long mask_separate;
unsigned long mask_shared_by_type;
unsigned long mask_shared_by_dir;
unsigned long mask_shared_by_all;
};
成员
type
事件的类型
dir
事件的方向
mask_separate
枚举 iio_event_info 值的位掩码。 在此掩码中设置的属性将按通道注册。
mask_shared_by_type
枚举 iio_event_info 值的位掩码。 在此掩码中设置的属性将由通道类型共享。
mask_shared_by_dir
枚举 iio_event_info 值的位掩码。 在此掩码中设置的属性将由通道类型和方向共享。
mask_shared_by_all
枚举 iio_event_info 值的位掩码。 在此掩码中设置的属性将由所有通道共享。
-
struct iio_scan_type¶
缓冲区中通道数据格式的规范
定义:
struct iio_scan_type {
char sign;
u8 realbits;
u8 storagebits;
u8 shift;
u8 repeat;
enum iio_endian endianness;
};
成员
sign
‘s’ 或 ‘u’,用于指定有符号或无符号
realbits
数据的有效位数
storagebits
Realbits + 填充
shift
在屏蔽 realbits 之前,向右移动此值。
repeat
real/storage 位重复的次数。 当 repeat 元素大于 1 时,sysfs 中的 type 元素将显示一个 repeat 值。 否则,将省略重复次数。
endianness
小端或大端
-
struct iio_chan_spec¶
单个通道的规范
定义:
struct iio_chan_spec {
enum iio_chan_type type;
int channel;
int channel2;
unsigned long address;
int scan_index;
union {
struct iio_scan_type scan_type;
struct {
const struct iio_scan_type *ext_scan_type;
unsigned int num_ext_scan_type;
};
};
long info_mask_separate;
long info_mask_separate_available;
long info_mask_shared_by_type;
long info_mask_shared_by_type_available;
long info_mask_shared_by_dir;
long info_mask_shared_by_dir_available;
long info_mask_shared_by_all;
long info_mask_shared_by_all_available;
const struct iio_event_spec *event_spec;
unsigned int num_event_specs;
const struct iio_chan_spec_ext_info *ext_info;
const char *extend_name;
const char *datasheet_name;
unsigned int modified:1;
unsigned int indexed:1;
unsigned int output:1;
unsigned int differential:1;
unsigned int has_ext_scan_type:1;
};
成员
type
通道正在进行什么类型的测量。
channel
我们希望为通道分配什么编号。
channel2
如果差分通道有第二个编号,则这是它。 如果设置了 modified,则此处的值指定修饰符。
address
驱动程序特定的标识符。
scan_index
单调索引,用于在从缓冲区读取时提供扫描中的排序。
{unnamed_union}
anonymous
scan_type
描述扫描类型的结构 - 与 ext_scan_type 互斥。
{unnamed_struct}
anonymous
ext_scan_type
用于通道存在多个扫描格式的罕见情况。 当使用此选项时,必须设置标志 has_ext_scan_type,并且驱动程序必须在
struct iio_info
中实现 get_current_scan_type。num_ext_scan_type
ext_scan_type 中的元素数。
info_mask_separate
要导出哪些特定于此通道的信息。
info_mask_separate_available
要导出哪些特定于此通道的可用性信息。
info_mask_shared_by_type
要导出哪些由同一类型的所有通道共享的信息。
info_mask_shared_by_type_available
要导出哪些由同一类型的所有通道共享的可用性信息。
info_mask_shared_by_dir
要导出哪些由同一方向的所有通道共享的信息。
info_mask_shared_by_dir_available
要导出哪些由同一方向的所有通道共享的可用性信息。
info_mask_shared_by_all
要导出哪些由所有通道共享的信息。
info_mask_shared_by_all_available
要导出哪些由所有通道共享的可用性信息。
event_spec
应为此通道注册的事件数组。
num_event_specs
event_spec 数组的大小。
ext_info
此通道的扩展信息属性数组。 该数组以 NULL 结尾,最后一个元素应将其 name 字段设置为 NULL。
extend_name
允许使用信息性的名称标记通道属性。请注意,这与修改器不同,它对代码等没有影响。此字段已弃用,建议使用 iio_info->read_label() 来覆盖标签,与 extend_name 不同,它不影响 sysfs 文件名。
datasheet_name
内核中用于通道映射的名称。它应该对应于数据表中通道首次引用的名称 (例如,IND),或最接近的复合名称 (例如,IND-INC)。
modified
修改器是否应用于此通道。这些取决于通道类型。修改器在 channel2 中设置。例如,IIO_MOD_X 用于关于“x”轴的轴向传感器。
indexed
指定通道具有数字索引。如果不是,通道索引号将被 sysfs 属性抑制,但不会被事件代码抑制。
output
通道是输出。
differential
通道是差分的。
has_ext_scan_type
如果使用 ext_scan_type 代替 scan_type,则为 True。
-
bool iio_channel_has_info(const struct iio_chan_spec *chan, enum iio_chan_info_enum type)¶
检查通道是否支持信息属性
参数
const struct iio_chan_spec *chan
要查询的通道
enum iio_chan_info_enum type
要检查的信息属性的类型
描述
如果通道支持报告给定信息属性类型的值,则返回 true,否则返回 false。
-
bool iio_channel_has_available(const struct iio_chan_spec *chan, enum iio_chan_info_enum type)¶
检查通道是否具有 available 属性
参数
const struct iio_chan_spec *chan
要查询的通道
enum iio_chan_info_enum type
要检查的 available 属性的类型
描述
如果通道支持报告给定属性类型的可用值,则返回 true,否则返回 false。
-
struct iio_info¶
关于设备的常量信息
定义:
struct iio_info {
const struct attribute_group *event_attrs;
const struct attribute_group *attrs;
int (*read_raw)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2, long mask);
int (*read_raw_multi)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int max_len,int *vals,int *val_len, long mask);
int (*read_avail)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,const int **vals,int *type,int *length, long mask);
int (*write_raw)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int val,int val2, long mask);
int (*read_label)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan, char *label);
int (*write_raw_get_fmt)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan, long mask);
int (*read_event_config)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type, enum iio_event_direction dir);
int (*write_event_config)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir, bool state);
int (*read_event_value)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir, enum iio_event_info info, int *val, int *val2);
int (*write_event_value)(struct iio_dev *indio_dev,const struct iio_chan_spec *chan,enum iio_event_type type,enum iio_event_direction dir, enum iio_event_info info, int val, int val2);
int (*read_event_label)(struct iio_dev *indio_dev,struct iio_chan_spec const *chan,enum iio_event_type type,enum iio_event_direction dir, char *label);
int (*validate_trigger)(struct iio_dev *indio_dev, struct iio_trigger *trig);
int (*get_current_scan_type)(const struct iio_dev *indio_dev, const struct iio_chan_spec *chan);
int (*update_scan_mode)(struct iio_dev *indio_dev, const unsigned long *scan_mask);
int (*debugfs_reg_access)(struct iio_dev *indio_dev,unsigned int reg, unsigned int writeval, unsigned int *readval);
int (*fwnode_xlate)(struct iio_dev *indio_dev, const struct fwnode_reference_args *iiospec);
int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned int val);
int (*hwfifo_flush_to_buffer)(struct iio_dev *indio_dev, unsigned int count);
};
成员
event_attrs
事件控制属性
attrs
通用设备属性
read_raw
用于从设备请求值的函数。mask 指定哪个值。请注意,0 表示读取有问题的通道。返回值将指定设备返回的值的类型。val 和 val2 将包含构成返回值的元素。
read_raw_multi
用于从设备返回值的函数。mask 指定哪个值。请注意,0 表示读取有问题的通道。返回值将指定设备返回的值的类型。vals 指针包含构成返回值的元素。max_len 指定 vals 指针可以包含的最大元素数。val_len 用于返回 vals 中有效元素的长度。
read_avail
用于从设备返回可用值的函数。mask 指定哪个值。请注意,0 表示有问题的通道的可用值。返回值指定在 vals 中返回的是 IIO_AVAIL_LIST 还是 IIO_AVAIL_RANGE。vals 的类型在 type 中返回,vals 的数量在 length 中返回。对于范围,始终返回三个 vals:min、step 和 max。对于列表,枚举所有可能的值。
write_raw
用于将值写入设备的函数。参数与 read_raw 的参数相同。
read_label
用于请求指定标签的标签名称的函数,以便更好地识别通道。
write_raw_get_fmt
回调函数,用于查询预期的格式/精度。如果驱动程序未设置,则 write_raw 返回 IIO_VAL_INT_PLUS_MICRO。
read_event_config
查明是否启用了事件。
write_event_config
设置是否启用了事件。
read_event_value
读取与事件关联的配置值。
write_event_value
写入事件的配置值。
read_event_label
用于请求指定标签的标签名称的函数,以便更好地识别事件。
validate_trigger
当当前触发器发生更改时,用于验证触发器的函数。
get_current_scan_type
必须由在通道规范中使用 ext_scan_type 的驱动程序实现,以返回通道当前活动的 ext_scan 类型的索引。
update_scan_mode
用于在通道发生更改时配置设备和扫描缓冲区的函数
debugfs_reg_access
用于读取或写入设备寄存器值的函数
fwnode_xlate
基于 fwnode 的函数指针,用于获取通道说明符索引。
hwfifo_set_watermark
用于设置当前硬件 fifo 水位线的函数指针;有关硬件 fifo 如何运行的详细信息,请参阅 ABI 文件测试/sysfs-bus-iio 中的 hwfifo_* 条目
hwfifo_flush_to_buffer
用于将存储在硬件 fifo 中的样本刷新到设备缓冲区的函数指针。驱动程序不应刷新超过 count 个样本。该函数必须返回刷新的样本数,如果未刷新样本则返回 0,如果未刷新样本并且存在错误则返回负整数。
-
struct iio_buffer_setup_ops¶
与缓冲区设置相关的回调
定义:
struct iio_buffer_setup_ops {
int (*preenable)(struct iio_dev *);
int (*postenable)(struct iio_dev *);
int (*predisable)(struct iio_dev *);
int (*postdisable)(struct iio_dev *);
bool (*validate_scan_mask)(struct iio_dev *indio_dev, const unsigned long *scan_mask);
};
成员
preenable
[驱动程序] 在将缓冲区标记为启用之前运行的函数
postenable
[驱动程序] 在将缓冲区标记为启用之后运行的函数
predisable
[驱动程序] 在将缓冲区标记为禁用之前运行的函数
postdisable
[驱动程序] 在将缓冲区标记为禁用之后运行的函数
validate_scan_mask
[驱动程序] 用于检查给定扫描掩码对于设备是否有效的函数回调。
-
struct iio_dev¶
工业 I/O 设备
定义:
struct iio_dev {
int modes;
struct device dev;
struct iio_buffer *buffer;
int scan_bytes;
const unsigned long *available_scan_masks;
unsigned int __private masklength;
const unsigned long *active_scan_mask;
bool __private scan_timestamp;
struct iio_trigger *trig;
struct iio_poll_func *pollfunc;
struct iio_poll_func *pollfunc_event;
struct iio_chan_spec const *channels;
int num_channels;
const char *name;
const char *label;
const struct iio_info *info;
const struct iio_buffer_setup_ops *setup_ops;
void *__private priv;
};
成员
modes
[驱动程序] 列出 IIO 设备支持的所有操作模式的位掩码。此列表应在注册 IIO 设备之前初始化。它也可以由 IIO 核心填充,作为在驱动程序中启用特定功能的结果 (请参阅 iio_triggered_event_setup())。
dev
[驱动程序] 设备结构,应分配父级和所有者
buffer
[驱动程序] 任何存在的缓冲区
scan_bytes
[内部] 捕获的字节数,用于馈送到缓冲区解复用器
available_scan_masks
[驱动程序] 允许的位掩码的可选数组。按偏好顺序对数组进行排序,最优先的掩码排在最前面。
masklength
[内部] 从通道建立的掩码长度
active_scan_mask
[内部] 缓冲区请求的所有扫描掩码的并集
scan_timestamp
[内部] 如果任何缓冲区已请求时间戳,则设置
trig
[内部] 当前设备触发器(缓冲区模式)
pollfunc
[驱动程序] 在收到触发器时运行的函数
pollfunc_event
[驱动程序] 在收到事件触发器时运行的函数
channels
[驱动程序] 通道规范结构表
num_channels
[驱动程序] 在 channels 中指定的通道数。
name
[驱动程序] 设备的名称。
label
[驱动程序] 用于标识此设备的唯一名称
info
[驱动程序] 来自驱动程序的回调和常量信息
setup_ops
[驱动程序] 在缓冲区启用/禁用之前和之后调用的回调
priv
[驱动程序] 对驱动程序的私有信息的引用 必须 仅 通过 iio_priv() 辅助函数访问
-
iio_device_register¶
iio_device_register (indio_dev)
向 IIO 子系统注册设备
参数
indio_dev
由设备驱动程序填充的设备结构
-
devm_iio_device_register¶
devm_iio_device_register (dev, indio_dev)
资源管理的
iio_device_register()
参数
dev
要为其分配 iio_dev 的设备
indio_dev
由设备驱动程序填充的设备结构
描述
管理的 iio_device_register。使用此函数注册的 IIO 设备会在驱动程序分离时自动注销。此函数在内部调用 iio_device_register()
。有关更多信息,请参阅该函数。
返回
成功时返回 0,失败时返回负错误号。
-
void iio_device_put(struct iio_dev *indio_dev)¶
struct device
的引用计数取消分配
参数
struct iio_dev *indio_dev
包含设备的 IIO 设备结构
参数
struct device *dev
嵌入在 IIO 设备中的设备
注意
该设备必须是 IIO 设备,否则结果是未定义的。
参数
struct iio_dev *indio_dev
IIO 设备结构
返回
传递的 IIO 设备
参数
struct iio_dev *indio_dev
IIO 设备结构
struct device *parent
对父设备对象的引用
描述
必须在 IIO 设备分配(通过 devm_iio_device_alloc()
)& IIO 设备注册(通过 iio_device_register()
和 devm_iio_device_register()
))之间调用此实用程序。默认情况下,设备分配还会将父设备分配给 IIO 设备对象。在使用 devm_iio_device_alloc()
的情况下,有时父设备必须与用于管理分配的设备不同。在这种情况下,应使用此辅助函数来更改父设备,因此需要在分配 & 注册之间调用它。
参数
struct iio_dev *indio_dev
IIO 设备结构
void *data
特定于驱动程序的数据
描述
允许将任意指针附加到 IIO 设备,稍后可以通过 iio_device_get_drvdata()
检索该指针。
-
IIO_DECLARE_BUFFER_WITH_TS¶
IIO_DECLARE_BUFFER_WITH_TS (type, name, count)
声明带有时间戳的缓冲区
参数
type
缓冲区的元素类型
name
缓冲区的标识符名称
count
缓冲区中的元素数
描述
声明一个可以安全地与 iio_push_to_buffer_with_ts() 一起使用的缓冲区。除了为 type 的 count 元素分配足够的空间外,它还在缓冲区的末尾为 s64 时间戳分配空间,并确保时间戳的正确对齐。
-
IIO_DECLARE_DMA_BUFFER_WITH_TS¶
IIO_DECLARE_DMA_BUFFER_WITH_TS (type, name, count)
声明一个 DMA 对齐的带有时间戳的缓冲区
参数
type
缓冲区的元素类型
name
缓冲区的标识符名称
count
缓冲区中的元素数
描述
与 IIO_DECLARE_BUFFER_WITH_TS()
相同,但它使用 __aligned(IIO_DMA_MINALIGN) 来确保缓冲区不与 struct 中排在它之前的任何内容共享缓存行。这不应该用于堆栈分配的缓冲区,因为堆栈内存通常不能用于 DMA。
参数
struct iio_dev *indio_dev
设备的 IIO 设备结构
参数
struct iio_dev *indio_dev
与将暂停触发器的设备关联的 iio_dev
描述
成功时返回 0,否则返回负数
-
int iio_device_resume_triggering(struct iio_dev *indio_dev)¶
恢复附加到先前使用
iio_device_suspend_triggering()
暂停的 iio_dev 的触发器
参数
struct iio_dev *indio_dev
与将恢复触发器的设备关联的 iio_dev
描述
成功时返回 0,否则返回负数
-
const struct iio_scan_type *iio_get_current_scan_type(const struct iio_dev *indio_dev, const struct iio_chan_spec *chan)¶
获取通道的当前扫描类型
参数
const struct iio_dev *indio_dev
要获取扫描类型的 IIO 设备
const struct iio_chan_spec *chan
要获取扫描类型的通道
描述
大多数设备每个通道只有一个扫描类型,可以直接访问而无需调用此函数。在通道规范中实现 ext_scan_type 的核心 IIO 代码和驱动程序应使用此函数来获取通道的当前扫描类型。
返回
通道的当前扫描类型或错误。
参数
const struct iio_dev *indio_dev
要获取掩码长度的 IIO 设备
-
iio_for_each_active_channel¶
iio_for_each_active_channel (indio_dev, chan)
迭代活动通道
参数
indio_dev
IIO 设备
chan
保存已启用通道的索引
-
IIO_DEGREE_TO_RAD¶
IIO_DEGREE_TO_RAD (deg)
将度数转换为弧度
参数
deg
以度数为单位的值
描述
返回从度数转换为弧度的给定值
-
IIO_RAD_TO_DEGREE¶
IIO_RAD_TO_DEGREE (rad)
将弧度转换为度数
参数
rad
以弧度为单位的值
描述
返回从弧度转换为度数的给定值
-
IIO_G_TO_M_S_2¶
IIO_G_TO_M_S_2 (g)
将 g 转换为米/秒**2
参数
g
以 g 为单位的值
描述
返回从 g 转换为米/秒**2 的给定值
-
IIO_M_S_2_TO_G¶
IIO_M_S_2_TO_G (ms2)
将米/秒**2 转换为 g
参数
ms2
以米/秒**2 为单位的值
描述
返回从米/秒**2 转换为 g 的给定值
参数
struct iio_dev *indio_dev
正在查询其 ID 的设备结构
描述
IIO 设备 ID 是一个唯一的索引,例如用于字符设备 /dev/iio:device[ID] 的命名。
返回
设备的唯一 ID。
参数
struct iio_dev *indio_dev
设备的 IIO 设备结构
返回
如果启用了缓冲区,则为 True。
参数
struct iio_dev *indio_dev
包含设备的 IIO 设备结构
clockid_t clock_id
要设置的时间戳时钟 POSIX 标识符。
返回
成功时为 0,或为负错误代码。
参数
const struct iio_dev *indio_dev
包含设备的 IIO 设备结构
返回
设备的当前时间戳时钟的时钟 ID。
参数
const struct iio_dev *indio_dev
设备
返回
事件的时间戳,以纳秒为单位。
-
int iio_read_mount_matrix(struct device *dev, struct iio_mount_matrix *matrix)¶
从设备 "mount-matrix" 属性检索 iio 设备安装矩阵
参数
struct device *dev
分配了安装矩阵属性的设备
struct iio_mount_matrix *matrix
存储检索到的矩阵的位置
描述
如果设备未分配任何安装矩阵属性,则将填充默认的 3x3 单位矩阵。
返回
成功时为 0,失败时为负错误代码。
-
ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)¶
将 IIO 值格式化为其字符串表示形式
参数
char *buf
格式化值写入的缓冲区,假设它足够大(即 PAGE_SIZE)。
unsigned int type
IIO_VAL_* 常量之一。 这决定了 val 和 val2 参数的格式。
int size
vals 中包含的 IIO 值条目的数量
int *vals
指向值的指针,确切含义取决于 type 参数。
返回
默认为 0,失败时为负数,或者属于 IIO_VAL_* 常量的类型的总写入字符数。
-
int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer, int *fract)¶
从字符串解析定点数
参数
const char *str
要解析的字符串
int fract_mult
第一位小数的乘数,应为 10 的幂
int *integer
数字的整数部分
int *fract
数字的小数部分
返回
成功时为 0,如果无法解析字符串,则为负错误代码。
参数
struct device *parent
父设备。
int sizeof_priv
要为私有结构分配的空间。
返回
成功时指向已分配的 iio_dev 的指针,失败时为 NULL。
参数
struct iio_dev *dev
与设备关联的 iio_dev
-
struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)¶
资源管理的
iio_device_alloc()
参数
struct device *parent
为其分配 iio_dev 的设备,以及此 IIO 设备的父设备
int sizeof_priv
要为私有结构分配的空间。
描述
托管的 iio_device_alloc。 使用此函数分配的 iio_dev 会在驱动程序分离时自动释放。
返回
成功时指向已分配的 iio_dev 的指针,失败时为 NULL。
参数
struct iio_dev *indio_dev
包含活动和可用扫描掩码的 IIO 设备
返回
如果未设置 active_scan_mask,则为索引或 -EINVAL
参数
struct iio_dev *indio_dev
表示设备的设备结构。
参数
struct iio_dev *indio_dev
与设备关联的 iio_dev
描述
如果设备处于直接模式,则保证保持该状态,直到调用 __iio_device_release_direct()
为止。
与 __iio_device_release_direct()
一起使用。
驱动程序应仅调用 iio_device_claim_direct()。
返回
成功时为 true,失败时为 false。
参数
struct iio_dev *indio_dev
与设备关联的 iio_dev
描述
释放声明。 不再保证设备保持在直接模式。
驱动程序应仅调用 iio_device_release_direct()。
与 __iio_device_claim_direct()
一起使用
参数
struct iio_dev *indio_dev
与设备关联的 iio_dev
描述
如果设备处于缓冲区模式,则保证保持该状态,直到调用 iio_device_release_buffer_mode()
为止。
与 iio_device_release_buffer_mode()
一起使用。
返回
成功时为 0,失败时为 -EBUSY。
参数
struct iio_dev *indio_dev
与设备关联的 iio_dev
描述
释放声明。 不再保证设备保持在缓冲区模式。
与 iio_device_claim_buffer_mode()
一起使用。
参数
struct iio_dev *indio_dev
设备的 IIO 设备结构