Skip to content

Commit 420167a

Browse files
committed
drivers: counter: cc23x0: Add power management to RTC
Add PM support for RTC to cc23x0 SoC. Signed-off-by: Stoyan Bogdanov <sbogdanov@baylibre.com>
1 parent fdd02c5 commit 420167a

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

drivers/counter/counter_cc23x0_rtc.c

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <zephyr/kernel.h>
1313
#include <zephyr/drivers/clock_control.h>
1414
#include <zephyr/logging/log.h>
15+
#include <zephyr/pm/device.h>
1516

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

157+
#ifdef CONFIG_PM_DEVICE
158+
159+
static int rtc_cc23x0_pm_action(const struct device *dev, enum pm_device_action action)
160+
{
161+
switch (action) {
162+
case PM_DEVICE_ACTION_SUSPEND:
163+
return 0;
164+
case PM_DEVICE_ACTION_RESUME:
165+
counter_cc23x0_get_pending_int(dev);
166+
return 0;
167+
default:
168+
return -ENOTSUP;
169+
}
170+
}
171+
172+
#endif /* CONFIG_PM_DEVICE */
173+
156174
static uint32_t counter_cc23x0_get_top_value(const struct device *dev)
157175
{
158176
ARG_UNUSED(dev);
@@ -221,21 +239,22 @@ static DEVICE_API(counter, rtc_cc23x0_api) = {
221239
.get_freq = counter_cc23x0_get_freq,
222240
};
223241

224-
#define CC23X0_INIT(inst) \
225-
static const struct counter_cc23x0_config cc23x0_config_##inst = { \
226-
.counter_info = \
227-
{ \
228-
.max_top_value = UINT32_MAX, \
229-
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
230-
.channels = 1, \
231-
}, \
232-
.base = DT_INST_REG_ADDR(inst), \
233-
}; \
234-
\
235-
static struct counter_cc23x0_data cc23x0_data_##inst; \
236-
\
237-
DEVICE_DT_INST_DEFINE(0, &counter_cc23x0_init, NULL, &cc23x0_data_##inst, \
238-
&cc23x0_config_##inst, POST_KERNEL, CONFIG_COUNTER_INIT_PRIORITY, \
239-
&rtc_cc23x0_api);
242+
#define CC23X0_INIT(inst) \
243+
PM_DEVICE_DT_INST_DEFINE(inst, rtc_cc23x0_pm_action); \
244+
\
245+
static const struct counter_cc23x0_config cc23x0_config_##inst = { \
246+
.counter_info = { \
247+
.max_top_value = UINT32_MAX, \
248+
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
249+
.channels = 1, \
250+
}, \
251+
.base = DT_INST_REG_ADDR(inst), \
252+
}; \
253+
\
254+
static struct counter_cc23x0_data cc23x0_data_##inst; \
255+
\
256+
DEVICE_DT_INST_DEFINE(0, &counter_cc23x0_init, PM_DEVICE_DT_INST_GET(inst), \
257+
&cc23x0_data_##inst, &cc23x0_config_##inst, POST_KERNEL, \
258+
CONFIG_COUNTER_INIT_PRIORITY, &rtc_cc23x0_api);
240259

241260
DT_INST_FOREACH_STATUS_OKAY(CC23X0_INIT)

0 commit comments

Comments
 (0)