From patchwork Fri Oct 21 16:49:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 6870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp803453wrr; Fri, 21 Oct 2022 09:57:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7SJkokthmNkfR4SdFIARzqBuc7FA/sYf29dDqjxm2PUeHlGVrAapnKFMl7uRhYTpE9LKBx X-Received: by 2002:a17:907:7da5:b0:78e:2c3b:55a2 with SMTP id oz37-20020a1709077da500b0078e2c3b55a2mr16141681ejc.96.1666371474160; Fri, 21 Oct 2022 09:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666371474; cv=none; d=google.com; s=arc-20160816; b=XU36lUmaUEoTohzViNh1/Jpy0gcboMrRWu7GhcYBdY7NidijwqExHHK4Buito6KYBv z8n0174kFdf7ErDygEgOkeMg8jOvzBuemZwi+yl5qHx/RlYlYNUx8+eAK6LluUkU8oW6 5GFCPYirFXdbdTCz5yNew0lmXojKf4f9pMED4JvYVAjydRuYitXhLEajJhlIvsOiBZ// 6MPGFhEvGzJdWDlnalkeC71MhpmUkbUpqHEk+zRlYUGMVw2NCQLGGYxqHuoBZPZBbbbo fqjmtu9+YxkM7bjjIzv63J2sbT79b3Pi5Dxy3sLX0nyPxNDKWbQKuIHtpCYpSAs6rXfO I3Wg== 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=k7Y+/ddtJyLJ3y+Tsy2pWfsNMuVl2yzDPLL4Knpi5uQ=; b=w8SEWu8CgRcDVi6uSkEA2h6LcXAwzCJn2HLO2gcLgMeL8sAibH0k2Nh38vOd2mO061 nn7Qkf1EX+jT6BCbrO7bcx+P0mxxL/hlC6/FLrUs3bsQ3Yw+23pEBfmxaxg/ShXvofH6 tWGd0OuZsixbIC4oyfObxSH71V4g1UyKO6LGlfJgWTaJdDG7M8cpWz0l2qtPv7lXjgST 4tOYce4ioaThAVlWVJLPdX4M6W4nSSQUq/YpN9ZWKfZ/aQeLOEJU+ViTDvQju2jTfNVl WXwCQcl238HY81guBSG8WTDrYPGeE+So/dbMrPDZh6yJvZQkf7J/vdqgIY4AKrIIgMaq ySfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=JmR6uqmr; 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 y11-20020a056402358b00b0045d22bc81a0si21229567edc.231.2022.10.21.09.57.27; Fri, 21 Oct 2022 09:57:54 -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=JmR6uqmr; 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 S230477AbiJUQuj (ORCPT + 99 others); Fri, 21 Oct 2022 12:50:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229867AbiJUQuV (ORCPT ); Fri, 21 Oct 2022 12:50:21 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2472247E1D; Fri, 21 Oct 2022 09:50:16 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id t16so8118816edd.2; Fri, 21 Oct 2022 09:50:16 -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=k7Y+/ddtJyLJ3y+Tsy2pWfsNMuVl2yzDPLL4Knpi5uQ=; b=JmR6uqmrN8Zk9EGQSPo9yTgif7RPsu0jbccyDDVVqODFTNKicFsGDxRFa0Wjy27em7 3dpc8lFlDhmBZuoiU3Kk3/Buvwl73Nq2iRVI8829rWrjPKMzc6KpC5hppZgcfGogHpY5 fuRHYL1S9+U/zcvN34WLJN0AsSUfJLs3RLfjMo2jmRhqMdZ9t7KKtZUJMQtXFq6fHV4o klaoBnf8yaVEfbrow3fX39Ztd+UomzbbFCd353vR7CiXlu4qcxNrX5mplW94ZgCtUS+T 5xgTG5QjNKqPCnoLHwGP4zwgpm8g7mS4H5fyyr4PVXypRX2d9rFzGPUJm9pRPhfY6ifI zvZA== 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=k7Y+/ddtJyLJ3y+Tsy2pWfsNMuVl2yzDPLL4Knpi5uQ=; b=nYt/xOuWNS4XNpaJSOgpA1hECqviDUPb91/Pc4UK9Cq2atfEq8Qvw4n+nlMKIxIM54 vqfyGvK7VHk2FTJQlt5r2xk+1v+j29C7fK9XM0W9vC5MAdPD/MXy77oy48wNhZAoP162 d7v7qfY/uyw3qewmtdjuc/0uYryuPgOOX6FWKU/WpKkiqlKyKMJyYjNQooMwmBxHhOkA Ocs9YtL29lpXy7GwM4EFQUDkbxjH6/Hnx+BVs8nOSOTdfFfGgMdpCjDsw0zTIHld1Rq1 FS378AuLu8awqlkKCQqQUp/Zw794yA0m5aqVtdaq3lLQqyD7YIlUqOz6civxSZt4dD5N +uiQ== X-Gm-Message-State: ACrzQf3jf+N/mFXtVPJD7P7QvrzV4qqeI4s7afom8L9CYTVzXu67AcDl 1yQdNR6SVnPAlyDcadjh6w2bDf7sm3o= X-Received: by 2002:a17:907:7203:b0:792:56d7:2851 with SMTP id dr3-20020a170907720300b0079256d72851mr12035419ejc.268.1666371015000; Fri, 21 Oct 2022 09:50:15 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a01-0c22-7b0b-4500-0000-0000-0000-0e63.c22.pool.telefonica.de. [2a01:c22:7b0b:4500::e63]) by smtp.googlemail.com with ESMTPSA id l23-20020aa7d957000000b0044ef2ac2650sm13725331eds.90.2022.10.21.09.50.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 09:50:14 -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: [PATCH v3 1/2] hwmon: (jc42) Convert register access and caching to regmap/regcache Date: Fri, 21 Oct 2022 18:49:59 +0200 Message-Id: <20221021165000.1865615-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221021165000.1865615-1-martin.blumenstingl@googlemail.com> References: <20221021165000.1865615-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?1747317134815699964?= X-GMAIL-MSGID: =?utf-8?q?1747317134815699964?= Switch the jc42 driver to use an I2C regmap to access the registers. Also move over to regmap's built-in caching instead of adding a custom caching implementation. This works for JC42_REG_TEMP_UPPER, JC42_REG_TEMP_LOWER and JC42_REG_TEMP_CRITICAL as these values never change except when explicitly written. The cache For JC42_REG_TEMP is dropped (regmap can't cache it because it's volatile, meaning it can change at any time) as well for simplicity and consistency with other drivers. Signed-off-by: Martin Blumenstingl --- drivers/hwmon/Kconfig | 1 + drivers/hwmon/jc42.c | 214 +++++++++++++++++++++++------------------- 2 files changed, 116 insertions(+), 99 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 7ac3daaf59ce..d3bccc8176c5 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -799,6 +799,7 @@ config SENSORS_IT87 config SENSORS_JC42 tristate "JEDEC JC42.4 compliant memory module temperature sensors" depends on I2C + select REGMAP_I2C help If you say yes here, you get support for JEDEC JC42.4 compliant temperature sensors, which are used on many DDR3 memory modules for diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index 30888feaf589..8d70960d5444 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c @@ -19,6 +19,7 @@ #include #include #include +#include /* Addresses to scan */ static const unsigned short normal_i2c[] = { @@ -199,31 +200,13 @@ static struct jc42_chips jc42_chips[] = { { STM_MANID, STTS3000_DEVID, STTS3000_DEVID_MASK }, }; -enum temp_index { - t_input = 0, - t_crit, - t_min, - t_max, - t_num_temp -}; - -static const u8 temp_regs[t_num_temp] = { - [t_input] = JC42_REG_TEMP, - [t_crit] = JC42_REG_TEMP_CRITICAL, - [t_min] = JC42_REG_TEMP_LOWER, - [t_max] = JC42_REG_TEMP_UPPER, -}; - /* Each client has this additional data */ struct jc42_data { - struct i2c_client *client; - struct mutex update_lock; /* protect register access */ + struct regmap *regmap; bool extended; /* true if extended range supported */ bool valid; - unsigned long last_updated; /* In jiffies */ u16 orig_config; /* original configuration */ u16 config; /* current configuration */ - u16 temp[t_num_temp];/* Temperatures */ }; #define JC42_TEMP_MIN_EXTENDED (-40000) @@ -248,74 +231,84 @@ static int jc42_temp_from_reg(s16 reg) return reg * 125 / 2; } -static struct jc42_data *jc42_update_device(struct device *dev) -{ - struct jc42_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - struct jc42_data *ret = data; - int i, val; - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { - for (i = 0; i < t_num_temp; i++) { - val = i2c_smbus_read_word_swapped(client, temp_regs[i]); - if (val < 0) { - ret = ERR_PTR(val); - goto abort; - } - data->temp[i] = val; - } - data->last_updated = jiffies; - data->valid = true; - } -abort: - mutex_unlock(&data->update_lock); - return ret; -} - static int jc42_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { - struct jc42_data *data = jc42_update_device(dev); - int temp, hyst; - - if (IS_ERR(data)) - return PTR_ERR(data); + struct jc42_data *data = dev_get_drvdata(dev); + unsigned int regval; + int ret, temp, hyst; switch (attr) { case hwmon_temp_input: - *val = jc42_temp_from_reg(data->temp[t_input]); + ret = regmap_read(data->regmap, JC42_REG_TEMP, ®val); + if (ret) + return ret; + + *val = jc42_temp_from_reg(regval); return 0; case hwmon_temp_min: - *val = jc42_temp_from_reg(data->temp[t_min]); + ret = regmap_read(data->regmap, JC42_REG_TEMP_LOWER, ®val); + if (ret) + return ret; + + *val = jc42_temp_from_reg(regval); return 0; case hwmon_temp_max: - *val = jc42_temp_from_reg(data->temp[t_max]); + ret = regmap_read(data->regmap, JC42_REG_TEMP_UPPER, ®val); + if (ret) + return ret; + + *val = jc42_temp_from_reg(regval); return 0; case hwmon_temp_crit: - *val = jc42_temp_from_reg(data->temp[t_crit]); + ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL, + ®val); + if (ret) + return ret; + + *val = jc42_temp_from_reg(regval); return 0; case hwmon_temp_max_hyst: - temp = jc42_temp_from_reg(data->temp[t_max]); + ret = regmap_read(data->regmap, JC42_REG_TEMP_UPPER, ®val); + if (ret) + return ret; + + temp = jc42_temp_from_reg(regval); hyst = jc42_hysteresis[(data->config & JC42_CFG_HYST_MASK) >> JC42_CFG_HYST_SHIFT]; *val = temp - hyst; return 0; case hwmon_temp_crit_hyst: - temp = jc42_temp_from_reg(data->temp[t_crit]); + ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL, + ®val); + if (ret) + return ret; + + temp = jc42_temp_from_reg(regval); hyst = jc42_hysteresis[(data->config & JC42_CFG_HYST_MASK) >> JC42_CFG_HYST_SHIFT]; *val = temp - hyst; return 0; case hwmon_temp_min_alarm: - *val = (data->temp[t_input] >> JC42_ALARM_MIN_BIT) & 1; + ret = regmap_read(data->regmap, JC42_REG_TEMP, ®val); + if (ret) + return ret; + + *val = (regval >> JC42_ALARM_MIN_BIT) & 1; return 0; case hwmon_temp_max_alarm: - *val = (data->temp[t_input] >> JC42_ALARM_MAX_BIT) & 1; + ret = regmap_read(data->regmap, JC42_REG_TEMP, ®val); + if (ret) + return ret; + + *val = (regval >> JC42_ALARM_MAX_BIT) & 1; return 0; case hwmon_temp_crit_alarm: - *val = (data->temp[t_input] >> JC42_ALARM_CRIT_BIT) & 1; + ret = regmap_read(data->regmap, JC42_REG_TEMP, ®val); + if (ret) + return ret; + + *val = (regval >> JC42_ALARM_CRIT_BIT) & 1; return 0; default: return -EOPNOTSUPP; @@ -326,29 +319,29 @@ static int jc42_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { struct jc42_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; + unsigned int regval; int diff, hyst; int ret; - mutex_lock(&data->update_lock); - switch (attr) { case hwmon_temp_min: - data->temp[t_min] = jc42_temp_to_reg(val, data->extended); - ret = i2c_smbus_write_word_swapped(client, temp_regs[t_min], - data->temp[t_min]); + ret = regmap_write(data->regmap, JC42_REG_TEMP_LOWER, + jc42_temp_to_reg(val, data->extended)); break; case hwmon_temp_max: - data->temp[t_max] = jc42_temp_to_reg(val, data->extended); - ret = i2c_smbus_write_word_swapped(client, temp_regs[t_max], - data->temp[t_max]); + ret = regmap_write(data->regmap, JC42_REG_TEMP_UPPER, + jc42_temp_to_reg(val, data->extended)); break; case hwmon_temp_crit: - data->temp[t_crit] = jc42_temp_to_reg(val, data->extended); - ret = i2c_smbus_write_word_swapped(client, temp_regs[t_crit], - data->temp[t_crit]); + ret = regmap_write(data->regmap, JC42_REG_TEMP_CRITICAL, + jc42_temp_to_reg(val, data->extended)); break; case hwmon_temp_crit_hyst: + ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL, + ®val); + if (ret) + return ret; + /* * JC42.4 compliant chips only support four hysteresis values. * Pick best choice and go from there. @@ -356,7 +349,7 @@ static int jc42_write(struct device *dev, enum hwmon_sensor_types type, val = clamp_val(val, (data->extended ? JC42_TEMP_MIN_EXTENDED : JC42_TEMP_MIN) - 6000, JC42_TEMP_MAX); - diff = jc42_temp_from_reg(data->temp[t_crit]) - val; + diff = jc42_temp_from_reg(regval) - val; hyst = 0; if (diff > 0) { if (diff < 2250) @@ -368,17 +361,14 @@ static int jc42_write(struct device *dev, enum hwmon_sensor_types type, } data->config = (data->config & ~JC42_CFG_HYST_MASK) | (hyst << JC42_CFG_HYST_SHIFT); - ret = i2c_smbus_write_word_swapped(data->client, - JC42_REG_CONFIG, - data->config); + ret = regmap_write(data->regmap, JC42_REG_CONFIG, + data->config); break; default: ret = -EOPNOTSUPP; break; } - mutex_unlock(&data->update_lock); - return ret; } @@ -470,51 +460,79 @@ static const struct hwmon_chip_info jc42_chip_info = { .info = jc42_info, }; +static bool jc42_readable_reg(struct device *dev, unsigned int reg) +{ + return (reg >= JC42_REG_CAP && reg <= JC42_REG_DEVICEID) || + reg == JC42_REG_SMBUS; +} + +static bool jc42_writable_reg(struct device *dev, unsigned int reg) +{ + return (reg >= JC42_REG_CONFIG && reg <= JC42_REG_TEMP_CRITICAL) || + reg == JC42_REG_SMBUS; +} + +static bool jc42_volatile_reg(struct device *dev, unsigned int reg) +{ + return reg == JC42_REG_CONFIG || reg == JC42_REG_TEMP; +} + +static const struct regmap_config jc42_regmap_config = { + .reg_bits = 8, + .val_bits = 16, + .val_format_endian = REGMAP_ENDIAN_BIG, + .max_register = JC42_REG_SMBUS, + .writeable_reg = jc42_writable_reg, + .readable_reg = jc42_readable_reg, + .volatile_reg = jc42_volatile_reg, + .cache_type = REGCACHE_RBTREE, +}; + static int jc42_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct device *hwmon_dev; + unsigned int config, cap; struct jc42_data *data; - int config, cap; + int ret; data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->client = client; + data->regmap = devm_regmap_init_i2c(client, &jc42_regmap_config); + if (IS_ERR(data->regmap)) + return PTR_ERR(data->regmap); + i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP); - if (cap < 0) - return cap; + ret = regmap_read(data->regmap, JC42_REG_CAP, &cap); + if (ret) + return ret; data->extended = !!(cap & JC42_CAP_RANGE); if (device_property_read_bool(dev, "smbus-timeout-disable")) { - int smbus; - /* * Not all chips support this register, but from a * quick read of various datasheets no chip appears * incompatible with the below attempt to disable * the timeout. And the whole thing is opt-in... */ - smbus = i2c_smbus_read_word_swapped(client, JC42_REG_SMBUS); - if (smbus < 0) - return smbus; - i2c_smbus_write_word_swapped(client, JC42_REG_SMBUS, - smbus | SMBUS_STMOUT); + ret = regmap_set_bits(data->regmap, JC42_REG_SMBUS, + SMBUS_STMOUT); + if (ret) + return ret; } - config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG); - if (config < 0) - return config; + ret = regmap_read(data->regmap, JC42_REG_CONFIG, &config); + if (ret) + return ret; data->orig_config = config; if (config & JC42_CFG_SHUTDOWN) { config &= ~JC42_CFG_SHUTDOWN; - i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config); + regmap_write(data->regmap, JC42_REG_CONFIG, config); } data->config = config; @@ -535,7 +553,7 @@ static void jc42_remove(struct i2c_client *client) config = (data->orig_config & ~JC42_CFG_HYST_MASK) | (data->config & JC42_CFG_HYST_MASK); - i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config); + regmap_write(data->regmap, JC42_REG_CONFIG, config); } } @@ -546,8 +564,7 @@ static int jc42_suspend(struct device *dev) struct jc42_data *data = dev_get_drvdata(dev); data->config |= JC42_CFG_SHUTDOWN; - i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, - data->config); + regmap_write(data->regmap, JC42_REG_CONFIG, data->config); return 0; } @@ -556,8 +573,7 @@ static int jc42_resume(struct device *dev) struct jc42_data *data = dev_get_drvdata(dev); data->config &= ~JC42_CFG_SHUTDOWN; - i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, - data->config); + regmap_write(data->regmap, JC42_REG_CONFIG, data->config); return 0; } From patchwork Fri Oct 21 16:50:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 6869 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp803445wrr; Fri, 21 Oct 2022 09:57:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4EP2nI4wnmf/bSNckPtchf2DkaDMvxcuWe1AnLaU5cjzHtN8VK33/+e8psfvBsiVdtC0ZO X-Received: by 2002:a17:907:760c:b0:78d:b37f:5ce4 with SMTP id jx12-20020a170907760c00b0078db37f5ce4mr15853692ejc.50.1666371473124; Fri, 21 Oct 2022 09:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666371473; cv=none; d=google.com; s=arc-20160816; b=Aw94EDRxX4o5E1uHe50HWYnABPOG71H356wOsSvYxv9A4ZzJWsqEFIOWt7YtOYOhja 349DlkgZGti6/Jy3LUFw/MDsfXuIbD6RWbCgVeI2MdsyKw/MFpHvdf5mtA4s71Nl63or 9Znu+DBUYoSVCchjWO515Y1U4r0pvB4duBpc62py8HtcKm6yo7PnTcpAT4+X0ey0mejR SlTRPdw5ufgshhC3zVLLynWjhHaPNJC44Fea9aWt/T9meTI/a9BdBoKQtL6NTFfuKSSD zNZ9gLs3HI6vhiigiUrGNUXjgQuVjpuY1Ni2NfuNqjFMfs4/4kc78stVd2hbaINLl4dm z3MQ== 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=C3xihInAFJQTl2KRc26pyAdZJDLSBMJZBLTKuN0TfOY=; b=0IyIx4Qd8vWI/0UsTpLwI8x+/w5AEIb0Th+lwc0SP8nrrNtbZHaXmZxXkZ2pAw8Z1V 4NuvBcyBkSLca99CFwrj+2Eg6Tc7n16L62e4+f0fpHFkM+6g6LwQNhxx5fuEVLmXWX5v CS23qnCnw0dwzHTds8+GsIRcw7pCP4ebfnlcnEwasuoawgBtIRxIMr8IJUodyU2M77XF 3BdyTrPk40rk2K+CELljiSz17Jh+QAsLwL8GD8s+mOzM4XOPuERUx2x3LMRB0ounwyux FfE2H5p4gAuynElQ3rxyTN3Qzu2/Ura1MhNiC4IZ3XbM5dUM7cn80329cN8QkmQkH7kH GvNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=QfiA3SBf; 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 t4-20020a056402020400b00458b42ff246si17749343edv.236.2022.10.21.09.57.26; Fri, 21 Oct 2022 09:57:53 -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=QfiA3SBf; 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 S230302AbiJUQud (ORCPT + 99 others); Fri, 21 Oct 2022 12:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229682AbiJUQuU (ORCPT ); Fri, 21 Oct 2022 12:50:20 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D54EB251D7D; Fri, 21 Oct 2022 09:50:17 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id l22so8101379edj.5; Fri, 21 Oct 2022 09:50:17 -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=C3xihInAFJQTl2KRc26pyAdZJDLSBMJZBLTKuN0TfOY=; b=QfiA3SBfzLH/NwONgFFuq5Xl/WKmwFD/h9fyNaAK9tjQz4wcB4DEatJ/sTVQdx0ZMa fb1fpTBX/qEp04A0EeUYDnIxxdyNTe3xehPISLW/P05oYNfIo2CnTctZL+k3+le5ch5Q ZKlz0QmGWkBLdKxdPAcwMu6Uk64+UGYdUIyPwCz0tAlGiVE+nfu74tVstwFHHJdcpZxD zTTZFV2txeqsg3TOs9k7ijQg0pyyMGzgYm45c16rn4nSODqTdq92YPKkoQ3+dJWHBdE6 8UOECdpJ5hv4wZ6wZg1crIRk7O6yK+S2zM2RDzuTxbUTd5AnWTOLAiRU/5/plvHdnFwP GQxw== 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=C3xihInAFJQTl2KRc26pyAdZJDLSBMJZBLTKuN0TfOY=; b=A4TRcvQS8kyJI8GUrEfqNVW1yK/cqIndw69C1dxHwxNCamoujVyQ34FkXI4pBXv0n2 rqzySHtPIYuLVJwWs/tFRs+/rZVccSq1V5QtHaGGawOPFE2wxWplXWCLoh3J0XNJEiWl jQLZrJOlg3ag9E8U/dqA8he/e2nv40GlE0YcKgjs6v1/P3hFcIQUdRkDKfF5AAeD63sc F1bAes7ETtDrpVYAmEfGGCGiAWTj2JYj46gig6R2xMrhkRvGQhAoH1k3wM++D/ZfMues 8WnJdBuPWqCASL1RKA2g+O6U2gliRVvd6ZMDeClZYaaH5tSelWt//nD8FA3QM4X2e2+j 5JHg== X-Gm-Message-State: ACrzQf2BfdGcb36ko4B+Da/l17zXOSetxQnvOWfBxeQghSnY2DAJuJwS 5Lszo4plf/SdG0VGybHvy60= X-Received: by 2002:a17:906:58c6:b0:78d:b37f:5ce5 with SMTP id e6-20020a17090658c600b0078db37f5ce5mr16456644ejs.707.1666371015957; Fri, 21 Oct 2022 09:50:15 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a01-0c22-7b0b-4500-0000-0000-0000-0e63.c22.pool.telefonica.de. [2a01:c22:7b0b:4500::e63]) by smtp.googlemail.com with ESMTPSA id l23-20020aa7d957000000b0044ef2ac2650sm13725331eds.90.2022.10.21.09.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 09:50:15 -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: [PATCH v3 2/2] hwmon: (jc42) Restore the min/max/critical temperatures on resume Date: Fri, 21 Oct 2022 18:50:00 +0200 Message-Id: <20221021165000.1865615-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221021165000.1865615-1-martin.blumenstingl@googlemail.com> References: <20221021165000.1865615-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?1747317133622819137?= X-GMAIL-MSGID: =?utf-8?q?1747317133622819137?= 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 Reviewed-by: Guenter Roeck --- 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 8d70960d5444..52a60eb0791b 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c @@ -565,6 +565,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; } @@ -572,9 +576,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 = {