요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
========
Triggers
========
* struct iio_trigger — industrial I/O trigger device
* :c:func:`devm_iio_trigger_alloc` — Resource-managed iio_trigger_alloc
* :c:func:`devm_iio_trigger_register` — Resource-managed iio_trigger_register
iio_trigger_unregister
* :c:func:`iio_trigger_validate_own_device` — Check if a trigger and IIO
device belong to the same device
In many situations it is useful for a driver to be able to capture data based
on some external event (trigger) as opposed to periodically polling for data.
An IIO trigger can be provided by a device driver that also has an IIO device
based on hardware generated events (e.g. data ready or threshold exceeded) or
provided by a separate driver from an independent interrupt source (e.g. GPIO
line connected to some external system, timer interrupt or user space writing
a specific file in sysfs). A trigger may initiate data capture for a number of
sensors and also it may be completely unrelated to the sensor itself.
IIO trigger sysfs interface
===========================
There are two locations in sysfs related to triggers:
* :file:`/sys/bus/iio/devices/trigger{Y}/*`, this file is created once an
IIO trigger is registered with the IIO core and corresponds to trigger
with index Y.
Because triggers can be very different depending on type there are few
standard attributes that we can describe here:
* :file:`name`, trigger name that can be later used for association with a
device.
* :file:`sampling_frequency`, some timer based triggers use this attribute to
specify the frequency for trigger calls.
* :file:`/sys/bus/iio/devices/iio:device{X}/trigger/*`, this directory is
created once the device supports a triggered buffer. We can associate a
trigger with our device by writing the trigger's name in the
:file:`current_trigger` file.
IIO trigger setup
=================
Let's see a simple example of how to setup a trigger to be used by a driver::
struct iio_trigger_ops trigger_ops = {
.set_trigger_state = sample_trigger_state,
.validate_device = sample_validate_device,
}
struct iio_trigger *trig;
/* first, allocate memory for our trigger */
trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx);
/* setup trigger operations field */
trig->ops = &trigger_ops;
/* now register the trigger with the IIO core */
iio_trigger_register(trig);
IIO trigger ops
===============
* struct iio_trigger_ops — operations structure for an iio_trigger.
Notice that a trigger has a set of operations attached:
* :file:`set_trigger_state`, switch the trigger on/off on demand.
* :file:`validate_device`, function to validate the device when the current
trigger gets changed.
More details
============
.. kernel-doc:: include/linux/iio/trigger.h
.. kernel-doc:: drivers/iio/industrialio-trigger.c
:export:
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
IIO trigger 개요
1-20문서 제목은 `Triggers`입니다. `struct iio_trigger`는 industrial I/O trigger device입니다. `devm_iio_trigger_alloc`과 `devm_iio_trigger_register`는 resource-managed allocation·registration을 제공하고 `iio_trigger_validate_own_device`는 trigger와 IIO device가 같은 device에 속하는지 확인합니다.
주기적으로 data를 polling하는 대신 external event, 즉 trigger를 기준으로 capture하는 편이 유용한 경우가 많습니다. Trigger는 IIO device도 가진 driver가 data-ready나 threshold-exceeded 같은 hardware event로 제공할 수 있습니다.
또는 별도 driver가 GPIO line, timer interrupt, userspace의 특정 sysfs file write 같은 독립 interrupt source에서 trigger를 제공할 수 있습니다. Trigger 하나가 여러 sensor의 capture를 시작할 수도 있고 sensor 자체와 전혀 관련이 없을 수도 있습니다.
Sensor 내부와 독립 source를 구분합니다.
IIO trigger sysfs interface
21-41Trigger 관련 sysfs 위치는 두 곳입니다. `/sys/bus/iio/devices/trigger{Y}/*`는 IIO trigger를 core에 등록하면 생성되며 index Y인 trigger를 나타냅니다.
Trigger type이 매우 다양해 standard attribute는 적습니다. `name`은 나중에 device와 연결할 때 쓰는 trigger 이름이고, 일부 timer-based trigger의 `sampling_frequency`는 trigger call frequency를 지정합니다.
`/sys/bus/iio/devices/iio:device{X}/trigger/*` directory는 device가 triggered buffer를 지원하면 생성됩니다. `current_trigger` file에 trigger name을 쓰면 그 trigger를 device와 연결합니다.
Trigger object와 device association directory를 구분합니다.
IIO trigger setup
42-62간단한 setup은 `iio_trigger_ops`에 `set_trigger_state`와 `validate_device` callback을 지정하고, `iio_trigger_alloc`으로 memory를 할당한 뒤 `trig->ops`를 설정하고 `iio_trigger_register`로 IIO core에 등록합니다.
struct iio_trigger_ops trigger_ops = {
.set_trigger_state = sample_trigger_state,
.validate_device = sample_validate_device,
}
struct iio_trigger *trig;
/* first, allocate memory for our trigger */
trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx);
/* setup trigger operations field */
trig->ops = &trigger_ops;
/* now register the trigger with the IIO core */
iio_trigger_register(trig);
Operation 정의에서 core 등록까지의 순서입니다.
IIO trigger operation
63-73`struct iio_trigger_ops`는 `iio_trigger` operation structure입니다. Trigger에는 operation 집합이 연결됩니다.
`set_trigger_state`는 요청에 따라 trigger를 on/off합니다. `validate_device`는 current trigger가 바뀔 때 device를 검증합니다.
Trigger state와 association 검증 callback입니다.
Trigger kernel API source
74-78Trigger public declaration은 `include/linux/iio/trigger.h`, exported implementation은 `drivers/iio/industrialio-trigger.c`의 kernel-doc에서 가져옵니다.
.. kernel-doc:: include/linux/iio/trigger.h
.. kernel-doc:: drivers/iio/industrialio-trigger.c
:export:
Header와 exported core source입니다.
요약과 해설
triggers.rst:1-78IIO trigger는 sensor 내부 event뿐 아니라 독립 GPIO·timer·userspace source에서도 생성할 수 있고 여러 sensor가 공유할 수도 있습니다. Trigger object를 등록한 뒤 current_trigger로 device에 연결하며 ops가 state와 association을 검증합니다.