← Documents Documentation/leds/ledtrig-transient.rst GitHub 원문 ↗

Linux 6.18.37 · LEDs

LED Transient Trigger

activate·state·duration으로 단발 상태를 유지하고 자동 복원하는 trigger입니다.

Source pathDocumentation/leds/ledtrig-transient.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

ledtrig-transient.rst:1-160

Transient trigger는 한 번만 상태를 유지한 뒤 반대 상태로 자동 복귀하므로 application 종료에도 상태가 남지 않습니다.

Suspend 동안 timer는 흐르지만 LED update는 멈추며, 실행 중 timer의 연장·단축은 지원하지 않습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 =====================
2 LED Transient Trigger
3 =====================
4
5 The leds timer trigger does not currently have an interface to activate
6 a one shot timer. The current support allows for setting two timers, one for
7 specifying how long a state to be on, and the second for how long the state
8 to be off. The delay_on value specifies the time period an LED should stay
9 in on state, followed by a delay_off value that specifies how long the LED
10 should stay in off state. The on and off cycle repeats until the trigger
11 gets deactivated. There is no provision for one time activation to implement
12 features that require an on or off state to be held just once and then stay in
13 the original state forever.
14
15 Without one shot timer interface, user space can still use timer trigger to
16 set a timer to hold a state, however when user space application crashes or
17 goes away without deactivating the timer, the hardware will be left in that
18 state permanently.
19
20 Transient trigger addresses the need for one shot timer activation. The
21 transient trigger can be enabled and disabled just like the other leds
22 triggers.
23
24 When an led class device driver registers itself, it can specify all leds
25 triggers it supports and a default trigger. During registration, activation
26 routine for the default trigger gets called. During registration of an led
27 class device, the LED state does not change.
28
29 When the driver unregisters, deactivation routine for the currently active
30 trigger will be called, and LED state is changed to LED_OFF.
31
32 Driver suspend changes the LED state to LED_OFF and resume doesn't change
33 the state. Please note that there is no explicit interaction between the
34 suspend and resume actions and the currently enabled trigger. LED state
35 changes are suspended while the driver is in suspend state. Any timers
36 that are active at the time driver gets suspended, continue to run, without
37 being able to actually change the LED state. Once driver is resumed, triggers
38 start functioning again.
39
40 LED state changes are controlled using brightness which is a common led
41 class device property. When brightness is set to 0 from user space via
42 echo 0 > brightness, it will result in deactivating the current trigger.
43
44 Transient trigger uses standard register and unregister interfaces. During
45 trigger registration, for each led class device that specifies this trigger
46 as its default trigger, trigger activation routine will get called. During
47 registration, the LED state does not change, unless there is another trigger
48 active, in which case LED state changes to LED_OFF.
49
50 During trigger unregistration, LED state gets changed to LED_OFF.
51
52 Transient trigger activation routine doesn't change the LED state. It
53 creates its properties and does its initialization. Transient trigger
54 deactivation routine, will cancel any timer that is active before it cleans
55 up and removes the properties it created. It will restore the LED state to
56 non-transient state. When driver gets suspended, irrespective of the transient
57 state, the LED state changes to LED_OFF.
58
59 Transient trigger can be enabled and disabled from user space on led class
60 devices, that support this trigger as shown below::
61
62 echo transient > trigger
63 echo none > trigger
64
65 NOTE:
66 Add a new property trigger state to control the state.
67
68 This trigger exports three properties, activate, state, and duration. When
69 transient trigger is activated these properties are set to default values.
70
71 - duration allows setting timer value in msecs. The initial value is 0.
72 - activate allows activating and deactivating the timer specified by
73 duration as needed. The initial and default value is 0. This will allow
74 duration to be set after trigger activation.
75 - state allows user to specify a transient state to be held for the specified
76 duration.
77
78 activate
79 - one shot timer activate mechanism.
80 1 when activated, 0 when deactivated.
81 default value is zero when transient trigger is enabled,
82 to allow duration to be set.
83
84 activate state indicates a timer with a value of specified
85 duration running.
86 deactivated state indicates that there is no active timer
87 running.
88
89 duration
90 - one shot timer value. When activate is set, duration value
91 is used to start a timer that runs once. This value doesn't
92 get changed by the trigger unless user does a set via
93 echo new_value > duration
94
95 state
96 - transient state to be held. It has two values 0 or 1. 0 maps
97 to LED_OFF and 1 maps to LED_FULL. The specified state is
98 held for the duration of the one shot timer and then the
99 state gets changed to the non-transient state which is the
100 inverse of transient state.
101 If state = LED_FULL, when the timer runs out the state will
102 go back to LED_OFF.
103 If state = LED_OFF, when the timer runs out the state will
104 go back to LED_FULL.
105 Please note that current LED state is not checked prior to
106 changing the state to the specified state.
107 Driver could map these values to inverted depending on the
108 default states it defines for the LED in its brightness_set()
109 interface which is called from the led brightness_set()
110 interfaces to control the LED state.
111
112 When timer expires activate goes back to deactivated state, duration is left
113 at the set value to be used when activate is set at a future time. This will
114 allow user app to set the time once and activate it to run it once for the
115 specified value as needed. When timer expires, state is restored to the
116 non-transient state which is the inverse of the transient state:
117
118 ================= ===============================================
119 echo 1 > activate starts timer = duration when duration is not 0.
120 echo 0 > activate cancels currently running timer.
121 echo n > duration stores timer value to be used upon next
122 activate. Currently active timer if
123 any, continues to run for the specified time.
124 echo 0 > duration stores timer value to be used upon next
125 activate. Currently active timer if any,
126 continues to run for the specified time.
127 echo 1 > state stores desired transient state LED_FULL to be
128 held for the specified duration.
129 echo 0 > state stores desired transient state LED_OFF to be
130 held for the specified duration.
131 ================= ===============================================
132
133 What is not supported
134 =====================
135
136 - Timer activation is one shot and extending and/or shortening the timer
137 is not supported.
138
139 Examples
140 ========
141
142 use-case 1::
143
144 echo transient > trigger
145 echo n > duration
146 echo 1 > state
147
148 repeat the following step as needed::
149
150 echo 1 > activate - start timer = duration to run once
151 echo 1 > activate - start timer = duration to run once
152 echo none > trigger
153
154 This trigger is intended to be used for the following example use cases:
155
156 - Use of LED by user space app as activity indicator.
157 - Use of LED by user space app as a kind of watchdog indicator -- as
158 long as the app is alive, it can keep the LED illuminated, if it dies
159 the LED will be extinguished automatically.
160 - Use by any user space app that needs a transient GPIO output.
161

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Transient trigger가 필요한 이유

1-32

기존 LED timer trigger는 one-shot timer 활성화 interface가 없습니다. `delay_on`과 `delay_off`로 on·off 시간을 정하면 trigger를 비활성화할 때까지 cycle이 반복되므로, 한 상태를 딱 한 번 유지한 뒤 영구히 원래 상태로 돌아가는 동작을 직접 표현하지 못합니다.

Userspace가 timer trigger로 비슷한 동작을 만들 수는 있지만 application이 timer를 해제하지 못한 채 crash하거나 종료되면 hardware가 그 상태에 영구히 남을 수 있습니다.

Transient trigger는 한 번만 실행되는 timer를 제공하며 다른 LED trigger와 같은 방식으로 활성화·비활성화할 수 있습니다.

LED class driver 등록 때 지원 trigger와 default trigger를 지정할 수 있고 default의 activation routine이 호출되지만, 등록 자체는 LED 상태를 바꾸지 않습니다. Driver unregister 때는 현재 trigger의 deactivation routine이 호출되고 LED가 `LED_OFF`로 바뀝니다.

Timer와 transient 비교
기능Timer triggerTransient trigger
동작On·off cycle 반복한 번만 상태 유지
종료Trigger 비활성화 필요Duration 만료 후 자동 복귀
Application crash상태가 남을 수 있음Timer 만료로 복귀

반복 timer가 해결하지 못하는 단발 상태 유지 문제입니다.

=====================
LED Transient Trigger
=====================

The leds timer trigger does not currently have an interface to activate
a one shot timer. The current support allows for setting two timers, one for
specifying how long a state to be on, and the second for how long the state
to be off. The delay_on value specifies the time period an LED should stay
in on state, followed by a delay_off value that specifies how long the LED
should stay in off state. The on and off cycle repeats until the trigger
gets deactivated. There is no provision for one time activation to implement
features that require an on or off state to be held just once and then stay in
the original state forever.

Without one shot timer interface, user space can still use timer trigger to
set a timer to hold a state, however when user space application crashes or
goes away without deactivating the timer, the hardware will be left in that
state permanently.

Transient trigger addresses the need for one shot timer activation. The
transient trigger can be enabled and disabled just like the other leds
triggers.

When an led class device driver registers itself, it can specify all leds
triggers it supports and a default trigger. During registration, activation
routine for the default trigger gets called. During registration of an led
class device, the LED state does not change.

When the driver unregisters, deactivation routine for the currently active
trigger will be called, and LED state is changed to LED_OFF.

Driver suspend changes the LED state to LED_OFF and resume doesn't change

Suspend·resume와 trigger 등록

33-63

Driver suspend는 LED를 `LED_OFF`로 바꾸고 resume 자체는 상태를 바꾸지 않습니다. Suspend·resume와 현재 trigger 사이에는 명시적인 상호작용이 없습니다.

