Documentation/driver-api/iio/triggers.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

Triggers

Hardware·GPIO·timer·userspace IIO trigger source, sysfs association, registration과 operation callback을 설명합니다.

Source pathDocumentation/driver-api/iio/triggers.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

triggers.rst:1-78

IIO trigger는 sensor 내부 event뿐 아니라 독립 GPIO·timer·userspace source에서도 생성할 수 있고 여러 sensor가 공유할 수도 있습니다. Trigger object를 등록한 뒤 current_trigger로 device에 연결하며 ops가 state와 association을 검증합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ========
2 Triggers
3 ========
4
5 * struct iio_trigger — industrial I/O trigger device
6 * :c:func:`devm_iio_trigger_alloc` — Resource-managed iio_trigger_alloc
7 * :c:func:`devm_iio_trigger_register` — Resource-managed iio_trigger_register
8 iio_trigger_unregister
9 * :c:func:`iio_trigger_validate_own_device` — Check if a trigger and IIO
10 device belong to the same device
11
12 In many situations it is useful for a driver to be able to capture data based
13 on some external event (trigger) as opposed to periodically polling for data.
14 An IIO trigger can be provided by a device driver that also has an IIO device
15 based on hardware generated events (e.g. data ready or threshold exceeded) or
16 provided by a separate driver from an independent interrupt source (e.g. GPIO
17 line connected to some external system, timer interrupt or user space writing
18 a specific file in sysfs). A trigger may initiate data capture for a number of
19 sensors and also it may be completely unrelated to the sensor itself.
20
21 IIO trigger sysfs interface
22 ===========================
23
24 There are two locations in sysfs related to triggers:
25
26 * :file:`/sys/bus/iio/devices/trigger{Y}/*`, this file is created once an
27 IIO trigger is registered with the IIO core and corresponds to trigger
28 with index Y.
29 Because triggers can be very different depending on type there are few
30 standard attributes that we can describe here:
31
32 * :file:`name`, trigger name that can be later used for association with a
33 device.
34 * :file:`sampling_frequency`, some timer based triggers use this attribute to
35 specify the frequency for trigger calls.
36
37 * :file:`/sys/bus/iio/devices/iio:device{X}/trigger/*`, this directory is
38 created once the device supports a triggered buffer. We can associate a
39 trigger with our device by writing the trigger's name in the
40 :file:`current_trigger` file.
41
42 IIO trigger setup
43 =================
44
45 Let's see a simple example of how to setup a trigger to be used by a driver::
46
47 struct iio_trigger_ops trigger_ops = {
48 .set_trigger_state = sample_trigger_state,
49 .validate_device = sample_validate_device,
50 }
51
52 struct iio_trigger *trig;
53
54 /* first, allocate memory for our trigger */
55 trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx);
56
57 /* setup trigger operations field */
58 trig->ops = &trigger_ops;
59
60 /* now register the trigger with the IIO core */
61 iio_trigger_register(trig);
62
63 IIO trigger ops
64 ===============
65
66 * struct iio_trigger_ops — operations structure for an iio_trigger.
67
68 Notice that a trigger has a set of operations attached:
69
70 * :file:`set_trigger_state`, switch the trigger on/off on demand.
71 * :file:`validate_device`, function to validate the device when the current
72 trigger gets changed.
73
74 More details
75 ============
76 .. kernel-doc:: include/linux/iio/trigger.h
77 .. kernel-doc:: drivers/iio/industrialio-trigger.c
78 :export:
79

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 자체와 전혀 관련이 없을 수도 있습니다.

IIO trigger source
SourceSensor 관계
IIO device hardwareData ready, threshold exceeded같은 device driver
Independent interruptGPIO line, timer IRQ별도 driver 가능
Userspace특정 sysfs file writeSoftware-generated
Shared trigger여러 sensor captureSensor와 무관할 수도 있음

Sensor 내부와 독립 source를 구분합니다.

IIO trigger sysfs interface

21-41

Trigger 관련 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 sysfs 위치
Path생성 조건내용
/sys/bus/iio/devices/trigger{Y}/*Trigger 등록name, optional sampling_frequency
/sys/bus/iio/devices/iio:device{X}/trigger/*Device가 triggered buffer 지원current_trigger association

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);
Trigger registration
iio_trigger_ops 정의set_trigger_state·validate_device 지정iio_trigger_alloc()trig->ops 연결iio_trigger_register()Trigger sysfs object 생성

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를 검증합니다.

iio_trigger_ops
Operation역할
set_trigger_state요청에 따라 trigger on/off
validate_devicecurrent trigger 변경 시 device 검증

Trigger state와 association 검증 callback입니다.

Trigger kernel API source

74-78

Trigger 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:
IIO trigger kernel-doc source
범위Source path
Trigger declarationinclude/linux/iio/trigger.h
Exported trigger coredrivers/iio/industrialio-trigger.c

Header와 exported core source입니다.