mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] rtc: ab-eoz9: fix the undervoltage handling
@ 2024-11-22 10:10 Maxime Chevallier
  2024-11-22 10:10 ` [PATCH 1/2] rtc: ab-eoz9: check the lowest voltage threshold first Maxime Chevallier
  2024-11-22 10:10 ` [PATCH 2/2] rtc: ab-eoz9: don't fail temperature reads on undervoltage notification Maxime Chevallier
  0 siblings, 2 replies; 4+ messages in thread
From: Maxime Chevallier @ 2024-11-22 10:10 UTC (permalink / raw)
  To: Alexandre Belloni, Artem Panfilov
  Cc: Maxime Chevallier, linux-rtc, linux-kernel, Alexis Lothoré,
	thomas.petazzoni

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(-)

-- 
2.47.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] rtc: ab-eoz9: check the lowest voltage threshold first
  2024-11-22 10:10 [PATCH 0/2] rtc: ab-eoz9: fix the undervoltage handling Maxime Chevallier
@ 2024-11-22 10:10 ` Maxime Chevallier
  2024-11-22 10:10 ` [PATCH 2/2] rtc: ab-eoz9: don't fail temperature reads on undervoltage notification Maxime Chevallier
  1 sibling, 0 replies; 4+ messages in thread
From: Maxime Chevallier @ 2024-11-22 10:10 UTC (permalink / raw)
  To: Alexandre Belloni, Artem Panfilov
  Cc: Maxime Chevallier, linux-rtc, linux-kernel, Alexis Lothoré,
	thomas.petazzoni

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")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/rtc/rtc-ab-eoz9.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-ab-eoz9.c b/drivers/rtc/rtc-ab-eoz9.c
index 02f7d0711287..85853da258d2 100644
--- a/drivers/rtc/rtc-ab-eoz9.c
+++ b/drivers/rtc/rtc-ab-eoz9.c
@@ -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;
 	}
 
-- 
2.47.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] rtc: ab-eoz9: don't fail temperature reads on undervoltage notification
  2024-11-22 10:10 [PATCH 0/2] rtc: ab-eoz9: fix the undervoltage handling Maxime Chevallier
  2024-11-22 10:10 ` [PATCH 1/2] rtc: ab-eoz9: check the lowest voltage threshold first Maxime Chevallier
@ 2024-11-22 10:10 ` Maxime Chevallier
  2024-11-25 22:34   ` (subset) " Alexandre Belloni
  1 sibling, 1 reply; 4+ messages in thread
From: Maxime Chevallier @ 2024-11-22 10:10 UTC (permalink / raw)
  To: Alexandre Belloni, Artem Panfilov
  Cc: Maxime Chevallier, linux-rtc, linux-kernel, Alexis Lothoré,
	thomas.petazzoni

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")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/rtc/rtc-ab-eoz9.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/rtc/rtc-ab-eoz9.c b/drivers/rtc/rtc-ab-eoz9.c
index 85853da258d2..52914bb3e5e1 100644
--- a/drivers/rtc/rtc-ab-eoz9.c
+++ b/drivers/rtc/rtc-ab-eoz9.c
@@ -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);
-- 
2.47.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: (subset) [PATCH 2/2] rtc: ab-eoz9: don't fail temperature reads on undervoltage notification
  2024-11-22 10:10 ` [PATCH 2/2] rtc: ab-eoz9: don't fail temperature reads on undervoltage notification Maxime Chevallier
@ 2024-11-25 22:34   ` Alexandre Belloni
  0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2024-11-25 22:34 UTC (permalink / raw)
  To: Artem Panfilov, Maxime Chevallier
  Cc: linux-rtc, linux-kernel, Alexis Lothoré, thomas.petazzoni

On Fri, 22 Nov 2024 11:10:30 +0100, Maxime Chevallier wrote:
> 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,

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-25 22:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-22 10:10 [PATCH 0/2] rtc: ab-eoz9: fix the undervoltage handling Maxime Chevallier
2024-11-22 10:10 ` [PATCH 1/2] rtc: ab-eoz9: check the lowest voltage threshold first Maxime Chevallier
2024-11-22 10:10 ` [PATCH 2/2] rtc: ab-eoz9: don't fail temperature reads on undervoltage notification Maxime Chevallier
2024-11-25 22:34   ` (subset) " Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®