From nobody Wed Jul 1 13:27:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17E08C433FE for ; Tue, 21 Dec 2021 17:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240658AbhLURus (ORCPT ); Tue, 21 Dec 2021 12:50:48 -0500 Received: from aposti.net ([89.234.176.197]:39338 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240647AbhLURuq (ORCPT ); Tue, 21 Dec 2021 12:50:46 -0500 From: Paul Cercueil To: Jean Delvare , Guenter Roeck , Rob Herring Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH 1/2] dt-bindings: hwmon: Introduce common properties Date: Tue, 21 Dec 2021 17:50:28 +0000 Message-Id: <20211221175029.144906-2-paul@crapouillou.net> In-Reply-To: <20211221175029.144906-1-paul@crapouillou.net> References: <20211221175029.144906-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Introduce a file for common properties of hwmon sensors. As of now it contains only the "label" property, which can contain a descriptive label that allows to uniquely identify a device within the system. Signed-off-by: Paul Cercueil --- .../devicetree/bindings/hwmon/common.yaml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/common.yaml diff --git a/Documentation/devicetree/bindings/hwmon/common.yaml b/Document= ation/devicetree/bindings/hwmon/common.yaml new file mode 100644 index 000000000000..997f74127d8c --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/common.yaml @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/common.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common properties for hwmon sensors + +maintainers: + - Jean Delvare + - Guenter Roeck + +description: | + This document defines device tree properties common to several hwmon + sensors. It doesn't constitue a device tree binding specification by its= elf but + is meant to be referenced by device tree bindings. + + When referenced from sensor tree bindings the properties defined in this + document are defined as follows. The sensor tree bindings are responsibl= e for + defining whether each property is required or optional. + +properties: + label: + $ref: /schemas/types.yaml#/definitions/string + description: > + Descriptive label that allows to uniquely identify a device within + the system. + +additionalProperties: true + +... --=20 2.34.1 From nobody Wed Jul 1 13:27:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27CF3C433EF for ; Tue, 21 Dec 2021 17:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240665AbhLURuy (ORCPT ); Tue, 21 Dec 2021 12:50:54 -0500 Received: from aposti.net ([89.234.176.197]:39354 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240646AbhLURux (ORCPT ); Tue, 21 Dec 2021 12:50:53 -0500 From: Paul Cercueil To: Jean Delvare , Guenter Roeck , Rob Herring Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil , Cosmin Tanislav Subject: [PATCH 2/2] hwmon: Add "label" attribute Date: Tue, 21 Dec 2021 17:50:29 +0000 Message-Id: <20211221175029.144906-3-paul@crapouillou.net> In-Reply-To: <20211221175029.144906-1-paul@crapouillou.net> References: <20211221175029.144906-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If a label is defined in the device tree for this device add that to the device specific attributes. This is useful for userspace to be able to identify an individual device when multiple identical chips are present in the system. Signed-off-by: Paul Cercueil Tested-by: Cosmin Tanislav --- drivers/hwmon/hwmon.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 3501a3ead4ba..15826260a463 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -71,8 +71,23 @@ name_show(struct device *dev, struct device_attribute *a= ttr, char *buf) } static DEVICE_ATTR_RO(name); =20 +static ssize_t +label_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + const char *label; + int ret; + + ret =3D device_property_read_string(dev, "label", &label); + if (ret < 0) + return ret; + + return sysfs_emit(buf, "%s\n", label); +} +static DEVICE_ATTR_RO(label); + static struct attribute *hwmon_dev_attrs[] =3D { &dev_attr_name.attr, + &dev_attr_label.attr, NULL }; =20 @@ -81,7 +96,12 @@ static umode_t hwmon_dev_name_is_visible(struct kobject = *kobj, { struct device *dev =3D kobj_to_dev(kobj); =20 - if (to_hwmon_device(dev)->name =3D=3D NULL) + if (attr =3D=3D &dev_attr_name.attr && + to_hwmon_device(dev)->name =3D=3D NULL) + return 0; + + if (attr =3D=3D &dev_attr_label.attr && + !device_property_present(dev, "label")) return 0; =20 return attr->mode; --=20 2.34.1