|
9 | 9 | #include <zephyr/drivers/counter.h>
|
10 | 10 | #include <zephyr/irq.h>
|
11 | 11 | #include <zephyr/logging/log.h>
|
| 12 | +#include <zephyr/pm/device.h> |
12 | 13 |
|
13 | 14 | #include <wut.h>
|
14 | 15 | #include <wrap_max32_lp.h>
|
@@ -230,6 +231,31 @@ static int counter_max32_wut_init(const struct device *dev)
|
230 | 231 | return 0;
|
231 | 232 | }
|
232 | 233 |
|
| 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 | + |
233 | 259 | static const struct counter_driver_api counter_max32_wut_driver_api = {
|
234 | 260 | .start = counter_max32_wut_start,
|
235 | 261 | .stop = counter_max32_wut_stop,
|
@@ -271,8 +297,9 @@ static const struct counter_driver_api counter_max32_wut_driver_api = {
|
271 | 297 | .wakeup_source = DT_PROP(TIMER(_num), wakeup_source), \
|
272 | 298 | }; \
|
273 | 299 | 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, \ |
276 | 303 | CONFIG_COUNTER_INIT_PRIORITY, &counter_max32_wut_driver_api);
|
277 | 304 |
|
278 | 305 | DT_INST_FOREACH_STATUS_OKAY(COUNTER_MAX32_WUT_DEFINE)
|
0 commit comments