Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2348166lqo; Mon, 20 May 2024 03:01:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVczFoCVuvHyHQ9WO3+qlXZaCKc5eFkHazHgmOajlakk8XFiD8G/nSNeRZUZC06n6PMMvpgrU8/i9f/vRpZtiehM17Oe9OtNC3e9/LqKA== X-Google-Smtp-Source: AGHT+IEATB4umn40V3NLOYBu0vnw5ppf+/Rd3mFZt2Gn6bwHq6eReEyhWt7FVMd/TO63WygtEEga X-Received: by 2002:a05:6a21:3949:b0:1b1:d519:6cce with SMTP id adf61e73a8af0-1b1d5196dc6mr3234569637.57.1716199303050; Mon, 20 May 2024 03:01:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716199303; cv=pass; d=google.com; s=arc-20160816; b=pxR5zsYqhJhgFQasu7KdV1+h5RoYP7PVwSzh4pgWtWysMGB+8teyBbGlhLhUevgz3G PrkHsjmVBROlCAnVmCkxq9sNEzNhlSSi0McraEAb+m1vGAUZNP21GNw5+Dl12BP1oh1V 76vcuE69YjyrrEni5ZBKvIUs8PW+ZczyxORYxFfnBd9mJnEhB8Goq+uxVKjtSHb89VlG Us41ChneElyrD2HSYwUqnvxtMHvxVkgd+E8mCZLNGwzqpML8uP496i3RWz9BHMJ1LFhp A38ra4geC4P5QqkQPAo46cjaoF4ZUAGyxeWt8ex/jOzdlJ5kVmjRA9Y6Xhu/JmDkzrgS qVGw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=z+z82TlFDjIiQ1+Kq0yJxWdfIsUsIj+42ixeqD/cq0s=; fh=ilYn24DrbkS5/SSJpQ9bwmnzSJDVPtZy9VYJXzt05/I=; b=Il/kibjbZBX+9hJ+Df8xFbzIWaz4dzi97qV/h8SGHKhoszqIDUnIE1oEIhuMwn6wWs XxTRsyTy/mgtqawrOSZscUC5XkTnm7y6a7wWZJK62U6jBZLCHX2q8/3VlE9z8tPKDRTQ zK/Ne4R8R6JIVmPy/dD8AL4Ki/yKdOshW8sWq6auDwpFT4KhQwblhEvZtRbeNEB1Gfn6 b0qRA3trWgRpybxYQiWXXomUXZQEDIE898/VIafFcaLBtCJZI77BF5Lj84gck/h7j68u B4OMVxBgEmXMQDqv8Xj2w3/aJbYwWaxu7AEcVzKHtbRvvnB+QxnBuF5dHvNx51q6lq87 Sakg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=YSIi45ZR; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-183579-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183579-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-65be1e29103si7418336a12.179.2024.05.20.03.01.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 03:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183579-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=YSIi45ZR; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-183579-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183579-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A42C4B20916 for ; Mon, 20 May 2024 10:01:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC97C4E1D9; Mon, 20 May 2024 10:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="YSIi45ZR" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E44B481CE; Mon, 20 May 2024 10:01:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716199276; cv=none; b=bEs8VVeCgP3xlzWY1DRwiqKyhJ1pLVLC8OxVnJICCdHlfsJA+c2g+TvrPvbtM0HpiLglWomffzS7V0VpaTGA09vy+sxUkyYhfFAIEfrIKDWcKUTrKQqtMj1PWa+ZCeGR71mG0lHKCxL7vvPozHTc9M0NtJt/3qtrNbh/CsSAKdo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716199276; c=relaxed/simple; bh=Rf0pRVyMBzjhJ6DOcgU1r/DeZA59QefuS6EJvAEoqp0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ipxKz3RwhTYlx7ZtFMDWxUKftvLO39+yO+ASzbQGBrxW7uyzYx/O5zXDP1iFtZ0JguivSXHP0ylEhHoNx/k0f6+6dyEW2l/nxRCZ28BUlenqXbriayCeYTw+h76UGOkq+psl4zBm7go5C2BKuh6x1fm2Vik/+4SEBAyR3OY2OoM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=YSIi45ZR; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1716199266; bh=Rf0pRVyMBzjhJ6DOcgU1r/DeZA59QefuS6EJvAEoqp0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YSIi45ZRwpIZD0B/wcPrKTSpy6S4qpGKAm6pyvN4VrvgZGCx8tCAOk/Yw7PB2fknP mCGTbgmCsyu9Jd6DAs87K5vQDRisNaIGcK1btfPATOwXYirgceVb++ZririOjPONoH N0YV4ze1BF0okdBKYT/JtwN1kCynmB8ZFuBqeGpE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 20 May 2024 12:00:29 +0200 Subject: [PATCH 1/5] leds: introduce led_color_name function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240520-cros_ec-led-v1-1-4068fc5c051a@weissschuh.net> References: <20240520-cros_ec-led-v1-0-4068fc5c051a@weissschuh.net> In-Reply-To: <20240520-cros_ec-led-v1-0-4068fc5c051a@weissschuh.net> To: Pavel Machek , Lee Jones , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Benson Leung , Guenter Roeck Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev, Dustin Howett , Mario Limonciello , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1716199265; l=1785; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Rf0pRVyMBzjhJ6DOcgU1r/DeZA59QefuS6EJvAEoqp0=; b=y+XCEet8JP8ljO5zdUixzxW3CRR+uCsN4T+I5VQfLBmS3UCUE+iS14kKo8vvreQ19ZhrWaKul 3chr3drQwKWDU+r8TSFhd7oGAxR2skbY0ubJIZtm9LRUXAwrIU6Ql0K X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= This is similar to the existing led_colors array but is safer to use and usable by everyone. Getting string representations of color ids is useful for drivers which are handling color ids anyways, for example for the multicolor API. Signed-off-by: Thomas Weißschuh --- drivers/leds/led-core.c | 9 +++++++++ include/linux/leds.h | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index 89c9806cc97f..04a49958458e 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -534,6 +534,15 @@ int led_compose_name(struct device *dev, struct led_init_data *init_data, } EXPORT_SYMBOL_GPL(led_compose_name); +const char *led_color_name(u8 color_id) +{ + if (color_id >= ARRAY_SIZE(led_colors)) + return NULL; + + return led_colors[color_id]; +} +EXPORT_SYMBOL_GPL(led_color_name); + enum led_default_state led_init_default_state_get(struct fwnode_handle *fwnode) { const char *state = NULL; diff --git a/include/linux/leds.h b/include/linux/leds.h index db6b114bb3d9..0f1b955fa3f7 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -427,6 +427,16 @@ void led_sysfs_enable(struct led_classdev *led_cdev); int led_compose_name(struct device *dev, struct led_init_data *init_data, char *led_classdev_name); +/** + * led_color_name - get string representation of color id + * @color_id: The LED_COLOR_ID_* constant + * + * Get the string name of a LED_COLOR_ID_* constant. + * + * Returns: A string constant or NULL on an invalid ID. + */ +const char *led_color_name(u8 color_id); + /** * led_sysfs_is_disabled - check if LED sysfs interface is disabled * @led_cdev: the LED to query -- 2.45.1