From patchwork Thu Jun 13 14:48:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13696924 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 22140145B26 for ; Thu, 13 Jun 2024 14:48:47 +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=1718290130; cv=none; b=N1mrdTJoTlST0/kwGAQNTsNGIrOKrlveNts+aMtpN+oZDQuex1bg5NSwPDid1N1yrvWqDZzuaqc9CJHdvXH5WfK5Ad36Suo8r9gea0PfuHw1oAk7h6ZJGTeQTjKTJELyu3E1aw+3CUUcD1IE3fKXeOdwU/yr3SAOBi9MXdeFDeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718290130; c=relaxed/simple; bh=+TIq9UEk/in9R9arwQHciP7DyhwtaxbN8xJ/tBiBiTI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VVNS+H8jwjSJJo91/mb0gg2iy5olW9VcChz+YXcDG1ulTAxXPTEJY3uaqHUJyXZKPfr4/fflK1gB9HujVzakPRji7aJobmkaqmUKpgQNevPBichYj3awuOo+88XvnDyUX6WBt4FwaNaiTnln/HoAmqtW4R0NMdQpF0Qouv8IORE= 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=MkQ51ipE; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="MkQ51ipE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1718290120; bh=+TIq9UEk/in9R9arwQHciP7DyhwtaxbN8xJ/tBiBiTI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MkQ51ipEz8MeoKoDc89T1cX50VehBiQO4LRj0ZEqx6EnVsqZKassbiqk6IIU2eff0 1BO9KBA7A00dboxYfFVWTjENI3QncMuf4vGDe8zVAWt3fbN41hlWp0z5Q0ITV1/iln a02RlzNbDjkGq/c87j63WlvyS13xsqfPF/NSJXUQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 13 Jun 2024 16:48:36 +0200 Subject: [PATCH v3 1/5] leds: core: Introduce led_get_color_name() function Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-cros_ec-led-v3-1-500b50f41e0f@weissschuh.net> References: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> In-Reply-To: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> To: Pavel Machek , Lee Jones , =?utf-8?q?Thoma?= =?utf-8?q?s_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=9Fs?= =?utf-8?q?chuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718290119; l=1805; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=+TIq9UEk/in9R9arwQHciP7DyhwtaxbN8xJ/tBiBiTI=; b=SE9q7Ag3aDwUioQbinFnnfI+m5tsTa9WLPkcf3osAf2nVkePKJ6RPC9Q68QSvT8ZEjX+9P49F 6cwR7cqGP8tCVl8bEzR2kGfLZEDsRBE0MQYnIS3LHw9X1LMrgQvO59I 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 From patchwork Thu Jun 13 14:48:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13696922 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 75F4E1DFE1 for ; Thu, 13 Jun 2024 14:48:47 +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=1718290128; cv=none; b=XtNUbjldervRS4jzEou60Q1IhhLFZQNDGVzGlcFs6Z18WGwW8cIVwodtMxC9RnxZY+wis1ZPLBL0CbGmuViKoaWGlcZOH5hORK5Ky8gSPI9Ga98umIf45jZClB1u6uovwSUEDIV9A6zz9Va8FVUluKTds/6IdWjqeZqxB1dB158= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718290128; c=relaxed/simple; bh=RYdWV51r8PcyeNbSw5etkeGipgLJ2iNvDv6KpRFCB3g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TxaIn3hisntSsydeppEpMP86Lm/qKXsDWuDP/5l/n4L6cECLObL+3YHKVwskIRPOGv4Obu80FOg2BK58TCkIi+quny4cqZOObMUEmOhOlNcZrxJf3Vcs8qaNhREhPIbGsM4roHW4AuzPy/3VtXOmV8g28RS+GM0lzGGxRJpQwNc= 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=XN1JFlti; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="XN1JFlti" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1718290120; bh=RYdWV51r8PcyeNbSw5etkeGipgLJ2iNvDv6KpRFCB3g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XN1JFltiFXp2L2rqTWR4Bz22ATckDg7dp1tfm/cpV2hBrSJEvEOCSoL97+FO3IO+z 85ywGoHF876rW5xjwbhMHGwN7zw3rMNyabdV8OpnQSAgk0NAQBXksKAKAK2j+e5tUS F6JedxHDukOqh/Zv8Ql0ybBwe6hROnjwyN0LtxKo= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 13 Jun 2024 16:48:37 +0200 Subject: [PATCH v3 2/5] leds: multicolor: Use led_get_color_name() function Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-cros_ec-led-v3-2-500b50f41e0f@weissschuh.net> References: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> In-Reply-To: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> To: Pavel Machek , Lee Jones , =?utf-8?q?Thoma?= =?utf-8?q?s_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=9Fs?= =?utf-8?q?chuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718290119; l=942; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=RYdWV51r8PcyeNbSw5etkeGipgLJ2iNvDv6KpRFCB3g=; b=OItp3aZh/jgZ1XoXq/Awow9+PJGcoX1ucS+3ULAY1SaAQkDtBjZYWsqdkIXTJJsHIMeZ7pUsA CuWDYaZXNKMDlICN14C6oy/Lv+V9npjsNFOx04X51PW3RxG0yI4/cYO X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= led_get_color_name() is a safer alternative to led_colors. led-class-multicolor.c is the only external user of led_colors and its removal allows unexporting the array. Signed-off-by: Thomas Weißschuh --- drivers/leds/led-class-multicolor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/leds/led-class-multicolor.c b/drivers/leds/led-class-multicolor.c index ec62a4811613..584e3786a1e7 100644 --- a/drivers/leds/led-class-multicolor.c +++ b/drivers/leds/led-class-multicolor.c @@ -101,7 +101,7 @@ static ssize_t multi_index_show(struct device *dev, for (i = 0; i < mcled_cdev->num_colors; i++) { index = mcled_cdev->subled_info[i].color_index; - len += sprintf(buf + len, "%s", led_colors[index]); + len += sprintf(buf + len, "%s", led_get_color_name(index)); if (i < mcled_cdev->num_colors - 1) len += sprintf(buf + len, " "); } From patchwork Thu Jun 13 14:48:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13696923 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 1FBD71411D6 for ; Thu, 13 Jun 2024 14:48:48 +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=1718290129; cv=none; b=eKxl25TliOl4iYaftvVuqPocpGeCPv6QKz+LdW/HxQxr/ZyQ71AxnIMSwdM8cVN/LzSfpo1D6jSdo1+b5U8r54H/b5o4CoHk6ZVB9SGIigQgDR1S0j7GXt6w5mtHYUyQlZXjj9PKsHVWxH6iEaTfSi9RVGJEBBFqE4tTjMJQE1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718290129; c=relaxed/simple; bh=xGK5CAoX3hqfJgz9DdqkUhpIVSEo7t/GIW+AAIYvcaw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i3nGH1SdGHl3MNLKYCvh4JTdKnwrEkB7gdkp1UAvMjaSfRz4/93C7r3JyIjFmTHNiXFCcIF14A7qHcl8SnWVJne9Ogcyel+kITJZQrpHzU+t31Pz2noikkmEaKqiEQnqzZqBCS9cNLDQWFiRnL5/WaFVpAKF/6bnQHg3PsTbNuc= 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=EcpfRZ3u; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="EcpfRZ3u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1718290120; bh=xGK5CAoX3hqfJgz9DdqkUhpIVSEo7t/GIW+AAIYvcaw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EcpfRZ3u6p2ellkVSRyC2XKQq+uCEDAN/awKz4RuhuSd7M6r+wLjGNLqEEKl6JPk0 W+SCga4DoL/kque4Vr5ul1j7vfYPrDe2BP+85R0T/7yTyTX6E8Qaw292db1gx40pCl hGyi62zc53wFrvO70bcFhR6cXdhy/q4LjN/Jz6+k= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 13 Jun 2024 16:48:38 +0200 Subject: [PATCH v3 3/5] leds: core: Unexport led_colors[] array Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-cros_ec-led-v3-3-500b50f41e0f@weissschuh.net> References: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> In-Reply-To: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> To: Pavel Machek , Lee Jones , =?utf-8?q?Thoma?= =?utf-8?q?s_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=9Fs?= =?utf-8?q?chuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718290119; l=1434; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=xGK5CAoX3hqfJgz9DdqkUhpIVSEo7t/GIW+AAIYvcaw=; b=z65+2JKASgSAQluTrx6XZcnjq4H7Q7ozK0ieb9s0GOlP1gBHSapstFXcUXIojpFv/+gdT9E1o W5jI1R/zxMPDKwR+u5F89s2xqK2fqUDP9MtDuR50QqN7rub8Mo8OWaC X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= There are no external users left, make the array static. Signed-off-by: Thomas Weißschuh --- drivers/leds/led-core.c | 3 +-- drivers/leds/leds.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c index e0dd2284e84a..f2cea4e094f6 100644 --- a/drivers/leds/led-core.c +++ b/drivers/leds/led-core.c @@ -25,7 +25,7 @@ EXPORT_SYMBOL_GPL(leds_list_lock); LIST_HEAD(leds_list); EXPORT_SYMBOL_GPL(leds_list); -const char * const led_colors[LED_COLOR_ID_MAX] = { +static const char * const led_colors[LED_COLOR_ID_MAX] = { [LED_COLOR_ID_WHITE] = "white", [LED_COLOR_ID_RED] = "red", [LED_COLOR_ID_GREEN] = "green", @@ -42,7 +42,6 @@ const char * const led_colors[LED_COLOR_ID_MAX] = { [LED_COLOR_ID_CYAN] = "cyan", [LED_COLOR_ID_LIME] = "lime", }; -EXPORT_SYMBOL_GPL(led_colors); static int __led_set_brightness(struct led_classdev *led_cdev, unsigned int value) { diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h index 1138e2ab82e5..d7999e7372a4 100644 --- a/drivers/leds/leds.h +++ b/drivers/leds/leds.h @@ -30,6 +30,5 @@ ssize_t led_trigger_write(struct file *filp, struct kobject *kobj, extern struct rw_semaphore leds_list_lock; extern struct list_head leds_list; -extern const char * const led_colors[LED_COLOR_ID_MAX]; #endif /* __LEDS_H_INCLUDED */ From patchwork Thu Jun 13 14:48:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13696926 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 1FD7314534B for ; Thu, 13 Jun 2024 14:48:48 +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=1718290130; cv=none; b=YzdbTGPeppZtesTz1EEpACQcGbzjAEngzR+bnVKdsWCA/wi3dhAJkxgMStJgdwQiPFY+itdXQSJIwzf3+rRT+/FGSqK+zS7SbUhCW8oVZkY3kaY8wd6y3uicsjFyNgqBPbCqc9FIS2930Oe2QFwPmy+peR5mAzjbLyAWkVpwrzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718290130; c=relaxed/simple; bh=aWt0SapQ2kwkPr8k/i7OfMsafugN4xnNlAf7wUXpGYI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SNzEs6H+nCbsht9CxvCkVMkO4mgbAXzqTdjQXcGrjH+j3TN7d3P/H998ayhCUKYdE0B3D58FZJmGnCukBiqQx7yKNNy/fMRyfsPEabgUeX+B0Q2NTkkuy6yqENaQIUtWKkpFqUydBnq8wkHmPlAci3XnT37WdXR9aL9ViPkBe3Y= 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=P1iSjTwT; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="P1iSjTwT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1718290120; bh=aWt0SapQ2kwkPr8k/i7OfMsafugN4xnNlAf7wUXpGYI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=P1iSjTwTSdcunVLAhR43fKC5Tdis2vQ95sQ14RKJRl133IjR+sV4jPVWqv9s19X8u c+s+9Ja9kqG9t8p0TBhKOnCNSduuLIJsO8V09iDPxKChurO8+PKlt6Vy626UgOdNxR r3ry8ygfJsBoZT4m1Z4fFp+mWC559EVu4UEGDZqY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 13 Jun 2024 16:48:39 +0200 Subject: [PATCH v3 4/5] leds: Add ChromeOS EC driver Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-cros_ec-led-v3-4-500b50f41e0f@weissschuh.net> References: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> In-Reply-To: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> To: Pavel Machek , Lee Jones , =?utf-8?q?Thoma?= =?utf-8?q?s_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=9Fs?= =?utf-8?q?chuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718290119; l=11181; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=aWt0SapQ2kwkPr8k/i7OfMsafugN4xnNlAf7wUXpGYI=; b=i36YOFnHvWIO0/e1oXLpJfSAY0iJ2x4eDzDPdziYSkbpvR0sPKu4Tv+Y45PjHlIANnzjvAFzD wLBkRlUcAqiC8iekcXfcXjvrU0h5tfNikSfqXDX7mccG5JO+sWjJko7 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The ChromeOS Embedded Controller exposes an LED control command. Expose its functionality through the leds subsystem. The LEDs are exposed as multicolor devices. A hardware trigger, which is active by default, is provided to let the EC itself take over control over the LED. The driver is designed to be probed via the cros_ec mfd device. Signed-off-by: Thomas Weißschuh --- MAINTAINERS | 5 + drivers/leds/Kconfig | 15 +++ drivers/leds/Makefile | 1 + drivers/leds/leds-cros_ec.c | 299 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 320 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index aacccb376c28..8bc3491a08af 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5135,6 +5135,11 @@ S: Maintained F: Documentation/devicetree/bindings/sound/google,cros-ec-codec.yaml F: sound/soc/codecs/cros_ec_codec.* +CHROMEOS EC LED DRIVER +M: Thomas Weißschuh +S: Maintained +F: drivers/leds/leds-cros_ec.c + CHROMEOS EC SUBDRIVERS M: Benson Leung R: Guenter Roeck diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 05e6af88b88c..aa2fec9a34ed 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -179,6 +179,21 @@ config LEDS_CR0014114 To compile this driver as a module, choose M here: the module will be called leds-cr0014114. +config LEDS_CROS_EC + tristate "LED Support for ChromeOS EC" + depends on MFD_CROS_EC_DEV + depends on LEDS_CLASS_MULTICOLOR + select LEDS_TRIGGERS + default MFD_CROS_EC_DEV + help + This option enables support for LEDs managed by ChromeOS ECs. + All LEDs exposed by the EC are supported in multicolor mode. + A hardware trigger to switch back to the automatic behaviour is + provided. + + To compile this driver as a module, choose M here: the module + will be called leds-cros_ec. + config LEDS_EL15203000 tristate "LED Support for Crane EL15203000" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index effdfc6f1e95..3491904e13f7 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o obj-$(CONFIG_LEDS_CPCAP) += leds-cpcap.o +obj-$(CONFIG_LEDS_CROS_EC) += leds-cros_ec.o obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o obj-$(CONFIG_LEDS_DA9052) += leds-da9052.o obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o diff --git a/drivers/leds/leds-cros_ec.c b/drivers/leds/leds-cros_ec.c new file mode 100644 index 000000000000..7bb21a587713 --- /dev/null +++ b/drivers/leds/leds-cros_ec.c @@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * ChromeOS EC LED Driver + * + * Copyright (C) 2024 Thomas Weißschuh + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRV_NAME "cros-ec-led" + +static const char * const cros_ec_led_functions[] = { + [EC_LED_ID_BATTERY_LED] = LED_FUNCTION_CHARGING, + [EC_LED_ID_POWER_LED] = LED_FUNCTION_POWER, + [EC_LED_ID_ADAPTER_LED] = "adapter", + [EC_LED_ID_LEFT_LED] = "left", + [EC_LED_ID_RIGHT_LED] = "right", + [EC_LED_ID_RECOVERY_HW_REINIT_LED] = "recovery-hw-reinit", + [EC_LED_ID_SYSRQ_DEBUG_LED] = "sysrq-debug", +}; + +static_assert(ARRAY_SIZE(cros_ec_led_functions) == EC_LED_ID_COUNT); + +static const int cros_ec_led_to_linux_id[] = { + [EC_LED_COLOR_RED] = LED_COLOR_ID_RED, + [EC_LED_COLOR_GREEN] = LED_COLOR_ID_GREEN, + [EC_LED_COLOR_BLUE] = LED_COLOR_ID_BLUE, + [EC_LED_COLOR_YELLOW] = LED_COLOR_ID_YELLOW, + [EC_LED_COLOR_WHITE] = LED_COLOR_ID_WHITE, + [EC_LED_COLOR_AMBER] = LED_COLOR_ID_AMBER, +}; + +static_assert(ARRAY_SIZE(cros_ec_led_to_linux_id) == EC_LED_COLOR_COUNT); + +static const int cros_ec_linux_to_ec_id[] = { + [LED_COLOR_ID_RED] = EC_LED_COLOR_RED, + [LED_COLOR_ID_GREEN] = EC_LED_COLOR_GREEN, + [LED_COLOR_ID_BLUE] = EC_LED_COLOR_BLUE, + [LED_COLOR_ID_YELLOW] = EC_LED_COLOR_YELLOW, + [LED_COLOR_ID_WHITE] = EC_LED_COLOR_WHITE, + [LED_COLOR_ID_AMBER] = EC_LED_COLOR_AMBER, +}; + +struct cros_ec_led_priv { + struct led_classdev_mc led_mc_cdev; + struct cros_ec_device *cros_ec; + enum ec_led_id led_id; +}; + +static inline struct cros_ec_led_priv *cros_ec_led_cdev_to_priv(struct led_classdev *led_cdev) +{ + return container_of(lcdev_to_mccdev(led_cdev), struct cros_ec_led_priv, led_mc_cdev); +} + +union cros_ec_led_cmd_data { + struct ec_params_led_control req; + struct ec_response_led_control resp; +} __packed; + +static int cros_ec_led_send_cmd(struct cros_ec_device *cros_ec, + union cros_ec_led_cmd_data *arg) +{ + int ret; + struct { + struct cros_ec_command msg; + union cros_ec_led_cmd_data data; + } __packed buf = { + .msg = { + .version = 1, + .command = EC_CMD_LED_CONTROL, + .insize = sizeof(arg->resp), + .outsize = sizeof(arg->req), + }, + .data.req = arg->req + }; + + ret = cros_ec_cmd_xfer_status(cros_ec, &buf.msg); + if (ret < 0) + return ret; + + arg->resp = buf.data.resp; + + return 0; +} + +static int cros_ec_led_trigger_activate(struct led_classdev *led_cdev) +{ + struct cros_ec_led_priv *priv = cros_ec_led_cdev_to_priv(led_cdev); + union cros_ec_led_cmd_data arg = {}; + + arg.req.led_id = priv->led_id; + arg.req.flags = EC_LED_FLAGS_AUTO; + + return cros_ec_led_send_cmd(priv->cros_ec, &arg); +} + +static struct led_hw_trigger_type cros_ec_led_trigger_type; + +static struct led_trigger cros_ec_led_trigger = { + .name = "chromeos-auto", + .trigger_type = &cros_ec_led_trigger_type, + .activate = cros_ec_led_trigger_activate, +}; + +static int cros_ec_led_brightness_set_blocking(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct cros_ec_led_priv *priv = cros_ec_led_cdev_to_priv(led_cdev); + union cros_ec_led_cmd_data arg = {}; + enum ec_led_colors led_color; + struct mc_subled *subled; + size_t i; + + led_mc_calc_color_components(&priv->led_mc_cdev, brightness); + + arg.req.led_id = priv->led_id; + + for (i = 0; i < priv->led_mc_cdev.num_colors; i++) { + subled = &priv->led_mc_cdev.subled_info[i]; + led_color = cros_ec_linux_to_ec_id[subled->color_index]; + arg.req.brightness[led_color] = subled->brightness; + } + + return cros_ec_led_send_cmd(priv->cros_ec, &arg); +} + +static int cros_ec_led_count_subleds(struct device *dev, + struct ec_response_led_control *resp, + unsigned int *max_brightness) +{ + unsigned int range, common_range = 0; + int num_subleds = 0; + size_t i; + + for (i = 0; i < EC_LED_COLOR_COUNT; i++) { + range = resp->brightness_range[i]; + + if (!range) + continue; + + num_subleds++; + + if (!common_range) + common_range = range; + + if (common_range != range) { + /* The multicolor LED API expects a uniform max_brightness */ + dev_warn(dev, "Inconsistent LED brightness values\n"); + return -EINVAL; + } + } + + if (!num_subleds) + return -EINVAL; + + *max_brightness = common_range; + return num_subleds; +} + +static const char *cros_ec_led_get_color_name(struct led_classdev_mc *led_mc_cdev) +{ + int color; + + if (led_mc_cdev->num_colors == 1) + color = led_mc_cdev->subled_info[0].color_index; + else + color = LED_COLOR_ID_MULTI; + + return led_get_color_name(color); +} + +static int cros_ec_led_probe_led(struct device *dev, struct cros_ec_device *cros_ec, + enum ec_led_id id) +{ + union cros_ec_led_cmd_data arg = {}; + struct cros_ec_led_priv *priv; + struct led_classdev *led_cdev; + struct mc_subled *subleds; + int ret, num_subleds; + size_t i, subled; + + arg.req.led_id = id; + arg.req.flags = EC_LED_FLAGS_QUERY; + ret = cros_ec_led_send_cmd(cros_ec, &arg); + /* Unknown LED, skip */ + if (ret == -EINVAL) + return 0; + if (ret == -EOPNOTSUPP) + return -ENODEV; + if (ret < 0) + return ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + num_subleds = cros_ec_led_count_subleds(dev, &arg.resp, + &priv->led_mc_cdev.led_cdev.max_brightness); + if (num_subleds < 0) + return num_subleds; + + priv->cros_ec = cros_ec; + priv->led_id = id; + + subleds = devm_kcalloc(dev, num_subleds, sizeof(*subleds), GFP_KERNEL); + if (!subleds) + return -ENOMEM; + + subled = 0; + for (i = 0; i < EC_LED_COLOR_COUNT; i++) { + if (!arg.resp.brightness_range[i]) + continue; + + subleds[subled].color_index = cros_ec_led_to_linux_id[i]; + if (subled == 0) + subleds[subled].intensity = 100; + subled++; + } + + priv->led_mc_cdev.subled_info = subleds; + priv->led_mc_cdev.num_colors = num_subleds; + + led_cdev = &priv->led_mc_cdev.led_cdev; + led_cdev->brightness_set_blocking = cros_ec_led_brightness_set_blocking; + led_cdev->trigger_type = &cros_ec_led_trigger_type; + led_cdev->default_trigger = cros_ec_led_trigger.name; + led_cdev->hw_control_trigger = cros_ec_led_trigger.name; + + led_cdev->name = devm_kasprintf(dev, GFP_KERNEL, "chromeos:%s:%s", + cros_ec_led_get_color_name(&priv->led_mc_cdev), + cros_ec_led_functions[id]); + if (!led_cdev->name) + return -ENOMEM; + + return devm_led_classdev_multicolor_register(dev, &priv->led_mc_cdev); +} + +static int cros_ec_led_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent); + struct cros_ec_device *cros_ec = ec_dev->ec_dev; + int ret = 0; + size_t i; + + for (i = 0; i < EC_LED_ID_COUNT; i++) { + ret = cros_ec_led_probe_led(dev, cros_ec, i); + if (ret) + break; + } + + return ret; +} + +static const struct platform_device_id cros_ec_led_id[] = { + { DRV_NAME, 0 }, + {} +}; + +static struct platform_driver cros_ec_led_driver = { + .driver.name = DRV_NAME, + .probe = cros_ec_led_probe, + .id_table = cros_ec_led_id, +}; + +static int __init cros_ec_led_init(void) +{ + int ret; + + ret = led_trigger_register(&cros_ec_led_trigger); + if (ret) + return ret; + + ret = platform_driver_register(&cros_ec_led_driver); + if (ret) + led_trigger_unregister(&cros_ec_led_trigger); + + return ret; +}; +module_init(cros_ec_led_init); + +static void __exit cros_ec_led_exit(void) +{ + platform_driver_unregister(&cros_ec_led_driver); + led_trigger_unregister(&cros_ec_led_trigger); +}; +module_exit(cros_ec_led_exit); + +MODULE_DEVICE_TABLE(platform, cros_ec_led_id); +MODULE_DESCRIPTION("ChromeOS EC LED Driver"); +MODULE_AUTHOR("Thomas Weißschuh X-Patchwork-Id: 13696927 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 C2B53146A6E for ; Thu, 13 Jun 2024 14:48:50 +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=1718290132; cv=none; b=KmsnjyvGWsW0mpPt55OnFrm+pmsDi0ucqBOYDOHtVrOrPxfRUbl9JSrJDwOmr1+FKva67fcYF1ImissUNe8izAfYLiZroF4wqWYLM9fVbCsHM29Rg0SeZ2SGXN2qQm4zgY59I0MIHjCP6h8WTHHx3Gb0Q29wJtpTRnUbMzF4lX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718290132; c=relaxed/simple; bh=yVxyVIwMRddgUEXhVZPY0twYDEXyBd/qRw3RPwi32Eg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lwMesW5KLI2UVHgwjjWcRypNpFrKoWVqZv5GAvinElGbNvayT7LozZ0nh9XSswcZQZvmSJjxAeybozXcMo2WLX+M4Ru5zZyikIcO8gsbICqnIVT9B9AdjjOu6BmF1hHcYLp42EJbOGo76CzFeZk8pR9sSjLURhNwkDwZ3EwJcGk= 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=pLd4/VbA; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="pLd4/VbA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1718290120; bh=yVxyVIwMRddgUEXhVZPY0twYDEXyBd/qRw3RPwi32Eg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pLd4/VbAsVstarpEzFdot13IT4mpN+rMLEk92Hldp/KOBHZrEUNlt7h3LVQZDwrDf STz3oQldRrJGpAL8HXEcJZGklrh3uTqfM1j2QC+f79i1fLLRMoX342pG1Jarg/pcOP UV4n+hl0mWNy5HTJ59M2qCBDqTG3ipn8Tgh13JeI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 13 Jun 2024 16:48:40 +0200 Subject: [PATCH v3 5/5] mfd: cros_ec: Register LED subdevice Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240613-cros_ec-led-v3-5-500b50f41e0f@weissschuh.net> References: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> In-Reply-To: <20240613-cros_ec-led-v3-0-500b50f41e0f@weissschuh.net> To: Pavel Machek , Lee Jones , =?utf-8?q?Thoma?= =?utf-8?q?s_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=9Fs?= =?utf-8?q?chuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718290119; l=1053; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=yVxyVIwMRddgUEXhVZPY0twYDEXyBd/qRw3RPwi32Eg=; b=N/ZDeeBVukUv4uGrxzH8013chzUsFpC2ISJK3xoUpLuH+svvdsuJuaVl8u+lAI3vDRmc+p8As a/mu6Gz3/4UB/mDhRXTvpg8sW1RvC7GWucN3XzW/7ltiWxe4AGV47YC X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add ChromeOS EC-based LED control as EC subdevice. Signed-off-by: Thomas Weißschuh --- drivers/mfd/cros_ec_dev.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c index a52d59cc2b1e..d8408054ba15 100644 --- a/drivers/mfd/cros_ec_dev.c +++ b/drivers/mfd/cros_ec_dev.c @@ -99,6 +99,10 @@ static const struct mfd_cell cros_ec_wdt_cells[] = { { .name = "cros-ec-wdt", } }; +static const struct mfd_cell cros_ec_led_cells[] = { + { .name = "cros-ec-led", }, +}; + static const struct cros_feature_to_cells cros_subdevices[] = { { .id = EC_FEATURE_CEC, @@ -125,6 +129,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_ec_wdt_cells, .num_cells = ARRAY_SIZE(cros_ec_wdt_cells), }, + { + .id = EC_FEATURE_LED, + .mfd_cells = cros_ec_led_cells, + .num_cells = ARRAY_SIZE(cros_ec_led_cells), + }, }; static const struct mfd_cell cros_ec_platform_cells[] = {