devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] rtc: expand charge support, implement rx8130 charging
@ 2020-09-07 14:27 Bastian Krause
  2020-09-07 14:27 ` [PATCH 1/8] dt-bindings: rtc: let aux-voltage-chargeable supersede trickle-diode-disable Bastian Krause
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

In order to preserve previous RTC charging behavior while allowing to
add new charging configurations this series adds the dt property
aux-voltage-chargeable as a uint enum. It supersedes the
trickle-diode-disable flag.

Then the ds1307 driver's charging infrastructure is generalized:

- support charging on 'aux-voltage-chargeable = <1>'
- keep the previous charge default per chip
- make trickle-resistor-ohms optional for charging
- apply DS13XX_TRICKLE_CHARGER_MAGIC only conditionally

This preparatory work allows to enable Epson's RX8130 backup
battery and make it chargeable when 'aux-voltage-chargeable = <1>' is
given.

I decided to create a new series for this as the patches of previous
efforts changed drastically:

- https://lore.kernel.org/linux-rtc/20190628002151.4925-1-marex@denx.de/
- https://lore.kernel.org/linux-rtc/20190905130336.10651-1-marex@denx.de/
- https://lore.kernel.org/linux-rtc/98fa7181-3ebe-d7c3-cfac-fee841c81e15@pengutronix.de/T/

Regards,
Bastian

Bastian Krause (8):
  dt-bindings: rtc: let aux-voltage-chargeable supersede
    trickle-diode-disable
  dt-bindings: rtc: ds1307: let aux-voltage-chargeable supersede
    trickle-diode-disable
  dt-bindings: rtc: ds1307: add rx8130 aux-voltage-chargeable support
  rtc: ds1307: apply DS13XX_TRICKLE_CHARGER_MAGIC only conditionally
  rtc: ds1307: introduce requires_trickle_resistor per chip
  rtc: ds1307: store previous charge default per chip
  rtc: ds1307: consider aux-voltage-chargeable
  rtc: ds1307: enable rx8130's backup battery, make it chargeable
    optionally

 .../devicetree/bindings/rtc/rtc-ds1307.txt    |  9 ++-
 .../devicetree/bindings/rtc/rtc.yaml          | 10 ++++
 drivers/rtc/rtc-ds1307.c                      | 58 +++++++++++++++++--
 3 files changed, 71 insertions(+), 6 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/8] dt-bindings: rtc: let aux-voltage-chargeable supersede trickle-diode-disable
  2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
@ 2020-09-07 14:27 ` Bastian Krause
  2020-09-08 20:22   ` Rob Herring
  2020-09-07 14:27 ` [PATCH 2/8] dt-bindings: rtc: ds1307: " Bastian Krause
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

Some RTCs can be equipped with a chargeable battery or supercap.
Every RTC allowing this whose driver's implement it are charged by
default. To disable this the trickle-diode-disable flag exists.

If a driver did not support charging and some time later one wants to
add that feature, there is currently no way to do it without breaking
dt backwards compatibility. RTCs on boards without the
trickle-diode-disable flag in their device tree would suddenly charge
their battery/supercap which is a change in behavior.

Change that by introducing aux-voltage-chargeable, not as a flag but as
a uint32 enum allowing to set "do not charge" (0) or "charge" (1). This
dt property is optional, so we can now distinguish these cases.

Care must be taken to support the old behavior for device trees without
aux-voltage-chargeable nonetheless to stay compatible.

Suggested-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
In a previous series aux-voltage-chargeable was added as a ds1307 dt
property. Discussions lead to turning that into a generic rtc dt
property:
https://lore.kernel.org/linux-rtc/98fa7181-3ebe-d7c3-cfac-fee841c81e15@pengutronix.de/T/
---
 Documentation/devicetree/bindings/rtc/rtc.yaml | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Documentation/devicetree/bindings/rtc/rtc.yaml b/Documentation/devicetree/bindings/rtc/rtc.yaml
index ee237b2ed66a..e895c772ce99 100644
--- a/Documentation/devicetree/bindings/rtc/rtc.yaml
+++ b/Documentation/devicetree/bindings/rtc/rtc.yaml
@@ -17,6 +17,15 @@ properties:
   $nodename:
     pattern: "^rtc(@.*|-[0-9a-f])*$"
 
