From patchwork Fri Jun 16 09:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 109025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1230238vqr; Fri, 16 Jun 2023 03:26:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RvIKyprF6pvosbBCq1SFbuuDkS/lVVbm8m/RvJm04xAiulKO1ZV2iRlN8hx3cv9PqXtwC X-Received: by 2002:a05:6a00:2308:b0:661:237d:6c1f with SMTP id h8-20020a056a00230800b00661237d6c1fmr1917011pfh.3.1686911175860; Fri, 16 Jun 2023 03:26:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686911175; cv=none; d=google.com; s=arc-20160816; b=OtCG+FZ0cjD12njqtritpfjxw7198CvyBoffFEy+QgrGnv/0Jr8Vc3eFCVIQZ2m9SN s+yZtS3xgfavoxuf6kdhWhIbYYQLYV4pdepkWJZ80S3r4AY7L2KhSlOrVDsnisgNnp53 fxuuwK+qAynLXLWQE9TBdN2/+/k1dts7p5qn5KGOoMVrEqpdeGzkmmddVt4AwGQaTIgN VBZs+LEFynknvqpRJAR7rqwKMvNPtH8nr/Ou/RoFw6j7Ji8iwY/gAyxmwn4383mquzhp 7BipA5CmO61xNFw4INmxxBq+ii9xe73M/x7R9xNmUfgAeOAIdKyM0MERWiL9oBE1VCfw MpgA== 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=oIBYslblOctDgmeuid7XuyqEOXErfDHKQ06ITsadHWU=; b=Fab3V0X9VAvcXA/6kb5vj8/EGHi8wPtO7Ct8B2IpB9TfM5APgXYo7qvR6bupa8R1YK es6KTDq/EGjc3K+KZGzgDR59+pdBZ9EU8HlE3wzz85/ecDePZbe5L+0D3j/oS/RYw8PR M9EISSCJaCMSY4q6LtlwqVRD9qGKzmTGR28nrzkp+DRD+7OjeyAH96RdJJiKF9o7RPOq VrwzTI8dOb0evgzv0RYHY8D1oGVdSRtw3Lc1p19gLeGd8d7AiRflnCsEX7oaC0ZH9i8P YJabvSVYqXCROAPCvO57uYyRM+EKtrywVrQyR70TUNfQBBLJtbJZfa7MfwVutZE0gVjV g1hA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o20-20020aa79794000000b00666c9148d03si519363pfp.6.2023.06.16.03.26.02; Fri, 16 Jun 2023 03:26:15 -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 S234971AbjFPKQb (ORCPT + 99 others); Fri, 16 Jun 2023 06:16:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245214AbjFPKQR (ORCPT ); Fri, 16 Jun 2023 06:16:17 -0400 X-Greylist: delayed 613 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 16 Jun 2023 03:16:15 PDT Received: from 5.mo563.mail-out.ovh.net (5.mo563.mail-out.ovh.net [46.105.53.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 551D730C7 for ; Fri, 16 Jun 2023 03:16:15 -0700 (PDT) Received: from director3.derp.mail-out.ovh.net (director3.derp.mail-out.ovh.net [152.228.215.222]) by mo563.mail-out.ovh.net (Postfix) with ESMTPS id BFF98239AA; Fri, 16 Jun 2023 09:57:55 +0000 (UTC) Received: from director3.derp.mail-out.ovh.net (director3.derp.mail-out.ovh.net. [127.0.0.1]) by director3.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Fri, 16 Jun 2023 09:57:55 +0000 (UTC) Received: from pro2.mail.ovh.net (unknown [10.108.16.74]) by director3.derp.mail-out.ovh.net (Postfix) with ESMTPS id 93AC7107971; Fri, 16 Jun 2023 09:57:55 +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; Fri, 16 Jun 2023 11:57:55 +0200 From: Jean-Jacques Hiblot To: , , , , CC: , , , Jean-Jacques Hiblot Subject: [PATCH v9 3/5] leds: class: store the color index in struct led_classdev Date: Fri, 16 Jun 2023 11:57:44 +0200 Message-ID: <20230616095746.872220-4-jjhiblot@traphandler.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230616095746.872220-1-jjhiblot@traphandler.com> References: <20230616095746.872220-1-jjhiblot@traphandler.com> MIME-Version: 1.0 X-Originating-IP: [88.161.25.233] X-ClientProxiedBy: CAS3.emp2.local (172.16.1.3) To DAG1EX1.emp2.local (172.16.2.1) X-Ovh-Tracer-Id: 3612731329022540251 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrgedvgedgvddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgtghisehtkeertdertddtnecuhfhrohhmpeflvggrnhdqlfgrtghquhgvshcujfhisghlohhtuceojhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduteevleevvefggfdvueffffejhfehheeuiedtgedtjeeghfehueduudegfeefueenucfkpheptddrtddrtddrtddpkeekrdduiedurddvhedrvdeffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepughirhgvtghtohhrfedruggvrhhprdhmrghilhdqohhuthdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepjhhjhhhisghlohhtsehtrhgrphhhrghnughlvghrrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqlhgvughssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehieef 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_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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768854573318108329?= X-GMAIL-MSGID: =?utf-8?q?1768854573318108329?= 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..1509e71fcde1 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 (ex: "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..6cca21b227dd 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -76,6 +76,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[] = { @@ -90,6 +102,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 +495,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 +508,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 */