getting battery status from RTC driver
Rasmus Villemoes
rasmus.villemoes at prevas.dk
Fri May 1 16:46:28 CEST 2020
Hi,
I have an application where I need to retrieve the battery status from a
pcf2129 (the pcf2127 driver works fine for that chip as well).
Currently, the various drivers seem to handle low battery quite
inconsistently:
pcf2127 just prints a warning, still populates tm, and returns 0.
pcf8563 is similar, except that it returns -1.
rx8010sj and s35392a has a debug message (so probably not normally
printed), and returns -EINVAL without populating tm.
The pcf8563 behaviour is closest to what I need, except that a bare -1
return cannot really be used to distinguish from "there was some error
communicating with the chip" from the case I'm interested in, the chip
working just fine, but having some low voltage bit set. [For my use
case, I really do want the time, even if it may be inaccurate, so I'd
like to distinguish "can't talk to the RTC", "got a time, use it with
caution", and "all is well, the time is now..."]
Changing all the _get methods to optionally pass back some "low_volt"
status is a lot of churn. So what I'm thinking is to just change
dm_rtc_get(), and then abuse one of the ints in struct rtc_time to allow
the driver to pass back such extra info in some otherwise unused bits.
I.e., dm_rtc_get would become
int dm_rtc_get(struct udevice *dev, struct rtc_time *time, int *flags)
with flags being optional. Then something like
#define RTC_ISDST_EXTRA 0xfffffffe
#define RTC_ISDST_LOW_VOLT 0x2
and in dm_rtc_get do
if (flags)
*flags = time->tm_isdst & RTC_ISDST_EXTRA;
time->tm_isdst &= ~RTC_ISDST_EXTRA;
and drivers which know how to read the battery status can set
RTC_ISDST_LOW_VOLT in tm_isdst (only in their dm method).
Is this too hacky? Other ideas for how the caller can obtain the battery
status (preferably as part of an rtc_get call)?
Thanks,
Rasmus
More information about the U-Boot
mailing list