+  aux-voltage-chargeable:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 1]
+    description:
+      Tells whether the battery/supercap of the RTC (if any) is
+      chargeable or not:
+      0: not chargeable
+      1: chargeable
+
   quartz-load-femtofarads:
     $ref: /schemas/types.yaml#/definitions/uint32
     description:
@@ -35,6 +44,7 @@ properties:
     description:
       Do not use internal trickle charger diode. Should be given if
       internal trickle charger diode should be disabled.
+    deprecated: true
 
   trickle-resistor-ohms:
     $ref: /schemas/types.yaml#/definitions/uint32
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/8] dt-bindings: rtc: ds1307: let aux-voltage-chargeable supersede trickle-diode-disable
  2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
  2020-09-07 14:27 ` [PATCH 1/8] dt-bindings: rtc: let aux-voltage-chargeable supersede trickle-diode-disable Bastian Krause
@ 2020-09-07 14:27 ` Bastian Krause
  2020-09-15 16:00   ` Rob Herring
  2020-09-07 14:27 ` [PATCH 3/8] dt-bindings: rtc: ds1307: add rx8130 aux-voltage-chargeable support Bastian Krause
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

trickle-diode-disable is deprecated, so reflect that in the driver's
binding and add the new aux-voltage-chargeable.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
Previous version:
https://lore.kernel.org/linux-rtc/20200415163701.21989-2-bst@pengutronix.de/
---
 Documentation/devicetree/bindings/rtc/rtc-ds1307.txt | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt b/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
index 66f0a31ae9ce..08ea9734da80 100644
--- a/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
+++ b/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
@@ -31,9 +31,16 @@ Optional properties:
 	Selected resistor for trickle charger
 	Possible values are 250, 2000, 4000
 	Should be given if trickle charger should be enabled
-- trickle-diode-disable : ds1339, ds1340 and ds 1388 only
+- aux-voltage-chargeable: ds1339, ds1340 and ds1388 only
+	Tells whether the battery/supercap of the RTC (if any) is
+	chargeable or not.
+	Possible values are 0 (not chargeable), 1 (chargeable)
+
+Deprecated properties:
+- trickle-diode-disable : ds1339, ds1340 and ds1388 only
 	Do not use internal trickle charger diode
 	Should be given if internal trickle charger diode should be disabled
+	(superseded by aux-voltage-chargeable)
 
 Example:
 	ds1339: rtc@68 {
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/8] dt-bindings: rtc: ds1307: add rx8130 aux-voltage-chargeable support
  2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
  2020-09-07 14:27 ` [PATCH 1/8] dt-bindings: rtc: let aux-voltage-chargeable supersede trickle-diode-disable Bastian Krause
  2020-09-07 14:27 ` [PATCH 2/8] dt-bindings: rtc: ds1307: " Bastian Krause
@ 2020-09-07 14:27 ` Bastian Krause
  2020-09-15 16:00   ` Rob Herring
  2020-09-07 14:27 ` [PATCH 4/8] rtc: ds1307: apply DS13XX_TRICKLE_CHARGER_MAGIC only conditionally Bastian Krause
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

Epson's RX8130 was not charged before. A related patch will allow
optional charging.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
Previous version:
https://lore.kernel.org/linux-rtc/20200415163701.21989-2-bst@pengutronix.de/
---
 Documentation/devicetree/bindings/rtc/rtc-ds1307.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt b/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
index 08ea9734da80..36f610bb051e 100644
--- a/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
+++ b/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
@@ -31,7 +31,7 @@ Optional properties:
 	Selected resistor for trickle charger
 	Possible values are 250, 2000, 4000
 	Should be given if trickle charger should be enabled
-- aux-voltage-chargeable: ds1339, ds1340 and ds1388 only
+- aux-voltage-chargeable: ds1339, ds1340, ds1388 and rx8130 only
 	Tells whether the battery/supercap of the RTC (if any) is
 	chargeable or not.
 	Possible values are 0 (not chargeable), 1 (chargeable)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/8] rtc: ds1307: apply DS13XX_TRICKLE_CHARGER_MAGIC only conditionally
  2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
                   ` (2 preceding siblings ...)
  2020-09-07 14:27 ` [PATCH 3/8] dt-bindings: rtc: ds1307: add rx8130 aux-voltage-chargeable support Bastian Krause
@ 2020-09-07 14:27 ` Bastian Krause
  2020-09-07 14:27 ` [PATCH 5/8] rtc: ds1307: introduce requires_trickle_resistor per chip Bastian Krause
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

DS13XX_TRICKLE_CHARGER_MAGIC sets the trickle-charge select (TCS) bits
(7..4). The datasheet of Maxim Integrated's DS1339 [1] for instance
reads:

"To prevent accidental enabling, only a pattern on 1010 enables the
trickle charger. All other patterns disable the trickle charger."

Since not all RTCs connected to a backup battery or supercap use these
bits DS13XX_TRICKLE_CHARGER_MAGIC should not get applied for all charger
setups unconditionally.
Epson's RX8130 is such an example: Instead of TCS bits "SMPTSEL1",
"SMPTSEL0",  "CHGEN" and "INIEN" are expected as bit 7..4.

DS1339 and DS1340 are currently the only RTCs in the ds1307 driver that
apply DS13XX_TRICKLE_CHARGER_MAGIC to their setup register value. So
apply DS13XX_TRICKLE_CHARGER_MAGIC in do_trickle_setup_ds1339() which
is used by both RTCs.

[1] https://datasheets.maximintegrated.com/en/ds/DS1339-DS1339U.pdf
[2] https://support.epson.biz/td/api/doc_check.php?dl=app_RX8130CE

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
No previous version.
---
 drivers/rtc/rtc-ds1307.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 54c85cdd019d..ff5242d10b21 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -507,6 +507,8 @@ static u8 do_trickle_setup_ds1339(struct ds1307 *ds1307, u32 ohms, bool diode)
 	u8 setup = (diode) ? DS1307_TRICKLE_CHARGER_DIODE :
 		DS1307_TRICKLE_CHARGER_NO_DIODE;
 
+	setup |= DS13XX_TRICKLE_CHARGER_MAGIC;
+
 	switch (ohms) {
 	case 250:
 		setup |= DS1307_TRICKLE_CHARGER_250_OHM;
@@ -1758,7 +1760,6 @@ static int ds1307_probe(struct i2c_client *client,
 		trickle_charger_setup = pdata->trickle_charger_setup;
 
 	if (trickle_charger_setup && chip->trickle_charger_reg) {
-		trickle_charger_setup |= DS13XX_TRICKLE_CHARGER_MAGIC;
 		dev_dbg(ds1307->dev,
 			"writing trickle charger info 0x%x to 0x%x\n",
 			trickle_charger_setup, chip->trickle_charger_reg);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/8] rtc: ds1307: introduce requires_trickle_resistor per chip
  2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
                   ` (3 preceding siblings ...)
  2020-09-07 14:27 ` [PATCH 4/8] rtc: ds1307: apply DS13XX_TRICKLE_CHARGER_MAGIC only conditionally Bastian Krause
@ 2020-09-07 14:27 ` Bastian Krause
  2020-09-07 14:27 ` [PATCH 6/8] rtc: ds1307: store previous charge default " Bastian Krause
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

Make trickle-resistor-ohms optional for charging setups that do not
require specifying ROUT bits (specifying the resistor value between Vcc
and Vbackup). In order to allow specifying that, introduce
requires_trickle_resistor per chip.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
No previous version.
---
 drivers/rtc/rtc-ds1307.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index ff5242d10b21..7983438b677a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -190,6 +190,10 @@ struct chip_desc {
 	u16			trickle_charger_reg;
 	u8			(*do_trickle_setup)(struct ds1307 *, u32,
 						    bool);
+	/* Does the RTC require trickle-resistor-ohms to select the value of
+	 * the resistor between Vcc and Vbackup?
+	 */
+	bool			requires_trickle_resistor;
 };
 
 static const struct chip_desc chips[last_ds_type];
@@ -981,6 +985,7 @@ static const struct chip_desc chips[last_ds_type] = {
 		.bbsqi_bit	= DS1339_BIT_BBSQI,
 		.trickle_charger_reg = 0x10,
 		.do_trickle_setup = &do_trickle_setup_ds1339,
+		.requires_trickle_resistor = true,
 	},
 	[ds_1340] = {
 		.century_reg	= DS1307_REG_HOUR,
@@ -988,6 +993,7 @@ static const struct chip_desc chips[last_ds_type] = {
 		.century_bit	= DS1340_BIT_CENTURY,
 		.do_trickle_setup = &do_trickle_setup_ds1339,
 		.trickle_charger_reg = 0x08,
+		.requires_trickle_resistor = true,
 	},
 	[ds_1341] = {
 		.century_reg	= DS1307_REG_MONTH,
@@ -1302,7 +1308,7 @@ static u8 ds1307_trickle_init(struct ds1307 *ds1307,
 		return 0;
 
 	if (device_property_read_u32(ds1307->dev, "trickle-resistor-ohms",
-				     &ohms))
+				     &ohms) && chip->requires_trickle_resistor)
 		return 0;
 
 	if (device_property_read_bool(ds1307->dev, "trickle-diode-disable"))
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/8] rtc: ds1307: store previous charge default per chip
  2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
                   ` (4 preceding siblings ...)
  2020-09-07 14:27 ` [PATCH 5/8] rtc: ds1307: introduce requires_trickle_resistor per chip Bastian Krause
@ 2020-09-07 14:27 ` Bastian Krause
  2020-09-07 14:27 ` [PATCH 7/8] rtc: ds1307: consider aux-voltage-chargeable Bastian Krause
  2020-09-07 14:27 ` [PATCH 8/8] rtc: ds1307: enable rx8130's backup battery, make it chargeable optionally Bastian Krause
  7 siblings, 0 replies; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

