linux-leds.vger.kernel.org archive mirror
 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 v2 08/13] leds: trigger: netdev: add support for LED hw control
Date: Thu, 25 May 2023 16:53:56 +0200	[thread overview]
Message-ID: <20230525145401.27007-9-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com>

Add support for LED hw control for the netdev trigger.

The trigger on calling set_baseline_state to configure a new mode, will
do various check to verify if hw control can be used for the requested
mode in can_hw_control() function.

It will first check if the LED driver supports hw control for the netdev
trigger, then will use hw_control_is_supported() and finally will call
hw_control_set() to apply the requested mode.

To use such mode, interval MUST be set to the default value and net_dev
MUST be set. If one of these 2 value are not valid, hw control will
never be used and normal software fallback is used.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/leds/trigger/ledtrig-netdev.c | 39 ++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index cb2ec33abc4e..8d6381415208 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -68,6 +68,13 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
 	int current_brightness;
 	struct led_classdev *led_cdev = trigger_data->led_cdev;
 
+	/* Already validated, hw control is possible with the requested mode */
+	if (trigger_data->hw_control) {
+		led_cdev->hw_control_set(led_cdev, trigger_data->mode);
+
+		return;
+	}
+
 	current_brightness = led_cdev->brightness;
 	if (current_brightness)
 		led_cdev->blink_brightness = current_brightness;
@@ -103,12 +110,42 @@ static bool supports_hw_control(struct led_classdev *led_cdev)
 
 static bool can_hw_control(struct led_netdev_data *trigger_data)
 {
+	unsigned int interval = atomic_read(&trigger_data->interval);
 	struct led_classdev *led_cdev = trigger_data->led_cdev;
+	unsigned long default_interval = msecs_to_jiffies(50);
+	int ret;
 
 	if (!supports_hw_control(led_cdev))
 		return false;
 
-	return false;
+	/*
+	 * Interval must be set to the default
+	 * value. Any different value is rejected if in hw
+	 * control.
+	 */
+	if (interval != default_interval)
+		return false;
+
+	/*
+	 * net_dev must be set with hw control, otherwise no
+	 * blinking can be happening and there is nothing to
+	 * offloaded.
+	 */
+	if (!trigger_data->net_dev)
+		return false;
+
+	/* Check if the requested mode is supported */
+	ret = led_cdev->hw_control_is_supported(led_cdev, trigger_data->mode);
+	/* Fall back to software blinking if not supported */
+	if (ret == -EOPNOTSUPP)
+		return false;
+	if (ret) {
+		dev_warn(led_cdev->dev,
+			 "Current mode check failed with error %d\n", ret);
+		return false;
+	}
+
+	return true;
 }
 
 static ssize_t device_name_show(struct device *dev,
-- 
2.39.2


  parent reply	other threads:[~2023-05-25 14:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25 14:53 [net-next PATCH v2 00/13] leds: introduce new LED hw control APIs Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 01/13] leds: add APIs for LEDs hw control Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 02/13] leds: add API to get attached device for LED " Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 03/13] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 04/13] leds: trigger: netdev: refactor code setting device name Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 05/13] leds: trigger: netdev: introduce check for possible hw control Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 06/13] leds: trigger: netdev: add basic check for hw control support Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 07/13] leds: trigger: netdev: reject interval store for hw_control Christian Marangi
2023-05-25 14:53 ` Christian Marangi [this message]
2023-05-25 14:53 ` [net-next PATCH v2 09/13] leds: trigger: netdev: validate configured netdev Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 10/13] leds: trigger: netdev: init mode if hw control already active Christian Marangi
2023-05-25 14:53 ` [net-next PATCH v2 11/13] leds: trigger: netdev: expose netdev trigger modes in linux include Christian Marangi
2023-05-25 14:54 ` [net-next PATCH v2 12/13] net: dsa: qca8k: implement hw_control ops Christian Marangi
2023-05-25 14:54 ` [net-next PATCH v2 13/13] net: dsa: qca8k: add op to get ports netdev Christian Marangi
2023-05-26  3:43 ` [net-next PATCH v2 00/13] leds: introduce new LED hw control APIs Jakub Kicinski
2023-05-27 11:31   ` 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=20230525145401.27007-9-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 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).