From patchwork Mon Dec 4 16:50:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Gloor X-Patchwork-Id: 173462 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2892824vqy; Mon, 4 Dec 2023 08:52:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6sF7UXEJRJRE5Gfwy5LwzlUbzTM5E+4wtUyS9jGKQL1YcknbtJ/m7rV9CX2tG7TaS4tEe X-Received: by 2002:a05:6a20:5151:b0:18c:651:c40e with SMTP id b17-20020a056a20515100b0018c0651c40emr4090336pzc.50.1701708741212; Mon, 04 Dec 2023 08:52:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701708741; cv=none; d=google.com; s=arc-20160816; b=ofW/onqWyeXEs3ULgK47tfvtBxCJIF7ZeTaSOZ4vLP1bgWfka3ysHigTpQKMPFpDty n9GxS8aDfchsDy5xu+pU0cuyTH3ubYeIPM2qBbsVqfsYVvEl4RXgAVeQo3VMBfyw+lm4 Q/CHHtIBi9p7McN9d9OvoSMn6SoPQr/SNvFvSMdw4509m5bOTSqTXSI10gfml4mTFq/A djEISqUJN0w8AAcsHei6/Qt7hzlmSCbcBJ/RAyqVhxBvohwZ6i4nMCX6Rj4slAI1elLt Lip/M6Uq7/FCTBRS8VeKgjbNN2DqY0V0tCYVmscWy8dw5x58qSEf5TYERwwmtxM0GirJ bEPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eUmRc1qv4lJFw0jikkqXdpFyDJspUjwfKoRI9Ht+6BA=; fh=fjNSoY0LvOsWcORqEKQpjzRbUZLsws7xZhkeCHIPeqI=; b=qwewjmt+cnA7Wzd8X+2ZljyH2ZJWNv3oSm1qEsAY6ASi5HE+bDSlz0kRTrvj/nDABD RemRTRSX6HJENfEeMvHKtmHqBzgsds7ve2/2Tn/frvC9aDRdIXijpTpwfddvmTYjrb5d eVTqcmm02yXjCr/NK4RxXVgjPIVr1VBWz6RakKScQY/x1v1cY47PypkcJuB+PR/gbTMM w5xSxQ+h4KEllQwfIDuNPrC5EmpQdXMUvVnZswkerN8wr2BnhjOzsUGRNy4YAPc6iz6q ipWXjmxow+r2DI98Lh3pgs5NY9WXXbC++HWMtno7f+1WjFLJqxgk+/Rrlu9UJ7aMUZxv dQEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m2-20020a63ed42000000b005c6617f183fsi4013085pgk.303.2023.12.04.08.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:52:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6F42E80A4A30; Mon, 4 Dec 2023 08:52:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235441AbjLDQvu (ORCPT + 99 others); Mon, 4 Dec 2023 11:51:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbjLDQvn (ORCPT ); Mon, 4 Dec 2023 11:51:43 -0500 Received: from mxout017.mail.hostpoint.ch (mxout017.mail.hostpoint.ch [IPv6:2a00:d70:0:e::317]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B0F2BB; Mon, 4 Dec 2023 08:51:48 -0800 (PST) Received: from [10.0.2.46] (helo=asmtp013.mail.hostpoint.ch) by mxout017.mail.hostpoint.ch with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96.2 (FreeBSD)) (envelope-from ) id 1rACAV-000EP4-1k; Mon, 04 Dec 2023 17:51:39 +0100 Received: from 157.20.79.83.dynamic.wline.res.cust.swisscom.ch ([83.79.20.157] helo=thinkpad.localdomain) by asmtp013.mail.hostpoint.ch with esmtpa (Exim 4.96.2 (FreeBSD)) (envelope-from ) id 1rACAV-000JX2-1G; Mon, 04 Dec 2023 17:51:39 +0100 X-Authenticated-Sender-Id: code@stefan-gloor.ch From: Stefan Gloor To: jdelvare@suse.com, linux@roeck-us.net, corbet@lwn.net, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stefan Gloor Subject: [PATCH v2 1/2] hwmon: sht3x: add sts3x support Date: Mon, 4 Dec 2023 17:50:03 +0100 Message-ID: <20231204165004.8491-2-code@stefan-gloor.ch> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231204165004.8491-1-code@stefan-gloor.ch> References: <20231204165004.8491-1-code@stefan-gloor.ch> MIME-Version: 1.0 X-Vs-State: 0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 08:52:18 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784370944991360336 X-GMAIL-MSGID: 1784370944991360336 Add information regarding the existing support for sts3x series and update the datasheet links. Signed-off-by: Stefan Gloor --- Documentation/hwmon/sht3x.rst | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Documentation/hwmon/sht3x.rst b/Documentation/hwmon/sht3x.rst index 87864ffd1777..957c854f5d08 100644 --- a/Documentation/hwmon/sht3x.rst +++ b/Documentation/hwmon/sht3x.rst @@ -9,7 +9,19 @@ Supported chips: Addresses scanned: none - Datasheet: https://www.sensirion.com/file/datasheet_sht3x_digital + Datasheets: + - https://sensirion.com/media/documents/213E6A3B/63A5A569/Datasheet_SHT3x_DIS.pdf + - https://sensirion.com/media/documents/051DF50B/639C8101/Sensirion_Humidity_and_Temperature_Sensors_Datasheet_SHT33.pdf + + * Sensirion STS3x-DIS + + Prefix: 'sts3x' + + Addresses scanned: none + + Datasheets: + - https://sensirion.com/media/documents/1DA31AFD/61641F76/Sensirion_Temperature_Sensors_STS3x_Datasheet.pdf + - https://sensirion.com/media/documents/292A335C/65537BAF/Sensirion_Datasheet_STS32_STS33.pdf Author: @@ -19,16 +31,17 @@ Author: Description ----------- -This driver implements support for the Sensirion SHT3x-DIS chip, a humidity -and temperature sensor. Temperature is measured in degrees celsius, relative -humidity is expressed as a percentage. In the sysfs interface, all values are -scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500. +This driver implements support for the Sensirion SHT3x-DIS and STS3x-DIS +series of humidity and temperature sensors. Temperature is measured in degrees +celsius, relative humidity is expressed as a percentage. In the sysfs interface, +all values are scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500. The device communicates with the I2C protocol. Sensors can have the I2C -addresses 0x44 or 0x45, depending on the wiring. See -Documentation/i2c/instantiating-devices.rst for methods to instantiate the device. +addresses 0x44 or 0x45 (0x4a or 0x4b for sts3x), depending on the wiring. See +Documentation/i2c/instantiating-devices.rst for methods to instantiate the +device. -Even if sht3x sensor supports clock-strech(blocking mode) and non-strench +Even if sht3x sensor supports clock-stretch (blocking mode) and non-stretch (non-blocking mode) in single-shot mode, this driver only supports the latter. The sht3x sensor supports a single shot mode as well as 5 periodic measure From patchwork Mon Dec 4 16:50:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Gloor X-Patchwork-Id: 173461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2892731vqy; Mon, 4 Dec 2023 08:52:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFALLlQv6ne4J5LmD8xYGqcnRtNvFN4+SqZWIVBz0H8LC1Bx6pdBKYYjO9KTJ/hDDgIBfYa X-Received: by 2002:a17:90a:d253:b0:286:6cc1:5fbd with SMTP id o19-20020a17090ad25300b002866cc15fbdmr1537136pjw.64.1701708731655; Mon, 04 Dec 2023 08:52:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701708731; cv=none; d=google.com; s=arc-20160816; b=neXSyWlqhgnyDQBp9fZkr0p18r0C4hxohmnqM1H68j+cBEINfJcjDMOuRl6yPtuDiK wfN7tObl+/uns97w3NvFf8eCsaxKzEMkvtxDLztdUFxxjhAa58yrAg0gd37k+m6lr+V1 Plqj57Ee3agA7P3GtZ7gpraluft4Oq8ory4iDHwHX7BdP2tPYwTs4qGIqe58czDyIXIy YUVOf9eWGqeAgg6CapU4ciETisPuLyroiXu0ixB+DTeTNvD8MJQEXGa/J7UlgOgeXtVg 7b2BVUxvMv0K7UFboq5+eXQ7zCiKnprFIIVbu5BrcgsmlTBpyHyCt/3fSbHxqFIiEAom ji6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Im1qHCVNryxTcA/Flm0iD60Cvm+G/LZvF6CGft8F870=; fh=fjNSoY0LvOsWcORqEKQpjzRbUZLsws7xZhkeCHIPeqI=; b=UocPDSZwZnVubm9GjCLOyJqNtklHwY51op73heNBPUG4tWx4UlBH7+fSq3x+ArnFk9 JUvhWKGk+OkU/GwNxD5NZ3YA8EGP85lEd3e0Mn9kDjPB1iqGtJk0APIUSC1/jZO2LhGN Yg2+4UiCg90Ams05WapcURXEWYJX93rJzMi5GCCFahtquDnB++edHF72yhA9kTdb8Qmp PyszynTaYOcxorI0r6a2ekUBA9yzdl/q5SxNTYQYHoph7IBLF4pSnm7n9ZunaUsqxbGp uQ+bhvne3IiCSLCC9pFn9RLgVitnNOFe3W7kIjsZKiSzYpHrQCqPLvc9eGcq7bcmKDzl gMrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id cu23-20020a17090afa9700b00286a6ea90a6si2202468pjb.119.2023.12.04.08.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:52:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 52EA18034628; Mon, 4 Dec 2023 08:52:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235438AbjLDQvr (ORCPT + 99 others); Mon, 4 Dec 2023 11:51:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235424AbjLDQvn (ORCPT ); Mon, 4 Dec 2023 11:51:43 -0500 Received: from mxout017.mail.hostpoint.ch (mxout017.mail.hostpoint.ch [IPv6:2a00:d70:0:e::317]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 356B3C6; Mon, 4 Dec 2023 08:51:48 -0800 (PST) Received: from [10.0.2.46] (helo=asmtp013.mail.hostpoint.ch) by mxout017.mail.hostpoint.ch with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96.2 (FreeBSD)) (envelope-from ) id 1rACAV-000EP8-2S; Mon, 04 Dec 2023 17:51:39 +0100 Received: from 157.20.79.83.dynamic.wline.res.cust.swisscom.ch ([83.79.20.157] helo=thinkpad.localdomain) by asmtp013.mail.hostpoint.ch with esmtpa (Exim 4.96.2 (FreeBSD)) (envelope-from ) id 1rACAV-000JX2-1i; Mon, 04 Dec 2023 17:51:39 +0100 X-Authenticated-Sender-Id: code@stefan-gloor.ch From: Stefan Gloor To: jdelvare@suse.com, linux@roeck-us.net, corbet@lwn.net, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stefan Gloor Subject: [PATCH v2 2/2] hwmon: sht3x: read out sensor serial number Date: Mon, 4 Dec 2023 17:50:04 +0100 Message-ID: <20231204165004.8491-3-code@stefan-gloor.ch> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231204165004.8491-1-code@stefan-gloor.ch> References: <20231204165004.8491-1-code@stefan-gloor.ch> MIME-Version: 1.0 X-Vs-State: 0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 04 Dec 2023 08:52:07 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784370935003273167 X-GMAIL-MSGID: 1784370935003273167 The temperature/humidity sensors of the STS3x/SHT3x family are calibrated and factory-programmed with a unique serial number. For some sensors, this serial number can be used to obtain a calibration certificate via an API provided by the manufacturer (Sensirion). Expose the serial number via debugfs. Tested with: 2x STS31, 1x STS32, 1x SHT31 Signed-off-by: Stefan Gloor --- Documentation/hwmon/sht3x.rst | 11 +++++++ drivers/hwmon/sht3x.c | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/Documentation/hwmon/sht3x.rst b/Documentation/hwmon/sht3x.rst index 957c854f5d08..9585fa7c5a5d 100644 --- a/Documentation/hwmon/sht3x.rst +++ b/Documentation/hwmon/sht3x.rst @@ -65,6 +65,10 @@ When the temperature and humidity readings move back between the hysteresis values, the alert bit is set to 0 and the alert pin on the sensor is set to low. +The serial number exposed to debugfs allows for unique identification of the +sensors. For sts32, sts33 and sht33, the manufacturer provides calibration +certificates through an API. + sysfs-Interface --------------- @@ -99,3 +103,10 @@ repeatability: write or read repeatability, higher repeatability means - 1: medium repeatability - 2: high repeatability =================== ============================================================ + +debugfs-Interface +----------------- + +=================== ============================================================ +serial_number: unique serial number of the sensor in decimal +=================== ============================================================ diff --git a/drivers/hwmon/sht3x.c b/drivers/hwmon/sht3x.c index 79657910b79e..537365c6213b 100644 --- a/drivers/hwmon/sht3x.c +++ b/drivers/hwmon/sht3x.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,7 @@ static const unsigned char sht3x_cmd_heater_off[] = { 0x30, 0x66 }; /* other commands */ static const unsigned char sht3x_cmd_read_status_reg[] = { 0xf3, 0x2d }; static const unsigned char sht3x_cmd_clear_status_reg[] = { 0x30, 0x41 }; +static const unsigned char sht3x_cmd_read_serial_number[] = { 0x37, 0x80 }; /* delays for single-shot mode i2c commands, both in us */ #define SHT3X_SINGLE_WAIT_TIME_HPM 15000 @@ -163,12 +165,14 @@ struct sht3x_data { enum sht3x_chips chip_id; struct mutex i2c_lock; /* lock for sending i2c commands */ struct mutex data_lock; /* lock for updating driver data */ + struct dentry *debugfs; u8 mode; const unsigned char *command; u32 wait_time; /* in us*/ unsigned long last_update; /* last update in periodic mode*/ enum sht3x_repeatability repeatability; + u32 serial_number; /* * cached values for temperature and humidity and limits @@ -831,6 +835,50 @@ static int sht3x_write(struct device *dev, enum hwmon_sensor_types type, } } +#ifdef CONFIG_DEBUG_FS + +static void sht3x_debugfs_init(struct sht3x_data *data) +{ + char name[32]; + struct dentry *sensor_dir; + + data->debugfs = debugfs_lookup("sht3x", NULL); + if (IS_ERR_OR_NULL(data->debugfs)) + data->debugfs = debugfs_create_dir("sht3x", NULL); + + snprintf(name, sizeof(name), "i2c%u-%02x", + data->client->adapter->nr, data->client->addr); + sensor_dir = debugfs_create_dir(name, data->debugfs); + debugfs_create_u32("serial_number", 0444, + sensor_dir, &data->serial_number); +} + +#else + +static void sht3x_debugfs_init(struct sht3x_data *data) +{ +} + +#endif + +static int sht3x_serial_number_read(struct sht3x_data *data) +{ + int ret; + char buffer[SHT3X_RESPONSE_LENGTH]; + struct i2c_client *client = data->client; + + ret = sht3x_read_from_command(client, data, + sht3x_cmd_read_serial_number, + buffer, + SHT3X_RESPONSE_LENGTH, 0); + if (ret) + return ret; + + data->serial_number = (buffer[0] << 24) | (buffer[1] << 16) | + (buffer[3] << 8) | buffer[4]; + return ret; +} + static const struct hwmon_ops sht3x_ops = { .is_visible = sht3x_is_visible, .read = sht3x_read, @@ -899,6 +947,13 @@ static int sht3x_probe(struct i2c_client *client) if (ret) return ret; + ret = sht3x_serial_number_read(data); + if (ret) { + dev_dbg(dev, "unable to read serial number\n"); + data->serial_number = 0; + } + sht3x_debugfs_init(data); + hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data,