mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
To: Pavel Machek <pavel@ucw.cz>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-leds@vger.kernel.org" <linux-leds@vger.kernel.org>,
	kernel <kernel@sberdevices.ru>
Subject: [RFC PATCH v1 1/1] leds: support to use own workqueue for each LED
Date: Sun, 30 Oct 2022 06:07:05 +0000	[thread overview]
Message-ID: <33d05330-7c52-e873-bf32-209d40c77632@sberdevices.ru> (raw)
In-Reply-To: <9a0a70a8-0886-1115-6151-72d2cba842cf@sberdevices.ru>

This allows to set own workqueue for each LED. This may be useful, because
default 'system_wq' does not guarantee execution order of each work_struct,
thus for several brightness update requests (for multiple leds), real
brightness switch could be in random order.

Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
---
 drivers/leds/led-core.c | 8 ++++++--
 include/linux/leds.h    | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 4a97cb745788..e8ecf332793a 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -188,6 +188,9 @@ static void led_blink_setup(struct led_classdev *led_cdev,
 
 void led_init_core(struct led_classdev *led_cdev)
 {
+	if (!led_cdev->set_brightness_wq)
+		led_cdev->set_brightness_wq = system_wq;
+
 	INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed);
 
 	timer_setup(&led_cdev->blink_timer, led_timer_function, 0);
@@ -252,7 +255,8 @@ void led_set_brightness(struct led_classdev *led_cdev, unsigned int brightness)
 		 */
 		if (!brightness) {
 			set_bit(LED_BLINK_DISABLE, &led_cdev->work_flags);
-			schedule_work(&led_cdev->set_brightness_work);
+			queue_work(led_cdev->set_brightness_wq,
+				   &led_cdev->set_brightness_work);
 		} else {
 			set_bit(LED_BLINK_BRIGHTNESS_CHANGE,
 				&led_cdev->work_flags);
@@ -273,7 +277,7 @@ void led_set_brightness_nopm(struct led_classdev *led_cdev, unsigned int value)
 
 	/* If brightness setting can sleep, delegate it to a work queue task */
 	led_cdev->delayed_set_value = value;
-	schedule_work(&led_cdev->set_brightness_work);
+	queue_work(led_cdev->set_brightness_wq, &led_cdev->set_brightness_work);
 }
 EXPORT_SYMBOL_GPL(led_set_brightness_nopm);
 
diff --git a/include/linux/leds.h b/include/linux/leds.h
index ba4861ec73d3..1121bae21fed 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -140,6 +140,7 @@ struct led_classdev {
 	void			(*flash_resume)(struct led_classdev *led_cdev);
 
 	struct work_struct	set_brightness_work;
+	struct workqueue_struct *set_brightness_wq;
 	int			delayed_set_value;
 
 #ifdef CONFIG_LEDS_TRIGGERS
-- 
2.35.0

  reply	other threads:[~2022-10-30  6:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-30  6:04 [RFC PATCH v1 0/1] Support " Arseniy Krasnov
2022-10-30  6:07 ` Arseniy Krasnov [this message]
2022-10-30 12:20   ` [RFC PATCH v1 1/1] leds: support " Pavel Machek
2022-10-30 14:01     ` Arseniy Krasnov
2022-10-30 20:15       ` Pavel Machek
2022-10-31  7:01         ` Arseniy Krasnov
2022-10-31 14:47           ` Dmitry Rokosov
2022-11-09 18:01             ` Dmitry Rokosov

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=33d05330-7c52-e873-bf32-209d40c77632@sberdevices.ru \
    --to=avkrasnov@sberdevices.ru \
    --cc=kernel@sberdevices.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®