Skip to content

Commit f7280fa

Browse files
Lefucjuszkartben
authored andcommitted
drivers: counter: Add MCP7940N property to enable VBAT backup
This PR adds a new devicetree property that allows enabling external battery backup functionality. Signed-off-by: Marcin Lyda <elektromarcin@gmail.com>
1 parent 76e1fc7 commit f7280fa

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

drivers/counter/rtc_mcp7940n.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2019-2020 Peter Bigot Consulting, LLC
33
* Copyright (c) 2021 Laird Connectivity
4+
* Copyright (c) 2025 Marcin Lyda <elektromarcin@gmail.com>
45
*
56
* SPDX-License-Identifier: Apache-2.0
67
*/
@@ -50,6 +51,7 @@ struct mcp7940n_config {
5051
struct counter_config_info generic;
5152
struct i2c_dt_spec i2c;
5253
const struct gpio_dt_spec int_gpios;
54+
bool vbat_enable;
5355
};
5456

5557
struct mcp7940n_data {
@@ -678,6 +680,10 @@ static int mcp7940n_init(const struct device *dev)
678680
goto out;
679681
}
680682

683+
/* Configure VBat enable */
684+
data->registers.rtc_weekday.vbaten = cfg->vbat_enable;
685+
686+
/* Set day of week and update VBat enable config */
681687
rc = set_day_of_week(dev, &unix_time);
682688
if (rc < 0) {
683689
goto out;
@@ -693,7 +699,6 @@ static int mcp7940n_init(const struct device *dev)
693699

694700
/* Configure alarm interrupt gpio */
695701
if (cfg->int_gpios.port != NULL) {
696-
697702
if (!gpio_is_ready_dt(&cfg->int_gpios)) {
698703
LOG_ERR("Port device %s is not ready",
699704
cfg->int_gpios.port->name);
@@ -757,6 +762,7 @@ static DEVICE_API(counter, mcp7940n_api) = {
757762
}, \
758763
.i2c = I2C_DT_SPEC_INST_GET(index), \
759764
.int_gpios = GPIO_DT_SPEC_INST_GET_OR(index, int_gpios, {0}), \
765+
.vbat_enable = DT_INST_PROP(index, vbat_enable) \
760766
}; \
761767
\
762768
DEVICE_DT_INST_DEFINE(index, mcp7940n_init, NULL, \

dts/bindings/rtc/microchip,mcp7940n.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
22
# Copyright (c) 2021 Laird Connectivity
33
# Copyright (c) 2023 Nordic Semiconductor ASA
4+
# Copyright (c) 2025 Marcin Lyda <elektromarcin@gmail.com>
45
#
56
# SPDX-License-Identifier: Apache-2.0
67
#
@@ -21,3 +22,8 @@ properties:
2122
Host input connected to the MCP7940N MFP open drain output pin
2223
2324
Notifies when an alarm has triggered by asserting this line.
25+
26+
vbat-enable:
27+
type: boolean
28+
description: |
29+
Enables external battery backup functionality

0 commit comments

Comments
 (0)