From: Zaixiang Xu <zaixiang.xu.dev@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Zaixiang Xu <zaixiang.xu.dev@gmail.com>
Subject: [PATCH v7 3/4] hwmon: (sht3x) Add devicetree support
Date: Mon, 13 Jul 2026 15:45:58 +0800 [thread overview]
Message-ID: <20260713074559.12196-4-zaixiang.xu.dev@gmail.com> (raw)
In-Reply-To: <20260713074559.12196-1-zaixiang.xu.dev@gmail.com>
Add an of_device_id table to support devicetree based instantiation
of the supported sensors.
The devicetree binding models all higher accuracy parts with a
fallback to the base part of their group, so only the two base
compatibles need to be listed. The match data distinguishes the
humidity and temperature parts (SHT3x) from the temperature-only
parts (STS3x), which require different configuration.
Start enum sht3x_chips at 1: with sht3x equal to 0, the OF match
data for the SHT devices would be NULL, causing i2c_get_match_data()
to fall back to i2c_device_id name matching, which fails for
devicetree names. The devices would then only work because the
resulting chip id 0 happens to equal sht3x. Non-zero match data
avoids relying on that coincidence.
Signed-off-by: Zaixiang Xu <zaixiang.xu.dev@gmail.com>
---
drivers/hwmon/sht3x.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c
index c2f6b73aa7f3..6d47cfd340f8 100644
--- a/drivers/hwmon/sht3x.c
+++ b/drivers/hwmon/sht3x.c
@@ -61,7 +61,7 @@ static const unsigned char sht3x_cmd_read_serial_number[] = { 0x37, 0x80 };
#define SHT3X_MAX_HUMIDITY 100000
enum sht3x_chips {
- sht3x,
+ sht3x = 1,
sts3x,
};
@@ -939,8 +939,19 @@ static const struct i2c_device_id sht3x_ids[] = {
MODULE_DEVICE_TABLE(i2c, sht3x_ids);
+static const struct of_device_id sht3x_of_match[] = {
+ { .compatible = "sensirion,sht30", .data = (void *)(uintptr_t)sht3x },
+ { .compatible = "sensirion,sts30", .data = (void *)(uintptr_t)sts3x },
+ { }
+};
+
+MODULE_DEVICE_TABLE(of, sht3x_of_match);
+
static struct i2c_driver sht3x_i2c_driver = {
- .driver.name = "sht3x",
+ .driver = {
+ .name = "sht3x",
+ .of_match_table = sht3x_of_match,
+ },
.probe = sht3x_probe,
.id_table = sht3x_ids,
};
--
2.34.1
next prev parent reply other threads:[~2026-07-13 7:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 7:45 [PATCH v7 0/4] hwmon: (sht3x) Add support for GXCAS GXHT30 Zaixiang Xu
2026-07-13 7:45 ` [PATCH v7 1/4] dt-bindings: vendor-prefixes: Add GXCAS Technology Zaixiang Xu
2026-07-13 7:47 ` sashiko-bot
2026-07-13 7:45 ` [PATCH v7 2/4] dt-bindings: hwmon: Add Sensirion SHT30 series Zaixiang Xu
2026-07-13 7:55 ` sashiko-bot
2026-07-13 8:27 ` Zaixiang Xu
2026-07-13 7:45 ` Zaixiang Xu [this message]
2026-07-13 8:01 ` [PATCH v7 3/4] hwmon: (sht3x) Add devicetree support sashiko-bot
2026-07-13 8:28 ` Zaixiang Xu
2026-07-13 7:45 ` [PATCH v7 4/4] hwmon: (sht3x) Document support for GXCAS GXHT30 Zaixiang Xu
2026-07-13 7:48 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260713074559.12196-4-zaixiang.xu.dev@gmail.com \
--to=zaixiang.xu.dev@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox