Skip to content

Add Power Management support to RTC counter driver for TI cc23x0 SoC #91611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions drivers/counter/counter_cc23x0_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zephyr/kernel.h>
#include <zephyr/drivers/clock_control.h>
#include <zephyr/logging/log.h>
#include <zephyr/pm/device.h>

#include <inc/hw_rtc.h>
#include <inc/hw_types.h>
Expand Down Expand Up @@ -153,6 +154,23 @@ static uint32_t counter_cc23x0_get_pending_int(const struct device *dev)
return -ESRCH;
}

#ifdef CONFIG_PM_DEVICE

static int rtc_cc23x0_pm_action(const struct device *dev, enum pm_device_action action)
{
switch (action) {
case PM_DEVICE_ACTION_SUSPEND:
return 0;
case PM_DEVICE_ACTION_RESUME:
counter_cc23x0_get_pending_int(dev);
return 0;
default:
return -ENOTSUP;
}
}

#endif /* CONFIG_PM_DEVICE */

static uint32_t counter_cc23x0_get_top_value(const struct device *dev)
{
ARG_UNUSED(dev);
Expand Down Expand Up @@ -221,21 +239,22 @@ static DEVICE_API(counter, rtc_cc23x0_api) = {
.get_freq = counter_cc23x0_get_freq,
};

#define CC23X0_INIT(inst) \
static const struct counter_cc23x0_config cc23x0_config_##inst = { \
.counter_info = \
{ \
.max_top_value = UINT32_MAX, \
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
.channels = 1, \
}, \
.base = DT_INST_REG_ADDR(inst), \
}; \
\
static struct counter_cc23x0_data cc23x0_data_##inst; \
\
DEVICE_DT_INST_DEFINE(0, &counter_cc23x0_init, NULL, &cc23x0_data_##inst, \
&cc23x0_config_##inst, POST_KERNEL, CONFIG_COUNTER_INIT_PRIORITY, \
&rtc_cc23x0_api);
#define CC23X0_INIT(inst) \
PM_DEVICE_DT_INST_DEFINE(inst, rtc_cc23x0_pm_action); \
\
static const struct counter_cc23x0_config cc23x0_config_##inst = { \
.counter_info = { \
.max_top_value = UINT32_MAX, \
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
.channels = 1, \
}, \
.base = DT_INST_REG_ADDR(inst), \
}; \
\
static struct counter_cc23x0_data cc23x0_data_##inst; \
\
DEVICE_DT_INST_DEFINE(0, &counter_cc23x0_init, PM_DEVICE_DT_INST_GET(inst), \
&cc23x0_data_##inst, &cc23x0_config_##inst, POST_KERNEL, \
CONFIG_COUNTER_INIT_PRIORITY, &rtc_cc23x0_api);

DT_INST_FOREACH_STATUS_OKAY(CC23X0_INIT)