Skip to content

Commit d035847

Browse files
mmahadevan108kartben
authored andcommitted
drivers: gpio: Add PM Action for MCUX LPC driver
Add PM action for MCUX LPC driver Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent d4d8163 commit d035847

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

drivers/gpio/gpio_mcux_lpc.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <errno.h>
1818
#include <zephyr/device.h>
1919
#include <zephyr/drivers/gpio.h>
20+
#include <zephyr/pm/device.h>
2021
#include <zephyr/irq.h>
2122
#include <soc.h>
2223
#include <fsl_common.h>
@@ -406,14 +407,34 @@ static int gpio_mcux_lpc_manage_cb(const struct device *port,
406407
return gpio_manage_callback(&data->callbacks, callback, set);
407408
}
408409

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)
410411
{
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;
413421

422+
GPIO_PortInit(config->gpio_base, config->port_no);
423+
break;
424+
default:
425+
return -ENOTSUP;
426+
}
414427
return 0;
415428
}
416429

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+
417438
static DEVICE_API(gpio, gpio_mcux_lpc_driver_api) = {
418439
.pin_configure = gpio_mcux_lpc_configure,
419440
.port_get_raw = gpio_mcux_lpc_port_get_raw,
@@ -465,7 +486,10 @@ static DEVICE_API(gpio, gpio_mcux_lpc_driver_api) = {
465486
\
466487
static struct gpio_mcux_lpc_data gpio_mcux_lpc_data_##n; \
467488
\
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), \
469493
&gpio_mcux_lpc_data_##n, \
470494
&gpio_mcux_lpc_config_##n, PRE_KERNEL_1, \
471495
CONFIG_GPIO_INIT_PRIORITY, \

0 commit comments

Comments
 (0)