From: "Marek Behún" <kabel@kernel.org>
To: netdev@vger.kernel.org
Cc: linux-leds@vger.kernel.org, "Pavel Machek" <pavel@ucw.cz>,
"Dan Murphy" <dmurphy@ti.com>,
"Russell King" <linux@armlinux.org.uk>,
"Andrew Lunn" <andrew@lunn.ch>,
"Matthias Schiffer" <matthias.schiffer@ew.tq-group.com>,
"David S. Miller" <davem@davemloft.net>,
"Jacek Anaszewski" <jacek.anaszewski@gmail.com>,
"Ben Whitten" <ben.whitten@gmail.com>,
"Marek Behún" <kabel@kernel.org>
Subject: [PATCH RFC leds + net-next 3/7] leds: trigger: add API for HW offloading of triggers
Date: Fri, 30 Oct 2020 12:44:31 +0100 [thread overview]
Message-ID: <20201030114435.20169-4-kabel@kernel.org> (raw)
In-Reply-To: <20201030114435.20169-1-kabel@kernel.org>
Add method trigger_offload() and member variable `offloaded` to struct
led_classdev. Add helper functions led_trigger_offload() and
led_trigger_offload_stop().
The trigger_offload() method, when implemented by the LED driver, should
be called (via led_trigger_offload() function) from trigger code wanting
to be offloaded at the moment when configuration of the trigger changes.
If the trigger is successfully offloaded, this method returns 0 and the
trigger does not have to blink the LED in software.
If the trigger with given configuration cannot be offloaded, the method
should return -EOPNOTSUPP, in which case the trigger must blink the LED
in SW.
Signed-off-by: Marek Behún <kabel@kernel.org>
---
Documentation/leds/leds-class.rst | 20 ++++++++++++++++++++
drivers/leds/led-triggers.c | 1 +
include/linux/leds.h | 27 +++++++++++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst
index a0708d3f3d0b..45360ff99f8d 100644
--- a/Documentation/leds/leds-class.rst
+++ b/Documentation/leds/leds-class.rst
@@ -169,6 +169,26 @@ 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 offloading of LED triggers
+===================================
+
+Some LEDs can offload SW triggers to hardware (for example a LED connected to
+an ethernet PHY or an ethernet switch can be configured to blink on activity on
+the network, which in software is done by the netdev trigger).
+
+To do such offloading, both the trigger code and LED driver must support this.
+The LED must implement the trigger_offload() method and the trigger code must
+try to call this method (via led_trigger_offload() function) when configuration
+of the trigger (trigger_data) changes.
+
+The implementation of the trigger_offload() method by the LED driver must return
+0 if the offload is successful and -EOPNOTSUPP if the requested trigger
+configuration is not supported and the trigger should be executed in software.
+If trigger_offload() returns negative value, the trigger will be done in
+software, so any active offloading must also be disabled.
+
+If the second argument (enable) to the trigger_offload() method is false, any
+active HW offloading must be deactivated.
Known Issues
============
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 91da90cfb11d..9056a66f4661 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -177,6 +177,7 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
flags);
cancel_work_sync(&led_cdev->set_brightness_work);
led_stop_software_blink(led_cdev);
+ led_trigger_offload_stop(led_cdev);
if (led_cdev->trigger->deactivate)
led_cdev->trigger->deactivate(led_cdev);
device_remove_groups(led_cdev->dev, led_cdev->trigger->groups);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 6a8d6409c993..d7e17f1d6f3c 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -148,6 +148,11 @@ struct led_classdev {
/* LEDs that have private triggers have this set */
struct led_hw_trigger_type *trigger_type;
+
+ /* some LEDs may be able to offload some SW triggers to HW */
+ int (*trigger_offload)(struct led_classdev *led_cdev,
+ bool enable);
+ bool offloaded;
#endif
#ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
@@ -405,6 +410,28 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
return led_cdev->trigger_data;
}
+static inline int led_trigger_offload(struct led_classdev *led_cdev)
+{
+ int ret;
+
+ if (!led_cdev->trigger_offload)
+ return -EOPNOTSUPP;
+
+ ret = led_cdev->trigger_offload(led_cdev, true);
+ led_cdev->offloaded = !ret;
+
+ return ret;
+}
+
+static inline void led_trigger_offload_stop(struct led_classdev *led_cdev)
+{
+ if (!led_cdev->trigger_offload)
+ return;
+
+ if (led_cdev->offloaded)
+ led_cdev->trigger_offload(led_cdev, false);
+}
+
/**
* led_trigger_rename_static - rename a trigger
* @name: the new trigger name
--
2.26.2
next prev parent reply other threads:[~2020-10-30 11:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-30 11:44 [PATCH RFC leds + net-next 0/7] netdev trigger offloading and LEDs on Marvell PHYs Marek Behún
2020-10-30 11:44 ` [PATCH RFC leds + net-next 1/7] leds: trigger: netdev: don't explicitly zero kzalloced data Marek Behún
2020-11-25 12:34 ` Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 2/7] leds: trigger: netdev: simplify the driver by using bit field members Marek Behún
2020-10-30 22:37 ` Jacek Anaszewski
2020-10-30 23:45 ` Marek Behún
2020-11-01 16:40 ` Jacek Anaszewski
2021-03-01 10:30 ` Pavel Machek
2020-10-30 11:44 ` Marek Behún [this message]
2021-03-01 10:38 ` [PATCH RFC leds + net-next 3/7] leds: trigger: add API for HW offloading of triggers Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 4/7] leds: trigger: netdev: support HW offloading Marek Behún
2020-11-05 14:44 ` Marek Behún
2021-03-01 10:44 ` Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 5/7] net: phy: add simple incrementing phyindex member to phy_device struct Marek Behún
2021-03-01 10:46 ` Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 6/7] net: phy: add support for LEDs connected to ethernet PHYs Marek Behún
2021-03-01 10:52 ` Pavel Machek
2020-10-30 11:44 ` [PATCH RFC leds + net-next 7/7] net: phy: marvell: support LEDs connected on Marvell PHYs Marek Behún
2020-10-30 15:04 ` kernel test robot
2020-10-30 16:04 ` kernel test robot
2020-11-25 12:38 ` Pavel Machek
2021-03-01 11:05 ` Pavel Machek
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=20201030114435.20169-4-kabel@kernel.org \
--to=kabel@kernel.org \
--cc=andrew@lunn.ch \
--cc=ben.whitten@gmail.com \
--cc=davem@davemloft.net \
--cc=dmurphy@ti.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-leds@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.schiffer@ew.tq-group.com \
--cc=netdev@vger.kernel.org \
--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.