* [PATCH 1/4] rtc: pcf2127: remove redundant break statement in switch-case
2026-03-11 20:02 [PATCH 0/4] rtc: pcf2127: add support for battery low voltage detection Hugo Villeneuve
@ 2026-03-11 20:02 ` Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 2/4] rtc: pcf2127: add pcf2127_pwrmng_get/set Hugo Villeneuve
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Hugo Villeneuve @ 2026-03-11 20:02 UTC (permalink / raw)
To: alexandre.belloni
Cc: linux-rtc, linux-kernel, hugo, bruno.thomsen, giampiero,
p.rosenberger, antonio, Hugo Villeneuve
From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Remove unreachable break statement after return.
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
drivers/rtc/rtc-pcf2127.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index bb4fe81d3d62c..e2e9746027348 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -404,8 +404,6 @@ static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
PCF2127_CTRL3_PM,
FIELD_PREP(PCF2127_CTRL3_PM, mode + value));
- break;
-
default:
return -EINVAL;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/4] rtc: pcf2127: add pcf2127_pwrmng_get/set
2026-03-11 20:02 [PATCH 0/4] rtc: pcf2127: add support for battery low voltage detection Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 1/4] rtc: pcf2127: remove redundant break statement in switch-case Hugo Villeneuve
@ 2026-03-11 20:02 ` Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 3/4] rtc: add battery low voltage detection feature Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 4/4] rtc: pcf2127: support battery low voltage detection function Hugo Villeneuve
3 siblings, 0 replies; 5+ messages in thread
From: Hugo Villeneuve @ 2026-03-11 20:02 UTC (permalink / raw)
To: alexandre.belloni
Cc: linux-rtc, linux-kernel, hugo, bruno.thomsen, giampiero,
p.rosenberger, antonio, Hugo Villeneuve
From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Add common functions to get/set the pwrmng field in the CTRL3 register,
used by pcf2127_param_get() and pcf2127_param_set().
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
These functions will also be used in the following patch
to add battery low detection.
---
drivers/rtc/rtc-pcf2127.c | 42 +++++++++++++++++++++++++++------------
1 file changed, 29 insertions(+), 13 deletions(-)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index e2e9746027348..0605295026564 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -213,6 +213,30 @@ struct pcf2127 {
bool ts_valid[PCF2127_MAX_TS_SUPPORTED]; /* Timestamp valid indication. */
};
+static int pcf2127_pwrmng_get(struct device *dev, u8 *pwrmng)
+{
+ struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
+ u32 value;
+ int ret;
+
+ ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
+ if (ret < 0)
+ return ret;
+
+ *pwrmng = FIELD_GET(PCF2127_CTRL3_PM, value);
+
+ return 0;
+}
+
+static int pcf2127_pwrmng_set(struct device *dev, u8 pwrmng)
+{
+ struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
+
+ return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
+ PCF2127_CTRL3_PM,
+ FIELD_PREP(PCF2127_CTRL3_PM, pwrmng));
+}
+
/*
* In the routines that deal directly with the pcf2127 hardware, we use
* rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
@@ -337,18 +361,15 @@ static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
{
- struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
- u32 value;
+ u8 value;
int ret;
switch (param->param) {
case RTC_PARAM_BACKUP_SWITCH_MODE:
- ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
+ ret = pcf2127_pwrmng_get(dev, &value);
if (ret < 0)
return ret;
- value = FIELD_GET(PCF2127_CTRL3_PM, value);
-
if (value < 0x3)
param->uvalue = RTC_BSM_LEVEL;
else if (value < 0x6)
@@ -367,19 +388,16 @@ static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
{
- struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
u8 mode = 0;
- u32 value;
+ u8 value;
int ret;
switch (param->param) {
case RTC_PARAM_BACKUP_SWITCH_MODE:
- ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &value);
+ ret = pcf2127_pwrmng_get(dev, &value);
if (ret < 0)
return ret;
- value = FIELD_GET(PCF2127_CTRL3_PM, value);
-
if (value > 5)
value -= 5;
else if (value > 2)
@@ -400,9 +418,7 @@ static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
return -EINVAL;
}
- return regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
- PCF2127_CTRL3_PM,
- FIELD_PREP(PCF2127_CTRL3_PM, mode + value));
+ return pcf2127_pwrmng_set(dev, mode + value);
default:
return -EINVAL;
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/4] rtc: add battery low voltage detection feature
2026-03-11 20:02 [PATCH 0/4] rtc: pcf2127: add support for battery low voltage detection Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 1/4] rtc: pcf2127: remove redundant break statement in switch-case Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 2/4] rtc: pcf2127: add pcf2127_pwrmng_get/set Hugo Villeneuve
@ 2026-03-11 20:02 ` Hugo Villeneuve
2026-03-11 20:02 ` [PATCH 4/4] rtc: pcf2127: support battery low voltage detection function Hugo Villeneuve
3 siblings, 0 replies; 5+ messages in thread
From: Hugo Villeneuve @ 2026-03-11 20:02 UTC (permalink / raw)
To: alexandre.belloni
Cc: linux-rtc, linux-kernel, hugo, bruno.thomsen, giampiero,
p.rosenberger, antonio, Hugo Villeneuve
From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
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@dimonoff.com>
---
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
/* parameter list */
#define RTC_PARAM_FEATURES 0
#define RTC_PARAM_CORRECTION 1
#define RTC_PARAM_BACKUP_SWITCH_MODE 2
+#define RTC_PARAM_BATTERY_LOW_DETECT 3
#define RTC_BSM_DISABLED 0
#define RTC_BSM_DIRECT 1
#define RTC_BSM_LEVEL 2
#define RTC_BSM_STANDBY 3
+#define RTC_BATTERY_LOW_DETECT_DISABLED 0
+#define RTC_BATTERY_LOW_DETECT_ENABLED 1
+
#define RTC_MAX_FREQ 8192
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 4/4] rtc: pcf2127: support battery low voltage detection function
2026-03-11 20:02 [PATCH 0/4] rtc: pcf2127: add support for battery low voltage detection Hugo Villeneuve
` (2 preceding siblings ...)
2026-03-11 20:02 ` [PATCH 3/4] rtc: add battery low voltage detection feature Hugo Villeneuve
@ 2026-03-11 20:02 ` Hugo Villeneuve
3 siblings, 0 replies; 5+ messages in thread
From: Hugo Villeneuve @ 2026-03-11 20:02 UTC (permalink / raw)
To: alexandre.belloni
Cc: linux-rtc, linux-kernel, hugo, bruno.thomsen, giampiero,
p.rosenberger, antonio, Hugo Villeneuve
From: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Add support for parameter RTC_PARAM_BATTERY_LOW_DETECT in RTC_PARAM_SET
ioctl to enable/disable/query battery low voltage detection. This is
especially relevant on the pcf2131 where this function is disabled by
default, contrary to the pcf2127.
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
drivers/rtc/rtc-pcf2127.c | 60 ++++++++++++++++++++++++++++++++-------
1 file changed, 50 insertions(+), 10 deletions(-)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 0605295026564..05b08867ffcb3 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -364,12 +364,12 @@ static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
u8 value;
int ret;
+ ret = pcf2127_pwrmng_get(dev, &value);
+ if (ret < 0)
+ return ret;
+
switch (param->param) {
case RTC_PARAM_BACKUP_SWITCH_MODE:
- ret = pcf2127_pwrmng_get(dev, &value);
- if (ret < 0)
- return ret;
-
if (value < 0x3)
param->uvalue = RTC_BSM_LEVEL;
else if (value < 0x6)
@@ -379,6 +379,14 @@ static int pcf2127_param_get(struct device *dev, struct rtc_param *param)
break;
+ case RTC_PARAM_BATTERY_LOW_DETECT:
+ if (value == 0x0 || value == 0x3)
+ param->uvalue = RTC_BATTERY_LOW_DETECT_ENABLED;
+ else
+ param->uvalue = RTC_BATTERY_LOW_DETECT_DISABLED;
+
+ break;
+
default:
return -EINVAL;
}
@@ -392,12 +400,12 @@ static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
u8 value;
int ret;
+ ret = pcf2127_pwrmng_get(dev, &value);
+ if (ret < 0)
+ return ret;
+
switch (param->param) {
case RTC_PARAM_BACKUP_SWITCH_MODE:
- ret = pcf2127_pwrmng_get(dev, &value);
- if (ret < 0)
- return ret;
-
if (value > 5)
value -= 5;
else if (value > 2)
@@ -418,13 +426,45 @@ static int pcf2127_param_set(struct device *dev, struct rtc_param *param)
return -EINVAL;
}
- return pcf2127_pwrmng_set(dev, mode + value);
+ break;
+
+ case RTC_PARAM_BATTERY_LOW_DETECT:
+ if (value > 5) {
+ value -= 5;
+ mode = 5;
+ } else if (value > 2) {
+ value -= 3;
+ mode = 3;
+ }
+
+ switch (param->uvalue) {
+ case RTC_BATTERY_LOW_DETECT_DISABLED:
+ if (mode != 5)
+ if (value == 0)
+ value = 1;
+
+ break;
+ case RTC_BATTERY_LOW_DETECT_ENABLED:
+ if (mode != 5)
+ value = 0; /* Enable battery low detection. */
+ else
+ return -EINVAL; /*
+ * battery low detection can't be enabled if
+ * battery switch over is disabled.
+ */
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ break;
default:
return -EINVAL;
}
- return 0;
+ return pcf2127_pwrmng_set(dev, mode + value);
}
static int pcf2127_rtc_ioctl(struct device *dev,
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread