ledtrig-transient.txt 7.2 KB

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