From nobody Thu Oct 2 22:59:32 2025 Received: from mail-43170.protonmail.ch (mail-43170.protonmail.ch [185.70.43.170]) (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 5011F319858; Wed, 10 Sep 2025 12:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757505695; cv=none; b=cQ1SScfSeZJBCsizPjjvwJasqPvGrAGXlkOGNvxcNvPr19Wc+RC51e3vC98U6jPk52vLD+fzE0FDRaAra6e3GWx3/Lct6G4Z5ou3LNCtt3IB9B/mRRPMBxKgp4vw03S8BSWW2ha6HyXINQjeGMdWe5mmRNBlC0K5N8gyQu3R7lo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757505695; c=relaxed/simple; bh=Gcb5IZdx91tE9heqd3TCL/vKpfvSJeT7p8ruz7OBMGE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dElOUzV1VsdPy9tRxJFn70DPdtEFQzGqPoUuSMka2Ohg9LfWjLXyBlczLTWK6pWqtCmtKAhCSGH5yM98x5gI6TJFHa64hV/9CXPxzRahOh0WKYSwbUN8ezbovMwPJWCyE4/xxkGvN4ZUM7Kkv450YBJd0ENu5funxsHO7e0EmTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vinarskis.com; spf=pass smtp.mailfrom=vinarskis.com; dkim=pass (2048-bit key) header.d=vinarskis.com header.i=@vinarskis.com header.b=YOQTzDwf; arc=none smtp.client-ip=185.70.43.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vinarskis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vinarskis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vinarskis.com header.i=@vinarskis.com header.b="YOQTzDwf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vinarskis.com; s=protonmail; t=1757505690; x=1757764890; bh=amlesrrCjtNi/rMOXRLaP/ew+FLiQjpAjiXhBIB6iFo=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=YOQTzDwfVpD/gqjhjBmhI/Xf37NlZC9uEXyALze5c/VZkehDZLDcHyMkdzdXr0FP4 qSmKBs9DV0XeShRuTfy/zSgYFYt/ns4U9naG3ANyJlEV1dXGHRFN+BYbDEI4ybWXq5 3C+juG/M6V0+DsFjWAr7hyuEogymBiTle+SQCrEkTjTsMAbzTbzmuYHnXzVr7YmXWi ZpTSykU5FPRzfZrSiTA7hVdrPoOsa58/Fu3jzDF5XKxpTiLGwsP+5yAMqYQz2CrW9R KbdZlJM6LjuAw3zoYl/E2z6lgr2r7S8LxHREFiq/ZvNHvnvg6XbrDLpdySrgG5tbmg LYf8MZUv2wNuQ== X-Pm-Submission-Id: 4cMK6H4k7Vz2ScCy From: Aleksandrs Vinarskis Date: Wed, 10 Sep 2025 14:01:10 +0200 Subject: [PATCH v5 3/4] leds: led-class: Add devicetree support to led_get() 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: quoted-printable Message-Id: <20250910-leds-v5-3-bb90a0f897d5@vinarskis.com> References: <20250910-leds-v5-0-bb90a0f897d5@vinarskis.com> In-Reply-To: <20250910-leds-v5-0-bb90a0f897d5@vinarskis.com> To: Hans de Goede , Lee Jones , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bryan O'Donoghue , Jingoo Han , Mauro Carvalho Chehab , Jean-Jacques Hiblot , Jacopo Mondi , Sakari Ailus , Bjorn Andersson , Konrad Dybcio , Daniel Thompson Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, threeway@gmail.com, Andy Shevchenko , Aleksandrs Vinarskis , Linus Walleij X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2813; i=alex@vinarskis.com; h=from:subject:message-id; bh=YlfJ62d/o3pOGGQtdA6W03es+ClzT+tk2OK+jve8yPw=; b=owGbwMvMwCX2dl3hIv4AZgHG02pJDBkHMya88djY7L3Se+PD7UJznNYpNX44ZlU9v/a6WJF8k 8D5oNM/OkpZGMS4GGTFFFm6/3xN61o0dy3DdY1vMHNYmUCGMHBxCsBEQpwY/ko3tBfrmlj5W0eV vuo83uPwUGvSRMHshgf5E4/pcYaU7WNk+NgssO13nfQBl1fCIZ85X/7edIlZZ3tCzKu3rCev1Lh HsQIA X-Developer-Key: i=alex@vinarskis.com; a=openpgp; fpr=8E21FAE2D2967BB123303E8C684FD4BA28133815 From: Hans de Goede Add 'name' argument to of_led_get() such that it can lookup LEDs in devicetree by either name or index. And use this modified function to add devicetree support to the generic (non devicetree specific) [devm_]led_get() function. This uses the standard devicetree pattern of adding a -names string array to map names to the indexes for an array of resources. Reviewed-by: Andy Shevchenko Reviewed-by: Lee Jones Reviewed-by: Linus Walleij Signed-off-by: Hans de Goede Signed-off-by: Aleksandrs Vinarskis --- drivers/leds/led-class.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 15633fbf3c166aa4f521774d245f6399a642bced..f3faf37f9a08ac762ed87b91cb3= cab5faa8eacb0 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -252,15 +252,23 @@ static const struct class leds_class =3D { * of_led_get() - request a LED device via the LED framework * @np: device node to get the LED device from * @index: the index of the LED + * @name: the name of the LED used to map it to its function, if present * * Returns the LED device parsed from the phandle specified in the "leds" * property of a device tree node or a negative error-code on failure. */ -static struct led_classdev *of_led_get(struct device_node *np, int index) +static struct led_classdev *of_led_get(struct device_node *np, int index, + const char *name) { struct device *led_dev; struct device_node *led_node; =20 + /* + * For named LEDs, first look up the name in the "led-names" property. + * If it cannot be found, then of_parse_phandle() will propagate the erro= r. + */ + if (name) + index =3D of_property_match_string(np, "led-names", name); led_node =3D of_parse_phandle(np, "leds", index); if (!led_node) return ERR_PTR(-ENOENT); @@ -324,7 +332,7 @@ struct led_classdev *__must_check devm_of_led_get(struc= t device *dev, if (!dev) return ERR_PTR(-EINVAL); =20 - led =3D of_led_get(dev->of_node, index); + led =3D of_led_get(dev->of_node, index, NULL); if (IS_ERR(led)) return led; =20 @@ -342,9 +350,14 @@ EXPORT_SYMBOL_GPL(devm_of_led_get); struct led_classdev *led_get(struct device *dev, char *con_id) { struct led_lookup_data *lookup; + struct led_classdev *led_cdev; const char *provider =3D NULL; struct device *led_dev; =20 + led_cdev =3D of_led_get(dev->of_node, -1, con_id); + if (!IS_ERR(led_cdev) || PTR_ERR(led_cdev) !=3D -ENOENT) + return led_cdev; + mutex_lock(&leds_lookup_lock); list_for_each_entry(lookup, &leds_lookup_list, list) { if (!strcmp(lookup->dev_id, dev_name(dev)) && --=20 2.48.1