From patchwork Tue May 3 11:27:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Schwermer X-Patchwork-Id: 569172 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 F3F19C433F5 for ; Tue, 3 May 2022 11:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234586AbiECLbA (ORCPT ); Tue, 3 May 2022 07:31:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234304AbiECLa6 (ORCPT ); Tue, 3 May 2022 07:30:58 -0400 Received: from mail.schwermer.no (mail.schwermer.no [49.12.228.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DD762B27B; Tue, 3 May 2022 04:27:25 -0700 (PDT) X-Virus-Scanned: Yes From: Sven Schwermer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=svenschwermer.de; s=mail; t=1651577243; bh=X1P1czu7olInCuAQsy8kh9ER4hFIClKs76hLpKYw1KQ=; h=From:To:Cc:Subject:In-Reply-To:References; b=C++waFrmpLW4z31URtuRSBlGy4QI0L2rbDWoUO0GDTF7R07CpWNLWq+fAFfWfYf4/ TnhEW3Uaz+dbwcBhEq9TVXDqef0KGLqi07m78Pzr3Yp1I+orngCyr3t1HoSKcVjwb0 dhSUxaWYTLtQfHNoBfTTzCg+8FX/3wcG0HGAkNaG+YGM9lRNHLn5McrmMtP0opPrlF 0SjV3M2W6rz7wRckPlp9uvR6NRFxSzczMo+IlXOQ3N1tta44NzPfJHoR0NUF3pIKRD WBxk3a03yBW7tkkRgdG6F0yABOt9mnEKc1AiFVnTTRvyvhXo3WQct/J9iKc+VmvTil cPep9RBxYGCJg== To: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, pavel@ucw.cz, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, dmurphy@ti.com, devicetree@vger.kernel.org Cc: Sven Schwermer Subject: [PATCH v2 1/2] dt-bindings: leds: Add multi-color default-intensities property Date: Tue, 3 May 2022 13:27:06 +0200 Message-Id: <364df52a196fa0ae5db07e599995fcf8dfafb43e.1651577132.git.sven.schwermer@disruptive-technologies.com> In-Reply-To: <20220502204616.GA27288@ucw.cz> References: <20220502204616.GA27288@ucw.cz> Mime-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Sven Schwermer This allows to assign intensity values to the indivisual sub LEDs (colors) at driver probe time, i.e. most commonly at kernel boot time. This is crucial for setting a specific color early in the boot process. Signed-off-by: Sven Schwermer --- Notes: V1->V2: no changes .../devicetree/bindings/leds/leds-class-multicolor.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/leds/leds-class-multicolor.yaml b/Documentation/devicetree/bindings/leds/leds-class-multicolor.yaml index 37445c68cdef..c483967a847c 100644 --- a/Documentation/devicetree/bindings/leds/leds-class-multicolor.yaml +++ b/Documentation/devicetree/bindings/leds/leds-class-multicolor.yaml @@ -31,6 +31,13 @@ patternProperties: include/linux/leds/common.h. enum: [ 8, 9 ] + default-intensities: + description: | + This parameter, if present, sets the initial intensities of the + individual colors. This array must have the same length as the + multi-color LED has sub LEDs (colors). + $ref: /schemas/types.yaml#/definitions/uint32-array + $ref: "common.yaml#" required: From patchwork Tue May 3 11:27:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Schwermer X-Patchwork-Id: 570646 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 0588EC433EF for ; Tue, 3 May 2022 11:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234398AbiECLa7 (ORCPT ); Tue, 3 May 2022 07:30:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233393AbiECLa6 (ORCPT ); Tue, 3 May 2022 07:30:58 -0400 Received: from mail.schwermer.no (mail.schwermer.no [49.12.228.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB25B27B03; Tue, 3 May 2022 04:27:25 -0700 (PDT) X-Virus-Scanned: Yes From: Sven Schwermer DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=svenschwermer.de; s=mail; t=1651577243; bh=d8ER+kGznK/svT0YX/8SOUfQKwEh0SoW3+nU3n0R0iQ=; h=From:To:Cc:Subject:In-Reply-To:References; b=ldu/MxdDCgWaGzqMGeqCOYDb32L+lBLFO0bwvbw3WNkr9kcvlFHuf790dMy4raw+t bVn6qYYuRcCuol0alaXOhzyryVWx1tDhngq3ztnq6HEw8KFkpefxv5IkkCJRjR6h5E V/k7yYnjFMyhG3B46jZ9sFjWyTlIGVMK0crEYsptTChnK8pO22m4YxZsjPC83RWrXu o9WdxnFU8Q88TUpIHUmal70aij33YdNysi8TslaQpD/YgG/41iC9mbdcoYNIB2ITnh CxqXUlAGe6M1uNVxILWatKWzz0x/BydL3l3Vhx2ePHI/Tl+O7Mm4jzTgurL+l6Uuu0 UUiSwRxag+aqg== To: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, pavel@ucw.cz, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, dmurphy@ti.com, devicetree@vger.kernel.org Cc: Sven Schwermer Subject: [PATCH v2 2/2] leds: multicolor: Read default-intensities property Date: Tue, 3 May 2022 13:27:07 +0200 Message-Id: <980857efbf41b77667b0e0b5044f06409295d7d0.1651577132.git.sven.schwermer@disruptive-technologies.com> In-Reply-To: <364df52a196fa0ae5db07e599995fcf8dfafb43e.1651577132.git.sven.schwermer@disruptive-technologies.com> References: <364df52a196fa0ae5db07e599995fcf8dfafb43e.1651577132.git.sven.schwermer@disruptive-technologies.com> Mime-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Sven Schwermer This allows to assign intensity values taken from the firmware interface (if available) to the indivisual sub LEDs (colors) at driver probe time, i.e. most commonly at kernel boot time. This is crucial for setting a specific color and early in the boot process. While it would be possible to set a static color in the bootloader, this mechanism allows setting a pattern (e.g. blinking) at a specific color. Signed-off-by: Sven Schwermer --- Notes: V1->V2: Fix mixup drivers/leds/led-class-multicolor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/leds/led-class-multicolor.c b/drivers/leds/led-class-multicolor.c index e317408583df..84f237784246 100644 --- a/drivers/leds/led-class-multicolor.c +++ b/drivers/leds/led-class-multicolor.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "leds.h" @@ -116,6 +117,26 @@ static struct attribute *led_multicolor_attrs[] = { }; ATTRIBUTE_GROUPS(led_multicolor); +static void multi_load_default_intensities(struct device *parent, + struct led_classdev_mc *mcled_cdev, + struct fwnode_handle *fwnode) +{ + u32 intensities[LED_COLOR_ID_MAX]; + unsigned int i; + int ret; + + ret = fwnode_property_read_u32_array(fwnode, "default-intensities", + intensities, mcled_cdev->num_colors); + if (ret < 0) { + if (ret != -ENODATA) + dev_warn(parent, "failed to read default-intensities property: %d", ret); + return; + } + + for (i = 0; i < mcled_cdev->num_colors; i++) + mcled_cdev->subled_info[i].intensity = intensities[i]; +} + int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) @@ -134,6 +155,9 @@ int led_classdev_multicolor_register_ext(struct device *parent, led_cdev = &mcled_cdev->led_cdev; mcled_cdev->led_cdev.groups = led_multicolor_groups; + if (init_data && init_data->fwnode) + multi_load_default_intensities(parent, mcled_cdev, init_data->fwnode); + return led_classdev_register_ext(parent, led_cdev, init_data); } EXPORT_SYMBOL_GPL(led_classdev_multicolor_register_ext);