* [PATCH 0/2] rtc: pcf2127: make battery switch-over configurable
@ 2024-10-22 8:01 Philipp Rosenberger
2024-10-22 8:01 ` [PATCH 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property Philipp Rosenberger
2024-10-22 8:01 ` [PATCH 2/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
0 siblings, 2 replies; 3+ messages in thread
From: Philipp Rosenberger @ 2024-10-22 8:01 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-rtc, devicetree, linux-kernel
Cc: Lino Sanfilippo, Philipp Rosenberger
Hello,
this patch series adds a dt property for the pcf2127 driver to
configure the battery switch-over behavior.
The default behavior for battery switch-over has changed with PCF2131.
For PCF2127, PCF2129 and PCA2129 the default is battary switch-over and
battery low power detection is enabled. For PCF2131 this is now the
opposite. At least PCF2127 and PCF2129 are not recomended for new
designs. This leaves the PCF2131 as "replacement" part.
This patch series introduces the nxp,battery-switch-over optional
property. With this property the PWRMNG bits of the Control_3 register
can be changed.
I have tested this on a device with PCF2129 and one with PCF2131.
Best regards,
Philipp
Philipp Rosenberger (2):
dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
rtc: pcf2127: make battery switch-over configurable
.../devicetree/bindings/rtc/nxp,pcf2127.yaml | 10 +++
drivers/rtc/rtc-pcf2127.c | 61 ++++++++++++++-----
2 files changed, 56 insertions(+), 15 deletions(-)
--
2.39.5
---------------------------------------------------------------------------------
sps
Smart Production Solutions
Nuremberg, 12 - 14 November 2024
Visit us: Hall 5, Booth 228
---------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
2024-10-22 8:01 [PATCH 0/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
@ 2024-10-22 8:01 ` Philipp Rosenberger
2024-10-22 8:01 ` [PATCH 2/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
1 sibling, 0 replies; 3+ messages in thread
From: Philipp Rosenberger @ 2024-10-22 8:01 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-rtc, devicetree, linux-kernel
Cc: Lino Sanfilippo, Philipp Rosenberger
The nxp,battery-switch-over property is used to control the switch-over,
battery low detection and extra power fail detection functions.
The PCF2131 has a different default value for the PWRMNG bits. It is set
to 0x7: battery switch-over function is disabled, only one power supply
(VDD); battery low detection function is disabled.
This is the opposite of the default of the PCF2127/PCA2129 and PCF2129.
With the nxp,battery-switch-over the behavior can be controlled through
the device tree.
Signed-off-by: Philipp Rosenberger <p.rosenberger@kunbus.com>
---
Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml b/Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml
index 2d9fe5a75b06..5739c3e371e7 100644
--- a/Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml
+++ b/Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml
@@ -30,6 +30,16 @@ properties:
reset-source: true
+ nxp,battery-switch-over:
+ description:
+ Battery and power related configuration. This property is used to set the
+ PWRMNG bits of the Control_3 register to control the battery switch-over,
+ battery low detection and extra power fail detection functions.
+ The actual supported functions depend on the device capabilities.
+ $ref: /schemas/types.yaml#/definitions/uint8
+ minimum: 0
+ maximum: 7
+
required:
- compatible
- reg
--
2.39.5
---------------------------------------------------------------------------------
sps
Smart Production Solutions
Nuremberg, 12 - 14 November 2024
Visit us: Hall 5, Booth 228
---------------------------------------------------------------------------------
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] rtc: pcf2127: make battery switch-over configurable
2024-10-22 8:01 [PATCH 0/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
2024-10-22 8:01 ` [PATCH 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property Philipp Rosenberger
@ 2024-10-22 8:01 ` Philipp Rosenberger
1 sibling, 0 replies; 3+ messages in thread
From: Philipp Rosenberger @ 2024-10-22 8:01 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-rtc, devicetree, linux-kernel
Cc: Lino Sanfilippo, Philipp Rosenberger
The battery switch-over function of the PCF2127, PCA2129 and PCF2129
have the opposite default behavior as the PCF2131. If the PCF2131 is
used as replacement for one of the others, the battery switch-over will
be disabled.
Add nxp,battery-switch-over as an optional devicetree property to configure
the battery switch-over, battery low detection and extra power fail
detection functions.
The property reflects the value of the PWRMNG bits of the Control_3
register.
Signed-off-by: Philipp Rosenberger <p.rosenberger@kunbus.com>
---
drivers/rtc/rtc-pcf2127.c | 61 +++++++++++++++++++++++++++++----------
1 file changed, 46 insertions(+), 15 deletions(-)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 9c04c4e1a49c..812764b65b34 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))
/* Time and date registers */
#define PCF2127_REG_TIME_BASE 0x03
#define PCF2127_BIT_SC_OSF BIT(7)
@@ -529,6 +530,49 @@ 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)
+{
+ u8 val = 0xff;
+ 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__);
+ return ret;
+ }
+
+ ret = device_property_read_u8(dev, "nxp,battery-switch-over", &val);
+ if (ret < 0)
+ return 0;
+
+ if (val > 7) {
+ dev_warn(dev,
+ "%s: ignoring invalid value for nxp,battery-switch-over: %u\n",
+ __func__, val);
+ return 0;
+ };
+ ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL3,
+ PCF2127_BIT_CTRL3_PWRMNG_MASK, val << 5);
+ if (ret) {
+ dev_err(dev,
+ "%s: battery switch-over config (ctrl3) failed\n",
+ __func__);
+ return ret;
+ }
+
+ return 0;
+}
+
/* Alarm */
static int pcf2127_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
@@ -1224,22 +1268,9 @@ static int pcf2127_probe(struct device *dev, struct regmap *regmap,
}
pcf2127_watchdog_init(dev, pcf2127);
-
- /*
- * 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__);
+ ret = pcf2127_battery_init(dev, pcf2127);
+ if (ret < 0)
return ret;
- }
/*
* Enable timestamp functions 1 to 4.
--
2.39.5
---------------------------------------------------------------------------------
sps
Smart Production Solutions
Nuremberg, 12 - 14 November 2024
Visit us: Hall 5, Booth 228
---------------------------------------------------------------------------------
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-22 8:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 8:01 [PATCH 0/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
2024-10-22 8:01 ` [PATCH 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property Philipp Rosenberger
2024-10-22 8:01 ` [PATCH 2/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox