Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1088498rwb; Fri, 7 Oct 2022 08:01:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM466OIIfZV7G6vp4b6q9GHG1wO9wWhJqjQai7nJcG+xTNn31wUTnJ9Cw92IQaPdt42+uhu9 X-Received: by 2002:a17:907:a46:b0:782:1c1c:8141 with SMTP id be6-20020a1709070a4600b007821c1c8141mr4400071ejc.549.1665154882927; Fri, 07 Oct 2022 08:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665154882; cv=none; d=google.com; s=arc-20160816; b=d33VxCjnahPxj2/Vk+mRbHmj8fGgZZHFC5HDcTHAvC1OoI72xcPGhMt6IE+67utisR 7uKzq3WknnfD2p843Bx9hd0dkXgaJd+UOAkZclLUsyEYhnUw9DgjhlCYIDmYBihhuKbw ZSkUJICjlu1a+LACC+6qcerARDs9duOlUP0PQOl3nsSTdrGt/O3J5sxy+scXLXB9dAg8 ZD+kyoplVcFayKLBzrgH5tBtJ2vBchQ9Kg9dSkXXlmQ99MXEkW/EG7DONKFTdf6qHUje 3YWXw4VyDaxueDDLf7lm0VNf1lXk4X6PIo+HYlum57kQ7zhJKOhYafU0joEV1w6mr0+a NHGw== 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=uBaS1uc3lUUN0E5o1WwpteeCQMaQT/ua7c2+DxwlhQ8=; b=JLhNjInBi+bVSt0yFzQimYASZSlbEugQODBM7f4MVAhJC2n2py/YP+7Any75Jv7X0c Vbpj+CermCqhhVyOYQ3Ii/jWEkWH2pwoRUxe6Sg89JBtgV3+Y0U+PJbKEl3Q54W+J+kI PsNXe+ebDcFU1y/18qqQ2GWpyr89LkkLhixJO7DlGR9WtDzzhVvXxTzpVnmfrNi4TlzR N8Q58Cqk/G65irwykwDo+3FqXLVBmvmG9wtXjDLg2hAlvvIXuWsOGFIyF2otB5m/kMBA /k9N7hppHyZc8TA8BuesS/jZOgc/SU70FIJTUJJfgMh26uHY5v3OZH9AfPqPjOMf0Gch 1X5Q== 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 c30-20020a50d65e000000b00452dfa2bb27si2156346edj.134.2022.10.07.08.00.56; Fri, 07 Oct 2022 08:01:22 -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 S229959AbiJGO5F (ORCPT + 99 others); Fri, 7 Oct 2022 10:57:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbiJGO4y (ORCPT ); Fri, 7 Oct 2022 10:56:54 -0400 Received: from smtpout1.mo528.mail-out.ovh.net (smtpout1.mo528.mail-out.ovh.net [46.105.34.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 249278C46F; Fri, 7 Oct 2022 07:56:53 -0700 (PDT) Received: from pro2.mail.ovh.net (unknown [10.109.146.13]) by mo528.mail-out.ovh.net (Postfix) with ESMTPS id A03D212E155CC; Fri, 7 Oct 2022 16:56:51 +0200 (CEST) Received: from localhost.localdomain (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.12; Fri, 7 Oct 2022 16:56:50 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , , , , , , Jean-Jacques Hiblot Subject: [PATCH v4 4/6] leds: class: store the color index in struct led_classdev Date: Fri, 7 Oct 2022 16:56:39 +0200 Message-ID: <20221007145641.3307075-5-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221007145641.3307075-1-jjhiblot@traphandler.com> References: <20221007145641.3307075-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: CAS1.emp2.local (172.16.1.1) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 4481926056142977499 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeijedgkeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepphhrohdvrdhmrghilhdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehvdek X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 This information might be useful for more than only deriving the led's name. And since we have this information, we can expose it in the sysfs. Signed-off-by: Jean-Jacques Hiblot --- Documentation/ABI/testing/sysfs-class-led | 9 +++++++++ drivers/leds/led-class.c | 20 ++++++++++++++++++++ include/linux/leds.h | 1 + 3 files changed, 30 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led index 2e24ac3bd7ef..e3ae9111b70d 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: October 2022 +KernelVersion: 6.1 +Description: + Color of the led. + + This is a read-only file. Reading this file returns the color + of the led as a string (ex: "red", "green"). + 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 2fea79a2300d..fcc528f82f92 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -74,6 +74,18 @@ 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 sprintf(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[] = { @@ -88,6 +100,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, }; @@ -375,6 +388,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; @@ -384,6 +401,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 41df18f42d00..9d38cb90331d 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -71,6 +71,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.25.1