* [PATCH v2 0/2] rtc: pcf2127: make battery switch-over configurable
@ 2024-10-22 9:28 Philipp Rosenberger
2024-10-22 9:28 ` [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property Philipp Rosenberger
2024-10-22 9:28 ` [PATCH v2 2/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
0 siblings, 2 replies; 10+ messages in thread
From: Philipp Rosenberger @ 2024-10-22 9:28 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-rtc, devicetree, linux-kernel
Cc: Lino Sanfilippo, Philipp Rosenberger
Hello,
sorry about the broken V1 series. I didn't know, that our IT added a
footer to external mails. This also replaced all tabs with spaces.
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
Changes for V2:
- Just fixed the broken tabs and removed the footer from the mails.
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
2024-10-22 9:28 [PATCH v2 0/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
@ 2024-10-22 9:28 ` Philipp Rosenberger
2024-10-22 16:35 ` Conor Dooley
2024-10-22 9:28 ` [PATCH v2 2/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
1 sibling, 1 reply; 10+ messages in thread
From: Philipp Rosenberger @ 2024-10-22 9:28 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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/2] rtc: pcf2127: make battery switch-over configurable
2024-10-22 9:28 [PATCH v2 0/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
2024-10-22 9:28 ` [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property Philipp Rosenberger
@ 2024-10-22 9:28 ` Philipp Rosenberger
2024-10-23 0:07 ` Nobuhiro Iwamatsu
1 sibling, 1 reply; 10+ messages in thread
From: Philipp Rosenberger @ 2024-10-22 9:28 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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
2024-10-22 9:28 ` [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property Philipp Rosenberger
@ 2024-10-22 16:35 ` Conor Dooley
2024-10-23 7:06 ` Krzysztof Kozlowski
2024-10-24 7:11 ` Philipp Rosenberger
0 siblings, 2 replies; 10+ messages in thread
From: Conor Dooley @ 2024-10-22 16:35 UTC (permalink / raw)
To: Philipp Rosenberger
Cc: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-rtc, devicetree, linux-kernel, Lino Sanfilippo
[-- Attachment #1: Type: text/plain, Size: 1985 bytes --]
On Tue, Oct 22, 2024 at 11:28:54AM +0200, Philipp Rosenberger wrote:
> 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
Beyond the fact that I dislike register-content properties like this, where
it is not possible to grok the meaning by reading the property, what
even makes this suitable for DT in the first place? Reading the commit
message this sounds like software policy, and that different users of
the same board might want to configure these register bits in different
ways.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] rtc: pcf2127: make battery switch-over configurable
2024-10-22 9:28 ` [PATCH v2 2/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
@ 2024-10-23 0:07 ` Nobuhiro Iwamatsu
0 siblings, 0 replies; 10+ messages in thread
From: Nobuhiro Iwamatsu @ 2024-10-23 0:07 UTC (permalink / raw)
To: Philipp Rosenberger
Cc: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-rtc, devicetree, Linux Kernel Mailing List, Lino Sanfilippo
Hello,
2024年10月22日(火) 18:29 Philipp Rosenberger <p.rosenberger@kunbus.com>:
>
> 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;
> + };
Please remove ';' .
Otherwise
Reviewed-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Best regards,
Nobuhiro
--
Nobuhiro Iwamatsu
iwamatsu at {nigauri.org / debian.org / kernel.org}
GPG ID: 32247FBB40AD1FA6
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
2024-10-22 16:35 ` Conor Dooley
@ 2024-10-23 7:06 ` Krzysztof Kozlowski
2024-10-24 7:11 ` Philipp Rosenberger
1 sibling, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-23 7:06 UTC (permalink / raw)
To: Conor Dooley
Cc: Philipp Rosenberger, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, linux-rtc, devicetree,
linux-kernel, Lino Sanfilippo
On Tue, Oct 22, 2024 at 05:35:55PM +0100, Conor Dooley wrote:
> On Tue, Oct 22, 2024 at 11:28:54AM +0200, Philipp Rosenberger wrote:
> > 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
>
> Beyond the fact that I dislike register-content properties like this, where
> it is not possible to grok the meaning by reading the property, what
> even makes this suitable for DT in the first place? Reading the commit
> message this sounds like software policy, and that different users of
> the same board might want to configure these register bits in different
> ways.
Especially that according to commit msg this is model specific, so
compatible already defines different default value of this register.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
2024-10-22 16:35 ` Conor Dooley
2024-10-23 7:06 ` Krzysztof Kozlowski
@ 2024-10-24 7:11 ` Philipp Rosenberger
2024-10-24 7:25 ` Krzysztof Kozlowski
1 sibling, 1 reply; 10+ messages in thread
From: Philipp Rosenberger @ 2024-10-24 7:11 UTC (permalink / raw)
To: Conor Dooley
Cc: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
linux-rtc, devicetree, linux-kernel, Lino Sanfilippo
On 22.10.24 18:35, Conor Dooley wrote:
> On Tue, Oct 22, 2024 at 11:28:54AM +0200, Philipp Rosenberger wrote:
>> 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
>
> Beyond the fact that I dislike register-content properties like this, where
> it is not possible to grok the meaning by reading the property, what
Yes, I'm not satisfied with this solution myself.
There are three different functions, which can be configured in the
register:
- battery switch-over mode: standard; direct; disabled
- battery low detection: enabled; disabled
- extra power fail detection: enabled; disabled
I'm not sure what a proper way is to implement this in the devicetree.
> even makes this suitable for DT in the first place? Reading the commit
> message this sounds like software policy, and that different users of
> the same board might want to configure these register bits in different
> ways.
It is less a software policy, but a configuration how the hardware is
implemented. If the device has no battery, it is possible to disable the
battery switch-over function. In this case the V_BAT must be connected
to ground.
If a battery is connected, the battery switchover will only work if the
battery switch-over function is in standard mode or direct switching mode.
Until now the driver has just ignored the PWRMNG bits. As the default
was battery switching in standard mode. Thus all use cases worked good
enough. Battery switching was working if a battery was connected. If no
battery was connected it did no real harm (the rtc may have used a tiny
bit more power then needed, I guess).
With the new PCF2131 the default has changed to battery switch-over
disabled. Now even with a battery attached, the rtc will lose time after
a power cycle.
I guess I should describe this better in the commit message.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
2024-10-24 7:11 ` Philipp Rosenberger
@ 2024-10-24 7:25 ` Krzysztof Kozlowski
2024-10-28 14:54 ` Philipp Rosenberger
0 siblings, 1 reply; 10+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-24 7:25 UTC (permalink / raw)
To: Philipp Rosenberger
Cc: Conor Dooley, Alexandre Belloni, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux-rtc, devicetree, linux-kernel,
Lino Sanfilippo
On Thu, Oct 24, 2024 at 09:11:04AM +0200, Philipp Rosenberger wrote:
> On 22.10.24 18:35, Conor Dooley wrote:
> > On Tue, Oct 22, 2024 at 11:28:54AM +0200, Philipp Rosenberger wrote:
> > > 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
> >
> > Beyond the fact that I dislike register-content properties like this, where
> > it is not possible to grok the meaning by reading the property, what
>
> Yes, I'm not satisfied with this solution myself.
> There are three different functions, which can be configured in the
> register:
> - battery switch-over mode: standard; direct; disabled
> - battery low detection: enabled; disabled
> - extra power fail detection: enabled; disabled
>
> I'm not sure what a proper way is to implement this in the devicetree.
>
> > even makes this suitable for DT in the first place? Reading the commit
> > message this sounds like software policy, and that different users of
> > the same board might want to configure these register bits in different
> > ways.
>
> It is less a software policy, but a configuration how the hardware is
> implemented. If the device has no battery, it is possible to disable the
> battery switch-over function. In this case the V_BAT must be connected to
> ground.
monitored-battery property already tells you this.
> If a battery is connected, the battery switchover will only work if the
> battery switch-over function is in standard mode or direct switching mode.
> Until now the driver has just ignored the PWRMNG bits. As the default was
> battery switching in standard mode. Thus all use cases worked good enough.
> Battery switching was working if a battery was connected. If no battery was
> connected it did no real harm (the rtc may have used a tiny bit more power
> then needed, I guess).
Why driver cannot use standard mode always? Or other way?
> With the new PCF2131 the default has changed to battery switch-over
> disabled. Now even with a battery attached, the rtc will lose time after a
> power cycle.
> I guess I should describe this better in the commit message.
In any case this is pcf2131 related, right? So compatible implies it.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
2024-10-24 7:25 ` Krzysztof Kozlowski
@ 2024-10-28 14:54 ` Philipp Rosenberger
2024-10-28 15:55 ` Krzysztof Kozlowski
0 siblings, 1 reply; 10+ messages in thread
From: Philipp Rosenberger @ 2024-10-28 14:54 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Conor Dooley, Alexandre Belloni, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux-rtc, devicetree, linux-kernel,
Lino Sanfilippo
On 24.10.24 09:25, Krzysztof Kozlowski wrote:
> On Thu, Oct 24, 2024 at 09:11:04AM +0200, Philipp Rosenberger wrote:
>> On 22.10.24 18:35, Conor Dooley wrote:
>>> On Tue, Oct 22, 2024 at 11:28:54AM +0200, Philipp Rosenberger wrote:
>>>> 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
>>>
>>> Beyond the fact that I dislike register-content properties like this, where
>>> it is not possible to grok the meaning by reading the property, what
>>
>> Yes, I'm not satisfied with this solution myself.
>> There are three different functions, which can be configured in the
>> register:
>> - battery switch-over mode: standard; direct; disabled
>> - battery low detection: enabled; disabled
>> - extra power fail detection: enabled; disabled
>>
>> I'm not sure what a proper way is to implement this in the devicetree.
>>
>>> even makes this suitable for DT in the first place? Reading the commit
>>> message this sounds like software policy, and that different users of
>>> the same board might want to configure these register bits in different
>>> ways.
>>
>> It is less a software policy, but a configuration how the hardware is
>> implemented. If the device has no battery, it is possible to disable the
>> battery switch-over function. In this case the V_BAT must be connected to
>> ground.
>
> monitored-battery property already tells you this.
If I understand this correctly, the monitored-battery property is meant
for rechargeable batteries, not for a simple button cell to back up an RTC.
>
>> If a battery is connected, the battery switchover will only work if the
>> battery switch-over function is in standard mode or direct switching mode.
>> Until now the driver has just ignored the PWRMNG bits. As the default was
>> battery switching in standard mode. Thus all use cases worked good enough.
>> Battery switching was working if a battery was connected. If no battery was
>> connected it did no real harm (the rtc may have used a tiny bit more power
>> then needed, I guess).
>
> Why driver cannot use standard mode always? Or other way?
This would overwrite any configuration set by a bootloader/firmware. For
the older chips (pre PCF2131) this was no problem. As the reset default,
was "battery switch-over in standard mode". The driver just left the
whole battery switch-over configuration untouched.
If we decide to change the battery switch-over configuration
unconditionally, this could overwrite any third-party configuration.
>> With the new PCF2131 the default has changed to battery switch-over
>> disabled. Now even with a battery attached, the rtc will lose time after a
>> power cycle.
>> I guess I should describe this better in the commit message.
>
> In any case this is pcf2131 related, right? So compatible implies it.
The reason, why this property is necessary for our devices is the new
PCF2131. But the function is not limited to this device.
I’m considering simplifying this to just a property that informs the
driver that a backup battery is available. If the property is available,
the driver will enable the battery switch-over function; otherwise, it
will not touch the configuration.
Best regards,
Philipp
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property
2024-10-28 14:54 ` Philipp Rosenberger
@ 2024-10-28 15:55 ` Krzysztof Kozlowski
0 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2024-10-28 15:55 UTC (permalink / raw)
To: Philipp Rosenberger
Cc: Conor Dooley, Alexandre Belloni, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux-rtc, devicetree, linux-kernel,
Lino Sanfilippo
On 28/10/2024 15:54, Philipp Rosenberger wrote:
> On 24.10.24 09:25, Krzysztof Kozlowski wrote:
>> On Thu, Oct 24, 2024 at 09:11:04AM +0200, Philipp Rosenberger wrote:
>>> On 22.10.24 18:35, Conor Dooley wrote:
>>>> On Tue, Oct 22, 2024 at 11:28:54AM +0200, Philipp Rosenberger wrote:
>>>>> 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
>>>>
>>>> Beyond the fact that I dislike register-content properties like this, where
>>>> it is not possible to grok the meaning by reading the property, what
>>>
>>> Yes, I'm not satisfied with this solution myself.
>>> There are three different functions, which can be configured in the
>>> register:
>>> - battery switch-over mode: standard; direct; disabled
>>> - battery low detection: enabled; disabled
>>> - extra power fail detection: enabled; disabled
>>>
>>> I'm not sure what a proper way is to implement this in the devicetree.
>>>
>>>> even makes this suitable for DT in the first place? Reading the commit
>>>> message this sounds like software policy, and that different users of
>>>> the same board might want to configure these register bits in different
>>>> ways.
>>>
>>> It is less a software policy, but a configuration how the hardware is
>>> implemented. If the device has no battery, it is possible to disable the
>>> battery switch-over function. In this case the V_BAT must be connected to
>>> ground.
>>
>> monitored-battery property already tells you this.
>
> If I understand this correctly, the monitored-battery property is meant
> for rechargeable batteries, not for a simple button cell to back up an RTC.
Uh, right, this is not a charger. Then property, when described as real
hardware characteristic, is fine, e.g. "nxp,no-backup-battery".
>
>>
>>> If a battery is connected, the battery switchover will only work if the
>>> battery switch-over function is in standard mode or direct switching mode.
>>> Until now the driver has just ignored the PWRMNG bits. As the default was
>>> battery switching in standard mode. Thus all use cases worked good enough.
>>> Battery switching was working if a battery was connected. If no battery was
>>> connected it did no real harm (the rtc may have used a tiny bit more power
>>> then needed, I guess).
>>
>> Why driver cannot use standard mode always? Or other way?
>
> This would overwrite any configuration set by a bootloader/firmware. For
> the older chips (pre PCF2131) this was no problem. As the reset default,
> was "battery switch-over in standard mode". The driver just left the
> whole battery switch-over configuration untouched.
> If we decide to change the battery switch-over configuration
> unconditionally, this could overwrite any third-party configuration.
I still don't get why this is a problem. Why device cannot be configured
completely?
>
>>> With the new PCF2131 the default has changed to battery switch-over
>>> disabled. Now even with a battery attached, the rtc will lose time after a
>>> power cycle.
>>> I guess I should describe this better in the commit message.
>>
>> In any case this is pcf2131 related, right? So compatible implies it.
>
> The reason, why this property is necessary for our devices is the new
> PCF2131. But the function is not limited to this device.
>
> I’m considering simplifying this to just a property that informs the
> driver that a backup battery is available. If the property is available,
> the driver will enable the battery switch-over function; otherwise, it
> will not touch the configuration.
Sure.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-10-28 15:56 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 9:28 [PATCH v2 0/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
2024-10-22 9:28 ` [PATCH v2 1/2] dt-bindings: rtc: pcf2127: Add nxp,battery-switch-over property Philipp Rosenberger
2024-10-22 16:35 ` Conor Dooley
2024-10-23 7:06 ` Krzysztof Kozlowski
2024-10-24 7:11 ` Philipp Rosenberger
2024-10-24 7:25 ` Krzysztof Kozlowski
2024-10-28 14:54 ` Philipp Rosenberger
2024-10-28 15:55 ` Krzysztof Kozlowski
2024-10-22 9:28 ` [PATCH v2 2/2] rtc: pcf2127: make battery switch-over configurable Philipp Rosenberger
2024-10-23 0:07 ` Nobuhiro Iwamatsu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).