drivers: memc: Add device PM to MCUX Flexspi driver

Add Device level power manangement support to the
MCUX FlexSPI driver.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
This commit is contained in:
Mahesh Mahadevan 2022-12-16 09:20:48 -06:00 committed by David Leach
parent 6d31619102
commit db7dedaead

View file

@ -11,6 +11,7 @@
#ifdef CONFIG_PINCTRL
#include <zephyr/drivers/pinctrl.h>
#endif
#include <zephyr/pm/device.h>
#include "memc_mcux_flexspi.h"
@ -174,6 +175,37 @@ static int memc_flexspi_init(const struct device *dev)
return 0;
}
#ifdef CONFIG_PM_DEVICE
static int memc_flexspi_pm_action(const struct device *dev, enum pm_device_action action)
{
struct memc_flexspi_data *data = dev->data;
int ret;
switch (action) {
case PM_DEVICE_ACTION_RESUME:
#ifdef CONFIG_PINCTRL
ret = pinctrl_apply_state(data->pincfg, PINCTRL_STATE_DEFAULT);
if (ret < 0 && ret != -ENOENT) {
return ret;
}
#endif
break;
case PM_DEVICE_ACTION_SUSPEND:
#ifdef CONFIG_PINCTRL
ret = pinctrl_apply_state(data->pincfg, PINCTRL_STATE_SLEEP);
if (ret < 0 && ret != -ENOENT) {
return ret;
}
#endif
break;
default:
return -ENOTSUP;
}
return 0;
}
#endif
#if defined(CONFIG_XIP) && defined(CONFIG_CODE_FLEXSPI)
#define MEMC_FLEXSPI_CFG_XIP(node_id) DT_SAME_NODE(node_id, DT_NODELABEL(flexspi))
#elif defined(CONFIG_XIP) && defined(CONFIG_CODE_FLEXSPI2)
@ -209,9 +241,11 @@ static int memc_flexspi_init(const struct device *dev)
PINCTRL_INIT(n) \
}; \
\
PM_DEVICE_DT_INST_DEFINE(n, memc_flexspi_pm_action); \
\
DEVICE_DT_INST_DEFINE(n, \
memc_flexspi_init, \
NULL, \
PM_DEVICE_DT_INST_GET(n), \
&memc_flexspi_data_##n, \
NULL, \
POST_KERNEL, \