From patchwork Thu Oct 20 21:03:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 6404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp323244wrr; Thu, 20 Oct 2022 14:06:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70NFgmvHRENZjpZz4YlS8uMJen/z8HguMrLRpvH9l2kXS/MY+YMUC9ForEDB3kFGoSxrPH X-Received: by 2002:a17:90b:1b0b:b0:20d:7c31:e75d with SMTP id nu11-20020a17090b1b0b00b0020d7c31e75dmr17744089pjb.101.1666299992267; Thu, 20 Oct 2022 14:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666299992; cv=none; d=google.com; s=arc-20160816; b=EtPt8T1nrevCioPRnewMKwGPdLB6ejoVchg8liMSE5leSjX/osrnTpSvHpfCgcJYHP MetpP4olGRJLBWvOqDGRnfdp5mhMQ2y+11uREA8g56Q4LaSsDHRD4QZ+1KSVkFznDUE6 ++/N5ykcucFc2ixqREgEDKk5XjqmXaawIi8xEwHRz7XPBJSFl5Ol3S0de4wFhj8cmCwr 2E97dmsK2XkHjp+RI9fOxvBr+V2LQxpnAzeqMLtamPnUE7IZ/ILxkVJdyBJw+AJuQHwF SMWe5kAxRNp+WyNs7BZJcyQ27uAIdwuOhnFmE/nnprduGTwalt3E/nZVOuK8QJwDYhum 1s7g== 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 :dkim-signature; bh=VcGsClt3EeHDOcwNreFbmj7M3tyyEYsggkdvW5UHGGM=; b=vfO6f9DL44nWRT6TNZSFo34aOjKwt776gUOnl9HzqrbjiOs7nn4cI2Tabpnm4mIkfE IxXNZF+ghuFYPC+5pyDrhLqp9Sd1o2aEtbObUohFx4CIKdilswsXIMAP8+SDFBQnGXnd GXBLpBmAGk318ZcMjQda12w9ySjVwn1OpmoZMJeab2eLUf/RBQ9N0/oAm+DLr5phKwTG U60Ns0yut6bNuWAoGmsqVNLLJXhvHghS+5+fJ3EHNxr/Xx0PUHAUKMU0g2l9+3AfKPM3 /ezSBehCjcX6pDO8Q6QVkoliqS8o+YGMnxBSWDmhfACPHuWAqFMer5ncyVT2RR6RsE0I cPpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=oLpOq5hM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j185-20020a638bc2000000b0043ab83b731asi23699200pge.689.2022.10.20.14.06.19; Thu, 20 Oct 2022 14:06:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=oLpOq5hM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbiJTVDz (ORCPT + 99 others); Thu, 20 Oct 2022 17:03:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbiJTVDr (ORCPT ); Thu, 20 Oct 2022 17:03:47 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DEC3CABC0; Thu, 20 Oct 2022 14:03:46 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id g27so1374018edf.11; Thu, 20 Oct 2022 14:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VcGsClt3EeHDOcwNreFbmj7M3tyyEYsggkdvW5UHGGM=; b=oLpOq5hMgEz8wPlei0nKhKh1Xpou/ksdbhusfa3NMyvCI+C68vxtrpTI3riwbsjvlY Qle2gY108r3XtwAq8ZMxr0pFoh2T0KANSzSE+E46ZQJ9WzE0qznHwSI47NAJ8n4diFjJ 7Mbn61S6+dLcsKHBhLkyWAPq6kjruhblVmQqXCueZsTBp1WU1dLT8n07EyyLejdsz78v CIznAV8C0b5gW3xtPT/fduziMZK6MxewF+sHN4jTqPbhARuwsiuO0wnE9YgoU+zhDLke 4Xxm6RFVoddWhPQiRdmsxGTBq7zek+LIl7kCWuEixLji89BK1eZJGgYe849e+t2F9Sz4 78IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VcGsClt3EeHDOcwNreFbmj7M3tyyEYsggkdvW5UHGGM=; b=vZzY93TsHc302d2Rgl/GU2pJnNNjmrYpcqboBKatEi9q+i/bVKkTwfnFNxN1+aOQ5I fuTB7xAsA9mvKwA2G07zNz1kc3vy9EGxZrTXfiHMpZcmaFc0OtJx2833cWDvZFubl2rG xzvdJhtgKpotUZmwHgab+z6r90H9c4THs91Mmyip/aIbuztVNcI+XGWNBg7YO/tWd/03 kYKLmDikmvvF0HsT5Wf4y3pVyhbZ1i5c/tRikLy+8XYVO6MIIm3+fjsHWJiWX4GJNrS9 ++QUSkTqlJUatzRCg6FKGm4xKCC3COkuitB1stt1nJBMWx9ke9S+tsZFHiwxf4hXObKZ 5DCA== X-Gm-Message-State: ACrzQf1r/s4xDS9cJcnPnxQXQOiSD6Rcc8TRwfTqs5HBQW50TM4jPcjj ssQcyWsMtWTARQaLl+wKbxY= X-Received: by 2002:a05:6402:26d2:b0:45d:280b:5878 with SMTP id x18-20020a05640226d200b0045d280b5878mr14204625edd.385.1666299824877; Thu, 20 Oct 2022 14:03:44 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a01-0c23-c046-3500-0000-0000-0000-0e63.c23.pool.telefonica.de. [2a01:c23:c046:3500::e63]) by smtp.googlemail.com with ESMTPSA id 18-20020a170906211200b00779cde476e4sm10748721ejt.62.2022.10.20.14.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:03:44 -0700 (PDT) From: Martin Blumenstingl To: linux@roeck-us.net, linux-hwmon@vger.kernel.org Cc: jdelvare@suse.com, linux-kernel@vger.kernel.org, Martin Blumenstingl Subject: [RFC PATCH v2 3/4] hwmon: (jc42) Restore the min/max/critical temperatures on resume Date: Thu, 20 Oct 2022 23:03:19 +0200 Message-Id: <20221020210320.1624617-4-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221020210320.1624617-1-martin.blumenstingl@googlemail.com> References: <20221020210320.1624617-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747242180651183326?= X-GMAIL-MSGID: =?utf-8?q?1747242180651183326?= The JC42 compatible thermal sensor on Kingston KSM32ES8/16ME DIMMs (using Micron E-Die) is an ST Microelectronics STTS2004 (manufacturer 0x104a, device 0x2201). It does not keep the previously programmed minimum, maximum and critical temperatures after system suspend and resume (which is a shutdown / startup cycle for the JC42 temperature sensor). This results in an alarm on system resume because the hardware default for these values is 0°C (so any environment temperature greater than 0°C will trigger the alarm). Example before system suspend: jc42-i2c-0-1a Adapter: SMBus PIIX4 adapter port 0 at 0b00 temp1: +34.8°C (low = +0.0°C) (high = +85.0°C, hyst = +85.0°C) (crit = +95.0°C, hyst = +95.0°C) Example after system resume (without this change): jc42-i2c-0-1a Adapter: SMBus PIIX4 adapter port 0 at 0b00 temp1: +34.8°C (low = +0.0°C) ALARM (HIGH, CRIT) (high = +0.0°C, hyst = +0.0°C) (crit = +0.0°C, hyst = +0.0°C) Apply the cached values from the JC42_REG_TEMP_UPPER, JC42_REG_TEMP_LOWER, JC42_REG_TEMP_CRITICAL and JC42_REG_SMBUS (where the SMBUS register is not related to this issue but a side-effect of using regcache_sync() during system resume with the previously cached/programmed values. This fixes the alarm due to the hardware defaults of 0°C because the previously applied limits (set by userspace) are re-applied on system resume. Fixes: 175c490c9e7f ("hwmon: (jc42) Add support for STTS2004 and AT30TSE004") Signed-off-by: Martin Blumenstingl --- drivers/hwmon/jc42.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index 3f524ab5451c..61311483a5c6 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c @@ -582,6 +582,10 @@ static int jc42_suspend(struct device *dev) data->config |= JC42_CFG_SHUTDOWN; regmap_write(data->regmap, JC42_REG_CONFIG, data->config); + + regcache_cache_only(data->regmap, true); + regcache_mark_dirty(data->regmap); + return 0; } @@ -589,9 +593,13 @@ static int jc42_resume(struct device *dev) { struct jc42_data *data = dev_get_drvdata(dev); + regcache_cache_only(data->regmap, false); + data->config &= ~JC42_CFG_SHUTDOWN; regmap_write(data->regmap, JC42_REG_CONFIG, data->config); - return 0; + + /* Restore cached register values to hardware */ + return regcache_sync(data->regmap); } static const struct dev_pm_ops jc42_dev_pm_ops = {