From: Christian Marangi <ansuelsmth@gmail.com>
To: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
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>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Jonathan Corbet <corbet@lwn.net>,
Christian Marangi <ansuelsmth@gmail.com>,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
Jacek Anaszewski <jacek.anaszewski@gmail.com>,
John Crispin <john@phrozen.org>,
linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
linux-doc@vger.kernel.org, Tim Harvey <tharvey@gateworks.com>,
Alexander Stein <alexander.stein@ew.tq-group.com>,
Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
Bagas Sanjaya <bagasdotme@gmail.com>,
Arun.Ramadoss@microchip.com
Subject: [PATCH v8 02/13] leds: add function to configure hardware controlled LED
Date: Thu, 16 Feb 2023 02:32:19 +0100 [thread overview]
Message-ID: <20230216013230.22978-3-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com>
Add hw_control_configure helper to configure how the LED should work in
hardware mode. The function require to support the particular trigger and
will use the passed flag to elaborate the data and apply the
correct configuration. This function will then be used by the trigger to
request and update hardware configuration.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
Documentation/leds/leds-class.rst | 60 +++++++++++++++++++++++++++++++
include/linux/leds.h | 43 ++++++++++++++++++++++
2 files changed, 103 insertions(+)
diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst
index 984d73499d83..8a23589e9fca 100644
--- a/Documentation/leds/leds-class.rst
+++ b/Documentation/leds/leds-class.rst
@@ -200,10 +200,70 @@ The LED must implement 3 main API:
It's advised to the driver to put the LED in the old state
but this is not enforcerd and putting the LED off is also accepted.
+- hw_control_configure():
+ This will be used to configure the various blink modes LED support
+ in hardware mode.
+
With LED_BLINK_HW_CONTROLLED blink_mode hw_control_status/start/stop is optional
and any software only trigger will reject activation as the LED supports only
hardware mode.
+Where a trigger has support for hardware controlled blink modes,
+hw_control_configure() will be used to check whether a particular blink mode
+is supported and configure the blink mode using various specific command.
+
+hw_control_configure() takes 3 arguments:
+
+- struct led_classdev *led_cdev
+
+- unsigned long flag:
+ This can be used for multiple purpose based on passed command
+ in the 3rd argument of this function.
+ It may be NULL if the 3rd argument doesn't require them.
+
+ The unsigned long flag is specific to the trigger and its meaning
+ change across different triggers.
+ For this exact reason LED driver needs to declare explicit support
+ for the trigger supporting hardware blink mode.
+ The driver should return -EOPNOTSUPP if asked to enter in hardware
+ blink mode with an unsupported trigger.
+
+ The LED driver may also report -EOPNOTSUPP if the requested flag
+ are rejected and can't be handled in hw blink mode by the LED.
+
+ Flag can both be a single blink mode or a set of multiple blink
+ mode. LED driver must be able to handle both cases.
+
+- enum led_blink_hw_cmd cmd:
+ This is used to request to the LED driver various operation.
+
+ They may return -EOPNOTSUPP or -EINVAL based on the provided flags.
+
+hw_control_configure() supports the following cmd:
+
+- LED_BLINK_HW_ENABLE:
+ enable the blink mode requested in flag. Returns 0 or a negative
+ error.
+
+- LED_BLINK_HW_DISABLE:
+ disable the blink mode requested in flag. Returns 0 or a negative
+ error.
+
+- LED_BLINK_HW_STATUS:
+ read the status of the blink mode requested in flag. Return a mask
+ of the enabled blink mode requested in flag or a negative error.
+
+- LED_BLINK_HW_SUPPORTED:
+ ask the LED driver if the blink mode requested in flag is supported.
+ Return 1 if supported or a negative error in any other case.
+
+- LED_BLINK_HW_RESET:
+ reset any blink mode currently active. Value in flag are ignored.
+ Return 0 or a negative error.
+
+ LED driver can set the blink mode to a default state or keep everything
+ disabled.
+
Known Issues
============
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 5c360fba9ccf..c25558ca5f85 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -94,6 +94,14 @@ enum led_blink_modes {
LED_BLINK_SWHW_CONTROLLED,
};
+enum led_blink_hw_cmd {
+ LED_BLINK_HW_ENABLE, /* Enable the hardware blink mode */
+ LED_BLINK_HW_DISABLE, /* Disable the hardware blink mode */
+ LED_BLINK_HW_STATUS, /* Read the status of the hardware blink mode */
+ LED_BLINK_HW_SUPPORTED, /* Ask the driver if the hardware blink mode is supported */
+ LED_BLINK_HW_RESET, /* Reset any hardware blink active */
+};
+
struct led_classdev {
const char *name;
unsigned int brightness;
@@ -199,6 +207,17 @@ struct led_classdev {
* the old status but that is not mandatory and also putting it off is accepted.
*/
int (*hw_control_stop)(struct led_classdev *led_cdev);
+ /* This will be used to configure the various blink modes LED support in hardware
+ * mode.
+ * The LED driver require to support the active trigger and will elaborate the
+ * unsigned long flag and do the operation based on the provided cmd.
+ * Current operation are enable,disable,supported and status.
+ * A trigger will use this to enable or disable the asked blink mode, check the
+ * status of the blink mode or ask if the blink mode can run in hardware mode.
+ */
+ int (*hw_control_configure)(struct led_classdev *led_cdev,
+ unsigned long flag,
+ enum led_blink_hw_cmd cmd);
#endif
#ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
@@ -473,6 +492,30 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
return led_cdev->trigger_data;
}
+#ifdef CONFIG_LEDS_HARDWARE_CONTROL
+static inline bool led_trigger_blink_mode_is_supported(struct led_classdev *led_cdev,
+ unsigned long flag)
+{
+ int ret;
+
+ /* Sanity check: make sure led support hw mode */
+ if (led_cdev->blink_mode == LED_BLINK_SW_CONTROLLED)
+ return false;
+
+ ret = led_cdev->hw_control_configure(led_cdev, flag, LED_BLINK_HW_SUPPORTED);
+ if (ret > 0)
+ return true;
+
+ return false;
+}
+#else
+static inline bool led_trigger_blink_mode_is_supported(struct led_classdev *led_cdev,
+ unsigned long flag)
+{
+ return false;
+}
+#endif
+
/**
* led_trigger_rename_static - rename a trigger
* @name: the new trigger name
--
2.38.1
next prev parent reply other threads:[~2023-02-16 1:36 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 1:32 [PATCH v8 00/13] Adds support for PHY LEDs with offload triggers Christian Marangi
2023-02-16 1:32 ` [PATCH v8 01/13] leds: add support for hardware driven LEDs Christian Marangi
2023-02-16 1:32 ` Christian Marangi [this message]
2023-02-16 1:32 ` [PATCH v8 03/13] leds: trigger: netdev: drop NETDEV_LED_MODE_LINKUP from mode Christian Marangi
2023-02-16 1:32 ` [PATCH v8 04/13] leds: trigger: netdev: rename and expose NETDEV trigger enum modes Christian Marangi
2023-02-16 1:32 ` [PATCH v8 05/13] leds: trigger: netdev: convert device attr to macro Christian Marangi
2023-02-16 1:32 ` [PATCH v8 06/13] leds: trigger: netdev: add hardware control support Christian Marangi
2023-02-16 1:32 ` [PATCH v8 07/13] leds: trigger: netdev: use mutex instead of spinlocks Christian Marangi
2023-02-16 1:32 ` [PATCH v8 08/13] leds: trigger: netdev: add available mode sysfs attr Christian Marangi
2023-02-16 1:32 ` [PATCH v8 09/13] leds: trigger: netdev: add additional hardware only triggers Christian Marangi
2023-02-16 1:32 ` [PATCH v8 10/13] net: dsa: qca8k: add LEDs support Christian Marangi
2023-02-16 1:32 ` [PATCH v8 11/13] dt-bindings: leds: Document netdev trigger Christian Marangi
2023-02-17 23:03 ` Rob Herring
2023-02-17 5:58 ` Christian Marangi
2023-02-21 1:44 ` Rob Herring
2023-02-16 1:32 ` [PATCH v8 12/13] dt-bindings: net: phy: Document support for leds node Christian Marangi
2023-02-16 2:32 ` Rob Herring
2023-02-16 10:00 ` Christian Marangi
2023-02-17 23:10 ` Rob Herring
2023-02-16 1:32 ` [PATCH v8 13/13] dt-bindings: net: dsa: qca8k: add LEDs definition example Christian Marangi
2023-02-21 1:48 ` Rob Herring
2023-02-17 14:30 ` [PATCH v8 00/13] Adds support for PHY LEDs with offload triggers Andrew Lunn
2023-02-17 5:01 ` Christian Marangi
2023-02-22 15:02 ` Lee Jones
2023-03-06 18:43 ` Christian Marangi
2023-03-08 14:06 ` Lee Jones
2023-03-09 9:09 ` Linus Walleij
2023-03-09 9:32 ` Hans de Goede
2023-03-09 15:22 ` Andrew Lunn
2023-03-10 9:37 ` Linus Walleij
2023-03-10 15:15 ` Andrew Lunn
2023-03-13 9:28 ` Michael Walle
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=20230216013230.22978-3-ansuelsmth@gmail.com \
--to=ansuelsmth@gmail.com \
--cc=Arun.Ramadoss@microchip.com \
--cc=alexander.stein@ew.tq-group.com \
--cc=andrew@lunn.ch \
--cc=bagasdotme@gmail.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=jacek.anaszewski@gmail.com \
--cc=john@phrozen.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--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=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=pavel@ucw.cz \
--cc=rasmus.villemoes@prevas.dk \
--cc=rmk+kernel@armlinux.org.uk \
--cc=robh+dt@kernel.org \
--cc=tharvey@gateworks.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).