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