Suspend 동안 LED 상태 변경은 멈추지만 이미 active인 timer는 계속 진행됩니다. 이 동안 timer가 hardware LED 상태를 실제로 바꾸지는 못하며, resume 뒤 trigger가 다시 동작합니다.

Brightness는 공통 LED class property입니다. Userspace가 `echo 0 > brightness`를 실행하면 현재 trigger가 비활성화됩니다.

Transient trigger는 표준 register·unregister interface를 사용합니다. 등록 때 default로 지정한 device에서 activation routine이 호출되며 보통 상태는 유지되지만 다른 trigger가 active하면 `LED_OFF`로 바뀝니다. Trigger unregister는 LED를 `LED_OFF`로 바꿉니다.

Activation routine은 LED 상태를 바꾸지 않고 property 생성과 초기화만 수행합니다. Deactivation routine은 active timer를 취소하고 property를 제거한 뒤 non-transient 상태를 복원합니다.

Suspend 중 transient timer
Driver suspend: LED를 `LED_OFF`로 설정Active timer는 계속 실행Suspend 중 LED state update는 hardware에 적용되지 않음Driver resume: 상태를 직접 바꾸지 않음Resume 뒤 trigger 동작 재개

Timer 시간은 흐르지만 hardware 상태 변경은 정지합니다.

the state. Please note that there is no explicit interaction between the
suspend and resume actions and the currently enabled trigger. LED state
changes are suspended while the driver is in suspend state. Any timers
that are active at the time driver gets suspended, continue to run, without
being able to actually change the LED state. Once driver is resumed, triggers
start functioning again.

LED state changes are controlled using brightness which is a common led
class device property. When brightness is set to 0 from user space via
echo 0 > brightness, it will result in deactivating the current trigger.

Transient trigger uses standard register and unregister interfaces. During
trigger registration, for each led class device that specifies this trigger
as its default trigger, trigger activation routine will get called. During
registration, the LED state does not change, unless there is another trigger
active, in which case LED state changes to LED_OFF.

During trigger unregistration, LED state gets changed to LED_OFF.

Transient trigger activation routine doesn't change the LED state. It
creates its properties and does its initialization. Transient trigger
deactivation routine, will cancel any timer that is active before it cleans
up and removes the properties it created. It will restore the LED state to
non-transient state. When driver gets suspended, irrespective of the transient
state, the LED state changes to LED_OFF.

Transient trigger can be enabled and disabled from user space on led class
devices, that support this trigger as shown below::

        echo transient > trigger
        echo none > trigger

activate·state·duration property

64-103

Userspace는 `echo transient > trigger`로 활성화하고 `echo none > trigger`로 비활성화합니다. Trigger가 노출하는 property는 `activate`, `state`, `duration` 세 개이며 활성화 시 기본값으로 초기화됩니다.

`duration`은 millisecond 단위 one-shot timer 값이고 초기값은 0입니다. `activate`는 이 duration을 사용하는 timer를 시작하거나 취소하며 초기·기본값은 0입니다. 먼저 trigger를 활성화한 뒤 duration을 설정할 수 있도록 이렇게 설계되었습니다.

`activate = 1`은 지정 duration timer가 실행 중임을 뜻하고 `0`은 active timer가 없음을 뜻합니다. `duration`을 다시 쓰더라도 이미 실행 중인 timer는 원래 시간으로 계속 실행됩니다.

`state`는 duration 동안 유지할 transient 상태입니다. `0`은 `LED_OFF`, `1`은 `LED_FULL`이며 만료 뒤에는 그 반대인 non-transient 상태로 바뀝니다. 현재 LED 상태는 transient 상태를 적용하기 전에 검사하지 않습니다.

Driver의 `brightness_set()` 구현이 기본 LED polarity를 반대로 mapping할 수 있으므로 실제 hardware level은 driver 정의에 따라 invert될 수 있습니다.

Transient trigger property
Property의미
`duration`ms, 기본 0다음 one-shot 실행 시간 저장
`activate`1저장된 duration으로 timer 시작
`activate`0실행 중 timer 취소
`state`1Duration 동안 `LED_FULL`, 만료 후 `LED_OFF`
`state`0Duration 동안 `LED_OFF`, 만료 후 `LED_FULL`

세 property의 값과 부작용입니다.


NOTE:
        Add a new property trigger state to control the state.

This trigger exports three properties, activate, state, and duration. When
transient trigger is activated these properties are set to default values.

- duration allows setting timer value in msecs. The initial value is 0.
- activate allows activating and deactivating the timer specified by
  duration as needed. The initial and default value is 0.  This will allow
  duration to be set after trigger activation.
