Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp592153lqh; Fri, 31 May 2024 10:08:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVkECa9uk0kescrv48KT6JAc78PNFhlthg2xsK3B/xa+BxFhMPCm9lvNRcCHI1muJQoucL2+8I0Sbee3+FxBsJA2aCygdkV+TFBCGcVTQ== X-Google-Smtp-Source: AGHT+IHOdUHGlT08WUQmqDrZj8JDXMunRGlDeMDTzoqLAhNquz7pg/oLh8vGBaa60CkCTnvi2LtS X-Received: by 2002:a17:90a:d593:b0:2c1:bb0c:9af4 with SMTP id 98e67ed59e1d1-2c1dc4b479cmr2729490a91.0.1717175301805; Fri, 31 May 2024 10:08:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717175301; cv=pass; d=google.com; s=arc-20160816; b=Qd3dwjLO5QQacFDetcTFPyJBshfNwuvw3CjNLbN0en/FWYbUjSqk0SKgkWjRBHEJEt d+gstqcLwmRcycl3KlMIAjz9CnizpilROAMblDpCq+/T6g2rhY/c6NOC2eOD+7IK8om6 jmefDr0Ji0FZWJG5kFJTfGgGlY9CplWC6OxnDeiD/axWQvai0j9ybeXb7PYffcz0fFC/ +4TOEQo1uPJLwGNl5x3orCA7+DlIVQHhvdVOrTe5RIRs0D48nExhS4i5H/bvV6RiWMgJ 1offqRCqfLjESEJ/4AendJRiPD/BbWqV9aylZqK8U8eWvuHEIP5R8iJMLvfLqmQmaPfl EXmg== 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=Q42o44SkCoTrzV4r+1GMmyYx3J87YZztGXcvxQCuSrM=; fh=XLi9m/0X8PjVhIWQEAZtk+9KXM176oIARH6s/tAj4ok=; b=01QlFHH+R1xtWCQ2b05mbBjeG3kmpJVhXH+ch2oW959U6UbNRtABKImHEc1ufL202Y j26yruXoxd5Sp83dgF5Gnta+dVE0GhDbTLvRug1PIwWt1+1/k7cRDXvMfz/CFeJQBvsF bOA8X3pNXfckvy2PUABVdYEXqkVCR/ojaX/LQ5ra5PN60J4l8u9TJxC9dKzkDCs5n4nM //cdkRdJhpqPZpiM6Lj7MEPob6eG85QSGJk3Nw6PUFGhMCE1DYVdk/sKYCqQeRCNOVCp /l63s965EmI3MBCgHtDDHFtV6TEMVrd5/xZFi5a7YAVmCGXRCyCRwYVWqPZ584seHO5s TfeA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=peunh7G5; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-197164-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197164-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c1a77b62dcsi3784457a91.110.2024.05.31.10.08.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 10:08:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197164-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=peunh7G5; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net dmarc=pass fromdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-197164-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197164-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=weissschuh.net 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 82308B2A0F2 for ; Fri, 31 May 2024 16:35:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E04E316936F; Fri, 31 May 2024 16:33:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="peunh7G5" 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 40AF017D89E; Fri, 31 May 2024 16:33:42 +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=1717173224; cv=none; b=pbzDhjzYLs73M9pDd1j+OAAINlc56wMPyendpSBK/oQz9i9xlSUo8H45ZWV892RBVzZmOT1bd/lk5JRMKVggR7oOqGvSOPDMTDvbSCoOJooTlAYCbwhBGJHf4YsU9Gij7z4n3kXc21gkI8tkwx3tCahRLtbBpLkPEAYVNIuZDBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717173224; c=relaxed/simple; bh=jaXh6FVnKJ8THkebhacKfDXHombFjeJ5bXLceH94XZ8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p4dzp6E3P/4sxqbv7h1DJkveUagchSzfqoRAabaZO9psaoZlSXaPrvpy0eNyZyPskbzrclGPw5ClZPGcWu6U2TggjCcKvNaqL5JpmP3/rImNHm3U6aNupDXfU1asCI2BYUtBVxfvUZcqWuqshoNPngAbIO6qVVUIbzRFh/Lu+i4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=peunh7G5; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=1717173219; bh=jaXh6FVnKJ8THkebhacKfDXHombFjeJ5bXLceH94XZ8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=peunh7G5Uyw+cvUOZ13e6S8vfU7F4Ual54QHxsVlLSNMj4cm8FLckCyGVX2zbft4c D2vSsfEV789RYCVT1IIcPMBPM5ghDsBpvMeqexjMKz1u69ZLWL2o1V47dLnCr08X++ ffVbr12EV4EnsnXyBFGqnFhr/QRghVPzSsRCmxfE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 31 May 2024 18:33:31 +0200 Subject: [PATCH v2 1/5] leds: core: Introduce led_get_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: <20240531-cros_ec-led-v2-1-6cc34408b40d@weissschuh.net> References: <20240531-cros_ec-led-v2-0-6cc34408b40d@weissschuh.net> In-Reply-To: <20240531-cros_ec-led-v2-0-6cc34408b40d@weissschuh.net> To: Pavel Machek , Lee Jones , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Benson Leung , Guenter Roeck , Tzung-Bi Shih 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=1717173219; l=1805; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=jaXh6FVnKJ8THkebhacKfDXHombFjeJ5bXLceH94XZ8=; b=sw6asO9DbB2NI/kSNYDhSG6SZ2ydPJIKgcDPNFgUM+Enzsq4KXtYtgzA8WNQ+Gyd2y64YfJcD 0Gh5LNwCTwDAUvSFtXBelRktdOkWqvVcUUkMyoM5rlCtTJHv0dgiCV2 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..e0dd2284e84a 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_get_color_name(u8 color_id) +{ + if (color_id >= ARRAY_SIZE(led_colors)) + return NULL; + + return led_colors[color_id]; +} +EXPORT_SYMBOL_GPL(led_get_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 6300313c46b7..dedea965afbf 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_get_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_get_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