Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6582173rwp; Tue, 18 Jul 2023 02:43:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlE9gFXYgTlEEnyfulMGq29z0/U9vFoObpHPum9TnaGlbFajP3eKepzk6br4mlLYyaawkKLD X-Received: by 2002:aa7:d507:0:b0:51e:1a5d:bc8c with SMTP id y7-20020aa7d507000000b0051e1a5dbc8cmr11556951edq.42.1689673419043; Tue, 18 Jul 2023 02:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689673419; cv=none; d=google.com; s=arc-20160816; b=WZcpbtrfxb6AG7+zPneNkosusbLTQl7INXhv0NXaUBUQfPyezXT2PqRoI+LgyySObJ H0qrzraXhMyiP+Cn1ExbkfFRMT9YFHUeO9FarecQBHylWeqdBKcpL1/7ALQtQTo0rO1Y POyFStht2TOv+ZAIdPpHbqlB9Fvw1kESijNhBwLygwfYS5HMdtherg2ZCoVm1yTmXyAl LpMkx/0wUX51O8iyxc2sRFmtP6k6oxJsPGc4qL1AEEA9gNzEqxLRdEjEPIAbVqJdh4Ai FbnsupjcZ1CC+wRV+48ThNDLDWODgcmdmYcmUSkZXBVp9XZ/DZO5MGQqCxaAvdXFBhfQ 498Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fp+knBiPpBv/YqT/bbTbKLi72khh2XjRi9mTIh1mKf4=; fh=lx8eiLb3A97b6nMYJWK3I4WGV0oFQKclDiNm3vzlRKo=; b=Jvtb2YenvuY9UkoGW9fsvh6+P9vopHBAKs+5mSDrcIKh96cLa6mo1DSQmJcpdGlulS DHW2y5xU6zJUIHY/5HNKaT15GsQ2eye6nuNFrJ4eRSQ9tDQ3+yU3D0uftw3FDT0LxuvT dwEHIrE8qNCpoao46kg3y1p5o1xPi1mCqWtjmUTyylHqvkafQR2X/Svte0L2jG6r/Fqb cHFqY+hufkCKXggP3Mt++8HPxSrAh563se5S8b6LcuPNfXXsAtePuh0I7D/PyGIG/IpD 4ZSLXTeWHMNaiaB7j5hIV6H7cg8DrRWE7z0Du9vWX0rTUe+v6FSH5CsRU2BMrWvWq4Dd vx/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020aa7c993000000b0051e2667a8absi935584edt.94.2023.07.18.02.43.14; Tue, 18 Jul 2023 02:43:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232267AbjGRJZw (ORCPT + 99 others); Tue, 18 Jul 2023 05:25:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbjGRJZo (ORCPT ); Tue, 18 Jul 2023 05:25:44 -0400 Received: from 4.mo563.mail-out.ovh.net (4.mo563.mail-out.ovh.net [46.105.53.192]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D24CFE60 for ; Tue, 18 Jul 2023 02:25:41 -0700 (PDT) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net [51.68.80.175]) by mo563.mail-out.ovh.net (Postfix) with ESMTPS id 2052D22C0F; Tue, 18 Jul 2023 09:25:40 +0000 (UTC) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net. [127.0.0.1]) by director1.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Tue, 18 Jul 2023 09:25:39 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.109.138.11]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id BA75D1FA43E; Tue, 18 Jul 2023 09:25:39 +0000 (UTC) Received: from traphandler.com (88.161.25.233) by DAG1EX1.emp2.local (172.16.2.1) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 18 Jul 2023 11:25:39 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot Subject: [PATCH v11 3/5] leds: class: store the color index in struct led_classdev Date: Tue, 18 Jul 2023 11:25:25 +0200 Message-ID: <20230718092527.37516-4-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230718092527.37516-1-jjhiblot@traphandler.com> References: <20230718092527.37516-1-jjhiblot@traphandler.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [88.161.25.233] X-ClientProxiedBy: DAG1EX1.emp2.local (172.16.2.1) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 6526560286219844059 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrgeeggddugecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomheplfgvrghnqdflrggtqhhuvghsucfjihgslhhothcuoehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepudetveelveevgffgvdeuffffjefhheehueeitdegtdejgefhheeuuddugeeffeeunecukfhppedtrddtrddtrddtpdekkedrudeiuddrvdehrddvfeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpohhuthdphhgvlhhopeguihhrvggtthhorhdurdguvghrphdrmhgrihhlqdhouhhtrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehjjhhhihgslhhothesthhrrghphhgrnhgulhgvrhdrtghomhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhlvggushesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheeife X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Store the color of the LED so that it is not lost after the LED's name has been composed. This color information can then be exposed to the user space or used by the LED consumer. Signed-off-by: Jean-Jacques Hiblot --- Documentation/ABI/testing/sysfs-class-led | 9 +++++++++ drivers/leds/led-class.c | 21 +++++++++++++++++++++ include/linux/leds.h | 1 + 3 files changed, 31 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led index 2e24ac3bd7ef..b2ff0012c0f2 100644 --- a/Documentation/ABI/testing/sysfs-class-led +++ b/Documentation/ABI/testing/sysfs-class-led @@ -59,6 +59,15 @@ Description: brightness. Reading this file when no hw brightness change event has happened will return an ENODATA error. +What: /sys/class/leds//color +Date: June 2023 +KernelVersion: 6.5 +Description: + Color of the LED. + + This is a read-only file. Reading this file returns the color + of the LED as a string (e.g: "red", "green", "multicolor"). + What: /sys/class/leds//trigger Date: March 2006 KernelVersion: 2.6.17 diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index eb1a8494dc5b..a90a3f505c71 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -76,6 +76,19 @@ static ssize_t max_brightness_show(struct device *dev, } static DEVICE_ATTR_RO(max_brightness); +static ssize_t color_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + const char *color_text = "invalid"; + struct led_classdev *led_cdev = dev_get_drvdata(dev); + + if (led_cdev->color < LED_COLOR_ID_MAX) + color_text = led_colors[led_cdev->color]; + + return sysfs_emit(buf, "%s\n", color_text); +} +static DEVICE_ATTR_RO(color); + #ifdef CONFIG_LEDS_TRIGGERS static BIN_ATTR(trigger, 0644, led_trigger_read, led_trigger_write, 0); static struct bin_attribute *led_trigger_bin_attrs[] = { @@ -90,6 +103,7 @@ static const struct attribute_group led_trigger_group = { static struct attribute *led_class_attrs[] = { &dev_attr_brightness.attr, &dev_attr_max_brightness.attr, + &dev_attr_color.attr, NULL, }; @@ -482,6 +496,10 @@ int led_classdev_register_ext(struct device *parent, if (fwnode_property_present(init_data->fwnode, "retain-state-shutdown")) led_cdev->flags |= LED_RETAIN_AT_SHUTDOWN; + + if (fwnode_property_present(init_data->fwnode, "color")) + fwnode_property_read_u32(init_data->fwnode, "color", + &led_cdev->color); } } else { proposed_name = led_cdev->name; @@ -491,6 +509,9 @@ int led_classdev_register_ext(struct device *parent, if (ret < 0) return ret; + if (led_cdev->color >= LED_COLOR_ID_MAX) + dev_warn(parent, "LED %s color identifier out of range\n", final_name); + mutex_init(&led_cdev->led_access); mutex_lock(&led_cdev->led_access); led_cdev->dev = device_create_with_groups(leds_class, parent, 0, diff --git a/include/linux/leds.h b/include/linux/leds.h index 95311c70d95c..487d00dac4de 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -100,6 +100,7 @@ struct led_classdev { const char *name; unsigned int brightness; unsigned int max_brightness; + unsigned int color; int flags; /* Lower 16 bits reflect status */ -- 2.34.1