xref: /openbmc/linux/Documentation/leds/ledtrig-transient.rst (revision b7ecdb00daa7ef5dc61e08e6a030cb93497b292b)
18dab9197SMauro Carvalho Chehab=====================
28dab9197SMauro Carvalho ChehabLED Transient Trigger
38dab9197SMauro Carvalho Chehab=====================
48dab9197SMauro Carvalho Chehab
58dab9197SMauro Carvalho ChehabThe leds timer trigger does not currently have an interface to activate
68dab9197SMauro Carvalho Chehaba one shot timer. The current support allows for setting two timers, one for
78dab9197SMauro Carvalho Chehabspecifying how long a state to be on, and the second for how long the state
88dab9197SMauro Carvalho Chehabto be off. The delay_on value specifies the time period an LED should stay
98dab9197SMauro Carvalho Chehabin on state, followed by a delay_off value that specifies how long the LED
108dab9197SMauro Carvalho Chehabshould stay in off state. The on and off cycle repeats until the trigger
118dab9197SMauro Carvalho Chehabgets deactivated. There is no provision for one time activation to implement
128dab9197SMauro Carvalho Chehabfeatures that require an on or off state to be held just once and then stay in
138dab9197SMauro Carvalho Chehabthe original state forever.
148dab9197SMauro Carvalho Chehab
158dab9197SMauro Carvalho ChehabWithout one shot timer interface, user space can still use timer trigger to
168dab9197SMauro Carvalho Chehabset a timer to hold a state, however when user space application crashes or
178dab9197SMauro Carvalho Chehabgoes away without deactivating the timer, the hardware will be left in that
188dab9197SMauro Carvalho Chehabstate permanently.
198dab9197SMauro Carvalho Chehab
208dab9197SMauro Carvalho ChehabAs a specific example of this use-case, let's look at vibrate feature on
218dab9197SMauro Carvalho Chehabphones. Vibrate function on phones is implemented using PWM pins on SoC or
228dab9197SMauro Carvalho ChehabPMIC. There is a need to activate one shot timer to control the vibrate
238dab9197SMauro Carvalho Chehabfeature, to prevent user space crashes leaving the phone in vibrate mode
248dab9197SMauro Carvalho Chehabpermanently causing the battery to drain.
258dab9197SMauro Carvalho Chehab
268dab9197SMauro Carvalho ChehabTransient trigger addresses the need for one shot timer activation. The
278dab9197SMauro Carvalho Chehabtransient trigger can be enabled and disabled just like the other leds
288dab9197SMauro Carvalho Chehabtriggers.
298dab9197SMauro Carvalho Chehab
308dab9197SMauro Carvalho ChehabWhen an led class device driver registers itself, it can specify all leds
318dab9197SMauro Carvalho Chehabtriggers it supports and a default trigger. During registration, activation
328dab9197SMauro Carvalho Chehabroutine for the default trigger gets called. During registration of an led
338dab9197SMauro Carvalho Chehabclass device, the LED state does not change.
348dab9197SMauro Carvalho Chehab
358dab9197SMauro Carvalho ChehabWhen the driver unregisters, deactivation routine for the currently active
368dab9197SMauro Carvalho Chehabtrigger will be called, and LED state is changed to LED_OFF.
378dab9197SMauro Carvalho Chehab
388dab9197SMauro Carvalho ChehabDriver suspend changes the LED state to LED_OFF and resume doesn't change
398dab9197SMauro Carvalho Chehabthe state. Please note that there is no explicit interaction between the
408dab9197SMauro Carvalho Chehabsuspend and resume actions and the currently enabled trigger. LED state
418dab9197SMauro Carvalho Chehabchanges are suspended while the driver is in suspend state. Any timers
428dab9197SMauro Carvalho Chehabthat are active at the time driver gets suspended, continue to run, without
438dab9197SMauro Carvalho Chehabbeing able to actually change the LED state. Once driver is resumed, triggers
448dab9197SMauro Carvalho Chehabstart functioning again.
458dab9197SMauro Carvalho Chehab
468dab9197SMauro Carvalho ChehabLED state changes are controlled using brightness which is a common led
478dab9197SMauro Carvalho Chehabclass device property. When brightness is set to 0 from user space via
488dab9197SMauro Carvalho Chehabecho 0 > brightness, it will result in deactivating the current trigger.
498dab9197SMauro Carvalho Chehab
508dab9197SMauro Carvalho ChehabTransient trigger uses standard register and unregister interfaces. During
518dab9197SMauro Carvalho Chehabtrigger registration, for each led class device that specifies this trigger
528dab9197SMauro Carvalho Chehabas its default trigger, trigger activation routine will get called. During
538dab9197SMauro Carvalho Chehabregistration, the LED state does not change, unless there is another trigger
548dab9197SMauro Carvalho Chehabactive, in which case LED state changes to LED_OFF.
558dab9197SMauro Carvalho Chehab
568dab9197SMauro Carvalho ChehabDuring trigger unregistration, LED state gets changed to LED_OFF.
578dab9197SMauro Carvalho Chehab
588dab9197SMauro Carvalho ChehabTransient trigger activation routine doesn't change the LED state. It
598dab9197SMauro Carvalho Chehabcreates its properties and does its initialization. Transient trigger
608dab9197SMauro Carvalho Chehabdeactivation routine, will cancel any timer that is active before it cleans
618dab9197SMauro Carvalho Chehabup and removes the properties it created. It will restore the LED state to
628dab9197SMauro Carvalho Chehabnon-transient state. When driver gets suspended, irrespective of the transient
638dab9197SMauro Carvalho Chehabstate, the LED state changes to LED_OFF.
648dab9197SMauro Carvalho Chehab
658dab9197SMauro Carvalho ChehabTransient trigger can be enabled and disabled from user space on led class
668dab9197SMauro Carvalho Chehabdevices, that support this trigger as shown below::
678dab9197SMauro Carvalho Chehab
688dab9197SMauro Carvalho Chehab	echo transient > trigger
698dab9197SMauro Carvalho Chehab	echo none > trigger
708dab9197SMauro Carvalho Chehab
718dab9197SMauro Carvalho ChehabNOTE:
728dab9197SMauro Carvalho Chehab	Add a new property trigger state to control the state.
738dab9197SMauro Carvalho Chehab
748dab9197SMauro Carvalho ChehabThis trigger exports three properties, activate, state, and duration. When
758dab9197SMauro Carvalho Chehabtransient trigger is activated these properties are set to default values.
768dab9197SMauro Carvalho Chehab
778dab9197SMauro Carvalho Chehab- duration allows setting timer value in msecs. The initial value is 0.
788dab9197SMauro Carvalho Chehab- activate allows activating and deactivating the timer specified by
798dab9197SMauro Carvalho Chehab  duration as needed. The initial and default value is 0.  This will allow
808dab9197SMauro Carvalho Chehab  duration to be set after trigger activation.
818dab9197SMauro Carvalho Chehab- state allows user to specify a transient state to be held for the specified
828dab9197SMauro Carvalho Chehab  duration.
838dab9197SMauro Carvalho Chehab
848dab9197SMauro Carvalho Chehab	activate
858dab9197SMauro Carvalho Chehab	      - one shot timer activate mechanism.
868dab9197SMauro Carvalho Chehab		1 when activated, 0 when deactivated.
878dab9197SMauro Carvalho Chehab		default value is zero when transient trigger is enabled,
888dab9197SMauro Carvalho Chehab		to allow duration to be set.
898dab9197SMauro Carvalho Chehab
908dab9197SMauro Carvalho Chehab		activate state indicates a timer with a value of specified
918dab9197SMauro Carvalho Chehab		duration running.
928dab9197SMauro Carvalho Chehab		deactivated state indicates that there is no active timer
938dab9197SMauro Carvalho Chehab		running.
948dab9197SMauro Carvalho Chehab
958dab9197SMauro Carvalho Chehab	duration
968dab9197SMauro Carvalho Chehab	      - one shot timer value. When activate is set, duration value
978dab9197SMauro Carvalho Chehab		is used to start a timer that runs once. This value doesn't
988dab9197SMauro Carvalho Chehab		get changed by the trigger unless user does a set via
998dab9197SMauro Carvalho Chehab		echo new_value > duration
1008dab9197SMauro Carvalho Chehab
1018dab9197SMauro Carvalho Chehab	state
1028dab9197SMauro Carvalho Chehab	      - transient state to be held. It has two values 0 or 1. 0 maps
1038dab9197SMauro Carvalho Chehab		to LED_OFF and 1 maps to LED_FULL. The specified state is
1048dab9197SMauro Carvalho Chehab		held for the duration of the one shot timer and then the
1058dab9197SMauro Carvalho Chehab		state gets changed to the non-transient state which is the
1068dab9197SMauro Carvalho Chehab		inverse of transient state.
1078dab9197SMauro Carvalho Chehab		If state = LED_FULL, when the timer runs out the state will
1088dab9197SMauro Carvalho Chehab		go back to LED_OFF.
1098dab9197SMauro Carvalho Chehab		If state = LED_OFF, when the timer runs out the state will
1108dab9197SMauro Carvalho Chehab		go back to LED_FULL.
1118dab9197SMauro Carvalho Chehab		Please note that current LED state is not checked prior to
1128dab9197SMauro Carvalho Chehab		changing the state to the specified state.
1138dab9197SMauro Carvalho Chehab		Driver could map these values to inverted depending on the
1148dab9197SMauro Carvalho Chehab		default states it defines for the LED in its brightness_set()
1158dab9197SMauro Carvalho Chehab		interface which is called from the led brightness_set()
1168dab9197SMauro Carvalho Chehab		interfaces to control the LED state.
1178dab9197SMauro Carvalho Chehab
1188dab9197SMauro Carvalho ChehabWhen timer expires activate goes back to deactivated state, duration is left
1198dab9197SMauro Carvalho Chehabat the set value to be used when activate is set at a future time. This will
1208dab9197SMauro Carvalho Chehaballow user app to set the time once and activate it to run it once for the
1218dab9197SMauro Carvalho Chehabspecified value as needed. When timer expires, state is restored to the
1228dab9197SMauro Carvalho Chehabnon-transient state which is the inverse of the transient state:
1238dab9197SMauro Carvalho Chehab
1248dab9197SMauro Carvalho Chehab	=================   ===============================================
1258dab9197SMauro Carvalho Chehab	echo 1 > activate   starts timer = duration when duration is not 0.
1268dab9197SMauro Carvalho Chehab	echo 0 > activate   cancels currently running timer.
1278dab9197SMauro Carvalho Chehab	echo n > duration   stores timer value to be used upon next
1288dab9197SMauro Carvalho Chehab			    activate. Currently active timer if
1298dab9197SMauro Carvalho Chehab			    any, continues to run for the specified time.
1308dab9197SMauro Carvalho Chehab	echo 0 > duration   stores timer value to be used upon next
1318dab9197SMauro Carvalho Chehab			    activate. Currently active timer if any,
1328dab9197SMauro Carvalho Chehab			    continues to run for the specified time.
1338dab9197SMauro Carvalho Chehab	echo 1 > state      stores desired transient state LED_FULL to be
1348dab9197SMauro Carvalho Chehab			    held for the specified duration.
1358dab9197SMauro Carvalho Chehab	echo 0 > state      stores desired transient state LED_OFF to be
1368dab9197SMauro Carvalho Chehab			    held for the specified duration.
1378dab9197SMauro Carvalho Chehab	=================   ===============================================
1388dab9197SMauro Carvalho Chehab
1398dab9197SMauro Carvalho ChehabWhat is not supported
1408dab9197SMauro Carvalho Chehab=====================
1418dab9197SMauro Carvalho Chehab
1428dab9197SMauro Carvalho Chehab- Timer activation is one shot and extending and/or shortening the timer
1438dab9197SMauro Carvalho Chehab  is not supported.
1448dab9197SMauro Carvalho Chehab
1458dab9197SMauro Carvalho ChehabExamples
1468dab9197SMauro Carvalho Chehab========
1478dab9197SMauro Carvalho Chehab
1488dab9197SMauro Carvalho Chehabuse-case 1::
1498dab9197SMauro Carvalho Chehab
1508dab9197SMauro Carvalho Chehab	echo transient > trigger
1518dab9197SMauro Carvalho Chehab	echo n > duration
1528dab9197SMauro Carvalho Chehab	echo 1 > state
1538dab9197SMauro Carvalho Chehab
1548dab9197SMauro Carvalho Chehabrepeat the following step as needed::
1558dab9197SMauro Carvalho Chehab
1568dab9197SMauro Carvalho Chehab	echo 1 > activate - start timer = duration to run once
1578dab9197SMauro Carvalho Chehab	echo 1 > activate - start timer = duration to run once
1588dab9197SMauro Carvalho Chehab	echo none > trigger
1598dab9197SMauro Carvalho Chehab
160*b7ecdb00SRandy DunlapThis trigger is intended to be used for the following example use cases:
1618dab9197SMauro Carvalho Chehab
1628dab9197SMauro Carvalho Chehab - Control of vibrate (phones, tablets etc.) hardware by user space app.
1638dab9197SMauro Carvalho Chehab - Use of LED by user space app as activity indicator.
1648dab9197SMauro Carvalho Chehab - Use of LED by user space app as a kind of watchdog indicator -- as
1658dab9197SMauro Carvalho Chehab   long as the app is alive, it can keep the LED illuminated, if it dies
1668dab9197SMauro Carvalho Chehab   the LED will be extinguished automatically.
1678dab9197SMauro Carvalho Chehab - Use by any user space app that needs a transient GPIO output.
168