Le 11/11/2024 à 16:41, Philipp Rosenberger a écrit :
The PCF2127, PCF2129, and PCA2129 RTCs have the battery switch-over function
enabled by default. However, the newer PCF2131 RTC has the opposite default
behavior, requiring explicit enablement for battery backup.
Add support for the `nxp,battery-backed` device tree property to enable battery
switch-over in standard mode for the rtc-pcf2127 driver. If this property is set
and no battery switch-over mode is already configured, the driver will enable
standard mode; otherwise, existing configurations remain unchanged.
Signed-off-by: Philipp Rosenberger <p.rosenberger-pnUOlEj4XnTQT0dZR+AlfA@xxxxxxxxxxxxxxxx>
---
drivers/rtc/rtc-pcf2127.c | 76 +++++++++++++++++++++++++++++++--------
1 file changed, 61 insertions(+), 15 deletions(-)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 9c04c4e1a49c..c80e31fec134 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -48,6 +48,7 @@
#define PCF2127_BIT_CTRL3_BLF BIT(2)
#define PCF2127_BIT_CTRL3_BF BIT(3)
#define PCF2127_BIT_CTRL3_BTSE BIT(4)
+#define PCF2127_BIT_CTRL3_PWRMNG_MASK (BIT(5) | BIT(6) | BIT(7))
GENMASK(7, 5)?
/* Time and date registers */
#define PCF2127_REG_TIME_BASE 0x03
#define PCF2127_BIT_SC_OSF BIT(7)
@@ -529,6 +530,64 @@ static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127)
return devm_watchdog_register_device(dev, &pcf2127->wdd);
}
+static int pcf2127_battery_init(struct device *dev, struct pcf2127 *pcf2127)
+{
+ unsigned int ctrl3;
+ unsigned int pwrmng;
+ int ret;
+
+ /*
+ * Disable battery low/switch-over timestamp and interrupts.
+ * Clear battery interrupt flags which can block new trigger events.
+ * Note: This is the default chip behaviour but added to ensure
+ * correct tamper timestamp and interrupt function.
+ */
+ ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
+ PCF2127_BIT_CTRL3_BTSE |
+ PCF2127_BIT_CTRL3_BIE |
+ PCF2127_BIT_CTRL3_BLIE, 0);
+ if (ret) {
+ dev_err(dev, "%s: interrupt config (ctrl3) failed\n",
+ __func__);
dev_err_probe() could be used.
+ return ret;
+ }
+
+ if (!device_property_read_bool(dev, "nxp,battery-backed"))
+ return 0;
+
+ ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &ctrl3);
+ if (ret) {
+ dev_err(dev, "%s: read ctrl3 faild\n", __func__);
s/faild/failed/
dev_err_probe() could be used.
+ return ret;
+ }
...
CJ