Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: leds: leds-class: Document new Hardware driven LEDs APIs

Document new Hardware driven LEDs APIs.

Some LEDs can be programmed to be driven by hardware. This is not
limited to blink but also to turn off or on autonomously.
To support this feature, a LED needs to implement various additional
ops and needs to declare specific support for the supported triggers.

Add documentation for each required value and API to make hw control
possible and implementable by both LEDs and triggers.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Christian Marangi and committed by
David S. Miller
8aa2fd7b 052c38eb

+81
+81
Documentation/leds/leds-class.rst
··· 169 169 should completely turn off the LED and cancel the previously programmed 170 170 hardware blinking function, if any. 171 171 172 + Hardware driven LEDs 173 + ==================== 174 + 175 + Some LEDs can be programmed to be driven by hardware. This is not 176 + limited to blink but also to turn off or on autonomously. 177 + To support this feature, a LED needs to implement various additional 178 + ops and needs to declare specific support for the supported triggers. 179 + 180 + With hw control we refer to the LED driven by hardware. 181 + 182 + LED driver must define the following value to support hw control: 183 + 184 + - hw_control_trigger: 185 + unique trigger name supported by the LED in hw control 186 + mode. 187 + 188 + LED driver must implement the following API to support hw control: 189 + - hw_control_is_supported: 190 + check if the flags passed by the supported trigger can 191 + be parsed and activate hw control on the LED. 192 + 193 + Return 0 if the passed flags mask is supported and 194 + can be set with hw_control_set(). 195 + 196 + If the passed flags mask is not supported -EOPNOTSUPP 197 + must be returned, the LED trigger will use software 198 + fallback in this case. 199 + 200 + Return a negative error in case of any other error like 201 + device not ready or timeouts. 202 + 203 + - hw_control_set: 204 + activate hw control. LED driver will use the provided 205 + flags passed from the supported trigger, parse them to 206 + a set of mode and setup the LED to be driven by hardware 207 + following the requested modes. 208 + 209 + Set LED_OFF via the brightness_set to deactivate hw control. 210 + 211 + Return 0 on success, a negative error number on failing to 212 + apply flags. 213 + 214 + - hw_control_get: 215 + get active modes from a LED already in hw control, parse 216 + them and set in flags the current active flags for the 217 + supported trigger. 218 + 219 + Return 0 on success, a negative error number on failing 220 + parsing the initial mode. 221 + Error from this function is NOT FATAL as the device may 222 + be in a not supported initial state by the attached LED 223 + trigger. 224 + 225 + - hw_control_get_device: 226 + return the device associated with the LED driver in 227 + hw control. A trigger might use this to match the 228 + returned device from this function with a configured 229 + device for the trigger as the source for blinking 230 + events and correctly enable hw control. 231 + (example a netdev trigger configured to blink for a 232 + particular dev match the returned dev from get_device 233 + to set hw control) 234 + 235 + Returns a pointer to a struct device or NULL if nothing 236 + is currently attached. 237 + 238 + LED driver can activate additional modes by default to workaround the 239 + impossibility of supporting each different mode on the supported trigger. 240 + Examples are hardcoding the blink speed to a set interval, enable special 241 + feature like bypassing blink if some requirements are not met. 242 + 243 + A trigger should first check if the hw control API are supported by the LED 244 + driver and check if the trigger is supported to verify if hw control is possible, 245 + use hw_control_is_supported to check if the flags are supported and only at 246 + the end use hw_control_set to activate hw control. 247 + 248 + A trigger can use hw_control_get to check if a LED is already in hw control 249 + and init their flags. 250 + 251 + When the LED is in hw control, no software blink is possible and doing so 252 + will effectively disable hw control. 172 253 173 254 Known Issues 174 255 ============