|
17 | 17 | #include <errno.h>
|
18 | 18 | #include <zephyr/device.h>
|
19 | 19 | #include <zephyr/drivers/gpio.h>
|
| 20 | +#include <zephyr/pm/device.h> |
20 | 21 | #include <zephyr/irq.h>
|
21 | 22 | #include <soc.h>
|
22 | 23 | #include <fsl_common.h>
|
@@ -406,14 +407,34 @@ static int gpio_mcux_lpc_manage_cb(const struct device *port,
|
406 | 407 | return gpio_manage_callback(&data->callbacks, callback, set);
|
407 | 408 | }
|
408 | 409 |
|
409 |
| -static int gpio_mcux_lpc_init(const struct device *dev) |
| 410 | +static int gpio_mcux_lpc_pm_action(const struct device *dev, enum pm_device_action action) |
410 | 411 | {
|
411 |
| - const struct gpio_mcux_lpc_config *config = dev->config; |
412 |
| - GPIO_PortInit(config->gpio_base, config->port_no); |
| 412 | + switch (action) { |
| 413 | + case PM_DEVICE_ACTION_RESUME: |
| 414 | + break; |
| 415 | + case PM_DEVICE_ACTION_SUSPEND: |
| 416 | + break; |
| 417 | + case PM_DEVICE_ACTION_TURN_OFF: |
| 418 | + break; |
| 419 | + case PM_DEVICE_ACTION_TURN_ON: |
| 420 | + const struct gpio_mcux_lpc_config *config = dev->config; |
413 | 421 |
|
| 422 | + GPIO_PortInit(config->gpio_base, config->port_no); |
| 423 | + break; |
| 424 | + default: |
| 425 | + return -ENOTSUP; |
| 426 | + } |
414 | 427 | return 0;
|
415 | 428 | }
|
416 | 429 |
|
| 430 | +static int gpio_mcux_lpc_init(const struct device *dev) |
| 431 | +{ |
| 432 | + /* Rest of the init is done from the PM_DEVICE_TURN_ON action |
| 433 | + * which is invoked by pm_device_driver_init(). |
| 434 | + */ |
| 435 | + return pm_device_driver_init(dev, gpio_mcux_lpc_pm_action); |
| 436 | +} |
| 437 | + |
417 | 438 | static DEVICE_API(gpio, gpio_mcux_lpc_driver_api) = {
|
418 | 439 | .pin_configure = gpio_mcux_lpc_configure,
|
419 | 440 | .port_get_raw = gpio_mcux_lpc_port_get_raw,
|
@@ -465,7 +486,10 @@ static DEVICE_API(gpio, gpio_mcux_lpc_driver_api) = {
|
465 | 486 | \
|
466 | 487 | static struct gpio_mcux_lpc_data gpio_mcux_lpc_data_##n; \
|
467 | 488 | \
|
468 |
| - DEVICE_DT_INST_DEFINE(n, lpc_gpio_init_##n, NULL, \ |
| 489 | + PM_DEVICE_DT_INST_DEFINE(n, gpio_mcux_lpc_pm_action); \ |
| 490 | + \ |
| 491 | + DEVICE_DT_INST_DEFINE(n, lpc_gpio_init_##n, \ |
| 492 | + PM_DEVICE_DT_INST_GET(n), \ |
469 | 493 | &gpio_mcux_lpc_data_##n, \
|
470 | 494 | &gpio_mcux_lpc_config_##n, PRE_KERNEL_1, \
|
471 | 495 | CONFIG_GPIO_INIT_PRIORITY, \
|
|
0 commit comments