All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>, Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Christian Marangi <ansuelsmth@gmail.com>,
	linux-leds@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [net-next PATCH v3 03/13] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs
Date: Sat, 27 May 2023 13:28:44 +0200	[thread overview]
Message-ID: <20230527112854.2366-4-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com>

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>
---
 Documentation/leds/leds-class.rst | 80 +++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst
index cd155ead8703..3d7874c18982 100644
--- a/Documentation/leds/leds-class.rst
+++ b/Documentation/leds/leds-class.rst
@@ -169,6 +169,86 @@ Setting the brightness to zero with brightness_set() callback function
 should completely turn off the LED and cancel the previously programmed
 hardware blinking function, if any.
 
+Hardware driven LEDs
+====================
+
+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.
+
+With hw control we refer to the LED driven by hardware.
+
+LED driver must define the following value to support hw control:
+
+    - hw_control_trigger:
+               unique trigger name supported by the LED in hw control
+               mode.
+
+LED driver must implement the following API to support hw control:
+    - hw_control_is_supported:
+                check if the flags passed by the supported trigger can
+                be parsed and activate hw control on the LED.
+
+                Return 0 if the passed flags mask is supported and
+                can be set with hw_control_set().
+
+                If the passed flags mask is not supported -EOPNOTSUPP
+                must be returned, the LED trigger will use software
+                fallback in this case.
+
+                Return a negative error in case of any other error like
+                device not ready or timeouts.
+
+     - hw_control_set:
+                activate hw control. LED driver will use the provided
+                flags passed from the supported trigger, parse them to
+                a set of mode and setup the LED to be driven by hardware
+                following the requested modes.
+
+                Set LED_OFF via the brightness_set to deactivate hw control.
+
+                Return 0 on success, a negative error number on flags apply
+                fail.
+
+    - hw_control_get:
+                get active modes from a LED already in hw control, parse
+                them and set in flags the current active flags for the
+                supported trigger.
+
+                Return 0 on success, a negative error number on failing
+                parsing the initial mode.
+                Error from this function is NOT FATAL as the device may
+                be in a not supported initial state by the attached LED
+                trigger.
+
+    - hw_control_get_device:
+                return the device associated with the LED driver in
+                hw control. A trigger might use this to match the
+                returned device from this function with a configured
+                device for the trigger as the source for blinking
+                events and correctly enable hw control.
+                (example a netdev trigger configured to blink for a
+                particular dev match the returned dev from get_device
+                to set hw control)
+
+                Return a device or NULL if nothing is currently attached.
+
+LED driver can activate additional modes by default to workaround the
+impossibility of supporting each different mode on the supported trigger.
+Example are hardcoding the blink speed to a set interval, enable special
+feature like bypassing blink if some requirements are not met.
+
+A trigger should first check if the hw control API are supported by the LED
+driver and check if the trigger is supported to verify if hw control is possible,
+use hw_control_is_supported to check if the flags are supported and only at
+the end use hw_control_set to activate hw control.
+
+A trigger can use hw_control_get to check if a LED is already in hw control
+and init their flags.
+
+When the LED is in hw control, no software blink is possible and doing so
+will effectively disable hw control.
 
 Known Issues
 ============
-- 
2.39.2


  parent reply	other threads:[~2023-05-27 11:29 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-27 11:28 [net-next PATCH v3 00/13] leds: introduce new LED hw control APIs Christian Marangi
2023-05-27 11:28 ` [net-next PATCH v3 01/13] leds: add APIs for LEDs hw control Christian Marangi
2023-05-29 15:31   ` Andrew Lunn
2023-05-27 11:28 ` [net-next PATCH v3 02/13] leds: add API to get attached device for LED " Christian Marangi
2023-05-27 11:28 ` Christian Marangi [this message]
2023-05-29  8:10   ` [net-next PATCH v3 03/13] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs Bagas Sanjaya
2023-05-29 14:12     ` Jonathan Corbet
2023-05-29 14:09       ` Christian Marangi
2023-05-30  3:09         ` Bagas Sanjaya
2023-05-30 12:24           ` Andrew Lunn
2023-05-29 14:52     ` Andrew Lunn
2023-05-27 11:28 ` [net-next PATCH v3 04/13] leds: trigger: netdev: refactor code setting device name Christian Marangi
2023-05-27 11:28 ` [net-next PATCH v3 05/13] leds: trigger: netdev: introduce check for possible hw control Christian Marangi
2023-05-29 15:32   ` Andrew Lunn
2023-05-27 11:28 ` [net-next PATCH v3 06/13] leds: trigger: netdev: add basic check for hw control support Christian Marangi
2023-05-29 15:33   ` Andrew Lunn
2023-05-27 11:28 ` [net-next PATCH v3 07/13] leds: trigger: netdev: reject interval store for hw_control Christian Marangi
2023-05-29 15:33   ` Andrew Lunn
2023-05-27 11:28 ` [net-next PATCH v3 08/13] leds: trigger: netdev: add support for LED hw control Christian Marangi
2023-05-29 15:45   ` Andrew Lunn
2023-05-29 15:52     ` Christian Marangi
2023-05-27 11:28 ` [net-next PATCH v3 09/13] leds: trigger: netdev: validate configured netdev Christian Marangi
2023-05-27 11:28 ` [net-next PATCH v3 10/13] leds: trigger: netdev: init mode if hw control already active Christian Marangi
2023-05-27 11:28 ` [net-next PATCH v3 11/13] leds: trigger: netdev: expose netdev trigger modes in linux include Christian Marangi
2023-05-29 15:47   ` Andrew Lunn
2023-05-27 11:28 ` [net-next PATCH v3 12/13] net: dsa: qca8k: implement hw_control ops Christian Marangi
2023-05-29 15:52   ` Andrew Lunn
2023-05-27 11:28 ` [net-next PATCH v3 13/13] net: dsa: qca8k: add op to get ports netdev Christian Marangi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230527112854.2366-4-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.