drivers: flash: spi_nor: support device PM
Support device power management in spi_nor driver. Only use SUSPEND/RESUME if `CONFIG_SPI_NOR_IDLE_IN_DPD` is not enabled to avoid state conflicts. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
c3dc01ddf3
commit
ec44816ae7
1 changed files with 41 additions and 1 deletions
|
@ -16,6 +16,7 @@
|
|||
#include <string.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/sys_clock.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
|
||||
#include "spi_nor.h"
|
||||
#include "jesd216.h"
|
||||
|
@ -1246,6 +1247,44 @@ static int spi_nor_configure(const struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
|
||||
static int spi_nor_pm_control(const struct device *dev, enum pm_device_action action)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
switch (action) {
|
||||
#ifdef CONFIG_SPI_NOR_IDLE_IN_DPD
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
break;
|
||||
#else
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
acquire_device(dev);
|
||||
rc = enter_dpd(dev);
|
||||
release_device(dev);
|
||||
break;
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
acquire_device(dev);
|
||||
rc = exit_dpd(dev);
|
||||
release_device(dev);
|
||||
break;
|
||||
#endif /* CONFIG_SPI_NOR_IDLE_IN_DPD */
|
||||
case PM_DEVICE_ACTION_TURN_ON:
|
||||
/* Coming out of power off */
|
||||
rc = spi_nor_configure(dev);
|
||||
break;
|
||||
case PM_DEVICE_ACTION_TURN_OFF:
|
||||
break;
|
||||
default:
|
||||
rc = -ENOSYS;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
/**
|
||||
* @brief Initialize and configure the flash
|
||||
*
|
||||
|
@ -1389,7 +1428,8 @@ static const struct spi_nor_config spi_nor_config_0 = {
|
|||
|
||||
static struct spi_nor_data spi_nor_data_0;
|
||||
|
||||
DEVICE_DT_INST_DEFINE(0, &spi_nor_init, NULL,
|
||||
PM_DEVICE_DT_INST_DEFINE(0, spi_nor_pm_control);
|
||||
DEVICE_DT_INST_DEFINE(0, &spi_nor_init, PM_DEVICE_DT_INST_GET(0),
|
||||
&spi_nor_data_0, &spi_nor_config_0,
|
||||
POST_KERNEL, CONFIG_SPI_NOR_INIT_PRIORITY,
|
||||
&spi_nor_api);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue