devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bastian Krause <bst@pengutronix.de>
To: linux-rtc@vger.kernel.org
Cc: devicetree@vger.kernel.org,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Rob Herring <robh+dt@kernel.org>,
	Arnaud Ebalard <arno@natisbad.org>, Marek Vasut <marex@denx.de>,
	kernel@pengutronix.de, Bastian Krause <bst@pengutronix.de>
Subject: [PATCH 8/8] rtc: ds1307: enable rx8130's backup battery, make it chargeable optionally
Date: Mon,  7 Sep 2020 16:27:27 +0200	[thread overview]
Message-ID: <20200907142727.26472-9-bst@pengutronix.de> (raw)
In-Reply-To: <20200907142727.26472-1-bst@pengutronix.de>

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


      parent reply	other threads:[~2020-09-07 16:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Bastian Krause [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200907142727.26472-9-bst@pengutronix.de \
    --to=bst@pengutronix.de \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=arno@natisbad.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-rtc@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).