|
11 | 11 | #include <zephyr/drivers/clock_control.h>
|
12 | 12 | #include <zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h>
|
13 | 13 | #include <zephyr/irq.h>
|
| 14 | +#include <zephyr/pm/device.h> |
14 | 15 |
|
15 | 16 | LOG_MODULE_REGISTER(mcux_ctimer, CONFIG_COUNTER_LOG_LEVEL);
|
16 | 17 |
|
@@ -248,7 +249,7 @@ static void mcux_lpc_ctimer_isr(const struct device *dev)
|
248 | 249 | #endif
|
249 | 250 | }
|
250 | 251 |
|
251 |
| -static int mcux_lpc_ctimer_init(const struct device *dev) |
| 252 | +static int mcux_lpc_ctimer_init_common(const struct device *dev) |
252 | 253 | {
|
253 | 254 | const struct mcux_lpc_ctimer_config *config = dev->config;
|
254 | 255 | struct mcux_lpc_ctimer_data *data = dev->data;
|
@@ -277,6 +278,32 @@ static int mcux_lpc_ctimer_init(const struct device *dev)
|
277 | 278 | return 0;
|
278 | 279 | }
|
279 | 280 |
|
| 281 | +static int mcux_lpc_ctimer_pm_action(const struct device *dev, enum pm_device_action action) |
| 282 | +{ |
| 283 | + switch (action) { |
| 284 | + case PM_DEVICE_ACTION_RESUME: |
| 285 | + break; |
| 286 | + case PM_DEVICE_ACTION_SUSPEND: |
| 287 | + break; |
| 288 | + case PM_DEVICE_ACTION_TURN_OFF: |
| 289 | + break; |
| 290 | + case PM_DEVICE_ACTION_TURN_ON: |
| 291 | + mcux_lpc_ctimer_init_common(dev); |
| 292 | + break; |
| 293 | + default: |
| 294 | + return -ENOTSUP; |
| 295 | + } |
| 296 | + return 0; |
| 297 | +} |
| 298 | + |
| 299 | +static int mcux_lpc_ctimer_init(const struct device *dev) |
| 300 | +{ |
| 301 | + /* Rest of the init is done from the PM_DEVICE_TURN_ON action |
| 302 | + * which is invoked by pm_device_driver_init(). |
| 303 | + */ |
| 304 | + return pm_device_driver_init(dev, mcux_lpc_ctimer_pm_action); |
| 305 | +} |
| 306 | + |
280 | 307 | static DEVICE_API(counter, mcux_ctimer_driver_api) = {
|
281 | 308 | .start = mcux_lpc_ctimer_start,
|
282 | 309 | .stop = mcux_lpc_ctimer_stop,
|
@@ -306,8 +333,10 @@ static DEVICE_API(counter, mcux_ctimer_driver_api) = {
|
306 | 333 | .prescale = DT_INST_PROP(id, prescale), \
|
307 | 334 | .irq_config_func = mcux_lpc_ctimer_irq_config_##id, \
|
308 | 335 | }; \
|
| 336 | + PM_DEVICE_DT_INST_DEFINE(id, mcux_lpc_ctimer_pm_action); \ |
309 | 337 | static struct mcux_lpc_ctimer_data mcux_lpc_ctimer_data_##id; \
|
310 |
| - DEVICE_DT_INST_DEFINE(id, &mcux_lpc_ctimer_init, NULL, &mcux_lpc_ctimer_data_##id, \ |
| 338 | + DEVICE_DT_INST_DEFINE(id, &mcux_lpc_ctimer_init, PM_DEVICE_DT_INST_GET(id), \ |
| 339 | + &mcux_lpc_ctimer_data_##id, \ |
311 | 340 | &mcux_lpc_ctimer_config_##id, POST_KERNEL, \
|
312 | 341 | CONFIG_COUNTER_INIT_PRIORITY, &mcux_ctimer_driver_api); \
|
313 | 342 | static void mcux_lpc_ctimer_irq_config_##id(const struct device *dev) \
|
|
0 commit comments