Skip to contentSkip to conversation

rtc: ab-eoz9: fix the undervoltage handling

PATCH Applied Maxime Chevallier 2 participants 4 messages Nov 22, 2024 – Nov 25, 2024 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

cover rtc: ab-eoz9: fix the undervoltage handling

The AB EOZ9 can report if there are undervoltage conditions encountered while the RTC is maintaining the date and time. This is useful when a device is stored for a long amount of time without being used, to know how reliable the reported date and time are at reboot.

Patch 1 reworks the user report of undervoltages by checking the lowest threshold first.

Patch 2 makes so that we don't fail the temperature readout, as when the system is currently running, the RTC battery should be at a nominal voltage. Temperature-related undervoltage reports are about what happened while the system was down, and not about the current state of the power supply.

Maxime Chevallier (2):
rtc: ab-eoz9: check the lowest voltage threshold first
rtc: ab-eoz9: don't fail temperature reads on undervoltage
notification

 drivers/rtc/rtc-ab-eoz9.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
Signature · 1 line
2.47.0
#1 lore raw

PATCH 1/2 rtc: ab-eoz9: check the lowest voltage threshold first

When checking the internal status flags for time validity, 2 different voltage thresholds are verified :

VLOW1 is at 2.1V and indicates that temperature monitoring isn't possible at that voltage. This stops any temperature compensation and can cause time deviations

VLOW2 is at 1.3V, below that voltage no timekeeping is possible.

In both cases, we consider the reported time to be unreliable and print a warning.

The current code checks for VLOW1 undervoltage first, but as it is higher than VLOW2 it will always trigger before the VLOW2 threshold is hit.

Make sure we first check the VLOW2 condition when checking time validity.

Fixes 67075b63cce2 ("rtc: add AB-RTCMC-32.768kHz-EOZ9 RTC support")
---
 drivers/rtc/rtc-ab-eoz9.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/rtc/rtc-ab-eoz9.c +4 -4
index 02f7d0711287..85853da258d2 100644
@@ -116,15 +116,15 @@ static int abeoz9_check_validity(struct device *dev)
 		return -EINVAL;
 	}
 
-	if (val & ABEOZ9_REG_CTRL_STATUS_V1F) {
+	if (val & ABEOZ9_REG_CTRL_STATUS_V2F) {
 		dev_warn(dev,
-			 "voltage drops below VLOW1 threshold, date is invalid\n");
+			 "voltage drops below VLOW2 threshold, date is invalid\n");
 		return -EINVAL;
 	}
 
-	if ((val & ABEOZ9_REG_CTRL_STATUS_V2F)) {
+	if ((val & ABEOZ9_REG_CTRL_STATUS_V1F)) {
 		dev_warn(dev,
-			 "voltage drops below VLOW2 threshold, date is invalid\n");
+			 "voltage drops below VLOW1 threshold, date is invalid\n");
 		return -EINVAL;
 	}
 
Signature · 1 line
2.47.0
#2 lore raw

PATCH 2/2 rtc: ab-eoz9: don't fail temperature reads on undervoltage notification

In reply to Maxime Chevallier

The undervoltage flags reported by the RTC are useful to know if the time and date are reliable after a reboot. Although the threshold VLOW1 indicates that the thermometer has been shutdown and time compensation is off, it doesn't mean that the temperature readout is currently impossible.

As the system is running, the RTC voltage is now fully established and we can read the temperature.

Fixes 67075b63cce2 ("rtc: add AB-RTCMC-32.768kHz-EOZ9 RTC support")
---
 drivers/rtc/rtc-ab-eoz9.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/rtc/rtc-ab-eoz9.c +0 -7
index 85853da258d2..52914bb3e5e1 100644
@@ -396,13 +396,6 @@ static int abeoz9z3_temp_read(struct device *dev,
 	if (ret < 0)
 		return ret;
 
-	if ((val & ABEOZ9_REG_CTRL_STATUS_V1F) ||
-	    (val & ABEOZ9_REG_CTRL_STATUS_V2F)) {
-		dev_err(dev,
-			"thermometer might be disabled due to low voltage\n");
-		return -EINVAL;
-	}
-
 	switch (attr) {
 	case hwmon_temp_input:
 		ret = regmap_read(regmap, ABEOZ9_REG_REG_TEMP, &val);
Signature · 1 line
2.47.0
maintainer Applied
#3 lore raw

Re: (subset) [PATCH 2/2] rtc: ab-eoz9: don't fail temperature reads on undervoltage notification

Quoted 10 lines · Maxime Chevallier

The undervoltage flags reported by the RTC are useful to know if the time and date are reliable after a reboot. Although the threshold VLOW1 indicates that the thermometer has been shutdown and time compensation is off, it doesn't mean that the temperature readout is currently impossible.

As the system is running, the RTC voltage is now fully established and we can read the temperature.

[...]

Applied, thanks!

[2/2] rtc: ab-eoz9: don't fail temperature reads on undervoltage notification

      https://git.kernel.org/abelloni/c/e0779a0dcf41

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com