-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
2 changed files
with
13 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Copyright (c) 2019-2020 Peter Bigot Consulting, LLC | ||
* Copyright (c) 2021 Laird Connectivity | ||
* Copyright (c) 2025 Marcin Lyda <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
@@ -50,6 +51,7 @@ struct mcp7940n_config { | |
struct counter_config_info generic; | ||
struct i2c_dt_spec i2c; | ||
const struct gpio_dt_spec int_gpios; | ||
bool vbat_enable; | ||
}; | ||
|
||
struct mcp7940n_data { | ||
|
@@ -678,6 +680,10 @@ static int mcp7940n_init(const struct device *dev) | |
goto out; | ||
} | ||
|
||
/* Configure VBat enable */ | ||
data->registers.rtc_weekday.vbaten = cfg->vbat_enable; | ||
|
||
/* Set day of week and update VBat enable config */ | ||
rc = set_day_of_week(dev, &unix_time); | ||
if (rc < 0) { | ||
goto out; | ||
|
@@ -693,7 +699,6 @@ static int mcp7940n_init(const struct device *dev) | |
|
||
/* Configure alarm interrupt gpio */ | ||
if (cfg->int_gpios.port != NULL) { | ||
|
||
if (!gpio_is_ready_dt(&cfg->int_gpios)) { | ||
LOG_ERR("Port device %s is not ready", | ||
cfg->int_gpios.port->name); | ||
|
@@ -757,6 +762,7 @@ static DEVICE_API(counter, mcp7940n_api) = { | |
}, \ | ||
.i2c = I2C_DT_SPEC_INST_GET(index), \ | ||
.int_gpios = GPIO_DT_SPEC_INST_GET_OR(index, int_gpios, {0}), \ | ||
.vbat_enable = DT_INST_PROP_OR(index, vbat_enable, false) \ | ||
}; \ | ||
\ | ||
DEVICE_DT_INST_DEFINE(index, mcp7940n_init, NULL, \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# | ||
# Copyright (c) 2021 Laird Connectivity | ||
# Copyright (c) 2023 Nordic Semiconductor ASA | ||
# Copyright (c) 2025 Marcin Lyda <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
@@ -21,3 +22,8 @@ properties: | |
Host input connected to the MCP7940N MFP open drain output pin | ||
Notifies when an alarm has triggered by asserting this line. | ||
vbat-enable: | ||
type: boolean | ||
description: | | ||
Enables external battery backup functionality |