From patchwork Sun Oct 30 06:04:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 620146 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 3C053C38A02 for ; Sun, 30 Oct 2022 06:05:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229597AbiJ3GFm (ORCPT ); Sun, 30 Oct 2022 02:05:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbiJ3GFm (ORCPT ); Sun, 30 Oct 2022 02:05:42 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A79FBB; Sat, 29 Oct 2022 23:05:38 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 981FA5FD0D; Sun, 30 Oct 2022 09:05:34 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1667109934; bh=Mj6XeGhibfGmSiEoTN5jf4ujH17LQ75QJnsy4cgB8Go=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=c+ccjpSE8FDHp9W8PipF45eu6bKB8Wp2qvhDjbOlJoJ7WHzFwAS7h8coDc63s7/wo c64/QtpDpI2hWLMzp3+uVg5HGLuqjaCkSfAb7uigfg3eUvJXNDr4dS3bWHTlIB+F93 e2s1YCwcYWayCSfDtBd+46thh0AnvQER97mE9RxVu0JUwgN4MmBGzFxikrAyCh9RAG P8wN+6MarQkUJvuj14asjJT+4j57SV2sCyV29cRCabwoU16CZv7CQuhMNU5fa3xZHP OcpEoIuuufL60rPa1aJ6EjSeK2jxgfoi5ziO+epUwPqhOW8P/vo+5nA6PEbqm42kQk bH5Oc+iRDBuag== Received: from S-MS-EXCH02.sberdevices.ru (S-MS-EXCH02.sberdevices.ru [172.16.1.5]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 30 Oct 2022 09:05:33 +0300 (MSK) From: Arseniy Krasnov To: Pavel Machek CC: "linux-kernel@vger.kernel.org" , "linux-leds@vger.kernel.org" , kernel Subject: [RFC PATCH v1 0/1] Support to use own workqueue for each LED Thread-Topic: [RFC PATCH v1 0/1] Support to use own workqueue for each LED Thread-Index: AQHY7CWKPTqYZU7OvEqkn9ySnKgCJg== Date: Sun, 30 Oct 2022 06:04:59 +0000 Message-ID: <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: <9C39020E49B98E4B9770742F765209BE@sberdevices.ru> 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 use own workqueue for each LED. This could be useful when we have multiple LEDs which must work mutually (from user's point of view), for example when complex animation must be played. Problem is that default wq - 'system_wq' does not guarantee order of callbacks execution, which control brightness of every LED. So when userspace or pattern logic wants to change brightness in one order, kworkers may do it in random way, thus breaking smoothness of animation. Here is example how to use this patch: E.g. special workqueue must be allocated and set for each LED during init of 'led_classdev'. Then later in 'led_init_core()', 'system_wq' won't be used for such LEDs. Arseniy Krasnov(1): drivers/leds/led-core.c | 8 ++++++-- include/linux/leds.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) --- a/drivers/leds/leds-aw2013.c +++ b/drivers/leds/leds-aw2013.c @@ -264,11 +264,17 @@ static int aw2013_probe_dt(struct aw2013 *chip) struct device_node *np = dev_of_node(&chip->client->dev), *child; int count, ret = 0, i = 0; struct aw2013_led *led; + struct workqueue_struct *wq; count = of_get_available_child_count(np); if (!count || count > AW2013_MAX_LEDS) return -EINVAL; + wq = alloc_ordered_workqueue("aw2013_wq", 0); + + if (!wq) + return -ENOMEM; + regmap_write(chip->regmap, AW2013_RSTR, AW2013_RSTR_RESET); for_each_available_child_of_node(np, child) { @@ -299,6 +305,7 @@ static int aw2013_probe_dt(struct aw2013 *chip) led->cdev.brightness_set_blocking = aw2013_brightness_set; led->cdev.blink_set = aw2013_blink_set; + led->cdev.set_brightness_wq = wq; ret = devm_led_classdev_register_ext(&chip->client->dev, &led->cdev, &init_data);