Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4639841rwl; Tue, 28 Mar 2023 09:18:53 -0700 (PDT) X-Google-Smtp-Source: AKy350bI3JNN1xo20qent2pj3vCcvG0GUtAks7jb+JoEDursrY7oRHBhkMwgbtbud8gqEjNQDM/i X-Received: by 2002:aa7:d552:0:b0:4fb:ec6a:2357 with SMTP id u18-20020aa7d552000000b004fbec6a2357mr15145330edr.34.1680020333688; Tue, 28 Mar 2023 09:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680020333; cv=none; d=google.com; s=arc-20160816; b=ws3mQhiU+ZgTC5zDzsXz4dTCVxCdorerNG4w0ABK9+nJ50rdyHBacs9Y1O8DwWup3y RHZySY5jgfPT/chDMy6umBfyI9G/jRj23Oueh1bQwcVZp/CoE547Symr7Lw98Gyqlitm ibvIBu7Bj7HGGMfgYTZH45InVbUphnXJGThN8rO8bwxfxiu6bekaz9IC7lyBgyfaOEre e7ROenbfRrkEpwwr4LFma8JI+snjmvqgTPih/ZZEu4mCsg5btFarTxR1bbYNL66b9+qB TSmIGG3tqS1uGADuqtnbow9y93nGhQqARkGrYzC37Zd7eBGkQYrDeMkqCLWCqBAWHTDV 7Sng== 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=ym5QdxGrjyox6nWCzFcp+DTdEql7T0WX5wzCngscTns=; b=I8cbRn+ZawvjfmIo7SqZZFqlfuKDec9Rq653rrVEtuuGyGmqNggtTyC41FhnZYTAxI EsMPzazklTZruGittL68phQUb5/8iSfPoMtkS/+PaTMAwr4P9oSh808RYyhw/w0tT+E9 vTDW+82gS5aUzRqip38UiAesEKIUZ8n9OI2Bu+gHeo4xQ0tg8/wb+OQdndIrAUapCI4f dkx1clcbjTiPoOmI8aO+OnX+AfVnmgc09NA5L9RBxPMhH+qH3b5wIvWO2koU816X+2lb QzKlc4youVOCAEAFzeaDacJds4JCNpwO1q6tysW7t+wuPl7TKvLK8Wi/Bw0w8glbebOt Yd/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 s10-20020aa7d78a000000b004ab162a8415si31460965edq.283.2023.03.28.09.18.27; Tue, 28 Mar 2023 09:18:53 -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 S232241AbjC1QQC (ORCPT + 99 others); Tue, 28 Mar 2023 12:16:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbjC1QQA (ORCPT ); Tue, 28 Mar 2023 12:16:00 -0400 Received: from 10.mo562.mail-out.ovh.net (10.mo562.mail-out.ovh.net [46.105.72.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F17983E7 for ; Tue, 28 Mar 2023 09:15:57 -0700 (PDT) Received: from director2.derp.mail-out.ovh.net (director2.derp.mail-out.ovh.net [79.137.60.36]) by mo562.mail-out.ovh.net (Postfix) with ESMTPS id F181E23E07; Tue, 28 Mar 2023 16:15:55 +0000 (UTC) Received: from director2.derp.mail-out.ovh.net (director2.derp.mail-out.ovh.net. [127.0.0.1]) by director2.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Tue, 28 Mar 2023 16:15:55 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.108.4.231]) by director2.derp.mail-out.ovh.net (Postfix) with ESMTPS id DA6FE1FE9A; Tue, 28 Mar 2023 16:15:55 +0000 (UTC) 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.23; Tue, 28 Mar 2023 18:15:55 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , , , , , Jean-Jacques Hiblot Subject: [PATCH v8 4/6] leds: class: store the color index in struct led_classdev Date: Tue, 28 Mar 2023 18:15:39 +0200 Message-ID: <20230328161541.599463-5-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230328161541.599463-1-jjhiblot@traphandler.com> References: <20230328161541.599463-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: DAG8EX1.emp2.local (172.16.2.81) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 1349672516321163739 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehgedgleekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepughirhgvtghtohhrvddruggvrhhprdhmrghilhdqohhuthdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqlhgvughssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehiedv X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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..c6e53213b1e7 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: March 2023 +KernelVersion: 6.3 +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 9cddcd908bce..4432e85a5fc6 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 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[] = { @@ -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