From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793418518; b=3YScrb8ReLaMECjMhlWk7khTDiv4hXu+0lklN/5nBJFo7en7IJ4+o/Dwffif+0Atx1qV GfUqFAmy3C4o2/+0jENhIzAXW46W2TJInK5SZxb6Ay4ojf0YOZUgHXM3GxXi2rVvwBJEk EDZLN36MAg20cKVBQbshOK+3uMyNebEykMOYF9xys7msuLMs3EcP8WP7xoeO/nEKORIjI BfpzIsxVwvgRMNaKxXpl/Pf5nsuHr0fMT8x3Nhjhdd5Hr7MQ9k5CydGDsjJtSqYDQrwIT Hz1ICupL8VcLHYHq5/QPEjEYY7B0D8pPw/4a1DrDc9v0ETSxo/IKciBebKj8lexBEew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793418518; h=DMARC-Filter:Received:Received:X-Authority-Analysis:DKIM-Signature: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Type:Content-Transfer-Encoding:X-AntiAbuse:X-AntiAbuse: X-AntiAbuse:X-AntiAbuse:X-AntiAbuse:X-BWhitelist:X-Source-IP: X-Source-L:X-Exim-ID:X-Source:X-Source-Args:X-Source-Dir: X-Source-Sender:X-Source-Auth:X-Email-Count:X-Org:X-Source-Cap: X-Local-Domain:X-CMAE-Envelope; bh=MDdIdi5+ffHd758cvPs70oCm+GjydlyLzm7J3zfaTck=; b=TkE/PUeBi7CzPWFi/vFQrAohyutfXS3fXjgVcDpYTfBZEs4E5Sc1th7W7UL5eXdVw+A7 9mxrm0/Gct3+Flf971YcyRpbpS0lF7Scrp5G/vdyyQZZYMlK10+t5lONF2PRN7oRhe6g0 tdyprUNFD+tQeosLdSqIDgpdfhRXsSGwELc8Le04anPb5Sfh2Hj0X7hhqfoq+6f2o6LDp 4EnImEUppyFeDaIjD/1UK2dZelyWwEIOpWtXO1lzxu41e75DW94HUWNhB1ti5+rR4fp/F vZFYwxw4q4gUjn0gRX1bFoliQmHFmg8VpSz0akn2k+in3duuWOlZ0g5ozDfVdiJmpDw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=roeck-us.net; spf=fail smtp.mailfrom=roeck-us.net; dkim=pass header.d=roeck-us.net header.i=@roeck-us.net header.a=rsa-sha256 header.s=default header.b=BxJtzJmE; arc=none smtp.remote-ip=44.202.169.39 Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F306606A31A for ; Sat, 31 Oct 2026 03:48:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F306606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=roeck-us.net header.i=@roeck-us.net header.a=rsa-sha256 header.s=default header.b=BxJtzJmE Received: from eig-obgw-6003b.ext.cloudfilter.net ([10.0.30.175]) by cmsmtp with ESMTPS id MwVvxHjSZMylkN056xkKga; Sat, 31 Oct 2026 03:48:36 +0000 Received: from 162-215-252-36.unifiedlayer.com ([208.91.199.152]) by cmsmtp with ESMTPS id N055xkhDU1fkWN056xPKH7; Sat, 31 Oct 2026 03:48:36 +0000 X-Authority-Analysis: v=2.4 cv=CLMqXQrD c=1 sm=1 tr=0 ts=6ae56514 a=QNED+QcLUkoL9qulTODnwA==:117 a=2cfIYNtKkjgZNaOwnGXpGw==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=M0FbrtG7MMAA:10 a=VwQbUJbxAAAA:8 a=_jlGtV7tAAAA:8 a=yK5Kont1CLQfG7VcaMoA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=nlm17XC03S6CtCLSeiRr:22 a=KPbNTLLc3YvdawN95zVk:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MDdIdi5+ffHd758cvPs70oCm+GjydlyLzm7J3zfaTck=; b=BxJtzJmEr85GfvucVyPc87w0HR gRRx1R2x9yuinKJv6WjzBTuSAgJ9fzMeLqxiKiF7wrVZEHclu4wR5w5rWaV3mPCUIodr3OOfhC1x+ LZLSekz/fzFzn5zlmLY1fR88BgedPeryCYfIimyMYKPHpqRVHFGUyK9hMIT4kNOW5hDRIQ1HDb7fT JEMJEVAAQasn8ETO4x4krrMlhvKLX/bXSR4PscIWqNzSr8YCg9MHe9/PFUZZ3rpS0EtJtY6zjr9NU K3+9wJPBQCg3ziIkGWQqn1yA/X9kk1W4TraEMDDYIYSzhfBHYKqTITcJt9hROE8+cCYOTFZ335aUq l4GcRnug==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:58590 helo=server.roeck-us.net) by bh-25.webhostbox.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xN055-00000003hdO-2hgq; Sat, 31 Oct 2026 09:18:35 +0530 From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: Guenter Roeck , Sashiko Subject: [PATCH] hwmon: (tmp108) Fix initial conversion delay and wait until ready Date: Fri, 30 Oct 2026 20:48:34 -0700 Message-ID: <20261031034834.1079813-1-linux@roeck-us.net> X-Mailer: git-send-email 2.45.2 X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-BWhitelist: no X-Source-IP: 108.223.40.66 X-Source-L: No X-Exim-ID: 1xN055-00000003hdO-2hgq X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 108-223-40-66.lightspeed.sntcca.sbcglobal.net (server.roeck-us.net) [108.223.40.66]:58590 X-Source-Auth: guenter@roeck-us.net X-Email-Count: 4 X-Org: HG=direseller_whb_net_legacy;ORG=directi; X-Source-Cap: cm9lY2s7YWN0aXZzdG07YmgtMjUud2ViaG9zdGJveC5uZXQ= X-Local-Domain: yes X-CMAE-Envelope: MS4xfNDMqaGrLhNi8bNZFPoE4G3WvocwqX7wdXoT9HucS+jDTvI1brDHp3t16By+dNmHVygDM4Glxs9KWY0KuOIX3s7q1L0T6RcUmXaTZDlXYGsf+zUdF29v TEx04gJ9sJc+BuLAd0++Vb9e9Zibstsi1gPAJObO1NCQcWHTC4AUhyiBr79yoGcQYPbxQ0RM02WXrK8VhD0D/jgBchweqeAk67eqIzT22o/ClmIGjpyNeYOL In tmp108_common_probe(), the driver only adds the 30 ms conversion delay (TMP108_CONVERSION_TIME_MS) to ready_time if the sensor was previously in TMP108_MODE_SHUTDOWN. However, the TMP108 hardware defaults to continuous conversion mode (TMP108_MODE_CONTINUOUS) upon power-on reset, including immediately after enabling the vcc supply regulator during probe, while the temperature register retains its power-on reset value of 0x0000 (0°C) until the first conversion completes. Because the initial mode is not shutdown, the delay is bypassed and early reads via thermal zone registration or sysfs before the first conversion finishes return an uninitialized 0°C reading. In addition, returning -EAGAIN from tmp108_read() while waiting for a conversion to complete after probe or resume can trigger an unnecessary tight retry loop in callers or fail initial reads. Unconditionally set ready_time to TMP108_CONVERSION_TIME_MS ahead in tmp108_common_probe(), track ready_time as ktime_t, and wait for the remaining conversion time in tmp108_read() using usleep_range() instead of returning -EAGAIN. Reported-by: Sashiko Fixes: 66e1c9171339 ("hwmon: Add Texas Instruments TMP108 temperature sensor driver.") Signed-off-by: Guenter Roeck --- drivers/hwmon/tmp108.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c index 91d20a1ce112..862b944d3e60 100644 --- a/drivers/hwmon/tmp108.c +++ b/drivers/hwmon/tmp108.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -78,7 +78,7 @@ struct tmp108 { struct regmap *regmap; u16 orig_config; - u64 ready_time; + ktime_t ready_time; const struct tmp108_params *params; }; @@ -121,6 +121,7 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type, struct tmp108 *tmp108 = dev_get_drvdata(dev); unsigned int regval; int err, hyst; + s64 delay; if (type == hwmon_chip) { if (attr == hwmon_chip_update_interval) { @@ -137,12 +138,10 @@ static int tmp108_read(struct device *dev, enum hwmon_sensor_types type, switch (attr) { case hwmon_temp_input: - /* Is it too early to return a conversion ? */ - if (time_before64(get_jiffies_64(), tmp108->ready_time)) { - dev_dbg(dev, "%s: Conversion not ready yet..\n", - __func__); - return -EAGAIN; - } + /* Wait if it is too early to return a conversion */ + delay = ktime_us_delta(tmp108->ready_time, ktime_get()); + if (delay > 0) + usleep_range(delay, delay + 1000); err = regmap_read(tmp108->regmap, TMP108_REG_TEMP, ®val); if (err < 0) return err; @@ -477,11 +476,8 @@ static int tmp108_common_probe(struct device *dev, struct regmap *regmap, char * return err; } - tmp108->ready_time = get_jiffies_64(); - if ((tmp108->orig_config & TMP108_CONF_MODE_MASK) == - TMP108_MODE_SHUTDOWN) - tmp108->ready_time += - msecs_to_jiffies(TMP108_CONVERSION_TIME_MS); + tmp108->ready_time = ktime_add_ms(ktime_get(), + TMP108_CONVERSION_TIME_MS); err = devm_add_action_or_reset(dev, tmp108_restore_config, tmp108); if (err) { @@ -528,8 +524,8 @@ static int tmp108_resume(struct device *dev) err = regmap_update_bits(tmp108->regmap, TMP108_REG_CONF, TMP108_CONF_MODE_MASK, TMP108_MODE_CONTINUOUS); - tmp108->ready_time = get_jiffies_64() + - msecs_to_jiffies(TMP108_CONVERSION_TIME_MS); + tmp108->ready_time = ktime_add_ms(ktime_get(), + TMP108_CONVERSION_TIME_MS); return err; } -- 2.45.2