2022-10-21 17:20:45

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH v3 0/2] hwmon: (jc42) regmap conversion and resume fix

Hello,

this is a follow-up to the comments I got from Guenter on v1 of my patch
from [0] titled:
"hwmon: (jc42) Restore the min/max/critical temperatures on resume"
There Guenter suggested: "The best solution would probably be to convert
the driver to use regmap and let regmap handle the caching". That's the
goal of this series - in addition to fixing the original resume issue
(see patch #3 - which was the reason for v1 of this series).

Guenter suggested:
> Make sure that the alarm bits are not dropped after reading the
> temperature (running the 'sensors' command with alarms active should
> do)
I configured the limits to be below the case temperature on my system
(as the jc42 sensor - a ST Microelectronics STTS2004 - is part of the
DIMMs) and ran sensors three times in a row. The output is the same for
all runs:
temp1: +35.0°C (low = +0.0°C) ALARM (HIGH, CRIT)
(high = +25.0°C, hyst = +25.0°C)
(crit = +30.0°C, hyst = +30.0°C)
My conclusion is that the alarm bit is not dropped after reading the
temperature.


Changes sinc v2 at [1]:
- squashed patches #1, #2 and #4 into the new patch #1 (without any
other changes to content in jc42.c)
- patch #3 has no changes other than it's numbering (see previous
change)
- dropped RFC prefix

Changes since v1 at [0]:
- marked as RFC
- added patches for regmap (patch #1) and regcache (patch #2) conversion
- patch #3 has been updated to use regcache for restoring the register
values during system resume (this was originally patch 1/1)
- added another patch to remove caching of the temperature register


[0] https://lore.kernel.org/linux-hwmon/[email protected]/
[1] https://lore.kernel.org/linux-hwmon/[email protected]/


Martin Blumenstingl (2):
hwmon: (jc42) Convert register access and caching to regmap/regcache
hwmon: (jc42) Restore the min/max/critical temperatures on resume

drivers/hwmon/Kconfig | 1 +
drivers/hwmon/jc42.c | 224 +++++++++++++++++++++++-------------------
2 files changed, 125 insertions(+), 100 deletions(-)

--
2.38.1


2022-10-21 17:25:19

by Martin Blumenstingl

[permalink] [raw]
Subject: [PATCH v3 2/2] hwmon: (jc42) Restore the min/max/critical temperatures on resume

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 <[email protected]>
---
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 = {
--
2.38.1

2022-10-21 17:42:53

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] hwmon: (jc42) Restore the min/max/critical temperatures on resume

On Fri, Oct 21, 2022 at 06:50:00PM +0200, Martin Blumenstingl wrote:
> 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 <[email protected]>

Nice use of regmap.

For my reference:

Reviewed-by: Guenter Roeck <[email protected]>

Thanks,
Guenter

> ---
> 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 = {
> --
> 2.38.1
>