From: Brian Sune <briansune@gmail.com>
To: alexandre.belloni@bootlin.com
Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org,
Brian Sune <briansune@gmail.com>
Subject: [PATCH v1] Fix missing RTC charge ctrl
Date: Sat, 18 Apr 2026 02:38:49 +0800 [thread overview]
Message-ID: <20260417183849.88144-1-briansune@gmail.com> (raw)
Default driver did not consider battery supported
use cases, which DTS and probe did not control
the charge switch and strength. As such battery
could be dried out and possible dmanage.
Signed-off-by: Brian Sune <briansune@gmail.com>
---
drivers/rtc/rtc-sd3078.c | 47 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-sd3078.c b/drivers/rtc/rtc-sd3078.c
index 10cc1dcfc774..871e6d9acd86 100644
--- a/drivers/rtc/rtc-sd3078.c
+++ b/drivers/rtc/rtc-sd3078.c
@@ -22,11 +22,17 @@
#define SD3078_REG_CTRL1 0x0f
#define SD3078_REG_CTRL2 0x10
#define SD3078_REG_CTRL3 0x11
+#define SD3078_REG_AGTC 0x17
+#define SD3078_REG_CHARGE 0x18
#define KEY_WRITE1 0x80
#define KEY_WRITE2 0x04
#define KEY_WRITE3 0x80
+#define CLK_F32K 0x40
+
+#define BAT_IIC 0x80
+
#define NUM_TIME_REGS (SD3078_REG_YR - SD3078_REG_SC + 1)
/*
@@ -36,6 +42,13 @@
*/
#define WRITE_PROTECT_EN 0
+static const char * const sd3078_charge_names[] = {
+ "10k", /* 0x00 */
+ "5k", /* 0x01 */
+ "2k", /* 0x02 */
+ "inf", /* 0x03 */
+};
+
/*
* In order to prevent arbitrary modification of the time register,
* when modification of the register,
@@ -148,13 +161,15 @@ static const struct rtc_class_ops sd3078_rtc_ops = {
static const struct regmap_config regmap_config = {
.reg_bits = 8,
.val_bits = 8,
- .max_register = 0x11,
+ .max_register = 0x18,
};
static int sd3078_probe(struct i2c_client *client)
{
int ret;
+ unsigned int val;
struct regmap *regmap;
+ bool f32k_out, bat_iic;
struct rtc_device *rtc;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
@@ -182,6 +197,36 @@ static int sd3078_probe(struct i2c_client *client)
sd3078_enable_reg_write(regmap);
+ f32k_out = device_property_read_bool(&client->dev, "CLOCK_F32K");
+ regmap_update_bits(regmap, SD3078_REG_CTRL3,
+ CLK_F32K, !f32k_out);
+
+ bat_iic = device_property_read_bool(&client->dev, "IIC_ON_BAT");
+ regmap_update_bits(regmap, SD3078_REG_AGTC,
+ BAT_IIC, bat_iic);
+
+ ret = regmap_read(regmap, SD3078_REG_CHARGE, &val);
+ if (!ret) {
+ dev_info(&client->dev, "RTC BAT Charge: %s",
+ (val & 0x80) ? "ON" : "OFF");
+ }
+
+ ret = device_property_read_u32(&client->dev, "BAT_CHARGE", &val);
+ if (!ret) {
+ // 0: 10k, 1: 5k, 2: 2k, 3: inf
+ dev_info(&client->dev, "Enable Battery Charge.\n");
+ regmap_write(regmap, SD3078_REG_CHARGE,
+ (val < 3) ? (u8)(val|0x80) : 0x03);
+ }
+
+ ret = regmap_read(regmap, SD3078_REG_CHARGE, &val);
+ if (!ret) {
+ dev_info(&client->dev, "RTC BAT charge: %s",
+ (val & 0x80) ? "ON" : "OFF");
+ dev_info(&client->dev, "RTC BAT Charge Strength: %s",
+ sd3078_charge_names[val & 0x03]);
+ }
+
return 0;
}
--
2.34.1
reply other threads:[~2026-04-17 18:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260417183849.88144-1-briansune@gmail.com \
--to=briansune@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.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