Re: [PATCH 3/4] rtc: add battery low voltage detection feature
From: Hugo Villeneuve
Date: Mon Nov 23 2026 - 10:27:45 EST
Hi Alexandre,
On Sat, 21 Nov 2026 13:36:32 +0100
Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx> wrote:
> On 20/11/2026 18:40:27-0500, Hugo Villeneuve wrote:
> > Hi Alexandre,
> >
> > On Fri, 20 Nov 2026 17:12:49 +0100
> > Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx> wrote:
> >
> > > On 20/11/2026 14:40:50+0100, Alexandre Belloni wrote:
> > > > Hello,
> > > >
> > > > On 06/08/2026 14:55:00+0200, Stefan Kerkmann wrote:
> > > > >
> > > > >
> > > > > On 3/11/26 21:02, Hugo Villeneuve wrote:
> > > > > > From: Hugo Villeneuve <hvilleneuve@xxxxxxxxxxxx>
> > > > > >
> > > > > > Some RTCs have a battery low voltage detection function. Add new feature
> > > > > > so that it can be enabled, disabled or queried at runtime.
> > > > > >
> > > > > > Signed-off-by: Hugo Villeneuve <hvilleneuve@xxxxxxxxxxxx>
> > > > > > ---
> > > > > > include/uapi/linux/rtc.h | 7 ++++++-
> > > > > > 1 file changed, 6 insertions(+), 1 deletion(-)
> > > > > >
> > > > > > diff --git a/include/uapi/linux/rtc.h b/include/uapi/linux/rtc.h
> > > > > > index 97aca4503a6a3..596eec119bb3a 100644
> > > > > > --- a/include/uapi/linux/rtc.h
> > > > > > +++ b/include/uapi/linux/rtc.h
> > > > > > @@ -134,18 +134,23 @@ struct rtc_param {
> > > > > > #define RTC_FEATURE_CORRECTION 5
> > > > > > #define RTC_FEATURE_BACKUP_SWITCH_MODE 6
> > > > > > #define RTC_FEATURE_ALARM_WAKEUP_ONLY 7
> > > > > > -#define RTC_FEATURE_CNT 8
> > > > > > +#define RTC_FEATURE_BATTERY_LOW_DETECT 8
> > > > > > +#define RTC_FEATURE_CNT 9
> > > >
> > > > This is adding a new ABI and it took me a while to find enough time to
> > > > review the datasheet for the RTCs we support and others. What we need
> > > > instead of a boolean is a voltage threshold. So maybe this should be
> > > > better named something like RTC_FEATURE_BATTERY_LOW_THRES_MV
> >
> > I am not sure to understand that proposal, because with the
> > pcf2127/31, you can enable the low battery detection function, but you
> > cannot select the threshold voltage...
>
> This is exactly my point, there are RTCs where you can select the
> threshold voltage so we have to design for them. We can have 0mv mean
> disabled because we are never going to have a 0 or negative threshold.
For me, it is confusing and weird to have a threshold voltage
parameter that you can set on ICs that a have a fixed threshold voltage.
Also, once you set a threshold voltage for an IC that have that
capability, setting it to 0 to disable it seems more complicated than
simply setting the parameter to enable or disable. This also means that
if some application/service at startup were to set a threshold voltage,
then disabling it later by setting it to 0mv would lose the threshold
voltage previously set.
So, why not simply add a new parameter like you suggested to set the
threshold voltage on ICs that support it,
RTC_FEATURE_BATTERY_LOW_THRES_MV? Then you can reuse the enable/disable
boolean to enable/disable the function and keep the threshold voltage
unaffected/unmodified.
Hugo.