- state allows user to specify a transient state to be held for the specified
  duration.

        activate
              - one shot timer activate mechanism.
                1 when activated, 0 when deactivated.
                default value is zero when transient trigger is enabled,
                to allow duration to be set.

                activate state indicates a timer with a value of specified
                duration running.
                deactivated state indicates that there is no active timer
                running.

        duration
              - one shot timer value. When activate is set, duration value
                is used to start a timer that runs once. This value doesn't
                get changed by the trigger unless user does a set via
                echo new_value > duration

        state
              - transient state to be held. It has two values 0 or 1. 0 maps
                to LED_OFF and 1 maps to LED_FULL. The specified state is
                held for the duration of the one shot timer and then the
                state gets changed to the non-transient state which is the
                inverse of transient state.
                If state = LED_FULL, when the timer runs out the state will
                go back to LED_OFF.
                If state = LED_OFF, when the timer runs out the state will

Timer 만료와 command 의미

104-134

Timer가 만료되면 `activate`는 0인 deactivated 상태로 돌아갑니다. `duration`은 설정값을 유지하므로 application은 시간을 한 번만 정한 뒤 필요할 때마다 `activate = 1`로 같은 one-shot을 실행할 수 있습니다.

만료 시 LED는 transient state의 반대인 non-transient state로 복원됩니다. `state = LED_FULL`이었다면 `LED_OFF`, `state = LED_OFF`였다면 `LED_FULL`로 돌아갑니다.

`echo n > duration`이나 `echo 0 > duration`은 다음 activate에 사용할 값만 저장하며 현재 active timer의 남은 시간을 늘리거나 줄이지 않습니다. 이 trigger는 실행 중 timer 연장·단축을 지원하지 않습니다.

Transient sysfs command
명령결과
`echo 1 > activate`Duration이 0이 아니면 one-shot 시작
`echo 0 > activate`현재 timer 취소
`echo n > duration`다음 실행 시간 저장, 현재 timer는 계속
`echo 0 > duration`다음 실행값 0 저장, 현재 timer는 계속
`echo 1 > state`Transient state를 `LED_FULL`로 저장
`echo 0 > state`Transient state를 `LED_OFF`로 저장

현재 timer와 다음 실행에 미치는 영향을 구분합니다.

                go back to LED_FULL.
                Please note that current LED state is not checked prior to
                changing the state to the specified state.
                Driver could map these values to inverted depending on the
                default states it defines for the LED in its brightness_set()
                interface which is called from the led brightness_set()
                interfaces to control the LED state.

When timer expires activate goes back to deactivated state, duration is left
at the set value to be used when activate is set at a future time. This will
allow user app to set the time once and activate it to run it once for the
specified value as needed. When timer expires, state is restored to the
non-transient state which is the inverse of the transient state:

        =================   ===============================================
        echo 1 > activate   starts timer = duration when duration is not 0.
        echo 0 > activate   cancels currently running timer.
        echo n > duration   stores timer value to be used upon next
                            activate. Currently active timer if
                            any, continues to run for the specified time.
        echo 0 > duration   stores timer value to be used upon next
                            activate. Currently active timer if any,
                            continues to run for the specified time.
        echo 1 > state      stores desired transient state LED_FULL to be
                            held for the specified duration.
        echo 0 > state      stores desired transient state LED_OFF to be
                            held for the specified duration.
        =================   ===============================================

What is not supported
=====================

제약과 활용 사례

135-160

지원하지 않는 기능은 active timer의 연장과 단축입니다. Timer activation은 항상 one-shot입니다.

예제는 trigger를 `transient`로 선택하고 duration `n`과 `state = 1`을 저장한 뒤 필요할 때마다 `activate = 1`을 써서 한 번 실행합니다. 작업이 끝나면 `trigger = none`으로 해제합니다.

주요 활용은 userspace activity indicator, application 생존 여부를 나타내는 watchdog indicator, transient GPIO output입니다. Watchdog 용도에서는 application이 살아 있는 동안 LED를 계속 재활성화하고, application이 죽으면 timer 만료로 LED가 자동 소등됩니다.

Transient 반복 사용
`trigger = transient``duration = n`, `state = 1` 설정필요할 때 `activate = 1`Timer 만료 후 반대 상태로 자동 복귀같은 설정으로 `activate = 1` 재사용종료 시 `trigger = none`

Duration과 state는 유지하고 activate만 반복합니다.


- Timer activation is one shot and extending and/or shortening the timer
  is not supported.

Examples
========

use-case 1::

        echo transient > trigger
        echo n > duration
        echo 1 > state

repeat the following step as needed::

        echo 1 > activate - start timer = duration to run once
        echo 1 > activate - start timer = duration to run once
        echo none > trigger

This trigger is intended to be used for the following example use cases:

 - Use of LED by user space app as activity indicator.
 - Use of LED by user space app as a kind of watchdog indicator -- as
   long as the app is alive, it can keep the LED illuminated, if it dies
   the LED will be extinguished automatically.
 - Use by any user space app that needs a transient GPIO output.