* [PATCH 0/4] rtc: ds1307: Add support for Epson RX8901CE
@ 2025-12-19 12:10 Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901 Fredrik M Olsson
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Fredrik M Olsson @ 2025-12-19 12:10 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Nobuhiro Iwamatsu
Cc: linux-rtc, devicetree, linux-kernel, Fredrik M Olsson, kernel
Add basic support for the Epson RX8901CE RTC.
Datasheet: https://download.epsondevice.com/td/pdf/app/RX8901CE_en.pdf
Also includes a bug fix for an issue with reading the weekday from the
RTC which affects both the existing rx8130 and this rx8901 driver.
Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
---
Fredrik M Olsson (4):
dt-bindings: rtc: ds1307: Add epson,rx8901
rtc: ds1307: Fix off-by-one issue with wday for rx8130
rtc: ds1307: Add Driver for Epson RX8901CE
rtc: ds1307: Add support for reading RX8901CE battery VL status
.../devicetree/bindings/rtc/rtc-ds1307.yaml | 1 +
drivers/rtc/rtc-ds1307.c | 104 ++++++++++++++++++++-
2 files changed, 102 insertions(+), 3 deletions(-)
---
base-commit: ea1013c1539270e372fc99854bc6e4d94eaeff66
change-id: 20251126-ds1307-rx8901-add-a0fe173093e3
Best regards,
--
Fredrik M Olsson <fredrik.m.olsson@axis.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901
2025-12-19 12:10 [PATCH 0/4] rtc: ds1307: Add support for Epson RX8901CE Fredrik M Olsson
@ 2025-12-19 12:10 ` Fredrik M Olsson
2025-12-20 8:59 ` Krzysztof Kozlowski
2025-12-24 5:04 ` nobuhiro.iwamatsu.x90
2025-12-19 12:10 ` [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130 Fredrik M Olsson
` (2 subsequent siblings)
3 siblings, 2 replies; 14+ messages in thread
From: Fredrik M Olsson @ 2025-12-19 12:10 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Nobuhiro Iwamatsu
Cc: linux-rtc, devicetree, linux-kernel, Fredrik M Olsson, kernel
Add compatible string epson,rx8901 for the Epson RX8901CE RTC.
Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
---
Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml b/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml
index 98d10e680144..9b2796804f07 100644
--- a/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml
+++ b/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml
@@ -31,6 +31,7 @@ properties:
- epson,rx8025
- isil,isl12057
- epson,rx8130
+ - epson,rx8901
- items:
- enum:
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130
2025-12-19 12:10 [PATCH 0/4] rtc: ds1307: Add support for Epson RX8901CE Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901 Fredrik M Olsson
@ 2025-12-19 12:10 ` Fredrik M Olsson
2025-12-24 5:06 ` nobuhiro.iwamatsu.x90
2025-12-19 12:10 ` [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status Fredrik M Olsson
3 siblings, 1 reply; 14+ messages in thread
From: Fredrik M Olsson @ 2025-12-19 12:10 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Nobuhiro Iwamatsu
Cc: linux-rtc, devicetree, linux-kernel, Fredrik M Olsson, kernel
The RTC represent each weekday with a individual bit set in the WDAY
register, where the 0th bit represent the first day of the week and the
6th bit represents the last day of the week. For each passed day the
chip performs a rotary-left-shift by one to advance the weekday by one.
The tm_wday field represent weekdays by a value in the range of 0-6.
The fls() function return the bit index of the last bit set. To handle
when there are no bits set it will return 0, and if the 0th bit is set
it will return 1, and if the 1st bit is set it will return 2, and so on.
In order to make the result of the fls() function fall into the expected
range of 0-6 (instead of 1-7) this patch subtracts one from the result
(which matches how the value is written in ds1307_set_time()).
Fixes: 204756f016726 ("rtc: ds1307: Fix wday settings for rx8130")
Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
---
drivers/rtc/rtc-ds1307.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 7205c59ff729..bf42c250ea7d 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -308,7 +308,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
t->tm_hour = bcd2bin(tmp);
/* rx8130 is bit position, not BCD */
if (ds1307->type == rx_8130)
- t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f);
+ t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f) - 1;
else
t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f);
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE
2025-12-19 12:10 [PATCH 0/4] rtc: ds1307: Add support for Epson RX8901CE Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901 Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130 Fredrik M Olsson
@ 2025-12-19 12:10 ` Fredrik M Olsson
2025-12-24 5:05 ` nobuhiro.iwamatsu.x90
2026-01-31 0:03 ` Alexandre Belloni
2025-12-19 12:10 ` [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status Fredrik M Olsson
3 siblings, 2 replies; 14+ messages in thread
From: Fredrik M Olsson @ 2025-12-19 12:10 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Nobuhiro Iwamatsu
Cc: linux-rtc, devicetree, linux-kernel, Fredrik M Olsson, kernel
Adds Support for:
- Reading and writing time to/from the RTC.
- Switching to backup battery supply when primary supply disappears.
- Optionally enabling battery charging.
Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
---
drivers/rtc/rtc-ds1307.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 60 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index bf42c250ea7d..99d95e520108 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -48,6 +48,7 @@ enum ds_type {
mcp794xx,
rx_8025,
rx_8130,
+ rx_8901,
last_ds_type /* always last */
/* rs5c372 too? different address... */
};
@@ -129,6 +130,12 @@ enum ds_type {
#define RX8130_REG_CONTROL1_INIEN BIT(4)
#define RX8130_REG_CONTROL1_CHGEN BIT(5)
+#define RX8901_REG_INTF 0x0e
+#define RX8901_REG_INTF_VLF BIT(1)
+#define RX8901_REG_PWSW_CFG 0x37
+#define RX8901_REG_PWSW_CFG_INIEN BIT(6)
+#define RX8901_REG_PWSW_CFG_CHGEN BIT(7)
+
#define MCP794XX_REG_CONTROL 0x07
# define MCP794XX_BIT_ALM0_EN 0x10
# define MCP794XX_BIT_ALM1_EN 0x20
@@ -226,6 +233,19 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
dev_warn_once(dev, "oscillator failed, set time!\n");
return -EINVAL;
}
+ } else if (ds1307->type == rx_8901) {
+ unsigned int regflag;
+
+ ret = regmap_read(ds1307->regmap, RX8901_REG_INTF, ®flag);
+ if (ret) {
+ dev_err(dev, "%s error %d\n", "read", ret);
+ return ret;
+ }
+
+ if (regflag & RX8901_REG_INTF_VLF) {
+ dev_warn_once(dev, "oscillator failed, set time!\n");
+ return -EINVAL;
+ }
}
/* read the RTC date and time registers all at once */
@@ -307,7 +327,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
tmp = regs[DS1307_REG_HOUR] & 0x3f;
t->tm_hour = bcd2bin(tmp);
/* rx8130 is bit position, not BCD */
- if (ds1307->type == rx_8130)
+ if (ds1307->type == rx_8130 || ds1307->type == rx_8901)
t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f) - 1;
else
t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
@@ -358,7 +378,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
regs[DS1307_REG_MIN] = bin2bcd(t->tm_min);
regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
/* rx8130 is bit position, not BCD */
- if (ds1307->type == rx_8130)
+ if (ds1307->type == rx_8130 || ds1307->type == rx_8901)
regs[DS1307_REG_WDAY] = 1 << t->tm_wday;
else
regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
@@ -422,6 +442,17 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
dev_err(dev, "%s error %d\n", "write", result);
return result;
}
+ } else if (ds1307->type == rx_8901) {
+ /*
+ * clear Voltage Loss Flag as data is available now (writing 1
+ * to the other bits in the INTF register has no effect)
+ */
+ result = regmap_write(ds1307->regmap, RX8901_REG_INTF,
+ 0xff ^ RX8901_REG_INTF_VLF);
+ if (result) {
+ dev_err(dev, "%s error %d\n", "write", result);
+ return result;
+ }
}
return 0;
@@ -568,6 +599,17 @@ static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode)
return setup;
}
+static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms, bool diode)
+{
+ /* make sure that the backup battery is enabled */
+ u8 setup = RX8901_REG_PWSW_CFG_INIEN;
+
+ if (diode)
+ setup |= RX8901_REG_PWSW_CFG_CHGEN;
+
+ return setup;
+}
+
static irqreturn_t rx8130_irq(int irq, void *dev_id)
{
struct ds1307 *ds1307 = dev_id;
@@ -960,6 +1002,11 @@ static const struct rtc_class_ops rx8130_rtc_ops = {
.alarm_irq_enable = rx8130_alarm_irq_enable,
};
+static const struct rtc_class_ops rx8901_rtc_ops = {
+ .read_time = ds1307_get_time,
+ .set_time = ds1307_set_time,
+};
+
static const struct rtc_class_ops mcp794xx_rtc_ops = {
.read_time = ds1307_get_time,
.set_time = ds1307_set_time,
@@ -1040,6 +1087,12 @@ static const struct chip_desc chips[last_ds_type] = {
.trickle_charger_reg = RX8130_REG_CONTROL1,
.do_trickle_setup = &do_trickle_setup_rx8130,
},
+ [rx_8901] = {
+ .offset = 0x0,
+ .rtc_ops = &rx8901_rtc_ops,
+ .trickle_charger_reg = RX8901_REG_PWSW_CFG,
+ .do_trickle_setup = &do_trickle_setup_rx8901,
+ },
[m41t0] = {
.rtc_ops = &m41txx_rtc_ops,
},
@@ -1081,6 +1134,7 @@ static const struct i2c_device_id ds1307_id[] = {
{ "rx8025", rx_8025 },
{ "isl12057", ds_1337 },
{ "rx8130", rx_8130 },
+ { "rx8901", rx_8901 },
{ }
};
MODULE_DEVICE_TABLE(i2c, ds1307_id);
@@ -1158,6 +1212,10 @@ static const struct of_device_id ds1307_of_match[] = {
.compatible = "epson,rx8130",
.data = (void *)rx_8130
},
+ {
+ .compatible = "epson,rx8901",
+ .data = (void *)rx_8901
+ },
{ }
};
MODULE_DEVICE_TABLE(of, ds1307_of_match);
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status
2025-12-19 12:10 [PATCH 0/4] rtc: ds1307: Add support for Epson RX8901CE Fredrik M Olsson
` (2 preceding siblings ...)
2025-12-19 12:10 ` [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE Fredrik M Olsson
@ 2025-12-19 12:10 ` Fredrik M Olsson
2025-12-24 5:07 ` nobuhiro.iwamatsu.x90
2026-01-31 0:05 ` Alexandre Belloni
3 siblings, 2 replies; 14+ messages in thread
From: Fredrik M Olsson @ 2025-12-19 12:10 UTC (permalink / raw)
To: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Nobuhiro Iwamatsu
Cc: linux-rtc, devicetree, linux-kernel, Fredrik M Olsson, kernel
Adds support for:
- Reading the battery voltage low status using the RTC_VL_READ ioctl,
which also reports invalid time information if the VLF flag is set.
Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
---
drivers/rtc/rtc-ds1307.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 43 insertions(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 99d95e520108..ca062ed0c867 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -133,8 +133,11 @@ enum ds_type {
#define RX8901_REG_INTF 0x0e
#define RX8901_REG_INTF_VLF BIT(1)
#define RX8901_REG_PWSW_CFG 0x37
+#define RX8901_REG_PWSW_CFG_VBATLDETEN BIT(4)
#define RX8901_REG_PWSW_CFG_INIEN BIT(6)
#define RX8901_REG_PWSW_CFG_CHGEN BIT(7)
+#define RX8901_REG_BUF_INTF 0x46
+#define RX8901_REG_BUF_INTF_VBATLF BIT(3)
#define MCP794XX_REG_CONTROL 0x07
# define MCP794XX_BIT_ALM0_EN 0x10
@@ -458,6 +461,39 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
return 0;
}
+#ifdef CONFIG_RTC_INTF_DEV
+static int rx8901_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+{
+ struct ds1307 *ds1307 = dev_get_drvdata(dev);
+ unsigned int regflag, tmp = 0;
+ int ret = 0;
+
+ switch (cmd) {
+ case RTC_VL_READ:
+ ret = regmap_read(ds1307->regmap, RX8901_REG_INTF, ®flag);
+ if (ret)
+ return ret;
+
+ if (regflag & RX8901_REG_INTF_VLF)
+ tmp |= RTC_VL_DATA_INVALID;
+
+ ret = regmap_read(ds1307->regmap, RX8901_REG_BUF_INTF, ®flag);
+ if (ret)
+ return ret;
+
+ if (regflag & RX8901_REG_BUF_INTF_VBATLF)
+ tmp |= RTC_VL_BACKUP_LOW;
+
+ return put_user(tmp, (unsigned int __user *)arg);
+ default:
+ return -ENOIOCTLCMD;
+ }
+ return ret;
+}
+#else
+#define rx8901_ioctl NULL
+#endif
+
static int ds1337_read_alarm(struct device *dev, struct rtc_wkalrm *t)
{
struct ds1307 *ds1307 = dev_get_drvdata(dev);
@@ -599,10 +635,13 @@ static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode)
return setup;
}
-static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms, bool diode)
+static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms __always_unused, bool diode)
{
- /* make sure that the backup battery is enabled */
- u8 setup = RX8901_REG_PWSW_CFG_INIEN;
+ /*
+ * make sure that the backup battery is enabled and that battery
+ * voltage detection is performed
+ */
+ u8 setup = RX8901_REG_PWSW_CFG_INIEN | RX8901_REG_PWSW_CFG_VBATLDETEN;
if (diode)
setup |= RX8901_REG_PWSW_CFG_CHGEN;
@@ -1005,6 +1044,7 @@ static const struct rtc_class_ops rx8130_rtc_ops = {
static const struct rtc_class_ops rx8901_rtc_ops = {
.read_time = ds1307_get_time,
.set_time = ds1307_set_time,
+ .ioctl = rx8901_ioctl,
};
static const struct rtc_class_ops mcp794xx_rtc_ops = {
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901
2025-12-19 12:10 ` [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901 Fredrik M Olsson
@ 2025-12-20 8:59 ` Krzysztof Kozlowski
2025-12-24 5:04 ` nobuhiro.iwamatsu.x90
1 sibling, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2025-12-20 8:59 UTC (permalink / raw)
To: Fredrik M Olsson
Cc: Alexandre Belloni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Nobuhiro Iwamatsu, linux-rtc, devicetree, linux-kernel, kernel
On Fri, Dec 19, 2025 at 01:10:35PM +0100, Fredrik M Olsson wrote:
> Add compatible string epson,rx8901 for the Epson RX8901CE RTC.
>
> Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
> ---
> Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml | 1 +
> 1 file changed, 1 insertion(+)
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901
2025-12-19 12:10 ` [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901 Fredrik M Olsson
2025-12-20 8:59 ` Krzysztof Kozlowski
@ 2025-12-24 5:04 ` nobuhiro.iwamatsu.x90
1 sibling, 0 replies; 14+ messages in thread
From: nobuhiro.iwamatsu.x90 @ 2025-12-24 5:04 UTC (permalink / raw)
To: fredrik.m.olsson, alexandre.belloni, robh, krzk+dt, conor+dt
Cc: linux-rtc, devicetree, linux-kernel, kernel
Hi Fredrik,
> -----Original Message-----
> From: Fredrik M Olsson <fredrik.m.olsson@axis.com>
> Sent: Friday, December 19, 2025 9:11 PM
> To: Alexandre Belloni <alexandre.belloni@bootlin.com>; Rob Herring
> <robh@kernel.org>; Krzysztof Kozlowski <krzk+dt@kernel.org>; Conor Dooley
> <conor+dt@kernel.org>; iwamatsu nobuhiro(岩松 信洋 □DITC○CPT)
> <nobuhiro.iwamatsu.x90@mail.toshiba>
> Cc: linux-rtc@vger.kernel.org; devicetree@vger.kernel.org;
> linux-kernel@vger.kernel.org; Fredrik M Olsson <fredrik.m.olsson@axis.com>;
> kernel@axis.com
> Subject: [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901
>
> Add compatible string epson,rx8901 for the Epson RX8901CE RTC.
>
> Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
Reviewed-by: Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@mail.toshiba>
Best regards,
Nobuhiro
> ---
> Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml
> b/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml
> index 98d10e680144..9b2796804f07 100644
> --- a/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml
> +++ b/Documentation/devicetree/bindings/rtc/rtc-ds1307.yaml
> @@ -31,6 +31,7 @@ properties:
> - epson,rx8025
> - isil,isl12057
> - epson,rx8130
> + - epson,rx8901
>
> - items:
> - enum:
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE
2025-12-19 12:10 ` [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE Fredrik M Olsson
@ 2025-12-24 5:05 ` nobuhiro.iwamatsu.x90
2026-01-31 0:03 ` Alexandre Belloni
1 sibling, 0 replies; 14+ messages in thread
From: nobuhiro.iwamatsu.x90 @ 2025-12-24 5:05 UTC (permalink / raw)
To: fredrik.m.olsson, alexandre.belloni, robh, krzk+dt, conor+dt
Cc: linux-rtc, devicetree, linux-kernel, kernel
Hi Fredrik,
> -----Original Message-----
> From: Fredrik M Olsson <fredrik.m.olsson@axis.com>
> Sent: Friday, December 19, 2025 9:11 PM
> To: Alexandre Belloni <alexandre.belloni@bootlin.com>; Rob Herring
> <robh@kernel.org>; Krzysztof Kozlowski <krzk+dt@kernel.org>; Conor Dooley
> <conor+dt@kernel.org>; iwamatsu nobuhiro(岩松 信洋 □DITC○CPT)
> <nobuhiro.iwamatsu.x90@mail.toshiba>
> Cc: linux-rtc@vger.kernel.org; devicetree@vger.kernel.org;
> linux-kernel@vger.kernel.org; Fredrik M Olsson <fredrik.m.olsson@axis.com>;
> kernel@axis.com
> Subject: [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE
>
> Adds Support for:
> - Reading and writing time to/from the RTC.
> - Switching to backup battery supply when primary supply disappears.
> - Optionally enabling battery charging.
>
> Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
Reviewed-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.x90@mail.toshiba>
Best regards,
Nobuhiro
> ---
> drivers/rtc/rtc-ds1307.c | 62
> ++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 60 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index
> bf42c250ea7d..99d95e520108 100644
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -48,6 +48,7 @@ enum ds_type {
> mcp794xx,
> rx_8025,
> rx_8130,
> + rx_8901,
> last_ds_type /* always last */
> /* rs5c372 too? different address... */ }; @@ -129,6 +130,12 @@
> enum ds_type {
> #define RX8130_REG_CONTROL1_INIEN BIT(4)
> #define RX8130_REG_CONTROL1_CHGEN BIT(5)
>
> +#define RX8901_REG_INTF 0x0e
> +#define RX8901_REG_INTF_VLF BIT(1)
> +#define RX8901_REG_PWSW_CFG 0x37
> +#define RX8901_REG_PWSW_CFG_INIEN BIT(6)
> +#define RX8901_REG_PWSW_CFG_CHGEN BIT(7)
> +
> #define MCP794XX_REG_CONTROL 0x07
> # define MCP794XX_BIT_ALM0_EN 0x10
> # define MCP794XX_BIT_ALM1_EN 0x20
> @@ -226,6 +233,19 @@ static int ds1307_get_time(struct device *dev, struct
> rtc_time *t)
> dev_warn_once(dev, "oscillator failed, set time!\n");
> return -EINVAL;
> }
> + } else if (ds1307->type == rx_8901) {
> + unsigned int regflag;
> +
> + ret = regmap_read(ds1307->regmap, RX8901_REG_INTF,
> ®flag);
> + if (ret) {
> + dev_err(dev, "%s error %d\n", "read", ret);
> + return ret;
> + }
> +
> + if (regflag & RX8901_REG_INTF_VLF) {
> + dev_warn_once(dev, "oscillator failed, set time!\n");
> + return -EINVAL;
> + }
> }
>
> /* read the RTC date and time registers all at once */ @@ -307,7
> +327,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
> tmp = regs[DS1307_REG_HOUR] & 0x3f;
> t->tm_hour = bcd2bin(tmp);
> /* rx8130 is bit position, not BCD */
> - if (ds1307->type == rx_8130)
> + if (ds1307->type == rx_8130 || ds1307->type == rx_8901)
> t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f) - 1;
> else
> t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
> @@ -358,7 +378,7 @@ static int ds1307_set_time(struct device *dev, struct
> rtc_time *t)
> regs[DS1307_REG_MIN] = bin2bcd(t->tm_min);
> regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
> /* rx8130 is bit position, not BCD */
> - if (ds1307->type == rx_8130)
> + if (ds1307->type == rx_8130 || ds1307->type == rx_8901)
> regs[DS1307_REG_WDAY] = 1 << t->tm_wday;
> else
> regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1); @@
> -422,6 +442,17 @@ static int ds1307_set_time(struct device *dev, struct
> rtc_time *t)
> dev_err(dev, "%s error %d\n", "write", result);
> return result;
> }
> + } else if (ds1307->type == rx_8901) {
> + /*
> + * clear Voltage Loss Flag as data is available now (writing 1
> + * to the other bits in the INTF register has no effect)
> + */
> + result = regmap_write(ds1307->regmap, RX8901_REG_INTF,
> + 0xff ^ RX8901_REG_INTF_VLF);
> + if (result) {
> + dev_err(dev, "%s error %d\n", "write", result);
> + return result;
> + }
> }
>
> return 0;
> @@ -568,6 +599,17 @@ static u8 do_trickle_setup_rx8130(struct ds1307
> *ds1307, u32 ohms, bool diode)
> return setup;
> }
>
> +static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms, bool
> +diode) {
> + /* make sure that the backup battery is enabled */
> + u8 setup = RX8901_REG_PWSW_CFG_INIEN;
> +
> + if (diode)
> + setup |= RX8901_REG_PWSW_CFG_CHGEN;
> +
> + return setup;
> +}
> +
> static irqreturn_t rx8130_irq(int irq, void *dev_id) {
> struct ds1307 *ds1307 = dev_id;
> @@ -960,6 +1002,11 @@ static const struct rtc_class_ops rx8130_rtc_ops = {
> .alarm_irq_enable = rx8130_alarm_irq_enable, };
>
> +static const struct rtc_class_ops rx8901_rtc_ops = {
> + .read_time = ds1307_get_time,
> + .set_time = ds1307_set_time,
> +};
> +
> static const struct rtc_class_ops mcp794xx_rtc_ops = {
> .read_time = ds1307_get_time,
> .set_time = ds1307_set_time,
> @@ -1040,6 +1087,12 @@ static const struct chip_desc chips[last_ds_type] = {
> .trickle_charger_reg = RX8130_REG_CONTROL1,
> .do_trickle_setup = &do_trickle_setup_rx8130,
> },
> + [rx_8901] = {
> + .offset = 0x0,
> + .rtc_ops = &rx8901_rtc_ops,
> + .trickle_charger_reg = RX8901_REG_PWSW_CFG,
> + .do_trickle_setup = &do_trickle_setup_rx8901,
> + },
> [m41t0] = {
> .rtc_ops = &m41txx_rtc_ops,
> },
> @@ -1081,6 +1134,7 @@ static const struct i2c_device_id ds1307_id[] = {
> { "rx8025", rx_8025 },
> { "isl12057", ds_1337 },
> { "rx8130", rx_8130 },
> + { "rx8901", rx_8901 },
> { }
> };
> MODULE_DEVICE_TABLE(i2c, ds1307_id);
> @@ -1158,6 +1212,10 @@ static const struct of_device_id ds1307_of_match[]
> = {
> .compatible = "epson,rx8130",
> .data = (void *)rx_8130
> },
> + {
> + .compatible = "epson,rx8901",
> + .data = (void *)rx_8901
> + },
> { }
> };
> MODULE_DEVICE_TABLE(of, ds1307_of_match);
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130
2025-12-19 12:10 ` [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130 Fredrik M Olsson
@ 2025-12-24 5:06 ` nobuhiro.iwamatsu.x90
0 siblings, 0 replies; 14+ messages in thread
From: nobuhiro.iwamatsu.x90 @ 2025-12-24 5:06 UTC (permalink / raw)
To: fredrik.m.olsson, alexandre.belloni, robh, krzk+dt, conor+dt
Cc: linux-rtc, devicetree, linux-kernel, kernel
Hi Fredrik,
> -----Original Message-----
> From: Fredrik M Olsson <fredrik.m.olsson@axis.com>
> Sent: Friday, December 19, 2025 9:11 PM
> To: Alexandre Belloni <alexandre.belloni@bootlin.com>; Rob Herring
> <robh@kernel.org>; Krzysztof Kozlowski <krzk+dt@kernel.org>; Conor Dooley
> <conor+dt@kernel.org>; iwamatsu nobuhiro(岩松 信洋 □DITC○CPT)
> <nobuhiro.iwamatsu.x90@mail.toshiba>
> Cc: linux-rtc@vger.kernel.org; devicetree@vger.kernel.org;
> linux-kernel@vger.kernel.org; Fredrik M Olsson <fredrik.m.olsson@axis.com>;
> kernel@axis.com
> Subject: [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130
>
> The RTC represent each weekday with a individual bit set in the WDAY register,
> where the 0th bit represent the first day of the week and the 6th bit represents
> the last day of the week. For each passed day the chip performs a
> rotary-left-shift by one to advance the weekday by one.
>
> The tm_wday field represent weekdays by a value in the range of 0-6.
>
> The fls() function return the bit index of the last bit set. To handle when there
> are no bits set it will return 0, and if the 0th bit is set it will return 1, and if the
> 1st bit is set it will return 2, and so on.
>
> In order to make the result of the fls() function fall into the expected range of
> 0-6 (instead of 1-7) this patch subtracts one from the result (which matches
> how the value is written in ds1307_set_time()).
>
> Fixes: 204756f016726 ("rtc: ds1307: Fix wday settings for rx8130")
> Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
Thanks for fixing.
Reviewed-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.x90@mail.toshiba>
Best regards,
Nobuhiro
> ---
> drivers/rtc/rtc-ds1307.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index
> 7205c59ff729..bf42c250ea7d 100644
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -308,7 +308,7 @@ static int ds1307_get_time(struct device *dev, struct
> rtc_time *t)
> t->tm_hour = bcd2bin(tmp);
> /* rx8130 is bit position, not BCD */
> if (ds1307->type == rx_8130)
> - t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f);
> + t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f) - 1;
> else
> t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
> t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f);
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status
2025-12-19 12:10 ` [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status Fredrik M Olsson
@ 2025-12-24 5:07 ` nobuhiro.iwamatsu.x90
2026-01-31 0:05 ` Alexandre Belloni
1 sibling, 0 replies; 14+ messages in thread
From: nobuhiro.iwamatsu.x90 @ 2025-12-24 5:07 UTC (permalink / raw)
To: fredrik.m.olsson, alexandre.belloni, robh, krzk+dt, conor+dt
Cc: linux-rtc, devicetree, linux-kernel, kernel
Hi Fredrik,
> -----Original Message-----
> From: Fredrik M Olsson <fredrik.m.olsson@axis.com>
> Sent: Friday, December 19, 2025 9:11 PM
> To: Alexandre Belloni <alexandre.belloni@bootlin.com>; Rob Herring
> <robh@kernel.org>; Krzysztof Kozlowski <krzk+dt@kernel.org>; Conor Dooley
> <conor+dt@kernel.org>; iwamatsu nobuhiro(岩松 信洋 □DITC○CPT)
> <nobuhiro.iwamatsu.x90@mail.toshiba>
> Cc: linux-rtc@vger.kernel.org; devicetree@vger.kernel.org;
> linux-kernel@vger.kernel.org; Fredrik M Olsson <fredrik.m.olsson@axis.com>;
> kernel@axis.com
> Subject: [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery
> VL status
>
> Adds support for:
> - Reading the battery voltage low status using the RTC_VL_READ ioctl,
> which also reports invalid time information if the VLF flag is set.
>
> Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
Reviewed-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.x90@mail.toshiba>
Best regards,
Nobuhiro
> ---
> drivers/rtc/rtc-ds1307.c | 46
> +++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index
> 99d95e520108..ca062ed0c867 100644
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -133,8 +133,11 @@ enum ds_type {
> #define RX8901_REG_INTF 0x0e
> #define RX8901_REG_INTF_VLF BIT(1)
> #define RX8901_REG_PWSW_CFG 0x37
> +#define RX8901_REG_PWSW_CFG_VBATLDETEN BIT(4)
> #define RX8901_REG_PWSW_CFG_INIEN BIT(6)
> #define RX8901_REG_PWSW_CFG_CHGEN BIT(7)
> +#define RX8901_REG_BUF_INTF 0x46
> +#define RX8901_REG_BUF_INTF_VBATLF BIT(3)
>
> #define MCP794XX_REG_CONTROL 0x07
> # define MCP794XX_BIT_ALM0_EN 0x10
> @@ -458,6 +461,39 @@ static int ds1307_set_time(struct device *dev, struct
> rtc_time *t)
> return 0;
> }
>
> +#ifdef CONFIG_RTC_INTF_DEV
> +static int rx8901_ioctl(struct device *dev, unsigned int cmd, unsigned
> +long arg) {
> + struct ds1307 *ds1307 = dev_get_drvdata(dev);
> + unsigned int regflag, tmp = 0;
> + int ret = 0;
> +
> + switch (cmd) {
> + case RTC_VL_READ:
> + ret = regmap_read(ds1307->regmap, RX8901_REG_INTF,
> ®flag);
> + if (ret)
> + return ret;
> +
> + if (regflag & RX8901_REG_INTF_VLF)
> + tmp |= RTC_VL_DATA_INVALID;
> +
> + ret = regmap_read(ds1307->regmap, RX8901_REG_BUF_INTF,
> ®flag);
> + if (ret)
> + return ret;
> +
> + if (regflag & RX8901_REG_BUF_INTF_VBATLF)
> + tmp |= RTC_VL_BACKUP_LOW;
> +
> + return put_user(tmp, (unsigned int __user *)arg);
> + default:
> + return -ENOIOCTLCMD;
> + }
> + return ret;
> +}
> +#else
> +#define rx8901_ioctl NULL
> +#endif
> +
> static int ds1337_read_alarm(struct device *dev, struct rtc_wkalrm *t) {
> struct ds1307 *ds1307 = dev_get_drvdata(dev);
> @@ -599,10 +635,13 @@ static u8 do_trickle_setup_rx8130(struct ds1307
> *ds1307, u32 ohms, bool diode)
> return setup;
> }
>
> -static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms, bool
> diode)
> +static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms
> +__always_unused, bool diode)
> {
> - /* make sure that the backup battery is enabled */
> - u8 setup = RX8901_REG_PWSW_CFG_INIEN;
> + /*
> + * make sure that the backup battery is enabled and that battery
> + * voltage detection is performed
> + */
> + u8 setup = RX8901_REG_PWSW_CFG_INIEN |
> RX8901_REG_PWSW_CFG_VBATLDETEN;
>
> if (diode)
> setup |= RX8901_REG_PWSW_CFG_CHGEN;
> @@ -1005,6 +1044,7 @@ static const struct rtc_class_ops rx8130_rtc_ops =
> { static const struct rtc_class_ops rx8901_rtc_ops = {
> .read_time = ds1307_get_time,
> .set_time = ds1307_set_time,
> + .ioctl = rx8901_ioctl,
> };
>
> static const struct rtc_class_ops mcp794xx_rtc_ops = {
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE
2025-12-19 12:10 ` [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE Fredrik M Olsson
2025-12-24 5:05 ` nobuhiro.iwamatsu.x90
@ 2026-01-31 0:03 ` Alexandre Belloni
2026-02-03 14:23 ` Fredrik M Olsson
1 sibling, 1 reply; 14+ messages in thread
From: Alexandre Belloni @ 2026-01-31 0:03 UTC (permalink / raw)
To: Fredrik M Olsson
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nobuhiro Iwamatsu,
linux-rtc, devicetree, linux-kernel, kernel
Hello,
On 19/12/2025 13:10:37+0100, Fredrik M Olsson wrote:
> #define MCP794XX_REG_CONTROL 0x07
> # define MCP794XX_BIT_ALM0_EN 0x10
> # define MCP794XX_BIT_ALM1_EN 0x20
> @@ -226,6 +233,19 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
> dev_warn_once(dev, "oscillator failed, set time!\n");
> return -EINVAL;
> }
> + } else if (ds1307->type == rx_8901) {
> + unsigned int regflag;
> +
> + ret = regmap_read(ds1307->regmap, RX8901_REG_INTF, ®flag);
> + if (ret) {
> + dev_err(dev, "%s error %d\n", "read", ret);
The multiple dev_err you are adding should be dev_dbg as there is no
other actions for the user than to restart the operation when it fails
so there is not actual value apart when debugging.
> + return ret;
> + }
> +
> + if (regflag & RX8901_REG_INTF_VLF) {
> + dev_warn_once(dev, "oscillator failed, set time!\n");
> + return -EINVAL;
> + }
> }
>
> /* read the RTC date and time registers all at once */
> @@ -307,7 +327,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
> tmp = regs[DS1307_REG_HOUR] & 0x3f;
> t->tm_hour = bcd2bin(tmp);
> /* rx8130 is bit position, not BCD */
> - if (ds1307->type == rx_8130)
> + if (ds1307->type == rx_8130 || ds1307->type == rx_8901)
> t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f) - 1;
> else
> t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
> @@ -358,7 +378,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
> regs[DS1307_REG_MIN] = bin2bcd(t->tm_min);
> regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
> /* rx8130 is bit position, not BCD */
> - if (ds1307->type == rx_8130)
> + if (ds1307->type == rx_8130 || ds1307->type == rx_8901)
> regs[DS1307_REG_WDAY] = 1 << t->tm_wday;
> else
> regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
> @@ -422,6 +442,17 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
> dev_err(dev, "%s error %d\n", "write", result);
> return result;
> }
> + } else if (ds1307->type == rx_8901) {
> + /*
> + * clear Voltage Loss Flag as data is available now (writing 1
> + * to the other bits in the INTF register has no effect)
> + */
> + result = regmap_write(ds1307->regmap, RX8901_REG_INTF,
> + 0xff ^ RX8901_REG_INTF_VLF);
> + if (result) {
> + dev_err(dev, "%s error %d\n", "write", result);
> + return result;
> + }
> }
>
> return 0;
> @@ -568,6 +599,17 @@ static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode)
> return setup;
> }
>
> +static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms, bool diode)
> +{
> + /* make sure that the backup battery is enabled */
> + u8 setup = RX8901_REG_PWSW_CFG_INIEN;
You can't do this as this will cause issues in the future for people
wanting to keep this bit disabled (the main reason being that you don't
want to draw power from the battery while your device sits on a shelf).
You have to handle the RTC_PARAM_BACKUP_SWITCH_MODE parameter and then
switch it from userspace.
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status
2025-12-19 12:10 ` [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status Fredrik M Olsson
2025-12-24 5:07 ` nobuhiro.iwamatsu.x90
@ 2026-01-31 0:05 ` Alexandre Belloni
2026-02-03 14:26 ` Fredrik M Olsson
1 sibling, 1 reply; 14+ messages in thread
From: Alexandre Belloni @ 2026-01-31 0:05 UTC (permalink / raw)
To: Fredrik M Olsson
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nobuhiro Iwamatsu,
linux-rtc, devicetree, linux-kernel, kernel
On 19/12/2025 13:10:38+0100, Fredrik M Olsson wrote:
> Adds support for:
> - Reading the battery voltage low status using the RTC_VL_READ ioctl,
> which also reports invalid time information if the VLF flag is set.
>
> Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
> ---
> drivers/rtc/rtc-ds1307.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
> index 99d95e520108..ca062ed0c867 100644
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -133,8 +133,11 @@ enum ds_type {
> #define RX8901_REG_INTF 0x0e
> #define RX8901_REG_INTF_VLF BIT(1)
> #define RX8901_REG_PWSW_CFG 0x37
> +#define RX8901_REG_PWSW_CFG_VBATLDETEN BIT(4)
> #define RX8901_REG_PWSW_CFG_INIEN BIT(6)
> #define RX8901_REG_PWSW_CFG_CHGEN BIT(7)
> +#define RX8901_REG_BUF_INTF 0x46
> +#define RX8901_REG_BUF_INTF_VBATLF BIT(3)
>
> #define MCP794XX_REG_CONTROL 0x07
> # define MCP794XX_BIT_ALM0_EN 0x10
> @@ -458,6 +461,39 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
> return 0;
> }
>
> +#ifdef CONFIG_RTC_INTF_DEV
> +static int rx8901_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
> +{
> + struct ds1307 *ds1307 = dev_get_drvdata(dev);
> + unsigned int regflag, tmp = 0;
> + int ret = 0;
> +
> + switch (cmd) {
> + case RTC_VL_READ:
> + ret = regmap_read(ds1307->regmap, RX8901_REG_INTF, ®flag);
> + if (ret)
> + return ret;
> +
> + if (regflag & RX8901_REG_INTF_VLF)
> + tmp |= RTC_VL_DATA_INVALID;
> +
> + ret = regmap_read(ds1307->regmap, RX8901_REG_BUF_INTF, ®flag);
> + if (ret)
> + return ret;
> +
> + if (regflag & RX8901_REG_BUF_INTF_VBATLF)
> + tmp |= RTC_VL_BACKUP_LOW;
> +
> + return put_user(tmp, (unsigned int __user *)arg);
> + default:
> + return -ENOIOCTLCMD;
> + }
> + return ret;
> +}
> +#else
> +#define rx8901_ioctl NULL
> +#endif
> +
> static int ds1337_read_alarm(struct device *dev, struct rtc_wkalrm *t)
> {
> struct ds1307 *ds1307 = dev_get_drvdata(dev);
> @@ -599,10 +635,13 @@ static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode)
> return setup;
> }
>
> -static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms, bool diode)
> +static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms __always_unused, bool diode)
> {
> - /* make sure that the backup battery is enabled */
> - u8 setup = RX8901_REG_PWSW_CFG_INIEN;
> + /*
> + * make sure that the backup battery is enabled and that battery
> + * voltage detection is performed
> + */
> + u8 setup = RX8901_REG_PWSW_CFG_INIEN | RX8901_REG_PWSW_CFG_VBATLDETEN;
>
> if (diode)
> setup |= RX8901_REG_PWSW_CFG_CHGEN;
> @@ -1005,6 +1044,7 @@ static const struct rtc_class_ops rx8130_rtc_ops = {
> static const struct rtc_class_ops rx8901_rtc_ops = {
> .read_time = ds1307_get_time,
> .set_time = ds1307_set_time,
> + .ioctl = rx8901_ioctl,
> };
>
This seems to be an unrelated changed that hasn't been squashed in the
proper patch.
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE
2026-01-31 0:03 ` Alexandre Belloni
@ 2026-02-03 14:23 ` Fredrik M Olsson
0 siblings, 0 replies; 14+ messages in thread
From: Fredrik M Olsson @ 2026-02-03 14:23 UTC (permalink / raw)
To: Alexandre Belloni, Fredrik M Olsson
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nobuhiro Iwamatsu,
linux-rtc, devicetree, linux-kernel, kernel
On 1/31/26 01:03, Alexandre Belloni wrote:
> [Some people who received this message don't often get email from alexandre.belloni@bootlin.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Hello,
>
> On 19/12/2025 13:10:37+0100, Fredrik M Olsson wrote:
>> #define MCP794XX_REG_CONTROL 0x07
>> # define MCP794XX_BIT_ALM0_EN 0x10
>> # define MCP794XX_BIT_ALM1_EN 0x20
>> @@ -226,6 +233,19 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
>> dev_warn_once(dev, "oscillator failed, set time!\n");
>> return -EINVAL;
>> }
>> + } else if (ds1307->type == rx_8901) {
>> + unsigned int regflag;
>> +
>> + ret = regmap_read(ds1307->regmap, RX8901_REG_INTF, ®flag);
>> + if (ret) {
>> + dev_err(dev, "%s error %d\n", "read", ret);
>
> The multiple dev_err you are adding should be dev_dbg as there is no
> other actions for the user than to restart the operation when it fails
> so there is not actual value apart when debugging.
>
Okay thanks I will update that for v2.
>> + return ret;
>> + }
>> +
>> + if (regflag & RX8901_REG_INTF_VLF) {
>> + dev_warn_once(dev, "oscillator failed, set time!\n");
>> + return -EINVAL;
>> + }
>> }
>>
>> /* read the RTC date and time registers all at once */
>> @@ -307,7 +327,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
>> tmp = regs[DS1307_REG_HOUR] & 0x3f;
>> t->tm_hour = bcd2bin(tmp);
>> /* rx8130 is bit position, not BCD */
>> - if (ds1307->type == rx_8130)
>> + if (ds1307->type == rx_8130 || ds1307->type == rx_8901)
>> t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f) - 1;
>> else
>> t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
>> @@ -358,7 +378,7 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
>> regs[DS1307_REG_MIN] = bin2bcd(t->tm_min);
>> regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
>> /* rx8130 is bit position, not BCD */
>> - if (ds1307->type == rx_8130)
>> + if (ds1307->type == rx_8130 || ds1307->type == rx_8901)
>> regs[DS1307_REG_WDAY] = 1 << t->tm_wday;
>> else
>> regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
>> @@ -422,6 +442,17 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
>> dev_err(dev, "%s error %d\n", "write", result);
>> return result;
>> }
>> + } else if (ds1307->type == rx_8901) {
>> + /*
>> + * clear Voltage Loss Flag as data is available now (writing 1
>> + * to the other bits in the INTF register has no effect)
>> + */
>> + result = regmap_write(ds1307->regmap, RX8901_REG_INTF,
>> + 0xff ^ RX8901_REG_INTF_VLF);
>> + if (result) {
>> + dev_err(dev, "%s error %d\n", "write", result);
>> + return result;
>> + }
>> }
>>
>> return 0;
>> @@ -568,6 +599,17 @@ static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode)
>> return setup;
>> }
>>
>> +static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms, bool diode)
>> +{
>> + /* make sure that the backup battery is enabled */
>> + u8 setup = RX8901_REG_PWSW_CFG_INIEN;
>
> You can't do this as this will cause issues in the future for people
> wanting to keep this bit disabled (the main reason being that you don't
> want to draw power from the battery while your device sits on a shelf).
> You have to handle the RTC_PARAM_BACKUP_SWITCH_MODE parameter and then
> switch it from userspace.
Here my intention was to do something similar to what was done before
for the rx8130 device [1], which as I understand it require similar
setup initialization as the rx8901 device does. Is using the
RTC_PARAM_BACKUP_SWITCH_MODE the new way of performing this initialization?
>
>
> --
> Alexandre Belloni, co-owner and COO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
[1] 0026f1604c9b (rtc: ds1307: enable rx8130's backup battery, make it
chargeable optionally)
--
/Fredrik
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status
2026-01-31 0:05 ` Alexandre Belloni
@ 2026-02-03 14:26 ` Fredrik M Olsson
0 siblings, 0 replies; 14+ messages in thread
From: Fredrik M Olsson @ 2026-02-03 14:26 UTC (permalink / raw)
To: Alexandre Belloni, Fredrik M Olsson
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nobuhiro Iwamatsu,
linux-rtc, devicetree, linux-kernel, kernel
On 1/31/26 01:05, Alexandre Belloni wrote:
> [Some people who received this message don't often get email from alexandre.belloni@bootlin.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On 19/12/2025 13:10:38+0100, Fredrik M Olsson wrote:
>> Adds support for:
>> - Reading the battery voltage low status using the RTC_VL_READ ioctl,
>> which also reports invalid time information if the VLF flag is set.
>>
>> Signed-off-by: Fredrik M Olsson <fredrik.m.olsson@axis.com>
>> ---
>> drivers/rtc/rtc-ds1307.c | 46 +++++++++++++++++++++++++++++++++++++++++++---
>> 1 file changed, 43 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
>> index 99d95e520108..ca062ed0c867 100644
>> --- a/drivers/rtc/rtc-ds1307.c
>> +++ b/drivers/rtc/rtc-ds1307.c
>> @@ -133,8 +133,11 @@ enum ds_type {
>> #define RX8901_REG_INTF 0x0e
>> #define RX8901_REG_INTF_VLF BIT(1)
>> #define RX8901_REG_PWSW_CFG 0x37
>> +#define RX8901_REG_PWSW_CFG_VBATLDETEN BIT(4)
>> #define RX8901_REG_PWSW_CFG_INIEN BIT(6)
>> #define RX8901_REG_PWSW_CFG_CHGEN BIT(7)
>> +#define RX8901_REG_BUF_INTF 0x46
>> +#define RX8901_REG_BUF_INTF_VBATLF BIT(3)
>>
>> #define MCP794XX_REG_CONTROL 0x07
>> # define MCP794XX_BIT_ALM0_EN 0x10
>> @@ -458,6 +461,39 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
>> return 0;
>> }
>>
>> +#ifdef CONFIG_RTC_INTF_DEV
>> +static int rx8901_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
>> +{
>> + struct ds1307 *ds1307 = dev_get_drvdata(dev);
>> + unsigned int regflag, tmp = 0;
>> + int ret = 0;
>> +
>> + switch (cmd) {
>> + case RTC_VL_READ:
>> + ret = regmap_read(ds1307->regmap, RX8901_REG_INTF, ®flag);
>> + if (ret)
>> + return ret;
>> +
>> + if (regflag & RX8901_REG_INTF_VLF)
>> + tmp |= RTC_VL_DATA_INVALID;
>> +
>> + ret = regmap_read(ds1307->regmap, RX8901_REG_BUF_INTF, ®flag);
>> + if (ret)
>> + return ret;
>> +
>> + if (regflag & RX8901_REG_BUF_INTF_VBATLF)
>> + tmp |= RTC_VL_BACKUP_LOW;
>> +
>> + return put_user(tmp, (unsigned int __user *)arg);
>> + default:
>> + return -ENOIOCTLCMD;
>> + }
>> + return ret;
>> +}
>> +#else
>> +#define rx8901_ioctl NULL
>> +#endif
>> +
>> static int ds1337_read_alarm(struct device *dev, struct rtc_wkalrm *t)
>> {
>> struct ds1307 *ds1307 = dev_get_drvdata(dev);
>> @@ -599,10 +635,13 @@ static u8 do_trickle_setup_rx8130(struct ds1307 *ds1307, u32 ohms, bool diode)
>> return setup;
>> }
>>
>> -static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms, bool diode)
>> +static u8 do_trickle_setup_rx8901(struct ds1307 *ds1307, u32 ohms __always_unused, bool diode)
>> {
>> - /* make sure that the backup battery is enabled */
>> - u8 setup = RX8901_REG_PWSW_CFG_INIEN;
>> + /*
>> + * make sure that the backup battery is enabled and that battery
>> + * voltage detection is performed
>> + */
>> + u8 setup = RX8901_REG_PWSW_CFG_INIEN | RX8901_REG_PWSW_CFG_VBATLDETEN;
>>
>> if (diode)
>> setup |= RX8901_REG_PWSW_CFG_CHGEN;
>> @@ -1005,6 +1044,7 @@ static const struct rtc_class_ops rx8130_rtc_ops = {
>> static const struct rtc_class_ops rx8901_rtc_ops = {
>> .read_time = ds1307_get_time,
>> .set_time = ds1307_set_time,
>> + .ioctl = rx8901_ioctl,
>> };
>>
>
> This seems to be an unrelated changed that hasn't been squashed in the
> proper patch.
>
Okay I will squash this change into patch 3 for v2.
>
> --
> Alexandre Belloni, co-owner and COO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
--
/Fredrik
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-02-03 14:26 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-19 12:10 [PATCH 0/4] rtc: ds1307: Add support for Epson RX8901CE Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 1/4] dt-bindings: rtc: ds1307: Add epson,rx8901 Fredrik M Olsson
2025-12-20 8:59 ` Krzysztof Kozlowski
2025-12-24 5:04 ` nobuhiro.iwamatsu.x90
2025-12-19 12:10 ` [PATCH 2/4] rtc: ds1307: Fix off-by-one issue with wday for rx8130 Fredrik M Olsson
2025-12-24 5:06 ` nobuhiro.iwamatsu.x90
2025-12-19 12:10 ` [PATCH 3/4] rtc: ds1307: Add Driver for Epson RX8901CE Fredrik M Olsson
2025-12-24 5:05 ` nobuhiro.iwamatsu.x90
2026-01-31 0:03 ` Alexandre Belloni
2026-02-03 14:23 ` Fredrik M Olsson
2025-12-19 12:10 ` [PATCH 4/4] rtc: ds1307: Add support for reading RX8901CE battery VL status Fredrik M Olsson
2025-12-24 5:07 ` nobuhiro.iwamatsu.x90
2026-01-31 0:05 ` Alexandre Belloni
2026-02-03 14:26 ` Fredrik M Olsson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox