From nobody Wed Sep 10 01:58:02 2025 Received: from mail-244107.protonmail.ch (mail-244107.protonmail.ch [109.224.244.107]) (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 E695E2F998E; Fri, 5 Sep 2025 08:00:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757059214; cv=none; b=I/I37NPXRNJCNxtMp19Mu9zsczMMADh/teSSZs1qyVHCUyzvAQ0bNXQM93wDGrTz6lZxOT0Xw6x0RYdN2vKKm7FrRkxSHe40oHD5bI4o612tK7XzqCCu857h+UE0WbIEVS9ZFSarz+Wzx8mOfo3WYMCS330rhe1ilVQTOMXdFkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757059214; c=relaxed/simple; bh=yMCxA1YBoWSwXEzfIBx2mS17OtHXmCeiYqirRRvAdG4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l/y9nv57E3d4HzQjL4xHM0TA6BBgm3n1m0go6YBopMt6l8E+RBB038QrABmHUePXZPfnWfRkRIFtjL4XfxuMHcTQ5YwpzNx/QEuDsY7WZYF2hwPHrTiwfhklPvMmsU+Bvv5TW+hPxbJnJG56A0oaeASwtAZCMdrPGDFBIWLOKkA= 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=JOQD/D9E; arc=none smtp.client-ip=109.224.244.107 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="JOQD/D9E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vinarskis.com; s=protonmail; t=1757059210; x=1757318410; bh=TKLUfGH8uv3WLk2SOPxFiRNjJURmOMHDoaZeUzdLiOs=; 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=JOQD/D9Et30KnY8JwuEIwpaQHwFLtBFnWWCN6ak9KOYk2pjw4OyrVEsZXHm0WhXxo IxCB8k28ZVSTNkDiFFlmMt+wIkk6i306RgMQnuvXYYVMxi1vXovM3T8uPxkmR0/CTN 6uaDjJPr5kvs7DR+k+Wl9qJj3yN3/PRk3e7phsrjk198586Ye9Sj4h1FOGcYCCS7Up mJSCCIHtCVHG4sw3XaeYO9paRD0DIATQaIct4eruYaz6BQXoMzctwj+zxAoYfxZb5H w/p+QVzhb5IcWV+AiLzFyRYS+C2l69McwbCbP96wya76u1SN0AInvi55ThTyXWYdXP ls/jvkJCI6L6Q== X-Pm-Submission-Id: 4cJ8080fKzz2ScWY From: Aleksandrs Vinarskis Date: Fri, 05 Sep 2025 09:59:31 +0200 Subject: [PATCH v2 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: <20250905-leds-v2-3-ed8f66f56da8@vinarskis.com> References: <20250905-leds-v2-0-ed8f66f56da8@vinarskis.com> In-Reply-To: <20250905-leds-v2-0-ed8f66f56da8@vinarskis.com> To: Hans de Goede , Lee Jones , Pavel Machek , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bryan O'Donoghue , Daniel Thompson , Jingoo Han , Mauro Carvalho Chehab , Jean-Jacques Hiblot , Jacopo Mondi , Sakari Ailus , Bjorn Andersson , Konrad Dybcio Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Thompson , dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, Aleksandrs Vinarskis , Andy Shevchenko , Linus Walleij X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2846; i=alex@vinarskis.com; h=from:subject:message-id; bh=q4BZRBIPBJ3imnNcJBChAehI+qOXxd1Xc7eYB34jKo0=; b=owGbwMvMwCX2dl3hIv4AZgHG02pJDBm7ZtS/ku/L05jXe15Y9c+f/171HP/OSgiKxjL0x6tr6 1WtXf6+o5SFQYyLQVZMkaX7z9e0rkVz1zJc1/gGM4eVCWQIAxenAExk5XSGf5pWrnd+TLlbUfbR Xu1MdIj46oXztyadC5wyrf37SefTigsZGa4Jq80+MeVfUP4j349Cq2qnWfve+OAqtmpjZ8B240c XKlkA 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 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 15633fbf3c166aa4f521774d245f6399a642bced..982eb4c1aac998e85b104d7cba2= 6e786ca62056f 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,16 @@ 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 + if (dev->of_node) { + 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