From patchwork Sun Oct 30 06:07:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 620373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CEA0C38A02 for ; Sun, 30 Oct 2022 06:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229476AbiJ3GHn (ORCPT ); Sun, 30 Oct 2022 02:07:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbiJ3GHn (ORCPT ); Sun, 30 Oct 2022 02:07:43 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 241B410F; Sat, 29 Oct 2022 23:07:41 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 8613A5FD0D; Sun, 30 Oct 2022 09:07:39 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1667110059; bh=70gQPUCJRtL+Gl1erP4Tp6BQPO1jX8JvWrWFY8MQuHI=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=kOnQRetVPv+2UCipFwjhn9VvzjZbNb1MtZPEkL4XSVlkO2q0AgbiBUUxbZzxB6wXH yq/VsHBq0lC8A0RvQ3eLGOuhYQ9Z6013ctIfPPy260AwnRtZJCMuHS4FvxxFiHTD0H 16ZKDb5LwUolBDySp5pnIaGKusXFqbIN3fOaSwY0FwdBlGRoBI3d1InUZt00XuVa8u nchrawSXaximexdtUtxiV97DRznAweF0b0Zly7PJIYrDWOV7F72/wXvQR8BYQh9k+i skjfhiiYz4VV/aqlMXCs6Npx2Fp6uHAkrgzyRUCpA4i+DixbBbUK3ewUxQb5HiIhB5 51F9m8vuwQWXg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 30 Oct 2022 09:07:39 +0300 (MSK) From: Arseniy Krasnov To: Pavel Machek CC: "linux-kernel@vger.kernel.org" , "linux-leds@vger.kernel.org" , kernel Subject: [RFC PATCH v1 1/1] leds: support to use own workqueue for each LED Thread-Topic: [RFC PATCH v1 1/1] leds: support to use own workqueue for each LED Thread-Index: AQHY7CXVXNE+VpHZTEOLMCYP8pPo3Q== Date: Sun, 30 Oct 2022 06:07:05 +0000 Message-ID: <33d05330-7c52-e873-bf32-209d40c77632@sberdevices.ru> In-Reply-To: <9a0a70a8-0886-1115-6151-72d2cba842cf@sberdevices.ru> Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.1.12] Content-ID: MIME-Version: 1.0 X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/10/30 00:33:00 #20534548 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org 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 --- 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