Skip to content

Commit ee883a9

Browse files
seankyerkartben
authored andcommitted
drivers: counter: counter_max32_wut: Add backup support
Added backup power mode support to max32 wut. Signed-off-by: Sean Kyer <Sean.Kyer@analog.com>
1 parent ab43ceb commit ee883a9

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

drivers/counter/counter_max32_wut.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/drivers/counter.h>
1010
#include <zephyr/irq.h>
1111
#include <zephyr/logging/log.h>
12+
#include <zephyr/pm/device.h>
1213

1314
#include <wut.h>
1415
#include <wrap_max32_lp.h>
@@ -230,6 +231,31 @@ static int counter_max32_wut_init(const struct device *dev)
230231
return 0;
231232
}
232233

234+
#ifdef CONFIG_PM_DEVICE
235+
static int counter_max32_wut_pm_action(const struct device *dev, enum pm_device_action action)
236+
{
237+
int ret;
238+
239+
switch (action) {
240+
case PM_DEVICE_ACTION_RESUME:
241+
242+
ret = counter_max32_wut_init(dev);
243+
if (ret != 0) {
244+
return ret;
245+
}
246+
247+
break;
248+
249+
case PM_DEVICE_ACTION_SUSPEND:
250+
break;
251+
default:
252+
return -ENOTSUP;
253+
}
254+
255+
return 0;
256+
}
257+
#endif /* CONFIG_PM_DEVICE */
258+
233259
static const struct counter_driver_api counter_max32_wut_driver_api = {
234260
.start = counter_max32_wut_start,
235261
.stop = counter_max32_wut_stop,
@@ -271,8 +297,9 @@ static const struct counter_driver_api counter_max32_wut_driver_api = {
271297
.wakeup_source = DT_PROP(TIMER(_num), wakeup_source), \
272298
}; \
273299
static struct max32_wut_data max32_wut_data##_num; \
274-
DEVICE_DT_INST_DEFINE(_num, &counter_max32_wut_init, NULL, &max32_wut_data##_num, \
275-
&max32_wut_config_##_num, PRE_KERNEL_1, \
300+
PM_DEVICE_DT_INST_DEFINE(_num, counter_max32_wut_pm_action); \
301+
DEVICE_DT_INST_DEFINE(_num, &counter_max32_wut_init, PM_DEVICE_DT_INST_GET(_num), \
302+
&max32_wut_data##_num, &max32_wut_config_##_num, PRE_KERNEL_1, \
276303
CONFIG_COUNTER_INIT_PRIORITY, &counter_max32_wut_driver_api);
277304

278305
DT_INST_FOREACH_STATUS_OKAY(COUNTER_MAX32_WUT_DEFINE)

0 commit comments

Comments
 (0)