Some RTC's batteries and supercaps were charged by default until now.
In contrast other RTCs allow charging but the driver did not configure
them to do so until now. These must not be charged by default to stay
backwards compatible.

In order to do that, store the charge default per chip.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
No previous version.
---
 drivers/rtc/rtc-ds1307.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 7983438b677a..270621e1c9cf 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -194,6 +194,11 @@ struct chip_desc {
 	 * the resistor between Vcc and Vbackup?
 	 */
 	bool			requires_trickle_resistor;
+	/* Some RTC's batteries and supercaps were charged by default, others
+	 * allow charging but were not configured previously to do so.
+	 * Remember this behavior to stay backwards compatible.
+	 */
+	bool			charge_default;
 };
 
 static const struct chip_desc chips[last_ds_type];
@@ -986,6 +991,7 @@ static const struct chip_desc chips[last_ds_type] = {
 		.trickle_charger_reg = 0x10,
 		.do_trickle_setup = &do_trickle_setup_ds1339,
 		.requires_trickle_resistor = true,
+		.charge_default = true,
 	},
 	[ds_1340] = {
 		.century_reg	= DS1307_REG_HOUR,
@@ -994,6 +1000,7 @@ static const struct chip_desc chips[last_ds_type] = {
 		.do_trickle_setup = &do_trickle_setup_ds1339,
 		.trickle_charger_reg = 0x08,
 		.requires_trickle_resistor = true,
+		.charge_default = true,
 	},
 	[ds_1341] = {
 		.century_reg	= DS1307_REG_MONTH,
@@ -1302,7 +1309,7 @@ static u8 ds1307_trickle_init(struct ds1307 *ds1307,
 			      const struct chip_desc *chip)
 {
 	u32 ohms;
-	bool diode = true;
+	bool diode = chip->charge_default;
 
 	if (!chip->do_trickle_setup)
 		return 0;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/8] rtc: ds1307: consider aux-voltage-chargeable
  2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
                   ` (5 preceding siblings ...)
  2020-09-07 14:27 ` [PATCH 6/8] rtc: ds1307: store previous charge default " Bastian Krause
@ 2020-09-07 14:27 ` Bastian Krause
  2020-09-07 14:27 ` [PATCH 8/8] rtc: ds1307: enable rx8130's backup battery, make it chargeable optionally Bastian Krause
  7 siblings, 0 replies; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

Prefer aux-voltage-chargeable over trickle-diode-disable and set diode
accordingly. This is then passed to the chip's appropriate charge setup
function.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
This is the discussion that lead to this patch:
https://lore.kernel.org/linux-rtc/a492b6a0-b41c-a088-3ba1-f1448a074b34@pengutronix.de/
---
 drivers/rtc/rtc-ds1307.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 270621e1c9cf..9bf1822a989f 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -1308,7 +1308,7 @@ static int ds1307_nvram_write(void *priv, unsigned int offset, void *val,
 static u8 ds1307_trickle_init(struct ds1307 *ds1307,
 			      const struct chip_desc *chip)
 {
-	u32 ohms;
+	u32 ohms, chargeable;
 	bool diode = chip->charge_default;
 
 	if (!chip->do_trickle_setup)
@@ -1318,8 +1318,27 @@ static u8 ds1307_trickle_init(struct ds1307 *ds1307,
 				     &ohms) && chip->requires_trickle_resistor)
 		return 0;
 
-	if (device_property_read_bool(ds1307->dev, "trickle-diode-disable"))
+	/* aux-voltage-chargeable takes precedence over the deprecated
+	 * trickle-diode-disable
+	 */
+	if (!device_property_read_u32(ds1307->dev, "aux-voltage-chargeable",
+				     &chargeable)) {
+		switch (chargeable) {
+		case 0:
+			diode = false;
+			break;
+		case 1:
+			diode = true;
+			break;
+		default:
+			dev_warn(ds1307->dev,
+				 "unsupported aux-voltage-chargeable value\n");
+			break;
+		}
+	} else if (device_property_read_bool(ds1307->dev,
+					     "trickle-diode-disable")) {
 		diode = false;
+	}
 
 	return chip->do_trickle_setup(ds1307, ohms, diode);
 }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 8/8] rtc: ds1307: enable rx8130's backup battery, make it chargeable optionally
  2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
                   ` (6 preceding siblings ...)
  2020-09-07 14:27 ` [PATCH 7/8] rtc: ds1307: consider aux-voltage-chargeable Bastian Krause
@ 2020-09-07 14:27 ` Bastian Krause
  7 siblings, 0 replies; 12+ messages in thread
From: Bastian Krause @ 2020-09-07 14:27 UTC (permalink / raw)
  To: linux-rtc
  Cc: devicetree, Alessandro Zummo, Alexandre Belloni, Rob Herring,
	Arnaud Ebalard, Marek Vasut, kernel, Bastian Krause

The ds1307 charger infrastructure now allows to add a rx8130 charger
setup that..

- does not depend on trickle-resistor-ohms
- does not use DS13XX_TRICKLE_CHARGER_MAGIC trickle-charge select (TCS)
  bits
- keeps previous no-charge behavior for device trees without
  aux-voltage-chargeable

Make that happen.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
---
Based on:
- https://lore.kernel.org/linux-rtc/20200415163701.21989-1-bst@pengutronix.de/
- https://lore.kernel.org/linux-rtc/20200415163701.21989-3-bst@pengutronix.de/

Changes since then:
- use chager_reg (called trickle_charger_reg before patch 4/8)
- use charger setup function to set backup battery enable bit, charge
  bit optionally (introduced by patch 5/8)
---
 drivers/rtc/rtc-ds1307.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 9bf1822a989f..1fe0c2df2578 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -122,6 +122,9 @@ enum ds_type {
 #define RX8130_REG_FLAG_AF		BIT(3)
 #define RX8130_REG_CONTROL0		0x1e
 #define RX8130_REG_CONTROL0_AIE		BIT(3)
+#define RX8130_REG_CONTROL1		0x1f
+#define RX8130_REG_CONTROL1_INIEN	BIT(4)
+#define RX8130_REG_CONTROL1_CHGEN	BIT(5)
 
 #define MCP794XX_REG_CONTROL		0x07
 #	define MCP794XX_BIT_ALM0_EN	0x10
@@ -536,6 +539,16 @@ static u8 do_trickle_setup_ds1339(struct ds1307 *ds1307, u32 ohms, bool diode)
 	return setup;
 }
 
+static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode)
+{
+	/* make sure that the backup battery is enabled */
+	u8 setup = RX8130_REG_CONTROL1_INIEN;
+	if (diode)
+		setup |= RX8130_REG_CONTROL1_CHGEN;
+
+	return setup;
+}
+
 static irqreturn_t rx8130_irq(int irq, void *dev_id)
 {
 	struct ds1307           *ds1307 = dev_id;
@@ -1024,6 +1037,8 @@ static const struct chip_desc chips[last_ds_type] = {
 		.offset		= 0x10,
 		.irq_handler = rx8130_irq,
 		.rtc_ops = &rx8130_rtc_ops,
+		.trickle_charger_reg = RX8130_REG_CONTROL1,
+		.do_trickle_setup = &do_trickle_setup_rx8130,
 	},
 	[m41t0] = {
 		.rtc_ops	= &m41txx_rtc_ops,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/8] dt-bindings: rtc: let aux-voltage-chargeable supersede trickle-diode-disable
  2020-09-07 14:27 ` [PATCH 1/8] dt-bindings: rtc: let aux-voltage-chargeable supersede trickle-diode-disable Bastian Krause
@ 2020-09-08 20:22   ` Rob Herring
  0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2020-09-08 20:22 UTC (permalink / raw)
  To: Bastian Krause
  Cc: devicetree, kernel, Alexandre Belloni, Alessandro Zummo,
	linux-rtc, Arnaud Ebalard, Marek Vasut, Rob Herring

On Mon, 07 Sep 2020 16:27:20 +0200, Bastian Krause wrote:
> Some RTCs can be equipped with a chargeable battery or supercap.
> Every RTC allowing this whose driver's implement it are charged by
> default. To disable this the trickle-diode-disable flag exists.
> 
> If a driver did not support charging and some time later one wants to
> add that feature, there is currently no way to do it without breaking
> dt backwards compatibility. RTCs on boards without the
> trickle-diode-disable flag in their device tree would suddenly charge
> their battery/supercap which is a change in behavior.
> 
> Change that by introducing aux-voltage-chargeable, not as a flag but as
> a uint32 enum allowing to set "do not charge" (0) or "charge" (1). This
> dt property is optional, so we can now distinguish these cases.
> 
> Care must be taken to support the old behavior for device trees without
> aux-voltage-chargeable nonetheless to stay compatible.
> 
> Suggested-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
> In a previous series aux-voltage-chargeable was added as a ds1307 dt
> property. Discussions lead to turning that into a generic rtc dt
> property:
> https://lore.kernel.org/linux-rtc/98fa7181-3ebe-d7c3-cfac-fee841c81e15@pengutronix.de/T/
> ---
>  Documentation/devicetree/bindings/rtc/rtc.yaml | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 


My bot found errors running 'make dt_binding_check' on your patch:

Traceback (most recent call last):
  File "/usr/local/bin/dt-extract-example", line 45, in <module>
    binding = yaml.load(open(args.yamlfile, encoding='utf-8').read())
  File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/main.py", line 343, in load
    return constructor.get_single_data()
  File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/constructor.py", line 111, in get_single_data
    node = self.composer.get_single_node()
  File "_ruamel_yaml.pyx", line 706, in _ruamel_yaml.CParser.get_single_node
  File "_ruamel_yaml.pyx", line 724, in _ruamel_yaml.CParser._compose_document
  File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
  File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
  File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
  File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
  File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
  File "_ruamel_yaml.pyx", line 891, in _ruamel_yaml.CParser._compose_mapping_node
  File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event
ruamel.yaml.scanner.ScannerError: mapping values are not allowed in this context
  in "<unicode string>", line 25, column 24
make[1]: *** [Documentation/devicetree/bindings/Makefile:18: Documentation/devicetree/bindings/rtc/rtc.example.dts] Error 1
make[1]: *** Deleting file 'Documentation/devicetree/bindings/rtc/rtc.example.dts'
make[1]: *** Waiting for unfinished jobs....
./Documentation/devicetree/bindings/rtc/rtc.yaml:  mapping values are not allowed in this context
  in "<unicode string>", line 25, column 24
schemas/rtc/rtc.yaml: ignoring, error parsing file
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/rtc/rtc.yaml: ignoring, error parsing file
warning: no schema found in file: ./Documentation/devicetree/bindings/rtc/rtc.yaml
make: *** [Makefile:1366: dt_binding_check] Error 2


See https://patchwork.ozlabs.org/patch/1358937

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure dt-schema is up to date:

pip3 install git+https://github.com/devicetree-org/dt-schema.git@master --upgrade

Please check and re-submit.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/8] dt-bindings: rtc: ds1307: let aux-voltage-chargeable supersede trickle-diode-disable
  2020-09-07 14:27 ` [PATCH 2/8] dt-bindings: rtc: ds1307: " Bastian Krause
@ 2020-09-15 16:00   ` Rob Herring
  0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2020-09-15 16:00 UTC (permalink / raw)
  To: Bastian Krause
  Cc: Arnaud Ebalard, Alexandre Belloni, Alessandro Zummo, linux-rtc,
	Rob Herring, Marek Vasut, kernel, devicetree

On Mon, 07 Sep 2020 16:27:21 +0200, Bastian Krause wrote:
> trickle-diode-disable is deprecated, so reflect that in the driver's
> binding and add the new aux-voltage-chargeable.
> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
> Previous version:
> https://lore.kernel.org/linux-rtc/20200415163701.21989-2-bst@pengutronix.de/
> ---
>  Documentation/devicetree/bindings/rtc/rtc-ds1307.txt | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/8] dt-bindings: rtc: ds1307: add rx8130 aux-voltage-chargeable support
  2020-09-07 14:27 ` [PATCH 3/8] dt-bindings: rtc: ds1307: add rx8130 aux-voltage-chargeable support Bastian Krause
@ 2020-09-15 16:00   ` Rob Herring
  0 siblings, 0 replies; 12+ messages in thread
From: Rob Herring @ 2020-09-15 16:00 UTC (permalink / raw)
  To: Bastian Krause
  Cc: Marek Vasut, Alexandre Belloni, kernel, Alessandro Zummo,
	linux-rtc, devicetree, Arnaud Ebalard, Rob Herring

On Mon, 07 Sep 2020 16:27:22 +0200, Bastian Krause wrote:
> Epson's RX8130 was not charged before. A related patch will allow
> optional charging.
> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> ---
> Previous version:
> https://lore.kernel.org/linux-rtc/20200415163701.21989-2-bst@pengutronix.de/
> ---
>  Documentation/devicetree/bindings/rtc/rtc-ds1307.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-09-15 22:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-07 14:27 [PATCH 0/8] rtc: expand charge support, implement rx8130 charging Bastian Krause
2020-09-07 14:27 ` [PATCH 1/8] dt-bindings: rtc: let aux-voltage-chargeable supersede trickle-diode-disable Bastian Krause
2020-09-08 20:22   ` Rob Herring
2020-09-07 14:27 ` [PATCH 2/8] dt-bindings: rtc: ds1307: " Bastian Krause
2020-09-15 16:00   ` Rob Herring
2020-09-07 14:27 ` [PATCH 3/8] dt-bindings: rtc: ds1307: add rx8130 aux-voltage-chargeable support Bastian Krause
2020-09-15 16:00   ` Rob Herring
2020-09-07 14:27 ` [PATCH 4/8] rtc: ds1307: apply DS13XX_TRICKLE_CHARGER_MAGIC only conditionally Bastian Krause
2020-09-07 14:27 ` [PATCH 5/8] rtc: ds1307: introduce requires_trickle_resistor per chip Bastian Krause
2020-09-07 14:27 ` [PATCH 6/8] rtc: ds1307: store previous charge default " Bastian Krause
2020-09-07 14:27 ` [PATCH 7/8] rtc: ds1307: consider aux-voltage-chargeable Bastian Krause
2020-09-07 14:27 ` [PATCH 8/8] rtc: ds1307: enable rx8130's backup battery, make it chargeable optionally Bastian Krause

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).