Skip to content

RFC: hwclock-rtc: add RTC_PARAM_BATTERY_LOW_DETECT support - #4513

Draft
KarlK90 wants to merge 2 commits into
util-linux:masterfrom
KarlK90:feature/hwclock-rtc/bld
Draft

RFC: hwclock-rtc: add RTC_PARAM_BATTERY_LOW_DETECT support#4513
KarlK90 wants to merge 2 commits into
util-linux:masterfrom
KarlK90:feature/hwclock-rtc/bld

Conversation

@KarlK90

@KarlK90 KarlK90 commented Jul 30, 2026

Copy link
Copy Markdown

Draft PR - depends on pending linux patch series

Some rtcs like the pcf2131 do not enable low battery detection by default. A new linux patch series1 exposes a parameter to enable the detection, support is implemented in this commit.

@KarlK90 KarlK90 changed the title RFC: hwclock-rtc: add RTC_FEATURE_BATTERY_LOW_DETECT parameter RFC: hwclock-rtc: add RTC_PARAMETER_BATTERY_LOW_DETECT support Jul 30, 2026
@KarlK90 KarlK90 changed the title RFC: hwclock-rtc: add RTC_PARAMETER_BATTERY_LOW_DETECT support RFC: hwclock-rtc: add RTC_PARAM_BATTERY_LOW_DETECT support Jul 30, 2026
@KarlK90
KarlK90 force-pushed the feature/hwclock-rtc/bld branch from 5424d9e to 018cc92 Compare July 30, 2026 12:18
Comment thread sys-utils/hwclock-rtc.c Outdated
# define RTC_PARAM_CORRECTION 1
# define RTC_PARAM_BACKUP_SWITCH_MODE 2
# define RTC_PARAM_BATTERY_LOW_DETECT 3
#endif /* RTC_PARAM_GET */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot define it in the ifndef RTC_PARAM_GET block, do it later

#if defined(RTC_PARAM_GET) && !defined(RTC_PARAM_BATTERY_LOW_DETECT)
# define RTC_PARAM_BATTERY_LOW_DETECT 3
#endif

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. But won't that result in compilation error in the case that RTC_PARAM_GET is undefined?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, RTC_PARAM_GET is required, but the code in this case is not strict enough. I'll improve it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f089382 should make RTC_PARAM_GET use more robust.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have cherry-picked your commit and updated my commit on top of it.

@karelzak karelzak added the KERNEL-FIRST Postponed until the kernel portion got merged into Linus' tree. label Aug 3, 2026
@KarlK90
KarlK90 force-pushed the feature/hwclock-rtc/bld branch from 018cc92 to 870e88f Compare August 3, 2026 12:51
karelzak and others added 2 commits August 10, 2026 17:13
Replace broad #ifndef __GNU__ guards with feature-specific #ifdef
RTC_PARAM_GET and #ifdef RTC_VL_READ to guard the code that depends
on these ioctls.

Move the fallback definitions for RTC_PARAM_GET, RTC_PARAM_SET,
RTC_VL_READ, and RTC_VL_CLR from hwclock-rtc.c to hwclock.h under
feature macros consistently.

Signed-off-by: Karel Zak <kzak@redhat.com>
Some rtcs like the pcf2131 do not enable low battery detection by
default. A new linux patch series[1] exposes a parameter to enable the
detection, support is implemented in this commit.

[1]: https://lore.kernel.org/all/20260311200237.3531981-1-hugo@hugovil.com/

Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
@KarlK90
KarlK90 force-pushed the feature/hwclock-rtc/bld branch from 870e88f to 6252cea Compare August 10, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

KERNEL-FIRST Postponed until the kernel portion got merged into Linus' tree.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants